Sfoglia il codice sorgente

chore: update formatting

Sam Jaffe 1 anno fa
parent
commit
563fd8c826
40 ha cambiato i file con 891 aggiunte e 893 eliminazioni
  1. 1 1
      .clang-format
  2. 15 15
      engine/include/game/engine/engine_fwd.hpp
  3. 37 37
      engine/include/game/engine/entity.hpp
  4. 21 21
      engine/include/game/engine/fps_counter.hpp
  5. 53 53
      engine/include/game/engine/game_dispatch.hpp
  6. 39 39
      engine/include/game/engine/scene.hpp
  7. 6 6
      engine/include/game/engine/serial.hpp
  8. 17 18
      engine/include/game/engine/text_engine.hpp
  9. 71 72
      engine/src/game_dispatch.cpp
  10. 39 39
      engine/src/serial.cxx
  11. 1 1
      engine/test/scene_test.cxx
  12. 23 23
      graphics/include/game/graphics/exception.h
  13. 19 19
      graphics/include/game/graphics/graphics_fwd.h
  14. 66 66
      graphics/include/game/graphics/manager.hpp
  15. 12 12
      graphics/include/game/graphics/material.hpp
  16. 8 8
      graphics/include/game/graphics/object.hpp
  17. 47 47
      graphics/include/game/graphics/renderer.hpp
  18. 5 5
      graphics/include/game/graphics/shader.hpp
  19. 5 5
      graphics/include/game/graphics/shader_program.hpp
  20. 4 4
      graphics/include/game/graphics/texture.hpp
  21. 4 4
      graphics/include/game/graphics/vertex.h
  22. 26 26
      graphics/src/helper.hpp
  23. 32 32
      graphics/src/matrix.cxx
  24. 6 6
      graphics/src/matrix.hpp
  25. 25 25
      graphics/src/openGL/error_formatter.cxx
  26. 23 23
      graphics/src/openGL/opengl_manager.cxx
  27. 2 2
      graphics/src/openGL/opengl_renderer.cxx
  28. 36 36
      graphics/src/openGL/opengl_renderer.h
  29. 1 1
      graphics/src/renderer.cxx
  30. 9 9
      graphics/src/renderer_impl.hpp
  31. 15 15
      math/include/game/math/angle.hpp
  32. 24 24
      math/include/game/math/common.hpp
  33. 35 35
      math/include/game/math/compare.hpp
  34. 26 26
      math/include/game/math/math_fwd.hpp
  35. 9 9
      math/src/angle.cpp
  36. 107 107
      math/src/common.cpp
  37. 1 1
      math/test/common_test.cxx
  38. 1 1
      util/include/game/util/files.hpp
  39. 18 18
      util/src/files.cxx
  40. 2 2
      util/src/osx_env.mm

+ 1 - 1
.clang-format

@@ -101,7 +101,7 @@ SpacesInContainerLiterals: true
 SpacesInCStyleCastParentheses: false
 SpacesInParentheses: false
 SpacesInSquareBrackets: false
-Standard:        Cpp11
+Standard:        c++20
 TabWidth:        8
 UseTab:          Never
 ...

+ 15 - 15
engine/include/game/engine/engine_fwd.hpp

@@ -11,23 +11,23 @@
 #include <unordered_map>
 
 namespace engine {
-  using collision_t = int;
+using collision_t = int;
 
-  using raw_key_t = int;
-  using key_enum_t = int;
-  using scene_id_t = std::string;
+using raw_key_t = int;
+using key_enum_t = int;
+using scene_id_t = std::string;
 
-  using key_binding = std::unordered_map<raw_key_t, key_enum_t>;
+using key_binding = std::unordered_map<raw_key_t, key_enum_t>;
 
-  class collidable;
-  class entity;
-  class fps_counter;
-  class game_dispatch;
-  class scene;
-  class text_engine;
+class collidable;
+class entity;
+class fps_counter;
+class game_dispatch;
+class scene;
+class text_engine;
 
-  namespace event {
-    struct key_event;
-    struct mouse_event;
-  }
+namespace event {
+  struct key_event;
+  struct mouse_event;
+}
 }

+ 37 - 37
engine/include/game/engine/entity.hpp

@@ -16,41 +16,41 @@
 #include "game/util/identity.hpp"
 
 namespace engine {
-  class collidable : identity<collidable> {
-  public:
-    collidable(graphics::object const & obj);
-
-    virtual void collide(collidable const &) {}
-    graphics::object const & render_info() const { return render_info_; }
-
-  protected:
-    void move(math::vec2 const & delta);
-    // A mix of position and graphics info
-    graphics::object render_info_;
-  };
-
-  class entity : public collidable {
-  public:
-    // TODO: Extract this out?
-    entity(Json::Value const & json, graphics::object const & obj);
-    void update(float delta);
-
-  private:
-    // The scene that owns this object
-    std::weak_ptr<scene> in_scene;
-
-    // Position info
-    math::vec2 last_position{{-1, -1}};
-    math::vec2 velocity;
-    math::vec2 acceleration{{0, 0}};
-    float angular_velocity{0.f};
-    // Graphics info
-    std::size_t frame_index{0};
-    std::vector<math::vec2> frame_texture_coords;
-
-    float scale{1.f};
-
-    collision_t collides_with;
-    collision_t collides_as;
-  };
+class collidable : identity<collidable> {
+public:
+  collidable(graphics::object const & obj);
+
+  virtual void collide(collidable const &) {}
+  graphics::object const & render_info() const { return render_info_; }
+
+protected:
+  void move(math::vec2 const & delta);
+  // A mix of position and graphics info
+  graphics::object render_info_;
+};
+
+class entity : public collidable {
+public:
+  // TODO: Extract this out?
+  entity(Json::Value const & json, graphics::object const & obj);
+  void update(float delta);
+
+private:
+  // The scene that owns this object
+  std::weak_ptr<scene> in_scene;
+
+  // Position info
+  math::vec2 last_position{{-1, -1}};
+  math::vec2 velocity;
+  math::vec2 acceleration{{0, 0}};
+  float angular_velocity{0.f};
+  // Graphics info
+  std::size_t frame_index{0};
+  std::vector<math::vec2> frame_texture_coords;
+
+  float scale{1.f};
+
+  collision_t collides_with;
+  collision_t collides_as;
+};
 }

+ 21 - 21
engine/include/game/engine/fps_counter.hpp

@@ -14,25 +14,25 @@
 #include "game/util/time.hpp"
 
 namespace engine {
-  class text_engine;
-  class fps_counter {
-  public:
-    fps_counter(std::shared_ptr<text_engine> text_engine,
-                std::size_t precision = 3);
-    ~fps_counter();
-
-    void set_frame_step(env::clock::duration const & since);
-
-    void render(graphics::renderer & renderer) const;
-    std::vector<graphics::object> const & glyphs() const { return glyphs_; }
-
-  private:
-    std::string fps(env::clock::duration const & since) const;
-
-    int counter_{0}, change_after_{10};
-    std::size_t digits_;
-    std::size_t magnitude_;
-    std::shared_ptr<text_engine> text_engine_;
-    std::vector<graphics::object> glyphs_;
-  };
+class text_engine;
+class fps_counter {
+public:
+  fps_counter(std::shared_ptr<text_engine> text_engine,
+              std::size_t precision = 3);
+  ~fps_counter();
+
+  void set_frame_step(env::clock::duration const & since);
+
+  void render(graphics::renderer & renderer) const;
+  std::vector<graphics::object> const & glyphs() const { return glyphs_; }
+
+private:
+  std::string fps(env::clock::duration const & since) const;
+
+  int counter_{0}, change_after_{10};
+  std::size_t digits_;
+  std::size_t magnitude_;
+  std::shared_ptr<text_engine> text_engine_;
+  std::vector<graphics::object> glyphs_;
+};
 }

+ 53 - 53
engine/include/game/engine/game_dispatch.hpp

@@ -20,57 +20,57 @@
 #include "game/util/time.hpp"
 
 namespace engine {
-  class game_dispatch {
-  public:
-    using scene_t = std::shared_ptr<scene>;
-
-  public:
-    game_dispatch(std::shared_ptr<graphics::renderer> renderer);
-    ~game_dispatch();
-
-    void process_key_event(raw_key_t key, bool press);
-    void process_mouse_event(math::vec2 click, bool press);
-    graphics::manager const & graphics_manager() const;
-
-    bool is_running() const { return running; }
-    void quit() { running = false; }
-
-  public:
-    void update();
-    void render();
-
-    std::shared_ptr<graphics::renderer> make_renderer(math::vec2 const &) const;
-    void register_scene(scene_t scn);
-    void activate_scene(scene_id_t const & id);
-    void set_current_timestamp();
-    void set_target_fps(env::clock::duration fps) {
-      minimum_frame_duration_ = fps;
-    }
-
-  private:
-    env::clock::tick next_frame();
-
-  private:
-    math::vec2 screen_size_;
-    std::shared_ptr<graphics::renderer> renderer_, batch_renderer_;
-    env::clock::duration minimum_frame_duration_;
-    std::shared_ptr<text_engine> text_engine_;
-    std::unique_ptr<fps_counter> counter_;
-
-    std::unordered_map<scene_id_t, scene_t> scenes_;
-
-    bool running = true;
-    env::clock::timestamp current_timestamp;
-    struct current_scene_info {
-      current_scene_info();
-      current_scene_info(scene_t);
-
-      scene_t ptr;
-
-      std::string current_scene_id; // metadata
-      math::vec2 local_size;        // metadata
-      bool is_mouse_event;
-      bool is_keyboard_event;
-    } current_scene_;
-  };
+class game_dispatch {
+public:
+  using scene_t = std::shared_ptr<scene>;
+
+public:
+  game_dispatch(std::shared_ptr<graphics::renderer> renderer);
+  ~game_dispatch();
+
+  void process_key_event(raw_key_t key, bool press);
+  void process_mouse_event(math::vec2 click, bool press);
+  graphics::manager const & graphics_manager() const;
+
+  bool is_running() const { return running; }
+  void quit() { running = false; }
+
+public:
+  void update();
+  void render();
+
+  std::shared_ptr<graphics::renderer> make_renderer(math::vec2 const &) const;
+  void register_scene(scene_t scn);
+  void activate_scene(scene_id_t const & id);
+  void set_current_timestamp();
+  void set_target_fps(env::clock::duration fps) {
+    minimum_frame_duration_ = fps;
+  }
+
+private:
+  env::clock::tick next_frame();
+
+private:
+  math::vec2 screen_size_;
+  std::shared_ptr<graphics::renderer> renderer_, batch_renderer_;
+  env::clock::duration minimum_frame_duration_;
+  std::shared_ptr<text_engine> text_engine_;
+  std::unique_ptr<fps_counter> counter_;
+
+  std::unordered_map<scene_id_t, scene_t> scenes_;
+
+  bool running = true;
+  env::clock::timestamp current_timestamp;
+  struct current_scene_info {
+    current_scene_info();
+    current_scene_info(scene_t);
+
+    scene_t ptr;
+
+    std::string current_scene_id; // metadata
+    math::vec2 local_size;        // metadata
+    bool is_mouse_event;
+    bool is_keyboard_event;
+  } current_scene_;
+};
 }

+ 39 - 39
engine/include/game/engine/scene.hpp

@@ -19,43 +19,43 @@
 #include "engine_fwd.hpp"
 
 namespace engine {
-  class scene : public identity<scene, std::string> {
-  public:
-    scene(std::string const &, math::vec2 const &,
-          std::shared_ptr<game_dispatch>);
-    virtual ~scene();
-
-    virtual void update(float delta) = 0;
-    virtual void render() = 0;
-    virtual void handle_key_event(event::key_event evt);
-    virtual void handle_mouse_event(event::mouse_event evt);
-
-    math::vec2 size() const;
-    key_binding const & keys() const;
-
-  protected:
-    graphics::manager const & graphics_manager() const;
-    void change_scene(std::string const & scene_id);
-    bool in_bounds(math::dim2::point const & c) const;
-    bool in_bounds(collidable * c) const;
-    void check_collisions();
-    static void check_collisions(std::vector<collidable *> const & from,
-                                 std::vector<collidable *> const & to);
-
-  protected:
-    graphics::renderer & renderer() { return *renderer_; }
-
-    std::vector<entity> entities;
-
-    // Map from entity::collides_with -> [entity*]
-    std::unordered_map<collision_t, std::vector<collidable *>> colliders;
-    // Map from entity::collides_as -> [entity*]
-    std::unordered_map<collision_t, std::vector<collidable *>> collidables;
-
-  private:
-    math::vec2 local_bounds_;
-    std::shared_ptr<graphics::renderer> renderer_;
-    key_binding keys_;
-    std::weak_ptr<game_dispatch> dispatch_;
-  };
+class scene : public identity<scene, std::string> {
+public:
+  scene(std::string const &, math::vec2 const &,
+        std::shared_ptr<game_dispatch>);
+  virtual ~scene();
+
+  virtual void update(float delta) = 0;
+  virtual void render() = 0;
+  virtual void handle_key_event(event::key_event evt);
+  virtual void handle_mouse_event(event::mouse_event evt);
+
+  math::vec2 size() const;
+  key_binding const & keys() const;
+
+protected:
+  graphics::manager const & graphics_manager() const;
+  void change_scene(std::string const & scene_id);
+  bool in_bounds(math::dim2::point const & c) const;
+  bool in_bounds(collidable * c) const;
+  void check_collisions();
+  static void check_collisions(std::vector<collidable *> const & from,
+                               std::vector<collidable *> const & to);
+
+protected:
+  graphics::renderer & renderer() { return *renderer_; }
+
+  std::vector<entity> entities;
+
+  // Map from entity::collides_with -> [entity*]
+  std::unordered_map<collision_t, std::vector<collidable *>> colliders;
+  // Map from entity::collides_as -> [entity*]
+  std::unordered_map<collision_t, std::vector<collidable *>> collidables;
+
+private:
+  math::vec2 local_bounds_;
+  std::shared_ptr<graphics::renderer> renderer_;
+  key_binding keys_;
+  std::weak_ptr<game_dispatch> dispatch_;
+};
 }

+ 6 - 6
engine/include/game/engine/serial.hpp

@@ -14,10 +14,10 @@
 #include "game/math/math_fwd.hpp"
 
 namespace engine {
-  Json::Value read_file(std::string const & abs_path);
-  math::vec2 to_vec2(Json::Value const & json);
-  math::vec2i to_vec2i(Json::Value const & json);
-  math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup);
-  graphics::object to_object(Json::Value const & json,
-                             graphics::manager const & mgr);
+Json::Value read_file(std::string const & abs_path);
+math::vec2 to_vec2(Json::Value const & json);
+math::vec2i to_vec2i(Json::Value const & json);
+math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup);
+graphics::object to_object(Json::Value const & json,
+                           graphics::manager const & mgr);
 }

+ 17 - 18
engine/include/game/engine/text_engine.hpp

@@ -17,25 +17,24 @@
 #include "vector/vector.hpp"
 
 namespace engine {
-  class text_engine {
-  public:
-    struct cell {
-      math::vec2 origin;
-      math::vec2 size;
-      std::string content;
-    };
+class text_engine {
+public:
+  struct cell {
+    math::vec2 origin;
+    math::vec2 size;
+    std::string content;
+  };
 
-  public:
-    text_engine(std::string const & font,
-                std::shared_ptr<graphics::manager const> manager);
+public:
+  text_engine(std::string const & font,
+              std::shared_ptr<graphics::manager const> manager);
 
-    void create_text_cells(std::vector<graphics::object> & out,
-                           cell const & in);
+  void create_text_cells(std::vector<graphics::object> & out, cell const & in);
 
-  private:
-    //    std::shared_ptr<graphics::manager const> manager_;
-    std::string font_;
-    graphics::object prototype_;
-    std::unordered_map<char, math::vec2> glyphs_;
-  };
+private:
+  //    std::shared_ptr<graphics::manager const> manager_;
+  std::string font_;
+  graphics::object prototype_;
+  std::unordered_map<char, math::vec2> glyphs_;
+};
 }

+ 71 - 72
engine/src/game_dispatch.cpp

