Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
22a476c
Merge pull request #2 from multitheftauto/master
CrosRoad95 May 30, 2018
d9229bc
Merge pull request #3 from multitheftauto/master
CrosRoad95 Jun 1, 2018
6e3ea50
Merge pull request #4 from multitheftauto/master
CrosRoad95 Jun 23, 2018
ec62964
Merge pull request #5 from multitheftauto/master
CrosRoad95 Jun 29, 2018
ad8eb2f
test 1
CrosRoad95 Jun 30, 2018
6591fc1
Merge pull request #7 from multitheftauto/master
CrosRoad95 Jul 1, 2018
fb084fc
Merge pull request #9 from multitheftauto/master
CrosRoad95 Jul 2, 2018
3055613
Merge pull request #10 from multitheftauto/master
CrosRoad95 Jul 4, 2018
f5dd372
Merge pull request #10 from multitheftauto/master
CrosRoad95 Jul 4, 2018
86baf91
removed pathfinding from master
CrosRoad95 Jul 4, 2018
9258936
Merge remote-tracking branch 'origin/master'
CrosRoad95 Jul 12, 2018
6fd451b
Merge remote-tracking branch 'origin/master'
CrosRoad95 Sep 21, 2018
f71c7b0
Merge pull request #11 from multitheftauto/master
CrosRoad95 Sep 22, 2018
ef48974
Merge remote-tracking branch 'origin/master'
CrosRoad95 Sep 22, 2018
46104d1
Merge branch 'master' into test
CrosRoad95 Sep 23, 2018
f29ae6d
engineGetModelCollisionProperties and engineGetModelCollisionData
CrosRoad95 Sep 23, 2018
af03ec5
set and get function almost done, beginnings of creating new shapes
CrosRoad95 Sep 23, 2018
85aecc8
updating bounding box, for now only box collisions
CrosRoad95 Sep 24, 2018
ebf9905
bounding box function improved
CrosRoad95 Sep 25, 2018
4ea64d4
a bit refactor
CrosRoad95 Sep 26, 2018
dccdec2
creating triangle
CrosRoad95 Sep 27, 2018
1037be4
update
CrosRoad95 Sep 28, 2018
9c58e52
index argument for engineGetModelCollisionData
CrosRoad95 Sep 28, 2018
a6a2ce4
upgraded, added many check for arguments
CrosRoad95 Sep 29, 2018
bada30a
added function for getting model collision
CrosRoad95 Sep 29, 2018
55eacc9
engineModelIsCollisionLoaded function
CrosRoad95 Sep 29, 2018
9ce7e11
renemed function for checking collision
CrosRoad95 Sep 30, 2018
08bb127
removed unnecessary condition
CrosRoad95 Sep 30, 2018
74233e1
a bit refactor, and test of restoring collision
CrosRoad95 Sep 30, 2018
03ca694
removing collision boxes
CrosRoad95 Sep 30, 2018
acf7efa
removing triangles and vertices test
CrosRoad95 Oct 4, 2018
b940020
almost finished restoring, test for removing collision
CrosRoad95 Oct 6, 2018
b8f8e00
Merge pull request #15 from multitheftauto/master
CrosRoad95 Nov 13, 2018
5e98d3c
fix and removed create & destroy functions for future pr
CrosRoad95 Nov 21, 2018
82f9dfa
refactor, updated each function, removed create/remove functions
CrosRoad95 Nov 25, 2018
a4301fb
Merge remote-tracking branch 'origin/master' into test
CrosRoad95 Dec 17, 2018
454fb1f
removed unneded declaration
CrosRoad95 Dec 17, 2018
82aa84c
updated
CrosRoad95 Jan 16, 2019
061b858
Merge remote-tracking branch 'upstream/master' into test
patrikjuvonen Feb 23, 2019
0873320
Merge remote-tracking branch 'upstream/master' into test
patrikjuvonen Feb 23, 2019
4547c91
Fix formatting
patrikjuvonen Feb 23, 2019
f4a7069
Add missing return on error
patrikjuvonen Feb 23, 2019
b65846c
Return nullptr instead
patrikjuvonen Feb 23, 2019
5d8187f
Fix formatting, addendum to 4547c91844b81d31a1643e6bccd1dabef5166284
patrikjuvonen Feb 23, 2019
50376a8
Use const where possible
patrikjuvonen Feb 23, 2019
6f2ea46
Use range-based loop
patrikjuvonen Feb 23, 2019
f896206
Merge branch 'test' of https://github.com/CrosRoad95/mtasa-blue into …
patrikjuvonen Feb 23, 2019
f3d5bc8
Fix formatting, addendum to 5d8187ff71ebbe7bf68678ee48892fb8aa03e879
patrikjuvonen Feb 24, 2019
4c151d9
Get rid of lua_pushtablevalue
patrikjuvonen Feb 24, 2019
9529a0b
Merge branch 'master' into test
CrosRoad95 Oct 13, 2019
4a33097
Merge branch 'master' into test
qaisjp Apr 2, 2020
c487e0e
Merge branch 'master' into test
qaisjp Apr 2, 2020
c63b525
Update Client/mods/deathmatch/logic/CClientColModel.h
CrosRoad95 May 4, 2020
f46f529
Update Client/mods/deathmatch/logic/CClientColModel.h
CrosRoad95 May 4, 2020
8825887
Update Client/mods/deathmatch/logic/CClientColModel.h
CrosRoad95 May 4, 2020
9ff0ca6
Update Client/mods/deathmatch/logic/CClientColModel.h
CrosRoad95 May 24, 2020
e736462
Merge remote-tracking branch 'mta/master' into test
CrosRoad95 May 24, 2020
f2678a5
Merge remote-tracking branch 'origin/test' into test
CrosRoad95 May 24, 2020
31b51a7
fixing conflicts
CrosRoad95 May 24, 2020
ad31524
try to change to enumclass
CrosRoad95 May 24, 2020
d1c36e8
not working
CrosRoad95 May 31, 2020
9327756
Merge remote-tracking branch 'origin/master' into test
CrosRoad95 Aug 14, 2020
c53ab6b
Merge remote-tracking branch 'origin/master' into test
CrosRoad95 Sep 6, 2020
10ddd8f
Merge branch 'master' into test
StrixG Oct 17, 2020
e2d7493
Merge branch 'master' into test
StrixG Oct 18, 2020
c508ac3
Fix eCollisionShape enum
StrixG Oct 18, 2020
439a174
Merge remote-tracking branch 'origin/master' into test
CrosRoad95 Nov 1, 2020
236bc91
use new parser
CrosRoad95 Nov 1, 2020
41e7ef3
Fix arg parser compilation
sbx320 Nov 1, 2020
505c11d
fix compilation
CrosRoad95 Nov 2, 2020
6c3ba18
rename variables
CrosRoad95 Nov 3, 2020
ddc7259
Merge branch 'master' into test
Nov 27, 2020
2898a50
Merge branch 'master' into test
CrosRoad95 Apr 25, 2021
671268b
revert some unnecessary changes
CrosRoad95 Apr 25, 2021
d6fd63b
remove even more unnecessary changes
CrosRoad95 Apr 25, 2021
d430db0
refactor getData to use new parser
CrosRoad95 Apr 25, 2021
a3572b1
Merge branch 'master' into test
patrikjuvonen Aug 4, 2021
75e1d8d
Update CColModelSA.h
patrikjuvonen Aug 4, 2021
ac881de
Update CClientColModel.cpp
patrikjuvonen Aug 4, 2021
eb8557e
Update CLuaEngineDefs.cpp
patrikjuvonen Aug 4, 2021
b094621
Update CLuaEngineDefs.cpp
patrikjuvonen Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 122 additions & 12 deletions Client/game_sa/CColModelSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include <windows.h>
#include <game/CColModel.h>

