Namespaces instead of underscore prefix for binds

Thanks to neikeq for the initial work.

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
This commit is contained in:
Max Hilbrunner 2021-08-13 16:46:14 +02:00
parent 3d673fac50
commit 81f7d1890b
14 changed files with 964 additions and 917 deletions

File diff suppressed because it is too large Load Diff

View File

@ -42,12 +42,16 @@
#include "core/os/thread.h"
#include "core/templates/safe_refcount.h"
class _ResourceLoader : public Object {
GDCLASS(_ResourceLoader, Object);
class MainLoop;
namespace core_bind {
class ResourceLoader : public Object {
GDCLASS(ResourceLoader, Object);
protected:
static void _bind_methods();
static _ResourceLoader *singleton;
static ResourceLoader *singleton;
public:
enum ThreadLoadStatus {
@ -63,7 +67,7 @@ public:
CACHE_MODE_REPLACE, // Resource and subresource use path cache, but replace existing loaded resources when available with information from disk.
};
static _ResourceLoader *get_singleton() { return singleton; }
static ResourceLoader *get_singleton() { return singleton; }
Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false);
ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = Array());
@ -77,18 +81,15 @@ public:
bool exists(const String &p_path, const String &p_type_hint = "");
ResourceUID::ID get_resource_uid(const String &p_path);
_ResourceLoader() { singleton = this; }
ResourceLoader() { singleton = this; }
};
VARIANT_ENUM_CAST(_ResourceLoader::ThreadLoadStatus);
VARIANT_ENUM_CAST(_ResourceLoader::CacheMode);
class _ResourceSaver : public Object {
GDCLASS(_ResourceSaver, Object);
class ResourceSaver : public Object {
GDCLASS(ResourceSaver, Object);
protected:
static void _bind_methods();
static _ResourceSaver *singleton;
static ResourceSaver *singleton;
public:
enum SaverFlags {
@ -101,24 +102,20 @@ public:
FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
};
static _ResourceSaver *get_singleton() { return singleton; }
static ResourceSaver *get_singleton() { return singleton; }
Error save(const String &p_path, const RES &p_resource, SaverFlags p_flags);
Vector<String> get_recognized_extensions(const RES &p_resource);
_ResourceSaver() { singleton = this; }
ResourceSaver() { singleton = this; }
};
VARIANT_ENUM_CAST(_ResourceSaver::SaverFlags);
class MainLoop;
class _OS : public Object {
GDCLASS(_OS, Object);
class OS : public Object {
GDCLASS(OS, Object);
protected:
static void _bind_methods();
static _OS *singleton;
static OS *singleton;
public:
enum VideoDriver {
@ -245,26 +242,21 @@ public:
bool request_permissions();
Vector<String> get_granted_permissions() const;
static _OS *get_singleton() { return singleton; }
static OS *get_singleton() { return singleton; }
_OS() { singleton = this; }
OS() { singleton = this; }
};
VARIANT_ENUM_CAST(_OS::VideoDriver);
VARIANT_ENUM_CAST(_OS::Weekday);
VARIANT_ENUM_CAST(_OS::Month);
VARIANT_ENUM_CAST(_OS::SystemDir);
class Geometry2D : public Object {
GDCLASS(Geometry2D, Object);
class _Geometry2D : public Object {
GDCLASS(_Geometry2D, Object);
static _Geometry2D *singleton;
static Geometry2D *singleton;
protected:
static void _bind_methods();
public:
static _Geometry2D *get_singleton();
static Geometry2D *get_singleton();
Variant segment_intersects_segment(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b);
Variant line_intersects_line(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b);
Vector<Vector2> get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
@ -315,23 +307,19 @@ public:
Dictionary make_atlas(const Vector<Size2> &p_rects);
_Geometry2D() { singleton = this; }
Geometry2D() { singleton = this; }
};
VARIANT_ENUM_CAST(_Geometry2D::PolyBooleanOperation);
VARIANT_ENUM_CAST(_Geometry2D::PolyJoinType);
VARIANT_ENUM_CAST(_Geometry2D::PolyEndType);
class Geometry3D : public Object {
GDCLASS(Geometry3D, Object);
class _Geometry3D : public Object {
GDCLASS(_Geometry3D, Object);
static _Geometry3D *singleton;
static Geometry3D *singleton;
protected:
static void _bind_methods();
public:
static _Geometry3D *get_singleton();
static Geometry3D *get_singleton();
Vector<Plane> build_box_planes(const Vector3 &p_extents);
Vector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
Vector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
@ -347,11 +335,11 @@ public:
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
_Geometry3D() { singleton = this; }
Geometry3D() { singleton = this; }
};
class _File : public RefCounted {
GDCLASS(_File, RefCounted);
class File : public RefCounted {
GDCLASS(File, RefCounted);
FileAccess *f = nullptr;
bool big_endian = false;
@ -445,15 +433,12 @@ public:
uint64_t get_modified_time(const String &p_file) const;
_File() {}
virtual ~_File();
File() {}
virtual ~File();
};
VARIANT_ENUM_CAST(_File::ModeFlags);
VARIANT_ENUM_CAST(_File::CompressionMode);
class _Directory : public RefCounted {
GDCLASS(_Directory, RefCounted);
class Directory : public RefCounted {
GDCLASS(Directory, RefCounted);
DirAccess *d;
bool dir_open = false;
@ -490,24 +475,24 @@ public:
Error rename(String p_from, String p_to);
Error remove(String p_name);
_Directory();
virtual ~_Directory();
Directory();
virtual ~Directory();
private:
bool _list_skip_navigational = false;
bool _list_skip_hidden = false;
};
class _Marshalls : public Object {
GDCLASS(_Marshalls, Object);
class Marshalls : public Object {
GDCLASS(Marshalls, Object);
static _Marshalls *singleton;
static Marshalls *singleton;
protected:
static void _bind_methods();
public:
static _Marshalls *get_singleton();
static Marshalls *get_singleton();
String variant_to_base64(const Variant &p_var, bool p_full_objects = false);
Variant base64_to_variant(const String &p_str, bool p_allow_objects = false);
@ -518,13 +503,13 @@ public:
String utf8_to_base64(const String &p_str);
String base64_to_utf8(const String &p_str);
_Marshalls() { singleton = this; }
~_Marshalls() { singleton = nullptr; }
Marshalls() { singleton = this; }
~Marshalls() { singleton = nullptr; }
};
class _Mutex : public RefCounted {
GDCLASS(_Mutex, RefCounted);
Mutex mutex;
class Mutex : public RefCounted {
GDCLASS(Mutex, RefCounted);
::Mutex mutex;
static void _bind_methods();
@ -534,9 +519,9 @@ public:
void unlock();
};
class _Semaphore : public RefCounted {
GDCLASS(_Semaphore, RefCounted);
Semaphore semaphore;
class Semaphore : public RefCounted {
GDCLASS(Semaphore, RefCounted);
::Semaphore semaphore;
static void _bind_methods();
@ -546,8 +531,8 @@ public:
void post();
};
class _Thread : public RefCounted {
GDCLASS(_Thread, RefCounted);
class Thread : public RefCounted {
GDCLASS(Thread, RefCounted);
protected:
Variant ret;
@ -555,7 +540,7 @@ protected:
SafeFlag active;
Object *target_instance = nullptr;
StringName target_method;
Thread thread;
::Thread thread;
static void _bind_methods();
static void _start_func(void *ud);
@ -573,10 +558,10 @@ public:
Variant wait_to_finish();
};
VARIANT_ENUM_CAST(_Thread::Priority);
namespace special {
class _ClassDB : public Object {
GDCLASS(_ClassDB, Object);
class ClassDB : public Object {
GDCLASS(ClassDB, Object);
protected:
static void _bind_methods();
@ -609,19 +594,21 @@ public:
bool is_class_enabled(StringName p_class) const;
_ClassDB() {}
~_ClassDB() {}
ClassDB() {}
~ClassDB() {}
};
class _Engine : public Object {
GDCLASS(_Engine, Object);
} // namespace special
class Engine : public Object {
GDCLASS(Engine, Object);
protected:
static void _bind_methods();
static _Engine *singleton;
static Engine *singleton;
public:
static _Engine *get_singleton() { return singleton; }
static Engine *get_singleton() { return singleton; }
void set_physics_ticks_per_second(int p_ips);
int get_physics_ticks_per_second() const;
@ -661,14 +648,14 @@ public:
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;
_Engine() { singleton = this; }
Engine() { singleton = this; }
};
class _EngineDebugger : public Object {
GDCLASS(_EngineDebugger, Object);
class EngineDebugger : public Object {
GDCLASS(EngineDebugger, Object);
class ProfilerCallable {
friend class _EngineDebugger;
friend class EngineDebugger;
Callable callable_toggle;
Callable callable_add;
@ -689,10 +676,10 @@ class _EngineDebugger : public Object {
protected:
static void _bind_methods();
static _EngineDebugger *singleton;
static EngineDebugger *singleton;
public:
static _EngineDebugger *get_singleton() { return singleton; }
static EngineDebugger *get_singleton() { return singleton; }
bool is_active();
@ -714,8 +701,29 @@ public:
static void call_tick(void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time);
static Error call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured);
_EngineDebugger() { singleton = this; }
~_EngineDebugger();
EngineDebugger() { singleton = this; }
~EngineDebugger();
};
} // namespace core_bind
VARIANT_ENUM_CAST(core_bind::ResourceLoader::ThreadLoadStatus);
VARIANT_ENUM_CAST(core_bind::ResourceLoader::CacheMode);
VARIANT_ENUM_CAST(core_bind::ResourceSaver::SaverFlags);
VARIANT_ENUM_CAST(core_bind::OS::VideoDriver);
VARIANT_ENUM_CAST(core_bind::OS::Weekday);
VARIANT_ENUM_CAST(core_bind::OS::Month);
VARIANT_ENUM_CAST(core_bind::OS::SystemDir);
VARIANT_ENUM_CAST(core_bind::Geometry2D::PolyBooleanOperation);
VARIANT_ENUM_CAST(core_bind::Geometry2D::PolyJoinType);
VARIANT_ENUM_CAST(core_bind::Geometry2D::PolyEndType);
VARIANT_ENUM_CAST(core_bind::File::ModeFlags);
VARIANT_ENUM_CAST(core_bind::File::CompressionMode);
VARIANT_ENUM_CAST(core_bind::Thread::Priority);
#endif // CORE_BIND_H

View File

@ -330,7 +330,7 @@ public:
if (type->method_map.has(p_name)) {
memdelete(bind);
// overloading not supported
// Overloading not supported
ERR_FAIL_V_MSG(nullptr, "Method already bound: " + instance_type + "::" + p_name + ".");
}
type->method_map[p_name] = bind;
@ -409,25 +409,25 @@ public:
#ifdef DEBUG_METHODS_ENABLED
#define BIND_CONSTANT(m_constant) \
ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#define BIND_ENUM_CONSTANT(m_constant) \
ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
#else
#define BIND_CONSTANT(m_constant) \
ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#define BIND_ENUM_CONSTANT(m_constant) \
ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#endif
#ifdef TOOLS_ENABLED
#define BIND_VMETHOD(m_method) \
ClassDB::add_virtual_method(get_class_static(), m_method);
::ClassDB::add_virtual_method(get_class_static(), m_method);
#else
@ -437,11 +437,11 @@ public:
#define GDREGISTER_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
ClassDB::register_class<m_class>(); \
::ClassDB::register_class<m_class>(); \
}
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
ClassDB::register_virtual_class<m_class>(); \
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
::ClassDB::register_virtual_class<m_class>(); \
}
#include "core/disabled_classes.gen.h"

View File

@ -137,17 +137,17 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK,
};
#define ADD_SIGNAL(m_signal) ClassDB::add_signal(get_class_static(), m_signal)
#define ADD_PROPERTY(m_property, m_setter, m_getter) ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter))
#define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter), m_index)
#define ADD_PROPERTY_DEFAULT(m_property, m_default) ClassDB::set_property_default_value(get_class_static(), m_property, m_default)
#define ADD_GROUP(m_name, m_prefix) ClassDB::add_property_group(get_class_static(), m_name, m_prefix)
#define ADD_SUBGROUP(m_name, m_prefix) ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix)
#define ADD_SIGNAL(m_signal) ::ClassDB::add_signal(get_class_static(), m_signal)
#define ADD_PROPERTY(m_property, m_setter, m_getter) ::ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter))
#define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ::ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter), m_index)
#define ADD_PROPERTY_DEFAULT(m_property, m_default) ::ClassDB::set_property_default_value(get_class_static(), m_property, m_default)
#define ADD_GROUP(m_name, m_prefix) ::ClassDB::add_property_group(get_class_static(), m_name, m_prefix)
#define ADD_SUBGROUP(m_name, m_prefix) ::ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix)
struct PropertyInfo {
Variant::Type type = Variant::NIL;
String name;
StringName class_name; //for classes
StringName class_name; // For classes
PropertyHint hint = PROPERTY_HINT_NONE;
String hint_string;
uint32_t usage = PROPERTY_USAGE_DEFAULT;
@ -277,7 +277,7 @@ struct ObjectNativeExtension {
};
#define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__)
#define GDVIRTUAL_BIND(m_name) ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info());
#define GDVIRTUAL_BIND(m_name) ::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info());
/*
the following is an incomprehensible blob of hacks and workarounds to compensate for many of the fallencies in C++. As a plus, this macro pretty much alone defines the object model.
@ -299,7 +299,7 @@ private:
private: \
void operator=(const m_class &p_rval) {} \
mutable StringName _class_name; \
friend class ClassDB; \
friend class ::ClassDB; \
\
public: \
virtual String get_class() const override { \
@ -372,7 +372,7 @@ public:
return; \
} \
m_inherits::initialize_class(); \
ClassDB::_add_class<m_class>(); \
::ClassDB::_add_class<m_class>(); \
if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
_bind_methods(); \
} \
@ -415,13 +415,13 @@ protected:
} \
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
if (!_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
::ClassDB::get_property_list(#m_class, p_list, true, this); \
} \
if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
_get_property_list(p_list); \
} \
if (_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
::ClassDB::get_property_list(#m_class, p_list, true, this); \
} \
if (p_reversed) { \
m_inherits::_get_property_listv(p_list, p_reversed); \

View File

@ -84,18 +84,18 @@ static Ref<ResourceFormatSaverCrypto> resource_format_saver_crypto;
static Ref<ResourceFormatLoaderCrypto> resource_format_loader_crypto;
static Ref<NativeExtensionResourceLoader> resource_loader_native_extension;
static _ResourceLoader *_resource_loader = nullptr;
static _ResourceSaver *_resource_saver = nullptr;
static _OS *_os = nullptr;
static _Engine *_engine = nullptr;
static _ClassDB *_classdb = nullptr;
static _Marshalls *_marshalls = nullptr;
static _EngineDebugger *_engine_debugger = nullptr;
static core_bind::ResourceLoader *_resource_loader = nullptr;
static core_bind::ResourceSaver *_resource_saver = nullptr;
static core_bind::OS *_os = nullptr;
static core_bind::Engine *_engine = nullptr;
static core_bind::special::ClassDB *_classdb = nullptr;
static core_bind::Marshalls *_marshalls = nullptr;
static core_bind::EngineDebugger *_engine_debugger = nullptr;
static IP *ip = nullptr;
static _Geometry2D *_geometry_2d = nullptr;
static _Geometry3D *_geometry_3d = nullptr;
static core_bind::Geometry2D *_geometry_2d = nullptr;
static core_bind::Geometry3D *_geometry_3d = nullptr;
extern Mutex _global_mutex;
@ -203,11 +203,11 @@ void register_core_types() {
GDREGISTER_CLASS(ResourceFormatLoader);
GDREGISTER_CLASS(ResourceFormatSaver);
GDREGISTER_CLASS(_File);
GDREGISTER_CLASS(_Directory);
GDREGISTER_CLASS(_Thread);
GDREGISTER_CLASS(_Mutex);
GDREGISTER_CLASS(_Semaphore);
GDREGISTER_CLASS(core_bind::File);
GDREGISTER_CLASS(core_bind::Directory);
GDREGISTER_CLASS(core_bind::Thread);
GDREGISTER_CLASS(core_bind::Mutex);
GDREGISTER_CLASS(core_bind::Semaphore);
GDREGISTER_CLASS(XMLParser);
GDREGISTER_CLASS(JSON);
@ -240,16 +240,16 @@ void register_core_types() {
ip = IP::create();
_geometry_2d = memnew(_Geometry2D);
_geometry_3d = memnew(_Geometry3D);
_geometry_2d = memnew(core_bind::Geometry2D);
_geometry_3d = memnew(core_bind::Geometry3D);
_resource_loader = memnew(_ResourceLoader);
_resource_saver = memnew(_ResourceSaver);
_os = memnew(_OS);
_engine = memnew(_Engine);
_classdb = memnew(_ClassDB);
_marshalls = memnew(_Marshalls);
_engine_debugger = memnew(_EngineDebugger);
_resource_loader = memnew(core_bind::ResourceLoader);
_resource_saver = memnew(core_bind::ResourceSaver);
_os = memnew(core_bind::OS);
_engine = memnew(core_bind::Engine);
_classdb = memnew(core_bind::special::ClassDB);
_marshalls = memnew(core_bind::Marshalls);
_engine_debugger = memnew(core_bind::EngineDebugger);
}
void register_core_settings() {
@ -266,35 +266,35 @@ void register_core_settings() {
void register_core_singletons() {
GDREGISTER_CLASS(ProjectSettings);
GDREGISTER_VIRTUAL_CLASS(IP);
GDREGISTER_CLASS(_Geometry2D);
GDREGISTER_CLASS(_Geometry3D);
GDREGISTER_CLASS(_ResourceLoader);
GDREGISTER_CLASS(_ResourceSaver);
GDREGISTER_CLASS(_OS);
GDREGISTER_CLASS(_Engine);
GDREGISTER_CLASS(_ClassDB);
GDREGISTER_CLASS(_Marshalls);
GDREGISTER_CLASS(core_bind::Geometry2D);
GDREGISTER_CLASS(core_bind::Geometry3D);
GDREGISTER_CLASS(core_bind::ResourceLoader);
GDREGISTER_CLASS(core_bind::ResourceSaver);
GDREGISTER_CLASS(core_bind::OS);
GDREGISTER_CLASS(core_bind::Engine);
GDREGISTER_CLASS(core_bind::special::ClassDB);
GDREGISTER_CLASS(core_bind::Marshalls);
GDREGISTER_CLASS(TranslationServer);
GDREGISTER_VIRTUAL_CLASS(Input);
GDREGISTER_CLASS(InputMap);
GDREGISTER_CLASS(Expression);
GDREGISTER_CLASS(_EngineDebugger);
GDREGISTER_CLASS(core_bind::EngineDebugger);
GDREGISTER_CLASS(Time);
Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton(), "IP"));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry2D", _Geometry2D::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry3D", _Geometry3D::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceLoader", _ResourceLoader::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceSaver", _ResourceSaver::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("OS", _OS::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Engine", _Engine::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry2D", core_bind::Geometry2D::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry3D", core_bind::Geometry3D::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceLoader", core_bind::ResourceLoader::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceSaver", core_bind::ResourceSaver::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("OS", core_bind::OS::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Engine", core_bind::Engine::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ClassDB", _classdb));
Engine::get_singleton()->add_singleton(Engine::Singleton("Marshalls", _Marshalls::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Marshalls", core_bind::Marshalls::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("TranslationServer", TranslationServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Input", Input::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("EngineDebugger", _EngineDebugger::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("EngineDebugger", core_bind::EngineDebugger::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("NativeExtensionManager", NativeExtensionManager::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceUID", ResourceUID::get_singleton()));

View File

@ -241,14 +241,27 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
}
};
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, String(#m_enum).replace("::", ".")); \
} \
namespace godot {
namespace details {
inline String enum_qualified_name_to_class_info_name(const String &p_qualified_name) {
Vector<String> parts = p_qualified_name.split("::", false);
if (parts.size() <= 2)
return String(".").join(parts);
// Contains namespace. We only want the class and enum names.
return parts[parts.size() - 2] + "." + parts[parts.size() - 1];
}
} // namespace details
} // namespace godot
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, \
godot::details::enum_qualified_name_to_class_info_name(String(#m_enum))); \
} \
};
#define MAKE_ENUM_TYPE_INFO(m_enum) \

View File

@ -31,7 +31,7 @@
#include "fbx_material.h"
// FIXME: Shouldn't depend on core_bind.h! Use DirAccessRef like the rest of
// the engine instead of _Directory.
// the engine instead of core_bind::Directory.
#include "core/core_bind.h"
#include "scene/resources/material.h"
#include "scene/resources/texture.h"
@ -55,7 +55,7 @@ void FBXMaterial::add_search_string(String p_filename, String p_current_director
}
String find_file(const String &p_base, const String &p_file_to_find) {
_Directory dir;
core_bind::Directory dir;
dir.open(p_base);
dir.list_dir_begin();
@ -84,7 +84,7 @@ String find_file(const String &p_base, const String &p_file_to_find) {
// fbx will not give us good path information and let's not regex them to fix them
// no relative paths are in fbx generally they have a rel field but it's populated incorrectly by the SDK.
String FBXMaterial::find_texture_path_by_filename(const String p_filename, const String p_current_directory) {
_Directory dir;
core_bind::Directory dir;
Vector<String> paths;
add_search_string(p_filename, p_current_directory, "", paths);
add_search_string(p_filename, p_current_directory, "texture", paths);

View File

@ -241,7 +241,7 @@ MonoBoolean godot_icall_Internal_IsAssembliesReloadingNeeded() {
void godot_icall_Internal_ReloadAssemblies(MonoBoolean p_soft_reload) {
#ifdef GD_MONO_HOT_RELOAD
_GodotSharp::get_singleton()->call_deferred(SNAME("_reload_assemblies"), (bool)p_soft_reload);
mono_bind::GodotSharp::get_singleton()->call_deferred(SNAME("_reload_assemblies"), (bool)p_soft_reload);
#endif
}

View File

@ -73,7 +73,7 @@
#endif
// TODO:
// This has turn into a gigantic mess. There's too much going on here. Too much #ifdef as well.
// This has turned into a gigantic mess. There's too much going on here. Too much #ifdef as well.
// It's just painful to read... It needs to be re-structured. Please, clean this up, future me.
GDMono *GDMono::singleton = nullptr;
@ -1335,23 +1335,25 @@ GDMono::~GDMono() {
singleton = nullptr;
}
_GodotSharp *_GodotSharp::singleton = nullptr;
namespace mono_bind {
void _GodotSharp::attach_thread() {
GodotSharp *GodotSharp::singleton = nullptr;
void GodotSharp::attach_thread() {
GDMonoUtils::attach_current_thread();
}
void _GodotSharp::detach_thread() {
void GodotSharp::detach_thread() {
GDMonoUtils::detach_current_thread();
}
int32_t _GodotSharp::get_domain_id() {
int32_t GodotSharp::get_domain_id() {
MonoDomain *domain = mono_domain_get();
ERR_FAIL_NULL_V(domain, -1);
return mono_domain_get_id(domain);
}
int32_t _GodotSharp::get_scripts_domain_id() {
int32_t GodotSharp::get_scripts_domain_id() {
ERR_FAIL_NULL_V_MSG(GDMono::get_singleton(),
-1, "The Mono runtime is not initialized");
MonoDomain *domain = GDMono::get_singleton()->get_scripts_domain();
@ -1359,21 +1361,21 @@ int32_t _GodotSharp::get_scripts_domain_id() {
return mono_domain_get_id(domain);
}
bool _GodotSharp::is_scripts_domain_loaded() {
bool GodotSharp::is_scripts_domain_loaded() {
return GDMono::get_singleton() != nullptr &&
GDMono::get_singleton()->is_runtime_initialized() &&
GDMono::get_singleton()->get_scripts_domain() != nullptr;
}
bool _GodotSharp::_is_domain_finalizing_for_unload(int32_t p_domain_id) {
bool GodotSharp::_is_domain_finalizing_for_unload(int32_t p_domain_id) {
return is_domain_finalizing_for_unload(p_domain_id);
}
bool _GodotSharp::is_domain_finalizing_for_unload(int32_t p_domain_id) {
bool GodotSharp::is_domain_finalizing_for_unload(int32_t p_domain_id) {
return is_domain_finalizing_for_unload(mono_domain_get_by_id(p_domain_id));
}
bool _GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) {
bool GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) {
GDMono *gd_mono = GDMono::get_singleton();
ERR_FAIL_COND_V_MSG(!gd_mono || !gd_mono->is_runtime_initialized(),
@ -1388,15 +1390,15 @@ bool _GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) {
return mono_domain_is_unloading(p_domain);
}
bool _GodotSharp::is_runtime_shutting_down() {
bool GodotSharp::is_runtime_shutting_down() {
return mono_runtime_is_shutting_down();
}
bool _GodotSharp::is_runtime_initialized() {
bool GodotSharp::is_runtime_initialized() {
return GDMono::get_singleton() != nullptr && GDMono::get_singleton()->is_runtime_initialized();
}
void _GodotSharp::_reload_assemblies(bool p_soft_reload) {
void GodotSharp::_reload_assemblies(bool p_soft_reload) {
#ifdef GD_MONO_HOT_RELOAD
CRASH_COND(CSharpLanguage::get_singleton() == nullptr);
// This method may be called more than once with `call_deferred`, so we need to check
@ -1407,24 +1409,26 @@ void _GodotSharp::_reload_assemblies(bool p_soft_reload) {
#endif
}
void _GodotSharp::_bind_methods() {
ClassDB::bind_method(D_METHOD("attach_thread"), &_GodotSharp::attach_thread);
ClassDB::bind_method(D_METHOD("detach_thread"), &_GodotSharp::detach_thread);
void GodotSharp::_bind_methods() {
ClassDB::bind_method(D_METHOD("attach_thread"), &GodotSharp::attach_thread);
ClassDB::bind_method(D_METHOD("detach_thread"), &GodotSharp::detach_thread);
ClassDB::bind_method(D_METHOD("get_domain_id"), &_GodotSharp::get_domain_id);
ClassDB::bind_method(D_METHOD("get_scripts_domain_id"), &_GodotSharp::get_scripts_domain_id);
ClassDB::bind_method(D_METHOD("is_scripts_domain_loaded"), &_GodotSharp::is_scripts_domain_loaded);
ClassDB::bind_method(D_METHOD("is_domain_finalizing_for_unload", "domain_id"), &_GodotSharp::_is_domain_finalizing_for_unload);
ClassDB::bind_method(D_METHOD("get_domain_id"), &GodotSharp::get_domain_id);
ClassDB::bind_method(D_METHOD("get_scripts_domain_id"), &GodotSharp::get_scripts_domain_id);
ClassDB::bind_method(D_METHOD("is_scripts_domain_loaded"), &GodotSharp::is_scripts_domain_loaded);
ClassDB::bind_method(D_METHOD("is_domain_finalizing_for_unload", "domain_id"), &GodotSharp::_is_domain_finalizing_for_unload);
ClassDB::bind_method(D_METHOD("is_runtime_shutting_down"), &_GodotSharp::is_runtime_shutting_down);
ClassDB::bind_method(D_METHOD("is_runtime_initialized"), &_GodotSharp::is_runtime_initialized);
ClassDB::bind_method(D_METHOD("_reload_assemblies"), &_GodotSharp::_reload_assemblies);
ClassDB::bind_method(D_METHOD("is_runtime_shutting_down"), &GodotSharp::is_runtime_shutting_down);
ClassDB::bind_method(D_METHOD("is_runtime_initialized"), &GodotSharp::is_runtime_initialized);
ClassDB::bind_method(D_METHOD("_reload_assemblies"), &GodotSharp::_reload_assemblies);
}
_GodotSharp::_GodotSharp() {
GodotSharp::GodotSharp() {
singleton = this;
}
_GodotSharp::~_GodotSharp() {
GodotSharp::~GodotSharp() {
singleton = nullptr;
}
} // namespace mono_bind

View File

@ -293,8 +293,10 @@ public:
gdmono::ScopeExitDomainUnload __gdmono__scope__exit__domain__unload__(m_mono_domain); \
(void)__gdmono__scope__exit__domain__unload__;
class _GodotSharp : public Object {
GDCLASS(_GodotSharp, Object);
namespace mono_bind {
class GodotSharp : public Object {
GDCLASS(GodotSharp, Object);
friend class GDMono;
@ -303,11 +305,11 @@ class _GodotSharp : public Object {
void _reload_assemblies(bool p_soft_reload);
protected:
static _GodotSharp *singleton;
static GodotSharp *singleton;
static void _bind_methods();
public:
static _GodotSharp *get_singleton() { return singleton; }
static GodotSharp *get_singleton() { return singleton; }
void attach_thread();
void detach_thread();
@ -323,8 +325,10 @@ public:
bool is_runtime_shutting_down();
bool is_runtime_initialized();
_GodotSharp();
~_GodotSharp();
GodotSharp();
~GodotSharp();
};
} // namespace mono_bind
#endif // GD_MONO_H

View File

@ -38,15 +38,15 @@ CSharpLanguage *script_language_cs = nullptr;
Ref<ResourceFormatLoaderCSharpScript> resource_loader_cs;
Ref<ResourceFormatSaverCSharpScript> resource_saver_cs;
_GodotSharp *_godotsharp = nullptr;
mono_bind::GodotSharp *_godotsharp = nullptr;
void register_mono_types() {
GDREGISTER_CLASS(CSharpScript);
_godotsharp = memnew(_GodotSharp);
_godotsharp = memnew(mono_bind::GodotSharp);
GDREGISTER_CLASS(_GodotSharp);
Engine::get_singleton()->add_singleton(Engine::Singleton("GodotSharp", _GodotSharp::get_singleton()));
GDREGISTER_CLASS(mono_bind::GodotSharp);
Engine::get_singleton()->add_singleton(Engine::Singleton("GodotSharp", mono_bind::GodotSharp::get_singleton()));
script_language_cs = memnew(CSharpLanguage);
script_language_cs->set_language_index(ScriptServer::get_language_count());

View File

@ -43,7 +43,7 @@
VisualScriptLanguage *visual_script_language = nullptr;
#ifdef TOOLS_ENABLED
static _VisualScriptEditor *vs_editor_singleton = nullptr;
static vs_bind::VisualScriptEditor *vs_editor_singleton = nullptr;
#endif
void register_visual_script_types() {
@ -114,10 +114,10 @@ void register_visual_script_types() {
#ifdef TOOLS_ENABLED
ClassDB::set_current_api(ClassDB::API_EDITOR);
GDREGISTER_CLASS(_VisualScriptEditor);
GDREGISTER_CLASS(vs_bind::VisualScriptEditor);
ClassDB::set_current_api(ClassDB::API_CORE);
vs_editor_singleton = memnew(_VisualScriptEditor);
Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptEditor", _VisualScriptEditor::get_singleton()));
vs_editor_singleton = memnew(vs_bind::VisualScriptEditor);
Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptEditor", vs_bind::VisualScriptEditor::get_singleton()));
VisualScriptEditor::register_editor();
#endif

View File

@ -4521,44 +4521,49 @@ void VisualScriptEditor::register_editor() {
EditorNode::add_plugin_init_callback(register_editor_callback);
}
Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) {
void VisualScriptEditor::validate() {
}
namespace vs_bind {
Ref<VisualScriptNode> VisualScriptEditor::create_node_custom(const String &p_name) {
Ref<VisualScriptCustomNode> node;
node.instantiate();
node->set_script(singleton->custom_nodes[p_name]);
return node;
}
_VisualScriptEditor *_VisualScriptEditor::singleton = nullptr;
Map<String, REF> _VisualScriptEditor::custom_nodes;
VisualScriptEditor *VisualScriptEditor::singleton = nullptr;
Map<String, REF> VisualScriptEditor::custom_nodes;
_VisualScriptEditor::_VisualScriptEditor() {
VisualScriptEditor::VisualScriptEditor() {
singleton = this;
}
_VisualScriptEditor::~_VisualScriptEditor() {
VisualScriptEditor::~VisualScriptEditor() {
custom_nodes.clear();
}
void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
void VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
String node_name = "custom/" + p_category + "/" + p_name;
custom_nodes.insert(node_name, p_script);
VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom);
VisualScriptLanguage::singleton->add_register_func(node_name, &VisualScriptEditor::create_node_custom);
emit_signal(SNAME("custom_nodes_updated"));
}
void _VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) {
void VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) {
String node_name = "custom/" + p_category + "/" + p_name;
custom_nodes.erase(node_name);
VisualScriptLanguage::singleton->remove_register_func(node_name);
emit_signal(SNAME("custom_nodes_updated"));
}
void _VisualScriptEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &_VisualScriptEditor::add_custom_node);
ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &_VisualScriptEditor::remove_custom_node);
void VisualScriptEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &VisualScriptEditor::add_custom_node);
ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &VisualScriptEditor::remove_custom_node);
ADD_SIGNAL(MethodInfo("custom_nodes_updated"));
}
void VisualScriptEditor::validate() {
}
} // namespace vs_bind
#endif

View File

@ -332,28 +332,33 @@ public:
~VisualScriptEditor();
};
namespace vs_bind {
// Singleton
class _VisualScriptEditor : public Object {
GDCLASS(_VisualScriptEditor, Object);
class VisualScriptEditor : public Object {
GDCLASS(VisualScriptEditor, Object);
friend class VisualScriptLanguage;
protected:
static void _bind_methods();
static _VisualScriptEditor *singleton;
static VisualScriptEditor *singleton;
static Map<String, REF> custom_nodes;
static Ref<VisualScriptNode> create_node_custom(const String &p_name);
public:
static _VisualScriptEditor *get_singleton() { return singleton; }
static VisualScriptEditor *get_singleton() { return singleton; }
void add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script);
void remove_custom_node(const String &p_name, const String &p_category);
_VisualScriptEditor();
~_VisualScriptEditor();
VisualScriptEditor();
~VisualScriptEditor();
};
} // namespace vs_bind
#endif
#endif // VISUALSCRIPT_EDITOR_H