@@ -38,12 +38,15 @@ namespace RTE {
38
38
m_BlueGlow = glowFile.GetAsBitmap ();
39
39
m_BlueGlowHash = glowFile.GetHash ();
40
40
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
+ };
47
50
48
51
return 0 ;
49
52
}
@@ -54,17 +57,15 @@ namespace RTE {
54
57
ClearScreenPostEffects ();
55
58
ClearScenePostEffects ();
56
59
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 ();
63
64
}
64
65
65
66
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
67
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) {
68
69
int screenOcclusionOffsetX = g_SceneMan.GetScreenOcclusion (playerScreen).GetFloorIntX ();
69
70
int screenOcclusionOffsetY = g_SceneMan.GetScreenOcclusion (playerScreen).GetFloorIntY ();
70
71
int occludedOffsetX = targetBitmap->w + screenOcclusionOffsetX;
@@ -98,7 +99,7 @@ namespace RTE {
98
99
99
100
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100
101
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) {
102
103
bool found = false ;
103
104
104
105
// Do the first unwrapped rect
@@ -124,25 +125,20 @@ namespace RTE {
124
125
125
126
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126
127
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 ;
141
137
}
142
138
143
139
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144
140
145
- void PostProcessMan::RegisterGlowDotEffect (const Vector &effectPos, DotGlowColor color, int strength) {
141
+ void PostProcessMan::RegisterGlowDotEffect (const Vector &effectPos, DotGlowColor color, unsigned char strength) {
146
142
// These effects only apply only once per drawn sim update, and only on the first frame drawn after one or more sim updates
147
143
if (color != NoDot && g_TimerMan.DrawnSimUpdate () && g_TimerMan.SimUpdatesSinceDrawn () >= 0 ) {
148
144
RegisterPostEffect (effectPos, GetDotGlowEffect (color), GetDotGlowEffectHash (color), strength);
@@ -180,7 +176,7 @@ namespace RTE {
180
176
181
177
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
182
178
183
- void PostProcessMan::GetNetworkPostEffectsList (int whichScreen, std::list<PostEffect> & outputList) {
179
+ void PostProcessMan::GetNetworkPostEffectsList (short whichScreen, std::list<PostEffect> & outputList) {
184
180
ScreenRelativeEffectsMutex[whichScreen].lock ();
185
181
outputList.clear ();
186
182
for (std::list<PostEffect>::iterator eItr = m_ScreenRelativeEffects[whichScreen].begin (); eItr != m_ScreenRelativeEffects[whichScreen].end (); ++eItr) {
@@ -191,7 +187,7 @@ namespace RTE {
191
187
192
188
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
193
189
194
- void PostProcessMan::SetNetworkPostEffectsList (int whichScreen, std::list<PostEffect> & inputList) {
190
+ void PostProcessMan::SetNetworkPostEffectsList (short whichScreen, std::list<PostEffect> & inputList) {
195
191
ScreenRelativeEffectsMutex[whichScreen].lock ();
196
192
m_ScreenRelativeEffects[whichScreen].clear ();
197
193
for (std::list<PostEffect>::iterator eItr = inputList.begin (); eItr != inputList.end (); ++eItr) {
@@ -202,7 +198,7 @@ namespace RTE {
202
198
203
199
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
204
200
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) {
206
202
bool found = false ;
207
203
bool unseen = false ;
208
204
Vector postEffectPosRelativeToBox;
@@ -221,7 +217,7 @@ namespace RTE {
221
217
222
218
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223
219
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) {
225
221
bool found = false ;
226
222
bool unseen = false ;
227
223
Vector postEffectPosRelativeToBox;
@@ -358,48 +354,31 @@ namespace RTE {
358
354
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
359
355
360
356
void PostProcessMan::DrawPostScreenEffects () {
361
- BITMAP *pBitmap = 0 ;
357
+ BITMAP *effectBitmap = 0 ;
362
358
int effectPosX = 0 ;
363
359
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);
375
369
376
370
// 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);
379
373
} 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 );
397
376
398
377
Matrix newAngle;
399
- newAngle.SetRadAngle (angle );
378
+ newAngle.SetRadAngle (postEffect. m_Angle );
400
379
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);
403
382
}
404
383
}
405
384
}
0 commit comments