diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2022-09-06 15:35:33 +0200 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2022-09-07 15:05:46 +0200 |
commit | 532e378cd9da5ab2121c6da8ac7d06ae7d5b6006 (patch) | |
tree | 073e9497b43233b4ebc35c9c8fc2203d214520d8 /servers/physics_server_2d.h | |
parent | 019253512d75eb5e012772921ace6c092d8f5380 (diff) |
Expose registration of physics servers to GDExtension
This exposes PhysicsServer2DManager and PhysicsServer3DManager.
Diffstat (limited to 'servers/physics_server_2d.h')
-rw-r--r-- | servers/physics_server_2d.h | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index f1e05e7a46..d5b4dc05e6 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -766,16 +766,18 @@ public: real_t get_collision_unsafe_fraction() const; }; -typedef PhysicsServer2D *(*CreatePhysicsServer2DCallback)(); +class PhysicsServer2DManager : public Object { + GDCLASS(PhysicsServer2DManager, Object); + + static PhysicsServer2DManager *singleton; -class PhysicsServer2DManager { struct ClassInfo { String name; - CreatePhysicsServer2DCallback create_callback = nullptr; + Callable create_callback; ClassInfo() {} - ClassInfo(String p_name, CreatePhysicsServer2DCallback p_create_callback) : + ClassInfo(String p_name, Callable p_create_callback) : name(p_name), create_callback(p_create_callback) {} @@ -789,24 +791,30 @@ class PhysicsServer2DManager { } }; - static Vector<ClassInfo> physics_2d_servers; - static int default_server_id; - static int default_server_priority; + Vector<ClassInfo> physics_2d_servers; + int default_server_id = -1; + int default_server_priority = -1; + + void on_servers_changed(); + +protected: + static void _bind_methods(); public: static const String setting_property_name; -private: - static void on_servers_changed(); + static PhysicsServer2DManager *get_singleton(); -public: - static void register_server(const String &p_name, CreatePhysicsServer2DCallback p_creat_callback); - static void set_default_server(const String &p_name, int p_priority = 0); - static int find_server_id(const String &p_name); - static int get_servers_count(); - static String get_server_name(int p_id); - static PhysicsServer2D *new_default_server(); - static PhysicsServer2D *new_server(const String &p_name); + void register_server(const String &p_name, const Callable &p_create_callback); + void set_default_server(const String &p_name, int p_priority = 0); + int find_server_id(const String &p_name); + int get_servers_count(); + String get_server_name(int p_id); + PhysicsServer2D *new_default_server(); + PhysicsServer2D *new_server(const String &p_name); + + PhysicsServer2DManager(); + ~PhysicsServer2DManager(); }; VARIANT_ENUM_CAST(PhysicsServer2D::ShapeType); |