#define FUNC_CColModel_Constructor 0x40FB60
#define FUNC_CColModel_Destructor 0x40F700
#define FUNC_CColModel_Constructor 0x40FB60
#define FUNC_CColModel_Destructor 0x40F700

enum class eCollisionShape;

typedef struct
{
Expand All @@ -27,22 +29,28 @@ typedef struct

typedef struct
{
CVector vecCenter;
float fRadius;
CVector vecCenter;
float fRadius;
uchar material;
uchar flags;
CColLighting lighting;
uchar light;
} CColSphereSA;

typedef struct
{
CVector min;
CVector max;
CVector min;
CVector max;
uchar material;
uchar flags;
CColLighting lighting;
uchar light;
} CColBoxSA;

typedef struct
{
unsigned short v1;
unsigned short v2;
unsigned short v3;
EColSurface material;
unsigned short vertex[3];
uchar material;
CColLighting lighting;
} CColTriangleSA;

Expand All @@ -58,19 +66,121 @@ typedef struct
char name[0x18];
} ColModelFileHeader;

typedef struct
{
CVector m_vecStart;
float m_fStartSize;
CVector m_vecEnd;
float m_fEndSize;
} CColLine;

typedef struct
{
CVector m_vecStart;
float m_fStartRadius;
unsigned char m_nMaterial;
unsigned char m_nPiece;
unsigned char m_nLighting;
char _pad13;
CVector m_vecEnd;
float m_fEndRadius;
} CColDisk;

