|
1 |
| -#include "kotlin_binding_manager.h" |
2 |
| - |
3 |
| -#include "gd_kotlin.h" |
| 1 | +#include "godot_jvm.h" |
4 | 2 | #include "jvm/wrapper/memory/memory_manager.h"
|
| 3 | +#include "jvm_binding_manager.h" |
5 | 4 |
|
6 |
| -GDExtensionInstanceBindingCallbacks KotlinBindingManager::_instance_binding_callbacks = { |
| 5 | +GDExtensionInstanceBindingCallbacks JvmBindingManager::_instance_binding_callbacks = { |
7 | 6 | &_instance_binding_create_callback,
|
8 | 7 | &_instance_binding_free_callback,
|
9 | 8 | nullptr
|
10 | 9 | };
|
11 | 10 |
|
12 |
| -void* KotlinBindingManager::_instance_binding_create_callback(void* p_token, void* p_instance) { |
13 |
| - KotlinBinding* binding = memnew(KotlinBinding); |
| 11 | +void* JvmBindingManager::_instance_binding_create_callback(void* p_token, void* p_instance) { |
| 12 | + JvmBinding* binding = memnew(JvmBinding); |
14 | 13 | binding->init(reinterpret_cast<godot::Object*>(p_instance));
|
15 | 14 |
|
16 | 15 | return binding;
|
17 | 16 | }
|
18 | 17 |
|
19 |
| -void KotlinBindingManager::_instance_binding_free_callback(void* p_token, void* p_instance, void* p_binding) { |
| 18 | +void JvmBindingManager::_instance_binding_free_callback(void* p_token, void* p_instance, void* p_binding) { |
20 | 19 | // Called in the destructor of the Object.
|
21 | 20 | // It's the very last action done in the destructor so assume variables local to the Object have been cleaned (including script and extension).
|
22 | 21 | // There are 2 cases, either an Object has been freed, and we have to release its reference OR it's a RefCounted and the JVM instance is already dead.
|
23 | 22 |
|
24 |
| - godot::memdelete(reinterpret_cast<KotlinBinding*>(p_binding)); |
| 23 | + godot::memdelete(reinterpret_cast<JvmBinding*>(p_binding)); |
25 | 24 |
|
26 | 25 | godot::Object* object = reinterpret_cast<godot::Object*>(p_instance);
|
27 | 26 | if (!object->is_ref_counted()) { MemoryManager::get_instance().queue_dead_object(object); }
|
28 | 27 | }
|
29 | 28 |
|
30 |
| -KotlinBinding* KotlinBindingManager::set_instance_binding(godot::Object* p_object) { |
| 29 | +JvmBinding* JvmBindingManager::set_instance_binding(godot::Object* p_object) { |
31 | 30 | // Godot being weird. Call this function only if the JVM is the creator of the object, otherwise it will crash in case the object has any other bindings.
|
32 | 31 | // If not the creator (When you want to bind an existing object to JVM), use get_instance_binding instead.
|
33 | 32 |
|
34 |
| - KotlinBinding* binding = memnew(KotlinBinding); |
| 33 | + JvmBinding* binding = memnew(JvmBinding); |
35 | 34 | binding->init(p_object);
|
36 | 35 |
|
37 | 36 | if (p_object->is_ref_counted()) {
|
38 | 37 | reinterpret_cast<godot::RefCounted*>(p_object)->init_ref();
|
39 | 38 | binding->test_and_set_incremented();
|
40 | 39 | }
|
41 |
| - p_object->set_instance_binding(&GDKotlin::get_instance(), binding, &_instance_binding_callbacks); |
| 40 | + p_object->set_instance_binding(&GodotJvm::get_instance(), binding, &_instance_binding_callbacks); |
42 | 41 |
|
43 | 42 | return binding;
|
44 | 43 | }
|
45 | 44 |
|
46 |
| -KotlinBinding* KotlinBindingManager::get_instance_binding(godot::Object* p_object) { |
| 45 | +JvmBinding* JvmBindingManager::get_instance_binding(godot::Object* p_object) { |
47 | 46 | // Godot being weird but this is how you create a binding if it doesn't exist already, otherwise just retrieve it.
|
48 | 47 | // Use this function to bind an existing object to the JVM, the callbacks provided will handle the creation of the binding.
|
49 |
| - KotlinBinding* binding = |
50 |
| - reinterpret_cast<KotlinBinding*>(p_object->get_instance_binding(&GDKotlin::get_instance(), &_instance_binding_callbacks)); |
| 48 | + JvmBinding* binding = |
| 49 | + reinterpret_cast<JvmBinding*>(p_object->get_instance_binding(&GodotJvm::get_instance(), &_instance_binding_callbacks)); |
51 | 50 |
|
52 | 51 | if (p_object->is_ref_counted() && !binding->test_and_set_incremented()) {
|
53 | 52 | reinterpret_cast<godot::RefCounted*>(p_object)->reference();
|
54 | 53 | }
|
55 | 54 | return binding;
|
56 | 55 | }
|
57 | 56 |
|
58 |
| -void KotlinBindingManager::free_binding(godot::Object* p_ref) { |
59 |
| - p_ref->free_instance_binding(&GDKotlin::get_instance()); |
| 57 | +void JvmBindingManager::free_binding(godot::Object* p_ref) { |
| 58 | + p_ref->free_instance_binding(&GodotJvm::get_instance()); |
60 | 59 | }
|
0 commit comments