Linux build fixes

This commit is contained in:
Jack Andersen 2019-05-25 20:24:13 -10:00
parent 20862139b6
commit 9f94db6c82
83 changed files with 839 additions and 295 deletions

8
.gitignore vendored
View File

@ -33,10 +33,16 @@ CMakeLists.txt.user
*.qmlproject.user *.qmlproject.user
*.qmlproject.user.* *.qmlproject.user.*
#Intellij IDEA
.idea/PrimeWorldEditor.iml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml
.idea/workspace.xml
#Dew #Dew
.dew/* .dew/*
# PrimeWorldEditor files # PrimeWorldEditor files
bin/* bin/*
bin-debug/*
build/* build/*

View File

@ -0,0 +1,13 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C>
<option name="NAMESPACE_BRACE_PLACEMENT" value="2" />
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
<option name="BLOCK_BRACE_PLACEMENT" value="2" />
</Objective-C>
<codeStyleSettings language="ObjectiveC">
<option name="BRACE_STYLE" value="2" />
<option name="CLASS_BRACE_STYLE" value="2" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -1,19 +1,17 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
set(MACOSX_DEPLOYMENT_TARGET 10.10)
project(PrimeWorldEditor CXX) project(PrimeWorldEditor CXX)
include(./dew.cmake) include(./dew.cmake)
integrate_dew() integrate_dew()
include(cmake/generate_product_version.cmake)
# Set where the binary files will be built. The program will not execute from # Set where the binary files will be built. The program will not execute from
# here. You must run "make install" to install these to the proper location # here. You must run "make install" to install these to the proper location
# as defined above. # as defined above.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin-debug)
endif()
add_subdirectory(src/Core) add_subdirectory(src/Core)
add_subdirectory(src/Editor) add_subdirectory(src/Editor)

82
cmake/VersionInfo.in Normal file
View File

@ -0,0 +1,82 @@
#pragma once
#ifndef PRODUCT_VERSION_MAJOR
#define PRODUCT_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef PRODUCT_VERSION_MINOR
#define PRODUCT_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef PRODUCT_VERSION_PATCH
#define PRODUCT_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef FILE_VERSION_MAJOR
#define FILE_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef FILE_VERSION_MINOR
#define FILE_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef FILE_VERSION_PATCH
#define FILE_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef FILE_VERSION_BUILD
#define FILE_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef __TO_STRING
#define __TO_STRING_IMPL(x) #x
#define __TO_STRING(x) __TO_STRING_IMPL(x)
#endif
#define PRODUCT_VERSION_MAJOR_MINOR_STR __TO_STRING(PRODUCT_VERSION_MAJOR) "." __TO_STRING(PRODUCT_VERSION_MINOR)
#define PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR PRODUCT_VERSION_MAJOR_MINOR_STR "." __TO_STRING(PRODUCT_VERSION_PATCH)
#define PRODUCT_VERSION_FULL_STR PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(PRODUCT_VERSION_BUILD)
#define PRODUCT_VERSION_RESOURCE PRODUCT_VERSION_MAJOR,PRODUCT_VERSION_MINOR,PRODUCT_VERSION_PATCH,PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_RESOURCE_STR PRODUCT_VERSION_FULL_STR "\0"
#define FILE_VERSION_MAJOR_MINOR_STR __TO_STRING(FILE_VERSION_MAJOR) "." __TO_STRING(FILE_VERSION_MINOR)
#define FILE_VERSION_MAJOR_MINOR_PATCH_STR FILE_VERSION_MAJOR_MINOR_STR "." __TO_STRING(FILE_VERSION_PATCH)
#define FILE_VERSION_FULL_STR FILE_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(FILE_VERSION_BUILD)
#define FILE_VERSION_RESOURCE FILE_VERSION_MAJOR,FILE_VERSION_MINOR,FILE_VERSION_PATCH,FILE_VERSION_BUILD
#define FILE_VERSION_RESOURCE_STR FILE_VERSION_FULL_STR "\0"
#ifndef PRODUCT_ICON
#define PRODUCT_ICON "@PRODUCT_ICON@"
#endif
#ifndef PRODUCT_COMMENTS
#define PRODUCT_COMMENTS "@PRODUCT_COMMENTS@\0"
#endif
#ifndef PRODUCT_COMPANY_NAME
#define PRODUCT_COMPANY_NAME "@PRODUCT_COMPANY_NAME@\0"
#endif
#ifndef PRODUCT_COMPANY_COPYRIGHT
#define PRODUCT_COMPANY_COPYRIGHT "@PRODUCT_COMPANY_COPYRIGHT@\0"
#endif
#ifndef PRODUCT_FILE_DESCRIPTION
#define PRODUCT_FILE_DESCRIPTION "@PRODUCT_FILE_DESCRIPTION@\0"
#endif
#ifndef PRODUCT_INTERNAL_NAME
#define PRODUCT_INTERNAL_NAME "@PRODUCT_NAME@\0"
#endif
#ifndef PRODUCT_ORIGINAL_FILENAME
#define PRODUCT_ORIGINAL_FILENAME "@PRODUCT_ORIGINAL_FILENAME@\0"
#endif
#ifndef PRODUCT_BUNDLE
#define PRODUCT_BUNDLE "@PRODUCT_BUNDLE@\0"
#endif

40
cmake/VersionResource.rc Normal file
View File

@ -0,0 +1,40 @@
#include "VersionInfo.h"
#include "winres.h"
IDI_ICON1 ICON PRODUCT_ICON
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILE_VERSION_RESOURCE
PRODUCTVERSION PRODUCT_VERSION_RESOURCE
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "041904b0"
BEGIN
VALUE "Comments", PRODUCT_COMMENTS
VALUE "CompanyName", PRODUCT_COMPANY_NAME
VALUE "FileDescription", PRODUCT_FILE_DESCRIPTION
VALUE "FileVersion", FILE_VERSION_RESOURCE_STR
VALUE "InternalName", PRODUCT_INTERNAL_NAME
VALUE "LegalCopyright", PRODUCT_COMPANY_COPYRIGHT
VALUE "OriginalFilename", PRODUCT_ORIGINAL_FILENAME
VALUE "ProductName", PRODUCT_BUNDLE
VALUE "ProductVersion", PRODUCT_VERSION_RESOURCE_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x419, 1200
END
END

View File

@ -0,0 +1,107 @@
include (CMakeParseArguments)
set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR})
# generate_product_version() function
#
# This function uses VersionInfo.in template file and VersionResource.rc file
# to generate WIN32 resource with version information and general resource strings.
#
# Usage:
# generate_product_version(
# SomeOutputResourceVariable
# NAME MyGreatProject
# ICON ${PATH_TO_APP_ICON}
# VERSION_MAJOR 2
# VERSION_MINOR 3
# VERSION_PATH ${BUILD_COUNTER}
# VERSION_REVISION ${BUILD_REVISION}
# )
# where BUILD_COUNTER and BUILD_REVISION could be values from your CI server.
#
# You can use generated resource for your executable targets:
# add_executable(target-name ${target-files} ${SomeOutputResourceVariable})
#
# You can specify resource strings in arguments:
# NAME - name of executable (no defaults, ex: Microsoft Word)
# BUNDLE - bundle (${NAME} is default, ex: Microsoft Office)
# ICON - path to application icon (${CMAKE_SOURCE_DIR}/product.ico by default)
# VERSION_MAJOR - 1 is default
# VERSION_MINOR - 0 is default
# VERSION_PATCH - 0 is default
# VERSION_REVISION - 0 is default
# COMPANY_NAME - your company name (no defaults)
# COMPANY_COPYRIGHT - ${COMPANY_NAME} (C) Copyright ${CURRENT_YEAR} is default
# COMMENTS - ${NAME} v${VERSION_MAJOR}.${VERSION_MINOR} is default
# ORIGINAL_FILENAME - ${NAME} is default
# INTERNAL_NAME - ${NAME} is default
# FILE_DESCRIPTION - ${NAME} is default
function(generate_product_version outfiles)
set (options)
set (oneValueArgs
NAME
BUNDLE
ICON
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH
VERSION_REVISION
COMPANY_NAME
COMPANY_COPYRIGHT
COMMENTS
ORIGINAL_FILENAME
INTERNAL_NAME
FILE_DESCRIPTION)
set (multiValueArgs)
cmake_parse_arguments(PRODUCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT PRODUCT_BUNDLE OR "${PRODUCT_BUNDLE}" STREQUAL "")
set(PRODUCT_BUNDLE "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_ICON OR "${PRODUCT_ICON}" STREQUAL "")
set(PRODUCT_ICON "${CMAKE_SOURCE_DIR}/product.ico")
endif()
if (NOT PRODUCT_VERSION_MAJOR EQUAL 0 AND (NOT PRODUCT_VERSION_MAJOR OR "${PRODUCT_VERSION_MAJOR}" STREQUAL ""))
set(PRODUCT_VERSION_MAJOR 1)
endif()
if (NOT PRODUCT_VERSION_MINOR EQUAL 0 AND (NOT PRODUCT_VERSION_MINOR OR "${PRODUCT_VERSION_MINOR}" STREQUAL ""))
set(PRODUCT_VERSION_MINOR 0)
endif()
if (NOT PRODUCT_VERSION_PATCH EQUAL 0 AND (NOT PRODUCT_VERSION_PATCH OR "${PRODUCT_VERSION_PATCH}" STREQUAL ""))
set(PRODUCT_VERSION_PATCH 0)
endif()
if (NOT PRODUCT_VERSION_REVISION EQUAL 0 AND (NOT PRODUCT_VERSION_REVISION OR "${PRODUCT_VERSION_REVISION}" STREQUAL ""))
set(PRODUCT_VERSION_REVISION 0)
endif()
if (NOT PRODUCT_COMPANY_COPYRIGHT OR "${PRODUCT_COMPANY_COPYRIGHT}" STREQUAL "")
string(TIMESTAMP PRODUCT_CURRENT_YEAR "%Y")
set(PRODUCT_COMPANY_COPYRIGHT "${PRODUCT_COMPANY_NAME} (C) Copyright ${PRODUCT_CURRENT_YEAR}")
endif()
if (NOT PRODUCT_COMMENTS OR "${PRODUCT_COMMENTS}" STREQUAL "")
set(PRODUCT_COMMENTS "${PRODUCT_NAME} v${PRODUCT_VERSION_MAJOR}.${PRODUCT_VERSION_MINOR}")
endif()
if (NOT PRODUCT_ORIGINAL_FILENAME OR "${PRODUCT_ORIGINAL_FILENAME}" STREQUAL "")
set(PRODUCT_ORIGINAL_FILENAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_INTERNAL_NAME OR "${PRODUCT_INTERNAL_NAME}" STREQUAL "")
set(PRODUCT_INTERNAL_NAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_FILE_DESCRIPTION OR "${PRODUCT_FILE_DESCRIPTION}" STREQUAL "")
set(PRODUCT_FILE_DESCRIPTION "${PRODUCT_NAME}")
endif()
set (_VersionInfoFile ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h)
set (_VersionResourceFile ${CMAKE_CURRENT_BINARY_DIR}/VersionResource.rc)
configure_file(
${GenerateProductVersionCurrentDir}/VersionInfo.in
${_VersionInfoFile}
@ONLY)
configure_file(
${GenerateProductVersionCurrentDir}/VersionResource.rc
${_VersionResourceFile}
COPYONLY)
list(APPEND ${outfiles} ${_VersionInfoFile} ${_VersionResourceFile})
set (${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction()

View File

@ -17,7 +17,7 @@ function(integrate_dew)
return() return()
endif() endif()
if (${CMAKE_BUILD_TYPE} STREQUAL Debug) if ("${CMAKE_BUILD_TYPE}" STREQUAL Debug)
set(dew_cmake_prefix_suffix debug) set(dew_cmake_prefix_suffix debug)
else() else()
set(dew_cmake_prefix_suffix release) set(dew_cmake_prefix_suffix release)

View File

@ -12,12 +12,13 @@
"url": "https://github.com/jackoalan/assimp", "url": "https://github.com/jackoalan/assimp",
"type": "git", "type": "git",
"head": "static-lib-export", "head": "static-lib-export",
"ref": "2c16b2f6c517006367a558c06075584bbd230367", "ref": "d048bccad1ea3f72906da2d970b30f187db91f33",
"dependson": [ "dependson": [
"zlib" "zlib"
], ],
"cmake_defines": { "cmake_defines": {
"ASSIMP_BUILD_ZLIB": "OFF", "ASSIMP_BUILD_ZLIB": "OFF",
"ASSIMP_BUILD_MINIZIP": "ON",
"ASSIMP_BUILD_ASSIMP_TOOLS": "OFF" "ASSIMP_BUILD_ASSIMP_TOOLS": "OFF"
} }
}, },
@ -26,21 +27,21 @@
"url": "https://github.com/AxioDL/nod", "url": "https://github.com/AxioDL/nod",
"type": "git", "type": "git",
"head": "master", "head": "master",
"ref": "4dd0375cae9557a1881d56f722e20557075a9d93" "ref": "a1284ae06586b958f36b8ecaba29390835ed2820"
}, },
{ {
"name": "CodeGen", "name": "CodeGen",
"url": "https://github.com/jackoalan/CodeGen", "url": "https://github.com/jackoalan/CodeGen",
"type": "git", "type": "git",
"head": "cmake", "head": "cmake",
"ref": "94dc9ac32986f14a734c3523dd85d50ae50f7128" "ref": "7a71e4866a60c5bf49e6d8f26717726d939c2aaf"
}, },
{ {
"name": "LibCommon", "name": "LibCommon",
"url": "https://github.com/jackoalan/LibCommon", "url": "https://github.com/jackoalan/LibCommon",
"type": "git", "type": "git",
"head": "dew", "head": "dew",
"ref": "4c780619259a31168e6a8ce6e7018b2ea640b3af" "ref": "f5c22715fbeb451a167ec3494f9d40ad53866029"
}, },
{ {
"name": "lzo", "name": "lzo",

View File

@ -10,7 +10,10 @@ find_package(logvisor CONFIG REQUIRED)
find_package(lzokay CONFIG REQUIRED) find_package(lzokay CONFIG REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(assimp CONFIG REQUIRED) find_package(assimp CONFIG REQUIRED)
find_package(zlib REQUIRED) find_package(ZLIB REQUIRED)
# AssImp's cmake config is pretty awful. It doesn't include necesary libraries. Hopefully this can be fixed later.
find_library(IIRXML_LIBRARY NAMES IrrXMLd IrrXML)
include(codegen) include(codegen)
@ -41,6 +44,7 @@ target_link_libraries(
OpenGL::GL OpenGL::GL
codegen::codegen codegen::codegen
assimp::assimp assimp::assimp
${IIRXML_LIBRARY}
${ZLIB_LIBRARY} ${ZLIB_LIBRARY}
) )

View File

@ -182,7 +182,7 @@ void CAssetNameMap::PostLoadValidate()
for (auto Iter = Dupes.begin(); Iter != Dupes.end(); Iter++) for (auto Iter = Dupes.begin(); Iter != Dupes.end(); Iter++)
{ {
warnf("\t%s", Iter->FullPath()); warnf("\t%s", *Iter->FullPath());
} }
mMap.clear(); mMap.clear();
@ -195,7 +195,7 @@ TString CAssetNameMap::DefaultNameMapPath(EIDLength IDLength)
{ {
ASSERT(IDLength != kInvalidIDLength); ASSERT(IDLength != kInvalidIDLength);
TString Suffix = (IDLength == k32Bit ? "32" : "64"); TString Suffix = (IDLength == k32Bit ? "32" : "64");
return gkAssetMapPath + Suffix + "." + gkAssetMapExt; return gDataDir + gkAssetMapPath + Suffix + "." + gkAssetMapExt;
} }
TString CAssetNameMap::DefaultNameMapPath(EGame Game) TString CAssetNameMap::DefaultNameMapPath(EGame Game)

View File

@ -8,7 +8,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
const TString gkAssetMapPath = "../resources/gameinfo/AssetNameMap"; const TString gkAssetMapPath = "resources/gameinfo/AssetNameMap";
const TString gkAssetMapExt = "xml"; const TString gkAssetMapExt = "xml";
class CAssetNameMap class CAssetNameMap

View File

@ -19,6 +19,12 @@
#define USE_ASSET_NAME_MAP 1 #define USE_ASSET_NAME_MAP 1
#define EXPORT_COOKED 1 #define EXPORT_COOKED 1
#if NOD_UCS2
static nod::SystemStringView TStringToNodString(const TString& string) { return ToWChar(string); }
#else
static nod::SystemStringView TStringToNodString(const TString& string) { return *string; }
#endif
CGameExporter::CGameExporter(EDiscType DiscType, EGame Game, bool FrontEnd, ERegion Region, const TString& rkGameName, const TString& rkGameID, float BuildVersion) CGameExporter::CGameExporter(EDiscType DiscType, EGame Game, bool FrontEnd, ERegion Region, const TString& rkGameName, const TString& rkGameID, float BuildVersion)
: mGame(Game) : mGame(Game)
, mRegion(Region) , mRegion(Region)
@ -198,16 +204,16 @@ bool CGameExporter::ExtractDiscData()
if (IsWii) if (IsWii)
{ {
// Extract crypto files // Extract crypto files
if (!pDataPartition->extractCryptoFiles(ToWChar(AbsDiscDir), Context)) if (!pDataPartition->extractCryptoFiles(TStringToNodString(AbsDiscDir), Context))
return false; return false;
// Extract disc header files // Extract disc header files
if (!mpDisc->extractDiscHeaderFiles(ToWChar(AbsDiscDir), Context)) if (!mpDisc->extractDiscHeaderFiles(TStringToNodString(AbsDiscDir), Context))
return false; return false;
} }
// Extract system files // Extract system files
if (!pDataPartition->extractSysFiles(ToWChar(AbsDiscDir), Context)) if (!pDataPartition->extractSysFiles(TStringToNodString(AbsDiscDir), Context))
return false; return false;
return true; return true;
@ -226,7 +232,7 @@ bool CGameExporter::ExtractDiscNodeRecursive(const nod::Node *pkNode, const TStr
if (Iter->getKind() == nod::Node::Kind::File) if (Iter->getKind() == nod::Node::Kind::File)
{ {
TString FilePath = rkDir + Iter->getName().data(); TString FilePath = rkDir + Iter->getName().data();
bool Success = Iter->extractToDirectory(ToWChar(rkDir), rkContext); bool Success = Iter->extractToDirectory(TStringToNodString(rkDir), rkContext);
if (!Success) return false; if (!Success) return false;
if (FilePath.GetFileExtension().CaseInsensitiveCompare("pak")) if (FilePath.GetFileExtension().CaseInsensitiveCompare("pak"))

View File

@ -63,6 +63,7 @@ class CGameExporter
// Progress // Progress
IProgressNotifier *mpProgress; IProgressNotifier *mpProgress;
public:
enum EExportStep enum EExportStep
{ {
eES_ExtractDisc, eES_ExtractDisc,
@ -72,7 +73,6 @@ class CGameExporter
eES_NumSteps eES_NumSteps
}; };
public:
CGameExporter(EDiscType DiscType, EGame Game, bool FrontEnd, ERegion Region, const TString& rkGameName, const TString& rkGameID, float BuildVersion); CGameExporter(EDiscType DiscType, EGame Game, bool FrontEnd, ERegion Region, const TString& rkGameName, const TString& rkGameID, float BuildVersion);
bool Export(nod::DiscBase *pDisc, const TString& rkOutputDir, CAssetNameMap *pNameMap, CGameInfo *pGameInfo, IProgressNotifier *pProgress); bool Export(nod::DiscBase *pDisc, const TString& rkOutputDir, CAssetNameMap *pNameMap, CGameInfo *pGameInfo, IProgressNotifier *pProgress);
void LoadResource(const CAssetID& rkID, std::vector<uint8>& rBuffer); void LoadResource(const CAssetID& rkID, std::vector<uint8>& rBuffer);

View File

@ -1,4 +1,5 @@
#include "CGameInfo.h" #include "CGameInfo.h"
#include "CResourceStore.h"
#include <Common/FileUtil.h> #include <Common/FileUtil.h>
bool CGameInfo::LoadGameInfo(EGame Game) bool CGameInfo::LoadGameInfo(EGame Game)
@ -83,5 +84,5 @@ TString CGameInfo::GetDefaultGameInfoPath(EGame Game)
return ""; return "";
TString GameName = GetGameShortName(Game); TString GameName = GetGameShortName(Game);
return TString::Format("%s/GameInfo%s.%s", *gkGameInfoDir, *GameName, *gkGameInfoExt); return TString::Format("%s/%s/GameInfo%s.%s", *gDataDir, *gkGameInfoDir, *GameName, *gkGameInfoExt);
} }

View File

@ -8,7 +8,7 @@
#include <Common/Serialization/XML.h> #include <Common/Serialization/XML.h>
#include <map> #include <map>
const TString gkGameInfoDir = "../resources/gameinfo"; const TString gkGameInfoDir = "resources/gameinfo";
const TString gkGameInfoExt = "xml"; const TString gkGameInfoExt = "xml";
//@todo merge this class into CGameTemplate //@todo merge this class into CGameTemplate

View File

@ -5,6 +5,12 @@
#include <Common/Serialization/XML.h> #include <Common/Serialization/XML.h>
#include <nod/nod.hpp> #include <nod/nod.hpp>
#if NOD_UCS2
static nod::SystemStringView TStringToNodString(const TString& string) { return ToWChar(string); }
#else
static nod::SystemStringView TStringToNodString(const TString& string) { return *string; }
#endif
CGameProject::~CGameProject() CGameProject::~CGameProject()
{ {
if (mpResourceStore) if (mpResourceStore)
@ -88,13 +94,13 @@ bool CGameProject::BuildISO(const TString& rkIsoPath, IProgressNotifier *pProgre
if (!IsWiiBuild()) if (!IsWiiBuild())
{ {
nod::DiscBuilderGCN Builder(ToWChar(rkIsoPath), ProgressCallback); nod::DiscBuilderGCN Builder(TStringToNodString(rkIsoPath), ProgressCallback);
return Builder.buildFromDirectory(ToWChar(DiscRoot)) == nod::EBuildResult::Success; return Builder.buildFromDirectory(TStringToNodString(DiscRoot)) == nod::EBuildResult::Success;
} }
else else
{ {
nod::DiscBuilderWii Builder(ToWChar(rkIsoPath), IsTrilogy(), ProgressCallback); nod::DiscBuilderWii Builder(TStringToNodString(rkIsoPath), IsTrilogy(), ProgressCallback);
return Builder.buildFromDirectory(ToWChar(DiscRoot)) == nod::EBuildResult::Success; return Builder.buildFromDirectory(TStringToNodString(DiscRoot)) == nod::EBuildResult::Success;
} }
} }
@ -113,8 +119,8 @@ bool CGameProject::MergeISO(const TString& rkIsoPath, nod::DiscWii *pOriginalIso
TString DiscRoot = DiscFilesystemRoot(false); TString DiscRoot = DiscFilesystemRoot(false);
nod::DiscMergerWii Merger(ToWChar(rkIsoPath), *pOriginalIso, IsTrilogy(), ProgressCallback); nod::DiscMergerWii Merger(TStringToNodString(rkIsoPath), *pOriginalIso, IsTrilogy(), ProgressCallback);
return Merger.mergeFromDirectory(ToWChar(DiscRoot)) == nod::EBuildResult::Success; return Merger.mergeFromDirectory(TStringToNodString(DiscRoot)) == nod::EBuildResult::Success;
} }
void CGameProject::GetWorldList(std::list<CAssetID>& rOut) const void CGameProject::GetWorldList(std::list<CAssetID>& rOut) const

View File

@ -12,6 +12,7 @@
#include <tinyxml2.h> #include <tinyxml2.h>
using namespace tinyxml2; using namespace tinyxml2;
TString gDataDir;
CResourceStore *gpResourceStore = nullptr; CResourceStore *gpResourceStore = nullptr;
CResourceStore *gpEditorStore = nullptr; CResourceStore *gpEditorStore = nullptr;
@ -607,6 +608,19 @@ bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry)
return true; return true;
} }
#ifdef _WIN32
static int wrap_fopen(FILE** pFile, const char *filename, const char *mode)
{
return fopen_s(pFile, filename, mode);
}
#else
static int wrap_fopen(FILE** pFile, const char *filename, const char *mode)
{
*pFile = fopen(filename, mode);
return *pFile == nullptr;
}
#endif
void CResourceStore::ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly) void CResourceStore::ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly)
{ {
// Read file contents -first- then move assets -after-; this // Read file contents -first- then move assets -after-; this
@ -615,7 +629,7 @@ void CResourceStore::ImportNamesFromPakContentsTxt(const TString& rkTxtPath, boo
// todo: move to CAssetNameMap? // todo: move to CAssetNameMap?
std::map<CResourceEntry*, TString> PathMap; std::map<CResourceEntry*, TString> PathMap;
FILE *pContentsFile; FILE *pContentsFile;
fopen_s(&pContentsFile, *rkTxtPath, "r"); wrap_fopen(&pContentsFile, *rkTxtPath, "r");
if (!pContentsFile) if (!pContentsFile)
{ {

View File

@ -93,6 +93,7 @@ public:
inline bool IsEditorStore() const { return mpProj == nullptr; } inline bool IsEditorStore() const { return mpProj == nullptr; }
}; };
extern TString gDataDir;
extern CResourceStore *gpResourceStore; extern CResourceStore *gpResourceStore;
extern CResourceStore *gpEditorStore; extern CResourceStore *gpEditorStore;

View File

@ -73,7 +73,7 @@ TString CVirtualDirectory::FullPath() const
if (IsRoot()) if (IsRoot())
return ""; return "";
else else
return (mpParent ? mpParent->FullPath() + mName : mName) + '/'; return (mpParent ? mpParent->FullPath() + mName : static_cast<TString::BaseClass>(mName)) + '/';
} }
TString CVirtualDirectory::AbsolutePath() const TString CVirtualDirectory::AbsolutePath() const
@ -89,7 +89,7 @@ CVirtualDirectory* CVirtualDirectory::GetRoot()
CVirtualDirectory* CVirtualDirectory::FindChildDirectory(const TString& rkName, bool AllowCreate) CVirtualDirectory* CVirtualDirectory::FindChildDirectory(const TString& rkName, bool AllowCreate)
{ {
uint32 SlashIdx = rkName.IndexOf("\\/"); uint32 SlashIdx = rkName.IndexOf("\\/");
TString DirName = (SlashIdx == -1 ? rkName : rkName.SubString(0, SlashIdx)); TString DirName = (SlashIdx == -1 ? static_cast<TString::BaseClass>(rkName) : rkName.SubString(0, SlashIdx));
for (uint32 iSub = 0; iSub < mSubdirectories.size(); iSub++) for (uint32 iSub = 0; iSub < mSubdirectories.size(); iSub++)
{ {
@ -173,7 +173,7 @@ bool CVirtualDirectory::AddChild(const TString &rkPath, CResourceEntry *pEntry)
else if (IsValidDirectoryPath(rkPath)) else if (IsValidDirectoryPath(rkPath))
{ {
uint32 SlashIdx = rkPath.IndexOf("\\/"); uint32 SlashIdx = rkPath.IndexOf("\\/");
TString DirName = (SlashIdx == -1 ? rkPath : rkPath.SubString(0, SlashIdx)); TString DirName = (SlashIdx == -1 ? static_cast<TString::BaseClass>(rkPath) : rkPath.SubString(0, SlashIdx));
TString Remaining = (SlashIdx == -1 ? "" : rkPath.SubString(SlashIdx + 1, rkPath.Size() - SlashIdx)); TString Remaining = (SlashIdx == -1 ? "" : rkPath.SubString(SlashIdx + 1, rkPath.Size() - SlashIdx));
// Check if this subdirectory already exists // Check if this subdirectory already exists
@ -286,7 +286,7 @@ void CVirtualDirectory::SortSubdirectories()
bool CVirtualDirectory::Rename(const TString& rkNewName) bool CVirtualDirectory::Rename(const TString& rkNewName)
{ {
debugf("MOVING DIRECTORY: %s --> %s", *FullPath(), *mpParent->FullPath() + rkNewName + '/'); debugf("MOVING DIRECTORY: %s --> %s", *FullPath(), *(mpParent->FullPath() + rkNewName + '/'));
if (!IsRoot()) if (!IsRoot())
{ {

View File

@ -12,7 +12,7 @@ class CRenderbuffer
bool mInitialized; bool mInitialized;
public: public:
CRenderbuffer::CRenderbuffer() CRenderbuffer()
: mWidth(0) : mWidth(0)
, mHeight(0) , mHeight(0)
, mEnableMultisampling(false) , mEnableMultisampling(false)
@ -20,7 +20,7 @@ public:
{ {
} }
CRenderbuffer::CRenderbuffer(uint Width, uint Height) CRenderbuffer(uint Width, uint Height)
: mWidth(Width) : mWidth(Width)
, mHeight(Height) , mHeight(Height)
, mEnableMultisampling(false) , mEnableMultisampling(false)
@ -28,20 +28,20 @@ public:
{ {
} }
CRenderbuffer::~CRenderbuffer() ~CRenderbuffer()
{ {
if (mInitialized) if (mInitialized)
glDeleteRenderbuffers(1, &mRenderbuffer); glDeleteRenderbuffers(1, &mRenderbuffer);
} }
void CRenderbuffer::Init() void Init()
{ {
mInitialized = true; mInitialized = true;
glGenRenderbuffers(1, &mRenderbuffer); glGenRenderbuffers(1, &mRenderbuffer);
InitStorage(); InitStorage();
} }
inline void CRenderbuffer::Resize(uint Width, uint Height) inline void Resize(uint Width, uint Height)
{ {
mWidth = Width; mWidth = Width;
mHeight = Height; mHeight = Height;
@ -50,13 +50,13 @@ public:
InitStorage(); InitStorage();
} }
inline void CRenderbuffer::Bind() inline void Bind()
{ {
if (!mInitialized) Init(); if (!mInitialized) Init();
glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
} }
inline void CRenderbuffer::Unbind() inline void Unbind()
{ {
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
} }

View File

@ -216,8 +216,8 @@ void CShader::SetCurrent()
// ************ STATIC ************ // ************ STATIC ************
CShader* CShader::FromResourceFile(const TString& rkShaderName) CShader* CShader::FromResourceFile(const TString& rkShaderName)
{ {
TString VertexShaderFilename = "../resources/shaders/" + rkShaderName + ".vs"; TString VertexShaderFilename = gDataDir + "resources/shaders/" + rkShaderName + ".vs";
TString PixelShaderFilename = "../resources/shaders/" + rkShaderName + ".ps"; TString PixelShaderFilename = gDataDir + "resources/shaders/" + rkShaderName + ".ps";
TString VertexShaderText, PixelShaderText; TString VertexShaderText, PixelShaderText;
if (!FileUtil::LoadFileToString(VertexShaderFilename, VertexShaderText)) if (!FileUtil::LoadFileToString(VertexShaderFilename, VertexShaderText))

View File

@ -6,18 +6,18 @@
#include <iostream> #include <iostream>
// ************ MEMBER INITIALIZATION ************ // ************ MEMBER INITIALIZATION ************
CVertexBuffer CDrawUtil::mGridVertices; std::optional<CVertexBuffer> CDrawUtil::mGridVertices;
CIndexBuffer CDrawUtil::mGridIndices; CIndexBuffer CDrawUtil::mGridIndices;
CDynamicVertexBuffer CDrawUtil::mSquareVertices; std::optional<CDynamicVertexBuffer> CDrawUtil::mSquareVertices;
CIndexBuffer CDrawUtil::mSquareIndices; CIndexBuffer CDrawUtil::mSquareIndices;
CDynamicVertexBuffer CDrawUtil::mLineVertices; std::optional<CDynamicVertexBuffer> CDrawUtil::mLineVertices;
CIndexBuffer CDrawUtil::mLineIndices; CIndexBuffer CDrawUtil::mLineIndices;
TResPtr<CModel> CDrawUtil::mpCubeModel; TResPtr<CModel> CDrawUtil::mpCubeModel;
CVertexBuffer CDrawUtil::mWireCubeVertices; std::optional<CVertexBuffer> CDrawUtil::mWireCubeVertices;
CIndexBuffer CDrawUtil::mWireCubeIndices; CIndexBuffer CDrawUtil::mWireCubeIndices;
TResPtr<CModel> CDrawUtil::mpSphereModel; TResPtr<CModel> CDrawUtil::mpSphereModel;
@ -45,7 +45,7 @@ void CDrawUtil::DrawGrid(CColor LineColor, CColor BoldLineColor)
{ {
Init(); Init();
mGridVertices.Bind(); mGridVertices->Bind();
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
CGraphics::UpdateMVPBlock(); CGraphics::UpdateMVPBlock();
@ -88,13 +88,13 @@ void CDrawUtil::DrawSquare(const float *pTexCoords)
for (uint32 iTex = 0; iTex < 8; iTex++) for (uint32 iTex = 0; iTex < 8; iTex++)
{ {
EVertexAttribute TexAttrib = (EVertexAttribute) ((uint) (EVertexAttribute::Tex0) << iTex); EVertexAttribute TexAttrib = (EVertexAttribute) ((uint) (EVertexAttribute::Tex0) << iTex);
mSquareVertices.BufferAttrib(TexAttrib, pTexCoords); mSquareVertices->BufferAttrib(TexAttrib, pTexCoords);
} }
// Draw // Draw
mSquareVertices.Bind(); mSquareVertices->Bind();
mSquareIndices.DrawElements(); mSquareIndices.DrawElements();
mSquareVertices.Unbind(); mSquareVertices->Unbind();
} }
void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB) void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB)
@ -114,13 +114,13 @@ void CDrawUtil::DrawLine(const CVector3f& PointA, const CVector3f& PointB, const
// Copy vec3s into an array to ensure they are adjacent in memory // Copy vec3s into an array to ensure they are adjacent in memory
CVector3f Points[2] = { PointA, PointB }; CVector3f Points[2] = { PointA, PointB };
mLineVertices.BufferAttrib(EVertexAttribute::Position, Points); mLineVertices->BufferAttrib(EVertexAttribute::Position, Points);
// Draw // Draw
UseColorShader(LineColor); UseColorShader(LineColor);
mLineVertices.Bind(); mLineVertices->Bind();
mLineIndices.DrawElements(); mLineIndices.DrawElements();
mLineVertices.Unbind(); mLineVertices->Unbind();
} }
void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor) void CDrawUtil::DrawLine(const CVector2f& PointA, const CVector2f& PointB, const CColor& LineColor)
@ -161,9 +161,9 @@ void CDrawUtil::DrawWireCube()
{ {
Init(); Init();
glLineWidth(1.f); glLineWidth(1.f);
mWireCubeVertices.Bind(); mWireCubeVertices->Bind();
mWireCubeIndices.DrawElements(); mWireCubeIndices.DrawElements();
mWireCubeVertices.Unbind(); mWireCubeVertices->Unbind();
} }
void CDrawUtil::DrawWireCube(const CAABox& kAABox, const CColor& kColor) void CDrawUtil::DrawWireCube(const CAABox& kAABox, const CColor& kColor)
@ -413,22 +413,23 @@ void CDrawUtil::InitGrid()
int MinIdx = (kGridSize - 1) / -2; int MinIdx = (kGridSize - 1) / -2;
int MaxIdx = (kGridSize - 1) / 2; int MaxIdx = (kGridSize - 1) / 2;
mGridVertices.SetVertexDesc(EVertexAttribute::Position); mGridVertices.emplace();
mGridVertices.Reserve(kGridSize * 4); mGridVertices->SetVertexDesc(EVertexAttribute::Position);
mGridVertices->Reserve(kGridSize * 4);
for (int32 i = MinIdx; i <= MaxIdx; i++) for (int32 i = MinIdx; i <= MaxIdx; i++)
{ {
if (i == 0) continue; if (i == 0) continue;
mGridVertices.AddVertex(CVector3f(MinIdx * kGridSpacing, i * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(MinIdx * kGridSpacing, i * kGridSpacing, 0.0f));
mGridVertices.AddVertex(CVector3f(MaxIdx * kGridSpacing, i * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(MaxIdx * kGridSpacing, i * kGridSpacing, 0.0f));
mGridVertices.AddVertex(CVector3f(i * kGridSpacing, MinIdx * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(i * kGridSpacing, MinIdx * kGridSpacing, 0.0f));
mGridVertices.AddVertex(CVector3f(i * kGridSpacing, MaxIdx * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(i * kGridSpacing, MaxIdx * kGridSpacing, 0.0f));
} }
mGridVertices.AddVertex(CVector3f(MinIdx * kGridSpacing, 0, 0.0f)); mGridVertices->AddVertex(CVector3f(MinIdx * kGridSpacing, 0, 0.0f));
mGridVertices.AddVertex(CVector3f(MaxIdx * kGridSpacing, 0, 0.0f)); mGridVertices->AddVertex(CVector3f(MaxIdx * kGridSpacing, 0, 0.0f));
mGridVertices.AddVertex(CVector3f(0, MinIdx * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(0, MinIdx * kGridSpacing, 0.0f));
mGridVertices.AddVertex(CVector3f(0, MaxIdx * kGridSpacing, 0.0f)); mGridVertices->AddVertex(CVector3f(0, MaxIdx * kGridSpacing, 0.0f));
int NumIndices = kGridSize * 4; int NumIndices = kGridSize * 4;
mGridIndices.Reserve(NumIndices); mGridIndices.Reserve(NumIndices);
@ -439,17 +440,18 @@ void CDrawUtil::InitGrid()
void CDrawUtil::InitSquare() void CDrawUtil::InitSquare()
{ {
debugf("Creating square"); debugf("Creating square");
mSquareVertices.SetActiveAttribs(EVertexAttribute::Position | mSquareVertices.emplace();
EVertexAttribute::Normal | mSquareVertices->SetActiveAttribs(EVertexAttribute::Position |
EVertexAttribute::Tex0 | EVertexAttribute::Normal |
EVertexAttribute::Tex1 | EVertexAttribute::Tex0 |
EVertexAttribute::Tex2 | EVertexAttribute::Tex1 |
EVertexAttribute::Tex3 | EVertexAttribute::Tex2 |
EVertexAttribute::Tex4 | EVertexAttribute::Tex3 |
EVertexAttribute::Tex5 | EVertexAttribute::Tex4 |
EVertexAttribute::Tex6 | EVertexAttribute::Tex5 |
EVertexAttribute::Tex7 ); EVertexAttribute::Tex6 |
mSquareVertices.SetVertexCount(4); EVertexAttribute::Tex7 );
mSquareVertices->SetVertexCount(4);
CVector3f SquareVertices[] = { CVector3f SquareVertices[] = {
CVector3f(-1.f, 1.f, 0.f), CVector3f(-1.f, 1.f, 0.f),
@ -472,13 +474,13 @@ void CDrawUtil::InitSquare()
CVector2f(0.f, 0.f) CVector2f(0.f, 0.f)
}; };
mSquareVertices.BufferAttrib(EVertexAttribute::Position, SquareVertices); mSquareVertices->BufferAttrib(EVertexAttribute::Position, SquareVertices);
mSquareVertices.BufferAttrib(EVertexAttribute::Normal, SquareNormals); mSquareVertices->BufferAttrib(EVertexAttribute::Normal, SquareNormals);
for (uint32 iTex = 0; iTex < 8; iTex++) for (uint32 iTex = 0; iTex < 8; iTex++)
{ {
EVertexAttribute Attrib = (EVertexAttribute) (EVertexAttribute::Tex0 << iTex); EVertexAttribute Attrib = (EVertexAttribute) (EVertexAttribute::Tex0 << iTex);
mSquareVertices.BufferAttrib(Attrib, SquareTexCoords); mSquareVertices->BufferAttrib(Attrib, SquareTexCoords);
} }
mSquareIndices.Reserve(4); mSquareIndices.Reserve(4);
@ -492,8 +494,9 @@ void CDrawUtil::InitSquare()
void CDrawUtil::InitLine() void CDrawUtil::InitLine()
{ {
debugf("Creating line"); debugf("Creating line");
mLineVertices.SetActiveAttribs(EVertexAttribute::Position); mLineVertices.emplace();
mLineVertices.SetVertexCount(2); mLineVertices->SetActiveAttribs(EVertexAttribute::Position);
mLineVertices->SetVertexCount(2);
mLineIndices.Reserve(2); mLineIndices.Reserve(2);
mLineIndices.SetPrimitiveType(GL_LINES); mLineIndices.SetPrimitiveType(GL_LINES);
@ -510,16 +513,17 @@ void CDrawUtil::InitCube()
void CDrawUtil::InitWireCube() void CDrawUtil::InitWireCube()
{ {
debugf("Creating wire cube"); debugf("Creating wire cube");
mWireCubeVertices.SetVertexDesc(EVertexAttribute::Position); mWireCubeVertices.emplace();
mWireCubeVertices.Reserve(8); mWireCubeVertices->SetVertexDesc(EVertexAttribute::Position);
mWireCubeVertices.AddVertex(CVector3f(-0.5f, -0.5f, -0.5f)); mWireCubeVertices->Reserve(8);
mWireCubeVertices.AddVertex(CVector3f(-0.5f, 0.5f, -0.5f)); mWireCubeVertices->AddVertex(CVector3f(-0.5f, -0.5f, -0.5f));
mWireCubeVertices.AddVertex(CVector3f( 0.5f, 0.5f, -0.5f)); mWireCubeVertices->AddVertex(CVector3f(-0.5f, 0.5f, -0.5f));
mWireCubeVertices.AddVertex(CVector3f( 0.5f, -0.5f, -0.5f)); mWireCubeVertices->AddVertex(CVector3f( 0.5f, 0.5f, -0.5f));
mWireCubeVertices.AddVertex(CVector3f(-0.5f, -0.5f, 0.5f)); mWireCubeVertices->AddVertex(CVector3f( 0.5f, -0.5f, -0.5f));
mWireCubeVertices.AddVertex(CVector3f( 0.5f, -0.5f, 0.5f)); mWireCubeVertices->AddVertex(CVector3f(-0.5f, -0.5f, 0.5f));
mWireCubeVertices.AddVertex(CVector3f( 0.5f, 0.5f, 0.5f)); mWireCubeVertices->AddVertex(CVector3f( 0.5f, -0.5f, 0.5f));
mWireCubeVertices.AddVertex(CVector3f(-0.5f, 0.5f, 0.5f)); mWireCubeVertices->AddVertex(CVector3f( 0.5f, 0.5f, 0.5f));
mWireCubeVertices->AddVertex(CVector3f(-0.5f, 0.5f, 0.5f));
uint16 Indices[] = { uint16 Indices[] = {
0, 1, 0, 1,
@ -585,6 +589,10 @@ void CDrawUtil::Shutdown()
if (mDrawUtilInitialized) if (mDrawUtilInitialized)
{ {
debugf("Shutting down"); debugf("Shutting down");
mGridVertices = std::nullopt;
mSquareVertices = std::nullopt;
mLineVertices = std::nullopt;
mWireCubeVertices = std::nullopt;
delete mpColorShader; delete mpColorShader;
delete mpColorShaderLighting; delete mpColorShaderLighting;
delete mpTextureShader; delete mpTextureShader;

View File

@ -4,9 +4,11 @@
#include "Core/OpenGL/CVertexBuffer.h" #include "Core/OpenGL/CVertexBuffer.h"
#include "Core/OpenGL/CDynamicVertexBuffer.h" #include "Core/OpenGL/CDynamicVertexBuffer.h"
#include "Core/OpenGL/CIndexBuffer.h" #include "Core/OpenGL/CIndexBuffer.h"
#include "Core/Resource/model/CModel.h" #include "Core/Resource/Model/CModel.h"
#include "Core/Resource/CLight.h" #include "Core/Resource/CLight.h"
#include <optional>
/** /**
* @todo there are a LOT of problems with how this is implemented; trying to * @todo there are a LOT of problems with how this is implemented; trying to
* use CDrawUtil in a lot of places in the codebase just plain doesn't work * use CDrawUtil in a lot of places in the codebase just plain doesn't work
@ -17,22 +19,22 @@
class CDrawUtil class CDrawUtil
{ {
// 7x7 Grid // 7x7 Grid
static CVertexBuffer mGridVertices; static std::optional<CVertexBuffer> mGridVertices;
static CIndexBuffer mGridIndices; static CIndexBuffer mGridIndices;
// Square // Square
static CDynamicVertexBuffer mSquareVertices; static std::optional<CDynamicVertexBuffer> mSquareVertices;
static CIndexBuffer mSquareIndices; static CIndexBuffer mSquareIndices;
// Line // Line
static CDynamicVertexBuffer mLineVertices; static std::optional<CDynamicVertexBuffer> mLineVertices;
static CIndexBuffer mLineIndices; static CIndexBuffer mLineIndices;
// Cube // Cube
static TResPtr<CModel> mpCubeModel; static TResPtr<CModel> mpCubeModel;
// Wire Cube // Wire Cube
static CVertexBuffer mWireCubeVertices; static std::optional<CVertexBuffer> mWireCubeVertices;
static CIndexBuffer mWireCubeIndices; static CIndexBuffer mWireCubeIndices;
// Sphere // Sphere

View File

@ -26,9 +26,9 @@ const CColor CGraphics::skDefaultAmbientColor = CColor(0.5f, 0.5f, 0.5f, 1.f);
CColor CGraphics::sAreaAmbientColor = CColor::skBlack; CColor CGraphics::sAreaAmbientColor = CColor::skBlack;
float CGraphics::sWorldLightMultiplier; float CGraphics::sWorldLightMultiplier;
CLight CGraphics::sDefaultDirectionalLights[3] = { CLight CGraphics::sDefaultDirectionalLights[3] = {
*CLight::BuildDirectional(CVector3f(0), CVector3f (0.f, -0.866025f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f)), CLight::BuildDirectional(CVector3f(0), CVector3f (0.f, -0.866025f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f)),
*CLight::BuildDirectional(CVector3f(0), CVector3f(-0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f)), CLight::BuildDirectional(CVector3f(0), CVector3f(-0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f)),
*CLight::BuildDirectional(CVector3f(0), CVector3f( 0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f)) CLight::BuildDirectional(CVector3f(0), CVector3f( 0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 1.f))
}; };
// ************ FUNCTIONS ************ // ************ FUNCTIONS ************

View File

@ -2,6 +2,8 @@
#include <Common/Math/CTransform4f.h> #include <Common/Math/CTransform4f.h>
#include <Common/Math/MathUtil.h> #include <Common/Math/MathUtil.h>
#include <cfloat>
CAnimation::CAnimation(CResourceEntry *pEntry /*= 0*/) CAnimation::CAnimation(CResourceEntry *pEntry /*= 0*/)
: CResource(pEntry) : CResource(pEntry)
, mDuration(0.f) , mDuration(0.f)

