CPedModelInfo and CTempColModels

This commit is contained in:
aap 2021-01-24 17:14:16 +01:00
parent 1bee2caf5c
commit a202e67349
12 changed files with 219 additions and 65 deletions

View File

@ -204,3 +204,10 @@ CColModel::operator=(const CColModel &other)
}
return *this;
}
bool
CColModel::Write(base::cRelocatableChunkWriter &writer, bool allocSpace)
{
assert(0 && "TODO(LCS)");
return 1;
}

View File

@ -36,4 +36,6 @@ struct CColModel
void *operator new(size_t);
void operator delete(void *p, size_t);
CColModel& operator=(const CColModel& other);
bool Write(base::cRelocatableChunkWriter &writer, bool allocSpace);
};

View File

@ -1,11 +1,12 @@
#include "common.h"
#include "main.h"
#include "TempColModels.h"
#include "Game.h"
CColModel CTempColModels::ms_colModelPed1;
// LCS: haven't yet checked the numbers but they probably haven't changed
CColModel CTempColModels::ms_colModelPed2;
CColModel CTempColModels::ms_colModelBBox;
CColModel CTempColModels::ms_colModelBumper1;
CColModel CTempColModels::ms_colModelWheel1;
CColModel CTempColModels::ms_colModelPanel1;
@ -16,7 +17,9 @@ CColModel CTempColModels::ms_colModelPedGroundHit;
CColModel CTempColModels::ms_colModelBoot1;
CColModel CTempColModels::ms_colModelDoor1;
CColModel CTempColModels::ms_colModelBonnet1;
CColModel CTempColModels::ms_colModelWeapon;
CColModel CTempColModels::ms_colModelFerryDocked;
CTempColModels *gpTempColModels;
CColSphere s_aPedSpheres[3];
@ -34,6 +37,7 @@ CColSphere s_aBootSpheres[4];
CColSphere s_aWheelSpheres[2];
CColSphere s_aBodyPartSpheres1[2];
CColSphere s_aBodyPartSpheres2[2];
CColBox S_aFerryDockedBoxes[1];
void
CTempColModels::Initialise(void)
@ -44,11 +48,26 @@ CTempColModels::Initialise(void)
colmodel.level = LEVEL_GENERIC;\
colmodel.ownsCollisionVolumes = false;
int i;
if(gMakeResources){
if(gpTempColModels == nil){
gpTempColModels = new CTempColModels;
gpTempColModels->Initialise();
return;
}
ms_colModelBBox.boundingSphere.Set(2.0f, CVector(0.0f, 0.0f, 0.0f));
ms_colModelBBox.boundingBox.Set(CVector(-2.0f, -2.0f, -2.0f), CVector(2.0f, 2.0f, 2.0f));
ms_colModelBBox.level = LEVEL_GENERIC;
ms_colModelBBox.boundingSphere.Set(2.0f, CVector(0.0f, 0.0f, 0.0f));
ms_colModelBBox.boundingBox.Set(CVector(-2.0f, -2.0f, -2.0f), CVector(2.0f, 2.0f, 2.0f));
ms_colModelBBox.level = LEVEL_GENERIC;
ms_colModelPed1.boundingSphere.Set(1.25f, CVector(0.0f, 0.0f, 0.0f));
ms_colModelPed1.boundingBox.Set(CVector(-0.35f, -0.35f, -1.0f), CVector(0.35f, 0.35f, 0.9f));
SET_COLMODEL_SPHERES(ms_colModelPed1, s_aPedSpheres);
ms_colModelWeapon.boundingSphere.Set(0.25f, CVector(0.0f, 0.0f, 0.0f));
ms_colModelWeapon.boundingBox.Set(CVector(-0.25f, -0.25f, -0.25f), CVector(0.25f, 0.25f, 0.25f));
}
int i;
for (i = 0; i < ARRAY_SIZE(ms_colModelCutObj); i++) {
ms_colModelCutObj[i].boundingSphere.Set(2.0f, CVector(0.0f, 0.0f, 0.0f));
@ -74,10 +93,6 @@ CTempColModels::Initialise(void)
s_aPedSpheres[i].piece = 0;
}
ms_colModelPed1.boundingSphere.Set(1.25f, CVector(0.0f, 0.0f, 0.0f));
ms_colModelPed1.boundingBox.Set(CVector(-0.35f, -0.35f, -1.0f), CVector(0.35f, 0.35f, 0.9f));
SET_COLMODEL_SPHERES(ms_colModelPed1, s_aPedSpheres);
// Ped 2 Spheres
s_aPed2Spheres[0].radius = 0.3f;
@ -294,13 +309,47 @@ CTempColModels::Initialise(void)
SET_COLMODEL_SPHERES(ms_colModelBodyPart2, s_aBodyPartSpheres2);
ms_colModelWeapon.boundingSphere.radius = 0.25f;
ms_colModelWeapon.boundingBox.min.x = -0.25f;
ms_colModelWeapon.boundingBox.min.y = -0.25f;
ms_colModelWeapon.boundingBox.min.z = -0.25f;
ms_colModelWeapon.boundingBox.max.x = 0.25f;
ms_colModelWeapon.boundingBox.max.y = 0.25f;
ms_colModelWeapon.boundingBox.max.z = 0.25f;
// Ferry Docked
S_aFerryDockedBoxes[0].Set(CVector(-6.3f, -22.78f, -2.0f), CVector(6.3f, 22.78f, 2.8f), SURFACE_THICK_METAL_PLATE, SURFACE_DEFAULT);
ms_colModelFerryDocked.boundingSphere.Set(35.0f, CVector(0.0f, -0.0f, 0.0f));
ms_colModelFerryDocked.boundingBox.Set(S_aFerryDockedBoxes[0].min, S_aFerryDockedBoxes[0].max);
ms_colModelFerryDocked.spheres = nil;
ms_colModelFerryDocked.numSpheres = 0;
ms_colModelFerryDocked.boxes = S_aFerryDockedBoxes;
ms_colModelFerryDocked.numBoxes = ARRAY_SIZE(S_aFerryDockedBoxes);
ms_colModelFerryDocked.level = LEVEL_GENERIC;
#undef SET_COLMODEL_SPHERES
}
void
CTempColModels::Write(base::cRelocatableChunkWriter &writer)
{
writer.AllocateRaw(this, sizeof(*this), 0x10, false, true);
ms_colModelBBox.Write(writer, false);
writer.AddPatch(&ms_colModelBBox);
ms_colModelPed1.Write(writer, false);
writer.AddPatch(&ms_colModelPed1);
ms_colModelWeapon.Write(writer, false);
writer.AddPatch(&ms_colModelWeapon);
for(int i = 0; i < ARRAY_SIZE(ms_colModelCutObj); i++)
ms_colModelCutObj[i].Write(writer, true);
ms_colModelPed2.Write(writer, true);
ms_colModelPedGroundHit.Write(writer, true);
ms_colModelDoor1.Write(writer, true);
ms_colModelBumper1.Write(writer, true);
ms_colModelPanel1.Write(writer, true);
ms_colModelBonnet1.Write(writer, true);
ms_colModelBoot1.Write(writer, true);
ms_colModelWheel1.Write(writer, true);
ms_colModelBodyPart1.Write(writer, true);
ms_colModelBodyPart2.Write(writer, true);
ms_colModelFerryDocked.Write(writer, true);
}

