Merge branch 'liteCraft' into Vulkan
commit
b21d127ef7
|
@ -5,8 +5,9 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
|
@ -23,9 +24,9 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
|
@ -16,7 +16,6 @@ import com.github.hydos.ginger.engine.common.font.FontType;
|
|||
import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
||||
import com.github.hydos.ginger.engine.common.io.Window;
|
||||
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
||||
import com.github.hydos.ginger.engine.common.obj.shapes.StaticCube;
|
||||
import com.github.hydos.ginger.engine.opengl.api.*;
|
||||
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||
import com.github.hydos.ginger.engine.opengl.render.models.TexturedModel;
|
||||
|
@ -43,7 +42,7 @@ public class Litecraft extends Game
|
|||
Litecraft.INSTANCE = this;
|
||||
// set constants
|
||||
this.setupConstants();
|
||||
this.setupGinger();
|
||||
this.setupGinger(1280, 720, 60);
|
||||
Blocks.init(); // make sure blocks are initialised
|
||||
this.frameTimer = System.currentTimeMillis();
|
||||
setupKeybinds(); // setup keybinds
|
||||
|
@ -75,9 +74,8 @@ public class Litecraft extends Game
|
|||
@Override
|
||||
public void render()
|
||||
{
|
||||
fps += 1; // This section updates the debug stats once per real-time second, regardless of how many frames have been rendered
|
||||
if (System.currentTimeMillis() > frameTimer + 1000)
|
||||
updateDebugStats();
|
||||
fps += 1;
|
||||
if (System.currentTimeMillis() > frameTimer + 1000) updateDebugStats();
|
||||
// Render shadows
|
||||
GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
||||
// If there's a world, render it!
|
||||
|
@ -101,8 +99,6 @@ public class Litecraft extends Game
|
|||
public void update()
|
||||
{
|
||||
Input.invokeAllListeners();
|
||||
data.player.updateMovement();
|
||||
data.camera.updateMovement();
|
||||
}
|
||||
|
||||
private void setupConstants()
|
||||
|
@ -114,14 +110,18 @@ public class Litecraft extends Game
|
|||
}
|
||||
|
||||
// set up Ginger3D engine stuff
|
||||
private void setupGinger()
|
||||
private void setupGinger(int windowWidth, int windowHeight, float frameCap)
|
||||
{
|
||||
if (engine == null) // Prevents this from being run more than once on accident.
|
||||
{
|
||||
this.setupWindow();
|
||||
GingerUtils.init(); // set up ginger utilities
|
||||
Window.create(windowWidth, windowHeight, "Litecraft", frameCap, RenderAPI.OpenGL); // create window
|
||||
// set up the gateways keybind key tracking
|
||||
KeyCallbackHandler.trackWindow(Window.getWindow());
|
||||
MouseCallbackHandler.trackWindow(Window.getWindow());
|
||||
// set up ginger utilities
|
||||
GingerUtils.init();
|
||||
//Set the player model
|
||||
TexturedModel playerModel = ModelLoader.loadGenericCube("block/cubes/stone/brick/stonebrick.png");
|
||||
StaticCube.scaleCube(1f);
|
||||
Light sun = new Light(new Vector3f(0, 105, 0), new Vector3f(0.9765625f, 0.98828125f, 0.05859375f), new Vector3f(0.002f, 0.002f, 0.002f));
|
||||
FontType font = new FontType(GlLoader.loadFontAtlas("candara.png"), "candara.fnt");
|
||||
this.engine = new GingerGL();
|
||||
|
@ -149,13 +149,6 @@ public class Litecraft extends Game
|
|||
Input.addPressCallback(Keybind.FLY_UP, () -> this.player.move(RelativeDirection.UP));
|
||||
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.player.move(RelativeDirection.DOWN));
|
||||
}
|
||||
|
||||
private void setupWindow()
|
||||
{
|
||||
Window.create(1280, 720, "LiteCraft", 60, RenderAPI.OpenGL); // create window
|
||||
KeyCallbackHandler.trackWindow(Window.getWindow()); // set up the gateways keybind key tracking
|
||||
MouseCallbackHandler.trackWindow(Window.getWindow());
|
||||
}
|
||||
|
||||
/**
|
||||
* Things that should be ticked: Entities when deciding an action, in-game timers (such as smelting), the in-game time
|
||||
|
@ -167,6 +160,12 @@ public class Litecraft extends Game
|
|||
// Open the title screen if it's not already open.
|
||||
if (GingerRegister.getInstance().currentScreen == null && world == null)
|
||||
engine.openScreen(new TitleScreen());
|
||||
|
||||
if (data.player != null && data.camera != null)
|
||||
{
|
||||
data.player.updateMovement();
|
||||
data.camera.updateMovement();
|
||||
}
|
||||
}
|
||||
|
||||
// @formatter=off
|
||||
|
|
|
@ -29,6 +29,6 @@ public class ExitGameScreen extends Screen
|
|||
{}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
public void cleanup()
|
||||
{ infoText.remove(); }
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class IngameHUD extends Screen
|
|||
{
|
||||
debugText = ginger3D.registerText("Loading...", 2, new Vector2f(0, 0), 1f, true, "debugInfo");
|
||||
debugText.setBorderWidth(0.5f);
|
||||
positionText = ginger3D.registerText("Loading...", 2, new Vector2f(0, -0.1f), 1f, true, "debugInfo");
|
||||
positionText = ginger3D.registerText("Loading...", 2, new Vector2f(0, -0.1f), 1f, true, "posInfo");
|
||||
positionText.setBorderWidth(0.5f);
|
||||
}
|
||||
|
||||
|
@ -35,15 +35,15 @@ public class IngameHUD extends Screen
|
|||
// long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
long totalMemory = Runtime.getRuntime().totalMemory();
|
||||
long freeMemory = Runtime.getRuntime().freeMemory();
|
||||
long usedMemory = totalMemory - freeMemory;
|
||||
long usedMemory = (totalMemory - freeMemory) / 1024 / 1024;
|
||||
Vector4i dbg = litecraft.dbgStats;
|
||||
Vector3f position = GingerRegister.getInstance().game.data.player.getPosition();
|
||||
debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z + " Mem: " + (usedMemory / 1024 / 1024) + "MB / " + (totalMemory / 1024 / 1024) + " MB");
|
||||
positionText.setText("Position " + (int) position.x() + ", " + (int) position.y() + ", "+ (int) position.z() );
|
||||
debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y() + " TPS: " + dbg.z() + " TWL: " + dbg.w() + " Mem: " + usedMemory + "MB");
|
||||
positionText.setText("Position: " + (int) position.x() + ", " + (int) position.y() + ", "+ (int) position.z() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
public void cleanup()
|
||||
{
|
||||
debugText.remove();
|
||||
positionText.remove();
|
||||
|
|
|
@ -41,7 +41,7 @@ public class TitleScreen extends Screen
|
|||
public void tick()
|
||||
{
|
||||
Vector4i dbg = litecraft.dbgStats;
|
||||
debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z);
|
||||
debugText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y() + " TPS: " + dbg.z() + " TWL: " + dbg.w());
|
||||
playButton.update();
|
||||
if (playButton.isClicked())
|
||||
{
|
||||
|
@ -49,14 +49,14 @@ public class TitleScreen extends Screen
|
|||
|
||||
if (Litecraft.getInstance().getWorld() == null)
|
||||
{
|
||||
Litecraft.getInstance().setSave(new LitecraftSave("cegregatedordinaldata", false));
|
||||
Litecraft.getInstance().setSave(new LitecraftSave("SegregatedOrdinalData", false));
|
||||
Litecraft.getInstance().changeWorld(Litecraft.getInstance().getSave().getWorldOrCreate(Dimensions.OVERWORLD));
|
||||
ginger3D.setGingerPlayer(Litecraft.getInstance().getWorld().player);
|
||||
}
|
||||
if (Litecraft.getInstance().getWorld() != null)
|
||||
{
|
||||
ginger3D.openScreen(new IngameHUD());
|
||||
this.close();
|
||||
this.cleanup();
|
||||
}
|
||||
//TODO: add world creation gui so it takes u to world creation place
|
||||
//TODO: add a texture to be rendered behind the gui as an option
|
||||
|
@ -64,7 +64,7 @@ public class TitleScreen extends Screen
|
|||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
public void cleanup()
|
||||
{
|
||||
this.debugText.remove();
|
||||
this.playButton.hide(Litecraft.getInstance().data.guis);
|
||||
|
|
|
@ -197,7 +197,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
public void unloadAllChunks()
|
||||
{
|
||||
LongList chunkPositions = new LongArrayList();
|
||||
@SuppressWarnings("rawtypes") List<CompletableFuture> futures = new ArrayList<>();
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
if (this.chunks != null)
|
||||
{
|
||||
this.chunks.forEach((pos, chunk) ->
|
||||
|
|
|
@ -76,6 +76,10 @@ public class Window
|
|||
}
|
||||
}
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
|
||||
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
|
||||
window = GLFW.glfwCreateWindow(actualWidth, actualHeight, title, (fullscreen) ? GLFW.glfwGetPrimaryMonitor() : 0, getWindow());
|
||||
|
@ -98,7 +102,7 @@ public class Window
|
|||
oldWindowHeight = getHeight();
|
||||
}
|
||||
|
||||
public static void create(int width, int height, String title, int fpsCap, RenderAPI api)
|
||||
public static void create(int width, int height, String title, float fpsCap, RenderAPI api)
|
||||
{
|
||||
Window.width = width / 2;
|
||||
Window.height = height / 2;
|
||||
|
|
|
@ -30,35 +30,6 @@ public class NormalMappedObjLoader
|
|||
v2.addTangent(tangent);
|
||||
}
|
||||
|
||||
private static float convertDataToArrays(List<VertexNM> vertices, List<Vector2f> textures,
|
||||
List<Vector3f> normals, float[] verticesArray, float[] texturesArray,
|
||||
float[] normalsArray, float[] tangentsArray)
|
||||
{
|
||||
float furthestPoint = 0;
|
||||
for (int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
VertexNM currentVertex = vertices.get(i);
|
||||
if (currentVertex.getLength() > furthestPoint)
|
||||
{ furthestPoint = currentVertex.getLength(); }
|
||||
Vector3f position = currentVertex.getPosition();
|
||||
Vector2f textureCoord = textures.get(currentVertex.getTextureIndex());
|
||||
Vector3f normalVector = normals.get(currentVertex.getNormalIndex());
|
||||
Vector3f tangent = currentVertex.getAverageTangent();
|
||||
verticesArray[i * 3] = position.x;
|
||||
verticesArray[i * 3 + 1] = position.y;
|
||||
verticesArray[i * 3 + 2] = position.z;
|
||||
texturesArray[i * 2] = textureCoord.x;
|
||||
texturesArray[i * 2 + 1] = 1 - textureCoord.y;
|
||||
normalsArray[i * 3] = normalVector.x;
|
||||
normalsArray[i * 3 + 1] = normalVector.y;
|
||||
normalsArray[i * 3 + 2] = normalVector.z;
|
||||
tangentsArray[i * 3] = tangent.x;
|
||||
tangentsArray[i * 3 + 1] = tangent.y;
|
||||
tangentsArray[i * 3 + 2] = tangent.z;
|
||||
}
|
||||
return furthestPoint;
|
||||
}
|
||||
|
||||
private static int[] convertIndicesListToArray(List<Integer> indices)
|
||||
{
|
||||
int[] indicesArray = new int[indices.size()];
|
||||
|
@ -161,10 +132,6 @@ public class NormalMappedObjLoader
|
|||
float[] texturesArray = new float[vertices.size() * 2];
|
||||
float[] normalsArray = new float[vertices.size() * 3];
|
||||
float[] tangentsArray = new float[vertices.size() * 3];
|
||||
@SuppressWarnings("unused")
|
||||
//some weird eclipse only error here i think
|
||||
float furthest = convertDataToArrays(vertices, textures, normals, verticesArray,
|
||||
texturesArray, normalsArray, tangentsArray);
|
||||
int[] indicesArray = convertIndicesListToArray(indices);
|
||||
return GlLoader.loadToVAO(verticesArray, indicesArray, normalsArray, tangentsArray, texturesArray);
|
||||
}
|
||||
|
|
|
@ -87,11 +87,4 @@ public class StaticCube
|
|||
{ mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); }
|
||||
return mesh;
|
||||
}
|
||||
|
||||
public static void scaleCube(float multiplier)
|
||||
{
|
||||
for (int i = 0; i < vertices.length; i++)
|
||||
{ vertices[i] = vertices[i] * multiplier; }
|
||||
mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ public abstract class Screen
|
|||
|
||||
public abstract void tick();
|
||||
|
||||
public abstract void close();
|
||||
public abstract void cleanup();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class GingerGL
|
|||
|
||||
public void openScreen(Screen screen)
|
||||
{
|
||||
if (registry.currentScreen != null) registry.currentScreen.close();
|
||||
if (registry.currentScreen != null) registry.currentScreen.cleanup();
|
||||
registry.currentScreen = screen;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,12 +75,13 @@ public class BinaryData implements Iterable<Map.Entry<String, BaseDataSection>>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, BaseDataSection>> iterator() {
|
||||
return this.sections.entrySet().iterator();
|
||||
}
|
||||
public Iterator<Map.Entry<String, BaseDataSection>> iterator()
|
||||
{ return this.sections.entrySet().iterator(); }
|
||||
|
||||
public static BinaryData read(File file) throws SODParseException {
|
||||
try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
|
||||
public static BinaryData read(File file) throws SODParseException
|
||||
{
|
||||
try (DataInputStream dis = new DataInputStream(new FileInputStream(file)))
|
||||
{
|
||||
long magic = dis.readLong();
|
||||
|
||||
if (magic != 0xA77D1E) {
|
||||
|
@ -88,9 +89,11 @@ public class BinaryData implements Iterable<Map.Entry<String, BaseDataSection>>
|
|||
}
|
||||
|
||||
return Parser.parse(dis);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println("Error in parsing file " + file.toString());
|
||||
e.printStackTrace();
|
||||
//throw new SODParseException("Error in parsing file " + file.toString());
|
||||
return new BinaryData();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue