Skip to content

Commit

Permalink
Revert Typelist reimplementation and try a simpler approach
Browse files Browse the repository at this point in the history
This reverts commit 7119e15.
This reverts commit cace3a3.
This reverts commit d5d013d.
This reverts commit daf0085.
This reverts commit d14b08d.
  • Loading branch information
Zegeri committed Sep 18, 2018
1 parent 71c3a08 commit ed249cc
Show file tree
Hide file tree
Showing 15 changed files with 1,192 additions and 141 deletions.
379 changes: 369 additions & 10 deletions sdk/include/loki/HierarchyGenerators.h

Large diffs are not rendered by default.

28 changes: 3 additions & 25 deletions sdk/include/loki/TypeManip.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,7 @@ namespace Loki
template <bool flag, typename T, typename U>
struct Select
{
private:
template<bool>
struct In
{ typedef T Result; };

template<>
struct In<false>
{ typedef U Result; };

public:
typedef typename In<flag>::Result Result;
using Result = std::conditional_t<flag, T, U>;
};


Expand All @@ -84,20 +74,8 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////

template <typename T, typename U>
struct IsSameType
{
private:
template<typename>
struct In
{ enum { value = false }; };

template<>
struct In<T>
{ enum { value = true }; };

public:
enum { value = In<U>::value };
};
struct IsSameType : std::is_same<T, U>
{};

////////////////////////////////////////////////////////////////////////////////
// Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big)
Expand Down
813 changes: 755 additions & 58 deletions sdk/include/loki/Typelist.h

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/xrGame/accumulative_states.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ struct accumulative_pair_t
}; // struct accumulative_pair_t
} // namespace detail

#define ACCUMULATIVE_STATE_LIST Loki::Typelist<>
#define ADD_ACCUMULATIVE_STATE(id, type) using Accumulative_State_Type_##type = \
Loki::TL::Prepend<detail::accumulative_pair_t<id, type>, ACCUMULATIVE_STATE_LIST>::result
#define ACCUMULATIVE_STATE_LIST Loki::NullType
#define ADD_ACCUMULATIVE_STATE(id, type) \
typedef Loki::Typelist<detail::accumulative_pair_t<id, type>, ACCUMULATIVE_STATE_LIST> \
Accumulative_State_Type_##type;
#define SAVE_TYPE_LIST(id, type) Accumulative_State_Type_##type

} // namespace award_system
Expand Down
20 changes: 10 additions & 10 deletions src/xrGame/alife_registry_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@
#include "alife_space.h"
#include "Common/object_type_traits.h"

template <typename, typename>
template <typename TContainer, typename TList>
struct RegistryHelper;

template <typename TContainer>
struct RegistryHelper<TContainer, Loki::Typelist<>>
struct RegistryHelper<TContainer, Loki::NullType>
{
static void Save(TContainer*, IWriter&) {};
static void Load(TContainer*, IReader&) {};
};

template <typename TContainer, typename T, typename... Ts>
struct RegistryHelper<TContainer, Loki::Typelist<T, Ts...>>
template <typename TContainer, typename Head, typename Tail>
struct RegistryHelper<TContainer, Loki::Typelist<Head, Tail>>
{
static constexpr bool isSerializable = object_type_traits::is_base_and_derived<ISerializable, T>::value;
static constexpr bool isSerializable =
object_type_traits::is_base_and_derived<ISerializable, Head>::value;

static void Save(TContainer* self, IWriter& writer)
{
if constexpr (isSerializable)
self->T::save(writer);
RegistryHelper<TContainer, Loki::Typelist<Ts...>>::Save(self, writer);
self->Head::save(writer);
RegistryHelper<TContainer, Tail>::Save(self, writer);
};

static void Load(TContainer* self, IReader& reader)
{
if constexpr (isSerializable)
self->T::load(reader);
RegistryHelper<TContainer, Loki::Typelist<Ts...>>::Load(self, reader);
self->Head::load(reader);
RegistryHelper<TContainer, Tail>::Load(self, reader);
}

};

void CALifeRegistryContainer::load(IReader& file_stream)
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/alife_registry_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CLinearRegistryType : public _base, public _type
{
};

