-
-
Save michicc/86e6b312c96b1d6566c3f556b90a1d53 to your computer and use it in GitHub Desktop.
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
struct InternalCommand : Command { CmdUnpackProc *unpack_cmd; }; | |
template <Commands Tcmd> | |
constexpr CmdUnpackProc *MakeCmdTrampoline() | |
{ | |
return [](const CommandContainer *cp, bool my_cmd) -> bool { | |
return DoCommand<Tcmd>::FromNet(my_cmd, cp->err_msg, cp->callback, cp->tile, cp->p1, cp->p2, cp->text); | |
}; | |
} | |
template <typename T> | |
inline constexpr InternalCommand CommandFromTrait() noexcept { return { T::proc, T::name, T::flags, T::type, MakeCmdTrampoline<T::cmd>() }; }; | |
template<typename T, T... i> | |
inline constexpr auto MakeCommandsFromTraits(std::integer_sequence<T, i...>) noexcept { | |
return std::array<InternalCommand, sizeof...(i)>{{ CommandFromTrait<CommandTraits<static_cast<Commands>(i)>>()... }}; | |
} | |
static constexpr auto _command_proc_table = MakeCommandsFromTraits(std::make_integer_sequence<std::underlying_type_t<Commands>, CMD_END>{}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment