[Refactor] Moved some stuff around

pull/12/head^2
Caroline Bell 2020-03-03 16:49:31 -08:00
parent 3526a9cff8
commit de51a12bdb
10 changed files with 28 additions and 121 deletions

View File

@ -2,6 +2,7 @@ package com.github.halotroop.litecraft;
import org.joml.*;
import com.github.halotroop.litecraft.gingeraddons.opengl.render.renderers.GLBlockRenderer;
import com.github.halotroop.litecraft.save.LitecraftSave;
import com.github.halotroop.litecraft.screens.*;
import com.github.halotroop.litecraft.types.block.Blocks;
@ -19,7 +20,7 @@ import com.github.hydos.ginger.engine.common.io.Window;
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
import com.github.hydos.ginger.engine.opengl.api.*;
import com.github.hydos.ginger.engine.opengl.postprocessing.PostProcessing;
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
import com.github.hydos.ginger.engine.opengl.render.*;
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
import com.github.hydos.ginger.engine.vulkan.api.GingerVK;
@ -36,6 +37,7 @@ public class Litecraft extends Game
public int fps, ups, tps;
public Vector4i dbgStats = new Vector4i();
private long frameTimer;
public GLBlockRenderer glBlockRenderer;
public Litecraft()
{
@ -142,6 +144,8 @@ public class Litecraft extends Game
this.data.handleGuis = false;
((GingerGL) engine).setup(new MasterRenderer(this.camera), INSTANCE);
((GingerGL) engine).setGlobalFont(font);
glBlockRenderer = new GLBlockRenderer(GingerRegister.getInstance().masterRenderer.getEntityShader(),
GingerRegister.getInstance().masterRenderer.getProjectionMatrix());
this.data.entities.add(this.player);
break;
}
@ -208,5 +212,5 @@ public class Litecraft extends Game
@Override
public void renderScene()
{ world.render(GingerRegister.getInstance().masterRenderer.gLBlockRenderer); }
{ world.render(glBlockRenderer); }
}

View File

@ -1,8 +1,9 @@
package com.github.halotroop.litecraft.render;
package com.github.halotroop.litecraft.gingeraddons.opengl.render.renderers;
import org.joml.Matrix4f;
import org.lwjgl.opengl.*;
import com.github.halotroop.litecraft.gingeraddons.opengl.utils.GLVoxelLoader;
import com.github.halotroop.litecraft.types.block.BlockInstance;
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
import com.github.hydos.ginger.engine.common.api.GingerRegister;

View File