View File

@ -5,6 +5,8 @@
#include <Common/Macros.h> #include <Common/Macros.h>
#include <Common/Math/MathUtil.h> #include <Common/Math/MathUtil.h>
#include <cfloat>
// ************ CBone ************ // ************ CBone ************
CBone::CBone(CSkeleton *pSkel) CBone::CBone(CSkeleton *pSkel)
: mpSkeleton(pSkel) : mpSkeleton(pSkel)

View File

@ -21,10 +21,6 @@ CGameArea::~CGameArea()
for (uint32 iSCLY = 0; iSCLY < mScriptLayers.size(); iSCLY++) for (uint32 iSCLY = 0; iSCLY < mScriptLayers.size(); iSCLY++)
delete mScriptLayers[iSCLY]; delete mScriptLayers[iSCLY];
for (uint32 iLyr = 0; iLyr < mLightLayers.size(); iLyr++)
for (uint32 iLight = 0; iLight < mLightLayers[iLyr].size(); iLight++)
delete mLightLayers[iLyr][iLight];
} }
CDependencyTree* CGameArea::BuildDependencyTree() const CDependencyTree* CGameArea::BuildDependencyTree() const

View File

@ -53,7 +53,7 @@ class CGameArea : public CResource
// Collision // Collision
std::unique_ptr<CCollisionMeshGroup> mpCollision; std::unique_ptr<CCollisionMeshGroup> mpCollision;
// Lights // Lights
std::vector<std::vector<CLight*>> mLightLayers; std::vector<std::vector<CLight>> mLightLayers;
// Path Mesh // Path Mesh
CAssetID mPathID; CAssetID mPathID;
// Portal Area // Portal Area
@ -98,7 +98,7 @@ public:
inline CScriptLayer* ScriptLayer(uint32 Index) const { return mScriptLayers[Index]; } inline CScriptLayer* ScriptLayer(uint32 Index) const { return mScriptLayers[Index]; }
inline uint32 NumLightLayers() const { return mLightLayers.size(); } inline uint32 NumLightLayers() const { return mLightLayers.size(); }
inline uint32 NumLights(uint32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); } inline uint32 NumLights(uint32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); }
inline CLight* Light(uint32 LayerIndex, uint32 LightIndex) const { return mLightLayers[LayerIndex][LightIndex]; } inline CLight* Light(uint32 LayerIndex, uint32 LightIndex) { return &mLightLayers[LayerIndex][LightIndex]; }
inline CAssetID PathID() const { return mPathID; } inline CAssetID PathID() const { return mPathID; }
inline CPoiToWorld* PoiToWorldMap() const { return mpPoiToWorldMap; } inline CPoiToWorld* PoiToWorldMap() const { return mpPoiToWorldMap; }
inline CAssetID PortalAreaID() const { return mPortalAreaID; } inline CAssetID PortalAreaID() const { return mPortalAreaID; }

