Skip to content

Commit e1e1e9b

Browse files
committed
minor refactore
1 parent 07fa77a commit e1e1e9b

45 files changed

Lines changed: 253 additions & 221 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/AiCharacterController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "stdafx.h"
22
#include "AiCharacterController.h"
33

4-
void AiCharacterController::UpdateFrame(Pedestrian* pedestrian, Timespan deltaTime)
4+
void AiCharacterController::UpdateFrame(Pedestrian* pedestrian)
55
{
66

77
}

src/AiCharacterController.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ class AiCharacterController final: public CharacterController
77
{
88
public:
99
// process controller logic
10-
// @param deltaTime: Time since last frame
11-
void UpdateFrame(Pedestrian* pedestrian, Timespan deltaTime) override;
10+
void UpdateFrame(Pedestrian* pedestrian) override;
1211
};

src/CameraController.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class CameraController
1414
{
1515
}
1616
// handle camera controller logic
17-
// @param deltaTime: Time since last frame
18-
virtual void UpdateFrame(Timespan deltaTime)
17+
virtual void UpdateFrame()
1918
{
2019
}
2120
// handle input events

src/Carnage3D.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<ClInclude Include="GraphicsContext.h" />
208208
<ClInclude Include="GraphicsDefs.h" />
209209
<ClInclude Include="GraphicsDevice.h" />
210+
<ClInclude Include="TimeManager.h" />
210211
<ClInclude Include="UiContext.h" />
211212
<ClInclude Include="UiManager.h" />
212213
<ClInclude Include="handle.h" />
@@ -278,6 +279,7 @@
278279
<ClCompile Include="FileSystem.cpp" />
279280
<ClCompile Include="GameParams.cpp" />
280281
<ClCompile Include="GpuTextureArray2D.cpp" />
282+
<ClCompile Include="TimeManager.cpp" />
281283
<ClCompile Include="UiManager.cpp" />
282284
<ClCompile Include="imgui.cpp" />
283285
<ClCompile Include="ConsoleWindow.cpp" />

src/Carnage3D.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
<ClInclude Include="InputsManager.h">
330330
<Filter>Application</Filter>
331331
</ClInclude>
332+
<ClInclude Include="TimeManager.h">
333+
<Filter>Application</Filter>
334+
</ClInclude>
332335
</ItemGroup>
333336
<ItemGroup>
334337
<ClCompile Include="stdafx.cpp">
@@ -513,6 +516,9 @@
513516
<ClCompile Include="InputsManager.cpp">
514517
<Filter>Application</Filter>
515518
</ClCompile>
519+
<ClCompile Include="TimeManager.cpp">
520+
<Filter>Application</Filter>
521+
</ClCompile>
516522
</ItemGroup>
517523
<ItemGroup>
518524
<None Include="..\gamedata\config\sys_config.json.default">

src/CarnageGame.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "PhysicsManager.h"
88
#include "Pedestrian.h"
99
#include "MemoryManager.h"
10+
#include "TimeManager.h"
1011

1112
static const char* InputsConfigPath = "config/inputs.json";
1213
static const char* GTA1MapFileExtension = ".CMP";
@@ -126,7 +127,6 @@ bool CarnageGame::Initialize()
126127
}
127128

128129
SetupScreenLayout(mNumPlayers);
129-
mGameTime = 0;
130130
return true;
131131
}
132132

@@ -137,22 +137,21 @@ void CarnageGame::Deinit()
137137
gGameMap.Cleanup();
138138
}
139139

140-
void CarnageGame::UpdateFrame(Timespan deltaTime)
140+
void CarnageGame::UpdateFrame()
141141
{
142-
// advance game time
143-
mGameTime += deltaTime;
142+
float deltaTime = gTimeManager.mGameFrameDelta;
144143

145144
gSpriteManager.UpdateBlocksAnimations(deltaTime);
146-
gPhysics.UpdateFrame(deltaTime);
147-
gGameObjectsManager.UpdateFrame(deltaTime);
145+
gPhysics.UpdateFrame();
146+
gGameObjectsManager.UpdateFrame();
148147

149148
for (int ihuman = 0; ihuman < GAME_MAX_PLAYERS; ++ihuman)
150149
{
151150
if (mHumanSlot[ihuman].mCharPedestrian == nullptr)
152151
continue;
153152

154-
mHumanSlot[ihuman].mCharController.UpdateFrame(mHumanSlot[ihuman].mCharPedestrian, deltaTime);
155-
mHumanSlot[ihuman].mCharView.UpdateFrame(deltaTime);
153+
mHumanSlot[ihuman].mCharController.UpdateFrame(mHumanSlot[ihuman].mCharPedestrian);
154+
mHumanSlot[ihuman].mCharView.UpdateFrame();
156155
}
157156
}
158157

src/CarnageGame.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class CarnageGame final: public cxx::noncopyable
2424
HumanCharacterSlot mHumanSlot[GAME_MAX_PLAYERS];
2525
int mNumPlayers = 0;
2626