@@ -19,95 +19,94 @@
 #include "matrix/matrix_helpers.hpp"
 
 namespace engine {
-  namespace {
-    event::event_type mask(event::event_type t, bool pressed) {
-      return static_cast<event::event_type>(
-          t | (pressed ? event::PRESSED_MASK : event::RELEASED_MASK));
-    }
+namespace {
+  event::event_type mask(event::event_type t, bool pressed) {
+    return static_cast<event::event_type>(
+        t | (pressed ? event::PRESSED_MASK : event::RELEASED_MASK));
   }
+}
 
-  game_dispatch::game_dispatch(std::shared_ptr<graphics::renderer> renderer)
-      : screen_size_(env::screen_size()), renderer_(renderer),
-        batch_renderer_(make_renderer(screen_size_)),
-        minimum_frame_duration_(0),
-        text_engine_(new text_engine("font", renderer->manager())),
-        counter_(new fps_counter(text_engine_)), scenes_(),
-        current_timestamp(env::clock::now()), current_scene_() {}
-
-  game_dispatch::~game_dispatch() {}
+game_dispatch::game_dispatch(std::shared_ptr<graphics::renderer> renderer)
+    : screen_size_(env::screen_size()), renderer_(renderer),
+      batch_renderer_(make_renderer(screen_size_)), minimum_frame_duration_(0),
+      text_engine_(new text_engine("font", renderer->manager())),
+      counter_(new fps_counter(text_engine_)), scenes_(),
+      current_timestamp(env::clock::now()), current_scene_() {}
 
-  void game_dispatch::register_scene(scene_t scn) {
-    scenes_.emplace(scn->id, scn);
-  }
+game_dispatch::~game_dispatch() {}
 
-  void game_dispatch::activate_scene(scene_id_t const & id) {
-    // TODO: Cleanup
-    current_scene_ = current_scene_info(scenes_[id]);
-  }
+void game_dispatch::register_scene(scene_t scn) {
+  scenes_.emplace(scn->id, scn);
+}
 
-  void game_dispatch::set_current_timestamp() {
-    current_timestamp = env::clock::now();
-  }
+void game_dispatch::activate_scene(scene_id_t const & id) {
+  // TODO: Cleanup
+  current_scene_ = current_scene_info(scenes_[id]);
+}
 
-  game_dispatch::current_scene_info::current_scene_info() {}
+void game_dispatch::set_current_timestamp() {
+  current_timestamp = env::clock::now();
+}
 
-  game_dispatch::current_scene_info::current_scene_info(scene_t curr)
-      : ptr(curr), current_scene_id(ptr->id), local_size(ptr->size()) {}
+game_dispatch::current_scene_info::current_scene_info() {}
 
-  graphics::manager const & game_dispatch::graphics_manager() const {
-    return *renderer_->manager();
-  }
+game_dispatch::current_scene_info::current_scene_info(scene_t curr)
+    : ptr(curr), current_scene_id(ptr->id), local_size(ptr->size()) {}
 
-  void game_dispatch::process_key_event(raw_key_t key, bool press) {
-    //    if (!current_scene_.is_keyboard_event) return;
-    auto const & binding = current_scene_.ptr->keys();
-    auto it = binding.find(key);
-    if (it == binding.end()) return;
+graphics::manager const & game_dispatch::graphics_manager() const {
+  return *renderer_->manager();
+}
 
-    current_scene_.ptr->handle_key_event(
-        {it->second, mask(event::KEY_MASK, press)});
-  }
+void game_dispatch::process_key_event(raw_key_t key, bool press) {
+  //    if (!current_scene_.is_keyboard_event) return;
+  auto const & binding = current_scene_.ptr->keys();
+  auto it = binding.find(key);
+  if (it == binding.end()) return;
 
-  void game_dispatch::process_mouse_event(math::vec2 mouse_pos, bool press) {
-    //    if (!current_scene_.is_mouse_event) return;
-    math::vec2 local_scene_position =
-        mouse_pos * current_scene_.local_size / screen_size_;
+  current_scene_.ptr->handle_key_event(
+      {it->second, mask(event::KEY_MASK, press)});
+}
 
-    current_scene_.ptr->handle_mouse_event(
-        {local_scene_position, mask(event::MOUSE_MASK, press)});
-  }
+void game_dispatch::process_mouse_event(math::vec2 mouse_pos, bool press) {
+  //    if (!current_scene_.is_mouse_event) return;
+  math::vec2 local_scene_position =
+      mouse_pos * current_scene_.local_size / screen_size_;
 
-  env::clock::tick game_dispatch::next_frame() {
-    env::clock::tick t(current_timestamp);
+  current_scene_.ptr->handle_mouse_event(
+      {local_scene_position, mask(event::MOUSE_MASK, press)});
+}
 
-    while (t.since < minimum_frame_duration_) {
-      std::this_thread::sleep_for(minimum_frame_duration_ - t.since);
-      t = env::clock::tick(current_timestamp);
-    }
+env::clock::tick game_dispatch::next_frame() {
+  env::clock::tick t(current_timestamp);
 
-    current_timestamp = t.now;
-    return t;
+  while (t.since < minimum_frame_duration_) {
+    std::this_thread::sleep_for(minimum_frame_duration_ - t.since);
+    t = env::clock::tick(current_timestamp);
   }
 
-  void game_dispatch::update() {
-    env::clock::tick t = next_frame();
-    counter_->set_frame_step(t.since);
-    current_scene_.ptr->update(std::chrono::duration<float>(t.since).count());
-  }
+  current_timestamp = t.now;
+  return t;
+}
 
-  void game_dispatch::render() {
-    batch_renderer_->clear();
-    counter_->render(*batch_renderer_);
-    batch_renderer_->flush();
-    current_scene_.ptr->render();
-    renderer_->flush();
-  }
+void game_dispatch::update() {
+  env::clock::tick t = next_frame();
+  counter_->set_frame_step(t.since);
+  current_scene_.ptr->update(std::chrono::duration<float>(t.since).count());
+}
 
-  std::shared_ptr<graphics::renderer>
-  game_dispatch::make_renderer(math::vec2 const & bounds) const {
-    math::vec2 const factor = screen_size_ / bounds;
-    float const scale = std::min(factor[0], factor[1]);
-    return std::make_shared<graphics::batch_renderer>(
-        renderer_.get(), math::matrix::scalar(make_vector(scale, scale, 1.f)));
-  }
+void game_dispatch::render() {
+  batch_renderer_->clear();
+  counter_->render(*batch_renderer_);
+  batch_renderer_->flush();
+  current_scene_.ptr->render();
+  renderer_->flush();
+}
+
+std::shared_ptr<graphics::renderer>
+game_dispatch::make_renderer(math::vec2 const & bounds) const {
+  math::vec2 const factor = screen_size_ / bounds;
+  float const scale = std::min(factor[0], factor[1]);
+  return std::make_shared<graphics::batch_renderer>(
+      renderer_.get(), math::matrix::scalar(make_vector(scale, scale, 1.f)));
+}
 }

+ 39 - 39
engine/src/serial.cxx

@@ -19,50 +19,50 @@
 #include "vector/vector.hpp"
 
 namespace engine {
-  Json::Value read_file(std::string const & abs_path) {
-    Json::Value json;
-    std::ifstream(abs_path) >> json;
-    return json;
-  }
+Json::Value read_file(std::string const & abs_path) {
+  Json::Value json;
+  std::ifstream(abs_path) >> json;
+  return json;
+}
 
-  math::vec2 to_vec2(Json::Value const & json) {
-    return make_vector(json[0].asFloat(), json[1].asFloat());
-  }
+math::vec2 to_vec2(Json::Value const & json) {
+  return make_vector(json[0].asFloat(), json[1].asFloat());
+}
 
-  math::vec2i to_vec2i(Json::Value const & json) {
-    return make_vector(json[0].asInt(), json[1].asInt());
-  }
+math::vec2i to_vec2i(Json::Value const & json) {
+  return make_vector(json[0].asInt(), json[1].asInt());
+}
 
-  math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup) {
-    return json.isNull() ? backup : to_vec2(json);
-  }
+math::vec2 to_vec2(Json::Value const & json, math::vec2 const & backup) {
+  return json.isNull() ? backup : to_vec2(json);
+}
 
-  identity<graphics::shader_program> to_program(Json::Value const & json,
-                                                graphics::manager const & mgr) {
-    // TODO (sjaffe): This should be an error, not defaulting to OpenGL...
-    if (json.empty()) {
-      return mgr.get("data/shaders/BlankShader.fragment.glsl",
-                     "data/shaders/BlankShader.vertex.glsl");
-    }
-    return mgr.get(json["fragmentShader"].asString(),
-                   json["vertexShader"].asString());
+identity<graphics::shader_program> to_program(Json::Value const & json,
+                                              graphics::manager const & mgr) {
+  // TODO (sjaffe): This should be an error, not defaulting to OpenGL...
+  if (json.empty()) {
+    return mgr.get("data/shaders/BlankShader.fragment.glsl",
+                   "data/shaders/BlankShader.vertex.glsl");
   }
+  return mgr.get(json["fragmentShader"].asString(),
+                 json["vertexShader"].asString());
+}
 
-  identity<graphics::material> to_material(Json::Value const & json,
-                                           graphics::manager const & mgr) {
-    return mgr.get(to_program(json["shaderProgram"], mgr),
-                   json["texture"]["file"].asString(),
-                   json["texture"]["uniform"].asString());
-  }
+identity<graphics::material> to_material(Json::Value const & json,
+                                         graphics::manager const & mgr) {
+  return mgr.get(to_program(json["shaderProgram"], mgr),
+                 json["texture"]["file"].asString(),
+                 json["texture"]["uniform"].asString());
+}
 
-  graphics::object to_object(Json::Value const & json,
-                             graphics::manager const & mgr) {
-    identity<graphics::material> mat = to_material(json["material"], mgr);
-    auto frame_size = to_vec2(json["frameSize"], make_vector(1.f, 1.f));
-    auto origin = to_vec2(json["position"]);
-    return mgr.create_object(mat, origin, frame_size, json["scale"].asFloat());
-    //    math::dim2::rectangle pos = {to_vec2(json["position"]),
-    //                                 mat.actual().size() * frame_size};
-    //    return {pos, pos, mat, {{{0, 0}}, frame_size}};
-  }
+graphics::object to_object(Json::Value const & json,
+                           graphics::manager const & mgr) {
+  identity<graphics::material> mat = to_material(json["material"], mgr);
+  auto frame_size = to_vec2(json["frameSize"], make_vector(1.f, 1.f));
+  auto origin = to_vec2(json["position"]);
+  return mgr.create_object(mat, origin, frame_size, json["scale"].asFloat());
+  //    math::dim2::rectangle pos = {to_vec2(json["position"]),
+  //                                 mat.actual().size() * frame_size};
+  //    return {pos, pos, mat, {{{0, 0}}, frame_size}};
+}
 }

+ 1 - 1
engine/test/scene_test.cxx

@@ -15,7 +15,7 @@
 #include "mock_renderer.h"
 
 namespace env {
-  void resize_screen(math::vec2i const & size);
+void resize_screen(math::vec2i const & size);
 }
 
 struct test_scene : engine::scene {

+ 23 - 23
graphics/include/game/graphics/exception.h

@@ -12,31 +12,31 @@
 #include <string>
 
 namespace graphics {
-  struct file_read_error : std::runtime_error {
-    file_read_error(std::string const & file)
-        : std::runtime_error("Unable to read file " + file) {}
-    file_read_error(std::string const & type, std::string const & file)
-        : std::runtime_error("Unable to read " + type + " file " + file) {}
-  };
+struct file_read_error : std::runtime_error {
+  file_read_error(std::string const & file)
+      : std::runtime_error("Unable to read file " + file) {}
+  file_read_error(std::string const & type, std::string const & file)
+      : std::runtime_error("Unable to read " + type + " file " + file) {}
+};
 
-  struct unknown_texture_format : std::runtime_error {
-    unknown_texture_format(int components)
-        : std::runtime_error("Invalid number of components provided: " +
-                             std::to_string(components)) {}
-  };
+struct unknown_texture_format : std::runtime_error {
+  unknown_texture_format(int components)
+      : std::runtime_error("Invalid number of components provided: " +
+                           std::to_string(components)) {}
+};
 
-  template <typename E> struct unmapped_enum : std::logic_error {
-    // TODO (sjaffe): This is just an int cast, which isn't all that helpful.
-    // Instead, one might use  https://github.com/Neargye/magic_enum
-    // or wait for C++ to implement that sort of thing through metaclasses, etc.
-    unmapped_enum(E en)
-        : std::logic_error("Unknown " + type_name + std::to_string((int)en)) {}
-    unmapped_enum(std::string const & str)
-        : std::logic_error("Unknown " + type_name + str) {}
+template <typename E> struct unmapped_enum : std::logic_error {
+  // TODO (sjaffe): This is just an int cast, which isn't all that helpful.
+  // Instead, one might use  https://github.com/Neargye/magic_enum
+  // or wait for C++ to implement that sort of thing through metaclasses, etc.
+  unmapped_enum(E en)
+      : std::logic_error("Unknown " + type_name + std::to_string((int)en)) {}
+  unmapped_enum(std::string const & str)
+      : std::logic_error("Unknown " + type_name + str) {}
 
-    static std::string const type_name;
-  };
+  static std::string const type_name;
+};
 
-  template <typename E>
-  std::string const unmapped_enum<E>::type_name{typeid(E).name()};
+template <typename E>
+std::string const unmapped_enum<E>::type_name{typeid(E).name()};
 }

+ 19 - 19
graphics/include/game/graphics/graphics_fwd.h

@@ -11,24 +11,24 @@
 #include "game/util/identity.hpp"
 
 namespace graphics {
-  // API classes
-  class manager;
-  struct object;
-  class renderer;
-  struct vertex;
+// API classes
+class manager;
+struct object;
+class renderer;
+struct vertex;
 
-  // Implementation classes
-  struct material;
-  struct shader;
-  struct shader_program;
-  class texture;
-  namespace materials {
-    enum class uniform : unsigned int;
-  }
-  namespace shaders {
-    enum class type : unsigned int;
-  }
-  namespace textures {
-    enum class format : unsigned int;
-  }
+// Implementation classes
+struct material;
+struct shader;
+struct shader_program;
+class texture;
+namespace materials {
+  enum class uniform : unsigned int;
+}
+namespace shaders {
+  enum class type : unsigned int;
+}
+namespace textures {
+  enum class format : unsigned int;
+}
 }

+ 66 - 66
graphics/include/game/graphics/manager.hpp

@@ -15,76 +15,76 @@
 #include "game/math/math_fwd.hpp"
 
 namespace graphics {
-  class manager {
-  public:
-    manager();
-    ~manager();
+class manager {
+public:
+  manager();
+  ~manager();
 
-    /**
-     * @brief Load a material - from either cache or by fetching data from the
-     * given arguments - and return its identifier.
-     * A material is a linkage of shader(s) and texture(s), that desribe the
-     * needed details to draw it on a page.
-     * @param program The shader program that should be used to paint this
-     * material.
-     * @param texture The path to an image file for this material
-     * @param uniform The name of the uniform to use as a fallback texture
-     */
-    identity<material> get(identity<shader_program> program,
-                           std::string const & texture,
-                           std::string const & uniform) const;
-    /**
-     * @brief Load a shader - from either cache or by fetching data from the
-     * given arguments - and return its identifier.
-     * A shader is a type of program that is run on the GPU by a library like
-     * OpenGL.
-     * @param type A shader type describe what it draws...
-     * @param path The path to the shader's source code file.
-     */
-    identity<shader> get(shaders::type type, std::string const & path) const;
-    /**
-     * @brief Load a shader_program - from either cache or by fetching data from
-     * the given arguments - and return its identifier.
-     * @param fragment The file path to the fragment shader code.
-     * @param vertex The file path to the vertex shader code.
-     */
-    identity<shader_program> get(std::string const & fragment,
-                                 std::string const & vertex) const;
-    /**
-     * @brief Load a texture - from either cache or by fetching data from the
-     * given arguments - and return its identifier.
-     * @param path The file path to an imagefile that contains one or more
-     * drawings of the object to be rendered.
-     */
-    identity<texture> get(std::string const & path) const;
+  /**
+   * @brief Load a material - from either cache or by fetching data from the
+   * given arguments - and return its identifier.
+   * A material is a linkage of shader(s) and texture(s), that desribe the
+   * needed details to draw it on a page.
+   * @param program The shader program that should be used to paint this
+   * material.
+   * @param texture The path to an image file for this material
+   * @param uniform The name of the uniform to use as a fallback texture
+   */
+  identity<material> get(identity<shader_program> program,
+                         std::string const & texture,
+                         std::string const & uniform) const;
+  /**
+   * @brief Load a shader - from either cache or by fetching data from the
+   * given arguments - and return its identifier.
+   * A shader is a type of program that is run on the GPU by a library like
+   * OpenGL.
+   * @param type A shader type describe what it draws...
+   * @param path The path to the shader's source code file.
+   */
+  identity<shader> get(shaders::type type, std::string const & path) const;
+  /**
+   * @brief Load a shader_program - from either cache or by fetching data from
+   * the given arguments - and return its identifier.
+   * @param fragment The file path to the fragment shader code.
+   * @param vertex The file path to the vertex shader code.
+   */
+  identity<shader_program> get(std::string const & fragment,
+                               std::string const & vertex) const;
+  /**
+   * @brief Load a texture - from either cache or by fetching data from the
+   * given arguments - and return its identifier.
+   * @param path The file path to an imagefile that contains one or more
+   * drawings of the object to be rendered.
+   */
+  identity<texture> get(std::string const & path) const;
 
-    // TODO: This is kinda dumb...
-    object create_object(identity<material> fromMaterial, math::vec2 atPosition,
-                         math::vec2 frameWidth, float scale) const;
+  // TODO: This is kinda dumb...
+  object create_object(identity<material> fromMaterial, math::vec2 atPosition,
+                       math::vec2 frameWidth, float scale) const;
 
-    /**
-     * @brief Translate a material identity into an actual object.
-     * Used for internal linkage with the implementation code.
-     */
-    material const & get(identity<material> identity) const;
-    /**
-     * @brief Translate a texture identity into an actual object.
-     * Used for internal linkage with the implementation code.
-     */
-    texture const & get(identity<texture> identity) const;
+  /**
+   * @brief Translate a material identity into an actual object.
+   * Used for internal linkage with the implementation code.
+   */
+  material const & get(identity<material> identity) const;
+  /**
+   * @brief Translate a texture identity into an actual object.
+   * Used for internal linkage with the implementation code.
+   */
+  texture const & get(identity<texture> identity) const;
 
-  private:
-    void prepare_uniforms() const;
-    identity<texture> texture_or_uniform(std::string const & path,
-                                         std::string const & uniform) const;
+private:
+  void prepare_uniforms() const;
+  identity<texture> texture_or_uniform(std::string const & path,
+                                       std::string const & uniform) const;
 
-    virtual shader compile(shaders::type type,
-                           std::string const & path) const = 0;
-    virtual shader_program compile(identity<shader> fragment,
-                                   identity<shader> vertex) const = 0;
-    virtual texture compile(textures::format color, math::vec2i size,
-                            void const * buffer) const = 0;
+  virtual shader compile(shaders::type type,
+                         std::string const & path) const = 0;
+  virtual shader_program compile(identity<shader> fragment,
+                                 identity<shader> vertex) const = 0;
+  virtual texture compile(textures::format color, math::vec2i size,
+                          void const * buffer) const = 0;
 
-    std::unique_ptr<struct manager_cache> pcache_;
-  };
+  std::unique_ptr<struct manager_cache> pcache_;
+};
 }

+ 12 - 12
graphics/include/game/graphics/material.hpp

@@ -14,18 +14,18 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  struct uniform {
-    identity<texture> texture;
-    materials::uniform
-        uniform_id; // TODO (sjaffe): use an enum and hide remapping?
-  };
+struct uniform {
+  identity<texture> texture;
+  materials::uniform
+      uniform_id; // TODO (sjaffe): use an enum and hide remapping?
+};
 
-  struct material : public identity<material> {
-    material(identity<shader_program> const & sp, math::vec2i size,
-             std::vector<uniform> const & uniforms);
+struct material : public identity<material> {
+  material(identity<shader_program> const & sp, math::vec2i size,
+           std::vector<uniform> const & uniforms);
 
-    identity<shader_program> program;
-    math::vec2i size;
-    std::vector<uniform> uniforms;
-  };
+  identity<shader_program> program;
+  math::vec2i size;
+  std::vector<uniform> uniforms;
+};
 }

+ 8 - 8
graphics/include/game/graphics/object.hpp

@@ -15,13 +15,13 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  struct object {
-    math::dim2::rectangle location;
-    math::dim2::quad points;
-    identity<material> material;
-    math::dim2::rectangle frame;
-  }; // size:56, align:4
+struct object {
+  math::dim2::rectangle location;
+  math::dim2::quad points;
+  identity<material> material;
+  math::dim2::rectangle frame;
+}; // size:56, align:4
 
-  void vertices(std::vector<vertex> & out, object const & obj);
-  void vertices(std::vector<vertex> & out, std::vector<object> const & obj);
+void vertices(std::vector<vertex> & out, object const & obj);
+void vertices(std::vector<vertex> & out, std::vector<object> const & obj);
 }

+ 47 - 47
graphics/include/game/graphics/renderer.hpp

@@ -17,57 +17,57 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  struct renderer {
-    virtual ~renderer() {}
-    virtual std::shared_ptr<manager const> manager() const = 0;
-    virtual void draw(object const & obj) = 0;
-    virtual void draw(identity<material>, math::matr4 const &,
-                      std::vector<vertex> const &) = 0;
-    virtual void clear() = 0;
-    virtual void flush() = 0;
-  };
+struct renderer {
+  virtual ~renderer() {}
+  virtual std::shared_ptr<manager const> manager() const = 0;
+  virtual void draw(object const & obj) = 0;
+  virtual void draw(identity<material>, math::matr4 const &,
+                    std::vector<vertex> const &) = 0;
+  virtual void clear() = 0;
+  virtual void flush() = 0;
+};
 
-  enum class driver {}; // Dummy class...
+enum class driver {}; // Dummy class...
 
-  class direct_renderer : public renderer {
-  public:
-    direct_renderer(std::string const & driver_id);
-    direct_renderer(class renderer_impl * pi);
-    std::shared_ptr<class manager const> manager() const override;
-    void draw(object const & obj) override;
-    void draw(identity<material>, math::matr4 const &,
-              std::vector<vertex> const &) override;
-    void clear() override;
-    void flush() override;
+class direct_renderer : public renderer {
+public:
+  direct_renderer(std::string const & driver_id);
+  direct_renderer(class renderer_impl * pi);
+  std::shared_ptr<class manager const> manager() const override;
+  void draw(object const & obj) override;
+  void draw(identity<material>, math::matr4 const &,
+            std::vector<vertex> const &) override;
+  void clear() override;
+  void flush() override;
 
-  private:
-    struct renderer_impl * pimpl;
-  };
+private:
+  struct renderer_impl * pimpl;
+};
 
-  class batch_renderer : public renderer {
-  public:
-    batch_renderer(renderer * impl, std::size_t batch_size = 0);
-    batch_renderer(renderer * impl, math::matr4 const &,
-                   std::size_t batch_size = 0);
-    ~batch_renderer();
-    std::shared_ptr<class manager const> manager() const override {
-      return impl_->manager();
-    }
-    void draw(object const & obj) override;
-    void draw(identity<material>, math::matr4 const &,
-              std::vector<vertex> const &) override;
-    void clear() override { impl_->clear(); }
-    void flush() override;
+class batch_renderer : public renderer {
+public:
+  batch_renderer(renderer * impl, std::size_t batch_size = 0);
+  batch_renderer(renderer * impl, math::matr4 const &,
+                 std::size_t batch_size = 0);
+  ~batch_renderer();
+  std::shared_ptr<class manager const> manager() const override {
+    return impl_->manager();
+  }
+  void draw(object const & obj) override;
+  void draw(identity<material>, math::matr4 const &,
+            std::vector<vertex> const &) override;
+  void clear() override { impl_->clear(); }
+  void flush() override;
 
-  private:
-    void check();
-    void write();
+private:
+  void check();
+  void write();
 
-  private:
-    renderer * impl_;
-    std::unordered_map<identity<material>, std::vector<vertex>> batches_;
-    math::matr4 object_to_world_;
-    std::size_t batch_size_;
-    std::size_t elements_;
-  };
+private:
+  renderer * impl_;
+  std::unordered_map<identity<material>, std::vector<vertex>> batches_;
+  math::matr4 object_to_world_;
+  std::size_t batch_size_;
+  std::size_t elements_;
+};
 }

+ 5 - 5
graphics/include/game/graphics/shader.hpp

@@ -12,10 +12,10 @@
 #include "game/graphics/graphics_fwd.h"
 
 namespace graphics {
-  struct shader : public identity<shader> {
-    shader(unsigned int id, shaders::type, std::string const &);
+struct shader : public identity<shader> {
+  shader(unsigned int id, shaders::type, std::string const &);
 
-    shaders::type type;
-    std::string path;
-  };
+  shaders::type type;
+  std::string path;
+};
 }

+ 5 - 5
graphics/include/game/graphics/shader_program.hpp

@@ -12,10 +12,10 @@
 #include "game/graphics/graphics_fwd.h"
 
 namespace graphics {
-  struct shader_program : public identity<shader_program> {
-    shader_program(unsigned int id, identity<shader>, identity<shader>);
+struct shader_program : public identity<shader_program> {
+  shader_program(unsigned int id, identity<shader>, identity<shader>);
 
-    identity<shader> fragment_shader;
-    identity<shader> vertex_shader;
-  };
+  identity<shader> fragment_shader;
+  identity<shader> vertex_shader;
+};
 }

+ 4 - 4
graphics/include/game/graphics/texture.hpp

@@ -12,9 +12,9 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  struct texture : public identity<texture> {
-    texture(unsigned int id, math::vec2i const & size);
+struct texture : public identity<texture> {
+  texture(unsigned int id, math::vec2i const & size);
 
-    math::vec2i const size;
-  };
+  math::vec2i const size;
+};
 }