View File

@ -3,7 +3,7 @@
#include "Core/Render/CDrawUtil.h" #include "Core/Render/CDrawUtil.h"
#include "Core/Render/CRenderer.h" #include "Core/Render/CRenderer.h"
CDynamicVertexBuffer CFont::smGlyphVertices; std::optional<CDynamicVertexBuffer> CFont::smGlyphVertices;
CIndexBuffer CFont::smGlyphIndices; CIndexBuffer CFont::smGlyphIndices;
bool CFont::smBuffersInitialized = false; bool CFont::smBuffersInitialized = false;
@ -43,7 +43,7 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
GLuint ColorLoc = pTextShader->GetUniformLocation("FontColor"); GLuint ColorLoc = pTextShader->GetUniformLocation("FontColor");
GLuint LayerLoc = pTextShader->GetUniformLocation("RGBALayer"); GLuint LayerLoc = pTextShader->GetUniformLocation("RGBALayer");
mpFontTexture->Bind(0); mpFontTexture->Bind(0);
smGlyphVertices.Bind(); smGlyphVertices->Bind();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
// Initialize some more stuff before we start the character loop // Initialize some more stuff before we start the character loop
@ -116,7 +116,7 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
// Load shader uniforms, buffer texture // Load shader uniforms, buffer texture
glUniformMatrix4fv(ModelMtxLoc, 1, GL_FALSE, (GLfloat*) &GlyphTransform); glUniformMatrix4fv(ModelMtxLoc, 1, GL_FALSE, (GLfloat*) &GlyphTransform);
smGlyphVertices.BufferAttrib(EVertexAttribute::Tex0, &pGlyph->TexCoords); smGlyphVertices->BufferAttrib(EVertexAttribute::Tex0, &pGlyph->TexCoords);
// Draw fill // Draw fill
glUniform1i(LayerLoc, GlyphLayer); glUniform1i(LayerLoc, GlyphLayer);
@ -148,8 +148,9 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
void CFont::InitBuffers() void CFont::InitBuffers()
{ {
smGlyphVertices.SetActiveAttribs(EVertexAttribute::Position | EVertexAttribute::Tex0); smGlyphVertices.emplace();
smGlyphVertices.SetVertexCount(4); smGlyphVertices->SetActiveAttribs(EVertexAttribute::Position | EVertexAttribute::Tex0);
smGlyphVertices->SetVertexCount(4);
CVector3f Vertices[4] = { CVector3f Vertices[4] = {
CVector3f( 0.f, 0.f, 0.f), CVector3f( 0.f, 0.f, 0.f),
@ -157,7 +158,7 @@ void CFont::InitBuffers()
CVector3f( 0.f, -2.f, 0.f), CVector3f( 0.f, -2.f, 0.f),
CVector3f( 2.f, -2.f, 0.f) CVector3f( 2.f, -2.f, 0.f)
}; };
smGlyphVertices.BufferAttrib(EVertexAttribute::Position, Vertices); smGlyphVertices->BufferAttrib(EVertexAttribute::Position, Vertices);
CVector2f TexCoords[4] = { CVector2f TexCoords[4] = {
CVector2f(0.f, 0.f), CVector2f(0.f, 0.f),
@ -165,7 +166,7 @@ void CFont::InitBuffers()
CVector2f(0.f, 1.f), CVector2f(0.f, 1.f),
CVector2f(1.f, 1.f) CVector2f(1.f, 1.f)
}; };
smGlyphVertices.BufferAttrib(EVertexAttribute::Tex0, TexCoords); smGlyphVertices->BufferAttrib(EVertexAttribute::Tex0, TexCoords);
smGlyphIndices.Reserve(4); smGlyphIndices.Reserve(4);
smGlyphIndices.AddIndex(0); smGlyphIndices.AddIndex(0);
@ -176,3 +177,12 @@ void CFont::InitBuffers()
smBuffersInitialized = true; smBuffersInitialized = true;
} }
void CFont::ShutdownBuffers()
{
if (smBuffersInitialized)
{
smGlyphVertices = std::nullopt;
smBuffersInitialized = false;
}
}

