refactor(renderer): Replace 'add' method with 'put' in RendererWorkingSet interface and implementations

This commit is contained in:
extio-de
2025-12-25 12:02:04 +01:00
parent b0bc14793f
commit c0b4c402c0
4 changed files with 33 additions and 33 deletions

View File

@@ -104,8 +104,8 @@ public class G2DRenderer implements Renderer {
EventQueue.invokeAndWait(() -> { EventQueue.invokeAndWait(() -> {
// this invokeAndWait() call is also important to wait until applyVideoOptions() has been completed, which also puts events to AWT event queue // 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"); LOGGER.debug("Viewport initialized");
this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, this.rendererData.getRenderingBoPool().acquire("G2DRenderer_background", G2DDrawBackground.class)); this.rendererData.getRendererWorkingSet().put(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_tooltip", G2DDrawControlTooltip.class));
}); });
} }
catch (InvocationTargetException | InterruptedException e) { catch (InvocationTargetException | InterruptedException e) {
@@ -255,14 +255,14 @@ public class G2DRenderer implements Renderer {
.setColor(RgbaColor.WHITE) .setColor(RgbaColor.WHITE)
.setLayer(RenderingBoLayer.TOP) .setLayer(RenderingBoLayer.TOP)
.withPositionAbsoluteAnchorTopRight(100, 35); .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)); this.fpsHistory.add(Integer.valueOf((int) this.frameDur));
final var drawFpsHistory = this.rendererData.getRenderingBoPool().acquire("g2DRenderer_fpsHistory", G2DDrawFpsHistory.class) final var drawFpsHistory = this.rendererData.getRenderingBoPool().acquire("g2DRenderer_fpsHistory", G2DDrawFpsHistory.class)
.setHistory(this.fpsHistory) .setHistory(this.fpsHistory)
.setLayer(RenderingBoLayer.TOP) .setLayer(RenderingBoLayer.TOP)
.withPositionAbsoluteAnchorTopRight(100, 50); .withPositionAbsoluteAnchorTopRight(100, 50);
this.rendererData.getRendererWorkingSet().add(this.rendererModuleId, drawFpsHistory); this.rendererData.getRendererWorkingSet().put(this.rendererModuleId, drawFpsHistory);
} }
private void frameCap() throws InterruptedException { private void frameCap() throws InterruptedException {

View File

@@ -8,9 +8,9 @@ import de.extio.game_engine.renderer.model.RenderingBo;
public interface RendererWorkingSet { public interface RendererWorkingSet {
void add(String producerId, RenderingBo work); void put(String producerId, RenderingBo work);
void add(String producerId, List<RenderingBo> work); void put(String producerId, List<RenderingBo> work);
RenderingBo get(String producerId, String id); RenderingBo get(String producerId, String id);

View File

@@ -30,14 +30,14 @@ public class RendererWorkingSetImpl implements RendererWorkingSet {
} }
@Override @Override
public void add(final String producerId, final RenderingBo work) { public void put(final String producerId, final RenderingBo work) {
this.getWorkingSetByProducer(producerId) this.getWorkingSetByProducer(producerId)
.next() .next()
.put(work.getId(), work); .put(work.getId(), work);
} }
@Override @Override
public void add(final String producerId, final List<RenderingBo> work) { public void put(final String producerId, final List<RenderingBo> work) {
final var nextMap = this.getWorkingSetByProducer(producerId).next(); final var nextMap = this.getWorkingSetByProducer(producerId).next();
for (final RenderingBo bo : work) { for (final RenderingBo bo : work) {
nextMap.put(bo.getId(), bo); nextMap.put(bo.getId(), bo);

View File

@@ -51,7 +51,7 @@ public class RendererWorkingSetImplTest {
void addSingleAddsToUncommittedWork() { void addSingleAddsToUncommittedWork() {
final RenderingBo bo1 = mock(RenderingBo.class); final RenderingBo bo1 = mock(RenderingBo.class);
when(bo1.getId()).thenReturn("bo1"); 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()); final var uncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId());
assertNotNull(uncommitted); assertNotNull(uncommitted);
@@ -65,7 +65,7 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo2 = mock(RenderingBo.class); final RenderingBo bo2 = mock(RenderingBo.class);
when(bo2.getId()).thenReturn("bo2"); 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()); final var uncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId());
assertEquals(Map.of("bo1", bo1, "bo2", bo2), uncommitted); assertEquals(Map.of("bo1", bo1, "bo2", bo2), uncommitted);
@@ -78,8 +78,8 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo2 = mock(RenderingBo.class); final RenderingBo bo2 = mock(RenderingBo.class);
when(bo2.getId()).thenReturn("bo2"); when(bo2.getId()).thenReturn("bo2");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), false); final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), false);
final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId());
@@ -102,8 +102,8 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo3 = mock(RenderingBo.class); final RenderingBo bo3 = mock(RenderingBo.class);
when(bo3.getId()).thenReturn("bo3"); when(bo3.getId()).thenReturn("bo3");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), true); final var returnedUncommitted = this.workingSet.commit(this.moduleA.getId(), true);
final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId()); final var currentUncommitted = this.workingSet.getUncommittedWork(this.moduleA.getId());
@@ -116,7 +116,7 @@ public class RendererWorkingSetImplTest {
assertEquals(2, live.size()); assertEquals(2, live.size());
assertTrue(live.containsAll(List.of(bo1, bo2))); assertTrue(live.containsAll(List.of(bo1, bo2)));
this.workingSet.add(this.moduleA.getId(), bo3); this.workingSet.put(this.moduleA.getId(), bo3);
final List<RenderingBo> liveAfterAdd = new ArrayList<>(); final List<RenderingBo> liveAfterAdd = new ArrayList<>();
this.workingSet.getLiveSet(liveAfterAdd, null); this.workingSet.getLiveSet(liveAfterAdd, null);
assertEquals(2, liveAfterAdd.size()); assertEquals(2, liveAfterAdd.size());
@@ -132,9 +132,9 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo3 = mock(RenderingBo.class); final RenderingBo bo3 = mock(RenderingBo.class);
when(bo3.getId()).thenReturn("bo3"); when(bo3.getId()).thenReturn("bo3");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
this.workingSet.add(this.moduleB.getId(), bo3); this.workingSet.put(this.moduleB.getId(), bo3);
this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleA.getId(), false);
this.workingSet.commit(this.moduleB.getId(), false); this.workingSet.commit(this.moduleB.getId(), false);
@@ -163,9 +163,9 @@ public class RendererWorkingSetImplTest {
final var bo2 = new TestBoB(); final var bo2 = new TestBoB();
bo2.setId("bo2"); 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.commit(this.moduleA.getId(), false);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
// Before clear // Before clear
final List<RenderingBo> liveBefore = new ArrayList<>(); final List<RenderingBo> liveBefore = new ArrayList<>();
@@ -193,7 +193,7 @@ public class RendererWorkingSetImplTest {
void clearOnUnknownProducerDoesNothing() { void clearOnUnknownProducerDoesNothing() {
final RenderingBo bo1 = mock(RenderingBo.class); final RenderingBo bo1 = mock(RenderingBo.class);
when(bo1.getId()).thenReturn("bo1"); 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.commit(this.moduleA.getId(), false);
this.workingSet.clear(this.moduleC.getId()); this.workingSet.clear(this.moduleC.getId());
@@ -211,13 +211,13 @@ public class RendererWorkingSetImplTest {
final var bo2 = new TestBoA(); final var bo2 = new TestBoA();
bo2.setId("bo2"); bo2.setId("bo2");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleA.getId(), false);
final var bo3 = new TestBoB(); final var bo3 = new TestBoB();
bo3.setId("bo3"); bo3.setId("bo3");
this.workingSet.add(this.moduleA.getId(), bo3); this.workingSet.put(this.moduleA.getId(), bo3);
this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleA.getId(), false);
verify(this.renderingBoPool, times(1)).release(bo1); verify(this.renderingBoPool, times(1)).release(bo1);
@@ -236,8 +236,8 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo2 = mock(RenderingBo.class); final RenderingBo bo2 = mock(RenderingBo.class);
when(bo2.getId()).thenReturn("bo2"); when(bo2.getId()).thenReturn("bo2");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
final var retrieved1 = this.workingSet.get(this.moduleA.getId(), "bo1"); final var retrieved1 = this.workingSet.get(this.moduleA.getId(), "bo1");
final var retrieved2 = this.workingSet.get(this.moduleA.getId(), "bo2"); final var retrieved2 = this.workingSet.get(this.moduleA.getId(), "bo2");
@@ -255,8 +255,8 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo2 = mock(RenderingBo.class); final RenderingBo bo2 = mock(RenderingBo.class);
when(bo2.getId()).thenReturn("bo2"); when(bo2.getId()).thenReturn("bo2");
this.workingSet.add(this.moduleA.getId(), bo1); this.workingSet.put(this.moduleA.getId(), bo1);
this.workingSet.add(this.moduleA.getId(), bo2); this.workingSet.put(this.moduleA.getId(), bo2);
final var committedWork = this.workingSet.commit(this.moduleA.getId(), false); final var committedWork = this.workingSet.commit(this.moduleA.getId(), false);
// After commit without clone, the uncommitted work should be empty // After commit without clone, the uncommitted work should be empty
@@ -277,12 +277,12 @@ public class RendererWorkingSetImplTest {
final RenderingBo bo1_replacement = mock(RenderingBo.class); final RenderingBo bo1_replacement = mock(RenderingBo.class);
when(bo1_replacement.getId()).thenReturn("bo1"); 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()); final var uncommittedBefore = this.workingSet.getUncommittedWork(this.moduleA.getId());
assertEquals(1, uncommittedBefore.size()); assertEquals(1, uncommittedBefore.size());
assertSame(bo1, uncommittedBefore.get("bo1")); 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()); final var uncommittedAfter = this.workingSet.getUncommittedWork(this.moduleA.getId());
assertEquals(1, uncommittedAfter.size()); assertEquals(1, uncommittedAfter.size());
assertSame(bo1_replacement, uncommittedAfter.get("bo1")); assertSame(bo1_replacement, uncommittedAfter.get("bo1"));
@@ -297,9 +297,9 @@ public class RendererWorkingSetImplTest {
final var boA2 = new TestBoA(); final var boA2 = new TestBoA();
boA2.setId("boA2"); boA2.setId("boA2");
this.workingSet.add(this.moduleA.getId(), boA1); this.workingSet.put(this.moduleA.getId(), boA1);
this.workingSet.add(this.moduleB.getId(), boB1); this.workingSet.put(this.moduleB.getId(), boB1);
this.workingSet.add(this.moduleA.getId(), boA2); this.workingSet.put(this.moduleA.getId(), boA2);
this.workingSet.commit(this.moduleA.getId(), false); this.workingSet.commit(this.moduleA.getId(), false);
this.workingSet.commit(this.moduleB.getId(), false); this.workingSet.commit(this.moduleB.getId(), false);