-
-
Notifications
You must be signed in to change notification settings - Fork 463
Extract SA interfaces to separate files #1 (C3DMarkerSAInterface) #4063
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,18 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: game_sa/C3DMarkerSA.h | ||
* PURPOSE: Header file for 3D Marker entity class | ||
* | ||
* Multi Theft Auto is available from http://www.multitheftauto.com/ | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <game/C3DMarker.h> | ||
#include <CMatrix_Pad.h> | ||
|
||
class C3DMarkerSAInterface | ||
{ | ||
public: | ||
CMatrix_Padded m_mat; // local space to world space transform // 0 | ||
DWORD dwPad, dwPad2; // not sure why we need these, it appears to be this way though (eAi) // 64/68 | ||
RpClump* m_pRwObject; // 72 | ||
DWORD* m_pMaterial; // 76 | ||
|
||
WORD m_nType; // 80 | ||
bool m_bIsUsed; // has this marker been allocated this frame? // 82 | ||
DWORD m_nIdentifier; // 84 | ||
|
||
DWORD rwColour; // 88 | ||
WORD m_nPulsePeriod; // 92 | ||
short m_nRotateRate; // deg per frame (in either direction) // 94 | ||
DWORD m_nStartTime; // 96 | ||
float m_fPulseFraction; // 100 | ||
float m_fStdSize; // 104 | ||
float m_fSize; // 108 | ||
float m_fBrightness; // 112 | ||
float m_fCameraRange; // 116 | ||
|
||
CVector m_normal; // Normal of the object point at // 120 | ||
// the following variables remember the last time we read the heigh of the | ||
// map. Using this we don't have to do this every frame and we can still have moving markers. | ||
WORD m_LastMapReadX, m_LastMapReadY; // 132 / 134 | ||
float m_LastMapReadResultZ; // 136 | ||
float m_roofHeight; // 140 | ||
CVector m_lastPosition; // 144 | ||
DWORD m_OnScreenTestTime; // time last screen check was done // 156 | ||
}; | ||
#include "interfaces/C3DMarkerSAInterface.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is interesting, but i think there were some sort of design choices involved. So we store SA interfaces and wrappers in the same file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that generally the separation of MTA wrappers and SA internal structures is reasonable. I don't think that this can harm the existed code in any way. |
||
|
||
class C3DMarkerSA : public C3DMarker | ||
{ | ||
|
@@ -55,16 +23,16 @@ class C3DMarkerSA : public C3DMarker | |
C3DMarkerSA(C3DMarkerSAInterface* markerInterface) { internalInterface = markerInterface; }; | ||
|
||
C3DMarkerSAInterface* GetInterface() { return internalInterface; } | ||
C3DMarkerSAInterface* GetInterface() const { return internalInterface; } | ||
|
||
void GetMatrix(CMatrix* pMatrix); | ||
void SetMatrix(CMatrix* pMatrix); | ||
void SetPosition(CVector* vecPosition); | ||
CVector* GetPosition(); | ||
DWORD GetType(); // need enum? | ||
void SetType(DWORD dwType); // doesn't work propperly (not virtualed) | ||
e3DMarkerType GetType() const override; | ||
void SetType(e3DMarkerType type); // doesn't work propperly (not virtualed) | ||
bool IsActive(); | ||
DWORD GetIdentifier(); | ||
SharedUtil::SColor GetColor(); | ||
void SetColor(const SharedUtil::SColor color); // actually BGRA | ||
void SetPulsePeriod(WORD wPulsePeriod); | ||
void SetRotateRate(short RotateRate); | ||
|
@@ -78,5 +46,5 @@ class C3DMarkerSA : public C3DMarker | |
void Disable(); | ||
void Reset(); | ||
void SetActive() { internalInterface->m_bIsUsed = true; } | ||
RpClump* GetRwObject() { return internalInterface->m_pRwObject; } | ||
RpClump* GetRwObject() { return reinterpret_cast<RpClump*>(internalInterface->m_pRwObject); } | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: game_sa/interfaces/C3DMarkerSAInterface.cpp | ||
* PURPOSE: 3D Marker game layer interface | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
#include "StdInc.h" | ||
#include "C3DMarkerSAInterface.h" | ||
|
||
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) | ||
{ | ||
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); | ||
} | ||
|
||
void C3DMarkerSAInterface::DeleteMarkerObject() | ||
{ | ||
((void(__thiscall*)(C3DMarkerSAInterface*))0x722390)(this); | ||
} | ||
|
||
bool C3DMarkerSAInterface::IsZCoordinateUpToDate() const | ||
{ | ||
const CVector& pos = m_mat.GetPosition(); | ||
return m_LastMapReadX == static_cast<std::uint16_t>(pos.fX) && m_LastMapReadY == static_cast<std::uint16_t>(pos.fY); | ||
} | ||
|
||
void C3DMarkerSAInterface::SetZCoordinateIfNotUpToDate(float newZPos) | ||
{ | ||
if (!IsZCoordinateUpToDate()) | ||
{ | ||
CVector& pos = m_mat.GetPosition(); | ||
pos.fZ = newZPos; | ||
} | ||
} | ||
|
||
void C3DMarkerSAInterface::UpdateZCoordinate(CVector point, float zDistance) | ||
{ | ||
((void(__thiscall*)(C3DMarkerSAInterface*, CVector, float))0x724D40)(this, point, zDistance); | ||
} | ||
|
||
void C3DMarkerSAInterface::DeleteIfHasAtomic() | ||
{ | ||
if (m_pRwObject) | ||
DeleteMarkerObject(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: game_sa/interfaces/C3DMarkerSAInterface.h | ||
* PURPOSE: Header file for 3D Marker game layer interface | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <game/C3DMarker.h> | ||
#include "game/RenderWare.h" | ||
#include "../CMatrixSA.h" | ||
|
||
class C3DMarkerSAInterface | ||
{ | ||
public: | ||
CMatrixSAInterface m_mat; // local space to world space transform | ||
RpAtomic* m_pRwObject; | ||
RpMaterial* m_pMaterial; | ||
std::uint16_t m_nType; // e3DMarkerType | ||
bool m_bIsUsed; // has this marker been allocated this frame? | ||
bool m_mustBeRenderedThisFrame; | ||
std::uint32_t m_nIdentifier; | ||
RwColor rwColour; | ||
std::uint16_t m_nPulsePeriod; | ||
std::int16_t m_nRotateRate; // deg per frame (in either direction) | ||
std::uint32_t m_nStartTime; | ||
float m_fPulseFraction; | ||
float m_fStdSize; | ||
float m_fSize; | ||
float m_fBrightness; | ||
float m_fCameraRange; | ||
CVector m_normal; // Normal of the object point at | ||
|
||
// The following variables remember the last time we read the height of the map. | ||
// Using this we don't have to do this every frame and we can still have moving markers. | ||
std::uint16_t m_LastMapReadX; | ||
std::uint16_t m_LastMapReadY; | ||
float m_LastMapReadResultZ; | ||
float m_roofHeight; | ||
CVector m_lastPosition; | ||
std::uint32_t m_OnScreenTestTime; // time last screen check was done | ||
|
||
public: | ||
inline 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, | ||
float pulseFraction, std::int16_t rotateRate); | ||
inline void DeleteMarkerObject(); | ||
inline bool IsZCoordinateUpToDate() const; | ||
inline void SetZCoordinateIfNotUpToDate(float newZPos); | ||
inline void UpdateZCoordinate(CVector point, float zDistance); | ||
inline void DeleteIfHasAtomic(); | ||
}; | ||
static_assert(sizeof(C3DMarkerSAInterface) == 0xA0, "Invalid size for C3DMarkerSAInterface"); |
Uh oh!
There was an error while loading. Please reload this page.