From 8d90cd7e01de77ede288d752ba4e8de13f5bfe00 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sat, 8 Aug 2015 11:21:49 -0400 Subject: [PATCH] Material lookup by name + minor fixes --- Common/StringUtil.cpp | 2 +- Core/main.cpp | 14 ------------- PrimeWorldEditor.pro | 10 ++++++--- Resource/CMaterialSet.cpp | 7 +++++++ Resource/CMaterialSet.h | 1 + Resource/factory/CMaterialLoader.cpp | 31 ++++++++++++++-------------- Resource/factory/CMaterialLoader.h | 1 + Resource/factory/CModelLoader.h | 1 - Resource/model/CModel.h | 1 - 9 files changed, 33 insertions(+), 35 deletions(-) diff --git a/Common/StringUtil.cpp b/Common/StringUtil.cpp index b8b97543..c91d76c9 100644 --- a/Common/StringUtil.cpp +++ b/Common/StringUtil.cpp @@ -211,7 +211,7 @@ namespace StringUtil int CodePoint; // One byte - if ((cstr[0] & 0x80000000) == 0) + if ((cstr[0] & 0x80) == 0) { CodePoint = cstr[0] & 0x7FFFFFFF; cstr++; diff --git a/Core/main.cpp b/Core/main.cpp index b564c15b..ed346897 100644 --- a/Core/main.cpp +++ b/Core/main.cpp @@ -1,20 +1,8 @@ #include #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include #include -#include - -#include int main(int argc, char *argv[]) { @@ -24,8 +12,6 @@ int main(int argc, char *argv[]) w.show(); CTemplateLoader::LoadGameList(); - //CTexture *pTex = CTextureDecoder::LoadDDS(CFileInStream("E:/34f7c12211777ce8.dds", IOUtil::LittleEndian)); - //CTextureEncoder::EncodeTXTR(CFileOutStream("E:/Unpacked/Metroid Prime 3 Dolphin/Metroid4-pak/34f7c12211777ce8.TXTR", IOUtil::BigEndian), pTex); app.setStyle(new CDarkStyle); qApp->setStyle(QStyleFactory::create("Fusion")); diff --git a/PrimeWorldEditor.pro b/PrimeWorldEditor.pro index ab471801..6b011208 100644 --- a/PrimeWorldEditor.pro +++ b/PrimeWorldEditor.pro @@ -132,7 +132,8 @@ SOURCES += \ Resource/factory/CScanLoader.cpp \ UI/WStringPreviewPanel.cpp \ UI/WScanPreviewPanel.cpp \ - UI/WIntegralSpinBox.cpp + UI/WIntegralSpinBox.cpp \ + UI/CAboutDialog.cpp HEADERS += \ Common/AnimUtil.h \ @@ -278,7 +279,8 @@ HEADERS += \ Resource/factory/CScanLoader.h \ UI/WStringPreviewPanel.h \ UI/WScanPreviewPanel.h \ - UI/WIntegralSpinBox.h + UI/WIntegralSpinBox.h \ + UI/CAboutDialog.h FORMS += \ UI/CWorldEditorWindow.ui \ @@ -292,7 +294,8 @@ FORMS += \ UI/WorldEditor/WModifyTab.ui \ UI/WorldEditor/WInstancesTab.ui \ UI/WorldEditor/CLayerEditor.ui \ - UI/WScanPreviewPanel.ui + UI/WScanPreviewPanel.ui \ + UI/CAboutDialog.ui INCLUDEPATH += E:\C++\Libraries\glm\glm .\ @@ -338,3 +341,4 @@ DISTFILES += \ RESOURCES += \ Icons.qrc + diff --git a/Resource/CMaterialSet.cpp b/Resource/CMaterialSet.cpp index c524b7f3..f9c21dcf 100644 --- a/Resource/CMaterialSet.cpp +++ b/Resource/CMaterialSet.cpp @@ -40,3 +40,10 @@ CMaterial* CMaterialSet::MaterialByName(const std::string &name) if ((*it)->Name() == name) return *it; return nullptr; } + +u32 CMaterialSet::MaterialIndexByName(const std::string& name) +{ + for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) + if (mMaterials[iMat]->Name() == name) return iMat; + return -1; +} diff --git a/Resource/CMaterialSet.h b/Resource/CMaterialSet.h index 1313b9b0..1a3f59af 100644 --- a/Resource/CMaterialSet.h +++ b/Resource/CMaterialSet.h @@ -20,6 +20,7 @@ public: u32 NumMaterials(); CMaterial* MaterialByIndex(u32 index); CMaterial* MaterialByName(const std::string& name); + u32 MaterialIndexByName(const std::string& name); }; #endif // CMATERIALSET_H diff --git a/Resource/factory/CMaterialLoader.cpp b/Resource/factory/CMaterialLoader.cpp index 6485e998..8b58d872 100644 --- a/Resource/factory/CMaterialLoader.cpp +++ b/Resource/factory/CMaterialLoader.cpp @@ -15,21 +15,6 @@ CMaterialLoader::~CMaterialLoader() { } -CMaterialSet* CMaterialLoader::LoadMaterialSet(CInputStream& Mat, EGame Version) -{ - CMaterialLoader Loader; - Loader.mpSet = new CMaterialSet(); - Loader.mpFile = &Mat; - Loader.mVersion = Version; - - if ((Version >= ePrimeKioskDemo) && (Version <= eEchoes)) - Loader.ReadPrimeMatSet(); - else - Loader.ReadCorruptionMatSet(); - - return Loader.mpSet; -} - void CMaterialLoader::ReadPrimeMatSet() { // Textures @@ -590,3 +575,19 @@ void CMaterialLoader::CreateCorruptionPasses(CMaterial *pMat) } } } + +// ************ STATIC ************ +CMaterialSet* CMaterialLoader::LoadMaterialSet(CInputStream& Mat, EGame Version) +{ + CMaterialLoader Loader; + Loader.mpSet = new CMaterialSet(); + Loader.mpFile = &Mat; + Loader.mVersion = Version; + + if ((Version >= ePrimeKioskDemo) && (Version <= eEchoes)) + Loader.ReadPrimeMatSet(); + else + Loader.ReadCorruptionMatSet(); + + return Loader.mpSet; +} diff --git a/Resource/factory/CMaterialLoader.h b/Resource/factory/CMaterialLoader.h index 75d33d56..d8a1c5c6 100644 --- a/Resource/factory/CMaterialLoader.h +++ b/Resource/factory/CMaterialLoader.h @@ -32,6 +32,7 @@ class CMaterialLoader CMaterial* ReadCorruptionMaterial(); void CreateCorruptionPasses(CMaterial *pMat); + // Static public: static CMaterialSet* LoadMaterialSet(CInputStream& Mat, EGame Version); }; diff --git a/Resource/factory/CModelLoader.h b/Resource/factory/CModelLoader.h index 1b6e359e..15111a0e 100644 --- a/Resource/factory/CModelLoader.h +++ b/Resource/factory/CModelLoader.h @@ -1,7 +1,6 @@ #ifndef CMODELLOADER_H #define CMODELLOADER_H -#include "../model/SModelData.h" #include "../model/CBasicModel.h" #include "../model/CModel.h" #include "../EFormatVersion.h" diff --git a/Resource/model/CModel.h b/Resource/model/CModel.h index 8cc24a2a..f1689433 100644 --- a/Resource/model/CModel.h +++ b/Resource/model/CModel.h @@ -2,7 +2,6 @@ #define CMODEL_H #include "CBasicModel.h" -#include "SModelData.h" #include "SSurface.h" #include "../CMaterialSet.h"