Compare commits

..

2 Commits

Author SHA1 Message Date
Sara 7e452fa7ff feat: enabled macro expansion in Doxyfile 2024-05-29 23:07:05 +02:00
Sara 0a81bc2994 feat: renamed godot_macros.h to godot_macros.hpp 2024-05-29 23:06:39 +02:00
2 changed files with 41 additions and 31 deletions

View File

@ -2352,7 +2352,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO. # The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
MACRO_EXPANSION = NO MACRO_EXPANSION = YES
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and # the macro expansion is limited to the macros specified with the PREDEFINED and

View File

@ -1,5 +1,9 @@
#ifndef UC_GODOT_MACROS_H #ifndef UTILS_GODOT_MACROS_HPP
#define UC_GODOT_MACROS_H #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/classes/engine.hpp"
#include "godot_cpp/core/class_db.hpp" #include "godot_cpp/core/class_db.hpp"
@ -9,7 +13,8 @@
#define MACRO_STRING_INNER(_Arg) #_Arg #define MACRO_STRING_INNER(_Arg) #_Arg
#define MACRO_STRING(_Arg) MACRO_STRING_INNER(_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_. * 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. * 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::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_) 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_. * 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. * 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::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_) godot::ClassDB::add_property(MACRO_STRING(CLASSNAME), godot::PropertyInfo(PropType_, #PropName_, __VA_ARGS__), "set_" #PropName_, "get_" #PropName_)
/*! Register a function. /*! \def GDFUNCTION(FnName_)
* * \brief Register a function CLASSNAME::FnName_() to godot.
* Register a function CLASSNAME::_FnName() to godot. *
* Requires setting CLASSNAME as a #define first. * 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. /*! \def GDFUNCTION_ARGS(FnName_, ...)
* * \brief Register a function CLASSNAME::FnName_(...) to godot.
* Register a function CLASSNAME::_FnName(...) to godot. *
* Requires setting CLASSNAME as a #define first. * 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. /*! \def GDFUNCTION_STATIC(FnName_)
* * \brief Register a static member function CLASSNAME::FnName_() to godot.
* Register a static member function CLASSNAME::_FnName() to godot. *
* Requires setting CLASSNAME as a #define first. * 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. /*! \def GDFUNCTION_STATIC_ARGS(FnName_, ...)
* * \brief Register a static member function CLASSNAME::FnName_(...) to godot.
* Register a static member function CLASSNAME::_FnName(...) to godot. *
* Requires setting CLASSNAME as a #define first. * 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. /*! \def GDSIGNAL(...)
* * \brief Declare a godot Observer signal.
* Declare the existence of a Observer signal to godot.
*/ */
#define GDSIGNAL(...) godot::ClassDB::add_signal(MACRO_STRING(CLASSNAME), godot::MethodInfo(__VA_ARGS__)) #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. * 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. * Useful for _ready, _enter/_exit, _process, etc. functions.
*/ */
#define GDEDITORONLY() if(!godot::Engine::get_singleton()->is_editor_hint()) return; #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. * Useful for _ready, _enter/_exit, _process, etc. functions.
*/ */
#define GDGAMEONLY() if(godot::Engine::get_singleton()->is_editor_hint()) return; #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. * 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__};\ enum Value {__VA_ARGS__};\
private:\ private:\
Value value{};\ Value value{};\
@ -94,4 +104,4 @@
inline Name_(Name_ const &value): value{value.value} {}\ inline Name_(Name_ const &value): value{value.value} {}\
} }
#endif // !UC_GODOT_MACROS_H #endif // !UTILS_GODOT_MACROS_HPP