1 module godot.c.core;
2 
3 public import core.stdc.stddef : wchar_t;
4 import godot.c.api;
5 
6 @nogc nothrow:
7 extern(C):
8 
9 enum GODOT_API_VERSION = 1;
10 
11 ////// Error
12 
13 enum godot_error {
14 	GODOT_OK,
15 	GODOT_FAILED, ///< Generic fail error
16 	GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
17 	GODOT_ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
18 	GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
19 	GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
20 	GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory
21 	GODOT_ERR_FILE_NOT_FOUND,
22 	GODOT_ERR_FILE_BAD_DRIVE,
23 	GODOT_ERR_FILE_BAD_PATH,
24 	GODOT_ERR_FILE_NO_PERMISSION, // (10)
25 	GODOT_ERR_FILE_ALREADY_IN_USE,
26 	GODOT_ERR_FILE_CANT_OPEN,
27 	GODOT_ERR_FILE_CANT_WRITE,
28 	GODOT_ERR_FILE_CANT_READ,
29 	GODOT_ERR_FILE_UNRECOGNIZED, // (15)
30 	GODOT_ERR_FILE_CORRUPT,
31 	GODOT_ERR_FILE_MISSING_DEPENDENCIES,
32 	GODOT_ERR_FILE_EOF,
33 	GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file
34 	GODOT_ERR_CANT_CREATE, // (20)
35 	GODOT_ERR_QUERY_FAILED,
36 	GODOT_ERR_ALREADY_IN_USE,
37 	GODOT_ERR_LOCKED, ///< resource is locked
38 	GODOT_ERR_TIMEOUT,
39 	GODOT_ERR_CANT_CONNECT, // (25)
40 	GODOT_ERR_CANT_RESOLVE,
41 	GODOT_ERR_CONNECTION_ERROR,
42 	GODOT_ERR_CANT_ACQUIRE_RESOURCE,
43 	GODOT_ERR_CANT_FORK,
44 	GODOT_ERR_INVALID_DATA, ///< Data passed is invalid	(30)
45 	GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
46 	GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists
47 	GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
48 	GODOT_ERR_DATABASE_CANT_READ, ///< database is full
49 	GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full	(35)
50 	GODOT_ERR_COMPILATION_FAILED,
51 	GODOT_ERR_METHOD_NOT_FOUND,
52 	GODOT_ERR_LINK_FAILED,
53 	GODOT_ERR_SCRIPT_FAILED,
54 	GODOT_ERR_CYCLIC_LINK, // (40)
55 	GODOT_ERR_INVALID_DECLARATION,
56 	GODOT_ERR_DUPLICATE_SYMBOL,
57 	GODOT_ERR_PARSE_ERROR,
58 	GODOT_ERR_BUSY,
59 	GODOT_ERR_SKIP, // (45)
60 	GODOT_ERR_HELP, ///< user requested help!!
61 	GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
62 	GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
63 	GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
64 	GODOT_ERR_WTF = GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
65 }
66 
67 ////// bool
68 
69 alias godot_bool = bool;
70 
71 enum GODOT_TRUE = 1;
72 enum GODOT_FALSE = 0;
73 
74 /////// int
75 
76 alias godot_int = int; // C++'s int; Godot assumes it to be always 32 bits.
77 
78 /////// real
79 
80 alias godot_real = float;
81 
82 /////// Object reference (type-safe void pointer)
83 struct godot_object
84 {
85 	package(godot) void* ptr;
86 }
87 
88 // core types
89 // NOTE: quite a few of these have sizes that cause D to generate incorrect
90 // calling convention for SysV ABI (bugs 5570 & 13207). Partial workaround is
91 // using larger integers instead of byte arrays. Needs fixing eventually...
92 
93 struct godot_array
94 {
95 	size_t _opaque;
96 }
97 struct godot_basis
98 {
99 	uint[9] _opaque;
100 }
101 struct godot_color
102 {
103 	ulong[2] _opaque;
104 }
105 struct godot_dictionary
106 {
107 	size_t _opaque;
108 }
109 struct godot_node_path
110 {
111 	size_t _opaque;
112 }
113 struct godot_plane
114 {
115 	ulong[2] _opaque;
116 }
117 
118 mixin template PoolArray(Type, string name)
119 {
120 	mixin("struct godot_pool_"~name~"_array { size_t _opaque; }");
121 	mixin("struct godot_pool_"~name~"_array_read_access { ubyte _opaque; }");
122 	mixin("struct godot_pool_"~name~"_array_write_access { ubyte _opaque; }");
123 }
124 mixin PoolArray!(ubyte, "byte");
125 mixin PoolArray!(int, "int");
126 mixin PoolArray!(float, "real");
127 mixin PoolArray!(godot_string, "string");
128 mixin PoolArray!(godot_vector2, "vector2");
129 mixin PoolArray!(godot_vector3, "vector3");
130 mixin PoolArray!(godot_color, "color");
131 
132 
133 struct godot_quat
134 {
135 	ulong[2] _opaque;
136 }
137 struct godot_rect2
138 {
139 	ulong[2] _opaque;
140 }
141 struct godot_aabb
142 {
143 	ulong[3] _opaque;
144 }
145 struct godot_rid
146 {
147 	size_t _opaque;
148 }
149 struct godot_string
150 {
151 	size_t _opaque;
152 }
153 struct godot_char_string
154 {
155 	size_t _opaque;
156 }
157 struct godot_string_name
158 {
159 	size_t _opaque;
160 }
161 struct godot_transform
162 {
163 	ulong[6] _opaque;
164 }
165 struct godot_transform2d
166 {
167 	ulong[3] _opaque;
168 }
169 struct godot_variant
170 {
171 	ulong[2] _opaque;
172 	size_t _opaque2;
173 }
174 enum godot_variant_type
175 {
176 	GODOT_VARIANT_TYPE_NIL,
177 
178 	// atomic types
179 	GODOT_VARIANT_TYPE_BOOL,
180 	GODOT_VARIANT_TYPE_INT,
181 	GODOT_VARIANT_TYPE_REAL,
182 	GODOT_VARIANT_TYPE_STRING,
183 
184 	// math types
185 
186 	GODOT_VARIANT_TYPE_VECTOR2, // 5
187 	GODOT_VARIANT_TYPE_RECT2,
188 	GODOT_VARIANT_TYPE_VECTOR3,
189 	GODOT_VARIANT_TYPE_TRANSFORM2D,
190 	GODOT_VARIANT_TYPE_PLANE,
191 	GODOT_VARIANT_TYPE_QUAT, // 10
192 	GODOT_VARIANT_TYPE_AABB,
193 	GODOT_VARIANT_TYPE_BASIS,
194 	GODOT_VARIANT_TYPE_TRANSFORM,
195 
196 	// misc types
197 	GODOT_VARIANT_TYPE_COLOR,
198 	GODOT_VARIANT_TYPE_NODE_PATH, // 15
199 	GODOT_VARIANT_TYPE_RID,
200 	GODOT_VARIANT_TYPE_OBJECT,
201 	GODOT_VARIANT_TYPE_DICTIONARY,
202 	GODOT_VARIANT_TYPE_ARRAY, // 20
203 
204 	// arrays
205 	GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY,
206 	GODOT_VARIANT_TYPE_POOL_INT_ARRAY,
207 	GODOT_VARIANT_TYPE_POOL_REAL_ARRAY,
208 	GODOT_VARIANT_TYPE_POOL_STRING_ARRAY,
209 	GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, // 25
210 	GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY,
211 	GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY,
212 }
213 enum godot_variant_call_error_error
214 {
215 	GODOT_CALL_ERROR_CALL_OK,
216 	GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD,
217 	GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT,
218 	GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS,
219 	GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS,
220 	GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL,
221 }
222 struct godot_variant_call_error
223 {
224 	godot_variant_call_error_error error;
225 	int argument;
226 	godot_variant_type expected;
227 }
228 enum godot_variant_operator {
229 	// comparison
230 	GODOT_VARIANT_OP_EQUAL,
231 	GODOT_VARIANT_OP_NOT_EQUAL,
232 	GODOT_VARIANT_OP_LESS,
233 	GODOT_VARIANT_OP_LESS_EQUAL,
234 	GODOT_VARIANT_OP_GREATER,
235 	GODOT_VARIANT_OP_GREATER_EQUAL,
236 
237 	// mathematic
238 	GODOT_VARIANT_OP_ADD,
239 	GODOT_VARIANT_OP_SUBTRACT,
240 	GODOT_VARIANT_OP_MULTIPLY,
241 	GODOT_VARIANT_OP_DIVIDE,
242 	GODOT_VARIANT_OP_NEGATE,
243 	GODOT_VARIANT_OP_POSITIVE,
244 	GODOT_VARIANT_OP_MODULE,
245 	GODOT_VARIANT_OP_STRING_CONCAT,
246 
247 	// bitwise
248 	GODOT_VARIANT_OP_SHIFT_LEFT,
249 	GODOT_VARIANT_OP_SHIFT_RIGHT,
250 	GODOT_VARIANT_OP_BIT_AND,
251 	GODOT_VARIANT_OP_BIT_OR,
252 	GODOT_VARIANT_OP_BIT_XOR,
253 	GODOT_VARIANT_OP_BIT_NEGATE,
254 
255 	// logic
256 	GODOT_VARIANT_OP_AND,
257 	GODOT_VARIANT_OP_OR,
258 	GODOT_VARIANT_OP_XOR,
259 	GODOT_VARIANT_OP_NOT,
260 
261 	// containment
262 	GODOT_VARIANT_OP_IN,
263 
264 	GODOT_VARIANT_OP_MAX,
265 }
266 struct godot_vector2
267 {
268 	ulong _opaque;
269 }
270 struct godot_vector3
271 {
272 	uint[3] _opaque;
273 }
274 enum godot_vector3_axis
275 {
276 	GODOT_VECTOR3_AXIS_X,
277 	GODOT_VECTOR3_AXIS_Y,
278 	GODOT_VECTOR3_AXIS_Z,
279 }
280 
281 ////// MethodBind API
282 
283 struct godot_method_bind {
284 	ubyte[1] _dont_touch_that; // TODO
285 }
286 
287 struct godot_gdnative_api_version {
288 	uint major;
289 	uint minor;
290 }
291 
292 struct godot_gdnative_init_options {
293 	godot_bool in_editor;
294 	ulong core_api_hash;
295 	ulong editor_api_hash;
296 	ulong no_api_hash;
297 	void function(const godot_object p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) report_version_mismatch;
298 	void function(const godot_object p_library, const char *p_what) report_loading_error;
299 	godot_object gd_native_library; // pointer to GDNativeLibrary that is being initialized
300 	const(godot_gdnative_core_api_struct)* api_struct; // contains all C function pointers
301 	const(godot_string)* active_library_path;
302 }
303 
304 struct godot_gdnative_terminate_options {
305 	godot_bool in_editor;
306 }
307 
308 alias godot_class_constructor = godot_object function();
309 
310 ////// GDNative procedure types
311 alias godot_gdnative_init_fn = void function(godot_gdnative_init_options *);
312 alias godot_gdnative_terminate_fn = void function(godot_gdnative_terminate_options *);
313 alias godot_gdnative_procedure_fn = godot_variant function(void *, godot_array *);
314 
315 alias native_call_cb = godot_variant function(void *, godot_array *);
316 
317