diff --git a/src/component/CCharacterComponent.cpp b/src/component/CCharacterComponent.cpp index 3ede2c8..18f5c98 100644 --- a/src/component/CCharacterComponent.cpp +++ b/src/component/CCharacterComponent.cpp @@ -1,14 +1,20 @@ #include "component/CCharacterComponent.hpp" +#include "component/Texture.hpp" #include "component/Util.hpp" #include "db/Db.hpp" #include "model/CM2Model.hpp" #include "object/Types.hpp" #include +#include st_race* CCharacterComponent::s_chrVarArray; uint32_t CCharacterComponent::s_chrVarArrayLength; int32_t s_bInRenderPrep = 0; +char* s_pathEnd; +char s_path[STORM_MAX_PATH]; + +#define TEXTURE_INDEX(section, texture) (3 * section + texture) CCharacterComponent* CCharacterComponent::AllocComponent() { // TODO ObjectAlloc @@ -96,7 +102,38 @@ int32_t CCharacterComponent::ItemsLoaded(int32_t a2) { } void CCharacterComponent::LoadBaseVariation(COMPONENT_VARIATIONS sectionIndex, int32_t textureIndex, int32_t variationIndex, int32_t colorIndex, COMPONENT_SECTIONS section, const char* a7) { + int32_t index = TEXTURE_INDEX(sectionIndex, textureIndex); + + if (this->m_texture[index]) { + TextureCacheDestroyTexture(this->m_texture[index]); + } + + auto valid = ComponentValidateBase( + CCharacterComponent::s_chrVarArray, + this->m_data.raceID, + this->m_data.sexID, + sectionIndex, + variationIndex, + colorIndex + ); + if (!valid) { + return; + } + + auto sectionsRec = this->GetSectionsRecord(sectionIndex, variationIndex, colorIndex, nullptr); + + auto textureName = sectionsRec->m_textureName[textureIndex]; + + if (*textureName) { + SStrCopy(s_pathEnd, textureName); + this->m_texture[index] = TextureCacheCreateTexture(s_path); + } + + this->m_sections |= 1 << section; + // TODO + + this->m_flags &= ~0x8; } void CCharacterComponent::PrepSections() { diff --git a/src/component/CCharacterComponent.hpp b/src/component/CCharacterComponent.hpp index 480349e..3d8052b 100644 --- a/src/component/CCharacterComponent.hpp +++ b/src/component/CCharacterComponent.hpp @@ -5,6 +5,7 @@ #include "gx/Texture.hpp" #include +class CACHEENTRY; class CharSectionsRec; class CM2Model; @@ -60,8 +61,10 @@ class CCharacterComponent { // Member variables uint32_t m_flags = 0x1 | 0x2 | 0x4; + uint32_t m_sections = 0xFFFFFFFF; ComponentData m_data; HTEXTURE m_baseTexture = nullptr; + CACHEENTRY* m_texture[NUM_COMPONENT_VARIATIONS * 3] = {}; // Member functions void CreateBaseTexture(); diff --git a/src/component/Texture.cpp b/src/component/Texture.cpp new file mode 100644 index 0000000..7ccd561 --- /dev/null +++ b/src/component/Texture.cpp @@ -0,0 +1,9 @@ +#include "component/Texture.hpp" + +CACHEENTRY* TextureCacheCreateTexture(const char* fileName) { + // TODO +} + +void TextureCacheDestroyTexture(void* texture) { + // TODO +} diff --git a/src/component/Texture.hpp b/src/component/Texture.hpp new file mode 100644 index 0000000..b52ea55 --- /dev/null +++ b/src/component/Texture.hpp @@ -0,0 +1,22 @@ +#ifndef COMPONENT_TEXTURE_HPP +#define COMPONENT_TEXTURE_HPP + +#include + +class CAsyncObject; + +class CACHEENTRY : public TSHashObject { + public: + // Member variables + CAsyncObject* m_asyncObject = nullptr; + char m_fileName[128]; + uint32_t m_refCount = 0; + void* m_memHandle = nullptr; + +}; + +CACHEENTRY* TextureCacheCreateTexture(const char* fileName); + +void TextureCacheDestroyTexture(void* texture); + +#endif