From e9fbd2ccfd9bd70cfdae0161f4c32aa29f6b7274 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 10 May 2020 10:04:20 +0200 Subject: CWeaponModelInfo --- src/animation/AnimManager.cpp | 3 ++- src/modelinfo/ModelInfo.cpp | 15 +++++++++++ src/modelinfo/ModelInfo.h | 3 +++ src/modelinfo/WeaponModelInfo.cpp | 53 +++++++++++++++++++++++++++++++++++++++ src/modelinfo/WeaponModelInfo.h | 22 ++++++++++++++++ src/rw/VisibilityPlugins.cpp | 19 ++++++++++++++ src/rw/VisibilityPlugins.h | 1 + 7 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/modelinfo/WeaponModelInfo.cpp create mode 100644 src/modelinfo/WeaponModelInfo.h (limited to 'src') diff --git a/src/animation/AnimManager.cpp b/src/animation/AnimManager.cpp index c31d7a5b..63dc172c 100644 --- a/src/animation/AnimManager.cpp +++ b/src/animation/AnimManager.cpp @@ -145,7 +145,7 @@ AnimAssocDesc aStdAnimDescs[] = { { ANIM_DRIVEBY_R, ASSOC_DELETEFADEDOUT | ASSOC_PARTIAL }, { ANIM_CAR_LB, ASSOC_DELETEFADEDOUT | ASSOC_PARTIAL }, { ANIM_DRIVE_BOAT, ASSOC_DELETEFADEDOUT }, - { ANIM_CAR_GETOUT_LHS, ASSOC_FADEOUTWHENDONE | ASSOC_PARTIAL }, + { ANIM_CAR_GETOUT_RHS, ASSOC_FADEOUTWHENDONE | ASSOC_PARTIAL }, { ANIM_CAR_GETOUT_LOW_RHS, ASSOC_FADEOUTWHENDONE | ASSOC_PARTIAL }, { ANIM_CAR_CLOSE_RHS, ASSOC_FADEOUTWHENDONE | ASSOC_PARTIAL }, { ANIM_CAR_HOOKERTALK, ASSOC_REPEAT | ASSOC_PARTIAL }, @@ -906,6 +906,7 @@ CAnimManager::LoadAnimFile(RwStream *stream, bool compress, char (*somename)[32] int animIndex = animBlock->firstIndex; for(j = 0; j < animBlock->numAnims; j++){ + assert(animIndex < ARRAY_SIZE(ms_aAnimations)); CAnimBlendHierarchy *hier = &ms_aAnimations[animIndex++]; // animation name diff --git a/src/modelinfo/ModelInfo.cpp b/src/modelinfo/ModelInfo.cpp index 29466777..3dc048c9 100644 --- a/src/modelinfo/ModelInfo.cpp +++ b/src/modelinfo/ModelInfo.cpp @@ -9,6 +9,7 @@ CBaseModelInfo *CModelInfo::ms_modelInfoPtrs[MODELINFOSIZE]; CStore CModelInfo::ms_simpleModelStore; CStore CModelInfo::ms_timeModelStore; +CStore CModelInfo::ms_weaponModelStore; CStore CModelInfo::ms_clumpModelStore; CStore CModelInfo::ms_pedModelStore; CStore CModelInfo::ms_vehicleModelStore; @@ -25,6 +26,7 @@ CModelInfo::Initialise(void) ms_2dEffectStore.clear(); ms_simpleModelStore.clear(); ms_timeModelStore.clear(); + ms_weaponModelStore.clear(); ms_clumpModelStore.clear(); ms_pedModelStore.clear(); ms_vehicleModelStore.clear(); @@ -86,6 +88,8 @@ CModelInfo::ShutDown(void) ms_simpleModelStore.store[i].Shutdown(); for(i = 0; i < ms_timeModelStore.allocPtr; i++) ms_timeModelStore.store[i].Shutdown(); + for(i = 0; i < ms_weaponModelStore.allocPtr; i++) + ms_weaponModelStore.store[i].Shutdown(); for(i = 0; i < ms_clumpModelStore.allocPtr; i++) ms_clumpModelStore.store[i].Shutdown(); for(i = 0; i < ms_vehicleModelStore.allocPtr; i++) @@ -98,6 +102,7 @@ CModelInfo::ShutDown(void) ms_2dEffectStore.clear(); ms_simpleModelStore.clear(); ms_timeModelStore.clear(); + ms_weaponModelStore.clear(); ms_pedModelStore.clear(); ms_clumpModelStore.clear(); ms_vehicleModelStore.clear(); @@ -123,6 +128,16 @@ CModelInfo::AddTimeModel(int id) return modelinfo; } +CWeaponModelInfo* +CModelInfo::AddWeaponModel(int id) +{ + CWeaponModelInfo *modelinfo; + modelinfo = CModelInfo::ms_weaponModelStore.alloc(); + CModelInfo::ms_modelInfoPtrs[id] = modelinfo; + modelinfo->Init(); + return modelinfo; +} + CClumpModelInfo* CModelInfo::AddClumpModel(int id) { diff --git a/src/modelinfo/ModelInfo.h b/src/modelinfo/ModelInfo.h index fd545e3d..a24ba797 100644 --- a/src/modelinfo/ModelInfo.h +++ b/src/modelinfo/ModelInfo.h @@ -4,6 +4,7 @@ #include "BaseModelInfo.h" #include "SimpleModelInfo.h" #include "TimeModelInfo.h" +#include "WeaponModelInfo.h" #include "ClumpModelInfo.h" #include "PedModelInfo.h" #include "VehicleModelInfo.h" @@ -14,6 +15,7 @@ class CModelInfo static CBaseModelInfo *ms_modelInfoPtrs[MODELINFOSIZE]; static CStore ms_simpleModelStore; static CStore ms_timeModelStore; + static CStore ms_weaponModelStore; static CStore ms_clumpModelStore; static CStore ms_pedModelStore; static CStore ms_vehicleModelStore; @@ -25,6 +27,7 @@ public: static CSimpleModelInfo *AddSimpleModel(int id); static CTimeModelInfo *AddTimeModel(int id); + static CWeaponModelInfo *AddWeaponModel(int id); static CClumpModelInfo *AddClumpModel(int id); static CPedModelInfo *AddPedModel(int id); static CVehicleModelInfo *AddVehicleModel(int id); diff --git a/src/modelinfo/WeaponModelInfo.cpp b/src/modelinfo/WeaponModelInfo.cpp new file mode 100644 index 00000000..fe5ead01 --- /dev/null +++ b/src/modelinfo/WeaponModelInfo.cpp @@ -0,0 +1,53 @@ +#include "common.h" + +#include "ModelInfo.h" +#include "AnimManager.h" +#include "VisibilityPlugins.h" + +void +CWeaponModelInfo::SetAnimFile(const char *file) +{ + if(strcasecmp(file, "null") == 0) + return; + + m_animFileName = new char[strlen(file)+1]; + strcpy(m_animFileName, file); +} + +void +CWeaponModelInfo::ConvertAnimFileIndex(void) +{ + if(m_animFileIndex != -1){ + // we have a string pointer in that union + int32 index = CAnimManager::GetAnimationBlockIndex(m_animFileName); + delete[] m_animFileName; + m_animFileIndex = index; + } +} + +void +CWeaponModelInfo::Init(void) +{ + CSimpleModelInfo::Init(); + SetWeaponInfo(0); +} + +void +CWeaponModelInfo::SetWeaponInfo(int32 weaponId) +{ + m_atomics[2] = (RpAtomic*)weaponId; +} + +int32 +CWeaponModelInfo::GetWeaponInfo(void) +{ + return (int32)(uintptr)m_atomics[2]; +} + +void +CWeaponModelInfo::SetAtomic(int n, RpAtomic *atomic) +{ + CSimpleModelInfo::SetAtomic(n, atomic); + CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderWeaponCB); +} + diff --git a/src/modelinfo/WeaponModelInfo.h b/src/modelinfo/WeaponModelInfo.h new file mode 100644 index 00000000..17e717db --- /dev/null +++ b/src/modelinfo/WeaponModelInfo.h @@ -0,0 +1,22 @@ +#pragma once + +#include "SimpleModelInfo.h" + +class CWeaponModelInfo : public CSimpleModelInfo +{ + union { + int32 m_animFileIndex; + char *m_animFileName; + }; +public: + CWeaponModelInfo(void) : CSimpleModelInfo(MITYPE_WEAPON) { m_animFileIndex = -1; } + + virtual void SetAnimFile(const char *file); + virtual void ConvertAnimFileIndex(void); + virtual int GetAnimFileIndex(void) { return m_animFileIndex; } + + void Init(void); + void SetWeaponInfo(int32 weaponId); + int32 GetWeaponInfo(void); + void SetAtomic(int n, RpAtomic *atomic); +}; diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 14f68e52..93a478e5 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -218,6 +218,25 @@ CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha) return atomic; } +//--MIAMI: done +RpAtomic* +CVisibilityPlugins::RenderWeaponCB(RpAtomic *atomic) +{ + RwMatrix *m; + RwV3d view; + float maxdist, distsq; + CSimpleModelInfo *mi; + + mi = GetAtomicModelInfo(atomic); + m = RwFrameGetLTM(RpAtomicGetFrame(atomic)); + RwV3dSub(&view, RwMatrixGetPos(m), ms_pCameraPosn); + maxdist = mi->GetLodDistance(0); + distsq = RwV3dDotProduct(&view, &view); + if(distsq < maxdist*maxdist) + AtomicDefaultRenderCallBack(atomic); + return atomic; +} + RpAtomic* CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist) { diff --git a/src/rw/VisibilityPlugins.h b/src/rw/VisibilityPlugins.h index b367d7ee..e2fc4d19 100644 --- a/src/rw/VisibilityPlugins.h +++ b/src/rw/VisibilityPlugins.h @@ -46,6 +46,7 @@ public: static RpAtomic *RenderWheelAtomicCB(RpAtomic *atomic); static RpAtomic *RenderObjNormalAtomic(RpAtomic *atomic); static RpAtomic *RenderAlphaAtomic(RpAtomic *atomic, int alpha); + static RpAtomic *RenderWeaponCB(RpAtomic *atomic); static RpAtomic *RenderFadingAtomic(RpAtomic *atm, float dist); static RpAtomic *RenderVehicleHiDetailCB(RpAtomic *atomic); -- cgit v1.2.3