class CALifeRegistryContainer : public Loki::GenLinearHierarchy<registry_type_list, CLinearRegistryType>
class CALifeRegistryContainer : public Loki::GenLinearHierarchy<registry_type_list, CLinearRegistryType>::LinBase
{
private:
typedef registry_type_list TYPE_LIST;
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/alife_registry_container_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once

#include <loki/HierarchyGenerators.h>
#define registry_type_list Loki::Typelist<>
#define add_to_registry_type_list(a) using registry_##a = Loki::TL::Prepend<a, registry_type_list>::result;
#define registry_type_list Loki::NullType
#define add_to_registry_type_list(a) typedef Loki::Typelist<a, registry_type_list> registry_##a;
#define define_constant(a) (a*)0
#define save_registry_type_list(a) registry_##a
5 changes: 3 additions & 2 deletions src/xrGame/base_client_classes_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ struct linear_registrator<_type, Loki::EmptyType> : public _type
template <typename _1, typename _2>
struct heritage
{
using tl = Loki::Typelist<_1, _2>;
using result = Loki::GenLinearHierarchy<tl, linear_registrator>;
typedef Loki::Typelist<_1, Loki::Typelist<_2, Loki::NullType>> tl;
typedef typename Loki::TL::Erase<tl, Loki::EmptyType>::Result pure_tl;
typedef typename Loki::GenLinearHierarchy<pure_tl, linear_registrator>::LinBase result;
};

template <typename base>
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/game_state_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class game_state_accumulator : public game_events_handler
bool check_accumulative_value(enum_accumulative_player_values param_id, u32_binary_function* func, u32 right_arg);

using accumulative_values_collection_t = AssociativeVector<enum_accumulative_player_values, player_state_param*>;

private:
// average_values_collection_t m_average_values;
accumulative_values_collection_t m_accumulative_values;
Expand Down
11 changes: 11 additions & 0 deletions src/xrGame/game_state_accumulator_inline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
template <typename TypeListElement>
void game_state_accumulator::init_acpv_list()
{
static_assert(Loki::TL::is_Typelist<TypeListElement>::value,
"Type must have a Loki Type List type use ADD_ACCUMULATIVE_STATE macro define.");
init_acpv_list<TypeListElement::Tail>();

player_state_param* tmp_obj_inst = new typename TypeListElement::Head::value_type(this);

m_accumulative_values.insert(std::make_pair(TypeListElement::Head::value_id, tmp_obj_inst));
}
13 changes: 7 additions & 6 deletions src/xrGame/game_state_accumulator_state_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@

namespace award_system
{

template <typename>
struct AccumulatorHelper;

template <>
struct AccumulatorHelper<Loki::Typelist<>> {
struct AccumulatorHelper<Loki::NullType> {
static void init_acpv(game_state_accumulator*,
game_state_accumulator::accumulative_values_collection_t&)
{
}
};

template <typename T, typename... Ts>
struct AccumulatorHelper<Loki::Typelist<T, Ts...>> {
template <typename Head, typename Tail>
struct AccumulatorHelper<Loki::Typelist<Head, Tail>> {
static void init_acpv(game_state_accumulator* self,
game_state_accumulator::accumulative_values_collection_t& accumulative_values)
{
AccumulatorHelper<Loki::Typelist<Ts...>>::init_acpv(self, accumulative_values);
player_state_param* tmp_obj_inst = new typename T::value_type(self);
accumulative_values.insert(std::make_pair(T::value_id, tmp_obj_inst));
AccumulatorHelper<Tail>::init_acpv(self, accumulative_values);
player_state_param* tmp_obj_inst = new typename Head::value_type(self);
accumulative_values.insert(std::make_pair(Head::value_id, tmp_obj_inst));
}
};

Expand Down
1 change: 1 addition & 0 deletions src/xrGame/xrGame.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@
<ClInclude Include="game_path_manager.h" />
<ClInclude Include="game_path_manager_inline.h" />
<ClInclude Include="game_state_accumulator.h" />
<ClInclude Include="game_state_accumulator_inline.h" />
<ClInclude Include="game_sv_artefacthunt.h" />
<ClInclude Include="game_sv_base.h" />
<ClInclude Include="game_sv_base_console_vars.h" />
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/xrGame.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -5682,6 +5682,9 @@
<ClInclude Include="game_state_accumulator.h">
<Filter>Core\Server\Games\client\mp\award_system\player_state</Filter>
</ClInclude>
<ClInclude Include="game_state_accumulator_inline.h">
<Filter>Core\Server\Games\client\mp\award_system\player_state</Filter>
</ClInclude>
<ClInclude Include="hits_store.h">
<Filter>Core\Server\Games\client\mp\award_system\player_state</Filter>
</ClInclude>
Expand Down
6 changes: 3 additions & 3 deletions src/xrServerEntities/smart_cast_impl0.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ struct CTypeHelper
};

template <>
struct add<Loki::EmptyType>
struct add<Loki::NullType>
{
typedef Loki::Typelist<Loki::Typelist<T, Loki::Typelist<P, Loki::EmptyType>>, List> result;
typedef Loki::Typelist<Loki::Typelist<T, Loki::Typelist<P, Loki::NullType>>, List> result;
};

typedef typename add<List>::result result;
};
};

#define cast_type_list Loki::EmptyType
#define cast_type_list Loki::NullType
#define add_to_cast_list(B, A) typedef SmartDynamicCast::CTypeHelper<cast_type_list, A, B>::result TypeList_##A##B
#define save_cast_list(B, A) TypeList_##A##B

Expand Down
40 changes: 20 additions & 20 deletions src/xrServerEntities/smart_cast_impl1.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct exists
};

template <>
struct iterator<Loki::EmptyType>
struct iterator<Loki::NullType>
{
enum
{
Expand All @@ -83,7 +83,7 @@ struct merge
};

template <>
struct iterator<Loki::EmptyType>
struct iterator<Loki::NullType>
{
typedef List2 result;
};
Expand Down Expand Up @@ -116,9 +116,9 @@ struct has_conversion
};

template <>
struct search_base<Loki::EmptyType>
struct search_base<Loki::NullType>
{
typedef Loki::EmptyType result;
typedef Loki::NullType result;
};

template <typename T>
Expand Down Expand Up @@ -149,7 +149,7 @@ struct has_conversion
};

template <>
struct search_conversion<Loki::EmptyType>
struct search_conversion<Loki::NullType>
{
enum
{
Expand Down Expand Up @@ -197,7 +197,7 @@ struct has_any_conversion
};

template <>
struct iterator<Loki::EmptyType>
struct iterator<Loki::NullType>
{
enum
{
Expand Down Expand Up @@ -233,14 +233,14 @@ struct CMatcher
template <bool>
struct _selector
{
typedef Loki::Typelist<typename PrevHead::Head, Loki::Typelist<Target, Loki::EmptyType>> result;
typedef Loki::Typelist<typename PrevHead::Head, Loki::Typelist<Target, Loki::NullType>> result;
};

template <>
struct _selector<false>
{
typedef Loki::Typelist<typename PrevHead::Head,
Loki::Typelist<Head, Loki::Typelist<Target, Loki::EmptyType>>>
Loki::Typelist<Head, Loki::Typelist<Target, Loki::NullType>>>
result;
};

Expand All @@ -258,7 +258,7 @@ struct CMatcher
};

template <>
struct CMatchHelper3<Loki::EmptyType>
struct CMatchHelper3<Loki::NullType>
{
typedef typename CMatchHelper<typename T::Tail>::result result;
};
Expand Down Expand Up @@ -290,9 +290,9 @@ struct CMatcher
};

template <>
struct CMatchHelper<Loki::EmptyType>
struct CMatchHelper<Loki::NullType>
{
typedef Loki::EmptyType result;
typedef Loki::NullType result;
};

typedef typename CMatchHelper<cast_type_list>::result result;
Expand Down Expand Up @@ -326,7 +326,7 @@ struct conversion_sequence
typedef search_result result;
};

typedef typename selector<is_type<Loki::EmptyType, search_result>::value>::result result;
typedef typename selector<is_type<Loki::NullType, search_result>::value>::result result;
};

template <bool>
Expand All @@ -346,7 +346,7 @@ struct conversion_sequence
typedef typename list_iterator<Tail>::result result;
};

typedef typename _selector<!is_type<Loki::EmptyType, helper_result>::value>::result result;
typedef typename _selector<!is_type<Loki::NullType, helper_result>::value>::result result;
};

template <>
Expand All @@ -369,7 +369,7 @@ struct conversion_sequence
typedef typename list_iterator<Tail>::result result;
};

typedef typename _selector2<!is_type<Loki::EmptyType, helper_result>::value>::result result;
typedef typename _selector2<!is_type<Loki::NullType, helper_result>::value>::result result;
};

template <>
Expand All @@ -386,9 +386,9 @@ struct conversion_sequence
};

template <>
struct list_iterator<Loki::EmptyType>
struct list_iterator<Loki::NullType>
{
typedef Loki::EmptyType result;
typedef Loki::NullType result;
};

template <int length>
Expand All @@ -410,7 +410,7 @@ struct conversion_sequence
typedef typename list_iterator<cast_type_list>::result result;
};

typedef typename _selector<!is_type<Loki::EmptyType, nearest>::value>::result result;
typedef typename _selector<!is_type<Loki::NullType, nearest>::value>::result result;
};

template <>
Expand All @@ -422,7 +422,7 @@ struct conversion_sequence
template <>
struct selector<0>
{
typedef Loki::EmptyType result;
typedef Loki::NullType result;
};

typedef typename selector<max_length>::result result;
Expand Down Expand Up @@ -451,7 +451,7 @@ struct CSmartCaster
};

template <>
struct CHelper<Loki::EmptyType>
struct CHelper<Loki::NullType>
{
IC static Target* smart_cast(Head* p) { return (SmartDynamicCast::smart_cast<Target>(p)); }
};
Expand All @@ -474,7 +474,7 @@ struct CSmartMatcher
}

template <>
IC static T1* smart_cast<Loki::EmptyType>(T2* p)
IC static T1* smart_cast<Loki::NullType>(T2* p)
{
#ifdef SHOW_SMART_CAST_UNOPTIMIZED_CASES
#pragma todo("Dima to all : this smart_cast is not optimized!")
Expand Down

0 comments on commit ed249cc

Please sign in to comment.