Skip to content

Commit d69c750

Browse files
committed
-
1 parent 75ebd5e commit d69c750

26 files changed

Lines changed: 372 additions & 90 deletions

gamedata/entities/gta_objects.json

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
{
7373
"name": "train_doors",
7474
"class": "decoration",
75-
"frameCount": 8
75+
"frameCount": 8,
76+
"flags": ["carobject"]
7677
},
7778
{
7879
"name": "blood",
@@ -109,7 +110,8 @@
109110
{
110111
"name": "skid_dirt1",
111112
"class": "decoration",
112-
"frameCount": 3
113+
"frameCount": 3,
114+
"flags": ["carobject"]
113115
},
114116
{
115117
"name": "skid_dirt2",
@@ -169,12 +171,14 @@
169171
{
170172
"name": "tank_gun",
171173
"class": "decoration",
172-
"frameCount": 1
174+
"frameCount": 1,
175+
"flags": ["carobject"]
173176
},
174177
{
175178
"name": "tank_gun_barrel",
176179
"class": "decoration",
177-
"frameCount": 1
180+
"frameCount": 1,
181+
"flags": ["carobject"]
178182
},
179183
{
180184
"name": "coffin",
@@ -194,12 +198,14 @@
194198
{
195199
"name": "tank_gun_wrecked",
196200
"class": "obstacle",
197-
"frameCount": 1
201+
"frameCount": 1,
202+
"flags": ["carobject"]
198203
},
199204
{
200205
"name": "tank_gun_barrel_wrecked",
201206
"class": "obstacle",
202-
"frameCount": 1
207+
"frameCount": 1,
208+
"flags": ["carobject"]
203209
},
204210
{
205211
"name": "phone",
@@ -244,17 +250,20 @@
244250
{
245251
"name": "water_jet",
246252
"class": "decoration",
247-
"frameCount": 8
253+
"frameCount": 8,
254+
"flags": ["carobject"]
248255
},
249256
{
250257
"name": "water_jet_end",
251258
"class": "decoration",
252-
"frameCount": 8
259+
"frameCount": 8,
260+
"flags": ["carobject"]
253261
},
254262
{
255263
"name": "firehose",
256264
"class": "decoration",
257-
"frameCount": 1
265+
"frameCount": 1,
266+
"flags": ["carobject"]
258267
},
259268
{
260269
"name": "big_smoke",
@@ -264,12 +273,14 @@
264273
{
265274
"name": "unknown52",
266275
"class": "obstacle",
267-
"frameCount": 1
276+
"frameCount": 1,
277+
"flags": ["carobject"]
268278
},
269279
{
270280
"name": "exhaust",
271281
"class": "decoration",
272-
"frameCount": 11
282+
"frameCount": 11,
283+
"flags": ["carobject"]
273284
},
274285
{
275286
"name": "splash",
@@ -279,27 +290,32 @@
279290
{
280291
"name": "fire_truck_arm1",
281292
"class": "decoration",
282-
"frameCount": 1
293+
"frameCount": 1,
294+
"flags": ["carobject"]
283295
},
284296
{
285297
"name": "fire_truck_arm2",
286298
"class": "decoration",
287-
"frameCount": 1
299+
"frameCount": 1,
300+
"flags": ["carobject"]
288301
},
289302
{
290303
"name": "fire_truck_arm3",
291304
"class": "decoration",
292-
"frameCount": 1
305+
"frameCount": 1,
306+
"flags": ["carobject"]
293307
},
294308
{
295309
"name": "fire_truck_arm4",
296310
"class": "decoration",
297-
"frameCount": 1
311+
"frameCount": 1,
312+
"flags": ["carobject"]
298313
},
299314
{
300315
"name": "swat_gun",
301316
"class": "decoration",
302-
"frameCount": 1
317+
"frameCount": 1,
318+
"flags": ["carobject"]
303319
},
304320
{
305321
"name": "check_flag",
@@ -354,7 +370,8 @@
354370
{
355371
"name": "tv_camera",
356372
"class": "decoration",
357-
"frameCount": 1
373+
"frameCount": 1,
374+
"flags": ["carobject"]
358375
},
359376
{
360377
"name": "unknown71",
@@ -454,12 +471,14 @@
454471
{
455472
"name": "unknown90",
456473
"class": "decoration",
457-
"frameCount": 1
474+
"frameCount": 1,
475+
"flags": ["carobject"]
458476
},
459477
{
460478
"name": "unknown91",
461479
"class": "decoration",
462-
"frameCount": 1
480+
"frameCount": 1,
481+
"flags": ["carobject"]
463482
},
464483
{
465484
"name": "helicopter_blade",

src/Carnage3D.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
<ClInclude Include="GameObjectsManager.h" />
177177
<ClInclude Include="GpuBufferTexture.h" />
178178
<ClInclude Include="CharacterController.h" />
179+
<ClInclude Include="Obstacle.h" />
179180
<ClInclude Include="PedestrianStates.h" />
180181
<ClInclude Include="PhysicsDefs.h" />
181182
<ClInclude Include="PhysicsManager.h" />
@@ -261,6 +262,7 @@
261262
<ClCompile Include="CharacterController.cpp" />
262263
<ClCompile Include="MemoryManager.cpp" />
263264
<ClCompile Include="mem_allocators.cpp" />
265+
<ClCompile Include="Obstacle.cpp" />
264266
<ClCompile Include="path_utils.cpp" />
265267
<ClCompile Include="PedestrianStates.cpp" />
266268
<ClCompile Include="PhysicsManager.cpp" />

src/Carnage3D.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@
344344
<ClInclude Include="Decoration.h">
345345
<Filter>Game\GameObjects</Filter>
346346
</ClInclude>
347+
<ClInclude Include="Obstacle.h">
348+
<Filter>Game\GameObjects</Filter>
349+
</ClInclude>
347350
</ItemGroup>
348351
<ItemGroup>
349352
<ClCompile Include="stdafx.cpp">
@@ -537,6 +540,9 @@
537540
<ClCompile Include="Decoration.cpp">
538541
<Filter>Game\GameObjects</Filter>
539542
</ClCompile>
543+
<ClCompile Include="Obstacle.cpp">
544+
<Filter>Game\GameObjects</Filter>
545+
</ClCompile>
540546
</ItemGroup>
541547
<ItemGroup>
542548
<None Include="..\gamedata\config\sys_config.json.default">

src/Decoration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Decoration::Spawn(const glm::vec3& startPosition, cxx::angle_t startRotatio
4141

4242
mDrawSprite.mPosition.x = startPosition.x;
4343
mDrawSprite.mPosition.y = startPosition.z;
44-
mDrawSprite.mHeight = startPosition.y + 0.1f;
44+
mDrawSprite.mHeight = startPosition.y;
4545
mDrawSprite.mRotateAngle = startRotation;
4646

4747
mAnimationState.SetNull();

src/Decoration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Decoration final: public GameObject
66
{
77
friend class GameObjectsManager;
88

9+
// add runtime information support for gameobject
910
decl_rtti(Decoration, GameObject)
1011

1112
public:

src/GameCheatsWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
155155
ImGui::Checkbox("Enable debug draw", &mEnableDebugDraw);
156156

157157
ImGui::Checkbox("Draw decorations", &mEnableDrawDecorations);
158+
ImGui::Checkbox("Draw obstacles", &mEnableDrawObstacles);
158159
ImGui::Checkbox("Draw pedestrians", &mEnableDrawPedestrians);
159160
ImGui::Checkbox("Draw vehicles", &mEnableDrawVehicles);
160161
ImGui::Checkbox("Draw city mesh", &mEnableDrawCityMesh);

src/GameCheatsWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class GameCheatsWindow: public DebugWindow
1010
bool mEnableBlocksAnimation;
1111
bool mEnableDebugDraw;
1212
bool mEnableDrawDecorations = true;
13+
bool mEnableDrawObstacles = true;
1314
bool mEnableDrawPedestrians = true;
1415
bool mEnableDrawVehicles = true;
1516
bool mEnableDrawCityMesh = true;

src/GameObject.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ GameObject::GameObject(eGameObjectClass objectTypeID, GameObjectID uniqueID)
1515

1616
GameObject::~GameObject()
1717
{
18+
SetDetached();
1819
}
1920

2021
void GameObject::MarkForDeletion()
@@ -26,3 +27,63 @@ bool GameObject::IsMarkedForDeletion() const
2627
{
2728
return mMarkedForDeletion;
2829
}
30+
31+
void GameObject::SetAttachedToObject(GameObject* parentObject)
32+
{
33+
if (parentObject == nullptr || parentObject == this)
34+
{
35+
debug_assert(false);
36+
return;
37+
}
38+
39+
if (mParentObject == parentObject)
40+
return;
41+
42+
if (mParentObject)
43+
{
44+
SetDetached();
45+
}
46+
47+
mParentObject = parentObject;
48+
mParentObject->mAttachedObjects.push_back(this);
49+
}
50+
51+
void GameObject::SetDetached()
52+
{
53+
if (mParentObject == nullptr)
54+
return;
55+
56+
cxx::erase_elements(mParentObject->mAttachedObjects, this);
57+
mParentObject = nullptr;
58+
}
59+
60+
bool GameObject::IsAttachedToObject() const
61+
{
62+
return mParentObject != nullptr;
63+
}
64+
65+
bool GameObject::IsAttachedToObject(GameObject* parentObject) const
66+
{
67+
return mParentObject && (mParentObject == parentObject);
68+
}
69+
70+
bool GameObject::HasAttachedObjects()
71+
{
72+
return !mAttachedObjects.empty();
73+
}
74+
75+
GameObject* GameObject::GetParentObject() const
76+
{
77+
return mParentObject;
78+
}
79+
80+
GameObject* GameObject::GetAttachedObject(int index) const
81+
{
82+
GameObject* gameobject = nullptr;
83+
debug_assert(index >= 0);
84+
if (index < (int) mAttachedObjects.size())
85+
{
86+
gameobject = mAttachedObjects[index];
87+
}
88+
return gameobject;
89+
}

src/GameObject.h

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ class GameObject: public cxx::noncopyable
99
{
1010
friend class GameObjectsManager;
1111

12+
// add runtime information support for gameobject
1213
decl_rtti_base(GameObject)
1314

1415
public:
1516
const GameObjectID mObjectID; // its unique for all game objects except projectiles or effects, see GAMEOBJECT_ID_NULL
1617
const eGameObjectClass mObjectTypeID;
1718

19+
// readonly
20+
eGameObjectFlags mFlags = eGameObjectFlags_None;
21+
1822
public:
1923
virtual ~GameObject();
2024

@@ -36,17 +40,40 @@ class GameObject: public cxx::noncopyable
3640

3741
bool IsMarkedForDeletion() const;
3842

39-
// shortcuts
40-
inline bool IsPedestrianObject() const { return mObjectTypeID == eGameObjectClass_Pedestrian; }
41-
inline bool IsProjectileObject() const { return mObjectTypeID == eGameObjectClass_Projectile; }
42-
inline bool IsDecorationObject() const { return mObjectTypeID == eGameObjectClass_Decoration; }
43-
inline bool IsCarObject() const { return mObjectTypeID == eGameObjectClass_Car; }
44-
inline bool IsPowerupObject() const { return mObjectTypeID == eGameObjectClass_Powerup; }
45-
inline bool IsObstacleObject() const { return mObjectTypeID == eGameObjectClass_Obstacle; }
43+
// Attach or detach object to other object
44+
void SetAttachedToObject(GameObject* parentObject);
45+
void SetDetached();
46+
47+
// Inspect hierarchy
48+
bool IsAttachedToObject() const;
49+
bool IsAttachedToObject(GameObject* parentObject) const;
50+
bool HasAttachedObjects();
51+
52+
// Inspect hierarchy
53+
GameObject* GetParentObject() const;
54+
GameObject* GetAttachedObject(int index) const;
55+
56+
// class shortcuts
57+
inline bool IsPedestrianClass() const { return mObjectTypeID == eGameObjectClass_Pedestrian; }
58+
inline bool IsProjectileClass() const { return mObjectTypeID == eGameObjectClass_Projectile; }
59+
inline bool IsDecorationClass() const { return mObjectTypeID == eGameObjectClass_Decoration; }
60+
inline bool IsVehicleClass() const { return mObjectTypeID == eGameObjectClass_Car; }
61+
inline bool IsPowerupClass() const { return mObjectTypeID == eGameObjectClass_Powerup; }
62+
inline bool IsObstacleClass() const { return mObjectTypeID == eGameObjectClass_Obstacle; }
63+
64+
// flag shortcuts
65+
inline bool IsInvisibleFlag() const { return (mFlags & eGameObjectFlags_Invisible) != 0; }
66+
inline bool IsCarObjectFlag() const { return (mFlags & eGameObjectFlags_CarObject) != 0; }
4667

4768
protected:
4869
GameObject(eGameObjectClass objectTypeID, GameObjectID uniqueID);
4970

71+
protected:
72+
// todo: add attachment point and angle
73+
74+
GameObject* mParentObject = nullptr;
75+
std::vector<GameObject*> mAttachedObjects;
76+
5077
private:
5178
// marked object will be destroyed next game frame
5279
bool mMarkedForDeletion = false;

src/GameObjectDefs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Pedestrian;
77
class Vehicle;
88
class Projectile;
99
class Decoration;
10+
class Obstacle;
1011

1112
// some game objects has null identifier, they are dacals, projectiles and short-lived effects
1213
#define GAMEOBJECT_ID_NULL 0
@@ -27,10 +28,11 @@ enum eGameObjectClass
2728

2829
decl_enum_strings(eGameObjectClass);
2930

30-
enum eGameObjectFlags: unsigned int
31+
enum eGameObjectFlags: unsigned short
3132
{
3233
eGameObjectFlags_None = 0,
3334
eGameObjectFlags_Invisible = BIT(0),
35+
eGameObjectFlags_CarObject = BIT(1),
3436
};
3537

3638
decl_enum_as_flags(eGameObjectFlags);

0 commit comments

Comments
 (0)