+ 4 - 4
graphics/include/game/graphics/vertex.h

@@ -12,8 +12,8 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  struct vertex {
-    math::vec2 position, texture_coords;
-    math::rgba color;
-  };
+struct vertex {
+  math::vec2 position, texture_coords;
+  math::rgba color;
+};
 }

+ 26 - 26
graphics/src/helper.hpp

@@ -16,34 +16,34 @@
 #include "vector/vector.hpp"
 
 namespace graphics {
-  namespace textures {
-    enum class format : unsigned int { RGB, RGBA };
-    struct external_data {
-      external_data(std::string const & abs_path);
-      ~external_data();
-      format color;
-      math::vec2i size;
-      void * buffer;
-    };
-  }
-  namespace shaders {
-    enum class type : unsigned int { FRAGMENT, VERTEX };
-  }
-  namespace materials {
-    enum class uniform : unsigned int { NORMAL, DIFFUSE, SPECULAR };
-  }
+namespace textures {
+  enum class format : unsigned int { RGB, RGBA };
+  struct external_data {
+    external_data(std::string const & abs_path);
+    ~external_data();
+    format color;
+    math::vec2i size;
+    void * buffer;
+  };
+}
+namespace shaders {
+  enum class type : unsigned int { FRAGMENT, VERTEX };
+}
+namespace materials {
+  enum class uniform : unsigned int { NORMAL, DIFFUSE, SPECULAR };
+}
 }
 
 namespace std {
-  template <> struct hash<graphics::shaders::type> {
-    std::size_t operator()(graphics::shaders::type tp) const {
-      return std::hash<unsigned int>()(static_cast<unsigned int>(tp));
-    }
-  };
+template <> struct hash<graphics::shaders::type> {
+  std::size_t operator()(graphics::shaders::type tp) const {
+    return std::hash<unsigned int>()(static_cast<unsigned int>(tp));
+  }
+};
 
-  template <> struct hash<graphics::materials::uniform> {
-    std::size_t operator()(graphics::materials::uniform uf) const {
-      return std::hash<unsigned int>()(static_cast<unsigned int>(uf));
-    }
-  };
+template <> struct hash<graphics::materials::uniform> {
+  std::size_t operator()(graphics::materials::uniform uf) const {
+    return std::hash<unsigned int>()(static_cast<unsigned int>(uf));
+  }
+};
 }

+ 32 - 32
graphics/src/matrix.cxx

@@ -12,39 +12,39 @@
 #include "matrix/matrix.hpp"
 
 namespace graphics {
-  math::matr4 orthogonal_view(float left, float right, float bottom, float top,
-                              float near, float far) {
-    math::matr4 matrix;
-    matrix(0, 0) = 2.f / (right - left);
-    matrix(1, 1) = 2.f / (top - bottom);
-    matrix(2, 2) = -2.f / (far - near);
-    matrix(0, 3) = -(right + left) / (right - left);
-    matrix(1, 3) = -(top + bottom) / (top - bottom);
-    matrix(2, 3) = -(far + near) / (far - near);
-    matrix(3, 3) = 1.f;
-    return matrix;
-  }
+math::matr4 orthogonal_view(float left, float right, float bottom, float top,
+                            float near, float far) {
+  math::matr4 matrix;
+  matrix(0, 0) = 2.f / (right - left);
+  matrix(1, 1) = 2.f / (top - bottom);
+  matrix(2, 2) = -2.f / (far - near);
+  matrix(0, 3) = -(right + left) / (right - left);
+  matrix(1, 3) = -(top + bottom) / (top - bottom);
+  matrix(2, 3) = -(far + near) / (far - near);
+  matrix(3, 3) = 1.f;
+  return matrix;
+}
 
-  math::matr4 frustum_view(float left, float right, float bottom, float top,
-                           float near, float far) {
-    math::matr4 matrix;
-    matrix(0, 0) = 2.f * near / (right - left);
-    matrix(1, 1) = 2.f * near / (top - bottom);
-    matrix(2, 0) = (right + left) / (right - left);
-    matrix(2, 1) = (top + bottom) / (top - bottom);
-    matrix(2, 2) = -(far + near) / (far - near);
-    matrix(2, 3) = -1.f;
-    matrix(3, 2) = -(2.f * far * near) / (far - near);
-    matrix(3, 3) = 0.f;
-    return matrix;
-  }
+math::matr4 frustum_view(float left, float right, float bottom, float top,
+                         float near, float far) {
+  math::matr4 matrix;
+  matrix(0, 0) = 2.f * near / (right - left);
+  matrix(1, 1) = 2.f * near / (top - bottom);
+  matrix(2, 0) = (right + left) / (right - left);
+  matrix(2, 1) = (top + bottom) / (top - bottom);
+  matrix(2, 2) = -(far + near) / (far - near);
+  matrix(2, 3) = -1.f;
+  matrix(3, 2) = -(2.f * far * near) / (far - near);
+  matrix(3, 3) = 0.f;
+  return matrix;
+}
 
-  math::matr4 perspective(math::degree fovY, float aspect, float front,
-                          float back) {
-    float tangent = tan(fovY);
-    float height = front * tangent;
-    float width = height * aspect;
+math::matr4 perspective(math::degree fovY, float aspect, float front,
+                        float back) {
+  float tangent = tan(fovY);
+  float height = front * tangent;
+  float width = height * aspect;
 
-    return frustum_view(-width, width, -height, height, front, back);
-  }
+  return frustum_view(-width, width, -height, height, front, back);
+}
 }

+ 6 - 6
graphics/src/matrix.hpp

@@ -11,10 +11,10 @@
 #include "game/math/math_fwd.hpp"
 
 namespace graphics {
-  math::matr4 orthogonal_view(float left, float right, float bottom, float top,
-                              float near, float far);
-  math::matr4 frustum_view(float left, float right, float bottom, float top,
-                           float near, float far);
-  math::matr4 perspective(math::degree fovY, float aspect, float front,
-                          float back);
+math::matr4 orthogonal_view(float left, float right, float bottom, float top,
+                            float near, float far);
+math::matr4 frustum_view(float left, float right, float bottom, float top,
+                         float near, float far);
+math::matr4 perspective(math::degree fovY, float aspect, float front,
+                        float back);
 }

+ 25 - 25
graphics/src/openGL/error_formatter.cxx

@@ -79,29 +79,29 @@ void error_formatter::operator()() const {
 }
 
 namespace graphics {
-  void print_shader_error(GLuint id, std::string const & path) {
-    std::string fileName = path.substr(path.find_last_of("/") + 1);
-    error_formatter{id,
-                    fileName,
-                    path,
-                    "GLSL shader compile error!",
-                    "File location: " + path,
-                    "GLSL Compile Error in " + fileName,
-                    glGetShaderiv,
-                    glGetShaderInfoLog}();
-  }
-
-  void print_shader_program_error(GLuint id, std::string const & frag_path,
-                                  std::string const & vert_path) {
-    std::string fileName = frag_path.substr(frag_path.find_last_of("/") + 1);
-    error_formatter{id,
-                    fileName,
-                    frag_path,
-                    "GLSL program link error!",
-                    "File location of vertex shader: " + vert_path +
-                        "\nFile location of fragment shader: " + frag_path,
-                    "GLSL Link Error",
-                    glGetProgramiv,
-                    glGetProgramInfoLog}();
-  }
+void print_shader_error(GLuint id, std::string const & path) {
+  std::string fileName = path.substr(path.find_last_of("/") + 1);
+  error_formatter{id,
+                  fileName,
+                  path,
+                  "GLSL shader compile error!",
+                  "File location: " + path,
+                  "GLSL Compile Error in " + fileName,
+                  glGetShaderiv,
+                  glGetShaderInfoLog}();
+}
+
+void print_shader_program_error(GLuint id, std::string const & frag_path,
+                                std::string const & vert_path) {
+  std::string fileName = frag_path.substr(frag_path.find_last_of("/") + 1);
+  error_formatter{id,
+                  fileName,
+                  frag_path,
+                  "GLSL program link error!",
+                  "File location of vertex shader: " + vert_path +
+                      "\nFile location of fragment shader: " + frag_path,
+                  "GLSL Link Error",
+                  glGetProgramiv,
+                  glGetProgramInfoLog}();
+}
 }

+ 23 - 23
graphics/src/openGL/opengl_manager.cxx

