Skip to content

Commit 4bf5d32

Browse files
committed
Clean up
1 parent 549cc8f commit 4bf5d32

File tree

13 files changed

+237
-267
lines changed

13 files changed

+237
-267
lines changed

Client/game_sa/CAutomobileSA.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#define MAX_PASSENGER_COUNT 8
2222
#define MAX_DOORS 6 // also in CDamageManager
23-
#define CAR_NODES_NUM 25
2423

2524
class CBouncingPanelSAInterface
2625
{
@@ -38,7 +37,7 @@ class CAutomobileSAInterface : public CVehicleSAInterface
3837
public:
3938
CDamageManagerSAInterface m_damageManager;
4039
CDoorSAInterface m_doors[MAX_DOORS];
41-
RwFrame* m_aCarNodes[CAR_NODES_NUM];
40+
RwFrame* m_aCarNodes[static_cast<std::size_t>(eCarNodes::NUM_NODES)];
4241
CBouncingPanelSAInterface m_panels[3];
4342
CDoorSAInterface m_swingingChassis;
4443
CColPointSAInterface m_wheelColPoint[MAX_WHEELS];

Client/game_sa/CBikeSA.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@
1414
#include <game/CBike.h>
1515
#include "CVehicleSA.h"
1616

17-
namespace eBikeNodes
17+
enum class eBikeNodes
1818
{
19-
enum
20-
{
21-
NONE = 0,
22-
CHASIS,
23-
FORKS_FRONT,
24-
FORKS_REAR,
25-
WHEEL_FRONT,
26-
WHEEL_REAR,
27-
MUDGUARD,
28-
HANDLEBARS,
29-
MISC_A,
30-
MISC_B,
19+
NONE = 0,
20+
CHASSIS,
21+
FORKS_FRONT,
22+
FORKS_REAR,
23+
WHEEL_FRONT,
24+
WHEEL_REAR,
25+
MUDGUARD,
26+
HANDLEBARS,
27+
MISC_A,
28+
MISC_B,
3129

32-
NUM_NODES
33-
};
34-
}
30+
NUM_NODES
31+
};
3532

3633
struct sRideAnimData
3734
{
@@ -48,7 +45,7 @@ static_assert(sizeof(sRideAnimData) == 0x1C, "Invalid size for sRideAnimData");
4845
class CBikeSAInterface : public CVehicleSAInterface
4946
{
5047
public:
51-
RwFrame* m_apModelNodes[eBikeNodes::NUM_NODES];
48+
RwFrame* m_apModelNodes[static_cast<std::size_t>(eBikeNodes::NUM_NODES)];
5249
int8 m_bLeanMatrixCalculated;
5350
int8 pad0[3]; // Maybe prev value is int32
5451
int8 m_mLeanMatrix[72];

Client/game_sa/CBmxSA.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@
1414
#include <game/CBmx.h>
1515
#include "CBikeSA.h"
1616

17-
namespace eBmxNodes
17+
enum class eBmxNodes
1818
{
19-
enum
20-
{
21-
NONE = 0,
22-
CHASIS,
23-
FORKS_FRONT,
24-
FORKS_REAR,
25-
WHEEL_FRONT,
26-
WHEEL_REAR,
27-
HANDLEBARS,
28-
CHAINSET,
29-
PEDAL_R,
30-
PEDAL_L,
19+
NONE = 0,
20+
CHASSIS,
21+
FORKS_FRONT,
22+
FORKS_REAR,
23+
WHEEL_FRONT,
24+
WHEEL_REAR,
25+
HANDLEBARS,
26+
CHAINSET,
27+
PEDAL_R,
28+
PEDAL_L,
3129

32-
NUM_NODES
33-
};
34-
}
30+
NUM_NODES
31+
};
3532

3633
class CBmxSAInterface : public CBikeSAInterface
3734
{

Client/game_sa/CBoatSA.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,30 @@
1414
#include <game/CBoat.h>
1515
#include "CVehicleSA.h"
1616

17-
namespace eBoatNodes
17+
enum class eBoatNodes
1818
{
19-
enum
20-
{
21-
NONE = 0,
22-
MOVING,
23-
WINDSCREEN,
24-
RUDDER,
25-
FLAP_LEFT,
26-
FLAP_RIGHT,
27-
REARFLAP_LEFT,
28-
REARFLAP_RIGHT,
29-
STATIC_PROP,
30-
MOVING_PROP,
31-
STATIC_PROP2,
32-
MOVING_PROP2,
19+
NONE = 0,
20+
MOVING,
21+
WINDSCREEN,
22+
RUDDER,
23+
FLAP_LEFT,
24+
FLAP_RIGHT,
25+
REARFLAP_LEFT,
26+
REARFLAP_RIGHT,
27+
STATIC_PROP,
28+
MOVING_PROP,
29+
STATIC_PROP2,
30+
MOVING_PROP2,
3331

34-
NUM_NODES
35-
};
36-
}
32+
NUM_NODES
33+
};
3734

3835
class CBoatSAInterface : public CVehicleSAInterface
3936
{
4037
public:
4138
uint32 pad1[3]; // 1440
4239
uint32 BoatFlags; // 1452
43-
RwFrame* pBoatParts[eBoatNodes::NUM_NODES]; // 1456
40+
RwFrame* pBoatParts[static_cast<std::size_t>(eBoatNodes::NUM_NODES)]; // 1456
4441
uint32 pad2[3]; // 1500
4542
uint16 pad3; // 1512
4643
uint8 pad4[2]; // 1514

Client/game_sa/CTrainSA.h

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,27 @@
1414
#include "CVehicleSA.h"
1515
#include "CDoorSA.h"
1616

17-
namespace eTrainNode
17+
enum class eTrainNodes
1818
{
19-
enum
20-
{
21-
NONE = 0,
22-
DOOR_LF = 1,
23-
DOOR_RF = 2,
24-
WHEEL_RF1 = 3,
25-
WHEEL_RF2 = 4,
26-
WHEEL_RF3 = 5,
27-
WHEEL_RB1 = 6,
28-
WHEEL_RB2 = 7,
29-
WHEEL_RB3 = 8,
30-
WHEEL_LF1 = 9,
31-
WHEEL_LF2 = 10,
32-
WHEEL_LF3 = 11,
33-
WHEEL_LB1 = 12,
34-
WHEEL_LB2 = 13,
35-
WHEEL_LB3 = 14,
36-
BOGIE_FRONT = 15,
37-
BOGIE_REAR = 16,
38-
NUM_NODES
39-
};
19+
NONE = 0,
20+
DOOR_LF,
21+
DOOR_RF,
22+
WHEEL_RF1,
23+
WHEEL_RF2,
24+
WHEEL_RF3,
25+
WHEEL_RB1,
26+
WHEEL_RB2,
27+
WHEEL_RB3,
28+
WHEEL_LF1,
29+
WHEEL_LF2,
30+
WHEEL_LF3,
31+
WHEEL_LB1,
32+
WHEEL_LB2,
33+
WHEEL_LB3,
34+
BOGIE_FRONT,
35+
BOGIE_REAR,
36+
37+
NUM_NODES
4038
};
4139

4240
enum class eTrainPassengersGenerationState : unsigned char
@@ -101,7 +99,7 @@ class CTrainSAInterface : public CVehicleSAInterface
10199
CTrainSAInterface* m_prevCarriage;
102100
CTrainSAInterface* m_nextCarriage;
103101
CDoorSAInterface m_aDoors[MAX_DOORS];
104-
RwFrame* m_aTrainNodes[eTrainNode::NUM_NODES];
102+
RwFrame* m_aTrainNodes[static_cast<std::size_t>(eTrainNodes::NUM_NODES)];
105103
};
106104
static_assert(sizeof(CTrainSAInterface) == 0x6AC, "Invalid size for CTrainSAInterface");
107105

Client/game_sa/CVehicleSA.cpp

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,13 +1502,13 @@ void CVehicleSA::SetGravity(const CVector* pvecGravity)
15021502
m_vecGravity = *pvecGravity;
15031503
}
15041504

