Skip to content

Commit 686ec5d

Browse files
committed
Move C3DMarkerSAInterface
1 parent 924c920 commit 686ec5d

File tree

10 files changed

+147
-111
lines changed

10 files changed

+147
-111
lines changed

Client/game_sa/C3DMarkerSA.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: game_sa/C3DMarkerSA.cpp
66
* PURPOSE: 3D Marker entity
77
*
8-
* Multi Theft Auto is available from http://www.multitheftauto.com/
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
99
*
1010
*****************************************************************************/
1111

@@ -40,14 +40,14 @@ CVector* C3DMarkerSA::GetPosition()
4040
return &GetInterface()->m_mat.vPos;
4141
}
4242

43-
DWORD C3DMarkerSA::GetType()
43+
e3DMarkerType C3DMarkerSA::GetType() const
4444
{
45-
return GetInterface()->m_nType;
45+
return static_cast<e3DMarkerType>(GetInterface()->m_nType);
4646
}
4747

48-
void C3DMarkerSA::SetType(DWORD dwType)
48+
void C3DMarkerSA::SetType(e3DMarkerType type)
4949
{
50-
GetInterface()->m_nType = (unsigned short)(dwType);
50+
GetInterface()->m_nType = type;
5151
}
5252

5353
bool C3DMarkerSA::IsActive()
@@ -60,22 +60,9 @@ DWORD C3DMarkerSA::GetIdentifier()
6060
return GetInterface()->m_nIdentifier;
6161
}
6262

63-
SharedUtil::SColor C3DMarkerSA::GetColor()
64-
{
65-
// From ABGR
66-
unsigned long ulABGR = GetInterface()->rwColour;
67-
SharedUtil::SColor color;
68-
color.A = (ulABGR >> 24) & 0xff;
69-
color.B = (ulABGR >> 16) & 0xff;
70-
color.G = (ulABGR >> 8) & 0xff;
71-
color.R = ulABGR & 0xff;
72-
return color;
73-
}
74-
7563
void C3DMarkerSA::SetColor(const SharedUtil::SColor color)
7664
{
77-
// To ABGR
78-
GetInterface()->rwColour = (color.A << 24) | (color.B << 16) | (color.G << 8) | color.R;
65+
GetInterface()->rwColour = RwColor{color.R, color.G, color.B, color.A};
7966
}
8067

8168
void C3DMarkerSA::SetPulsePeriod(WORD wPulsePeriod)

Client/game_sa/C3DMarkerSA.h

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,18 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: game_sa/C3DMarkerSA.h
66
* PURPOSE: Header file for 3D Marker entity class
77
*
8-
* Multi Theft Auto is available from http://www.multitheftauto.com/
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
99
*
1010
*****************************************************************************/
1111

1212
#pragma once
1313

1414
#include <game/C3DMarker.h>
15-
#include <CMatrix_Pad.h>
16-
17-
class C3DMarkerSAInterface
18-
{
19-
public:
20-
CMatrix_Padded m_mat; // local space to world space transform // 0
21-
DWORD dwPad, dwPad2; // not sure why we need these, it appears to be this way though (eAi) // 64/68
22-
RpClump* m_pRwObject; // 72
23-
DWORD* m_pMaterial; // 76
24-
25-
WORD m_nType; // 80
26-
bool m_bIsUsed; // has this marker been allocated this frame? // 82
27-
DWORD m_nIdentifier; // 84
28-
29-
DWORD rwColour; // 88
30-
WORD m_nPulsePeriod; // 92
31-
short m_nRotateRate; // deg per frame (in either direction) // 94
32-
DWORD m_nStartTime; // 96
33-
float m_fPulseFraction; // 100
34-
float m_fStdSize; // 104
35-
float m_fSize; // 108
36-
float m_fBrightness; // 112
37-
float m_fCameraRange; // 116
38-
39-
CVector m_normal; // Normal of the object point at // 120
40-
// the following variables remember the last time we read the heigh of the
41-
// map. Using this we don't have to do this every frame and we can still have moving markers.
42-
WORD m_LastMapReadX, m_LastMapReadY; // 132 / 134
43-
float m_LastMapReadResultZ; // 136
44-
float m_roofHeight; // 140
45-
CVector m_lastPosition; // 144
46-
DWORD m_OnScreenTestTime; // time last screen check was done // 156
47-
};
15+
#include "interfaces/C3DMarkerSAInterface.h"
4816