@@ -29,40 +29,40 @@
 #include "game/util/time.hpp"
 
 namespace graphics {
-  extern void print_shader_error(GLuint, std::string const &);
-  extern void print_shader_program_error(GLuint, std::string const &,
-                                         std::string const &);
+extern void print_shader_error(GLuint, std::string const &);
+extern void print_shader_program_error(GLuint, std::string const &,
+                                       std::string const &);
 
-  struct compilation_error : std::runtime_error {
-    using std::runtime_error::runtime_error;
-  };
+struct compilation_error : std::runtime_error {
+  using std::runtime_error::runtime_error;
+};
 
-  struct linker_error : std::runtime_error {
-    using std::runtime_error::runtime_error;
-  };
+struct linker_error : std::runtime_error {
+  using std::runtime_error::runtime_error;
+};
 }
 
 using namespace graphics;
 
 namespace {
-  int glfmt(textures::format color_fmt) {
-    switch (color_fmt) {
-    case textures::format::RGB:
-      return GL_RGB;
-    case textures::format::RGBA:
-      return GL_RGBA;
-    }
+int glfmt(textures::format color_fmt) {
+  switch (color_fmt) {
+  case textures::format::RGB:
+    return GL_RGB;
+  case textures::format::RGBA:
+    return GL_RGBA;
   }
+}
 
-  int gltype(shaders::type tp) {
-    switch (tp) {
-    case shaders::type::FRAGMENT:
-      return GL_FRAGMENT_SHADER;
-    case shaders::type::VERTEX:
-      return GL_VERTEX_SHADER;
-    }
+int gltype(shaders::type tp) {
+  switch (tp) {
+  case shaders::type::FRAGMENT:
+    return GL_FRAGMENT_SHADER;
+  case shaders::type::VERTEX:
+    return GL_VERTEX_SHADER;
   }
 }
+}
 
 texture opengl_manager::compile(textures::format color, math::vec2i size,
                                 void const * buffer) const {

+ 2 - 2
graphics/src/openGL/opengl_renderer.cxx

@@ -120,6 +120,6 @@ renderer_impl * get_openGL() {
 }
 
 namespace {
-  bool _ =
-      graphics::renderer_impl_factory::instance().bind("openGL", &get_openGL);
+bool _ =
+    graphics::renderer_impl_factory::instance().bind("openGL", &get_openGL);
 }

+ 36 - 36
graphics/src/openGL/opengl_renderer.h

@@ -17,50 +17,50 @@
 #include "matrix/matrix_helpers.hpp"
 
 namespace graphics {
-  struct opengl_uniform_data {
-    unsigned int operator[](materials::uniform id) { return uniform_id[id]; }
-    std::unordered_map<materials::uniform, unsigned int> uniform_id;
-  };
+struct opengl_uniform_data {
+  unsigned int operator[](materials::uniform id) { return uniform_id[id]; }
+  std::unordered_map<materials::uniform, unsigned int> uniform_id;
+};
 
-  class opengl_manager : public manager {
-  public:
-    shader compile(shaders::type type, std::string const & path) const override;
-    shader_program compile(identity<shader> fragment,
-                           identity<shader> vertex) const override;
-    texture compile(textures::format color, math::vec2i size,
-                    void const * buffer) const override;
+class opengl_manager : public manager {
+public:
+  shader compile(shaders::type type, std::string const & path) const override;
+  shader_program compile(identity<shader> fragment,
+                         identity<shader> vertex) const override;
+  texture compile(textures::format color, math::vec2i size,
+                  void const * buffer) const override;
 
-    opengl_uniform_data & data(identity<shader_program> id);
+  opengl_uniform_data & data(identity<shader_program> id);
 
-  private:
-    std::unordered_map<identity<shader_program>, opengl_uniform_data> data_;
-  };
+private:
+  std::unordered_map<identity<shader_program>, opengl_uniform_data> data_;
+};
 
-  class opengl_renderer : public renderer_impl {
-  public:
-    opengl_renderer();
-    ~opengl_renderer();
+class opengl_renderer : public renderer_impl {
+public:
+  opengl_renderer();
+  ~opengl_renderer();
 
-    void draw(identity<material>, math::matr4 const &,
-              std::vector<vertex> const &) override;
-    void clear() override;
-    void flush() override;
+  void draw(identity<material>, math::matr4 const &,
+            std::vector<vertex> const &) override;
+  void clear() override;
+  void flush() override;
 
-    std::shared_ptr<class manager const> manager() const override {
-      return manager_;
-    }
+  std::shared_ptr<class manager const> manager() const override {
+    return manager_;
+  }
 
-  private:
-    void activate(material const & mat);
+private:
+  void activate(material const & mat);
 
-  private:
-    const math::matr4 identity{math::matrix::identity<float, 4>()};
+private:
+  const math::matr4 identity{math::matrix::identity<float, 4>()};
 
-    std::shared_ptr<opengl_manager> manager_;
-    unsigned int active_material;
+  std::shared_ptr<opengl_manager> manager_;
+  unsigned int active_material;
 
-    math::matr4 world_to_clip{identity};
-    double current_time{0.0};
-    unsigned int vertex_array_object{0}, vertex_buffer_object{0};
-  };
+  math::matr4 world_to_clip{identity};
+  double current_time{0.0};
+  unsigned int vertex_array_object{0}, vertex_buffer_object{0};
+};
 }

+ 1 - 1
graphics/src/renderer.cxx

@@ -26,7 +26,7 @@ renderer_impl * get_renderer_impl(std::string const & id) {
 }
 
 namespace {
-  const math::matr4 identity4 = math::matrix::identity<float, 4>();
+const math::matr4 identity4 = math::matrix::identity<float, 4>();
 }
 
 direct_renderer::direct_renderer(std::string const & driver_id)

+ 9 - 9
graphics/src/renderer_impl.hpp

@@ -15,14 +15,14 @@
 #include "resource_factory/prototype_factory.hpp"
 
 namespace graphics {
-  using renderer_impl_factory = objects::prototype::factory<renderer_impl *>;
+using renderer_impl_factory = objects::prototype::factory<renderer_impl *>;
 
-  struct renderer_impl {
-    virtual ~renderer_impl() {}
-    virtual std::shared_ptr<manager const> manager() const = 0;
-    virtual void draw(identity<material>, math::matr4 const &,
-                      std::vector<vertex> const &) = 0;
-    virtual void clear() = 0;
-    virtual void flush() = 0;
-  };
+struct renderer_impl {
+  virtual ~renderer_impl() {}
+  virtual std::shared_ptr<manager const> manager() const = 0;
+  virtual void draw(identity<material>, math::matr4 const &,
+                    std::vector<vertex> const &) = 0;
+  virtual void clear() = 0;
+  virtual void flush() = 0;
+};
 }

+ 15 - 15
math/include/game/math/angle.hpp

@@ -8,21 +8,21 @@
 #pragma once
 
 namespace math {
-  struct degree {
-    degree(double v);
-    degree operator-() const;
-    double value;
-  };
+struct degree {
+  degree(double v);
+  degree operator-() const;
+  double value;
+};
 
-  struct radian {
-    radian(double v);
-    radian(degree d);
-    radian operator-() const;
-    operator degree() const;
-    double value;
-  };
+struct radian {
+  radian(double v);
+  radian(degree d);
+  radian operator-() const;
+  operator degree() const;
+  double value;
+};
 
-  double sin(radian r);
-  double cos(radian r);
-  double tan(radian r);
+double sin(radian r);
+double cos(radian r);
+double tan(radian r);
 }

+ 24 - 24
math/include/game/math/common.hpp

@@ -10,33 +10,33 @@
 #include "math_fwd.hpp"
 
 namespace math {
-  vec2 rotate(vec2 const & point, radian r);
-  vec2 rotate(vec2 const & center, vec2 const & point, radian r);
-  dim2::quad rotate(vec2 const & center, dim2::quad const & q, radian r);
+vec2 rotate(vec2 const & point, radian r);
+vec2 rotate(vec2 const & center, vec2 const & point, radian r);
+dim2::quad rotate(vec2 const & center, dim2::quad const & q, radian r);
 
-  bool contains(dim2::line const & shape, dim2::point const & pt);
-  bool contains(dim2::circle const & shape, dim2::point const & pt);
-  bool contains(dim2::quad const & shape, dim2::point const & pt);
+bool contains(dim2::line const & shape, dim2::point const & pt);
+bool contains(dim2::circle const & shape, dim2::point const & pt);
+bool contains(dim2::quad const & shape, dim2::point const & pt);
 
-  bool intersects(dim2::line const & lhs, dim2::line const & rhs);
-  bool intersects(dim2::line const & lhs, dim2::circle const & rhs);
-  bool intersects(dim2::line const & lhs, dim2::quad const & rhs);
-  bool intersects(dim2::quad const & lhs, dim2::line const & rhs);
-  bool intersects(dim2::quad const & lhs, dim2::circle const & rhs);
-  bool intersects(dim2::quad const & lhs, dim2::quad const & rhs);
-  bool intersects(dim2::circle const & lhs, dim2::line const & rhs);
-  bool intersects(dim2::circle const & lhs, dim2::quad const & rhs);
-  bool intersects(dim2::circle const & lhs, dim2::circle const & rhs);
+bool intersects(dim2::line const & lhs, dim2::line const & rhs);
+bool intersects(dim2::line const & lhs, dim2::circle const & rhs);
+bool intersects(dim2::line const & lhs, dim2::quad const & rhs);
+bool intersects(dim2::quad const & lhs, dim2::line const & rhs);
+bool intersects(dim2::quad const & lhs, dim2::circle const & rhs);
+bool intersects(dim2::quad const & lhs, dim2::quad const & rhs);
+bool intersects(dim2::circle const & lhs, dim2::line const & rhs);
+bool intersects(dim2::circle const & lhs, dim2::quad const & rhs);
+bool intersects(dim2::circle const & lhs, dim2::circle const & rhs);
 }
 
 namespace math {
-  inline bool intersects(dim2::quad const & lhs, dim2::line const & rhs) {
-    return intersects(rhs, lhs);
-  }
-  inline bool intersects(dim2::circle const & lhs, dim2::line const & rhs) {
-    return intersects(rhs, lhs);
-  }
-  inline bool intersects(dim2::circle const & lhs, dim2::quad const & rhs) {
-    return intersects(rhs, lhs);
-  }
+inline bool intersects(dim2::quad const & lhs, dim2::line const & rhs) {
+  return intersects(rhs, lhs);
+}
+inline bool intersects(dim2::circle const & lhs, dim2::line const & rhs) {
+  return intersects(rhs, lhs);
+}
+inline bool intersects(dim2::circle const & lhs, dim2::quad const & rhs) {
+  return intersects(rhs, lhs);
+}
 }

+ 35 - 35
math/include/game/math/compare.hpp

@@ -4,39 +4,39 @@
 #include <cmath>
 
 namespace math {
-  template <typename T> T safe_div(T num, T denom) {
-    return (num == denom && denom == 0) ? 0 : num / denom;
-  }
-
-  template <typename T> bool between_exclusive(T val, T min, T max) {
-    return val >= min && val < max;
-  }
-
-  template <typename T> bool between(T val, T min, T max) {
-    return val >= min && val <= max;
-  }
-
-  template <typename T> bool approx_equal(T lhs, T rhs, T eps) {
-    T const a = std::abs(lhs);
-    T const b = std::abs(rhs);
-    return std::abs(lhs - rhs) <= (std::max(a, b) * eps);
-  }
-
-  template <typename T> bool essentially_equal(T lhs, T rhs, T eps) {
-    T const a = std::abs(lhs);
-    T const b = std::abs(rhs);
-    return std::abs(lhs - rhs) <= (std::min(a, b) * eps);
-  }
-
-  template <typename T> bool definitely_greater(T lhs, T rhs, T eps) {
-    T const a = std::abs(lhs);
-    T const b = std::abs(rhs);
-    return (lhs - rhs) > (std::max(a, b) * eps);
-  }
-
-  template <typename T> bool definitely_less(T lhs, T rhs, T eps) {
-    T const a = std::abs(lhs);
-    T const b = std::abs(rhs);
-    return (rhs - lhs) > (std::max(a, b) * eps);
-  }
+template <typename T> T safe_div(T num, T denom) {
+  return (num == denom && denom == 0) ? 0 : num / denom;
+}
+
+template <typename T> bool between_exclusive(T val, T min, T max) {
+  return val >= min && val < max;
+}
+
+template <typename T> bool between(T val, T min, T max) {
+  return val >= min && val <= max;
+}
+
+template <typename T> bool approx_equal(T lhs, T rhs, T eps) {
+  T const a = std::abs(lhs);
+  T const b = std::abs(rhs);
+  return std::abs(lhs - rhs) <= (std::max(a, b) * eps);
+}
+
+template <typename T> bool essentially_equal(T lhs, T rhs, T eps) {
+  T const a = std::abs(lhs);
+  T const b = std::abs(rhs);
+  return std::abs(lhs - rhs) <= (std::min(a, b) * eps);
+}
+
+template <typename T> bool definitely_greater(T lhs, T rhs, T eps) {
+  T const a = std::abs(lhs);
+  T const b = std::abs(rhs);
+  return (lhs - rhs) > (std::max(a, b) * eps);
+}
+
+template <typename T> bool definitely_less(T lhs, T rhs, T eps) {
+  T const a = std::abs(lhs);
+  T const b = std::abs(rhs);
+  return (rhs - lhs) > (std::max(a, b) * eps);
+}
 }

+ 26 - 26
math/include/game/math/math_fwd.hpp

@@ -11,33 +11,33 @@
 #include <cstdint>
 
 namespace math {
-  namespace vector {
-    template <typename, size_t> class vector;
-  }
-  namespace matrix {
-    template <typename, size_t, size_t> class matrix;
-
-    template <typename T, size_t N> using square_matrix = matrix<T, N, N>;
-  }
+namespace vector {
+  template <typename, size_t> class vector;
+}
+namespace matrix {
+  template <typename, size_t, size_t> class matrix;
+
+  template <typename T, size_t N> using square_matrix = matrix<T, N, N>;
+}
 }
 
 namespace math {
-  using vec2i = vector::vector<int, 2>;
-  using vec2 = vector::vector<float, 2>;
-  using vec3 = vector::vector<float, 3>;
-  using rgba = vector::vector<uint8_t, 4>;
-
-  using matr4 = matrix::matrix<float, 4, 4>;
-
-  namespace dim2 {
-    using point = vec2;
-    struct line;
-    struct circle;
-    struct quad;
-    struct rectangle;
-    struct square;
-  }
-
-  struct degree;
-  struct radian;
+using vec2i = vector::vector<int, 2>;
+using vec2 = vector::vector<float, 2>;
+using vec3 = vector::vector<float, 3>;
+using rgba = vector::vector<uint8_t, 4>;
+
+using matr4 = matrix::matrix<float, 4, 4>;
+
+namespace dim2 {
+  using point = vec2;
+  struct line;
+  struct circle;
+  struct quad;
+  struct rectangle;
+  struct square;
+}
+
+struct degree;
+struct radian;
 }

+ 9 - 9
math/src/angle.cpp

@@ -10,15 +10,15 @@
 #include <cmath>
 
 namespace math {
-  degree::degree(double v) : value(v) {}
-  degree degree::operator-() const { return degree(-value); }
+degree::degree(double v) : value(v) {}
+degree degree::operator-() const { return degree(-value); }
 
-  radian::radian(double v) : value(v) {}
-  radian::radian(degree d) : value(d.value * M_PI / 180.f) {}
-  radian radian::operator-() const { return radian(-value); }
-  radian::operator degree() const { return {value * M_1_PI * 180.f}; }
+radian::radian(double v) : value(v) {}
+radian::radian(degree d) : value(d.value * M_PI / 180.f) {}
+radian radian::operator-() const { return radian(-value); }
+radian::operator degree() const { return {value * M_1_PI * 180.f}; }
 
-  double sin(radian r) { return std::sin(r.value); }
-  double cos(radian r) { return std::cos(r.value); }
-  double tan(radian r) { return std::tan(r.value); }
+double sin(radian r) { return std::sin(r.value); }
+double cos(radian r) { return std::cos(r.value); }
+double tan(radian r) { return std::tan(r.value); }
 }

+ 107 - 107
math/src/common.cpp

@@ -14,132 +14,132 @@
 #include "game/math/shape.hpp"
 
 namespace math {
-  vec2 rotate(vec2 const & point, radian r) {
-    vec2 vcos = point * static_cast<float>(cos(r));
-    vec2 vsin = point * static_cast<float>(sin(r));
-    return {{vcos[0] - vsin[1], vsin[0] + vcos[1]}};
-  }
+vec2 rotate(vec2 const & point, radian r) {
+  vec2 vcos = point * static_cast<float>(cos(r));
+  vec2 vsin = point * static_cast<float>(sin(r));
+  return {{vcos[0] - vsin[1], vsin[0] + vcos[1]}};
+}
 
-  vec2 rotate(vec2 const & c, vec2 const & p, radian r) {
-    return rotate(p - c, r) + c;
-  }
+vec2 rotate(vec2 const & c, vec2 const & p, radian r) {
+  return rotate(p - c, r) + c;
+}
 
-  dim2::quad rotate(vec2 const & c, dim2::quad const & q, radian r) {
-    return {rotate(c, q.ll, r), rotate(c, q.lr, r), rotate(c, q.ur, r),
-            rotate(c, q.ul, r)};
-  }
+dim2::quad rotate(vec2 const & c, dim2::quad const & q, radian r) {
+  return {rotate(c, q.ll, r), rotate(c, q.lr, r), rotate(c, q.ur, r),
+          rotate(c, q.ul, r)};
+}
 
-  enum orientation { colinear = 0, clockwise = 1, anticlockwise = 2 };
+enum orientation { colinear = 0, clockwise = 1, anticlockwise = 2 };
 
-  orientation orient(dim2::line const & ln, dim2::point const & pt) {
-    auto val = (ln.second[1] - ln.first[1]) * (pt[0] - ln.second[0]) -
-               (ln.second[0] - ln.first[0]) * (pt[1] - ln.second[1]);
+orientation orient(dim2::line const & ln, dim2::point const & pt) {
+  auto val = (ln.second[1] - ln.first[1]) * (pt[0] - ln.second[0]) -
+             (ln.second[0] - ln.first[0]) * (pt[1] - ln.second[1]);
 
-    if (val == 0) return colinear;
-    return (val > 0) ? clockwise : anticlockwise;
-  }
+  if (val == 0) return colinear;
+  return (val > 0) ? clockwise : anticlockwise;
+}
 
-  bool contains(dim2::line const & ln, dim2::point const & pt) {
-    auto xs = std::minmax(ln.first[0], ln.second[0]);
-    auto ys = std::minmax(ln.first[1], ln.second[1]);
-    return orient(ln, pt) == colinear && between(pt[0], xs.first, xs.second) &&
-           between(pt[1], ys.first, ys.second);
-  }
+bool contains(dim2::line const & ln, dim2::point const & pt) {
+  auto xs = std::minmax(ln.first[0], ln.second[0]);
+  auto ys = std::minmax(ln.first[1], ln.second[1]);
+  return orient(ln, pt) == colinear && between(pt[0], xs.first, xs.second) &&
+         between(pt[1], ys.first, ys.second);
+}
 
-  bool contains(dim2::circle const & shape, dim2::point const & pt) {
-    vec2 const delta = pt - shape.center;
-    return delta.dot(delta) <= std::pow(shape.radius, 2);
-  }
+bool contains(dim2::circle const & shape, dim2::point const & pt) {
+  vec2 const delta = pt - shape.center;
+  return delta.dot(delta) <= std::pow(shape.radius, 2);
+}
 
-  static dim2::line ray_x(dim2::point const & pt, dim2::line const & l) {
-    auto x_inf = std::max({l.first[0], l.second[0], pt[0]}) + 1;
-    return {pt, {{x_inf, pt[1]}}};
-  }
+static dim2::line ray_x(dim2::point const & pt, dim2::line const & l) {
+  auto x_inf = std::max({l.first[0], l.second[0], pt[0]}) + 1;
+  return {pt, {{x_inf, pt[1]}}};
+}
 
-  static bool contains(std::vector<dim2::line> const & segments,
-                       dim2::point const & pt) {
-    int hits = 0;
-    for (auto l : segments) {
-      if (!intersects(l, ray_x(pt, l))) continue;
-      if (orient(l, pt) == colinear) return contains(l, pt);
-      ++hits;
-    }
-    return (hits & 1) == 1;
+static bool contains(std::vector<dim2::line> const & segments,
+                     dim2::point const & pt) {
+  int hits = 0;
+  for (auto l : segments) {
+    if (!intersects(l, ray_x(pt, l))) continue;
+    if (orient(l, pt) == colinear) return contains(l, pt);
+    ++hits;
   }
+  return (hits & 1) == 1;
+}
 
-  bool contains(dim2::quad const & shape, dim2::point const & pt) {
-    return contains(shapes::segments(shape), pt);
-  }
+bool contains(dim2::quad const & shape, dim2::point const & pt) {
+  return contains(shapes::segments(shape), pt);
+}
 
-  bool intersects(dim2::line const & lhs, dim2::line const & rhs) {
-    // https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
-    // Find the four orientations needed for general and special cases
-    orientation o1 = orient(lhs, rhs.first);
-    orientation o2 = orient(lhs, rhs.second);
-    orientation o3 = orient(rhs, lhs.first);
-    orientation o4 = orient(rhs, lhs.second);
+bool intersects(dim2::line const & lhs, dim2::line const & rhs) {
+  // https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
+  // Find the four orientations needed for general and special cases
+  orientation o1 = orient(lhs, rhs.first);
+  orientation o2 = orient(lhs, rhs.second);
+  orientation o3 = orient(rhs, lhs.first);
+  orientation o4 = orient(rhs, lhs.second);
 
-    // General Case: Lines cross through each other
-    if (o1 != o2 && o3 != o4) return true;
+  // General Case: Lines cross through each other
+  if (o1 != o2 && o3 != o4) return true;
 
-    // Special Cases: one of the points exists on the other line
-    return contains(lhs, rhs.first) || contains(lhs, rhs.second) ||
-           contains(rhs, lhs.first) || contains(rhs, lhs.second);
-  }
+  // Special Cases: one of the points exists on the other line
+  return contains(lhs, rhs.first) || contains(lhs, rhs.second) ||
+         contains(rhs, lhs.first) || contains(rhs, lhs.second);
+}
 
-  bool intersects(dim2::line const & lhs, dim2::circle const & rhs) {
-    if (contains(rhs, lhs.first) || contains(rhs, lhs.second)) { return true; }
-    dim2::line const orth = lines::orthogonal(lhs, rhs.center);
-    vec2 const delta = orth.second - orth.first;
-    return delta.dot(delta) <= std::pow(rhs.radius, 2) && intersects(lhs, orth);
-  }
+bool intersects(dim2::line const & lhs, dim2::circle const & rhs) {
+  if (contains(rhs, lhs.first) || contains(rhs, lhs.second)) { return true; }
+  dim2::line const orth = lines::orthogonal(lhs, rhs.center);
+  vec2 const delta = orth.second - orth.first;
+  return delta.dot(delta) <= std::pow(rhs.radius, 2) && intersects(lhs, orth);
+}
 
-  bool intersects(dim2::line const & lhs, dim2::quad const & rhs) {
-    std::vector<dim2::line> segments = shapes::segments(rhs);
-    auto lhs_intersects = [&lhs](dim2::line const & ln) {
-      return intersects(lhs, ln);
-    };
-    return std::any_of(segments.begin(), segments.end(), lhs_intersects) ||
-           contains(segments, lhs.first);
-  }
+bool intersects(dim2::line const & lhs, dim2::quad const & rhs) {
+  std::vector<dim2::line> segments = shapes::segments(rhs);
+  auto lhs_intersects = [&lhs](dim2::line const & ln) {
+    return intersects(lhs, ln);
+  };
+  return std::any_of(segments.begin(), segments.end(), lhs_intersects) ||
+         contains(segments, lhs.first);
+}
 
-  bool intersects(dim2::quad const & lhs, dim2::circle const & rhs) {
-    std::vector<dim2::line> segments = shapes::segments(lhs);
-    auto rhs_intersects = [&rhs](dim2::line const & ln) {
-      return intersects(ln, rhs);
-    };
-    return std::any_of(segments.begin(), segments.end(), rhs_intersects) ||
-           contains(lhs, rhs.center);
-  }
+bool intersects(dim2::quad const & lhs, dim2::circle const & rhs) {
+  std::vector<dim2::line> segments = shapes::segments(lhs);
+  auto rhs_intersects = [&rhs](dim2::line const & ln) {
+    return intersects(ln, rhs);
+  };
+  return std::any_of(segments.begin(), segments.end(), rhs_intersects) ||
+         contains(lhs, rhs.center);
+}
 
-  bool check_edges(dim2::line const & seg, dim2::triangle const & tri) {
-    return orient(seg, tri.a) == clockwise && orient(seg, tri.b) == clockwise &&
-           orient(seg, tri.c) == clockwise;
-  }
+bool check_edges(dim2::line const & seg, dim2::triangle const & tri) {
+  return orient(seg, tri.a) == clockwise && orient(seg, tri.b) == clockwise &&
+         orient(seg, tri.c) == clockwise;
+}
 
-  bool intersects(dim2::triangle const & lhs, dim2::triangle const & rhs) {
-    if (check_edges({lhs.a, lhs.b}, rhs)) return false;
-    if (check_edges({lhs.b, lhs.c}, rhs)) return false;
-    if (check_edges({lhs.c, lhs.a}, rhs)) return false;
-    if (check_edges({rhs.a, rhs.b}, lhs)) return false;
-    if (check_edges({rhs.b, rhs.c}, lhs)) return false;
-    if (check_edges({rhs.c, rhs.a}, lhs)) return false;
-    return true;
-  }
+bool intersects(dim2::triangle const & lhs, dim2::triangle const & rhs) {
+  if (check_edges({lhs.a, lhs.b}, rhs)) return false;
+  if (check_edges({lhs.b, lhs.c}, rhs)) return false;
+  if (check_edges({lhs.c, lhs.a}, rhs)) return false;
+  if (check_edges({rhs.a, rhs.b}, lhs)) return false;
+  if (check_edges({rhs.b, rhs.c}, lhs)) return false;
+  if (check_edges({rhs.c, rhs.a}, lhs)) return false;
+  return true;
+}
 
-  // TODO (sjaffe): This does not cause intersection when the edges brush
-  //                against one another, is this good?
-  bool intersects(dim2::quad const & lhs, dim2::quad const & rhs) {
-    dim2::triangle l1{lhs.ll, lhs.lr, lhs.ul};
-    dim2::triangle l2{lhs.ul, lhs.ur, lhs.ll};
-    dim2::triangle r1{rhs.ll, rhs.lr, rhs.ul};
-    dim2::triangle r2{rhs.ul, rhs.ur, rhs.ll};
-    return intersects(l1, r1) || intersects(l2, r2) || intersects(l1, r2) ||
-           intersects(l2, r1);
-  }
+// TODO (sjaffe): This does not cause intersection when the edges brush
+//                against one another, is this good?
+bool intersects(dim2::quad const & lhs, dim2::quad const & rhs) {
+  dim2::triangle l1{lhs.ll, lhs.lr, lhs.ul};
+  dim2::triangle l2{lhs.ul, lhs.ur, lhs.ll};
+  dim2::triangle r1{rhs.ll, rhs.lr, rhs.ul};
+  dim2::triangle r2{rhs.ul, rhs.ur, rhs.ll};
+  return intersects(l1, r1) || intersects(l2, r2) || intersects(l1, r2) ||
+         intersects(l2, r1);
+}
 
-  bool intersects(dim2::circle const & lhs, dim2::circle const & rhs) {
-    vec2 const delta = rhs.center - lhs.center;
-    return delta.dot(delta) <= std::pow(lhs.radius + rhs.radius, 2);
-  }
+bool intersects(dim2::circle const & lhs, dim2::circle const & rhs) {
+  vec2 const delta = rhs.center - lhs.center;
+  return delta.dot(delta) <= std::pow(lhs.radius + rhs.radius, 2);
+}
 }

+ 1 - 1
math/test/common_test.cxx

@@ -19,7 +19,7 @@ using namespace math::dim2;
 using namespace testing;
 
 namespace math {
-  bool intersects(dim2::triangle const &, dim2::triangle const &);
+bool intersects(dim2::triangle const &, dim2::triangle const &);
 }
 
 template <typename T, typename G>

+ 1 - 1
util/include/game/util/files.hpp

@@ -12,5 +12,5 @@
 #include <string>
 
 namespace files {
-  std::unique_ptr<char[]> load(std::string const & absolute_path);
+std::unique_ptr<char[]> load(std::string const & absolute_path);
 }

+ 18 - 18
util/src/files.cxx

@@ -11,26 +11,26 @@
 #include "scope_guard/scope_guard.hpp"
 
 namespace files {
-  std::unique_ptr<char[]> load(std::string const & absolute_path) {
-    FILE * fp = fopen(absolute_path.c_str(), "r");
-    if (!fp) { return nullptr; }
+std::unique_ptr<char[]> load(std::string const & absolute_path) {
+  FILE * fp = fopen(absolute_path.c_str(), "r");
+  if (!fp) { return nullptr; }
 
-    scope(exit) { fclose(fp); };
-    // Determine file size
-    fseek(fp, 0, SEEK_END);
-    long size = ftell(fp);
-    if (size < 0) { return nullptr; }
+  scope(exit) { fclose(fp); };
+  // Determine file size
+  fseek(fp, 0, SEEK_END);
+  long size = ftell(fp);
+  if (size < 0) { return nullptr; }
 
-    std::unique_ptr<char[]> buffer{new char[size + 1]};
+  std::unique_ptr<char[]> buffer{new char[size + 1]};
 
-    rewind(fp);
-    size_t read = fread(buffer.get(), sizeof(char), size, fp);
-    if (read != static_cast<size_t>(size)) {
-      fputs("Error reading file", stderr);
-      return nullptr;
-    } else {
-      buffer[read] = '\0';
-    }
-    return buffer;
+  rewind(fp);
+  size_t read = fread(buffer.get(), sizeof(char), size, fp);
+  if (read != static_cast<size_t>(size)) {
+    fputs("Error reading file", stderr);
+    return nullptr;
+  } else {
+    buffer[read] = '\0';
   }
+  return buffer;
+}
 }

+ 2 - 2
util/src/osx_env.mm

@@ -85,8 +85,8 @@ math::vec2i OSXEnvironment::screen_resolution() const {
 
 }
 
-namespace env { namespace osx {
+namespace env::osx {
 void bundle(std::string const &id) {
   static_cast<OSXEnvironment &>(Environment::global_instance()).bundle(id);
 }
-}}
+}