Browse Source

better formatting

Kajetan Johannes Hammerle 5 months ago
parent
commit
70e30ee8d3

+ 2 - 1
Game.cpp

@@ -52,7 +52,8 @@ void Game::tick() {
 
 void Game::render(float lag, Renderer& renderer) const {
     renderer.translateTo(0.0f, 0.0f).update();
-    renderer.drawRectangle(lastX + (x - lastX) * lag, lastY + (y - lastY) * lag, playerWidth, playerHeight, Color4(255, 0, 0, 255));
+    renderer.drawRectangle(lastX + (x - lastX) * lag, lastY + (y - lastY) * lag, playerWidth, playerHeight,
+                           Color4(255, 0, 0, 255));
     renderer.translateTo(0.0f, 0.0f).update();
     StringBuffer<100> s;
     s.append("FPS: ").append(fps.getUpdatesPerSecond());

+ 5 - 6
Game.h

@@ -3,10 +3,14 @@
 
 #include "input/Buttons.h"
 #include "input/Controller.h"
-#include "utils/Clock.h"
 #include "rendering/Renderer.h"
+#include "utils/Clock.h"
 
 class Game final {
+    const Controller& controller;
+    const Clock& fps;
+    const Clock& tps;
+
 public:
     Game(Controller& c, const Clock& fps, const Clock& tps);
 
@@ -14,11 +18,6 @@ public:
     void render(float lag, Renderer& renderer) const;
 
     bool isRunning() const;
-
-private:
-    const Controller& controller;
-    const Clock& fps;
-    const Clock& tps;
 };
 
 #endif

+ 14 - 19
Main.cpp

@@ -1,29 +1,24 @@
 #include <iostream>
-#include <bits/getopt_core.h>
 
-#include "gaming-core/wrapper/GLFW.h"
+#include <getopt.h>
+
+#include "Game.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"
+#include "gaming-core/wrapper/Shader.h"
 #include "gaming-core/wrapper/Window.h"
 #include "gaming-core/wrapper/WindowOptions.h"
-#include "gaming-core/utils/Clock.h"
-#include "gaming-core/wrapper/Shader.h"
 #include "rendering/Renderer.h"
-#include "Game.h"
 
 bool parseArgs(int argAmount, char* const* args, WindowOptions& options) {
     while(true) {
         switch(getopt(argAmount, args, "fv")) {
-            case '?':
-                return true;
-            case 'f':
-                options.fullscreen = true;
-                break;
-            case 'v':
-                options.vsync = true;
-                break;
-            case -1:
-                return false;
+            case '?': return true;
+            case 'f': options.fullscreen = true; break;
+            case 'v': options.vsync = true; break;
+            case -1: return false;
         }
     }
 }
@@ -38,7 +33,7 @@ int main(int argAmount, char* const* args) {
     if(window.hasError() || GLEW::init()) {
         return 0;
     }
-    
+
     Shader shader("resources/shader/vertex.vs", "resources/shader/fragment.fs");
     if(shader.hasError()) {
         return 0;
@@ -67,7 +62,7 @@ int main(int argAmount, char* const* args) {
             buttons.tick();
             game.tick();
         }
-        
+
         Size size = window.getSize();
         GL::setViewport(size.width, size.height);
 
@@ -76,10 +71,10 @@ int main(int argAmount, char* const* args) {
         view.translate(Vector3(-1.0f, 1.0f, 0.0f));
         shader.setMatrix("view", view.getValues());
 
-        game.render(static_cast<float> (lag) / nanosPerTick, renderer);
+        game.render(static_cast<float>(lag) / nanosPerTick, renderer);
         window.swapBuffers();
         GL::clearFramebuffer();
-        
+
         glfwPollEvents();
     }
     return 0;

+ 6 - 5
input/Controller.cpp

@@ -1,9 +1,10 @@
 #include "input/Controller.h"
 
-Controller::Controller(Buttons& bs) : list(bs.get()), a(bs.add(GLFW_KEY_A, "A")), b(bs.add(GLFW_KEY_S, "B")),
-x(bs.add(GLFW_KEY_X, "X")), y(bs.add(GLFW_KEY_Z, "Y")), l(bs.add(GLFW_KEY_Q, "L")), r(bs.add(GLFW_KEY_W, "R")),
-start(bs.add(GLFW_KEY_E, "Start")), select(bs.add(GLFW_KEY_D, "Select")), left(bs.add(GLFW_KEY_LEFT, "Left")),
-right(bs.add(GLFW_KEY_RIGHT, "Right")), up(bs.add(GLFW_KEY_UP, "Up")), down(bs.add(GLFW_KEY_DOWN, "Down")) {
+Controller::Controller(Buttons& bs)
+    : list(bs.get()), a(bs.add(GLFW_KEY_A, "A")), b(bs.add(GLFW_KEY_S, "B")), x(bs.add(GLFW_KEY_X, "X")),
+      y(bs.add(GLFW_KEY_Z, "Y")), l(bs.add(GLFW_KEY_Q, "L")), r(bs.add(GLFW_KEY_W, "R")),
+      start(bs.add(GLFW_KEY_E, "Start")), select(bs.add(GLFW_KEY_D, "Select")), left(bs.add(GLFW_KEY_LEFT, "Left")),
+      right(bs.add(GLFW_KEY_RIGHT, "Right")), up(bs.add(GLFW_KEY_UP, "Up")), down(bs.add(GLFW_KEY_DOWN, "Down")) {
     bs.mapGamepadButton(a, GLFW_GAMEPAD_BUTTON_A);
     bs.mapGamepadButton(b, GLFW_GAMEPAD_BUTTON_B);
     bs.mapGamepadButton(x, GLFW_GAMEPAD_BUTTON_X);
@@ -18,7 +19,7 @@ right(bs.add(GLFW_KEY_RIGHT, "Right")), up(bs.add(GLFW_KEY_UP, "Up")), down(bs.a
     bs.mapGamepadButton(right, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT);
     bs.mapGamepadButton(down, GLFW_GAMEPAD_BUTTON_DPAD_DOWN);
     bs.mapGamepadButton(left, GLFW_GAMEPAD_BUTTON_DPAD_LEFT);
-    
+
     bs.mapGamepadAxis(left, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
     bs.mapGamepadAxis(right, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
     bs.mapGamepadAxis(left, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);

+ 3 - 3
rendering/ColorRenderer.cpp

@@ -1,14 +1,14 @@
 #include "rendering/ColorRenderer.h"
-#include "gaming-core/wrapper/Attributes.h"
 #include "gaming-core/utils/Buffer.h"
+#include "gaming-core/wrapper/Attributes.h"
 
 ColorRenderer::ColorRenderer() {
     vertexBuffer.setAttributes(Attributes().addFloat(2).addSpacer().addColor4());
-    vertexBuffer.setStreamData(sizeof (Vertex) * 3);
+    vertexBuffer.setStreamData(sizeof(Vertex) * 3);
 }
 
 void ColorRenderer::draw(const Vertex& v1, const Vertex& v2, const Vertex& v3) {
-    Buffer buffer(sizeof (Vertex) * 3);
+    Buffer buffer(sizeof(Vertex) * 3);
     buffer.add(v1).add(v2).add(v3);
     vertexBuffer.updateData(0, buffer.getLength(), buffer);
     vertexBuffer.draw(3);

+ 1 - 2
rendering/ColorRenderer.h

@@ -1,11 +1,10 @@
 #ifndef COLORRENDERER_H
 #define COLORRENDERER_H
 
-#include "gaming-core/wrapper/VertexBuffer.h"
 #include "gaming-core/utils/Color.h"
+#include "gaming-core/wrapper/VertexBuffer.h"
 
 struct ColorRenderer final {
-
     struct Vertex {
         float x;
         float y;

+ 5 - 5
rendering/FontRenderer.cpp

@@ -1,20 +1,20 @@
 #include "rendering/FontRenderer.h"
-#include "gaming-core/wrapper/Attributes.h"
-#include "gaming-core/utils/Color.h"
 #include "gaming-core/utils/Buffer.h"
+#include "gaming-core/utils/Color.h"
+#include "gaming-core/wrapper/Attributes.h"
 
 FontRenderer::FontRenderer() : activeTex(0), scale(1) {
     tex.add("resources/font8x8.png");
     tex.add("resources/font16x16.png");
     tex.add("resources/font24x24.png");
     vertexBuffer.setAttributes(Attributes().addFloat(2).addFloat(2).addColor4());
-    vertexBuffer.setStreamData(256 * 4 * sizeof (float) * 8);
+    vertexBuffer.setStreamData(256 * 4 * sizeof(float) * 8);
 }
 
 float FontRenderer::drawString(float x, float y, const char* text) {
     const int maxIndex = 256;
 
-    Buffer buffer(sizeof (float) * maxIndex * 4 * 8);
+    Buffer buffer(sizeof(float) * maxIndex * 4 * 8);
 
     int index = 0;
     Color4 color(0xFF, 0xFF, 0xFF, 0xFF);
@@ -55,7 +55,7 @@ float FontRenderer::drawString(float x, float y, const char* text) {
 
     tex[activeTex].bindTo(0);
     vertexBuffer.updateData(0, buffer.getLength(), buffer);
-    vertexBuffer.drawStrip(buffer.getLength() / (4 * sizeof (float) + sizeof (Color4)));
+    vertexBuffer.drawStrip(buffer.getLength() / (4 * sizeof(float) + sizeof(Color4)));
     return y + addY;
 }
 

+ 2 - 2
rendering/FontRenderer.h

@@ -1,9 +1,9 @@
 #ifndef FONTRENDERER_H
 #define FONTRENDERER_H
 
-#include "gaming-core/wrapper/VertexBuffer.h"
-#include "gaming-core/utils/List.h"
 #include "gaming-core/rendering/FileTexture.h"
+#include "gaming-core/utils/List.h"
+#include "gaming-core/wrapper/VertexBuffer.h"
 #include "utils/Array.h"
 
 class FontRenderer final {

+ 1 - 1
rendering/Mesh.cpp

@@ -14,7 +14,7 @@ void Mesh::clear() {
 }
 
 void Mesh::build() {
-    vertexBuffer.setStaticData(sizeof (VertexData) * buffer.getLength(), buffer.begin());
+    vertexBuffer.setStaticData(sizeof(VertexData) * buffer.getLength(), buffer.begin());
 }
 
 void Mesh::draw() {

+ 0 - 1
rendering/Mesh.h

@@ -5,7 +5,6 @@
 #include "utils/List.h"
 
 struct Mesh final {
-
     struct VertexData final {
         float x;
         float y;

+ 2 - 1
rendering/Renderer.cpp

@@ -79,7 +79,8 @@ float Renderer::drawString(float x, float y, const char* text) {
     return fontRenderer.drawString(x, y, text);
 }
 
-void Renderer::drawTriangle(const ColorRenderer::Vertex& v1, const ColorRenderer::Vertex& v2, const ColorRenderer::Vertex& v3) {
+void Renderer::drawTriangle(const ColorRenderer::Vertex& v1, const ColorRenderer::Vertex& v2,
+                            const ColorRenderer::Vertex& v3) {
     setTextureMode(false);
     setColorMode(true);
     colorRenderer.draw(v1, v2, v3);

+ 10 - 9
rendering/Renderer.h

@@ -3,10 +3,17 @@
 
 #include "gaming-core/wrapper/Shader.h"
 #include "math/MatrixStack.h"
-#include "rendering/FontRenderer.h"
 #include "rendering/ColorRenderer.h"
+#include "rendering/FontRenderer.h"
 
 class Renderer final {
+    Shader& shader;
+    bool texture;
+    bool color;
+    MatrixStack<10> stack;
+    FontRenderer fontRenderer;
+    ColorRenderer colorRenderer;
+
 public:
     Renderer(Shader& shader);
 
@@ -27,20 +34,14 @@ public:
 
     void setStringSize(int size);
     float drawString(float x, float y, const char* text);
-    void drawTriangle(const ColorRenderer::Vertex& v1, const ColorRenderer::Vertex& v2, const ColorRenderer::Vertex& v3);
+    void drawTriangle(const ColorRenderer::Vertex& v1, const ColorRenderer::Vertex& v2,
+                      const ColorRenderer::Vertex& v3);
     void drawTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Color4 color);
     void drawRectangle(float x, float y, float width, float height, Color4 color);
 
 private:
     void setTextureMode(bool b);
     void setColorMode(bool b);
-    
-    Shader& shader;
-    bool texture;
-    bool color;
-    MatrixStack<10> stack;
-    FontRenderer fontRenderer;
-    ColorRenderer colorRenderer;
 };
 
 #endif

+ 1 - 1
resources/shader/fragment.fs

@@ -13,7 +13,7 @@ out vec4 color;
 
 void main() {
     if(useTexture) {
-        color = texture2D(samp, varTex);
+        color = texture(samp, varTex);
         if(useColor) {
             color = vec4(varColor.xyz, color.r);
         }

+ 1 - 1
resources/shader/vertex.vs

@@ -13,7 +13,7 @@ out vec2 varTex;
 out vec4 varColor;
 
 void main() { 
-    varTex = tex; 
+    varTex = tex;
     varColor = color; 
     gl_Position = view * model * vec4(position, 0.0, 1.0);
 }