View File

@ -9,6 +9,7 @@
#include "Core/OpenGL/CIndexBuffer.h" #include "Core/OpenGL/CIndexBuffer.h"
#include <Common/BasicTypes.h> #include <Common/BasicTypes.h>
#include <optional>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -20,9 +21,9 @@ class CFont : public CResource
{ {
DECLARE_RESOURCE_TYPE(Font) DECLARE_RESOURCE_TYPE(Font)
friend class CFontLoader; friend class CFontLoader;
static CDynamicVertexBuffer smGlyphVertices; // This is the vertex buffer used to draw glyphs. It has two attributes - Pos and Tex0. Tex0 should be updated for each glyph. static std::optional<CDynamicVertexBuffer> smGlyphVertices; // This is the vertex buffer used to draw glyphs. It has two attributes - Pos and Tex0. Tex0 should be updated for each glyph.
static CIndexBuffer smGlyphIndices; // This is the index buffer used to draw glyphs. It uses a triangle strip. static CIndexBuffer smGlyphIndices; // This is the index buffer used to draw glyphs. It uses a triangle strip.
static bool smBuffersInitialized; // This bool indicates whether the vertex/index buffer have been initialized. Checked at the start of RenderString(). static bool smBuffersInitialized; // This bool indicates whether the vertex/index buffer have been initialized. Checked at the start of RenderString().
uint32 mUnknown; // Value at offset 0x8. Not sure what this is. Including for experimentation purposes. uint32 mUnknown; // Value at offset 0x8. Not sure what this is. Including for experimentation purposes.
uint32 mLineHeight; // Height of each line, in points uint32 mLineHeight; // Height of each line, in points
@ -70,7 +71,8 @@ public:
inline TString FontName() const { return mFontName; } inline TString FontName() const { return mFontName; }
inline CTexture* Texture() const { return mpFontTexture; } inline CTexture* Texture() const { return mpFontTexture; }
private: private:
void InitBuffers(); static void InitBuffers();
static void ShutdownBuffers();
}; };
#endif // CFONT_H #endif // CFONT_H

View File

@ -216,56 +216,56 @@ void CLight::Load() const
} }
// ************ STATIC ************ // ************ STATIC ************
CLight* CLight::BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor) CLight CLight::BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor)
{ {
CLight *pLight = new CLight; CLight pLight;
pLight->mType = ELightType::LocalAmbient; pLight.mType = ELightType::LocalAmbient;
pLight->mPosition = rkPosition; pLight.mPosition = rkPosition;
pLight->mDirection = skDefaultLightDir; pLight.mDirection = skDefaultLightDir;
pLight->mColor = rkColor; pLight.mColor = rkColor;
pLight->mSpotCutoff = 0.f; pLight.mSpotCutoff = 0.f;
return pLight; return pLight;
} }
CLight* CLight::BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor) CLight CLight::BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor)
{ {
CLight *pLight = new CLight; CLight pLight;
pLight->mType = ELightType::Directional; pLight.mType = ELightType::Directional;
pLight->mPosition = rkPosition; pLight.mPosition = rkPosition;
pLight->mDirection = rkDirection; pLight.mDirection = rkDirection;
pLight->mColor = rkColor; pLight.mColor = rkColor;
pLight->mSpotCutoff = 0.f; pLight.mSpotCutoff = 0.f;
return pLight; return pLight;
} }
CLight* CLight::BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff) CLight CLight::BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff)
{ {
CLight *pLight = new CLight; CLight pLight;
pLight->mType = ELightType::Spot; pLight.mType = ELightType::Spot;
pLight->mPosition = rkPosition; pLight.mPosition = rkPosition;
pLight->mDirection = -rkDirection.Normalized(); pLight.mDirection = -rkDirection.Normalized();
pLight->mColor = rkColor; pLight.mColor = rkColor;
pLight->mSpotCutoff = Cutoff * 0.5f; pLight.mSpotCutoff = Cutoff * 0.5f;
pLight->mAngleAttenCoefficients = pLight->CalculateSpotAngleAtten(); pLight.mAngleAttenCoefficients = pLight.CalculateSpotAngleAtten();
return pLight; return pLight;
} }
CLight* CLight::BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, CLight CLight::BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
float DistAttenA, float DistAttenB, float DistAttenC, float DistAttenA, float DistAttenB, float DistAttenC,
float AngleAttenA, float AngleAttenB, float AngleAttenC) float AngleAttenA, float AngleAttenB, float AngleAttenC)
{ {
CLight *pLight = new CLight; CLight pLight;
pLight->mType = ELightType::Custom; pLight.mType = ELightType::Custom;
pLight->mPosition = rkPosition; pLight.mPosition = rkPosition;
pLight->mDirection = rkDirection; pLight.mDirection = rkDirection;
pLight->mColor = rkColor; pLight.mColor = rkColor;
pLight->mSpotCutoff = 0.f; pLight.mSpotCutoff = 0.f;
pLight->mDistAttenCoefficients.X = DistAttenA; pLight.mDistAttenCoefficients.X = DistAttenA;
pLight->mDistAttenCoefficients.Y = DistAttenB; pLight.mDistAttenCoefficients.Y = DistAttenB;
pLight->mDistAttenCoefficients.Z = DistAttenC; pLight.mDistAttenCoefficients.Z = DistAttenC;
pLight->mAngleAttenCoefficients.X = AngleAttenA; pLight.mAngleAttenCoefficients.X = AngleAttenA;
pLight->mAngleAttenCoefficients.Y = AngleAttenB; pLight.mAngleAttenCoefficients.Y = AngleAttenB;
pLight->mAngleAttenCoefficients.Z = AngleAttenC * AngleAttenC; pLight.mAngleAttenCoefficients.Z = AngleAttenC * AngleAttenC;
return pLight; return pLight;
} }

