diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index b23b68304..0acf40b9a 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -1473,10 +1473,6 @@ void Renderer::DrawBlob(Vec2 pos, RGB colour) BlendPixel(pos + Vec2{ -1, +1 }, colour.WithAlpha(64)); } -float temp[CELL*3][CELL*3]; -float fire_alphaf[CELL*3][CELL*3]; -float glow_alphaf[11][11]; -float blur_alphaf[7][7]; void Renderer::prepare_alpha(int size, float intensity) { fireIntensity = intensity; @@ -1484,6 +1480,7 @@ void Renderer::prepare_alpha(int size, float intensity) int x,y,i,j; float multiplier = 255.0f*fireIntensity; + float temp[CELL*3][CELL*3]; memset(temp, 0, sizeof(temp)); for (x=0; x -static void initDeltaPos(); static void changeType(ELEMENT_CHANGETYPE_FUNC_ARGS); void Element::Element_ETRD() @@ -46,8 +45,6 @@ void Element::Element_ETRD() HighTemperatureTransition = NT; ChangeType = &changeType; - - initDeltaPos(); } static void changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) @@ -75,12 +72,10 @@ public: int length; }; -const int maxLength = 12; -std::vector deltaPos; - -static void initDeltaPos() +static const std::vector InitDeltaPos() { - deltaPos.clear(); + const int maxLength = 12; + std::vector deltaPos; for (int ry = -maxLength; ry <= maxLength; ry++) for (int rx = -maxLength; rx <= maxLength; rx++) { @@ -91,7 +86,9 @@ static void initDeltaPos() std::stable_sort(deltaPos.begin(), deltaPos.end(), [](const ETRD_deltaWithLength &a, const ETRD_deltaWithLength &b) { return a.length < b.length; }); + return deltaPos; } +static const auto deltaPos = InitDeltaPos(); int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId) { @@ -118,9 +115,8 @@ int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId) // TODO: probably not optimal if excessive stacking is used if (sim->parts.lastActiveIndex > (int)deltaPos.size()*2) { - for (std::vector::iterator iter = deltaPos.begin(), end = deltaPos.end(); iter != end; ++iter) + for (auto &delta : deltaPos) { - ETRD_deltaWithLength delta = (*iter); ui::Point checkPos = targetPos + delta.d; int checkDistance = delta.length; if (parts[targetId].tmp >= checkDistance) // tmp sets min distance diff --git a/src/simulation/elements/LOLZ.cpp b/src/simulation/elements/LOLZ.cpp index 8f22276c4..0951b28b0 100644 --- a/src/simulation/elements/LOLZ.cpp +++ b/src/simulation/elements/LOLZ.cpp @@ -43,7 +43,7 @@ void Element::Element_LOLZ() HighTemperatureTransition = NT; } -int Element_LOLZ_RuleTable[9][9] = +extern const int Element_LOLZ_RuleTable[9][9] = { {0,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,1,0,0}, @@ -55,5 +55,3 @@ int Element_LOLZ_RuleTable[9][9] = {0,1,0,0,0,0,0,1,0}, {0,1,0,0,0,0,0,1,0}, }; - -int Element_LOLZ_lolz[XRES/9][YRES/9]; diff --git a/src/simulation/elements/LOLZ.h b/src/simulation/elements/LOLZ.h index 1eaecdab7..c4d87d161 100644 --- a/src/simulation/elements/LOLZ.h +++ b/src/simulation/elements/LOLZ.h @@ -1,7 +1,5 @@ #pragma once #include "simulation/ElementDefs.h" -extern int Element_LOLZ_RuleTable[9][9]; -extern int Element_LOLZ_lolz[XRES/9][YRES/9]; -extern int Element_LOVE_RuleTable[9][9]; -extern int Element_LOVE_love[XRES/9][YRES/9]; +extern const int Element_LOLZ_RuleTable[9][9]; +extern const int Element_LOVE_RuleTable[9][9]; diff --git a/src/simulation/elements/LOVE.cpp b/src/simulation/elements/LOVE.cpp index 8674bf1c5..4d0b19b72 100644 --- a/src/simulation/elements/LOVE.cpp +++ b/src/simulation/elements/LOVE.cpp @@ -42,7 +42,7 @@ void Element::Element_LOVE() HighTemperatureTransition = NT; } -int Element_LOVE_RuleTable[9][9] = +extern const int Element_LOVE_RuleTable[9][9] = { {0,0,1,1,0,0,0,0,0}, {0,1,0,0,1,1,0,0,0}, @@ -54,5 +54,3 @@ int Element_LOVE_RuleTable[9][9] = {0,1,0,0,1,1,0,0,0}, {0,0,1,1,0,0,0,0,0}, }; - -int Element_LOVE_love[XRES/9][YRES/9]; diff --git a/src/simulation/elements/PIPE.h b/src/simulation/elements/PIPE.h index ad3d5d253..c5d0bdb5e 100644 --- a/src/simulation/elements/PIPE.h +++ b/src/simulation/elements/PIPE.h @@ -24,5 +24,4 @@ constexpr int PFLAG_COLOR_GREEN = 0x00080000; constexpr int PFLAG_COLOR_BLUE = 0x000C0000; constexpr int PFLAG_COLORS = 0x000C0000; -extern int Element_PPIP_ppip_changed; extern const std::array, 8> Element_PIPE_offsets; diff --git a/src/simulation/elements/PPIP.cpp b/src/simulation/elements/PPIP.cpp index f42441ecb..5f16840b9 100644 --- a/src/simulation/elements/PPIP.cpp +++ b/src/simulation/elements/PPIP.cpp @@ -61,8 +61,6 @@ constexpr int PPIP_TMPFLAG_TRIGGER_REVERSE = 0x04000000; // 0x00002000 will transfer like a single pixel pipe when in reverse mode // 0x0001C000 reverse single pixel pipe direction -int Element_PPIP_ppip_changed = 0; - void Element_PPIP_flood_trigger(Simulation * sim, int x, int y, int sparkedBy) { int coord_stack_limit = XRES*YRES; @@ -120,7 +118,7 @@ void Element_PPIP_flood_trigger(Simulation * sim, int x, int y, int sparkedBy) for (x=x1; x<=x2; x++) { if (!(parts[ID(pmap[y][x])].tmp & prop) && sparkedBy != PT_HEAC) - Element_PPIP_ppip_changed = 1; + sim->Element_PPIP_ppip_changed = 1; parts[ID(pmap[y][x])].tmp |= prop; } diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index c25773e08..c581118e3 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -67,8 +67,6 @@ struct StackData } }; -int tempParts[XRES]; - constexpr int PISTON_INACTIVE = 0x00; constexpr int PISTON_RETRACT = 0x01; constexpr int PISTON_EXTEND = 0x02; @@ -221,14 +219,14 @@ static StackData CanMoveStack(Simulation * sim, int stackX, int stackY, int dire if (!r) { spaces++; - tempParts[currentPos++] = -1; + sim->Element_PSTN_tempParts[currentPos++] = -1; if (spaces >= amount) break; } else { if (currentPos - spaces < maxSize && (!retract || (TYP(r) == PT_FRME && posX == stackX && posY == stackY))) - tempParts[currentPos++] = ID(r); + sim->Element_PSTN_tempParts[currentPos++] = ID(r); else return StackData(currentPos - spaces, spaces); } @@ -306,13 +304,13 @@ static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, i break; } else { foundParts = true; - tempParts[currentPos++] = ID(r); + sim->Element_PSTN_tempParts[currentPos++] = ID(r); } } if(foundParts) { //Move particles for(int j = 0; j < currentPos; j++) { - int jP = tempParts[j]; + int jP = sim->Element_PSTN_tempParts[j]; int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f); int destX = srcX-directionX*amount, destY = srcY-directionY*amount; sim->pmap[srcY][srcX] = 0; @@ -329,7 +327,7 @@ static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, i //Move particles int possibleMovement = 0; for(int j = currentPos-1; j >= 0; j--) { - int jP = tempParts[j]; + int jP = sim->Element_PSTN_tempParts[j]; if(jP < 0) { possibleMovement++; continue; diff --git a/src/simulation/elements/TRON.cpp b/src/simulation/elements/TRON.cpp index b818d25fa..e8a68830b 100644 --- a/src/simulation/elements/TRON.cpp +++ b/src/simulation/elements/TRON.cpp @@ -3,7 +3,6 @@ static int update(UPDATE_FUNC_ARGS); static int graphics(GRAPHICS_FUNC_ARGS); static void create(ELEMENT_CREATE_FUNC_ARGS); -static void init_graphics(); static int trymovetron(Simulation * sim, int x, int y, int dir, int i, int len); static bool canmovetron(Simulation * sim, int r, int len); static int new_tronhead(Simulation * sim, int x, int y, int i, int direction); @@ -52,8 +51,6 @@ void Element::Element_TRON() Update = &update; Graphics = &graphics; Create = &create; - - init_graphics(); } /* TRON element is meant to resemble a tron bike (or worm) moving around and trying to avoid obstacles itself. @@ -80,20 +77,24 @@ constexpr auto TRON_WAIT = UINT32_C(0x00000004); //it was just created, so W constexpr auto TRON_NODIE = UINT32_C(0x00000008); constexpr auto TRON_DEATH = UINT32_C(0x00000010); //Crashed, now dying constexpr auto TRON_NORANDOM = UINT32_C(0x00010000); -int tron_rx[4] = {-1, 0, 1, 0}; -int tron_ry[4] = { 0,-1, 0, 1}; -unsigned int tron_colours[32]; +constexpr int tron_rx[4] = {-1, 0, 1, 0}; +constexpr int tron_ry[4] = { 0,-1, 0, 1}; -static void init_graphics() +static const std::array MakeTronColors() { + std::array tron_colours; int i; int r, g, b; for (i=0; i<32; i++) { + // funny almost-bug: if (i<<4) > 360(ish), HSV_to_RGB does nothing with r/g/b, + // but since the variables are reused across iterations of the loop, they will still have sane values HSV_to_RGB(i<<4,255,255,&r,&g,&b); tron_colours[i] = r<<16 | g<<8 | b; } + return tron_colours; } +static const auto tron_colours = MakeTronColors(); static int update(UPDATE_FUNC_ARGS) {