Browse Source

new core version

Kajetan Johannes Hammerle 2 months ago
parent
commit
a18446bb08
7 changed files with 21 additions and 23 deletions
  1. 2 3
      Game.cpp
  2. 11 9
      Main.cpp
  3. 1 2
      rendering/ColorRenderer.cpp
  4. 4 5
      rendering/FontRenderer.cpp
  5. 1 1
      rendering/FontRenderer.h
  6. 1 2
      rendering/Mesh.cpp
  7. 1 1
      subprojects/gaming-core

+ 2 - 3
Game.cpp

@@ -15,7 +15,6 @@ void Game::tick() {
     player.preTick();
     if(physicsToggle) {
         // forces from the player
-        std::cout << controller.a.getDownTime() << "\n";
         if(controller.a.isDown() && player.onGround) {
             player.jumpTicks = 10;
             player.onGround = false;
@@ -72,7 +71,6 @@ void Game::render(float lag, Renderer& r) const {
         .scale(1.0f, -1.0f)
         .translateY(size.height)
         .update();
-
     Vector2 pos = Utils::interpolate(player.lastPosition, player.position, lag);
     r.drawRectangle(pos, player.size, Color4(0xFF, 0x00, 0x00, 0xFF));
 
@@ -80,6 +78,7 @@ void Game::render(float lag, Renderer& r) const {
     r.setStringSize(2);
     StringBuffer<100> s("FPS: ");
     s.append(fps.getUpdatesPerSecond()).append(" ");
+    s.append("%6.2f", tps.getUpdatesPerSecond()).append(" ");
     s.append(physicsToggle ? "Force Physics" : "Velocity Physics");
     float y = 10.0f;
     y = r.drawString(10.0f, y, s);
@@ -91,4 +90,4 @@ void Game::render(float lag, Renderer& r) const {
 
 bool Game::isRunning() const {
     return !controller.select.isDown();
-}
+}

+ 11 - 9
Main.cpp

@@ -27,20 +27,22 @@ int main(int argAmount, char* const* args) {
     if(parseArgs(argAmount, args, options)) {
         return 0;
     }
-
-    TextInput* input = nullptr;
-    Window w(input, options);
-    if(w.getError().has()) {
-        std::cout << w.getError().message << '\n';
+    Window w;
+    Error error = w.open(options);
+    if(error.has()) {
+        error.message.printLine();
         return 0;
     }
 
-    Shader shader("resources/shader/vertex.vs", "resources/shader/fragment.fs");
-    if(shader.hasError()) {
+    Shader cubeShader;
+    error = cubeShader.compile("resources/shader/vertex.vs", nullptr,
+                               "resources/shader/fragment.fs");
+    if(error.has()) {
+        error.message.printLine();
         return 0;
     }
 
-    Controller controller(w.getButtons());
+    Controller controller(w.buttons);
     static Game game(controller, w.getFrameClock(), w.getTickClock(), size);
 
     struct GameBase {
@@ -75,7 +77,7 @@ int main(int argAmount, char* const* args) {
             return game.isRunning();
         }
     };
-    GameBase base(w, game, shader);
+    GameBase base(w, game, cubeShader);
     w.run(base, 10'000'000);
     return 0;
 }

+ 1 - 2
rendering/ColorRenderer.cpp

@@ -3,8 +3,7 @@
 #include "utils/Buffer.h"
 
 ColorRenderer::ColorRenderer() {
-    vertexBuffer.setAttributes(
-        Attributes().addFloat(2).addSpacer().addColor4());
+    vertexBuffer.init(Attributes().addFloat(2).addSpacer().addColor4());
     vertexBuffer.setStreamData(sizeof(Vertex) * 3);
 }
 

+ 4 - 5
rendering/FontRenderer.cpp

@@ -4,11 +4,10 @@
 #include "utils/Color.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());
+    tex[0].load("resources/font8x8.png", 0);
+    tex[1].load("resources/font16x16.png", 0);
+    tex[2].load("resources/font24x24.png", 0);
+    vertexBuffer.init(Attributes().addFloat(2).addFloat(2).addColor4());
     vertexBuffer.setStreamData(256 * 4 * sizeof(float) * 8);
 }
 

+ 1 - 1
rendering/FontRenderer.h

@@ -8,7 +8,7 @@
 
 class FontRenderer final {
     VertexBuffer vertexBuffer;
-    ArrayList<FileTexture, 3> tex;
+    Array<FileTexture, 3> tex;
     int activeTex;
     int scale;
 

+ 1 - 2
rendering/Mesh.cpp

@@ -2,8 +2,7 @@
 #include "rendering/Attributes.h"
 
 Mesh::Mesh() {
-    vertexBuffer.setAttributes(
-        Attributes().addFloat(3).addFloat(2).addFloat(3));
+    vertexBuffer.init(Attributes().addFloat(3).addFloat(2).addFloat(3));
 }
 
 void Mesh::add(const VertexData& data) {

+ 1 - 1
subprojects/gaming-core

@@ -1 +1 @@
-Subproject commit f2184c96f9ed350792c4429aa3aaa530ba1b617a
+Subproject commit 14d9f19f59b6f90a8d107f8a0005d9e600758d32