From 0a81bc2994b7e5e4167a24d909e022b876477703 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 29 May 2024 23:06:39 +0200 Subject: [PATCH] feat: renamed godot_macros.h to godot_macros.hpp --- godot_macros.h => godot_macros.hpp | 70 +++++++++++++++++------------- 1 file changed, 40 insertions(+), 30 deletions(-) rename godot_macros.h => godot_macros.hpp (57%) diff --git a/godot_macros.h b/godot_macros.hpp similarity index 57% rename from godot_macros.h rename to godot_macros.hpp index 79869d4..bd72c01 100644 --- a/godot_macros.h +++ b/godot_macros.hpp @@ -1,5 +1,9 @@ -#ifndef UC_GODOT_MACROS_H -#define UC_GODOT_MACROS_H +#ifndef UTILS_GODOT_MACROS_HPP +#define UTILS_GODOT_MACROS_HPP + +/*! \file godot_macros.h + * \brief C-style preprocessor macros to simplify using godot's C++ API. + */ #include "godot_cpp/classes/engine.hpp" #include "godot_cpp/core/class_db.hpp" @@ -9,7 +13,8 @@ #define MACRO_STRING_INNER(_Arg) #_Arg #define MACRO_STRING(_Arg) MACRO_STRING_INNER(_Arg) -/*! Register property. +/*! \def GDPROPERTY(PropName_, PropType_) + * \brief Register property. * * Register variable CLASSNAME::PropName_ with variant type PropType_. * Requires setting CLASSNAME as a #define first. Also requires a CLASSNAME::get_PropName_ and CLASSNAME::set_PropName_ to exist. @@ -19,7 +24,8 @@ godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \ godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_), "set_" #PropName_, "get_" #PropName_) -/*! Register a hinted property. +/*! \def GDPROPERTY_HINTED(PropName_, PropType_, ...) + * \brief Register a hinted property. * * Register variable CLASSNAME::PropName_ with variant type PropType_. * Requires setting CLASSNAME as a #define first, and CLASSNAME::get_PropName and CLASSNAME::set_PropName_ to exist. @@ -29,62 +35,66 @@ godot::ClassDB::bind_method(godot::D_METHOD("set_" #PropName_, "value"), &CLASSNAME::set_##PropName_); \ godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_, __VA_ARGS__), "set_" #PropName_, "get_" #PropName_) -/*! Register a function. - * - * Register a function CLASSNAME::_FnName() to godot. +/*! \def GDFUNCTION(FnName_) + * \brief Register a function CLASSNAME::FnName_() to godot. + * * Requires setting CLASSNAME as a #define first. */ -#define GDFUNCTION(_FnName) godot::ClassDB::bind_method(godot::D_METHOD(#_FnName), &CLASSNAME::_FnName) +#define GDFUNCTION(FnName_) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_), &CLASSNAME::FnName_) -/*! Register a function with arguments. - * - * Register a function CLASSNAME::_FnName(...) to godot. +/*! \def GDFUNCTION_ARGS(FnName_, ...) + * \brief Register a function CLASSNAME::FnName_(...) to godot. + * * Requires setting CLASSNAME as a #define first. */ -#define GDFUNCTION_ARGS(_FnName, ...) godot::ClassDB::bind_method(godot::D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName) +#define GDFUNCTION_ARGS(FnName_, ...) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_) -/*! Register a static function. - * - * Register a static member function CLASSNAME::_FnName() to godot. +/*! \def GDFUNCTION_STATIC(FnName_) + * \brief Register a static member function CLASSNAME::FnName_() to godot. + * * Requires setting CLASSNAME as a #define first. */ -#define GDFUNCTION_STATIC(_FnName) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#_FnName), &CLASSNAME::_FnName) +#define GDFUNCTION_STATIC(FnName_) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_), &CLASSNAME::_FnName) -/*! Register a static function with arguments. - * - * Register a static member function CLASSNAME::_FnName(...) to godot. +/*! \def GDFUNCTION_STATIC_ARGS(FnName_, ...) + * \brief Register a static member function CLASSNAME::FnName_(...) to godot. + * * Requires setting CLASSNAME as a #define first. */ -#define GDFUNCTION_STATIC_ARGS(_FnName, ...) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#_FnName, __VA_ARGS__), &CLASSNAME::_FnName) +#define GDFUNCTION_STATIC_ARGS(FnName_, ...) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_) -/*! Declare a godot Observer signal. - * - * Declare the existence of a Observer signal to godot. +/*! \def GDSIGNAL(...) + * \brief Declare a godot Observer signal. */ #define GDSIGNAL(...) godot::ClassDB::add_signal(MACRO_STRING(CLASSNAME), godot::MethodInfo(__VA_ARGS__)) -/*! Construct godot resource type hint. +/*! \def GDRESOURCETYPE(Class_) + * \brief Construct godot resource type hint. * * Use when registering properties of arrays of resource classes. */ -#define GDRESOURCETYPE(_Class) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_RESOURCE_TYPE, #_Class) +#define GDRESOURCETYPE(Class_) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_RESOURCE_TYPE, #Class_) -/*! Execute the rest of the function only if currently running as editor. +/*! \def GDEDITORONLY() + * \brief Execute the rest of the function only if currently running as editor. * * Useful for _ready, _enter/_exit, _process, etc. functions. */ #define GDEDITORONLY() if(!godot::Engine::get_singleton()->is_editor_hint()) return; -/*! Execute the rest of the function only if currently running as game. +/*! \def GDGAMEONLY() + * \brief Execute the rest of the function only if currently running as game. * * Useful for _ready, _enter/_exit, _process, etc. functions. */ #define GDGAMEONLY() if(godot::Engine::get_singleton()->is_editor_hint()) return; -/*! Declare a scoped enum struct. +/*! \def GDENUM(Name_, ...) + * \brief Declare a scoped enum struct. * * Declares a struct Name_ with an enum Value and a single variable and a get_property_hint() function. */ -#define GDENUM(Name_, ...) struct Name_ {\ +#define GDENUM(Name_, ...)\ +struct Name_ {\ enum Value {__VA_ARGS__};\ private:\ Value value{};\ @@ -94,4 +104,4 @@ inline Name_(Name_ const &value): value{value.value} {}\ } -#endif // !UC_GODOT_MACROS_H +#endif // !UTILS_GODOT_MACROS_HPP