Browse Source

Now it works on VS2017 (#11)

* update appveyor config
* update build system
* refactoring
Michele Caini 8 years ago
parent
commit
df065c5647
4 changed files with 53 additions and 62 deletions
  1. 14 11
      CMakeLists.txt
  2. 2 3
      appveyor.yml
  3. 35 46
      src/registry.hpp
  4. 2 2
      test/registry.cpp

+ 14 - 11
CMakeLists.txt

@@ -38,17 +38,20 @@ message("*")
 
 set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wconversion")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -DDEBUG")
-
-if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-    # it seems that -O3 ruins the performance when using clang ...
-    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
-else()
-    # ... on the other side, GCC is incredibly comfortable with it.
-    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
+
+if(NOT MSVC)
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wconversion")
+    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE")
+    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -DDEBUG")
+
+    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+        # it seems that -O3 ruins the performance when using clang ...
+        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
+    else()
+        # ... on the other side, GCC is incredibly comfortable with it.
+        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
+    endif()
 endif()
 
 #

+ 2 - 3
appveyor.yml

@@ -1,7 +1,7 @@
 # can use variables like {build} and {branch}
 version: 1.0.{build}
 
-image: Visual Studio 2015
+image: Visual Studio 2017
 
 environment:
   BUILD_DIR: "%APPVEYOR_BUILD_FOLDER%\\build"
@@ -13,9 +13,8 @@ configuration:
   - Release
 
 before_build:
-  - deps.bat
   - cd %BUILD_DIR%
-  - cmake .. -G"%CMAKE_GENERATOR_NAME%"
+  - cmake .. -G"Visual Studio 15 2017"
 
 build:
   parallel: true

+ 35 - 46
src/registry.hpp

