organisation and stuff

pull/12/head
valoeghese 2020-02-28 20:04:37 +13:00
parent d5f21f0072
commit 3f2738ac1a
8 changed files with 80 additions and 34 deletions

View File

@ -3,11 +3,10 @@ package com.github.halotroop.litecraft;
import java.io.IOException;
import org.joml.*;
import org.lwjgl.glfw.GLFW;
import com.github.halotroop.litecraft.save.LitecraftSave;
import com.github.halotroop.litecraft.screens.TitleScreen;
import com.github.halotroop.litecraft.types.block.*;
import com.github.halotroop.litecraft.types.block.Blocks;
import com.github.halotroop.litecraft.util.RelativeDirection;
import com.github.halotroop.litecraft.world.World;
import com.github.halotroop.litecraft.world.gen.Dimensions;
@ -33,7 +32,7 @@ public class Litecraft extends Game
private Ginger ginger3D;
private static Litecraft INSTANCE;
public Player player;
public Camera camera;
private Camera camera;
//temp stuff to test out fbo fixes
int oldWindowWidth = Window.width;
int oldWindowHeight = Window.height;
@ -46,21 +45,53 @@ public class Litecraft extends Game
Litecraft.INSTANCE = this;
dbgStats = new Vector4i();
// set constants
this.setupConstants();
this.setupWindow();
Blocks.setup(); // make sure blocks are initialised
GingerUtils.init(); // set up ginger utilities
Window.setBackgroundColour(0.2f, 0.2f, 0.6f); // set the window refresh colour
// set up Ginger3D stuff
this.setupGinger();
this.oldWindowWidth = Window.width;
this.oldWindowHeight = Window.height;
this.frameTimer = System.currentTimeMillis();
setupKeybinds(); // set up keybinds
//start the game loop
this.ginger3D.startGame();
}
private void setupConstants()
{
Constants.movementSpeed = 0.5f; // movement speed
Constants.turnSpeed = 0.00006f; // turn speed
Constants.gravity = new Vector3f(0, -0.0000000005f, 0); // compute gravity as a vec3f
Constants.jumpPower = 0.00005f; // jump power
}
private void setupWindow()
{
Window.create(1200, 800, "LiteCraft", 60); // create window
KeyCallbackHandler.trackWindow(Window.window); // set up the gateways keybind key tracking
MouseCallbackHandler.trackWindow(Window.window);
setupKeybinds(); // set up keybind
Blocks.setup(); // make sure blocks are initialised
GingerUtils.init(); // set up ginger utilities
Window.setBackgroundColour(0.2f, 0.2f, 0.6f); // set the window refresh colour
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
}
private void setupKeybinds()
{
Input.addPressCallback(Keybind.EXIT, this::exit);
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
Input.addInitialPressCallback(Keybind.WIREFRAME, GingerRegister.getInstance()::toggleWireframe);
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.movePlayer(RelativeDirection.FORWARD));
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.movePlayer(RelativeDirection.BACKWARD));
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT));
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT));
Input.addPressCallback(Keybind.FLY_UP, () -> this.movePlayer(RelativeDirection.UP));
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.movePlayer(RelativeDirection.DOWN));
}
private void setupGinger() {
TexturedModel playerModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
StaticCube.scaleCube(1f);
// set up Ginger3D stuff
this.player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
this.player = new Player(playerModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
this.camera = new FirstPersonCamera(player);
this.player.isVisible = false;
this.ginger3D = new Ginger();
@ -72,24 +103,10 @@ public class Litecraft extends Game
Light sun = new Light(new Vector3f(100, 105, -100), new Vector3f(1.3f, 1.3f, 1.3f), new Vector3f(0.0001f, 0.0001f, 0.0001f));
this.data.lights.add(sun);
this.data.entities.add(this.player);
this.oldWindowWidth = Window.width;
this.oldWindowHeight = Window.height;
this.frameTimer = System.currentTimeMillis();
//start the game loop
this.ginger3D.startGame();
}
private void setupKeybinds()
{
Input.addPressCallback(Keybind.EXIT, this::exit);
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.movePlayer(RelativeDirection.FORWARD));
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.movePlayer(RelativeDirection.BACKWARD));
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT));
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT));
Input.addPressCallback(Keybind.FLY_UP, () -> this.movePlayer(RelativeDirection.UP));
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.movePlayer(RelativeDirection.DOWN));
}
public Camera getCamera()
{ return this.camera; }
@Override
public void exit()
@ -151,8 +168,6 @@ public class Litecraft extends Game
tps++;
Input.invokeAllListeners();
data.player.updateMovement();
if (Window.isKeyDown(GLFW.GLFW_KEY_TAB))
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
}
public static Litecraft getInstance()

