Browse Source

command line arg for skipping all visualization

Kajetan Johannes Hammerle 3 years ago
parent
commit
3d1132230b
2 changed files with 19 additions and 8 deletions
  1. 4 3
      Game.cpp
  2. 15 5
      Main.cpp

+ 4 - 3
Game.cpp

@@ -28,9 +28,10 @@ float Point::distance(const Point& other) const {
 
 Game::Game(Keys& keys, const char* file, bool steps) : keys(keys), keyNext(keys.add(GLFW_KEY_N)), active(0),
 state(SPLIT) {
-    if(file == nullptr) {
+    // try getting number
+    int amount = atoi(file);
+    if(amount > 0) {
         Random r;
-        int amount = steps ? 50 : 100000;
         for(int i = 0; i < amount; i++) {
             data.push_back({r.nextFloat(), r.nextFloat()});
         }
@@ -370,7 +371,7 @@ void Game::skip() {
         finalizeMerge();
     }
     time = std::chrono::high_resolution_clock::now().time_since_epoch().count() - time;
-    std::cout << "Took " << (time / 1000000.0) << "ms\n";
+    std::cout << (time / 1000000.0) << " ms\n";
     state = END;
     hullA.clear();
     hullB.clear();

+ 15 - 5
Main.cpp

@@ -1,5 +1,6 @@
 #include <iostream>
 #include <cstring>
+#include <fstream>
 
 #include "rendering/GLFW.h"
 #include "rendering/Window.h"
@@ -8,6 +9,7 @@
 #include "rendering/GL.h"
 #include "rendering/Renderer.h"
 #include "Game.h"
+#include "utils/Random.h"
 
 bool initGLEW() {
     GLenum err = glewInit();
@@ -34,18 +36,26 @@ void initCallbacks(Window& w, Keys& keys) {
 }
 
 int main(int argAmount, const char** args) {
-    const char* file = nullptr;
-    if(argAmount >= 2 && strcmp(args[1], "-r") != 0) {
-        file = args[1];
+    if(argAmount < 2 || strcmp(args[1], "-r") == 0) {
+        std::cout << "expecting at least one argument: filename or number\n";
+        return 0;
     }
     bool steps = true;
+    bool skip = true;
     for(int i = 1; i < argAmount; i++) {
         if(strcmp(args[i], "-r") == 0) {
             steps = false;
-            break;
+        } else if(strcmp(args[i], "-v") == 0) {
+            skip = false;
         }
     }
 
+    if(skip) {
+        Keys keys;
+        Game game(keys, args[1], steps);
+        return 0;
+    }
+
     if(GLFW::hasError()) {
         return 0;
     }
@@ -61,7 +71,7 @@ int main(int argAmount, const char** args) {
     }
 
     Keys keys;
-    Game game(keys, file, steps);
+    Game game(keys, args[1], steps);
 
     initCallbacks(window, keys);
     window.show();