From c603c41b927439cd2506d3e23ad33bc24297a7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 16 Jul 2022 13:27:28 +0200 Subject: [PATCH] Fix PIPE graphics hack giving Lua graphics functions bad particle IDs --- src/simulation/elements/PIPE.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index cb3a3049c..31399dcc0 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -1,6 +1,4 @@ #include "simulation/ElementCommon.h" -//Temp particle used for graphics -Particle tpart; int Element_PIPE_update(UPDATE_FUNC_ARGS); int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS); @@ -55,8 +53,6 @@ void Element::Element_PIPE() Update = &Element_PIPE_update; Graphics = &Element_PIPE_graphics; - - memset(&tpart, 0, sizeof(Particle)); } // 0x000000FF element @@ -374,24 +370,31 @@ int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS) } else { - //Emulate the graphics of stored particle - tpart.type = t; - tpart.temp = cpart->temp; - tpart.life = cpart->tmp2; - tpart.tmp = cpart->tmp3; - tpart.ctype = cpart->tmp4; + // Temp particle used for graphics. + Particle tpart = *cpart; + + // Emulate the graphics of stored particle. + memset(cpart, 0, sizeof(Particle)); + cpart->type = t; + cpart->temp = tpart.temp; + cpart->life = tpart.tmp2; + cpart->tmp = tpart.tmp3; + cpart->ctype = tpart.tmp4; *colr = PIXR(ren->sim->elements[t].Colour); *colg = PIXG(ren->sim->elements[t].Colour); *colb = PIXB(ren->sim->elements[t].Colour); if (ren->sim->elements[t].Graphics) { - (*(ren->sim->elements[t].Graphics))(ren, &tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); + (*(ren->sim->elements[t].Graphics))(ren, cpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); } else { - Element::defaultGraphics(ren, &tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); + Element::defaultGraphics(ren, cpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb); } + + // Restore original particle data. + *cpart = tpart; } //*colr = PIXR(elements[t].pcolors); //*colg = PIXG(elements[t].pcolors);