View File

@ -69,10 +69,10 @@ public:
void Load() const; void Load() const;
// Static // Static
static CLight* BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor); static CLight BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor);
static CLight* BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor); static CLight BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor);
static CLight* BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff); static CLight BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff);
static CLight* BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, static CLight BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
float DistAttenA, float DistAttenB, float DistAttenC, float DistAttenA, float DistAttenB, float DistAttenC,
float AngleAttenA, float AngleAttenB, float AngleAttenC); float AngleAttenA, float AngleAttenB, float AngleAttenC);

View File

@ -40,11 +40,13 @@ class CMaterial
friend class CMaterialLoader; friend class CMaterialLoader;
friend class CMaterialCooker; friend class CMaterialCooker;
public:
enum class EShaderStatus enum class EShaderStatus
{ {
NoShader, ShaderExists, ShaderFailed NoShader, ShaderExists, ShaderFailed
}; };
private:
// Statics // Statics
static uint64 sCurrentMaterial; // The hash for the currently bound material static uint64 sCurrentMaterial; // The hash for the currently bound material
static CColor sCurrentTint; // The tint for the currently bound material static CColor sCurrentTint; // The tint for the currently bound material

View File

@ -2,7 +2,7 @@
#include <Common/Macros.h> #include <Common/Macros.h>
#include <algorithm> #include <algorithm>
std::unordered_map<EResourceType, CResTypeInfo*> CResTypeInfo::smTypeMap; std::unordered_map<EResourceType, std::unique_ptr<CResTypeInfo>> CResTypeInfo::smTypeMap;
CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension) CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension)
: mType(Type) : mType(Type)
@ -15,7 +15,7 @@ CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const
#if !PUBLIC_RELEASE #if !PUBLIC_RELEASE
ASSERT(smTypeMap.find(Type) == smTypeMap.end()); ASSERT(smTypeMap.find(Type) == smTypeMap.end());
#endif #endif
smTypeMap[Type] = this; smTypeMap[Type] = std::unique_ptr<CResTypeInfo>(this);
} }
bool CResTypeInfo::IsInGame(EGame Game) const bool CResTypeInfo::IsInGame(EGame Game) const
@ -48,7 +48,7 @@ void CResTypeInfo::GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut)
{ {
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++) for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
{ {
CResTypeInfo *pType = Iter->second; CResTypeInfo *pType = Iter->second.get();
if (pType->IsInGame(Game)) if (pType->IsInGame(Game))
rOut.push_back(pType); rOut.push_back(pType);
@ -78,7 +78,7 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
// Not cached - do a slow lookup // Not cached - do a slow lookup
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++) for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
{ {
CResTypeInfo *pType = Iter->second; CResTypeInfo *pType = Iter->second.get();
if (pType->CookedExtension(Game) == Ext) if (pType->CookedExtension(Game) == Ext)
{ {
@ -98,6 +98,12 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
return nullptr; return nullptr;
} }
CResTypeInfo* CResTypeInfo::FindTypeInfo(EResourceType Type)
{
auto Iter = smTypeMap.find(Type);
return (Iter == smTypeMap.end() ? nullptr : Iter->second.get());
}
// ************ SERIALIZATION ************ // ************ SERIALIZATION ************
void Serialize(IArchive& rArc, CResTypeInfo*& rpType) void Serialize(IArchive& rArc, CResTypeInfo*& rpType)
{ {

View File

@ -25,11 +25,12 @@ class CResTypeInfo
bool mCanHaveDependencies; bool mCanHaveDependencies;
bool mCanBeCreated; bool mCanBeCreated;
static std::unordered_map<EResourceType, CResTypeInfo*> smTypeMap; static std::unordered_map<EResourceType, std::unique_ptr<CResTypeInfo>> smTypeMap;
// Private Methods // Private Methods
CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension); CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension);
~CResTypeInfo() {} ~CResTypeInfo() = default;
friend class std::default_delete<CResTypeInfo>;
// Public Methods // Public Methods
public: public:
@ -47,11 +48,7 @@ public:
static void GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut); static void GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut);
static CResTypeInfo* TypeForCookedExtension(EGame, CFourCC Ext); static CResTypeInfo* TypeForCookedExtension(EGame, CFourCC Ext);
inline static CResTypeInfo* FindTypeInfo(EResourceType Type) static CResTypeInfo* FindTypeInfo(EResourceType Type);
{
auto Iter = smTypeMap.find(Type);
return (Iter == smTypeMap.end() ? nullptr : Iter->second);
}
private: private:
// Creation // Creation

View File

@ -1,4 +1,5 @@
#include "CTexture.h" #include "CTexture.h"
#include <cmath>
CTexture::CTexture(CResourceEntry *pEntry /*= 0*/) CTexture::CTexture(CResourceEntry *pEntry /*= 0*/)
: CResource(pEntry) : CResource(pEntry)
@ -143,7 +144,7 @@ float CTexture::ReadTexelAlpha(const CVector2f& rkTexCoord)
// todo: support texel formats other than DXT1 // todo: support texel formats other than DXT1
// DXT1 is definitely the most complicated one anyway; try reusing CTextureDecoder functions for other formats // DXT1 is definitely the most complicated one anyway; try reusing CTextureDecoder functions for other formats
uint32 TexelX = (uint32) ((mWidth - 1) * rkTexCoord.X); uint32 TexelX = (uint32) ((mWidth - 1) * rkTexCoord.X);
uint32 TexelY = (uint32) ((mHeight - 1) * (1.f - fmodf(rkTexCoord.Y, 1.f))); uint32 TexelY = (uint32) ((mHeight - 1) * (1.f - std::fmod(rkTexCoord.Y, 1.f)));
if (mTexelFormat == ETexelFormat::DXT1 && mBufferExists) if (mTexelFormat == ETexelFormat::DXT1 && mBufferExists)
{ {

View File

@ -1,5 +1,6 @@
#include "CCollisionRenderData.h" #include "CCollisionRenderData.h"
#include <Core/Render/CDrawUtil.h> #include <Core/Render/CDrawUtil.h>
#include <algorithm>
/** Build from collision data */ /** Build from collision data */
void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData) void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData)

View File

@ -99,6 +99,7 @@ enum class EUVAnimMode
ConvolutedModeA = 0x7, ConvolutedModeA = 0x7,
ConvolutedModeB = 0x8, ConvolutedModeB = 0x8,
SimpleMode = 0xA, SimpleMode = 0xA,
Eleven = 0xB,
NoUVAnim = -1 NoUVAnim = -1
}; };

View File

@ -8,6 +8,7 @@
#include <Common/CFourCC.h> #include <Common/CFourCC.h>
#include <cfloat>
#include <iostream> #include <iostream>
CAreaLoader::CAreaLoader() CAreaLoader::CAreaLoader()
@ -151,7 +152,7 @@ void CAreaLoader::ReadSCLYPrime()
CFourCC SCGN = mpMREA->ReadFourCC(); CFourCC SCGN = mpMREA->ReadFourCC();
if (SCGN != FOURCC('SCGN')) if (SCGN != FOURCC('SCGN'))
errorf("%s [0x%X]: Invalid SCGN magic: %s", *mpMREA->GetSourceString(), mpMREA->Tell() - 4, SCGN.ToString()); errorf("%s [0x%X]: Invalid SCGN magic: %s", *mpMREA->GetSourceString(), mpMREA->Tell() - 4, *SCGN.ToString());
else else
{ {
@ -191,7 +192,7 @@ void CAreaLoader::ReadLightsPrime()
mpMREA->Seek(0x4, SEEK_CUR); mpMREA->Seek(0x4, SEEK_CUR);
// Relevant data is read - now we process and form a CLight out of it // Relevant data is read - now we process and form a CLight out of it
CLight *pLight; CLight pLight;
CColor LightColor = CColor(Color.X, Color.Y, Color.Z, 0.f); CColor LightColor = CColor(Color.X, Color.Y, Color.Z, 0.f);
if (Multiplier < FLT_EPSILON) if (Multiplier < FLT_EPSILON)
@ -225,7 +226,7 @@ void CAreaLoader::ReadLightsPrime()
float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f; float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f;
float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f; float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f;
float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f;
pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); pLight.SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
} }
// Custom // Custom
@ -240,7 +241,7 @@ void CAreaLoader::ReadLightsPrime()
1.f, 0.f, 0.f); 1.f, 0.f, 0.f);
} }
pLight->SetLayer(iLyr); pLight.SetLayer(iLyr);
mpArea->mLightLayers[iLyr][iLight] = pLight; mpArea->mLightLayers[iLyr][iLight] = pLight;
} }
} }
@ -493,7 +494,7 @@ void CAreaLoader::ReadLightsCorruption()
mpMREA->Seek(0x18, SEEK_CUR); mpMREA->Seek(0x18, SEEK_CUR);
// Relevant data is read - now we process and form a CLight out of it // Relevant data is read - now we process and form a CLight out of it
CLight *pLight; CLight pLight;
if (Multiplier < FLT_EPSILON) if (Multiplier < FLT_EPSILON)
Multiplier = FLT_EPSILON; Multiplier = FLT_EPSILON;
@ -518,7 +519,7 @@ void CAreaLoader::ReadLightsCorruption()
float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f; float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f;
float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f; float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f;
float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f; float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f;
pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC); pLight.SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
} }
// Custom // Custom
@ -533,7 +534,7 @@ void CAreaLoader::ReadLightsCorruption()
1.f, 0.f, 0.f); 1.f, 0.f, 0.f);
} }
pLight->SetLayer(iLayer); pLight.SetLayer(iLayer);
mpArea->mLightLayers[iLayer][iLight] = pLight; mpArea->mLightLayers[iLayer][iLight] = pLight;
} }
} }

View File

@ -379,28 +379,28 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
switch (pPass->mAnimMode) switch (pPass->mAnimMode)
{ {
case 3: // Rotation case EUVAnimMode::UVRotation: // Rotation
case 7: // ??? case EUVAnimMode::ConvolutedModeA: // ???
pPass->mAnimParams[0] = mpFile->ReadFloat(); pPass->mAnimParams[0] = mpFile->ReadFloat();
pPass->mAnimParams[1] = mpFile->ReadFloat(); pPass->mAnimParams[1] = mpFile->ReadFloat();
break; break;
case 2: // UV Scroll case EUVAnimMode::UVScroll: // UV Scroll
case 4: // U Scroll case EUVAnimMode::HFilmstrip: // U Scroll
case 5: // V Scroll case EUVAnimMode::VFilmstrip: // V Scroll
pPass->mAnimParams[0] = mpFile->ReadFloat(); pPass->mAnimParams[0] = mpFile->ReadFloat();
pPass->mAnimParams[1] = mpFile->ReadFloat(); pPass->mAnimParams[1] = mpFile->ReadFloat();
pPass->mAnimParams[2] = mpFile->ReadFloat(); pPass->mAnimParams[2] = mpFile->ReadFloat();
pPass->mAnimParams[3] = mpFile->ReadFloat(); pPass->mAnimParams[3] = mpFile->ReadFloat();
break; break;
case 0: // Inverse ModelView Matrix case EUVAnimMode::InverseMV: // Inverse ModelView Matrix
case 1: // Inverse ModelView Matrix Translated case EUVAnimMode::InverseMVTranslated: // Inverse ModelView Matrix Translated
case 6: // Model Matrix case EUVAnimMode::ModelMatrix: // Model Matrix
case 10: // Yet-to-be-named case EUVAnimMode::SimpleMode: // Yet-to-be-named
break; break;
// Unknown/unsupported animation type // Unknown/unsupported animation type
case 8: case EUVAnimMode::ConvolutedModeB:
case 11: case EUVAnimMode::Eleven:
break; break;
default: default:
errorf("%s [0x%X]: Unsupported animation mode encountered: %d", *mpFile->GetSourceString(), mpFile->Tell() - 8, pPass->mAnimMode); errorf("%s [0x%X]: Unsupported animation mode encountered: %d", *mpFile->GetSourceString(), mpFile->Tell() - 8, pPass->mAnimMode);

View File

@ -111,19 +111,6 @@ EGame CScriptTemplate::Game() const
return mpGame->Game(); return mpGame->Game();
} }
// ************ PROPERTY FETCHING ************
template<class PropType>
PropType* TFetchProperty(CStructProperty* pProperties, const TIDString& rkID)
{
if (rkID.IsEmpty()) return nullptr;
IProperty *pProp = pProperties->ChildByIDString(rkID);
if (pProp && (pProp->Type() == PropEnum))
return static_cast<PropType*>(pProp)->ValuePtr();
else
return nullptr;
}
EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj) EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
{ {
if (pObj->Template() != this) if (pObj->Template() != this)

View File

@ -52,7 +52,6 @@ public:
ScaleEnabled, ScaleDisabled, ScaleVolume ScaleEnabled, ScaleDisabled, ScaleVolume
}; };
private:
struct SEditorAsset struct SEditorAsset
{ {
enum class EAssetType { enum class EAssetType {
@ -75,6 +74,7 @@ private:
} }
}; };
private:
std::vector<TString> mModules; std::vector<TString> mModules;
std::unique_ptr<CStructProperty> mpProperties; std::unique_ptr<CStructProperty> mpProperties;
std::vector<SEditorAsset> mAssets; std::vector<SEditorAsset> mAssets;

View File

@ -5,7 +5,7 @@ namespace NGameList
{ {
/** Path for the templates directory */ /** Path for the templates directory */
const TString gkTemplatesDir = "../templates/"; const TString gkTemplatesDir = "templates/";
/** Path to the game list file */ /** Path to the game list file */
const TString gkGameListPath = gkTemplatesDir + "GameList.xml"; const TString gkGameListPath = gkTemplatesDir + "GameList.xml";
@ -33,7 +33,7 @@ struct SGameInfo
} }
} }
}; };
SGameInfo gGameList[EGame::Max]; SGameInfo gGameList[int(EGame::Max)];
/** Whether the game list has been loaded */ /** Whether the game list has been loaded */
bool gLoadedGameList = false; bool gLoadedGameList = false;
@ -88,7 +88,7 @@ void LoadGameList()
ASSERT(!gLoadedGameList); ASSERT(!gLoadedGameList);
debugf("Loading game list"); debugf("Loading game list");
CXMLReader Reader(gkGameListPath); CXMLReader Reader(gDataDir + gkGameListPath);
ASSERT(Reader.IsValid()); ASSERT(Reader.IsValid());
SerializeGameList(Reader); SerializeGameList(Reader);
@ -101,7 +101,7 @@ void SaveGameList()
ASSERT(gLoadedGameList); ASSERT(gLoadedGameList);
debugf("Saving game list"); debugf("Saving game list");
CXMLWriter Writer(gkGameListPath, "GameList"); CXMLWriter Writer(gDataDir + gkGameListPath, "GameList");
ASSERT(Writer.IsValid()); ASSERT(Writer.IsValid());
SerializeGameList(Writer); SerializeGameList(Writer);
@ -151,7 +151,7 @@ CGameTemplate* GetGameTemplate(EGame Game)
// Load the game template, if it hasn't been loaded yet. // Load the game template, if it hasn't been loaded yet.
if (!GameInfo.pTemplate && !GameInfo.Name.IsEmpty()) if (!GameInfo.pTemplate && !GameInfo.Name.IsEmpty())
{ {
TString GamePath = gkTemplatesDir + GameInfo.TemplatePath; TString GamePath = gDataDir + gkTemplatesDir + GameInfo.TemplatePath;
GameInfo.pTemplate = std::make_unique<CGameTemplate>(); GameInfo.pTemplate = std::make_unique<CGameTemplate>();
GameInfo.pTemplate->Load(GamePath); GameInfo.pTemplate->Load(GamePath);
} }

