|
@@ -3,89 +3,71 @@
|
|
|
#include "gaming-core/wrapper/GLFW.h"
|
|
|
#include "gaming-core/wrapper/GL.h"
|
|
|
#include "gaming-core/wrapper/GLEW.h"
|
|
|
-#include "gaming-core/utils/Size.h"
|
|
|
-#include "client/rendering/wrapper/Window.h"
|
|
|
+#include "gaming-core/wrapper/Window.h"
|
|
|
#include "client/rendering/Shaders.h"
|
|
|
#include "client/rendering/Framebuffers.h"
|
|
|
-#include "client/input/Control.h"
|
|
|
+#include "client/input/Controller.h"
|
|
|
#include "client/rendering/Engine.h"
|
|
|
#include "gaming-core/utils/Clock.h"
|
|
|
#include "client/rendering/RenderSettings.h"
|
|
|
+#include "gaming-core/wrapper/WindowOptions.h"
|
|
|
|
|
|
-void initCallbacks(Window& w, Size& size, Framebuffers& framebuffers, Control& control) {
|
|
|
- static Size& cSize = size;
|
|
|
- static Framebuffers& cFramebuffers = framebuffers;
|
|
|
- static Control& cControl = control;
|
|
|
- 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) {
|
|
|
- cControl.keys.press(key);
|
|
|
- } else if(action == GLFW_RELEASE) {
|
|
|
- cControl.keys.release(key);
|
|
|
- }
|
|
|
- });
|
|
|
- w.setMouseButtonCallback([](GLFWwindow*, int button, int action, int) {
|
|
|
- if(action == GLFW_PRESS) {
|
|
|
- cControl.buttons.press(button);
|
|
|
- } else if(action == GLFW_RELEASE) {
|
|
|
- cControl.buttons.release(button);
|
|
|
- }
|
|
|
- });
|
|
|
- w.setCursorPosCallback([](GLFWwindow*, double x, double y) {
|
|
|
- cControl.buttons.move(x, y);
|
|
|
- });
|
|
|
+void updateSize(const Window& window, Size& size, Framebuffers& framebuffers) {
|
|
|
+ Size newSize = window.getSize();
|
|
|
+ if(newSize.width != size.width || newSize.height != size.height) {
|
|
|
+ size = newSize;
|
|
|
+ GL::setViewport(size.width, size.height);
|
|
|
+ framebuffers.resize(size);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int main() {
|
|
|
if(GLFW::init()) {
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Size size(1024, 620);
|
|
|
- Window window(size, "Test");
|
|
|
+ WindowOptions options(4, 0, size, false, "test");
|
|
|
+ Window window(options);
|
|
|
if(window.hasError() || GLEW::init()) {
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Shaders shaders;
|
|
|
if(shaders.hasError()) {
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Framebuffers framebuffers(size);
|
|
|
if(framebuffers.hasError()) {
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
RenderSettings renderSettings;
|
|
|
Engine engine(shaders, framebuffers, size, renderSettings);
|
|
|
-
|
|
|
- Control control;
|
|
|
+
|
|
|
+ Buttons buttons(window);
|
|
|
+ Controller controller(buttons);
|
|
|
Clock fps;
|
|
|
Clock tps;
|
|
|
- static Game game(control, fps, tps, renderSettings, size);
|
|
|
+ static Game game(controller, fps, tps, renderSettings, size);
|
|
|
|
|
|
- initCallbacks(window, size, framebuffers, control);
|
|
|
window.show();
|
|
|
-
|
|
|
+
|
|
|
GL::checkAndPrintError("setup error");
|
|
|
|
|
|
const Clock::Nanos nanosPerTick = 50000000;
|
|
|
Clock::Nanos lag = 0;
|
|
|
while(!window.shouldClose() && game.isRunning()) {
|
|
|
GL::checkAndPrintError("loop error");
|
|
|
+ updateSize(window, size, framebuffers);
|
|
|
engine.renderTick(static_cast<float> (lag) / nanosPerTick, game);
|
|
|
window.swapBuffers();
|
|
|
lag += fps.update();
|
|
|
while(lag >= nanosPerTick) {
|
|
|
lag -= nanosPerTick;
|
|
|
tps.update();
|
|
|
- control.tick();
|
|
|
+ buttons.tick();
|
|
|
game.tick();
|
|
|
}
|
|
|
glfwPollEvents();
|