From 5d16df4e0951f3a935da04a6930b30149a2edcff Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Wed, 18 Dec 2024 01:23:14 +0000 Subject: [PATCH 01/37] Added passthrough methods to get objects from parent context. --- .../com/physmo/garnet/toolkit/Component.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/main/java/com/physmo/garnet/toolkit/Component.java b/src/main/java/com/physmo/garnet/toolkit/Component.java index 30a8bb5..1bf1bc9 100644 --- a/src/main/java/com/physmo/garnet/toolkit/Component.java +++ b/src/main/java/com/physmo/garnet/toolkit/Component.java @@ -2,6 +2,8 @@ import com.physmo.garnet.graphics.Graphics; +import java.util.List; + /** * Abstract class representing logic and behaviour that can be attached to a game object. */ @@ -17,4 +19,65 @@ public abstract class Component { public void setParent(GameObject parent) { this.parent = parent; } + + + // Parent Context pass-though methods: + + /** + * Retrieves an object of the specified type from the parent context. + * This method is a pass-through to the parent context's {@code getObjectByType} method. + * + * @param The type of the object to retrieve. + * @param clazz The {@code Class} object representing the type of the object to retrieve. + * @return An object of the specified type, if found in the parent context. + * @throws RuntimeException If no object of the specified type is found. + */ + public T getObjectByTypeFromParentContext(Class clazz) { + return parent.getContext().getObjectByType(clazz); + } + + /** + * Searches the parent context for a specific component of the specified type. + * This method allows retrieving components associated with game objects + * within the current context. + * + * @param The type of the component to retrieve. + * @param clazz The {@code Class} object representing the type of the component to retrieve. + * @return The component of the specified type, or {@code null} if no matching component is found. + */ + public T getComponentFromParentContext(Class clazz) { + return parent.getContext().getComponent(clazz); + } + + /** + * Retrieves a list of game objects that are associated with the specified tag. + * This method delegates the call to the parent context's {@code getObjectsByTag} method. + * + * @param tag The string-based tag used to filter game objects. + * @return A list of {@code GameObject} instances that match the specified tag. + */ + public List getObjectsByTagFromParentContext(String tag) { + return parent.getContext().getObjectsByTag(tag); + } + + /** + * Retrieves the first {@code GameObject} with the specified tag from the parent context. + * This method delegates the request to the parent context's {@code getObjectByTag} method. + * + * @param tag The string-based tag used to identify the {@code GameObject}. + * @return The first {@code GameObject} that matches the provided tag, + * or {@code null} if no matching object is found. + */ + public GameObject getObjectByTagFromParentContext(String tag) { + return parent.getContext().getObjectByTag(tag); + } + + private void checkParentContextAvailable() { + if (parent == null) { + throw new RuntimeException("Component: parent context not available (Parent is null)"); + } + if (parent.getContext() == null) { + throw new RuntimeException("Component: parent context not available (Context is null)"); + } + } } From c7331d3dbe511b23d15b350934b186690455bde4 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:54:16 +0000 Subject: [PATCH 02/37] Add ParticleManagerExample showcasing particle system usage This new example demonstrates how to use the ParticleManager toolkit to create and manage particle systems with custom emitters and renderers. It includes sample particles with varying lifetimes, colors, and animations to guide users in implementing similar effects. --- .../toolkit/ParticleManagerExample.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java b/src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java new file mode 100644 index 0000000..420be6a --- /dev/null +++ b/src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java @@ -0,0 +1,87 @@ +package com.physmo.garnetexamples.toolkit; + +import com.physmo.garnet.Garnet; +import com.physmo.garnet.GarnetApp; +import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.Texture; +import com.physmo.garnet.graphics.TileSheet; +import com.physmo.garnet.structure.Vector3; +import com.physmo.garnet.toolkit.color.ColorSupplierLinear; +import com.physmo.garnet.toolkit.particle.Emitter; +import com.physmo.garnet.toolkit.particle.ParticleManager; +import com.physmo.garnet.toolkit.particle.ParticleTemplate; + +public class ParticleManagerExample extends GarnetApp { + + private static final String fileName1 = "space.PNG"; + Texture texture; + TileSheet tileSheet; + ParticleManager particleManager; + + public ParticleManagerExample(Garnet garnet, String name) { + super(garnet, name); + } + + public static void main(String[] args) { + Garnet garnet = new Garnet(640, 480); + GarnetApp app = new ParticleManagerExample(garnet, ""); + + garnet.setApp(app); + + garnet.init(); + garnet.run(); + } + + @Override + public void init(Garnet garnet) { + Graphics g = garnet.getGraphics(); + + // Load the texture resource and create a tilesheet to access it. + texture = Texture.loadTexture(fileName1); + tileSheet = new TileSheet(texture, 16, 16); + g.addTexture(texture); + + // Create the particle manager and set a default render function. + particleManager = new ParticleManager(1000); + + particleManager.setParticleDrawer(p -> { + float pAge = (float) (p.age / p.lifeTime); + g.setColor(p.colorSupplier.getColor(pAge)); + g.drawImage(tileSheet, (int) (p.position.x) - 8, (int) (p.position.y) - 8, 4, 0); + }); + + + ParticleTemplate pt1 = new ParticleTemplate(); + pt1.setLifeTime(1, 2); + pt1.setColorSupplier(new ColorSupplierLinear(new int[]{0xff00ffff, 0x00ffffff})); + + ParticleTemplate pt2 = new ParticleTemplate(); + pt2.setLifeTime(1, 2); + pt2.setColorSupplier(new ColorSupplierLinear(new int[]{0xff0000ff, 0x00ff00ff})); + + + // Add a custom drawer to this particle type. + pt2.setParticleDrawer(p -> { + g.setColor(p.colorSupplier.getColor(p.age / p.lifeTime)); + g.drawImage(tileSheet, p.position.x, p.position.y, 3, 0); + }); + + Emitter e1 = new Emitter(new Vector3(100, 100, 0), 5, pt1); + e1.setEmitPerSecond(150); + Emitter e2 = new Emitter(new Vector3(200, 100, 0), 5, pt2); + e2.setEmitPerSecond(150); + + particleManager.addEmitter(e1); + particleManager.addEmitter(e2); + } + + @Override + public void tick(double delta) { + particleManager.tick(delta); + } + + @Override + public void draw(Graphics g) { + particleManager.draw(g); + } +} From 43c7cbf9699af2bc257eeb8cd7dec55618604448 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:55:27 +0000 Subject: [PATCH 03/37] Let tick rate be controlled --- src/main/java/com/physmo/garnet/Garnet.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/physmo/garnet/Garnet.java b/src/main/java/com/physmo/garnet/Garnet.java index b675a5c..d8e933a 100644 --- a/src/main/java/com/physmo/garnet/Garnet.java +++ b/src/main/java/com/physmo/garnet/Garnet.java @@ -38,13 +38,13 @@ public class Garnet { private final List keyboardCallbacks = new ArrayList<>(); private final GameClock gameClock = new GameClock(); - private final double tickRate = 1; private final Input input; private final Display display; private final Graphics graphics; private final Sound sound; private final DebugDrawer debugDrawer; private final boolean drawFrameGraph = false; + private double tickRate = 1; private GarnetApp garnetApp; private double runningLogicDelta = 0; /** @@ -61,6 +61,14 @@ public Garnet(int windowWidth, int windowHeight) { debugDrawer = new DebugDrawer(input); } + public double getTickRate() { + return tickRate; + } + + public void setTickRate(double tickRate) { + this.tickRate = tickRate; + } + public void setGarnetApp(GarnetApp garnetApp) { this.garnetApp = garnetApp; } From 860ac985a8400f69d0299b15a05906b8036532ba Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:56:08 +0000 Subject: [PATCH 04/37] Cleanup --- .../physmo/garnet/toolkit/particle/ParticleManager.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/particle/ParticleManager.java b/src/main/java/com/physmo/garnet/toolkit/particle/ParticleManager.java index a06a70e..8b3effb 100644 --- a/src/main/java/com/physmo/garnet/toolkit/particle/ParticleManager.java +++ b/src/main/java/com/physmo/garnet/toolkit/particle/ParticleManager.java @@ -34,11 +34,7 @@ public void tick(double delta) { emitter.tick(delta); } - List emitterList2 = new ArrayList<>(); - for (Emitter emitter : emitterList) { - if (!emitter.remove) emitterList2.add(emitter); - } - emitterList = emitterList2; + emitterList.removeIf(e -> e.remove); for (Particle particle : particles) { if (particle.active) @@ -47,6 +43,7 @@ public void tick(double delta) { } + // TODO: we'll optimise this later. public Particle getFreeParticle() { for (Particle particle : particles) { From 35baeebe85e9f8459b95fb4c2221d61487994780 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:57:07 +0000 Subject: [PATCH 05/37] Refactor canvas size management in Display class. Replaced separate canvas width and height variables with a unified `canvasSize` array. Adjusted related calculations and methods to use this new structure for improved clarity and consistency. Removed redundant commented-out code and cleaned up unused variables. --- src/main/java/com/physmo/garnet/Display.java | 49 +++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/physmo/garnet/Display.java b/src/main/java/com/physmo/garnet/Display.java index f5f6685..9ea8a1a 100644 --- a/src/main/java/com/physmo/garnet/Display.java +++ b/src/main/java/com/physmo/garnet/Display.java @@ -46,18 +46,30 @@ */ public class Display { - private long windowHandle; public double[] glViewportScale = new double[2]; public int[] glViewportOffsets = new int[2]; int primaryMonitorWidth; int primaryMonitorHeight; - double windowScale = 1; int storedWindowX = 0; int storedWindowY = 0; - int canvasWidth = 0; // Canvas refers to the internal game width and height. - int canvasHeight = 0; + + int[] canvasSize = new int[2]; + private long windowHandle; int stretchMode = 2; + private int windowWidth; + private int windowHeight; + + public Display(int windowWidth, int windowHeight) { + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + canvasSize[0] = windowWidth; + canvasSize[1] = windowHeight; + } + + public int[] getCanvasSize() { + return canvasSize; + } public int getWindowWidth() { return windowWidth; @@ -67,12 +79,10 @@ public int getWindowHeight() { return windowHeight; } - public long getWindowHandle() { return windowHandle; } - public double[] getWindowToPixelsScale() { int[] bufferSize = getWindowSize(); double w = (double) bufferSize[0] / (double) windowWidth; @@ -86,7 +96,6 @@ public int[] getWindowSize() { return new int[]{w2[0], h2[0]}; } - private int windowWidth; public int[] getBufferSize() { int[] w = new int[1], h = new int[1]; @@ -130,14 +139,6 @@ public void setFullScreen(boolean val) { glfwSetWindowMonitor(windowHandle, 0, storedWindowX, storedWindowY, windowWidth, windowHeight, GLFW_DONT_CARE); } } - private int windowHeight; - - public Display(int windowWidth, int windowHeight) { - this.windowWidth = windowWidth; - this.windowHeight = windowHeight; - canvasWidth = windowWidth; - canvasHeight = windowHeight; - } public double[] getWindowToBufferScale() { int[] bufferSize = getBufferSize(); @@ -145,10 +146,6 @@ public double[] getWindowToBufferScale() { double h = (double) bufferSize[1] / (double) windowHeight; return new double[]{w, h}; -// int[] bufferSize = getBufferSize(); -// double w = (double) canvasWidth / (double) windowWidth; -// double h = (double) canvasHeight / (double) windowHeight; -// return new double[]{w, h}; } public void setWindowScale(double windowScale, boolean centerWindow) { @@ -251,26 +248,26 @@ public void placeGlViewport() { glViewport(0, 0, bufferSize[0], bufferSize[1]); glViewportOffsets[0] = 0; glViewportOffsets[1] = 0; - glViewportScale[0] = (double) canvasWidth / bufferSize[0]; - glViewportScale[1] = (double) canvasHeight / bufferSize[1]; + glViewportScale[0] = (double) canvasSize[0] / bufferSize[0]; + glViewportScale[1] = (double) canvasSize[1] / bufferSize[1]; } // Scale and keep aspect. if (stretchMode == 2) { - double aspect = (double) canvasWidth / (double) canvasHeight; + double aspect = (double) canvasSize[0] / (double) canvasSize[1]; double windowAspect = (double) bufferSize[0] / (double) bufferSize[1]; int newWidth, newHeight; double scale; if (aspect > windowAspect) { - scale = (double) canvasWidth / bufferSize[0]; + scale = (double) canvasSize[0] / bufferSize[0]; } else { - scale = (double) canvasHeight / bufferSize[1]; + scale = (double) canvasSize[1] / bufferSize[1]; } - newWidth = (int) (canvasWidth / scale); - newHeight = (int) (canvasHeight / scale); + newWidth = (int) (canvasSize[0] / scale); + newHeight = (int) (canvasSize[1] / scale); int xOffset = (bufferSize[0] - newWidth) / 2; int yOffset = (bufferSize[1] - newHeight) / 2; From 6de8aa7a37b3cec7080706d2109a847dfd1384f3 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:57:22 +0000 Subject: [PATCH 06/37] Initialize default emissionRateCurve in Emitter constructor Set a default value for the emissionRateCurve to ensure it is not null upon initialization. This prevents potential issues with uninitialized curves and simplifies the usage of the Emitter class. --- src/main/java/com/physmo/garnet/toolkit/particle/Emitter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/particle/Emitter.java b/src/main/java/com/physmo/garnet/toolkit/particle/Emitter.java index 22a8c6d..bc3ef87 100644 --- a/src/main/java/com/physmo/garnet/toolkit/particle/Emitter.java +++ b/src/main/java/com/physmo/garnet/toolkit/particle/Emitter.java @@ -17,7 +17,7 @@ public class Emitter { ParticleTemplate particleTemplate; double emitPerSecond = 1500; - Curve emissionRateCurve; + Curve emissionRateCurve = new StandardCurve(CurveType.LINE_DOWN); public Emitter(Vector3 position, double duration, ParticleTemplate particleTemplate) { this.particleTemplate = particleTemplate; From cef5af003d7756c45b013a97c312a9cc2a99a6f4 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:57:39 +0000 Subject: [PATCH 07/37] Add and enhance Array test cases Refactored existing test to use `size()` method properly. Added new test cases to validate array clearing, item addition/retrieval, and iterator functionality to improve test coverage. --- .../physmo/garnet/structure/ArrayTest.groovy | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy b/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy index d8f89dc..90016a4 100644 --- a/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy +++ b/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy @@ -15,8 +15,66 @@ class ArrayTest extends Specification { } then: - array.size == 6 + array.size() == 6 array.getCapacity() == 10; } + + def "Clear clears the Array"() { + given: + Array array = new Array<>(5); + + when: + array.add("A") + array.add("B") + array.add("C") + array.add("D") + array.clear() + + then: + array.size == 0 + + } + + def "Array items can be added and retrieved"() { + given: + Array array = new Array<>(5); + + when: + array.add("A") + array.add("B") + array.add("C") + + + then: + array.get(0) == "A" + array.get(1) == "B" + array.get(2) == "C" + + } + + def "Array iterator works as expected"() { + + given: + Array array = new Array<>(5); + + and: + array.add("A") + array.add("B") + array.add("C") + + when: + int count = 0 + String[] strings = new String[5] + for (String str : array) { + strings[count++] = str + } + + then: + strings[0] == "A" + strings[1] == "B" + strings[2] == "C" + + } + } From bc4fa103a36f5aa82d27b28d470c097a222ed0bb Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:58:35 +0000 Subject: [PATCH 08/37] Refactor and enhance CollisionSystem functionality Refactored methods to improve clarity and efficiency, including changes like replacing `size() == 0` with `isEmpty()`. Added new utilities such as `getListOfActiveCollidables` and `removeColliderFromGameObject`, alongside enhanced comments for better documentation. Rearranged and reintroduced methods for consistency and future extensibility. --- .../simplecollision/CollisionSystem.java | 137 +++++++++++------- 1 file changed, 85 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java index fc8ac4d..bd02678 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java @@ -4,6 +4,7 @@ import com.physmo.garnet.graphics.Graphics; import com.physmo.garnet.structure.Rect; import com.physmo.garnet.structure.Vector3; +import com.physmo.garnet.toolkit.Component; import com.physmo.garnet.toolkit.GameObject; import com.physmo.garnet.toolkit.StringIdBroker; @@ -31,10 +32,6 @@ public void init() { } - public int getTestsPerFrame() { - return testsPerFrame; - } - @Override public void tick(double t) { testsPerFrame = 0; @@ -52,7 +49,7 @@ public void tick(double t) { } private void removePendingCollidables() { - if (collidablesPendingRemoval.size() == 0) return; + if (collidablesPendingRemoval.isEmpty()) return; List keepList = new ArrayList<>(); @@ -96,6 +93,37 @@ private List calculateCollisions2() { return collisions; } + @Override + public void draw(Graphics g) { + + if (collisionDrawingCallback == null) return; + List activeCollidables = getListOfActiveCollidables(); + for (Collidable collidable : activeCollidables) { + collisionDrawingCallback.draw(collidable); + } + + } + + /** + * Retrieves a list of all active collidable objects currently present in the collision system. + * A collidable object is considered active if its associated game object is active. + * + * @return A list of active Collidable objects. + */ + public List getListOfActiveCollidables() { + List activeCollidables = new ArrayList<>(); + for (Collidable collidable : collidables) { + if (!collidable.collisionGetGameObject().isActive()) continue; + activeCollidables.add(collidable); + } + return activeCollidables; + } + + public int getTestsPerFrame() { + return testsPerFrame; + } + + // TODO: don't create a list here, pass it in. public List getListOfCollidablesWithTag(String tag) { int tagId = StringIdBroker.INSTANCE.getId(tag); @@ -107,6 +135,29 @@ public List getListOfCollidablesWithTag(String tag) { return collidableList; } + /** + * Calculates all collisions between active collidable objects in the system. + * The method retrieves the list of active collidables, identifies pairs of objects + * that are colliding, and stores these interactions as {@code CollisionPacket} instances. + * + * @return A list of {@code CollisionPacket} objects representing detected collisions + * between pairs of collidable objects. + */ + private List calculateCollisions() { + List collisions = new ArrayList<>(); + List activeCollidables = getListOfActiveCollidables(); + + for (Collidable c1 : activeCollidables) { + for (Collidable c2 : activeCollidables) { + if (c1 == c2) continue; + boolean collided = testCollision(c1, c2); + if (collided) collisions.add(new CollisionPacket(c1, c2)); + } + } + + return collisions; + } + /** * Search system for objects that are close to a supplied coordinate. * @@ -160,51 +211,10 @@ public boolean testCollision(Collidable c1, Collidable c2) { return rect1.intersect(rect2); } - private List calculateCollisions() { - List collisions = new ArrayList<>(); - List activeCollidables = getListOfActiveCollidables(); - - for (Collidable c1 : activeCollidables) { - for (Collidable c2 : activeCollidables) { - if (c1 == c2) continue; - boolean collided = testCollision(c1, c2); - if (collided) collisions.add(new CollisionPacket(c1, c2)); - } - } - - return collisions; - } - - @Override - public void draw(Graphics g) { - - if (collisionDrawingCallback == null) return; - List activeCollidables = getListOfActiveCollidables(); - for (Collidable collidable : activeCollidables) { - collisionDrawingCallback.draw(collidable); - } - - } - - - /** - * Adds a collidable object to the collision system. - * NOTE: Collidable must be removed when parent object is destroyed. - * - * @param collidable The collidable object to add. - */ - public void addCollidable(Collidable collidable) { - collidables.add(collidable); - } - public int getSize() { return collidables.size(); } - public void removeCollidable(Collidable collidable) { - collidablesPendingRemoval.add(collidable); - } - /** * Check for objects that are close to each other and call their * processing functions @@ -262,13 +272,26 @@ public int processCloseObjects(String tag, double distanceThreshold) { return count; } - public List getListOfActiveCollidables() { - List activeCollidables = new ArrayList<>(); - for (Collidable collidable : collidables) { - if (!collidable.collisionGetGameObject().isActive()) continue; - activeCollidables.add(collidable); + /** + * Removes all collider components from the specified GameObject. + * A collider component is identified as an instance of a class + * implementing the {@code Collidable} interface. This method iterates + * through all components of the GameObject and removes the ones + * that are collidable from the associated collision system. + * + * @param gameObject The GameObject from which collider components will be removed. + */ + public void removeColliderFromGameObject(GameObject gameObject) { + for (Component component : gameObject.getComponents()) { + if (component instanceof Collidable c) { + removeCollidable(c); + } } - return activeCollidables; + } + + public void removeCollidable(Collidable collidable) { + if (collidable == null) throw new RuntimeException("collidable is null"); + collidablesPendingRemoval.add(collidable); } /** @@ -286,4 +309,14 @@ public ColliderComponent addNewColliderToGameObject(GameObject gameObject) { return colliderComponent; } + /** + * Adds a collidable object to the collision system. + * NOTE: Collidable must be removed when parent object is destroyed. + * + * @param collidable The collidable object to add. + */ + public void addCollidable(Collidable collidable) { + collidables.add(collidable); + } + } From a877ee6af51b84161d317faaceecdccb641407e8 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:58:46 +0000 Subject: [PATCH 09/37] Add Javadoc to ObjectPool class Introduce detailed Javadoc comments for the ObjectPool class, explaining its purpose and usage. This improves code readability and provides clarity on its functionality and type parameters. --- src/main/java/com/physmo/garnet/graphics/ObjectPool.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/physmo/garnet/graphics/ObjectPool.java b/src/main/java/com/physmo/garnet/graphics/ObjectPool.java index 5b255de..b76266e 100644 --- a/src/main/java/com/physmo/garnet/graphics/ObjectPool.java +++ b/src/main/java/com/physmo/garnet/graphics/ObjectPool.java @@ -2,6 +2,13 @@ import java.lang.reflect.Array; +/** + * A generic object pool implementation that allows for efficient reuse of objects. + * The ObjectPool class maintains a pool of reusable objects to minimize object creation + * overhead by recycling objects instead of creating new ones each time. + * + * @param the type of object to be pooled in this ObjectPool instance + */ public class ObjectPool { T[] pool; From caab3c852525b5c6f7bedc41cb87899c77321dfb Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sat, 11 Jan 2025 16:59:02 +0000 Subject: [PATCH 10/37] Add gravity support to particles Introduced gravityDirection and gravityForce properties to both Particle and ParticleTemplate classes. Added getter and setter methods to manage these properties, enabling gravity-related behavior for particles. This update enhances the particle system with more physics-based dynamics. --- .../garnet/toolkit/particle/Particle.java | 19 +++++++++ .../toolkit/particle/ParticleTemplate.java | 40 ++++++++++++++----- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/particle/Particle.java b/src/main/java/com/physmo/garnet/toolkit/particle/Particle.java index e82950a..6a4e264 100644 --- a/src/main/java/com/physmo/garnet/toolkit/particle/Particle.java +++ b/src/main/java/com/physmo/garnet/toolkit/particle/Particle.java @@ -18,6 +18,25 @@ public class Particle { Vector3 force = new Vector3(); boolean active = false; + Vector3 gravityDirection; + double gravityForce; + + public Vector3 getGravityDirection() { + return gravityDirection; + } + + public void setGravityDirection(Vector3 gravityDirection) { + this.gravityDirection = gravityDirection; + } + + public double getGravityForce() { + return gravityForce; + } + + public void setGravityForce(double gravityForce) { + this.gravityForce = gravityForce; + } + ParticleDrawer particleDrawer; public ParticleDrawer getParticleDrawer() { diff --git a/src/main/java/com/physmo/garnet/toolkit/particle/ParticleTemplate.java b/src/main/java/com/physmo/garnet/toolkit/particle/ParticleTemplate.java index 18e4c33..258a0e3 100644 --- a/src/main/java/com/physmo/garnet/toolkit/particle/ParticleTemplate.java +++ b/src/main/java/com/physmo/garnet/toolkit/particle/ParticleTemplate.java @@ -15,27 +15,22 @@ public class ParticleTemplate { Vector3 velocity; double velocityJitter; Vector3 force; + + Vector3 gravityDirection; + double gravityForce; RangedValue lifeTime; RangedValue speed; Curve speedCurve; ColorSupplier colorSupplier; - ParticleDrawer particleDrawer; - - public ParticleDrawer getParticleDrawer() { - return particleDrawer; - } - - public void setParticleDrawer(ParticleDrawer particleDrawer) { - this.particleDrawer = particleDrawer; - } - public ParticleTemplate() { positionJitter = 2.1; position = new Vector3(); velocity = new Vector3(); + gravityDirection = new Vector3(); velocityJitter = 0.1; force = new Vector3(); + gravityForce = 0.0; //friction=0.9; lifeTime = new RangedValue(0.2, 3); speed = new RangedValue(10, 50); @@ -43,6 +38,30 @@ public ParticleTemplate() { colorSupplier = new ColorSupplierLinear(new int[]{ColorUtils.YELLOW, ColorUtils.asRGBA(1, 0, 0, 0)}); } + public Vector3 getGravityDirection() { + return gravityDirection; + } + + public void setGravityDirection(Vector3 gravityDirection) { + this.gravityDirection = gravityDirection; + } + + public double getGravityForce() { + return gravityForce; + } + + public void setGravityForce(double gravityForce) { + this.gravityForce = gravityForce; + } + + public ParticleDrawer getParticleDrawer() { + return particleDrawer; + } + + public void setParticleDrawer(ParticleDrawer particleDrawer) { + this.particleDrawer = particleDrawer; + } + public void initExplosion() { positionJitter = 2.1; position = new Vector3(); @@ -86,6 +105,7 @@ public void initParticle(Particle p, Vector3 emitterPos) { p.speedCurve = speedCurve; p.colorSupplier = colorSupplier; p.particleDrawer = particleDrawer; + } public Vector3 getVectorWithJitter(Vector3 v, double jitter) { From b0c684c2102c710c31c61d02f823e2b6526693d7 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:01:57 +0000 Subject: [PATCH 11/37] Refactor animation frame retrieval to use output parameter. Changed `getImage` method in `Animation` to use an output parameter instead of returning a value. Updated `AnimationExample` to adapt to this new method signature, improving memory reuse and avoiding unnecessary object creation. --- .../com/physmo/garnet/graphics/Animation.java | 8 ++++---- .../garnetexamples/graphics/AnimationExample.java | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/physmo/garnet/graphics/Animation.java b/src/main/java/com/physmo/garnet/graphics/Animation.java index babaa84..7ec2e68 100644 --- a/src/main/java/com/physmo/garnet/graphics/Animation.java +++ b/src/main/java/com/physmo/garnet/graphics/Animation.java @@ -81,20 +81,20 @@ private int calculateFrameFromTime(double t) { /** * The current frame of the animation as an index of the total number of frames. * - * @return + * @return the current frame index */ public int getCurrentFrameIndex() { return currentFrame; } /** - * Returns the current from as a SubImage object compatible with image drawing methods. + * Returns the current frame as a SubImage object compatible with image drawing methods. * * @return A SubImage object representing the image area of the frame. */ - public SubImage getImage() { + public void getImage(SubImage outSubImage) { FrameInfo frameInfo = frameList.get(currentFrame); - return tileSheet.getSubImage(frameInfo.col, frameInfo.row); + tileSheet.getSubImage(frameInfo.col, frameInfo.row, outSubImage); } private class FrameInfo { diff --git a/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java b/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java index 70e03ef..e9a2970 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java +++ b/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java @@ -5,6 +5,7 @@ import com.physmo.garnet.GarnetApp; import com.physmo.garnet.graphics.Animation; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.Texture; // NOTE: On MacOS the following VM argument is required: -XstartOnFirstThread @@ -15,6 +16,9 @@ public class AnimationExample extends GarnetApp { Animation animation1; Animation animation2; Animation animation3; + SubImage subImage1 = new SubImage(); + SubImage subImage2 = new SubImage(); + SubImage subImage3 = new SubImage(); private Texture texture1; @@ -78,9 +82,14 @@ public void draw(Graphics g) { // Draw unscaled sprites using sprite sheet graphics.setZoom(3); - graphics.drawImage(animation1.getImage(), 0, 10); - graphics.drawImage(animation2.getImage(), 0, 10 + 30); - graphics.drawImage(animation3.getImage(), 0, 10 + 60); + + animation1.getImage(subImage1); + animation2.getImage(subImage2); + animation3.getImage(subImage3); + + graphics.drawImage(subImage1, 0, 10); + graphics.drawImage(subImage2, 0, 10 + 30); + graphics.drawImage(subImage3, 0, 10 + 60); } From 2455dbd00a8bf882818089abc3c996318a0c52bc Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:02:18 +0000 Subject: [PATCH 12/37] Refactor to reuse SubImage instances for performance. Replaced per-call SubImage object allocations with reusable instances across relevant classes. Added `configure` method to SubImage for updating properties. These changes reduce memory allocation overhead and enhance rendering performance. --- .../com/physmo/garnet/graphics/SubImage.java | 16 ++++++++++++++++ .../com/physmo/garnet/graphics/TileSheet.java | 14 ++++++++++++-- .../java/com/physmo/garnet/text/RegularFont.java | 6 ++++-- .../physmo/garnet/tilegrid/TileGridDrawer.java | 11 +++++++++-- .../garnetexamples/graphics/TileGridExample.java | 6 ++++-- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/physmo/garnet/graphics/SubImage.java b/src/main/java/com/physmo/garnet/graphics/SubImage.java index 30d44ec..df874b6 100644 --- a/src/main/java/com/physmo/garnet/graphics/SubImage.java +++ b/src/main/java/com/physmo/garnet/graphics/SubImage.java @@ -12,6 +12,14 @@ public class SubImage { public int w; public int h; + public SubImage() { + texture = null; + x = 0; + y = 0; + w = 0; + h = 0; + } + public SubImage(Texture texture, int x, int y, int w, int h) { this.texture = texture; this.x = x; @@ -19,4 +27,12 @@ public SubImage(Texture texture, int x, int y, int w, int h) { this.w = w; this.h = h; } + + public void configure(Texture texture, int x, int y, int w, int h) { + this.texture = texture; + this.x = x; + this.y = y; + this.w = w; + this.h = h; + } } diff --git a/src/main/java/com/physmo/garnet/graphics/TileSheet.java b/src/main/java/com/physmo/garnet/graphics/TileSheet.java index e35552a..632c6a5 100644 --- a/src/main/java/com/physmo/garnet/graphics/TileSheet.java +++ b/src/main/java/com/physmo/garnet/graphics/TileSheet.java @@ -37,8 +37,18 @@ public int[] getTileCoordsFromIndex(int index) { return new int[]{x, y}; } - public SubImage getSubImage(int column, int row) { - return new SubImage(texture, column * tileWidth, row * tileHeight, tileWidth, tileHeight); + /** + * Retrieves a portion of the texture based on the specified tile column and row, + * and configures the provided SubImage object with the resulting subimage's properties. + *

+ * NOTE: To avoid allocating many new subImage objects, an output parameter is used. + * + * @param column the column index of the desired tile. + * @param row the row index of the desired tile. + * @param outSubImage the SubImage object to configure with the properties of the designated tile. + */ + public void getSubImage(int column, int row, SubImage outSubImage) { + outSubImage.configure(texture, column * tileWidth, row * tileHeight, tileWidth, tileHeight); } public int getTileIndexFromCoords(int x, int y) { diff --git a/src/main/java/com/physmo/garnet/text/RegularFont.java b/src/main/java/com/physmo/garnet/text/RegularFont.java index 46414e2..39dfa95 100644 --- a/src/main/java/com/physmo/garnet/text/RegularFont.java +++ b/src/main/java/com/physmo/garnet/text/RegularFont.java @@ -2,6 +2,7 @@ import com.physmo.garnet.FileUtils; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.Texture; import com.physmo.garnet.graphics.TileSheet; @@ -19,6 +20,7 @@ public class RegularFont implements DrawableFont { private final int charHeight; double scale = 1; private int horizontalPad = 0; + private SubImage characterSubImage = new SubImage(); public RegularFont(String path, int charWidth, int charHeight) { this(FileUtils.getFileFromResourceAsStream(path), charWidth, charHeight); @@ -87,8 +89,8 @@ private void renderText(Graphics graphics, String text, int x, int y) { public void renderChar(Graphics graphics, char c, int x, int y) { int cy = ((int) c) / 16; int cx = ((int) c) % 16; - - graphics.drawImageScaled(tileSheet.getSubImage(cx, cy), x, y, scale); + tileSheet.getSubImage(cx, cy, characterSubImage); + graphics.drawImageScaled(characterSubImage, x, y, scale); } diff --git a/src/main/java/com/physmo/garnet/tilegrid/TileGridDrawer.java b/src/main/java/com/physmo/garnet/tilegrid/TileGridDrawer.java index 5c553c4..de09387 100644 --- a/src/main/java/com/physmo/garnet/tilegrid/TileGridDrawer.java +++ b/src/main/java/com/physmo/garnet/tilegrid/TileGridDrawer.java @@ -1,11 +1,15 @@ package com.physmo.garnet.tilegrid; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.TileSheet; import com.physmo.garnet.graphics.Viewport; /** - * Note: window position and size will be scaled by the scale value. + * The TileGridDrawer class is responsible for rendering a grid of tiles + * based on a defined TileSheet and TileGridData configuration. It allows + * setting the tile properties, viewport configuration, and drawing the + * visible portion of the grid onto a Graphics object. */ public class TileGridDrawer { @@ -13,6 +17,7 @@ public class TileGridDrawer { private int viewportId = -1; private TileSheet tileSheet; private TileGridData tileGridData; + SubImage tileSubImage = new SubImage(); public TileGridDrawer() { tileWidth = 16; @@ -50,12 +55,14 @@ public void draw(Graphics g, int drawPosX, int drawPosY) { int xSize = (int) ((visibleRect[2]) / tileWidth) + 3; int ySize = (int) ((visibleRect[3]) / tileHeight) + 3; + for (int y = yStart; y <= yStart + ySize; y++) { for (int x = xStart; x <= xStart + xSize; x++) { int tileId = tileGridData.getTileId(x, y); if (tileId == -1) continue; tCoords = tileSheet.getTileCoordsFromIndex(tileId); - g.drawImage(tileSheet.getSubImage(tCoords[0], tCoords[1]), + tileSheet.getSubImage(tCoords[0], tCoords[1], tileSubImage); + g.drawImage(tileSubImage, drawPosX + ((x) * (tileWidth)), drawPosY + ((y) * (tileHeight))); } diff --git a/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java b/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java index 73208bf..b90f5ad 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java +++ b/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java @@ -3,6 +3,7 @@ import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.Texture; import com.physmo.garnet.graphics.TileSheet; import com.physmo.garnet.graphics.Viewport; @@ -26,6 +27,7 @@ public class TileGridExample extends GarnetApp { int wallTileID; int grassTileID; Viewport viewport; + SubImage subImage = new SubImage(); public TileGridExample(Garnet garnet, String name) { super(garnet, name); @@ -84,7 +86,7 @@ public void init(Garnet garnet) { } } - + tileSheet.getSubImage(0, 0, subImage); } @Override @@ -118,7 +120,7 @@ public void tick(double delta) { @Override public void draw(Graphics g) { tileGridDrawer.draw(g, 0, 0); - g.drawImage(tileSheet.getSubImage(0, 0), 64, 86); + g.drawImage(subImage, 64, 86); } } From 20fd791f53370b8ee2ad086611a904dc76de27ce Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:02:36 +0000 Subject: [PATCH 13/37] Refactor SubImage usage for improved efficiency. Replaced repeated SubImage object creation with reusable instances in Graphics and example classes. This reduces object churn and improves rendering performance by minimizing redundant calls to create SubImage objects. --- .../java/com/physmo/garnet/graphics/Graphics.java | 13 +++++++------ .../garnetexamples/graphics/TileSheetExample.java | 5 ++++- .../garnetexamples/graphics/ViewportExample.java | 9 +++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/physmo/garnet/graphics/Graphics.java b/src/main/java/com/physmo/garnet/graphics/Graphics.java index feec746..813cb07 100644 --- a/src/main/java/com/physmo/garnet/graphics/Graphics.java +++ b/src/main/java/com/physmo/garnet/graphics/Graphics.java @@ -37,10 +37,9 @@ public class Graphics { private int currentDrawOrder; private int currentlyBoundTextureId; private int backgroundColor = 0; - private double xo = 0; - private double yo = 0; private int clipRectHash = 0; private int activeViewportId = 0; + SubImage subImage = new SubImage(); public Graphics(Display display) { this.display = display; @@ -152,9 +151,9 @@ public void setActiveViewport(int id) { if (id == activeViewportId) return; activeViewportId = id; viewportManager.setActiveViewport(id); - Viewport viewport = viewportManager.getActiveViewport(); - xo = viewport.getWindowX() - viewport.getX(); - yo = viewport.getWindowY() - viewport.getY(); +// Viewport viewport = viewportManager.getActiveViewport(); +// xo = viewport.getWindowX() - viewport.getX(); +// yo = viewport.getWindowY() - viewport.getY(); } public void drawRect(float x, float y, float w, float h) { @@ -205,6 +204,7 @@ public Sprite2D drawImage(TileSheet tileSheet, double x, double y, int tileX, in return sprite2D; } + /** * Draws an image from a specified tile in the given TileSheet at the specified coordinates. * @@ -216,7 +216,8 @@ public Sprite2D drawImage(TileSheet tileSheet, double x, double y, int tileX, in * @return the Sprite2D object representing the drawn image */ public Sprite2D drawImage(TileSheet tileSheet, double x, double y, int tileX, int tileY) { - return drawImage(tileSheet.getSubImage(tileX, tileY), x, y); + tileSheet.getSubImage(tileX, tileY, subImage); + return drawImage(subImage, x, y); } /** diff --git a/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java b/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java index 16fdfc4..5916843 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java +++ b/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java @@ -3,6 +3,7 @@ import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.Texture; import com.physmo.garnet.graphics.TileSheet; @@ -65,7 +66,9 @@ public void draw(Graphics g) { // Draw sprite using the getSubImage helper function. g.setColor(GREEN); - g.drawImage(tileSheet.getSubImage(2, 2), (int) xPos + 20, 5); + SubImage subImage = new SubImage(); + tileSheet.getSubImage(2, 2, subImage); + g.drawImage(subImage, (int) xPos + 20, 5); g.setColor(BLUE); g.drawImage(tileSheet, mp[0], mp[1], 2, 2); diff --git a/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java b/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java index cbe1def..f904330 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java +++ b/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java @@ -3,6 +3,7 @@ import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.graphics.SubImage; import com.physmo.garnet.graphics.Texture; import com.physmo.garnet.graphics.TileSheet; import com.physmo.garnet.graphics.Viewport; @@ -93,12 +94,16 @@ public void draw(Graphics g) { } + SubImage subImage = new SubImage(); + public void drawSomeThings(Graphics g) { g.drawCircle(50, 50, 50, 50); g.filledCircle(50, 50 + 100, 50, 50); g.drawRect(0, 0, 100, 100); + tileSheet.getSubImage(2, 2, subImage); + for (int i = 0; i < 8; i++) { - g.drawImage(tileSheet.getSubImage(2, 2), i * 16, i * 16); + g.drawImage(subImage, i * 16, i * 16); } g.drawImage(tileSheet, 16 * 3, 16, 2, 2, angle); @@ -106,7 +111,7 @@ public void drawSomeThings(Graphics g) { // Draw a sprite at the lower right corner of the viewport's visible window. Viewport activeViewport = g.getViewportManager().getActiveViewport(); double[] visibleRect = activeViewport.getVisibleRect(); - g.drawImage(tileSheet.getSubImage(2, 2), + g.drawImage(subImage, visibleRect[0] + visibleRect[2] - 16, visibleRect[1] + visibleRect[3] - 16); } } From e204a0ca90a5f33da1ecfc9d6977459f227b35d4 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:03:00 +0000 Subject: [PATCH 14/37] Add new utility methods and enhance `Array` class functionality Introduced `removeIf`, `addAll`, and other utility methods to improve the versatility of the `Array` class. Enhanced documentation for existing and new methods, providing clarity on their purpose and usage. These updates increase usability and maintainability of the class. --- .../com/physmo/garnet/structure/Array.java | 110 ++++++++++++++++-- 1 file changed, 103 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/physmo/garnet/structure/Array.java b/src/main/java/com/physmo/garnet/structure/Array.java index 4901e24..4e60eda 100644 --- a/src/main/java/com/physmo/garnet/structure/Array.java +++ b/src/main/java/com/physmo/garnet/structure/Array.java @@ -3,6 +3,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; /** * A generic dynamic array that supports adding elements, resizing, sorting, @@ -17,14 +20,25 @@ public class Array implements Iterable { public T[] array; public int size; + /** + * Constructs an Array with a specified initial capacity. The array is initialized + * to hold elements of type T, and the initial size of the array is set to 0. + * + * @param capacity the initial capacity of the array + * (i.e., the maximum number of elements it can hold before resizing). + */ public Array(int capacity) { array = (T[]) new Object[capacity]; size = 0; } - public void add(T element) { - if (size == array.length) doubleArrayCapacity(); - array[size++] = element; + /** + * Returns the current capacity of the underlying array. + * + * @return the total number of elements the array can hold. + */ + public int getCapacity() { + return array.length; } private void doubleArrayCapacity() { @@ -33,10 +47,11 @@ private void doubleArrayCapacity() { array = newArray; } - public int getCapacity() { - return array.length; - } - + /** + * Removes all elements from the array. After calling this method, the array will + * be empty, and its size will be reset to zero. The elements in the array will + * be set to null. + */ public void clear() { for (int i = 0; i < size; i++) { array[i] = null; @@ -44,18 +59,99 @@ public void clear() { size = 0; } + /** + * Removes all elements from the array that satisfy the given predicate. + * + * @param filter a predicate used to determine which elements should be removed. + * The predicate is applied to each element, and elements for which + * the predicate returns true are removed. + * @return true if any elements were removed as a result of the operation, + * false otherwise. + */ + public boolean removeIf(Predicate filter) { + Objects.requireNonNull(filter); + boolean removed = false; + + int readPos = 0; + int writePos = 0; + for (int i = 0; i < size; i++) { + if (filter.test(array[i])) { + readPos++; + removed = true; + continue; + } + array[writePos++] = array[readPos++]; + } + size = writePos; + return removed; + } + + /** + * Adds all elements from the specified list to the array. + * + * @param list the list containing elements to be added to this array + * @throws NullPointerException if the specified list is null + */ + public void addAll(List list) { + for (T t : list) { + add(t); + } + } + + /** + * Adds the specified element to the array. If the underlying array's capacity + * is reached, it is automatically doubled before adding the element. + * + * @param element the element to be added to the array + */ + public void add(T element) { + if (size == array.length) doubleArrayCapacity(); + array[size++] = element; + } + + /** + * Returns the current number of elements stored in the array. + * + * @return the number of elements currently present in the array. + */ public int size() { return size; } + /** + * Sorts the elements in the array using the specified comparator. + * The sorting is performed on the internal array from the beginning + * of the array up to the current size of the array. + * + * @param comparator the comparator to determine the order of the array. + * A {@code null} comparator indicates that the elements' + * natural ordering should be used. + */ public void sort(Comparator comparator) { Arrays.sort(array, 0, size, comparator); } + /** + * Retrieves the element at the specified index from the array. + * + * @param index the position of the element to retrieve, zero-based. + * Must be within the range `0` to `size - 1`, where `size` is + * the number of elements currently stored in the array. + * @return the element of type T stored at the specified index. + * @throws ArrayIndexOutOfBoundsException if the index is out of bounds + * (i.e., less than 0 or greater than or equal to the current size + * of the array). + */ public T get(int index) { return array[index]; } + /** + * Returns an iterator over elements of type T in the array. + * The iterator allows sequential access to the elements stored in the array. + * + * @return an Iterator of type T that allows traversal of the array's elements. + */ @Override public Iterator iterator() { return new Iterator() { From 78262c2eeedccb2728a41fdf7a62da28a974c72e Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:03:08 +0000 Subject: [PATCH 15/37] Add tests for removeIf and addAll methods in ArrayTest Added a test for the removeIf method to validate element removal based on a condition. Also introduced a test for the addAll method to ensure proper addition of a collection. Both tests confirm expected behavior and maintain correct array size. --- .../physmo/garnet/structure/ArrayTest.groovy | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy b/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy index 90016a4..e14f629 100644 --- a/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy +++ b/src/test/groovy/com/physmo/garnet/structure/ArrayTest.groovy @@ -77,4 +77,54 @@ class ArrayTest extends Specification { } + def "Test removeIf"() { + given: + Array array = new Array<>(5); + + and: + array.add("A") + array.add("X") + array.add("B") + array.add("X") + array.add("C") + + when: + int startingSize = array.size() + array.removeIf { s -> return (s == "X") } + + then: + array.get(0) == "A" + array.get(1) == "B" + array.get(2) == "C" + startingSize == 5 + array.size() == 3 + } + + def "Test addAll"() { + given: + Array array = new Array<>(5); + List list = new ArrayList<>() + + and: + array.add("A") + array.add("B") + array.add("C") + list.add("D") + list.add("E") + list.add("F") + + when: + int startingSize = array.size() + array.addAll(list) + + then: + array.get(0) == "A" + array.get(1) == "B" + array.get(2) == "C" + array.get(3) == "D" + array.get(4) == "E" + array.get(5) == "F" + startingSize == 3 + array.size() == 6 + } } From 52a03b02f271b835f7ba5155604f2aa2d81cd0a7 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:04:10 +0000 Subject: [PATCH 16/37] Simplify collision handling and optimize memory usage. Replaced temporary lists with reusable `Array` objects to reduce memory allocation overhead. Refactored `removePendingCollidables` for streamlined list processing using `removeIf`. These changes improve performance and code clarity. --- .../simplecollision/CollisionSystem.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java index bd02678..df0aa2c 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java @@ -2,6 +2,7 @@ import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.structure.Array; import com.physmo.garnet.structure.Rect; import com.physmo.garnet.structure.Vector3; import com.physmo.garnet.toolkit.Component; @@ -48,18 +49,13 @@ public void tick(double t) { } + private void removePendingCollidables() { if (collidablesPendingRemoval.isEmpty()) return; - List keepList = new ArrayList<>(); - - for (Collidable collidable : collidables) { - if (collidablesPendingRemoval.contains(collidable)) continue; - keepList.add(collidable); - } + collidables.removeIf(collidable -> collidablesPendingRemoval.contains(collidable)); collidablesPendingRemoval.clear(); - collidables = keepList; } private List calculateCollisions2() { @@ -71,10 +67,11 @@ private List calculateCollisions2() { List listOfActiveCells = bucketGrid.getListOfActiveCells(); + Array surroundingObjects = new Array<>(10); for (Integer[] cellCoords : listOfActiveCells) { List cellObjects = bucketGrid.getCellObjects(cellCoords[0], cellCoords[1]); - List surroundingObjects = bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1); + bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjects); for (Object cellObject : cellObjects) { for (Object surroundingObject : surroundingObjects) { @@ -174,7 +171,8 @@ public List getNearestObjects(String tag, int x, int y, double w int tileRadius = (int) ((withinRadius / bucketGrid.getCellWidth()) + 1); - List surroundingObjects = bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], tileRadius); + Array surroundingObjects = new Array<>(50); + bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], tileRadius, surroundingObjects); List filteredObjects = new ArrayList<>(); for (Object surroundingObject : surroundingObjects) { @@ -228,13 +226,16 @@ public int processCloseObjects(String tag, double distanceThreshold) { coBucketGrid.addObject(collidable, (int) collidable.collisionGetRegion().x, (int) collidable.collisionGetRegion().y); } + int count = 0; List nearObjects = new ArrayList<>(); List listOfActiveCells = coBucketGrid.getListOfActiveCells(); + Array surroundingObjects = new Array<>(50); + for (Integer[] cellCoords : listOfActiveCells) { List cellObjects = coBucketGrid.getCellObjects(cellCoords[0], cellCoords[1]); - List surroundingObjects = coBucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1); + coBucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjects); for (Object cellObject : cellObjects) { From 84e382655c0fa8cacb854a0058205d2996f00876 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:04:23 +0000 Subject: [PATCH 17/37] Update project version and dependencies in pom.xml Bump project version to 0.5.3b-SNAPSHOT and include additional configurations such as UTF-8 encoding and specific plugin versions. Comment out the javadoc attachment execution to refine the build process. --- pom.xml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 10c8b6b..aa06237 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.nickd3000 garnet - 0.5.2 + 0.5.3b-SNAPSHOT jar ${project.groupId}:${project.artifactId} https://github.com/nickd3000/garnet @@ -60,12 +60,14 @@ src/test/java + src/main/resources src/main/resources_examples + @@ -75,7 +77,9 @@ 17 17 + UTF-8 + 3.13.0 @@ -86,12 +90,16 @@ ${java.home}/bin/javadoc - - attach-javadoc - - jar - - + + + + + + + + + + @@ -105,6 +113,7 @@ + 3.3.1 org.apache.maven.plugins From 7a38c83aa10575253e1a7caa626549c867e38a94 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Sun, 12 Jan 2025 01:05:12 +0000 Subject: [PATCH 18/37] Add Javadoc comments and enhance grid handling methods Javadoc comments were added to improve clarity and documentation for key methods. Modified `getSurroundingObjects` to use an output array, improving performance and flexibility. These changes enhance the code's maintainability and usability. --- .../simplecollision/GameObjectBucketGrid.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java index af15b92..1a155e7 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java @@ -1,5 +1,7 @@ package com.physmo.garnet.toolkit.simplecollision; +import com.physmo.garnet.structure.Array; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -37,6 +39,15 @@ public int[] getCellCoordsForPoint(int x, int y) { return new int[]{x / cellWidth, y / cellHeight}; } + /** + * Adds an object to the appropriate cell in the grid based on its coordinates. + * If the cell does not exist, it is created. Limits the number of objects per cell + * to the specified maximum. + * + * @param o the object to be added + * @param x the x-coordinate where the object should be added + * @param y the y-coordinate where the object should be added + */ public void addObject(Object o, int x, int y) { int num = encoder(x / cellWidth, y / cellHeight); @@ -67,6 +78,14 @@ public Integer[] decoder(int v) { return new Integer[]{x - gridSize, y - gridSize}; } + + /** + * Retrieves a list of active cells from the grid. Each cell is represented + * as an array of integers where the first element is the x-coordinate + * and the second element is the y-coordinate of the cell. + * + * @return a list of active cells, where each cell is represented as an Integer array [x, y] + */ public List getListOfActiveCells() { List activeCells = new ArrayList<>(); for (Integer integer : objects.keySet()) { @@ -92,19 +111,28 @@ public List getCellObjects(int cellX, int cellY) { return new ArrayList<>(); } - public List getSurroundingObjects(int cellX, int cellY, int tileRadius) { + + /** + * Retrieves all objects within a specified radius of a given cell coordinate + * and appends them to the provided output array. + * + * @param cellX the x-coordinate of the central cell + * @param cellY the y-coordinate of the central cell + * @param tileRadius the radius (in cells) surrounding the central cell to include + * @param outSurroundingObjects the array to which the surrounding objects will be added + */ + public void getSurroundingObjects(int cellX, int cellY, int tileRadius, Array outSurroundingObjects) { int cx = cellX; int cy = cellY; int index; - List list = new ArrayList<>(); for (int y = cy - tileRadius; y <= cy + tileRadius; y++) { for (int x = cx - tileRadius; x <= cx + tileRadius; x++) { index = encoder(x, y); if (objects.containsKey(index)) { - list.addAll(objects.get(index)); + outSurroundingObjects.addAll(objects.get(index)); } } } - return list; + } } From 2663a8016fd034e1b126474e07ac62a66616bbeb Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:15:51 +0000 Subject: [PATCH 19/37] Refactor collision lists and add collision group support Replaced List with Array for collision tracking to improve performance and memory usage. Introduced a collision group field with getter and setter methods for enhanced collision management. Cleaned and optimized the `tick` method to reuse a shared `keepList` instance. --- .../simplecollision/ColliderComponent.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/ColliderComponent.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/ColliderComponent.java index e6f7599..2223cab 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/ColliderComponent.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/ColliderComponent.java @@ -1,13 +1,11 @@ package com.physmo.garnet.toolkit.simplecollision; import com.physmo.garnet.graphics.Graphics; +import com.physmo.garnet.structure.Array; import com.physmo.garnet.structure.Rect; import com.physmo.garnet.toolkit.Component; import com.physmo.garnet.toolkit.GameObject; -import java.util.ArrayList; -import java.util.List; - /** * A helper component that encapsulates a collidable and offers a place to add callback methods * when certain collision events occur. @@ -16,14 +14,16 @@ public class ColliderComponent extends Component implements Collidable { int ox, oy, width, height; + int collisionGroup = 0; Rect collisionRegion = new Rect(); CollisionCallback callbackEnter = null; CollisionCallback callbackLeave = null; CollisionCallback callbackContinue = null; ProximityCallback callbackProximity = null; - List newCollisions = new ArrayList<>(); - List existingCollisions = new ArrayList<>(); + + Array newCollisions = new Array<>(20); + Array existingCollisions = new Array<>(20); public ColliderComponent() { setCallbackEnter(a -> { @@ -88,9 +88,12 @@ public void setCollisionRegion(int offsetX, int offsetY, int width, int height) this.height = height; } + Array keepList = new Array<>(50); + @Override public void tick(double t) { - List keepList = new ArrayList<>(); + + keepList.clear(); // First handle collisions leaving for (GameObject other : existingCollisions) { @@ -119,6 +122,7 @@ public void tick(double t) { existingCollisions.addAll(keepList); } + @Override public void draw(Graphics g) { @@ -151,6 +155,16 @@ public GameObject collisionGetGameObject() { return parent; } + @Override + public int getCollisionGroup() { + return collisionGroup; + } + + @Override + public void setCollisionGroup(int collisionGroup) { + this.collisionGroup = collisionGroup; + } + // TODO: list all resources public String report() { return ""; From 027228e0a2fd4c5e5b6afb6371291cbdfbf24e14 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:00 +0000 Subject: [PATCH 20/37] Refactor collision lists and add collision group support Replaced List with Array for collision tracking to improve performance and memory usage. Introduced a collision group field with getter and setter methods for enhanced collision management. Cleaned and optimized the `tick` method to reuse a shared `keepList` instance. --- .../garnet/toolkit/simplecollision/Collidable.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/Collidable.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/Collidable.java index bf88f3d..d48d450 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/Collidable.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/Collidable.java @@ -11,4 +11,14 @@ public interface Collidable { void proximityCallback(RelativeObject relativeObject); GameObject collisionGetGameObject(); + + int getCollisionGroup(); + + /** + * Sets the collision group identifier for the object implementing the Collidable interface. + * The collision group is used to categorize objects for collision detection or filtering. + * + * @param collisionGroup an integer representing the collision group for this object + */ + void setCollisionGroup(int collisionGroup); } From 9b878f5bb518eff0a3b9c97ef6d1774cafab0470 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:11 +0000 Subject: [PATCH 21/37] Use consistent parameter types in processCloseObjects. Updated the method call to use an integer tag (0) instead of a string ("testobject") for consistency with the collision system API. This ensures uniform handling and reduces potential type mismatches. --- .../garnetexamples/collision/CollisionExample_CloseObjects.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java b/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java index e1fd792..ca3976e 100644 --- a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java +++ b/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java @@ -93,7 +93,7 @@ public void tick(double delta) { List objectsByTag = context.getObjectsByTag("testobject"); objectsByTag.get(0).getTransform().set(mps[0] - 8, mps[1] - 8, 0); - closeObjectTestCount = collisionSystem.processCloseObjects("testobject", 20); + closeObjectTestCount = collisionSystem.processCloseObjects(0, 20); } @Override From 329f439e37f0a9f527ccc02536ae523027d0286c Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:24 +0000 Subject: [PATCH 22/37] Refactor collision system for efficiency and flexibility. Updated the collision handling to use temporary arrays for optimized processing and introduced collision group filtering for improved granularity. Enhanced the `calculateCollisions2` method and added utility methods like `setCollisionGroupMatrix` and `canGroupsCollide`. Included additional comments and annotations to clarify behavior and improve maintainability. --- .../simplecollision/CollisionSystem.java | 161 +++++++++++------- 1 file changed, 99 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java index df0aa2c..efdde58 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionSystem.java @@ -13,15 +13,19 @@ import java.util.List; public class CollisionSystem extends GameObject { - + // TODO: we could have multiple lists based on collision group List collidables = new ArrayList<>(); List collidablesPendingRemoval = new ArrayList<>(); CollisionDrawingCallback collisionDrawingCallback = null; int testsPerFrame = 0; GameObjectBucketGrid bucketGrid; + Array surroundingObjectsTemp = new Array<>(100); + Array collisions = new Array<>(100); + int[] collisionGroupMatrix = new int[0xff]; public CollisionSystem(String name) { super(name); + setCollisionGroupMatrix(0, 0, true); } public void setCollisionDrawingCallback(CollisionDrawingCallback collisionDrawingCallback) { @@ -33,14 +37,28 @@ public void init() { } + /** + * Configures the collision detection behavior between two specified collision groups. + * This method determines whether objects in the provided groups are allowed to interact + * during collision detection. + * + * @param group1 The first collision group identifier (0-15). + * @param group2 The second collision group identifier (0-15). + * @param canCollide A boolean indicating whether objects in the two groups can collide; + * {@code true} enables collisions, {@code false} disables collisions. + */ + public void setCollisionGroupMatrix(int group1, int group2, boolean canCollide) { + int index = ((group1 & 0b1111) << 4) | group2 & 0b1111; + collisionGroupMatrix[index] = canCollide ?1:0; + } + @Override public void tick(double t) { testsPerFrame = 0; removePendingCollidables(); - -// List collisions = calculateCollisions(); - List collisions = calculateCollisions2(); + collisions.clear(); + calculateCollisions2(collisions); // Notify collider of collision. for (CollisionPacket collision : collisions) { @@ -49,7 +67,26 @@ public void tick(double t) { } - + /** + * Removes all pending collidable objects from the collision system. + *

+ * This method processes the collection of collidables marked for removal + * (`collidablesPendingRemoval`) and eliminates any corresponding objects + * from the main `collidables` list. After all pending removals are processed, + * the temporary storage used for tracking objects to be removed is cleared. + *

+ * The purpose of this method is to ensure the collision system's data structure + * remains synchronized by removing collidables that are no longer active or + * required for collision detection. + *

+ * Implementation Notes: + * - If the `collidablesPendingRemoval` list is empty, the method exits early, + * avoiding unnecessary processing. + * - The `removeIf` method is used to efficiently filter `collidables` based + * on membership in the `collidablesPendingRemoval` list. + * - After processing, `collidablesPendingRemoval` is cleared to prepare for + * the next update cycle. + */ private void removePendingCollidables() { if (collidablesPendingRemoval.isEmpty()) return; @@ -58,27 +95,29 @@ private void removePendingCollidables() { collidablesPendingRemoval.clear(); } - private List calculateCollisions2() { - List collisions = new ArrayList<>(); + private void calculateCollisions2(Array outCollisions) { + bucketGrid = new GameObjectBucketGrid(32, 32); for (Collidable collidable : getListOfActiveCollidables()) { bucketGrid.addObject(collidable, (int) collidable.collisionGetRegion().x, (int) collidable.collisionGetRegion().y); } + int[] listOfActiveCellsEncoded = bucketGrid.getListOfActiveCellsEncoded(); + int[] cellCoords = new int[2]; - List listOfActiveCells = bucketGrid.getListOfActiveCells(); - Array surroundingObjects = new Array<>(10); - for (Integer[] cellCoords : listOfActiveCells) { - + for (int cellCoordsEncoded : listOfActiveCellsEncoded) { + bucketGrid.decoder(cellCoordsEncoded, cellCoords); List cellObjects = bucketGrid.getCellObjects(cellCoords[0], cellCoords[1]); - bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjects); + surroundingObjectsTemp.clear(); + bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjectsTemp); for (Object cellObject : cellObjects) { - for (Object surroundingObject : surroundingObjects) { + for (Object surroundingObject : surroundingObjectsTemp) { if (cellObject == surroundingObject) continue; + if (!canGroupsCollide((Collidable) cellObject, (Collidable) surroundingObject)) continue; boolean collided = testCollision((Collidable) cellObject, (Collidable) surroundingObject); - if (collided) collisions.add( + if (collided) outCollisions.add( new CollisionPacket((Collidable) cellObject, (Collidable) surroundingObject)); } @@ -86,8 +125,11 @@ private List calculateCollisions2() { } + } - return collisions; + private boolean canGroupsCollide(Collidable collidable1, Collidable collidable2) { + int index = ((collidable1.getCollisionGroup() & 0b1111) << 4) | collidable2.getCollisionGroup() & 0b1111; + return collisionGroupMatrix[index] == 1; } @Override @@ -116,6 +158,11 @@ public List getListOfActiveCollidables() { return activeCollidables; } + /** + * Retrieves the number of collision tests performed per frame. + * + * @return The number of collision tests conducted during a single frame. + */ public int getTestsPerFrame() { return testsPerFrame; } @@ -132,57 +179,33 @@ public List getListOfCollidablesWithTag(String tag) { return collidableList; } - /** - * Calculates all collisions between active collidable objects in the system. - * The method retrieves the list of active collidables, identifies pairs of objects - * that are colliding, and stores these interactions as {@code CollisionPacket} instances. - * - * @return A list of {@code CollisionPacket} objects representing detected collisions - * between pairs of collidable objects. - */ - private List calculateCollisions() { - List collisions = new ArrayList<>(); - List activeCollidables = getListOfActiveCollidables(); - - for (Collidable c1 : activeCollidables) { - for (Collidable c2 : activeCollidables) { - if (c1 == c2) continue; - boolean collided = testCollision(c1, c2); - if (collided) collisions.add(new CollisionPacket(c1, c2)); - } - } - - return collisions; - } /** - * Search system for objects that are close to a supplied coordinate. + * Populates a list of objects that are nearest to a given point within a specified radius, + * filtered by collision group. The method identifies all nearby objects that match the collision group + * and calculates their distance, direction, and relative properties before adding them to the output list. * - * @param x - * @param y - * @param withinRadius - * @return + * @param collisionGroup The collision group to filter objects by. Only objects belonging to this group are considered. + * @param x The x-coordinate of the origin point to search from. + * @param y The y-coordinate of the origin point to search from. + * @param withinRadius The radius within which to search for objects. + * @param outNearObjects A list of RelativeObject instances that will be populated with nearby objects and their relative properties. */ - public List getNearestObjects(String tag, int x, int y, double withinRadius) { - int tagId = StringIdBroker.INSTANCE.getId(tag); - int cellWidth = bucketGrid.getCellWidth(); + public void getNearestObjects(int collisionGroup, int x, int y, double withinRadius, Array outNearObjects) { int[] cellCoords = bucketGrid.getCellCoordsForPoint(x, y); int tileRadius = (int) ((withinRadius / bucketGrid.getCellWidth()) + 1); - Array surroundingObjects = new Array<>(50); - bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], tileRadius, surroundingObjects); + surroundingObjectsTemp.clear(); + bucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], tileRadius, surroundingObjectsTemp); List filteredObjects = new ArrayList<>(); - for (Object surroundingObject : surroundingObjects) { - if (((Collidable) surroundingObject).collisionGetGameObject().hasTag(tagId)) + for (Object surroundingObject : surroundingObjectsTemp) { + if (((Collidable) surroundingObject).getCollisionGroup() == collisionGroup) filteredObjects.add(surroundingObject); } - - List nearObjects = new ArrayList<>(); - for (Object surroundingObject : filteredObjects) { Vector3 transform1 = ((Collidable) surroundingObject).collisionGetGameObject().getTransform(); double distance = transform1.distance(x, y); @@ -194,11 +217,10 @@ public List getNearestObjects(String tag, int x, int y, double w relativeObject.dx = (transform1.x - x) / distance; relativeObject.dy = (transform1.y - y) / distance; relativeObject.otherObject = (Collidable) surroundingObject; - nearObjects.add(relativeObject); + outNearObjects.add(relativeObject); } } - return nearObjects; } @@ -209,6 +231,11 @@ public boolean testCollision(Collidable c1, Collidable c2) { return rect1.intersect(rect2); } + /** + * Retrieves the total number of collidable objects currently present in the collision system. + * + * @return The number of collidable objects in the system. + */ public int getSize() { return collidables.size(); } @@ -217,31 +244,32 @@ public int getSize() { * Check for objects that are close to each other and call their * processing functions */ - public int processCloseObjects(String tag, double distanceThreshold) { - int tagId = StringIdBroker.INSTANCE.getId(tag); + public int processCloseObjects(int collisionGroup, double distanceThreshold) { GameObjectBucketGrid coBucketGrid = new GameObjectBucketGrid(32, 32); for (Collidable collidable : getListOfActiveCollidables()) { - if (!collidable.collisionGetGameObject().hasTag(tagId)) continue; + if (collidable.getCollisionGroup() != collisionGroup) continue; coBucketGrid.addObject(collidable, (int) collidable.collisionGetRegion().x, (int) collidable.collisionGetRegion().y); } int count = 0; List nearObjects = new ArrayList<>(); - List listOfActiveCells = coBucketGrid.getListOfActiveCells(); - Array surroundingObjects = new Array<>(50); - for (Integer[] cellCoords : listOfActiveCells) { + int[] listOfActiveCellsEncoded = coBucketGrid.getListOfActiveCellsEncoded(); + int[] cellCoords = new int[2]; + for (int cellCoordsEncoded : listOfActiveCellsEncoded) { + coBucketGrid.decoder(cellCoordsEncoded, cellCoords); List cellObjects = coBucketGrid.getCellObjects(cellCoords[0], cellCoords[1]); - coBucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjects); + surroundingObjectsTemp.clear(); + coBucketGrid.getSurroundingObjects(cellCoords[0], cellCoords[1], 1, surroundingObjectsTemp); for (Object cellObject : cellObjects) { GameObject gameObject1 = ((Collidable) cellObject).collisionGetGameObject(); - for (Object surroundingObject : surroundingObjects) { + for (Object surroundingObject : surroundingObjectsTemp) { GameObject gameObject2 = ((Collidable) surroundingObject).collisionGetGameObject(); if (gameObject1 == gameObject2) continue; count++; @@ -290,6 +318,15 @@ public void removeColliderFromGameObject(GameObject gameObject) { } } + /** + * Marks a specific collidable object for removal from the collision system. + * The collidable object will be added to a pending removal list and will + * be removed from the system during the next update cycle. + * + * @param collidable The collidable object to mark for removal. This parameter + * cannot be null. If a null value is provided, a runtime + * exception will be thrown. + */ public void removeCollidable(Collidable collidable) { if (collidable == null) throw new RuntimeException("collidable is null"); collidablesPendingRemoval.add(collidable); From ef5477fa69dc67f80f618d51a1d2445e85643900 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:35 +0000 Subject: [PATCH 23/37] Refine context methods with updated documentation. Improved the documentation for `draw` and `reset` methods to provide clearer descriptions of their behavior and parameters. Added exception details and clarified use cases to enhance code readability and maintainability. --- src/main/java/com/physmo/garnet/toolkit/Context.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/Context.java b/src/main/java/com/physmo/garnet/toolkit/Context.java index eaab32b..f15fc36 100644 --- a/src/main/java/com/physmo/garnet/toolkit/Context.java +++ b/src/main/java/com/physmo/garnet/toolkit/Context.java @@ -176,7 +176,11 @@ public void tick(double t) { } /** - * Draw every game object in this context. + * Renders all drawable objects in this context using the specified graphics object. + * Throws an exception if the context is not initialized. + * + * @param g The {@code Graphics} object used to draw the game objects. + * @throws RuntimeException If the context is not initialized. */ public void draw(Graphics g) { if (!initialised) throw new RuntimeException("Context: not initialised"); @@ -188,7 +192,11 @@ public void draw(Graphics g) { } /** - * Erase all objects contained within this context. + * Resets the context by clearing all objects currently stored. + * + * This method removes all objects from the internal list, effectively resetting + * the state of the context. Typically used to restart or clean up the context + * before reinitializing or reloading new data. */ public void reset() { objects.clear(); From 014df258942cd412f21eb03e51c7da614d17eff4 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:45 +0000 Subject: [PATCH 24/37] Add JavaDoc comments for input access methods Added documentation for `getMouse` and `getKeyboard` methods to clarify their purpose and return values. These comments improve code readability and assist developers in understanding the API. --- src/main/java/com/physmo/garnet/input/Input.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/physmo/garnet/input/Input.java b/src/main/java/com/physmo/garnet/input/Input.java index ae1c8b4..26e0612 100644 --- a/src/main/java/com/physmo/garnet/input/Input.java +++ b/src/main/java/com/physmo/garnet/input/Input.java @@ -30,10 +30,20 @@ public void tick() { keyboard.update(); } + /** + * Retrieves the Mouse instance used for handling mouse input. + * + * @return the Mouse instance associated with this input manager + */ public Mouse getMouse() { return mouse; } + /** + * Retrieves the Keyboard instance used for handling keyboard input. + * + * @return the Keyboard instance associated with this input manager + */ public Keyboard getKeyboard() { return keyboard; } From b41d5a5531a68c31119a879f5be7fd6c62c20bfb Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:16:55 +0000 Subject: [PATCH 25/37] Add method to calculate tile index from 2D coordinates This method computes the index of a tile in a 1D array representation using its 2D coordinates. It simplifies tile lookups in the tile sheet and improves code readability by centralizing this logic. --- src/main/java/com/physmo/garnet/graphics/TileSheet.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/physmo/garnet/graphics/TileSheet.java b/src/main/java/com/physmo/garnet/graphics/TileSheet.java index 632c6a5..0530508 100644 --- a/src/main/java/com/physmo/garnet/graphics/TileSheet.java +++ b/src/main/java/com/physmo/garnet/graphics/TileSheet.java @@ -51,6 +51,14 @@ public void getSubImage(int column, int row, SubImage outSubImage) { outSubImage.configure(texture, column * tileWidth, row * tileHeight, tileWidth, tileHeight); } + /** + * Calculates the index of a tile in a 1D array representation of the tile map + * based on its 2D coordinates within the tile sheet. + * + * @param x the x-coordinate (column) of the tile. + * @param y the y-coordinate (row) of the tile. + * @return the index of the tile in the 1D array representation. + */ public int getTileIndexFromCoords(int x, int y) { return x + (y * tilesWide); } From 46b048a012ccff331f8c9e7ef7bfd510c1aa5a76 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:17:12 +0000 Subject: [PATCH 26/37] Enhance Array class with utility methods and optimizations. Added utility methods: `isEmpty`, `contains`, `indexOf`, and `setAt`. Optimized `addAll` to improve performance and added overload for the `Array` type. These enhancements improve usability and maintain consistency for array operations. --- .../com/physmo/garnet/structure/Array.java | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/physmo/garnet/structure/Array.java b/src/main/java/com/physmo/garnet/structure/Array.java index 4e60eda..6736b02 100644 --- a/src/main/java/com/physmo/garnet/structure/Array.java +++ b/src/main/java/com/physmo/garnet/structure/Array.java @@ -93,9 +93,11 @@ public boolean removeIf(Predicate filter) { * @throws NullPointerException if the specified list is null */ public void addAll(List list) { - for (T t : list) { - add(t); - } + for (int i = 0; i < list.size(); i++) add(list.get(i)); + } + + public void addAll(Array list) { + for (int i = 0; i < list.size(); i++) add(list.get(i)); } /** @@ -118,6 +120,15 @@ public int size() { return size; } + /** + * Checks if the array is empty. + * + * @return true if the array contains no elements, false otherwise. + */ + public boolean isEmpty() { + return size == 0; + } + /** * Sorts the elements in the array using the specified comparator. * The sorting is performed on the internal array from the beginning @@ -131,6 +142,33 @@ public void sort(Comparator comparator) { Arrays.sort(array, 0, size, comparator); } + /** + * Checks whether the specified element is present in the array. + * + * @param element the element to check for presence in the array. Must be of type T. + * @return true if the element is found in the array, false otherwise. + */ + public boolean contains(T element) { + for (int i = 0; i < size; i++) { + if (array[i].equals(element)) return true; + } + return false; + } + + /** + * Retrieves the index of the specified element in the array. + * + * @param element the element to search for in the array. Must be of type T. + * @return the zero-based index of the element if found; -1 otherwise. + */ + public int indexOf(T element) { + for (int i = 0; i < size; i++) { + if (array[i].equals(element)) return i; + } + return -1; + } + + /** * Retrieves the element at the specified index from the array. * @@ -146,6 +184,25 @@ public T get(int index) { return array[index]; } + /** + * Sets the specified element at the given index in the array. + * + * @param index the zero-based index where the element should be set. + * Must be within the range `0` to `size - 1`. + * @param element the element of type T to set at the specified index. + * @throws ArrayIndexOutOfBoundsException if the index is out of bounds + * (i.e., less than 0 or greater than or equal to the current size + * of the array). + * @throws NullPointerException if the provided element is null. + */ + public void setAt(int index, T element) { + if (index < 0 || index >= size) { + throw new ArrayIndexOutOfBoundsException("Index out of bounds: " + index); + } + Objects.requireNonNull(element, "Element cannot be null"); + array[index] = element; + } + /** * Returns an iterator over elements of type T in the array. * The iterator allows sequential access to the elements stored in the array. From 51c503e24589c73b5d67fab00ef3b05a66b114f4 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:17:24 +0000 Subject: [PATCH 27/37] Add documentation for CollisionPacket class. Introduced a JavaDoc comment describing the purpose and usage of the `CollisionPacket` class. This change improves code readability and helps developers understand its role in managing collision events. --- .../garnet/toolkit/simplecollision/CollisionPacket.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionPacket.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionPacket.java index 76c2e79..c2b332d 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionPacket.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/CollisionPacket.java @@ -1,6 +1,11 @@ package com.physmo.garnet.toolkit.simplecollision; +/** + * Represents a data packet for managing collision events between two Collidable entities. + * This class is used to encapsulate details about the source and target entities involved + * in a collision or related interaction. + */ public class CollisionPacket { public Collidable sourceEntity; From 0b8c9a8f12b52729e3beed3454bdd6e0bc505343 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:17:31 +0000 Subject: [PATCH 28/37] Fix decoder return type in GameObjectBucketGridTest Changed the return type from Integer[] to int[] in the test to match the expected data type. This ensures compatibility and correctness in decoding grid positions during the test. --- .../com/physmo/garnet/toolkit/GameObjectBucketGridTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/physmo/garnet/toolkit/GameObjectBucketGridTest.java b/src/test/java/com/physmo/garnet/toolkit/GameObjectBucketGridTest.java index f57f119..c7f7685 100644 --- a/src/test/java/com/physmo/garnet/toolkit/GameObjectBucketGridTest.java +++ b/src/test/java/com/physmo/garnet/toolkit/GameObjectBucketGridTest.java @@ -18,7 +18,7 @@ public void testRangeOfPoints() { public void testEncodeDecode(int cellX, int cellY) { int encodedValue = gameObjectBucketGrid.encoder(cellX, cellY); - Integer[] decodedPosition = gameObjectBucketGrid.decoder(encodedValue); + int[] decodedPosition = gameObjectBucketGrid.decoder(encodedValue); Assertions.assertEquals(cellX, decodedPosition[0]); Assertions.assertEquals(cellY, decodedPosition[1]); } From 60f64bbb437e754aa66809ecb216872b8647bddd Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:17:41 +0000 Subject: [PATCH 29/37] Refactor GameObjectBucketGrid to use custom BucketGridMap. Replaced HashMap with BucketGridMap for improved structure and performance. Updated decoder methods and adjusted return types to use primitive arrays for efficiency. Added a faster encoded version of active cell retrieval to optimize grid operations. --- .../simplecollision/GameObjectBucketGrid.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java index 1a155e7..2531914 100644 --- a/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/GameObjectBucketGrid.java @@ -3,12 +3,12 @@ import com.physmo.garnet.structure.Array; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class GameObjectBucketGrid { - Map> objects = new HashMap<>(); + //Map> objects = new HashMap<>(); + BucketGridMap objects = new BucketGridMap(); + int cellWidth; int cellHeight; int maxObjectsPerCell = 10; @@ -32,7 +32,7 @@ public int getSize() { } public void clear() { - objects = new HashMap<>(); + objects.clear(); } public int[] getCellCoordsForPoint(int x, int y) { @@ -72,13 +72,13 @@ public int encoder(int x, int y) { return ((x & 0b1111_1111_1111) << 12) + (y & 0b1111_1111_1111); } - public Integer[] decoder(int v) { + public void decoder(int v, int[] coords) { int x = (v >> 12) & 0b1111_1111_1111; int y = (v) & 0b1111_1111_1111; - return new Integer[]{x - gridSize, y - gridSize}; + coords[0] = x - gridSize; + coords[1] = y - gridSize; } - /** * Retrieves a list of active cells from the grid. Each cell is represented * as an array of integers where the first element is the x-coordinate @@ -86,14 +86,24 @@ public Integer[] decoder(int v) { * * @return a list of active cells, where each cell is represented as an Integer array [x, y] */ - public List getListOfActiveCells() { - List activeCells = new ArrayList<>(); + public List getListOfActiveCells() { + List activeCells = new ArrayList<>(); for (Integer integer : objects.keySet()) { activeCells.add(decoder(integer)); } return activeCells; } + public int[] decoder(int v) { + int x = (v >> 12) & 0b1111_1111_1111; + int y = (v) & 0b1111_1111_1111; + return new int[]{x - gridSize, y - gridSize}; + } + + // Faster version + public int[] getListOfActiveCellsEncoded() { + return objects.keySet(); + } /** * Return a list of objects contained in the cell referred to by the supplied coordinate. From 72634a5a4b3ea17aeaf0aaa7ad2502c830364a5b Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:17:53 +0000 Subject: [PATCH 30/37] Refactor collision system handling to use Array. Replaced List with Array for nearestObjects to improve performance and simplify management. Updated method calls to align with the new Array-based implementation. This change optimizes collision handling and ensures better memory handling for large object sets. --- .../physmo/garnetexamples/collision/CollisionExample.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java b/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java index f239eb5..cf0ef64 100644 --- a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java +++ b/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java @@ -5,6 +5,7 @@ import com.physmo.garnet.graphics.Graphics; import com.physmo.garnet.graphics.Texture; import com.physmo.garnet.graphics.TileSheet; +import com.physmo.garnet.structure.Array; import com.physmo.garnet.toolkit.Context; import com.physmo.garnet.toolkit.GameObject; import com.physmo.garnet.toolkit.simplecollision.ColliderComponent; @@ -26,7 +27,7 @@ public class CollisionExample extends GarnetApp { double scale = 1; Random random = new Random(12345); CollisionSystem collisionSystem; - List nearestObjects; + Array nearestObjects = new Array<>(100); public CollisionExample(Garnet garnet, String name) { super(garnet, name); @@ -87,9 +88,10 @@ public void tick(double delta) { List objectsByTag = context.getObjectsByTag("testobject"); objectsByTag.get(0).getTransform().set(mps[0] - 8, mps[1] - 8, 0); - nearestObjects = collisionSystem.getNearestObjects("testobject", mps[0] - 8, mps[1] - 8, 150); + nearestObjects.clear(); + collisionSystem.getNearestObjects(0, mps[0] - 8, mps[1] - 8, 150, nearestObjects); - collisionSystem.processCloseObjects("testobject", 20); + collisionSystem.processCloseObjects(0, 20); } @Override From 431244f6549be8bff5b7a42fd45737735351b81e Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:18:06 +0000 Subject: [PATCH 31/37] Update project version to 0.5.3c-SNAPSHOT Incremented the version from 0.5.3b-SNAPSHOT to 0.5.3c-SNAPSHOT in the pom.xml file. This reflects ongoing development changes and ensures proper version tracking. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aa06237..c6e00a4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.nickd3000 garnet - 0.5.3b-SNAPSHOT + 0.5.3c-SNAPSHOT jar ${project.groupId}:${project.artifactId} https://github.com/nickd3000/garnet From 5f363735b02c0b9a9eb9f151a050915201e865ad Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:29:14 +0000 Subject: [PATCH 32/37] Add BucketGridMap and corresponding test class Introduced BucketGridMap to manage key-value storage with basic functionality such as put, get, and size. Added a Spock-based test to ensure correct behavior with large data insertion. --- .../simplecollision/BucketGridMap.java | 75 +++++++++++++++++++ .../simplecollision/BucketGridMapTest.groovy | 22 ++++++ 2 files changed, 97 insertions(+) create mode 100644 src/main/java/com/physmo/garnet/toolkit/simplecollision/BucketGridMap.java create mode 100644 src/test/groovy/com/physmo/garnet/toolkit/simplecollision/BucketGridMapTest.groovy diff --git a/src/main/java/com/physmo/garnet/toolkit/simplecollision/BucketGridMap.java b/src/main/java/com/physmo/garnet/toolkit/simplecollision/BucketGridMap.java new file mode 100644 index 0000000..55e5908 --- /dev/null +++ b/src/main/java/com/physmo/garnet/toolkit/simplecollision/BucketGridMap.java @@ -0,0 +1,75 @@ +package com.physmo.garnet.toolkit.simplecollision; + +import com.physmo.garnet.structure.Array; + +import java.util.Arrays; +import java.util.List; + + +public class BucketGridMap { + // TODO: this must be rewritten to use basic arrays! + + int[] keys = new int[100]; + Array> objects = new Array<>(100); + + int size = 0; + + + public int[] keySet() { + int[] subset = new int[size]; + for (int i = 0; i < size; i++) { + subset[i] = keys[i]; + } + return subset; + } + + public void clear() { + Arrays.fill(keys, -1); + size = 0; + objects.clear(); + } + + public int size() { + return size; + } + + public boolean containsKey(int key) { + return getKeyIndex(key) != -1; + } + + public int getKeyIndex(int key) { + for (int i = 0; i < size; i++) { + if (keys[i] == key) return i; + } + return -1; + } + + public List get(int key) { + int index = getKeyIndex(key); + if (index == -1) return null; + + return objects.get(index); + } + + public void put(int key, List value) { + int index = getKeyIndex(key); + + if (index != -1) { + // Key exists + objects.setAt(index, value); + } else { + if (keys.length == size) doubleKeySetSize(); + keys[size++] = key; + objects.add(value); + } + + + //if (keys.size > 1000) System.out.println("BucketGridMap is getting big " + keys.size); + } + + public void doubleKeySetSize() { + int[] newKeys = new int[keys.length * 2]; + System.arraycopy(keys, 0, newKeys, 0, keys.length); + keys = newKeys; + } +} diff --git a/src/test/groovy/com/physmo/garnet/toolkit/simplecollision/BucketGridMapTest.groovy b/src/test/groovy/com/physmo/garnet/toolkit/simplecollision/BucketGridMapTest.groovy new file mode 100644 index 0000000..7d782c6 --- /dev/null +++ b/src/test/groovy/com/physmo/garnet/toolkit/simplecollision/BucketGridMapTest.groovy @@ -0,0 +1,22 @@ +package com.physmo.garnet.toolkit.simplecollision + +import spock.lang.Specification + +class BucketGridMapTest extends Specification { + def "cdscs"() { + given: + BucketGridMap bucketGridMap = new BucketGridMap() + + when: + List obj = new ArrayList<>() + + for (int i = 0; i < 5000; i++) { + //println i + bucketGridMap.put(i, obj) + } + + then: + bucketGridMap.size() == 5000 + + } +} From 27568fd16ba2855810cf6066e37149a39bf5c05a Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:29:38 +0000 Subject: [PATCH 33/37] Refactor package structure to use 'com.physmo.reference'. Renamed all classes to align packages under 'com.physmo.reference' instead of 'com.physmo.garnetexamples'. This improves clarity and consistency in the project structure. Additionally, reintroduced and reorganized the DummyClass under the updated package path. --- .../physmo/garnetexamples/toolkit/support/DummyClass.java | 4 ---- .../physmo/{garnetexamples => reference}/HelloWorld.java | 2 +- .../collision/CollisionExample.java | 2 +- .../collision/CollisionExample_CloseObjects.java | 2 +- .../collision/ComponentCollidingSprite.java | 2 +- .../context/BasicContextExample.java | 4 ++-- .../context/support/ContextExampleComponent.java | 2 +- .../graphics/AnimationExample.java | 2 +- .../graphics/FullScreenExample.java | 2 +- .../graphics/MovementExample.java | 2 +- .../graphics/PrimitiveDrawingExample.java | 2 +- .../graphics/RotatedSpriteExample.java | 2 +- .../graphics/SimpleSpriteExample.java | 2 +- .../graphics/SpriteDrawingExample.java | 2 +- .../{garnetexamples => reference}/graphics/StressTest.java | 4 ++-- .../graphics/TileGridExample.java | 2 +- .../graphics/TileSheetExample.java | 2 +- .../graphics/ViewportExample.java | 2 +- .../graphics/WindowScaleExample.java | 2 +- .../graphics/support/FloatingInvaderComponent.java | 2 +- .../input/KeyboardExample.java | 2 +- .../{garnetexamples => reference}/input/MouseExample.java | 2 +- .../misc/CurveMotionExample.java | 2 +- .../sound/SimpleSoundExample.java | 2 +- .../sound/SoundVolumeExample.java | 2 +- .../{garnetexamples => reference}/text/BMFontExample.java | 2 +- .../text/ParagraphExample.java | 2 +- .../text/RegularFontExample.java | 2 +- .../toolkit/ColorSupplierLinearExample.java | 2 +- .../toolkit/ContextExample.java | 6 +++--- .../toolkit/InlineTextureExample.java | 2 +- .../toolkit/ParticleManagerExample.java | 2 +- .../toolkit/StateMachineExample.java | 2 +- .../com/physmo/reference/toolkit/support/DummyClass.java | 4 ++++ .../toolkit/support/DummyGameObject.java | 2 +- .../wiki/GeneralStructure.java | 2 +- 36 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 src/main/java/com/physmo/garnetexamples/toolkit/support/DummyClass.java rename src/main/java/com/physmo/{garnetexamples => reference}/HelloWorld.java (96%) rename src/main/java/com/physmo/{garnetexamples => reference}/collision/CollisionExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/collision/CollisionExample_CloseObjects.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/collision/ComponentCollidingSprite.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/context/BasicContextExample.java (90%) rename src/main/java/com/physmo/{garnetexamples => reference}/context/support/ContextExampleComponent.java (89%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/AnimationExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/FullScreenExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/MovementExample.java (96%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/PrimitiveDrawingExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/RotatedSpriteExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/SimpleSpriteExample.java (96%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/SpriteDrawingExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/StressTest.java (95%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/TileGridExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/TileSheetExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/ViewportExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/WindowScaleExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/graphics/support/FloatingInvaderComponent.java (96%) rename src/main/java/com/physmo/{garnetexamples => reference}/input/KeyboardExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/input/MouseExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/misc/CurveMotionExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/sound/SimpleSoundExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/sound/SoundVolumeExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/text/BMFontExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/text/ParagraphExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/text/RegularFontExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/ColorSupplierLinearExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/ContextExample.java (77%) rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/InlineTextureExample.java (97%) rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/ParticleManagerExample.java (98%) rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/StateMachineExample.java (94%) create mode 100644 src/main/java/com/physmo/reference/toolkit/support/DummyClass.java rename src/main/java/com/physmo/{garnetexamples => reference}/toolkit/support/DummyGameObject.java (91%) rename src/main/java/com/physmo/{garnetexamples => reference}/wiki/GeneralStructure.java (95%) diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/support/DummyClass.java b/src/main/java/com/physmo/garnetexamples/toolkit/support/DummyClass.java deleted file mode 100644 index 65bdbc6..0000000 --- a/src/main/java/com/physmo/garnetexamples/toolkit/support/DummyClass.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.physmo.garnetexamples.toolkit.support; - -public class DummyClass { -} diff --git a/src/main/java/com/physmo/garnetexamples/HelloWorld.java b/src/main/java/com/physmo/reference/HelloWorld.java similarity index 96% rename from src/main/java/com/physmo/garnetexamples/HelloWorld.java rename to src/main/java/com/physmo/reference/HelloWorld.java index ebaa2a4..642c0c3 100644 --- a/src/main/java/com/physmo/garnetexamples/HelloWorld.java +++ b/src/main/java/com/physmo/reference/HelloWorld.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples; +package com.physmo.reference; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java b/src/main/java/com/physmo/reference/collision/CollisionExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java rename to src/main/java/com/physmo/reference/collision/CollisionExample.java index cf0ef64..804886a 100644 --- a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample.java +++ b/src/main/java/com/physmo/reference/collision/CollisionExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.collision; +package com.physmo.reference.collision; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java b/src/main/java/com/physmo/reference/collision/CollisionExample_CloseObjects.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java rename to src/main/java/com/physmo/reference/collision/CollisionExample_CloseObjects.java index ca3976e..0347d47 100644 --- a/src/main/java/com/physmo/garnetexamples/collision/CollisionExample_CloseObjects.java +++ b/src/main/java/com/physmo/reference/collision/CollisionExample_CloseObjects.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.collision; +package com.physmo.reference.collision; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/collision/ComponentCollidingSprite.java b/src/main/java/com/physmo/reference/collision/ComponentCollidingSprite.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/collision/ComponentCollidingSprite.java rename to src/main/java/com/physmo/reference/collision/ComponentCollidingSprite.java index 7452bd5..a2a0837 100644 --- a/src/main/java/com/physmo/garnetexamples/collision/ComponentCollidingSprite.java +++ b/src/main/java/com/physmo/reference/collision/ComponentCollidingSprite.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.collision; +package com.physmo.reference.collision; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.graphics.Graphics; diff --git a/src/main/java/com/physmo/garnetexamples/context/BasicContextExample.java b/src/main/java/com/physmo/reference/context/BasicContextExample.java similarity index 90% rename from src/main/java/com/physmo/garnetexamples/context/BasicContextExample.java rename to src/main/java/com/physmo/reference/context/BasicContextExample.java index b3463cd..089f351 100644 --- a/src/main/java/com/physmo/garnetexamples/context/BasicContextExample.java +++ b/src/main/java/com/physmo/reference/context/BasicContextExample.java @@ -1,8 +1,8 @@ -package com.physmo.garnetexamples.context; +package com.physmo.reference.context; import com.physmo.garnet.toolkit.Context; import com.physmo.garnet.toolkit.GameObject; -import com.physmo.garnetexamples.context.support.ContextExampleComponent; +import com.physmo.reference.context.support.ContextExampleComponent; public class BasicContextExample { public static void main(String[] args) { diff --git a/src/main/java/com/physmo/garnetexamples/context/support/ContextExampleComponent.java b/src/main/java/com/physmo/reference/context/support/ContextExampleComponent.java similarity index 89% rename from src/main/java/com/physmo/garnetexamples/context/support/ContextExampleComponent.java rename to src/main/java/com/physmo/reference/context/support/ContextExampleComponent.java index 57375b1..ab54831 100644 --- a/src/main/java/com/physmo/garnetexamples/context/support/ContextExampleComponent.java +++ b/src/main/java/com/physmo/reference/context/support/ContextExampleComponent.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.context.support; +package com.physmo.reference.context.support; import com.physmo.garnet.graphics.Graphics; import com.physmo.garnet.toolkit.Component; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java b/src/main/java/com/physmo/reference/graphics/AnimationExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java rename to src/main/java/com/physmo/reference/graphics/AnimationExample.java index e9a2970..2459bf8 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/AnimationExample.java +++ b/src/main/java/com/physmo/reference/graphics/AnimationExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/FullScreenExample.java b/src/main/java/com/physmo/reference/graphics/FullScreenExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/graphics/FullScreenExample.java rename to src/main/java/com/physmo/reference/graphics/FullScreenExample.java index f7092e2..8b9bb5a 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/FullScreenExample.java +++ b/src/main/java/com/physmo/reference/graphics/FullScreenExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/MovementExample.java b/src/main/java/com/physmo/reference/graphics/MovementExample.java similarity index 96% rename from src/main/java/com/physmo/garnetexamples/graphics/MovementExample.java rename to src/main/java/com/physmo/reference/graphics/MovementExample.java index 4c0dac6..0cc93f2 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/MovementExample.java +++ b/src/main/java/com/physmo/reference/graphics/MovementExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/PrimitiveDrawingExample.java b/src/main/java/com/physmo/reference/graphics/PrimitiveDrawingExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/graphics/PrimitiveDrawingExample.java rename to src/main/java/com/physmo/reference/graphics/PrimitiveDrawingExample.java index 5faf8db..c3415ae 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/PrimitiveDrawingExample.java +++ b/src/main/java/com/physmo/reference/graphics/PrimitiveDrawingExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/RotatedSpriteExample.java b/src/main/java/com/physmo/reference/graphics/RotatedSpriteExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/graphics/RotatedSpriteExample.java rename to src/main/java/com/physmo/reference/graphics/RotatedSpriteExample.java index 53e20c6..da5d240 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/RotatedSpriteExample.java +++ b/src/main/java/com/physmo/reference/graphics/RotatedSpriteExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/SimpleSpriteExample.java b/src/main/java/com/physmo/reference/graphics/SimpleSpriteExample.java similarity index 96% rename from src/main/java/com/physmo/garnetexamples/graphics/SimpleSpriteExample.java rename to src/main/java/com/physmo/reference/graphics/SimpleSpriteExample.java index c7a62c2..321f6d1 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/SimpleSpriteExample.java +++ b/src/main/java/com/physmo/reference/graphics/SimpleSpriteExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/SpriteDrawingExample.java b/src/main/java/com/physmo/reference/graphics/SpriteDrawingExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/graphics/SpriteDrawingExample.java rename to src/main/java/com/physmo/reference/graphics/SpriteDrawingExample.java index dd1636a..a0b0267 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/SpriteDrawingExample.java +++ b/src/main/java/com/physmo/reference/graphics/SpriteDrawingExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/StressTest.java b/src/main/java/com/physmo/reference/graphics/StressTest.java similarity index 95% rename from src/main/java/com/physmo/garnetexamples/graphics/StressTest.java rename to src/main/java/com/physmo/reference/graphics/StressTest.java index d79f9cf..52141eb 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/StressTest.java +++ b/src/main/java/com/physmo/reference/graphics/StressTest.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; @@ -8,7 +8,7 @@ import com.physmo.garnet.graphics.TileSheet; import com.physmo.garnet.toolkit.Context; import com.physmo.garnet.toolkit.GameObject; -import com.physmo.garnetexamples.graphics.support.FloatingInvaderComponent; +import com.physmo.reference.graphics.support.FloatingInvaderComponent; // NOTE: On MacOS the following VM argument is required: -XstartOnFirstThread public class StressTest extends GarnetApp { diff --git a/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java b/src/main/java/com/physmo/reference/graphics/TileGridExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java rename to src/main/java/com/physmo/reference/graphics/TileGridExample.java index b90f5ad..35d1039 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/TileGridExample.java +++ b/src/main/java/com/physmo/reference/graphics/TileGridExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java b/src/main/java/com/physmo/reference/graphics/TileSheetExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java rename to src/main/java/com/physmo/reference/graphics/TileSheetExample.java index 5916843..a01039a 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/TileSheetExample.java +++ b/src/main/java/com/physmo/reference/graphics/TileSheetExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java b/src/main/java/com/physmo/reference/graphics/ViewportExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java rename to src/main/java/com/physmo/reference/graphics/ViewportExample.java index f904330..96f27e7 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/ViewportExample.java +++ b/src/main/java/com/physmo/reference/graphics/ViewportExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/WindowScaleExample.java b/src/main/java/com/physmo/reference/graphics/WindowScaleExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/graphics/WindowScaleExample.java rename to src/main/java/com/physmo/reference/graphics/WindowScaleExample.java index 7636fc8..e1f803d 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/WindowScaleExample.java +++ b/src/main/java/com/physmo/reference/graphics/WindowScaleExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics; +package com.physmo.reference.graphics; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/graphics/support/FloatingInvaderComponent.java b/src/main/java/com/physmo/reference/graphics/support/FloatingInvaderComponent.java similarity index 96% rename from src/main/java/com/physmo/garnetexamples/graphics/support/FloatingInvaderComponent.java rename to src/main/java/com/physmo/reference/graphics/support/FloatingInvaderComponent.java index 072b971..c46122a 100644 --- a/src/main/java/com/physmo/garnetexamples/graphics/support/FloatingInvaderComponent.java +++ b/src/main/java/com/physmo/reference/graphics/support/FloatingInvaderComponent.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.graphics.support; +package com.physmo.reference.graphics.support; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.graphics.Graphics; diff --git a/src/main/java/com/physmo/garnetexamples/input/KeyboardExample.java b/src/main/java/com/physmo/reference/input/KeyboardExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/input/KeyboardExample.java rename to src/main/java/com/physmo/reference/input/KeyboardExample.java index 69f08a0..74ab8b7 100644 --- a/src/main/java/com/physmo/garnetexamples/input/KeyboardExample.java +++ b/src/main/java/com/physmo/reference/input/KeyboardExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.input; +package com.physmo.reference.input; import com.physmo.garnet.FileUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/input/MouseExample.java b/src/main/java/com/physmo/reference/input/MouseExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/input/MouseExample.java rename to src/main/java/com/physmo/reference/input/MouseExample.java index c603467..4794eed 100644 --- a/src/main/java/com/physmo/garnetexamples/input/MouseExample.java +++ b/src/main/java/com/physmo/reference/input/MouseExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.input; +package com.physmo.reference.input; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.FileUtils; diff --git a/src/main/java/com/physmo/garnetexamples/misc/CurveMotionExample.java b/src/main/java/com/physmo/reference/misc/CurveMotionExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/misc/CurveMotionExample.java rename to src/main/java/com/physmo/reference/misc/CurveMotionExample.java index c9c8b6f..892a293 100644 --- a/src/main/java/com/physmo/garnetexamples/misc/CurveMotionExample.java +++ b/src/main/java/com/physmo/reference/misc/CurveMotionExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.misc; +package com.physmo.reference.misc; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.FileUtils; diff --git a/src/main/java/com/physmo/garnetexamples/sound/SimpleSoundExample.java b/src/main/java/com/physmo/reference/sound/SimpleSoundExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/sound/SimpleSoundExample.java rename to src/main/java/com/physmo/reference/sound/SimpleSoundExample.java index a7090a6..60073c5 100644 --- a/src/main/java/com/physmo/garnetexamples/sound/SimpleSoundExample.java +++ b/src/main/java/com/physmo/reference/sound/SimpleSoundExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.sound; +package com.physmo.reference.sound; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.FileUtils; diff --git a/src/main/java/com/physmo/garnetexamples/sound/SoundVolumeExample.java b/src/main/java/com/physmo/reference/sound/SoundVolumeExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/sound/SoundVolumeExample.java rename to src/main/java/com/physmo/reference/sound/SoundVolumeExample.java index 4ff9ddb..ce8a0e6 100644 --- a/src/main/java/com/physmo/garnetexamples/sound/SoundVolumeExample.java +++ b/src/main/java/com/physmo/reference/sound/SoundVolumeExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.sound; +package com.physmo.reference.sound; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.FileUtils; diff --git a/src/main/java/com/physmo/garnetexamples/text/BMFontExample.java b/src/main/java/com/physmo/reference/text/BMFontExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/text/BMFontExample.java rename to src/main/java/com/physmo/reference/text/BMFontExample.java index 895a43c..697f7b3 100644 --- a/src/main/java/com/physmo/garnetexamples/text/BMFontExample.java +++ b/src/main/java/com/physmo/reference/text/BMFontExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.text; +package com.physmo.reference.text; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/text/ParagraphExample.java b/src/main/java/com/physmo/reference/text/ParagraphExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/text/ParagraphExample.java rename to src/main/java/com/physmo/reference/text/ParagraphExample.java index cee6789..0d51b27 100644 --- a/src/main/java/com/physmo/garnetexamples/text/ParagraphExample.java +++ b/src/main/java/com/physmo/reference/text/ParagraphExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.text; +package com.physmo.reference.text; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/text/RegularFontExample.java b/src/main/java/com/physmo/reference/text/RegularFontExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/text/RegularFontExample.java rename to src/main/java/com/physmo/reference/text/RegularFontExample.java index 1f29390..0bddd45 100644 --- a/src/main/java/com/physmo/garnetexamples/text/RegularFontExample.java +++ b/src/main/java/com/physmo/reference/text/RegularFontExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.text; +package com.physmo.reference.text; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/ColorSupplierLinearExample.java b/src/main/java/com/physmo/reference/toolkit/ColorSupplierLinearExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/toolkit/ColorSupplierLinearExample.java rename to src/main/java/com/physmo/reference/toolkit/ColorSupplierLinearExample.java index d9893a6..56ad1b3 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/ColorSupplierLinearExample.java +++ b/src/main/java/com/physmo/reference/toolkit/ColorSupplierLinearExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.toolkit; +package com.physmo.reference.toolkit; import com.physmo.garnet.ColorUtils; import com.physmo.garnet.Garnet; diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/ContextExample.java b/src/main/java/com/physmo/reference/toolkit/ContextExample.java similarity index 77% rename from src/main/java/com/physmo/garnetexamples/toolkit/ContextExample.java rename to src/main/java/com/physmo/reference/toolkit/ContextExample.java index 7ec6021..528563a 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/ContextExample.java +++ b/src/main/java/com/physmo/reference/toolkit/ContextExample.java @@ -1,8 +1,8 @@ -package com.physmo.garnetexamples.toolkit; +package com.physmo.reference.toolkit; import com.physmo.garnet.toolkit.Context; -import com.physmo.garnetexamples.toolkit.support.DummyClass; -import com.physmo.garnetexamples.toolkit.support.DummyGameObject; +import com.physmo.reference.toolkit.support.DummyClass; +import com.physmo.reference.toolkit.support.DummyGameObject; public class ContextExample { diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/InlineTextureExample.java b/src/main/java/com/physmo/reference/toolkit/InlineTextureExample.java similarity index 97% rename from src/main/java/com/physmo/garnetexamples/toolkit/InlineTextureExample.java rename to src/main/java/com/physmo/reference/toolkit/InlineTextureExample.java index d889bdf..1fa67d5 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/InlineTextureExample.java +++ b/src/main/java/com/physmo/reference/toolkit/InlineTextureExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.toolkit; +package com.physmo.reference.toolkit; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java b/src/main/java/com/physmo/reference/toolkit/ParticleManagerExample.java similarity index 98% rename from src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java rename to src/main/java/com/physmo/reference/toolkit/ParticleManagerExample.java index 420be6a..f54927f 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/ParticleManagerExample.java +++ b/src/main/java/com/physmo/reference/toolkit/ParticleManagerExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.toolkit; +package com.physmo.reference.toolkit; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/StateMachineExample.java b/src/main/java/com/physmo/reference/toolkit/StateMachineExample.java similarity index 94% rename from src/main/java/com/physmo/garnetexamples/toolkit/StateMachineExample.java rename to src/main/java/com/physmo/reference/toolkit/StateMachineExample.java index 47e44d7..64e5019 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/StateMachineExample.java +++ b/src/main/java/com/physmo/reference/toolkit/StateMachineExample.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.toolkit; +package com.physmo.reference.toolkit; import com.physmo.garnet.toolkit.stateMachine.StateMachine; diff --git a/src/main/java/com/physmo/reference/toolkit/support/DummyClass.java b/src/main/java/com/physmo/reference/toolkit/support/DummyClass.java new file mode 100644 index 0000000..c0fa400 --- /dev/null +++ b/src/main/java/com/physmo/reference/toolkit/support/DummyClass.java @@ -0,0 +1,4 @@ +package com.physmo.reference.toolkit.support; + +public class DummyClass { +} diff --git a/src/main/java/com/physmo/garnetexamples/toolkit/support/DummyGameObject.java b/src/main/java/com/physmo/reference/toolkit/support/DummyGameObject.java similarity index 91% rename from src/main/java/com/physmo/garnetexamples/toolkit/support/DummyGameObject.java rename to src/main/java/com/physmo/reference/toolkit/support/DummyGameObject.java index a736c10..be1506e 100644 --- a/src/main/java/com/physmo/garnetexamples/toolkit/support/DummyGameObject.java +++ b/src/main/java/com/physmo/reference/toolkit/support/DummyGameObject.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.toolkit.support; +package com.physmo.reference.toolkit.support; import com.physmo.garnet.graphics.Graphics; import com.physmo.garnet.toolkit.GameObject; diff --git a/src/main/java/com/physmo/garnetexamples/wiki/GeneralStructure.java b/src/main/java/com/physmo/reference/wiki/GeneralStructure.java similarity index 95% rename from src/main/java/com/physmo/garnetexamples/wiki/GeneralStructure.java rename to src/main/java/com/physmo/reference/wiki/GeneralStructure.java index 0ac5ed0..3314317 100644 --- a/src/main/java/com/physmo/garnetexamples/wiki/GeneralStructure.java +++ b/src/main/java/com/physmo/reference/wiki/GeneralStructure.java @@ -1,4 +1,4 @@ -package com.physmo.garnetexamples.wiki; +package com.physmo.reference.wiki; import com.physmo.garnet.Garnet; import com.physmo.garnet.GarnetApp; From c3f0f3a17f2f76850f4c4b9bd3ca12f99e769c35 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:44:29 +0000 Subject: [PATCH 34/37] Update project version to 0.5.3 Remove the SNAPSHOT designation to mark the version as a stable release. This change is necessary for the finalization of this release cycle. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6e00a4..81874eb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.nickd3000 garnet - 0.5.3c-SNAPSHOT + 0.5.3 jar ${project.groupId}:${project.artifactId} https://github.com/nickd3000/garnet From f01b3f7ce183e45cf566e7f157fbdd78f4b83695 Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:44:38 +0000 Subject: [PATCH 35/37] Update Garnet dependency version to 0.5.3 This updates the README to reflect the latest version of the Garnet library. Ensures users install the correct and most recent version, 0.5.3, for compatibility and new features. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cffd412..4b2bcb4 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ Feedback is really useful at this stage, so please feel free to create a small p io.github.nickd3000 garnet - 0.5.2 + 0.5.3 ``` From dceb85e1e65973bf072515d9f1dc726ea667295d Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 14:54:04 +0000 Subject: [PATCH 36/37] Update LWJGL version and re-enable Javadoc configuration Upgraded LWJGL to 3.3.1 and adjusted natives for macOS ARM64 compatibility. Additionally, restored the Javadoc plugin execution to generate Javadoc artifacts correctly. These changes ensure better platform support and proper documentation generation. --- pom.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 81874eb..a42d2a2 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ LWJGL Based game engine - 3.3.0 - natives-macos + 3.3.1 + natives-macos-arm64 17 17 @@ -90,16 +90,16 @@ ${java.home}/bin/javadoc - - - - - - - - - - + + attach-javadoc + + jar + + + 17 + UTF-8 + + From 1918d5d511c71d40d4f8df3cc62c6c9750e81f7d Mon Sep 17 00:00:00 2001 From: Nick Donnelly Date: Tue, 14 Jan 2025 15:01:34 +0000 Subject: [PATCH 37/37] Downgrade Maven Javadoc plugin and add ignore option Revert the plugin version to 3.1.0 due to compatibility issues. Added an option to suppress doclint errors, preventing build failures. This ensures smoother builds until further updates. --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a42d2a2..9a961fd 100644 --- a/pom.xml +++ b/pom.xml @@ -85,9 +85,10 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.1.0 ${java.home}/bin/javadoc + -Xdoclint:none