Fixed NPE on Alt-F4 and partially implemented fullscreen key

pull/12/head
Caroline Bell 2020-02-27 14:34:33 -08:00
parent 087dfc40f1
commit aeb5969684
5 changed files with 24 additions and 13 deletions

View File

@ -78,12 +78,16 @@ public class Litecraft extends Game
}
private void setupKeybinds()
{ Input.addPressCallback(Keybind.EXIT, this::exit); }
{
Input.addPressCallback(Keybind.EXIT, this::exit);
Input.addPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
}
@Override
public void exit()
{
this.world.unloadAllChunks();
if (this.world != null)
this.world.unloadAllChunks();
ginger3D.cleanup();
System.exit(0);
}
@ -120,9 +124,9 @@ public class Litecraft extends Game
@Override
public void tick()
{
tps++;
Input.invokeAllListeners();
data.player.updateMovement();
tps++;
if (Window.isKeyDown(GLFW.GLFW_KEY_TAB))
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
}

View File

@ -96,7 +96,7 @@ public final class LitecraftSave
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
return world;
}

View File

@ -137,11 +137,11 @@ public class World implements BlockAccess, WorldGenConstants
public void unloadAllChunks()
{
LongList chunkPositions = new LongArrayList();
this.chunks.forEach((pos, chunk) -> { // for every chunk in memory
chunkPositions.add((long) pos); // add pos to chunk positions list for removal later
this.save.saveChunk(chunk); // save chunk
});
if (this.chunks != null)
this.chunks.forEach((pos, chunk) -> { // for every chunk in memory
chunkPositions.add((long) pos); // add pos to chunk positions list for removal later
this.save.saveChunk(chunk); // save chunk
});
chunkPositions.forEach((LongConsumer) (pos -> this.chunks.remove(pos))); // remove all chunks
}

View File

@ -11,6 +11,9 @@ import com.github.hydos.ginger.engine.render.texture.Image;
public class Window
{
public static boolean isFullscreen()
{ return fullscreen; }
public static int width;
public static int height;
private static String title;
@ -19,7 +22,7 @@ public class Window
private static boolean[] mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private static GLFWImage.Buffer iconBuffer = null;
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 dx = 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_RESIZABLE, GLFW.GLFW_TRUE);
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)
{
System.err.println("Error: Couldnt initilize window");
@ -188,6 +191,9 @@ public class Window
oldY = newY;
}
public void setFullscreen(boolean t)
{ Window.isFullscreen = t; }
public static void fullscreen()
{
Window.fullscreen = !Window.isFullscreen();
}
}

View File

@ -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_2 = new Keybind(GLFW.GLFW_KEY_3, 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 boolean mouse;