typedef struct
{
signed __int16 x;
signed __int16 y;
signed __int16 z;
CVector getVector() const { return CVector(x * 0.0078125f, y * 0.0078125f, z * 0.0078125f); }
void setVector(CVector vec)
{
x = static_cast<signed __int16>(vec.fX * 128);
y = static_cast<signed __int16>(vec.fY * 128);
z = static_cast<signed __int16>(vec.fZ * 128);
}
} CompressedVector;
Comment on lines +91 to +101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use std::int16_t? You'll need to include the header #include <cstdint>.


typedef struct
{
WORD numColSpheres;
WORD numColBoxes;
WORD numColTriangles;
BYTE ucNumWheels;
BYTE pad3;
BYTE m_nFlags;
CColSphereSA* pColSpheres;
CColBoxSA* pColBoxes;
void* pSuspensionLines;
void* pUnknown;
CompressedVector* pVertices;
CColTriangleSA* pColTriangles;
CColTrianglePlaneSA* pColTrianglePlanes;
unsigned int m_nNumShadowTriangles;
unsigned int m_nNumShadowVertices;
CompressedVector* m_pShadowVertices;
CColTriangleSA* m_pShadowTriangles;

std::map<ushort, CompressedVector> getAllVertices() const
{
std::map<ushort, CompressedVector> vertices;
for (uint i = 0; numColTriangles > i; i++)
{
vertices[pColTriangles[i].vertex[0]] = pVertices[pColTriangles[i].vertex[0]];
vertices[pColTriangles[i].vertex[1]] = pVertices[pColTriangles[i].vertex[1]];
vertices[pColTriangles[i].vertex[2]] = pVertices[pColTriangles[i].vertex[2]];
}
return vertices;
}

unsigned short getNumVertices() const
{
unsigned short numVertices = 0;
for (uint i = 0; numColTriangles > i; i++)
{
numVertices = std::max(std::max(numVertices, pColTriangles[i].vertex[0]), std::max(pColTriangles[i].vertex[1], pColTriangles[i].vertex[2]));
}
return numVertices;
}

bool isValidIndex(eCollisionShape eShape, ushort usIndex, ushort numVertices = 0) const
{
switch (eShape)
{
case eCollisionShape::BOX:
return (usIndex >= 0 && usIndex < numColBoxes);
break;
case eCollisionShape::SPHERE:
return (usIndex >= 0 && usIndex < numColSpheres);
break;
case eCollisionShape::TRIANGLE:
return (usIndex >= 0 && usIndex < numColTriangles);
break;
case eCollisionShape::VERTEX:
return (usIndex >= 0 && usIndex < numVertices);
break;
}
return false;
}

std::vector<ushort> getTrianglesByVertex(ushort usVertex) const
{
std::vector<ushort> vecTriangles;
CColTriangleSA colTriangle;
for (ushort i = 0; i < numColTriangles; i++)
{
colTriangle = pColTriangles[i];
if (colTriangle.vertex[0] == usVertex || colTriangle.vertex[1] == usVertex || colTriangle.vertex[2] == usVertex)
vecTriangles.push_back(i);
}
return vecTriangles;
}

std::map<ushort, ushort> getVerticesUsage() const
{
std::map<ushort, ushort> verticesUsage;
for (ushort i = 0; i < numColTriangles; i++)
for (char cVertex = 0; cVertex < 3; cVertex++)
verticesUsage[pColTriangles[i].vertex[cVertex]]++;
return verticesUsage;
}
} CColDataSA;

class CColModelSAInterface
Expand Down
23 changes: 20 additions & 3 deletions Client/mods/deathmatch/logic/CClientColModel.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* (Shared logic for modifications)
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/CClientColModel.cpp
* FILE: mods/deathmatch/logic/CClientColModel.cpp
* PURPOSE: Model collision (.col file) entity class
*
*****************************************************************************/

#include "StdInc.h"
#include "../Client/game_sa/CModelInfoSA.h"
#include "../Client/game_sa/CColModelSA.h"
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we are allowed to include stuff from game_sa