@ -1,4 +1,4 @@
package com.github.halotroop.litecraft.render;
package com.github.halotroop.litecraft.gingeraddons.opengl.utils;
import java.nio.ByteBuffer;
@ -7,7 +7,7 @@ import org.lwjgl.opengl.*;
import com.github.halotroop.litecraft.types.block.*;
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
class GLVoxelLoader extends GLLoader
public class GLVoxelLoader extends GLLoader
{
public static int createBlockAtlas()
{

View File

@ -5,8 +5,8 @@ import java.util.function.ToIntFunction;
import org.joml.Vector3f;
import com.github.halotroop.litecraft.gingeraddons.opengl.render.renderers.GLBlockRenderer;
import com.github.halotroop.litecraft.logic.SODSerializable;
import com.github.halotroop.litecraft.render.GLBlockRenderer;
import com.github.halotroop.litecraft.types.block.*;
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;

View File

@ -8,7 +8,7 @@ import java.util.function.LongConsumer;
import org.joml.Vector3f;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.render.GLBlockRenderer;
import com.github.halotroop.litecraft.gingeraddons.opengl.render.renderers.GLBlockRenderer;
import com.github.halotroop.litecraft.save.LitecraftSave;
import com.github.halotroop.litecraft.types.block.*;
import com.github.halotroop.litecraft.types.entity.PlayerEntity;

View File

@ -3,8 +3,8 @@ package com.github.hydos.ginger.engine.common.api;
import com.github.hydos.ginger.engine.common.api.game.Game;
import com.github.hydos.ginger.engine.common.io.Window;
import com.github.hydos.ginger.engine.common.screen.Screen;
import com.github.hydos.ginger.engine.common.util.Timer;
import com.github.hydos.ginger.engine.common.util.Timer.TickListener;
import com.github.hydos.ginger.engine.common.utils.Timer;
import com.github.hydos.ginger.engine.common.utils.Timer.TickListener;
import com.github.hydos.ginger.engine.opengl.api.GingerUtils;
public abstract class GingerEngine

View File

@ -1,100 +0,0 @@
package com.github.hydos.ginger.engine.common.elements.objects;
import org.joml.Vector3f;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.util.RelativeDirection;
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
import com.github.hydos.ginger.engine.common.Constants;
import com.github.hydos.ginger.engine.common.api.GingerRegister;
import com.github.hydos.ginger.engine.common.io.Window;
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
public class Player extends RenderObject implements WorldGenConstants
{
private boolean isInAir = false;
private double upwardsSpeed;
private boolean noWeight = true; // because the force of gravity on an object's mass is called WEIGHT, not gravity
private int chunkX, chunkY, chunkZ;
public Player(GLTexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
{
super(model, position, rotX, rotY, rotZ, scale);
this.chunkX = (int) position.x >> POS_SHIFT;
this.chunkY = (int) position.y >> POS_SHIFT;
this.chunkZ = (int) position.z >> POS_SHIFT;
}
public void move(RelativeDirection direction)
{
float ry = (float) Math.toRadians(GingerRegister.getInstance().game.data.camera.getYaw());
switch (direction)
{
case FORWARD:
default:
position.z -= Math.cos(ry) * Constants.movementSpeed;
position.x += Math.sin(ry) * Constants.movementSpeed;
break;
case BACKWARD:
position.z += Math.cos(ry) * Constants.movementSpeed;
position.x -= Math.sin(ry) * Constants.movementSpeed;
break;
case LEFT:
ry -= RIGHT_ANGLE;
position.z -= Math.cos(ry) * Constants.movementSpeed;
position.x += Math.sin(ry) * Constants.movementSpeed;
break;
case RIGHT:
ry += RIGHT_ANGLE;
position.z -= Math.cos(ry) * Constants.movementSpeed;
position.x += Math.sin(ry) * Constants.movementSpeed;
break;
case UP:
if (this.noWeight)
position.y += Constants.movementSpeed;
else this.jump();
break;
case DOWN:
position.y -= Constants.movementSpeed;
break;
}
}
private static final float RIGHT_ANGLE = (float) (Math.PI / 2f);
private void jump()
{
if (!isInAir)
{
isInAir = true;
this.upwardsSpeed = Constants.jumpPower;
}
}
public int getChunkX()
{ return this.chunkX; }
public int getChunkY()
{ return this.chunkY; }
public int getChunkZ()
{ return this.chunkZ; }
public void updateMovement()
{
super.increasePosition(0, (float) (upwardsSpeed * (Window.getTime())), 0);
upwardsSpeed += Constants.gravity.y() * Window.getTime(); // TODO: Implement 3D gravity
isInAir = false;
upwardsSpeed = 0;
int newChunkX = (int) position.x >> POS_SHIFT;
int newChunkY = (int) position.y >> POS_SHIFT;
int newChunkZ = (int) position.z >> POS_SHIFT;
if (newChunkX != this.chunkX || newChunkY != this.chunkY || newChunkZ != this.chunkZ)
{
Litecraft.getInstance().getWorld().updateLoadedChunks(newChunkX, newChunkY, newChunkZ);
this.chunkX = newChunkX;
this.chunkY = newChunkY;
this.chunkZ = newChunkZ;
}
}
}

View File

@ -1,4 +1,4 @@
package com.github.hydos.ginger.engine.common.util;
package com.github.hydos.ginger.engine.common.utils;
import java.util.*;

View File

@ -10,7 +10,7 @@ import com.github.hydos.ginger.engine.common.font.*;
import com.github.hydos.ginger.engine.common.io.Window;
import com.github.hydos.ginger.engine.common.screen.Screen;
import com.github.hydos.ginger.engine.common.tools.MousePicker;
import com.github.hydos.ginger.engine.common.util.Timer;
import com.github.hydos.ginger.engine.common.utils.Timer;
import com.github.hydos.ginger.engine.opengl.postprocessing.*;
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;

View File

@ -6,7 +6,6 @@ import java.util.*;
import org.joml.*;
import org.lwjgl.opengl.*;
import com.github.halotroop.litecraft.render.GLBlockRenderer;
import com.github.hydos.ginger.engine.common.api.GingerRegister;
import com.github.hydos.ginger.engine.common.cameras.Camera;
import com.github.hydos.ginger.engine.common.elements.GuiTexture;
@ -32,7 +31,6 @@ public class MasterRenderer
// GL11.glCullFace(GL11.GL_BACK);
}
public GLBlockRenderer gLBlockRenderer;
private StaticShader entityShader;
public ObjectRenderer entityRenderer;
private GuiShader guiShader;
@ -48,8 +46,7 @@ public class MasterRenderer
{
createProjectionMatrix();
entityShader = new StaticShader();
gLBlockRenderer = new GLBlockRenderer(entityShader, projectionMatrix);
entityRenderer = new ObjectRenderer(entityShader, projectionMatrix);
entityRenderer = new ObjectRenderer(getEntityShader(), projectionMatrix);
guiShader = new GuiShader();
guiRenderer = new GuiRenderer(guiShader);
normalRenderer = new NormalMappingRenderer(projectionMatrix);
@ -58,7 +55,7 @@ public class MasterRenderer
public void cleanUp()
{
entityShader.cleanUp();
getEntityShader().cleanUp();
guiRenderer.cleanUp();
shadowMapRenderer.cleanUp();
normalRenderer.cleanUp();
@ -130,12 +127,12 @@ public class MasterRenderer
for (RenderObject entity : entities)
{ processEntity(entity); }
entityRenderer.prepare();
entityShader.start();
entityShader.loadSkyColour(Window.getColour());
entityShader.loadLights(lights);
entityShader.loadViewMatrix(camera);
getEntityShader().start();
getEntityShader().loadSkyColour(Window.getColour());
getEntityShader().loadLights(lights);
getEntityShader().loadViewMatrix(camera);
entityRenderer.render(this.entities);
entityShader.stop();
getEntityShader().stop();
this.entities.clear();
}
@ -172,4 +169,9 @@ public class MasterRenderer
shadowMapRenderer.render(entities, sun);
entities.clear();
}
public StaticShader getEntityShader()
{
return entityShader;
}
}