diff --git a/core/assets/prefabs/renderingEntity.prefab b/core/assets/prefabs/renderingEntity.prefab new file mode 100644 index 0000000..30999f3 --- /dev/null +++ b/core/assets/prefabs/renderingEntity.prefab @@ -0,0 +1,7 @@ +{ + "BackgroundColorComponent": { + "red": 145, + "green": 186, + "blue": 220 + } +} \ No newline at end of file diff --git a/core/src/main/java/jgd/platformer/Platformer.java b/core/src/main/java/jgd/platformer/Platformer.java index 5e752f3..208ca8f 100644 --- a/core/src/main/java/jgd/platformer/Platformer.java +++ b/core/src/main/java/jgd/platformer/Platformer.java @@ -39,7 +39,6 @@ public void create() { activeProfiles.add("fivePhaseRenderer"); activeProfiles.add("simpleEntityManager"); activeProfiles.add("nameConventionComponents"); - activeProfiles.add("backgroundRenderer"); activeProfiles.add("textureAtlas"); activeProfiles.add("shapeProvider"); activeProfiles.add("prefabManager"); @@ -89,6 +88,7 @@ public void render() { @Override public void resize(int width, int height) { + context.getSystem(RenderingEngine.class).screenResized(width, height); } @Override diff --git a/core/src/main/java/jgd/platformer/rendering/CharacterRenderer.java b/core/src/main/java/jgd/platformer/rendering/CharacterRenderer.java index 5c1c431..07324c7 100644 --- a/core/src/main/java/jgd/platformer/rendering/CharacterRenderer.java +++ b/core/src/main/java/jgd/platformer/rendering/CharacterRenderer.java @@ -1,7 +1,5 @@ package jgd.platformer.rendering; -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g3d.Material; import com.badlogic.gdx.graphics.g3d.Model; @@ -15,8 +13,7 @@ import com.gempukku.gaming.asset.texture.TextureAtlasProvider; import com.gempukku.gaming.asset.texture.TextureAtlasRegistry; import com.gempukku.gaming.rendering.environment.ArrayVertexOutput; -import com.gempukku.gaming.rendering.environment.EnvironmentRenderer; -import com.gempukku.gaming.rendering.environment.EnvironmentRendererRegistry; +import com.gempukku.gaming.rendering.event.RenderEnvironment; import com.gempukku.gaming.rendering.shape.ShapeDef; import com.gempukku.gaming.rendering.shape.ShapeOutput; import com.gempukku.gaming.rendering.shape.ShapeProvider; @@ -41,11 +38,9 @@ import java.util.Set; @RegisterSystem -public class CharacterRenderer implements EnvironmentRenderer, LifeCycleSystem { +public class CharacterRenderer implements LifeCycleSystem { private static final String CHARACTERS_ATLAS_ID = "characters"; @Inject - private EnvironmentRendererRegistry environmentRendererRegistry; - @Inject private ShapeProvider shapeProvider; @Inject private TextureAtlasRegistry textureAtlasRegistry; @@ -66,7 +61,6 @@ public class CharacterRenderer implements EnvironmentRenderer, LifeCycleSystem { @Override public void initialize() { - environmentRendererRegistry.registerEnvironmentRenderer(this); charactersIndex = entityIndexManager.addIndexOnComponents(CharacterRenderComponent.class, LocationComponent.class); Set textureNames = new HashSet<>(); @@ -112,19 +106,7 @@ public TextureRegion getTextureRegion(String textureId) { } @ReceiveEvent - public void characterRemoved(BeforeComponentRemoved event, EntityRef entity, CharacterRenderComponent characterRender, LocationComponent location) { - String characterId = characterRender.getId(); - modelInstances.remove(characterId); - models.remove(characterId).dispose(); - } - - @Override - public void renderEnvironmentForLight(Camera lightCamera) { - - } - - @Override - public void renderEnvironment(boolean hasDirectionalLight, Camera camera, Camera lightCamera, Texture lightTexture, int shadowFidelity, float ambientLight) { + public void renderCharacters(RenderEnvironment event, EntityRef renderingEntity) { if (!modelInstances.isEmpty()) { for (EntityRef entityRef : charactersIndex.getEntities()) { CharacterRenderComponent characterRender = entityRef.getComponent(CharacterRenderComponent.class); @@ -137,9 +119,16 @@ public void renderEnvironment(boolean hasDirectionalLight, Camera camera, Camera location.getZ() + characterRender.getTranslateZ()); } - modelBatch.begin(camera); + modelBatch.begin(event.getCamera()); modelBatch.render(modelInstances.values()); modelBatch.end(); } } + + @ReceiveEvent + public void characterRemoved(BeforeComponentRemoved event, EntityRef entity, CharacterRenderComponent characterRender, LocationComponent location) { + String characterId = characterRender.getId(); + modelInstances.remove(characterId); + models.remove(characterId).dispose(); + } } diff --git a/core/src/main/java/jgd/platformer/rendering/PlatformerBackgroundColorProvider.java b/core/src/main/java/jgd/platformer/rendering/PlatformerBackgroundColorProvider.java deleted file mode 100644 index 54e6859..0000000 --- a/core/src/main/java/jgd/platformer/rendering/PlatformerBackgroundColorProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -package jgd.platformer.rendering; - -import com.badlogic.gdx.math.Vector3; -import com.gempukku.gaming.rendering.BackgroundColorProvider; -import com.gempukku.secsy.context.annotation.RegisterSystem; - -@RegisterSystem( - shared = BackgroundColorProvider.class -) -public class PlatformerBackgroundColorProvider implements BackgroundColorProvider { - private Vector3 backgroundColor = new Vector3(145f / 255f, 186f / 255f, 220f / 255f); - - @Override - public Vector3 getBackgroundColor() { - return backgroundColor; - } -} diff --git a/core/src/main/java/jgd/platformer/rendering/PlatformerEnvironmentRenderer.java b/core/src/main/java/jgd/platformer/rendering/PlatformerEnvironmentRenderer.java index 81f7f97..e0cd723 100644 --- a/core/src/main/java/jgd/platformer/rendering/PlatformerEnvironmentRenderer.java +++ b/core/src/main/java/jgd/platformer/rendering/PlatformerEnvironmentRenderer.java @@ -1,7 +1,5 @@ package jgd.platformer.rendering; -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g3d.Material; import com.badlogic.gdx.graphics.g3d.Model; @@ -14,8 +12,7 @@ import com.gempukku.gaming.asset.texture.TextureAtlasProvider; import com.gempukku.gaming.asset.texture.TextureAtlasRegistry; import com.gempukku.gaming.rendering.environment.ArrayVertexOutput; -import com.gempukku.gaming.rendering.environment.EnvironmentRenderer; -import com.gempukku.gaming.rendering.environment.EnvironmentRendererRegistry; +import com.gempukku.gaming.rendering.event.RenderEnvironment; import com.gempukku.gaming.rendering.shape.ShapeOutput; import com.gempukku.gaming.rendering.shape.ShapeProvider; import com.gempukku.gaming.rendering.shape.TextureRegionMapper; @@ -34,9 +31,7 @@ import java.util.Map; @RegisterSystem -public class PlatformerEnvironmentRenderer implements EnvironmentRenderer, LifeCycleSystem { - @Inject - private EnvironmentRendererRegistry environmentRendererRegistry; +public class PlatformerEnvironmentRenderer implements LifeCycleSystem { @Inject private TextureAtlasRegistry textureAtlasRegistry; @Inject @@ -58,21 +53,11 @@ public void preInitialize() { modelBatch = new ModelBatch(); } - @Override - public void initialize() { - environmentRendererRegistry.registerEnvironmentRenderer(this); - } - @Override public void postDestroy() { destroyTerrain(); } - @Override - public void renderEnvironmentForLight(Camera lightCamera) { - - } - @ReceiveEvent public void levelLoader(AfterComponentAdded event, EntityRef entity, LevelComponent level) { ArrayVertexOutput vertices = new ArrayVertexOutput(); @@ -126,10 +111,10 @@ private void destroyTerrain() { terrain = null; } - @Override - public void renderEnvironment(boolean hasDirectionalLight, Camera camera, Camera lightCamera, Texture lightTexture, int shadowFidelity, float ambientLight) { + @ReceiveEvent + public void renderTerrain(RenderEnvironment event, EntityRef renderingEntity) { if (terrain != null) { - modelBatch.begin(camera); + modelBatch.begin(event.getCamera()); modelBatch.render(terrain); modelBatch.end(); } diff --git a/core/src/main/java/jgd/platformer/rendering/PlatformerRenderingEntityProvider.java b/core/src/main/java/jgd/platformer/rendering/PlatformerRenderingEntityProvider.java index d355302..0cafae4 100644 --- a/core/src/main/java/jgd/platformer/rendering/PlatformerRenderingEntityProvider.java +++ b/core/src/main/java/jgd/platformer/rendering/PlatformerRenderingEntityProvider.java @@ -1,6 +1,7 @@ package jgd.platformer.rendering; import com.badlogic.gdx.graphics.Camera; +import com.gempukku.gaming.asset.prefab.PrefabManager; import com.gempukku.gaming.rendering.RenderingEntityProvider; import com.gempukku.secsy.context.annotation.Inject; import com.gempukku.secsy.context.annotation.RegisterSystem; @@ -9,6 +10,7 @@ import com.gempukku.secsy.entity.EntityRef; import com.gempukku.secsy.entity.index.EntityIndex; import com.gempukku.secsy.entity.index.EntityIndexManager; +import com.gempukku.secsy.entity.io.EntityData; import jgd.platformer.component.LocationComponent; @RegisterSystem( @@ -17,6 +19,8 @@ public class PlatformerRenderingEntityProvider implements RenderingEntityProvider, LifeCycleSystem { private static final int DISTANCE_FROM_TERRAIN = 8; @Inject + private PrefabManager prefabManager; + @Inject private EntityManager entityManager; @Inject private EntityIndexManager entityIndexManager; @@ -27,7 +31,8 @@ public class PlatformerRenderingEntityProvider implements RenderingEntityProvide @Override public void initialize() { - cameraEntity = entityManager.createEntity(); + EntityData renderingEntity = prefabManager.getPrefabByName("renderingEntity"); + cameraEntity = entityManager.createEntity(renderingEntity); cameraFocusedEntities = entityIndexManager.addIndexOnComponents(CameraFocusComponent.class, LocationComponent.class); cameraBoundsEntities = entityIndexManager.addIndexOnComponents(CameraBoundsComponent.class); }