| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | #include <iostream>#include "client/rendering/wrapper/GLFWWrapper.h"#include "client/rendering/WindowSize.h"#include "client/rendering/wrapper/Window.h"#include "client/rendering/Shaders.h"#include "client/rendering/Framebuffers.h"#include "client/input/Keys.h"#include "client/input/MouseButtons.h"#include "client/Engine.h"bool initGLEW() {    GLenum err = glewInit();    if(err != GLEW_OK) {        std::cout << "could not initialize GLEW: " << glewGetErrorString(err) << "\n";        return true;    }    std::cout << "using GLEW " << glewGetString(GLEW_VERSION) << "\n";    return false;}void initCallbacks(Window& w, WindowSize& size, Framebuffers& framebuffers, Keys& keys, MouseButtons& buttons) {    static WindowSize& cSize = size;    static Framebuffers& cFramebuffers = framebuffers;    static Keys& cKeys = keys;    static MouseButtons& cButtons = buttons;    w.setFramebufferSizeCallback([](GLFWwindow*, int newWidth, int newHeight) {        glViewport(0, 0, newWidth, newHeight);        cSize.width = newWidth;        cSize.height = newHeight;        cFramebuffers.resize(newWidth, newHeight);    });    w.setKeyCallback([](GLFWwindow*, int key, int, int action, int) {        if(action == GLFW_PRESS) {            cKeys.press(key);        } else if(action == GLFW_RELEASE) {            cKeys.release(key);        }    });    w.setMouseButtonCallback([](GLFWwindow*, int button, int action, int) {        if(action == GLFW_PRESS) {            cButtons.press(button);        } else if(action == GLFW_RELEASE) {            cButtons.release(button);        }    });    w.setCursorPosCallback([](GLFWwindow*, double x, double y) {        cButtons.move(x, y);    });}int main() {    if(GLFWWrapper::hasError()) {        return 0;    }        WindowSize size(1024, 620);    Window window(size, "Test");    if(window.hasError() || initGLEW()) {        return 0;    }        Shaders shaders;    if(shaders.hasError()) {        return 0;    }        Framebuffers framebuffers(size);    if(framebuffers.hasError()) {        return 0;    }        Keys keys;    MouseButtons mButtons;    initCallbacks(window, size, framebuffers, keys, mButtons);        Engine engine(shaders, framebuffers, keys, mButtons, size);    window.show();    const u64 nanosPerTick = 50000000;    u64 lastTime = GLFWWrapper::getTimeNanos();    u64 lag = 0;    while(!window.shouldClose() && engine.isRunning()) {        engine.renderTick((float) lag / nanosPerTick);        window.swapBuffers();        u64 newTime = GLFWWrapper::getTimeNanos();        lag += newTime - lastTime;        lastTime = newTime;        while(lag >= nanosPerTick) {            lag -= nanosPerTick;            keys.tick();            mButtons.tick();            engine.tick();            mButtons.postTick();        }        glfwPollEvents();    }    return 0;}
 |