CClientColModel::CClientColModel(CClientManager* pManager, ElementID ID) : ClassInit(this), CClientEntity(ID)
{
Expand Down Expand Up @@ -158,3 +159,19 @@ bool CClientColModel::IsCOLData(const SString& strData)
{
return strData.length() > 32 && memcmp(strData, "COL", 3) == 0 && strData[7] == 0;
}

CColModelSAInterface* CClientColModel::GetColModelInterface()
{
if (m_pColModel)
return m_pColModel->GetInterface();
return nullptr;
}

void CClientColModel::UpdateVerticesCount()
{
CColModelSAInterface* pInterface = GetColModelInterface();
CColDataSA* pColData = pInterface->pColData;

if (pColData)
m_iVerticesCount = static_cast<unsigned short>(pColData->getNumVertices());
}
71 changes: 64 additions & 7 deletions Client/mods/deathmatch/logic/CClientColModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#include <list>
#include "CClientEntity.h"

class CClientColModel final : public CClientEntity
constexpr int MaxCollisionSize = 128; // collision bounding box in each axis
constexpr int MaxCollisionSize2 = MaxCollisionSize * 2;

class CClientColModel : public CClientEntity
{
DECLARE_CLASS(CClientColModel, CClientEntity)
public:
Expand All @@ -22,17 +25,66 @@ class CClientColModel final : public CClientEntity

eClientEntityType GetType() const { return CCLIENTCOL; }

bool LoadCol(const SString& strFile, bool bIsRawData);
bool Load(bool isRaw, SString input);

bool IsLoaded() { return m_pColModel != NULL; };
bool LoadCol(const SString& strFile, bool bIsRawData);
bool Load(bool isRaw, SString input);
int GetVerticesCount() const { return m_iVerticesCount; };
void SetCollisionHasChanged(bool bChanged) { b_hasChanged = bChanged; };
bool HasChanged() const { return b_hasChanged; };
bool IsLoaded() { return m_pColModel != NULL; };

bool Replace(unsigned short usModel);
void Restore(unsigned short usModel);
void RestoreAll();

bool HasReplaced(unsigned short usModel);
static bool IsCOLData(const SString& strData);
static bool CheckVector(CVector& vec, float fRadius = 0)
{
if (fRadius > 0)
{
return (MaxCollisionSize >= vec.fX + fRadius && vec.fX + fRadius >= -MaxCollisionSize && MaxCollisionSize >= vec.fY + fRadius &&
vec.fY + fRadius >= -MaxCollisionSize && MaxCollisionSize >= vec.fZ + fRadius && vec.fZ + fRadius >= -MaxCollisionSize) &&
(MaxCollisionSize >= vec.fX - fRadius && vec.fX - fRadius >= -MaxCollisionSize && MaxCollisionSize >= vec.fY - fRadius &&
vec.fY - fRadius >= -MaxCollisionSize && MaxCollisionSize >= vec.fZ - fRadius && vec.fZ - fRadius >= -MaxCollisionSize);
}
return (MaxCollisionSize >= vec.fX && vec.fX >= -MaxCollisionSize && MaxCollisionSize >= vec.fY && vec.fY >= -MaxCollisionSize &&
MaxCollisionSize >= vec.fZ && vec.fZ >= -MaxCollisionSize);
}
static bool CheckMoveVector(CVector& vec, float fRadius = 0)
{
if (fRadius > 0)
{
return ((MaxCollisionSize2 >= vec.fX + fRadius >= -MaxCollisionSize2 && MaxCollisionSize2 >= vec.fY + fRadius >= -MaxCollisionSize2 &&
MaxCollisionSize2 >= vec.fZ + fRadius >= -MaxCollisionSize2) &&
(MaxCollisionSize2 >= vec.fX - fRadius >= -MaxCollisionSize2 && MaxCollisionSize2 >= vec.fY - fRadius >= -MaxCollisionSize2 &&
MaxCollisionSize2 >= vec.fZ - fRadius >= -MaxCollisionSize2));
}
return (MaxCollisionSize2 >= vec.fX && vec.fX >= -MaxCollisionSize2 && MaxCollisionSize2 >= vec.fY && vec.fY >= -MaxCollisionSize2 &&
MaxCollisionSize2 >= vec.fZ && vec.fZ >= -MaxCollisionSize2);
}

// CompareVector returns true if all points in the second vector are greater than the corresponding points in the first vector
static bool CompareVector(CVector& vecMin, CVector& vecMax) { return vecMax.fX >= vecMin.fX && vecMax.fY >= vecMin.fY && vecMax.fZ >= vecMin.fZ; }

// AlignVector clamps a "source" vector between a min and max vector. Or something like that. I don't know.
static void AlignVector(CVector& destMin, CVector& destMax, const CVector& src)
{
if (src.fX < destMax.fX)
destMax.fX = src.fX;
if (src.fY < destMax.fY)
destMax.fY = src.fY;
if (src.fZ < destMax.fZ)
destMax.fZ = src.fZ;
if (src.fX > destMin.fX)
destMin.fX = src.fX;
if (src.fY > destMin.fY)
destMin.fY = src.fY;
if (src.fZ > destMin.fZ)
destMin.fZ = src.fZ;
}
void UpdateVerticesCount();

CColModelSAInterface* GetColModelInterface();

// Sorta a hack that these are required by CClientEntity...
void Unlink(){};
Expand All @@ -46,7 +98,12 @@ class CClientColModel final : public CClientEntity
void InternalRestore(unsigned short usModel);

class CClientColModelManager* m_pColModelManager;
int m_iVerticesCount;
CColModel* m_pColModel;
std::list<unsigned short> m_Replaced;

CColModel* m_pColModel;
std::list<unsigned short> m_Replaced;
// m_bHasChanged should be set to true when the bounding box has changed.
// This ensures that the bounding box is only recalculated when necessary.
// This is true by default as an object loaded collision could have the wrong bounding box.
bool b_hasChanged = true;
};
17 changes: 17 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,23 @@ ADD_ENUM(SURFACE_ADHESION_GROUP_SAND, "sand")
ADD_ENUM(SURFACE_ADHESION_GROUP_WET, "wet")
IMPLEMENT_ENUM_END("surface-adhesion-group")

IMPLEMENT_ENUM_CLASS_BEGIN(eCollisionShape)
ADD_ENUM(eCollisionShape::BOX, "box")
ADD_ENUM(eCollisionShape::SPHERE, "sphere")
ADD_ENUM(eCollisionShape::TRIANGLE, "triangle")
ADD_ENUM(eCollisionShape::VERTEX, "vertex")
IMPLEMENT_ENUM_CLASS_END("collision-shape")

IMPLEMENT_ENUM_CLASS_BEGIN(eCollisionKey)
ADD_ENUM(eCollisionKey::SIZE, "size")
ADD_ENUM(eCollisionKey::MATERIAL, "material")
ADD_ENUM(eCollisionKey::POSITION, "position")
ADD_ENUM(eCollisionKey::RADIUS, "radius")
ADD_ENUM(eCollisionKey::LIGHTING, "lighting")
ADD_ENUM(eCollisionKey::VERTICES, "vertices")
ADD_ENUM(eCollisionKey::MOVE, "move")
IMPLEMENT_ENUM_CLASS_END("collision-key")

IMPLEMENT_ENUM_CLASS_BEGIN(eClientModelType)
ADD_ENUM(eClientModelType::PED, "ped")
ADD_ENUM(eClientModelType::OBJECT, "object")
Expand Down
21 changes: 21 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ DECLARE_ENUM(eSurfaceBulletEffect);
DECLARE_ENUM(eSurfaceWheelEffect);
DECLARE_ENUM(eSurfaceSkidMarkType);
DECLARE_ENUM(eSurfaceAdhesionGroup);
DECLARE_ENUM_CLASS(eCollisionShape);
DECLARE_ENUM_CLASS(eClientModelType);

class CRemoteCall;
Expand Down Expand Up @@ -106,6 +107,18 @@ enum eJSONPrettyType
};
DECLARE_ENUM(eJSONPrettyType);

enum class eCollisionKey
{
SIZE,
MATERIAL,
POSITION,
RADIUS,
LIGHTING,
VERTICES,
MOVE,
};
DECLARE_ENUM_CLASS(eCollisionKey);

// class -> class type
inline eCGUIType GetClassType(CGUIButton*)
{
Expand Down Expand Up @@ -455,6 +468,14 @@ inline SString GetClassByTypeName(eObjectGroup::BreakMode*)
{
return "objectgroup-breakmode";
}
inline SString GetClassTypeName(eCollisionShape*)
{
return "collision-shape";
}
inline SString GetClassTypeName(eCollisionKey*)
{
return "collision-key";
}

inline SString GetClassByTypeName(eClientModelType)
{
Expand Down
Loading