Browse Source

core update

Kajetan Johannes Hammerle 3 years ago
parent
commit
a671d4ec89
5 changed files with 34 additions and 61 deletions
  1. 16 7
      Game.cpp
  2. 8 7
      Game.h
  3. 7 44
      Main.cpp
  4. 1 1
      gaming-core
  5. 2 2
      meson.build

+ 16 - 7
Game.cpp

@@ -12,13 +12,18 @@ Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
            Buttons& buttons, const Size& size)
     : shader(shader), noiceShader(noiceShader), noiceBuffer(buffer),
       buttons(buttons), size(size), frustum(60, 0.1f, 1000.0f, size),
-      up(buttons.add(GLFW_KEY_SPACE, "Up")),
-      down(buttons.add(GLFW_KEY_LEFT_SHIFT, "Down")),
-      left(buttons.add(GLFW_KEY_A, "left")),
-      right(buttons.add(GLFW_KEY_D, "right")),
-      front(buttons.add(GLFW_KEY_W, "front")),
-      back(buttons.add(GLFW_KEY_S, "back")),
-      toggle(buttons.add(GLFW_KEY_T, "toggle")), oldHeight(0.0f), height(0.0f) {
+      up(GLFW_KEY_SPACE, "Up"), down(GLFW_KEY_LEFT_SHIFT, "Down"),
+      left(GLFW_KEY_A, "left"), right(GLFW_KEY_D, "right"),
+      front(GLFW_KEY_W, "front"), back(GLFW_KEY_S, "back"),
+      toggle(GLFW_KEY_T, "toggle"), oldHeight(0.0f), height(0.0f) {
+    buttons.add(up);
+    buttons.add(down);
+    buttons.add(left);
+    buttons.add(right);
+    buttons.add(front);
+    buttons.add(back);
+    buttons.add(toggle);
+
     rectangleBuffer.setAttributes(Attributes().addFloat(2));
     float data[6][2] = {{-1.0f, -1.0f}, {-1.0, 1.0}, {1.0, -1.0},
                         {1.0f, 1.0f},   {-1.0, 1.0}, {1.0, -1.0}};
@@ -82,3 +87,7 @@ void Game::tick() {
         position -= Vector3(0.0f, 0.0f, speed);
     }
 }
+
+bool Game::isRunning() const {
+    return true;
+}

+ 8 - 7
Game.h

@@ -18,13 +18,13 @@ class Game final {
     VertexBuffer emptyBuffer;
     Frustum frustum;
 
-    Button& up;
-    Button& down;
-    Button& left;
-    Button& right;
-    Button& front;
-    Button& back;
-    Button& toggle;
+    Button up;
+    Button down;
+    Button left;
+    Button right;
+    Button front;
+    Button back;
+    Button toggle;
     Vector3 oldPosition;
     Vector3 position;
     float oldHeight;
@@ -36,6 +36,7 @@ public:
 
     void render(float lag);
     void tick();
+    bool isRunning() const;
 };
 
 #endif

+ 7 - 44
Main.cpp

@@ -1,31 +1,15 @@
 #include "Game.h"
 #include "LayeredFramebuffer.h"
-#include "gaming-core/input/Buttons.h"
 #include "gaming-core/rendering/Shader.h"
 #include "gaming-core/rendering/Window.h"
-#include "gaming-core/rendering/WindowOptions.h"
-#include "gaming-core/utils/Clock.h"
 #include "gaming-core/wrapper/GL.h"
-#include "gaming-core/wrapper/GLEW.h"
-#include "gaming-core/wrapper/GLFW.h"
-
-void updateSize(const Window& window, Size& size) {
-    Size newSize = window.getSize();
-    if(newSize.width != size.width || newSize.height != size.height) {
-        size = newSize;
-        GL::setViewport(size.width, size.height);
-    }
-}
 
 int main() {
-    if(GLFW::init()) {
-        return 0;
-    }
-
-    Size size(1024, 620);
-    WindowOptions options(4, 0, size, false, "test");
-    Window window(options);
-    if(window.hasError() || GLEW::init()) {
+    WindowOptions options(4, 0, {1024, 620}, false, "test");
+    TextInput* input = nullptr;
+    Window w(input, options);
+    if(w.getError().has()) {
+        std::cout << w.getError().message << '\n';
         return 0;
     }
 
@@ -46,30 +30,9 @@ int main() {
         return 0;
     }
 
-    Buttons buttons(window);
-    Clock fps;
-
-    window.show();
-
-    Game game(shader, noiceShader, buffer, buttons, size);
-
+    Game game(shader, noiceShader, buffer, w.getButtons(), w.getSize());
     GL::printError("setup error");
     GL::enableDepthTesting();
-
-    const Clock::Nanos nanosPerTick = 50000000;
-    Clock::Nanos lag = 0;
-    while(!window.shouldClose()) {
-        GL::printError("loop error");
-        updateSize(window, size);
-        game.render(static_cast<float>(lag) / nanosPerTick);
-        window.swapBuffers();
-        lag += fps.update();
-        while(lag >= nanosPerTick) {
-            lag -= nanosPerTick;
-            buttons.tick();
-            game.tick();
-        }
-        glfwPollEvents();
-    }
+    w.run(game, 50'000'000);
     return 0;
 }

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 48800a9c38ca720dbdc9132109def675c65f99e1
+Subproject commit 35425beaa48eab218b807971ff8d8294eb3ca6f3

+ 2 - 2
meson.build

@@ -6,9 +6,8 @@ sources = ['Main.cpp',
     'LayeredFramebuffer.cpp',
     'gaming-core/utils/Size.cpp',
     'gaming-core/utils/Clock.cpp',
-    'gaming-core/wrapper/GLFW.cpp',
+    'gaming-core/utils/Error.cpp',
     'gaming-core/wrapper/GL.cpp',
-    'gaming-core/wrapper/GLEW.cpp',
     'gaming-core/rendering/Window.cpp',
     'gaming-core/rendering/WindowOptions.cpp',
     'gaming-core/rendering/Shader.cpp',
@@ -21,6 +20,7 @@ sources = ['Main.cpp',
     'gaming-core/math/Matrix.cpp',
     'gaming-core/math/Quaternion.cpp',
     'gaming-core/math/Vector.cpp',
+    'gaming-core/input/TextInput.cpp',
     'gaming-core/input/Button.cpp',
     'gaming-core/input/Buttons.cpp']