Skip to content

Instantly share code, notes, and snippets.

@michicc

michicc/he.cpp Secret

Created October 17, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michicc/86e6b312c96b1d6566c3f556b90a1d53 to your computer and use it in GitHub Desktop.
Save michicc/86e6b312c96b1d6566c3f556b90a1d53 to your computer and use it in GitHub Desktop.
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