From 00fa5da4f26b8af7166086d8635c39ab4cba62ed Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:08:58 -0500 Subject: [PATCH 01/15] Added PAPR (currently clone of WOOD) --- src/simulation/elements/PAPR.cpp | 81 +++++++++++++++++++++++++++++ src/simulation/elements/meson.build | 1 + 2 files changed, 82 insertions(+) create mode 100644 src/simulation/elements/PAPR.cpp diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp new file mode 100644 index 000000000..b7ef6e17c --- /dev/null +++ b/src/simulation/elements/PAPR.cpp @@ -0,0 +1,81 @@ +#include "simulation/ElementCommon.h" + +static int update(UPDATE_FUNC_ARGS); +static int graphics(GRAPHICS_FUNC_ARGS); + +void Element::Element_PAPR() +{ + Identifier = "DEFAULT_PT_PAPR"; + Name = "PAPR"; + Colour = 0xF3F3CA_rgb; + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 20; + Explosive = 0; + Meltable = 0; + Hardness = 15; + + Weight = 100; + + HeatConduct = 164; + Description = "Paper. Flammable, readable, writable."; + + Properties = TYPE_SOLID | PROP_NEUTPENETRATE; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 873.0f; + HighTemperatureTransition = PT_FIRE; + + Update = &update; + Graphics = &graphics; +} + +static int update(UPDATE_FUNC_ARGS) +{ + if (parts[i].temp > 450 && parts[i].temp > parts[i].tmp) + parts[i].tmp = (int)parts[i].temp; + + if (parts[i].temp > 773.0f && sim->pv[y/CELL][x/CELL] <= -10.0f) + { + float temp = parts[i].temp; + sim->create_part(i, x, y, PT_BCOL); + parts[i].temp = temp; + } + + return 0; +} + +static int graphics(GRAPHICS_FUNC_ARGS) +{ + float maxtemp = std::max((float)cpart->tmp, cpart->temp); + if (maxtemp > 400) + { + *colr -= (int)restrict_flt((maxtemp-400)/3,0,172); + *colg -= (int)restrict_flt((maxtemp-400)/4,0,140); + *colb -= (int)restrict_flt((maxtemp-400)/20,0,44); + } + if (maxtemp < 273) + { + *colr -= (int)restrict_flt((273-maxtemp)/5,0,40); + *colg += (int)restrict_flt((273-maxtemp)/4,0,40); + *colb += (int)restrict_flt((273-maxtemp)/1.5,0,150); + } + return 0; +} diff --git a/src/simulation/elements/meson.build b/src/simulation/elements/meson.build index 05cc5792f..f8ac7d7cf 100644 --- a/src/simulation/elements/meson.build +++ b/src/simulation/elements/meson.build @@ -191,6 +191,7 @@ simulation_elem_names = [ 'VSNS', 'ROCK', 'LITH', + 'PAPR', ] simulation_elem_src = [] From 74c0467f6b55fad6ab9b5000d66338307ab7b4a7 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Mon, 11 Dec 2023 08:48:12 -0500 Subject: [PATCH 02/15] Basic burning properties --- src/simulation/elements/FIRE.cpp | 5 +++ src/simulation/elements/PAPR.cpp | 58 +++++++++++++++++++------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index 69d2b3fd2..59c243a97 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -195,6 +195,11 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } } } + // Make paper burn more reliably + if (rt==PT_PAPR) + { + parts[ID(r)].temp += 4; + } if (t == PT_LAVA) { diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index b7ef6e17c..4a9892f5d 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -3,6 +3,15 @@ static int update(UPDATE_FUNC_ARGS); static int graphics(GRAPHICS_FUNC_ARGS); +// Element overview: +// PAPR (Paper) is a flammable solid element that can be colored by certain other elements. +// Additionally, it can be read and written to by ARAY. + +// Property usage: +// life: Temporary read/write state for ARAY interaction +// tmp: Written color value. If dcolour is not black, it gets copied here. 1 bit alpha +// tmp2: Singe level + void Element::Element_PAPR() { Identifier = "DEFAULT_PT_PAPR"; @@ -14,7 +23,7 @@ void Element::Element_PAPR() Advection = 0.0f; AirDrag = 0.00f * CFDS; - AirLoss = 0.90f; + AirLoss = 0.995f; Loss = 0.00f; Collision = 0.0f; Gravity = 0.0f; @@ -22,14 +31,14 @@ void Element::Element_PAPR() HotAir = 0.000f * CFDS; Falldown = 0; - Flammable = 20; + Flammable = 0; Explosive = 0; Meltable = 0; Hardness = 15; Weight = 100; - HeatConduct = 164; + HeatConduct = 80; Description = "Paper. Flammable, readable, writable."; Properties = TYPE_SOLID | PROP_NEUTPENETRATE; @@ -40,8 +49,8 @@ void Element::Element_PAPR() HighPressureTransition = NT; LowTemperature = ITL; LowTemperatureTransition = NT; - HighTemperature = 873.0f; - HighTemperatureTransition = PT_FIRE; + HighTemperature = 700.0f; + HighTemperatureTransition = PT_NONE; // Add ash or broken paper element? Update = &update; Graphics = &graphics; @@ -49,33 +58,36 @@ void Element::Element_PAPR() static int update(UPDATE_FUNC_ARGS) { - if (parts[i].temp > 450 && parts[i].temp > parts[i].tmp) - parts[i].tmp = (int)parts[i].temp; - - if (parts[i].temp > 773.0f && sim->pv[y/CELL][x/CELL] <= -10.0f) + if (parts[i].temp > 450 && parts[i].temp >= parts[i].tmp2) { - float temp = parts[i].temp; - sim->create_part(i, x, y, PT_BCOL); - parts[i].temp = temp; + parts[i].tmp2 = (int)parts[i].temp; } + // Auto-ignition temperature + if (parts[i].temp > (451.0f - 32.f) / 1.8f + 273.15f) + { + parts[i].temp += 1; + if (sim->rng.chance((int)parts[i].temp-450,400)) + { + int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_FIRE); + if (np >= 0) + { + parts[np].life = 70; + // parts[np].temp = parts[i].temp; + } + } + } return 0; } static int graphics(GRAPHICS_FUNC_ARGS) { - float maxtemp = std::max((float)cpart->tmp, cpart->temp); - if (maxtemp > 400) + float maxtemp = std::max((float)cpart->tmp2, cpart->temp); + if (maxtemp > 450) { - *colr -= (int)restrict_flt((maxtemp-400)/3,0,172); - *colg -= (int)restrict_flt((maxtemp-400)/4,0,140); - *colb -= (int)restrict_flt((maxtemp-400)/20,0,44); - } - if (maxtemp < 273) - { - *colr -= (int)restrict_flt((273-maxtemp)/5,0,40); - *colg += (int)restrict_flt((273-maxtemp)/4,0,40); - *colb += (int)restrict_flt((273-maxtemp)/1.5,0,150); + *colr -= (int)restrict_flt((maxtemp-450)*1.2f,0,230); + *colg -= (int)restrict_flt((maxtemp-450)*1.4f,0,230); + *colb -= (int)restrict_flt((maxtemp-450)*1.7f,0,197); } return 0; } From 09f86ff962e0242ad4f17ff4b6ba872b2a738a5f Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:06:41 -0500 Subject: [PATCH 03/15] Additional PAPR behavior --- src/simulation/Simulation.cpp | 4 ++++ src/simulation/SimulationData.cpp | 4 ++++ src/simulation/elements/PAPR.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index b1040f7d9..537d6fd4b 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1094,6 +1094,10 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) const return 0; } break; + case PT_PAPR: + // May allow PAPR to block particles when marked? Or would that be too contrived? + result = 2; + break; default: // This should never happen // If it were to happen, try_move would interpret a 3 as a 1 diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp index 1e101a851..d1a886164 100644 --- a/src/simulation/SimulationData.cpp +++ b/src/simulation/SimulationData.cpp @@ -185,6 +185,10 @@ void SimulationData::init_can_move() //SAWD cannot be displaced by other powders if (elements[movingType].Properties & TYPE_PART) can_move[movingType][PT_SAWD] = 0; + + // Let most non-solids pass through PAPR + if (elements[movingType].Properties & (TYPE_GAS | TYPE_PART | TYPE_LIQUID)) + can_move[movingType][PT_PAPR] = 2; } //a list of lots of things PHOT can move through // TODO: replace with property diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index 4a9892f5d..1083418ee 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -8,8 +8,8 @@ static int graphics(GRAPHICS_FUNC_ARGS); // Additionally, it can be read and written to by ARAY. // Property usage: -// life: Temporary read/write state for ARAY interaction -// tmp: Written color value. If dcolour is not black, it gets copied here. 1 bit alpha +// life: Written color value. If dcolour is not black, it gets copied here. 1 bit alpha +// tmp: Temporary read/write state for ARAY interaction // tmp2: Singe level void Element::Element_PAPR() @@ -58,6 +58,7 @@ void Element::Element_PAPR() static int update(UPDATE_FUNC_ARGS) { + // Char when above burning temperature if (parts[i].temp > 450 && parts[i].temp >= parts[i].tmp2) { parts[i].tmp2 = (int)parts[i].temp; @@ -73,7 +74,6 @@ static int update(UPDATE_FUNC_ARGS) if (np >= 0) { parts[np].life = 70; - // parts[np].temp = parts[i].temp; } } } @@ -82,6 +82,7 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { + // Darken when burnt float maxtemp = std::max((float)cpart->tmp2, cpart->temp); if (maxtemp > 450) { From 8efefb0264bde23bde966bed5be76b2e1fad1047 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Mon, 11 Dec 2023 18:41:37 -0500 Subject: [PATCH 04/15] Updated PAPR passthrough behavior --- src/simulation/Simulation.cpp | 4 ++-- src/simulation/SimulationData.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 537d6fd4b..30f27acc4 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3330,9 +3330,9 @@ void Simulation::RecalcFreeParticles(bool do_life_dec) photons[y][x] = PMAP(i, t); else { - // Particles are sometimes allowed to go inside INVS and FILT + // Particles are sometimes allowed to go inside INVS, FILT, and PAPR // To make particles collide correctly when inside these elements, these elements must not overwrite an existing pmap entry from particles inside them - if (!pmap[y][x] || (t!=PT_INVIS && t!= PT_FILT)) + if (!pmap[y][x] || (t!=PT_INVIS && t!= PT_FILT && t != PT_PAPR)) pmap[y][x] = PMAP(i, t); // (there are a few exceptions, including energy particles - currently no limit on stacking those) if (t!=PT_THDR && t!=PT_EMBR && t!=PT_FIGH && t!=PT_PLSM) diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp index a125f3925..f7b3a86db 100644 --- a/src/simulation/SimulationData.cpp +++ b/src/simulation/SimulationData.cpp @@ -187,7 +187,7 @@ void SimulationData::init_can_move() can_move[movingType][PT_SAWD] = 0; // Let most non-solids pass through PAPR - if (elements[movingType].Properties & (TYPE_GAS | TYPE_PART | TYPE_LIQUID)) + if (elements[movingType].Properties & (TYPE_GAS | TYPE_PART | TYPE_LIQUID) && (movingType != PT_FIRE && movingType != PT_SMKE)) can_move[movingType][PT_PAPR] = 2; } //a list of lots of things PHOT can move through From f4dd854b7897568a93b52c2bd4c625e682d7a12a Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:08:00 -0500 Subject: [PATCH 05/15] ARAY read/writes PAPR and PAPR physics --- src/simulation/Simulation.cpp | 8 +++-- src/simulation/SimulationData.cpp | 4 +-- src/simulation/elements/ARAY.cpp | 50 ++++++++++++++++++++++++++++++- src/simulation/elements/PAPR.cpp | 46 +++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 6 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 30f27acc4..47480df31 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1095,8 +1095,12 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) const } break; case PT_PAPR: - // May allow PAPR to block particles when marked? Or would that be too contrived? - result = 2; + // 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))) + result = 2; + else + result = 0; break; default: // This should never happen diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp index f7b3a86db..4a14c1d47 100644 --- a/src/simulation/SimulationData.cpp +++ b/src/simulation/SimulationData.cpp @@ -186,9 +186,9 @@ void SimulationData::init_can_move() if (elements[movingType].Properties & TYPE_PART) can_move[movingType][PT_SAWD] = 0; - // Let most non-solids pass through PAPR + // Let most non-solids pass through unmarked PAPR if (elements[movingType].Properties & (TYPE_GAS | TYPE_PART | TYPE_LIQUID) && (movingType != PT_FIRE && movingType != PT_SMKE)) - can_move[movingType][PT_PAPR] = 2; + can_move[movingType][PT_PAPR] = 3; } //a list of lots of things PHOT can move through // TODO: replace with property diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index e101e3aac..0968cc804 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -165,6 +165,30 @@ static int update(UPDATE_FUNC_ARGS) { parts[r].life = 10; } + } + else if (rt == PT_PAPR) + { + if (parts[r].tmp) + { + if (parts[r].tmp & 0x10) + { + // Read + if ((parts[r].life >> 24) & 0x1) + { + break; + } + } + else + { + // Write + parts[r].life = 0x11A2222; + } + } + else + { + // Enter writing state + parts[r].tmp = 0x0A; + } // this if prevents BRAY from stopping on certain materials } else if (rt != PT_INWR && (rt != PT_SPRK || parts[r].ctype != PT_INWR) && rt != PT_ARAY && rt != PT_WIFI && !(rt == PT_SWCH && parts[r].life >= 10)) @@ -189,7 +213,7 @@ static int update(UPDATE_FUNC_ARGS) parts[r].dcolour = 0xFF000000; //this if prevents red BRAY from stopping on certain materials } - else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10)) + else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10) || rt==PT_PAPR) { if (rt == PT_STOR) { @@ -201,6 +225,30 @@ static int update(UPDATE_FUNC_ARGS) isBlackDeco = (parts[r].dcolour==0xFF000000); parts[r].life = 2; } + else if (rt == PT_PAPR) + { + if (parts[r].tmp) + { + if (parts[r].tmp & 0x10) + { + // Read + if ((parts[r].life >> 24) & 0x1) + { + break; + } + } + else + { + // Write + parts[r].life = 0x0; + } + } + else + { + // Enter reading state + parts[r].tmp = 0x1A; + } + } docontinue = 1; } else diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index 1083418ee..e216b6876 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -8,7 +8,7 @@ static int graphics(GRAPHICS_FUNC_ARGS); // Additionally, it can be read and written to by ARAY. // Property usage: -// life: Written color value. If dcolour is not black, it gets copied here. 1 bit alpha +// life: Written color value. Uses same format as dcolour. // tmp: Temporary read/write state for ARAY interaction // tmp2: Singe level @@ -77,11 +77,55 @@ static int update(UPDATE_FUNC_ARGS) } } } + + // Get marked by BCOL + if (TYP(pmap[y][x]) == PT_BCOL) + { + parts[i].life = 0x122222A; + } + + // Get unmarked by SOAP + for (auto rx = -1; rx <= 1; rx++) + { + 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; + } + } + } + } + + // Decrement tmp counter for laser reading/writing + if (parts[i].tmp & 0xF) + { + parts[i].tmp--; + } + else + { + parts[i].tmp = 0; + } return 0; } 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) + { + *colr = tr; + *colg = tg; + *colb = tb; + } // Darken when burnt float maxtemp = std::max((float)cpart->tmp2, cpart->temp); if (maxtemp > 450) From cb40d869cde3b40cd1b7f600b402f7b5ed66eafa Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:38:02 -0500 Subject: [PATCH 06/15] Add PAPR interaction with LDTC --- src/simulation/elements/LDTC.cpp | 56 +++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index db52e2511..645a2b2c2 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -104,7 +104,7 @@ static int update(UPDATE_FUNC_ARGS) if (!r) continue; bool boolMode = accepted_conductor(sim, r); - bool filtMode = copyColor && TYP(r) == PT_FILT; + bool filtMode = copyColor && (TYP(r) == PT_FILT || TYP(r) == PT_PAPR); if (!boolMode && !filtMode) continue; @@ -147,21 +147,59 @@ static int update(UPDATE_FUNC_ARGS) if (filtMode) { - if (!phot_data_type(TYP(rr))) + if (!phot_data_type(TYP(rr)) && TYP(rr) != PT_PAPR) continue; int nx = x + rx, ny = y + ry; int photonWl = TYP(rr) == PT_FILT ? Element_FILT_getWavelengths(&parts[ID(rr)]) : parts[ID(rr)].ctype; - while (TYP(r) == PT_FILT) + if (TYP(rr) == PT_PAPR) { - parts[ID(r)].ctype = photonWl; - nx += rx; - ny += ry; - if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) - break; - r = pmap[ny][nx]; + photonWl = 0x0; + int bit = 0x1; + while (TYP(rr) == PT_PAPR && bit <= 0x3FFFFFFF) + { + if ((parts[ID(rr)].life >> 24) & 0x1) + { + photonWl |= bit; + } + xCurrent += xStep; + yCurrent += yStep; + if (xCurrent < 0 || yCurrent < 0 || xCurrent >= XRES || yCurrent >= YRES) + break; + rr = pmap[yCurrent][xCurrent]; + bit <<= 1; + } + } + if (TYP(r) == PT_FILT) + { + while (TYP(r) == PT_FILT) + { + parts[ID(r)].ctype = photonWl; + nx += rx; + ny += ry; + if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) + break; + r = pmap[ny][nx]; + } + } + if (TYP(r) == PT_PAPR) + { + int bit = 0x1; + while (TYP(r) == PT_PAPR && bit <= 0x3FFFFFFF) + { + if (photonWl & bit) + parts[ID(r)].life = 0x1080820; + else + parts[ID(r)].life = 0x0; + nx += rx; + ny += ry; + if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) + break; + r = pmap[ny][nx]; + bit <<= 1; + } } break; } From 19461e315e522853b35527a17f6a493ba0b06e9c Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:55:13 -0500 Subject: [PATCH 07/15] Adjustments to ARAY read/write feature --- src/simulation/elements/ARAY.cpp | 4 ++++ src/simulation/elements/PAPR.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 0968cc804..38393d91a 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -173,6 +173,8 @@ static int update(UPDATE_FUNC_ARGS) if (parts[r].tmp & 0x10) { // Read + // End reading state early + parts[r].tmp = 0; if ((parts[r].life >> 24) & 0x1) { break; @@ -232,6 +234,8 @@ static int update(UPDATE_FUNC_ARGS) if (parts[r].tmp & 0x10) { // Read + // End reading state early + parts[r].tmp = 0; if ((parts[r].life >> 24) & 0x1) { break; diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index e216b6876..78fd53d01 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -134,5 +134,23 @@ static int graphics(GRAPHICS_FUNC_ARGS) *colg -= (int)restrict_flt((maxtemp-450)*1.4f,0,230); *colb -= (int)restrict_flt((maxtemp-450)*1.7f,0,197); } + if (cpart->tmp) + { + *pixel_mode |= PMODE_GLOW; + float flash = (cpart->tmp & 0xF) / 15.f; + *cola = flash * 200; + *colr = int(*colr * (1 - flash)); + *colg = int(*colg * (1 - flash)); + *colb = int(*colb * (1 - flash)); + if (cpart->tmp & 0x10) + { + *colr += int(255 * flash); + } + else + { + *colg += int(255 * flash); + *colb += int(255 * flash); + } + } return 0; } 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 08/15] 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; } From c8fc7b2e2aa4c672ce2793d044a611c208c00e2f Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:31:47 -0500 Subject: [PATCH 09/15] PAPR now respects deco settings and blackDecorations --- src/simulation/elements/PAPR.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index 5a69c6540..446779fe6 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -107,10 +107,20 @@ static int graphics(GRAPHICS_FUNC_ARGS) { if (cpart->life) { - 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); + // Render deco color when marked + if(gfctx.ren->decorations_enable && !gfctx.ren->blackDecorations) + { + 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); + } + else // If deco is disabled or blackDecorations is on, become a generic dark gray color + { + *colr = 20; + *colg = 20; + *colb = 20; + } } // Darken when burnt float maxtemp = std::max((float)cpart->tmp2, cpart->temp); From 1ac7a5d8f58af646a2728e4c2aaedcee23c698e3 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:51:50 -0500 Subject: [PATCH 10/15] Mark color now fades when PAPR scorches --- src/simulation/elements/PAPR.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index 446779fe6..af32405ea 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -105,12 +105,14 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { + float burnAmount = std::max((float)cpart->tmp2, cpart->temp); if (cpart->life) { // Render deco color when marked if(gfctx.ren->decorations_enable && !gfctx.ren->blackDecorations) { - float alpha = ((cpart->dcolour >> 24) & 0xFF) / 255.f; + // Burnt paper has more faded colors + float alpha = (((cpart->dcolour >> 24) & 0xFF) - restrict_flt((burnAmount - 450) * 1.5f, 0, 255)) / 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); @@ -123,12 +125,11 @@ static int graphics(GRAPHICS_FUNC_ARGS) } } // Darken when burnt - float maxtemp = std::max((float)cpart->tmp2, cpart->temp); - if (maxtemp > 450) + if (burnAmount > 450) { - *colr -= (int)restrict_flt((maxtemp-450)*1.2f,0,230); - *colg -= (int)restrict_flt((maxtemp-450)*1.4f,0,230); - *colb -= (int)restrict_flt((maxtemp-450)*1.7f,0,197); + *colr -= (int)restrict_flt((burnAmount - 450) * 1.2f, 0, 230); + *colg -= (int)restrict_flt((burnAmount - 450) * 1.4f, 0, 240); + *colb -= (int)restrict_flt((burnAmount - 450) * 1.7f, 0, 197); } if (cpart->tmp) { From 4a15cf5fd3f06e20efbd977f9dc60b0853d7fd71 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:17:57 -0500 Subject: [PATCH 11/15] Fixed LDTC -> PAPR mark color and adjust fading --- src/simulation/elements/LDTC.cpp | 2 +- src/simulation/elements/PAPR.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index efa114bee..63868c867 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -192,7 +192,7 @@ static int update(UPDATE_FUNC_ARGS) if (photonWl & bit) { parts[ID(r)].life = 1; - parts[ID(r)].dcolour = 0x1080820; + parts[ID(r)].dcolour = 0xFF0F0820; } else { diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index af32405ea..b1799d146 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -112,7 +112,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) if(gfctx.ren->decorations_enable && !gfctx.ren->blackDecorations) { // Burnt paper has more faded colors - float alpha = (((cpart->dcolour >> 24) & 0xFF) - restrict_flt((burnAmount - 450) * 1.5f, 0, 255)) / 255.f; + float alpha = restrict_flt(((cpart->dcolour >> 24) & 0xFF) - (burnAmount - 450) * 1.7f, 0, 255) / 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); @@ -127,15 +127,15 @@ static int graphics(GRAPHICS_FUNC_ARGS) // Darken when burnt if (burnAmount > 450) { - *colr -= (int)restrict_flt((burnAmount - 450) * 1.2f, 0, 230); - *colg -= (int)restrict_flt((burnAmount - 450) * 1.4f, 0, 240); - *colb -= (int)restrict_flt((burnAmount - 450) * 1.7f, 0, 197); + *colr -= (int)restrict_flt((burnAmount - 450) * 1.2f, 0, 220); + *colg -= (int)restrict_flt((burnAmount - 450) * 1.4f, 0, 230); + *colb -= (int)restrict_flt((burnAmount - 450) * 1.6f, 0, 197); } if (cpart->tmp) { *pixel_mode |= PMODE_GLOW; float flash = (cpart->tmp & 0xF) / 3.f; - *cola = flash * 200; + *cola = int(flash * 200); *colr = int(*colr * (1 - flash)); *colg = int(*colg * (1 - flash)); *colb = int(*colb * (1 - flash)); From 53f82f9caafa40d4a968575c004fb6b1ecb389fd Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:53:17 -0500 Subject: [PATCH 12/15] PAPR marks scorch correctly when deco is disabled --- src/simulation/elements/PAPR.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index b1799d146..fb2196d1d 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -112,16 +112,17 @@ static int graphics(GRAPHICS_FUNC_ARGS) if(gfctx.ren->decorations_enable && !gfctx.ren->blackDecorations) { // Burnt paper has more faded colors - float alpha = restrict_flt(((cpart->dcolour >> 24) & 0xFF) - (burnAmount - 450) * 1.7f, 0, 255) / 255.f; + float alpha = restrict_flt(((cpart->dcolour >> 24) & 0xFF) - restrict_flt((burnAmount - 450) * 1.7f, 0, 255), 0, 255) / 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); } else // If deco is disabled or blackDecorations is on, become a generic dark gray color { - *colr = 20; - *colg = 20; - *colb = 20; + float alpha = 1 - restrict_flt((burnAmount - 450) * 1.7f, 0, 255) / 255.f; + *colr = int(*colr * (1 - alpha) + 20 * alpha); + *colg = int(*colg * (1 - alpha) + 20 * alpha); + *colb = int(*colb * (1 - alpha) + 20 * alpha); } } // Darken when burnt From fdda40c24dedf35497bb2d895a31a740e1fea727 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Wed, 13 Dec 2023 03:51:54 -0500 Subject: [PATCH 13/15] Don't render PAPR if there is a particle on top of it --- src/simulation/elements/PAPR.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index fb2196d1d..dea58249c 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -105,6 +105,13 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { + // Don't render if there's a particle above you + int onTopOfMe = gfctx.sim->pmap[ny][nx]; + if (onTopOfMe && &gfctx.sim->parts[ID(onTopOfMe)] != cpart) + { + *pixel_mode = PMODE_NONE; + return 0; + } float burnAmount = std::max((float)cpart->tmp2, cpart->temp); if (cpart->life) { From 39b811e52c15ff9af9f92bb7ea8edd8bd06274a9 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Wed, 13 Dec 2023 05:47:17 -0500 Subject: [PATCH 14/15] Changed LDTC mark color --- src/simulation/elements/LDTC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index 63868c867..fd0281a51 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -192,7 +192,7 @@ static int update(UPDATE_FUNC_ARGS) if (photonWl & bit) { parts[ID(r)].life = 1; - parts[ID(r)].dcolour = 0xFF0F0820; + parts[ID(r)].dcolour = 0xFF1B133F; } else { From c0f248c6db394b34af8469a69ba4c63c14733f77 Mon Sep 17 00:00:00 2001 From: Rebmiami <59275598+Rebmiami@users.noreply.github.com> Date: Wed, 13 Dec 2023 06:24:18 -0500 Subject: [PATCH 15/15] Updated comments and element description --- src/simulation/elements/ARAY.cpp | 14 ++++++-------- src/simulation/elements/LDTC.cpp | 2 ++ src/simulation/elements/PAPR.cpp | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 3a2e9f6dd..b3832e366 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -168,11 +168,11 @@ static int update(UPDATE_FUNC_ARGS) } else if (rt == PT_PAPR) { + // In reading/writing state? if (parts[r].tmp) { - if (parts[r].tmp & 0x10) + if (parts[r].tmp & 0x10) // Reading state { - // Read // End reading state early parts[r].tmp = 0; if (parts[r].life) @@ -180,9 +180,8 @@ static int update(UPDATE_FUNC_ARGS) break; } } - else + else // Writing state { - // Write parts[r].life = 1; parts[r].dcolour = 0xFF1A2222; } @@ -230,11 +229,11 @@ static int update(UPDATE_FUNC_ARGS) } else if (rt == PT_PAPR) { + // In reading/writing state? if (parts[r].tmp) { - if (parts[r].tmp & 0x10) + if (parts[r].tmp & 0x10) // Reading state { - // Read // End reading state early parts[r].tmp = 0; if (parts[r].life) @@ -242,9 +241,8 @@ static int update(UPDATE_FUNC_ARGS) break; } } - else + else // Writing state { - // Write parts[r].life = 0; parts[r].dcolour = 0; } diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index fd0281a51..7f194b5b1 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -158,6 +158,7 @@ static int update(UPDATE_FUNC_ARGS) { photonWl = 0x0; int bit = 0x1; + // Read one bit of the wavelength from successive particles while (TYP(rr) == PT_PAPR && bit <= 0x3FFFFFFF) { if (parts[ID(rr)].life) @@ -186,6 +187,7 @@ static int update(UPDATE_FUNC_ARGS) } if (TYP(r) == PT_PAPR) { + // Write each bit of the wavelength to successive particles int bit = 0x1; while (TYP(r) == PT_PAPR && bit <= 0x3FFFFFFF) { diff --git a/src/simulation/elements/PAPR.cpp b/src/simulation/elements/PAPR.cpp index dea58249c..141a31039 100644 --- a/src/simulation/elements/PAPR.cpp +++ b/src/simulation/elements/PAPR.cpp @@ -5,10 +5,10 @@ static int graphics(GRAPHICS_FUNC_ARGS); // Element overview: // PAPR (Paper) is a flammable solid element that can be colored by certain other elements. -// Additionally, it can be read and written to by ARAY. +// Additionally, it can be read and written to by ARAY and LDTC. // Property usage: -// life: Written color value. Uses same format as dcolour. +// life: Whether or not the particle is marked // tmp: Temporary read/write state for ARAY interaction // tmp2: Singe level @@ -39,7 +39,7 @@ void Element::Element_PAPR() Weight = 100; HeatConduct = 80; - Description = "Paper. Flammable, readable, writable."; + Description = "Paper. Flammable, can be marked by BCOL or deco. Lets non-solids through when unmarked."; Properties = TYPE_SOLID | PROP_NEUTPENETRATE;