diff options
Diffstat (limited to 'modules')
166 files changed, 9746 insertions, 656 deletions
diff --git a/modules/cscript/godot_c.h b/modules/cscript/godot_c.h deleted file mode 100644 index e38de1e489..0000000000 --- a/modules/cscript/godot_c.h +++ /dev/null @@ -1,567 +0,0 @@ -/*************************************************************************/ -/* godot_c.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef GODOT_C_H -#define GODOT_C_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(GDAPI_BUILT_IN) || !defined(WINDOWS_ENABLED) -#define GDAPI -#elif defined(GDAPI_EXPORTS) -#define GDAPI __declspec(dllexport) -#else -#define GDAPI __declspec(dllimport) -#endif - -#define GODOT_API_VERSION 1 - -typedef int godot_bool; - -#define GODOT_FALSE 0 -#define GODOT_TRUE 1 - -////// Image - -#define GODOT_IMAGE_FORMAT_GRAYSCALE 0 -#define GODOT_IMAGE_FORMAT_INTENSITY 1 -#define GODOT_IMAGE_FORMAT_GRAYSCALE_ALPHA 2 -#define GODOT_IMAGE_FORMAT_RGB 3 -#define GODOT_IMAGE_FORMAT_RGBA 4 -#define GODOT_IMAGE_FORMAT_INDEXED 5 -#define GODOT_IMAGE_FORMAT_INDEXED_ALPHA 6 -#define GODOT_IMAGE_FORMAT_YUV_422 7 -#define GODOT_IMAGE_FORMAT_YUV_444 8 -#define GODOT_IMAGE_FORMAT_BC1 9 -#define GODOT_IMAGE_FORMAT_BC2 10 -#define GODOT_IMAGE_FORMAT_BC3 11 -#define GODOT_IMAGE_FORMAT_BC4 12 -#define GODOT_IMAGE_FORMAT_BC5 13 -#define GODOT_IMAGE_FORMAT_PVRTC2 14 -#define GODOT_IMAGE_FORMAT_PVRTC2_ALPHA 15 -#define GODOT_IMAGE_FORMAT_PVRTC4 16 -#define GODOT_IMAGE_FORMAT_PVRTC4_ALPHA 17 -#define GODOT_IMAGE_FORMAT_ETC 18 -#define GODOT_IMAGE_FORMAT_ATC 19 -#define GODOT_IMAGE_FORMAT_ATC_ALPHA_EXPLICIT 20 -#define GODOT_IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED 21 - -typedef void *godot_image; - -godot_image GDAPI godot_image_create_empty(); -godot_image GDAPI godot_image_create(int p_width, int p_height, int p_format, int p_use_mipmaps); -godot_image GDAPI godot_image_create_with_data(int p_width, int p_height, int p_format, int p_use_mipmaps, unsigned char *p_buffer); -int GDAPI godot_image_get_width(godot_image p_image); -int GDAPI godot_image_get_height(godot_image p_image); -int GDAPI godot_image_get_format(godot_image p_image); -int GDAPI godot_image_get_mipmap_count(godot_image p_image); -godot_image GDAPI godot_image_copy(godot_image p_image); -void GDAPI godot_image_free(godot_image p_image); - -////// RID - -typedef void *godot_rid; - -godot_rid GDAPI godot_rid_create(); -godot_rid GDAPI godot_rid_copy(godot_rid p_rid); -void GDAPI godot_rid_free(godot_rid p_rid); - -////// Variant (forward declared) - -typedef void *godot_variant; - -////// Dictionary - -typedef void *godot_dictionary; - -godot_dictionary GDAPI godot_dictionary_create(); -void GDAPI godot_dictionary_has(godot_dictionary p_dictionary, godot_variant p_key); -godot_variant GDAPI godot_dictionary_get(godot_dictionary p_dictionary, godot_variant p_key); -void GDAPI godot_dictionary_insert(godot_dictionary p_dictionary, godot_variant p_key, godot_variant p_value); -void GDAPI godot_dictionary_remove(godot_dictionary p_dictionary, godot_variant p_key); -void GDAPI godot_dictionary_clear(godot_dictionary p_dictionary); -int GDAPI godot_dictionary_get_size(godot_dictionary p_dictionary); -void GDAPI godot_dictionary_get_keys(godot_dictionary p_dictionary, godot_variant *p_keys); -godot_dictionary GDAPI godot_dictionary_copy(godot_dictionary p_dictionary); -void GDAPI godot_dictionary_free(godot_dictionary p_dictionary); - -////// Array - -typedef void *godot_array; - -godot_array GDAPI godot_array_create(); -godot_variant GDAPI godot_array_get(godot_array p_array, int p_index); -void GDAPI godot_array_set(godot_array p_array, int p_index, godot_variant p_value); -void GDAPI godot_array_resize(godot_array p_array, int p_size); -void GDAPI godot_array_insert(godot_array p_array, int p_position, godot_variant p_value); -void GDAPI godot_array_remove(godot_array p_array, int p_position); -void GDAPI godot_array_clear(godot_array p_array); -int GDAPI godot_array_get_size(godot_array p_array); -int GDAPI godot_array_find(godot_array p_array, godot_variant p_value, int p_from_pos = -1); -godot_array GDAPI godot_array_copy(godot_array p_array); -void GDAPI godot_array_free(godot_array p_array); - -////// InputEvent - -#define INPUT_EVENT_BUTTON_LEFT 1 -#define INPUT_EVENT_BUTTON_RIGHT 2 -#define INPUT_EVENT_BUTTON_MIDDLE 3 -#define INPUT_EVENT_BUTTON_WHEEL_UP 4 -#define INPUT_EVENT_BUTTON_WHEEL_DOWN 5 -#define INPUT_EVENT_BUTTON_WHEEL_LEFT 6 -#define INPUT_EVENT_BUTTON_WHEEL_RIGHT 7 -#define INPUT_EVENT_BUTTON_MASK_LEFT (1 << (INPUT_EVENT_BUTTON_LEFT - 1)) -#define INPUT_EVENT_BUTTON_MASK_RIGHT (1 << (INPUT_EVENT_BUTTON_RIGHT - 1)) -#define INPUT_EVENT_BUTTON_MASK_MIDDLE (1 << (INPUT_EVENT_BUTTON_MIDDLE - 1)) - -#define INPUT_EVENT_TYPE_NONE 0 -#define INPUT_EVENT_TYPE_KEY 1 -#define INPUT_EVENT_TYPE_MOUSE_MOTION 2 -#define INPUT_EVENT_TYPE_MOUSE_BUTTON 3 -#define INPUT_EVENT_TYPE_JOYPAD_MOTION 4 -#define INPUT_EVENT_TYPE_JOYPAD_BUTTON 5 -#define INPUT_EVENT_TYPE_SCREEN_TOUCH 6 -#define INPUT_EVENT_TYPE_SCREEN_DRAG 7 -#define INPUT_EVENT_TYPE_ACTION 8 - -typedef void *godot_input_event; - -godot_input_event GDAPI godot_input_event_create(); -godot_input_event GDAPI godot_input_event_copy(godot_input_event p_input_event); -void GDAPI godot_input_event_free(godot_input_event p_input_event); - -int GDAPI godot_input_event_get_type(godot_input_event p_event); -int GDAPI godot_input_event_get_device(godot_input_event p_event); - -godot_bool GDAPI godot_input_event_mod_has_alt(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_ctrl(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_command(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_shift(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_meta(godot_input_event p_event); - -int GDAPI godot_input_event_key_get_scancode(godot_input_event p_event); -int GDAPI godot_input_event_key_get_unicode(godot_input_event p_event); -godot_bool GDAPI godot_input_event_key_is_pressed(godot_input_event p_event); -godot_bool GDAPI godot_input_event_key_is_echo(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_get_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_y(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_global_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_global_y(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_button_mask(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_button_get_button_index(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mouse_button_is_pressed(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mouse_button_is_doubleclick(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_motion_get_relative_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_motion_get_relative_y(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_motion_get_speed_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_motion_get_speed_y(godot_input_event p_event); - -int GDAPI godot_input_event_joypad_motion_get_axis(godot_input_event p_event); -float GDAPI godot_input_event_joypad_motion_get_axis_value(godot_input_event p_event); - -int GDAPI godot_input_event_joypad_button_get_button_index(godot_input_event p_event); -godot_bool GDAPI godot_input_event_joypad_button_is_pressed(godot_input_event p_event); -float GDAPI godot_input_event_joypad_button_get_pressure(godot_input_event p_event); - -int GDAPI godot_input_event_screen_touch_get_index(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_get_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_get_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_is_pressed(godot_input_event p_event); - -int GDAPI godot_input_event_screen_drag_get_index(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_relative_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_relative_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_speed_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_speed_y(godot_input_event p_event); - -int GDAPI godot_input_event_is_action(godot_input_event p_event, char *p_action); -int GDAPI godot_input_event_is_action_pressed(godot_input_event p_event, char *p_action); - -////// ByteArray - -typedef void *godot_byte_array; - -godot_byte_array GDAPI godot_byte_array_create(); -godot_byte_array GDAPI godot_byte_array_copy(godot_byte_array p_byte_array); -void GDAPI godot_byte_array_free(godot_byte_array p_byte_array); - -int GDAPI godot_byte_array_get_size(godot_byte_array p_byte_array); -unsigned char GDAPI godot_byte_array_get(godot_byte_array p_byte_array, int p_index); -void GDAPI godot_byte_array_set(godot_byte_array p_byte_array, int p_index, unsigned char p_value); -void GDAPI godot_byte_array_remove(godot_byte_array p_byte_array, int p_index); -void GDAPI godot_byte_array_clear(godot_byte_array p_byte_array); - -typedef void *godot_byte_array_lock; - -godot_byte_array_lock GDAPI godot_byte_array_get_lock(godot_byte_array p_byte_array); -unsigned char GDAPI *godot_byte_array_lock_get_pointer(godot_byte_array_lock p_byte_array_lock); -void GDAPI godot_byte_array_lock_free(godot_byte_array_lock p_byte_array_lock); - -godot_image GDAPI godot_image_create_with_array(int p_width, int p_height, int p_format, int p_use_mipmaps, godot_array p_array); -godot_byte_array GDAPI godot_image_get_data(godot_image p_image); - -////// IntArray - -typedef void *godot_int_array; - -godot_int_array GDAPI godot_int_array_create(); -godot_int_array GDAPI godot_int_array_copy(godot_int_array p_int_array); -void GDAPI godot_int_array_free(godot_int_array p_int_array); - -int GDAPI godot_int_array_get_size(godot_int_array p_int_array); -int GDAPI godot_int_array_get(godot_int_array p_int_array, int p_index); -void GDAPI godot_int_array_set(godot_int_array p_int_array, int p_index, int p_value); -void GDAPI godot_int_array_remove(godot_int_array p_int_array, int p_index); -void GDAPI godot_int_array_clear(godot_int_array p_int_array); - -typedef void *godot_int_array_lock; - -godot_int_array_lock GDAPI godot_int_array_get_lock(godot_int_array p_int_array); -int GDAPI *godot_int_array_lock_get_pointer(godot_int_array_lock p_int_array_lock); -void GDAPI godot_int_array_lock_free(godot_int_array_lock p_int_array_lock); - -////// RealArray - -typedef void *godot_real_array; - -godot_real_array GDAPI godot_real_array_create(); -godot_real_array GDAPI godot_real_array_copy(godot_real_array p_real_array); -void GDAPI godot_real_array_free(godot_real_array p_real_array); - -int GDAPI godot_real_array_get_size(godot_real_array p_real_array); -float GDAPI godot_real_array_get(godot_real_array p_real_array, int p_index); -void GDAPI godot_real_array_set(godot_real_array p_real_array, int p_index, float p_value); -void GDAPI godot_real_array_remove(godot_real_array p_real_array, int p_index); -void GDAPI godot_real_array_clear(godot_real_array p_real_array); - -typedef void *godot_real_array_lock; - -godot_real_array_lock GDAPI godot_real_array_get_lock(godot_real_array p_real_array); -float GDAPI *godot_real_array_lock_get_pointer(godot_real_array_lock p_real_array_lock); -void GDAPI godot_real_array_lock_free(godot_real_array_lock p_real_array_lock); - -////// StringArray - -typedef void *godot_string_array; - -godot_string_array GDAPI godot_string_array_create(); -godot_string_array GDAPI godot_string_array_copy(godot_string_array p_string_array); -void GDAPI godot_string_array_free(godot_string_array p_string_array); - -int GDAPI godot_string_array_get_size(godot_string_array p_string_array); -int GDAPI godot_string_array_get(godot_string_array p_string_array, int p_index, unsigned char *p_string, int p_max_len); -void GDAPI godot_string_array_set(godot_string_array p_string_array, int p_index, unsigned char *p_string); -void GDAPI godot_string_array_remove(godot_string_array p_string_array, int p_index); -void GDAPI godot_string_array_clear(godot_string_array p_string_array); - -////// Vector2Array - -typedef void *godot_vector2_array; - -godot_vector2_array GDAPI godot_vector2_array_create(); -godot_vector2_array GDAPI godot_vector2_array_copy(godot_vector2_array p_vector2_array); -void GDAPI godot_vector2_array_free(godot_vector2_array p_vector2_array); - -int GDAPI godot_vector2_array_get_size(godot_vector2_array p_vector2_array); -int GDAPI godot_vector2_array_get_stride(godot_vector2_array p_vector2_array); -void GDAPI godot_vector2_array_get(godot_vector2_array p_vector2_array, int p_index, float *p_vector2); -void GDAPI godot_vector2_array_set(godot_vector2_array p_vector2_array, int p_index, float *p_vector2); -void GDAPI godot_vector2_array_remove(godot_vector2_array p_vector2_array, int p_index); -void GDAPI godot_vector2_array_clear(godot_vector2_array p_vector2_array); - -typedef void *godot_vector2_array_lock; - -godot_vector2_array_lock GDAPI godot_vector2_array_get_lock(godot_vector2_array p_vector2_array); -float GDAPI *godot_vector2_array_lock_get_pointer(godot_vector2_array_lock p_vector2_array_lock); -void GDAPI godot_vector2_array_lock_free(godot_vector2_array_lock p_vector2_array_lock); - -////// Vector3Array - -typedef void *godot_vector3_array; - -godot_vector3_array GDAPI godot_vector3_array_create(); -godot_vector3_array GDAPI godot_vector3_array_copy(godot_vector3_array p_vector3_array); -void GDAPI godot_vector3_array_free(godot_vector3_array p_vector3_array); - -int GDAPI godot_vector3_array_get_size(godot_vector3_array p_vector3_array); -int GDAPI godot_vector3_array_get_stride(godot_vector3_array p_vector3_array); -void GDAPI godot_vector3_array_get(godot_vector3_array p_vector3_array, int p_index, float *p_vector3); -void GDAPI godot_vector3_array_set(godot_vector3_array p_vector3_array, int p_index, float *p_vector3); -void GDAPI godot_vector3_array_remove(godot_vector3_array p_vector3_array, int p_index); -void GDAPI godot_vector3_array_clear(godot_vector3_array p_vector3_array); - -typedef void *godot_vector3_array_lock; - -godot_vector3_array_lock GDAPI godot_vector3_array_get_lock(godot_vector3_array p_vector3_array); -float GDAPI *godot_vector3_array_lock_get_pointer(godot_vector3_array_lock p_vector3_array_lock); -void GDAPI godot_vector3_array_lock_free(godot_vector3_array_lock p_vector3_array_lock); - -////// ColorArray - -typedef void *godot_color_array; - -godot_color_array GDAPI godot_color_array_create(); -godot_color_array GDAPI godot_color_array_copy(godot_color_array p_color_array); -void GDAPI godot_color_array_free(godot_color_array p_color_array); - -int GDAPI godot_color_array_get_size(godot_color_array p_color_array); -int GDAPI godot_color_array_get_stride(godot_color_array p_color_array); -void GDAPI godot_color_array_get(godot_color_array p_color_array, int p_index, float *p_color); -void GDAPI godot_color_array_set(godot_color_array p_color_array, int p_index, float *p_color); -void GDAPI godot_color_array_remove(godot_color_array p_color_array, int p_index); -void GDAPI godot_color_array_clear(godot_color_array p_color_array); - -typedef void *godot_color_array_lock; - -godot_color_array_lock GDAPI godot_color_array_get_lock(godot_color_array p_color_array); -float GDAPI *godot_color_array_lock_get_pointer(godot_color_array_lock p_color_array_lock); -void GDAPI godot_color_array_lock_free(godot_color_array_lock p_color_array_lock); - -////// Instance (forward declared) - -typedef void *godot_instance; - -////// Variant - -#define GODOT_VARIANT_NIL 0 -#define GODOT_VARIANT_BOOL 1 -#define GODOT_VARIANT_INT 2 -#define GODOT_VARIANT_REAL 3 -#define GODOT_VARIANT_STRING 4 -#define GODOT_VARIANT_VECTOR2 5 -#define GODOT_VARIANT_RECT2 6 -#define GODOT_VARIANT_VECTOR3 7 -#define GODOT_VARIANT_MATRIX32 8 -#define GODOT_VARIANT_PLANE 9 -#define GODOT_VARIANT_QUAT 10 -#define GODOT_VARIANT_AABB 11 -#define GODOT_VARIANT_MATRIX3 12 -#define GODOT_VARIANT_TRANSFORM 13 -#define GODOT_VARIANT_COLOR 14 -#define GODOT_VARIANT_IMAGE 15 -#define GODOT_VARIANT_NODE_PATH 16 -#define GODOT_VARIANT_RID 17 -#define GODOT_VARIANT_OBJECT 18 -#define GODOT_VARIANT_INPUT_EVENT 19 -#define GODOT_VARIANT_DICTIONARY 20 -#define GODOT_VARIANT_ARRAY 21 -#define GODOT_VARIANT_BYTE_ARRAY 22 -#define GODOT_VARIANT_INT_ARRAY 23 -#define GODOT_VARIANT_REAL_ARRAY 24 -#define GODOT_VARIANT_STRING_ARRAY 25 -#define GODOT_VARIANT_VECTOR2_ARRAY 26 -#define GODOT_VARIANT_VECTOR3_ARRAY 27 -#define GODOT_VARIANT_COLOR_ARRAY 28 -#define GODOT_VARIANT_MAX 29 - -godot_variant *godot_variant_new(); - -int GDAPI godot_variant_get_type(godot_variant p_variant); - -void GDAPI godot_variant_set_null(godot_variant p_variant); -void GDAPI godot_variant_set_bool(godot_variant p_variant, godot_bool p_bool); -void GDAPI godot_variant_set_int(godot_variant p_variant, int p_int); -void GDAPI godot_variant_set_float(godot_variant p_variant, int p_float); -void GDAPI godot_variant_set_string(godot_variant p_variant, char *p_string); -void GDAPI godot_variant_set_vector2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_rect2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_vector3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_matrix32(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_plane(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_aabb(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_matrix3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_transform(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_color(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_image(godot_variant p_variant, godot_image *p_image); -void GDAPI godot_variant_set_node_path(godot_variant p_variant, char *p_path); -void GDAPI godot_variant_set_rid(godot_variant p_variant, char *p_path); -void GDAPI godot_variant_set_instance(godot_variant p_variant, godot_instance p_instance); -void GDAPI godot_variant_set_input_event(godot_variant p_variant, godot_input_event p_instance); -void GDAPI godot_variant_set_dictionary(godot_variant p_variant, godot_dictionary p_dictionary); -void GDAPI godot_variant_set_array(godot_variant p_variant, godot_array p_array); -void GDAPI godot_variant_set_byte_array(godot_variant p_variant, godot_byte_array p_array); -void GDAPI godot_variant_set_int_array(godot_variant p_variant, godot_byte_array p_array); -void GDAPI godot_variant_set_string_array(godot_variant p_variant, godot_string_array p_array); -void GDAPI godot_variant_set_vector2_array(godot_variant p_variant, godot_vector2_array p_array); -void GDAPI godot_variant_set_vector3_array(godot_variant p_variant, godot_vector3_array p_array); -void GDAPI godot_variant_set_color_array(godot_variant p_variant, godot_color_array p_array); - -godot_bool GDAPI godot_variant_get_bool(godot_variant p_variant); -int GDAPI godot_variant_get_int(godot_variant p_variant); -float GDAPI godot_variant_get_float(godot_variant p_variant); -int GDAPI godot_variant_get_string(godot_variant p_variant, char *p_string, int p_bufsize); -void GDAPI godot_variant_get_vector2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_rect2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_vector3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_matrix32(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_plane(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_aabb(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_matrix3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_transform(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_color(godot_variant p_variant, float *p_elems); -godot_image GDAPI *godot_variant_get_image(godot_variant p_variant); -int GDAPI godot_variant_get_node_path(godot_variant p_variant, char *p_path, int p_bufsize); -godot_rid GDAPI godot_variant_get_rid(godot_variant p_variant); -godot_instance GDAPI godot_variant_get_instance(godot_variant p_variant); -void GDAPI godot_variant_get_input_event(godot_variant p_variant, godot_input_event); -void GDAPI godot_variant_get_dictionary(godot_variant p_variant, godot_dictionary); -godot_array GDAPI godot_variant_get_array(godot_variant p_variant); -godot_byte_array GDAPI godot_variant_get_byte_array(godot_variant p_variant); -godot_byte_array GDAPI godot_variant_get_int_array(godot_variant p_variant); -godot_string_array GDAPI godot_variant_get_string_array(godot_variant p_variant); -godot_vector2_array GDAPI godot_variant_get_vector2_array(godot_variant p_variant); -godot_vector3_array GDAPI godot_variant_get_vector3_array(godot_variant p_variant); -godot_color_array GDAPI godot_variant_get_color_array(godot_variant p_variant); - -void GDAPI godot_variant_delete(godot_variant p_variant); - -////// Class -/// - -char GDAPI **godot_class_get_list(); //get list of classes in array to array of strings, must be freed, use godot_list_free() - -int GDAPI godot_class_get_base(char *p_class, char *p_base, int p_max_len); -int GDAPI godot_class_get_name(char *p_class, char *p_base, int p_max_len); - -char GDAPI **godot_class_get_method_list(char *p_class); //free with godot_list_free() -int GDAPI godot_class_method_get_argument_count(char *p_class, char *p_method); -int GDAPI godot_class_method_get_argument_type(char *p_class, char *p_method, int p_argument); -godot_variant GDAPI godot_class_method_get_argument_default_value(char *p_class, char *p_method, int p_argument); - -char GDAPI **godot_class_get_constant_list(char *p_class); //free with godot_list_free() -int GDAPI godot_class_constant_get_value(char *p_class, char *p_constant); - -////// Instance - -typedef int godot_call_error; - -#define GODOT_CALL_OK -#define GODOT_CALL_ERROR_WRONG_ARGUMENTS -#define GODOT_CALL_ERROR_INVALID_INSTANCE - -godot_instance GDAPI godot_instance_new(char *p_class); -int GDAPI godot_instance_get_class(godot_instance p_instance, char *p_class, int p_max_len); - -typedef struct { - char *name; - int hint; - char *hint_string; - int usage; -} godot_property_info; - -godot_call_error GDAPI godot_instance_call(godot_instance p_instance, char *p_method, ...); -godot_call_error GDAPI godot_instance_call_ret(godot_instance p_instance, godot_variant r_return, char *p_method, ...); -godot_bool GDAPI godot_instance_set(godot_instance p_instance, char *p_prop, godot_variant p_value); -godot_variant GDAPI godot_instance_get(godot_instance p_instance, char *p_prop); - -#define GODOT_PROPERTY_HINT_NONE 0 ///< no hint provided. -#define GODOT_PROPERTY_HINT_RANGE 1 ///< hint_text = "min,max,step,slider; //slider is optional" -#define GODOT_PROPERTY_HINT_EXP_RANGE 2 ///< hint_text = "min,max,step", exponential edit -#define GODOT_PROPERTY_HINT_ENUM 3 ///< hint_text= "val1,val2,val3,etc" -#define GODOT_PROPERTY_HINT_EXP_EASING 4 /// exponential easing funciton (Math::ease) -#define GODOT_PROPERTY_HINT_LENGTH 5 ///< hint_text= "length" (as integer) -#define GODOT_PROPERTY_HINT_SPRITE_FRAME 6 -#define GODOT_PROPERTY_HINT_KEY_ACCEL 7 ///< hint_text= "length" (as integer) -#define GODOT_PROPERTY_HINT_FLAGS 8 ///< hint_text= "flag1,flag2,etc" (as bit flags) -#define GODOT_PROPERTY_HINT_ALL_FLAGS 9 -#define GODOT_PROPERTY_HINT_FILE 10 ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," -#define GODOT_PROPERTY_HINT_DIR 11 ///< a directort path must be passed -#define GODOT_PROPERTY_HINT_GLOBAL_FILE 12 ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," -#define GODOT_PROPERTY_HINT_GLOBAL_DIR 13 ///< a directort path must be passed -#define GODOT_PROPERTY_HINT_RESOURCE_TYPE 14 ///< a resource object type -#define GODOT_PROPERTY_HINT_MULTILINE_TEXT 15 ///< used for string properties that can contain multiple lines -#define GODOT_PROPERTY_HINT_COLOR_NO_ALPHA 16 ///< used for ignoring alpha component when editing a color -#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY 17 -#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS 18 -#define GODOT_PROPERTY_HINT_OBJECT_ID 19 - -#define GODOT_PROPERTY_USAGE_STORAGE 1 -#define GODOT_PROPERTY_USAGE_EDITOR 2 -#define GODOT_PROPERTY_USAGE_NETWORK 4 -#define GODOT_PROPERTY_USAGE_EDITOR_HELPER 8 -#define GODOT_PROPERTY_USAGE_CHECKABLE 16 //used for editing global variables -#define GODOT_PROPERTY_USAGE_CHECKED 32 //used for editing global variables -#define GODOT_PROPERTY_USAGE_INTERNATIONALIZED 64 //hint for internationalized strings -#define GODOT_PROPERTY_USAGE_BUNDLE 128 //used for optimized bundles -#define GODOT_PROPERTY_USAGE_CATEGORY 256 -#define GODOT_PROPERTY_USAGE_STORE_IF_NONZERO 512 //only store if nonzero -#define GODOT_PROPERTY_USAGE_STORE_IF_NONONE 1024 //only store if false -#define GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE 2048 -#define GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED 4096 -#define GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE 8192 -#define GODOT_PROPERTY_USAGE_STORE_IF_NULL 16384 -#define GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER 32768 - -#define GODOT_PROPERTY_USAGE_DEFAULT GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK -#define GODOT_PROPERTY_USAGE_DEFAULT_INTL GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED -#define GODOT_PROPERTY_USAGE_NOEDITOR GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK - -godot_property_info GDAPI **godot_instance_get_property_list(godot_instance p_instance); -void GDAPI godot_instance_free_property_list(godot_instance p_instance, godot_property_info **p_list); - -void GDAPI godot_list_free(char **p_name); //helper to free all the class list - -////// Script API - -typedef void *(godot_script_instance_func)(godot_instance); //passed an instance, return a pointer to your userdata -typedef void(godot_script_free_func)(godot_instance, void *); //passed an instance, please free your userdata - -void GDAPI godot_script_register(char *p_base, char *p_name, godot_script_instance_func p_instance_func, godot_script_free_func p_free_func); -void GDAPI godot_script_unregister(char *p_name); - -typedef GDAPI godot_variant(godot_script_func)(godot_instance, void *, godot_variant *, int); //instance,userdata,arguments,argument count. Return something or NULL. Arguments must not be freed. - -void GDAPI godot_script_add_function(char *p_name, char *p_function_name, godot_script_func p_func); -void GDAPI godot_script_add_validated_function(char *p_name, char *p_function_name, godot_script_func p_func, int *p_arg_types, int p_arg_count, godot_variant *p_default_args, int p_default_arg_count); - -typedef void(godot_set_property_func)(godot_instance, void *, godot_variant); //instance,userdata,value. Value must not be freed. -typedef godot_variant(godot_get_property_func)(godot_instance, void *); //instance,userdata. Return a value or NULL. - -void GDAPI godot_script_add_property(char *p_name, char *p_path, godot_set_property_func p_set_func, godot_get_property_func p_get_func); -void GDAPI godot_script_add_listed_property(char *p_name, char *p_path, godot_set_property_func p_set_func, godot_get_property_func p_get_func, int p_type, int p_hint, char *p_hint_string, int p_usage); - -////// System Functions - -//using these will help Godot track how much memory is in use in debug mode -void GDAPI *godot_alloc(int p_bytes); -void GDAPI *godot_realloc(void *p_ptr, int p_bytes); -void GDAPI godot_free(void *p_ptr); - -#ifdef __cplusplus -} -#endif - -#endif // GODOT_C_H diff --git a/modules/dds/register_types.cpp b/modules/dds/register_types.cpp index d0eaf3f995..4a758fe033 100644 --- a/modules/dds/register_types.cpp +++ b/modules/dds/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/dds/register_types.h b/modules/dds/register_types.h index 69f47006e2..4807c7dd5b 100644 --- a/modules/dds/register_types.h +++ b/modules/dds/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 9c976179fa..d79b7685d1 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -143,12 +144,14 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, f->get_32(); f->get_32(); - /*print_line("DDS width: "+itos(width)); + /* + print_line("DDS width: "+itos(width)); print_line("DDS height: "+itos(height)); - print_line("DDS mipmaps: "+itos(mipmaps));*/ + print_line("DDS mipmaps: "+itos(mipmaps)); - //printf("fourcc: %x fflags: %x, rgbbits: %x, fsize: %x\n",format_fourcc,format_flags,format_rgb_bits,format_size); - //printf("rmask: %x gmask: %x, bmask: %x, amask: %x\n",format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask); + printf("fourcc: %x fflags: %x, rgbbits: %x, fsize: %x\n",format_fourcc,format_flags,format_rgb_bits,format_size); + printf("rmask: %x gmask: %x, bmask: %x, amask: %x\n",format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask); + */ //must avoid this later while (f->get_pos() < 128) @@ -253,13 +256,13 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, uint32_t size = pitch * height; ERR_FAIL_COND_V(size != width * height * info.block_size, RES()); - uint8_t pallete[256 * 4]; - f->get_buffer(pallete, 256 * 4); + uint8_t palette[256 * 4]; + f->get_buffer(palette, 256 * 4); int colsize = 3; for (int i = 0; i < 256; i++) { - if (pallete[i * 4 + 3] < 255) + if (palette[i * 4 + 3] < 255) colsize = 4; } @@ -281,11 +284,11 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, int dst_ofs = size + i * colsize; int src_ofs = i * 4; - wb[dst_ofs + 0] = pallete[src_ofs + 2]; - wb[dst_ofs + 1] = pallete[src_ofs + 1]; - wb[dst_ofs + 2] = pallete[src_ofs + 0]; + wb[dst_ofs + 0] = palette[src_ofs + 2]; + wb[dst_ofs + 1] = palette[src_ofs + 1]; + wb[dst_ofs + 2] = palette[src_ofs + 0]; if (colsize == 4) - wb[dst_ofs + 3] = pallete[src_ofs + 3]; + wb[dst_ofs + 3] = palette[src_ofs + 3]; } wb = PoolVector<uint8_t>::Write(); diff --git a/modules/dds/texture_loader_dds.h b/modules/dds/texture_loader_dds.h index c347937cd5..3b36e7f1eb 100644 --- a/modules/dds/texture_loader_dds.h +++ b/modules/dds/texture_loader_dds.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/enet/SCsub b/modules/enet/SCsub index fb22d1cff0..42a933a66d 100644 --- a/modules/enet/SCsub +++ b/modules/enet/SCsub @@ -10,6 +10,7 @@ env_enet = env_modules.Clone() if (env['builtin_enet'] != 'no'): thirdparty_dir = "#thirdparty/enet/" thirdparty_sources = [ + "godot.cpp", "callbacks.c", "compress.c", "host.c", @@ -17,12 +18,11 @@ if (env['builtin_enet'] != 'no'): "packet.c", "peer.c", "protocol.c", - "unix.c", - "win32.c", ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] env_enet.add_source_files(env.modules_sources, thirdparty_sources) env_enet.Append(CPPPATH=[thirdparty_dir]) + env_enet.Append(CPPFLAGS=["-DGODOT_ENET"]) env_enet.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 2dfb0b4a6a..c05c86d9ae 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -53,8 +54,21 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE); ENetAddress address; - address.host = bind_ip; +#ifdef GODOT_ENET + if (bind_ip.is_wildcard()) { + address.wildcard = 1; + } else { + enet_address_set_ip(&address, bind_ip.get_ipv6(), 16); + } +#else + if (bind_ip.is_wildcard()) { + address.host = 0; + } else { + ERR_FAIL_COND_V(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER); + address.host = *(uint32_t *)bind_ip.get_ipv4(); + } +#endif address.port = p_port; host = enet_host_create(&address /* the address to bind the server host to */, @@ -76,7 +90,6 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE); - ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER); host = enet_host_create(NULL /* create a client host */, 1 /* only allow 1 outgoing connection */, @@ -89,7 +102,12 @@ Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port _setup_compressor(); ENetAddress address; - address.host = *((uint32_t *)p_ip.get_ipv4()); +#ifdef GODOT_ENET + enet_address_set_ip(&address, p_ip.get_ipv6(), 16); +#else + ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER); + address.host = *(uint32_t *)p_ip.get_ipv4(); +#endif address.port = p_port; //enet_address_set_host (& address, "localhost"); @@ -146,9 +164,6 @@ void NetworkedMultiplayerENet::poll() { break; } - IP_Address ip; - ip.set_ipv4((uint8_t *)&(event.peer->address.host)); - int *new_id = memnew(int); *new_id = event.data; @@ -657,7 +672,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { enet_compressor.decompress = enet_decompress; enet_compressor.destroy = enet_compressor_destroy; - bind_ip = ENET_HOST_ANY; + bind_ip = IP_Address("*"); } NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { @@ -668,6 +683,7 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { // sets IP for ENet to bind when using create_server // if no IP is set, then ENet bind to ENET_HOST_ANY void NetworkedMultiplayerENet::set_bind_ip(const IP_Address &p_ip) { - ERR_FAIL_COND(!p_ip.is_ipv4()); - bind_ip = *(uint32_t *)p_ip.get_ipv4(); + ERR_FAIL_COND(!p_ip.is_valid() && !p_ip.is_wildcard()); + + bind_ip = p_ip; } diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index 4b632adcc5..c20c1af68e 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/networked_multiplayer_enet.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -100,7 +101,7 @@ private: static void enet_compressor_destroy(void *context); void _setup_compressor(); - enet_uint32 bind_ip; + IP_Address bind_ip; protected: static void _bind_methods(); diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index 0dea038520..a6e6c87c14 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/enet/register_types.h b/modules/enet/register_types.h index 14cb1ba868..9bcb35a92b 100644 --- a/modules/enet/register_types.h +++ b/modules/enet/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp index 642ec027f3..60544594f6 100644 --- a/modules/etc1/image_etc.cpp +++ b/modules/etc1/image_etc.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/image_etc.h b/modules/etc1/image_etc.h index 18461819d6..69e082bb87 100644 --- a/modules/etc1/image_etc.h +++ b/modules/etc1/image_etc.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/register_types.cpp b/modules/etc1/register_types.cpp index b3b6419d26..859486222f 100644 --- a/modules/etc1/register_types.cpp +++ b/modules/etc1/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/register_types.h b/modules/etc1/register_types.h index fe92496cea..0552b87d65 100644 --- a/modules/etc1/register_types.h +++ b/modules/etc1/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp index bce10e691e..9817de3a0f 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc1/texture_loader_pkm.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc1/texture_loader_pkm.h index 19d15d21fc..8a0f06a51a 100644 --- a/modules/etc1/texture_loader_pkm.h +++ b/modules/etc1/texture_loader_pkm.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 5b1e1c189f..8401c36b54 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -70,7 +70,6 @@ if (env['builtin_freetype'] != 'no'): # LIBS contains first SCons Library objects ("SCons.Node.FS.File object") # and then plain strings for system library. We insert between the two. inserted = False - print(env["LIBS"]) for idx, linklib in enumerate(env["LIBS"]): if isinstance(linklib, basestring): # first system lib such as "X11", otherwise SCons lib object env["LIBS"].insert(idx, lib) diff --git a/modules/freetype/register_types.cpp b/modules/freetype/register_types.cpp index 2579a925d4..3f290c2138 100644 --- a/modules/freetype/register_types.cpp +++ b/modules/freetype/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/freetype/register_types.h b/modules/freetype/register_types.h index 2837898123..c3ba324ed1 100644 --- a/modules/freetype/register_types.h +++ b/modules/freetype/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/freetype/uwpdef.h b/modules/freetype/uwpdef.h index b4aabb1929..c29b14dd12 100644 --- a/modules/freetype/uwpdef.h +++ b/modules/freetype/uwpdef.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub new file mode 100644 index 0000000000..ac13319a1d --- /dev/null +++ b/modules/gdnative/SCsub @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.modules_sources, "*.cpp") +env.add_source_files(env.modules_sources, "godot/*.cpp") + +env.Append(CPPFLAGS=['-DGDAPI_BUILT_IN']) + +if "platform" in env and env["platform"] == "x11": # there has to be a better solution? + env.Append(LINKFLAGS=["-rdynamic"]) +env.use_ptrcall = True + +Export('env') diff --git a/modules/gdnative/api_generator.cpp b/modules/gdnative/api_generator.cpp new file mode 100644 index 0000000000..d5f22ee7a3 --- /dev/null +++ b/modules/gdnative/api_generator.cpp @@ -0,0 +1,442 @@ +/*************************************************************************/ +/* api_generator.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "api_generator.h" + +#ifdef TOOLS_ENABLED + +#include "class_db.h" +#include "core/global_config.h" +#include "core/global_constants.h" +#include "os/file_access.h" + +// helper stuff + +static Error save_file(const String &p_path, const List<String> &p_content) { + + FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE); + + ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE); + + for (const List<String>::Element *e = p_content.front(); e != NULL; e = e->next()) { + file->store_string(e->get()); + } + + file->close(); + + return OK; +} + +// helper stuff end + +struct MethodAPI { + String method_name; + String return_type; + + List<String> argument_types; + List<String> argument_names; + + Map<int, Variant> default_arguments; + + int argument_count; + bool has_varargs; + bool is_editor; + bool is_noscript; + bool is_const; + bool is_reverse; + bool is_virtual; + bool is_from_script; +}; + +struct PropertyAPI { + String name; + String getter; + String setter; + String type; +}; + +struct ConstantAPI { + String constant_name; + int constant_value; +}; + +struct SignalAPI { + String name; + List<String> argument_types; + List<String> argument_names; + Map<int, Variant> default_arguments; +}; + +struct ClassAPI { + String class_name; + String super_class_name; + + ClassDB::APIType api_type; + + bool is_singleton; + bool is_instanciable; + // @Unclear + bool is_creatable; + bool is_reference; + + List<MethodAPI> methods; + List<PropertyAPI> properties; + List<ConstantAPI> constants; + List<SignalAPI> signals_; +}; + +/* + * Reads the entire Godot API to a list + */ +List<ClassAPI> generate_c_api_classes() { + + List<ClassAPI> api; + + List<StringName> classes; + ClassDB::get_class_list(&classes); + + // Register global constants as a fake GlobalConstants singleton class + { + ClassAPI global_constants_api; + global_constants_api.class_name = L"GlobalConstants"; + global_constants_api.api_type = ClassDB::API_CORE; + global_constants_api.is_singleton = true; + global_constants_api.is_instanciable = false; + const int constants_count = GlobalConstants::get_global_constant_count(); + for (int i = 0; i < constants_count; ++i) { + ConstantAPI constant_api; + constant_api.constant_name = GlobalConstants::get_global_constant_name(i); + constant_api.constant_value = GlobalConstants::get_global_constant_value(i); + global_constants_api.constants.push_back(constant_api); + } + api.push_back(global_constants_api); + } + + for (List<StringName>::Element *e = classes.front(); e != NULL; e = e->next()) { + StringName class_name = e->get(); + + ClassAPI class_api; + class_api.api_type = ClassDB::get_api_type(e->get()); + class_api.class_name = class_name; + class_api.super_class_name = ClassDB::get_parent_class(class_name); + { + String name = class_name; + if (name.begins_with("_")) { + name.remove(0); + } + class_api.is_singleton = GlobalConfig::get_singleton()->has_singleton(name); + } + class_api.is_instanciable = !class_api.is_singleton && ClassDB::can_instance(class_name); + + { + bool is_reference = false; + List<StringName> inheriters; + ClassDB::get_inheriters_from_class("Reference", &inheriters); + is_reference = !!inheriters.find(class_name); + // @Unclear + class_api.is_reference = !class_api.is_singleton && is_reference; + } + + // constants + { + List<String> constant; + ClassDB::get_integer_constant_list(class_name, &constant, true); + for (List<String>::Element *c = constant.front(); c != NULL; c = c->next()) { + ConstantAPI constant_api; + constant_api.constant_name = c->get(); + constant_api.constant_value = ClassDB::get_integer_constant(class_name, c->get()); + + class_api.constants.push_back(constant_api); + } + } + + // signals + { + List<MethodInfo> signals_; + ClassDB::get_signal_list(class_name, &signals_, true); + + for (int i = 0; i < signals_.size(); i++) { + SignalAPI signal; + + MethodInfo method_info = signals_[i]; + signal.name = method_info.name; + + for (int j = 0; j < method_info.arguments.size(); j++) { + PropertyInfo argument = method_info.arguments[j]; + String type; + String name = argument.name; + + if (argument.name.find(":") != -1) { + type = argument.name.get_slice(":", 1); + name = argument.name.get_slice(":", 0); + } else if (argument.hint == PROPERTY_HINT_RESOURCE_TYPE) { + type = argument.hint_string; + } else if (argument.type == Variant::NIL) { + type = "Variant"; + } else { + type = Variant::get_type_name(argument.type); + } + + signal.argument_names.push_back(name); + signal.argument_types.push_back(type); + } + + Vector<Variant> default_arguments = method_info.default_arguments; + + int default_start = signal.argument_names.size() - default_arguments.size(); + + for (int j = 0; j < default_arguments.size(); j++) { + signal.default_arguments[default_start + j] = default_arguments[j]; + } + + class_api.signals_.push_back(signal); + } + } + + //properties + { + List<PropertyInfo> properties; + ClassDB::get_property_list(class_name, &properties, true); + + for (List<PropertyInfo>::Element *p = properties.front(); p != NULL; p = p->next()) { + PropertyAPI property_api; + + property_api.name = p->get().name; + property_api.getter = ClassDB::get_property_getter(class_name, p->get().name); + property_api.setter = ClassDB::get_property_setter(class_name, p->get().name); + + if (p->get().name.find(":") != -1) { + property_api.type = p->get().name.get_slice(":", 1); + property_api.name = p->get().name.get_slice(":", 0); + } else if (p->get().hint == PROPERTY_HINT_RESOURCE_TYPE) { + property_api.type = p->get().hint_string; + } else if (p->get().type == Variant::NIL) { + property_api.type = "Variant"; + } else { + property_api.type = Variant::get_type_name(p->get().type); + } + + if (!property_api.setter.empty() || !property_api.getter.empty()) { + class_api.properties.push_back(property_api); + } + } + } + + //methods + { + List<MethodInfo> methods; + ClassDB::get_method_list(class_name, &methods, true); + + for (List<MethodInfo>::Element *m = methods.front(); m != NULL; m = m->next()) { + MethodAPI method_api; + MethodBind *method_bind = ClassDB::get_method(class_name, m->get().name); + MethodInfo &method_info = m->get(); + + //method name + method_api.method_name = m->get().name; + //method return type + if (method_bind && method_bind->get_return_type() != StringName()) { + method_api.return_type = method_bind->get_return_type(); + } else if (method_api.method_name.find(":") != -1) { + method_api.return_type = method_api.method_name.get_slice(":", 1); + method_api.method_name = method_api.method_name.get_slice(":", 0); + } else if (m->get().return_val.type != Variant::NIL) { + method_api.return_type = m->get().return_val.hint == PROPERTY_HINT_RESOURCE_TYPE ? m->get().return_val.hint_string : Variant::get_type_name(m->get().return_val.type); + } else { + method_api.return_type = "void"; + } + + method_api.argument_count = method_info.arguments.size(); + method_api.has_varargs = method_bind && method_bind->is_vararg(); + + // Method flags + if (method_info.flags) { + const uint32_t flags = method_info.flags; + method_api.is_editor = flags & METHOD_FLAG_EDITOR; + method_api.is_noscript = flags & METHOD_FLAG_NOSCRIPT; + method_api.is_const = flags & METHOD_FLAG_CONST; + method_api.is_reverse = flags & METHOD_FLAG_REVERSE; + method_api.is_virtual = flags & METHOD_FLAG_VIRTUAL; + method_api.is_from_script = flags & METHOD_FLAG_FROM_SCRIPT; + } + + method_api.is_virtual = method_api.is_virtual || method_api.method_name[0] == '_'; + + // method argument name and type + + for (int i = 0; i < method_api.argument_count; i++) { + String arg_name; + String arg_type; + PropertyInfo arg_info = method_info.arguments[i]; + + arg_name = arg_info.name; + + if (arg_info.name.find(":") != -1) { + arg_type = arg_info.name.get_slice(":", 1); + arg_name = arg_info.name.get_slice(":", 0); + } else if (arg_info.hint == PROPERTY_HINT_RESOURCE_TYPE) { + arg_type = arg_info.hint_string; + } else if (arg_info.type == Variant::NIL) { + arg_type = "Variant"; + } else { + arg_type = Variant::get_type_name(arg_info.type); + } + + method_api.argument_names.push_back(arg_name); + method_api.argument_types.push_back(arg_type); + + if (method_bind && method_bind->has_default_argument(i)) { + method_api.default_arguments[i] = method_bind->get_default_argument(i); + } + } + + class_api.methods.push_back(method_api); + } + } + + api.push_back(class_api); + } + + return api; +} + +/* + * Generates the JSON source from the API in p_api + */ +static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { + + // I'm sorry for the \t mess + + List<String> source; + + source.push_back("[\n"); + + for (const List<ClassAPI>::Element *c = p_api.front(); c != NULL; c = c->next()) { + ClassAPI api = c->get(); + + source.push_back("\t{\n"); + + source.push_back("\t\t\"name\": \"" + api.class_name + "\",\n"); + source.push_back("\t\t\"base_class\": \"" + api.super_class_name + "\",\n"); + source.push_back(String("\t\t\"api_type\": \"") + (api.api_type == ClassDB::API_CORE ? "core" : (api.api_type == ClassDB::API_EDITOR ? "tools" : "none")) + "\",\n"); + source.push_back(String("\t\t\"singleton\": ") + (api.is_singleton ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\"instanciable\": ") + (api.is_instanciable ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\"is_reference\": ") + (api.is_reference ? "true" : "false") + ",\n"); + // @Unclear + // source.push_back(String("\t\t\"createable\": ") + (api.is_creatable ? "true" : "false") + ",\n"); + + source.push_back("\t\t\"constants\": {\n"); + for (List<ConstantAPI>::Element *e = api.constants.front(); e; e = e->next()) { + source.push_back("\t\t\t\"" + e->get().constant_name + "\": " + String::num_int64(e->get().constant_value) + (e->next() ? "," : "") + "\n"); + } + source.push_back("\t\t},\n"); + + source.push_back("\t\t\"properties\": [\n"); + for (List<PropertyAPI>::Element *e = api.properties.front(); e; e = e->next()) { + source.push_back("\t\t\t{\n"); + source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); + source.push_back("\t\t\t\t\"type\": \"" + e->get().type + "\",\n"); + source.push_back("\t\t\t\t\"getter\": \"" + e->get().getter + "\",\n"); + source.push_back("\t\t\t\t\"setter\": \"" + e->get().setter + "\"\n"); + source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); + } + source.push_back("\t\t],\n"); + + source.push_back("\t\t\"signals\": [\n"); + for (List<SignalAPI>::Element *e = api.signals_.front(); e; e = e->next()) { + source.push_back("\t\t\t{\n"); + source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); + source.push_back("\t\t\t\t\"arguments\": [\n"); + for (int i = 0; i < e->get().argument_names.size(); i++) { + source.push_back("\t\t\t\t\t{\n"); + source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n"); + source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n"); + source.push_back("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\n"); + source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n"); + } + source.push_back("\t\t\t\t]\n"); + source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); + } + source.push_back("\t\t],\n"); + + source.push_back("\t\t\"methods\": [\n"); + for (List<MethodAPI>::Element *e = api.methods.front(); e; e = e->next()) { + source.push_back("\t\t\t{\n"); + source.push_back("\t\t\t\t\"name\": \"" + e->get().method_name + "\",\n"); + source.push_back("\t\t\t\t\"return_type\": \"" + e->get().return_type + "\",\n"); + source.push_back(String("\t\t\t\t\"is_editor\": ") + (e->get().is_editor ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"is_noscript\": ") + (e->get().is_noscript ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"is_const\": ") + (e->get().is_const ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"is_reverse\": ") + (e->get().is_reverse ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"is_virtual\": ") + (e->get().is_virtual ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"has_varargs\": ") + (e->get().has_varargs ? "true" : "false") + ",\n"); + source.push_back(String("\t\t\t\t\"is_from_script\": ") + (e->get().is_from_script ? "true" : "false") + ",\n"); + source.push_back("\t\t\t\t\"arguments\": [\n"); + for (int i = 0; i < e->get().argument_names.size(); i++) { + source.push_back("\t\t\t\t\t{\n"); + source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n"); + source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n"); + source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n"); + source.push_back("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\n"); + source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n"); + } + source.push_back("\t\t\t\t]\n"); + source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); + } + source.push_back("\t\t]\n"); + + source.push_back(String("\t}") + (c->next() ? "," : "") + "\n"); + } + + source.push_back("]"); + + return source; +} + +// + +#endif + +/* + * Saves the whole Godot API to a JSON file located at + * p_path + */ +Error generate_c_api(const String &p_path) { + +#ifndef TOOLS_ENABLED + return ERR_BUG; +#else + + List<ClassAPI> api = generate_c_api_classes(); + + List<String> json_source = generate_c_api_json(api); + + return save_file(p_path, json_source); +#endif +} diff --git a/modules/cscript/godot_c.cpp b/modules/gdnative/api_generator.h index f754f2bb21..a108d7a7b6 100644 --- a/modules/cscript/godot_c.cpp +++ b/modules/gdnative/api_generator.h @@ -1,11 +1,12 @@ /*************************************************************************/ -/* godot_c.cpp */ +/* api_generator.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,4 +27,12 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "godot_c.h" +#ifndef API_GENERATOR_H +#define API_GENERATOR_H + +#include "core/ustring.h" +#include "typedefs.h" + +Error generate_c_api(const String &p_path); + +#endif // API_GENERATOR_H diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py new file mode 100644 index 0000000000..9f57b9bb74 --- /dev/null +++ b/modules/gdnative/config.py @@ -0,0 +1,8 @@ + + +def can_build(platform): + return True + + +def configure(env): + env.use_ptrcall = True diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp new file mode 100644 index 0000000000..09859d95bd --- /dev/null +++ b/modules/gdnative/gdnative.cpp @@ -0,0 +1,1280 @@ +/*************************************************************************/ +/* gdnative.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "gdnative.h" + +#include "global_config.h" +#include "global_constants.h" +#include "io/file_access_encrypted.h" +#include "os/file_access.h" +#include "os/os.h" + +#include "scene/main/scene_main_loop.h" +#include "scene/resources/scene_format_text.h" + +#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) +#include "api_generator.h" +#endif + +#ifdef TOOLS_ENABLED +#include "editor/editor_node.h" +#endif + +Error NativeLibrary::initialize(NativeLibrary *&p_native_lib, const StringName p_path) { + + if (GDNativeScriptLanguage::get_singleton()->initialized_libraries.has(p_path)) { + p_native_lib = GDNativeScriptLanguage::get_singleton()->initialized_libraries[p_path]; + return OK; + } + + NativeLibrary *lib = memnew(NativeLibrary); + lib->path = p_path; + + p_native_lib = lib; + + // Open the file + + Error error; + error = OS::get_singleton()->open_dynamic_library(p_path, lib->handle); + if (error) return error; + ERR_FAIL_COND_V(!lib->handle, ERR_BUG); + + // Get the method + + void *library_init; + error = OS::get_singleton()->get_dynamic_library_symbol_handle(lib->handle, GDNativeScriptLanguage::get_init_symbol_name(), library_init); + if (error) return error; + ERR_FAIL_COND_V(!library_init, ERR_BUG); + + void (*library_init_fpointer)(godot_native_init_options *) = (void (*)(godot_native_init_options *))library_init; + + godot_native_init_options options; + + options.in_editor = SceneTree::get_singleton()->is_editor_hint(); + options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); + options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); + options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + + library_init_fpointer(&options); // Catch errors? + + GDNativeScriptLanguage::get_singleton()->initialized_libraries[p_path] = lib; + + return OK; +} + +Error NativeLibrary::terminate(NativeLibrary *&p_native_lib) { + + if (!GDNativeScriptLanguage::get_singleton()->initialized_libraries.has(p_native_lib->path)) { + OS::get_singleton()->close_dynamic_library(p_native_lib->handle); + p_native_lib->handle = 0; + return OK; + } + + Error error = OK; + void *library_terminate; + error = OS::get_singleton()->get_dynamic_library_symbol_handle(p_native_lib->handle, GDNativeScriptLanguage::get_terminate_symbol_name(), library_terminate); + if (error) + return OK; // no terminate? okay, not that important lol + + void (*library_terminate_pointer)(godot_native_terminate_options *) = (void (*)(godot_native_terminate_options *))library_terminate; + + godot_native_terminate_options options; + options.in_editor = SceneTree::get_singleton()->is_editor_hint(); + + library_terminate_pointer(&options); + + GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path); + + OS::get_singleton()->close_dynamic_library(p_native_lib->handle); + p_native_lib->handle = 0; + + return OK; +} + +// Script +#ifdef TOOLS_ENABLED + +void GDNativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { + ERR_FAIL_COND(!script_data); + + List<PropertyInfo> pinfo; + Map<StringName, Variant> values; + + for (Map<StringName, GDNativeScriptData::Property>::Element *E = script_data->properties.front(); E; E = E->next()) { + PropertyInfo p = E->get().info; + p.name = String(E->key()); + pinfo.push_back(p); + values[p.name] = E->get().default_value; + } + + p_placeholder->update(pinfo, values); +} + +void GDNativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { + + placeholders.erase(p_placeholder); +} + +#endif + +bool GDNativeScript::can_instance() const { +#ifdef TOOLS_ENABLED + return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled()); +#else + // allow defaultlibrary without editor features + if (!library.is_valid()) { + String path = GLOBAL_GET("gdnative/default_gdnativelibrary"); + + RES lib = ResourceLoader::load(path); + + if (lib.is_valid() && lib->cast_to<GDNativeLibrary>()) { + return true; + } + } + + return script_data; +#endif + //return script_data || (!tool && !ScriptServer::is_scripting_enabled()); + // change to true enable in editor stuff. +} + +Ref<Script> GDNativeScript::get_base_script() const { + Ref<GDNativeScript> base_script; + base_script->library = library; + base_script->script_data = script_data; + base_script->script_name = script_data->base; + return base_script; +} + +StringName GDNativeScript::get_instance_base_type() const { + return script_data->base_native_type; +} + +ScriptInstance *GDNativeScript::instance_create(Object *p_this) { + +#ifdef TOOLS_ENABLED + + // find a good way to initialize stuff in the editor + if (!ScriptServer::is_scripting_enabled() && !is_tool()) { + // placeholder, for nodes. But for tools we want the real thing + + PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(GDNativeScriptLanguage::singleton, Ref<Script>((Script *)this), p_this)); + placeholders.insert(sins); + + if (!library.is_valid()) + return sins; + + if (!library->native_library) { + Error err = library->_initialize(); + if (err != OK) { + return sins; + } + } + + if (!script_data) { + script_data = library->get_script_data(script_name); + } + if (script_data && script_data->create_func.create_func) { + script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); + } + + _update_placeholder(sins); + + return sins; + } + +#endif + + if (!library.is_valid()) { + String path = GLOBAL_GET("gdnative/default_gdnativelibrary"); + + RES lib = ResourceLoader::load(path); + + if (lib.is_valid() && lib->cast_to<GDNativeLibrary>()) { + set_library(lib); + } + } + + GDNativeInstance *new_instance = memnew(GDNativeInstance); + + new_instance->owner = p_this; + new_instance->script = Ref<GDNativeScript>(this); + +#ifndef TOOLS_ENABLED + if (!ScriptServer::is_scripting_enabled()) { + new_instance->userdata = 0; + } else { + new_instance->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); + } +#else + new_instance->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); +#endif + + instances.insert(p_this); + return new_instance; +} + +bool GDNativeScript::instance_has(const Object *p_this) const { + return instances.has((Object *)p_this); // TODO +} + +bool GDNativeScript::has_source_code() const { + return false; +} + +String GDNativeScript::get_source_code() const { + return ""; +} + +Error GDNativeScript::reload(bool p_keep_state) { + return FAILED; +} + +bool GDNativeScript::has_method(const StringName &p_method) const { + if (!script_data) + return false; + GDNativeScriptData *data = script_data; + + while (data) { + if (data->methods.has(p_method)) + return true; + + data = data->base_data; + } + + return false; +} + +MethodInfo GDNativeScript::get_method_info(const StringName &p_method) const { + if (!script_data) + return MethodInfo(); + GDNativeScriptData *data = script_data; + + while (data) { + if (data->methods.has(p_method)) + return data->methods[p_method].info; + + data = data->base_data; + } + + ERR_FAIL_COND_V(!script_data->methods.has(p_method), MethodInfo()); + return MethodInfo(); +} + +void GDNativeScript::get_script_method_list(List<MethodInfo> *p_list) const { + if (!script_data) return; + + Set<MethodInfo> methods; + GDNativeScriptData *data = script_data; + + while (data) { + for (Map<StringName, GDNativeScriptData::Method>::Element *E = data->methods.front(); E; E = E->next()) { + methods.insert(E->get().info); + } + data = data->base_data; + } + + for (Set<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { + p_list->push_back(E->get()); + } +} + +void GDNativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { + if (!script_data) return; + + Set<PropertyInfo> properties; + GDNativeScriptData *data = script_data; + + while (data) { + for (Map<StringName, GDNativeScriptData::Property>::Element *E = data->properties.front(); E; E = E->next()) { + properties.insert(E->get().info); + } + data = data->base_data; + } + + for (Set<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + p_list->push_back(E->get()); + } +} + +bool GDNativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { + if (!script_data) return false; + + GDNativeScriptData *data = script_data; + + while (data) { + if (data->properties.has(p_property)) { + r_value = data->properties[p_property].default_value; + return true; + } + + data = data->base_data; + } + + return false; +} + +bool GDNativeScript::is_tool() const { + ERR_FAIL_COND_V(!script_data, false); + return script_data->is_tool; +} + +String GDNativeScript::get_node_type() const { + return ""; // ? +} + +ScriptLanguage *GDNativeScript::get_language() const { + return GDNativeScriptLanguage::singleton; +} + +bool GDNativeScript::has_script_signal(const StringName &p_signal) const { + if (!script_data) + return false; + + GDNativeScriptData *data = script_data; + + while (data) { + if (data->signals_.has(p_signal)) { + return true; + } + + data = data->base_data; + } + + return false; +} + +void GDNativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { + if (!script_data) + return; + + Set<MethodInfo> signals_; + GDNativeScriptData *data = script_data; + + while (data) { + + for (Map<StringName, GDNativeScriptData::Signal>::Element *S = data->signals_.front(); S; S = S->next()) { + signals_.insert(S->get().signal); + } + + data = data->base_data; + } + + for (Set<MethodInfo>::Element *E = signals_.front(); E; E = E->next()) { + r_signals->push_back(E->get()); + } +} + +Variant GDNativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + /* STEP 1, CREATE */ + + if (!library.is_valid() || ((String)script_name).empty() || !script_data) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + } + + r_error.error = Variant::CallError::CALL_OK; + REF ref; + Object *owner = NULL; + + GDNativeScriptData *_baseptr = script_data; + while (_baseptr->base_data) { + _baseptr = _baseptr->base_data; + } + + if (!(_baseptr->base_native_type == "")) { + owner = ClassDB::instance(_baseptr->base_native_type); + } else { + owner = memnew(Reference); //by default, no base means use reference + } + + Reference *r = owner->cast_to<Reference>(); + if (r) { + ref = REF(r); + } + + // GDScript does it like this: _create_instance(p_args, p_argcount, owner, r != NULL, r_error); + // @Todo support varargs for constructors. + GDNativeInstance *instance = (GDNativeInstance *)instance_create(owner); + + owner->set_script_instance(instance); + if (!instance) { + if (ref.is_null()) { + memdelete(owner); //no owner, sorry + } + return Variant(); + } + + if (ref.is_valid()) { + return ref; + } else { + return owner; + } +} + +Ref<GDNativeLibrary> GDNativeScript::get_library() const { + return library; +} + +void GDNativeScript::set_library(Ref<GDNativeLibrary> p_library) { + library = p_library; + +#ifdef TOOLS_ENABLED + if (!ScriptServer::is_scripting_enabled()) + return; +#endif + if (library.is_valid()) { + Error initalize_status = library->_initialize(); + ERR_FAIL_COND(initalize_status != OK); + if (script_name) { + script_data = library->native_library->scripts[script_name]; + ERR_FAIL_COND(!script_data); + } + } +} + +StringName GDNativeScript::get_script_name() const { + return script_name; +} + +void GDNativeScript::set_script_name(StringName p_script_name) { + script_name = p_script_name; + + if (library.is_valid()) { +#ifdef TOOLS_ENABLED + if (!library->native_library) { + library->_initialize(); + } +#endif + if (library->native_library) { + script_data = library->get_script_data(script_name); + ERR_FAIL_COND(!script_data); + } + } +} + +void GDNativeScript::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_library"), &GDNativeScript::get_library); + ClassDB::bind_method(D_METHOD("set_library", "library"), &GDNativeScript::set_library); + ClassDB::bind_method(D_METHOD("get_script_name"), &GDNativeScript::get_script_name); + ClassDB::bind_method(D_METHOD("set_script_name", "script_name"), &GDNativeScript::set_script_name); + + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDNativeScript::_new, MethodInfo(Variant::OBJECT, "new")); + + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); + ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "script_name"), "set_script_name", "get_script_name"); +} + +GDNativeScript::GDNativeScript() { + script_data = NULL; + GDNativeScriptLanguage::get_singleton()->script_list.insert(this); +} + +GDNativeScript::~GDNativeScript() { + //hmm + GDNativeScriptLanguage::get_singleton()->script_list.erase(this); +} + +// Library + +GDNativeLibrary *GDNativeLibrary::currently_initialized_library = NULL; + +GDNativeLibrary *GDNativeLibrary::get_currently_initialized_library() { + return currently_initialized_library; +} + +static const char *_dl_platforms_info[] = { + "|unix|so|Unix", + "unix|x11|so|X11", + "unix|server|so|Server", + "unix|android|so|Android", + "unix|blackberry|so|Blackberry 10", + "unix|haiku|so|Haiku", // Right? + "|mac|dynlib|Mac", + "mac|ios|dynlib|iOS", + "mac|osx|dynlib|OSX", + "|html5|js|HTML5", + "|windows|dll|Windows", + "windows|uwp|dll|UWP", + NULL // Finishing condition +}; + +void GDNativeLibrary::set_platform_file(StringName p_platform, String p_file) { + if (p_file.empty()) { + platform_files.erase(p_platform); + } else { + platform_files[p_platform] = p_file; + } +} + +String GDNativeLibrary::get_platform_file(StringName p_platform) const { + if (platform_files.has(p_platform)) { + return platform_files[p_platform]; + } else { + return ""; + } +} + +Error GDNativeLibrary::_initialize() { + _THREAD_SAFE_METHOD_ + + // Get the file + + const String platform_name = OS::get_singleton()->get_name(); + String platform_file(""); + char **platform_info = (char **)_dl_platforms_info; + + if (platform_files.has(platform_name.to_lower())) { + platform_file = platform_files[platform_name.to_lower()]; + } + + while (*platform_info) { + String platform_info_string(*platform_info); + + if (platform_name == platform_info_string.get_slicec('|', 3)) { + String platform_key = platform_info_string.get_slicec('|', 1); + String fallback_platform_key = platform_info_string.get_slicec('|', 0); + + if (platform_files.has(platform_key)) { + platform_file = platform_files[platform_key]; + } else if (!fallback_platform_key.empty() && platform_files.has(fallback_platform_key)) { + platform_file = platform_files[fallback_platform_key]; + } else { + return ERR_UNAVAILABLE; + } + } + platform_info++; + } + ERR_FAIL_COND_V(platform_file == "", ERR_DOES_NOT_EXIST); + + StringName path = GlobalConfig::get_singleton()->globalize_path(platform_file); + + GDNativeLibrary::currently_initialized_library = this; + + Error ret = NativeLibrary::initialize(native_library, path); + native_library->dllib = this; + + GDNativeLibrary::currently_initialized_library = NULL; + + return ret; +} + +Error GDNativeLibrary::_terminate() { + ERR_FAIL_COND_V(!native_library, ERR_BUG); + ERR_FAIL_COND_V(!native_library->handle, ERR_BUG); + + // de-init stuff + + for (Map<StringName, GDNativeScriptData *>::Element *E = native_library->scripts.front(); E; E = E->next()) { + for (Map<StringName, GDNativeScriptData::Method>::Element *M = E->get()->methods.front(); M; M = M->next()) { + if (M->get().method.free_func) { + M->get().method.free_func(M->get().method.method_data); + } + } + if (E->get()->create_func.free_func) { + E->get()->create_func.free_func(E->get()->create_func.method_data); + } + if (E->get()->destroy_func.free_func) { + E->get()->destroy_func.free_func(E->get()->destroy_func.method_data); + } + + for (Set<GDNativeScript *>::Element *S = GDNativeScriptLanguage::get_singleton()->script_list.front(); S; S = S->next()) { + if (S->get()->script_data == E->get()) { + S->get()->script_data = NULL; + } + } + + memdelete(E->get()); + } + + Error ret = NativeLibrary::terminate(native_library); + + native_library->scripts.clear(); + + return ret; +} + +void GDNativeLibrary::_register_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func) { + ERR_FAIL_COND(!native_library); + ERR_FAIL_COND(native_library->scripts.has(p_name)); + + GDNativeScriptData *s = memnew(GDNativeScriptData); + s->base = p_base; + s->create_func = p_instance_func; + s->destroy_func = p_destroy_func; + Map<StringName, GDNativeScriptData *>::Element *E = native_library->scripts.find(p_base); + if (E) { + s->base_data = E->get(); + s->base_native_type = s->base_data->base_native_type; + } else { + if (!ClassDB::class_exists(p_base)) { + memdelete(s); + ERR_EXPLAIN("Invalid base for registered type '" + p_name + "'"); + ERR_FAIL(); + } + s->base_native_type = p_base; + } + + native_library->scripts.insert(p_name, s); +} + +void GDNativeLibrary::_register_tool_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func) { + ERR_FAIL_COND(!native_library); + ERR_FAIL_COND(native_library->scripts.has(p_name)); + + GDNativeScriptData *s = memnew(GDNativeScriptData); + s->base = p_base; + s->create_func = p_instance_func; + s->destroy_func = p_destroy_func; + s->is_tool = true; + Map<StringName, GDNativeScriptData *>::Element *E = native_library->scripts.find(p_base); + if (E) { + s->base_data = E->get(); + s->base_native_type = s->base_data->base_native_type; + } else { + if (!ClassDB::class_exists(p_base)) { + memdelete(s); + ERR_EXPLAIN("Invalid base for registered type '" + p_name + "'"); + ERR_FAIL(); + } + s->base_native_type = p_base; + } + + native_library->scripts.insert(p_name, s); +} + +void GDNativeLibrary::_register_script_method(const StringName p_name, const StringName p_method, godot_method_attributes p_attr, godot_instance_method p_func, MethodInfo p_info) { + ERR_FAIL_COND(!native_library); + ERR_FAIL_COND(!native_library->scripts.has(p_name)); + + p_info.name = p_method; + GDNativeScriptData::Method method; + + method = GDNativeScriptData::Method(p_func, p_info, p_attr.rpc_type); + + native_library->scripts[p_name]->methods.insert(p_method, method); +} + +void GDNativeLibrary::_register_script_property(const StringName p_name, const String p_path, godot_property_attributes *p_attr, godot_property_set_func p_setter, godot_property_get_func p_getter) { + ERR_FAIL_COND(!native_library); + ERR_FAIL_COND(!native_library->scripts.has(p_name)); + + GDNativeScriptData::Property p; + + PropertyInfo pi; + pi.name = p_path; + + if (p_attr != NULL) { + pi = PropertyInfo((Variant::Type)p_attr->type, p_path, (PropertyHint)p_attr->hint, *(String *)&p_attr->hint_string, p_attr->usage); + + p = GDNativeScriptData::Property(p_setter, p_getter, pi, *(Variant *)&p_attr->default_value, p_attr->rset_type); + } + + native_library->scripts[p_name]->properties.insert(p_path, p); +} + +void GDNativeLibrary::_register_script_signal(const StringName p_name, const godot_signal *p_signal) { + ERR_FAIL_COND(!native_library); + ERR_FAIL_COND(!native_library->scripts.has(p_name)); + ERR_FAIL_COND(!p_signal); + + GDNativeScriptData::Signal signal; + + signal.signal.name = *(String *)&p_signal->name; + + { + List<PropertyInfo> arguments; + for (int i = 0; i < p_signal->num_args; i++) { + PropertyInfo info; + godot_signal_argument attrib = p_signal->args[i]; + + String *name = (String *)&attrib.name; + info.name = *name; + info.type = (Variant::Type)attrib.type; + info.hint = (PropertyHint)attrib.hint; + info.hint_string = *(String *)&attrib.hint_string; + info.usage = attrib.usage; + + arguments.push_back(info); + } + + signal.signal.arguments = arguments; + } + + { + Vector<Variant> default_arguments; + for (int i = 0; i < p_signal->num_default_args; i++) { + Variant *v; + godot_signal_argument attrib = p_signal->args[i]; + + v = (Variant *)&attrib.default_value; + + default_arguments.push_back(*v); + } + + signal.signal.default_arguments = default_arguments; + } + + native_library->scripts[p_name]->signals_.insert(*(String *)&p_signal->name, signal); +} + +GDNativeScriptData *GDNativeLibrary::get_script_data(const StringName p_name) { + ERR_FAIL_COND_V(!native_library, NULL); + + ERR_FAIL_COND_V(!native_library->scripts.has(p_name), NULL); + + return native_library->scripts[p_name]; +} + +bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + if (name.begins_with("platform/")) { + set_platform_file(name.get_slice("/", 1), p_value); + return true; + } + return false; +} + +bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_ret) const { + String name = p_name; + if (name.begins_with("platform/")) { + r_ret = get_platform_file(name.get_slice("/", 1)); + return true; + } + return false; +} + +void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { + char **platform_info = (char **)_dl_platforms_info; + + Set<String> registered_platform_names; + { + List<StringName> ep; + // ep.push_back("X11"); + // EditorImportExport::get_singleton()->get_export_platforms(&ep); + + // @Todo + // get export platforms with the new export system somehow. + for (List<StringName>::Element *E = ep.front(); E; E = E->next()) { + registered_platform_names.insert(String(E->get()).to_lower()); + } + } + + while (*platform_info) { + String platform_info_string(*platform_info); + String fallback_platform_key = platform_info_string.get_slicec('|', 0); + String platform_key = platform_info_string.get_slicec('|', 1); + String platform_extension = platform_info_string.get_slicec('|', 2); + String platform_name = platform_info_string.get_slicec('|', 3); + + registered_platform_names.erase(platform_name); + + if (fallback_platform_key.empty()) { + p_list->push_back(PropertyInfo(Variant::STRING, "platform/" + platform_key, PROPERTY_HINT_FILE, "*." + platform_extension)); + + } else { + if (platform_files.has(platform_key)) { + p_list->push_back(PropertyInfo(Variant::STRING, "platform/" + platform_key, PROPERTY_HINT_FILE, "*." + platform_extension, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED)); + } else { + p_list->push_back(PropertyInfo(Variant::STRING, "platform/" + platform_key, PROPERTY_HINT_FILE, "*." + platform_extension, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CHECKABLE)); + } + } + platform_info++; + } + + while (registered_platform_names.size()) { + const String platform_name = registered_platform_names.front()->get(); + registered_platform_names.erase(platform_name); + p_list->push_back(PropertyInfo(Variant::STRING, "platform/" + platform_name.to_lower(), PROPERTY_HINT_FILE, "*")); + } +} + +void GDNativeLibrary::_notification(int what) { + // TODO +} + +void GDNativeLibrary::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_platform_file", "platform", "file"), &GDNativeLibrary::set_platform_file); + ClassDB::bind_method(D_METHOD("get_platform_file", "platform"), &GDNativeLibrary::get_platform_file); +} + +GDNativeLibrary::GDNativeLibrary() { + native_library = NULL; +} + +GDNativeLibrary::~GDNativeLibrary() { + + if (!native_library) { + return; + } + + if (native_library->handle) { + _terminate(); + } +} + +// Instance + +bool GDNativeInstance::set(const StringName &p_name, const Variant &p_value) { + if (!script->script_data) + return false; + if (script->script_data->properties.has(p_name)) { + script->script_data->properties[p_name].setter.set_func((godot_object *)owner, script->script_data->properties[p_name].setter.method_data, userdata, *(godot_variant *)&p_value); + return true; + } + return false; +} + +bool GDNativeInstance::get(const StringName &p_name, Variant &r_ret) const { + if (!script->script_data) + return false; + if (script->script_data->properties.has(p_name)) { + godot_variant value = script->script_data->properties[p_name].getter.get_func((godot_object *)owner, script->script_data->properties[p_name].getter.method_data, userdata); + r_ret = *(Variant *)&value; + return true; + } + return false; +} + +void GDNativeInstance::get_property_list(List<PropertyInfo> *p_properties) const { + script->get_script_property_list(p_properties); + // TODO: dynamic properties +} + +Variant::Type GDNativeInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { + if (script->script_data->properties.has(p_name)) { + *r_is_valid = true; + return script->script_data->properties[p_name].info.type; + } + *r_is_valid = false; + return Variant::NIL; +} + +void GDNativeInstance::get_method_list(List<MethodInfo> *p_list) const { + script->get_script_method_list(p_list); +} + +bool GDNativeInstance::has_method(const StringName &p_method) const { + return script->has_method(p_method); +} + +Variant GDNativeInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + // TODO: validated methods & errors + + GDNativeScriptData *data_ptr = script->script_data; + while (data_ptr) { + Map<StringName, GDNativeScriptData::Method>::Element *E = data_ptr->methods.find(p_method); + if (E) { + godot_variant result = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); + return *(Variant *)&result; + } + data_ptr = data_ptr->base_data; + } + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); +} + +void GDNativeInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { + // TODO: validated methods & errors + + GDNativeScriptData *data_ptr = script->script_data; + while (data_ptr) { + Map<StringName, GDNativeScriptData::Method>::Element *E = data_ptr->methods.find(p_method); + if (E) { + E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); + } + data_ptr = data_ptr->base_data; + } +} + +void GDNativeInstance::_ml_call_reversed(GDNativeScriptData *data_ptr, const StringName &p_method, const Variant **p_args, int p_argcount) { + // TODO: validated methods & errors + + if (data_ptr->base_data) + _ml_call_reversed(data_ptr->base_data, p_method, p_args, p_argcount); + + // Variant::CallError ce; + + Map<StringName, GDNativeScriptData::Method>::Element *E = data_ptr->methods.find(p_method); + if (E) { + E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); + } +} + +void GDNativeInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { + if (script.ptr() && script->script_data) { + _ml_call_reversed(script->script_data, p_method, p_args, p_argcount); + } +} + +void GDNativeInstance::notification(int p_notification) { + Variant value = p_notification; + const Variant *args[1] = { &value }; + call_multilevel(GDNativeScriptLanguage::singleton->strings._notification, args, 1); +} + +Ref<Script> GDNativeInstance::get_script() const { + return script; +} + +ScriptLanguage *GDNativeInstance::get_language() { + return GDNativeScriptLanguage::singleton; +} + +ScriptInstance::RPCMode GDNativeInstance::get_rpc_mode(const StringName &p_method) const { + GDNativeScriptData::Method m = script->script_data->methods[p_method]; + switch (m.rpc_mode) { + case GODOT_METHOD_RPC_MODE_DISABLED: + return RPC_MODE_DISABLED; + case GODOT_METHOD_RPC_MODE_REMOTE: + return RPC_MODE_REMOTE; + case GODOT_METHOD_RPC_MODE_SYNC: + return RPC_MODE_SYNC; + case GODOT_METHOD_RPC_MODE_MASTER: + return RPC_MODE_MASTER; + case GODOT_METHOD_RPC_MODE_SLAVE: + return RPC_MODE_SLAVE; + default: + return RPC_MODE_DISABLED; + } +} + +ScriptInstance::RPCMode GDNativeInstance::get_rset_mode(const StringName &p_variable) const { + GDNativeScriptData::Property p = script->script_data->properties[p_variable]; + switch (p.rset_mode) { + case GODOT_METHOD_RPC_MODE_DISABLED: + return RPC_MODE_DISABLED; + case GODOT_METHOD_RPC_MODE_REMOTE: + return RPC_MODE_REMOTE; + case GODOT_METHOD_RPC_MODE_SYNC: + return RPC_MODE_SYNC; + case GODOT_METHOD_RPC_MODE_MASTER: + return RPC_MODE_MASTER; + case GODOT_METHOD_RPC_MODE_SLAVE: + return RPC_MODE_SLAVE; + default: + return RPC_MODE_DISABLED; + } +} + +GDNativeInstance::GDNativeInstance() { + owner = NULL; + userdata = NULL; +} + +GDNativeInstance::~GDNativeInstance() { + if (script.is_valid()) { + if (owner) { + script->instances.erase(owner); + } + if (!script->script_data) + return; + script->script_data->destroy_func.destroy_func((godot_object *)owner, script->script_data->destroy_func.method_data, userdata); + if (script->script_data->destroy_func.free_func) + script->script_data->destroy_func.free_func(script->script_data->destroy_func.method_data); + if (script->script_data->create_func.free_func) + script->script_data->create_func.free_func(script->script_data->create_func.method_data); + } +} + +// Language + +GDNativeScriptLanguage *GDNativeScriptLanguage::singleton = NULL; + +String GDNativeScriptLanguage::get_name() const { + return "Native"; +} + +void _add_reload_node() { +#ifdef TOOLS_ENABLED + GDNativeReloadNode *rn = memnew(GDNativeReloadNode); + EditorNode::get_singleton()->add_child(rn); +#endif +} + +void GDNativeScriptLanguage::init() { + // TODO: Expose globals + GLOBAL_DEF("gdnative/default_gdnativelibrary", ""); + PropertyInfo prop_info(Variant::STRING, "gdnative/default_gdnativelibrary", PROPERTY_HINT_FILE, "tres,res,dllib"); + GlobalConfig::get_singleton()->set_custom_property_info("gdnative/default_gdnativelibrary", prop_info); + +// generate bindings +#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) + + List<String> args = OS::get_singleton()->get_cmdline_args(); + + List<String>::Element *E = args.find("--gdnative-generate-json-api"); + + if (E && E->next()) { + if (generate_c_api(E->next()->get()) != OK) { + ERR_PRINT("Failed to generate C API\n"); + } + } +#endif + +#ifdef TOOLS_ENABLED + // if (SceneTree::get_singleton()->is_editor_hint()) { + EditorNode::add_init_callback(&_add_reload_node); +// } +#endif +} + +String GDNativeScriptLanguage::get_type() const { + return "Native"; +} + +String GDNativeScriptLanguage::get_extension() const { + return "gdn"; +} + +Error GDNativeScriptLanguage::execute_file(const String &p_path) { + return OK; // ?? +} + +void GDNativeScriptLanguage::finish() { + // cleanup is for noobs +} + +// scons doesn't want to link in the api source so we need to call a dummy function to cause it to link +extern "C" void _api_anchor(); + +void GDNativeScriptLanguage::_compile_dummy_for_the_api() { + _api_anchor(); +} + +Ref<Script> GDNativeScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { + GDNativeScript *src = memnew(GDNativeScript); + src->set_script_name(p_class_name); + return Ref<GDNativeScript>(src); +} + +bool GDNativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { + return false; // TODO +} + +Script *GDNativeScriptLanguage::create_script() const { + GDNativeScript *scr = memnew(GDNativeScript); + return scr; +} + +bool GDNativeScriptLanguage::has_named_classes() const { + return true; +} + +int GDNativeScriptLanguage::find_function(const String &p_function, const String &p_code) const { + return -1; // No source code! +} + +String GDNativeScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const { + return ""; // No source code! +} + +void GDNativeScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { + // TODO TODO TODO +} + +// TODO: Any debugging? (research) +String GDNativeScriptLanguage::debug_get_error() const { + return ""; +} + +int GDNativeScriptLanguage::debug_get_stack_level_count() const { + return 1; // ? +} + +int GDNativeScriptLanguage::debug_get_stack_level_line(int p_level) const { + return -1; +} + +String GDNativeScriptLanguage::debug_get_stack_level_function(int p_level) const { + return "[native code]"; // ? +} + +String GDNativeScriptLanguage::debug_get_stack_level_source(int p_level) const { + return ""; +} + +void GDNativeScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} + +void GDNativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} + +String GDNativeScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { + return ""; // ?? +} + +void GDNativeScriptLanguage::reload_all_scripts() { + // @Todo +} + +void GDNativeScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { + // @Todo + OS::get_singleton()->print("reload tool scripts\n"); +} + +void GDNativeScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdn"); // Container file format +} + +void GDNativeScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { +} + +void GDNativeScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const { +} + +// TODO: all profilling +void GDNativeScriptLanguage::profiling_start() { +} + +void GDNativeScriptLanguage::profiling_stop() { +} + +int GDNativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +int GDNativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +void GDNativeScriptLanguage::frame() { +} + +String GDNativeScriptLanguage::get_init_symbol_name() { + return "godot_native_init"; // TODO: Maybe make some internal function which would do the actual stuff +} + +String GDNativeScriptLanguage::get_terminate_symbol_name() { + return "godot_native_terminate"; +} + +GDNativeScriptLanguage::GDNativeScriptLanguage() { + ERR_FAIL_COND(singleton); + strings._notification = StringName("_notification"); + singleton = this; + initialized_libraries = Map<StringName, NativeLibrary *>(); +} + +GDNativeScriptLanguage::~GDNativeScriptLanguage() { + singleton = NULL; +} + +// DLReloadNode + +void GDNativeReloadNode::_bind_methods() { + ClassDB::bind_method("_notification", &GDNativeReloadNode::_notification); +} + +void GDNativeReloadNode::_notification(int p_what) { +#ifdef TOOLS_ENABLED + + switch (p_what) { + case MainLoop::NOTIFICATION_WM_FOCUS_IN: { + + Set<NativeLibrary *> libs_to_reload; + + for (Map<StringName, NativeLibrary *>::Element *L = GDNativeScriptLanguage::get_singleton()->initialized_libraries.front(); L; L = L->next()) { + // check if file got modified at all + // @Todo + + libs_to_reload.insert(L->get()); + } + + for (Set<NativeLibrary *>::Element *L = libs_to_reload.front(); L; L = L->next()) { + + GDNativeLibrary *lib = L->get()->dllib; + + lib->_terminate(); + lib->_initialize(); + + // update placeholders (if any) + + Set<GDNativeScript *> scripts; + + for (Set<GDNativeScript *>::Element *S = GDNativeScriptLanguage::get_singleton()->script_list.front(); S; S = S->next()) { + if (lib->native_library->scripts.has(S->get()->get_script_name())) { + GDNativeScript *script = S->get(); + script->script_data = lib->get_script_data(script->get_script_name()); + scripts.insert(script); + } + } + + for (Set<GDNativeScript *>::Element *S = scripts.front(); S; S = S->next()) { + GDNativeScript *script = S->get(); + if (script->placeholders.size() == 0) + continue; + + for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { + PlaceHolderScriptInstance *p = P->get(); + script->_update_placeholder(p); + } + } + } + + } break; + default: { + }; + } +#endif +} + +// Resource loader/saver + +RES ResourceFormatLoaderGDNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error) { + ResourceFormatLoaderText rsflt; + return rsflt.load(p_path, p_original_path, r_error); +} + +void ResourceFormatLoaderGDNativeScript::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdn"); +} +bool ResourceFormatLoaderGDNativeScript::handles_type(const String &p_type) const { + return (p_type == "Script" || p_type == "Native"); +} +String ResourceFormatLoaderGDNativeScript::get_resource_type(const String &p_path) const { + String el = p_path.get_extension().to_lower(); + if (el == "gdn") + return "Native"; + return ""; +} + +Error ResourceFormatSaverGDNativeScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { + ResourceFormatSaverText rfst; + return rfst.save(p_path, p_resource, p_flags); +} + +bool ResourceFormatSaverGDNativeScript::recognize(const RES &p_resource) const { + return p_resource->cast_to<GDNativeScript>() != NULL; +} + +void ResourceFormatSaverGDNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { + if (p_resource->cast_to<GDNativeScript>()) { + p_extensions->push_back("gdn"); + } +} diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h new file mode 100644 index 0000000000..27e0c3788b --- /dev/null +++ b/modules/gdnative/gdnative.h @@ -0,0 +1,417 @@ +/*************************************************************************/ +/* gdnative.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GDNATIVE_H +#define GDNATIVE_H + +#include "io/resource_loader.h" +#include "io/resource_saver.h" +#include "os/thread_safe.h" +#include "resource.h" +#include "scene/main/node.h" +#include "script_language.h" +#include "self_list.h" + +#include "godot.h" + +class GDNativeScriptData; +class GDNativeLibrary; + +struct NativeLibrary { + StringName path; + void *handle; + + GDNativeLibrary *dllib; + + Map<StringName, GDNativeScriptData *> scripts; + + static Error initialize(NativeLibrary *&p_native_lib, const StringName p_path); + static Error terminate(NativeLibrary *&p_native_lib); +}; + +struct GDNativeScriptData { + /* typedef void* (InstanceFunc)(godot_object* instance); + typedef void (DestroyFunc)(godot_object* instance,void* userdata); + typedef godot_variant (MethodFunc)(godot_object *instance, void *userdata, void *method_data, int arg_count,godot_variant **args); + typedef void (MethodDataFreeFunc)(void *method_data); + typedef void (SetterFunc)(godot_object* instance,void* userdata,godot_variant value); + typedef godot_variant (GetterFunc)(godot_object* instance,void* userdata);*/ + + struct Method { + godot_instance_method method; + MethodInfo info; + int rpc_mode; + + Method() { + } + Method(godot_instance_method p_method, MethodInfo p_info, int p_rpc_mode) { + method = p_method; + info = p_info; + rpc_mode = p_rpc_mode; + } + }; + struct Property { + godot_property_set_func setter; + godot_property_get_func getter; + PropertyInfo info; + Variant default_value; + int rset_mode; + + Property() { + } + Property(godot_property_set_func p_setter, godot_property_get_func p_getter) { + setter = p_setter; + getter = p_getter; + } + Property(godot_property_set_func p_setter, godot_property_get_func p_getter, PropertyInfo p_info, Variant p_default_value, int p_rset_mode) { + setter = p_setter; + getter = p_getter; + info = p_info; + default_value = p_default_value; + rset_mode = p_rset_mode; + } + }; + + struct Signal { + MethodInfo signal; + }; + + Map<StringName, Method> methods; + Map<StringName, Property> properties; + Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals + StringName base; + StringName base_native_type; + GDNativeScriptData *base_data; + godot_instance_create_func create_func; + godot_instance_destroy_func destroy_func; + + bool is_tool; + + GDNativeScriptData() { + base = StringName(); + base_data = NULL; + is_tool = false; + } + GDNativeScriptData(StringName p_base, godot_instance_create_func p_instance, godot_instance_destroy_func p_free) { + base = p_base; + base_data = NULL; + create_func = p_instance; + destroy_func = p_free; + is_tool = false; + } +}; + +class GDNativeLibrary; + +class GDNativeScript : public Script { + GDCLASS(GDNativeScript, Script); + + Ref<GDNativeLibrary> library; + StringName script_name; + StringName base_native_type; + Set<Object *> instances; + GDNativeScriptData *script_data; + +#ifdef TOOLS_ENABLED + Set<PlaceHolderScriptInstance *> placeholders; + void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); +#endif + + friend class GDNativeInstance; + friend class GDNativeScriptLanguage; + friend class GDNativeReloadNode; + friend class GDNativeLibrary; + +protected: + static void _bind_methods(); + +public: + virtual bool can_instance() const; + + virtual Ref<Script> get_base_script() const; //for script inheritance + + virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so + virtual ScriptInstance *instance_create(Object *p_this); + virtual bool instance_has(const Object *p_this) const; + + virtual bool has_source_code() const; + virtual String get_source_code() const; + virtual void set_source_code(const String &p_code) {} + virtual Error reload(bool p_keep_state = false); + + virtual bool has_method(const StringName &p_method) const; + virtual MethodInfo get_method_info(const StringName &p_method) const; + + virtual bool is_tool() const; + + virtual String get_node_type() const; + + virtual ScriptLanguage *get_language() const; + + virtual bool has_script_signal(const StringName &p_signal) const; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + + virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; + + virtual void update_exports() {} //editor tool + virtual void get_script_method_list(List<MethodInfo> *p_list) const; + virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + + Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + + Ref<GDNativeLibrary> get_library() const; + void set_library(Ref<GDNativeLibrary> p_library); + + StringName get_script_name() const; + void set_script_name(StringName p_script_name); + + GDNativeScript(); + ~GDNativeScript(); +}; + +class GDNativeLibrary : public Resource { + _THREAD_SAFE_CLASS_ + + GDCLASS(GDNativeLibrary, Resource); + OBJ_SAVE_TYPE(GDNativeLibrary); + + Map<StringName, String> platform_files; + NativeLibrary *native_library; + static GDNativeLibrary *currently_initialized_library; + +protected: + friend class GDNativeScript; + friend class NativeLibrary; + friend class GDNativeReloadNode; + + GDNativeScriptData *get_script_data(const StringName p_name); + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + void _notification(int p_what); + static void _bind_methods(); + +public: + Error _initialize(); + Error _terminate(); + + static GDNativeLibrary *get_currently_initialized_library(); + + void _register_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func); + void _register_tool_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func); + void _register_script_method(const StringName p_name, const StringName p_method, godot_method_attributes p_attr, godot_instance_method p_func, MethodInfo p_info); + void _register_script_property(const StringName p_name, const String p_path, godot_property_attributes *p_attr, godot_property_set_func p_setter, godot_property_get_func p_getter); + void _register_script_signal(const StringName p_name, const godot_signal *p_signal); + + void set_platform_file(StringName p_platform, String p_file); + String get_platform_file(StringName p_platform) const; + + GDNativeLibrary(); + ~GDNativeLibrary(); +}; + +class GDNativeInstance : public ScriptInstance { + friend class GDNativeScript; + + Object *owner; + Ref<GDNativeScript> script; + void *userdata; + + void _ml_call_reversed(GDNativeScriptData *data_ptr, const StringName &p_method, const Variant **p_args, int p_argcount); + +public: + _FORCE_INLINE_ Object *get_owner() { return owner; } + + _FORCE_INLINE_ void *get_userdata() { return userdata; } + + virtual bool set(const StringName &p_name, const Variant &p_value); + virtual bool get(const StringName &p_name, Variant &r_ret) const; + virtual void get_property_list(List<PropertyInfo> *p_properties) const; + virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const; + + virtual void get_method_list(List<MethodInfo> *p_list) const; + virtual bool has_method(const StringName &p_method) const; + virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); + + Variant debug_get_member_by_index(int p_idx) const { return Variant(); } + + virtual void notification(int p_notification); + + virtual Ref<Script> get_script() const; + + virtual ScriptLanguage *get_language(); + + void set_path(const String &p_path); + + void reload_members(); + + virtual RPCMode get_rpc_mode(const StringName &p_method) const; + virtual RPCMode get_rset_mode(const StringName &p_variable) const; + + GDNativeInstance(); + ~GDNativeInstance(); +}; + +class GDNativeReloadNode; + +class GDNativeScriptLanguage : public ScriptLanguage { + friend class GDNativeScript; + friend class GDNativeInstance; + friend class GDNativeReloadNode; + friend class GDNativeLibrary; + + static GDNativeScriptLanguage *singleton; + + Variant *_global_array; // @Unused necessary? + Vector<Variant> global_array; // @Unused necessary? + Map<StringName, int> globals; // @Unused necessary? + + // @Unused necessary? + void _add_global(const StringName &p_name, const Variant &p_value); + + Mutex *lock; + + Set<GDNativeScript *> script_list; + + bool profiling; + uint64_t script_frame_time; + + struct { + + StringName _notification; + + } strings; + +public: + Map<StringName, NativeLibrary *> initialized_libraries; + + _FORCE_INLINE_ static GDNativeScriptLanguage *get_singleton() { return singleton; } + + virtual String get_name() const; + + /* LANGUAGE FUNCTIONS */ + virtual void init(); + virtual String get_type() const; + virtual String get_extension() const; + virtual Error execute_file(const String &p_path); + virtual void finish(); + + /* EDITOR FUNCTIONS */ + + virtual void get_reserved_words(List<String> *p_words) const {}; + virtual void get_comment_delimiters(List<String> *p_delimiters) const {}; + virtual void get_string_delimiters(List<String> *p_delimiters) const {}; + virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; + virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const; + virtual Script *create_script() const; + virtual bool has_named_classes() const; + virtual int find_function(const String &p_function, const String &p_code) const; + virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; + + virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) { return ERR_UNAVAILABLE; } + + virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; } + + virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {}; + virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); + + /* MULTITHREAD FUNCTIONS */ + + //some VMs need to be notified of thread creation/exiting to allocate a stack + virtual void thread_enter() {} + virtual void thread_exit() {} + + /* DEBUGGER FUNCTIONS */ + + virtual String debug_get_error() const; + virtual int debug_get_stack_level_count() const; + virtual int debug_get_stack_level_line(int p_level) const; + virtual String debug_get_stack_level_function(int p_level) const; + virtual String debug_get_stack_level_source(int p_level) const; + virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1){}; + virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1); + + virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); } + + virtual void reload_all_scripts(); + virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload); + /* LOADER FUNCTIONS */ + + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual void get_public_functions(List<MethodInfo> *p_functions) const; + virtual void get_public_constants(List<Pair<String, Variant> > *p_constants) const; + + /* PROFILLER FUNCTIONS */ + + virtual void profiling_start(); + virtual void profiling_stop(); + + virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max); + virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max); + + virtual void frame(); + + static String get_init_symbol_name(); + static String get_terminate_symbol_name(); + + /* HACKER FUNCTIONS */ + void _compile_dummy_for_the_api(); + + GDNativeScriptLanguage(); + ~GDNativeScriptLanguage(); +}; + +class GDNativeReloadNode : public Node { + GDCLASS(GDNativeReloadNode, Node) +public: + static void _bind_methods(); + void _notification(int p_what); +}; + +class ResourceFormatLoaderGDNativeScript : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; +}; + +class ResourceFormatSaverGDNativeScript : public ResourceFormatSaver { + virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const RES &p_resource) const; + virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; +}; + +#endif // GDNATIVE_H diff --git a/modules/gdnative/godot.cpp b/modules/gdnative/godot.cpp new file mode 100644 index 0000000000..7477a28db6 --- /dev/null +++ b/modules/gdnative/godot.cpp @@ -0,0 +1,220 @@ +/*************************************************************************/ +/* godot.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot.h" + +#include "class_db.h" +#include "gdnative.h" +#include "global_config.h" +#include "global_constants.h" +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern "C" void _string_api_anchor(); +extern "C" void _vector2_api_anchor(); +extern "C" void _rect2_api_anchor(); +extern "C" void _vector3_api_anchor(); +extern "C" void _transform2d_api_anchor(); +extern "C" void _plane_api_anchor(); +extern "C" void _quat_api_anchor(); +extern "C" void _basis_api_anchor(); +extern "C" void _rect3_api_anchor(); +extern "C" void _transform_api_anchor(); +extern "C" void _color_api_anchor(); +extern "C" void _image_api_anchor(); +extern "C" void _node_path_api_anchor(); +extern "C" void _rid_api_anchor(); +extern "C" void _input_event_api_anchor(); +extern "C" void _dictionary_api_anchor(); +extern "C" void _array_api_anchor(); +extern "C" void _pool_arrays_api_anchor(); +extern "C" void _variant_api_anchor(); + +void _api_anchor() { + + _string_api_anchor(); + _vector2_api_anchor(); + _rect2_api_anchor(); + _vector3_api_anchor(); + _transform2d_api_anchor(); + _plane_api_anchor(); + _quat_api_anchor(); + _rect3_api_anchor(); + _basis_api_anchor(); + _transform_api_anchor(); + _color_api_anchor(); + _image_api_anchor(); + _node_path_api_anchor(); + _rid_api_anchor(); + _input_event_api_anchor(); + _dictionary_api_anchor(); + _array_api_anchor(); + _pool_arrays_api_anchor(); + _variant_api_anchor(); +} + +extern "C++" { +template <class a, class b> +_FORCE_INLINE_ a memcast(b v) { + return *((a *)&v); +} +} + +void GDAPI godot_object_destroy(godot_object *p_o) { + memdelete((Object *)p_o); +} + +// Singleton API + +godot_object GDAPI *godot_global_get_singleton(char *p_name) { + return (godot_object *)GlobalConfig::get_singleton()->get_singleton_object(String(p_name)); +} // result shouldn't be freed + +// MethodBind API + +godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname) { + + MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname)); + // MethodBind *mb = ClassDB::get_method("Node", "get_name"); + return (godot_method_bind *)mb; +} + +void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret) { + + MethodBind *mb = (MethodBind *)p_method_bind; + Object *o = (Object *)p_instance; + mb->ptrcall(o, p_args, p_ret); +} + +// @Todo +/* +void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind) +{ + +} +*/ + +// Script API + +void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { + GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library(); + if (!library) { + ERR_EXPLAIN("Attempt to register script after initializing library!"); + ERR_FAIL(); + } + library->_register_script(p_name, p_base, p_create_func, p_destroy_func); +} + +void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { + GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library(); + if (!library) { + ERR_EXPLAIN("Attempt to register script after initializing library!"); + ERR_FAIL(); + } + library->_register_tool_script(p_name, p_base, p_create_func, p_destroy_func); +} + +void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) { + GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library(); + if (!library) { + ERR_EXPLAIN("Attempt to register script after initializing library!"); + ERR_FAIL(); + } + library->_register_script_method(p_name, p_function_name, p_attr, p_method, MethodInfo()); +} + +void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) { + GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library(); + if (!library) { + ERR_EXPLAIN("Attempt to register script after initializing library!"); + ERR_FAIL(); + } + + library->_register_script_property(p_name, p_path, p_attr, p_set_func, p_get_func); +} + +void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *p_signal) { + GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library(); + if (!library) { + ERR_EXPLAIN("Attempt to register script after initializing library!"); + ERR_FAIL(); + } + + library->_register_script_signal(p_name, p_signal); +} + +void GDAPI *godot_native_get_userdata(godot_object *p_instance) { + Object *instance = (Object *)p_instance; + if (!instance) + return NULL; + if (instance->get_script_instance() && instance->get_script_instance()->get_language() == GDNativeScriptLanguage::get_singleton()) { + return ((GDNativeInstance *)instance->get_script_instance())->get_userdata(); + } + return NULL; +} + +godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) { + ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname)); + if (class_info) + return (godot_class_constructor)class_info->creation_func; + return NULL; +} + +godot_dictionary GDAPI godot_get_global_constants() { + godot_dictionary constants; + godot_dictionary_new(&constants); + Dictionary *p_constants = (Dictionary *)&constants; + const int constants_count = GlobalConstants::get_global_constant_count(); + for (int i = 0; i < constants_count; ++i) { + const char *name = GlobalConstants::get_global_constant_name(i); + int value = GlobalConstants::get_global_constant_value(i); + (*p_constants)[name] = value; + } + return constants; +} + +// System functions +void GDAPI *godot_alloc(int p_bytes) { + return memalloc(p_bytes); +} + +void GDAPI *godot_realloc(void *p_ptr, int p_bytes) { + return memrealloc(p_ptr, p_bytes); +} + +void GDAPI godot_free(void *p_ptr) { + memfree(p_ptr); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h new file mode 100644 index 0000000000..b05cafbe50 --- /dev/null +++ b/modules/gdnative/godot.h @@ -0,0 +1,411 @@ +/*************************************************************************/ +/* godot.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_C_H +#define GODOT_C_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef GDAPI_BUILT_IN +#define GDAPI_EXPORT +#endif + +#ifdef _WIN32 +#if defined(GDAPI_EXPORT) +#define GDCALLINGCONV +#define GDAPI __declspec(dllexport) GDCALLINGCONV +#else +#define GDCALLINGCONV +#define GDAPI __declspec(dllimport) GDCALLINGCONV +#endif +#elif defined(__APPLE__) +#include "TargetConditionals.h" +#if TARGET_OS_IPHONE +#define GDCALLINGCONV +#define GDAPI +#elif TARGET_OS_MAC +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif +#else +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif + +#include <stdbool.h> +#include <stdint.h> + +#define GODOT_API_VERSION 1 + +////// Error + +typedef enum godot_error { + GODOT_OK, + GODOT_FAILED, ///< Generic fail error + GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable + GODOT_ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet + GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource + GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5) + GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory + GODOT_ERR_FILE_NOT_FOUND, + GODOT_ERR_FILE_BAD_DRIVE, + GODOT_ERR_FILE_BAD_PATH, + GODOT_ERR_FILE_NO_PERMISSION, // (10) + GODOT_ERR_FILE_ALREADY_IN_USE, + GODOT_ERR_FILE_CANT_OPEN, + GODOT_ERR_FILE_CANT_WRITE, + GODOT_ERR_FILE_CANT_READ, + GODOT_ERR_FILE_UNRECOGNIZED, // (15) + GODOT_ERR_FILE_CORRUPT, + GODOT_ERR_FILE_MISSING_DEPENDENCIES, + GODOT_ERR_FILE_EOF, + GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file + GODOT_ERR_CANT_CREATE, // (20) + GODOT_ERR_QUERY_FAILED, + GODOT_ERR_ALREADY_IN_USE, + GODOT_ERR_LOCKED, ///< resource is locked + GODOT_ERR_TIMEOUT, + GODOT_ERR_CANT_CONNECT, // (25) + GODOT_ERR_CANT_RESOLVE, + GODOT_ERR_CONNECTION_ERROR, + GODOT_ERR_CANT_AQUIRE_RESOURCE, + GODOT_ERR_CANT_FORK, + GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30) + GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid + GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists + GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist + GODOT_ERR_DATABASE_CANT_READ, ///< database is full + GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35) + GODOT_ERR_COMPILATION_FAILED, + GODOT_ERR_METHOD_NOT_FOUND, + GODOT_ERR_LINK_FAILED, + GODOT_ERR_SCRIPT_FAILED, + GODOT_ERR_CYCLIC_LINK, // (40) + GODOT_ERR_INVALID_DECLARATION, + GODOT_ERR_DUPLICATE_SYMBOL, + GODOT_ERR_PARSE_ERROR, + GODOT_ERR_BUSY, + GODOT_ERR_SKIP, // (45) + GODOT_ERR_HELP, ///< user requested help!! + GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior. + GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames + GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though + GODOT_ERR_WTF = GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above +} godot_error; + +////// bool + +typedef bool godot_bool; + +#define GODOT_TRUE 1 +#define GODOT_FALSE 0 + +/////// int + +typedef int godot_int; + +/////// real + +typedef float godot_real; + +/////// Object (forward declared) +typedef void godot_object; + +/////// String + +#include "godot/godot_string.h" + +////// Vector2 + +#include "godot/godot_vector2.h" + +////// Rect2 + +#include "godot/godot_rect2.h" + +////// Vector3 + +#include "godot/godot_vector3.h" + +////// Transform2D + +#include "godot/godot_transform2d.h" + +/////// Plane + +#include "godot/godot_plane.h" + +/////// Quat + +#include "godot/godot_quat.h" + +/////// Rect3 + +#include "godot/godot_rect3.h" + +/////// Basis + +#include "godot/godot_basis.h" + +/////// Transform + +#include "godot/godot_transform.h" + +/////// Color + +#include "godot/godot_color.h" + +/////// Image + +#include "godot/godot_image.h" + +/////// NodePath + +#include "godot/godot_node_path.h" + +/////// RID + +#include "godot/godot_rid.h" + +/////// InputEvent + +#include "godot/godot_input_event.h" + +/////// Dictionary + +#include "godot/godot_dictionary.h" + +/////// Array + +#include "godot/godot_array.h" + +// single API file for Pool*Array +#include "godot/godot_pool_arrays.h" + +void GDAPI godot_object_destroy(godot_object *p_o); + +////// Variant + +#include "godot/godot_variant.h" + +////// Singleton API + +godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed + +////// MethodBind API + +typedef struct godot_method_bind { + uint8_t _dont_touch_that[1]; // TODO +} godot_method_bind; + +godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname); +void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret); + +////// Script API + +typedef struct godot_native_init_options { + godot_bool in_editor; + uint64_t core_api_hash; + uint64_t editor_api_hash; + uint64_t no_api_hash; +} godot_native_init_options; + +typedef struct godot_native_terminate_options { + godot_bool in_editor; +} godot_native_terminate_options; + +typedef enum godot_method_rpc_mode { + GODOT_METHOD_RPC_MODE_DISABLED, + GODOT_METHOD_RPC_MODE_REMOTE, + GODOT_METHOD_RPC_MODE_SYNC, + GODOT_METHOD_RPC_MODE_MASTER, + GODOT_METHOD_RPC_MODE_SLAVE, +} godot_method_rpc_mode; + +typedef struct godot_method_attributes { + godot_method_rpc_mode rpc_type; +} godot_method_attributes; + +typedef enum godot_property_hint { + GODOT_PROPERTY_HINT_NONE, ///< no hint provided. + GODOT_PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional" + GODOT_PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit + GODOT_PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" + GODOT_PROPERTY_HINT_EXP_EASING, /// exponential easing funciton (Math::ease) + GODOT_PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer) + GODOT_PROPERTY_HINT_SPRITE_FRAME, + GODOT_PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer) + GODOT_PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags) + GODOT_PROPERTY_HINT_LAYERS_2D_RENDER, + GODOT_PROPERTY_HINT_LAYERS_2D_PHYSICS, + GODOT_PROPERTY_HINT_LAYERS_3D_RENDER, + GODOT_PROPERTY_HINT_LAYERS_3D_PHYSICS, + GODOT_PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," + GODOT_PROPERTY_HINT_DIR, ///< a directort path must be passed + GODOT_PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," + GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directort path must be passed + GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type + GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines + GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color + GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY, + GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS, + GODOT_PROPERTY_HINT_OBJECT_ID, + GODOT_PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose + GODOT_PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts) + GODOT_PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type + GODOT_PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type + GODOT_PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance + GODOT_PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base + GODOT_PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type + GODOT_PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type + GODOT_PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance + GODOT_PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base + GODOT_PROPERTY_HINT_MAX, +} godot_property_hint; + +typedef enum godot_property_usage_flags { + + GODOT_PROPERTY_USAGE_STORAGE = 1, + GODOT_PROPERTY_USAGE_EDITOR = 2, + GODOT_PROPERTY_USAGE_NETWORK = 4, + GODOT_PROPERTY_USAGE_EDITOR_HELPER = 8, + GODOT_PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables + GODOT_PROPERTY_USAGE_CHECKED = 32, //used for editing global variables + GODOT_PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings + GODOT_PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor + GODOT_PROPERTY_USAGE_CATEGORY = 256, + GODOT_PROPERTY_USAGE_STORE_IF_NONZERO = 512, //only store if nonzero + GODOT_PROPERTY_USAGE_STORE_IF_NONONE = 1024, //only store if false + GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE = 2048, + GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED = 4096, + GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE = 8192, + GODOT_PROPERTY_USAGE_STORE_IF_NULL = 16384, + GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768, + GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536, + + GODOT_PROPERTY_USAGE_DEFAULT = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK, + GODOT_PROPERTY_USAGE_DEFAULT_INTL = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED, + GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK, +} godot_property_usage_flags; + +typedef struct godot_property_attributes { + godot_method_rpc_mode rset_type; + + godot_int type; + godot_property_hint hint; + godot_string hint_string; + godot_property_usage_flags usage; + godot_variant default_value; +} godot_property_attributes; + +typedef struct godot_instance_create_func { + // instance pointer, method_data - return user data + GDCALLINGCONV void *(*create_func)(godot_object *, void *); + void *method_data; + GDCALLINGCONV void (*free_func)(void *); +} godot_instance_create_func; + +typedef struct godot_instance_destroy_func { + // instance pointer, method data, user data + GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *); + void *method_data; + GDCALLINGCONV void (*free_func)(void *); +} godot_instance_destroy_func; + +void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func); + +void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func); + +typedef struct godot_instance_method { + // instance pointer, method data, user data, num args, args - return result as varaint + GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); + void *method_data; + GDCALLINGCONV void (*free_func)(void *); +} godot_instance_method; + +void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method); + +typedef struct godot_property_set_func { + // instance pointer, method data, user data, value + GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant); + void *method_data; + GDCALLINGCONV void (*free_func)(void *); +} godot_property_set_func; + +typedef struct godot_property_get_func { + // instance pointer, method data, user data, value + GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *); + void *method_data; + GDCALLINGCONV void (*free_func)(void *); +} godot_property_get_func; + +void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func); + +typedef struct godot_signal_argument { + godot_string name; + godot_int type; + godot_property_hint hint; + godot_string hint_string; + godot_property_usage_flags usage; + godot_variant default_value; +} godot_signal_argument; + +typedef struct godot_signal { + godot_string name; + int num_args; + godot_signal_argument *args; + int num_default_args; + godot_variant *default_args; +} godot_signal; + +void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *p_signal); + +void GDAPI *godot_native_get_userdata(godot_object *p_instance); + +// Calling convention? +typedef godot_object *(*godot_class_constructor)(); + +godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname); + +godot_dictionary GDAPI godot_get_global_constants(); + +////// System Functions + +//using these will help Godot track how much memory is in use in debug mode +void GDAPI *godot_alloc(int p_bytes); +void GDAPI *godot_realloc(void *p_ptr, int p_bytes); +void GDAPI godot_free(void *p_ptr); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_C_H diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp new file mode 100644 index 0000000000..6c55c5d048 --- /dev/null +++ b/modules/gdnative/godot/godot_array.cpp @@ -0,0 +1,300 @@ +/*************************************************************************/ +/* godot_array.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_array.h" + +#include "core/array.h" +#include "core/os/memory.h" + +#include "core/color.h" +#include "core/dvector.h" + +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _array_api_anchor() { +} + +void GDAPI godot_array_new(godot_array *p_arr) { + Array *a = (Array *)p_arr; + memnew_placement(a, Array); +} + +void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) { + Array *a = (Array *)p_arr; + PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a) { + Array *a = (Array *)p_arr; + PoolVector<Vector3> *pca = (PoolVector<Vector3> *)p_pv3a; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a) { + Array *a = (Array *)p_arr; + PoolVector<Vector2> *pca = (PoolVector<Vector2> *)p_pv2a; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_string_array(godot_array *p_arr, const godot_pool_string_array *p_psa) { + Array *a = (Array *)p_arr; + PoolVector<String> *pca = (PoolVector<String> *)p_psa; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_real_array(godot_array *p_arr, const godot_pool_real_array *p_pra) { + Array *a = (Array *)p_arr; + PoolVector<godot_real> *pca = (PoolVector<godot_real> *)p_pra; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_int_array(godot_array *p_arr, const godot_pool_int_array *p_pia) { + Array *a = (Array *)p_arr; + PoolVector<godot_int> *pca = (PoolVector<godot_int> *)p_pia; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_byte_array(godot_array *p_arr, const godot_pool_byte_array *p_pba) { + Array *a = (Array *)p_arr; + PoolVector<uint8_t> *pca = (PoolVector<uint8_t> *)p_pba; + memnew_placement(a, Array); + a->resize(pca->size()); + + for (size_t i = 0; i < a->size(); i++) { + Variant v = pca->operator[](i); + a->operator[](i) = v; + } +} + +void GDAPI godot_array_set(godot_array *p_arr, const godot_int p_idx, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->operator[](p_idx) = *val; +} + +godot_variant GDAPI *godot_array_get(godot_array *p_arr, const godot_int p_idx) { + Array *a = (Array *)p_arr; + return (godot_variant *)&a->operator[](p_idx); +} + +void GDAPI godot_array_append(godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->append(*val); +} + +void GDAPI godot_array_clear(godot_array *p_arr) { + Array *a = (Array *)p_arr; + a->clear(); +} + +godot_int GDAPI godot_array_count(godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + return a->count(*val); +} + +godot_bool GDAPI godot_array_empty(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + return a->empty(); +} + +void GDAPI godot_array_erase(godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->erase(*val); +} + +godot_variant GDAPI godot_array_front(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = a->front(); + return v; +} + +godot_variant GDAPI godot_array_back(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = a->back(); + return v; +} + +godot_int GDAPI godot_array_find(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_what; + return a->find(*val, p_from); +} + +godot_int GDAPI godot_array_find_last(const godot_array *p_arr, const godot_variant *p_what) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_what; + return a->find_last(*val); +} + +godot_bool GDAPI godot_array_has(const godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + return a->has(*val); +} + +uint32_t GDAPI godot_array_hash(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + return a->hash(); +} + +void GDAPI godot_array_insert(godot_array *p_arr, const godot_int p_pos, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->insert(p_pos, *val); +} + +void GDAPI godot_array_invert(godot_array *p_arr) { + Array *a = (Array *)p_arr; + a->invert(); +} + +godot_bool GDAPI godot_array_is_shared(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + return false; // @Todo how do I do it? +} + +godot_variant GDAPI godot_array_pop_back(godot_array *p_arr) { + Array *a = (Array *)p_arr; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = a->pop_back(); + return v; +} + +godot_variant GDAPI godot_array_pop_front(godot_array *p_arr) { + Array *a = (Array *)p_arr; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = a->pop_front(); + return v; +} + +void GDAPI godot_array_push_back(godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->push_back(*val); +} + +void GDAPI godot_array_push_front(godot_array *p_arr, const godot_variant *p_value) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_value; + a->push_front(*val); +} + +void GDAPI godot_array_remove(godot_array *p_arr, const godot_int p_idx) { + Array *a = (Array *)p_arr; + a->remove(p_idx); +} + +void GDAPI godot_array_resize(godot_array *p_arr, const godot_int p_size) { + Array *a = (Array *)p_arr; + a->resize(p_size); +} + +godot_int GDAPI godot_array_rfind(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from) { + Array *a = (Array *)p_arr; + Variant *val = (Variant *)p_what; + return a->rfind(*val, p_from); +} + +godot_int GDAPI godot_array_size(const godot_array *p_arr) { + Array *a = (Array *)p_arr; + return a->size(); +} + +void GDAPI godot_array_sort(godot_array *p_arr) { + Array *a = (Array *)p_arr; + a->sort(); +} + +void GDAPI godot_array_sort_custom(godot_array *p_arr, godot_object *p_obj, const godot_string *p_func) { + Array *a = (Array *)p_arr; + String *func = (String *)p_func; + a->sort_custom((Object *)p_obj, *func); +} + +void GDAPI godot_array_destroy(godot_array *p_arr) { + ((Array *)p_arr)->~Array(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h new file mode 100644 index 0000000000..b92ebb834f --- /dev/null +++ b/modules/gdnative/godot/godot_array.h @@ -0,0 +1,118 @@ +/*************************************************************************/ +/* godot_array.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef GODOT_ARRAY_H +#define GODOT_ARRAY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED +typedef struct godot_array { + uint8_t _dont_touch_that[8]; +} godot_array; +#endif + +#include "../godot.h" + +#include "godot_pool_arrays.h" +#include "godot_variant.h" + +void GDAPI godot_array_new(godot_array *p_arr); +void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca); +void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_array_new_pool_string_array(godot_array *p_arr, const godot_pool_string_array *p_psa); +void GDAPI godot_array_new_pool_real_array(godot_array *p_arr, const godot_pool_real_array *p_pra); +void GDAPI godot_array_new_pool_int_array(godot_array *p_arr, const godot_pool_int_array *p_pia); +void GDAPI godot_array_new_pool_byte_array(godot_array *p_arr, const godot_pool_byte_array *p_pba); + +void GDAPI godot_array_set(godot_array *p_arr, const godot_int p_idx, const godot_variant *p_value); + +godot_variant GDAPI *godot_array_get(godot_array *p_arr, const godot_int p_idx); + +void GDAPI godot_array_append(godot_array *p_arr, const godot_variant *p_value); + +void GDAPI godot_array_clear(godot_array *p_arr); + +godot_int GDAPI godot_array_count(godot_array *p_arr, const godot_variant *p_value); + +godot_bool GDAPI godot_array_empty(const godot_array *p_arr); + +void GDAPI godot_array_erase(godot_array *p_arr, const godot_variant *p_value); + +godot_variant GDAPI godot_array_front(const godot_array *p_arr); + +godot_variant GDAPI godot_array_back(const godot_array *p_arr); + +godot_int GDAPI godot_array_find(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from); + +godot_int GDAPI godot_array_find_last(const godot_array *p_arr, const godot_variant *p_what); + +godot_bool GDAPI godot_array_has(const godot_array *p_arr, const godot_variant *p_value); + +uint32_t GDAPI godot_array_hash(const godot_array *p_arr); + +void GDAPI godot_array_insert(godot_array *p_arr, const godot_int p_pos, const godot_variant *p_value); + +void GDAPI godot_array_invert(godot_array *p_arr); + +godot_bool GDAPI godot_array_is_shared(const godot_array *p_arr); + +godot_variant GDAPI godot_array_pop_back(godot_array *p_arr); + +godot_variant GDAPI godot_array_pop_front(godot_array *p_arr); + +void GDAPI godot_array_push_back(godot_array *p_arr, const godot_variant *p_value); + +void GDAPI godot_array_push_front(godot_array *p_arr, const godot_variant *p_value); + +void GDAPI godot_array_remove(godot_array *p_arr, const godot_int p_idx); + +void GDAPI godot_array_resize(godot_array *p_arr, const godot_int p_size); + +godot_int GDAPI godot_array_rfind(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from); + +godot_int GDAPI godot_array_size(const godot_array *p_arr); + +void GDAPI godot_array_sort(godot_array *p_arr); + +void GDAPI godot_array_sort_custom(godot_array *p_arr, godot_object *p_obj, const godot_string *p_func); + +void GDAPI godot_array_destroy(godot_array *p_arr); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_ARRAY_H diff --git a/modules/gdnative/godot/godot_basis.cpp b/modules/gdnative/godot/godot_basis.cpp new file mode 100644 index 0000000000..474cd3d448 --- /dev/null +++ b/modules/gdnative/godot/godot_basis.cpp @@ -0,0 +1,215 @@ +/*************************************************************************/ +/* godot_basis.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_basis.h" + +#include "math/matrix3.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _basis_api_anchor() { +} + +void GDAPI godot_basis_new(godot_basis *p_v) { + Basis *v = (Basis *)p_v; + *v = Basis(); +} + +void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_v, const godot_quat *p_euler) { + Basis *v = (Basis *)p_v; + Quat *euler = (Quat *)p_euler; + *v = Basis(*euler); +} + +void GDAPI godot_basis_new_with_euler(godot_basis *p_v, const godot_vector3 p_euler) { + Basis *v = (Basis *)p_v; + Vector3 *euler = (Vector3 *)&p_euler; + *v = Basis(*euler); +} + +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi) { + Basis *v = (Basis *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *v = Basis(*axis, p_phi); +} + +void GDAPI godot_basis_new_with_rows(godot_basis *p_v, const godot_vector3 p_row0, const godot_vector3 p_row1, const godot_vector3 p_row2) { + Basis *v = (Basis *)p_v; + const Vector3 *row0 = (Vector3 *)&p_row0; + const Vector3 *row1 = (Vector3 *)&p_row1; + const Vector3 *row2 = (Vector3 *)&p_row2; + *v = Basis(*row0, *row1, *row2); +} + +godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_v) { + const Basis *v = (const Basis *)p_v; + godot_quat quat; + Quat *p_quat = (Quat *)&quat; + *p_quat = v->operator Quat(); + return quat; +} + +/* + * p_elements is a pointer to an array of 3 (!!) vector3 + */ +void GDAPI godot_basis_get_elements(godot_basis *p_v, godot_vector3 *p_elements) { + Basis *v = (Basis *)p_v; + Vector3 *elements = (Vector3 *)p_elements; + elements[0] = v->elements[0]; + elements[1] = v->elements[1]; + elements[2] = v->elements[2]; +} + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_v, const godot_int p_axis) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_axis(p_axis); + return dest; +} + +void GDAPI godot_basis_set_axis(godot_basis *p_v, const godot_int p_axis, const godot_vector3 p_value) { + Basis *v = (Basis *)p_v; + const Vector3 *value = (Vector3 *)&p_value; + v->set_axis(p_axis, *value); +} + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_v, const godot_int p_row) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_row(p_row); + return dest; +} + +void GDAPI godot_basis_set_row(godot_basis *p_v, const godot_int p_row, const godot_vector3 p_value) { + Basis *v = (Basis *)p_v; + const Vector3 *value = (Vector3 *)&p_value; + v->set_row(p_row, *value); +} + +godot_real godot_basis_determinant(const godot_basis *p_v) { + Basis *v = (Basis *)p_v; + return v->determinant(); +} + +godot_vector3 godot_basis_get_euler(const godot_basis *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_euler(); + return dest; +} + +godot_int godot_basis_get_orthogonal_index(const godot_basis *p_v) { + const Basis *v = (Basis *)p_v; + return v->get_orthogonal_index(); +} + +godot_vector3 godot_basis_get_scale(const godot_basis *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_scale(); + return dest; +} + +void godot_basis_inverse(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->inverse(); +} + +void godot_basis_orthonormalized(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->orthonormalized(); +} + +void godot_basis_rotated(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *d = v->rotated(*axis, p_phi); +} + +void godot_basis_scaled(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_scale) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + const Vector3 *scale = (Vector3 *)&p_scale; + *d = v->scaled(*scale); +} + +godot_real godot_basis_tdotx(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdotx(*with); +} + +godot_real godot_basis_tdoty(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdoty(*with); +} + +godot_real godot_basis_tdotz(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdotz(*with); +} + +void godot_basis_transposed(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->transposed(); +} + +godot_vector3 godot_basis_xform(const godot_basis *p_v, const godot_vector3 p_vect) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + const Vector3 *vect = (Vector3 *)&p_vect; + *d = v->xform(*vect); + return dest; +} + +godot_vector3 godot_basis_xform_inv(const godot_basis *p_v, const godot_vector3 p_vect) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + const Vector3 *vect = (Vector3 *)&p_vect; + *d = v->xform_inv(*vect); + return dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_basis.h b/modules/gdnative/godot/godot_basis.h new file mode 100644 index 0000000000..2803396997 --- /dev/null +++ b/modules/gdnative/godot/godot_basis.h @@ -0,0 +1,84 @@ +/*************************************************************************/ +/* godot_basis.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_BASIS_H +#define GODOT_BASIS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED +typedef struct godot_basis { + uint8_t _dont_touch_that[36]; +} godot_basis; +#endif + +#include "../godot.h" +#include "godot_quat.h" + +void GDAPI godot_basis_new(godot_basis *p_v); +void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_v, const godot_quat *p_euler); +void GDAPI godot_basis_new_with_euler(godot_basis *p_v, const godot_vector3 p_euler); +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi); +void GDAPI godot_basis_new_with_rows(godot_basis *p_v, const godot_vector3 p_row0, const godot_vector3 p_row1, const godot_vector3 p_row2); + +godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_v); + +/* + * p_elements is a pointer to an array of 3 (!!) vector3 + */ +void GDAPI godot_basis_get_elements(godot_basis *p_v, godot_vector3 *p_elements); +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_v, const godot_int p_axis); +void GDAPI godot_basis_set_axis(godot_basis *p_v, const godot_int p_axis, const godot_vector3 p_value); +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_v, const godot_int p_row); +void GDAPI godot_basis_set_row(godot_basis *p_v, const godot_int p_row, const godot_vector3 p_value); + +godot_real godot_basis_determinant(const godot_basis *p_v); +godot_vector3 godot_basis_get_euler(const godot_basis *p_v); +godot_int godot_basis_get_orthogonal_index(const godot_basis *p_v); +godot_vector3 godot_basis_get_scale(const godot_basis *p_v); +void godot_basis_inverse(godot_basis *p_dest, const godot_basis *p_v); +void godot_basis_orthonormalized(godot_basis *p_dest, const godot_basis *p_v); +void godot_basis_rotated(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi); +void godot_basis_scaled(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_scale); +godot_real godot_basis_tdotx(const godot_basis *p_v, const godot_vector3 p_with); +godot_real godot_basis_tdoty(const godot_basis *p_v, const godot_vector3 p_with); +godot_real godot_basis_tdotz(const godot_basis *p_v, const godot_vector3 p_with); +void godot_basis_transposed(godot_basis *p_dest, const godot_basis *p_v); +godot_vector3 godot_basis_xform(const godot_basis *p_v, const godot_vector3 p_vect); +godot_vector3 godot_basis_xform_inv(const godot_basis *p_v, const godot_vector3 p_vect); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_BASIS_H diff --git a/modules/gdnative/godot/godot_color.cpp b/modules/gdnative/godot/godot_color.cpp new file mode 100644 index 0000000000..203ce672fa --- /dev/null +++ b/modules/gdnative/godot/godot_color.cpp @@ -0,0 +1,63 @@ +/*************************************************************************/ +/* godot_color.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_color.h" + +#include "color.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _color_api_anchor() { +} + +void GDAPI godot_color_new(godot_color *p_color) { + Color *color = (Color *)p_color; + *color = Color(); +} + +void GDAPI godot_color_new_rgba(godot_color *p_color, const godot_real r, const godot_real g, const godot_real b, const godot_real a) { + Color *color = (Color *)p_color; + *color = Color(r, g, b, a); +} + +uint32_t GDAPI godot_color_get_32(const godot_color *p_color) { + const Color *color = (const Color *)p_color; + return color->to_32(); +} + +float GDAPI *godot_color_index(godot_color *p_color, const godot_int idx) { + Color *color = (Color *)p_color; + return &color->operator[](idx); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_color.h b/modules/gdnative/godot/godot_color.h new file mode 100644 index 0000000000..b99a062a66 --- /dev/null +++ b/modules/gdnative/godot/godot_color.h @@ -0,0 +1,58 @@ +/*************************************************************************/ +/* godot_color.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_COLOR_H +#define GODOT_COLOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED +typedef struct godot_color { + uint8_t _dont_touch_that[16]; +} godot_color; +#endif + +#include "../godot.h" + +void GDAPI godot_color_new(godot_color *p_color); +void GDAPI godot_color_new_rgba(godot_color *p_color, const godot_real r, const godot_real g, const godot_real b, const godot_real a); + +uint32_t GDAPI godot_color_get_32(const godot_color *p_color); + +float GDAPI *godot_color_index(godot_color *p_color, const godot_int idx); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_COLOR_H diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp new file mode 100644 index 0000000000..16d08e58e2 --- /dev/null +++ b/modules/gdnative/godot/godot_dictionary.cpp @@ -0,0 +1,138 @@ +/*************************************************************************/ +/* godot_dictionary.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_dictionary.h" + +#include "core/dictionary.h" + +#include "core/os/memory.h" + +#include "core/io/json.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _dictionary_api_anchor() { +} + +void GDAPI godot_dictionary_new(godot_dictionary *p_dict) { + Dictionary *dict = (Dictionary *)p_dict; + memnew_placement(dict, Dictionary); +} + +void GDAPI godot_dictionary_clear(godot_dictionary *p_dict) { + Dictionary *dict = (Dictionary *)p_dict; + dict->clear(); +} + +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_dict) { + const Dictionary *dict = (const Dictionary *)p_dict; + return dict->empty(); +} + +void GDAPI godot_dictionary_erase(godot_dictionary *p_dict, const godot_variant *p_key) { + Dictionary *dict = (Dictionary *)p_dict; + Variant *key = (Variant *)p_key; + dict->erase(*key); +} + +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_dict, const godot_variant *p_key) { + const Dictionary *dict = (const Dictionary *)p_dict; + const Variant *key = (const Variant *)p_key; + return dict->has(*key); +} + +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_dict, const godot_array *p_keys) { + const Dictionary *dict = (const Dictionary *)p_dict; + const Array *keys = (const Array *)p_keys; + return dict->has_all(*keys); +} + +uint32_t GDAPI godot_dictionary_hash(const godot_dictionary *p_dict) { + const Dictionary *dict = (const Dictionary *)p_dict; + return dict->hash(); +} + +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_dict) { + godot_array a; + godot_array_new(&a); + const Dictionary *dict = (const Dictionary *)p_dict; + Array *array = (Array *)&a; + *array = dict->keys(); + return a; +} + +godot_int GDAPI godot_dictionary_parse_json(godot_dictionary *p_dict, const godot_string *p_json) { + Dictionary *dict = (Dictionary *)p_dict; + const String *json = (const String *)p_json; + Variant ret; + int err_line; + String err_str; + int err = (int)JSON::parse(*json, ret, err_str, err_line); + *dict = ret; + return err; +} + +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_dict, const godot_variant *p_key) { + Dictionary *dict = (Dictionary *)p_dict; + Variant *key = (Variant *)p_key; + return (godot_variant *)&dict->operator[](*key); +} + +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_dict) { + const Dictionary *dict = (const Dictionary *)p_dict; + return dict->size(); +} + +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_dict) { + const Dictionary *dict = (const Dictionary *)p_dict; + godot_string str; + godot_string_new(&str); + String *s = (String *)&str; + *s = JSON::print(Variant(*dict)); + return str; +} + +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_dict) { + godot_array a; + godot_array_new(&a); + const Dictionary *dict = (const Dictionary *)p_dict; + Array *array = (Array *)&a; + *array = dict->values(); + return a; +} + +void GDAPI godot_dictionary_destroy(godot_dictionary *p_dict) { + ((Dictionary *)p_dict)->~Dictionary(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h new file mode 100644 index 0000000000..3f7c504880 --- /dev/null +++ b/modules/gdnative/godot/godot_dictionary.h @@ -0,0 +1,80 @@ +/*************************************************************************/ +/* godot_dictionary.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_DICTIONARY_H +#define GODOT_DICTIONARY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_DICITIONARY_TYPE_DEFINED +typedef struct godot_dictionary { + uint8_t _dont_touch_that[8]; +} godot_dictionary; +#endif + +#include "godot_array.h" +#include "godot_variant.h" + +void GDAPI godot_dictionary_new(godot_dictionary *p_dict); + +void GDAPI godot_dictionary_clear(godot_dictionary *p_dict); + +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_dict); + +void GDAPI godot_dictionary_erase(godot_dictionary *p_dict, const godot_variant *p_key); + +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_dict, const godot_variant *p_key); + +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_dict, const godot_array *p_keys); + +uint32_t GDAPI godot_dictionary_hash(const godot_dictionary *p_dict); + +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_dict); + +godot_int GDAPI godot_dictionary_parse_json(godot_dictionary *p_dict, const godot_string *p_json); + +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_dict, const godot_variant *p_key); + +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_dict); + +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_dict); + +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_dict); + +void GDAPI godot_dictionary_destroy(godot_dictionary *p_dict); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_DICTIONARY_H diff --git a/modules/gdnative/godot/godot_image.cpp b/modules/gdnative/godot/godot_image.cpp new file mode 100644 index 0000000000..ae8290afc2 --- /dev/null +++ b/modules/gdnative/godot/godot_image.cpp @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* godot_image.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_image.h" + +#include "image.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _image_api_anchor() { +} + +#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) + +void GDAPI godot_image_new(godot_image *p_img) { + Image *img = (Image *)p_img; + memnew_placement_custom(img, Image, Image()); +} + +void GDAPI godot_image_new_with_png_jpg(godot_image *p_img, const uint8_t *p_mem_png_jpg, int p_len) { + Image *img = (Image *)p_img; + memnew_placement_custom(img, Image, Image(p_mem_png_jpg, p_len)); +} + +void GDAPI godot_image_new_with_xpm(godot_image *p_img, const char **p_xpm) { + Image *img = (Image *)p_img; + memnew_placement_custom(img, Image, Image(p_xpm)); +} + +void GDAPI godot_image_new_with_size_format(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format) { + Image *img = (Image *)p_img; + memnew_placement_custom(img, Image, Image(p_width, p_height, p_use_mipmaps, (Image::Format)p_format)); +} + +void GDAPI godot_image_new_with_size_format_data(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format, godot_pool_byte_array *p_data) { + Image *img = (Image *)p_img; + PoolVector<uint8_t> *data = (PoolVector<uint8_t> *)p_data; + memnew_placement_custom(img, Image, Image(p_width, p_height, p_use_mipmaps, (Image::Format)p_format, *data)); +} + +godot_pool_byte_array GDAPI godot_image_get_data(godot_image *p_img) { + Image *img = (Image *)p_img; + PoolVector<uint8_t> cpp_data = img->get_data(); + godot_pool_byte_array *data = (godot_pool_byte_array *)&cpp_data; + return *data; +} + +godot_error GDAPI godot_image_load(godot_image *p_img, const godot_string *p_path) { + Image *img = (Image *)p_img; + String *path = (String *)p_path; + return (godot_error)img->load(*path); +} + +godot_error GDAPI godot_image_save_png(godot_image *p_img, const godot_string *p_path) { + Image *img = (Image *)p_img; + String *path = (String *)p_path; + return (godot_error)img->save_png(*path); +} + +int GDAPI godot_image_get_width(const godot_image *p_img) { + Image *img = (Image *)p_img; + return img->get_width(); +} + +int GDAPI godot_image_get_height(const godot_image *p_img) { + Image *img = (Image *)p_img; + return img->get_height(); +} + +godot_bool GDAPI godot_image_has_mipmaps(const godot_image *p_img) { + Image *img = (Image *)p_img; + return img->has_mipmaps(); +} + +int GDAPI godot_image_get_mipmap_count(const godot_image *p_img) { + Image *img = (Image *)p_img; + return img->get_mipmap_count(); +} + +void GDAPI godot_image_destroy(godot_image *p_img) { + ((Image *)p_img)->~Image(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_image.h b/modules/gdnative/godot/godot_image.h new file mode 100644 index 0000000000..c43dd45148 --- /dev/null +++ b/modules/gdnative/godot/godot_image.h @@ -0,0 +1,124 @@ +/*************************************************************************/ +/* godot_image.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_IMAGE_H +#define GODOT_IMAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_IMAGE_TYPE_DEFINED +typedef struct godot_image { + uint8_t _dont_touch_that[32]; +} godot_image; +#endif + +#include "godot_pool_arrays.h" + +#include "../godot.h" + +// This is a copypasta of the C++ enum inside the Image class +// There's no neat way of automatically updating the C enum / using the C++ enum directly +// if somebody knows a way feel free to open a PR or open an issue (or ask for Karroffel or bojidar-bg on IRC) + +enum godot_image_format { + + GODOT_IMAGE_FORMAT_L8, //luminance + GODOT_IMAGE_FORMAT_LA8, //luminance-alpha + GODOT_IMAGE_FORMAT_R8, + GODOT_IMAGE_FORMAT_RG8, + GODOT_IMAGE_FORMAT_RGB8, + GODOT_IMAGE_FORMAT_RGBA8, + GODOT_IMAGE_FORMAT_RGB565, //16 bit + GODOT_IMAGE_FORMAT_RGBA4444, + GODOT_IMAGE_FORMAT_RGBA5551, + GODOT_IMAGE_FORMAT_RF, //float + GODOT_IMAGE_FORMAT_RGF, + GODOT_IMAGE_FORMAT_RGBF, + GODOT_IMAGE_FORMAT_RGBAF, + GODOT_IMAGE_FORMAT_RH, //half float + GODOT_IMAGE_FORMAT_RGH, + GODOT_IMAGE_FORMAT_RGBH, + GODOT_IMAGE_FORMAT_RGBAH, + GODOT_IMAGE_FORMAT_DXT1, //s3tc bc1 + GODOT_IMAGE_FORMAT_DXT3, //bc2 + GODOT_IMAGE_FORMAT_DXT5, //bc3 + GODOT_IMAGE_FORMAT_ATI1, //bc4 + GODOT_IMAGE_FORMAT_ATI2, //bc5 + GODOT_IMAGE_FORMAT_BPTC_RGBA, //btpc bc6h + GODOT_IMAGE_FORMAT_BPTC_RGBF, //float / + GODOT_IMAGE_FORMAT_BPTC_RGBFU, //unsigned float + GODOT_IMAGE_FORMAT_PVRTC2, //pvrtc + GODOT_IMAGE_FORMAT_PVRTC2A, + GODOT_IMAGE_FORMAT_PVRTC4, + GODOT_IMAGE_FORMAT_PVRTC4A, + GODOT_IMAGE_FORMAT_ETC, //etc1 + GODOT_IMAGE_FORMAT_ETC2_R11, //etc2 + GODOT_IMAGE_FORMAT_ETC2_R11S, //signed, NOT srgb. + GODOT_IMAGE_FORMAT_ETC2_RG11, + GODOT_IMAGE_FORMAT_ETC2_RG11S, + GODOT_IMAGE_FORMAT_ETC2_RGB8, + GODOT_IMAGE_FORMAT_ETC2_RGBA8, + GODOT_IMAGE_FORMAT_ETC2_RGB8A1, + GODOT_IMAGE_FORMAT_MAX +}; +typedef enum godot_image_format godot_image_format; + +void GDAPI godot_image_new(godot_image *p_img); +// p_len can be -1 +void GDAPI godot_image_new_with_png_jpg(godot_image *p_img, const uint8_t *p_mem_png_jpg, int p_len); +void GDAPI godot_image_new_with_xpm(godot_image *p_img, const char **p_xpm); + +void GDAPI godot_image_new_with_size_format(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format); +void GDAPI godot_image_new_with_size_format_data(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format, godot_pool_byte_array *p_data); + +godot_pool_byte_array GDAPI godot_image_get_data(godot_image *p_img); + +godot_error GDAPI godot_image_load(godot_image *p_img, const godot_string *p_path); +godot_error GDAPI godot_image_save_png(godot_image *p_img, const godot_string *p_path); + +int GDAPI godot_image_get_width(const godot_image *p_img); +int GDAPI godot_image_get_height(const godot_image *p_img); +godot_bool GDAPI godot_image_has_mipmaps(const godot_image *p_img); +int GDAPI godot_image_get_mipmap_count(const godot_image *p_img); + +// @Incomplete +// I think it's too complex for the binding authors to implement the image class anew, so we should definitely +// export all methods here. That takes a while so it's on my @Todo list + +void GDAPI godot_image_destroy(godot_image *p_img); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_IMAGE_H diff --git a/modules/gdnative/godot/godot_input_event.cpp b/modules/gdnative/godot/godot_input_event.cpp new file mode 100644 index 0000000000..0401c96a88 --- /dev/null +++ b/modules/gdnative/godot/godot_input_event.cpp @@ -0,0 +1,309 @@ +/*************************************************************************/ +/* godot_input_event.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_input_event.h" + +#include "os/input_event.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _input_event_api_anchor() { +} + +void GDAPI godot_input_event_new(godot_input_event *p_ie) { + InputEvent *ie = (InputEvent *)p_ie; + *ie = InputEvent(); +} + +godot_bool GDAPI godot_input_event_is_pressed(const godot_input_event *p_ie) { + const InputEvent *ie = (const InputEvent *)p_ie; + return ie->is_pressed(); +} + +godot_bool GDAPI godot_input_event_is_action(const godot_input_event *p_ie, const godot_string *p_action) { + const InputEvent *ie = (const InputEvent *)p_ie; + const String *action = (const String *)p_action; + return ie->is_action(*action); +} + +godot_bool GDAPI godot_input_event_is_action_pressed(const godot_input_event *p_ie, const godot_string *p_action) { + const InputEvent *ie = (const InputEvent *)p_ie; + const String *action = (const String *)p_action; + return ie->is_action_pressed(*action); +} + +godot_bool GDAPI godot_input_event_is_action_released(const godot_input_event *p_ie, const godot_string *p_action) { + const InputEvent *ie = (const InputEvent *)p_ie; + const String *action = (const String *)p_action; + return ie->is_action_released(*action); +} + +godot_bool GDAPI godot_input_event_is_echo(const godot_input_event *p_ie) { + const InputEvent *ie = (const InputEvent *)p_ie; + return ie->is_echo(); +} + +void GDAPI godot_input_event_set_as_action(godot_input_event *p_ie, const godot_string *p_action, const godot_bool p_pressed) { + InputEvent *ie = (InputEvent *)p_ie; + const String *action = (const String *)p_action; + return ie->set_as_action(*action, p_pressed); +} + +godot_string GDAPI godot_input_event_as_string(const godot_input_event *p_ie) { + const InputEvent *ie = (const InputEvent *)p_ie; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = (String)*ie; + return str; +} + +uint32_t GDAPI *godot_input_event_get_id(godot_input_event *p_ie) { + InputEvent *ie = (InputEvent *)p_ie; + return &ie->ID; +} + +godot_input_event_type GDAPI *godot_input_event_get_type(godot_input_event *p_ie) { + InputEvent *ie = (InputEvent *)p_ie; + return (godot_input_event_type *)&ie->type; +} + +godot_int GDAPI *godot_input_event_get_device(godot_input_event *p_ie) { + InputEvent *ie = (InputEvent *)p_ie; + return &ie->device; +} + +static InputModifierState *_get_mod_for_type(InputEvent *ie) { + switch (ie->type) { + case InputEvent::MOUSE_BUTTON: + return &ie->mouse_button.mod; + case InputEvent::MOUSE_MOTION: + return &ie->mouse_motion.mod; + case InputEvent::KEY: + return &ie->key.mod; + default: + return 0; + } +} + +godot_bool GDAPI *godot_input_event_mod_get_alt(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + InputModifierState *mod = _get_mod_for_type(ie); + return &mod->alt; +} + +godot_bool GDAPI *godot_input_event_mod_get_ctrl(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + InputModifierState *mod = _get_mod_for_type(ie); + return &mod->control; +} + +godot_bool GDAPI *godot_input_event_mod_get_command(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + InputModifierState *mod = _get_mod_for_type(ie); + return &mod->command; +} + +godot_bool GDAPI *godot_input_event_mod_get_shift(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + InputModifierState *mod = _get_mod_for_type(ie); + return &mod->shift; +} + +godot_bool GDAPI *godot_input_event_mod_get_meta(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + InputModifierState *mod = _get_mod_for_type(ie); + return &mod->meta; +} + +uint32_t GDAPI *godot_input_event_key_get_scancode(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->key.scancode; +} + +uint32_t GDAPI *godot_input_event_key_get_unicode(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->key.unicode; +} + +godot_bool GDAPI *godot_input_event_key_get_pressed(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->key.pressed; +} + +godot_bool GDAPI *godot_input_event_key_get_echo(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->key.echo; +} + +float GDAPI *godot_input_event_mouse_get_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.x; +} + +float GDAPI *godot_input_event_mouse_get_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.y; +} + +float GDAPI *godot_input_event_mouse_get_global_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.global_x; +} + +float GDAPI *godot_input_event_mouse_get_global_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.global_y; +} + +godot_int GDAPI *godot_input_event_mouse_get_button_mask(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.button_mask; +} + +godot_int GDAPI *godot_input_event_mouse_button_get_button_index(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.button_index; +} + +godot_bool GDAPI *godot_input_event_mouse_button_get_pressed(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.pressed; +} + +godot_bool GDAPI *godot_input_event_mouse_button_get_doubleclick(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_button.doubleclick; +} + +float GDAPI *godot_input_event_mouse_motion_get_relative_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_motion.relative_x; +} + +float GDAPI *godot_input_event_mouse_motion_get_relative_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_motion.relative_y; +} + +float GDAPI *godot_input_event_mouse_motion_get_speed_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_motion.speed_x; +} + +float GDAPI *godot_input_event_mouse_motion_get_speed_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->mouse_motion.speed_y; +} + +godot_int GDAPI *godot_input_event_joypad_motion_get_axis(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->joy_motion.axis; +} + +float GDAPI *godot_input_event_joypad_motion_get_axis_value(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->joy_motion.axis_value; +} + +godot_int GDAPI *godot_input_event_joypad_button_get_button_index(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->joy_button.button_index; +} + +godot_bool GDAPI *godot_input_event_joypad_button_get_pressed(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->joy_button.pressed; +} + +float GDAPI *godot_input_event_joypad_button_get_pressure(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->joy_button.pressure; +} + +godot_int GDAPI *godot_input_event_screen_touch_get_index(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_touch.index; +} + +float GDAPI *godot_input_event_screen_touch_get_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_touch.x; +} + +float GDAPI *godot_input_event_screen_touch_get_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_touch.y; +} + +godot_bool GDAPI *godot_input_event_screen_touch_get_pressed(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_touch.pressed; +} + +godot_int GDAPI *godot_input_event_screen_drag_get_index(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.index; +} + +float GDAPI *godot_input_event_screen_drag_get_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.x; +} + +float GDAPI *godot_input_event_screen_drag_get_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.y; +} + +float GDAPI *godot_input_event_screen_drag_get_relative_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.relative_x; +} + +float GDAPI *godot_input_event_screen_drag_get_relative_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.relative_y; +} + +float GDAPI *godot_input_event_screen_drag_get_speed_x(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.speed_x; +} + +float GDAPI *godot_input_event_screen_drag_get_speed_y(godot_input_event *p_event) { + InputEvent *ie = (InputEvent *)p_event; + return &ie->screen_drag.speed_y; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_input_event.h b/modules/gdnative/godot/godot_input_event.h new file mode 100644 index 0000000000..b0a133e3d9 --- /dev/null +++ b/modules/gdnative/godot/godot_input_event.h @@ -0,0 +1,235 @@ +/*************************************************************************/ +/* godot_input_event.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_INPUT_EVENT_H +#define GODOT_INPUT_EVENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_INPUT_EVENT_TYPE_DEFINED +typedef struct godot_input_event { + uint8_t _dont_touch_that[56]; +} godot_input_event; +#endif + +enum godot_input_event_type { + GODOT_INPUT_EVENT_TYPE_NONE, + GODOT_INPUT_EVENT_TYPE_KEY, + GODOT_INPUT_EVENT_TYPE_MOUSE_MOTION, + GODOT_INPUT_EVENT_TYPE_MOUSE_BUTTON, + GODOT_INPUT_EVENT_TYPE_JOYPAD_MOTION, + GODOT_INPUT_EVENT_TYPE_JOYPAD_BUTTON, + GODOT_INPUT_EVENT_TYPE_SCREEN_TOUCH, + GODOT_INPUT_EVENT_TYPE_SCREEN_DRAG, + GODOT_INPUT_EVENT_TYPE_ACTION, + GODOT_INPUT_EVENT_TYPE_TYPE_MAX +}; +typedef enum godot_input_event_type godot_input_event_type; + +enum { + GODOT_BUTTON_LEFT = 1, + GODOT_BUTTON_RIGHT = 2, + GODOT_BUTTON_MIDDLE = 3, + GODOT_BUTTON_WHEEL_UP = 4, + GODOT_BUTTON_WHEEL_DOWN = 5, + GODOT_BUTTON_WHEEL_LEFT = 6, + GODOT_BUTTON_WHEEL_RIGHT = 7, + GODOT_BUTTON_MASK_LEFT = (1 << (GODOT_BUTTON_LEFT - 1)), + GODOT_BUTTON_MASK_RIGHT = (1 << (GODOT_BUTTON_RIGHT - 1)), + GODOT_BUTTON_MASK_MIDDLE = (1 << (GODOT_BUTTON_MIDDLE - 1)), + +}; + +enum { + + GODOT_JOY_BUTTON_0 = 0, + GODOT_JOY_BUTTON_1 = 1, + GODOT_JOY_BUTTON_2 = 2, + GODOT_JOY_BUTTON_3 = 3, + GODOT_JOY_BUTTON_4 = 4, + GODOT_JOY_BUTTON_5 = 5, + GODOT_JOY_BUTTON_6 = 6, + GODOT_JOY_BUTTON_7 = 7, + GODOT_JOY_BUTTON_8 = 8, + GODOT_JOY_BUTTON_9 = 9, + GODOT_JOY_BUTTON_10 = 10, + GODOT_JOY_BUTTON_11 = 11, + GODOT_JOY_BUTTON_12 = 12, + GODOT_JOY_BUTTON_13 = 13, + GODOT_JOY_BUTTON_14 = 14, + GODOT_JOY_BUTTON_15 = 15, + GODOT_JOY_BUTTON_MAX = 16, + + GODOT_JOY_L = GODOT_JOY_BUTTON_4, + GODOT_JOY_R = GODOT_JOY_BUTTON_5, + GODOT_JOY_L2 = GODOT_JOY_BUTTON_6, + GODOT_JOY_R2 = GODOT_JOY_BUTTON_7, + GODOT_JOY_L3 = GODOT_JOY_BUTTON_8, + GODOT_JOY_R3 = GODOT_JOY_BUTTON_9, + GODOT_JOY_SELECT = GODOT_JOY_BUTTON_10, + GODOT_JOY_START = GODOT_JOY_BUTTON_11, + GODOT_JOY_DPAD_UP = GODOT_JOY_BUTTON_12, + GODOT_JOY_DPAD_DOWN = GODOT_JOY_BUTTON_13, + GODOT_JOY_DPAD_LEFT = GODOT_JOY_BUTTON_14, + GODOT_JOY_DPAD_RIGHT = GODOT_JOY_BUTTON_15, + + // a little history about game controllers (who copied who) + + GODOT_JOY_SNES_B = GODOT_JOY_BUTTON_0, + GODOT_JOY_SNES_A = GODOT_JOY_BUTTON_1, + GODOT_JOY_SNES_Y = GODOT_JOY_BUTTON_2, + GODOT_JOY_SNES_X = GODOT_JOY_BUTTON_3, + + GODOT_JOY_SONY_CIRCLE = GODOT_JOY_SNES_A, + GODOT_JOY_SONY_X = GODOT_JOY_SNES_B, + GODOT_JOY_SONY_SQUARE = GODOT_JOY_SNES_Y, + GODOT_JOY_SONY_TRIANGLE = GODOT_JOY_SNES_X, + + GODOT_JOY_SEGA_B = GODOT_JOY_SNES_A, + GODOT_JOY_SEGA_A = GODOT_JOY_SNES_B, + GODOT_JOY_SEGA_X = GODOT_JOY_SNES_Y, + GODOT_JOY_SEGA_Y = GODOT_JOY_SNES_X, + + GODOT_JOY_XBOX_B = GODOT_JOY_SEGA_B, + GODOT_JOY_XBOX_A = GODOT_JOY_SEGA_A, + GODOT_JOY_XBOX_X = GODOT_JOY_SEGA_X, + GODOT_JOY_XBOX_Y = GODOT_JOY_SEGA_Y, + + GODOT_JOY_DS_A = GODOT_JOY_SNES_A, + GODOT_JOY_DS_B = GODOT_JOY_SNES_B, + GODOT_JOY_DS_X = GODOT_JOY_SNES_X, + GODOT_JOY_DS_Y = GODOT_JOY_SNES_Y, + + GODOT_JOY_WII_C = GODOT_JOY_BUTTON_5, + GODOT_JOY_WII_Z = GODOT_JOY_BUTTON_6, + + GODOT_JOY_WII_MINUS = GODOT_JOY_BUTTON_9, + GODOT_JOY_WII_PLUS = GODOT_JOY_BUTTON_10, + + // end of history + + GODOT_JOY_AXIS_0 = 0, + GODOT_JOY_AXIS_1 = 1, + GODOT_JOY_AXIS_2 = 2, + GODOT_JOY_AXIS_3 = 3, + GODOT_JOY_AXIS_4 = 4, + GODOT_JOY_AXIS_5 = 5, + GODOT_JOY_AXIS_6 = 6, + GODOT_JOY_AXIS_7 = 7, + GODOT_JOY_AXIS_MAX = 8, + + GODOT_JOY_ANALOG_0_X = GODOT_JOY_AXIS_0, + GODOT_JOY_ANALOG_0_Y = GODOT_JOY_AXIS_1, + + GODOT_JOY_ANALOG_1_X = GODOT_JOY_AXIS_2, + GODOT_JOY_ANALOG_1_Y = GODOT_JOY_AXIS_3, + + GODOT_JOY_ANALOG_2_X = GODOT_JOY_AXIS_4, + GODOT_JOY_ANALOG_2_Y = GODOT_JOY_AXIS_5, + + GODOT_JOY_ANALOG_L2 = GODOT_JOY_AXIS_6, + GODOT_JOY_ANALOG_R2 = GODOT_JOY_AXIS_7, +}; + +#include "../godot.h" + +void GDAPI godot_input_event_new(godot_input_event *p_ie); + +godot_bool GDAPI godot_input_event_is_pressed(const godot_input_event *p_ie); +godot_bool GDAPI godot_input_event_is_action(const godot_input_event *p_ie, const godot_string *p_action); +godot_bool GDAPI godot_input_event_is_action_pressed(const godot_input_event *p_ie, const godot_string *p_action); +godot_bool GDAPI godot_input_event_is_action_released(const godot_input_event *p_ie, const godot_string *p_action); +godot_bool GDAPI godot_input_event_is_echo(const godot_input_event *p_ie); +void GDAPI godot_input_event_set_as_action(godot_input_event *p_ie, const godot_string *p_action, const godot_bool p_pressed); + +godot_string GDAPI godot_input_event_as_string(const godot_input_event *p_ie); + +// Note: +// We're returning pointers to the fields in the unions. +// This is because I'm too lazy to write setter functions + +uint32_t GDAPI *godot_input_event_get_id(godot_input_event *p_ie); +godot_input_event_type GDAPI *godot_input_event_get_type(godot_input_event *p_ie); +godot_int GDAPI *godot_input_event_get_device(godot_input_event *p_ie); + +godot_bool GDAPI *godot_input_event_mod_get_alt(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mod_get_ctrl(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mod_get_command(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mod_get_shift(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mod_get_meta(godot_input_event *p_event); + +uint32_t GDAPI *godot_input_event_key_get_scancode(godot_input_event *p_event); +uint32_t GDAPI *godot_input_event_key_get_unicode(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_key_get_pressed(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_key_get_echo(godot_input_event *p_event); + +float GDAPI *godot_input_event_mouse_get_x(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_get_y(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_get_global_x(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_get_global_y(godot_input_event *p_event); +godot_int GDAPI *godot_input_event_mouse_get_button_mask(godot_input_event *p_event); + +godot_int GDAPI *godot_input_event_mouse_button_get_button_index(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mouse_button_get_pressed(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_mouse_button_get_doubleclick(godot_input_event *p_event); + +float GDAPI *godot_input_event_mouse_motion_get_relative_x(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_motion_get_relative_y(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_motion_get_speed_x(godot_input_event *p_event); +float GDAPI *godot_input_event_mouse_motion_get_speed_y(godot_input_event *p_event); + +godot_int GDAPI *godot_input_event_joypad_motion_get_axis(godot_input_event *p_event); +float GDAPI *godot_input_event_joypad_motion_get_axis_value(godot_input_event *p_event); + +godot_int GDAPI *godot_input_event_joypad_button_get_button_index(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_joypad_button_get_pressed(godot_input_event *p_event); +float GDAPI *godot_input_event_joypad_button_get_pressure(godot_input_event *p_event); + +godot_int GDAPI *godot_input_event_screen_touch_get_index(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_touch_get_x(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_touch_get_y(godot_input_event *p_event); +godot_bool GDAPI *godot_input_event_screen_touch_get_pressed(godot_input_event *p_event); + +godot_int GDAPI *godot_input_event_screen_drag_get_index(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_x(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_y(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_relative_x(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_relative_y(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_speed_x(godot_input_event *p_event); +float GDAPI *godot_input_event_screen_drag_get_speed_y(godot_input_event *p_event); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_INPUT_EVENT_H diff --git a/modules/gdnative/godot/godot_node_path.cpp b/modules/gdnative/godot/godot_node_path.cpp new file mode 100644 index 0000000000..a2c9e11699 --- /dev/null +++ b/modules/gdnative/godot/godot_node_path.cpp @@ -0,0 +1,120 @@ +/*************************************************************************/ +/* godot_node_path.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_node_path.h" + +#include "path_db.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _node_path_api_anchor() { +} + +#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) + +// @Bug ? +// Do I need to memnew_placement when returning strings? + +void GDAPI godot_node_path_new(godot_node_path *p_np, const godot_string *p_from) { + NodePath *np = (NodePath *)p_np; + String *from = (String *)p_from; + memnew_placement_custom(np, NodePath, NodePath(*from)); +} + +void GDAPI godot_node_path_copy(godot_node_path *p_np, const godot_node_path *p_from) { + NodePath *np = (NodePath *)p_np; + NodePath *from = (NodePath *)p_from; + *np = *from; +} + +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_np, const godot_int p_idx) { + const NodePath *np = (const NodePath *)p_np; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = np->get_name(p_idx); + return str; +} + +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + return np->get_name_count(); +} + +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = np->get_property(); + return str; +} + +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_np, const godot_int p_idx) { + const NodePath *np = (const NodePath *)p_np; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = np->get_subname(p_idx); + return str; +} + +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + return np->get_subname_count(); +} + +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + return np->is_absolute(); +} + +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + return np->is_empty(); +} + +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_np) { + const NodePath *np = (const NodePath *)p_np; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = *np; + return str; +} + +void GDAPI godot_node_path_destroy(godot_node_path *p_np) { + ((NodePath *)p_np)->~NodePath(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_node_path.h b/modules/gdnative/godot/godot_node_path.h new file mode 100644 index 0000000000..c5f313d190 --- /dev/null +++ b/modules/gdnative/godot/godot_node_path.h @@ -0,0 +1,68 @@ +/*************************************************************************/ +/* godot_node_path.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_NODE_PATH_H +#define GODOT_NODE_PATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED +typedef struct godot_node_path { + uint8_t _dont_touch_that[8]; +} godot_node_path; +#endif + +#include "../godot.h" + +void GDAPI godot_node_path_new(godot_node_path *p_np, const godot_string *p_from); +void GDAPI godot_node_path_copy(godot_node_path *p_np, const godot_node_path *p_from); + +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_np, const godot_int p_idx); +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_np); + +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_np); +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_np, const godot_int p_idx); +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_np); + +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_np); +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_np); + +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_np); + +void GDAPI godot_node_path_destroy(godot_node_path *p_np); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_NODE_PATH_H diff --git a/modules/gdnative/godot/godot_plane.cpp b/modules/gdnative/godot/godot_plane.cpp new file mode 100644 index 0000000000..38329ef709 --- /dev/null +++ b/modules/gdnative/godot/godot_plane.cpp @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* godot_plane.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_plane.h" + +#include "math/plane.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _plane_api_anchor() { +} + +void GDAPI godot_plane_new(godot_plane *p_pl) { + Plane *pl = (Plane *)p_pl; + *pl = Plane(); +} + +void GDAPI godot_plane_new_with_normal(godot_plane *p_pl, const godot_vector3 *p_normal, const godot_real p_d) { + Plane *pl = (Plane *)p_pl; + const Vector3 *normal = (const Vector3 *)p_normal; + *pl = Plane(*normal, p_d); +} + +void GDAPI godot_plane_set_normal(godot_plane *p_pl, const godot_vector3 *p_normal) { + Plane *pl = (Plane *)p_pl; + const Vector3 *normal = (const Vector3 *)p_normal; + pl->set_normal(*normal); +} + +godot_vector3 godot_plane_get_normal(const godot_plane *p_pl) { + const Plane *pl = (const Plane *)p_pl; + const Vector3 normal = pl->get_normal(); + godot_vector3 *v3 = (godot_vector3 *)&normal; + return *v3; +} + +void GDAPI godot_plane_set_d(godot_plane *p_pl, const godot_real p_d) { + Plane *pl = (Plane *)p_pl; + pl->d = p_d; +} + +godot_real GDAPI godot_plane_get_d(const godot_plane *p_pl) { + const Plane *pl = (const Plane *)p_pl; + return pl->d; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_plane.h b/modules/gdnative/godot/godot_plane.h new file mode 100644 index 0000000000..c98e45c9cb --- /dev/null +++ b/modules/gdnative/godot/godot_plane.h @@ -0,0 +1,66 @@ +/*************************************************************************/ +/* godot_plane.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_PLANE_H +#define GODOT_PLANE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED +typedef struct godot_plane { + uint8_t _dont_touch_that[16]; +} godot_plane; +#endif + +#include "godot_vector3.h" + +void GDAPI godot_plane_new(godot_plane *p_pl); +void GDAPI godot_plane_new_with_normal(godot_plane *p_pl, const godot_vector3 *p_normal, const godot_real p_d); + +// @Incomplete +// These are additional valid constructors +// _FORCE_INLINE_ Plane(const Vector3 &p_normal, real_t p_d); +// _FORCE_INLINE_ Plane(const Vector3 &p_point, const Vector3& p_normal); +// _FORCE_INLINE_ Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE); + +void GDAPI godot_plane_set_normal(godot_plane *p_pl, const godot_vector3 *p_normal); +godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_pl); + +godot_real GDAPI godot_plane_get_d(const godot_plane *p_pl); +void GDAPI godot_plane_set_d(godot_plane *p_pl, const godot_real p_d); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_PLANE_H diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp new file mode 100644 index 0000000000..93e9a9e9dc --- /dev/null +++ b/modules/gdnative/godot/godot_pool_arrays.cpp @@ -0,0 +1,587 @@ +/*************************************************************************/ +/* godot_pool_arrays.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_pool_arrays.h" + +#include "array.h" +#include "dvector.h" +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _pool_arrays_api_anchor() { +} + +#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) + +// byte + +void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + memnew_placement(pba, PoolVector<uint8_t>); +} + +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<uint8_t>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->append(p_data); +} + +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_pba, const godot_pool_byte_array *p_array) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<uint8_t> *array = (PoolVector<uint8_t> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + return pba->insert(p_idx, p_data); +} + +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_pba) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_pba, const uint8_t p_data) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->push_back(p_data); +} + +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_pba, const godot_int p_idx) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_pba, const godot_int p_size) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + pba->set(p_idx, p_data); +} + +uint8_t GDAPI godot_pool_byte_array_get(godot_pool_byte_array *p_pba, const godot_int p_idx) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + return pba->get(p_idx); +} + +godot_int GDAPI godot_pool_byte_array_size(godot_pool_byte_array *p_pba) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) { + ((PoolVector<uint8_t> *)p_pba)->~PoolVector(); +} + +// int + +void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + memnew_placement(pba, PoolVector<uint8_t>); +} + +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<uint8_t>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pba, const godot_int p_data) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->append(p_data); +} + +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_pba, const godot_pool_int_array *p_array) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + PoolVector<godot_int> *array = (PoolVector<godot_int> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_pba, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + return pba->insert(p_idx, p_data); +} + +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_pba) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_pba, const godot_int p_data) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->push_back(p_data); +} + +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_pba, const godot_int p_idx) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_pba, const godot_int p_size) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_pba, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->set(p_idx, p_data); +} + +godot_int GDAPI godot_pool_int_array_get(godot_pool_int_array *p_pba, const godot_int p_idx) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + return pba->get(p_idx); +} + +godot_int GDAPI godot_pool_int_array_size(godot_pool_int_array *p_pba) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) { + ((PoolVector<godot_int> *)p_pba)->~PoolVector(); +} + +// real + +void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + memnew_placement(pba, PoolVector<uint8_t>); +} + +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) { + PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<uint8_t>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pba, const godot_real p_data) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + pba->append(p_data); +} + +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_pba, const godot_pool_real_array *p_array) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + PoolVector<godot_real> *array = (PoolVector<godot_real> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_pba, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + return pba->insert(p_idx, p_data); +} + +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_pba) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_pba, const godot_real p_data) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + pba->push_back(p_data); +} + +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_pba, const godot_int p_idx) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_pba, const godot_int p_size) { + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_pba, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + pba->set(p_idx, p_data); +} + +godot_real GDAPI godot_pool_real_array_get(godot_pool_real_array *p_pba, const godot_int p_idx) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + return pba->get(p_idx); +} + +godot_int GDAPI godot_pool_real_array_size(godot_pool_real_array *p_pba) { + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pba) { + ((PoolVector<godot_real> *)p_pba)->~PoolVector(); +} + +// string + +void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + memnew_placement(pba, PoolVector<String>); +} + +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<String>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_pba, const godot_string *p_data) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + String &s = *(String *)p_data; + pba->append(s); +} + +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_pba, const godot_pool_string_array *p_array) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + PoolVector<String> *array = (PoolVector<String> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_pba, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + String &s = *(String *)p_data; + return pba->insert(p_idx, s); +} + +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_pba) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_pba, const godot_string *p_data) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + String &s = *(String *)p_data; + pba->push_back(s); +} + +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_pba, const godot_int p_idx) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_pba, const godot_int p_size) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_pba, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + String &s = *(String *)p_data; + pba->set(p_idx, s); +} + +godot_string GDAPI godot_pool_string_array_get(godot_pool_string_array *p_pba, const godot_int p_idx) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = pba->get(p_idx); + return str; +} + +godot_int GDAPI godot_pool_string_array_size(godot_pool_string_array *p_pba) { + PoolVector<String> *pba = (PoolVector<String> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_pba) { + ((PoolVector<String> *)p_pba)->~PoolVector(); +} + +// vector2 + +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + memnew_placement(pba, PoolVector<Vector2>); +} + +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<Vector2>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pba, const godot_vector2 *p_data) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + Vector2 &s = *(Vector2 *)p_data; + pba->append(s); +} + +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_pba, const godot_pool_vector2_array *p_array) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + PoolVector<Vector2> *array = (PoolVector<Vector2> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_pba, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + Vector2 &s = *(Vector2 *)p_data; + return pba->insert(p_idx, s); +} + +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_pba) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_pba, const godot_vector2 *p_data) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + Vector2 &s = *(Vector2 *)p_data; + pba->push_back(s); +} + +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_pba, const godot_int p_idx) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_pba, const godot_int p_size) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_pba, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + Vector2 &s = *(Vector2 *)p_data; + pba->set(p_idx, s); +} + +godot_vector2 GDAPI godot_pool_vector2_array_get(godot_pool_vector2_array *p_pba, const godot_int p_idx) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + godot_vector2 v; + Vector2 *s = (Vector2 *)&v; + *s = pba->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_vector2_array_size(godot_pool_vector2_array *p_pba) { + PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pba) { + ((PoolVector<Vector2> *)p_pba)->~PoolVector(); +} + +// vector3 + +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + memnew_placement(pba, PoolVector<Vector3>); +} + +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<Vector3>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pba, const godot_vector3 *p_data) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + Vector3 &s = *(Vector3 *)p_data; + pba->append(s); +} + +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_pba, const godot_pool_vector3_array *p_array) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + PoolVector<Vector3> *array = (PoolVector<Vector3> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_pba, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + Vector3 &s = *(Vector3 *)p_data; + return pba->insert(p_idx, s); +} + +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_pba) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_pba, const godot_vector3 *p_data) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + Vector3 &s = *(Vector3 *)p_data; + pba->push_back(s); +} + +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_pba, const godot_int p_idx) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_pba, const godot_int p_size) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_pba, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + Vector3 &s = *(Vector3 *)p_data; + pba->set(p_idx, s); +} + +godot_vector3 GDAPI godot_pool_vector3_array_get(godot_pool_vector3_array *p_pba, const godot_int p_idx) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + godot_vector3 v; + Vector3 *s = (Vector3 *)&v; + *s = pba->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_vector3_array_size(godot_pool_vector3_array *p_pba) { + PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pba) { + ((PoolVector<Vector3> *)p_pba)->~PoolVector(); +} + +// color + +void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + memnew_placement(pba, PoolVector<Color>); +} + +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + Array *a = (Array *)p_a; + memnew_placement(pba, PoolVector<Color>); + + pba->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + pba->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pba, const godot_color *p_data) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + Color &s = *(Color *)p_data; + pba->append(s); +} + +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_pba, const godot_pool_color_array *p_array) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + PoolVector<Color> *array = (PoolVector<Color> *)p_array; + pba->append_array(*array); +} + +int GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_pba, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + Color &s = *(Color *)p_data; + return pba->insert(p_idx, s); +} + +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_pba) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + pba->invert(); +} + +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_pba, const godot_color *p_data) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + Color &s = *(Color *)p_data; + pba->push_back(s); +} + +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_pba, const godot_int p_idx) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + pba->remove(p_idx); +} + +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_pba, const godot_int p_size) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + pba->resize(p_size); +} + +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_pba, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + Color &s = *(Color *)p_data; + pba->set(p_idx, s); +} + +godot_color GDAPI godot_pool_color_array_get(godot_pool_color_array *p_pba, const godot_int p_idx) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + godot_color v; + Color *s = (Color *)&v; + *s = pba->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_color_array_size(godot_pool_color_array *p_pba) { + PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; + return pba->size(); +} + +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_pba) { + ((PoolVector<Color> *)p_pba)->~PoolVector(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h new file mode 100644 index 0000000000..ec9185f6f3 --- /dev/null +++ b/modules/gdnative/godot/godot_pool_arrays.h @@ -0,0 +1,285 @@ +/*************************************************************************/ +/* godot_pool_arrays.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_POOL_ARRAYS_H +#define GODOT_POOL_ARRAYS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +/////// PoolByteArray + +#ifndef GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED +typedef struct godot_pool_byte_array { + uint8_t _dont_touch_that[8]; +} godot_pool_byte_array; +#endif + +/////// PoolIntArray + +#ifndef GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED +typedef struct godot_pool_int_array { + uint8_t _dont_touch_that[8]; +} godot_pool_int_array; +#endif + +/////// PoolRealArray + +#ifndef GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED +typedef struct godot_pool_real_array { + uint8_t _dont_touch_that[8]; +} godot_pool_real_array; +#endif + +/////// PoolStringArray + +#ifndef GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED +typedef struct godot_pool_string_array { + uint8_t _dont_touch_that[8]; +} godot_pool_string_array; +#endif + +/////// PoolVector2Array + +#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED +typedef struct godot_pool_vector2_array { + uint8_t _dont_touch_that[8]; +} godot_pool_vector2_array; +#endif + +/////// PoolVector3Array + +#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED +typedef struct godot_pool_vector3_array { + uint8_t _dont_touch_that[8]; +} godot_pool_vector3_array; +#endif + +/////// PoolColorArray + +#ifndef GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED +typedef struct godot_pool_color_array { + uint8_t _dont_touch_that[8]; +} godot_pool_color_array; +#endif + +#include "../godot.h" + +#include "godot_array.h" + +// byte + +void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a); + +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_pba, const godot_pool_byte_array *p_array); + +int GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_pba); + +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_pba, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_pba, const godot_int p_idx); + +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_pba, const godot_int p_size); + +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data); +uint8_t GDAPI godot_pool_byte_array_get(godot_pool_byte_array *p_pba, const godot_int p_idx); + +godot_int GDAPI godot_pool_byte_array_size(godot_pool_byte_array *p_pba); + +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba); + +// int + +void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a); + +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data); + +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_pia, const godot_pool_int_array *p_array); + +int GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_pia, const godot_int p_idx, const godot_int p_data); + +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_pia); + +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_pia, const godot_int p_data); + +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_pia, const godot_int p_idx); + +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_pia, const godot_int p_size); + +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_pia, const godot_int p_idx, const godot_int p_data); +godot_int GDAPI godot_pool_int_array_get(godot_pool_int_array *p_pia, const godot_int p_idx); + +godot_int GDAPI godot_pool_int_array_size(godot_pool_int_array *p_pia); + +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia); + +// real + +void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a); + +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data); + +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_pra, const godot_pool_real_array *p_array); + +int GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_pra, const godot_int p_idx, const godot_real p_data); + +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_pra); + +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_pra, const godot_real p_data); + +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_pra, const godot_int p_idx); + +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_pra, const godot_int p_size); + +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_pra, const godot_int p_idx, const godot_real p_data); +godot_real GDAPI godot_pool_real_array_get(godot_pool_real_array *p_pra, const godot_int p_idx); + +godot_int GDAPI godot_pool_real_array_size(godot_pool_real_array *p_pra); + +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra); + +// string + +void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a); + +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data); + +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_psa, const godot_pool_string_array *p_array); + +int GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_psa, const godot_int p_idx, const godot_string *p_data); + +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_psa); + +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_psa, const godot_string *p_data); + +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_psa, const godot_int p_idx); + +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_psa, const godot_int p_size); + +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_psa, const godot_int p_idx, const godot_string *p_data); +godot_string GDAPI godot_pool_string_array_get(godot_pool_string_array *p_psa, const godot_int p_idx); + +godot_int GDAPI godot_pool_string_array_size(godot_pool_string_array *p_psa); + +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa); + +// vector2 + +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a); + +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_pv2a, const godot_pool_vector2_array *p_array); + +int GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_pv2a, const godot_int p_idx, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_pv2a); + +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_pv2a, const godot_int p_idx); + +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_pv2a, const godot_int p_size); + +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_pv2a, const godot_int p_idx, const godot_vector2 *p_data); +godot_vector2 GDAPI godot_pool_vector2_array_get(godot_pool_vector2_array *p_pv2a, const godot_int p_idx); + +godot_int GDAPI godot_pool_vector2_array_size(godot_pool_vector2_array *p_pv2a); + +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a); + +// vector3 + +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a); + +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_pv3a, const godot_pool_vector3_array *p_array); + +int GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_pv3a, const godot_int p_idx, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_pv3a); + +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_pv3a, const godot_int p_idx); + +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_pv3a, const godot_int p_size); + +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_pv3a, const godot_int p_idx, const godot_vector3 *p_data); +godot_vector3 GDAPI godot_pool_vector3_array_get(godot_pool_vector3_array *p_pv3a, const godot_int p_idx); + +godot_int GDAPI godot_pool_vector3_array_size(godot_pool_vector3_array *p_pv3a); + +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a); + +// color + +void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a); + +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data); + +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_pca, const godot_pool_color_array *p_array); + +int GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_pca, const godot_int p_idx, const godot_color *p_data); + +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_pca); + +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_pca, const godot_color *p_data); + +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_pca, const godot_int p_idx); + +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_pca, const godot_int p_size); + +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_pca, const godot_int p_idx, const godot_color *p_data); +godot_color GDAPI godot_pool_color_array_get(godot_pool_color_array *p_pca, const godot_int p_idx); + +godot_int GDAPI godot_pool_color_array_size(godot_pool_color_array *p_pca); + +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_pca); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_POOL_ARRAYS_H diff --git a/modules/gdnative/godot/godot_quat.cpp b/modules/gdnative/godot/godot_quat.cpp new file mode 100644 index 0000000000..7c3a71dfc0 --- /dev/null +++ b/modules/gdnative/godot/godot_quat.cpp @@ -0,0 +1,106 @@ +/*************************************************************************/ +/* godot_quat.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_quat.h" + +#include "math/quat.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _quat_api_anchor() { +} + +void GDAPI godot_quat_new(godot_quat *p_quat) { + Quat *quat = (Quat *)p_quat; + *quat = Quat(); +} + +void GDAPI godot_quat_new_with_elements(godot_quat *p_quat, const godot_real x, const godot_real y, const godot_real z, const godot_real w) { + Quat *quat = (Quat *)p_quat; + *quat = Quat(x, y, z, w); +} + +void GDAPI godot_quat_new_with_rotation(godot_quat *p_quat, const godot_vector3 *p_axis, const godot_real p_angle) { + Quat *quat = (Quat *)p_quat; + const Vector3 *axis = (const Vector3 *)p_axis; + *quat = Quat(*axis, p_angle); +} + +void GDAPI godot_quat_new_with_shortest_arc(godot_quat *p_quat, const godot_vector3 *p_v0, const godot_vector3 *p_v1) { + Quat *quat = (Quat *)p_quat; + const Vector3 *v0 = (const Vector3 *)p_v0; + const Vector3 *v1 = (const Vector3 *)p_v1; + *quat = Quat(*v0, *v1); +} + +godot_vector3 GDAPI godot_quat_get_euler(const godot_quat *p_quat) { + Quat *quat = (Quat *)p_quat; + Vector3 euler = quat->get_euler(); + return *(godot_vector3 *)&euler; +} + +void GDAPI godot_quat_set_euler(godot_quat *p_quat, const godot_vector3 *p_euler) { + Quat *quat = (Quat *)p_quat; + const Vector3 *euler = (const Vector3 *)p_euler; + quat->set_euler(*euler); +} + +godot_real GDAPI *godot_quat_index(godot_quat *p_quat, const godot_int p_idx) { + Quat *quat = (Quat *)p_quat; + switch (p_idx) { + case 0: + return &quat->x; + case 1: + return &quat->y; + case 2: + return &quat->z; + default: + return &quat->y; + } +} + +godot_real GDAPI godot_quat_const_index(const godot_quat *p_quat, const godot_int p_idx) { + const Quat *quat = (const Quat *)p_quat; + switch (p_idx) { + case 0: + return quat->x; + case 1: + return quat->y; + case 2: + return quat->z; + default: + return quat->y; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_quat.h b/modules/gdnative/godot/godot_quat.h new file mode 100644 index 0000000000..35b1acd3ed --- /dev/null +++ b/modules/gdnative/godot/godot_quat.h @@ -0,0 +1,62 @@ +/*************************************************************************/ +/* godot_quat.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_QUAT_H +#define GODOT_QUAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED +typedef struct godot_quat { + uint8_t _dont_touch_that[16]; +} godot_quat; +#endif + +#include "../godot.h" + +void GDAPI godot_quat_new(godot_quat *p_quat); +void GDAPI godot_quat_new_with_elements(godot_quat *p_quat, const godot_real x, const godot_real y, const godot_real z, const godot_real w); +void GDAPI godot_quat_new_with_rotation(godot_quat *p_quat, const godot_vector3 *p_axis, const godot_real p_angle); +void GDAPI godot_quat_new_with_shortest_arc(godot_quat *p_quat, const godot_vector3 *p_v0, const godot_vector3 *p_v1); + +godot_vector3 GDAPI godot_quat_get_euler(const godot_quat *p_quat); +void GDAPI godot_quat_set_euler(godot_quat *p_quat, const godot_vector3 *p_euler); + +godot_real GDAPI *godot_quat_index(godot_quat *p_quat, const godot_int p_idx); +godot_real GDAPI godot_quat_const_index(const godot_quat *p_quat, const godot_int p_idx); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_QUAT_H diff --git a/modules/gdnative/godot/godot_rect2.cpp b/modules/gdnative/godot/godot_rect2.cpp new file mode 100644 index 0000000000..b19096b79e --- /dev/null +++ b/modules/gdnative/godot/godot_rect2.cpp @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* godot_rect2.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_rect2.h" + +#include "math/math_2d.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rect2_api_anchor() { +} + +void GDAPI godot_rect2_new(godot_rect2 *p_rect) { + Rect2 *rect = (Rect2 *)p_rect; + *rect = Rect2(); +} + +void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *p_rect, const godot_vector2 *p_pos, const godot_vector2 *p_size) { + Rect2 *rect = (Rect2 *)p_rect; + const Vector2 *pos = (const Vector2 *)p_pos; + const Vector2 *size = (const Vector2 *)p_size; + *rect = Rect2(*pos, *size); +} + +godot_vector2 GDAPI *godot_rect2_get_pos(godot_rect2 *p_rect) { + Rect2 *rect = (Rect2 *)p_rect; + return (godot_vector2 *)&rect->pos; +} + +void GDAPI godot_rect2_set_pos(godot_rect2 *p_rect, const godot_vector2 *p_pos) { + Rect2 *rect = (Rect2 *)p_rect; + const Vector2 *pos = (const Vector2 *)p_pos; + rect->pos = *pos; +} + +godot_vector2 GDAPI *godot_rect2_get_size(godot_rect2 *p_rect) { + Rect2 *rect = (Rect2 *)p_rect; + return (godot_vector2 *)&rect->size; +} + +void GDAPI godot_rect2_set_size(godot_rect2 *p_rect, const godot_vector2 *p_size) { + Rect2 *rect = (Rect2 *)p_rect; + const Vector2 *size = (const Vector2 *)p_size; + rect->size = *size; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_rect2.h b/modules/gdnative/godot/godot_rect2.h new file mode 100644 index 0000000000..e9e4a26897 --- /dev/null +++ b/modules/gdnative/godot/godot_rect2.h @@ -0,0 +1,60 @@ +/*************************************************************************/ +/* godot_rect2.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_RECT2_H +#define GODOT_RECT2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED +typedef struct godot_rect2 { + uint8_t _dont_touch_that[16]; +} godot_rect2; +#endif + +#include "../godot.h" + +void GDAPI godot_rect2_new(godot_rect2 *p_rect); +void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *p_rect, const godot_vector2 *p_pos, const godot_vector2 *p_size); + +godot_vector2 GDAPI *godot_rect2_get_pos(godot_rect2 *p_rect); +void GDAPI godot_rect2_set_pos(godot_rect2 *p_rect, const godot_vector2 *p_pos); + +godot_vector2 GDAPI *godot_rect2_get_size(godot_rect2 *p_rect); +void GDAPI godot_rect2_set_size(godot_rect2 *p_rect, const godot_vector2 *p_size); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RECT3_H diff --git a/modules/gdnative/godot/godot_rect3.cpp b/modules/gdnative/godot/godot_rect3.cpp new file mode 100644 index 0000000000..96c5d17b1a --- /dev/null +++ b/modules/gdnative/godot/godot_rect3.cpp @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* godot_rect3.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_rect3.h" + +#include "math/rect3.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rect3_api_anchor() { +} + +void GDAPI godot_rect3_new(godot_rect3 *p_rect) { + Rect3 *rect = (Rect3 *)p_rect; + *rect = Rect3(); +} + +void GDAPI godot_rect3_new_with_pos_and_size(godot_rect3 *p_rect, const godot_vector3 *p_pos, const godot_vector3 *p_size) { + Rect3 *rect = (Rect3 *)p_rect; + const Vector3 *pos = (const Vector3 *)p_pos; + const Vector3 *size = (const Vector3 *)p_size; + *rect = Rect3(*pos, *size); +} + +godot_vector3 GDAPI *godot_rect3_get_pos(godot_rect3 *p_rect) { + Rect3 *rect = (Rect3 *)p_rect; + return (godot_vector3 *)&rect->pos; +} + +void GDAPI godot_rect3_set_pos(godot_rect3 *p_rect, const godot_vector3 *p_pos) { + Rect3 *rect = (Rect3 *)p_rect; + const Vector3 *pos = (const Vector3 *)p_pos; + rect->pos = *pos; +} + +godot_vector3 GDAPI *godot_rect3_get_size(godot_rect3 *p_rect) { + Rect3 *rect = (Rect3 *)p_rect; + return (godot_vector3 *)&rect->size; +} + +void GDAPI godot_rect3_set_size(godot_rect3 *p_rect, const godot_vector3 *p_size) { + Rect3 *rect = (Rect3 *)p_rect; + const Vector3 *size = (const Vector3 *)p_size; + rect->size = *size; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_rect3.h b/modules/gdnative/godot/godot_rect3.h new file mode 100644 index 0000000000..562ac8379e --- /dev/null +++ b/modules/gdnative/godot/godot_rect3.h @@ -0,0 +1,60 @@ +/*************************************************************************/ +/* godot_rect3.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_RECT3_H +#define GODOT_RECT3_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED +typedef struct godot_rect3 { + uint8_t _dont_touch_that[24]; +} godot_rect3; +#endif + +#include "../godot.h" + +void GDAPI godot_rect3_new(godot_rect3 *p_rect); +void GDAPI godot_rect3_new_with_pos_and_size(godot_rect3 *p_rect, const godot_vector3 *p_pos, const godot_vector3 *p_size); + +godot_vector3 GDAPI *godot_rect3_get_pos(godot_rect3 *p_rect); +void GDAPI godot_rect3_set_pos(godot_rect3 *p_rect, const godot_vector3 *p_pos); + +godot_vector3 GDAPI *godot_rect3_get_size(godot_rect3 *p_rect); +void GDAPI godot_rect3_set_size(godot_rect3 *p_rect, const godot_vector3 *p_size); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RECT3_H diff --git a/modules/gdnative/godot/godot_rid.cpp b/modules/gdnative/godot/godot_rid.cpp new file mode 100644 index 0000000000..fff31e3992 --- /dev/null +++ b/modules/gdnative/godot/godot_rid.cpp @@ -0,0 +1,65 @@ +/*************************************************************************/ +/* godot_rid.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_rid.h" + +#include "object.h" +#include "resource.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rid_api_anchor() { +} + +void GDAPI godot_rid_new(godot_rid *p_rid, godot_object *p_from) { + + Resource *res_from = ((Object *)p_from)->cast_to<Resource>(); + + RID *rid = (RID *)p_rid; + memnew_placement(rid, RID); + + if (res_from) { + *rid = RID(res_from->get_rid()); + } +} + +uint32_t GDAPI godot_rid_get_rid(const godot_rid *p_rid) { + RID *rid = (RID *)p_rid; + return rid->get_id(); +} + +void GDAPI godot_rid_destroy(godot_rid *p_rid) { + ((RID *)p_rid)->~RID(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_rid.h b/modules/gdnative/godot/godot_rid.h new file mode 100644 index 0000000000..e00c8f89ad --- /dev/null +++ b/modules/gdnative/godot/godot_rid.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* godot_rid.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_RID_H +#define GODOT_RID_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_RID_TYPE_DEFINED +typedef struct godot_rid { + uint8_t _dont_touch_that[8]; +} godot_rid; +#endif + +#include "../godot.h" + +void GDAPI godot_rid_new(godot_rid *p_rid, godot_object *p_from); + +uint32_t GDAPI godot_rid_get_rid(const godot_rid *p_rid); + +void GDAPI godot_rid_destroy(godot_rid *p_rid); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RID_H diff --git a/modules/gdnative/godot/godot_string.cpp b/modules/gdnative/godot/godot_string.cpp new file mode 100644 index 0000000000..92c0b04041 --- /dev/null +++ b/modules/gdnative/godot/godot_string.cpp @@ -0,0 +1,117 @@ +/*************************************************************************/ +/* godot_string.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_string.h" + +#include "string_db.h" +#include "ustring.h" + +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void _string_api_anchor() { +} + +void GDAPI godot_string_new(godot_string *p_str) { + String *p = (String *)p_str; + memnew_placement(p, String); + // *p = String(); // useless here +} + +void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, const int p_size) { + String *p = (String *)p_str; + memnew_placement(p, String); + *p = String::utf8(p_contents, p_size); +} + +void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size) { + String *p = (String *)p_str; + if (p_size != NULL) { + *p_size = p->utf8().length(); + } + if (p_dest != NULL) { + memcpy(p_dest, p->utf8().get_data(), *p_size); + } +} + +void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_string *p_src) { + String *dest = (String *)p_dest; + String *src = (String *)p_src; + + *dest = *src; +} + +wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx) { + String *s = (String *)p_str; + return &(s->operator[](p_idx)); +} + +const char GDAPI *godot_string_c_str(const godot_string *p_str) { + const String *s = (const String *)p_str; + return s->utf8().get_data(); +} + +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_str) { + const String *s = (const String *)p_str; + return s->c_str(); +} + +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b) { + String *a = (String *)p_a; + String *b = (String *)p_b; + return *a == *b; +} + +godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b) { + String *a = (String *)p_a; + String *b = (String *)p_b; + return *a < *b; +} + +void GDAPI godot_string_operator_plus(godot_string *p_dest, const godot_string *p_a, const godot_string *p_b) { + String *dest = (String *)p_dest; + const String *a = (String *)p_a; + const String *b = (String *)p_b; + + String tmp = *a + *b; + godot_string_new(p_dest); + *dest = tmp; +} + +void GDAPI godot_string_destroy(godot_string *p_str) { + String *p = (String *)p_str; + p->~String(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_string.h b/modules/gdnative/godot/godot_string.h new file mode 100644 index 0000000000..83ed5d6ec1 --- /dev/null +++ b/modules/gdnative/godot/godot_string.h @@ -0,0 +1,73 @@ +/*************************************************************************/ +/* godot_string.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_STRING_H +#define GODOT_STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include <wchar.h> + +#ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED +typedef struct godot_string { + uint8_t _dont_touch_that[8]; +} godot_string; +#endif + +#include "../godot.h" + +void GDAPI godot_string_new(godot_string *p_str); +void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, const int p_size); + +void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size); + +void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_string *p_src); + +wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx); +const char GDAPI *godot_string_c_str(const godot_string *p_str); +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_str); + +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b); +godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b); +void GDAPI godot_string_operator_plus(godot_string *p_dest, const godot_string *p_a, const godot_string *p_b); + +// @Incomplete +// hmm, I guess exposing the whole API doesn't make much sense +// since the language used in the library has its own string funcs + +void GDAPI godot_string_destroy(godot_string *p_str); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_STRING_H diff --git a/modules/gdnative/godot/godot_transform.cpp b/modules/gdnative/godot/godot_transform.cpp new file mode 100644 index 0000000000..681c2b049a --- /dev/null +++ b/modules/gdnative/godot/godot_transform.cpp @@ -0,0 +1,71 @@ +/*************************************************************************/ +/* godot_transform.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_transform.h" + +#include "math/transform.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _transform_api_anchor() { +} + +void GDAPI godot_transform_new(godot_transform *p_trans) { + Transform *trans = (Transform *)p_trans; + *trans = Transform(); +} + +void GDAPI godot_transform_new_with_basis(godot_transform *p_trans, const godot_basis *p_basis) { + Transform *trans = (Transform *)p_trans; + const Basis *basis = (const Basis *)p_basis; + *trans = Transform(*basis); +} + +void GDAPI godot_transform_new_with_basis_origin(godot_transform *p_trans, const godot_basis *p_basis, const godot_vector3 *p_origin) { + Transform *trans = (Transform *)p_trans; + const Basis *basis = (const Basis *)p_basis; + const Vector3 *origin = (const Vector3 *)p_origin; + *trans = Transform(*basis, *origin); +} + +godot_basis GDAPI *godot_transform_get_basis(godot_transform *p_trans) { + Transform *trans = (Transform *)p_trans; + return (godot_basis *)&trans->basis; +} + +godot_vector3 GDAPI *godot_transform_get_origin(godot_transform *p_trans) { + Transform *trans = (Transform *)p_trans; + return (godot_vector3 *)&trans->origin; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_transform.h b/modules/gdnative/godot/godot_transform.h new file mode 100644 index 0000000000..93817ffbf2 --- /dev/null +++ b/modules/gdnative/godot/godot_transform.h @@ -0,0 +1,58 @@ +/*************************************************************************/ +/* godot_transform.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_TRANSFORM_H +#define GODOT_TRANSFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED +typedef struct godot_transform { + uint8_t _dont_touch_that[48]; +} godot_transform; +#endif + +#include "../godot.h" + +void GDAPI godot_transform_new(godot_transform *p_trans); +void GDAPI godot_transform_new_with_basis(godot_transform *p_trans, const godot_basis *p_basis); +void GDAPI godot_transform_new_with_basis_origin(godot_transform *p_trans, const godot_basis *p_basis, const godot_vector3 *p_origin); + +godot_basis GDAPI *godot_transform_get_basis(godot_transform *p_trans); +godot_vector3 GDAPI *godot_transform_get_origin(godot_transform *p_trans); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_TRANSFORM_H diff --git a/modules/gdnative/godot/godot_transform2d.cpp b/modules/gdnative/godot/godot_transform2d.cpp new file mode 100644 index 0000000000..ffc7167559 --- /dev/null +++ b/modules/gdnative/godot/godot_transform2d.cpp @@ -0,0 +1,88 @@ +/*************************************************************************/ +/* godot_transform2d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_transform2d.h" + +#include "../godot.h" + +#include "math/math_2d.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _transform2d_api_anchor() { +} + +void GDAPI godot_transform2d_new_identity(godot_transform2d *p_t) { + Transform2D *t = (Transform2D *)p_t; + *t = Transform2D(); +} + +void GDAPI godot_transform2d_new_elements(godot_transform2d *p_t, const godot_vector2 *p_a, const godot_vector2 *p_b, const godot_vector2 *p_c) { + Transform2D *t = (Transform2D *)p_t; + Vector2 *a = (Vector2 *)p_a; + Vector2 *b = (Vector2 *)p_b; + Vector2 *c = (Vector2 *)p_c; + *t = Transform2D(a->x, a->y, b->x, b->y, c->x, c->y); +} + +void GDAPI godot_transform2d_new(godot_transform2d *p_t, const godot_real p_rot, const godot_vector2 *p_pos) { + Transform2D *t = (Transform2D *)p_t; + Vector2 *pos = (Vector2 *)p_pos; + *t = Transform2D(p_rot, *pos); +} + +godot_vector2 const GDAPI *godot_transform2d_const_index(const godot_transform2d *p_t, const godot_int p_idx) { + const Transform2D *t = (const Transform2D *)p_t; + const Vector2 *e = &t->operator[](p_idx); + return (godot_vector2 const *)e; +} + +godot_vector2 GDAPI *godot_transform2d_index(godot_transform2d *p_t, const godot_int p_idx) { + Transform2D *t = (Transform2D *)p_t; + Vector2 *e = &t->operator[](p_idx); + return (godot_vector2 *)e; +} + +godot_vector2 GDAPI godot_transform2d_get_axis(const godot_transform2d *p_t, const godot_int p_axis) { + return *godot_transform2d_const_index(p_t, p_axis); +} + +void GDAPI godot_transform2d_set_axis(godot_transform2d *p_t, const godot_int p_axis, const godot_vector2 *p_vec) { + godot_vector2 *origin_v = godot_transform2d_index(p_t, p_axis); + *origin_v = *p_vec; +} + +// @Incomplete +// See header file + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_transform2d.h b/modules/gdnative/godot/godot_transform2d.h new file mode 100644 index 0000000000..ae0569dbe8 --- /dev/null +++ b/modules/gdnative/godot/godot_transform2d.h @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* godot_transform2d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_TRANSFORM2D_H +#define GODOT_TRANSFORM2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED +typedef struct godot_transform2d { + uint8_t _dont_touch_that[24]; +} godot_transform2d; +#endif + +#include "../godot.h" + +#include "godot_vector2.h" + +void GDAPI godot_transform2d_new_identity(godot_transform2d *p_t); +void GDAPI godot_transform2d_new_elements(godot_transform2d *p_t, const godot_vector2 *p_a, const godot_vector2 *p_b, const godot_vector2 *p_c); +void GDAPI godot_transform2d_new(godot_transform2d *p_t, const godot_real p_rot, const godot_vector2 *p_pos); + +/* +godot_real GDAPI godot_transform2d_tdotx(const godot_transform2d *p_t, const godot_vector2 *p_v); +godot_real GDAPI godot_transform2d_tdoty(const godot_transform2d *p_t, const godot_vector2 *p_v); +*/ + +godot_vector2 const GDAPI *godot_transform2d_const_index(const godot_transform2d *p_t, const godot_int p_idx); +godot_vector2 GDAPI *godot_transform2d_index(godot_transform2d *p_t, const godot_int p_idx); + +godot_vector2 GDAPI godot_transform2d_get_axis(const godot_transform2d *p_t, const godot_int p_axis); +void GDAPI godot_transform2d_set_axis(godot_transform2d *p_t, const godot_int p_axis, const godot_vector2 *p_vec); + +/* +void GDAPI godot_transform2d_invert(godot_transform2d *p_t); +godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_t); +*/ + +// @Incomplete +// I feel like it should be enough to expose get and set, the whole logic can be done in the bindings. + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_TRANSFORM2D_H diff --git a/modules/gdnative/godot/godot_variant.cpp b/modules/gdnative/godot/godot_variant.cpp new file mode 100644 index 0000000000..2214f85056 --- /dev/null +++ b/modules/gdnative/godot/godot_variant.cpp @@ -0,0 +1,505 @@ +/*************************************************************************/ +/* godot_variant.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_variant.h" + +#include "../godot.h" + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _variant_api_anchor() { +} + +#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + return (godot_variant_type)v->get_type(); +} + +void GDAPI godot_variant_copy(godot_variant *p_dest, const godot_variant *p_src) { + Variant *dest = (Variant *)p_dest; + Variant *src = (Variant *)p_src; + *dest = *src; +} + +void GDAPI godot_variant_new_nil(godot_variant *p_v) { + Variant *v = (Variant *)p_v; + memnew_placement(v, Variant); +} + +void GDAPI godot_variant_new_bool(godot_variant *p_v, const godot_bool p_b) { + Variant *v = (Variant *)p_v; + memnew_placement_custom(v, Variant, Variant(p_b)); +} + +void GDAPI godot_variant_new_uint(godot_variant *p_v, const uint64_t p_i) { + Variant *v = (Variant *)p_v; + memnew_placement_custom(v, Variant, Variant(p_i)); +} + +void GDAPI godot_variant_new_int(godot_variant *p_v, const int64_t p_i) { + Variant *v = (Variant *)p_v; + memnew_placement_custom(v, Variant, Variant(p_i)); +} + +void GDAPI godot_variant_new_real(godot_variant *p_v, const double p_r) { + Variant *v = (Variant *)p_v; + memnew_placement_custom(v, Variant, Variant(p_r)); +} + +void GDAPI godot_variant_new_string(godot_variant *p_v, const godot_string *p_s) { + Variant *v = (Variant *)p_v; + String *s = (String *)p_s; + memnew_placement_custom(v, Variant, Variant(*s)); +} + +void GDAPI godot_variant_new_vector2(godot_variant *p_v, const godot_vector2 *p_v2) { + Variant *v = (Variant *)p_v; + Vector2 *v2 = (Vector2 *)p_v2; + memnew_placement_custom(v, Variant, Variant(*v2)); +} + +void GDAPI godot_variant_new_rect2(godot_variant *p_v, const godot_rect2 *p_rect2) { + Variant *v = (Variant *)p_v; + Rect2 *rect2 = (Rect2 *)p_rect2; + memnew_placement_custom(v, Variant, Variant(*rect2)); +} + +void GDAPI godot_variant_new_vector3(godot_variant *p_v, const godot_vector3 *p_v3) { + Variant *v = (Variant *)p_v; + Vector3 *v3 = (Vector3 *)p_v3; + memnew_placement_custom(v, Variant, Variant(*v3)); +} + +void GDAPI godot_variant_new_transform2d(godot_variant *p_v, const godot_transform2d *p_t2d) { + Variant *v = (Variant *)p_v; + Transform2D *t2d = (Transform2D *)p_t2d; + memnew_placement_custom(v, Variant, Variant(*t2d)); +} + +void GDAPI godot_variant_new_plane(godot_variant *p_v, const godot_plane *p_plane) { + Variant *v = (Variant *)p_v; + Plane *plane = (Plane *)p_plane; + memnew_placement_custom(v, Variant, Variant(*plane)); +} + +void GDAPI godot_variant_new_quat(godot_variant *p_v, const godot_quat *p_quat) { + Variant *v = (Variant *)p_v; + Quat *quat = (Quat *)p_quat; + memnew_placement_custom(v, Variant, Variant(*quat)); +} + +void GDAPI godot_variant_new_rect3(godot_variant *p_v, const godot_rect3 *p_rect3) { + Variant *v = (Variant *)p_v; + Rect3 *rect3 = (Rect3 *)p_rect3; + memnew_placement_custom(v, Variant, Variant(*rect3)); +} + +void GDAPI godot_variant_new_basis(godot_variant *p_v, const godot_basis *p_basis) { + Variant *v = (Variant *)p_v; + Basis *basis = (Basis *)p_basis; + memnew_placement_custom(v, Variant, Variant(*basis)); +} + +void GDAPI godot_variant_new_transform(godot_variant *p_v, const godot_transform *p_trans) { + Variant *v = (Variant *)p_v; + Transform *trans = (Transform *)p_trans; + memnew_placement_custom(v, Variant, Variant(*trans)); +} + +void GDAPI godot_variant_new_color(godot_variant *p_v, const godot_color *p_color) { + Variant *v = (Variant *)p_v; + Color *color = (Color *)p_color; + memnew_placement_custom(v, Variant, Variant(*color)); +} + +void GDAPI godot_variant_new_image(godot_variant *p_v, const godot_image *p_img) { + Variant *v = (Variant *)p_v; + Image *img = (Image *)p_img; + memnew_placement_custom(v, Variant, Variant(*img)); +} + +void GDAPI godot_variant_new_node_path(godot_variant *p_v, const godot_node_path *p_np) { + Variant *v = (Variant *)p_v; + NodePath *np = (NodePath *)p_np; + memnew_placement_custom(v, Variant, Variant(*np)); +} + +void GDAPI godot_variant_new_rid(godot_variant *p_v, const godot_rid *p_rid) { + Variant *v = (Variant *)p_v; + RID *rid = (RID *)p_rid; + memnew_placement_custom(v, Variant, Variant(*rid)); +} + +void GDAPI godot_variant_new_object(godot_variant *p_v, const godot_object *p_obj) { + Variant *v = (Variant *)p_v; + Object *obj = (Object *)p_obj; + memnew_placement_custom(v, Variant, Variant(obj)); +} + +void GDAPI godot_variant_new_input_event(godot_variant *p_v, const godot_input_event *p_event) { + Variant *v = (Variant *)p_v; + InputEvent *event = (InputEvent *)p_event; + memnew_placement_custom(v, Variant, Variant(*event)); +} + +void GDAPI godot_variant_new_dictionary(godot_variant *p_v, const godot_dictionary *p_dict) { + Variant *v = (Variant *)p_v; + Dictionary *dict = (Dictionary *)p_dict; + memnew_placement_custom(v, Variant, Variant(*dict)); +} + +void GDAPI godot_variant_new_array(godot_variant *p_v, const godot_array *p_arr) { + Variant *v = (Variant *)p_v; + Array *arr = (Array *)p_arr; + memnew_placement_custom(v, Variant, Variant(*arr)); +} + +void GDAPI godot_variant_new_pool_byte_array(godot_variant *p_v, const godot_pool_byte_array *p_pba) { + Variant *v = (Variant *)p_v; + PoolByteArray *pba = (PoolByteArray *)p_pba; + memnew_placement_custom(v, Variant, Variant(*pba)); +} + +void GDAPI godot_variant_new_pool_int_array(godot_variant *p_v, const godot_pool_int_array *p_pia) { + Variant *v = (Variant *)p_v; + PoolIntArray *pia = (PoolIntArray *)p_pia; + memnew_placement_custom(v, Variant, Variant(*pia)); +} + +void GDAPI godot_variant_new_pool_real_array(godot_variant *p_v, const godot_pool_real_array *p_pra) { + Variant *v = (Variant *)p_v; + PoolRealArray *pra = (PoolRealArray *)p_pra; + memnew_placement_custom(v, Variant, Variant(*pra)); +} + +void GDAPI godot_variant_new_pool_string_array(godot_variant *p_v, const godot_pool_string_array *p_psa) { + Variant *v = (Variant *)p_v; + PoolStringArray *psa = (PoolStringArray *)p_psa; + memnew_placement_custom(v, Variant, Variant(*psa)); +} + +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *p_v, const godot_pool_vector2_array *p_pv2a) { + Variant *v = (Variant *)p_v; + PoolVector2Array *pv2a = (PoolVector2Array *)p_pv2a; + memnew_placement_custom(v, Variant, Variant(*pv2a)); +} + +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *p_v, const godot_pool_vector3_array *p_pv3a) { + Variant *v = (Variant *)p_v; + PoolVector3Array *pv3a = (PoolVector3Array *)p_pv3a; + memnew_placement_custom(v, Variant, Variant(*pv3a)); +} + +void GDAPI godot_variant_new_pool_color_array(godot_variant *p_v, const godot_pool_color_array *p_pca) { + Variant *v = (Variant *)p_v; + PoolColorArray *pca = (PoolColorArray *)p_pca; + memnew_placement_custom(v, Variant, Variant(*pca)); +} + +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + return v->operator bool(); +} + +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + return v->operator uint64_t(); +} + +int64_t GDAPI godot_variant_as_int(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + return v->operator int64_t(); +} + +double GDAPI godot_variant_as_real(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + return v->operator double(); +} + +godot_string GDAPI godot_variant_as_string(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_string s; + godot_string_new(&s); + String *str = (String *)&s; + *str = v->operator String(); + return s; +} + +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_vector2 v2; + Vector2 *vec2 = (Vector2 *)&v2; + *vec2 = *v; + return v2; +} + +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_rect2 r2; + Rect2 *rect2 = (Rect2 *)&r2; + *rect2 = *v; + return r2; +} + +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_vector3 v3; + Vector3 *vec3 = (Vector3 *)&v3; + *vec3 = *v; + return v3; +} + +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_transform2d t2; + Transform2D *t = (Transform2D *)&t2; + *t = *v; + return t2; +} + +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_plane p; + Plane *pl = (Plane *)&p; + *pl = *v; + return p; +} + +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_quat q; + Quat *qt = (Quat *)&q; + *qt = *v; + return q; +} + +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_rect3 r; + Rect3 *r3 = (Rect3 *)&r; + *r3 = *v; + return r; +} + +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_basis b; + Basis *bs = (Basis *)&b; + *bs = *v; + return b; +} + +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_transform t; + Transform *tr = (Transform *)&t; + *tr = *v; + return t; +} + +godot_color GDAPI godot_variant_as_color(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_color c; + Color *col = (Color *)&c; + *col = *v; + return c; +} + +godot_image GDAPI godot_variant_as_image(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_image img; + godot_image_new(&img); + Image *i = (Image *)&img; + *i = *v; + return img; +} + +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_node_path np; + memnew_placement_custom((NodePath *)&np, NodePath, NodePath((String)*v)); + return np; +} + +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_rid rid; + memnew_placement_custom((RID *)&rid, RID, RID(*v)); + return rid; +} + +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_object *p = NULL; + Object **op = (Object **)&p; + *op = *v; + return p; +} + +godot_input_event GDAPI godot_variant_as_input_event(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_input_event ev; + InputEvent *event = (InputEvent *)&ev; + *event = *v; + return ev; +} + +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_dictionary dict; + godot_dictionary_new(&dict); + Dictionary *d = (Dictionary *)&dict; + *d = *v; + return dict; +} + +godot_array GDAPI godot_variant_as_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_array array; + godot_array_new(&array); + Array *a = (Array *)&array; + *a = *v; + return array; +} + +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_byte_array pba; + godot_pool_byte_array_new(&pba); + PoolByteArray *p = (PoolByteArray *)&pba; + *p = *v; + return pba; +} + +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_int_array pba; + godot_pool_int_array_new(&pba); + PoolIntArray *p = (PoolIntArray *)&pba; + *p = *v; + return pba; +} + +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_real_array pba; + godot_pool_real_array_new(&pba); + PoolRealArray *p = (PoolRealArray *)&pba; + *p = *v; + return pba; +} + +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_string_array pba; + godot_pool_string_array_new(&pba); + PoolStringArray *p = (PoolStringArray *)&pba; + *p = *v; + return pba; +} + +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_vector2_array pba; + godot_pool_vector2_array_new(&pba); + PoolVector2Array *p = (PoolVector2Array *)&pba; + *p = *v; + return pba; +} + +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_vector3_array pba; + godot_pool_vector3_array_new(&pba); + PoolVector3Array *p = (PoolVector3Array *)&pba; + *p = *v; + return pba; +} + +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_v) { + const Variant *v = (const Variant *)p_v; + godot_pool_color_array pba; + godot_pool_color_array_new(&pba); + PoolColorArray *p = (PoolColorArray *)&pba; + *p = *v; + return pba; +} + +godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */) { + Variant *v = (Variant *)p_v; + String *method = (String *)p_method; + Variant **args = (Variant **)p_args; + godot_variant res; + memnew_placement_custom((Variant *)&res, Variant, Variant(v->call(*method, args, p_argcount))); + return res; +} + +godot_bool GDAPI godot_variant_has_method(godot_variant *p_v, const godot_string *p_method) { + Variant *v = (Variant *)p_v; + String *method = (String *)p_method; + return v->has_method(*method); +} + +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_a, const godot_variant *p_b) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + return a->operator==(*b); +} + +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_a, const godot_variant *p_b) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + return a->operator<(*b); +} + +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_a, const godot_variant *p_b) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + return a->hash_compare(*b); +} + +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_v, godot_bool *p_valid) { + const Variant *v = (const Variant *)p_v; + bool &valid = *p_valid; + return v->booleanize(valid); +} + +void GDAPI godot_variant_destroy(godot_variant *p_v) { + ((Variant *)p_v)->~Variant(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_variant.h b/modules/gdnative/godot/godot_variant.h new file mode 100644 index 0000000000..6f98b32363 --- /dev/null +++ b/modules/gdnative/godot/godot_variant.h @@ -0,0 +1,179 @@ +/*************************************************************************/ +/* godot_variant.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_VARIANT_H +#define GODOT_VARIANT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED +typedef struct godot_variant { + uint8_t _dont_touch_that[24]; +} godot_variant; +#endif + +struct godot_transform2d; +typedef struct godot_transform2d godot_transform2d; + +#include "godot_array.h" +#include "godot_dictionary.h" +#include "godot_input_event.h" +#include "godot_node_path.h" +#include "godot_rid.h" +#include "godot_transform2d.h" + +typedef enum godot_variant_type { + GODOT_VARIANT_TYPE_NIL, + + // atomic types + GODOT_VARIANT_TYPE_BOOL, + GODOT_VARIANT_TYPE_INT, + GODOT_VARIANT_TYPE_REAL, + GODOT_VARIANT_TYPE_STRING, + + // math types + + GODOT_VARIANT_TYPE_VECTOR2, // 5 + GODOT_VARIANT_TYPE_RECT2, + GODOT_VARIANT_TYPE_VECTOR3, + GODOT_VARIANT_TYPE_TRANSFORM2D, + GODOT_VARIANT_TYPE_PLANE, + GODOT_VARIANT_TYPE_QUAT, // 10 + GODOT_VARIANT_TYPE_RECT3, //sorry naming convention fail :( not like it's used often + GODOT_VARIANT_TYPE_BASIS, + GODOT_VARIANT_TYPE_TRANSFORM, + + // misc types + GODOT_VARIANT_TYPE_COLOR, + GODOT_VARIANT_TYPE_IMAGE, // 15 + GODOT_VARIANT_TYPE_NODE_PATH, + GODOT_VARIANT_TYPE_RID, + GODOT_VARIANT_TYPE_OBJECT, + GODOT_VARIANT_TYPE_INPUT_EVENT, + GODOT_VARIANT_TYPE_DICTIONARY, // 20 + GODOT_VARIANT_TYPE_ARRAY, + + // arrays + GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY, + GODOT_VARIANT_TYPE_POOL_INT_ARRAY, + GODOT_VARIANT_TYPE_POOL_REAL_ARRAY, + GODOT_VARIANT_TYPE_POOL_STRING_ARRAY, // 25 + GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, + GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY, + GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY, +} godot_variant_type; + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v); + +void GDAPI godot_variant_copy(godot_variant *p_dest, const godot_variant *p_src); + +void GDAPI godot_variant_new_nil(godot_variant *p_v); + +void GDAPI godot_variant_new_bool(godot_variant *p_v, const godot_bool p_b); +void GDAPI godot_variant_new_uint(godot_variant *p_v, const uint64_t p_i); +void GDAPI godot_variant_new_int(godot_variant *p_v, const int64_t p_i); +void GDAPI godot_variant_new_real(godot_variant *p_v, const double p_r); +void GDAPI godot_variant_new_string(godot_variant *p_v, const godot_string *p_s); +void GDAPI godot_variant_new_vector2(godot_variant *p_v, const godot_vector2 *p_v2); +void GDAPI godot_variant_new_rect2(godot_variant *p_v, const godot_rect2 *p_rect2); +void GDAPI godot_variant_new_vector3(godot_variant *p_v, const godot_vector3 *p_v3); +void GDAPI godot_variant_new_transform2d(godot_variant *p_v, const godot_transform2d *p_t2d); +void GDAPI godot_variant_new_plane(godot_variant *p_v, const godot_plane *p_plane); +void GDAPI godot_variant_new_quat(godot_variant *p_v, const godot_quat *p_quat); +void GDAPI godot_variant_new_rect3(godot_variant *p_v, const godot_rect3 *p_rect3); +void GDAPI godot_variant_new_basis(godot_variant *p_v, const godot_basis *p_basis); +void GDAPI godot_variant_new_transform(godot_variant *p_v, const godot_transform *p_trans); +void GDAPI godot_variant_new_color(godot_variant *p_v, const godot_color *p_color); +void GDAPI godot_variant_new_image(godot_variant *p_v, const godot_image *p_img); +void GDAPI godot_variant_new_node_path(godot_variant *p_v, const godot_node_path *p_np); +void GDAPI godot_variant_new_rid(godot_variant *p_v, const godot_rid *p_rid); +void GDAPI godot_variant_new_object(godot_variant *p_v, const godot_object *p_obj); +void GDAPI godot_variant_new_input_event(godot_variant *p_v, const godot_input_event *p_event); +void GDAPI godot_variant_new_dictionary(godot_variant *p_v, const godot_dictionary *p_dict); +void GDAPI godot_variant_new_array(godot_variant *p_v, const godot_array *p_arr); +void GDAPI godot_variant_new_pool_byte_array(godot_variant *p_v, const godot_pool_byte_array *p_pba); +void GDAPI godot_variant_new_pool_int_array(godot_variant *p_v, const godot_pool_int_array *p_pia); +void GDAPI godot_variant_new_pool_real_array(godot_variant *p_v, const godot_pool_real_array *p_pra); +void GDAPI godot_variant_new_pool_string_array(godot_variant *p_v, const godot_pool_string_array *p_psa); +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *p_v, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *p_v, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_variant_new_pool_color_array(godot_variant *p_v, const godot_pool_color_array *p_pca); + +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_v); +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_v); +int64_t GDAPI godot_variant_as_int(const godot_variant *p_v); +double GDAPI godot_variant_as_real(const godot_variant *p_v); +godot_string GDAPI godot_variant_as_string(const godot_variant *p_v); +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_v); +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_v); +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_v); +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_v); +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_v); +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_v); +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_v); +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_v); +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_v); +godot_color GDAPI godot_variant_as_color(const godot_variant *p_v); +godot_image GDAPI godot_variant_as_image(const godot_variant *p_v); +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_v); +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_v); +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_v); +godot_input_event GDAPI godot_variant_as_input_event(const godot_variant *p_v); +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_v); +godot_array GDAPI godot_variant_as_array(const godot_variant *p_v); +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_v); +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_v); +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_v); +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_v); +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_v); +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_v); +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_v); + +godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */); + +godot_bool GDAPI godot_variant_has_method(godot_variant *p_v, const godot_string *p_method); + +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_a, const godot_variant *p_b); +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_a, const godot_variant *p_b); + +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_a, const godot_variant *p_b); + +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_v, godot_bool *p_valid); + +void GDAPI godot_variant_destroy(godot_variant *p_v); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/modules/gdnative/godot/godot_vector2.cpp b/modules/gdnative/godot/godot_vector2.cpp new file mode 100644 index 0000000000..87e60b6245 --- /dev/null +++ b/modules/gdnative/godot/godot_vector2.cpp @@ -0,0 +1,296 @@ +/*************************************************************************/ +/* godot_vector2.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_vector2.h" + +#include "math/math_2d.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _vector2_api_anchor() {} + +godot_vector2 GDAPI godot_vector2_new(const godot_real p_x, const godot_real p_y) { + godot_vector2 value; + Vector2 *v = (Vector2 *)&value; + v->x = p_x; + v->y = p_y; + return value; +} + +void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x) { + Vector2 *v = (Vector2 *)p_v; + v->x = p_x; +} + +void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y) { + Vector2 *v = (Vector2 *)p_v; + v->y = p_y; +} + +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->x; +} +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->y; +} + +void GDAPI godot_vector2_normalize(godot_vector2 *p_v) { + Vector2 *v = (Vector2 *)p_v; + v->normalize(); +} + +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_v) { + godot_vector2 dest; + const Vector2 *v = (Vector2 *)p_v; + Vector2 *d = (Vector2 *)&dest; + *d = v->normalized(); + return dest; +} + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->length(); +} + +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->length_squared(); +} + +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return v->distance_to(*b); +} + +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return v->distance_squared_to(*b); +} + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v + *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v - *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v * *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_v, const godot_real p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = *v * p_b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v / *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_v, const godot_real p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = *v / p_b; + return dest; +} + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return *v == *b; +} + +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return *v < *b; +} + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->abs(); + return dest; +} + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->angle(); +} + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_v, const godot_vector2 p_to) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *to = (Vector2 *)&p_to; + return v->angle_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_v, const godot_vector2 p_to) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *to = (Vector2 *)&p_to; + return v->angle_to_point(*to); +} + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_v, const godot_real length) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->clamped(length); + return dest; +} + +godot_vector2 GDAPI godot_vector2_cubic_interpolate( + const godot_vector2 *p_v, const godot_vector2 p_b, const godot_vector2 p_pre_a, + const godot_vector2 p_post_b, godot_real t) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + const Vector2 *pre_a = (Vector2 *)&p_pre_a; + const Vector2 *post_b = (Vector2 *)&p_post_b; + *d = v->cubic_interpolate(*b, *pre_a, *post_b, t); + return dest; +} + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_v, const godot_vector2 p_with) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *with = (Vector2 *)&p_with; + return v->dot(*with); +} + +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->floor(); + return dest; +} + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->aspect(); +} + +godot_vector2 GDAPI godot_vector2_linear_interpolate( + const godot_vector2 *p_v, + const godot_vector2 p_b, + godot_real t) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = v->linear_interpolate(*b, t); + return dest; +} + +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_v, const godot_vector2 p_vec) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *vec = (Vector2 *)&p_vec; + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + *d = v->reflect(*vec); + return dest; +} + +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_v, godot_real phi) { + const Vector2 *v = (Vector2 *)p_v; + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + *d = v->rotated(phi); + return dest; +} + +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_v, godot_vector2 p_vec) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *vec = (Vector2 *)&p_vec; + *d = v->slide(*vec); + return dest; +} + +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_v, godot_vector2 p_by) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *by = (Vector2 *)&p_by; + *d = v->snapped(*by); + return dest; +} + +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->tangent(); + return dest; +} + +godot_string GDAPI godot_vector2_to_string(const godot_vector2 *p_v) { + godot_string dest; + String *d = (String *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = "(" + *v + ")"; + return dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_vector2.h b/modules/gdnative/godot/godot_vector2.h new file mode 100644 index 0000000000..36a4f01d03 --- /dev/null +++ b/modules/gdnative/godot/godot_vector2.h @@ -0,0 +1,98 @@ +/*************************************************************************/ +/* godot_vector2.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_VECTOR2_H +#define GODOT_VECTOR2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED +typedef struct godot_vector2 { + uint8_t _dont_touch_that[8]; +} godot_vector2; +#endif + +#include "../godot.h" + +godot_vector2 GDAPI godot_vector2_new(const godot_real p_x, const godot_real p_y); + +void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x); +void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y); +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v); + +void GDAPI godot_vector2_normalize(godot_vector2 *p_v); +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_v); + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v); + +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_v, const godot_vector2 p_b); + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_v, const godot_vector2 p_to); +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_v, const godot_vector2 p_to); +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_v, godot_real length); +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_v, + const godot_vector2 p_b, const godot_vector2 p_pre_a, + const godot_vector2 p_post_b, godot_real t); +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_v, const godot_vector2 p_with); +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_v); +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_v, + const godot_vector2 p_b, godot_real t); +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_v, const godot_vector2 p_vec); +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_v, godot_real phi); +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_v, godot_vector2 p_vec); +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_v, godot_vector2 p_by); +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_v); +godot_string GDAPI godot_vector2_to_string(const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_v, const godot_real p_b); +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_v, const godot_real p_b); + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_v, const godot_vector2 p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_VECTOR2_H diff --git a/modules/gdnative/godot/godot_vector3.cpp b/modules/gdnative/godot/godot_vector3.cpp new file mode 100644 index 0000000000..5f71b9f7e4 --- /dev/null +++ b/modules/gdnative/godot/godot_vector3.cpp @@ -0,0 +1,342 @@ +/*************************************************************************/ +/* godot_vector3.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "godot_vector3.h" + +#include "math/vector3.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _vector3_api_anchor() { +} + +godot_vector3 GDAPI godot_vector3_new(const godot_real p_x, const godot_real p_y, const godot_real p_z) { + godot_vector3 value; + Vector3 *v = (Vector3 *)&value; + *v = Vector3(p_x, p_y, p_z); + return value; +} + +void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val) { + Vector3 *v = (Vector3 *)p_v; + v->set_axis(p_axis, p_val); +} + +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_v, const godot_int p_axis) { + Vector3 *v = (Vector3 *)p_v; + return v->get_axis(p_axis); +} + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + return v->min_axis(); +} + +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + return v->max_axis(); +} + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + return v->length(); +} + +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + return v->length_squared(); +} + +void GDAPI godot_vector3_normalize(godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + v->normalize(); +} + +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = v->normalized(); + return dest; +} + +godot_vector3 godot_vector3_inverse(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->inverse(); + return dest; +} + +void godot_vector3_zero(godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + v->zero(); +} + +void godot_vector3_snap(godot_vector3 *p_v, const godot_real val) { + Vector3 *v = (Vector3 *)p_v; + v->snap(val); +} + +godot_vector3 godot_vector3_snapped(const godot_vector3 *p_v, const godot_real val) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->snapped(val); + return dest; +} + +void godot_vector3_rotate(godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi) { + Vector3 *v = (Vector3 *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + v->rotate(*axis, phi); +} + +godot_vector3 godot_vector3_rotated(const godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *d = v->rotated(*axis, phi); + return dest; +} + +godot_vector3 godot_vector3_linear_interpolate(const godot_vector3 *p_v, const godot_vector3 p_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->linear_interpolate(*b, t); + return dest; +} + +godot_vector3 godot_vector3_cubic_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + const Vector3 *pre_a = (Vector3 *)&p_pre_a; + const Vector3 *post_b = (Vector3 *)&p_post_b; + *d = v->cubic_interpolate(*b, *pre_a, *post_b, t); + return dest; +} + +godot_vector3 godot_vector3_cubic_interpolaten(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + const Vector3 *pre_a = (Vector3 *)&p_pre_a; + const Vector3 *post_b = (Vector3 *)&p_post_b; + *d = v->cubic_interpolaten(*b, *pre_a, *post_b, t); + return dest; +} + +godot_vector3 godot_vector3_cross(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->cross(*b); + return dest; +} + +godot_real godot_vector3_dot(const godot_vector3 *p_v, const godot_vector3 p_b) { + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + return v->dot(*b); +} + +godot_basis godot_vector3_outer(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_basis dest; + Basis *d = (Basis *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->outer(*b); + return dest; +} + +godot_basis godot_vector3_to_diagonal_matrix(const godot_vector3 *p_v) { + godot_basis dest; + Basis *d = (Basis *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->to_diagonal_matrix(); + return dest; +} + +godot_vector3 godot_vector3_abs(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->abs(); + return dest; +} + +godot_vector3 godot_vector3_floor(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->floor(); + return dest; +} + +godot_vector3 godot_vector3_ceil(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->ceil(); + return dest; +} + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->distance_to(*b); +} + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->distance_squared_to(*b); +} + +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->angle_to(*b); +} + +godot_vector3 godot_vector3_slide(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->slide(*vec); + return dest; +} + +godot_vector3 godot_vector3_bounce(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->bounce(*vec); + return dest; +} + +godot_vector3 godot_vector3_reflect(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->reflect(*vec); + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v + *b; + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v - *b; + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v * *b; + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_v, const godot_real p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = *v * p_b; + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v / *b; + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_v, const godot_real p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = *v / p_b; + return dest; +} + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return *v == *b; +} + +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return *v < *b; +} + +godot_string GDAPI godot_vector3_to_string(const godot_vector3 *p_v) { + godot_string dest; + String *d = (String *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = "(" + *v + ")"; + return dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/godot_vector3.h b/modules/gdnative/godot/godot_vector3.h new file mode 100644 index 0000000000..654ddd7792 --- /dev/null +++ b/modules/gdnative/godot/godot_vector3.h @@ -0,0 +1,113 @@ +/*************************************************************************/ +/* godot_vector3.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_VECTOR3_H +#define GODOT_VECTOR3_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED +typedef struct godot_vector3 { + uint8_t _dont_touch_that[12]; +} godot_vector3; +#endif + +#define GODOT_VECTOR3_AXIX_X 0 +#define GODOT_VECTOR3_AXIX_Y 1 +#define GODOT_VECTOR3_AXIX_Z 2 + +#include "../godot.h" +#include "godot_basis.h" + +godot_vector3 GDAPI godot_vector3_new(const godot_real p_x, const godot_real p_y, const godot_real p_z); + +void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val); +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_v, const godot_int p_axis); + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_v); +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_v); + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_v); +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v); + +void GDAPI godot_vector3_normalize(godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_v); +void GDAPI godot_vector3_zero(godot_vector3 *p_v); +void GDAPI godot_vector3_snap(godot_vector3 *p_v, const godot_real val); +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_v, const godot_real val); +void GDAPI godot_vector3_rotate(godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi); +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_v, + const godot_vector3 p_axis, const godot_real phi); +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cubic_interpolaten(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_v); + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_v, const godot_vector3 p_b); + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_v, const godot_vector3 p_vec); +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_v, const godot_vector3 p_vec); +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_v, const godot_vector3 p_vec); + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_v, const godot_real p_b); +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_v, const godot_real p_b); + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_v, const godot_vector3 p_b); + +godot_string GDAPI godot_vector3_to_string(const godot_vector3 *p_v); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_VECTOR3_H diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp new file mode 100644 index 0000000000..8789c9a267 --- /dev/null +++ b/modules/gdnative/register_types.cpp @@ -0,0 +1,66 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" +#include "gdnative.h" + +#include "io/resource_loader.h" +#include "io/resource_saver.h" + +GDNativeScriptLanguage *script_language_gdn = NULL; +ResourceFormatLoaderGDNativeScript *resource_loader_gdn = NULL; +ResourceFormatSaverGDNativeScript *resource_saver_gdn = NULL; +//ResourceFormatLoaderDLLibrary *resource_loader_dllib=NULL; + +void register_gdnative_types() { + + ClassDB::register_class<GDNativeLibrary>(); + ClassDB::register_class<GDNativeScript>(); + + script_language_gdn = memnew(GDNativeScriptLanguage); + ScriptServer::register_language(script_language_gdn); + resource_loader_gdn = memnew(ResourceFormatLoaderGDNativeScript); + ResourceLoader::add_resource_format_loader(resource_loader_gdn); + resource_saver_gdn = memnew(ResourceFormatSaverGDNativeScript); + ResourceSaver::add_resource_format_saver(resource_saver_gdn); +} + +void unregister_gdnative_types() { + + ScriptServer::unregister_language(script_language_gdn); + + if (script_language_gdn) + memdelete(script_language_gdn); + + if (resource_loader_gdn) + memdelete(resource_loader_gdn); + + if (resource_saver_gdn) + memdelete(resource_saver_gdn); +} diff --git a/modules/cscript/register_types.h b/modules/gdnative/register_types.h index 6614ee3a19..48e778cb2c 100644 --- a/modules/cscript/register_types.h +++ b/modules/gdnative/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,5 +27,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -void register_cscript_types(); -void unregister_cscript_types(); +void register_gdnative_types(); +void unregister_gdnative_types(); diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 3f8c710674..12b43d6060 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -1539,7 +1540,7 @@ Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode signature += "::0"; } - //funciton and class + //function and class if (p_class->name) { signature += "::" + String(p_class->name) + "." + String(func_name); @@ -1660,7 +1661,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa String sub = p_class->extends_class[i]; if (script->subclasses.has(sub)) { - Ref<Script> subclass = script->subclasses[sub]; //avoid reference from dissapearing + Ref<Script> subclass = script->subclasses[sub]; //avoid reference from disappearing script = subclass; } else { diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h index c84bd97246..b7ff092eba 100644 --- a/modules/gdscript/gd_compiler.h +++ b/modules/gdscript/gd_compiler.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 702876ecdc..c2f14f5466 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "editor/editor_settings.h" #include "gd_compiler.h" #include "gd_script.h" #include "global_config.h" @@ -1070,7 +1072,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con //return _guess_expression_type(context,context._class->variables[i].expression,context._class->variables[i].line,r_type); } - //try to guess from assignment in construtor or _ready + //try to guess from assignment in constructor or _ready if (_guess_identifier_from_assignment_in_function(context, p_line + 1, p_identifier, "_ready", r_type)) return true; if (_guess_identifier_from_assignment_in_function(context, p_line + 1, p_identifier, "_enter_tree", r_type)) @@ -2390,8 +2392,27 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", "Tabs") == "Tabs" ? 0 : 1; + + if (use_space_indentation) { + int indent_size = EDITOR_DEF("text_editor/indent/size", 4); + + String space_indent = ""; + for (int i = 0; i < indent_size; i++) { + space_indent += " "; + } + return space_indent; + } +#endif + return "\t"; +} + void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { + String indent = _get_indentation(); + Vector<String> lines = p_code.split("\n"); List<int> indent_stack; @@ -2431,8 +2452,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t if (i >= p_from_line) { l = ""; - for (int j = 0; j < indent_stack.size(); j++) - l += "\t"; + for (int j = 0; j < indent_stack.size(); j++) { + l += indent; + } l += st; } else if (i > p_to_line) { diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index aaf97001e9..608256c88a 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -189,7 +190,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (p_state) { //use existing (supplied) state (yielded) stack = (Variant *)p_state->stack.ptr(); - call_args = (Variant **)stack + sizeof(Variant) * p_state->stack_size; + call_args = (Variant **)&p_state->stack.ptr()[sizeof(Variant) * p_state->stack_size]; //ptr() to avoid bounds check line = p_state->line; ip = p_state->ip; alloca_size = p_state->stack.size(); diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h index 321b3b6cfa..f0bf33147b 100644 --- a/modules/gdscript/gd_function.h +++ b/modules/gdscript/gd_function.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index fa92f0a194..a361971ef4 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h index cde1a9210d..4d52abaeab 100644 --- a/modules/gdscript/gd_functions.h +++ b/modules/gdscript/gd_functions.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 86b97e27a9..cd16fef6b3 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -76,7 +77,7 @@ bool GDParser::_enter_indent_block(BlockNode *p_block) { // be more python-like int current = tab_level.back()->get(); - tab_level.push_back(current + 1); + tab_level.push_back(current); return true; //_set_error("newline expected after ':'."); //return false; @@ -1021,7 +1022,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool OperatorNode::Operator op; bool valid = true; -//assign, if allowed is only alowed on the first operator +//assign, if allowed is only allowed on the first operator #define _VALIDATE_ASSIGN \ if (!p_allow_assign) { \ _set_error("Unexpected assign."); \ @@ -1253,7 +1254,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators after ternary if."); return NULL; @@ -1263,7 +1264,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators after ternary else."); return NULL; @@ -1300,7 +1301,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators."); return NULL; @@ -2258,7 +2259,16 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->statements.push_back(nl); #endif + bool is_first_line = true; + while (true) { + if (!is_first_line && tab_level.back()->prev() && tab_level.back()->prev()->get() == indent_level) { + // pythonic single-line expression, don't parse future lines + tab_level.pop_back(); + p_block->end_line = tokenizer->get_token_line(); + return; + } + is_first_line = false; GDTokenizer::Token token = tokenizer->get_token(); if (error_set) @@ -2412,7 +2422,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->sub_blocks.push_back(cf_if->body); if (!_enter_indent_block(cf_if->body)) { - _set_error("Expected intended block after 'if'"); + _set_error("Expected indented block after 'if'"); p_block->end_line = tokenizer->get_token_line(); return; } @@ -2427,9 +2437,8 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { while (true) { - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { - tokenizer->advance(); - } + while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()) + ; if (tab_level.back()->get() < indent_level) { //not at current indent level p_block->end_line = tokenizer->get_token_line(); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 8d2c136818..445ad7361c 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index e1cc75acfc..fe20a842cf 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -532,7 +533,7 @@ bool GDScript::_update_exports() { } } } else { - //print_line("unchaged is "+get_path()); + //print_line("unchanged is "+get_path()); } if (base_cache.is_valid()) { @@ -1271,7 +1272,7 @@ void GDInstance::call_multilevel_reversed(const StringName &p_method, const Vari void GDInstance::notification(int p_notification) { - //notification is not virutal, it gets called at ALL levels just like in C. + //notification is not virtual, it gets called at ALL levels just like in C. Variant value = p_notification; const Variant *args[1] = { &value }; @@ -1695,9 +1696,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so //same thing for placeholders #ifdef TOOLS_ENABLED - while (E->get()->placeholders.size()) { + for (Set<PlaceHolderScriptInstance *>::Element *P = E->get()->placeholders.front(); P; P = P->next()) { - Object *obj = E->get()->placeholders.front()->get()->get_owner(); + Object *obj = P->get()->get_owner(); //save instance info List<Pair<StringName, Variant> > state; if (obj->get_script_instance()) { diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index d64cc9798d..f92c11b9e0 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -389,6 +390,7 @@ public: #ifdef TOOLS_ENABLED virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result); #endif + virtual String _get_indentation() const; virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 981924191f..13674f1f9a 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -117,6 +118,7 @@ const char *GDTokenizer::token_names[TK_MAX] = { "'.'", "'?'", "':'", + "'$'", "'\\n'", "PI", "_", diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index c1ed8ad92e..ea7629b661 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 5acd412f7e..41ea0c2a26 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gdscript/register_types.h b/modules/gdscript/register_types.h index 5778dfcadc..4e969f5bd4 100644 --- a/modules/gdscript/register_types.h +++ b/modules/gdscript/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 128592fa29..d1f54e021f 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 2a0c2b9646..c386e4f66b 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index a6a3a03503..39fe0a1675 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -834,9 +835,9 @@ void GridMapEditor::edit(GridMap *p_gridmap) { //update grids indicator_mat.instance(); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); indicator_mat->set_albedo(Color(0.8, 0.5, 0.1)); Vector<Vector3> grid_points[3]; @@ -1309,9 +1310,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { inner_mat.instance(); inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.3)); - inner_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); - inner_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); - inner_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); + inner_mat->set_flag(SpatialMaterial::FLAG_ONTOP, true); + inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); d[VS::ARRAY_VERTEX] = triangles; VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d); @@ -1319,10 +1320,10 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { outer_mat.instance(); outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.3)); - outer_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); - outer_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); + outer_mat->set_flag(SpatialMaterial::FLAG_ONTOP, true); + outer_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); outer_mat->set_line_width(3.0); - outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); + outer_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); d[VS::ARRAY_VERTEX] = lines; VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d); diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 27a063ee41..d928e6afac 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -112,9 +113,9 @@ class GridMapEditor : public VBoxContainer { RID duplicate_mesh; RID duplicate_instance; - Ref<FixedSpatialMaterial> indicator_mat; - Ref<FixedSpatialMaterial> inner_mat; - Ref<FixedSpatialMaterial> outer_mat; + Ref<SpatialMaterial> indicator_mat; + Ref<SpatialMaterial> inner_mat; + Ref<SpatialMaterial> outer_mat; bool updating; diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index 4035caea78..e4def9378f 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/gridmap/register_types.h b/modules/gridmap/register_types.h index cc7c13961a..1978353fc3 100644 --- a/modules/gridmap/register_types.h +++ b/modules/gridmap/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index ca928c4fe6..83685d6446 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index 0803cfba1e..d23e8a7d48 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/jpg/register_types.cpp b/modules/jpg/register_types.cpp index ce0330643a..2379bee0df 100644 --- a/modules/jpg/register_types.cpp +++ b/modules/jpg/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/jpg/register_types.h b/modules/jpg/register_types.h index 62132bf461..c14f860742 100644 --- a/modules/jpg/register_types.h +++ b/modules/jpg/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/cscript/SCsub b/modules/multiscript/SCsub index 0882406761..0882406761 100644 --- a/modules/cscript/SCsub +++ b/modules/multiscript/SCsub diff --git a/modules/cscript/config.py b/modules/multiscript/config.py index 5698a37295..5698a37295 100644 --- a/modules/cscript/config.py +++ b/modules/multiscript/config.py diff --git a/modules/multiscript/multiscript.cpp b/modules/multiscript/multiscript.cpp new file mode 100644 index 0000000000..b2633b7207 --- /dev/null +++ b/modules/multiscript/multiscript.cpp @@ -0,0 +1,750 @@ +/*************************************************************************/ +/* multiscript.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "multiscript.h" + +bool MultiScriptInstance::set(const StringName &p_name, const Variant &p_value) { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + bool found = sarr[i]->set(p_name, p_value); + if (found) + return true; + } + + if (String(p_name).begins_with("script_")) { + bool valid; + owner->set(p_name, p_value, &valid); + return valid; + } + return false; +} + +bool MultiScriptInstance::get(const StringName &p_name, Variant &r_ret) const { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + bool found = sarr[i]->get(p_name, r_ret); + if (found) + return true; + } + if (String(p_name).begins_with("script_")) { + bool valid; + r_ret = owner->get(p_name, &valid); + return valid; + } + return false; +} +void MultiScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + Set<String> existing; + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + List<PropertyInfo> pl; + sarr[i]->get_property_list(&pl); + + for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) { + + if (existing.has(E->get().name)) + continue; + + p_properties->push_back(E->get()); + existing.insert(E->get().name); + } + } + + p_properties->push_back(PropertyInfo(Variant::NIL, "Scripts", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); + + for (int i = 0; i < owner->scripts.size(); i++) { + + p_properties->push_back(PropertyInfo(Variant::OBJECT, "script_" + String::chr('a' + i), PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_EDITOR)); + } + + if (owner->scripts.size() < 25) { + + p_properties->push_back(PropertyInfo(Variant::OBJECT, "script_" + String::chr('a' + (owner->scripts.size())), PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_EDITOR)); + } +} + +void MultiScriptInstance::get_method_list(List<MethodInfo> *p_list) const { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + Set<StringName> existing; + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + List<MethodInfo> ml; + sarr[i]->get_method_list(&ml); + + for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) { + + if (existing.has(E->get().name)) + continue; + + p_list->push_back(E->get()); + existing.insert(E->get().name); + } + } +} +bool MultiScriptInstance::has_method(const StringName &p_method) const { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + if (sarr[i]->has_method(p_method)) + return true; + } + + return false; +} + +Variant MultiScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + Variant r = sarr[i]->call(p_method, p_args, p_argcount, r_error); + if (r_error.error == Variant::CallError::CALL_OK) + return r; + else if (r_error.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) + return r; + } + + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); +} + +void MultiScriptInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + sarr[i]->call_multilevel(p_method, p_args, p_argcount); + } +} +void MultiScriptInstance::notification(int p_notification) { + + // ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + ScriptInstance *instance = instances[i]; + + if (!instance) + continue; + + instance->notification(p_notification); + } +} + +Ref<Script> MultiScriptInstance::get_script() const { + + return owner; +} + +ScriptLanguage *MultiScriptInstance::get_language() { + + return MultiScriptLanguage::get_singleton(); +} + +MultiScriptInstance::~MultiScriptInstance() { + + owner->remove_instance(object); +} + +Variant::Type MultiScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { + bool valid = false; + Variant::Type type; + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + type = sarr[i]->get_property_type(p_name, &valid); + if (valid) { + *r_is_valid = valid; + return type; + } + } + *r_is_valid = false; + return Variant::NIL; +} + +ScriptInstance::RPCMode MultiScriptInstance::get_rpc_mode(const StringName &p_method) const { + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + if (sarr[i]->has_method(p_method)) + return sarr[i]->get_rpc_mode(p_method); + } + return RPC_MODE_DISABLED; +} + +ScriptInstance::RPCMode MultiScriptInstance::get_rset_mode(const StringName &p_variable) const { + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for (int i = 0; i < sc; i++) { + + if (!sarr[i]) + continue; + + List<PropertyInfo> properties; + sarr[i]->get_property_list(&properties); + + for (List<PropertyInfo>::Element *P = properties.front(); P; P = P->next()) { + if (P->get().name == p_variable) { + return sarr[i]->get_rset_mode(p_variable); + } + } + } + return RPC_MODE_DISABLED; +} + +/////////////////// + +bool MultiScript::is_tool() const { + + for (int i = 0; i < scripts.size(); i++) { + + if (scripts[i]->is_tool()) + return true; + } + + return false; +} + +bool MultiScript::_set(const StringName &p_name, const Variant &p_value) { + + _THREAD_SAFE_METHOD_ + + String s = String(p_name); + if (s.begins_with("script_")) { + + int idx = s[7]; + if (idx == 0) + return false; + idx -= 'a'; + + ERR_FAIL_COND_V(idx < 0, false); + + Ref<Script> s = p_value; + + if (idx < scripts.size()) { + + if (s.is_null()) + remove_script(idx); + else + set_script(idx, s); + } else if (idx == scripts.size()) { + if (s.is_null()) + return false; + add_script(s); + } else + return false; + + return true; + } + + return false; +} + +bool MultiScript::_get(const StringName &p_name, Variant &r_ret) const { + + _THREAD_SAFE_METHOD_ + + String s = String(p_name); + if (s.begins_with("script_")) { + + int idx = s[7]; + if (idx == 0) + return false; + idx -= 'a'; + + ERR_FAIL_COND_V(idx < 0, false); + + if (idx < scripts.size()) { + + r_ret = get_script(idx); + return true; + } else if (idx == scripts.size()) { + r_ret = Ref<Script>(); + return true; + } + } + + return false; +} +void MultiScript::_get_property_list(List<PropertyInfo> *p_list) const { + + _THREAD_SAFE_METHOD_ + + for (int i = 0; i < scripts.size(); i++) { + + p_list->push_back(PropertyInfo(Variant::OBJECT, "script_" + String::chr('a' + i), PROPERTY_HINT_RESOURCE_TYPE, "Script")); + } + + if (scripts.size() < 25) { + + p_list->push_back(PropertyInfo(Variant::OBJECT, "script_" + String::chr('a' + (scripts.size())), PROPERTY_HINT_RESOURCE_TYPE, "Script")); + } +} + +void MultiScript::set_script(int p_idx, const Ref<Script> &p_script) { + + _THREAD_SAFE_METHOD_ + + ERR_FAIL_INDEX(p_idx, scripts.size()); + ERR_FAIL_COND(p_script.is_null()); + + scripts[p_idx] = p_script; + Ref<Script> s = p_script; + + for (Map<Object *, MultiScriptInstance *>::Element *E = instances.front(); E; E = E->next()) { + + MultiScriptInstance *msi = E->get(); + ScriptInstance *si = msi->instances[p_idx]; + if (si) { + msi->instances[p_idx] = NULL; + memdelete(si); + } + + if (p_script->can_instance()) + msi->instances[p_idx] = s->instance_create(msi->object); + } +} + +Ref<Script> MultiScript::get_script(int p_idx) const { + + _THREAD_SAFE_METHOD_ + + ERR_FAIL_INDEX_V(p_idx, scripts.size(), Ref<Script>()); + + return scripts[p_idx]; +} +void MultiScript::add_script(const Ref<Script> &p_script) { + + _THREAD_SAFE_METHOD_ + ERR_FAIL_COND(p_script.is_null()); + Multi *script_owner = memnew(Multi); + script_instances.push_back(script_owner); + scripts.push_back(p_script); + Ref<Script> s = p_script; + + for (Map<Object *, MultiScriptInstance *>::Element *E = instances.front(); E; E = E->next()) { + + MultiScriptInstance *msi = E->get(); + + if (p_script->can_instance()) { + script_owner->real_owner = msi->object; + msi->instances.push_back(s->instance_create(script_owner)); + } else { + msi->instances.push_back(NULL); + } + + msi->object->_change_notify(); + } + + _change_notify(); +} + +void MultiScript::remove_script(int p_idx) { + + _THREAD_SAFE_METHOD_ + + ERR_FAIL_INDEX(p_idx, scripts.size()); + + scripts.remove(p_idx); + script_instances.remove(p_idx); + + for (Map<Object *, MultiScriptInstance *>::Element *E = instances.front(); E; E = E->next()) { + + MultiScriptInstance *msi = E->get(); + ScriptInstance *si = msi->instances[p_idx]; + msi->instances.remove(p_idx); + if (si) { + memdelete(si); + } + + msi->object->_change_notify(); + } +} + +void MultiScript::remove_instance(Object *p_object) { + + _THREAD_SAFE_METHOD_ + instances.erase(p_object); +} + +bool MultiScript::can_instance() const { + + return true; +} + +StringName MultiScript::get_instance_base_type() const { + + return StringName(); +} +ScriptInstance *MultiScript::instance_create(Object *p_this) { + + _THREAD_SAFE_METHOD_ + MultiScriptInstance *msi = memnew(MultiScriptInstance); + msi->object = p_this; + msi->owner = this; + + for (int i = 0; i < scripts.size(); i++) { + + ScriptInstance *si; + + if (scripts[i]->can_instance()) { + script_instances[i]->real_owner = p_this; + si = scripts[i]->instance_create(script_instances[i]); + } else { + si = NULL; + } + + msi->instances.push_back(si); + } + + instances[p_this] = msi; + p_this->_change_notify(); + return msi; +} +bool MultiScript::instance_has(const Object *p_this) const { + + _THREAD_SAFE_METHOD_ + return instances.has((Object *)p_this); +} + +bool MultiScript::has_source_code() const { + + return false; +} +String MultiScript::get_source_code() const { + + return ""; +} +void MultiScript::set_source_code(const String &p_code) { +} +Error MultiScript::reload(bool p_keep_state) { + + for (int i = 0; i < scripts.size(); i++) + scripts[i]->reload(p_keep_state); + + return OK; +} + +String MultiScript::get_node_type() const { + + return ""; +} + +void MultiScript::_bind_methods() { +} + +ScriptLanguage *MultiScript::get_language() const { + + return MultiScriptLanguage::get_singleton(); +} + +/////////////// + +MultiScript::MultiScript() { +} + +MultiScript::~MultiScript() { + for (int i = 0; i < script_instances.size(); i++) { + memdelete(script_instances[i]); + } + + script_instances.resize(0); +} + +Ref<Script> MultiScript::get_base_script() const { + Ref<MultiScript> base_script; + return base_script; +} + +bool MultiScript::has_method(const StringName &p_method) const { + for (int i = 0; i < scripts.size(); i++) { + if (scripts[i]->has_method(p_method)) { + return true; + } + } + return false; +} + +MethodInfo MultiScript::get_method_info(const StringName &p_method) const { + for (int i = 0; i < scripts.size(); i++) { + if (scripts[i]->has_method(p_method)) { + return scripts[i]->get_method_info(p_method); + } + } + return MethodInfo(); +} + +bool MultiScript::has_script_signal(const StringName &p_signal) const { + for (int i = 0; i < scripts.size(); i++) { + if (scripts[i]->has_script_signal(p_signal)) { + return true; + } + } + return false; +} + +void MultiScript::get_script_signal_list(List<MethodInfo> *r_signals) const { + for (int i = 0; i < scripts.size(); i++) { + scripts[i]->get_script_signal_list(r_signals); + } +} + +bool MultiScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { + for (int i = 0; i < scripts.size(); i++) { + + if (scripts[i]->get_property_default_value(p_property, r_value)) { + return true; + } + } + return false; +} + +void MultiScript::get_script_method_list(List<MethodInfo> *p_list) const { + for (int i = 0; i < scripts.size(); i++) { + scripts[i]->get_script_method_list(p_list); + } +} + +void MultiScript::get_script_property_list(List<PropertyInfo> *p_list) const { + for (int i = 0; i < scripts.size(); i++) { + scripts[i]->get_script_property_list(p_list); + } +} + +void MultiScript::update_exports() { + for (int i = 0; i < scripts.size(); i++) { + scripts[i]->update_exports(); + } +} + +MultiScriptLanguage *MultiScriptLanguage::singleton = NULL; + +MultiScriptLanguage *MultiScriptLanguage::get_singleton() { + return singleton; +} + +String MultiScriptLanguage::get_name() const { + return "MultiScript"; +} + +void MultiScriptLanguage::init() {} + +String MultiScriptLanguage::get_type() const { + return "MultiScript"; +} + +String MultiScriptLanguage::get_extension() const { + return ""; +} + +Error MultiScriptLanguage::execute_file(const String &p_path) { + return OK; +} + +void MultiScriptLanguage::finish() {} + +void MultiScriptLanguage::get_reserved_words(List<String> *p_words) const {} + +void MultiScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {} + +void MultiScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {} + +Ref<Script> MultiScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { + MultiScript *s = memnew(MultiScript); + s->base_class_name = p_base_class_name; + return Ref<MultiScript>(s); +} + +bool MultiScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_fn) const { + return true; +} + +Script *MultiScriptLanguage::create_script() const { + return memnew(MultiScript); +} + +bool MultiScriptLanguage::has_named_classes() const { + return false; +} + +int MultiScriptLanguage::find_function(const String &p_function, const String &p_code) const { + return -1; +} + +String MultiScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const { + return ""; +} + +String MultiScriptLanguage::debug_get_error() const { + return ""; +} + +int MultiScriptLanguage::debug_get_stack_level_count() const { + return 0; +} + +int MultiScriptLanguage::debug_get_stack_level_line(int p_level) const { + return 0; +} + +String MultiScriptLanguage::debug_get_stack_level_function(int p_level) const { + return ""; +} + +String MultiScriptLanguage::debug_get_stack_level_source(int p_level) const { + return ""; +} + +void MultiScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} + +void MultiScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} + +void MultiScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} + +String MultiScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { + return ""; +} + +void MultiScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {} + +void MultiScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {} + +MultiScriptLanguage::MultiScriptLanguage() { + singleton = this; +} + +MultiScriptLanguage::~MultiScriptLanguage() {} + +void MultiScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { +} + +void MultiScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { +} + +void MultiScriptLanguage::reload_all_scripts() { +} + +void MultiScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { +} + +void MultiScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const { +} + +void MultiScriptLanguage::profiling_start() { +} + +void MultiScriptLanguage::profiling_stop() { +} + +int MultiScriptLanguage::profiling_get_accumulated_data(ScriptLanguage::ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +int MultiScriptLanguage::profiling_get_frame_data(ScriptLanguage::ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +void Multi::_bind_methods() { + // ClassDB::bind_method("call", &Multi::call); + // ClassDB::bind_method("call_multilevel", &Multi::call_multilevel); + // ClassDB::bind_method("call_multilevel_reversed", &Multi::call_multilevel_reversed); +} + +Variant Multi::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + if (real_owner) + return real_owner->call(p_method, p_args, p_argcount, r_error); + return Variant(); +} + +void Multi::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { + if (real_owner) + real_owner->call_multilevel(p_method, p_args, p_argcount); +} + +void Multi::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { + if (real_owner) + real_owner->call_multilevel_reversed(p_method, p_args, p_argcount); +} diff --git a/modules/multiscript/multiscript.h b/modules/multiscript/multiscript.h new file mode 100644 index 0000000000..7ec1d5402f --- /dev/null +++ b/modules/multiscript/multiscript.h @@ -0,0 +1,200 @@ +/*************************************************************************/ +/* multiscript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef MULTISCRIPT_H +#define MULTISCRIPT_H + +#include "os/thread_safe.h" +#include "script_language.h" + +class MultiScript; + +class Multi : public Object { + GDCLASS(Multi, Object) + + friend class MultiScript; + + Object *real_owner; + +public: + static void _bind_methods(); + + virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); +}; + +class MultiScriptInstance : public ScriptInstance { + friend class MultiScript; + mutable Vector<ScriptInstance *> instances; + Object *object; + mutable MultiScript *owner; + +public: + virtual bool set(const StringName &p_name, const Variant &p_value); + virtual bool get(const StringName &p_name, Variant &r_ret) const; + virtual void get_property_list(List<PropertyInfo> *p_properties) const; + + virtual void get_method_list(List<MethodInfo> *p_list) const; + virtual bool has_method(const StringName &p_method) const; + virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void notification(int p_notification); + + virtual Ref<Script> get_script() const; + + virtual ScriptLanguage *get_language(); + virtual ~MultiScriptInstance(); + + // ScriptInstance interface +public: + Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const; + RPCMode get_rpc_mode(const StringName &p_method) const; + RPCMode get_rset_mode(const StringName &p_variable) const; +}; + +class MultiScript : public Script { + + _THREAD_SAFE_CLASS_ + friend class MultiScriptInstance; + friend class MultiScriptLanguage; + GDCLASS(MultiScript, Script) + + StringName base_class_name; + + Vector<Ref<Script> > scripts; + Vector<Multi *> script_instances; + + Map<Object *, MultiScriptInstance *> instances; + +protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + + static void _bind_methods(); + +public: + void remove_instance(Object *p_object); + virtual bool can_instance() const; + + virtual StringName get_instance_base_type() const; + virtual ScriptInstance *instance_create(Object *p_this); + virtual bool instance_has(const Object *p_this) const; + + virtual bool has_source_code() const; + virtual String get_source_code() const; + virtual void set_source_code(const String &p_code); + virtual Error reload(bool p_keep_state = false); + + virtual bool is_tool() const; + + virtual String get_node_type() const; + + void set_script(int p_idx, const Ref<Script> &p_script); + Ref<Script> get_script(int p_idx) const; + void remove_script(int p_idx); + void add_script(const Ref<Script> &p_script); + + virtual ScriptLanguage *get_language() const; + + MultiScript(); + ~MultiScript(); + + virtual Ref<Script> get_base_script() const; + virtual bool has_method(const StringName &p_method) const; + virtual MethodInfo get_method_info(const StringName &p_method) const; + virtual bool has_script_signal(const StringName &p_signal) const; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; + virtual void get_script_method_list(List<MethodInfo> *p_list) const; + virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual void update_exports(); +}; + +class MultiScriptLanguage : public ScriptLanguage { + + static MultiScriptLanguage *singleton; + +public: + static _FORCE_INLINE_ MultiScriptLanguage *get_singleton(); + virtual String get_name() const; + + /* LANGUAGE FUNCTIONS */ + virtual void init(); + virtual String get_type() const; + virtual String get_extension() const; + virtual Error execute_file(const String &p_path); + virtual void finish(); + + /* EDITOR FUNCTIONS */ + virtual void get_reserved_words(List<String> *p_words) const; + virtual void get_comment_delimiters(List<String> *p_delimiters) const; + virtual void get_string_delimiters(List<String> *p_delimiters) const; + virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; + virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_fn = NULL) const; + virtual Script *create_script() const; + virtual bool has_named_classes() const; + virtual int find_function(const String &p_function, const String &p_code) const; + virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; + + /* DEBUGGER FUNCTIONS */ + + virtual String debug_get_error() const; + virtual int debug_get_stack_level_count() const; + virtual int debug_get_stack_level_line(int p_level) const; + virtual String debug_get_stack_level_function(int p_level) const; + virtual String debug_get_stack_level_source(int p_level) const; + virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1); + + /* LOADER FUNCTIONS */ + + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual void get_public_functions(List<MethodInfo> *p_functions) const; + + MultiScriptLanguage(); + virtual ~MultiScriptLanguage(); + + // ScriptLanguage interface +public: + void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; + void add_global_constant(const StringName &p_variable, const Variant &p_value); + void reload_all_scripts(); + void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload); + void get_public_constants(List<Pair<String, Variant> > *p_constants) const; + void profiling_start(); + void profiling_stop(); + int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max); + int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max); +}; + +#endif // MULTISCRIPT_H diff --git a/modules/multiscript/register_types.cpp b/modules/multiscript/register_types.cpp new file mode 100644 index 0000000000..8170a2d9c1 --- /dev/null +++ b/modules/multiscript/register_types.cpp @@ -0,0 +1,51 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "multiscript.h" + +#include "core/script_language.h" + +static MultiScriptLanguage *script_multi_script = NULL; + +void register_multiscript_types() { + script_multi_script = memnew(MultiScriptLanguage); + ScriptServer::register_language(script_multi_script); + ClassDB::register_class<MultiScript>(); + + // ClassDB::register_class<Multi>(); +} + +void unregister_multiscript_types() { + if (script_multi_script) { + ScriptServer::unregister_language(script_multi_script); + memdelete(script_multi_script); + } +} diff --git a/modules/cscript/register_types.cpp b/modules/multiscript/register_types.h index 2477bc51e2..b18d1adff2 100644 --- a/modules/cscript/register_types.cpp +++ b/modules/multiscript/register_types.h @@ -1,11 +1,12 @@ /*************************************************************************/ -/* register_types.cpp */ +/* register_types.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,9 +27,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "register_types.h" - -void register_cscript_types() { -} -void unregister_cscript_types() { -} +void register_multiscript_types(); +void unregister_multiscript_types(); diff --git a/modules/ogg/register_types.cpp b/modules/ogg/register_types.cpp index ed796ec092..9837ae12d9 100644 --- a/modules/ogg/register_types.cpp +++ b/modules/ogg/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/ogg/register_types.h b/modules/ogg/register_types.h index cc67b4d2f0..dc84227b80 100644 --- a/modules/ogg/register_types.h +++ b/modules/ogg/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/openssl/register_types.cpp b/modules/openssl/register_types.cpp index 6cc9fa3669..e1ae581caf 100644 --- a/modules/openssl/register_types.cpp +++ b/modules/openssl/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/openssl/register_types.h b/modules/openssl/register_types.h index 3bcee59bfd..ff39ec8798 100644 --- a/modules/openssl/register_types.h +++ b/modules/openssl/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/openssl/stream_peer_openssl.cpp b/modules/openssl/stream_peer_openssl.cpp index 3b25b8a50e..8159296b3c 100644 --- a/modules/openssl/stream_peer_openssl.cpp +++ b/modules/openssl/stream_peer_openssl.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h index 56b45802df..12262da94a 100644 --- a/modules/openssl/stream_peer_openssl.h +++ b/modules/openssl/stream_peer_openssl.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp index 52b055ca82..e361ebf019 100644 --- a/modules/opus/audio_stream_opus.cpp +++ b/modules/opus/audio_stream_opus.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Author: George Marques <george@gmarqu.es> */ /* */ diff --git a/modules/opus/audio_stream_opus.h b/modules/opus/audio_stream_opus.h index f1bee121b2..daf3958c2a 100644 --- a/modules/opus/audio_stream_opus.h +++ b/modules/opus/audio_stream_opus.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Author: George Marques <george@gmarqu.es> */ /* */ diff --git a/modules/opus/register_types.cpp b/modules/opus/register_types.cpp index 8a48c5084e..e8bff58cbb 100644 --- a/modules/opus/register_types.cpp +++ b/modules/opus/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/opus/register_types.h b/modules/opus/register_types.h index 09181b4f03..4517dc5df7 100644 --- a/modules/opus/register_types.h +++ b/modules/opus/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pbm/bitmap_loader_pbm.cpp b/modules/pbm/bitmap_loader_pbm.cpp index 04051fc38f..c8f25ad68c 100644 --- a/modules/pbm/bitmap_loader_pbm.cpp +++ b/modules/pbm/bitmap_loader_pbm.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pbm/bitmap_loader_pbm.h b/modules/pbm/bitmap_loader_pbm.h index 5e5062f435..7a72edaeee 100644 --- a/modules/pbm/bitmap_loader_pbm.h +++ b/modules/pbm/bitmap_loader_pbm.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pbm/register_types.cpp b/modules/pbm/register_types.cpp index abfc08c909..c9531ba14f 100644 --- a/modules/pbm/register_types.cpp +++ b/modules/pbm/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pbm/register_types.h b/modules/pbm/register_types.h index c9a125083d..3888fd6f77 100644 --- a/modules/pbm/register_types.h +++ b/modules/pbm/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pvr/register_types.cpp b/modules/pvr/register_types.cpp index 76fe7970d3..04e20558ce 100644 --- a/modules/pvr/register_types.cpp +++ b/modules/pvr/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pvr/register_types.h b/modules/pvr/register_types.h index ac2ab748df..7ff5237c03 100644 --- a/modules/pvr/register_types.h +++ b/modules/pvr/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 0409998408..62cbd9cd8d 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/pvr/texture_loader_pvr.h b/modules/pvr/texture_loader_pvr.h index 768070ee61..7d60831175 100644 --- a/modules/pvr/texture_loader_pvr.h +++ b/modules/pvr/texture_loader_pvr.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index e8fed382b5..eb9f1d2ab1 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/regex/regex.h b/modules/regex/regex.h index 7aecf9b3ec..106d2649a5 100644 --- a/modules/regex/regex.h +++ b/modules/regex/regex.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp index 2e24edcd84..eaa8f41e33 100644 --- a/modules/regex/register_types.cpp +++ b/modules/regex/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/regex/register_types.h b/modules/regex/register_types.h index 5d676b6daa..3b977edd32 100644 --- a/modules/regex/register_types.h +++ b/modules/regex/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/register_module_types.h b/modules/register_module_types.h index 7d9a130ea1..e30dab2819 100644 --- a/modules/register_module_types.h +++ b/modules/register_module_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index dd46dac234..c6835d4b62 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 198889402a..81f57c6822 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/squish/register_types.cpp b/modules/squish/register_types.cpp index 995711c758..41341db93b 100644 --- a/modules/squish/register_types.cpp +++ b/modules/squish/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/squish/register_types.h b/modules/squish/register_types.h index 0db4301997..3bf1b19dec 100644 --- a/modules/squish/register_types.h +++ b/modules/squish/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 884eb905fa..227e5e61b6 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -180,7 +181,7 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { //does this work? (it's less mem..) //decode_mem_size = ogg_alloc.alloc_buffer_length_in_bytes + info.setup_memory_required + info.temp_memory_required + info.max_frame_size; - //print_line("succeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size)); + //print_line("succeeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size)); length = stb_vorbis_stream_length_in_seconds(ogg_stream); stb_vorbis_close(ogg_stream); diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index c32b3e578d..bb895c4dfa 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp index 36b7ebc11a..726260b45c 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/stb_vorbis/register_types.h b/modules/stb_vorbis/register_types.h index 2824aa9f0c..c17e1eafe9 100644 --- a/modules/stb_vorbis/register_types.h +++ b/modules/stb_vorbis/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index 11d8551db5..9a3d5c2651 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h index 2f0fcbe9a1..c588b58fb2 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index deb54b5d80..1bea5439a3 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/theora/register_types.h b/modules/theora/register_types.h index 582aa785c7..cb9f9d1848 100644 --- a/modules/theora/register_types.h +++ b/modules/theora/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index c390701adb..28463e2cba 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index ea568906da..84b665382b 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index b05ea716ed..4006ad3428 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/register_types.h b/modules/visual_script/register_types.h index f6904420bd..2c0ee56268 100644 --- a/modules/visual_script/register_types.h +++ b/modules/visual_script/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 2b884c34fb..aec60391d3 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -1072,6 +1073,18 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { } } +int VisualScript::get_member_line(const StringName &p_member) const { +#ifdef TOOLS_ENABLED + if (has_function(p_member)) { + for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { + if (E->get().node->cast_to<VisualScriptFunction>()) + return E->key(); + } + } +#endif + return -1; +} + #ifdef TOOLS_ENABLED bool VisualScript::are_subnodes_edited() const { @@ -1489,7 +1502,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p VSDEBUG("WORKING MEM: " + itos(node->working_mem_idx)); if (current_node_id == f->node) { - //if function node, set up function arguments from begining of stack + //if function node, set up function arguments from beginning of stack for (int i = 0; i < f->argument_count; i++) { input_args[i] = &variant_stack[i]; diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index e3af3f4a1b..273a819611 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -355,6 +356,8 @@ public: virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual int get_member_line(const StringName &p_member) const; + #ifdef TOOLS_ENABLED virtual bool are_subnodes_edited() const; #endif diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 378ca06f90..203e0bb483 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 7246239513..8e9c0eca76 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index ae2d4d5df3..f1816a762e 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -1016,7 +1017,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } Rect2 pos = members->get_item_rect(ti); - new_function_menu->set_pos(members->get_global_pos() + pos.pos + Vector2(0, pos.size.y)); + new_function_menu->set_position(members->get_global_position() + pos.pos + Vector2(0, pos.size.y)); new_function_menu->popup(); return; } else if (p_button == 0) { @@ -2152,7 +2153,7 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { _update_graph(); _update_members(); - call_deferred("_center_on_node", p_line); //editor might be just created and size might not exist yet + call_deferred("call_deferred", "_center_on_node", p_line); //editor might be just created and size might not exist yet return; } @@ -2162,6 +2163,12 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { void VisualScriptEditor::trim_trailing_whitespace() { } +void VisualScriptEditor::convert_indent_to_spaces() { +} + +void VisualScriptEditor::convert_indent_to_tabs() { +} + void VisualScriptEditor::ensure_focus() { graph->grab_focus(); @@ -2191,18 +2198,6 @@ void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { } } -bool VisualScriptEditor::goto_method(const String &p_method) { - - if (!script->has_function(p_method)) - return false; - - edited_func = p_method; - selected = edited_func; - _update_members(); - _update_graph(); - return true; -} - void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray p_args) { if (script->has_function(p_function)) { @@ -2516,7 +2511,7 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro port_action_pos = p_release_pos; port_action_popup->set_size(Size2(1, 1)); - port_action_popup->set_pos(graph->get_global_pos() + p_release_pos); + port_action_popup->set_position(graph->get_global_position() + p_release_pos); port_action_popup->popup(); } @@ -2805,7 +2800,7 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i existing = Variant::construct(pinfo.type, &existingp, 1, ce, false); } - default_value_edit->set_pos(p_button->cast_to<Control>()->get_global_pos() + Vector2(0, p_button->cast_to<Control>()->get_size().y)); + default_value_edit->set_position(p_button->cast_to<Control>()->get_global_position() + Vector2(0, p_button->cast_to<Control>()->get_size().y)); default_value_edit->set_size(Size2(1, 1)); if (default_value_edit->edit(NULL, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) { if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 5ece1c9e2c..1fd97cc1bc 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -239,11 +240,12 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void goto_line(int p_line, bool p_with_error = false); virtual void trim_trailing_whitespace(); + virtual void convert_indent_to_spaces(); + virtual void convert_indent_to_tabs(); virtual void ensure_focus(); virtual void tag_saved_version(); virtual void reload(bool p_soft); virtual void get_breakpoints(List<int> *p_breakpoints); - virtual bool goto_method(const String &p_method); virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); virtual void set_debugger_active(bool p_active); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 741b422848..791b5d99ff 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -1180,7 +1181,7 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators."); return NULL; diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index 59a7d9fba0..4a9f59ebc3 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 78847fb588..2deb6064d3 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 1739f67b5b..e3936da9e5 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 3cd20050ce..84224dfcbe 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 3f82edc5f0..b56a3c2bcc 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 68bd1e6d4c..08f4191d3d 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index b2fc115660..c0933d1a78 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 919ced74b9..8f96eb6800 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index 35f72cdfad..638b7b5b41 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 88c8ecc0df..1b10637fdc 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h index a13e934f2a..519ceaaea1 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.h +++ b/modules/vorbis/audio_stream_ogg_vorbis.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/vorbis/register_types.cpp b/modules/vorbis/register_types.cpp index b405acd16b..d9865072b9 100644 --- a/modules/vorbis/register_types.cpp +++ b/modules/vorbis/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/vorbis/register_types.h b/modules/vorbis/register_types.h index b2adb55acd..e7cde7a66c 100644 --- a/modules/vorbis/register_types.h +++ b/modules/vorbis/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webm/register_types.cpp b/modules/webm/register_types.cpp index e50eb337ae..c234f81097 100644 --- a/modules/webm/register_types.cpp +++ b/modules/webm/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webm/register_types.h b/modules/webm/register_types.h index 3df0d7bbaa..cf412e601e 100644 --- a/modules/webm/register_types.h +++ b/modules/webm/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 8d6fbdfe75..9d8062d283 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h index 2b62cf48b6..b2e88347aa 100644 --- a/modules/webm/video_stream_webm.h +++ b/modules/webm/video_stream_webm.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 829e77873a..889eac71a7 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -86,9 +87,11 @@ static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { ERR_FAIL_V(Image()); } - //print_line("width: "+itos(features.width)); - //print_line("height: "+itos(features.height)); - //print_line("alpha: "+itos(features.has_alpha)); + /* + print_line("width: "+itos(features.width)); + print_line("height: "+itos(features.height)); + print_line("alpha: "+itos(features.has_alpha)); + */ PoolVector<uint8_t> dst_image; int datasize = features.width * features.height * (features.has_alpha ? 4 : 3); @@ -129,9 +132,11 @@ Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { ERR_FAIL_V(ERR_FILE_CORRUPT); } + /* print_line("width: " + itos(features.width)); print_line("height: " + itos(features.height)); print_line("alpha: " + itos(features.has_alpha)); + */ src_w = PoolVector<uint8_t>::Write(); diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index ccf22bae13..2d0ac796d3 100644 --- a/modules/webp/image_loader_webp.h +++ b/modules/webp/image_loader_webp.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webp/register_types.cpp b/modules/webp/register_types.cpp index 8a708aae6a..6e29986740 100644 --- a/modules/webp/register_types.cpp +++ b/modules/webp/register_types.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/webp/register_types.h b/modules/webp/register_types.h index ce1f29937b..d0aa148079 100644 --- a/modules/webp/register_types.h +++ b/modules/webp/register_types.h @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |