feat(component): add BuildComponentArray

This commit is contained in:
fallenoak 2025-10-16 17:11:11 -05:00
parent 113a98c202
commit e8487187d8
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
5 changed files with 154 additions and 4 deletions

View File

@ -1,8 +1,12 @@
#include "component/CCharacterComponent.hpp" #include "component/CCharacterComponent.hpp"
#include "component/Util.hpp"
#include "db/Db.hpp"
#include "model/CM2Model.hpp" #include "model/CM2Model.hpp"
#include "object/Types.hpp"
#include <storm/Memory.hpp> #include <storm/Memory.hpp>
st_race* CCharacterComponent::s_chrVarArray; st_race* CCharacterComponent::s_chrVarArray;
uint32_t CCharacterComponent::s_chrVarArrayLength;
int32_t s_bInRenderPrep = 0; int32_t s_bInRenderPrep = 0;
@ -20,6 +24,18 @@ void CCharacterComponent::Initialize() {
void CCharacterComponent::Initialize(EGxTexFormat textureFormat, uint32_t textureLevel, int32_t thread, int32_t compress) { void CCharacterComponent::Initialize(EGxTexFormat textureFormat, uint32_t textureLevel, int32_t thread, int32_t compress) {
// TODO // TODO
CCharacterComponent::InitDbData();
// TODO
}
void CCharacterComponent::InitDbData() {
uint32_t varArrayLength = (g_chrRacesDB.m_maxID + 1) * UNITSEX_NUM_SEXES;
CCharacterComponent::s_chrVarArrayLength = varArrayLength;
BuildComponentArray(varArrayLength, &CCharacterComponent::s_chrVarArray);
// TODO CountFacialFeatures(varArrayLength, &CCharacterComponent::s_characterFacialHairStylesList);
} }
void CCharacterComponent::CreateBaseTexture() { void CCharacterComponent::CreateBaseTexture() {

View File

@ -49,11 +49,13 @@ class CCharacterComponent {
public: public:
// Static variables // Static variables
static st_race* s_chrVarArray; static st_race* s_chrVarArray;
static uint32_t s_chrVarArrayLength;
// Static functions // Static functions
static CCharacterComponent* AllocComponent(); static CCharacterComponent* AllocComponent();
static void Initialize(); static void Initialize();
static void Initialize(EGxTexFormat textureFormat, uint32_t textureLevel, int32_t thread, int32_t compress); static void Initialize(EGxTexFormat textureFormat, uint32_t textureLevel, int32_t thread, int32_t compress);
static void InitDbData();
// Member variables // Member variables
uint32_t m_flags = 0x1 | 0x2 | 0x4; uint32_t m_flags = 0x1 | 0x2 | 0x4;

129
src/component/Util.cpp Normal file
View File

@ -0,0 +1,129 @@
#include "component/Util.hpp"
#include "db/Db.hpp"
#include "object/Types.hpp"
#include <storm/Memory.hpp>
int32_t BuildComponentArray(uint32_t varArrayLength, st_race** varArrayPtr) {
if (!varArrayLength) {
return 0;
}
auto varArray = new (STORM_ALLOC(sizeof(st_race) * varArrayLength)) st_race[varArrayLength];
int32_t prevRaceID = g_charSectionsDB.GetNumRecords() > 0 ? g_charSectionsDB.GetRecordByIndex(0)->m_raceID : 4;
int32_t prevSexID = g_charSectionsDB.GetNumRecords() > 0 ? g_charSectionsDB.GetRecordByIndex(0)->m_sexID : 8;
int32_t prevBaseSection = g_charSectionsDB.GetNumRecords() > 0 ? g_charSectionsDB.GetRecordByIndex(0)->m_baseSection : 12;
int32_t prevVariationIndex = 0;
// Build sections
int32_t variationIndex = 0;
for (int32_t i = 0; i < g_charSectionsDB.GetNumRecords(); i++) {
auto sectionsRec = g_charSectionsDB.GetRecordByIndex(i);
if (sectionsRec->m_baseSection >= NUM_COMPONENT_VARIATIONS) {
continue;
}
auto sectionChange = prevRaceID != sectionsRec->m_raceID
|| prevSexID != sectionsRec->m_sexID
|| prevBaseSection != sectionsRec->m_baseSection;
auto lastRecord = i == g_charSectionsDB.GetNumRecords() - 1;
if (sectionChange || lastRecord) {
auto& section = varArray[(prevRaceID * UNITSEX_NUM_SEXES + prevSexID)].sections[prevBaseSection];
section.variationCount = variationIndex + 1;
if (section.variationCount > 0) {
section.variationArray = new (STORM_ALLOC(sizeof(st_variation) * section.variationCount)) st_variation[section.variationCount];
}
variationIndex = 0;
}
if (variationIndex <= sectionsRec->m_variationIndex) {
variationIndex = sectionsRec->m_variationIndex;
}
prevRaceID = sectionsRec->m_raceID;
prevSexID = sectionsRec->m_sexID;
prevBaseSection = sectionsRec->m_baseSection;
}
// Build variations
prevRaceID = 1;
prevSexID = 0;
prevBaseSection = 0;
prevVariationIndex = 0;
int32_t colorIndex = 0;
for (int32_t i = 0; i < g_charSectionsDB.GetNumRecords(); i++) {
auto sectionsRec = g_charSectionsDB.GetRecordByIndex(i);
if (sectionsRec->m_baseSection >= NUM_COMPONENT_VARIATIONS) {
continue;
}
auto sectionChange = prevRaceID != sectionsRec->m_raceID
|| prevSexID != sectionsRec->m_sexID
|| prevBaseSection != sectionsRec->m_baseSection
|| prevVariationIndex != sectionsRec->m_variationIndex;
auto lastRecord = i == g_charSectionsDB.GetNumRecords() - 1;
if (sectionChange || lastRecord) {
auto& section = varArray[(prevRaceID * UNITSEX_NUM_SEXES + prevSexID)].sections[prevBaseSection];
if (section.variationCount > 0) {
auto& variation = section.variationArray[prevVariationIndex];
variation.colorCount = colorIndex + 1;
if (variation.colorCount > 0) {
variation.colorArray = new (STORM_ALLOC(sizeof(st_color) * variation.colorCount)) st_color[variation.colorCount];
}
}
colorIndex = 0;
}
if (colorIndex <= sectionsRec->m_colorIndex) {
colorIndex = sectionsRec->m_colorIndex;
}
prevRaceID = sectionsRec->m_raceID;
prevSexID = sectionsRec->m_sexID;
prevBaseSection = sectionsRec->m_baseSection;
prevVariationIndex = sectionsRec->m_variationIndex;
}
// Build colors
for (int32_t i = 0; i < g_charSectionsDB.GetNumRecords(); i++) {
auto sectionsRec = g_charSectionsDB.GetRecordByIndex(i);
if (sectionsRec->m_baseSection >= NUM_COMPONENT_VARIATIONS) {
continue;
}
auto& section = varArray[(sectionsRec->m_raceID * UNITSEX_NUM_SEXES + sectionsRec->m_sexID)].sections[sectionsRec->m_baseSection];
if (section.variationCount > 0 && sectionsRec->m_variationIndex < section.variationCount) {
auto& variation = section.variationArray[sectionsRec->m_variationIndex];
if (variation.colorCount > 0 && sectionsRec->m_colorIndex < variation.colorCount) {
auto& color = variation.colorArray[sectionsRec->m_colorIndex];
color.rec = sectionsRec;
}
}
}
*varArrayPtr = varArray;
return 1;
}

View File

@ -26,4 +26,6 @@ struct st_variation {
st_color* colorArray = nullptr; st_color* colorArray = nullptr;
}; };
int32_t BuildComponentArray(uint32_t varArrayLength, st_race** varArrayPtr);
#endif #endif

View File

@ -2,11 +2,12 @@
#define OBJECT_TYPES_HPP #define OBJECT_TYPES_HPP
enum UNIT_SEX { enum UNIT_SEX {
UNITSEX_MALE = 0, UNITSEX_MALE = 0,
UNITSEX_FEMALE = 1, UNITSEX_FEMALE = 1,
UNITSEX_NONE = 2, UNITSEX_NUM_SEXES = 2,
UNITSEX_NONE = 2,
UNITSEX_LAST, UNITSEX_LAST,
UNITSEX_BOTH = 3, UNITSEX_BOTH = 3,
}; };
#endif #endif