Skip to content

Commit cedba3a

Browse files
committed
Continue conversion
1 parent 3fd8246 commit cedba3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+982
-756
lines changed

CMakeLists.txt

+12-22
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,25 @@ add_compile_definitions(X11_ENABLED)
2020
#add_compile_definitions(__ANDROID__)
2121

2222

23-
# Godot-cpp
24-
file(GLOB_RECURSE GODOT-CPP godot-cpp/*.cpp)
25-
add_library(godot STATIC ${GODOT-CPP})
23+
# Project
24+
file(GLOB_RECURSE SOURCES src/*.c**)
25+
file(GLOB_RECURSE HEADERS src/*.h**)
26+
27+
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
2628

27-
target_include_directories(godot
28-
PUBLIC
29+
include_directories(src)
30+
include_directories(
31+
SYSTEM
2932
godot-cpp/include
3033
godot-cpp/include/godot_cpp
3134
godot-cpp/gen/include
3235
godot-cpp/gen/include/godot_cpp
3336
godot-cpp/gdextension
3437
)
3538

36-
37-
# Project
38-
file(GLOB_RECURSE SOURCES src/*.c**)
39-
file(GLOB_RECURSE HEADERS src/*.h**)
40-
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
41-
42-
target_include_directories(${PROJECT_NAME}
43-
PUBLIC
44-
src
45-
)
46-
47-
4839
find_package(JNI REQUIRED)
49-
include_directories(${JNI_INCLUDE_DIRS})
40+
include_directories(
41+
SYSTEM
42+
${JNI_INCLUDE_DIRS}
43+
)
5044

51-
target_link_libraries(${PROJECT_NAME}
52-
PRIVATE
53-
godot
54-
)

src/api/language/gdj_language.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class GdjLanguage : public JvmLanguage {
1919
void thread_enter() override;
2020
void thread_exit() override;
2121

22-
String get_name() const override;
23-
String get_type() const override;
22+
godot::String get_name() const override;
23+
godot::String get_type() const override;
2424
String get_extension() const override;
2525
void get_recognized_extensions(List<String>* p_extensions) const override;
2626

src/api/script/jvm_instance.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include "core/object/script_language.h"
55
#include "jvm_script.h"
6-
#include "jvm_wrapper/registration/kt_class.h"
7-
#include "jvm_wrapper/memory/memory_manager.h"
6+
#include "jvm/wrapper/registration/kt_class.h"
7+
#include "jvm/wrapper/memory/memory_manager.h"
88

99
class JvmInstance : public ScriptInstance {
1010
friend class MemoryManager;

src/api/script/jvm_script.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef GODOT_JVM_JVM_SCRIPT_H
22
#define GODOT_JVM_JVM_SCRIPT_H
33

4-
#include "jvm_wrapper/registration/kt_class.h"
4+
#include "jvm/wrapper/registration/kt_class.h"
55
#include "resource_format/hash.h"
66

77
#include <classes/script_language_extension.hpp>

src/core/jvm_binding.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef GODOT_JVM_JVM_BINDING_H
22
#define GODOT_JVM_JVM_BINDING_H
33

4-
#include "jvm_wrapper/registration/kt_object.h"
4+
#include "jvm/wrapper/registration/kt_object.h"
55
#include <atomic>
66

77
class JvmBinding {

src/core/variant_allocator.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef GODOT_JVM_VARIANT_ALLOCATOR_H
22
#define GODOT_JVM_VARIANT_ALLOCATOR_H
33

4-
#include "paged_allocator.h"
4+
#include "engine/paged_allocator.h"
5+
56
#include <variant/variant.hpp>
67

78
class VariantAllocator {
89
union BucketSmall {
910
BucketSmall() {}
11+
1012
~BucketSmall() {}
1113

1214
godot::StringName string_name;
@@ -17,6 +19,7 @@ class VariantAllocator {
1719

1820
union BucketLarge {
1921
BucketLarge() {}
22+
2023
~BucketLarge() {}
2124

2225
godot::Callable callable;

src/editor/godot_kotlin_jvm_editor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GodotKotlinJvmEditor : public EditorPlugin {
3939
GodotKotlinJvmEditor(const GodotKotlinJvmEditor&) = delete;
4040

4141
void _notification(int notification);
42-
void update_build_dialog(String log);
42+
void update_build_dialog(godot::String log);
4343

4444
};
4545

src/engine/marshalls.h

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/**************************************************************************/
2+
/* marshalls.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
//https://github.com/godotengine/godot/blob/1f787b63a54b74a5238653883fe1a531200b675e/core/io/marshalls.h#L167
32+
33+
#pragma once
34+
35+
#include <classes/ref_counted.hpp>
36+
#include <variant/variant.hpp>
37+
38+
// uintr_t is only for pairing with real_t, and we only need it in here.
39+
#ifdef REAL_T_IS_DOUBLE
40+
typedef uint64_t uintr_t;
41+
#else
42+
typedef uint32_t uintr_t;
43+
#endif
44+
45+
/**
46+
* Miscellaneous helpers for marshaling data types, and encoding
47+
* in an endian independent way
48+
*/
49+
50+
union MarshallFloat {
51+
uint32_t i; ///< int
52+
float f; ///< float
53+
};
54+
55+
union MarshallDouble {
56+
uint64_t l; ///< long long
57+
double d; ///< double
58+
};
59+
60+
// Behaves like one of the above, depending on compilation setting.
61+
union MarshallReal {
62+
uintr_t i;
63+
real_t r;
64+
};
65+
66+
static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
67+
for (int i = 0; i < 2; i++) {
68+
*p_arr = p_uint & 0xFF;
69+
p_arr++;
70+
p_uint >>= 8;
71+
}
72+
73+
return sizeof(uint16_t);
74+
}
75+
76+
static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
77+
for (int i = 0; i < 4; i++) {
78+
*p_arr = p_uint & 0xFF;
79+
p_arr++;
80+
p_uint >>= 8;
81+
}
82+
83+
return sizeof(uint32_t);
84+
}
85+
86+
static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
87+
MarshallFloat mf;
88+
mf.f = p_float;
89+
encode_uint32(mf.i, p_arr);
90+
91+
return sizeof(uint32_t);
92+
}
93+
94+
static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
95+
for (int i = 0; i < 8; i++) {
96+
*p_arr = p_uint & 0xFF;
97+
p_arr++;
98+
p_uint >>= 8;
99+
}
100+
101+
return sizeof(uint64_t);
102+
}
103+
104+
static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
105+
MarshallDouble md;
106+
md.d = p_double;
107+
encode_uint64(md.l, p_arr);
108+
109+
return sizeof(uint64_t);
110+
}
111+
112+
static inline unsigned int encode_uintr(uintr_t p_uint, uint8_t *p_arr) {
113+
for (size_t i = 0; i < sizeof(uintr_t); i++) {
114+
*p_arr = p_uint & 0xFF;
115+
p_arr++;
116+
p_uint >>= 8;
117+
}
118+
119+
return sizeof(uintr_t);
120+
}
121+
122+
static inline unsigned int encode_real(real_t p_real, uint8_t *p_arr) {
123+
MarshallReal mr;
124+
mr.r = p_real;
125+
encode_uintr(mr.i, p_arr);
126+
127+
return sizeof(uintr_t);
128+
}
129+
130+
static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
131+
int len = 0;
132+
133+
while (*p_string) {
134+
if (p_data) {
135+
*p_data = (uint8_t)*p_string;
136+
p_data++;
137+
}
138+
p_string++;
139+
len++;
140+
}
141+
142+
if (p_data) {
143+
*p_data = 0;
144+
}
145+
return len + 1;
146+
}
147+
148+
static inline uint16_t decode_uint16(const uint8_t *p_arr) {
149+
uint16_t u = 0;
150+
151+
for (int i = 0; i < 2; i++) {
152+
uint16_t b = *p_arr;
153+
b <<= (i * 8);
154+
u |= b;
155+
p_arr++;
156+
}
157+
158+
return u;
159+
}
160+
161+
static inline uint32_t decode_uint32(const uint8_t *p_arr) {
162+
uint32_t u = 0;
163+
164+
for (int i = 0; i < 4; i++) {
165+
uint32_t b = *p_arr;
166+
b <<= (i * 8);
167+
u |= b;
168+
p_arr++;
169+
}
170+
171+
return u;
172+
}
173+
174+
static inline float decode_float(const uint8_t *p_arr) {
175+
MarshallFloat mf;
176+
mf.i = decode_uint32(p_arr);
177+
return mf.f;
178+
}
179+
180+
static inline uint64_t decode_uint64(const uint8_t *p_arr) {
181+
uint64_t u = 0;
182+
183+
for (int i = 0; i < 8; i++) {
184+
uint64_t b = (*p_arr) & 0xFF;
185+
b <<= (i * 8);
186+
u |= b;
187+
p_arr++;
188+
}
189+
190+
return u;
191+
}
192+
193+
static inline double decode_double(const uint8_t *p_arr) {
194+
MarshallDouble md;
195+
md.l = decode_uint64(p_arr);
196+
return md.d;
197+
}

src/core/paged_allocator.h renamed to src/engine/paged_allocator.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31+
//https://github.com/godotengine/godot/blob/1f787b63a54b74a5238653883fe1a531200b675e/core/templates/paged_allocator.h
3132
#pragma once
3233

3334
#include <core/error_macros.hpp>

src/engine/utilities.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef GODOT_JVM_UTILITIES_H
2+
#define GODOT_JVM_UTILITIES_H
3+
4+
#include <classes/object.hpp>
5+
6+
_ALWAYS_INLINE_ bool is_ref_counted(godot::Object* obj) {
7+
//https://github.com/godotengine/godot/blob/1f787b63a54b74a5238653883fe1a531200b675e/core/object/object_id.h#L44
8+
return (obj->get_instance_id() & (uint64_t(1) << 63)) != 0;
9+
}
10+
11+
#endif // GODOT_JVM_UTILITIES_H

src/jvm/jni/env.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#include "logging.h"
55

6-
#include <core/string/ustring.h>
76
#include <jni.h>
87

8+
#include <variant/string.hpp>
9+
910
namespace jni {
1011

1112
class JObject;
@@ -34,15 +35,15 @@ namespace jni {
3435

3536
JNIEnv* env;
3637

37-
static inline void(*exception_handler)(Env, JThrowable) = nullptr;
38+
static inline void (*exception_handler)(Env, JThrowable) = nullptr;
3839

3940
public:
4041
explicit Env(JNIEnv*);
4142

4243
Env(const Env&) = default;
4344
Env& operator=(const Env&) = default;
4445

45-
static void set_exception_handler(void(*p_exception_handler)(Env, JThrowable));
46+
static void set_exception_handler(void (*p_exception_handler)(Env, JThrowable));
4647

4748
JavaVM* get_jvm();
4849

@@ -52,7 +53,7 @@ namespace jni {
5253
JClass find_class(const char* name);
5354

5455
JObject new_string(const char* str);
55-
String from_jstring(JString str);
56+
godot::String from_jstring(JString str);
5657

5758
bool exception_check();
5859
void exception_describe();
@@ -68,6 +69,6 @@ namespace jni {
6869

6970
bool is_valid();
7071
};
71-
}// namespace jni
72+
} // namespace jni
7273

73-
#endif// GODOT_LOADER_ENV_H
74+
#endif // GODOT_LOADER_ENV_H

0 commit comments

Comments
 (0)