View File

@ -5,9 +5,11 @@
class CTempColModels
{
public:
static CColModel ms_colModelPed1;
CColModel ms_colModelPed1;
CColModel ms_colModelBBox;
CColModel ms_colModelWeapon;
static CColModel ms_colModelPed2;
static CColModel ms_colModelBBox;
static CColModel ms_colModelBumper1;
static CColModel ms_colModelWheel1;
static CColModel ms_colModelPanel1;
@ -18,7 +20,10 @@ public:
static CColModel ms_colModelBoot1;
static CColModel ms_colModelDoor1;
static CColModel ms_colModelBonnet1;
static CColModel ms_colModelWeapon;
static CColModel ms_colModelFerryDocked;
static void Initialise(void);
void Initialise(void);
void Write(base::cRelocatableChunkWriter &writer);
};
extern CTempColModels *gpTempColModels;

View File

@ -81,7 +81,7 @@ CAnimViewer::Initialise(void) {
CCollision::Init();
CWorld::Initialise();
mod_HandlingManager.Initialise();
CTempColModels::Initialise();
gpTempColModels->Initialise();
CAnimManager::Initialise();
CModelInfo::Initialise();
CParticle::Initialise();

View File

@ -833,7 +833,7 @@ CFileLoader::LoadWeaponObject(const char *line)
mi->m_lodDistances[0] = dist;
mi->SetTexDictionary(txd);
mi->SetAnimFile(animFile);
mi->SetColModel(&CTempColModels::ms_colModelWeapon);
mi->SetColModel(&gpTempColModels->ms_colModelWeapon);
MatchModelString(model, id);
return id;
}
@ -849,7 +849,7 @@ CFileLoader::LoadClumpObject(const char *line)
mi = CModelInfo::AddClumpModel(id);
mi->SetModelName(model);
mi->SetTexDictionary(txd);
mi->SetColModel(&CTempColModels::ms_colModelBBox);
mi->SetColModel(&gpTempColModels->ms_colModelBBox);
}
}
@ -956,7 +956,7 @@ CFileLoader::LoadPedObject(const char *line)
mi->SetModelName(model);
mi->SetTexDictionary(txd);
mi->SetAnimFile(animFile);
mi->SetColModel(&CTempColModels::ms_colModelPed1);
mi->SetColModel(&gpTempColModels->ms_colModelPed1);
mi->m_pedType = CPedType::FindPedType(pedType);
mi->m_pedStatType = CPedStats::GetPedStatType(pedStats);
for(animGroupId = 0; animGroupId < NUM_ANIM_ASSOC_GROUPS; animGroupId++)

View File

