Skip to content

Commit 80105d0

Browse files
committed
-
1 parent a450169 commit 80105d0

27 files changed

Lines changed: 284 additions & 42 deletions

src/Carnage3D.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<ClInclude Include="common_utils.h" />
159159
<ClInclude Include="Convert.h" />
160160
<ClInclude Include="Decoration.h" />
161+
<ClInclude Include="Explosion.h" />
161162
<ClInclude Include="GameObjectDefs.h" />
162163
<ClInclude Include="game_version.h" />
163164
<ClInclude Include="GtaFontData.h" />
@@ -253,6 +254,7 @@
253254
<ClCompile Include="CommonTypes.cpp" />
254255
<ClCompile Include="Decoration.cpp" />
255256
<ClCompile Include="enums_impl.cpp" />
257+
<ClCompile Include="Explosion.cpp" />
256258
<ClCompile Include="GtaFontData.cpp" />
257259
<ClCompile Include="GameObject.cpp" />
258260
<ClCompile Include="GameObjectsManager.cpp" />

src/Carnage3D.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@
347347
<ClInclude Include="Obstacle.h">
348348
<Filter>Game\GameObjects</Filter>
349349
</ClInclude>
350+
<ClInclude Include="Explosion.h">
351+
<Filter>Game\GameObjects</Filter>
352+
</ClInclude>
350353
</ItemGroup>
351354
<ItemGroup>
352355
<ClCompile Include="stdafx.cpp">
@@ -543,6 +546,9 @@
543546
<ClCompile Include="Obstacle.cpp">
544547
<Filter>Game\GameObjects</Filter>
545548
</ClCompile>
549+
<ClCompile Include="Explosion.cpp">
550+
<Filter>Game\GameObjects</Filter>
551+
</ClCompile>
546552
</ItemGroup>
547553
<ItemGroup>
548554
<None Include="..\gamedata\config\sys_config.json.default">

