diff --git a/include/bedrock/type_id.h b/include/bedrock/type_id.h index 94829edc1..ab119a505 100644 --- a/include/bedrock/type_id.h +++ b/include/bedrock/type_id.h @@ -27,6 +27,20 @@ class typeid_t { // NOLINT(*-identifier-naming) }; template -BEDROCK_API typeid_t type_id(); +typeid_t type_id(); + +#define DEFINE_BEDROCK_TYPE_ID(Context, Type, Value) \ + template <> \ + inline typeid_t type_id() \ + { \ + 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 diff --git a/src/endstone_runtime/bedrock/command_registry.cpp b/src/endstone_runtime/bedrock/command_registry.cpp index 695ea5886..e36489089 100644 --- a/src/endstone_runtime/bedrock/command_registry.cpp +++ b/src/endstone_runtime/bedrock/command_registry.cpp @@ -50,7 +50,7 @@ void CommandRegistry::registerOverloadInternal(CommandRegistry::Signature &signa ENDSTONE_HOOK_CALL_ORIGINAL(&CommandRegistry::registerOverloadInternal, this, signature, overload); for (const auto ¶m : 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 = {}, Description = {}", param.type_id.id, describe(param)); } } diff --git a/src/endstone_runtime/bedrock/type_id.cpp b/src/endstone_runtime/bedrock/type_id.cpp deleted file mode 100644 index bfa9264a5..000000000 --- a/src/endstone_runtime/bedrock/type_id.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "bedrock/type_id.h" - -#include "bedrock/command/command_registry.h" - -#define DEFINE_BEDROCK_TYPE_ID(Context, Type, Value) \ - template <> \ - Bedrock::typeid_t Bedrock::type_id() \ - { \ - return {Value}; \ - } \ - [[maybe_unused]] void __##Context##__##Value() - -DEFINE_BEDROCK_TYPE_ID(CommandRegistry, std::string, 1); -DEFINE_BEDROCK_TYPE_ID(CommandRegistry, bool, 2); -DEFINE_BEDROCK_TYPE_ID(CommandRegistry, int, 5); -DEFINE_BEDROCK_TYPE_ID(CommandRegistry, float, 6); -DEFINE_BEDROCK_TYPE_ID(CommandRegistry, std::unique_ptr, 7);