@ -316,7 +316,7 @@ bool CGame::InitialiseOnceAfterRW(void)
{
TheText.Load();
CTimer::Initialise();
CTempColModels::Initialise();
gpTempColModels->Initialise();
mod_HandlingManager.Initialise();
CSurfaceTable::Initialise("DATA\\SURFACE.DAT");
CPedStats::Initialise();

View File

@ -9,8 +9,7 @@
#include "KeyGen.h"
#include "Streaming.h"
#include "smallHeap.h"
// LCS: file done except for TODO
#include "TempColModels.h"
CBaseModelInfo::CBaseModelInfo(ModelInfoType type)
{
@ -146,12 +145,39 @@ CBaseModelInfo::DeleteChunk(void)
}
}
inline int
GetColmodelID(CColModel *model)
{
int colModelid = 0;
if(model == &gpTempColModels->ms_colModelBBox) colModelid = 1;
if(model == &gpTempColModels->ms_colModelPed1) colModelid = 2;
if(model == &gpTempColModels->ms_colModelWeapon) colModelid = 3;
if(model == &CTempColModels::ms_colModelPed2) colModelid = 4;
if(model == &CTempColModels::ms_colModelPedGroundHit) colModelid = 5;
if(model == &CTempColModels::ms_colModelDoor1) colModelid = 6;
if(model == &CTempColModels::ms_colModelBumper1) colModelid = 7;
if(model == &CTempColModels::ms_colModelPanel1) colModelid = 8;
if(model == &CTempColModels::ms_colModelBonnet1) colModelid = 9;
if(model == &CTempColModels::ms_colModelBoot1) colModelid = 10;
if(model == &CTempColModels::ms_colModelWheel1) colModelid = 11;
if(model == &CTempColModels::ms_colModelBodyPart1) colModelid = 12;
if(model == &CTempColModels::ms_colModelBodyPart2) colModelid = 13;
if(model == &CTempColModels::ms_colModelCutObj[0]) colModelid = 14;
if(model == &CTempColModels::ms_colModelCutObj[1]) colModelid = 15;
if(model == &CTempColModels::ms_colModelCutObj[2]) colModelid = 16;
if(model == &CTempColModels::ms_colModelCutObj[3]) colModelid = 17;
if(model == &CTempColModels::ms_colModelCutObj[4]) colModelid = 18;
return colModelid;
}
void
CBaseModelInfo::Write(base::cRelocatableChunkWriter &writer)
{
m_chunk = nil;
RcWriteThis(writer);
if(m_colModel){
assert(0 && "TODO");
if(m_bOwnsColModel || GetColmodelID(m_colModel) != 0)
m_colModel->Write(writer, true);
writer.AddPatch(&m_colModel);
}
}

View File

@ -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,40 +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;
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);
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*
@ -114,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;
}
@ -153,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);
}

View File

@ -38,6 +38,8 @@ public:
CColModel *m_hitColModel;
int8 radio1, radio2;
static base::cRelocatableChunkClassInfo msClassInfo;
static CPedModelInfo msClassInstance;
static RwObjectNameIdAssocation m_pPedIds[PED_NODE_MAX];
CPedModelInfo(void) : CClumpModelInfo(MITYPE_PED) { m_hitColModel = nil; }
@ -45,7 +47,13 @@ public:
void DeleteRwObject(void);
void SetClump(RpClump *);
void CreateHitColModelSkinned(RpClump *clump);
virtual void LoadModel(void *model, const void *chunk);
virtual void Write(base::cRelocatableChunkWriter &writer);
virtual void *WriteModel(base::cRelocatableChunkWriter &writer);
virtual void RcWriteThis(base::cRelocatableChunkWriter &writer);
virtual void RcWriteEmpty(base::cRelocatableChunkWriter &writer);
bool CreateHitColModelSkinned(RpClump *clump);
CColModel *GetHitColModel(void) { return m_hitColModel; }
CColModel *AnimatePedColModelSkinned(RpClump *clump);
CColModel *AnimatePedColModelSkinnedWorld(RpClump *clump);

View File

@ -756,7 +756,7 @@ CHeli::InitHelis(void)
for(i = 0; i < NUM_HELIS; i++)
pHelis[i] = nil;
((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&CTempColModels::ms_colModelPed1);
((CVehicleModelInfo*)CModelInfo::GetModelInfo(MI_CHOPPER))->SetColModel(&gpTempColModels->ms_colModelPed1);
}
CHeli*

View File

@ -513,7 +513,7 @@ CWeapon::FireMelee(CEntity *shooter, CVector &fireSource)
if ( SQR(victimPedRadius) > (victimPedPos-fireSource).MagnitudeSqr() )
{
CVector collisionDist;
CColModel* victimPedCol = &CTempColModels::ms_colModelPed1;
CColModel* victimPedCol = &gpTempColModels->ms_colModelPed1;
bool useLocalPos = false;
if (victimPed->m_nPedState == PED_FALL
|| victimPed->m_nPedState == PED_DIE && victimPed->bIsPedDieAnimPlaying