diff options
author | aap <aap@papnet.eu> | 2021-08-23 14:13:30 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2021-08-23 14:13:30 +0200 |
commit | b89dd7f0e32d895ba275f0a9d0bce8797b6e2fab (patch) | |
tree | 9dba6051f14139261657ae5a61842e4a8179bf4b /src | |
parent | 381d0b4e3ece226865a87498b77d644e0570331e (diff) |
CModelInfo done
Diffstat (limited to 'src')
-rw-r--r-- | src/modelinfo/BaseModelInfo.cpp | 8 | ||||
-rw-r--r-- | src/modelinfo/BaseModelInfo.h | 3 | ||||
-rw-r--r-- | src/modelinfo/ModelInfo.cpp | 104 | ||||
-rw-r--r-- | src/modelinfo/ModelInfo.h | 18 |
4 files changed, 111 insertions, 22 deletions
diff --git a/src/modelinfo/BaseModelInfo.cpp b/src/modelinfo/BaseModelInfo.cpp index 6d1a7c79..9af21da0 100644 --- a/src/modelinfo/BaseModelInfo.cpp +++ b/src/modelinfo/BaseModelInfo.cpp @@ -22,8 +22,8 @@ CBaseModelInfo::CBaseModelInfo(ModelInfoType type) m_num2dEffects = 0; m_bOwnsColModel = false; m_nameKey = 0; - m_unk1 = 0; - m_unk2 = 0; + m_unk[0] = 0; + m_unk[1] = 0; m_name = new char[MAX_MODEL_NAME]; *(int32*)m_name = 0; } @@ -112,7 +112,7 @@ CBaseModelInfo::Add2dEffect(C2dEffect *fx) if(m_2dEffectsID >= 0) m_num2dEffects++; else{ - m_2dEffectsID = CModelInfo::Get2dEffectStore().GetIndex(fx); + m_2dEffectsID = CModelInfo::Get2dEffectIndex(fx); m_num2dEffects = 1; } } @@ -121,7 +121,7 @@ C2dEffect* CBaseModelInfo::Get2dEffect(int n) { if(m_2dEffectsID >= 0) - return CModelInfo::Get2dEffectStore().GetItem(m_2dEffectsID+n); + return CModelInfo::Get2dEffect(m_2dEffectsID+n); else return nil; } diff --git a/src/modelinfo/BaseModelInfo.h b/src/modelinfo/BaseModelInfo.h index c9ea13bb..f9020335 100644 --- a/src/modelinfo/BaseModelInfo.h +++ b/src/modelinfo/BaseModelInfo.h @@ -23,8 +23,7 @@ class C2dEffect; class CBaseModelInfo { protected: - uint32 m_unk1; - uint32 m_unk2; + uint32 m_unk[2]; // somehow related to GU texture stuff, unused here uint32 m_nameKey; union { char *m_name; // if not using chunks diff --git a/src/modelinfo/ModelInfo.cpp b/src/modelinfo/ModelInfo.cpp index 47f4e309..2f2bf8bc 100644 --- a/src/modelinfo/ModelInfo.cpp +++ b/src/modelinfo/ModelInfo.cpp @@ -6,7 +6,8 @@ #include "ModelInfo.h" #include "KeyGen.h" -CBaseModelInfo *CModelInfo::ms_modelInfoPtrs[MODELINFOSIZE]; +CBaseModelInfo **CModelInfo::ms_modelInfoPtrs; +int32 CModelInfo::msNumModelInfos; CStore<CSimpleModelInfo, SIMPLEMODELSIZE> CModelInfo::ms_simpleModelStore; CStore<CTimeModelInfo, TIMEMODELSIZE> CModelInfo::ms_timeModelStore; @@ -16,6 +17,8 @@ CStore<CPedModelInfo, PEDMODELSIZE> CModelInfo::ms_pedModelStore; CStore<CVehicleModelInfo, VEHICLEMODELSIZE> CModelInfo::ms_vehicleModelStore; CStore<C2dEffect, TWODFXSIZE> CModelInfo::ms_2dEffectStore; +C2dEffect *gp2dEffects; + void CModelInfo::Initialise(void) { @@ -30,9 +33,12 @@ CModelInfo::Initialise(void) debug("sizeof PedModelStore %d\n", sizeof(ms_pedModelStore)); debug("sizeof 2deffectsModelStore %d\n", sizeof(ms_2dEffectStore)); + ms_modelInfoPtrs = new CBaseModelInfo*[MODELINFOSIZE]; + msNumModelInfos = MODELINFOSIZE; for(i = 0; i < MODELINFOSIZE; i++) ms_modelInfoPtrs[i] = nil; ms_2dEffectStore.Clear(); + gp2dEffects = ms_2dEffectStore.store; ms_simpleModelStore.Clear(); ms_timeModelStore.Clear(); ms_weaponModelStore.Clear(); @@ -108,13 +114,13 @@ CModelInfo::ShutDown(void) for(i = 0; i < ms_2dEffectStore.allocPtr; i++) ms_2dEffectStore.store[i].Shutdown(); - ms_2dEffectStore.Clear(); ms_simpleModelStore.Clear(); ms_timeModelStore.Clear(); ms_weaponModelStore.Clear(); - ms_pedModelStore.Clear(); ms_clumpModelStore.Clear(); ms_vehicleModelStore.Clear(); + ms_pedModelStore.Clear(); + ms_2dEffectStore.Clear(); } CSimpleModelInfo* @@ -187,7 +193,7 @@ CModelInfo::GetModelInfo(const char *name, int *id) { uint32 hashKey = CKeyGen::GetUppercaseKey(name); CBaseModelInfo *modelinfo; - for(int i = 0; i < MODELINFOSIZE; i++){ + for(int i = 0; i < msNumModelInfos; i++){ modelinfo = CModelInfo::ms_modelInfoPtrs[i]; if(modelinfo && hashKey == modelinfo->GetNameHashKey()){ if(id) @@ -214,39 +220,67 @@ CModelInfo::GetModelInfo(const char *name, int minIndex, int maxIndex) return nil; } +CBaseModelInfo* +CModelInfo::GetModelInfoFromHashKey(uint32 hashKey, int *id) +{ + CBaseModelInfo *modelinfo; + for(int i = 0; i < msNumModelInfos; i++){ + modelinfo = CModelInfo::ms_modelInfoPtrs[i]; + if(modelinfo && hashKey == modelinfo->GetNameHashKey()){ + if(id) + *id = i; + return modelinfo; + } + } + return nil; +} + bool CModelInfo::IsBoatModel(int32 id) { - return GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && - ((CVehicleModelInfo*)GetModelInfo(id))->m_vehicleType == VEHICLE_TYPE_BOAT; + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_BOAT; } bool CModelInfo::IsBikeModel(int32 id) { - return GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && - ((CVehicleModelInfo*)GetModelInfo(id))->m_vehicleType == VEHICLE_TYPE_BIKE; + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_BIKE; } bool CModelInfo::IsCarModel(int32 id) { - return GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && - ((CVehicleModelInfo*)GetModelInfo(id))->m_vehicleType == VEHICLE_TYPE_CAR; + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_CAR; +} + +bool +CModelInfo::IsTrainModel(int32 id) +{ + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_TRAIN; } bool CModelInfo::IsHeliModel(int32 id) { - return GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && - ((CVehicleModelInfo*)GetModelInfo(id))->m_vehicleType == VEHICLE_TYPE_HELI; + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_HELI; } bool CModelInfo::IsPlaneModel(int32 id) { - return GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && - ((CVehicleModelInfo*)GetModelInfo(id))->m_vehicleType == VEHICLE_TYPE_PLANE; + CBaseModelInfo *mi = GetModelInfo(id); + return mi && mi->GetModelType() == MITYPE_VEHICLE && + ((CVehicleModelInfo*)mi)->m_vehicleType == VEHICLE_TYPE_PLANE; } void @@ -254,8 +288,48 @@ CModelInfo::ReInit2dEffects() { ms_2dEffectStore.Clear(); - for (int i = 0; i < MODELINFOSIZE; i++) { + for (int i = 0; i < msNumModelInfos; i++) { if (ms_modelInfoPtrs[i]) ms_modelInfoPtrs[i]->Init2dEffects(); } } + +void +CModelInfo::Load(uint32 numModelInfos, CBaseModelInfo **modelInfos) +{ + int i; + + msNumModelInfos = numModelInfos; + ms_modelInfoPtrs = modelInfos; + for(i = 0; i < msNumModelInfos; i++) + if(ms_modelInfoPtrs[i] && ms_modelInfoPtrs[i]->GetModelType() == MITYPE_VEHICLE && + ms_modelInfoPtrs[i]->GetRwObject()) + ((CVehicleModelInfo*)ms_modelInfoPtrs[i])->SetAtomicRenderCallbacks(); +} + +void +CModelInfo::Load2dEffects(uint32 numEffects, C2dEffect *effects) +{ + ms_2dEffectStore.allocPtr = numEffects; + gp2dEffects = effects; +} + +CModelInfo* +CModelInfo::Write(base::cRelocatableChunkWriter &writer) +{ + uint32 i; + uint32 numModelInfos; + + for(numModelInfos = msNumModelInfos; ms_modelInfoPtrs[numModelInfos-1] == nil; numModelInfos--); + writer.AllocateRaw(ms_modelInfoPtrs, sizeof(void*)*numModelInfos, sizeof(void*), false, true); + for(i = 0; i < numModelInfos; i++) + if(ms_modelInfoPtrs[i]){ + writer.AddPatch(ms_modelInfoPtrs[i]); + ms_modelInfoPtrs[i]->Write(writer); + } + + resNumModelInfos = numModelInfos; + resModelInfoPtrs = ms_modelInfoPtrs; + + return this; +} diff --git a/src/modelinfo/ModelInfo.h b/src/modelinfo/ModelInfo.h index a0be1937..1e401247 100644 --- a/src/modelinfo/ModelInfo.h +++ b/src/modelinfo/ModelInfo.h @@ -11,9 +11,12 @@ #include "XtraCompsModelInfo.h" #include "templates.h" +extern C2dEffect *gp2dEffects; + class CModelInfo { - static CBaseModelInfo *ms_modelInfoPtrs[MODELINFOSIZE]; + static CBaseModelInfo **ms_modelInfoPtrs; + static int32 msNumModelInfos; static CStore<CSimpleModelInfo, SIMPLEMODELSIZE> ms_simpleModelStore; static CStore<CTimeModelInfo, TIMEMODELSIZE> ms_timeModelStore; static CStore<CWeaponModelInfo, WEAPONMODELSIZE> ms_weaponModelStore; @@ -22,6 +25,9 @@ class CModelInfo static CStore<CVehicleModelInfo, VEHICLEMODELSIZE> ms_vehicleModelStore; static CStore<C2dEffect, TWODFXSIZE> ms_2dEffectStore; + // these fields are in the resource image + int32 resNumModelInfos; + CBaseModelInfo **resModelInfoPtrs; public: static void Initialise(void); static void ShutDown(void); @@ -34,12 +40,17 @@ public: static CVehicleModelInfo *AddVehicleModel(int id); static CStore<C2dEffect, TWODFXSIZE> &Get2dEffectStore(void) { return ms_2dEffectStore; } + static C2dEffect *Get2dEffect(int32 id) { return &gp2dEffects[id]; } + static int32 Get2dEffectIndex(C2dEffect *effect) { return effect - gp2dEffects; } static CBaseModelInfo *GetModelInfo(const char *name, int *id); static CBaseModelInfo *GetModelInfo(int id){ + if(id < 0 || id >= msNumModelInfos) + return nil; return ms_modelInfoPtrs[id]; } static CBaseModelInfo *GetModelInfo(const char *name, int minIndex, int maxIndex); + static CBaseModelInfo *GetModelInfoFromHashKey(uint32 hashKey, int *id); static CColModel *GetColModel(int id){ return ms_modelInfoPtrs[id]->GetColModel(); } @@ -47,7 +58,12 @@ public: static bool IsBoatModel(int32 id); static bool IsBikeModel(int32 id); static bool IsCarModel(int32 id); + static bool IsTrainModel(int32 id); static bool IsHeliModel(int32 id); static bool IsPlaneModel(int32 id); static void ReInit2dEffects(); + + static void Load(uint32 numModelInfos, CBaseModelInfo **modelInfos); + static void Load2dEffects(uint32 numEffects, C2dEffect *effects); + CModelInfo *Write(base::cRelocatableChunkWriter &writer); }; |