View File

@ -8,8 +8,8 @@ namespace NPropertyMap
{ {
/** Path to the property map file */ /** Path to the property map file */
const char* gpkLegacyMapPath = "../templates/PropertyMapLegacy.xml"; const char* gpkLegacyMapPath = "templates/PropertyMapLegacy.xml";
const char* gpkMapPath = "../templates/PropertyMap.xml"; const char* gpkMapPath = "templates/PropertyMap.xml";
/** Whether to do name lookups from the legacy map */ /** Whether to do name lookups from the legacy map */
const bool gkUseLegacyMapForNameLookups = false; const bool gkUseLegacyMapForNameLookups = false;
@ -150,13 +150,13 @@ void LoadMap()
if ( gkUseLegacyMapForNameLookups ) if ( gkUseLegacyMapForNameLookups )
{ {
CXMLReader Reader(gpkLegacyMapPath); CXMLReader Reader(gDataDir + gpkLegacyMapPath);
ASSERT(Reader.IsValid()); ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay); Reader << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay);
} }
else else
{ {
CXMLReader Reader(gpkMapPath); CXMLReader Reader(gDataDir + gpkMapPath);
ASSERT(Reader.IsValid()); ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay); Reader << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
@ -198,7 +198,7 @@ void SaveMap(bool Force /*= false*/)
{ {
if( gkUseLegacyMapForUpdates ) if( gkUseLegacyMapForUpdates )
{ {
CXMLWriter Writer(gpkLegacyMapPath, "PropertyMap"); CXMLWriter Writer(gDataDir + gpkLegacyMapPath, "PropertyMap");
ASSERT(Writer.IsValid()); ASSERT(Writer.IsValid());
Writer << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay); Writer << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay);
} }
@ -219,7 +219,7 @@ void SaveMap(bool Force /*= false*/)
} }
// Perform the actual save // Perform the actual save
CXMLWriter Writer(gpkMapPath, "PropertyMap"); CXMLWriter Writer(gDataDir + gpkMapPath, "PropertyMap");
ASSERT(Writer.IsValid()); ASSERT(Writer.IsValid());
Writer << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay); Writer << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
} }

View File