1505-
bool CVehicleSA::SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisionTypes collisionType, std::int32_t removalTime)
1505+
bool CVehicleSA::SpawnFlyingComponent(const eCarNodes& nodeIndex, const eCarComponentCollisionTypes& collisionType, std::int32_t removalTime)
15061506
{
1507-
if (nodeIndex < 1)
1507+
if (nodeIndex == eCarNodes::NONE)
15081508
return false;
15091509

15101510
DWORD nodesOffset = OFFSET_CAutomobile_Nodes;
1511-
RwFrame* defaultBikeChassisFrame;
1511+
RwFrame* defaultBikeChassisFrame = nullptr;
15121512

15131513
// CBike, CBmx, CBoat and CTrain don't inherit CAutomobile so let's do it manually!
15141514
switch (static_cast<VehicleClass>(GetVehicleInterface()->m_vehicleClass))
@@ -1525,11 +1525,7 @@ bool CVehicleSA::SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisio
15251525
}
15261526
case VehicleClass::TRAIN:
15271527
{
1528-
auto* trainInterface = static_cast<CTrainSAInterface*>(GetVehicleInterface());
1529-
if (!trainInterface)
1530-
return false;
1531-
1532-
if (nodeIndex >= sizeof(trainInterface->m_aTrainNodes) / sizeof(RwFrame*))
1528+
if (static_cast<eTrainNodes>(nodeIndex) >= eTrainNodes::NUM_NODES)
15331529
return false;
15341530

15351531
nodesOffset = OFFSET_CTrain_Nodes;
@@ -1542,30 +1538,26 @@ bool CVehicleSA::SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisio
15421538
if (!bikeInterface)
15431539
return false;
15441540

1545-
if (nodeIndex >= sizeof(bikeInterface->m_apModelNodes) / sizeof(RwFrame*))
1541+
if (static_cast<eBikeNodes>(nodeIndex) >= eBikeNodes::NUM_NODES)
15461542
return false;
15471543

15481544
nodesOffset = OFFSET_CBike_Nodes;
1549-
if (nodeIndex != 1)
1545+
if (static_cast<eBikeNodes>(nodeIndex) != eBikeNodes::CHASSIS)
15501546
break;
15511547

15521548
// Set the correct "bike_chassis" frame for bikes
15531549
defaultBikeChassisFrame = bikeInterface->m_apModelNodes[1];
15541550
if (defaultBikeChassisFrame && std::strcmp(defaultBikeChassisFrame->szName, "chassis_dummy") == 0)
15551551
{
1556-
RwFrame* correctChassisFrame = ((RwFrame * (__cdecl*)(RpClump*, const char*))FUNC_CClumpModelInfo_GetFrameFromName)(bikeInterface->m_pRwObject, "chassis");
1552+
RwFrame* correctChassisFrame = RwFrameFindFrame(RpGetFrame(bikeInterface->m_pRwObject), "chassis");
15571553
if (correctChassisFrame)
15581554
bikeInterface->m_apModelNodes[1] = correctChassisFrame;
15591555
}
15601556
break;
15611557
}
15621558
case VehicleClass::BOAT:
15631559
{
1564-
auto* boatInterface = static_cast<CBoatSAInterface*>(GetVehicleInterface());
1565-
if (!boatInterface)
1566-
return false;
1567-
1568-
if (nodeIndex >= sizeof(boatInterface->pBoatParts) / sizeof(RwFrame*))
1560+
if (static_cast<eBoatNodes>(nodeIndex) >= eBoatNodes::NUM_NODES)
15691561
return false;
15701562

15711563
nodesOffset = OFFSET_CBoat_Nodes;
@@ -1579,24 +1571,15 @@ bool CVehicleSA::SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisio
15791571
MemPut(0x6A85B3, nodesOffset);
15801572
MemPut(0x6A8631, nodesOffset);
15811573

1582-
DWORD dwInterface = (DWORD)GetInterface();
1583-
DWORD dwFunc = FUNC_CAutomobile__SpawnFlyingComponent;
1584-
DWORD dwReturn;
1585-
_asm
1586-
{
1587-
mov ecx, dwInterface
1588-
push collisionType
1589-
push nodeIndex
1590-
call dwFunc
1591-
mov dwReturn, eax
1592-
}
1574+
auto* componentObject = ((CObjectSAInterface * (__thiscall*)(CVehicleSAInterface*, int, int)) FUNC_CAutomobile__SpawnFlyingComponent)(GetVehicleInterface(), static_cast<int>(nodeIndex), static_cast<int>(collisionType));
15931575

15941576
// Restore default nodes array in CAutomobile::SpawnFlyingComponent
1577+
// CAutomobile::m_aCarNodes offset
15951578
MemPut(0x6A85B3, 0x648);
15961579
MemPut(0x6A8631, 0x648);
15971580

15981581
// Restore default chassis frame for bikes
1599-
if (nodeIndex == 1 && defaultBikeChassisFrame)
1582+
if (static_cast<eBikeNodes>(nodeIndex) == eBikeNodes::CHASSIS && defaultBikeChassisFrame)
16001583
{
16011584
auto* bikeInterface = static_cast<CBikeSAInterface*>(GetVehicleInterface());
16021585
if (bikeInterface && bikeInterface->m_apModelNodes)
@@ -1606,11 +1589,7 @@ bool CVehicleSA::SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisio
16061589
if (removalTime <= -1)
16071590
return true;
16081591

1609-
auto* componentObject = reinterpret_cast<CObjectSAInterface*>((DWORD*)dwReturn);
1610-
if (!componentObject)
1611-
return;
1612-
1613-
int CTimer_ms = *(int*)0xB7CB84; // CTimer::m_snTimeInMilliseconds
1592+
std::uint32_t CTimer_ms = *reinterpret_cast<std::uint32_t*>(VAR_CTimer_snTimeInMilliseconds);
16141593
componentObject->uiObjectRemovalTime = CTimer_ms + static_cast<std::uint32_t>(removalTime);
16151594

16161595
return true;
@@ -1623,16 +1602,16 @@ void CVehicleSA::SetWheelVisibility(eWheelPosition wheel, bool bVisible)
16231602
switch (wheel)
16241603
{
16251604
case FRONT_LEFT_WHEEL:
1626-
pFrame = vehicle->m_aCarNodes[CAR_NODE_WHEEL_LF];
1605+
pFrame = vehicle->m_aCarNodes[static_cast<std::size_t>(eCarNodes::WHEEL_LF)];
16271606
break;
16281607
case REAR_LEFT_WHEEL:
1629-
pFrame = vehicle->m_aCarNodes[CAR_NODE_WHEEL_LB];
1608+
pFrame = vehicle->m_aCarNodes[static_cast<std::size_t>(eCarNodes::WHEEL_LB)];
16301609
break;
16311610
case FRONT_RIGHT_WHEEL:
1632-
pFrame = vehicle->m_aCarNodes[CAR_NODE_WHEEL_RF];
1611+
pFrame = vehicle->m_aCarNodes[static_cast<std::size_t>(eCarNodes::WHEEL_RF)];
16331612
break;
16341613
case REAR_RIGHT_WHEEL:
1635-
pFrame = vehicle->m_aCarNodes[CAR_NODE_WHEEL_RB];
1614+
pFrame = vehicle->m_aCarNodes[static_cast<std::size_t>(eCarNodes::WHEEL_RB)];
16361615
break;
16371616
default:
16381617
break;

Client/game_sa/CVehicleSA.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct RwTexture;
106106
#define OFFSET_CBike_Nodes 0x5A0
107107
#define OFFSET_CBoat_Nodes 0x5B0
108108

109+
#define VAR_CTimer_snTimeInMilliseconds 0xB7CB84
110+
109111
struct SRailNodeSA
110112
{
111113
short sX; // x coordinate times 8
@@ -616,7 +618,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
616618
SharedUtil::SColor GetHeadLightColor() { return m_HeadLightColor; }
617619
void SetHeadLightColor(const SharedUtil::SColor color) { m_HeadLightColor = color; }
618620

619-
bool SpawnFlyingComponent(eCarNodes nodeIndex, eCarComponentCollisionTypes collisionType, std::int32_t removalTime = -1);
621+
bool SpawnFlyingComponent(const eCarNodes& nodeIndex, const eCarComponentCollisionTypes& collisionType, std::int32_t removalTime = -1);
620622
void SetWheelVisibility(eWheelPosition wheel, bool bVisible);
621623
CVector GetWheelPosition(eWheelPosition wheel);
622624

0 commit comments

Comments
 (0)