Skip to content

Commit

Permalink
Refactoring the code after change in gaming module.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinSc committed Jul 8, 2016
1 parent 5097425 commit 165d199
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 61 deletions.
7 changes: 7 additions & 0 deletions core/assets/prefabs/renderingEntity.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"BackgroundColorComponent": {
"red": 145,
"green": 186,
"blue": 220
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/jgd/platformer/Platformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -89,6 +88,7 @@ public void render() {

@Override
public void resize(int width, int height) {
context.getSystem(RenderingEngine.class).screenResized(width, height);
}

@Override
Expand Down
33 changes: 11 additions & 22 deletions core/src/main/java/jgd/platformer/rendering/CharacterRenderer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> textureNames = new HashSet<>();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 165d199

Please sign in to comment.