@@ -184,29 +184,31 @@ class Registry {
 
     static constexpr auto validity_bit = sizeof...(Component);
 
+    // variable templates are fine as well, but for the fact that MSVC goes crazy
+    template<typename Comp>
+    struct identifier {
+        static constexpr auto value = ident<Component...>.template get<Comp>();
+    };
+
 public:
     using entity_type = Entity;
     using size_type = typename std::vector<mask_type>::size_type;
 
     template<typename... Comp>
-    using view_type = View<pool_type, ident<Component...>.template get<Comp>()...>;
+    using view_type = View<pool_type, identifier<Comp>::value...>;
 
 private:
     template<typename Comp>
     void clone(entity_type to, entity_type from) {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-
-        if(entities[from].test(index)) {
-            assign<Comp>(to, std::get<index>(pool).get(from));
+        if(entities[from].test(identifier<Comp>::value)) {
+            assign<Comp>(to, std::get<identifier<Comp>::value>(pool).get(from));
         }
     }
 
     template<typename Comp>
     void sync(entity_type to, entity_type from) {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-
-        bool src = entities[from].test(index);
-        bool dst = entities[to].test(index);
+        bool src = entities[from].test(identifier<Comp>::value);
+        bool dst = entities[to].test(identifier<Comp>::value);
 
         if(src && dst) {
             copy<Comp>(to, from);
@@ -229,8 +231,7 @@ public:
 
     template<typename Comp>
     size_type size() const noexcept {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return std::get<index>(pool).size();
+        return std::get<identifier<Comp>::value>(pool).size();
     }
 
     size_type size() const noexcept {
@@ -239,8 +240,7 @@ public:
 
     template<typename Comp>
     size_type capacity() const noexcept {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return std::get<index>(pool).capacity();
+        return std::get<identifier<Comp>::value>(pool).capacity();
     }
 
     size_type capacity() const noexcept {
@@ -249,8 +249,7 @@ public:
 
     template<typename Comp>
     bool empty() const noexcept {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return std::get<index>(pool).empty();
+        return std::get<identifier<Comp>::value>(pool).empty();
     }
 
     bool empty() const noexcept {
@@ -298,17 +297,15 @@ public:
     template<typename Comp, typename... Args>
     Comp & assign(entity_type entity, Args... args) {
         assert(valid(entity));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        entities[entity].set(index);
-        return std::get<index>(pool).construct(entity, args...);
+        entities[entity].set(identifier<Comp>::value);
+        return std::get<identifier<Comp>::value>(pool).construct(entity, args...);
     }
 
     template<typename Comp>
     void remove(entity_type entity) {
         assert(valid(entity));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        entities[entity].reset(index);
-        std::get<index>(pool).destroy(entity);
+        entities[entity].reset(identifier<Comp>::value);
+        std::get<identifier<Comp>::value>(pool).destroy(entity);
     }
 
     template<typename... Comp>
@@ -317,7 +314,7 @@ public:
         using accumulator_type = bool[];
         bool all = true;
         auto &mask = entities[entity];
-        accumulator_type accumulator = { true, (all = all && mask.test(ident<Component...>.template get<Comp>()))... };
+        accumulator_type accumulator = { true, (all = all && mask.test(identifier<Comp>::value))... };
         (void)accumulator;
         return all;
     }
@@ -325,31 +322,26 @@ public:
     template<typename Comp>
     const Comp & get(entity_type entity) const noexcept {
         assert(valid(entity));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return std::get<index>(pool).get(entity);
+        return std::get<identifier<Comp>::value>(pool).get(entity);
     }
 
     template<typename Comp>
     Comp & get(entity_type entity) noexcept {
         assert(valid(entity));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return std::get<index>(pool).get(entity);
+        return std::get<identifier<Comp>::value>(pool).get(entity);
     }
 
     template<typename Comp, typename... Args>
     Comp & replace(entity_type entity, Args... args) {
         assert(valid(entity));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        return (std::get<index>(pool).get(entity) = Comp{args...});
+        return (std::get<identifier<Comp>::value>(pool).get(entity) = Comp{args...});
     }
 
     template<typename Comp, typename... Args>
     Comp & accomodate(entity_type entity, Args... args) {
         assert(valid(entity));
 
-        constexpr auto index = ident<Component...>.template get<Comp>();
-
-        return (entities[entity].test(index)
+        return (entities[entity].test(identifier<Comp>::value)
                 ? this->template replace<Comp>(entity, std::forward<Args>(args)...)
                 : this->template assign<Comp>(entity, std::forward<Args>(args)...));
     }
@@ -367,8 +359,7 @@ public:
     Comp & copy(entity_type to, entity_type from) {
         assert(valid(to));
         assert(valid(from));
-        constexpr auto index = ident<Component...>.template get<Comp>();
-        auto &&cpool = std::get<index>(pool);
+        auto &&cpool = std::get<identifier<Comp>::value>(pool);
         return (cpool.get(to) = cpool.get(from));
     }
 
@@ -384,18 +375,18 @@ public:
     void swap(entity_type lhs, entity_type rhs) {
         assert(valid(lhs));
         assert(valid(rhs));
-        std::get<ident<Component...>.template get<Comp>()>(pool).swap(lhs, rhs);
+        std::get<identifier<Comp>::value>(pool).swap(lhs, rhs);
     }
 
     template<typename Comp, typename Compare>
     void sort(Compare compare) {
-        std::get<ident<Component...>.template get<Comp>()>(pool).sort(std::move(compare));
+        std::get<identifier<Comp>::value>(pool).sort(std::move(compare));
     }
 
     template<typename To, typename From>
     void sort() {
-        auto &&to = std::get<ident<Component...>.template get<To>()>(pool);
-        auto &&from = std::get<ident<Component...>.template get<From>()>(pool);
+        auto &&to = std::get<identifier<To>::value>(pool);
+        auto &&from = std::get<identifier<From>::value>(pool);
         to.respect(from);
     }
 
@@ -403,19 +394,15 @@ public:
     void reset(entity_type entity) {
         assert(valid(entity));
 
-        constexpr auto index = ident<Component...>.template get<Comp>();
-
-        if(entities[entity].test(index)) {
+        if(entities[entity].test(identifier<Comp>::value)) {
             remove<Comp>(entity);
         }
     }
 
     template<typename Comp>
     void reset() {
-        constexpr auto index = ident<Component...>.template get<Comp>();
-
         for(entity_type entity = 0, last = entity_type(entities.size()); entity < last; ++entity) {
-            if(entities[entity].test(index)) {
+            if(entities[entity].test(identifier<Comp>::value)) {
                 remove<Comp>(entity);
             }
         }
@@ -423,18 +410,20 @@ public:
 
     void reset() {
         using accumulator_type = int[];
-        accumulator_type acc = { 0, (std::get<ident<Component...>.template get<Component>()>(pool).reset(), 0)... };
+        accumulator_type acc = { 0, (std::get<identifier<Component>::value>(pool).reset(), 0)... };
         entities.clear();
         available.clear();
         (void)acc;
     }
 
     template<typename... Comp>
-    std::enable_if_t<(sizeof...(Comp) == 1), view_type<Comp...>>
+    // view_type<Comp...> is fine as well, but for the fact that MSVC dislikes it
+    std::enable_if_t<(sizeof...(Comp) == 1), View<pool_type, identifier<Comp>::value...>>
     view() noexcept { return view_type<Comp...>{&pool}; }
 
     template<typename... Comp>
-    std::enable_if_t<(sizeof...(Comp) > 1), view_type<Comp...>>
+    // view_type<Comp...> is fine as well, but for the fact that MSVC dislikes it
+    std::enable_if_t<(sizeof...(Comp) > 1), View<pool_type, identifier<Comp>::value...>>
     view() noexcept { return view_type<Comp...>{&pool, entities.data()}; }
 
 private:

+ 2 - 2
test/registry.cpp

@@ -282,11 +282,11 @@ TEST(DefaultRegistry, ViewSingleComponent) {
     auto view = registry.view<char>();
 
     ASSERT_NE(view.begin(), view.end());
-    ASSERT_EQ(view.size(), typename registry_type::view_type<char>::size_type{1});
+    ASSERT_EQ(view.size(), typename decltype(view)::size_type{1});
 
     registry.assign<char>(e1);
 
-    ASSERT_EQ(view.size(), typename registry_type::view_type<char>::size_type{2});
+    ASSERT_EQ(view.size(), typename decltype(view)::size_type{2});
 
     registry.remove<char>(e1);
     registry.remove<char>(e2);