Skip to content

Commit

Permalink
refactor: move type_id definitions to header and remove type_id.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 3, 2024
1 parent 20cea31 commit b1da105
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
16 changes: 15 additions & 1 deletion include/bedrock/type_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ class typeid_t { // NOLINT(*-identifier-naming)
};

template <typename Context, typename Type>
BEDROCK_API typeid_t<Context> type_id();
typeid_t<Context> type_id();

#define DEFINE_BEDROCK_TYPE_ID(Context, Type, Value) \
template <> \
inline typeid_t<Context> type_id<Context, Type>() \
{ \
return {Value}; \
}

DEFINE_BEDROCK_TYPE_ID(class CommandRegistry, std::string, 1);
DEFINE_BEDROCK_TYPE_ID(class CommandRegistry, bool, 2);
DEFINE_BEDROCK_TYPE_ID(class CommandRegistry, int, 5);
DEFINE_BEDROCK_TYPE_ID(class CommandRegistry, float, 6);

#undef DEFINE_BEDROCK_TYPE_ID

} // namespace Bedrock
2 changes: 1 addition & 1 deletion src/endstone_runtime/bedrock/command_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void CommandRegistry::registerOverloadInternal(CommandRegistry::Signature &signa
ENDSTONE_HOOK_CALL_ORIGINAL(&CommandRegistry::registerOverloadInternal, this, signature, overload);

for (const auto &param : overload.params) {
// NOTE: Retrieve the typeid_t for each type after each game update and update values in `type_id.cpp`.
// NOTE: Retrieve the typeid_t after game updates and fix values in `type_id.cpp`.
spdlog::debug("Bedrock::typeid_t<CommandRegistry> = {}, Description = {}", param.type_id.id, describe(param));
}
}
Expand Down
31 changes: 0 additions & 31 deletions src/endstone_runtime/bedrock/type_id.cpp

This file was deleted.

0 comments on commit b1da105

Please sign in to comment.