Fixed NPE on Alt-F4 and partially implemented fullscreen key
parent
087dfc40f1
commit
aeb5969684
|
@ -78,12 +78,16 @@ public class Litecraft extends Game
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupKeybinds()
|
private void setupKeybinds()
|
||||||
{ Input.addPressCallback(Keybind.EXIT, this::exit); }
|
{
|
||||||
|
Input.addPressCallback(Keybind.EXIT, this::exit);
|
||||||
|
Input.addPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit()
|
public void exit()
|
||||||
{
|
{
|
||||||
this.world.unloadAllChunks();
|
if (this.world != null)
|
||||||
|
this.world.unloadAllChunks();
|
||||||
ginger3D.cleanup();
|
ginger3D.cleanup();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
@ -120,9 +124,9 @@ public class Litecraft extends Game
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
|
tps++;
|
||||||
Input.invokeAllListeners();
|
Input.invokeAllListeners();
|
||||||
data.player.updateMovement();
|
data.player.updateMovement();
|
||||||
tps++;
|
|
||||||
if (Window.isKeyDown(GLFW.GLFW_KEY_TAB))
|
if (Window.isKeyDown(GLFW.GLFW_KEY_TAB))
|
||||||
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
|
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public final class LitecraftSave
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = new World(seed, 2, dim, this); // create new world with seed read from file or 0, if it could not be read
|
World world = new World(seed, 10, dim, this); // create new world with seed read from file or 0, if it could not be read
|
||||||
world.spawnPlayer(); // spawn player in world
|
world.spawnPlayer(); // spawn player in world
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,11 +137,11 @@ public class World implements BlockAccess, WorldGenConstants
|
||||||
public void unloadAllChunks()
|
public void unloadAllChunks()
|
||||||
{
|
{
|
||||||
LongList chunkPositions = new LongArrayList();
|
LongList chunkPositions = new LongArrayList();
|
||||||
|
if (this.chunks != null)
|
||||||
this.chunks.forEach((pos, chunk) -> { // for every chunk in memory
|
this.chunks.forEach((pos, chunk) -> { // for every chunk in memory
|
||||||
chunkPositions.add((long) pos); // add pos to chunk positions list for removal later
|
chunkPositions.add((long) pos); // add pos to chunk positions list for removal later
|
||||||
this.save.saveChunk(chunk); // save chunk
|
this.save.saveChunk(chunk); // save chunk
|
||||||
});
|
});
|
||||||
|
|
||||||
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
|
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ import com.github.hydos.ginger.engine.render.texture.Image;
|
||||||
|
|
||||||
public class Window
|
public class Window
|
||||||
{
|
{
|
||||||
|
public static boolean isFullscreen()
|
||||||
|
{ return fullscreen; }
|
||||||
|
|
||||||
public static int width;
|
public static int width;
|
||||||
public static int height;
|
public static int height;
|
||||||
private static String title;
|
private static String title;
|
||||||
|
@ -19,7 +22,7 @@ public class Window
|
||||||
private static boolean[] mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
|
private static boolean[] mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
|
||||||
private static GLFWImage.Buffer iconBuffer = null;
|
private static GLFWImage.Buffer iconBuffer = null;
|
||||||
private static double fpsCap, time, processedTime = 0;
|
private static double fpsCap, time, processedTime = 0;
|
||||||
private static boolean isFullscreen = false;
|
private static boolean fullscreen = false;
|
||||||
public static double dy = 0;
|
public static double dy = 0;
|
||||||
public static double dx = 0;
|
public static double dx = 0;
|
||||||
static double oldX = 0;
|
static double oldX = 0;
|
||||||
|
@ -46,7 +49,7 @@ public class Window
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
|
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
|
||||||
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
|
||||||
window = GLFW.glfwCreateWindow(actuallWidth, actuallHeight, title, (isFullscreen) ? GLFW.glfwGetPrimaryMonitor() : 0, window);
|
window = GLFW.glfwCreateWindow(actuallWidth, actuallHeight, title, (fullscreen) ? GLFW.glfwGetPrimaryMonitor() : 0, window);
|
||||||
if (window == 0)
|
if (window == 0)
|
||||||
{
|
{
|
||||||
System.err.println("Error: Couldnt initilize window");
|
System.err.println("Error: Couldnt initilize window");
|
||||||
|
@ -188,6 +191,9 @@ public class Window
|
||||||
oldY = newY;
|
oldY = newY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFullscreen(boolean t)
|
public static void fullscreen()
|
||||||
{ Window.isFullscreen = t; }
|
{
|
||||||
|
Window.fullscreen = !Window.isFullscreen();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public final class Keybind
|
||||||
public static final Keybind SELECT_1 = new Keybind(GLFW.GLFW_KEY_2, false);
|
public static final Keybind SELECT_1 = new Keybind(GLFW.GLFW_KEY_2, false);
|
||||||
public static final Keybind SELECT_2 = new Keybind(GLFW.GLFW_KEY_3, false);
|
public static final Keybind SELECT_2 = new Keybind(GLFW.GLFW_KEY_3, false);
|
||||||
public static final Keybind EXIT = new Keybind(GLFW.GLFW_KEY_ESCAPE, false);
|
public static final Keybind EXIT = new Keybind(GLFW.GLFW_KEY_ESCAPE, false);
|
||||||
|
public static final Keybind FULLSCREEN = new Keybind(GLFW.GLFW_KEY_F11, false);
|
||||||
public int value;
|
public int value;
|
||||||
public boolean mouse;
|
public boolean mouse;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue