Skip to content

Commit

Permalink
2019.6.9
Browse files Browse the repository at this point in the history
  • Loading branch information
old-account-392754 committed Jun 9, 2019
1 parent 973a492 commit ccfb08c
Show file tree
Hide file tree
Showing 24 changed files with 762 additions and 225 deletions.
184 changes: 184 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,161 @@ auto bit_vector_test(tagged_array_view<T, index_type> v, index_type index) -> st
return bit_vector_test(v.data(), to_index(index));
}

#define STRUCT_MEMBER( i_type, name ) \
template<typename INDEX> \
static auto get_member(_struct_type& s) noexcept -> std::enable_if_t<std::is_same_v<INDEX, i_type>, std::add_lvalue_reference_t<decltype(s. name )>> { \
return s. name ; \
} \
template<typename INDEX> \
static auto get_member(_struct_type const& s) noexcept -> std::enable_if_t<std::is_same_v<INDEX, i_type>, std::add_lvalue_reference_t<std::add_const_t<decltype(s. name )>>> { \
return s. name ; \
}

template<typename T>
struct struct_wrapper {};

#define START_STRUCT( struct_name ) \
template<> \
struct struct_wrapper<struct_name> { \
using _struct_type = struct_name ; \

#define END_STRUCT };

template<typename A, typename B, typename ... C>
struct _supports_get : std::false_type {};
template<typename A, typename ... C>
struct _supports_get<A, decltype(void(std::declval<A>().get(std::declval<C>() ...))), C...> : std::true_type {};
template<typename A, typename ... C>
constexpr bool supports_get = _supports_get<A, void, C ...>::value;

template<typename A, typename B, typename index, typename ... C>
struct _supports_get_t1 : std::false_type {};
template<typename A, typename index, typename ... C>
struct _supports_get_t1<A, decltype(void(std::declval<A>().template get<index>(std::declval<C>() ...))), index, C...> : std::true_type {};
template<typename A, typename index, typename ... C>
constexpr bool supports_get_t1 = _supports_get_t1<A, void, index, C ...>::value;

#define GET_SET(container_name) \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get(tag_type t) noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get<INDEX>(t)), void>, decltype(container_name.get<INDEX>(t))> { \
return container_name.get<INDEX>(t); \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get(tag_type t) const noexcept-> std::enable_if_t<!std::is_same_v<decltype(container_name.get<INDEX>(t)), void>, decltype(container_name.get<INDEX>(t))> { \
return container_name.get<INDEX>(t); \
} \
template<typename INDEX, typename tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, value_type v) noexcept -> std::enable_if_t<std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get<INDEX>(t)), void>, void> { \
return container_name.set<INDEX>(t, v); \
} \
template<typename INDEX, typename tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, value_type const& v) noexcept -> std::enable_if_t<!std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get<INDEX>(t)), void>, void> { \
return container_name.set<INDEX>(t, v); \
} \
template<typename INDEX> \
RELEASE_INLINE auto get_row() noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get_row<INDEX>()), void>, decltype(container_name.get_row<INDEX>())> { \
return container_name.get_row<INDEX>(); \
} \
template<typename INDEX> \
RELEASE_INLINE auto get_row() const noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get_row<INDEX>()), void>, decltype(container_name.get_row<INDEX>())> { \
return container_name.get_row<INDEX>(); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type> \
RELEASE_INLINE auto get(tag_type t, inner_tag_type u) noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get<INDEX>(t,u)), void>, decltype(container_name.get<INDEX>(t,u))> { \
return container_name.get<INDEX>(t,u); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type> \
RELEASE_INLINE auto get(tag_type t, inner_tag_type u) const noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get<INDEX>(t,u)), void>, decltype(container_name.get<INDEX>(t,u))> { \
return container_name.get<INDEX>(t,u); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type v) noexcept -> std::enable_if_t<std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get<INDEX>(t,u)), void>, void> { \
return container_name.set<INDEX>(t, u, v); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type const& v) noexcept -> std::enable_if_t<!std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get<INDEX>(t,u)), void>, void> { \
return container_name.set<INDEX>(t, u, v); \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get_row(tag_type t) noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get_row<INDEX>(t)), void>, decltype(container_name.get_row<INDEX>(t))> { \
return container_name.get_row<INDEX>(t); \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get_row(tag_type t) const noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.get_row<INDEX>(t)), void>, decltype(container_name.get_row<INDEX>(t))> { \
return container_name.get_row<INDEX>(t); \
}

