Compare commits

...

2 Commits

7 changed files with 138 additions and 23 deletions

View File

@ -24,6 +24,21 @@ ComponentData::ComponentData() {
this->m_model = nullptr;
}
ComponentData::ComponentData(const CHARACTER_INFO& info) {
this->m_unkFlag &= 0xFFFFFFFC;
memset(&this->m_info, 0, sizeof(this->m_info));
this->m_model = nullptr;
this->m_info.raceID = info.raceID;
this->m_info.sexID = info.sexID;
this->m_info.classID = info.classID;
this->m_info.skinID = info.skinID;
this->m_info.faceID = info.faceID;
this->m_info.hairStyleID = info.hairStyleID;
this->m_info.hairColorID = info.hairColorID;
this->m_info.facialFeatureID = info.facialHairStyleID;
}
void CCharacterComponent::Initialize() {
CCharacterComponent::g_componentTextureLevelVar = CVar::Register(
"componentTextureLevel",

View File

@ -12,6 +12,7 @@ class CVar;
class ComponentData {
public:
ComponentData();
explicit ComponentData(const CHARACTER_INFO& info);
public:
CHARACTER_CREATE_INFO m_info;

View File

@ -8,6 +8,7 @@
#include "net/Connection.hpp"
#include "clientobject/Player_C.hpp"
#include "db/Db.hpp"
#include "glue/CCharacterComponent.hpp"
CSimpleModelFFX* CCharacterSelection::m_modelFrame = nullptr;
uint32_t CCharacterSelection::m_characterCount = 0;
@ -26,17 +27,20 @@ TSGrowableArray<CharacterSelectionDisplay> CCharacterSelection::s_characterList;
int32_t CCharacterSelection::m_selectionIndex = 0;
CharacterSelectionDisplay::CharacterSelectionDisplay()
: m_characterModel(nullptr) {
}
void CCharacterSelection::Initialize() {
// Empty method
}
void CCharacterSelection::RenderPrep() {
// TODO
auto index = CCharacterSelection::m_selectionIndex;
if (index < 0 || index >= CCharacterSelection::GetNumCharacters()) {
return;
}
auto component = CCharacterSelection::s_characterList[index].m_component;
if (component) {
component->RenderPrep(0);
}
}
void CCharacterSelection::SetBackgroundModel(const char* modelPath) {
@ -75,7 +79,6 @@ void CCharacterSelection::ShowCharacter() {
if (index < 0 || index >= CCharacterSelection::GetNumCharacters()) {
return;
}
// TODO
if (CCharacterSelection::m_modelFrame) {
auto model = CCharacterSelection::m_modelFrame->m_model;
@ -88,25 +91,57 @@ void CCharacterSelection::ShowCharacter() {
CCharacterSelection::m_charFacing = 0.0;
auto& character = CCharacterSelection::s_characterList[index];
if (character.m_component) {
// TODO: info = DayNightGetInfo();
float v42;
if (character.m_characterInfo.flags & 0x2000) {
// FFX::SetEffect(CGlueMgr__m_deathEffect);
v42 = 0.15f;
} else {
// FFX::SetEffect(CGlueMgr__m_glowEffect);
v42 = 0.4f;
}
// *((float *)info + 75) = v42;
if (character.m_characterModel) {
if (!character.m_characterModel->m_attachParent && CCharacterSelection::m_modelFrame && CCharacterSelection::m_modelFrame->m_model) {
character.m_characterModel->AttachToParent(CCharacterSelection::m_modelFrame->m_model, 0, nullptr, 0);
if (CCharacterSelection::m_modelFrame->m_model) {
character.m_component->m_data.m_model->AttachToParent(
CCharacterSelection::m_modelFrame->m_model,
0,
nullptr,
0);
if (character.m_petModel) {
character.m_petModel->AttachToParent(
CCharacterSelection::m_modelFrame->m_model, 1, nullptr,0);
}
}
// TODO
// TODO: sub_4E6AE0((int)s_charList.m_data[selectionIndex2].m_component, v5);
return;
}
auto rec = Player_C_GetModelName(character.m_characterInfo.raceID, character.m_characterInfo.sexID);
STORM_ASSERT(rec);
if (!rec->m_modelName) {
// TODO
if (!rec || !rec->m_modelName) {
return;
}
auto scene = CCharacterSelection::m_modelFrame->GetScene();
character.m_characterModel = scene->CreateModel(rec->m_modelName, 0);
auto model = scene->CreateModel(rec->m_modelName, 0);
ComponentData componentData(character.m_characterInfo);
componentData.m_model = model;
componentData.m_unkFlag |= 2;
character.m_component = CCharacterComponent::AllocComponent();
character.m_component->Init(&componentData, 0);
// TODO: set model ribbon emitters & particles
model->SetBoneSequence(0xFFFFFFFF, 0, 0xFFFFFFFF, 0, 1.0f, 1, 1);
// Handle pet model
// Handle hand items
++CCharacterSelection::m_characterCount;
}
@ -121,9 +156,10 @@ void CCharacterSelection::SetCharFacing(float facing) {
return;
}
auto character = CCharacterSelection::s_characterList[CCharacterSelection::m_selectionIndex];
if (character.m_characterModel) {
character.m_characterModel->SetWorldTransform(C3Vector(), facing, 1.0);
auto index = CCharacterSelection::m_selectionIndex;
auto component = CCharacterSelection::s_characterList[index].m_component;
if (component && component->m_data.m_model) {
component->m_data.m_model->SetWorldTransform(C3Vector(), facing, 1.0);
}
}

View File

@ -6,12 +6,14 @@
class CSimpleModelFFX;
class CM2Model;
class CCharacterComponent;
struct CharacterSelectionDisplay {
CharacterSelectionDisplay();
CharacterSelectionDisplay() = default;
CHARACTER_INFO m_characterInfo;
CM2Model* m_characterModel;
CHARACTER_INFO m_characterInfo = {};
CCharacterComponent* m_component = nullptr;
CM2Model* m_petModel = nullptr;
};
class CCharacterSelection {

View File

@ -1007,6 +1007,22 @@ int32_t CM2Model::InitializeLoaded() {
}
}
if (this->m_shared->skinProfile->skinSections.Count()) {
this->m_skinSections = reinterpret_cast<uint32_t*>(&data[0]);
data += (sizeof(uint32_t) * this->m_shared->skinProfile->skinSections.Count());
if (this->model30) {
memcpy(
this->m_skinSections,
this->model30->m_skinSections,
sizeof(uint32_t) * this->m_shared->skinProfile->skinSections.Count());
} else {
for (uint32_t i = 0; i < this->m_shared->skinProfile->skinSections.Count(); ++i) {
this->m_skinSections[i] = 1;
}
}
}
// TODO
if (this->m_shared->m_data->colors.Count()) {
@ -1104,7 +1120,10 @@ int32_t CM2Model::InitializeLoaded() {
}
case 1: {
// TODO
this->SetGeometryVisible(
modelCall->args[0],
modelCall->args[1],
modelCall->args[2]);
break;
}
@ -1729,3 +1748,42 @@ void CM2Model::WaitForLoad(const char* a2) {
this->InitializeLoaded();
}
}
void CM2Model::UnoptimizeVisibleGeometry() {
// TODO
}
void CM2Model::SetGeometryVisible(uint32_t start, uint32_t end, int32_t visible) {
if (this->m_loaded) {
bool needUpdate = false;
const auto& skinSections = this->m_shared->skinProfile->skinSections;
for (uint32_t i = 0; i < skinSections.Count(); ++i) {
uint32_t id = skinSections[i].skinSectionId;
if (start <= id && id <= end) {
if (this->m_skinSections[i] != static_cast<uint32_t>(visible)) {
this->m_skinSections[i] = static_cast<uint32_t>(visible);
needUpdate = true;
}
}
}
if (needUpdate) {
this->UnoptimizeVisibleGeometry();
}
} else {
auto modelCall = NEW(CM2ModelCall);
modelCall->type = 1;
modelCall->modelCallNext = nullptr;
modelCall->time = this->m_scene->m_time;
modelCall->args[0] = start;
modelCall->args[1] = end;
modelCall->args[2] = static_cast<uint32_t>(visible);
*this->m_modelCallTail = modelCall;
this->m_modelCallTail = &modelCall->modelCallNext;
}
}

View File

@ -101,6 +101,7 @@ class CM2Model {
uint32_t uint90 = 0;
M2ModelBone* m_bones = nullptr;
C44Matrix* m_boneMatrices = nullptr;
uint32_t* m_skinSections = nullptr;
M2ModelColor* m_colors = nullptr;
HTEXTURE* m_textures = nullptr;
M2ModelTextureWeight* m_textureWeights = nullptr;
@ -192,6 +193,8 @@ class CM2Model {
void UnsetBoneSequence(uint32_t boneId, int32_t a3, int32_t a4);
void UpdateLoaded();
void WaitForLoad(const char* a2);
void UnoptimizeVisibleGeometry();
void SetGeometryVisible(uint32_t start, uint32_t end, int32_t visible);
};
#endif

View File

@ -522,7 +522,7 @@ void CM2Scene::Animate(const C3Vector& cameraPos) {
batch = &skinProfile->batches[batchIndex];
skinSection = &model->m_shared->m_skinSections[batch->skinSectionIndex];
if (!skinSection) {
if (!model->m_skinSections[batch->skinSectionIndex]) {
continue;
}
}