public GameEngine(String windowTitle, int width, int height, boolean vSync, IGameLogic gameLogic) throws Exception { gameLoopThread = new Thread(this, "GAME_LOOP_THREAD"); window = new Window(windowTitle, width, height, vSync); this.gameLogic = gameLogic; timer = new Timer(); }
@Override public void render(Window window) { if ( window.isResized() ) { glViewport(0, 0, window.getWidth(), window.getHeight()); window.setResized(false); } window.setClearColor(color, color, color, 0.0f); renderer.clear(); } }
@Override public void input(Window window) { if (window.isKeyPressed(GLFW_KEY_UP)) { direction = 1; } else if (window.isKeyPressed(GLFW_KEY_DOWN)) { direction = -1; } else { direction = 0; } }
protected void render() { if ( window.getWindowOptions().showFps && timer.getLastLoopTime() - lastFps > 1 ) { lastFps = timer.getLastLoopTime(); window.setWindowTitle(windowTitle + " - " + fps + " FPS"); fps = 0; } fps++; gameLogic.render(window); window.update(); }
protected void gameLoop() { float elapsedTime; float accumulator = 0f; float interval = 1f / TARGET_UPS; boolean running = true; while (running && !window.windowShouldClose()) { elapsedTime = timer.getElapsedTime(); accumulator += elapsedTime; input(); while (accumulator >= interval) { update(interval); accumulator -= interval; } render(); if ( !window.isvSync() ) { sync(); } } }
protected void init() throws Exception { window.init(); timer.init(); gameLogic.init(); }
protected void render() { gameLogic.render(window); window.update(); } }
public void init(Window window) { glfwSetCursorPosCallback(window.getWindowHandle(), (windowHandle, xpos, ypos) -> { currentPos.x = xpos; currentPos.y = ypos; }); glfwSetCursorEnterCallback(window.getWindowHandle(), (windowHandle, entered) -> { inWindow = entered; }); glfwSetMouseButtonCallback(window.getWindowHandle(), (windowHandle, button, action, mode) -> { leftButtonPressed = button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS; rightButtonPressed = button == GLFW_MOUSE_BUTTON_2 && action == GLFW_PRESS; }); }
protected void gameLoop() { float elapsedTime; float accumulator = 0f; float interval = 1f / TARGET_UPS; boolean running = true; while (running && !window.windowShouldClose()) { elapsedTime = timer.getElapsedTime(); accumulator += elapsedTime; input(); while (accumulator >= interval) { update(interval); accumulator -= interval; } render(); if ( !window.isvSync() ) { sync(); } } }
protected void init() throws Exception { window.init(); timer.init(); gameLogic.init(); }
protected void render() { gameLogic.render(window); window.update(); } }
public void init(Window window) { glfwSetCursorPosCallback(window.getWindowHandle(), (windowHandle, xpos, ypos) -> { currentPos.x = xpos; currentPos.y = ypos; }); glfwSetCursorEnterCallback(window.getWindowHandle(), (windowHandle, entered) -> { inWindow = entered; }); glfwSetMouseButtonCallback(window.getWindowHandle(), (windowHandle, button, action, mode) -> { leftButtonPressed = button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS; rightButtonPressed = button == GLFW_MOUSE_BUTTON_2 && action == GLFW_PRESS; }); }
protected void render() { if ( window.getWindowOptions().showFps && timer.getLastLoopTime() - lastFps > 1 ) { lastFps = timer.getLastLoopTime(); window.setWindowTitle(windowTitle + " - " + fps + " FPS"); fps = 0; } fps++; gameLogic.render(window); window.update(); }
public void render(Window window, Camera camera, GameItem[] gameItems, SceneLight sceneLight, IHud hud) { clear(); if ( window.isResized() ) { glViewport(0, 0, window.getWidth(), window.getHeight()); window.setResized(false); } renderScene(window, camera, gameItems, sceneLight); renderHud(window, hud); }
protected void gameLoop() { float elapsedTime; float accumulator = 0f; float interval = 1f / TARGET_UPS; boolean running = true; while (running && !window.windowShouldClose()) { elapsedTime = timer.getElapsedTime(); accumulator += elapsedTime; input(); while (accumulator >= interval) { update(interval); accumulator -= interval; } render(); if (!window.isvSync()) { sync(); } } }
public GameEngine(String windowTitle, int width, int height, boolean vSync, IGameLogic gameLogic) throws Exception { gameLoopThread = new Thread(this, "GAME_LOOP_THREAD"); window = new Window(windowTitle, width, height, vSync); this.gameLogic = gameLogic; timer = new Timer(); }
protected void init() throws Exception { window.init(); timer.init(); mouseInput.init(window); gameLogic.init(window); }