diff --git a/src/main/java/com/krytpicalknight/processingMe/EntityManager.java b/src/main/java/com/krytpicalknight/processingMe/EntityManager.java index 12ea2f3..94553a1 100644 --- a/src/main/java/com/krytpicalknight/processingMe/EntityManager.java +++ b/src/main/java/com/krytpicalknight/processingMe/EntityManager.java @@ -6,6 +6,7 @@ import com.krytpicalknight.processingMe.render.ResourceRequirements; import processing.core.PApplet; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -19,33 +20,53 @@ public class EntityManager { /** - * + * Stores the all entities active in the application, including any rendered or unrendered. */ private List entityList; /** - * + * Used to lookup the Entity ID's to the relvant ones store within the entityList. + */ + private HashMap nameLookup; + + /** + * Reference to the renderManager, to setup rendered entities. */ private RenderManager renderManager; + /** + * Reference to the ResourceManager, allowing any resources required by a entity to be stored here. + */ private ResourceManager resourceM; -// private PApplet parent; - + /** + * To initialise all variables and references. + * @param renderM Reference to the RenderManager + * @param resourceManager Reference to the ResourceManager + */ public EntityManager(RenderManager renderM, ResourceManager resourceManager) { this.renderManager = renderM; -// this.parent = P; this.resourceM = resourceManager; entityList = new LinkedList<>(); } + /** + * Register and store entities to be used later in the application. + * + * @param intendedRegistry A Class containing entities that need to be stored here. + */ public void Registry(EntityRegistry intendedRegistry) { intendedRegistry.RegisterEntities(this); } + /** + * Gather and store all resources required by the application. + * + * @implNote To be called after all entities are stored. + */ public void registerResource() { for (Entity entSelect: entityList ) @@ -54,28 +75,72 @@ public void registerResource() } } - public void giveParentInstance(PApplet PA) + /** + * Gives a link to the main processing application to all entities, allowing for them to interact. + * + * @param parentInstance Link to main Processing instance + */ + public void giveParentInstance(PApplet parentInstance) { for (Entity entitySelected:entityList) { - entitySelected.setParentProcessing(PA); + entitySelected.setParentProcessing(parentInstance); } } + /** + * + */ + public void registerIDs() + { + nameLookup = new HashMap<>(); + + for (int index = 0; index < entityList.size();index++) + { +// String temp = String.format("%d:%s", index, entityList.get(index).getID()); + nameLookup.put(String.format("%d:%s", index, entityList.get(index).getID()), index); + } + } + + /** + * Add entity to registry & setup with renderManager + * By default, will also setup the entity to update every frame. + * Warning, frame-rate may vary + * @param entToAdd Entity to add to list + */ public void addToRegistry(Entity entToAdd) { entityList.add(entToAdd); renderManager.addToRender(entToAdd,true); } + /** + * Add entity to registry & setup with renderManager + * + * Warning, frame-rate may vary + * @param entToAdd Entity to add to list + * @param willUpdate Whether the entity will be updated every frame. + */ public void addToRegistry(Entity entToAdd, boolean willUpdate) { entityList.add(entToAdd); renderManager.addToRender(entToAdd, willUpdate); } + /** + * Retrieve a stored entity. Using a numerical index. + * + * @param index Index of entity to retrieve. + * @return The Entity at the given index. + */ public Entity getEntity(int index) { return this.entityList.get(index); } + + /** + * + * @deprecated + * @return Entire List of entites currently being stored + */ public List getEntityList() { return this.entityList; diff --git a/src/main/java/com/krytpicalknight/processingMe/EntityRegistry.java b/src/main/java/com/krytpicalknight/processingMe/EntityRegistry.java index 0b1b6ac..cdc5614 100644 --- a/src/main/java/com/krytpicalknight/processingMe/EntityRegistry.java +++ b/src/main/java/com/krytpicalknight/processingMe/EntityRegistry.java @@ -1,7 +1,5 @@ package com.krytpicalknight.processingMe; -import processing.core.PApplet; - /** * When a game/application wants to register their Entities, implementing this will then allow the * Entity Manager to use the class. @@ -10,6 +8,4 @@ public interface EntityRegistry { void RegisterEntities(EntityManager manager); - - } diff --git a/src/main/java/com/krytpicalknight/processingMe/MainApp.java b/src/main/java/com/krytpicalknight/processingMe/MainApp.java index b1aef94..25e8c3d 100644 --- a/src/main/java/com/krytpicalknight/processingMe/MainApp.java +++ b/src/main/java/com/krytpicalknight/processingMe/MainApp.java @@ -1,21 +1,16 @@ package com.krytpicalknight.processingMe; -import processing.core.PApplet; import com.krytpicalknight.processingMe.render.RenderManager; import com.krytpicalknight.processingMe.render.ResourceManager; -import com.krypticalKnight.testApp.entities.TestEntity; +import processing.core.PApplet; public class MainApp extends PApplet{ private static String version = "0.0.4"; -// private com.krytpicalknight.processingMe.ConfigManager configM = new com.krytpicalknight.processingMe.ConfigManager(); - - protected static RenderManager renderM; + private static RenderManager renderM; protected static EntityManager entityM; - protected static ResourceManager resourceM; - private PApplet instance; - + private static ResourceManager resourceM; public static void main(String[] args) { diff --git a/src/main/java/com/krytpicalknight/processingMe/render/Entity.java b/src/main/java/com/krytpicalknight/processingMe/render/Entity.java index 362b099..f6e8f28 100644 --- a/src/main/java/com/krytpicalknight/processingMe/render/Entity.java +++ b/src/main/java/com/krytpicalknight/processingMe/render/Entity.java @@ -12,7 +12,14 @@ */ public class Entity { - protected static String ID = "Entity"; + /** + * Set's an ID for the entity, allow for quick lookup. + */ + private final String ID = "Entity"; + + public String getID() { + return this.ID; + } /** * States whether the entity is being rendered or just existing in memory. @@ -29,15 +36,6 @@ public class Entity { */ protected PApplet parent; - /** - * BY default only sets up the parent processing instance - * @param P main processing instance - */ - public Entity(PApplet P) - { - this.parent = P; - } - /** * Will be used when the parent Processing instance is set later on. */ @@ -46,6 +44,12 @@ public Entity() } + /** + * Will allow entity to draw to the main processing window. + * + * Not needed if the entity does not interact with Processing + * @param p Sets the pointer to the main Processing instance, used to interact with the draw window. + */ public void setParentProcessing(PApplet p) { this.parent = p; @@ -89,4 +93,5 @@ public void update() { if(!canUpdate()) return; } + } diff --git a/src/main/java/com/krytpicalknight/processingMe/render/ResourceManager.java b/src/main/java/com/krytpicalknight/processingMe/render/ResourceManager.java index ce90088..f6a8e77 100644 --- a/src/main/java/com/krytpicalknight/processingMe/render/ResourceManager.java +++ b/src/main/java/com/krytpicalknight/processingMe/render/ResourceManager.java @@ -1,7 +1,5 @@ package com.krytpicalknight.processingMe.render; -import com.krytpicalknight.processingMe.MainApp; -import processing.core.PApplet; import processing.core.PImage; import processing.core.PShape;