4917
class C3DMarkerSA : public C3DMarker
5018
{
@@ -55,16 +23,16 @@ class C3DMarkerSA : public C3DMarker
5523
C3DMarkerSA(C3DMarkerSAInterface* markerInterface) { internalInterface = markerInterface; };
5624

5725
C3DMarkerSAInterface* GetInterface() { return internalInterface; }
26+
C3DMarkerSAInterface* GetInterface() const { return internalInterface; }
5827

5928
void GetMatrix(CMatrix* pMatrix);
6029
void SetMatrix(CMatrix* pMatrix);
6130
void SetPosition(CVector* vecPosition);
6231
CVector* GetPosition();
63-
DWORD GetType(); // need enum?
64-
void SetType(DWORD dwType); // doesn't work propperly (not virtualed)
32+
e3DMarkerType GetType() const override;
33+
void SetType(e3DMarkerType type); // doesn't work propperly (not virtualed)
6534
bool IsActive();
6635
DWORD GetIdentifier();
67-
SharedUtil::SColor GetColor();
6836
void SetColor(const SharedUtil::SColor color); // actually BGRA
6937
void SetPulsePeriod(WORD wPulsePeriod);
7038
void SetRotateRate(short RotateRate);
@@ -78,5 +46,5 @@ class C3DMarkerSA : public C3DMarker
7846
void Disable();
7947
void Reset();
8048
void SetActive() { internalInterface->m_bIsUsed = true; }
81-
RpClump* GetRwObject() { return internalInterface->m_pRwObject; }
49+
RpClump* GetRwObject() { return reinterpret_cast<RpClump*>(internalInterface->m_pRwObject); }
8250
};

Client/game_sa/CEntitySA.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,6 @@ class CReferences
4848
CReference* m_pFreeList;
4949
};
5050

