Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 15779c6

Browse files
committed
Replace C casts with C++ casts
1 parent 2cc2712 commit 15779c6

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

System/Color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace RTE {
6262
m_Index = index;
6363

6464
RGB color;
65-
get_color((int)m_Index, &color);
65+
get_color(static_cast<int>(m_Index), &color);
6666

6767
m_R = color.r * 4;
6868
m_G = color.g * 4;

System/Matrix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace RTE {
3838
m_ElementsUpdated = true;
3939

4040
// Inverse angle to make CCW positive direction.
41-
float const CosAngle = (float)cos(-angle);
42-
float const SinAngle = (float)sin(-angle);
41+
float const CosAngle = static_cast<float>(cos(-angle));
42+
float const SinAngle = static_cast<float>(sin(-angle));
4343
m_Elements[0][0] = CosAngle;
4444
m_Elements[0][1] = -SinAngle;
4545
m_Elements[1][0] = SinAngle;
@@ -176,8 +176,8 @@ namespace RTE {
176176

177177
void Matrix::UpdateElements() {
178178
// Inverse angle to make CCW positive direction.
179-
float const CosAngle = (float)cos(-m_Rotation);
180-
float const SinAngle = (float)sin(-m_Rotation);
179+
float const CosAngle = static_cast<float>(cos(-m_Rotation));
180+
float const SinAngle = static_cast<float>(sin(-m_Rotation));
181181
m_Elements[0][0] = CosAngle;
182182
m_Elements[0][1] = -SinAngle;
183183
m_Elements[1][0] = SinAngle;

System/PathFinder.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ namespace RTE {
2121
int sceneHeight = g_SceneMan.GetSceneHeight();
2222

2323
// Make overlapping nodes at seams if necessary, to make sure all scene pixels are covered
24-
int nodeXCount = ceilf((float)sceneWidth / (float)m_NodeDimension);
25-
int nodeYCount = ceilf((float)sceneHeight / (float)m_NodeDimension);
24+
int nodeXCount = ceilf(static_cast<float>(sceneWidth) / static_cast<float>(m_NodeDimension));
25+
int nodeYCount = ceilf(static_cast<float>(sceneHeight) / static_cast<float>(m_NodeDimension));
2626

2727
// Create and assign scene coordinate positions for all nodes
2828
PathNode *pNode = 0;
29-
Vector nodePos = Vector((float)nodeDimension / 2.0F, (float)nodeDimension / 2.0F);
29+
Vector nodePos = Vector(static_cast<float>(nodeDimension) / 2.0F, static_cast<float>(nodeDimension) / 2.0F);
3030
for (int x = 0; x < nodeXCount; ++x) {
3131
// Make sure no cell centers are off the scene (since they can overlap the far edge of the scene)
3232
if (nodePos.m_X >= sceneWidth) { nodePos.m_X = sceneWidth - 1; }
3333
// Start the column height over at middle of the top node each new column
34-
nodePos.m_Y = (float)nodeDimension / 2.0F;
34+
nodePos.m_Y = static_cast<float>(nodeDimension) / 2.0F;
3535
// Create the new column and fill it out
3636
vector<PathNode *> newColumn;
3737
for (int y = 0; y < nodeYCount; ++y) {
@@ -120,10 +120,10 @@ namespace RTE {
120120
g_SceneMan.ForceBounds(end);
121121

122122
// Convert from absolute scene pixel coordinates to path node indices
123-
int startNodeX = floorf(start.m_X / (float)m_NodeDimension);
124-
int startNodeY = floorf(start.m_Y / (float)m_NodeDimension);
125-
int endNodeX = floorf(end.m_X / (float)m_NodeDimension);
126-
int endNodeY = floorf(end.m_Y / (float)m_NodeDimension);
123+
int startNodeX = floorf(start.m_X / static_cast<float>(m_NodeDimension));
124+
int startNodeY = floorf(start.m_Y / static_cast<float>(m_NodeDimension));
125+
int endNodeX = floorf(end.m_X / static_cast<float>(m_NodeDimension));
126+
int endNodeY = floorf(end.m_Y / static_cast<float>(m_NodeDimension));
127127

128128
// Clear out the results if it happens to contain anything
129129
pathResult.clear();
@@ -321,10 +321,10 @@ namespace RTE {
321321
box.Unflip();
322322

323323
// Get the extents of the box' potential influence on nodes and their connecting edges
324-
int firstX = floorf((box.m_Corner.m_X / (float)m_NodeDimension) + 0.5F) - 1;
325-
int lastX = floorf(((box.m_Corner.m_X + box.m_Width) / (float)m_NodeDimension) + 0.5F) + 1;
326-
int firstY = floorf((box.m_Corner.m_Y / (float)m_NodeDimension) + 0.5F) - 1;
327-
int lastY = floorf(((box.m_Corner.m_Y + box.m_Height) / (float)m_NodeDimension) + 0.5F) + 1;
324+
int firstX = floorf((box.m_Corner.m_X / static_cast<float>(m_NodeDimension)) + 0.5F) - 1;
325+
int lastX = floorf(((box.m_Corner.m_X + box.m_Width) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1;
326+
int firstY = floorf((box.m_Corner.m_Y / static_cast<float>(m_NodeDimension)) + 0.5F) - 1;
327+
int lastY = floorf(((box.m_Corner.m_Y + box.m_Height) / static_cast<float>(m_NodeDimension)) + 0.5F) + 1;
328328

329329
// Truncate the influence
330330
if (firstX < 0) { firstX = 0; }

System/RTEError.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ namespace RTE {
3838
#define RTEAssert(expression, description) { \
3939
static bool alwaysIgnore = false; \
4040
if (!alwaysIgnore) { \
41-
if (RTEAssertFunc((int)(expression), description, __FILE__, __LINE__, alwaysIgnore)) { \
4241
__debugbreak(); \
4342
} \
4443
} \
44+
if (RTEAssertFunc(expression, description, __FILE__, __LINE__, alwaysIgnore)) { \
4545
}
4646
}
4747
#endif

System/RTETools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace RTE {
2121

2222
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2323

24-
int SelectRand(int min, int max) { return min + (int)((max - min) * PosRand() + 0.5); }
24+
int SelectRand(int min, int max) { return min + static_cast<int>((max - min) * PosRand() + 0.5); }
2525

2626
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2727

System/Timer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace RTE {
1616
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1717

1818
int Timer::Create() {
19-
m_TicksPerMS = (double)g_TimerMan.GetTicksPerSecond() * 0.001;
19+
m_TicksPerMS = static_cast<double>(g_TimerMan.GetTicksPerSecond()) * 0.001;
2020
return 0;
2121
}
2222

2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

2525
int Timer::Create(unsigned long elapsedSimTime) {
2626
SetElapsedSimTimeMS(elapsedSimTime);
27-
m_TicksPerMS = (double)g_TimerMan.GetTicksPerSecond() * 0.001;
27+
m_TicksPerMS = static_cast<double>(g_TimerMan.GetTicksPerSecond()) * 0.001;
2828
return 0;
2929
}
3030

@@ -35,7 +35,7 @@ namespace RTE {
3535
m_StartSimTime = reference.m_StartSimTime;
3636
m_RealTimeLimit = reference.m_RealTimeLimit;
3737
m_SimTimeLimit = reference.m_SimTimeLimit;
38-
m_TicksPerMS = (double)g_TimerMan.GetTicksPerSecond() * 0.001;
38+
m_TicksPerMS = static_cast<double>(g_TimerMan.GetTicksPerSecond()) * 0.001;
3939
return 0;
4040
}
4141
}

System/Timer.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ namespace RTE {
9191
/// This is when the timer is supposed to show that it has 'expired' or reached whatever time limit it is supposed to keep track of.
9292
/// </summary>
9393
/// <returns>A positive double with the real time limit relative to the start time.</returns>
94-
double GetRealTimeLimitS() const { return m_RealTimeLimit / (double)g_TimerMan.GetTicksPerSecond(); }
94+
double GetRealTimeLimitS() const { return m_RealTimeLimit / static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
9595

9696
/// <summary>
9797
/// Sets the real time limit value of this Timer, RELATVE to the start time.
9898
/// This is when the timer is supposed to show that it has 'expired' or reached whatever time limit it is supposed to keep track of.
9999
/// </summary>
100100
/// <param name="newTimeLimit">A positive double with the new real time limit relative to the start time.</param>
101-
void SetRealTimeLimitS(double newTimeLimit) { m_RealTimeLimit = newTimeLimit * (double)g_TimerMan.GetTicksPerSecond(); }
101+
void SetRealTimeLimitS(double newTimeLimit) { m_RealTimeLimit = newTimeLimit * static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
102102

103103
/// <summary>
104104
/// Gets the elapsed real time in ms since this Timer was Reset().
105105
/// </summary>
106106
/// <returns>A unsigned long value that represents the elapsed real time since Reset() in ms.</returns>
107-
double GetElapsedRealTimeMS() const { return (double)(g_TimerMan.GetRealTickCount() - m_StartRealTime) / m_TicksPerMS; }
107+
double GetElapsedRealTimeMS() const { return static_cast<double>(g_TimerMan.GetRealTickCount() - m_StartRealTime) / m_TicksPerMS; }
108108

109109
/// <summary>
110110
/// Sets the start real time value of this Timer, in seconds.
@@ -116,13 +116,13 @@ namespace RTE {
116116
/// Gets the elapsed real time in seconds since this Timer was Reset().
117117
/// </summary>
118118
/// <returns>A double value that represents the elapsed real time since Reset() in s.</returns>
119-
double GetElapsedRealTimeS() const { return (double)(g_TimerMan.GetRealTickCount() - m_StartRealTime) / (double)g_TimerMan.GetTicksPerSecond(); }
119+
double GetElapsedRealTimeS() const { return static_cast<double>(g_TimerMan.GetRealTickCount() - m_StartRealTime) / static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
120120

121121
/// <summary>
122122
/// Sets the start real time value of this Timer.
123123
/// </summary>
124124
/// <param name="newElapsedRealTime">An int64 with the new elapsed time value in seconds.</param>
125-
void SetElapsedRealTimeS(const double newElapsedRealTime) { m_StartRealTime = g_TimerMan.GetRealTickCount() - (newElapsedRealTime * (double)g_TimerMan.GetTicksPerSecond()); }
125+
void SetElapsedRealTimeS(const double newElapsedRealTime) { m_StartRealTime = g_TimerMan.GetRealTickCount() - (newElapsedRealTime * static_cast<double>(g_TimerMan.GetTicksPerSecond())); }
126126

127127
/// <summary>
128128
/// Returns how much time in ms that there is left till this Timer reaches a certain time limit.
@@ -148,7 +148,7 @@ namespace RTE {
148148
/// Returns how much time in ms that there is left till this Timer reaches a certain time limit previously set by SetRealTimeLimitS.
149149
/// </summary>
150150
/// <returns>A unsigned long with the real time left till the passed in value, or negative if this Timer is already past that point in time.</returns>
151-
double LeftTillRealTimeLimitS() { return (m_RealTimeLimit * (double)g_TimerMan.GetTicksPerSecond()) - GetElapsedRealTimeS(); }
151+
double LeftTillRealTimeLimitS() { return (m_RealTimeLimit * static_cast<double>(g_TimerMan.GetTicksPerSecond())) - GetElapsedRealTimeS(); }
152152

153153
/// <summary>
154154
/// Returns true if the elapsed real time is past a certain amount of time after the start previously set by SetRealTimeLimit.
@@ -169,7 +169,7 @@ namespace RTE {
169169
/// </summary>
170170
/// <param name="period">An int with the alternating period in ms. The time specified here is how long it will take for the switch to alternate.</param>
171171
/// <returns>Whether the elapsed time is in the first state or not.</returns>
172-
bool AlternateReal(int period) const { return ((int)GetElapsedRealTimeMS() % (period * 2)) > period; }
172+
bool AlternateReal(int period) const { return (static_cast<int>(GetElapsedRealTimeMS()) % (period * 2)) > period; }
173173
#pragma endregion
174174

175175
#pragma region Simulation Time
@@ -204,20 +204,20 @@ namespace RTE {
204204
/// This is when the timer is supposed to show that it has 'expired' or reached whatever time limit it is supposed to keep track of.
205205
/// </summary>
206206
/// <returns>A positive double with the sim time limit relative to the start time.</returns>
207-
double GetSimTimeLimitS() const { return m_SimTimeLimit / (double)g_TimerMan.GetTicksPerSecond(); }
207+
double GetSimTimeLimitS() const { return m_SimTimeLimit / static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
208208

209209
/// <summary>
210210
/// Sets the sim time limit value of this Timer, RELATVE to the start time.
211211
/// This is when the timer is supposed to show that it has 'expired' or reached whatever time limit it is supposed to keep track of.
212212
/// </summary>
213213
/// <param name="newTimeLimit">A positive double with the new sim time limit relative to the start time.</param>
214-
void SetSimTimeLimitS(double newTimeLimit) { m_SimTimeLimit = newTimeLimit * (double)g_TimerMan.GetTicksPerSecond(); }
214+
void SetSimTimeLimitS(double newTimeLimit) { m_SimTimeLimit = newTimeLimit * static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
215215

216216
/// <summary>
217217
/// Gets the elapsed time in ms since this Timer was Reset().
218218
/// </summary>
219219
/// <returns>A unsigned long value that represents the elapsed time since Reset() in ms.</returns>
220-
double GetElapsedSimTimeMS() const { return (double)(g_TimerMan.GetSimTickCount() - m_StartSimTime) / m_TicksPerMS; }
220+
double GetElapsedSimTimeMS() const { return static_cast<double>(g_TimerMan.GetSimTickCount() - m_StartSimTime) / m_TicksPerMS; }
221221

222222
/// <summary>
223223
/// Sets the start time value of this Timer, in ms.
@@ -229,13 +229,13 @@ namespace RTE {
229229
/// Gets the elapsed time in s since this Timer was Reset().
230230
/// </summary>
231231
/// <returns>A unsigned long value that represents the elapsed time since Reset() in s.</returns>
232-
double GetElapsedSimTimeS() const { return (double)(g_TimerMan.GetSimTickCount() - m_StartSimTime) / (double)g_TimerMan.GetTicksPerSecond(); }
232+
double GetElapsedSimTimeS() const { return static_cast<double>(g_TimerMan.GetSimTickCount() - m_StartSimTime) / static_cast<double>(g_TimerMan.GetTicksPerSecond()); }
233233

234234
/// <summary>
235235
/// Sets the start time value of this Timer, in seconds.
236236
/// </summary>
237237
/// <param name="newElapsedSimTime">An int64 with the new elapsed time value in seconds.</param>
238-
void SetElapsedSimTimeS(const double newElapsedSimTime) { m_StartSimTime = g_TimerMan.GetSimTickCount() - (newElapsedSimTime * (double)g_TimerMan.GetTicksPerSecond()); }
238+
void SetElapsedSimTimeS(const double newElapsedSimTime) { m_StartSimTime = g_TimerMan.GetSimTickCount() - (newElapsedSimTime * static_cast<double>(g_TimerMan.GetTicksPerSecond())); }
239239

240240
/// <summary>
241241
/// Returns how much time in ms that there is left till this Timer reaches a certain time limit.a certain time limit.
@@ -261,7 +261,7 @@ namespace RTE {
261261
/// Returns how much time in ms that there is left till this Timer reaches a certain time limit previously set by SetSimTimeLimitS.
262262
/// </summary>
263263
/// <returns>A unsigned long with the sim time left till the passed in value, or negative if this Timer is already past that point in time.</returns>
264-
double LeftTillSimTimeLimitS() const { return (m_SimTimeLimit * (double)g_TimerMan.GetTicksPerSecond()) - GetElapsedSimTimeS(); }
264+
double LeftTillSimTimeLimitS() const { return (m_SimTimeLimit * static_cast<double>(g_TimerMan.GetTicksPerSecond())) - GetElapsedSimTimeS(); }
265265

266266
/// <summary>
267267
/// Returns true if the elapsed sim time is past a certain amount of time after the start previously set by SetSimTimeLimit.
@@ -282,7 +282,7 @@ namespace RTE {
282282
/// </summary>
283283
/// <param name="period">An int with the alternating period in ms. The time specified here is how long it will take for the switch to alternate.</param>
284284
/// <returns>Whether the elapsed time is in the first state or not.</returns>
285-
bool AlternateSim(int period) const { if (period == 0) return true; else return ((int)GetElapsedSimTimeMS() % (period * 2)) > period; }
285+
bool AlternateSim(int period) const { return (period == 0) ? true : (static_cast<int>(GetElapsedSimTimeMS()) % (period * 2)) > period; }
286286
#pragma endregion
287287

288288
#pragma region Class Info

System/Vector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace RTE {
9191
/// Sets the X value of this Vector.
9292
/// </summary>
9393
/// <param name="newX">An int value that the X value will be set to.</param>
94-
void SetIntX(const int newX) { m_X = (float)newX; }
94+
void SetIntX(const int newX) { m_X = static_cast<float>(newX); }
9595

9696
/// <summary>
9797
/// Gets the Y value of this Vector.
@@ -109,7 +109,7 @@ namespace RTE {
109109
/// Sets the Y value of this Vector.
110110
/// </summary>
111111
/// <param name="newY">An int value that the Y value will be set to.</param>
112-
void SetIntY(const int newY) { m_Y = (float)newY; }
112+
void SetIntY(const int newY) { m_Y = static_cast<float>(newY); }
113113

114114
/// <summary>
115115
/// Sets both the X and Y values of this Vector.
@@ -123,7 +123,7 @@ namespace RTE {
123123
/// </summary>
124124
/// <param name="newX">An int value that the X value will be set to.</param>
125125
/// <param name="newY">An int value that the Y value will be set to.</param>
126-
void SetIntXY(const int newX, const int newY) { m_X = (float)newX; m_Y = (float)newY; }
126+
void SetIntXY(const int newX, const int newY) { m_X = static_cast<float>(newX); m_Y = static_cast<float>(newY); }
127127

128128
/// <summary>
129129
/// Gets the absolute largest of the two elements. Will always be positive.

0 commit comments

Comments
 (0)