...
 
Commits (9)
......@@ -5,7 +5,7 @@
#include "CInternalRayCastStructure.hpp"
namespace urde {
const CCollisionPrimitive::Type CCollidableAABox::sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox");
constexpr CCollisionPrimitive::Type sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox");
u32 CCollidableAABox::sTableIndex = -1;
CCollidableAABox::CCollidableAABox() = default;
......
......@@ -12,7 +12,6 @@ bool AABox_AABox_Bool(const CInternalCollisionStructure&);
} // namespace Collide
class CCollidableAABox : public CCollisionPrimitive {
static const Type sType;
static u32 sTableIndex;
zeus::CAABox x10_aabox;
......
#include "CCollidableCollisionSurface.hpp"
namespace urde {
const CCollisionPrimitive::Type CCollidableCollisionSurface::sType(CCollidableCollisionSurface::SetStaticTableIndex,
"CCollidableCollisionSurface");
constexpr CCollisionPrimitive::Type sType(CCollidableCollisionSurface::SetStaticTableIndex,
"CCollidableCollisionSurface");
u32 CCollidableCollisionSurface::sTableIndex = -1;
const CCollisionPrimitive::Type& CCollidableCollisionSurface::GetType() { return sType; }
......
......@@ -5,7 +5,6 @@
namespace urde {
class CCollidableCollisionSurface {
static const CCollisionPrimitive::Type sType;
static u32 sTableIndex;
public:
......
......@@ -7,8 +7,7 @@
#include "CToken.hpp"
namespace urde {
const CCollisionPrimitive::Type CCollidableOBBTreeGroup::sType(CCollidableOBBTreeGroup::SetStaticTableIndex,
"CCollidableOBBTreeGroup");
constexpr CCollisionPrimitive::Type sType(CCollidableOBBTreeGroup::SetStaticTableIndex, "CCollidableOBBTreeGroup");
u32 CCollidableOBBTreeGroup::sTableIndex = -1;
CCollidableOBBTreeGroupContainer::CCollidableOBBTreeGroupContainer(CInputStream& in) {
......
......@@ -24,7 +24,6 @@ public:
};
class CCollidableOBBTreeGroup : public CCollisionPrimitive {
static const Type sType;
static u32 sTableIndex;
const CCollidableOBBTreeGroupContainer* x10_container;
......
......@@ -5,7 +5,7 @@
#include "CInternalRayCastStructure.hpp"
namespace urde {
const CCollisionPrimitive::Type CCollidableSphere::sType(CCollidableSphere::SetStaticTableIndex, "CCollidableSphere");
constexpr CCollisionPrimitive::Type sType(CCollidableSphere::SetStaticTableIndex, "CCollidableSphere");
u32 CCollidableSphere::sTableIndex = -1;
namespace Collide {
......@@ -224,6 +224,8 @@ CRayCastResult CCollidableSphere::CastRayInternal(const CInternalRayCastStructur
return {};
}
const CCollisionPrimitive::Type& CCollidableSphere::GetType() { return sType; }
bool CCollidableSphere::CollideMovingAABox(const CInternalCollisionStructure& collision, const zeus::CVector3f& dir,
double& dOut, CCollisionInfo& infoOut) {
const CCollidableSphere& p0 = static_cast<const CCollidableSphere&>(collision.GetLeft().GetPrim());
......
......@@ -12,8 +12,8 @@ bool Sphere_AABox_Bool(const CInternalCollisionStructure&);
bool Sphere_Sphere(const CInternalCollisionStructure&, CCollisionInfoList&);
bool Sphere_Sphere_Bool(const CInternalCollisionStructure&);
} // namespace Collide
class CCollidableSphere : public CCollisionPrimitive {
static const Type sType;
static u32 sTableIndex;
zeus::CSphere x10_sphere;
......@@ -31,7 +31,7 @@ public:
FourCC GetPrimType() const override;
CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const override;
static const Type& GetType() { return sType; }
static const Type& GetType();
static void SetStaticTableIndex(u32 index) { sTableIndex = index; }
static bool CollideMovingAABox(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&);
static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&);
......
......@@ -54,15 +54,15 @@ using PrimitiveSetter = void (*)(u32);
class CCollisionPrimitive {
public:
class Type {
PrimitiveSetter x0_setter;
const char* x4_info;
PrimitiveSetter x0_setter = nullptr;
const char* x4_info = nullptr;
public:
Type() = default;
Type(PrimitiveSetter setter, const char* info) : x0_setter(setter), x4_info(info) {}
constexpr Type() noexcept = default;
constexpr Type(PrimitiveSetter setter, const char* info) noexcept : x0_setter(setter), x4_info(info) {}
const char* GetInfo() const { return x4_info; }
PrimitiveSetter GetSetter() const { return x0_setter; }
constexpr const char* GetInfo() const noexcept { return x4_info; }
constexpr PrimitiveSetter GetSetter() const noexcept { return x0_setter; }
};
class Comparison {
......@@ -71,12 +71,12 @@ public:
const char* x8_type2;
public:
Comparison(ComparisonFunc collider, const char* type1, const char* type2)
constexpr Comparison(ComparisonFunc collider, const char* type1, const char* type2) noexcept
: x0_collider(collider), x4_type1(type1), x8_type2(type2) {}
ComparisonFunc GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
constexpr ComparisonFunc GetCollider() const noexcept { return x0_collider; }
constexpr const char* GetType1() const noexcept { return x4_type1; }
constexpr const char* GetType2() const noexcept { return x8_type2; }
};
class MovingComparison {
......@@ -85,12 +85,12 @@ public:
const char* x8_type2;
public:
MovingComparison(MovingComparisonFunc collider, const char* type1, const char* type2)
constexpr MovingComparison(MovingComparisonFunc collider, const char* type1, const char* type2) noexcept
: x0_collider(collider), x4_type1(type1), x8_type2(type2) {}
MovingComparisonFunc GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
constexpr MovingComparisonFunc GetCollider() const noexcept { return x0_collider; }
constexpr const char* GetType1() const noexcept { return x4_type1; }
constexpr const char* GetType2() const noexcept { return x8_type2; }
};
class BooleanComparison {
......@@ -99,12 +99,12 @@ public:
const char* x8_type2;
public:
BooleanComparison(BooleanComparisonFunc collider, const char* type1, const char* type2)
constexpr BooleanComparison(BooleanComparisonFunc collider, const char* type1, const char* type2) noexcept
: x0_collider(collider), x4_type1(type1), x8_type2(type2) {}
BooleanComparisonFunc GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
constexpr BooleanComparisonFunc GetCollider() const noexcept { return x0_collider; }
constexpr const char* GetType1() const noexcept { return x4_type1; }
constexpr const char* GetType2() const noexcept { return x8_type2; }
};
private:
......
#include "CCollisionResponseData.hpp"
#include "Particle/CParticleDataFactory.hpp"
#include "Particle/CDecalDescription.hpp"
#include "Particle/CSwooshDescription.hpp"
#include "Particle/CElectricDescription.hpp"
#include "Particle/CGenDescription.hpp"
#include "Graphics/CModel.hpp"
#include "CSimplePool.hpp"
#include "CRandom16.hpp"
#include "Runtime/Collision/CCollisionResponseData.hpp"
#include <array>
#include "Runtime/CRandom16.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Particle/CDecalDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CParticleDataFactory.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
namespace urde {
const EWeaponCollisionResponseTypes CCollisionResponseData::skWorldMaterialTable[32] = {
namespace {
constexpr std::array skWorldMaterialTable{
EWeaponCollisionResponseTypes::Default, EWeaponCollisionResponseTypes::Unknown2,
EWeaponCollisionResponseTypes::Metal, EWeaponCollisionResponseTypes::Grass,
EWeaponCollisionResponseTypes::Ice, EWeaponCollisionResponseTypes::Goo,
......@@ -28,9 +32,9 @@ const EWeaponCollisionResponseTypes CCollisionResponseData::skWorldMaterialTable
EWeaponCollisionResponseTypes::Default, EWeaponCollisionResponseTypes::Default,
};
const s32 CCollisionResponseData::kInvalidSFX = -1;
constexpr s32 kInvalidSFX = -1;
static const std::vector<FourCC> kWCRTSFXIDs = {
constexpr std::array<FourCC, 94> kWCRTSFXIDs{{
SBIG('NSFX'), SBIG('DSFX'), SBIG('CSFX'), SBIG('MSFX'), SBIG('GRFX'), SBIG('ICFX'), SBIG('GOFX'), SBIG('WSFX'),
SBIG('WTFX'), SBIG('2MUD'), SBIG('2LAV'), SBIG('2SAN'), SBIG('2PRJ'), SBIG('DCFX'), SBIG('DSFX'), SBIG('DSHX'),
SBIG('DEFX'), SBIG('ESFX'), SBIG('SHFX'), SBIG('BEFX'), SBIG('WWFX'), SBIG('TAFX'), SBIG('GTFX'), SBIG('SPFX'),
......@@ -43,9 +47,9 @@ static const std::vector<FourCC> kWCRTSFXIDs = {
SBIG('GHFX'), SBIG('SHFX'), SBIG('FHFX'), SBIG('HFFX'), SBIG('PHFX'), SBIG('MHFX'), SBIG('HBFX'), SBIG('PBHX'),
SBIG('IBHX'), SBIG('6SVA'), SBIG('6RPR'), SBIG('6MTR'), SBIG('6PDS'), SBIG('6FLB'), SBIG('6DRN'), SBIG('6MRE'),
SBIG('CHFX'), SBIG('JZHS'), SBIG('6ISE'), SBIG('6BSE'), SBIG('6ATB'), SBIG('6ATA'),
};
}};
static const std::vector<FourCC> kWCRTIDs = {
constexpr std::array<FourCC, 94> kWCRTIDs{{
SBIG('NODP'), SBIG('DEFS'), SBIG('CRTS'), SBIG('MTLS'), SBIG('GRAS'), SBIG('ICEE'), SBIG('GOOO'), SBIG('WODS'),
SBIG('WATR'), SBIG('1MUD'), SBIG('1LAV'), SBIG('1SAN'), SBIG('1PRJ'), SBIG('DCHR'), SBIG('DCHS'), SBIG('DCSH'),
SBIG('DENM'), SBIG('DESP'), SBIG('DESH'), SBIG('BTLE'), SBIG('WASP'), SBIG('TALP'), SBIG('PTGM'), SBIG('SPIR'),
......@@ -57,33 +61,49 @@ static const std::vector<FourCC> kWCRTIDs = {
SBIG('JZSP'), SBIG('3ISE'), SBIG('3BSE'), SBIG('3ATB'), SBIG('3ATA'), SBIG('BTSH'), SBIG('WWSH'), SBIG('TASH'),
SBIG('TGSH'), SBIG('SPSH'), SBIG('FPSH'), SBIG('FFSH'), SBIG('PSSH'), SBIG('BMSH'), SBIG('BFSH'), SBIG('PBSH'),
SBIG('IBSH'), SBIG('3SVA'), SBIG('3RPR'), SBIG('3MTR'), SBIG('3PDS'), SBIG('3FLB'), SBIG('3DRN'), SBIG('3MRE'),
SBIG('CHSH'), SBIG('JZSH'), SBIG('5ISE'), SBIG('5BSE'), SBIG('5ATB'), SBIG('5ATA')};
static const std::vector<FourCC> kWCRTDecalIDs = {SBIG('NCDL'), SBIG('DDCL'), SBIG('CODL'), SBIG('MEDL'), SBIG('GRDL'),
SBIG('ICDL'), SBIG('GODL'), SBIG('WODL'), SBIG('WTDL'), SBIG('3MUD'),
SBIG('3LAV'), SBIG('3SAN'), SBIG('CHDL'), SBIG('ENDL')};
SBIG('CHSH'), SBIG('JZSH'), SBIG('5ISE'), SBIG('5BSE'), SBIG('5ATB'), SBIG('5ATA'),
}};
constexpr std::array<FourCC, 14> kWCRTDecalIDs{{
SBIG('NCDL'),
SBIG('DDCL'),
SBIG('CODL'),
SBIG('MEDL'),
SBIG('GRDL'),
SBIG('ICDL'),
SBIG('GODL'),
SBIG('WODL'),
SBIG('WTDL'),
SBIG('3MUD'),
SBIG('3LAV'),
SBIG('3SAN'),
SBIG('CHDL'),
SBIG('ENDL'),
}};
using CPF = CParticleDataFactory;
} // Anonymous namespace
void CCollisionResponseData::AddParticleSystemToResponse(EWeaponCollisionResponseTypes type, CInputStream& in,
CSimplePool* resPool) {
int i = int(type);
std::vector<CAssetId> tracker;
tracker.resize(8);
const auto i = size_t(type);
const std::vector<CAssetId> tracker(8);
x0_generators[i].emplace(CPF::GetChildGeneratorDesc(in, resPool, tracker).m_token);
}
bool CCollisionResponseData::CheckAndAddDecalToResponse(FourCC clsId, CInputStream& in, CSimplePool* resPool) {
int i = 0;
size_t i = 0;
for (const FourCC& type : kWCRTDecalIDs) {
if (type == clsId) {
FourCC cls = CPF::GetClassID(in);
if (cls == SBIG('NONE'))
const FourCC cls = CPF::GetClassID(in);
if (cls == SBIG('NONE')) {
return true;
}
CAssetId id = u64(in.readUint32Big());
if (!id.IsValid())
const CAssetId id{u64(in.readUint32Big())};
if (!id.IsValid()) {
return true;
}
x20_decals[i].emplace(resPool->GetObj({FOURCC('DPSC'), id}));
return true;
......@@ -94,12 +114,13 @@ bool CCollisionResponseData::CheckAndAddDecalToResponse(FourCC clsId, CInputStre
}
bool CCollisionResponseData::CheckAndAddSoundFXToResponse(FourCC clsId, CInputStream& in) {
int i = 0;
size_t i = 0;
for (const FourCC& type : kWCRTSFXIDs) {
if (type == clsId) {
FourCC cls = CPF::GetClassID(in);
if (cls == SBIG('NONE'))
const FourCC cls = CPF::GetClassID(in);
if (cls == SBIG('NONE')) {
return true;
}
x10_sfx[i] = CPF::GetInt(in);
return true;
......@@ -111,7 +132,7 @@ bool CCollisionResponseData::CheckAndAddSoundFXToResponse(FourCC clsId, CInputSt
}
bool CCollisionResponseData::CheckAndAddParticleSystemToResponse(FourCC clsId, CInputStream& in, CSimplePool* resPool) {
int i = 0;
size_t i = 0;
for (const FourCC& type : kWCRTIDs) {
if (type == clsId) {
AddParticleSystemToResponse(EWeaponCollisionResponseTypes(i), in, resPool);
......@@ -134,13 +155,7 @@ bool CCollisionResponseData::CheckAndAddResourceToResponse(FourCC clsId, CInputS
}
CCollisionResponseData::CCollisionResponseData(CInputStream& in, CSimplePool* resPool)
: x30_RNGE(50.f), x34_FOFF(0.2f) {
x0_generators.resize(94);
x10_sfx.resize(94);
x20_decals.resize(94);
for (s32& id : x10_sfx)
id = kInvalidSFX;
: x0_generators(94), x10_sfx(94, kInvalidSFX), x20_decals(94) {
FourCC clsId = CPF::GetClassID(in);
if (clsId == UncookedResType()) {
CRandom16 rand;
......@@ -164,8 +179,9 @@ CCollisionResponseData::CCollisionResponseData(CInputStream& in, CSimplePool* re
const std::optional<TLockedToken<CGenDescription>>&
CCollisionResponseData::GetParticleDescription(EWeaponCollisionResponseTypes type) const {
if (x0_generators[u32(type)])
return x0_generators[u32(type)];
if (x0_generators[size_t(type)]) {
return x0_generators[size_t(type)];
}
bool foundType = false;
if (ResponseTypeIsEnemyNormal(type)) {
......@@ -179,22 +195,24 @@ CCollisionResponseData::GetParticleDescription(EWeaponCollisionResponseTypes typ
foundType = true;
}
if (foundType && !x0_generators[u32(type)])
if (foundType && !x0_generators[size_t(type)]) {
type = EWeaponCollisionResponseTypes::EnemyNormal;
}
if (!x0_generators[u32(type)] && type != EWeaponCollisionResponseTypes::None)
if (!x0_generators[size_t(type)] && type != EWeaponCollisionResponseTypes::None) {
type = EWeaponCollisionResponseTypes::Default;
}
return x0_generators[u32(type)];
return x0_generators[size_t(type)];
}
const std::optional<TLockedToken<CDecalDescription>>&
CCollisionResponseData::GetDecalDescription(EWeaponCollisionResponseTypes type) const {
return x20_decals[u32(type)];
return x20_decals[size_t(type)];
}
s32 CCollisionResponseData::GetSoundEffectId(EWeaponCollisionResponseTypes type) const {
if (x10_sfx[u32(type)] == kInvalidSFX) {
if (x10_sfx[size_t(type)] == kInvalidSFX) {
if (ResponseTypeIsEnemyNormal(type))
type = EWeaponCollisionResponseTypes::EnemyNormal;
else if (ResponseTypeIsEnemySpecial(type))
......@@ -205,12 +223,13 @@ s32 CCollisionResponseData::GetSoundEffectId(EWeaponCollisionResponseTypes type)
type = EWeaponCollisionResponseTypes::Default;
}
return x10_sfx[u32(type)];
return x10_sfx[size_t(type)];
}
EWeaponCollisionResponseTypes CCollisionResponseData::GetWorldCollisionResponseType(s32 id) {
if (id < 0 || id >= 32)
if (id < 0 || size_t(id) >= skWorldMaterialTable.size()) {
return EWeaponCollisionResponseTypes::Default;
}
return skWorldMaterialTable[id];
}
......
......@@ -113,13 +113,11 @@ enum class EWeaponCollisionResponseTypes {
};
class CCollisionResponseData {
static const EWeaponCollisionResponseTypes skWorldMaterialTable[32];
static const s32 kInvalidSFX;
std::vector<std::optional<TLockedToken<CGenDescription>>> x0_generators;
std::vector<s32> x10_sfx;
std::vector<std::optional<TLockedToken<CDecalDescription>>> x20_decals;
float x30_RNGE;
float x34_FOFF;
float x30_RNGE = 50.0f;
float x34_FOFF = 0.2f;
void AddParticleSystemToResponse(EWeaponCollisionResponseTypes type, CInputStream& in, CSimplePool* resPool);
bool CheckAndAddDecalToResponse(FourCC clsId, CInputStream& in, CSimplePool* resPool);
......@@ -129,20 +127,18 @@ class CCollisionResponseData {
public:
CCollisionResponseData(CInputStream& in, CSimplePool* resPool);
const std::optional<TLockedToken<CGenDescription>>&
GetParticleDescription(EWeaponCollisionResponseTypes) const;
const std::optional<TLockedToken<CDecalDescription>>&
GetDecalDescription(EWeaponCollisionResponseTypes type) const;
s32 GetSoundEffectId(EWeaponCollisionResponseTypes) const;
static EWeaponCollisionResponseTypes GetWorldCollisionResponseType(s32);
static bool ResponseTypeIsEnemyShielded(EWeaponCollisionResponseTypes);
static bool ResponseTypeIsEnemyNormal(EWeaponCollisionResponseTypes);
static bool ResponseTypeIsEnemySpecial(EWeaponCollisionResponseTypes);
const std::optional<TLockedToken<CGenDescription>>& GetParticleDescription(EWeaponCollisionResponseTypes type) const;
const std::optional<TLockedToken<CDecalDescription>>& GetDecalDescription(EWeaponCollisionResponseTypes type) const;
s32 GetSoundEffectId(EWeaponCollisionResponseTypes type) const;
static EWeaponCollisionResponseTypes GetWorldCollisionResponseType(s32 id);
static bool ResponseTypeIsEnemyShielded(EWeaponCollisionResponseTypes type);
static bool ResponseTypeIsEnemyNormal(EWeaponCollisionResponseTypes type);
static bool ResponseTypeIsEnemySpecial(EWeaponCollisionResponseTypes type);
float GetAudibleRange() const { return x30_RNGE; }
float GetAudibleFallOff() const { return x34_FOFF; }
static FourCC UncookedResType();
};
CFactoryFnReturn FCollisionResponseDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference*);
CObjectReference* selfRef);
} // namespace urde