#define GET_SET_TV(index_name, container_name) \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get(tag_type t) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name[t]), void>, decltype(container_name[t])> { \
return container_name[t]; \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get(tag_type t) const noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name[t]), void>, decltype(container_name[t])> { \
return container_name[t]; \
} \
template<typename INDEX, typename tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, value_type v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name[t]), void>, void> { \
return container_name.set(t, v); \
} \
template<typename INDEX, typename tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, value_type const& v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name[t]), void>, void> { \
return container_name.set(t, v); \
} \
template<typename INDEX> \
RELEASE_INLINE auto get_row() noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.view()), void>, decltype(container_name.view())> { \
return container_name.view(); \
} \
template<typename INDEX> \
RELEASE_INLINE auto get_row() const noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.view()), void>, decltype(container_name.view())> { \
return container_name.view(); \
}

#define GET_SET_TFV(index_name, container_name) \
template<typename INDEX, typename tag_type, typename inner_tag_type> \
RELEASE_INLINE auto get(tag_type t, inner_tag_type u) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get(t,u)), void>, decltype(container_name.get(t,u))> { \
return container_name.get(t,u); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type> \
RELEASE_INLINE auto get(tag_type t, inner_tag_type u) const noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get(t,u)), void>, decltype(container_name.get(t,u))> { \
return container_name.get(t,u); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get(t,u)), void>, void> { \
return container_name.set(t, u, v); \
} \
template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> \
RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type const& v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get(t,u)), void>, void> { \
return container_name.set(t, u, v); \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get_row(tag_type t) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get_row(t)), void>, decltype(container_name.get_row(t))> { \
return container_name.get_row(t); \
} \
template<typename INDEX, typename tag_type> \
RELEASE_INLINE auto get_row(tag_type t) const noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get_row(t)), void>, decltype(container_name.get_row(t))> { \
return container_name.get_row(t); \
}

#define ARRAY_BACKING(container_name) \
template<typename obj_type> \
RELEASE_INLINE auto array_backing() noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.array_backing<obj_type>()), void>, decltype(container_name.array_backing<obj_type>())> { \
return container_name.array_backing<obj_type>(); \
} \
template<typename obj_type> \
RELEASE_INLINE auto array_backing() const noexcept -> std::enable_if_t<!std::is_same_v<decltype(container_name.array_backing<obj_type>()), void>, decltype(container_name.array_backing<obj_type>())> { \
return container_name.array_backing<obj_type>(); \
}

#define ARRAY_BACKING_BASE(container_name) \
template<typename obj_type> \
RELEASE_INLINE auto array_backing() noexcept -> std::enable_if_t<std::is_same_v<typename decltype(container_name)::contents_type, obj_type>, std::add_lvalue_reference_t<decltype(container_name)>> { \
return container_name; \
} \
template<typename obj_type> \
RELEASE_INLINE auto array_backing() const noexcept -> std::enable_if_t<std::is_same_v<typename decltype(container_name)::contents_type, obj_type>, std::add_lvalue_reference_t<std::add_const_t<decltype(container_name)>>> { \
return container_name; \
}

