-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Refactor Skirmish AI rules param functions No logic or interface changes, just some readability and preparation for further commits. * Refactor the rules param selection filter No logic or interface change, just readability (no longer crams everything into a single statement due to macro) and preparation for further commits. * Fix #866, rules params can now be boolean AI and selection filters read them as numbers, 0/1. --------- Co-authored-by: lhog <[email protected]>
- Loading branch information
Showing
8 changed files
with
155 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ | ||
|
||
#include "LuaRulesParams.h" | ||
#include "System/creg/STL_Variant.h" | ||
|
||
using namespace LuaRulesParams; | ||
|
||
CR_BIND(Param,) | ||
CR_REG_METADATA(Param, ( | ||
CR_MEMBER(los), | ||
CR_MEMBER(valueInt), | ||
CR_MEMBER(valueString) | ||
CR_MEMBER(value) | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef CR_STL_VARIANT_H | ||
#define CR_STL_VARIANT_H | ||
|
||
#include "creg_cond.h" | ||
#include <variant> | ||
|
||
#ifdef USING_CREG | ||
|
||
namespace creg | ||
{ | ||
template <typename T0, typename T1, typename T2> | ||
class Variant3Type : public IType | ||
{ | ||
public: | ||
using VT = std::variant<T0,T1,T2>; | ||
Variant3Type() : IType(sizeof(VT)) { } | ||
~Variant3Type() { } | ||
|
||
void Serialize(ISerializer* s, void* instance) | ||
{ | ||
VT& p = *(VT*)instance; | ||
if (s->IsWriting()) { | ||
int index = p.index(); | ||
s->SerializeInt(&index, sizeof(int)); | ||
switch (index) { | ||
case 0: DeduceType<T0>::Get()->Serialize(s, (void*) &(std::get<0>(p))); break; | ||
case 1: DeduceType<T1>::Get()->Serialize(s, (void*) &(std::get<1>(p))); break; | ||
case 2: DeduceType<T2>::Get()->Serialize(s, (void*) &(std::get<2>(p))); break; | ||
} | ||
} else { | ||
int index; | ||
s->SerializeInt(&index, sizeof(int)); | ||
switch (index) { | ||
case 0: { | ||
T0 x; | ||
DeduceType<T0>::Get()->Serialize(s, (void*) &x); | ||
p = std::move(x); // neither `p.emplace <T0>` nor `<0>` worked; still, should be safe | ||
} break; | ||
case 1: { | ||
T1 x; | ||
DeduceType<T1>::Get()->Serialize(s, (void*) &x); | ||
p = std::move(x); | ||
} break; | ||
case 2: { | ||
T2 x; | ||
DeduceType<T2>::Get()->Serialize(s, (void*) &x); | ||
p = std::move(x); | ||
} break; | ||
} | ||
} | ||
} | ||
std::string GetName() const { return "variant<" | ||
+ DeduceType<T0>::Get()->GetName() + "," | ||
+ DeduceType<T1>::Get()->GetName() + "," | ||
+ DeduceType<T2>::Get()->GetName() + ">"; | ||
} | ||
}; | ||
|
||
/* FIXME: ideally this would support arbitrary variants, but that involves some | ||
* recursive variadic template bullshit. Three just happened to be the first use case. */ | ||
template<typename T0, typename T1, typename T2> | ||
struct DeduceType<std::variant<T0,T1,T2> > { | ||
static std::unique_ptr<IType> Get() { | ||
return std::unique_ptr<IType>(new Variant3Type<T0,T1,T2>()); | ||
} | ||
}; | ||
} | ||
|
||
#endif // USING_CREG | ||
|
||
#endif // CR_STL_VARIANT_H |