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

Commit 422c41b

Browse files
committed
Renaming some variables and changing integral types to better match the limits of what they are supposed to contain to (possibly) save on them sweet sweet bytes
Other misc changes
1 parent 23a3f15 commit 422c41b

File tree

10 files changed

+237
-288
lines changed

10 files changed

+237
-288
lines changed

Managers/FrameMan.cpp

Lines changed: 74 additions & 101 deletions
Large diffs are not rendered by default.

Managers/FrameMan.h

Lines changed: 61 additions & 60 deletions
Large diffs are not rendered by default.

Managers/LuaMan.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,16 +1434,16 @@ int LuaMan::Create()
14341434
.def("RegisterPostEffect", &PostProcessMan::RegisterPostEffect),
14351435

14361436
class_<PrimitiveMan>("PrimitiveManager")
1437-
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawLinePrimitive)
1438-
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawLinePrimitive)
1439-
.def("DrawBoxPrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawBoxPrimitive)
1440-
.def("DrawBoxPrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawBoxPrimitive)
1441-
.def("DrawBoxFillPrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawBoxFillPrimitive)
1442-
.def("DrawBoxFillPrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned short color))&PrimitiveMan::DrawBoxFillPrimitive)
1443-
.def("DrawCirclePrimitive", (void (PrimitiveMan::*)(Vector pos, short radius, unsigned short color))&PrimitiveMan::DrawCirclePrimitive)
1444-
.def("DrawCirclePrimitive", (void (PrimitiveMan::*)(short player, Vector pos, short radius, unsigned short color))&PrimitiveMan::DrawCirclePrimitive)
1445-
.def("DrawCircleFillPrimitive", (void (PrimitiveMan::*)(Vector pos, short radius, unsigned short color))&PrimitiveMan::DrawCircleFillPrimitive)
1446-
.def("DrawCircleFillPrimitive", (void (PrimitiveMan::*)(short player, Vector pos, short radius, unsigned short color))&PrimitiveMan::DrawCircleFillPrimitive)
1437+
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawLinePrimitive)
1438+
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawLinePrimitive)
1439+
.def("DrawBoxPrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawBoxPrimitive)
1440+
.def("DrawBoxPrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawBoxPrimitive)
1441+
.def("DrawBoxFillPrimitive", (void (PrimitiveMan::*)(Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawBoxFillPrimitive)
1442+
.def("DrawBoxFillPrimitive", (void (PrimitiveMan::*)(short player, Vector start, Vector end, unsigned char color))&PrimitiveMan::DrawBoxFillPrimitive)
1443+
.def("DrawCirclePrimitive", (void (PrimitiveMan::*)(Vector pos, short radius, unsigned char color))&PrimitiveMan::DrawCirclePrimitive)
1444+
.def("DrawCirclePrimitive", (void (PrimitiveMan::*)(short player, Vector pos, short radius, unsigned char color))&PrimitiveMan::DrawCirclePrimitive)
1445+
.def("DrawCircleFillPrimitive", (void (PrimitiveMan::*)(Vector pos, short radius, unsigned char color))&PrimitiveMan::DrawCircleFillPrimitive)
1446+
.def("DrawCircleFillPrimitive", (void (PrimitiveMan::*)(short player, Vector pos, short radius, unsigned char color))&PrimitiveMan::DrawCircleFillPrimitive)
14471447
.def("DrawTextPrimitive", (void (PrimitiveMan::*)(Vector start, std::string text, bool isSmall, short alignment))&PrimitiveMan::DrawTextPrimitive)
14481448
.def("DrawTextPrimitive", (void (PrimitiveMan::*)(short player, Vector start, std::string text, bool isSmall, short alignment))&PrimitiveMan::DrawTextPrimitive)
14491449
.def("DrawBitmapPrimitive", (void (PrimitiveMan::*)(Vector start, Entity * pEntity, float rotAngle, unsigned short frame))&PrimitiveMan::DrawBitmapPrimitive)

Managers/PerformanceMan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ namespace RTE {
192192
sprintf_s(str, sizeof(str), "Sound channels: %d / %d ", g_AudioMan.GetPlayingChannelCount(), g_AudioMan.GetTotalChannelCount());
193193
g_FrameMan.GetLargeFont()->DrawAligned(&bitmapToDrawTo, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
194194

195-
if (m_AdvancedPerfStats) { DrawPeformanceGraphs(bitmapToDrawTo); }
195+
// If in split screen mode don't draw graphs because they don't fit anyway.
196+
if (m_AdvancedPerfStats && g_FrameMan.GetScreenCount() == 1) { DrawPeformanceGraphs(bitmapToDrawTo); }
196197
}
197198
}
198199

Managers/PerformanceMan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace RTE {
134134
/// Sets the current ping value to display.
135135
/// </summary>
136136
/// <param name="ping">Ping value to display.</param>
137-
void SetCurrentPing(unsigned int ping) { m_CurrentPing = ping; }
137+
void SetCurrentPing(unsigned short ping) { m_CurrentPing = ping; }
138138
#pragma endregion
139139

140140
#pragma region Class Info

Managers/PostProcessMan.cpp

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ namespace RTE {
3838
m_BlueGlow = glowFile.GetAsBitmap();
3939
m_BlueGlowHash = glowFile.GetHash();
4040

41-
m_TempEffectBitmap_16 = create_bitmap_ex(32, 16, 16);
42-
m_TempEffectBitmap_32 = create_bitmap_ex(32, 32, 32);
43-
m_TempEffectBitmap_64 = create_bitmap_ex(32, 64, 64);
44-
m_TempEffectBitmap_128 = create_bitmap_ex(32, 128, 128);
45-
m_TempEffectBitmap_256 = create_bitmap_ex(32, 256, 256);
46-
m_TempEffectBitmap_512 = create_bitmap_ex(32, 512, 512);
41+
// Create temporary bitmaps to rotate post effects in.
42+
m_TempEffectBitmaps = {
43+
{16, create_bitmap(16, 16)},
44+
{32, create_bitmap(32, 32)},
45+
{64, create_bitmap(64, 64)},
46+
{128, create_bitmap(128, 128)},
47+
{256, create_bitmap(256, 256)},
48+
{512, create_bitmap(512, 512)}
49+
};
4750

4851
return 0;
4952
}
@@ -54,17 +57,15 @@ namespace RTE {
5457
ClearScreenPostEffects();
5558
ClearScenePostEffects();
5659
Clear();
57-
destroy_bitmap(m_TempEffectBitmap_16);
58-
destroy_bitmap(m_TempEffectBitmap_32);
59-
destroy_bitmap(m_TempEffectBitmap_64);
60-
destroy_bitmap(m_TempEffectBitmap_128);
61-
destroy_bitmap(m_TempEffectBitmap_256);
62-
destroy_bitmap(m_TempEffectBitmap_512);
60+
for (std::pair<unsigned short, BITMAP *> tempBitmapEntry : m_TempEffectBitmaps) {
61+
destroy_bitmap(tempBitmapEntry.second);
62+
}
63+
m_TempEffectBitmaps.clear();
6364
}
6465

6566
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6667

67-
void PostProcessMan::AdjustEffectsPosToPlayerScreen(char playerScreen, BITMAP *targetBitmap, Vector targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList) {
68+
void PostProcessMan::AdjustEffectsPosToPlayerScreen(short playerScreen, BITMAP *targetBitmap, Vector targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList) {
6869
int screenOcclusionOffsetX = g_SceneMan.GetScreenOcclusion(playerScreen).GetFloorIntX();
6970
int screenOcclusionOffsetY = g_SceneMan.GetScreenOcclusion(playerScreen).GetFloorIntY();
7071
int occludedOffsetX = targetBitmap->w + screenOcclusionOffsetX;
@@ -98,7 +99,7 @@ namespace RTE {
9899

99100
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100101

101-
bool PostProcessMan::GetPostScreenEffectsWrapped(const Vector &boxPos, int boxWidth, int boxHeight, std::list<PostEffect> &effectsList, int team) {
102+
bool PostProcessMan::GetPostScreenEffectsWrapped(const Vector &boxPos, int boxWidth, int boxHeight, std::list<PostEffect> &effectsList, short team) {
102103
bool found = false;
103104

104105
// Do the first unwrapped rect
@@ -124,25 +125,20 @@ namespace RTE {
124125

125126
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126127

127-
BITMAP *PostProcessMan::GetTempEffectBitmap(unsigned short bitmapSize) const {
128-
if (bitmapSize <= 16) {
129-
return m_TempEffectBitmap_16;
130-
} else if (bitmapSize <= 32) {
131-
return m_TempEffectBitmap_32;
132-
} else if (bitmapSize <= 64) {
133-
return m_TempEffectBitmap_64;
134-
} else if (bitmapSize <= 128) {
135-
return m_TempEffectBitmap_128;
136-
} else if (bitmapSize <= 256) {
137-
return m_TempEffectBitmap_256;
138-
} else {
139-
return m_TempEffectBitmap_512;
140-
}
128+
BITMAP *PostProcessMan::GetTempEffectBitmap(BITMAP *bitmap) const {
129+
// Get the largest dimension of the bitmap and convert it to a multiple of 16, i.e. 16, 32, etc
130+
unsigned short bitmapSizeNeeded = std::ceil(static_cast<float>(std::max(bitmap->w, bitmap->h)) / 16) * 16;
131+
std::unordered_map<unsigned short, BITMAP *>::const_iterator correspondingBitmapSizeEntry = m_TempEffectBitmaps.find(bitmapSizeNeeded);
132+
133+
// If we didn't find a match then the bitmap size is greater than 512 but that's the biggest we've got, so return it
134+
if (correspondingBitmapSizeEntry == m_TempEffectBitmaps.end()) { correspondingBitmapSizeEntry = m_TempEffectBitmaps.find(512); }
135+
136+
return correspondingBitmapSizeEntry->second;
141137
}
142138

143139
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144140

145-
void PostProcessMan::RegisterGlowDotEffect(const Vector &effectPos, DotGlowColor color, int strength) {
141+
void PostProcessMan::RegisterGlowDotEffect(const Vector &effectPos, DotGlowColor color, unsigned char strength) {
146142
// These effects only apply only once per drawn sim update, and only on the first frame drawn after one or more sim updates
147143
if (color != NoDot && g_TimerMan.DrawnSimUpdate() && g_TimerMan.SimUpdatesSinceDrawn() >= 0) {
148144
RegisterPostEffect(effectPos, GetDotGlowEffect(color), GetDotGlowEffectHash(color), strength);
@@ -180,7 +176,7 @@ namespace RTE {
180176

181177
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
182178

183-
void PostProcessMan::GetNetworkPostEffectsList(int whichScreen, std::list<PostEffect> & outputList) {
179+
void PostProcessMan::GetNetworkPostEffectsList(short whichScreen, std::list<PostEffect> & outputList) {
184180
ScreenRelativeEffectsMutex[whichScreen].lock();
185181
outputList.clear();
186182
for (std::list<PostEffect>::iterator eItr = m_ScreenRelativeEffects[whichScreen].begin(); eItr != m_ScreenRelativeEffects[whichScreen].end(); ++eItr) {
@@ -191,7 +187,7 @@ namespace RTE {
191187

192188
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
193189

194-
void PostProcessMan::SetNetworkPostEffectsList(int whichScreen, std::list<PostEffect> & inputList) {
190+
void PostProcessMan::SetNetworkPostEffectsList(short whichScreen, std::list<PostEffect> & inputList) {
195191
ScreenRelativeEffectsMutex[whichScreen].lock();
196192
m_ScreenRelativeEffects[whichScreen].clear();
197193
for (std::list<PostEffect>::iterator eItr = inputList.begin(); eItr != inputList.end(); ++eItr) {
@@ -202,7 +198,7 @@ namespace RTE {
202198

203199
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
204200

205-
bool PostProcessMan::GetPostScreenEffects(Vector boxPos, int boxWidth, int boxHeight, std::list<PostEffect> &effectsList, int team) {
201+
bool PostProcessMan::GetPostScreenEffects(Vector boxPos, int boxWidth, int boxHeight, std::list<PostEffect> &effectsList, short team) {
206202
bool found = false;
207203
bool unseen = false;
208204
Vector postEffectPosRelativeToBox;
@@ -221,7 +217,7 @@ namespace RTE {
221217

222218
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223219

224-
bool PostProcessMan::GetPostScreenEffects(int left, int top, int right, int bottom, std::list<PostEffect> &effectsList, int team) {
220+
bool PostProcessMan::GetPostScreenEffects(int left, int top, int right, int bottom, std::list<PostEffect> &effectsList, short team) {
225221
bool found = false;
226222
bool unseen = false;
227223
Vector postEffectPosRelativeToBox;
@@ -358,48 +354,31 @@ namespace RTE {
358354
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
359355

360356
void PostProcessMan::DrawPostScreenEffects() {
361-
BITMAP *pBitmap = 0;
357+
BITMAP *effectBitmap = 0;
362358
int effectPosX = 0;
363359
int effectPosY = 0;
364-
int strength = 0;
365-
float angle = 0;
366-
367-
for (std::list<PostEffect>::iterator eItr = m_PostScreenEffects.begin(); eItr != m_PostScreenEffects.end(); ++eItr) {
368-
if ((*eItr).m_Bitmap) {
369-
pBitmap = (*eItr).m_Bitmap;
370-
strength = (*eItr).m_Strength;
371-
set_screen_blender(strength, strength, strength, strength);
372-
effectPosX = (*eItr).m_Pos.GetFloorIntX() - (pBitmap->w / 2);
373-
effectPosY = (*eItr).m_Pos.GetFloorIntY() - (pBitmap->h / 2);
374-
angle = (*eItr).m_Angle;
360+
unsigned char effectStrength = 0;
361+
362+
for (const PostEffect &postEffect : m_PostScreenEffects) {
363+
if (postEffect.m_Bitmap) {
364+
effectBitmap = postEffect.m_Bitmap;
365+
effectStrength = postEffect.m_Strength;
366+
effectPosX = postEffect.m_Pos.GetFloorIntX() - (effectBitmap->w / 2);
367+
effectPosY = postEffect.m_Pos.GetFloorIntY() - (effectBitmap->h / 2);
368+
set_screen_blender(effectStrength, effectStrength, effectStrength, effectStrength);
375369

376370
// Draw all the scene screen effects accumulated this frame
377-
if (angle == 0) {
378-
draw_trans_sprite(g_FrameMan.GetBackBuffer32(), pBitmap, effectPosX, effectPosY);
371+
if (postEffect.m_Angle == 0) {
372+
draw_trans_sprite(g_FrameMan.GetBackBuffer32(), effectBitmap, effectPosX, effectPosY);
379373
} else {
380-
BITMAP * pTargetBitmap;
381-
382-
if (pBitmap->w < 16 && pBitmap->h < 16) {
383-
pTargetBitmap = m_TempEffectBitmap_16;
384-
} else if (pBitmap->w < 32 && pBitmap->h < 32) {
385-
pTargetBitmap = m_TempEffectBitmap_32;
386-
} else if (pBitmap->w < 64 && pBitmap->h < 64) {
387-
pTargetBitmap = m_TempEffectBitmap_64;
388-
} else if (pBitmap->w < 128 && pBitmap->h < 128) {
389-
pTargetBitmap = m_TempEffectBitmap_128;
390-
} else if (pBitmap->w < 256 && pBitmap->h < 256) {
391-
pTargetBitmap = m_TempEffectBitmap_256;
392-
} else {
393-
pTargetBitmap = m_TempEffectBitmap_512;
394-
}
395-
396-
clear_to_color(pTargetBitmap, 0);
374+
BITMAP *targetBitmap = GetTempEffectBitmap(effectBitmap);
375+
clear_to_color(targetBitmap, 0);
397376

398377
Matrix newAngle;
399-
newAngle.SetRadAngle(angle);
378+
newAngle.SetRadAngle(postEffect.m_Angle);
400379

401-
rotate_sprite(pTargetBitmap, pBitmap, 0, 0, ftofix(newAngle.GetAllegroAngle()));
402-
draw_trans_sprite(g_FrameMan.GetBackBuffer32(), pTargetBitmap, effectPosX, effectPosY);
380+
rotate_sprite(targetBitmap, effectBitmap, 0, 0, ftofix(newAngle.GetAllegroAngle()));
381+
draw_trans_sprite(g_FrameMan.GetBackBuffer32(), targetBitmap, effectPosX, effectPosY);
403382
}
404383
}
405384
}

0 commit comments

Comments
 (0)