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

Commit e1bbac9

Browse files
authored
Merge pull request #113 from orengg/reduce_conditionals
reduce conditional statement complexity
2 parents ec6f8c2 + c2ada89 commit e1bbac9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Main.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,25 @@ bool PlayIntroTitle() {
438438
StarSize size;
439439

440440
for (int star = 0; star < starCount; ++star) {
441-
aStars[star].m_Size = size = PosRand() < 0.95 ? StarSmall : (PosRand() < 0.85 ? StarLarge : StarHuge);
442-
aStars[star].m_pBitmap = size == StarSmall ? apStarSmallBitmaps[SelectRand(0, starSmallBitmapCount - 1)] :
443-
(size == StarLarge ? apStarLargeBitmaps[SelectRand(0, starLargeBitmapCount - 1)] : apStarHugeBitmaps[SelectRand(0, starLargeBitmapCount - 1)]);
441+
if (PosRand() < 0.95) {
442+
aStars[star].m_Size = StarSmall;
443+
aStars[star].m_pBitmap = apStarSmallBitmaps[SelectRand(0, starSmallBitmapCount - 1)];
444+
aStars[star].m_Intensity = RangeRand(0.001, 0.5);
445+
}
446+
else if (PosRand() < 0.85) {
447+
aStars[star].m_Size = StarLarge;
448+
aStars[star].m_pBitmap = apStarLargeBitmaps[SelectRand(0, starLargeBitmapCount - 1)];
449+
aStars[star].m_Intensity = RangeRand(0.6, 1.0);
450+
}
451+
else {
452+
aStars[star].m_Size = StarHuge;
453+
aStars[star].m_pBitmap = apStarHugeBitmaps[SelectRand(0, starLargeBitmapCount - 1)];
454+
aStars[star].m_Intensity = RangeRand(0.9, 1.0);
455+
}
444456
aStars[star].m_Pos.SetXY(resX * PosRand(), pBackdrop->GetBitmap()->h * PosRand());//resY * PosRand());
445457
aStars[star].m_Pos.Floor();
446458
// To match the nebula scroll
447459
aStars[star].m_ScrollRatio = backdropScrollRatio;
448-
aStars[star].m_Intensity = size == StarSmall ? RangeRand(0.001, 0.5) : (size == StarLarge ? RangeRand(0.6, 1.0) : RangeRand(0.9, 1.0));
449460
}
450461

451462
// Font stuff
@@ -603,7 +614,7 @@ bool PlayIntroTitle() {
603614
for (int star = 0; star < starCount; ++star)
604615
{
605616
size = aStars[star].m_Size;
606-
int intensity = 185 * aStars[star].m_Intensity + (size == StarSmall ? 35 : (size == StarLarge ? 70 : 70)) * PosRand();
617+
int intensity = 185 * aStars[star].m_Intensity + (size == StarSmall ? 35 : 70) * PosRand();
607618
set_screen_blender(intensity, intensity, intensity, intensity);
608619
starDrawPos.SetXY(aStars[star].m_Pos.m_X, aStars[star].m_Pos.m_Y - scrollOffset.m_Y * aStars[star].m_ScrollRatio);
609620
draw_trans_sprite(g_FrameMan.GetBackBuffer32(), aStars[star].m_pBitmap, starDrawPos.GetFloorIntX(), starDrawPos.GetFloorIntY());

0 commit comments

Comments
 (0)