51-
class CMatrixEx
52-
{
53-
public:
54-
CMatrix_Padded matrix;
55-
CMatrix* pMatrix; // usually not initialized
56-
void* haveRwMatrix; // unknown pointer
57-
};
58-
59-
class XYZ
60-
{
61-
public:
62-
CMatrixEx matrix;
63-
class CPlaceableSAInterface* pRef;
64-
XYZ* pPrev;
65-
XYZ* pNext;
66-
};
67-
static_assert(sizeof(XYZ) == 0x54, "Invalid size for XYZ");
68-
69-
class XYZStore
70-
{
71-
public:
72-
XYZ head;
73-
XYZ tail;
74-
XYZ allocatedListHead;
75-
XYZ allocatedListTail;
76-
XYZ freeListHead;
77-
XYZ freeListTail;
78-
XYZ* pPool;
79-
};
80-
static_assert(sizeof(XYZStore) == 0x1FC, "Invalid size for XYZStore");
81-
8251
class CEntitySAInterface : public CPlaceableSAInterface
8352
{
8453
public:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/interfaces/C3DMarkerSAInterface.cpp
6+
* PURPOSE: 3D Marker game layer interface
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
#include "StdInc.h"
12+
#include "C3DMarkerSAInterface.h"
13+
14+
bool C3DMarkerSAInterface::AddMarker(std::uint32_t id, e3DMarkerType type, float size, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a, std::uint16_t pulsePeriod, float pulseFraction, std::int16_t rotateRate)
15+
{
16+
// Call C3dMarker::AddMarker
17+
return ((bool(__thiscall*)(C3DMarkerSAInterface*, std::uint32_t, std::uint16_t, float, std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t, std::uint16_t, float, std::int16_t))0x722230)(this, id, static_cast<std::uint16_t>(type), size, r, g, b, a, pulsePeriod, pulseFraction, rotateRate);
18+
}
19+
20+
void C3DMarkerSAInterface::DeleteMarkerObject()
21+
{
22+
// Call C3dMarker::DeleteMarkerObject
23+
((void(__thiscall*)(C3DMarkerSAInterface*))0x722390)(this);
24+
}
25+
26+
bool C3DMarkerSAInterface::IsZCoordinateUpToDate() const
27+
{
28+
const CVector& pos = m_mat.vPos;
29+
return m_LastMapReadX == static_cast<std::uint16_t>(pos.fX) && m_LastMapReadY == static_cast<std::uint16_t>(pos.fY);
30+
}
31+
32+
void C3DMarkerSAInterface::SetZCoordinateIfNotUpToDate(float newZPos)
33+
{
34+
if (!IsZCoordinateUpToDate())
35+
m_mat.vPos.fZ = newZPos;
36+
}
37+
38+
void C3DMarkerSAInterface::UpdateZCoordinate(CVector point, float zDistance)
39+
{
40+
// Call C3dMarker::UpdateZCoordinate
41+
((void(__thiscall*)(C3DMarkerSAInterface*, CVector, float))0x724D40)(this, point, zDistance);
42+
}
43+
44+
void C3DMarkerSAInterface::DeleteIfHasAtomic()
45+
{
46+
if (m_pRwObject)
47+
DeleteMarkerObject();
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/interfaces/C3DMarkerSAInterface.h
6+
* PURPOSE: Header file for 3D Marker game layer interface
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
#include <game/C3DMarker.h>
15+
#include <CMatrix_Pad.h>
16+
#include "game/RenderWare.h"
17+
18+
class C3DMarkerSAInterface
19+
{
20+
public:
21+
CMatrix_Padded m_mat; // local space to world space transform
22+
RpAtomic* m_pRwObject;
23+
RpMaterial* m_pMaterial;
24+
std::uint16_t m_nType; // e3DMarkerType
25+
bool m_bIsUsed; // has this marker been allocated this frame?
26+
bool m_mustBeRenderedThisFrame;
27+
std::uint32_t m_nIdentifier;
28+
RwColor rwColour;
29+
std::uint16_t m_nPulsePeriod;
30+
std::int16_t m_nRotateRate; // deg per frame (in either direction)
31+
std::uint32_t m_nStartTime;
32+
float m_fPulseFraction;
33+
float m_fStdSize;
34+
float m_fSize;
35+
float m_fBrightness;
36+
float m_fCameraRange;
37+
CVector m_normal; // Normal of the object point at
38+
39+
// The following variables remember the last time we read the height of the map.
40+
// Using this we don't have to do this every frame and we can still have moving markers.
41+
std::uint16_t m_LastMapReadX;
42+
std::uint16_t m_LastMapReadY;
43+
float m_LastMapReadResultZ;
44+
float m_roofHeight;
45+
CVector m_lastPosition;
46+
std::uint32_t m_OnScreenTestTime; // time last screen check was done
47+
48+
public:
49+
bool AddMarker(std::uint32_t id, e3DMarkerType type, float size, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a, std::uint16_t pulsePeriod,
50+
float pulseFraction, std::int16_t rotateRate);
51+
void DeleteMarkerObject();
52+
bool IsZCoordinateUpToDate() const;
53+
void SetZCoordinateIfNotUpToDate(float newZPos);
54+
void UpdateZCoordinate(CVector point, float zDistance);
55+
void DeleteIfHasAtomic();
56+
};
57+
static_assert(sizeof(C3DMarkerSAInterface) == 0xA0, "Invalid size for C3DMarkerSAInterface");

Client/game_sa/premake5.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ project "Game SA"
2424

2525
includedirs {
2626
"../../Shared/sdk",
27+
".",
2728
"../sdk/",
28-
"../../vendor/sparsehash/src/"
29+
"./interfaces",
30+
"../../vendor/sparsehash/src/",
2931
}
3032

3133
files {

Client/mods/deathmatch/logic/CClient3DMarker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ class CClient3DMarker : public CClientMarkerCommon
7373
C3DMarker* m_pMarker;
7474
unsigned int m_ulIdentifier;
7575
bool m_bMarkerStreamedIn;
76-
bool m_ignoreAlphaLimits;
76+
bool m_ignoreAlphaLimits{false};
7777
};

Client/sdk/game/C3DMarker.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: sdk/game/C3DMarker.h
66
* PURPOSE: 3D marker entity interface
77
*
8-
* Multi Theft Auto is available from http://www.multitheftauto.com/
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
99
*
1010
*****************************************************************************/
1111

@@ -29,10 +29,9 @@ class C3DMarker
2929
virtual void SetMatrix(CMatrix* pMatrix) = 0;
3030
virtual void SetPosition(CVector* vecPosition) = 0;
3131
virtual CVector* GetPosition() = 0;
32-
virtual DWORD GetType() = 0; // need enum?
32+
virtual e3DMarkerType GetType() const = 0;
3333
virtual bool IsActive() = 0;
3434
virtual DWORD GetIdentifier() = 0;
35-
virtual SharedUtil::SColor GetColor() = 0;
3635
virtual void SetColor(const SharedUtil::SColor color) = 0;
3736
virtual void SetPulsePeriod(WORD wPulsePeriod) = 0;
3837
virtual void SetPulseFraction(float fPulseFraction) = 0;

Client/sdk/game/Common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,9 @@ enum e3DMarkerType
753753
MARKER3D_TORUS,
754754
MARKER3D_CONE,
755755
MARKER3D_CONE_NO_COLLISION,
756-
MARKER3D_NUM
756+
MARKER3D_NUM,
757+
758+
NOT_ALLOCATED = 257, // see C3dMarker::DeleteMarkerObject
757759
};
758760

759761
enum eMarkerSprite

0 commit comments

Comments
 (0)