Make some free-floating arrays sim data

This commit is contained in:
Tamás Bálint Misius
2025-03-21 19:21:52 +01:00
parent 5e0fc38b8f
commit 2babec6d2b
11 changed files with 33 additions and 42 deletions

View File

@@ -1473,10 +1473,6 @@ void Renderer::DrawBlob(Vec2<int> 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<CELL; x++)
for (y=0; y<CELL; y++)

View File

@@ -1023,6 +1023,10 @@ void Simulation::clear_sim(void)
memset(fighters, 0, sizeof(fighters));
memset(&player, 0, sizeof(player));
memset(&player2, 0, sizeof(player2));
memset(&Element_LOLZ_lolz, 0, sizeof(Element_LOLZ_lolz));
memset(&Element_LOVE_love, 0, sizeof(Element_LOVE_love));
memset(&Element_PSTN_tempParts, 0, sizeof(Element_PSTN_tempParts));
Element_PPIP_ppip_changed = 0;
std::fill(elementCount, elementCount+PT_NUM, 0);
elementRecount = true;
fighcount = 0;

View File

@@ -128,6 +128,10 @@ public:
float fvx[YCELLS][XCELLS];
float fvy[YCELLS][XCELLS];
int Element_LOLZ_lolz[XRES/9][YRES/9];
int Element_LOVE_love[XRES/9][YRES/9];
int Element_PSTN_tempParts[std::max(XRES, YRES)];
int Element_PPIP_ppip_changed;
unsigned int pmap_count[YRES][XRES];

View File

@@ -2,7 +2,6 @@
#include "ETRD.h"
#include <algorithm>
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<ETRD_deltaWithLength> deltaPos;
static void initDeltaPos()
static const std::vector<ETRD_deltaWithLength> InitDeltaPos()
{
deltaPos.clear();
const int maxLength = 12;
std::vector<ETRD_deltaWithLength> 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<ETRD_deltaWithLength>::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

View File

@@ -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];

View File

@@ -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];

View File

@@ -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];

View File

@@ -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<Vec2<int>, 8> Element_PIPE_offsets;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<unsigned int, 32> MakeTronColors()
{
std::array<unsigned int, 32> 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)
{