Compare commits

..

No commits in common. "7e452fa7ff395e30e085b08de5bb797550236ac2" and "7251a29ecda4491546078d9ee03f597fc2507c66" have entirely different histories.

2 changed files with 31 additions and 41 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 = YES MACRO_EXPANSION = NO
# 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,9 +1,5 @@
#ifndef UTILS_GODOT_MACROS_HPP #ifndef UC_GODOT_MACROS_H
#define UTILS_GODOT_MACROS_HPP #define UC_GODOT_MACROS_H
/*! \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"
@ -13,8 +9,7 @@
#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)
/*! \def GDPROPERTY(PropName_, PropType_) /*! Register property.
* \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.
@ -24,8 +19,7 @@
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_)
/*! \def GDPROPERTY_HINTED(PropName_, PropType_, ...) /*! Register a hinted property.
* \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.
@ -35,66 +29,62 @@
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_)
/*! \def GDFUNCTION(FnName_) /*! Register a function.
* \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)
/*! \def GDFUNCTION_ARGS(FnName_, ...) /*! Register a function with arguments.
* \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)
/*! \def GDFUNCTION_STATIC(FnName_) /*! Register a static function.
* \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)
/*! \def GDFUNCTION_STATIC_ARGS(FnName_, ...) /*! Register a static function with arguments.
* \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)
/*! \def GDSIGNAL(...) /*! Declare a godot Observer signal.
* \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__))
/*! \def GDRESOURCETYPE(Class_) /*! Construct godot resource type hint.
* \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)
/*! \def GDEDITORONLY() /*! Execute the rest of the function only if currently running as editor.
* \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;
/*! \def GDGAMEONLY() /*! Execute the rest of the function only if currently running as game.
* \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;
/*! \def GDENUM(Name_, ...) /*! Declare a scoped enum struct.
* \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_, ...)\ #define GDENUM(Name_, ...) struct Name_ {\
struct Name_ {\
enum Value {__VA_ARGS__};\ enum Value {__VA_ARGS__};\
private:\ private:\
Value value{};\ Value value{};\
@ -104,4 +94,4 @@ struct Name_ {\
inline Name_(Name_ const &value): value{value.value} {}\ inline Name_(Name_ const &value): value{value.value} {}\
} }
#endif // !UTILS_GODOT_MACROS_HPP #endif // !UC_GODOT_MACROS_H