feat(component): partially implement CCharacterComponent::LoadBaseVariation

This commit is contained in:
fallenoak 2025-10-17 22:46:17 -05:00
parent bdc76b2b79
commit 421accf989
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
4 changed files with 71 additions and 0 deletions

View File

@ -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 <storm/Memory.hpp>
#include <storm/String.hpp>
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() {

View File

@ -5,6 +5,7 @@
#include "gx/Texture.hpp"
#include <cstdint>
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();

View File

@ -0,0 +1,9 @@
#include "component/Texture.hpp"
CACHEENTRY* TextureCacheCreateTexture(const char* fileName) {
// TODO
}
void TextureCacheDestroyTexture(void* texture) {
// TODO
}

22
src/component/Texture.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef COMPONENT_TEXTURE_HPP
#define COMPONENT_TEXTURE_HPP
#include <storm/Hash.hpp>
class CAsyncObject;
class CACHEENTRY : public TSHashObject<CACHEENTRY, HASHKEY_NONE> {
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