From 450cf1a31e2fb60e1a81020ad4aa43df2e31c982 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 3 Jul 2020 02:31:13 -0700 Subject: [PATCH] Turn star and backbox vectors into arrays There's always 50 stars and always 18 backboxes, there's no reason to have them be vectors. --- desktop_version/src/Graphics.cpp | 29 ++++++++++++++++------------- desktop_version/src/Graphics.h | 14 ++++++++------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index cc8d1fac..f7ad24a7 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -39,13 +39,16 @@ void Graphics::init() setflipmode = false; //Background inits - for (int i = 0; i < 50; i++) + for (int i = 0; i < numstars; i++) { SDL_Rect s = {Sint16(fRandom() * 320), Sint16(fRandom() * 240), 2, 2}; int s2 = 4+(fRandom()*4); - stars.push_back(s); - starsspeed.push_back(s2); + stars[i] = s; + starsspeed[i] = s2; + } + for (int i = 0; i < numbackboxes; i++) + { SDL_Rect bb; int bvx = 0; int bvy = 0; @@ -64,10 +67,10 @@ void Graphics::init() setRect(bb, fRandom() * 320, fRandom() * 240, 12, 32) ; } float bint = 0.5 + ((fRandom() * 100) / 200); - backboxes.push_back(bb); - backboxvx.push_back(bvx); - backboxvy.push_back(bvy); - backboxint.push_back(bint); + backboxes[i] = bb; + backboxvx[i] = bvx; + backboxvy[i] = bvy; + backboxint[i] = bint; } backoffset = 0; backgrounddrawn = false; @@ -1938,7 +1941,7 @@ void Graphics::drawbackground( int t ) case 1: //Starfield FillRect(backBuffer,0x00000); - for (int i = 0; i < 50; i++) + for (int i = 0; i < numstars; i++) { stars[i].w = 2; stars[i].h = 2; @@ -2022,7 +2025,7 @@ void Graphics::drawbackground( int t ) } FillRect(backBuffer,bcol2); - for (int i = 0; i < 18; i++) + for (int i = 0; i < numbackboxes; i++) { switch(rcol) { @@ -2168,7 +2171,7 @@ void Graphics::drawbackground( int t ) case 6: //Final Starfield FillRect(backBuffer,0x000000); - for (int i = 0; i < 50; i++) + for (int i = 0; i < numstars; i++) { stars[i].w = 2; stars[i].h = 2; @@ -2227,7 +2230,7 @@ void Graphics::updatebackground(int t) { case 1: //Starfield - for (int i = 0; i < 50; i++) + for (int i = 0; i < numstars; i++) { stars[i].w = 2; stars[i].h = 2; @@ -2254,7 +2257,7 @@ void Graphics::updatebackground(int t) if (spcol >= 12) spcol = 0; } } - for (int i = 0; i < 18; i++) + for (int i = 0; i < numbackboxes; i++) { backboxes[i].x += backboxvx[i]; backboxes[i].y += backboxvy[i]; @@ -2370,7 +2373,7 @@ void Graphics::updatebackground(int t) break; case 6: //Final Starfield - for (int i = 0; i < 50; i++) + for (int i = 0; i < numstars; i++) { stars[i].w = 2; stars[i].h = 2; diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 24a220e4..3e63672f 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -280,14 +280,16 @@ public: int cutscenebarspos; int oldcutscenebarspos; - std::vector stars; - std::vector starsspeed; + static const int numstars = 50; + SDL_Rect stars[numstars]; + int starsspeed[numstars]; + static const int numbackboxes = 18; int spcol, spcoldel; - std::vector backboxes; - std::vector backboxvx; - std::vector backboxvy; - std::vector backboxint; + SDL_Rect backboxes[numbackboxes]; + int backboxvx[numbackboxes]; + int backboxvy[numbackboxes]; + float backboxint[numbackboxes]; int warpskip, warpfcol, warpbcol;