diff options
Diffstat (limited to 'src/modelinfo/PedModelInfo.cpp')
-rw-r--r-- | src/modelinfo/PedModelInfo.cpp | 127 |
1 files changed, 89 insertions, 38 deletions
diff --git a/src/modelinfo/PedModelInfo.cpp b/src/modelinfo/PedModelInfo.cpp index 25b260d3..1d519b10 100644 --- a/src/modelinfo/PedModelInfo.cpp +++ b/src/modelinfo/PedModelInfo.cpp @@ -1,5 +1,6 @@ #include "common.h" +#include "main.h" #include "RwHelper.h" #include "General.h" #include "Bones.h" @@ -9,12 +10,19 @@ #include "VisibilityPlugins.h" #include "ModelInfo.h" #include "custompipes.h" +#include "Streaming.h" +#include "Leeds.h" +#include "TempColModels.h" + +base::cRelocatableChunkClassInfo CPedModelInfo::msClassInfo("CPedModelInfo", VTABLE_ADDR(&msClassInstance), sizeof(msClassInstance)); +CPedModelInfo CPedModelInfo::msClassInstance; void CPedModelInfo::DeleteRwObject(void) { + CStreaming::UnregisterPointer(&m_hitColModel, 2); CClumpModelInfo::DeleteRwObject(); - if(m_hitColModel) + if(!gUseChunkFiles && m_hitColModel) delete m_hitColModel; m_hitColModel = nil; } @@ -41,13 +49,15 @@ CPedModelInfo::SetClump(RpClump *clump) #ifdef EXTENDED_PIPELINES CustomPipes::AttachRimPipe(clump); #endif + if(!IsClumpSkinned(clump)) + return; CClumpModelInfo::SetClump(clump); SetFrameIds(m_pPedIds); // not needed in VC actually if(m_hitColModel == nil) CreateHitColModelSkinned(clump); RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPedCB); - if(strcmp(GetModelName(), "player") == 0) - RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB); + //if(strcmp(GetModelName(), "player") == 0) + // RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB); } struct ColNodeInfo @@ -73,46 +83,27 @@ ColNodeInfo m_pColNodeInfos[NUMPEDINFONODES] = { { nil, PED_FOOTR, PEDPIECE_RIGHTLEG, 0.0f, 0.15f, 0.15f }, }; -void +bool CPedModelInfo::CreateHitColModelSkinned(RpClump *clump) { - RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(clump); CColModel *colmodel = new CColModel; CColSphere *spheres = (CColSphere*)RwMalloc(NUMPEDINFONODES*sizeof(CColSphere)); - RwFrame *root = RpClumpGetFrame(m_clump); - RwMatrix *invmat = RwMatrixCreate(); - RwMatrix *mat = RwMatrixCreate(); - RwMatrixInvert(invmat, RwFrameGetMatrix(RpClumpGetFrame(clump))); for(int i = 0; i < NUMPEDINFONODES; i++){ - *mat = *invmat; - - // From LCS. Otherwise gives FPE -#ifdef FIX_BUGS - spheres[i].center = CVector(0.0f, 0.0f, 0.0f); -#else - int id = ConvertPedNode2BoneTag(m_pColNodeInfos[i].pedNode); // this is wrong, wtf R* ??? - int idx = RpHAnimIDGetIndex(hier, id); - - // This doesn't really work as the positions are not initialized yet - RwMatrixTransform(mat, &RpHAnimHierarchyGetMatrixArray(hier)[idx], rwCOMBINEPRECONCAT); - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - RwV3dTransformPoints(&pos, &pos, 1, mat); - - spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z); -#endif + spheres[i].center.x = 0.0f; + spheres[i].center.y = 0.0f; + spheres[i].center.z = 0.0f; spheres[i].radius = m_pColNodeInfos[i].radius; spheres[i].surface = SURFACE_PED; spheres[i].piece = m_pColNodeInfos[i].pieceType; } - RwMatrixDestroy(invmat); - RwMatrixDestroy(mat); colmodel->spheres = spheres; colmodel->numSpheres = NUMPEDINFONODES; colmodel->boundingSphere.Set(2.0f, CVector(0.0f, 0.0f, 0.0f)); colmodel->boundingBox.Set(CVector(-0.5f, -0.5f, -1.2f), CVector(0.5f, 0.5f, 1.2f)); colmodel->level = LEVEL_GENERIC; m_hitColModel = colmodel; + return true; } CColModel* @@ -120,28 +111,27 @@ CPedModelInfo::AnimatePedColModelSkinned(RpClump *clump) { if(m_hitColModel == nil){ CreateHitColModelSkinned(clump); +#ifndef FIX_BUGS return m_hitColModel; +#endif + // we should really animate this now } - RwMatrix *invmat, *mat; + RwMatrix invmat, mat; CColSphere *spheres = m_hitColModel->spheres; RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(clump); - invmat = RwMatrixCreate(); - mat = RwMatrixCreate(); - RwMatrixInvert(invmat, RwFrameGetMatrix(RpClumpGetFrame(clump))); + RwMatrixInvert(&invmat, RwFrameGetMatrix(RpClumpGetFrame(clump))); for(int i = 0; i < NUMPEDINFONODES; i++){ - *mat = *invmat; + mat = invmat; int id = ConvertPedNode2BoneTag(m_pColNodeInfos[i].pedNode); int idx = RpHAnimIDGetIndex(hier, id); - RwMatrixTransform(mat, &RpHAnimHierarchyGetMatrixArray(hier)[idx], rwCOMBINEPRECONCAT); - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - RwV3dTransformPoints(&pos, &pos, 1, mat); + RwMatrixTransform(&mat, &RpHAnimHierarchyGetMatrixArray(hier)[idx], rwCOMBINEPRECONCAT); + RwV3d pos = { 0.0f, 0.0f, 0.0f }; // actually CVector + RwV3dTransformPoints(&pos, &pos, 1, &mat); spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z); } - RwMatrixDestroy(invmat); - RwMatrixDestroy(mat); return m_hitColModel; } @@ -159,10 +149,71 @@ CPedModelInfo::AnimatePedColModelSkinnedWorld(RpClump *clump) int idx = RpHAnimIDGetIndex(hier, id); mat = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; - RwV3d pos = { 0.0f, 0.0f, 0.0f }; + RwV3d pos = { 0.0f, 0.0f, 0.0f }; // actually CVector RwV3dTransformPoints(&pos, &pos, 1, mat); spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z); } return m_hitColModel; } + + +struct PedChunk +{ + CColModel *colmodel; + RpClump *clump; +}; + +void +CPedModelInfo::LoadModel(void *data, const void *chunk) +{ + PedChunk *chk = (PedChunk*)data; + m_hitColModel = chk->colmodel; + CStreaming::RegisterPointer(&m_hitColModel, 2, true); + CClumpModelInfo::LoadModel(chk->clump, chunk); +} + +void +CPedModelInfo::Write(base::cRelocatableChunkWriter &writer) +{ + SetColModel(&gpTempColModels->ms_colModelPed1); + CClumpModelInfo::Write(writer); + if(m_hitColModel){ + writer.AddPatch(&m_hitColModel); + m_hitColModel->Write(writer, true); + } +} + +void* +CPedModelInfo::WriteModel(base::cRelocatableChunkWriter &writer) +{ + PedChunk *chunk = new PedChunk; // LEAK + chunk->colmodel = nil; + chunk->clump = nil; + writer.AllocateRaw(chunk, sizeof(*chunk), sizeof(void*), false, true); + + chunk->clump = (RpClump*)CClumpModelInfo::WriteModel(writer); + if(chunk->clump) + writer.AddPatch(&chunk->clump); + + chunk->colmodel = m_hitColModel; + if(chunk->colmodel){ + writer.AddPatch(&chunk->colmodel); + chunk->colmodel->Write(writer, true); + } + return nil; +} + +void +CPedModelInfo::RcWriteThis(base::cRelocatableChunkWriter &writer) +{ + writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true); + writer.Class(VTABLE_ADDR(this), msClassInfo); +} + +void +CPedModelInfo::RcWriteEmpty(base::cRelocatableChunkWriter &writer) +{ + writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true); + writer.Class(VTABLE_ADDR(this), msClassInfo); +} |