From c0b4c402c0c70ac9515f4886597d0d373b001419 Mon Sep 17 00:00:00 2001 From: extio-de Date: Thu, 25 Dec 2025 12:02:04 +0100 Subject: [PATCH] refactor(renderer): Replace 'add' method with 'put' in RendererWorkingSet interface and implementations --- .../game_engine/renderer/g2d/G2DRenderer.java | 8 +-- .../renderer/work/RendererWorkingSet.java | 4 +- .../renderer/work/RendererWorkingSetImpl.java | 4 +- .../work/RendererWorkingSetImplTest.java | 50 +++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/G2DRenderer.java b/src/main/java/de/extio/game_engine/renderer/g2d/G2DRenderer.java index 6442992..7724bf8 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/G2DRenderer.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/G2DRenderer.java @@ -104,8 +104,8 @@ public class G2DRenderer implements Renderer { EventQueue.invokeAndWait(() -> { // this invokeAndWait() call is also important to wait until applyVideoOptions() has been completed, which also puts events to AWT event queue LOGGER.debug("Viewport initialized"); - this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, this.rendererData.getRenderingBoPool().acquire("G2DRenderer_background", G2DDrawBackground.class)); - this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, this.rendererData.getRenderingBoPool().acquire("G2DRenderer_tooltip", G2DDrawControlTooltip.class)); + this.rendererData.getRendererWorkingSet().put(this.rendererModuleId, this.rendererData.getRenderingBoPool().acquire("G2DRenderer_background", G2DDrawBackground.class)); + this.rendererData.getRendererWorkingSet().put(this.rendererModuleId, this.rendererData.getRenderingBoPool().acquire("G2DRenderer_tooltip", G2DDrawControlTooltip.class)); }); } catch (InvocationTargetException | InterruptedException e) { @@ -255,14 +255,14 @@ public class G2DRenderer implements Renderer { .setColor(RgbaColor.WHITE) .setLayer(RenderingBoLayer.TOP) .withPositionAbsoluteAnchorTopRight(100, 35); - this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, drawFont); + this.rendererData.getRendererWorkingSet().put(this.rendererModuleId, drawFont); this.fpsHistory.add(Integer.valueOf((int) this.frameDur)); final var drawFpsHistory = this.rendererData.getRenderingBoPool().acquire("g2DRenderer_fpsHistory", G2DDrawFpsHistory.class) .setHistory(this.fpsHistory) .setLayer(RenderingBoLayer.TOP) .withPositionAbsoluteAnchorTopRight(100, 50); - this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, drawFpsHistory); + this.rendererData.getRendererWorkingSet().put(this.rendererModuleId, drawFpsHistory); } private void frameCap() throws InterruptedException { diff --git a/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSet.java b/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSet.java index e0779a7..f9ea3ae 100644 --- a/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSet.java +++ b/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSet.java @@ -8,9 +8,9 @@ import de.extio.game_engine.renderer.model.RenderingBo; public interface RendererWorkingSet { - void add(String producerId, RenderingBo work); + void put(String producerId, RenderingBo work); - void add(String producerId, List work); + void put(String producerId, List work); RenderingBo get(String producerId, String id); diff --git a/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSetImpl.java b/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSetImpl.java index 6984fb1..ffd5bfa 100644 --- a/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSetImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/work/RendererWorkingSetImpl.java @@ -30,14 +30,14 @@ public class RendererWorkingSetImpl implements RendererWorkingSet { } @Override - public void add(final String producerId, final RenderingBo work) { + public void put(final String producerId, final RenderingBo work) { this.getWorkingSetByProducer(producerId) .next() .put(work.getId(), work); } @Override - public void add(final String producerId, final List work) { + public void put(final String producerId, final List work) { final var nextMap = this.getWorkingSetByProducer(producerId).next(); for (final RenderingBo bo : work) { nextMap.put(bo.getId(), bo); diff --git a/src/test/java/de/extio/game_engine/renderer/work/RendererWorkingSetImplTest.java b/src/test/java/de/extio/game_engine/renderer/work/RendererWorkingSetImplTest.java index cefecd5..d2269ce 100644 --- a/src/test/java/de/extio/game_engine/renderer/work/RendererWorkingSetImplTest.java +++ b/src/test/java/de/extio/game_engine/renderer/work/RendererWorkingSetImplTest.java @@ -51,7 +51,7 @@ public class RendererWorkingSetImplTest { void addSingleAddsToUncommittedWork() { final RenderingBo bo1 = mock(RenderingBo.class); when(bo1.getId()).thenReturn("bo1"); - this.workingSet.add(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo1); final var uncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); assertNotNull(uncommitted); @@ -65,7 +65,7 @@ public class RendererWorkingSetImplTest { final RenderingBo bo2 = mock(RenderingBo.class); when(bo2.getId()).thenReturn("bo2"); - this.workingSet.add(this.moduleA.getId(), List.of(bo1, bo2)); + this.workingSet.put(this.moduleA.getId(), List.of(bo1, bo2)); final var uncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); assertEquals(Map.of("bo1", bo1, "bo2", bo2), uncommitted); @@ -78,8 +78,8 @@ public class RendererWorkingSetImplTest { final RenderingBo bo2 = mock(RenderingBo.class); when(bo2.getId()).thenReturn("bo2"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), false); final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); @@ -102,8 +102,8 @@ public class RendererWorkingSetImplTest { final RenderingBo bo3 = mock(RenderingBo.class); when(bo3.getId()).thenReturn("bo3"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), true); final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); @@ -116,7 +116,7 @@ public class RendererWorkingSetImplTest { assertEquals(2, live.size()); assertTrue(live.containsAll(List.of(bo1, bo2))); - this.workingSet.add(this.moduleA.getId(), bo3); + this.workingSet.put(this.moduleA.getId(), bo3); final List liveAfterAdd = new ArrayList<>(); this.workingSet.getLiveSet(liveAfterAdd, null); assertEquals(2, liveAfterAdd.size()); @@ -132,9 +132,9 @@ public class RendererWorkingSetImplTest { final RenderingBo bo3 = mock(RenderingBo.class); when(bo3.getId()).thenReturn("bo3"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); - this.workingSet.add(this.moduleB.getId(), bo3); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleB.getId(), bo3); this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleB.getId(), false); @@ -163,9 +163,9 @@ public class RendererWorkingSetImplTest { final var bo2 = new TestBoB(); bo2.setId("bo2"); - this.workingSet.add(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo1); this.workingSet.commit(this.moduleA.getId(), false); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo2); // Before clear final List liveBefore = new ArrayList<>(); @@ -193,7 +193,7 @@ public class RendererWorkingSetImplTest { void clearOnUnknownProducerDoesNothing() { final RenderingBo bo1 = mock(RenderingBo.class); when(bo1.getId()).thenReturn("bo1"); - this.workingSet.add(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo1); this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.clear(this.moduleC.getId()); @@ -211,13 +211,13 @@ public class RendererWorkingSetImplTest { final var bo2 = new TestBoA(); bo2.setId("bo2"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); this.workingSet.commit(this.moduleA.getId(), false); final var bo3 = new TestBoB(); bo3.setId("bo3"); - this.workingSet.add(this.moduleA.getId(), bo3); + this.workingSet.put(this.moduleA.getId(), bo3); this.workingSet.commit(this.moduleA.getId(), false); verify(this.renderingBoPool, times(1)).release(bo1); @@ -236,8 +236,8 @@ public class RendererWorkingSetImplTest { final RenderingBo bo2 = mock(RenderingBo.class); when(bo2.getId()).thenReturn("bo2"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); final var retrieved1 = this.workingSet.get(this.moduleA.getId(), "bo1"); final var retrieved2 = this.workingSet.get(this.moduleA.getId(), "bo2"); @@ -255,8 +255,8 @@ public class RendererWorkingSetImplTest { final RenderingBo bo2 = mock(RenderingBo.class); when(bo2.getId()).thenReturn("bo2"); - this.workingSet.add(this.moduleA.getId(), bo1); - this.workingSet.add(this.moduleA.getId(), bo2); + this.workingSet.put(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo2); final var committedWork = this.workingSet.commit(this.moduleA.getId(), false); // After commit without clone, the uncommitted work should be empty @@ -277,12 +277,12 @@ public class RendererWorkingSetImplTest { final RenderingBo bo1_replacement = mock(RenderingBo.class); when(bo1_replacement.getId()).thenReturn("bo1"); - this.workingSet.add(this.moduleA.getId(), bo1); + this.workingSet.put(this.moduleA.getId(), bo1); final var uncommittedBefore = this.workingSet.getUncommittedWork(this.moduleA.getId()); assertEquals(1, uncommittedBefore.size()); assertSame(bo1, uncommittedBefore.get("bo1")); - this.workingSet.add(this.moduleA.getId(), bo1_replacement); + this.workingSet.put(this.moduleA.getId(), bo1_replacement); final var uncommittedAfter = this.workingSet.getUncommittedWork(this.moduleA.getId()); assertEquals(1, uncommittedAfter.size()); assertSame(bo1_replacement, uncommittedAfter.get("bo1")); @@ -297,9 +297,9 @@ public class RendererWorkingSetImplTest { final var boA2 = new TestBoA(); boA2.setId("boA2"); - this.workingSet.add(this.moduleA.getId(), boA1); - this.workingSet.add(this.moduleB.getId(), boB1); - this.workingSet.add(this.moduleA.getId(), boA2); + this.workingSet.put(this.moduleA.getId(), boA1); + this.workingSet.put(this.moduleB.getId(), boB1); + this.workingSet.put(this.moduleA.getId(), boA2); this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleB.getId(), false);