Browse Source

- merge up to head with submodules
- fix compiler errors with things as a consequence
- properly include scope_guard.hpp
- stub definition for linker error in graphics project

Sam Jaffe 6 years ago
parent
commit
1a390af252
9 changed files with 36 additions and 30 deletions
  1. 3 0
      .gitmodules
  2. 18 19
      graphics/graphics/texture.cpp
  3. 1 1
      include/expect
  4. 1 0
      include/scope_guard
  5. 4 2
      math/common.cpp
  6. 1 0
      math/math_fwd.hpp
  7. 1 1
      math/matrix
  8. 6 6
      math/shape.cpp
  9. 1 1
      math/vector

+ 3 - 0
.gitmodules

@@ -14,3 +14,6 @@
 [submodule "math/matrix"]
 	path = math/matrix
 	url = freenas:utility/matrix
+[submodule "include/scope_guard"]
+	path = include/scope_guard
+	url = freenas:utility/scope_guard

+ 18 - 19
graphics/graphics/texture.cpp

@@ -7,7 +7,7 @@
 
 #include "texture.hpp"
 
-#include "util/scope_exit.hpp"
+#include "scope_guard/scope_guard.hpp"
 
 #include <unordered_map>
 #include <string>
@@ -26,28 +26,26 @@ public:
   template <typename... Args>
   static T create(key_t const & key) {
     auto found = instances.find(key);
-    if (found != instances.end()) { return found->second; }
-    else {
-      return instances.emplace(key, T::create(key)).first->second;
+    if (found == instances.end()) {
+      found = instances.emplace(key, T::create(key)).first;
     }
+    return found->second;
   }
 private:
   static std::unordered_map<key_t, T> instances;
 };
 
-namespace graphics {
-  
-  namespace detail {
-    namespace texture {
-      
-      struct format {};
+namespace graphics { namespace detail { namespace texture {
+  struct format {};
       
-      std::unordered_map<std::string, ::graphics::texture> g_textures;
+  std::unordered_map<std::string, ::graphics::texture> g_textures;
     
-      unsigned int init(format = {}, math::vec2i = {}, unsigned char * = {});
-    }
+  unsigned int init(format = {}, math::vec2i = {}, unsigned char * = {}) {
+    throw; // TODO implement
   }
-  
+} } }
+
+namespace graphics {
   texture texture::create( std::string const & imagefile ) {
     using detail::texture::g_textures;
     auto found = g_textures.find(imagefile);
@@ -55,17 +53,18 @@ namespace graphics {
     
     int components = 0;
     math::vec2i size;
-    unsigned char * data = stbi_load( imagefile.c_str(), &size.x(), &size.y(), &components, 0 );
+    unsigned char * data = stbi_load(imagefile.c_str(), &size.x(), &size.y(),
+                                     &components, 0);
     scope(exit) { stbi_image_free( data ); };
-    return g_textures.emplace(imagefile, texture{ detail::texture::init({}, size, data), size }).first->second;
+    texture tex{ detail::texture::init({}, size, data), size };
+    return g_textures.emplace(imagefile, std::move(tex)).first->second;
   }
   
   texture texture::create( unsigned char * data, math::vec2i size ) {
     return { detail::texture::init({}, size, data), size };
   }
   
-  texture::texture( unsigned int id, math::vec2i sz ) : identity<graphics::texture>(id), size(sz) {
-    
+  texture::texture( unsigned int id, math::vec2i sz )
+  : identity<graphics::texture>(id), size(sz) {
   }
-  
 }

+ 1 - 1
include/expect

@@ -1 +1 @@
-Subproject commit 08408ea5c1358ff5a951c1ca755947974a8736fe
+Subproject commit 5d08b8fcbfc385310666c55b5d070a99fab2c2c0

+ 1 - 0
include/scope_guard

@@ -0,0 +1 @@
+Subproject commit 3bb5ab224b46ffebfd8585392ff70c1293422a95

+ 4 - 2
math/common.cpp

@@ -6,7 +6,9 @@
 //
 
 #include "common.hpp"
+
 #include "angle.hpp"
+#include "math_fwd.hpp"
 #include "shape.hpp"
 #include "vector.hpp"
 
@@ -15,10 +17,10 @@ namespace math {
     vec2 trans = p - c;
     vec2 vcos = trans * static_cast<float>(cos(r));
     vec2 vsin = trans * static_cast<float>(sin(r));
-    return {
+    return {{
       vcos[0] - vsin[1] + c[0],
       vsin[0] - vcos[1] + c[1]
-    };
+    }};
   }
   
   quad rotate(vec2 const & c, quad const & q, radian r) {

+ 1 - 0
math/math_fwd.hpp

@@ -7,6 +7,7 @@
 
 #pragma once
 
+#include <cstddef>
 #include <cstdint>
 
 namespace math {

+ 1 - 1
math/matrix

@@ -1 +1 @@
-Subproject commit ac1800bcb7a133b6b513c3efdd7125c0d54d2954
+Subproject commit 64e3782c8e8a095acef3364f41f82384db3d1ac5

+ 6 - 6
math/shape.cpp

@@ -12,22 +12,22 @@ namespace math {
   rectangle::operator quad() const {
     return {
       origin,
-      origin + vec2{ size.x(), 0.0 },
+      origin + vec2{{size.x(), 0.0}},
       origin + size,
-      origin + vec2{ 0.0, size.y() }
+      origin + vec2{{0.0, size.y()}}
     };
   }
 
   square::operator rectangle() const {
-    return { origin, origin + vec2{size, size} };
+    return { origin, origin + vec2{{size, size}} };
   }
   
   square::operator quad() const {
     return {
       origin,
-      origin + vec2{size, 0.0 },
-      origin + vec2{size, size},
-      origin + vec2{ 0.0, size}
+      origin + vec2{{size, 0.0 }},
+      origin + vec2{{size, size}},
+      origin + vec2{{ 0.0, size}}
     };
   }
   

+ 1 - 1
math/vector

@@ -1 +1 @@
-Subproject commit 4ac77cf1691c5f13718b3f55e663426959da9fb4
+Subproject commit c855de125e13a9dfc1ba7ce94179871f3a33daa4