template<typename value_type, typename tag_type, typename allocator = std::allocator<value_type>, bool padded = false>
class tagged_vector {
Expand All @@ -460,6 +615,9 @@ class tagged_vector {
storage.resize(to_index(t) + int32_t(padded) + 1);
return storage[to_index(t) + int32_t(padded)];
}
void set(tag_type t, value_type v) {
*(storage.data() + to_index(t) + int32_t(padded)) = v;
}
auto data() const { return storage.data(); }
auto data() { return storage.data(); }
auto array() const { return storage.data() + int32_t(padded); }
Expand Down Expand Up @@ -490,6 +648,21 @@ class tagged_vector {
#endif
);
};

template<typename i_type>
auto get(tag_type t) noexcept -> decltype(struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded)))) {
return struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded)));
}
template<typename i_type>
auto get(tag_type t) const noexcept -> decltype(struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded)))) {
return struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded)));
}
template<typename i_type>
void set(tag_type t, decltype(struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded)))) j) noexcept {
struct_wrapper<value_type>::template get_member<i_type>(*(storage.data() + to_index(t) + int32_t(padded))) = j;
}
template<typename i_type>
void get_row() const;
};

template<typename tag_type, typename allocator, bool padded>
Expand Down Expand Up @@ -558,6 +731,9 @@ class tagged_fixed_2dvector {
const value_type & get(variable_tag_type outer, fixed_tag_type inner) const {
return storage[(uint32_t)to_index(inner) + (uint32_t)to_index(outer) * _inner_size];
}
void set(variable_tag_type outer, fixed_tag_type inner, value_type v) {
storage[(uint32_t)to_index(inner) + (uint32_t)to_index(outer) * _inner_size] = v;
}
tagged_array_view<value_type, fixed_tag_type> get_row(variable_tag_type outer) {
return tagged_array_view<value_type, fixed_tag_type>((value_type*)(storage.data() + (uint32_t)to_index(outer) * _inner_size), int32_t(_inner_size));
}
Expand Down Expand Up @@ -606,6 +782,9 @@ class tagged_fixed_blocked_2dvector {
const value_type & get(variable_tag_type outer, fixed_tag_type inner) const {
return *((const value_type*)(storage.data() + (uint32_t)to_index(outer) * _inner_size) + (uint32_t)to_index(inner));
}
void set(variable_tag_type outer, fixed_tag_type inner, value_type v) {
*((value_type*)(storage.data() + (uint32_t)to_index(outer) * _inner_size) + (uint32_t)to_index(inner)) = v;
}
tagged_array_view<value_type, fixed_tag_type> get_row(variable_tag_type outer) {
return tagged_array_view<value_type, fixed_tag_type>((value_type*)(storage.data() + (uint32_t)to_index(outer) * _inner_size), _inner_size * block_size / sizeof(value_type));
}
Expand Down Expand Up @@ -1444,6 +1623,11 @@ class v_vector {
return *it;
}

void set(I x, uint32_t y, T value) {
auto it = elements.begin() + index[to_index(x)] + y;
*it = value;
}

void push_back(const T& elem) {
elements.push_back(elem);
}
Expand Down
2 changes: 2 additions & 0 deletions common/shared_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ namespace military {
using cb_type_tag = tag_type<uint8_t, std::true_type, struct cb_type_tag_type>;
using leader_trait_tag = tag_type<uint8_t, std::true_type, struct leader_trait_tag_type>;
using army_tag = tag_type<uint16_t, std::true_type, struct army_tag_type>;
using strategic_hq_tag = tag_type<uint16_t, std::true_type, struct strategic_hq_tag_type>;
using leader_tag = tag_type<uint16_t, std::true_type, struct leader_tag_type>;
using fleet_tag = tag_type<uint16_t, std::true_type, struct fleet_tag_type>;
using war_tag = tag_type<uint16_t, std::true_type, struct war_tag_type>;
using army_orders_tag = tag_type<uint16_t, std::true_type, struct army_orders_tag_type>;
using army_composition_tag = tag_type<uint8_t, std::true_type, struct army_composition_tag_tag_type>;

struct war_identifier {
war_tag war_id;
Expand Down
2 changes: 2 additions & 0 deletions concurrency_tools/concurrency_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ namespace alignment_type {
template<typename object_type, uint32_t minimum_size, size_t memory_size, int32_t align = alignment_type::none>
class stable_variable_vector_storage_mk_2 {
public:
using contents_type = object_type;

uint64_t* backing_storage = nullptr;
std::atomic<uint32_t> first_free = 0ui32;

Expand Down
49 changes: 7 additions & 42 deletions concurrency_tools/variable_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,19 @@ namespace variable_layout_detail {
};

RELEASE_INLINE static void reset(data& d) {}

template<typename T>
RELEASE_INLINE static void get(tag_type i, const data&) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static void get(tag_type i, const data&);
template<typename T>
RELEASE_INLINE static void get_row(data&) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static void get_row(data&);
template<typename T>
RELEASE_INLINE static void get_row(const data&) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static void get_row(const data&);
template<typename T>
RELEASE_INLINE static void get(tag_type i, data&) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static void get(tag_type i, data&);
template<typename U, typename T>
RELEASE_INLINE static std::enable_if_t<!std::is_trivially_copyable_v<T>> set(tag_type i, data&, T const&) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static std::enable_if_t<!std::is_trivially_copyable_v<T>> set(tag_type i, data&, T const&);
template<typename U, typename T>
RELEASE_INLINE static std::enable_if_t<std::is_trivially_copyable_v<T>> set(tag_type i, data&, T) {
#ifdef _DEBUG
assert(false);
#else
__assume(0);
#endif
}
RELEASE_INLINE static std::enable_if_t<std::is_trivially_copyable_v<T>> set(tag_type i, data&, T);
RELEASE_INLINE static void clear(tag_type i, data&) {}

template<typename ... CONTEXT>
Expand Down
8 changes: 8 additions & 0 deletions cultures/cpp.hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define ARRAY_BACKING_BASE(container_name) template<typename obj_type> RELEASE_INLINE auto array_backing() noexcept -> std::enable_if_t<std::is_same_v<container_name::contents_type, obj_type>, std::add_lvalue_reference_t<decltype(container_name)>> { return container_name; } template<typename obj_type> RELEASE_INLINE auto array_backing() const noexcept -> std::enable_if_t<std::is_same_v<container_name::contents_type, obj_type>, std::add_lvalue_reference_t<std::add_const_t<decltype(container_name)>>> { return container_name; }
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define GET_SET_TFV(index_name, container_name) template<typename INDEX, typename tag_type, typename inner_tag_type> RELEASE_INLINE auto get(tag_type t, inner_tag_type u) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get(t,u)), void>, decltype(container_name.get(t,u))> { return container_name.get(t,u); } template<typename INDEX, typename tag_type, typename inner_tag_type> RELEASE_INLINE auto get(tag_type t, inner_tag_type u) const noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get(t,u)), void>, decltype(container_name.get(t,u))> { return container_name.get(t,u); } template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get(t,u)), void>, void> { return container_name.set(t, u, v); } template<typename INDEX, typename tag_type, typename inner_tag_type, typename value_type> RELEASE_INLINE auto set(tag_type t, inner_tag_type u, value_type const& v) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_trivially_copyable_v<value_type> && !std::is_same_v<decltype(container_name.get(t,u)), void>, void> { return container_name.set(t, u, v); } template<typename INDEX, typename tag_type> RELEASE_INLINE auto get_row(tag_type t) noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get_row(t)), void>, decltype(container_name.get_row(t))> { return container_name.get_row(t); } template<typename INDEX, typename tag_type> RELEASE_INLINE auto get_row(tag_type t) const noexcept -> std::enable_if_t<std::is_same_v<INDEX, index_name> && !std::is_same_v<decltype(container_name.get_row(t)), void>, decltype(container_name.get_row(t))> { return container_name.get_row(t); }
Loading

0 comments on commit ccfb08c

Please sign in to comment.