27-
Timespan mGameTime;
28-
2927
cxx::randomizer mGameRand;
3028

3129
public:
@@ -36,7 +34,7 @@ class CarnageGame final: public cxx::noncopyable
3634
void Deinit();
3735

3836
// Common processing
39-
void UpdateFrame(Timespan deltaTime);
37+
void UpdateFrame();
4038
void InputEvent(KeyInputEvent& inputEvent);
4139
void InputEvent(MouseButtonInputEvent& inputEvent);
4240
void InputEvent(MouseMovedInputEvent& inputEvent);

src/CharacterController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CharacterController::~CharacterController()
77
{
88
}
99

10-
void CharacterController::UpdateFrame(Pedestrian* pedestrian, Timespan deltaTime)
10+
void CharacterController::UpdateFrame(Pedestrian* pedestrian)
1111
{
1212
}
1313

src/CharacterController.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class CharacterController: public cxx::noncopyable
99
virtual ~CharacterController();
1010

1111
// process controller logic
12-
// @param deltaTime: Time since last frame
13-
virtual void UpdateFrame(Pedestrian* pedestrian, Timespan deltaTime);
12+
virtual void UpdateFrame(Pedestrian* pedestrian);
1413

1514
// clear current state but keep target character bound to controller
1615
virtual void ResetControlState(Pedestrian* pedestrian);

src/CommonTypes.h

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct Color32
2323
// @param cr, cg, cb, ca: Color components
2424
inline void SetComponents(unsigned char cr, unsigned char cg, unsigned char cb, unsigned char ca)
2525
{
26-
mA = cr;
27-
mR = cg;
26+
mA = ca;
27+
mR = cr;
2828
mG = cg;
2929
mB = cb;
3030
}
@@ -253,73 +253,4 @@ struct Palette256
253253
}
254254
public:
255255
Color32 mColors[256];
256-
};
257-
258-
// defines time interval in milliseconds
259-
struct Timespan
260-
{
261-
public:
262-
// @param timeMilliseconds: Milliseconds
263-
Timespan() = default;
264-
Timespan(long long timeMilliseconds) : mMilliseconds(timeMilliseconds)
265-
{
266-
}
267-
inline Timespan& operator += (const Timespan& timespan)
268-
{
269-
mMilliseconds += timespan.mMilliseconds;
270-
return *this;
271-
}
272-
inline Timespan& operator -= (const Timespan& timespan)
273-
{
274-
mMilliseconds -= timespan.mMilliseconds;
275-
return *this;
276-
}
277-
278-
static const long long MillisecondsPerSecond = 1000LL;
279-
static const long long MillisecondsPerMinute = 60000LL;
280-
static const long long MillisecondsPerHour = 3600000LL;
281-
static const long long MillisecondsPerDay = 86400000LL;
282-
283-
// convert time to timespan
284-
// @param intime: Input amount of time specified in days/hours/minutes/seconds
285-
static Timespan FromDays(float intime)
286-
{
287-
return (long long)(intime * MillisecondsPerDay);
288-
}
289-
290-
static Timespan FromHours(float intime)
291-
{
292-
return (long long)(intime * MillisecondsPerHour);
293-
}
294-
295-
static Timespan FromMinutes(float intime)
296-
{
297-
return (long long)(intime * MillisecondsPerMinute);
298-
}
299-
300-
static Timespan FromSeconds(float intime)
301-
{
302-
return (long long)(intime * MillisecondsPerSecond);
303-
}
304-
305-
// convert timespan to specific time values
306-
inline float ToMinutes() const { return (mMilliseconds * 1.0f) / (MillisecondsPerMinute * 1.0f); }
307-
inline float ToSeconds() const { return (mMilliseconds * 1.0f) / (MillisecondsPerSecond * 1.0f); }
308-
inline float ToDays() const { return (mMilliseconds * 1.0f) / (MillisecondsPerDay * 1.0f); }
309-
inline float ToHours() const { return (mMilliseconds * 1.0f) / (MillisecondsPerHour * 1.0f); }
310-
311-
public:
312-
long long mMilliseconds = 0;
313-
};
314-
315-
inline bool operator == (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds == theR.mMilliseconds; }
316-
inline bool operator != (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds != theR.mMilliseconds; }
317-
318-
inline bool operator > (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds > theR.mMilliseconds; }
319-
inline bool operator < (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds < theR.mMilliseconds; }
320-
321-
inline bool operator >= (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds >= theR.mMilliseconds; }
322-
inline bool operator <= (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds <= theR.mMilliseconds; }
323-
324-
inline Timespan operator - (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds - theR.mMilliseconds; }
325-
inline Timespan operator + (const Timespan& theL, const Timespan& theR) { return theL.mMilliseconds + theR.mMilliseconds; }
256+
};

0 commit comments

Comments
 (0)