View File

@ -5,8 +5,10 @@ import java.util.Random;
import org.joml.Vector3f;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.world.*;
import com.github.halotroop.litecraft.world.gen.Dimension;
import com.github.hydos.ginger.engine.cameras.Camera;
import com.github.hydos.ginger.engine.elements.objects.Player;
import tk.valoeghese.sod.*;
@ -86,9 +88,13 @@ public final class LitecraftSave
try // try read the seed from the file
{
seed = properties.readLong(0); // seed is at index 0
playerX = playerData.readFloat(0); // player x/y/z is at index 1/2/3 respectively
playerX = playerData.readFloat(0); // player x/y/z is at index 0/1/2 respectively
playerY = playerData.readFloat(1);
playerZ = playerData.readFloat(2);
Camera camera = Litecraft.getInstance().getCamera(); // get camera
camera.setPitch(playerData.readFloat(3)); // read pitch, yaw, roll from 3/4/5
camera.setYaw(playerData.readFloat(4));
camera.setRoll(playerData.readFloat(5));
}
catch (Throwable e)
{
@ -133,6 +139,10 @@ public final class LitecraftSave
playerData.writeFloat(playerPos.x); // default spawn player x/y/z
playerData.writeFloat(playerPos.y);
playerData.writeFloat(playerPos.z);
Camera camera = Litecraft.getInstance().getCamera();
playerData.writeFloat(camera.getPitch());
playerData.writeFloat(camera.getYaw());
playerData.writeFloat(camera.getRoll());
data.put("properties", properties); // add properties section to data
data.put("player", playerData); // add player section to data
data.write(globalDataFile); // write to file

View File

@ -191,9 +191,16 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
this.fullyGenerated = properties.readBoolean(0); // index 0 is the "fully generated" property
}
catch (Throwable e)
{ System.out.println("An exception occurred reading properties for a chunk! This could be a benign error due to updates to chunk properties.");}
{
if (exceptionOccuredReadingNotif){
System.out.println("An exception occurred reading properties for a chunk! This could be a benign error due to updates to chunk properties.");
exceptionOccuredReadingNotif = false;
}
}
}
private static boolean exceptionOccuredReadingNotif = true;
private int nextId; // for saving
@Override

View File

@ -55,7 +55,7 @@ public class Ginger
gingerRegister.game.data.entities.remove(Litecraft.getInstance().player); // remove the old player
gingerRegister.game.data.player = player; // set all the player variables
Litecraft.getInstance().player = player;
Litecraft.getInstance().camera.player = player;
Litecraft.getInstance().getCamera().player = player;
gingerRegister.game.data.entities.add(player); // add the new player
}

View File

@ -61,6 +61,11 @@ public class GingerRegister
return null;
}
public void toggleWireframe()
{
this.wireframe = !this.wireframe;
}
public GUIText retrieveText(String string)
{
for (GUIText text : texts)

View File

@ -107,4 +107,13 @@ public class Camera
calculateCameraPosition(horizontalDistance, verticalDistance);
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
}
public void setPitch(float pitch)
{ this.pitch = pitch; }
public void setYaw(float yaw)
{ this.yaw = yaw; }
public void setRoll(float roll)
{ this.roll = roll; }
}

View File

@ -20,7 +20,6 @@ public class Player extends RenderObject
public void move(RelativeDirection direction)
{
float ry = (float) Math.toRadians(GingerRegister.getInstance().game.data.camera.getYaw());
System.out.println(ry);
switch (direction)
{
case FORWARD:

View File

@ -27,8 +27,9 @@ public enum Keybind
SLOT_10(GLFW.GLFW_KEY_0, false), // Select the tenth item slot in the toolbar
EXIT(GLFW.GLFW_KEY_ESCAPE, false), // Save and exit the game // (Open the pause menu later)
DEBUG(GLFW.GLFW_KEY_F3, false), // Toggle debug text onscreen
FULLSCREEN(GLFW.GLFW_KEY_F11, false); // Toggle fullscreen mode
FULLSCREEN(GLFW.GLFW_KEY_F11, false), // Toggle fullscreen mode
WIREFRAME(GLFW.GLFW_KEY_TAB, false); // Toggle wireframe
public int value;
public boolean mouse;