Skip to content

Commit 75ebd5e

Browse files
committed
-
1 parent 72077b7 commit 75ebd5e

12 files changed

Lines changed: 102 additions & 20 deletions

src/Decoration.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include "stdafx.h"
22
#include "Decoration.h"
3+
#include "TimeManager.h"
4+
#include "SpriteManager.h"
5+
#include "GameCheatsWindow.h"
36

4-
Decoration::Decoration(GameObjectID id)
7+
Decoration::Decoration(GameObjectID id, GameObjectStyle* desc)
58
: GameObject(eGameObjectClass_Decoration, id)
9+
, mGameObjectDesc(desc)
610
{
11+
debug_assert(mGameObjectDesc);
712
}
813

914
Decoration::~Decoration()
@@ -12,12 +17,34 @@ Decoration::~Decoration()
1217

1318
void Decoration::DrawFrame(SpriteBatch& spriteBatch)
1419
{
20+
if (!gGameCheatsWindow.mEnableDrawDecorations)
21+
return;
22+
23+
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetCurrentFrame(), 0, mDrawSprite);
24+
mDrawSprite.SetOriginToCenter();
25+
spriteBatch.DrawSprite(mDrawSprite);
1526
}
1627

1728
void Decoration::UpdateFrame()
1829
{
30+
float deltaTime = gTimeManager.mGameFrameDelta;
31+
mAnimationState.AdvanceAnimation(deltaTime);
1932
}
2033

2134
void Decoration::DrawDebug(DebugRenderer& debugRender)
2235
{
23-
}
36+
}
37+
38+
void Decoration::Spawn(const glm::vec3& startPosition, cxx::angle_t startRotation)
39+
{
40+
debug_assert(mGameObjectDesc);
41+
42+
mDrawSprite.mPosition.x = startPosition.x;
43+
mDrawSprite.mPosition.y = startPosition.z;
44+
mDrawSprite.mHeight = startPosition.y + 0.1f;
45+
mDrawSprite.mRotateAngle = startRotation;
46+
47+
mAnimationState.SetNull();
48+
mAnimationState.mAnimDesc = mGameObjectDesc->mAnimationData;
49+
mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
50+
}

src/Decoration.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ class Decoration final: public GameObject
99
decl_rtti(Decoration, GameObject)
1010

1111
public:
12-
Decoration(GameObjectID id);
12+
Decoration(GameObjectID id, GameObjectStyle* desc);
1313
~Decoration();
1414

1515
// override GameObject
16-
void DrawFrame(SpriteBatch& spriteBatch);
17-
void UpdateFrame();
18-
void DrawDebug(DebugRenderer& debugRender);
16+
void DrawFrame(SpriteBatch& spriteBatch) override;
17+
void UpdateFrame() override;
18+
void DrawDebug(DebugRenderer& debugRender) override;
19+
20+
// Setup initial state when spawned or respawned on level
21+
void Spawn(const glm::vec3& startPosition, cxx::angle_t startRotation);
1922

2023
private:
2124
SpriteAnimation mAnimationState;
22-
Sprite2D mSprite;
25+
Sprite2D mDrawSprite;
26+
GameObjectStyle* mGameObjectDesc = nullptr;
2327
};

src/GameCheatsWindow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
153153
{
154154
ImGui::Checkbox("Enable blocks animation", &mEnableBlocksAnimation);
155155
ImGui::Checkbox("Enable debug draw", &mEnableDebugDraw);
156+
157+
ImGui::Checkbox("Draw decorations", &mEnableDrawDecorations);
158+
ImGui::Checkbox("Draw pedestrians", &mEnableDrawPedestrians);
159+
ImGui::Checkbox("Draw vehicles", &mEnableDrawVehicles);
160+
ImGui::Checkbox("Draw city mesh", &mEnableDrawCityMesh);
156161
}
157162

158163
if (ImGui::CollapsingHeader("Ped"))

src/GameCheatsWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class GameCheatsWindow: public DebugWindow
99
bool mEnableGravity;
1010
bool mEnableBlocksAnimation;
1111
bool mEnableDebugDraw;
12+
bool mEnableDrawDecorations = true;
13+
bool mEnableDrawPedestrians = true;
14+
bool mEnableDrawVehicles = true;
15+
bool mEnableDrawCityMesh = true;
1216