@ -11,7 +11,7 @@ class CAssetProperty : public TSerializeableTypedProperty<CAssetID, EPropertyTyp
CResTypeFilter mTypeFilter; CResTypeFilter mTypeFilter;
protected: protected:
CAssetProperty::CAssetProperty(EGame Game) CAssetProperty(EGame Game)
: TSerializeableTypedProperty(Game) : TSerializeableTypedProperty(Game)
{ {
mDefaultValue = CAssetID::InvalidID( mGame ); mDefaultValue = CAssetID::InvalidID( mGame );

View File

@ -13,6 +13,7 @@
template<EPropertyType TypeEnum> template<EPropertyType TypeEnum>
class TEnumPropertyBase : public TSerializeableTypedProperty<int32, TypeEnum> class TEnumPropertyBase : public TSerializeableTypedProperty<int32, TypeEnum>
{ {
using base = TSerializeableTypedProperty<int32, TypeEnum>;
friend class IProperty; friend class IProperty;
struct SEnumValue struct SEnumValue
@ -47,17 +48,17 @@ class TEnumPropertyBase : public TSerializeableTypedProperty<int32, TypeEnum>
protected: protected:
/** Constructor */ /** Constructor */
TEnumPropertyBase(EGame Game) TEnumPropertyBase(EGame Game)
: TSerializeableTypedProperty(Game) : base(Game)
, mOverrideTypeName(false) , mOverrideTypeName(false)
{} {}
public: public:
virtual const char* HashableTypeName() const virtual const char* HashableTypeName() const
{ {
if (mpArchetype) if (base::mpArchetype)
return mpArchetype->HashableTypeName(); return base::mpArchetype->HashableTypeName();
else if (mOverrideTypeName) else if (mOverrideTypeName)
return *mName; return *base::mName;
else if (TypeEnum == EPropertyType::Enum) else if (TypeEnum == EPropertyType::Enum)
return "enum"; return "enum";
else else
@ -67,15 +68,15 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
// Skip TSerializeableTypedProperty, serialize default value ourselves so we can set SH_HexDisplay // Skip TSerializeableTypedProperty, serialize default value ourselves so we can set SH_HexDisplay
TTypedProperty::Serialize(rArc); TTypedProperty<int32, TypeEnum>::Serialize(rArc);
// Serialize default value // Serialize default value
TEnumPropertyBase* pArchetype = static_cast<TEnumPropertyBase*>(mpArchetype); TEnumPropertyBase* pArchetype = static_cast<TEnumPropertyBase*>(base::mpArchetype);
uint32 DefaultValueFlags = SH_Optional | (TypeEnum == EPropertyType::Enum ? SH_HexDisplay : 0); uint32 DefaultValueFlags = SH_Optional | (TypeEnum == EPropertyType::Enum ? SH_HexDisplay : 0);
rArc << SerialParameter("DefaultValue", mDefaultValue, DefaultValueFlags, pArchetype ? pArchetype->mDefaultValue : 0); rArc << SerialParameter("DefaultValue", base::mDefaultValue, DefaultValueFlags, pArchetype ? pArchetype->mDefaultValue : 0);
// Only serialize type name override for root archetypes. // Only serialize type name override for root archetypes.
if (!mpArchetype) if (!base::mpArchetype)
{ {
rArc << SerialParameter("OverrideTypeName", mOverrideTypeName, SH_Optional, false); rArc << SerialParameter("OverrideTypeName", mOverrideTypeName, SH_Optional, false);
} }
@ -88,19 +89,19 @@ public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (uint32&) ValueRef(pData), 0 ); Arc.SerializePrimitive( (uint32&) base::ValueRef(pData), 0 );
} }
virtual void InitFromArchetype(IProperty* pOther) virtual void InitFromArchetype(IProperty* pOther)
{ {
TTypedProperty::InitFromArchetype(pOther); base::InitFromArchetype(pOther);
TEnumPropertyBase* pOtherEnum = static_cast<TEnumPropertyBase*>(pOther); TEnumPropertyBase* pOtherEnum = static_cast<TEnumPropertyBase*>(pOther);
mValues = pOtherEnum->mValues; mValues = pOtherEnum->mValues;
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const
{ {
return TString::FromInt32( Value(pData), 0, 10 ); return TString::FromInt32( base::Value(pData), 0, 10 );
} }
void AddValue(TString ValueName, uint32 ValueID) void AddValue(TString ValueName, uint32 ValueID)
@ -137,21 +138,21 @@ public:
bool HasValidValue(void* pPropertyData) bool HasValidValue(void* pPropertyData)
{ {
if (mValues.empty()) return true; if (mValues.empty()) return true;
int ID = ValueRef(pPropertyData); int ID = base::ValueRef(pPropertyData);
uint32 Index = ValueIndex(ID); uint32 Index = ValueIndex(ID);
return Index >= 0 && Index < mValues.size(); return Index >= 0 && Index < mValues.size();
} }
bool OverridesTypeName() const bool OverridesTypeName() const
{ {
return mpArchetype ? TPropCast<TEnumPropertyBase>(mpArchetype)->OverridesTypeName() : mOverrideTypeName; return base::mpArchetype ? TPropCast<TEnumPropertyBase>(base::mpArchetype)->OverridesTypeName() : mOverrideTypeName;
} }
void SetOverrideTypeName(bool Override) void SetOverrideTypeName(bool Override)
{ {
if (mpArchetype) if (base::mpArchetype)
{ {
TEnumPropertyBase* pArchetype = TPropCast<TEnumPropertyBase>(RootArchetype()); TEnumPropertyBase* pArchetype = TPropCast<TEnumPropertyBase>(base::RootArchetype());
pArchetype->SetOverrideTypeName(Override); pArchetype->SetOverrideTypeName(Override);
} }
else else
@ -159,7 +160,7 @@ public:
if (mOverrideTypeName != Override) if (mOverrideTypeName != Override)
{ {
mOverrideTypeName = Override; mOverrideTypeName = Override;
MarkDirty(); base::MarkDirty();
} }
} }
} }

View File

@ -22,7 +22,7 @@ void CPropertyNameGenerator::Warmup()
mWords.clear(); mWords.clear();
// Load the word list from the file // Load the word list from the file
FILE* pListFile = fopen("../resources/WordList.txt", "r"); FILE* pListFile = fopen(*(gDataDir + "resources/WordList.txt"), "r");
ASSERT(pListFile); ASSERT(pListFile);
while (!feof(pListFile)) while (!feof(pListFile))

View File

@ -10,6 +10,8 @@
#include "Core/Resource/Script/NGameList.h" #include "Core/Resource/Script/NGameList.h"
#include "Core/Resource/Script/NPropertyMap.h" #include "Core/Resource/Script/NPropertyMap.h"
#include <cfloat>
/** IProperty */ /** IProperty */
IProperty::IProperty(EGame Game) IProperty::IProperty(EGame Game)
: mpParent( nullptr ) : mpParent( nullptr )
@ -311,7 +313,7 @@ TString IProperty::GetTemplateFileName()
pTemplateRoot = pTemplateRoot->RootParent(); pTemplateRoot = pTemplateRoot->RootParent();
// Now that we have the base property of our template, we can return the file path. // Now that we have the base property of our template, we can return the file path.
static const uint32 kChopAmount = strlen("../templates/"); static const uint32 kChopAmount = strlen(*(gDataDir + "templates/"));
if (pTemplateRoot->ScriptTemplate()) if (pTemplateRoot->ScriptTemplate())
{ {

View File

@ -419,29 +419,30 @@ public:
template<typename PropType, EPropertyType PropEnum> template<typename PropType, EPropertyType PropEnum>
class TSerializeableTypedProperty : public TTypedProperty<PropType, PropEnum> class TSerializeableTypedProperty : public TTypedProperty<PropType, PropEnum>
{ {
using base = TTypedProperty<PropType, PropEnum>;
protected: protected:
TSerializeableTypedProperty(EGame Game) TSerializeableTypedProperty(EGame Game)
: TTypedProperty(Game) : base(Game)
{} {}
public: public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedProperty::Serialize(rArc); base::Serialize(rArc);
TSerializeableTypedProperty* pArchetype = static_cast<TSerializeableTypedProperty*>(mpArchetype); TSerializeableTypedProperty* pArchetype = static_cast<TSerializeableTypedProperty*>(base::mpArchetype);
// Determine if default value should be serialized as optional. // Determine if default value should be serialized as optional.
// All MP1 properties should be optional. For MP2 and on, we set optional // All MP1 properties should be optional. For MP2 and on, we set optional
// on property types that don't have default values in the game executable. // on property types that don't have default values in the game executable.
bool MakeOptional = false; bool MakeOptional = false;
if (Game() <= EGame::Prime || pArchetype != nullptr) if (base::Game() <= EGame::Prime || pArchetype != nullptr)
{ {
MakeOptional = true; MakeOptional = true;
} }
else else
{ {
switch (Type()) switch (base::Type())
{ {
case EPropertyType::String: case EPropertyType::String:
case EPropertyType::Asset: case EPropertyType::Asset:
@ -457,17 +458,18 @@ public:
// Branch here to avoid constructing a default value if we don't need to. // Branch here to avoid constructing a default value if we don't need to.
if (MakeOptional) if (MakeOptional)
rArc << SerialParameter("DefaultValue", mDefaultValue, SH_Optional, pArchetype ? pArchetype->mDefaultValue : GetSerializationDefaultValue()); rArc << SerialParameter("DefaultValue", base::mDefaultValue, SH_Optional,
pArchetype ? pArchetype->mDefaultValue : GetSerializationDefaultValue());
else else
rArc << SerialParameter("DefaultValue", mDefaultValue); rArc << SerialParameter("DefaultValue", base::mDefaultValue);
} }
virtual bool ShouldSerialize() const virtual bool ShouldSerialize() const
{ {
TTypedProperty* pArchetype = static_cast<TTypedProperty*>(mpArchetype); base* pArchetype = static_cast<base*>(base::mpArchetype);
return TTypedProperty::ShouldSerialize() || return base::ShouldSerialize() ||
!(mDefaultValue == pArchetype->DefaultValue()); !(base::mDefaultValue == pArchetype->DefaultValue());
} }
/** Return default value for serialization - can be customized per type */ /** Return default value for serialization - can be customized per type */
@ -480,6 +482,7 @@ public:
template<typename PropType, EPropertyType PropEnum> template<typename PropType, EPropertyType PropEnum>
class TNumericalProperty : public TSerializeableTypedProperty<PropType, PropEnum> class TNumericalProperty : public TSerializeableTypedProperty<PropType, PropEnum>
{ {
using base = TSerializeableTypedProperty<PropType, PropEnum>;
friend class IProperty; friend class IProperty;
friend class CTemplateLoader; friend class CTemplateLoader;
@ -488,7 +491,7 @@ protected:
PropType mMaxValue; PropType mMaxValue;
TNumericalProperty(EGame Game) TNumericalProperty(EGame Game)
: TSerializeableTypedProperty(Game) : base(Game)
, mMinValue( -1 ) , mMinValue( -1 )
, mMaxValue( -1 ) , mMaxValue( -1 )
{} {}
@ -496,8 +499,8 @@ protected:
public: public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TSerializeableTypedProperty::Serialize(rArc); base::Serialize(rArc);
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(mpArchetype); TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
rArc << SerialParameter("Min", mMinValue, SH_Optional, pArchetype ? pArchetype->mMinValue : (PropType) -1) rArc << SerialParameter("Min", mMinValue, SH_Optional, pArchetype ? pArchetype->mMinValue : (PropType) -1)
<< SerialParameter("Max", mMaxValue, SH_Optional, pArchetype ? pArchetype->mMaxValue : (PropType) -1); << SerialParameter("Max", mMaxValue, SH_Optional, pArchetype ? pArchetype->mMaxValue : (PropType) -1);
@ -505,15 +508,15 @@ public:
virtual bool ShouldSerialize() const virtual bool ShouldSerialize() const
{ {
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(mpArchetype); TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
return TSerializeableTypedProperty::ShouldSerialize() || return base::ShouldSerialize() ||
mMinValue != pArchetype->mMinValue || mMinValue != pArchetype->mMinValue ||
mMaxValue != pArchetype->mMaxValue; mMaxValue != pArchetype->mMaxValue;
} }
virtual void InitFromArchetype(IProperty* pOther) virtual void InitFromArchetype(IProperty* pOther)
{ {
TSerializeableTypedProperty::InitFromArchetype(pOther); base::InitFromArchetype(pOther);
TNumericalProperty* pCastOther = static_cast<TNumericalProperty*>(pOther); TNumericalProperty* pCastOther = static_cast<TNumericalProperty*>(pOther);
mMinValue = pCastOther->mMinValue; mMinValue = pCastOther->mMinValue;
mMaxValue = pCastOther->mMaxValue; mMaxValue = pCastOther->mMaxValue;
@ -521,11 +524,11 @@ public:
virtual void PropertyValueChanged(void* pPropertyData) virtual void PropertyValueChanged(void* pPropertyData)
{ {
TSerializeableTypedProperty::PropertyValueChanged(pPropertyData); base::PropertyValueChanged(pPropertyData);
if (mMinValue >= 0 && mMaxValue >= 0) if (mMinValue >= 0 && mMaxValue >= 0)
{ {
PropType& rValue = ValueRef(pPropertyData); PropType& rValue = base::ValueRef(pPropertyData);
rValue = Math::Clamp(mMinValue, mMaxValue, rValue); rValue = Math::Clamp(mMinValue, mMaxValue, rValue);
} }
} }

View File

@ -23,7 +23,7 @@
#include "CVectorProperty.h" #include "CVectorProperty.h"
/** TPropertyRef: Embeds a reference to a property on a specific object */ /** TPropertyRef: Embeds a reference to a property on a specific object */
template<class PropertyClass, typename ValueType = PropertyClass::ValueType> template<class PropertyClass, typename ValueType = typename PropertyClass::ValueType>
class TPropertyRef class TPropertyRef
{ {
/** Property data being referenced */ /** Property data being referenced */
@ -96,17 +96,18 @@ typedef TPropertyRef<CArrayProperty> CArrayRef;
template<typename ValueType> template<typename ValueType>
class TEnumRef : public TPropertyRef<CEnumProperty, ValueType> class TEnumRef : public TPropertyRef<CEnumProperty, ValueType>
{ {
using base = TPropertyRef<CEnumProperty, ValueType>;
public: public:
TEnumRef() TEnumRef()
: TPropertyRef() : base()
{} {}
TEnumRef(void* pInData, IProperty* pInProperty) TEnumRef(void* pInData, IProperty* pInProperty)
: TPropertyRef(pInData, pInProperty) : base(pInData, pInProperty)
{} {}
TEnumRef(void* pInData, CEnumProperty* pInProperty) TEnumRef(void* pInData, CEnumProperty* pInProperty)
: TPropertyRef(pInData, pInProperty) : base(pInData, pInProperty)
{} {}
}; };

View File

@ -27,12 +27,12 @@ class CScriptNode : public CSceneNode
CLightParameters *mpLightParameters; CLightParameters *mpLightParameters;
public:
enum class EGameModeVisibility enum class EGameModeVisibility
{ {
Visible, NotVisible, Untested Visible, NotVisible, Untested
} mGameModeVisibility; } mGameModeVisibility;
public:
CScriptNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent = 0, CScriptObject *pObject = 0); CScriptNode(CScene *pScene, uint32 NodeID, CSceneNode *pParent = 0, CScriptObject *pObject = 0);
ENodeType NodeType(); ENodeType NodeType();
void PostLoad(); void PostLoad();

View File

@ -5,6 +5,7 @@
class CDamageableTriggerExtra : public CScriptExtra class CDamageableTriggerExtra : public CScriptExtra
{ {
public:
// Render fluid planes for doors in MP1 // Render fluid planes for doors in MP1
enum class ERenderSide enum class ERenderSide
{ {
@ -17,6 +18,7 @@ class CDamageableTriggerExtra : public CScriptExtra
Down = 0x20 Down = 0x20
}; };
private:
CVectorRef mPlaneSize; CVectorRef mPlaneSize;
TEnumRef<ERenderSide> mRenderSide; TEnumRef<ERenderSide> mRenderSide;
CAssetRef mTextureAssets[3]; CAssetRef mTextureAssets[3];

View File

@ -37,7 +37,6 @@ CEditorApplication::~CEditorApplication()
{ {
NDolphinIntegration::KillQuickplay(); NDolphinIntegration::KillQuickplay();
delete mpWorldEditor; delete mpWorldEditor;
delete mpProjectDialog;
} }
void CEditorApplication::InitEditor() void CEditorApplication::InitEditor()
@ -346,6 +345,7 @@ void CEditorApplication::OnEditorClose()
if (pEditor == mpWorldEditor) if (pEditor == mpWorldEditor)
{ {
mpWorldEditor->deleteLater();
mpWorldEditor = nullptr; mpWorldEditor = nullptr;
quit(); quit();
} }

View File

@ -33,7 +33,7 @@ CExportGameDialog::CExportGameDialog(const QString& rkIsoPath, const QString& rk
mpUI->setupUi(this); mpUI->setupUi(this);
// Set up disc // Set up disc
mpDisc = nod::OpenDiscFromImage(TO_WCHAR(rkIsoPath)).release(); mpDisc = nod::OpenDiscFromImage(QStringToNodString(rkIsoPath)).release();
if (ValidateGame()) if (ValidateGame())
{ {

View File

@ -226,7 +226,7 @@ void CGeneratePropertyNamesDialog::OnTreeItemDoubleClicked(QTreeWidgetItem* pIte
if (Text.endsWith(".xml")) if (Text.endsWith(".xml"))
{ {
TString TStrText = TO_TSTRING(Text); TString TStrText = TO_TSTRING(Text);
TString DirPath = "../templates/" + TStrText.GetFileDirectory(); TString DirPath = gDataDir + "templates/" + TStrText.GetFileDirectory();
TString AbsPath = FileUtil::MakeAbsolute(DirPath) + TStrText.GetFileName(); TString AbsPath = FileUtil::MakeAbsolute(DirPath) + TStrText.GetFileName();
UICommon::OpenInExternalApplication( TO_QSTRING(AbsPath) ); UICommon::OpenInExternalApplication( TO_QSTRING(AbsPath) );
} }

View File

@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
# TODO: These should be drive by CI if CI ever becomes a thing for PWE.
set(PWE_APP_NAME "Prime World Editor")
# obtain revision info from git # obtain revision info from git
find_package(Git) find_package(Git)
if(GIT_FOUND) if(GIT_FOUND)
@ -49,6 +52,7 @@ project(pwe_editor LANGUAGES CXX VERSION ${PWE_VERSION_STRING})
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
if (WIN32) if (WIN32)
set(QT_PLATFORM_COMPONENTS WinExtras) set(QT_PLATFORM_COMPONENTS WinExtras)
@ -56,10 +60,6 @@ if (WIN32)
endif() endif()
find_package(Qt5 COMPONENTS Core Widgets ${QT_PLATFORM_COMPONENTS} REQUIRED) find_package(Qt5 COMPONENTS Core Widgets ${QT_PLATFORM_COMPONENTS} REQUIRED)
find_package(assimp CONFIG REQUIRED)
# AssImp's cmake config is pretty awful. It doesn't include necesary libraries. Hopefully this can be fixed later.
find_library(IIRXML_LIBRARY NAMES IrrXMLd IrrXML)
file(GLOB_RECURSE source_files file(GLOB_RECURSE source_files
"*.cpp" "*.cpp"
@ -67,9 +67,39 @@ file(GLOB_RECURSE source_files
"*.hpp" "*.hpp"
) )
add_executable(pwe_editor ${source_files}) string(TIMESTAMP CURRENT_YEAR "%Y")
set_target_properties(pwe_editor PROPERTIES OUTPUT_NAME PrimeWorldEditor DEBUG_POSTFIX -debug) if (WIN32)
generate_product_version(rc_file NAME ${PWE_APP_NAME}
ICON ${CMAKE_CURRENT_SOURCE_DIR}/icons/win/AppIcon.ico
VERSION_MAJOR ${pwe_editor_VERSION_MAJOR} VERSION_MINOR ${pwe_editor_VERSION_MINOR}
VERSION_PATCH ${pwe_editor_VERSION_PATCH} VERSION_REVISION ${pwe_editor_VERSION_TWEAK}
COMPANY_NAME "Aruki" COMMENTS "${PWE_APP_NAME} ${PWE_WC_DESCRIBE}"
ORIGINAL_FILENAME "PrimeWorldEditor")
set(PLAT_SRCS ${rc_file} icons/win/PrimeWorldEditor.manifest)
elseif (APPLE)
set_source_files_properties(icons/mac/mainicon.icns PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
configure_file(icons/mac/Info.plist.in "${CMAKE_CURRENT_BINARY_DIR}/Info.plist" @ONLY)
file(GLOB_RECURSE RES_SOURCES ${CMAKE_SOURCE_DIR}/resources/* ${CMAKE_SOURCE_DIR}/templates/*)
foreach(src ${RES_SOURCES})
file(RELATIVE_PATH relsrc ${CMAKE_SOURCE_DIR} ${src})
get_filename_component(reldir ${relsrc} DIRECTORY)
set_source_files_properties(${src} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/${reldir})
endforeach()
set(PLAT_SRCS icons/mac/mainicon.icns ${RES_SOURCES})
else()
configure_file(icons/freedesktop/metainfo/PrimeWorldEditor.appdata.xml.in
"${CMAKE_CURRENT_BINARY_DIR}/PrimeWorldEditor.appdata.xml" @ONLY)
#install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PrimeWorldEditor.appdata.xml" DESTINATION share/metainfo)
install(DIRECTORY icons/freedesktop/applications icons/freedesktop/icons DESTINATION share)
endif()
add_executable(pwe_editor MACOSX_BUNDLE ${source_files} Icons.qrc ${PLAT_SRCS})
set_target_properties(pwe_editor PROPERTIES OUTPUT_NAME PrimeWorldEditor DEBUG_POSTFIX -debug
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist"
MACOSX_BUNDLE_BUNDLE_NAME "PrimeWorldEditor")
target_compile_features(pwe_editor PRIVATE cxx_std_17) target_compile_features(pwe_editor PRIVATE cxx_std_17)
@ -78,12 +108,8 @@ target_link_libraries(
pwe_core pwe_core
Qt5::Widgets Qt5::Widgets
${QT_PLATFORM_COMPONENTS_LIBS} ${QT_PLATFORM_COMPONENTS_LIBS}
${IIRXML_LIBRARY}
) )
# TODO: These should be drive by CI if CI ever becomes a thing for PWE.
set(PWE_APP_NAME "Prime World Editor")
target_compile_definitions( target_compile_definitions(
pwe_editor pwe_editor
PRIVATE PRIVATE
@ -102,11 +128,42 @@ if (WIN32)
message(FATAL_ERROR "Unable to find windeployqt") message(FATAL_ERROR "Unable to find windeployqt")
endif() endif()
# run windeployqt to gather necessary .dlls # run windeployqt to gather necessary qt libraries and plugins
add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${WINDEPLOYQT_PROGRAM} ARGS add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${WINDEPLOYQT_PROGRAM} ARGS
--no-angle --no-opengl-sw $<TARGET_FILE:pwe_editor>) --no-angle --no-opengl-sw $<TARGET_FILE:pwe_editor>)
# copy bin directory of dew prefix # copy bin directory of dew prefix
add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory
"${DEW_CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE_DIR:pwe_editor>) "${DEW_CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE_DIR:pwe_editor>)
elseif (APPLE)
find_program(MACDEPLOYQT_PROGRAM macdeployqt PATHS $ENV{QTDIR}/bin/)
if(MACDEPLOYQT_PROGRAM)
message(STATUS "Found ${MACDEPLOYQT_PROGRAM}")
else()
message(FATAL_ERROR "Unable to find macdeployqt")
endif()
# run macdeployqt to gather necessary qt libraries and plugins
add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${MACDEPLOYQT_PROGRAM} ARGS $<TARGET_FILE:pwe_editor>)
else()
target_compile_definitions(
pwe_editor
PRIVATE
"PWE_DATADIR=\"${CMAKE_INSTALL_PREFIX}/share/PrimeWorldEditor\""
)
install(TARGETS pwe_editor)
set(USER_PERMISSIONS DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/resources" DESTINATION share/PrimeWorldEditor ${USER_PERMISSIONS})
install(DIRECTORY "${CMAKE_SOURCE_DIR}/templates" DESTINATION share/PrimeWorldEditor ${USER_PERMISSIONS})
endif()
if (NOT APPLE)
add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory
"${CMAKE_SOURCE_DIR}/resources" "${CMAKE_BINARY_DIR}/resources")
add_custom_command(TARGET pwe_editor POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory
"${CMAKE_SOURCE_DIR}/templates" "${CMAKE_BINARY_DIR}/templates")
endif() endif()

View File

@ -165,7 +165,7 @@ void CProjectSettingsDialog::BuildISO()
// Verify this ISO matches the original // Verify this ISO matches the original
bool IsWii; bool IsWii;
pBaseDisc = nod::OpenDiscFromImage(TO_WCHAR(SourceIsoPath), IsWii); pBaseDisc = nod::OpenDiscFromImage(QStringToNodString(SourceIsoPath), IsWii);
if (!pBaseDisc || !IsWii) if (!pBaseDisc || !IsWii)
{ {

View File

@ -25,7 +25,8 @@ CSceneViewport::CSceneViewport(QWidget *pParent)
mpRenderer = new CRenderer(); mpRenderer = new CRenderer();
mpRenderer->SetClearColor(CColor::skBlack); mpRenderer->SetClearColor(CColor::skBlack);
mpRenderer->SetViewportSize(width(), height()); qreal pixelRatio = devicePixelRatioF();
mpRenderer->SetViewportSize(width() * pixelRatio, height() * pixelRatio);
mViewInfo.pScene = mpScene; mViewInfo.pScene = mpScene;
mViewInfo.pRenderer = mpRenderer; mViewInfo.pRenderer = mpRenderer;
@ -207,7 +208,7 @@ void CSceneViewport::CreateContextMenu()
mpPlayFromHereSeparator = new QAction(this); mpPlayFromHereSeparator = new QAction(this);
mpPlayFromHereSeparator->setSeparator(true); mpPlayFromHereSeparator->setSeparator(true);
mpPlayFromHereAction = new QAction("Play from here"); mpPlayFromHereAction = new QAction("Play from here", this);
connect(mpPlayFromHereAction, SIGNAL(triggered()), this, SLOT(OnPlayFromHere())); connect(mpPlayFromHereAction, SIGNAL(triggered()), this, SLOT(OnPlayFromHere()));
QList<QAction*> Actions; QList<QAction*> Actions;
@ -395,7 +396,8 @@ void CSceneViewport::ContextMenu(QContextMenuEvent *pEvent)
void CSceneViewport::OnResize() void CSceneViewport::OnResize()
{ {
mpRenderer->SetViewportSize(width(), height()); qreal pixelRatio = devicePixelRatioF();
mpRenderer->SetViewportSize(width() * pixelRatio, height() * pixelRatio);
} }
void CSceneViewport::OnMouseClick(QMouseEvent *pEvent) void CSceneViewport::OnMouseClick(QMouseEvent *pEvent)

View File

@ -66,6 +66,8 @@ CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget*
SET_WINDOWTITLE_APPVARS(WindowTitle); SET_WINDOWTITLE_APPVARS(WindowTitle);
} }
CCollisionEditor::~CCollisionEditor() {}
CCollisionEditorViewport* CCollisionEditor::Viewport() const CCollisionEditorViewport* CCollisionEditor::Viewport() const
{ {
return mpUI->Viewport; return mpUI->Viewport;

View File

@ -28,6 +28,7 @@ class CCollisionEditor : public IEditor
public: public:
/** Constructor/destructor */ /** Constructor/destructor */
explicit CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent = 0); explicit CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent = 0);
virtual ~CCollisionEditor();
virtual CCollisionEditorViewport* Viewport() const override; virtual CCollisionEditorViewport* Viewport() const override;
public slots: public slots:

View File

@ -27,7 +27,7 @@
<file>icons/SelectMode.png</file> <file>icons/SelectMode.png</file>
<file>icons/POI Important.png</file> <file>icons/POI Important.png</file>
<file>icons/POI Normal.png</file> <file>icons/POI Normal.png</file>
<file>icons/AppIcon.ico</file> <file>icons/win/AppIcon.ico</file>
<file>icons/New.png</file> <file>icons/New.png</file>
<file>icons/Open.png</file> <file>icons/Open.png</file>
<file>icons/Redo.png</file> <file>icons/Redo.png</file>

View File

@ -6,10 +6,10 @@
#include <Common/TString.h> #include <Common/TString.h>
#include <Core/Render/CDrawUtil.h> #include <Core/Render/CDrawUtil.h>
#include <Core/Render/CRenderer.h> #include <Core/Render/CRenderer.h>
#include <Core/Resource/cooker/CTextureEncoder.h> #include <Core/Resource/Cooker/CTextureEncoder.h>
#include <Core/Resource/factory/CModelLoader.h> #include <Core/Resource/Factory/CModelLoader.h>
#include <Core/Resource/factory/CMaterialLoader.h> #include <Core/Resource/Factory/CMaterialLoader.h>
#include <Core/Resource/factory/CTextureDecoder.h> #include <Core/Resource/Factory/CTextureDecoder.h>
#include <Core/Scene/CScene.h> #include <Core/Scene/CScene.h>
#include <iostream> #include <iostream>

View File

@ -56,7 +56,7 @@ EQuickplayLaunchResult LaunchQuickplay(QWidget* pParentWidget,
debugf("Launching quickplay..."); debugf("Launching quickplay...");
// Check if quickplay is supported for this project // Check if quickplay is supported for this project
TString QuickplayDir = "../resources/quickplay" / ::GetGameShortName(pProject->Game()); TString QuickplayDir = gDataDir + "resources/quickplay" / ::GetGameShortName(pProject->Game());
TString BuildString = "v" + TString::FromFloat(pProject->BuildVersion()); TString BuildString = "v" + TString::FromFloat(pProject->BuildVersion());
TString RelFile = QuickplayDir / BuildString + ".rel"; TString RelFile = QuickplayDir / BuildString + ".rel";
TString PatchFile = QuickplayDir / BuildString + ".bin"; TString PatchFile = QuickplayDir / BuildString + ".bin";
@ -203,7 +203,7 @@ EQuickplayLaunchResult LaunchQuickplay(QWidget* pParentWidget,
bool IsQuickplaySupported(CGameProject* pProject) bool IsQuickplaySupported(CGameProject* pProject)
{ {
// Quickplay is supported if there is a quickplay module & patch in the resources folder // Quickplay is supported if there is a quickplay module & patch in the resources folder
TString QuickplayDir = "../resources/quickplay" / ::GetGameShortName(pProject->Game()); TString QuickplayDir = gDataDir + "resources/quickplay" / ::GetGameShortName(pProject->Game());
TString BuildString = "v" + TString::FromFloat(pProject->BuildVersion()); TString BuildString = "v" + TString::FromFloat(pProject->BuildVersion());
TString RelFile = QuickplayDir / BuildString + ".rel"; TString RelFile = QuickplayDir / BuildString + ".rel";
TString PatchFile = QuickplayDir / BuildString + ".bin"; TString PatchFile = QuickplayDir / BuildString + ".bin";

View File

@ -989,7 +989,7 @@ void CResourceBrowser::ImportAssetNameMap()
void CResourceBrowser::ExportAssetNames() void CResourceBrowser::ExportAssetNames()
{ {
QString OutFile = UICommon::SaveFileDialog(this, "Export asset name map", "*.xml", "../resources/gameinfo/"); QString OutFile = UICommon::SaveFileDialog(this, "Export asset name map", "*.xml", *(gDataDir + "resources/gameinfo/"));
if (OutFile.isEmpty()) return; if (OutFile.isEmpty()) return;
TString OutFileStr = TO_TSTRING(OutFile); TString OutFileStr = TO_TSTRING(OutFile);

View File

@ -138,13 +138,13 @@ void CResourceTableContextMenu::OpenInExplorer()
if (mpClickedEntry) if (mpClickedEntry)
{ {
QString Path = TO_QSTRING( mpClickedEntry->CookedAssetPath() ); QString Path = TO_QSTRING( mpClickedEntry->CookedAssetPath() );
UICommon::OpenContainingFolder(Path); UICommon::OpenContainingFolder(nullptr, Path);
} }
else else
{ {
TString BasePath = mpBrowser->CurrentStore()->ResourcesDir(); TString BasePath = mpBrowser->CurrentStore()->ResourcesDir();
QString Path = TO_QSTRING( BasePath + mpClickedDirectory->FullPath() ); QString Path = TO_QSTRING( BasePath + mpClickedDirectory->FullPath() );
UICommon::OpenContainingFolder(Path); UICommon::OpenContainingFolder(nullptr, Path);
} }
} }

View File

@ -13,14 +13,48 @@ QWindow* FindWidgetWindowHandle(QWidget *pWidget)
return pWidget ? pWidget->windowHandle() : nullptr; return pWidget ? pWidget->windowHandle() : nullptr;
} }
void OpenContainingFolder(const QString& rkPath) void OpenContainingFolder(QWidget* parent, const QString& pathIn)
{ {
#if WIN32 const QFileInfo fileInfo(pathIn);
QStringList Args; // Mac, Windows support folder or file.
Args << "/select," << QDir::toNativeSeparators(rkPath); #if defined(Q_OS_WIN)
QProcess::startDetached("explorer", Args); QString paths = QProcessEnvironment::systemEnvironment().value(QStringLiteral("Path"));
QString explorer;
for (QString path : paths.split(QStringLiteral(";")))
{
QFileInfo finfo(QDir(path), QStringLiteral("explorer.exe"));
if (finfo.exists())
{
explorer = finfo.filePath();
break;
}
}
if (explorer.isEmpty())
{
QMessageBox::warning(parent, MainWindow::tr("Launching Windows Explorer Failed"),
MainWindow::tr("Could not find explorer.exe in path to launch Windows Explorer."));
return;
}
QStringList param;
if (!fileInfo.isDir())
param += QLatin1String("/select,");
param += QDir::toNativeSeparators(fileInfo.canonicalFilePath());
QProcess::startDetached(explorer, param);
#elif defined(Q_OS_MAC)
QStringList scriptArgs;
scriptArgs << QLatin1String("-e")
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
.arg(fileInfo.canonicalFilePath());
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
scriptArgs.clear();
scriptArgs << QLatin1String("-e") << QLatin1String("tell application \"Finder\" to activate");
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
#else #else
#error OpenContainingFolder() not implemented! // we cannot select a file here, because no file browser really supports it...
const QString folder = fileInfo.isDir() ? fileInfo.absoluteFilePath() : fileInfo.filePath();
QProcess browserProc;
const QString browserArgs = QStringLiteral("xdg-open \"%1\"").arg(QFileInfo(folder).path());
browserProc.startDetached(browserArgs);
#endif #endif
} }

View File

@ -38,12 +38,20 @@
//@todo This name isn't ideal, too similar to ToWChar and so might cause confusion //@todo This name isn't ideal, too similar to ToWChar and so might cause confusion
#define TO_WCHAR(Str) ToWChar( UICommon::ToT16String(Str) ) #define TO_WCHAR(Str) ToWChar( UICommon::ToT16String(Str) )
#include <nod/Util.hpp>
#if NOD_UCS2
#define QStringToNodString(string) TO_WCHAR(string)
#else
#define QStringToNodString(string) string.toUtf8().data()
#endif
namespace UICommon namespace UICommon
{ {
// Utility // Utility
QWindow* FindWidgetWindowHandle(QWidget* pWidget); QWindow* FindWidgetWindowHandle(QWidget* pWidget);
void OpenContainingFolder(const QString& rkPath); void OpenContainingFolder(QWidget* parent, const QString& pathIn);
bool OpenInExternalApplication(const QString& rkPath); bool OpenInExternalApplication(const QString& rkPath);
// Searches the widget's ancestry tree to find an ancestor of type ObjectT. // Searches the widget's ancestry tree to find an ancestor of type ObjectT.

View File

@ -19,7 +19,7 @@ public:
explicit TEnumComboBox(QWidget* pParent = 0) explicit TEnumComboBox(QWidget* pParent = 0)
: QComboBox(pParent) : QComboBox(pParent)
{ {
for (TEnumReflection<EnumT>::CIterator It; It; ++It) for (typename TEnumReflection<EnumT>::CIterator It; It; ++It)
{ {
if (It.Value() != TEnumReflection<EnumT>::ErrorValue()) if (It.Value() != TEnumReflection<EnumT>::ErrorValue())
{ {

View File

@ -0,0 +1,9 @@
[Desktop Entry]
Name=Prime World Editor
GenericName=Game Data Editor
Comment=Edit world assets from games by Retro Studios
Exec=PrimeWorldEditor
Icon=PrimeWorldEditor
Terminal=false
Type=Application
Categories=Development;

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright @CURRENT_YEAR@ Aruki -->
<component type="desktop-application">
<id>com.Aruki.PrimeWorldEditor</id>
<metadata_license>FSFAP</metadata_license>
<project_license>MIT</project_license>
<name>Prime World Editor</name>
<summary>Edit world assets from games by Retro Studios</summary>
<launchable type="desktop-id">PrimeWorldEditor.desktop</launchable>
<url type="homepage">http://github.com/arukibree/PrimeWorldEditor</url>
<provides>
<binary>PrimeWorldEditor</binary>
</provides>
<releases>
<release version="@pwe_editor_VERSION@" />
</releases>
</component>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>PrimeWorldEditor</string>
<key>CFBundleGetInfoString</key>
<string>@METADATA_VERSION_STRING@</string>
<key>CFBundleShortVersionString</key>
<string>@METADATA_VERSION_STRING@</string>
<key>NSHumanReadableCopyright</key>
<string>@CURRENT_YEAR@ Aruki</string>
<key>CFBundleIconFile</key>
<string>mainicon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.aruki.PrimeWorldEditor</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>@PWE_APP_NAME@</string>
<key>CFBundleVersion</key>
<string>@METADATA_VERSION_STRING@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

View File

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<description>Prime World Editor</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View File

@ -23,6 +23,47 @@ void QtLogRedirect(QtMsgType Type, const QMessageLogContext& /*rkContext*/, cons
} }
} }
static TString LocateDataDirectory()
{
#if !defined(_WIN32) && !defined(__APPLE__)
#ifdef PWE_DATADIR
{
/* This is for build-configured root */
TString dir = FileUtil::MakeAbsolute(PWE_DATADIR);
debugf("Checking '%s' for resources", *dir);
if (FileUtil::IsDirectory(dir + "resources"))
return dir;
}
#endif
{
/* This is for locating appimage root */
TString dir = FileUtil::MakeAbsolute(TString(QCoreApplication::applicationDirPath().toUtf8().data()) + "/../share/PrimeWorldEditor");
debugf("Checking '%s' for resources", *dir);
if (FileUtil::IsDirectory(dir + "resources"))
return dir;
}
#endif
{
/* This is for locating build directory root */
TString dir = FileUtil::MakeAbsolute(TString(QCoreApplication::applicationDirPath().toUtf8().data()) + "/..");
debugf("Checking '%s' for resources", *dir);
if (FileUtil::IsDirectory(dir + "resources"))
return dir;
}
TString dir = FileUtil::MakeAbsolute("..");
warnf("Falling back to '%s' for resources", *dir);
return dir;
}
static TString LocateLogPath()
{
#ifndef _WIN32
return TString(getenv("HOME")) + "/.primeworldeditor.log";
#else
return "primeworldeditor.log";
#endif
}
class CMain class CMain
{ {
public: public:
@ -35,7 +76,7 @@ public:
App.setApplicationName( APP_NAME ); App.setApplicationName( APP_NAME );
App.setApplicationVersion( APP_VERSION ); App.setApplicationVersion( APP_VERSION );
App.setOrganizationName("Aruki"); App.setOrganizationName("Aruki");
App.setWindowIcon(QIcon(":/icons/AppIcon.ico")); App.setWindowIcon(QIcon(":/icons/win/AppIcon.ico"));
// Create UI relay // Create UI relay
CUIRelay UIRelay(&App); CUIRelay UIRelay(&App);
@ -46,12 +87,15 @@ public:
SetupPalette(); SetupPalette();
// Init log // Init log
bool Initialized = NLog::InitLog("primeworldeditor.log"); bool Initialized = NLog::InitLog(LocateLogPath());
if (!Initialized) UICommon::ErrorMsg(0, "Couldn't open log file. Logging will not work for this session."); if (!Initialized) UICommon::ErrorMsg(0, "Couldn't open log file. Logging will not work for this session.");
qInstallMessageHandler(QtLogRedirect); qInstallMessageHandler(QtLogRedirect);
// Locate data directory
gDataDir = LocateDataDirectory();
// Create editor resource store // Create editor resource store
gpEditorStore = new CResourceStore("../resources/"); gpEditorStore = new CResourceStore(gDataDir + "resources/");
if (!gpEditorStore->DatabasePathExists()) if (!gpEditorStore->DatabasePathExists())
{ {