From a50f4a10f3c8c3b5edfe1b26970a947958d821a6 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:57:52 -0500 Subject: [PATCH] Reduce PAPR+ARAY read/write duration and reformat mark color --- src/simulation/Simulation.cpp | 2 +- src/simulation/elements/ARAY.cpp | 14 +++++++----- src/simulation/elements/LDTC.cpp | 12 +++++++--- src/simulation/elements/PAPR.cpp | 39 +++++++++++--------------------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 47480df31..d601be429 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1097,7 +1097,7 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) const case PT_PAPR: // BCOL can always pass through PAPR in order to color it // Most elements are blocked by marked PAPR, except for certified "weird" elements where it's inverse - if ((pt == PT_BCOL) || ((parts[ID(r)].life >> 24) & 0x01 ^ (pt != PT_ANAR && pt != PT_BIZR && pt != PT_BIZRG))) + if ((pt == PT_BCOL) || (parts[ID(r)].life ^ (pt != PT_ANAR && pt != PT_BIZR && pt != PT_BIZRG))) result = 2; else result = 0; diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 38393d91a..3a2e9f6dd 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -175,7 +175,7 @@ static int update(UPDATE_FUNC_ARGS) // Read // End reading state early parts[r].tmp = 0; - if ((parts[r].life >> 24) & 0x1) + if (parts[r].life) { break; } @@ -183,13 +183,14 @@ static int update(UPDATE_FUNC_ARGS) else { // Write - parts[r].life = 0x11A2222; + parts[r].life = 1; + parts[r].dcolour = 0xFF1A2222; } } else { // Enter writing state - parts[r].tmp = 0x0A; + parts[r].tmp = 0x03; } // this if prevents BRAY from stopping on certain materials } @@ -236,7 +237,7 @@ static int update(UPDATE_FUNC_ARGS) // Read // End reading state early parts[r].tmp = 0; - if ((parts[r].life >> 24) & 0x1) + if (parts[r].life) { break; } @@ -244,13 +245,14 @@ static int update(UPDATE_FUNC_ARGS) else { // Write - parts[r].life = 0x0; + parts[r].life = 0; + parts[r].dcolour = 0; } } else { // Enter reading state - parts[r].tmp = 0x1A; + parts[r].tmp = 0x13; } } docontinue = 1; diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index 645a2b2c2..efa114bee 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -160,7 +160,7 @@ static int update(UPDATE_FUNC_ARGS) int bit = 0x1; while (TYP(rr) == PT_PAPR && bit <= 0x3FFFFFFF) { - if ((parts[ID(rr)].life >> 24) & 0x1) + if (parts[ID(rr)].life) { photonWl |= bit; } @@ -190,9 +190,15 @@ static int update(UPDATE_FUNC_ARGS) while (TYP(r) == PT_PAPR && bit <= 0x3FFFFFFF) { if (photonWl & bit) - parts[ID(r)].life = 0x1080820; + { + parts[ID(r)].life = 1; + parts[ID(r)].dcolour = 0x1080820; + } else - parts[ID(r)].life = 0x0; + { + parts[ID(r)].life = 0; + parts[ID(r)].dcolour = 0; + } nx += rx; ny += ry; if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index 78fd53d01..5a69c6540 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -50,7 +50,7 @@ void Element::Element_PAPR() LowTemperature = ITL; LowTemperatureTransition = NT; HighTemperature = 700.0f; - HighTemperatureTransition = PT_NONE; // Add ash or broken paper element? + HighTemperatureTransition = PT_NONE; Update = &update; Graphics = &graphics; @@ -81,25 +81,14 @@ static int update(UPDATE_FUNC_ARGS) // Get marked by BCOL if (TYP(pmap[y][x]) == PT_BCOL) { - parts[i].life = 0x122222A; + parts[i].life = 1; + parts[i].dcolour = 0xFF22222A; } - // Get unmarked by SOAP - for (auto rx = -1; rx <= 1; rx++) + // Generally, these should correspond, but correct if they don't. + if (!parts[i].life != !parts[i].dcolour) { - for (auto ry = -1; ry <= 1; ry++) - { - if (rx || ry) - { - auto r = pmap[y+ry][x+rx]; - if (!r) - continue; - if (TYP(r) == PT_SOAP) - { - parts[i].life = 0; - } - } - } + parts[i].life = parts[i].dcolour ? 1 : 0; } // Decrement tmp counter for laser reading/writing @@ -116,15 +105,12 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { - int ta = (cpart->life >> 24) & 0x01; - int tr = (cpart->life >> 16) & 0xFF; - int tg = (cpart->life >> 8) & 0xFF; - int tb = (cpart->life) & 0xFF; - if (ta) + if (cpart->life) { - *colr = tr; - *colg = tg; - *colb = tb; + float alpha = ((cpart->dcolour >> 24) & 0xFF) / 255.f; + *colr = int(*colr * (1 - alpha) + ((cpart->dcolour >> 16) & 0xFF) * alpha); + *colg = int(*colg * (1 - alpha) + ((cpart->dcolour >> 8) & 0xFF) * alpha); + *colb = int(*colb * (1 - alpha) + ((cpart->dcolour) & 0xFF) * alpha); } // Darken when burnt float maxtemp = std::max((float)cpart->tmp2, cpart->temp); @@ -137,7 +123,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) if (cpart->tmp) { *pixel_mode |= PMODE_GLOW; - float flash = (cpart->tmp & 0xF) / 15.f; + float flash = (cpart->tmp & 0xF) / 3.f; *cola = flash * 200; *colr = int(*colr * (1 - flash)); *colg = int(*colg * (1 - flash)); @@ -152,5 +138,6 @@ static int graphics(GRAPHICS_FUNC_ARGS) *colb += int(255 * flash); } } + *pixel_mode |= NO_DECO; return 0; }