From 2c55a8a9d92fc8742c864b43dd919db6882e96fa Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 7 Apr 2024 00:17:48 +0100 Subject: [PATCH] Remove `Renderer` field from GraphicsFunContext - Only decorationsEnable & blackDecorations were ever read, graphics update functions shouldn't really be aware of the renderer. - `sim` should ideally not be there either, but `luaGraphicsWrapper` has more going on to sort out --- src/graphics/Renderer.cpp | 3 ++- src/graphics/Renderer.h | 3 ++- src/simulation/elements/EMBR.cpp | 4 ++-- src/simulation/elements/LCRY.cpp | 4 ++-- src/simulation/elements/LIFE.cpp | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 7b52489eed..d97fc0b7a7 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -176,9 +176,10 @@ void Renderer::render_parts() auto &elements = sd.elements; auto &graphicscache = sd.graphicscache; GraphicsFuncContext gfctx; - gfctx.ren = this; gfctx.sim = sim; gfctx.rng.seed(rng()); + gfctx.decorationsEnable = decorations_enable; + gfctx.blackDecorations = blackDecorations; gfctx.pipeSubcallCpart = nullptr; gfctx.pipeSubcallTpart = nullptr; int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y; diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index 452a9dd634..ec8a5e2a46 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -18,8 +18,9 @@ struct Particle; struct GraphicsFuncContext { - const Renderer *ren; const Simulation *sim; + bool decorationsEnable; + bool blackDecorations; RNG rng; const Particle *pipeSubcallCpart; Particle *pipeSubcallTpart; diff --git a/src/simulation/elements/EMBR.cpp b/src/simulation/elements/EMBR.cpp index 4edaa1ddda..95f80b8e2b 100644 --- a/src/simulation/elements/EMBR.cpp +++ b/src/simulation/elements/EMBR.cpp @@ -100,9 +100,9 @@ static int graphics(GRAPHICS_FUNC_ARGS) } bool deco = false; - if (gfctx.ren->decorations_enable && cpart->dcolour && (cpart->dcolour&0xFF000000)) + if (gfctx.decorationsEnable && cpart->dcolour && (cpart->dcolour&0xFF000000)) { - if (!gfctx.ren->blackDecorations) // if blackDecorations is off, always show deco + if (!gfctx.blackDecorations) // if blackDecorations is off, always show deco deco = true; else if (((cpart->dcolour>>24)&0xFF) >= 250 && ((cpart->dcolour>>16)&0xFF) <= 5 && ((cpart->dcolour>>8)&0xFF) <= 5 && ((cpart->dcolour)&0xFF) <= 5) // else only render black deco deco = true; diff --git a/src/simulation/elements/LCRY.cpp b/src/simulation/elements/LCRY.cpp index 08336aa959..df1de32bb3 100644 --- a/src/simulation/elements/LCRY.cpp +++ b/src/simulation/elements/LCRY.cpp @@ -107,9 +107,9 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { bool deco = false; - if (gfctx.ren->decorations_enable && cpart->dcolour && (cpart->dcolour&0xFF000000)) + if (gfctx.decorationsEnable && cpart->dcolour && (cpart->dcolour&0xFF000000)) { - if (!gfctx.ren->blackDecorations) // if blackDecorations is off, always show deco + if (!gfctx.blackDecorations) // if blackDecorations is off, always show deco deco = true; else if(((cpart->dcolour>>24)&0xFF) >= 250 && ((cpart->dcolour>>16)&0xFF) <= 5 && ((cpart->dcolour>>8)&0xFF) <= 5 && ((cpart->dcolour)&0xFF) <= 5) // else only render black deco deco = true; diff --git a/src/simulation/elements/LIFE.cpp b/src/simulation/elements/LIFE.cpp index 411f4096e9..a1a23cbbe9 100644 --- a/src/simulation/elements/LIFE.cpp +++ b/src/simulation/elements/LIFE.cpp @@ -58,10 +58,10 @@ static int graphics(GRAPHICS_FUNC_ARGS) colour1 = 0xFFFFFF_rgb; } auto ruleset = cpart->ctype; - bool renderDeco = !gfctx.ren->blackDecorations; + bool renderDeco = !gfctx.blackDecorations; if (ruleset >= 0 && ruleset < NGOL) { - if (!renderDeco || !gfctx.ren->decorations_enable) + if (!renderDeco || !gfctx.decorationsEnable) { colour1 = builtinGol[ruleset].colour; colour2 = builtinGol[ruleset].colour2;