1317
public:
1418
GameCheatsWindow();

src/GameDefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define METERS_PER_MAP_UNIT (4.0f)
2323

2424
#define SPRITE_ZERO_ANGLE 90.0f // all sprites in game are rotated at 90 degrees
25-
#define SPRITE_SCALE (METERS_PER_MAP_UNIT / PIXELS_PER_MAP_UNIT)
25+
#define MAP_SPRITE_SCALE (METERS_PER_MAP_UNIT / PIXELS_PER_MAP_UNIT)
2626
#define PED_SPRITE_DRAW_BOX_SIZE_PX 24 // with, height
2727
#define CAR_WHEEL_SIZE_W_PX 6
2828
#define CAR_WHEEL_SIZE_H_PX 12

src/GameObjectsManager.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ Projectile* GameObjectsManager::CreateProjectile(const glm::vec3& position, cxx:
129129
return instance;
130130
}
131131

132+
Decoration* GameObjectsManager::CreateDecoration(const glm::vec3& position, cxx::angle_t heading, GameObjectStyle* desc)
133+
{
134+
Decoration* instance = nullptr;
135+
debug_assert(gGameMap.mStyleData.IsLoaded());
136+
debug_assert(desc);
137+
debug_assert(desc->mClassID == eGameObjectClass_Decoration);
138+
if (desc->mClassID == eGameObjectClass_Decoration)
139+
{
140+
GameObjectID objectID = GenerateUniqueID();
141+
142+
instance = mDecorationsPool.create(objectID, desc);
143+
debug_assert(instance);
144+
145+
mAllObjectsList.push_back(instance);
146+
// init
147+
instance->Spawn(position, heading);
148+
}
149+
return instance;
150+
}
151+
132152
Vehicle* GameObjectsManager::GetVehicleByID(GameObjectID objectID) const
133153
{
134154
for (GameObject* currentObject: mAllObjectsList)
@@ -231,8 +251,15 @@ void GameObjectsManager::DestroyGameObject(GameObject* object)
231251
mProjectilesPool.destroy(projectile);
232252
}
233253
break;
234-
case eGameObjectClass_Powerup:
254+
235255
case eGameObjectClass_Decoration:
256+
{
257+
Decoration* decoration = static_cast<Decoration*>(object);
258+
mDecorationsPool.destroy(decoration);
259+
}
260+
break;
261+
262+
case eGameObjectClass_Powerup:
236263
case eGameObjectClass_Obstacle:
237264
default:
238265
{
@@ -276,14 +303,14 @@ bool GameObjectsManager::CreateStartupObjects()
276303
{
277304
int mapLevel = (int) Convert::PixelsToMapUnits(currObject.mZ);
278305
mapLevel = INVERT_MAP_LAYER(mapLevel);
279-
glm::vec3 carPosition
306+
glm::vec3 start_position
280307
{
281308
Convert::PixelsToMeters(currObject.mX),
282309
Convert::MapUnitsToMeters(mapLevel * 1.0f),
283310
Convert::PixelsToMeters(currObject.mY)
284311
};
285312

286-
cxx::angle_t rotationDegrees = Convert::Fix16ToAngle(currObject.mRotation);
313+
cxx::angle_t start_rotation = Convert::Fix16ToAngle(currObject.mRotation);
287314

288315
// create startup cars
289316
if (currObject.IsCarObject())
@@ -294,7 +321,7 @@ bool GameObjectsManager::CreateStartupObjects()
294321
debug_assert(false);
295322
continue;
296323
}
297-
Vehicle* startupCar = CreateCar(carPosition, rotationDegrees, carModel);
324+
Vehicle* startupCar = CreateCar(start_position, start_rotation, carModel);
298325
debug_assert(startupCar);
299326
continue;
300327
}
@@ -306,9 +333,14 @@ bool GameObjectsManager::CreateStartupObjects()
306333
GameObjectStyle& objectType = styleData.mGameObjects[objectTypeIndex];
307334
switch (objectType.mClassID)
308335
{
336+
case eGameObjectClass_Decoration:
337+
{
338+
Decoration* startupDecoration = CreateDecoration(start_position, start_rotation, &objectType);
339+
debug_assert(startupDecoration);
340+
}
341+
break;
309342
case eGameObjectClass_Projectile: break;
310343
case eGameObjectClass_Powerup: break;
311-
case eGameObjectClass_Decoration: break;
312344
case eGameObjectClass_Obstacle: break;
313345
default:
314346
debug_assert(false);

src/GameObjectsManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ class GameObjectsManager final: public cxx::noncopyable
3535
Vehicle* CreateCar(const glm::vec3& position, cxx::angle_t heading, CarStyle* desc);
3636
Vehicle* CreateCar(const glm::vec3& position, cxx::angle_t heading, eCarModel carModel);
3737

38-
// New projectile instance to map at specific location
38+
// Add new projectile instance to map at specific location
3939
Projectile* CreateProjectile(const glm::vec3& position, cxx::angle_t heading, eProjectileType typeID);
4040
Projectile* CreateProjectile(const glm::vec3& position, cxx::angle_t heading, ProjectileStyle* desc);
4141

42+
// Add new decoration instance to map at specific location
43+
Decoration* CreateDecoration(const glm::vec3& position, cxx::angle_t heading, GameObjectStyle* desc);
44+
4245
// find gameobject by its unique identifier
4346
// @param objectID: Unique identifier
4447
Vehicle* GetVehicleByID(GameObjectID objectID) const;

src/MapRenderer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ void MapRenderer::RenderFrame(RenderView* renderview)
7878
gGraphicsDevice.BindTexture(eTextureUnit_3, gSpriteManager.mPalettesTable);
7979
gGraphicsDevice.BindTexture(eTextureUnit_2, gSpriteManager.mPaletteIndicesTable);
8080

81-
DrawCityMesh(renderview);
81+
if (gGameCheatsWindow.mEnableDrawCityMesh)
82+
{
83+
DrawCityMesh(renderview);
84+
}
8285

8386
mSpriteBatch.BeginBatch(SpriteBatch::DepthAxis_Y);
8487

src/Pedestrian.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "PedestrianStates.h"
99
#include "Vehicle.h"
1010
#include "TimeManager.h"
11+
#include "GameCheatsWindow.h"
1112

1213
Pedestrian::Pedestrian(GameObjectID id) : GameObject(eGameObjectClass_Pedestrian, id)
1314
, mPhysicsBody()
@@ -90,6 +91,9 @@ void Pedestrian::DrawFrame(SpriteBatch& spriteBatch)
9091
glm::vec3 position = mPhysicsBody->mSmoothPosition;
9192
ComputeDrawHeight(position);
9293

94+
if (!gGameCheatsWindow.mEnableDrawPedestrians)
95+
return;
96+
9397
ePedestrianState currState = GetCurrentStateID();
9498
if (currState == ePedestrianState_DrivingCar)
9599
{
@@ -106,7 +110,6 @@ void Pedestrian::DrawFrame(SpriteBatch& spriteBatch)
106110
gSpriteManager.GetSpriteTexture(mObjectID, spriteIndex, remapClut, mDrawSprite);
107111

108112
mDrawSprite.mPosition = glm::vec2(position.x, position.z);
109-
mDrawSprite.mScale = SPRITE_SCALE;
110113
mDrawSprite.mRotateAngle = rotationAngle;
111114
mDrawSprite.mHeight = mDrawHeight;
112115
mDrawSprite.SetOriginToCenter();

src/Projectile.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Projectile::Projectile(ProjectileStyle* style)
1111
, mProjectileStyle(style)
1212
, mDrawHeight()
1313
, mStartPosition()
14-
, mDead()
1514
{
1615
debug_assert(style);
1716
}
@@ -51,7 +50,6 @@ void Projectile::Spawn(const glm::vec3& startPosition, cxx::angle_t startRotatio
5150
// setup sprite rotation and scale
5251
cxx::angle_t rotationAngle = startRotation + cxx::angle_t::from_degrees(SPRITE_ZERO_ANGLE);
5352
mDrawSprite.mRotateAngle = rotationAngle;
54-
mDrawSprite.mScale = SPRITE_SCALE;
5553
}
5654

5755
void Projectile::UpdateFrame()

0 commit comments

Comments
 (0)