src/CarnageGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool CarnageGame::SetInputActionsFromConfig()
175175
for (int ihuman = 0; ihuman < GAME_MAX_PLAYERS; ++ihuman)
176176
{
177177
HumanCharacterSlot& currentChar = mHumanSlot[ihuman];
178-
currentChar.mCharController.mInputs.SetNull();
178+
currentChar.mCharController.mInputs.Clear();
179179
if (ihuman == 0)
180180
{
181181
currentChar.mCharController.mInputs.SetDefaults();

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
mDrawSprite.mHeight = startPosition.y;
4242
mDrawSprite.mRotateAngle = startRotation;
4343

44-
mAnimationState.SetNull();
44+
mAnimationState.Clear();
4545
mAnimationState.mAnimDesc = mGameObjectDesc->mAnimationData;
4646
mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
4747
}

src/Explosion.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "stdafx.h"
2+
#include "Explosion.h"
3+
#include "TimeManager.h"
4+
#include "SpriteManager.h"
5+
6+
Explosion::Explosion(GameObjectID id)
7+
: GameObject(eGameObjectClass_Explosion, id)
8+
{
9+
}
10+
11+
Explosion::~Explosion()
12+
{
13+
}
14+
15+
void Explosion::PreDrawFrame()
16+
{
17+
}
18+
19+
void Explosion::UpdateFrame()
20+
{
21+
float deltaTime = gTimeManager.mGameFrameDelta;
22+
if (mAnimationState.AdvanceAnimation(deltaTime))
23+
{
24+
gSpriteManager.GetExplosionTexture(mAnimationState.GetCurrentFrame(), mDrawSprite);
25+
mDrawSprite.SetOriginToCenter();
26+
}
27+
28+
if (!mAnimationState.IsAnimationActive())
29+
{
30+
MarkForDeletion();
31+
}
32+
}
33+
34+
void Explosion::DrawDebug(DebugRenderer& debugRender)
35+
{
36+
}
37+
38+
void Explosion::Spawn(const glm::vec3& startPosition)
39+
{
40+
mDrawSprite.mPosition.x = startPosition.x;
41+
mDrawSprite.mPosition.y = startPosition.z;
42+
mDrawSprite.mHeight = startPosition.y;
43+
44+
mAnimationState.Clear();
45+
// todo
46+
int numFrames = gSpriteManager.GetExplosionFramesCount();
47+
mAnimationState.mAnimDesc.Setup(0, numFrames);
48+
mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
49+
mAnimationState.SetMaxRepeatCycles(1);
50+
51+
if (!gSpriteManager.GetExplosionTexture(0, mDrawSprite))
52+
{
53+
debug_assert(false);
54+
}
55+
mDrawSprite.SetOriginToCenter();
56+
}

src/Explosion.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include "GameObject.h"
4+
5+
class Explosion final: public GameObject
6+
{
7+
friend class GameObjectsManager;
8+
9+
// add runtime information support for gameobject
10+
decl_rtti(Explosion, GameObject)
11+
12+
public:
13+
Explosion(GameObjectID id);
14+
~Explosion();
15+
16+
// override GameObject
17+
void PreDrawFrame() override;
18+
void UpdateFrame() override;
19+
void DrawDebug(DebugRenderer& debugRender) override;
20+
21+
// Setup initial state when spawned or respawned on level
22+
void Spawn(const glm::vec3& startPosition);
23+
24+
private:
25+
SpriteAnimation mAnimationState;
26+
};

src/GameDefs.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,14 @@ struct SpriteVertex3D_Format: public VertexFormat
274274
struct MapMeshData
275275
{
276276
public:
277-
using TVertexType = CityVertex3D;
278277
MapMeshData() = default;
279-
280-
inline void SetNull()
278+
inline void Clear()
281279
{
282280
mBlocksVertices.clear();
283281
mBlocksIndices.clear();
284282
}
285-
286283
public:
284+
using TVertexType = CityVertex3D;
287285
std::vector<TVertexType> mBlocksVertices;
288286
std::vector<DrawIndex> mBlocksIndices;
289287
};
@@ -329,7 +327,7 @@ struct TextureRegion
329327
mV1 = 1.0f;
330328
}
331329
// clear texture region
332-
inline void SetNull()
330+
inline void Clear()
333331
{
334332
mRectangle.SetNull();
335333
}
@@ -346,7 +344,7 @@ class Spritesheet final
346344
public:
347345
Spritesheet() = default;
348346
// clear spritesheet
349-
inline void SetNull()
347+
inline void Clear()
350348
{
351349
mSpritesheetTexture = nullptr;
352350
mEntries.clear();

src/GameObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class GameObject: public cxx::noncopyable
6161
inline bool IsVehicleClass() const { return mObjectTypeID == eGameObjectClass_Car; }
6262
inline bool IsPowerupClass() const { return mObjectTypeID == eGameObjectClass_Powerup; }
6363
inline bool IsObstacleClass() const { return mObjectTypeID == eGameObjectClass_Obstacle; }
64+
inline bool IsExplosionClass() const { return mObjectTypeID == eGameObjectClass_Explosion; }
6465

6566
// flag shortcuts
6667
inline bool IsInvisibleFlag() const { return (mFlags & eGameObjectFlags_Invisible) != 0; }
@@ -78,7 +79,6 @@ class GameObject: public cxx::noncopyable
7879
// drawing spricific data
7980
Sprite2D mDrawSprite;
8081

81-
8282
private:
8383
// marked object will be destroyed next game frame
8484
bool mMarkedForDeletion = false;

src/GameObjectDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Vehicle;
88
class Projectile;
99
class Decoration;
1010
class Obstacle;
11+
class Explosion;
1112

1213
// some game objects has null identifier, they are dacals, projectiles and short-lived effects
1314
#define GAMEOBJECT_ID_NULL 0
@@ -23,6 +24,7 @@ enum eGameObjectClass
2324
eGameObjectClass_Powerup,
2425
eGameObjectClass_Decoration,
2526
eGameObjectClass_Obstacle,
27+
eGameObjectClass_Explosion,
2628
eGameObjectClass_COUNT,
2729
};
2830

src/GameObjectsManager.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ GameObjectsManager::~GameObjectsManager()
1616
mProjectilesPool.cleanup();
1717
mDecorationsPool.cleanup();
1818
mObstaclesPool.cleanup();
19+
mExplosionsPool.cleanup();
1920
}
2021

2122
bool GameObjectsManager::InitGameObjects()
@@ -150,6 +151,19 @@ Obstacle* GameObjectsManager::CreateObstacle(const glm::vec3& position, cxx::ang
150151
return instance;
151152
}
152153

154+
Explosion* GameObjectsManager::CreateExplosion(const glm::vec3& position)
155+
{
156+
GameObjectID objectID = GenerateUniqueID();
157+
158+
Explosion* instance = mExplosionsPool.create(objectID);
159+
debug_assert(instance);
160+
161+
mAllObjectsList.push_back(instance);
162+
// init
163+
instance->Spawn(position);
164+
return instance;
165+
}
166+
153167
Decoration* GameObjectsManager::CreateDecoration(const glm::vec3& position, cxx::angle_t heading, GameObjectStyle* desc)
154168
{
155169
Decoration* instance = nullptr;
@@ -302,6 +316,13 @@ void GameObjectsManager::DestroyGameObject(GameObject* object)
302316
}
303317
break;
304318

319+
case eGameObjectClass_Explosion:
320+
{
321+
Explosion* explosion = static_cast<Explosion*>(object);
322+
mExplosionsPool.destroy(explosion);
323+
}
324+
break;
325+
305326
case eGameObjectClass_Powerup:
306327
default:
307328
{
@@ -397,4 +418,4 @@ bool GameObjectsManager::CreateStartupObjects()
397418
}
398419
}
399420
return true;
400-
}
421+
}

0 commit comments

Comments
 (0)