replace RenderContext with ViewContext. use registered "services" to hold the renderer objects that used to live in RenderContext
This commit is contained in:
parent
1f4d42ab4c
commit
4b8deb90cb
|
@ -1,16 +1,24 @@
|
|||
package com.blarg.gdx;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.graphics.*;
|
||||
import com.blarg.gdx.states.StateManager;
|
||||
|
||||
public abstract class GameApp implements Disposable {
|
||||
public final EventManager eventManager;
|
||||
public final StateManager stateManager;
|
||||
public final RenderContext renderContext;
|
||||
public final ViewportContext viewportContext;
|
||||
public final ExtendedSpriteBatch spriteBatch;
|
||||
public final BillboardSpriteBatch billboardSpriteBatch;
|
||||
public final ModelBatch modelBatch;
|
||||
public final SolidColorTextureCache solidColorTextures;
|
||||
public final DebugGeometryRenderer debugGeometryRenderer;
|
||||
public final ShapeRenderer shapeRenderer;
|
||||
|
||||
boolean logHeapMemUsage = false;
|
||||
long lastHeapMemLogTime = 0;
|
||||
|
@ -20,7 +28,23 @@ public abstract class GameApp implements Disposable {
|
|||
|
||||
eventManager = new EventManager();
|
||||
stateManager = new StateManager(this, eventManager);
|
||||
renderContext = new RenderContext(true);
|
||||
viewportContext = new ViewportContext(true);
|
||||
spriteBatch = new ExtendedSpriteBatch();
|
||||
billboardSpriteBatch = new BillboardSpriteBatch();
|
||||
modelBatch = new ModelBatch();
|
||||
solidColorTextures = new SolidColorTextureCache();
|
||||
debugGeometryRenderer = new DebugGeometryRenderer();
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
|
||||
Services.register(eventManager);
|
||||
Services.register(stateManager);
|
||||
Services.register(viewportContext);
|
||||
Services.register(spriteBatch);
|
||||
Services.register(billboardSpriteBatch);
|
||||
Services.register(modelBatch);
|
||||
Services.register(solidColorTextures);
|
||||
Services.register(debugGeometryRenderer);
|
||||
Services.register(shapeRenderer);
|
||||
}
|
||||
|
||||
protected void toggleHeapMemUsageLogging(boolean enable) {
|
||||
|
@ -33,17 +57,21 @@ public abstract class GameApp implements Disposable {
|
|||
|
||||
public void onResize(int width, int height) {
|
||||
Gdx.app.debug("GameApp", String.format("onResize(%d, %d)", width, height));
|
||||
renderContext.onResize(width, height);
|
||||
viewportContext.onResize(width, height);
|
||||
}
|
||||
|
||||
public void onRender(float delta) {
|
||||
renderContext.onPreRender();
|
||||
stateManager.onRender(delta, renderContext);
|
||||
renderContext.onPostRender();
|
||||
viewportContext.onPreRender();
|
||||
spriteBatch.setProjectionMatrix(viewportContext.getOrthographicCamera().combined);
|
||||
spriteBatch.setPixelScale(viewportContext.pixelScaler.getScale());
|
||||
|
||||
stateManager.onRender(delta);
|
||||
|
||||
viewportContext.onPostRender();
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
renderContext.onUpdate(delta);
|
||||
viewportContext.onUpdate(delta);
|
||||
eventManager.onUpdate(delta);
|
||||
stateManager.onUpdate(delta);
|
||||
if (stateManager.isEmpty()) {
|
||||
|
@ -64,12 +92,14 @@ public abstract class GameApp implements Disposable {
|
|||
public void onPause() {
|
||||
Gdx.app.debug("GameApp", "onPause");
|
||||
stateManager.onAppPause();
|
||||
renderContext.onPause();
|
||||
viewportContext.onPause();
|
||||
solidColorTextures.onPause();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Gdx.app.debug("GameApp", "onResume");
|
||||
renderContext.onResume();
|
||||
viewportContext.onResume();
|
||||
solidColorTextures.onResume();
|
||||
stateManager.onAppResume();
|
||||
}
|
||||
|
||||
|
@ -77,6 +107,9 @@ public abstract class GameApp implements Disposable {
|
|||
public void dispose() {
|
||||
Gdx.app.debug("GameApp", "dispose");
|
||||
stateManager.dispose();
|
||||
renderContext.dispose();
|
||||
solidColorTextures.dispose();
|
||||
modelBatch.dispose();
|
||||
billboardSpriteBatch.dispose();
|
||||
spriteBatch.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.badlogic.gdx.utils.Disposable;
|
|||
import com.blarg.gdx.events.Event;
|
||||
import com.blarg.gdx.events.EventHandler;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
|
||||
public abstract class ComponentSystem extends EventHandler implements Disposable {
|
||||
public final EntityManager entityManager;
|
||||
|
@ -26,7 +25,7 @@ public abstract class ComponentSystem extends EventHandler implements Disposable
|
|||
public void onResize() {
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.blarg.gdx.entities.systemcomponents.EntityPresetComponent;
|
|||
import com.blarg.gdx.entities.systemcomponents.InactiveComponent;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.ReflectionUtils;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
|
||||
public class EntityManager implements Disposable {
|
||||
public final EventManager eventManager;
|
||||
|
@ -293,9 +292,9 @@ public class EntityManager implements Disposable {
|
|||
componentSystems.get(i).onResize();
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
for (int i = 0; i < componentSystems.size; ++i)
|
||||
componentSystems.get(i).onRender(delta, renderContext);
|
||||
componentSystems.get(i).onRender(delta);
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
|
|
|
@ -10,61 +10,59 @@ import com.badlogic.gdx.math.Vector3;
|
|||
public final class GraphicsHelpers {
|
||||
final static Matrix4 tmpTransform = new Matrix4();
|
||||
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin) {
|
||||
renderCoordinateSystemAxis(shapeRenderer, spriteBatch, projectionCamera, font, origin, 5.0f);
|
||||
public static void clear() {
|
||||
clear(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin, float axisLength) {
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
spriteBatch.begin(projectionCamera);
|
||||
public static void clear(float red, float green, float blue, float alpha) {
|
||||
Gdx.graphics.getGL20().glClearColor(red, green, blue, alpha);
|
||||
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
shapeRenderer.setColor(Color.WHITE);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f);
|
||||
public static void renderCoordinateSystemAxis(DebugGeometryRenderer debugGeometryRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin) {
|
||||
renderCoordinateSystemAxis(debugGeometryRenderer, spriteBatch, projectionCamera, font, origin, 5.0f);
|
||||
}
|
||||
|
||||
public static void renderCoordinateSystemAxis(DebugGeometryRenderer debugGeometryRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin, float axisLength) {
|
||||
debugGeometryRenderer.begin(projectionCamera);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f, Color.WHITE);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + -axisLength, origin.z + 0.0f, Color.BLACK);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + -axisLength, origin.y + 0.0f, origin.z + 0.0f, Color.GREEN);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + axisLength, origin.y + 0.0f, origin.z + 0.0f, Color.RED);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + -axisLength, Color.CYAN);
|
||||
debugGeometryRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + axisLength, Color.YELLOW);
|
||||
debugGeometryRenderer.end();
|
||||
|
||||
spriteBatch.begin(projectionCamera);
|
||||
spriteBatch.setColor(Color.WHITE);
|
||||
spriteBatch.draw(font, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f, "UP (+Y)", 0.5f);
|
||||
|
||||
shapeRenderer.setColor(Color.BLACK);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + -axisLength, origin.z + 0.0f);
|
||||
spriteBatch.setColor(Color.BLACK);
|
||||
spriteBatch.draw(font, origin.x + 0.0f, origin.y + -axisLength, origin.z + 0.0f, "DOWN (-Y)", 0.5f);
|
||||
|
||||
shapeRenderer.setColor(Color.GREEN);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + -axisLength, origin.y + 0.0f, origin.z + 0.0f);
|
||||
spriteBatch.setColor(Color.GREEN);
|
||||
spriteBatch.draw(font, origin.x + -axisLength, origin.y + 0.0f, origin.z + 0.0f, "LEFT (-X)", 0.5f);
|
||||
|
||||
shapeRenderer.setColor(Color.RED);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + axisLength, origin.y + 0.0f, origin.z + 0.0f);
|
||||
spriteBatch.setColor(Color.RED);
|
||||
spriteBatch.draw(font, origin.x + axisLength, origin.y + 0.0f, origin.z + 0.0f, "RIGHT (+X)", 0.5f);
|
||||
|
||||
shapeRenderer.setColor(Color.CYAN);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + -axisLength);
|
||||
spriteBatch.setColor(Color.CYAN);
|
||||
spriteBatch.draw(font, origin.x + 0.0f, origin.y + 0.0f, origin.z + -axisLength, "FORWARD (-Z)", 0.5f);
|
||||
|
||||
shapeRenderer.setColor(Color.YELLOW);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + axisLength);
|
||||
spriteBatch.setColor(Color.YELLOW);
|
||||
spriteBatch.draw(font, origin.x + 0.0f, origin.y + 0.0f, origin.z + axisLength, "BACKWARD (+Z)", 0.5f);
|
||||
|
||||
spriteBatch.end();
|
||||
shapeRenderer.end();
|
||||
}
|
||||
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, int width, int depth) {
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, Camera projectionCamera, int width, int depth) {
|
||||
tmpTransform.idt();
|
||||
renderGridPlane(shapeRenderer, width, depth, tmpTransform);
|
||||
renderGridPlane(shapeRenderer, projectionCamera, width, depth, tmpTransform);
|
||||
}
|
||||
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, int width, int depth, float minX, float minY, float minZ) {
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, Camera projectionCamera, int width, int depth, float minX, float minY, float minZ) {
|
||||
tmpTransform.idt().translate(minX, minY, minZ);
|
||||
renderGridPlane(shapeRenderer, width, depth, tmpTransform);
|
||||
renderGridPlane(shapeRenderer, projectionCamera, width, depth, tmpTransform);
|
||||
}
|
||||
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, int width, int depth, Matrix4 transform) {
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
public static void renderGridPlane(ShapeRenderer shapeRenderer, Camera projectionCamera, int width, int depth, Matrix4 transform) {
|
||||
shapeRenderer.setProjectionMatrix(projectionCamera.combined);
|
||||
shapeRenderer.setTransformMatrix(transform);
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
shapeRenderer.setColor(Color.WHITE);
|
||||
|
||||
for (int i = 0; i <= width; ++i)
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
package com.blarg.gdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.math.MathHelpers;
|
||||
|
||||
public class RenderContext implements Disposable {
|
||||
public final ExtendedSpriteBatch spriteBatch;
|
||||
public final BillboardSpriteBatch billboardSpriteBatch;
|
||||
public final ShapeRenderer debugGeometryRenderer2D;
|
||||
public final ShapeRenderer debugGeometryRenderer3D;
|
||||
public final ModelBatch modelBatch;
|
||||
public final ScreenPixelScaler pixelScaler;
|
||||
public final SolidColorTextureCache solidColorTextures;
|
||||
|
||||
Camera perspectiveCamera;
|
||||
OrthographicCamera orthographicCamera;
|
||||
|
||||
public RenderContext(boolean use2dPixelScaling) {
|
||||
Gdx.app.debug("RenderContext", "ctor");
|
||||
spriteBatch = new ExtendedSpriteBatch();
|
||||
billboardSpriteBatch = new BillboardSpriteBatch();
|
||||
debugGeometryRenderer2D = new ShapeRenderer();
|
||||
debugGeometryRenderer3D = new ShapeRenderer();
|
||||
modelBatch = new ModelBatch();
|
||||
solidColorTextures = new SolidColorTextureCache();
|
||||
|
||||
if (use2dPixelScaling)
|
||||
pixelScaler = new DefaultScreenPixelScaler();
|
||||
else
|
||||
pixelScaler = new NoScaleScreenPixelScaler();
|
||||
pixelScaler.calculateScale(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
orthographicCamera = new OrthographicCamera(pixelScaler.getScaledWidth(), pixelScaler.getScaledHeight());
|
||||
|
||||
setDefaultPerspectiveCamera();
|
||||
}
|
||||
|
||||
public Camera getPerspectiveCamera() {
|
||||
return perspectiveCamera;
|
||||
}
|
||||
|
||||
public OrthographicCamera getOrthographicCamera() {
|
||||
return orthographicCamera;
|
||||
}
|
||||
|
||||
public void setPerspectiveCamera(Camera camera) {
|
||||
if (camera == null)
|
||||
throw new IllegalArgumentException();
|
||||
perspectiveCamera = camera;
|
||||
}
|
||||
|
||||
public void setDefaultPerspectiveCamera() {
|
||||
PerspectiveCamera camera = new PerspectiveCamera(60.0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
camera.position.set(0.0f, 0.0f, 0.0f);
|
||||
camera.lookAt(MathHelpers.FORWARD_VECTOR3);
|
||||
camera.near = 0.1f;
|
||||
camera.far = 100.0f;
|
||||
camera.update();
|
||||
setPerspectiveCamera(camera);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
clear(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
public void clear(float red, float green, float blue, float alpha) {
|
||||
Gdx.graphics.getGL20().glClearColor(red, green, blue, alpha);
|
||||
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
public void onPreRender() {
|
||||
spriteBatch.setProjectionMatrix(orthographicCamera.combined);
|
||||
spriteBatch.setPixelScale(pixelScaler.getScale());
|
||||
debugGeometryRenderer2D.setProjectionMatrix(orthographicCamera.combined);
|
||||
debugGeometryRenderer3D.setProjectionMatrix(perspectiveCamera.combined);
|
||||
}
|
||||
|
||||
public void onPostRender() {
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
perspectiveCamera.update();
|
||||
orthographicCamera.update();
|
||||
}
|
||||
|
||||
public void onResize(int width, int height) {
|
||||
Gdx.app.debug("RenderContext", String.format("onResize(%d, %d)", width, height));
|
||||
pixelScaler.calculateScale(width, height);
|
||||
orthographicCamera.setToOrtho(false, pixelScaler.getScaledWidth(), pixelScaler.getScaledHeight());
|
||||
perspectiveCamera.viewportWidth = width;
|
||||
perspectiveCamera.viewportHeight = height;
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Gdx.app.debug("RenderContext", String.format("onPause"));
|
||||
solidColorTextures.onPause();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Gdx.app.debug("RenderContext", String.format("onResume"));
|
||||
solidColorTextures.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Gdx.app.debug("RenderContext", String.format("dispose"));
|
||||
solidColorTextures.dispose();
|
||||
modelBatch.dispose();
|
||||
billboardSpriteBatch.dispose();
|
||||
spriteBatch.dispose();
|
||||
}
|
||||
}
|
82
src/com/blarg/gdx/graphics/ViewportContext.java
Normal file
82
src/com/blarg/gdx/graphics/ViewportContext.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package com.blarg.gdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||
import com.blarg.gdx.math.MathHelpers;
|
||||
|
||||
/**
|
||||
* Manages graphics state relating to the viewport dimensions and camera(s).
|
||||
*/
|
||||
public class ViewportContext {
|
||||
public final ScreenPixelScaler pixelScaler;
|
||||
|
||||
Camera perspectiveCamera;
|
||||
OrthographicCamera orthographicCamera;
|
||||
|
||||
public ViewportContext(boolean use2dPixelScaling) {
|
||||
Gdx.app.debug("ViewportContext", "ctor");
|
||||
if (use2dPixelScaling)
|
||||
pixelScaler = new DefaultScreenPixelScaler();
|
||||
else
|
||||
pixelScaler = new NoScaleScreenPixelScaler();
|
||||
pixelScaler.calculateScale(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
orthographicCamera = new OrthographicCamera(pixelScaler.getScaledWidth(), pixelScaler.getScaledHeight());
|
||||
|
||||
setDefaultPerspectiveCamera();
|
||||
}
|
||||
|
||||
public Camera getPerspectiveCamera() {
|
||||
return perspectiveCamera;
|
||||
}
|
||||
|
||||
public OrthographicCamera getOrthographicCamera() {
|
||||
return orthographicCamera;
|
||||
}
|
||||
|
||||
public void setPerspectiveCamera(Camera camera) {
|
||||
if (camera == null)
|
||||
throw new IllegalArgumentException();
|
||||
perspectiveCamera = camera;
|
||||
}
|
||||
|
||||
public void setDefaultPerspectiveCamera() {
|
||||
PerspectiveCamera camera = new PerspectiveCamera(60.0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
camera.position.set(0.0f, 0.0f, 0.0f);
|
||||
camera.lookAt(MathHelpers.FORWARD_VECTOR3);
|
||||
camera.near = 0.1f;
|
||||
camera.far = 100.0f;
|
||||
camera.update();
|
||||
setPerspectiveCamera(camera);
|
||||
}
|
||||
|
||||
public void onPreRender() {
|
||||
|
||||
}
|
||||
|
||||
public void onPostRender() {
|
||||
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
perspectiveCamera.update();
|
||||
orthographicCamera.update();
|
||||
}
|
||||
|
||||
public void onResize(int width, int height) {
|
||||
Gdx.app.debug("ViewportContext", String.format("onResize(%d, %d)", width, height));
|
||||
pixelScaler.calculateScale(width, height);
|
||||
orthographicCamera.setToOrtho(false, pixelScaler.getScaledWidth(), pixelScaler.getScaledHeight());
|
||||
perspectiveCamera.viewportWidth = width;
|
||||
perspectiveCamera.viewportHeight = height;
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Gdx.app.debug("ViewportContext", String.format("onPause"));
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Gdx.app.debug("ViewportContext", String.format("onResume"));
|
||||
}
|
||||
}
|
|
@ -2,7 +2,10 @@ package com.blarg.gdx.graphics.screeneffects;
|
|||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.Services;
|
||||
import com.blarg.gdx.graphics.ExtendedSpriteBatch;
|
||||
import com.blarg.gdx.graphics.SolidColorTextureCache;
|
||||
import com.blarg.gdx.graphics.ViewportContext;
|
||||
|
||||
public class DimScreenEffect extends ScreenEffect
|
||||
{
|
||||
|
@ -14,28 +17,36 @@ public class DimScreenEffect extends ScreenEffect
|
|||
|
||||
Color renderColor;
|
||||
|
||||
ExtendedSpriteBatch spriteBatch;
|
||||
SolidColorTextureCache solidColorTextures;
|
||||
ViewportContext viewportContext;
|
||||
|
||||
public DimScreenEffect()
|
||||
{
|
||||
color = new Color(DEFAULT_DIM_COLOR);
|
||||
alpha = DEFAULT_DIM_ALPHA;
|
||||
|
||||
renderColor = new Color(color);
|
||||
|
||||
spriteBatch = Services.get(ExtendedSpriteBatch.class);
|
||||
solidColorTextures = Services.get(SolidColorTextureCache.class);
|
||||
viewportContext = Services.get(ViewportContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender(float delta, RenderContext renderContext)
|
||||
public void onRender(float delta)
|
||||
{
|
||||
renderColor.set(color);
|
||||
renderColor.a = alpha;
|
||||
Texture texture = renderContext.solidColorTextures.get(color);
|
||||
Texture texture = solidColorTextures.get(color);
|
||||
|
||||
renderContext.spriteBatch.begin();
|
||||
renderContext.spriteBatch.setColor(renderColor);
|
||||
renderContext.spriteBatch.draw(
|
||||
spriteBatch.begin();
|
||||
spriteBatch.setColor(renderColor);
|
||||
spriteBatch.draw(
|
||||
texture,
|
||||
0, 0,
|
||||
renderContext.pixelScaler.getScaledWidth(), renderContext.pixelScaler.getScaledHeight()
|
||||
viewportContext.pixelScaler.getScaledWidth(), viewportContext.pixelScaler.getScaledHeight()
|
||||
);
|
||||
renderContext.spriteBatch.end();
|
||||
spriteBatch.end();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ package com.blarg.gdx.graphics.screeneffects;
|
|||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.Services;
|
||||
import com.blarg.gdx.graphics.ExtendedSpriteBatch;
|
||||
import com.blarg.gdx.graphics.SolidColorTextureCache;
|
||||
import com.blarg.gdx.graphics.ViewportContext;
|
||||
|
||||
public class FadeScreenEffect extends ScreenEffect
|
||||
{
|
||||
|
@ -15,8 +18,16 @@ public class FadeScreenEffect extends ScreenEffect
|
|||
float fadeToAlpha;
|
||||
boolean isDoneFading;
|
||||
|
||||
ExtendedSpriteBatch spriteBatch;
|
||||
SolidColorTextureCache solidColorTextures;
|
||||
ViewportContext viewportContext;
|
||||
|
||||
public FadeScreenEffect() {
|
||||
color = new Color();
|
||||
|
||||
spriteBatch = Services.get(ExtendedSpriteBatch.class);
|
||||
solidColorTextures = Services.get(SolidColorTextureCache.class);
|
||||
viewportContext = Services.get(ViewportContext.class);
|
||||
}
|
||||
|
||||
public boolean isDoneFading() {
|
||||
|
@ -54,19 +65,19 @@ public class FadeScreenEffect extends ScreenEffect
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRender(float delta, RenderContext renderContext)
|
||||
public void onRender(float delta)
|
||||
{
|
||||
Texture texture = renderContext.solidColorTextures.get(Color.WHITE);
|
||||
Texture texture = solidColorTextures.get(Color.WHITE);
|
||||
color.a = alpha;
|
||||
|
||||
renderContext.spriteBatch.begin();
|
||||
renderContext.spriteBatch.setColor(color);
|
||||
renderContext.spriteBatch.draw(
|
||||
spriteBatch.begin();
|
||||
spriteBatch.setColor(color);
|
||||
spriteBatch.draw(
|
||||
texture,
|
||||
0, 0,
|
||||
renderContext.pixelScaler.getScaledWidth(), renderContext.pixelScaler.getScaledHeight()
|
||||
viewportContext.pixelScaler.getScaledWidth(), viewportContext.pixelScaler.getScaledHeight()
|
||||
);
|
||||
renderContext.spriteBatch.end();
|
||||
spriteBatch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,10 @@ package com.blarg.gdx.graphics.screeneffects;
|
|||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.Services;
|
||||
import com.blarg.gdx.graphics.ExtendedSpriteBatch;
|
||||
import com.blarg.gdx.graphics.SolidColorTextureCache;
|
||||
import com.blarg.gdx.graphics.ViewportContext;
|
||||
|
||||
public class FlashScreenEffect extends ScreenEffect
|
||||
{
|
||||
|
@ -17,6 +20,10 @@ public class FlashScreenEffect extends ScreenEffect
|
|||
boolean isFlashingIn;
|
||||
float alpha;
|
||||
|
||||
ExtendedSpriteBatch spriteBatch;
|
||||
SolidColorTextureCache solidColorTextures;
|
||||
ViewportContext viewportContext;
|
||||
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
@ -27,22 +34,26 @@ public class FlashScreenEffect extends ScreenEffect
|
|||
flashOutSpeed = DEFAULT_FLASH_SPEED;
|
||||
maximumIntensity = DEFAULT_MAX_INTENSITY;
|
||||
color = new Color(Color.WHITE);
|
||||
|
||||
spriteBatch = Services.get(ExtendedSpriteBatch.class);
|
||||
solidColorTextures = Services.get(SolidColorTextureCache.class);
|
||||
viewportContext = Services.get(ViewportContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender(float delta, RenderContext renderContext)
|
||||
public void onRender(float delta)
|
||||
{
|
||||
Texture texture = renderContext.solidColorTextures.get(Color.WHITE);
|
||||
Texture texture = solidColorTextures.get(Color.WHITE);
|
||||
color.a = alpha;
|
||||
|
||||
renderContext.spriteBatch.begin();
|
||||
renderContext.spriteBatch.setColor(color);
|
||||
renderContext.spriteBatch.draw(
|
||||
spriteBatch.begin();
|
||||
spriteBatch.setColor(color);
|
||||
spriteBatch.draw(
|
||||
texture,
|
||||
0, 0,
|
||||
renderContext.pixelScaler.getScaledWidth(), renderContext.pixelScaler.getScaledHeight()
|
||||
viewportContext.pixelScaler.getScaledWidth(), viewportContext.pixelScaler.getScaledHeight()
|
||||
);
|
||||
renderContext.spriteBatch.end();
|
||||
spriteBatch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.blarg.gdx.graphics.screeneffects;
|
||||
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
|
||||
public abstract class ScreenEffect implements Disposable
|
||||
{
|
||||
|
@ -26,7 +25,7 @@ public abstract class ScreenEffect implements Disposable
|
|||
public void onResize() {
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.blarg.gdx.graphics.screeneffects;
|
||||
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
@ -104,25 +103,25 @@ public class ScreenEffectManager implements Disposable
|
|||
effects.get(i).effect.onResize();
|
||||
}
|
||||
|
||||
public void onRenderLocal(float delta, RenderContext renderContext) {
|
||||
public void onRenderLocal(float delta) {
|
||||
if (numLocalEffects == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < effects.size(); ++i) {
|
||||
EffectInfo effectInfo = effects.get(i);
|
||||
if (effectInfo.isLocal)
|
||||
effectInfo.effect.onRender(delta, renderContext);
|
||||
effectInfo.effect.onRender(delta);
|
||||
}
|
||||
}
|
||||
|
||||
public void onRenderGlobal(float delta, RenderContext renderContext) {
|
||||
public void onRenderGlobal(float delta) {
|
||||
if (numGlobalEffects == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < effects.size(); ++i) {
|
||||
EffectInfo effectInfo = effects.get(i);
|
||||
if (!effectInfo.isLocal)
|
||||
effectInfo.effect.onRender(delta, renderContext);
|
||||
effectInfo.effect.onRender(delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.blarg.gdx.GameApp;
|
|||
import com.blarg.gdx.events.Event;
|
||||
import com.blarg.gdx.events.EventHandler;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.states.GameState;
|
||||
|
||||
public abstract class GameProcess extends EventHandler implements Disposable {
|
||||
|
@ -55,7 +54,7 @@ public abstract class GameProcess extends EventHandler implements Disposable {
|
|||
public void onResize() {
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
|
|
|
@ -2,11 +2,10 @@ package com.blarg.gdx.processes;
|
|||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.ReflectionUtils;
|
||||
import com.blarg.gdx.Strings;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.states.GameState;
|
||||
import com.blarg.gdx.ReflectionUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
@ -189,11 +188,11 @@ public class ProcessManager implements Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
for (int i = 0; i < processes.size(); ++i) {
|
||||
ProcessInfo processInfo = processes.get(i);
|
||||
if (!processInfo.isInactive)
|
||||
processInfo.process.onRender(delta, renderContext);
|
||||
processInfo.process.onRender(delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.blarg.gdx.GameApp;
|
|||
import com.blarg.gdx.events.Event;
|
||||
import com.blarg.gdx.events.EventHandler;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
import com.blarg.gdx.graphics.screeneffects.ScreenEffectManager;
|
||||
import com.blarg.gdx.processes.ProcessManager;
|
||||
|
||||
|
@ -80,12 +79,12 @@ public abstract class GameState extends EventHandler implements Disposable {
|
|||
effectManager.onResize();
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
// switch it up and do effects before processes here so that processes
|
||||
// (which would commonly be used for UI overlay elements) don't get
|
||||
// overwritten by local effects (e.g. flashes, etc.)
|
||||
effectManager.onRenderLocal(delta, renderContext);
|
||||
processManager.onRender(delta, renderContext);
|
||||
effectManager.onRenderLocal(delta);
|
||||
processManager.onRender(delta);
|
||||
}
|
||||
|
||||
public void onUpdate(float delta) {
|
||||
|
|
|
@ -3,10 +3,9 @@ package com.blarg.gdx.states;
|
|||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.GameApp;
|
||||
import com.blarg.gdx.ReflectionUtils;
|
||||
import com.blarg.gdx.Strings;
|
||||
import com.blarg.gdx.events.EventManager;
|
||||
import com.blarg.gdx.ReflectionUtils;
|
||||
import com.blarg.gdx.graphics.RenderContext;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
@ -254,12 +253,12 @@ public class StateManager implements Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
public void onRender(float delta, RenderContext renderContext) {
|
||||
public void onRender(float delta) {
|
||||
for (int i = getTopNonOverlayIndex(); i != -1 && i < states.size(); ++i) {
|
||||
StateInfo stateInfo = states.get(i);
|
||||
if (!stateInfo.isInactive) {
|
||||
stateInfo.state.onRender(delta, renderContext);
|
||||
stateInfo.state.effectManager.onRenderGlobal(delta, renderContext);
|
||||
stateInfo.state.onRender(delta);
|
||||
stateInfo.state.effectManager.onRenderGlobal(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue