diff options
Diffstat (limited to 'modules')
193 files changed, 14672 insertions, 3376 deletions
diff --git a/modules/SCsub b/modules/SCsub index 4b9c08cf78..d1c0cdc05c 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -7,7 +7,7 @@ env_modules = env.Clone() Export('env_modules') env.modules_sources = [ - "register_module_types.cpp", + "register_module_types.gen.cpp", ] # env.add_source_files(env.modules_sources,"*.cpp") Export('env') diff --git a/modules/cscript/SCsub b/modules/cscript/SCsub deleted file mode 100644 index 0882406761..0000000000 --- a/modules/cscript/SCsub +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -env.add_source_files(env.modules_sources, "*.cpp") - -Export('env') diff --git a/modules/cscript/godot_c.h b/modules/cscript/godot_c.h deleted file mode 100644 index 58acbf8bf9..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 function (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 ac981d2b1a..71593ebfa9 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 */ @@ -75,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 }, { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 }, { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 }, - { "ATI1", true, false, 4, 8, Image::FORMAT_ATI1 }, - { "ATI2", true, false, 4, 16, Image::FORMAT_ATI2 }, { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, @@ -143,12 +142,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) @@ -438,7 +439,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, wb = PoolVector<uint8_t>::Write(); } - Image img(width, height, mipmaps - 1, info.format, src_data); + Ref<Image> img = memnew(Image(width, height, mipmaps - 1, info.format, src_data)); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); 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/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 13760b33aa..68d5c9e611 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 */ @@ -507,7 +508,7 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { (uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash); /* hash = hash_djb2_one_32( - (uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash ); + (uint32_t)OS::get_singleton()->get_unique_id().hash64(), hash ); */ hash = hash_djb2_one_32( (uint32_t)((uint64_t)this), hash); //rely on aslr heap @@ -574,6 +575,9 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * case COMPRESS_ZLIB: { mode = Compression::MODE_DEFLATE; } break; + case COMPRESS_ZSTD: { + mode = Compression::MODE_ZSTD; + } break; default: { ERR_FAIL_V(0); } } @@ -607,6 +611,10 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE); } break; + case COMPRESS_ZSTD: { + + ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_ZSTD); + } break; default: {} } if (ret < 0) { @@ -628,7 +636,8 @@ void NetworkedMultiplayerENet::_setup_compressor() { enet_host_compress_with_range_coder(host); } break; case COMPRESS_FASTLZ: - case COMPRESS_ZLIB: { + case COMPRESS_ZLIB: + case COMPRESS_ZSTD: { enet_host_compress(host, &enet_compressor); } break; @@ -653,6 +662,7 @@ void NetworkedMultiplayerENet::_bind_methods() { BIND_CONSTANT(COMPRESS_RANGE_CODER); BIND_CONSTANT(COMPRESS_FASTLZ); BIND_CONSTANT(COMPRESS_ZLIB); + BIND_CONSTANT(COMPRESS_ZSTD); } NetworkedMultiplayerENet::NetworkedMultiplayerENet() { diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index deddf4ecc7..f2c3b838e4 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 */ @@ -42,7 +43,8 @@ public: COMPRESS_NONE, COMPRESS_RANGE_CODER, COMPRESS_FASTLZ, - COMPRESS_ZLIB + COMPRESS_ZLIB, + COMPRESS_ZSTD }; private: @@ -111,7 +113,7 @@ public: virtual int get_packet_peer() const; - Error create_server(int p_port, int p_max_peers = 32, int p_in_bandwidth = 0, int p_out_bandwidth = 0); + Error create_server(int p_port, int p_max_clients = 32, int p_in_bandwidth = 0, int p_out_bandwidth = 0); Error create_client(const IP_Address &p_ip, int p_port, int p_in_bandwidth = 0, int p_out_bandwidth = 0); void close_connection(); 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/etc/SCsub b/modules/etc/SCsub new file mode 100644 index 0000000000..8f5937017e --- /dev/null +++ b/modules/etc/SCsub @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_etc = env_modules.Clone() + +# Thirdparty source files +# Not unbundled so far since not widespread as shared library +thirdparty_dir = "#thirdparty/etc2comp/" +thirdparty_sources = [ + "EtcBlock4x4.cpp", + "EtcBlock4x4Encoding.cpp", + "EtcBlock4x4Encoding_ETC1.cpp", + "EtcBlock4x4Encoding_R11.cpp", + "EtcBlock4x4Encoding_RG11.cpp", + "EtcBlock4x4Encoding_RGB8A1.cpp", + "EtcBlock4x4Encoding_RGB8.cpp", + "EtcBlock4x4Encoding_RGBA8.cpp", + "Etc.cpp", + "EtcDifferentialTrys.cpp", + "EtcFilter.cpp", + "EtcImage.cpp", + "EtcIndividualTrys.cpp", + "EtcMath.cpp", + "EtcSortedBlockList.cpp", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_etc.add_source_files(env.modules_sources, thirdparty_sources) +env_etc.Append(CPPPATH=[thirdparty_dir]) + +# Godot source files +env_etc.add_source_files(env.modules_sources, "*.cpp") + +# upstream uses c++11 +env_etc.Append(CXXFLAGS="-std=gnu++11") diff --git a/modules/etc/config.py b/modules/etc/config.py new file mode 100644 index 0000000000..4b0b01b78e --- /dev/null +++ b/modules/etc/config.py @@ -0,0 +1,11 @@ + +def can_build(platform): + return True + + +def configure(env): + # Tools only, disabled for non-tools + # TODO: Find a cleaner way to achieve that + if (env["tools"] == "no"): + env["module_etc_enabled"] = "no" + env.disabled_modules.append("etc") diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp new file mode 100644 index 0000000000..353bd1274a --- /dev/null +++ b/modules/etc/image_etc.cpp @@ -0,0 +1,203 @@ +/*************************************************************************/ +/* image_etc.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 "image_etc.h" +#include "Etc.h" +#include "EtcFilter.h" +#include "image.h" +#include "os/copymem.h" +#include "os/os.h" +#include "print_string.h" + +static Image::Format _get_etc2_mode(Image::DetectChannels format) { + switch (format) { + case Image::DETECTED_L: + case Image::DETECTED_R: + return Image::FORMAT_ETC2_R11; + + case Image::DETECTED_RG: + return Image::FORMAT_ETC2_RG11; + + case Image::DETECTED_RGB: + return Image::FORMAT_ETC2_RGB8; + + case Image::DETECTED_RGBA: + return Image::FORMAT_ETC2_RGBA8; + + // TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551 + } + + ERR_FAIL_COND_V(true, Image::FORMAT_MAX); +} + +static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format) { + switch (format) { + case Image::FORMAT_ETC: + return Etc::Image::Format::ETC1; + + case Image::FORMAT_ETC2_R11: + return Etc::Image::Format::R11; + + case Image::FORMAT_ETC2_R11S: + return Etc::Image::Format::SIGNED_R11; + + case Image::FORMAT_ETC2_RG11: + return Etc::Image::Format::RG11; + + case Image::FORMAT_ETC2_RG11S: + return Etc::Image::Format::SIGNED_RG11; + + case Image::FORMAT_ETC2_RGB8: + return Etc::Image::Format::RGB8; + + case Image::FORMAT_ETC2_RGBA8: + return Etc::Image::Format::RGBA8; + + case Image::FORMAT_ETC2_RGB8A1: + return Etc::Image::Format::RGB8A1; + } + + ERR_FAIL_COND_V(true, Etc::Image::Format::UNKNOWN); +} + +static void _decompress_etc1(Image *p_img) { + // not implemented, to be removed +} + +static void _decompress_etc2(Image *p_img) { + // not implemented, to be removed +} + +static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format, Image::CompressSource p_source) { + Image::Format img_format = p_img->get_format(); + Image::DetectChannels detected_channels = p_img->get_detected_channels(); + + if (p_source == Image::COMPRESS_SOURCE_SRGB && (detected_channels == Image::DETECTED_R || detected_channels == Image::DETECTED_RG)) { + //R and RG do not support SRGB + detected_channels = Image::DETECTED_RGB; + } + + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //use RG channels only for normal + detected_channels = Image::DETECTED_RG; + } + + if (img_format >= Image::FORMAT_DXT1) { + return; //do not compress, already compressed + } + + if (img_format > Image::FORMAT_RGBA8) { + // TODO: we should be able to handle FORMAT_RGBA4444 and FORMAT_RGBA5551 eventually + return; + } + + int imgw = p_img->get_width(), imgh = p_img->get_height(); + ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); + + Image::Format etc_format = force_etc1_format ? Image::FORMAT_ETC : _get_etc2_mode(detected_channels); + + Ref<Image> img = p_img->duplicate(); + + if (img->get_format() != Image::FORMAT_RGBA8) + img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + + PoolVector<uint8_t>::Read r = img->get_data().read(); + + int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0; + + PoolVector<uint8_t> dst_data; + dst_data.resize(target_size); + + PoolVector<uint8_t>::Write w = dst_data.write(); + + // prepare parameters to be passed to etc2comp + int num_cpus = OS::get_singleton()->get_processor_count(); + int encoding_time = 0; + float effort = 0.0; //default, reasonable time + + if (p_lossy_quality > 0.75) + effort = 0.4; + else if (p_lossy_quality > 0.85) + effort = 0.6; + else if (p_lossy_quality > 0.95) + effort = 0.8; + + Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics + Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format); + + int wofs = 0; + + print_line("begin encoding, format: " + Image::get_format_name(etc_format)); + uint64_t t = OS::get_singleton()->get_ticks_msec(); + for (int i = 0; i < mmc + 1; i++) { + // convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF) + // NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion. + int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; + img->get_mipmap_offset_size_and_dimensions(i, mipmap_ofs, mipmap_size, mipmap_w, mipmap_h); + const uint8_t *src = &r[mipmap_ofs]; + + Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h]; + for (int i = 0; i < mipmap_w * mipmap_h; i++) { + int si = i * 4; // RGBA8 + src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); + } + + unsigned char *etc_data = NULL; + unsigned int etc_data_len = 0; + unsigned int extended_width = 0, extended_height = 0; + Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time); + + memcpy(&w[wofs], etc_data, etc_data_len); + wofs += etc_data_len; + + delete[] etc_data; + delete[] src_rgba_f; + } + print_line("time encoding: " + rtos(OS::get_singleton()->get_ticks_msec() - t)); + + p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data); +} + +static void _compress_etc1(Image *p_img, float p_lossy_quality) { + _compress_etc(p_img, p_lossy_quality, true, Image::COMPRESS_SOURCE_GENERIC); +} + +static void _compress_etc2(Image *p_img, float p_lossy_quality, Image::CompressSource p_source) { + _compress_etc(p_img, p_lossy_quality, false, p_source); +} + +void _register_etc_compress_func() { + + Image::_image_compress_etc1_func = _compress_etc1; + //Image::_image_decompress_etc1 = _decompress_etc1; + + Image::_image_compress_etc2_func = _compress_etc2; + //Image::_image_decompress_etc2 = _decompress_etc2; +} diff --git a/modules/etc1/image_etc.h b/modules/etc/image_etc.h index 18461819d6..3cbadef6fa 100644 --- a/modules/etc1/image_etc.h +++ b/modules/etc/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 */ @@ -29,6 +30,6 @@ #ifndef IMAGE_ETC1_H #define IMAGE_ETC1_H -void _register_etc1_compress_func(); +void _register_etc_compress_func(); #endif // IMAGE_ETC_H diff --git a/modules/etc1/register_types.cpp b/modules/etc/register_types.cpp index b3b6419d26..e777859a8f 100644 --- a/modules/etc1/register_types.cpp +++ b/modules/etc/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 */ @@ -33,15 +34,15 @@ static ResourceFormatPKM *resource_loader_pkm = NULL; -void register_etc1_types() { +void register_etc_types() { resource_loader_pkm = memnew(ResourceFormatPKM); ResourceLoader::add_resource_format_loader(resource_loader_pkm); - _register_etc1_compress_func(); + _register_etc_compress_func(); } -void unregister_etc1_types() { +void unregister_etc_types() { memdelete(resource_loader_pkm); } diff --git a/modules/etc1/register_types.h b/modules/etc/register_types.h index fe92496cea..44399376f3 100644 --- a/modules/etc1/register_types.h +++ b/modules/etc/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_etc1_types(); -void unregister_etc1_types(); +void register_etc_types(); +void unregister_etc_types(); diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index bce10e691e..c04528d2a0 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc/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 */ @@ -84,7 +85,7 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, int width = h.origWidth; int height = h.origHeight; - Image img(width, height, mipmaps, Image::FORMAT_ETC, src_data); + Ref<Image> img = memnew(Image(width, height, mipmaps, Image::FORMAT_ETC, src_data)); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc/texture_loader_pkm.h index 19d15d21fc..8a0f06a51a 100644 --- a/modules/etc1/texture_loader_pkm.h +++ b/modules/etc/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/etc1/SCsub b/modules/etc1/SCsub deleted file mode 100644 index 0c5dc66d2e..0000000000 --- a/modules/etc1/SCsub +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_etc1 = env_modules.Clone() - -# Thirdparty source files -# Not unbundled so far since not widespread as shared library -thirdparty_dir = "#thirdparty/rg-etc1/" -thirdparty_sources = [ - "rg_etc1.cpp", -] -thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - -env_etc1.add_source_files(env.modules_sources, thirdparty_sources) -env_etc1.Append(CPPPATH=[thirdparty_dir]) - -# Godot source files -env_etc1.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp deleted file mode 100644 index 642ec027f3..0000000000 --- a/modules/etc1/image_etc.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/*************************************************************************/ -/* image_etc.cpp */ -/*************************************************************************/ -/* 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. */ -/*************************************************************************/ -#include "image_etc.h" -#include "image.h" -#include "os/copymem.h" -#include "print_string.h" -#include "rg_etc1.h" -static void _decompress_etc(Image *p_img) { - - ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_ETC); - - int imgw = p_img->get_width(); - int imgh = p_img->get_height(); - PoolVector<uint8_t> src = p_img->get_data(); - PoolVector<uint8_t> dst; - - PoolVector<uint8_t>::Read r = src.read(); - - int mmc = p_img->get_mipmap_count(); - - for (int i = 0; i <= mmc; i++) { - - dst.resize(dst.size() + imgw * imgh * 3); - const uint8_t *srcbr = &r[p_img->get_mipmap_offset(i)]; - PoolVector<uint8_t>::Write w = dst.write(); - - uint8_t *wptr = &w[dst.size() - imgw * imgh * 3]; - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - uint8_t block[4 * 4 * 4]; - - rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block); - srcbr += 8; - - int maxx = MIN(imgw, 4); - int maxy = MIN(imgh, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t src_ofs = (yy * 4 + xx) * 4; - uint32_t dst_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - wptr[dst_ofs + 0] = block[src_ofs + 0]; - wptr[dst_ofs + 1] = block[src_ofs + 1]; - wptr[dst_ofs + 2] = block[src_ofs + 2]; - } - } - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - } - - r = PoolVector<uint8_t>::Read(); - //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); - *p_img = Image(p_img->get_width(), p_img->get_height(), p_img->has_mipmaps(), Image::FORMAT_RGB8, dst); - if (p_img->has_mipmaps()) - p_img->generate_mipmaps(); -} - -static void _compress_etc(Image *p_img) { - - Image img = *p_img; - - int imgw = img.get_width(), imgh = img.get_height(); - - ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); - - if (img.get_format() != Image::FORMAT_RGB8) - img.convert(Image::FORMAT_RGB8); - - PoolVector<uint8_t> res_data; - PoolVector<uint8_t> dst_data; - PoolVector<uint8_t>::Read r = img.get_data().read(); - - int target_size = Image::get_image_data_size(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC, p_img->has_mipmaps() ? -1 : 0); - int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC) : 0; - - dst_data.resize(target_size); - int mc = 0; - int ofs = 0; - PoolVector<uint8_t>::Write w = dst_data.write(); - - rg_etc1::etc1_pack_params pp; - pp.m_quality = rg_etc1::cLowQuality; - for (int i = 0; i <= mmc; i++) { - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - const uint8_t *src = &r[img.get_mipmap_offset(i)]; - int mmsize = MAX(bw, 1) * MAX(bh, 1) * 8; - - uint8_t *dst = &w[ofs]; - ofs += mmsize; - - //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - //print_line("x: "+itos(x)+" y: "+itos(y)); - - uint8_t block[4 * 4 * 4]; - zeromem(block, 4 * 4 * 4); - uint8_t cblock[8]; - - int maxy = MIN(imgh, 4); - int maxx = MIN(imgw, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t dst_ofs = (yy * 4 + xx) * 4; - uint32_t src_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - block[dst_ofs + 0] = src[src_ofs + 0]; - block[dst_ofs + 1] = src[src_ofs + 1]; - block[dst_ofs + 2] = src[src_ofs + 2]; - block[dst_ofs + 3] = 255; - } - } - - rg_etc1::pack_etc1_block(cblock, (const unsigned int *)block, pp); - for (int j = 0; j < 8; j++) { - - dst[j] = cblock[j]; - } - - dst += 8; - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - mc++; - } - - *p_img = Image(p_img->get_width(), p_img->get_height(), (mc - 1) ? true : false, Image::FORMAT_ETC, dst_data); -} - -void _register_etc1_compress_func() { - - rg_etc1::pack_etc1_block_init(); - Image::_image_compress_etc_func = _compress_etc; - Image::_image_decompress_etc = _decompress_etc; -} diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 5b1e1c189f..6a89e8e087 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -34,10 +34,13 @@ if (env['builtin_freetype'] != 'no'): "src/base/fttype1.c", "src/base/ftwinfnt.c", "src/bdf/bdf.c", + "src/bzip2/ftbzip2.c", "src/cache/ftcache.c", "src/cff/cff.c", "src/cid/type1cid.c", "src/gxvalid/gxvalid.c", + "src/gzip/ftgzip.c", + "src/lzw/ftlzw.c", "src/otvalid/otvalid.c", "src/pcf/pcf.c", "src/pfr/pfr.c", @@ -70,7 +73,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) @@ -78,6 +80,9 @@ if (env['builtin_freetype'] != 'no'): break if not inserted: env.Append(LIBS=[lib]) + env.Append(CCFLAGS=['-DFT2_BUILD_LIBRARY']) + if (env['target'] != 'release'): + env.Append(CCFLAGS=['-DZLIB_DEBUG']) # Godot source files env.add_source_files(env.modules_sources, "*.cpp") 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..65970d48c1 --- /dev/null +++ b/modules/gdnative/SCsub @@ -0,0 +1,13 @@ +#!/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']) +env.Append(CPPPATH=['#modules/gdnative/']) + +if "platform" in env and env["platform"] == "x11": # there has to be a better solution? + env.Append(LINKFLAGS=["-rdynamic"]) +env.use_ptrcall = True 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..440cc45479 --- /dev/null +++ b/modules/gdnative/gdnative.cpp @@ -0,0 +1,340 @@ +/*************************************************************************/ +/* 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_constants.h" +#include "io/file_access_encrypted.h" +#include "os/file_access.h" +#include "os/os.h" +#include "project_settings.h" + +#include "scene/main/scene_tree.h" + +const String init_symbol = "godot_gdnative_init"; +const String terminate_symbol = "godot_gdnative_terminate"; + +String GDNativeLibrary::platform_names[NUM_PLATFORMS] = { + "X11_32bit", + "X11_64bit", + "Windows_32bit", + "Windows_64bit", + "OSX", + + "Android", + "iOS", + + "WebAssembly" +}; +String GDNativeLibrary::platform_lib_ext[NUM_PLATFORMS] = { + "so", + "so", + "dll", + "dll", + "dylib", + + "so", + "dylib", + + "wasm" +}; + +// TODO(karroffel): make this actually do the right thing. +GDNativeLibrary::Platform GDNativeLibrary::current_platform = +#if defined(X11_ENABLED) + X11_64BIT; +#elif defined(WINDOWS_ENABLED) + WINDOWS_64BIT; +#elif defined(OSX_ENABLED) + OSX; +#else + X11_64BIT; // need a sensible default.. +#endif + +GDNativeLibrary::GDNativeLibrary() + : library_paths() { +} + +GDNativeLibrary::~GDNativeLibrary() { +} + +void GDNativeLibrary::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_library_path", "platform", "path"), &GDNativeLibrary::set_library_path); + ClassDB::bind_method(D_METHOD("get_library_path", "platform"), &GDNativeLibrary::get_library_path); +} + +bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + if (name.begins_with("platform/")) { + set_library_path(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_library_path(name.get_slice("/", 1)); + return true; + } + return false; +} + +void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { + for (int i = 0; i < NUM_PLATFORMS; i++) { + p_list->push_back(PropertyInfo(Variant::STRING, + "platform/" + platform_names[i], + PROPERTY_HINT_FILE, + "*." + platform_lib_ext[i])); + } +} + +void GDNativeLibrary::set_library_path(StringName p_platform, String p_path) { + int i; + for (i = 0; i <= NUM_PLATFORMS; i++) { + if (i == NUM_PLATFORMS) break; + if (platform_names[i] == p_platform) { + break; + } + } + + if (i == NUM_PLATFORMS) { + ERR_EXPLAIN(String("No such platform: ") + p_platform); + ERR_FAIL(); + } + + library_paths[i] = p_path; +} + +String GDNativeLibrary::get_library_path(StringName p_platform) const { + int i; + for (i = 0; i <= NUM_PLATFORMS; i++) { + if (i == NUM_PLATFORMS) break; + if (platform_names[i] == p_platform) { + break; + } + } + + if (i == NUM_PLATFORMS) { + ERR_EXPLAIN(String("No such platform: ") + p_platform); + ERR_FAIL_V(""); + } + + return library_paths[i]; +} + +String GDNativeLibrary::get_active_library_path() const { + return library_paths[GDNativeLibrary::current_platform]; +} + +GDNative::GDNative() { + native_handle = NULL; +} + +GDNative::~GDNative() { + // TODO(karroffel): implement ALL the things! +} + +extern "C" void _api_anchor(); + +void GDNative::_compile_dummy_for_api() { + _api_anchor(); +} + +void GDNative::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_library", "library"), &GDNative::set_library); + ClassDB::bind_method(D_METHOD("get_library"), &GDNative::get_library); + + ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize); + ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate); + + // TODO(karroffel): get_native_(raw_)call_types binding? + + // TODO(karroffel): make this a varargs function? + ClassDB::bind_method(D_METHOD("call_native", "procedure_name", "arguments"), &GDNative::call_native); + + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); +} + +void GDNative::set_library(Ref<GDNativeLibrary> p_library) { + ERR_EXPLAIN("Tried to change library of GDNative when it is already set"); + ERR_FAIL_COND(library.is_valid()); + library = p_library; +} + +Ref<GDNativeLibrary> GDNative::get_library() { + return library; +} + +bool GDNative::initialize() { + if (library.is_null()) { + ERR_PRINT("No library set, can't initialize GDNative object"); + return false; + } + + String lib_path = library->get_active_library_path(); + if (lib_path.empty()) { + ERR_PRINT("No library set for this platform"); + return false; + } + + String path = ProjectSettings::get_singleton()->globalize_path(lib_path); + Error err = OS::get_singleton()->open_dynamic_library(path, native_handle); + if (err != OK) { + return false; + } + + void *library_init; + err = OS::get_singleton()->get_dynamic_library_symbol_handle( + native_handle, + init_symbol, + library_init); + + if (err || !library_init) { + OS::get_singleton()->close_dynamic_library(native_handle); + native_handle = NULL; + ERR_PRINT("Failed to obtain godot_gdnative_init symbol"); + return false; + } + + godot_gdnative_init_fn library_init_fpointer; + library_init_fpointer = (godot_gdnative_init_fn)library_init; + + godot_gdnative_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); + options.gd_native_library = (godot_object *)(get_library().ptr()); + + library_init_fpointer(&options); + + return true; +} + +bool GDNative::terminate() { + + if (native_handle == NULL) { + ERR_PRINT("No valid library handle, can't terminate GDNative object"); + return false; + } + + Error error = OK; + void *library_terminate; + error = OS::get_singleton()->get_dynamic_library_symbol_handle( + native_handle, + terminate_symbol, + library_terminate); + if (error) { + OS::get_singleton()->close_dynamic_library(native_handle); + native_handle = NULL; + return true; + } + + godot_gdnative_terminate_fn library_terminate_pointer; + library_terminate_pointer = (godot_gdnative_terminate_fn)library_terminate; + + // TODO(karroffel): remove this? Should be part of NativeScript, not + // GDNative IMO + godot_gdnative_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(native_handle); + native_handle = NULL; + + return true; +} + +bool GDNative::is_initialized() { + return (native_handle != NULL); +} + +void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) { + native_calls.insert(p_call_type, p_callback); +} + +void GDNativeCallRegistry::register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback) { + native_raw_calls.insert(p_raw_call_type, p_callback); +} + +Vector<StringName> GDNativeCallRegistry::get_native_call_types() { + Vector<StringName> call_types; + call_types.resize(native_calls.size()); + + size_t idx = 0; + for (Map<StringName, native_call_cb>::Element *E = native_calls.front(); E; E = E->next(), idx++) { + call_types[idx] = E->key(); + } + + return call_types; +} + +Vector<StringName> GDNativeCallRegistry::get_native_raw_call_types() { + Vector<StringName> call_types; + call_types.resize(native_raw_calls.size()); + + size_t idx = 0; + for (Map<StringName, native_raw_call_cb>::Element *E = native_raw_calls.front(); E; E = E->next(), idx++) { + call_types[idx] = E->key(); + } + + return call_types; +} + +Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) { + + Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type); + if (!E) { + ERR_PRINT((String("No handler for native call type \"" + p_native_call_type) + "\" found").utf8().get_data()); + return Variant(); + } + + String procedure_name = p_procedure_name; + godot_variant result = E->get()(native_handle, (godot_string *)&procedure_name, (godot_array *)&p_arguments); + + return *(Variant *)&result; +} + +void GDNative::call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return) { + + Map<StringName, native_raw_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_raw_calls.find(p_raw_call_type); + if (!E) { + ERR_PRINT((String("No handler for native raw call type \"" + p_raw_call_type) + "\" found").utf8().get_data()); + return; + } + + String procedure_name = p_procedure_name; + E->get()(native_handle, (godot_string *)&procedure_name, data, num_args, args, r_return); +} diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h new file mode 100644 index 0000000000..003ec46a25 --- /dev/null +++ b/modules/gdnative/gdnative.h @@ -0,0 +1,144 @@ +/*************************************************************************/ +/* 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 <godot/gdnative.h> + +class GDNativeLibrary : public Resource { + GDCLASS(GDNativeLibrary, Resource) + + enum Platform { + X11_32BIT, + X11_64BIT, + WINDOWS_32BIT, + WINDOWS_64BIT, + // NOTE(karroffel): I heard OSX 32 bit is dead, so 64 only + OSX, + + // TODO(karroffel): all different android versions and archs + ANDROID, + + // TODO(karroffe): all different iOS versions and archs + IOS, + + // TODO(karroffel): figure out how to deal with web stuff at all... + WASM, + + // TODO(karroffel): does UWP have different libs?? + // UWP, + + NUM_PLATFORMS + + }; + + static String platform_names[NUM_PLATFORMS]; + static String platform_lib_ext[NUM_PLATFORMS]; + + // TODO(karroffel): make this actually do something lol. + static Platform current_platform; + + String library_paths[NUM_PLATFORMS]; + +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; + +public: + GDNativeLibrary(); + ~GDNativeLibrary(); + + static void _bind_methods(); + + void set_library_path(StringName p_platform, String p_path); + String get_library_path(StringName p_platform) const; + + String get_active_library_path() const; +}; + +typedef godot_variant (*native_call_cb)(void *, godot_string *, godot_array *); +typedef void (*native_raw_call_cb)(void *, godot_string *, void *, int, void **, void *); + +struct GDNativeCallRegistry { + static GDNativeCallRegistry *singleton; + + inline GDNativeCallRegistry *get_singleton() { + return singleton; + } + + inline GDNativeCallRegistry() + : native_calls(), + native_raw_calls() {} + + Map<StringName, native_call_cb> native_calls; + Map<StringName, native_raw_call_cb> native_raw_calls; + + void register_native_call_type(StringName p_call_type, native_call_cb p_callback); + void register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback); + + Vector<StringName> get_native_call_types(); + Vector<StringName> get_native_raw_call_types(); +}; + +class GDNative : public Reference { + GDCLASS(GDNative, Reference) + + Ref<GDNativeLibrary> library; + + // TODO(karroffel): different platforms? WASM???? + void *native_handle; + + void _compile_dummy_for_api(); + +public: + GDNative(); + ~GDNative(); + + static void _bind_methods(); + + void set_library(Ref<GDNativeLibrary> p_library); + Ref<GDNativeLibrary> get_library(); + + bool is_initialized(); + + bool initialize(); + bool terminate(); + + Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array()); + void call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return); +}; + +#endif // GDNATIVE_H diff --git a/modules/gdnative/godot/array.cpp b/modules/gdnative/godot/array.cpp new file mode 100644 index 0000000000..97c73dc253 --- /dev/null +++ b/modules/gdnative/godot/array.cpp @@ -0,0 +1,309 @@ +/*************************************************************************/ +/* 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 *r_dest) { + Array *dest = (Array *)r_dest; + memnew_placement(dest, Array); +} + +void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src) { + Array *dest = (Array *)r_dest; + const Array *src = (const Array *)p_src; + memnew_placement(dest, Array(*src)); +} + +void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca) { + Array *dest = (Array *)r_dest; + PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a) { + Array *dest = (Array *)r_dest; + PoolVector<Vector3> *pca = (PoolVector<Vector3> *)p_pv3a; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a) { + Array *dest = (Array *)r_dest; + PoolVector<Vector2> *pca = (PoolVector<Vector2> *)p_pv2a; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa) { + Array *dest = (Array *)r_dest; + PoolVector<String> *pca = (PoolVector<String> *)p_psa; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra) { + Array *dest = (Array *)r_dest; + PoolVector<godot_real> *pca = (PoolVector<godot_real> *)p_pra; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia) { + Array *dest = (Array *)r_dest; + PoolVector<godot_int> *pca = (PoolVector<godot_int> *)p_pia; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba) { + Array *dest = (Array *)r_dest; + PoolVector<uint8_t> *pca = (PoolVector<uint8_t> *)p_pba; + memnew_placement(dest, Array); + dest->resize(pca->size()); + + for (size_t i = 0; i < dest->size(); i++) { + Variant v = pca->operator[](i); + dest->operator[](i) = v; + } +} + +void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value) { + Array *self = (Array *)p_self; + Variant *val = (Variant *)p_value; + self->operator[](p_idx) = *val; +} + +godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx) { + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + const Array *self = (const Array *)p_self; + memnew_placement(dest, Variant(self->operator[](p_idx))); + return raw_dest; +} + +godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx) { + Array *self = (Array *)p_self; + return (godot_variant *)&self->operator[](p_idx); +} + +void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + Variant *val = (Variant *)p_value; + self->append(*val); +} + +void GDAPI godot_array_clear(godot_array *p_self) { + Array *self = (Array *)p_self; + self->clear(); +} + +godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_value; + return self->count(*val); +} + +godot_bool GDAPI godot_array_empty(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->empty(); +} + +void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->erase(*val); +} + +godot_variant GDAPI godot_array_front(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = self->front(); + return v; +} + +godot_variant GDAPI godot_array_back(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = self->back(); + return v; +} + +godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->find(*val, p_from); +} + +godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->find_last(*val); +} + +godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_value; + return self->has(*val); +} + +godot_int GDAPI godot_array_hash(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->hash(); +} + +void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->insert(p_pos, *val); +} + +void GDAPI godot_array_invert(godot_array *p_self) { + Array *self = (Array *)p_self; + self->invert(); +} + +godot_variant GDAPI godot_array_pop_back(godot_array *p_self) { + Array *self = (Array *)p_self; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = self->pop_back(); + return v; +} + +godot_variant GDAPI godot_array_pop_front(godot_array *p_self) { + Array *self = (Array *)p_self; + godot_variant v; + Variant *val = (Variant *)&v; + memnew_placement(val, Variant); + *val = self->pop_front(); + return v; +} + +void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->push_back(*val); +} + +void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->push_front(*val); +} + +void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx) { + Array *self = (Array *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size) { + Array *self = (Array *)p_self; + self->resize(p_size); +} + +godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->rfind(*val, p_from); +} + +godot_int GDAPI godot_array_size(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->size(); +} + +void GDAPI godot_array_sort(godot_array *p_self) { + Array *self = (Array *)p_self; + self->sort(); +} + +void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func) { + Array *self = (Array *)p_self; + const String *func = (const String *)p_func; + self->sort_custom((Object *)p_obj, *func); +} + +void GDAPI godot_array_destroy(godot_array *p_self) { + ((Array *)p_self)->~Array(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/array.h b/modules/gdnative/godot/array.h new file mode 100644 index 0000000000..158170ba0e --- /dev/null +++ b/modules/gdnative/godot/array.h @@ -0,0 +1,122 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_ARRAY_SIZE]; +} godot_array; +#endif + +#include <godot/pool_arrays.h> +#include <godot/variant.h> + +#include <godot/gdnative.h> + +void GDAPI godot_array_new(godot_array *r_dest); +void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src); +void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca); +void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa); +void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra); +void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia); +void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba); + +void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value); + +godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx); + +godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx); + +void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value); + +void GDAPI godot_array_clear(godot_array *p_self); + +godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value); + +godot_bool GDAPI godot_array_empty(const godot_array *p_self); + +void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value); + +godot_variant GDAPI godot_array_front(const godot_array *p_self); + +godot_variant GDAPI godot_array_back(const godot_array *p_self); + +godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from); + +godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what); + +godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value); + +godot_int GDAPI godot_array_hash(const godot_array *p_self); + +void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value); + +void GDAPI godot_array_invert(godot_array *p_self); + +godot_variant GDAPI godot_array_pop_back(godot_array *p_self); + +godot_variant GDAPI godot_array_pop_front(godot_array *p_self); + +void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value); + +void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value); + +void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx); + +void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size); + +godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from); + +godot_int GDAPI godot_array_size(const godot_array *p_self); + +void GDAPI godot_array_sort(godot_array *p_self); + +void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func); + +void GDAPI godot_array_destroy(godot_array *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_ARRAY_H diff --git a/modules/gdnative/godot/basis.cpp b/modules/gdnative/godot/basis.cpp new file mode 100644 index 0000000000..5cf379b7d5 --- /dev/null +++ b/modules/gdnative/godot/basis.cpp @@ -0,0 +1,272 @@ +/*************************************************************************/ +/* 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 "core/math/matrix3.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _basis_api_anchor() {} + +void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis) { + const Vector3 *x_axis = (const Vector3 *)p_x_axis; + const Vector3 *y_axis = (const Vector3 *)p_y_axis; + const Vector3 *z_axis = (const Vector3 *)p_z_axis; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*x_axis, *y_axis, *z_axis); +} + +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi) { + const Vector3 *axis = (const Vector3 *)p_axis; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*axis, p_phi); +} + +void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler) { + const Vector3 *euler = (const Vector3 *)p_euler; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*euler); +} + +godot_string GDAPI godot_basis_as_string(const godot_basis *p_self) { + godot_string ret; + const Basis *self = (const Basis *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->inverse(); + return dest; +} + +godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->transposed(); + return dest; +} + +godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->orthonormalized(); + return dest; +} + +godot_real GDAPI godot_basis_determinant(const godot_basis *p_self) { + const Basis *self = (const Basis *)p_self; + return self->determinant(); +} + +godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Basis *)&dest) = self->rotated(*axis, p_phi); + return dest; +} + +godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + *((Basis *)&dest) = self->scaled(*scale); + return dest; +} + +void GDAPI godot_basis_set_scale(godot_basis *p_self, const godot_vector3 *p_scale) { + Basis *self = (Basis *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + self->set_scale(*scale); +} + +void GDAPI godot_basis_set_rotation_euler(godot_basis *p_self, const godot_vector3 *p_euler) { + Basis *self = (Basis *)p_self; + const Vector3 *euler = (const Vector3 *)p_euler; + self->set_rotation_euler(*euler); +} + +void GDAPI godot_basis_set_rotation_axis_angle(godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_angle) { + Basis *self = (Basis *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + self->set_rotation_axis_angle(*axis, p_angle); +} + +godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + *((Vector3 *)&dest) = self->get_scale(); + return dest; +} + +godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + *((Vector3 *)&dest) = self->get_euler(); + return dest; +} + +godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdotx(*with); +} + +godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdoty(*with); +} + +godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdotz(*with); +} + +godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform(*v); + return dest; +} + +godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform_inv(*v); + return dest; +} + +godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self) { + const Basis *self = (const Basis *)p_self; + return self->get_orthogonal_index(); +} + +void GDAPI godot_basis_new(godot_basis *r_dest) { + Basis *dest = (Basis *)r_dest; + *dest = Basis(); +} + +void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler) { + Basis *dest = (Basis *)r_dest; + const Quat *euler = (const Quat *)p_euler; + *dest = Basis(*euler); +} + +// p_elements is a pointer to an array of 3 (!!) vector3 +void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements) { + const Basis *self = (const Basis *)p_self; + Vector3 *elements = (Vector3 *)p_elements; + elements[0] = self->elements[0]; + elements[1] = self->elements[1]; + elements[2] = self->elements[2]; +} + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *self = (const Basis *)p_self; + *d = self->get_axis(p_axis); + return dest; +} + +void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value) { + Basis *self = (Basis *)p_self; + const Vector3 *value = (const Vector3 *)p_value; + self->set_axis(p_axis, *value); +} + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *self = (const Basis *)p_self; + *d = self->get_row(p_row); + return dest; +} + +void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value) { + Basis *self = (Basis *)p_self; + const Vector3 *value = (const Vector3 *)p_value; + self->set_row(p_row, *value); +} + +godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b) { + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + return *self == *b; +} + +godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_substract(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + *dest = *self * p_b; + return raw_dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/basis.h b/modules/gdnative/godot/basis.h new file mode 100644 index 0000000000..e96b8b730d --- /dev/null +++ b/modules/gdnative/godot/basis.h @@ -0,0 +1,121 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_BASIS_SIZE 36 + +#ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_BASIS_SIZE]; +} godot_basis; +#endif + +#include <godot/gdnative.h> +#include <godot/quat.h> +#include <godot/vector3.h> + +void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis); +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi); +void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler); + +godot_string GDAPI godot_basis_as_string(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self); + +godot_real GDAPI godot_basis_determinant(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale); + +void GDAPI godot_basis_set_scale(godot_basis *p_self, const godot_vector3 *p_scale); + +void GDAPI godot_basis_set_rotation_euler(godot_basis *p_self, const godot_vector3 *p_euler); + +void GDAPI godot_basis_set_rotation_axis_angle(godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_angle); + +godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self); + +godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self); + +godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v); + +godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self); + +void GDAPI godot_basis_new(godot_basis *r_dest); + +void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler); + +// p_elements is a pointer to an array of 3 (!!) vector3 +void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements); + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis); + +void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value); + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row); + +void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value); + +godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_substract(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_BASIS_H diff --git a/modules/gdnative/godot/color.cpp b/modules/gdnative/godot/color.cpp new file mode 100644 index 0000000000..a5ffee1e0b --- /dev/null +++ b/modules/gdnative/godot/color.cpp @@ -0,0 +1,182 @@ +/*************************************************************************/ +/* 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 "core/color.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _color_api_anchor() {} + +void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) { + + Color *dest = (Color *)r_dest; + *dest = Color(p_r, p_g, p_b, p_a); +} + +void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b) { + + Color *dest = (Color *)r_dest; + *dest = Color(p_r, p_g, p_b); +} + +godot_real godot_color_get_r(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->r; +} + +void godot_color_set_r(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->r = val; +} + +godot_real godot_color_get_g(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->g; +} + +void godot_color_set_g(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->g = val; +} + +godot_real godot_color_get_b(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->b; +} + +void godot_color_set_b(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->b = val; +} + +godot_real godot_color_get_a(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->a; +} + +void godot_color_set_a(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->a = val; +} + +godot_real godot_color_get_h(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_h(); +} + +godot_real godot_color_get_s(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_s(); +} + +godot_real godot_color_get_v(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_v(); +} + +godot_string GDAPI godot_color_as_string(const godot_color *p_self) { + godot_string ret; + const Color *self = (const Color *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_int GDAPI godot_color_to_32(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->to_32(); +} + +godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->to_ARGB32(); +} + +godot_real GDAPI godot_color_gray(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->gray(); +} + +godot_color GDAPI godot_color_inverted(const godot_color *p_self) { + godot_color dest; + const Color *self = (const Color *)p_self; + *((Color *)&dest) = self->inverted(); + return dest; +} + +godot_color GDAPI godot_color_contrasted(const godot_color *p_self) { + godot_color dest; + const Color *self = (const Color *)p_self; + *((Color *)&dest) = self->contrasted(); + return dest; +} + +godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t) { + godot_color dest; + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + *((Color *)&dest) = self->linear_interpolate(*b, p_t); + return dest; +} + +godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over) { + godot_color dest; + const Color *self = (const Color *)p_self; + const Color *over = (const Color *)p_over; + *((Color *)&dest) = self->blend(*over); + return dest; +} + +godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha) { + godot_string dest; + const Color *self = (const Color *)p_self; + + memnew_placement(&dest, String(self->to_html(p_with_alpha))); + return dest; +} + +godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b) { + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + return *self == *b; +} + +godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b) { + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + return *self < *b; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/color.h b/modules/gdnative/godot/color.h new file mode 100644 index 0000000000..2cd6b48b48 --- /dev/null +++ b/modules/gdnative/godot/color.h @@ -0,0 +1,96 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_COLOR_SIZE 16 + +#ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_COLOR_SIZE]; +} godot_color; +#endif + +#include <godot/gdnative.h> +#include <godot/string.h> + +void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a); +void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b); + +godot_real godot_color_get_r(const godot_color *p_self); +void godot_color_set_r(godot_color *p_self, const godot_real r); + +godot_real godot_color_get_g(const godot_color *p_self); +void godot_color_set_g(godot_color *p_self, const godot_real g); + +godot_real godot_color_get_b(const godot_color *p_self); +void godot_color_set_b(godot_color *p_self, const godot_real b); + +godot_real godot_color_get_a(const godot_color *p_self); +void godot_color_set_a(godot_color *p_self, const godot_real a); + +godot_real godot_color_get_h(const godot_color *p_self); +godot_real godot_color_get_s(const godot_color *p_self); +godot_real godot_color_get_v(const godot_color *p_self); + +godot_string GDAPI godot_color_as_string(const godot_color *p_self); + +godot_int GDAPI godot_color_to_32(const godot_color *p_self); + +godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self); + +godot_real GDAPI godot_color_gray(const godot_color *p_self); + +godot_color GDAPI godot_color_inverted(const godot_color *p_self); + +godot_color GDAPI godot_color_contrasted(const godot_color *p_self); + +godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t); + +godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over); + +godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha); + +godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b); + +godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_COLOR_H diff --git a/modules/gdnative/godot/dictionary.cpp b/modules/gdnative/godot/dictionary.cpp new file mode 100644 index 0000000000..c538456432 --- /dev/null +++ b/modules/gdnative/godot/dictionary.cpp @@ -0,0 +1,155 @@ +/*************************************************************************/ +/* 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/variant.h" +// core/variant.h before to avoid compile errors with MSVC +#include "core/dictionary.h" +#include "core/io/json.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _dictionary_api_anchor() {} + +void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { + Dictionary *dest = (Dictionary *)r_dest; + memnew_placement(dest, Dictionary); +} + +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src) { + Dictionary *dest = (Dictionary *)r_dest; + const Dictionary *src = (const Dictionary *)p_src; + memnew_placement(dest, Dictionary(*src)); +} + +void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) { + Dictionary *self = (Dictionary *)p_self; + self->~Dictionary(); +} + +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->size(); +} + +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->empty(); +} + +void GDAPI godot_dictionary_clear(godot_dictionary *p_self) { + Dictionary *self = (Dictionary *)p_self; + self->clear(); +} + +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key) { + const Dictionary *self = (const Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + return self->has(*key); +} + +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys) { + const Dictionary *self = (const Dictionary *)p_self; + const Array *keys = (const Array *)p_keys; + return self->has_all(*keys); +} + +void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + self->erase(*key); +} + +godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->hash(); +} + +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self) { + godot_array dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(&dest, Array(self->keys())); + return dest; +} + +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self) { + godot_array dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(&dest, Array(self->values())); + return dest; +} + +godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key) { + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + const Dictionary *self = (const Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + memnew_placement(dest, Variant(self->operator[](*key))); + return raw_dest; +} + +void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + self->operator[](*key) = *value; +} + +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + return (godot_variant *)&self->operator[](*key); +} + +godot_variant GDAPI *godot_dictionary_next(const godot_dictionary *p_self, const godot_variant *p_key) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + return (godot_variant *)self->next(key); +} + +godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b) { + const Dictionary *self = (const Dictionary *)p_self; + const Dictionary *b = (const Dictionary *)p_b; + return *self == *b; +} + +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) { + godot_string raw_dest; + String *dest = (String *)&raw_dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(dest, String(JSON::print(Variant(*self)))); + return raw_dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/dictionary.h b/modules/gdnative/godot/dictionary.h new file mode 100644 index 0000000000..594b02b4dd --- /dev/null +++ b/modules/gdnative/godot/dictionary.h @@ -0,0 +1,89 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_DICTIONARY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_DICTIONARY_SIZE]; +} godot_dictionary; +#endif + +#include <godot/array.h> +#include <godot/gdnative.h> +#include <godot/variant.h> + +void GDAPI godot_dictionary_new(godot_dictionary *r_dest); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src); +void GDAPI godot_dictionary_destroy(godot_dictionary *p_self); + +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self); + +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self); + +void GDAPI godot_dictionary_clear(godot_dictionary *p_self); + +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key); + +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys); + +void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key); + +godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self); + +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self); + +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self); + +godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key); +void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value); + +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key); + +godot_variant GDAPI *godot_dictionary_next(const godot_dictionary *p_self, const godot_variant *p_key); + +godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b); + +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_DICTIONARY_H diff --git a/modules/gdnative/godot/gdnative.cpp b/modules/gdnative/godot/gdnative.cpp new file mode 100644 index 0000000000..4cda1f4560 --- /dev/null +++ b/modules/gdnative/godot/gdnative.cpp @@ -0,0 +1,190 @@ +/*************************************************************************/ +/* 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 <godot/gdnative.h> + +#include "class_db.h" +#include "error_macros.h" +#include "gdnative.h" +#include "global_constants.h" +#include "os/os.h" +#include "project_settings.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 _node_path_api_anchor(); +extern "C" void _rid_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(); + _node_path_api_anchor(); + _rid_api_anchor(); + _dictionary_api_anchor(); + _array_api_anchor(); + _pool_arrays_api_anchor(); + _variant_api_anchor(); +} + +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 *)ProjectSettings::get_singleton()->get_singleton_object(String(p_name)); +} // result shouldn't be freed + +void GDAPI *godot_get_stack_bottom() { + return OS::get_singleton()->get_stack_bottom(); +} + +// 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); +} + +godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error) { + MethodBind *mb = (MethodBind *)p_method_bind; + Object *o = (Object *)p_instance; + const Variant **args = (const Variant **)p_args; + + godot_variant ret; + godot_variant_new_nil(&ret); + + Variant *ret_val = (Variant *)&ret; + + Variant::CallError r_error; + *ret_val = mb->call(o, args, p_arg_count, r_error); + + if (p_call_error) { + p_call_error->error = (godot_variant_call_error_error)r_error.error; + p_call_error->argument = r_error.argument; + p_call_error->expected = (godot_variant_type)r_error.expected; + } + + return ret; +} + +// @Todo +/* +void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind) +{ + +} +*/ + +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); +} + +void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_ERROR); +} + +void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING); +} + +void GDAPI godot_print(const godot_string *p_message) { + print_line(*(String *)p_message); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/gdnative.h b/modules/gdnative/godot/gdnative.h new file mode 100644 index 0000000000..d849999079 --- /dev/null +++ b/modules/gdnative/godot/gdnative.h @@ -0,0 +1,303 @@ +/*************************************************************************/ +/* 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 GODOT_GDNATIVE_H +#define GODOT_GDNATIVE_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 + +// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! +#ifdef _WIN32 +#define GDN_EXPORT __declspec(dllexport) +#else +#define GDN_EXPORT +#endif + +#include <stdbool.h> +#include <stdint.h> + +#define GODOT_API_VERSION 1 + +////// Error + +typedef enum { + 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; + +/////// Brute force forward declarations for the rest +/* +typedef struct godot_variant godot_variant; +typedef struct godot_string godot_string; +typedef struct godot_vector2 godot_vector2; +typedef struct godot_rect2 godot_rect2; +typedef struct godot_vector3 godot_vector3; +typedef struct godot_transform2d godot_transform2d; +typedef struct godot_plane godot_plane; +typedef struct godot_quat godot_quat; +typedef struct godot_rect3 godot_rect3; +typedef struct godot_basis godot_basis; +typedef struct godot_transform godot_transform; +typedef struct godot_color godot_color; +typedef struct godot_node_path godot_node_path; +typedef struct godot_rid godot_rid; +typedef struct godot_dictionary godot_dictionary; +typedef struct godot_array godot_array; +typedef struct godot_pool_byte_array godot_pool_byte_array; +typedef struct godot_pool_int_array godot_pool_int_array; +typedef struct godot_pool_real_array godot_pool_real_array; +typedef struct godot_pool_string_array godot_pool_string_array; +typedef struct godot_pool_vector2_array godot_pool_vector2_array; +typedef struct godot_pool_vector3_array godot_pool_vector3_array; +typedef struct godot_pool_color_array godot_pool_color_array; +*/ +/////// String + +#include <godot/string.h> + +////// Vector2 + +#include <godot/vector2.h> + +////// Rect2 + +#include <godot/rect2.h> + +////// Vector3 + +#include <godot/vector3.h> + +////// Transform2D + +#include <godot/transform2d.h> + +/////// Plane + +#include <godot/plane.h> + +/////// Quat + +#include <godot/quat.h> + +/////// Rect3 + +#include <godot/rect3.h> + +/////// Basis + +#include <godot/basis.h> + +/////// Transform + +#include <godot/transform.h> + +/////// Color + +#include <godot/color.h> + +/////// NodePath + +#include <godot/node_path.h> + +/////// RID + +#include <godot/rid.h> + +/////// Dictionary + +#include <godot/dictionary.h> + +/////// Array + +#include <godot/array.h> + +// single API file for Pool*Array +#include <godot/pool_arrays.h> + +void GDAPI godot_object_destroy(godot_object *p_o); + +////// Variant + +#include <godot/variant.h> + +////// Singleton API + +godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed + +////// OS API + +void GDAPI *godot_get_stack_bottom(); // returns stack bottom of the main thread + +////// MethodBind API + +typedef struct { + 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); +godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); +////// Script API + +typedef struct { + godot_bool in_editor; + uint64_t core_api_hash; + uint64_t editor_api_hash; + uint64_t no_api_hash; + godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized +} godot_gdnative_init_options; + +typedef struct { + godot_bool in_editor; +} godot_gdnative_terminate_options; + +// 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(); + +////// GDNative procedure types +typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *); +typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *); +typedef godot_variant (*godot_gdnative_procedure_fn)(void *, godot_array *); + +////// 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); + +//print using Godot's error handler list +void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line); +void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line); +void GDAPI godot_print(const godot_string *p_message); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_C_H diff --git a/modules/gdnative/godot/icon.png.import b/modules/gdnative/godot/icon.png.import new file mode 100644 index 0000000000..27920124f9 --- /dev/null +++ b/modules/gdnative/godot/icon.png.import @@ -0,0 +1,23 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-aa47d037a37fb38b3b7e7828e4eec407.stex" + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +stream=false +size_limit=0 +detect_3d=true diff --git a/modules/gdnative/godot/node_path.cpp b/modules/gdnative/godot/node_path.cpp new file mode 100644 index 0000000000..f4179361be --- /dev/null +++ b/modules/gdnative/godot/node_path.cpp @@ -0,0 +1,116 @@ +/*************************************************************************/ +/* 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 "core/node_path.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _node_path_api_anchor() {} + +void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) { + NodePath *dest = (NodePath *)r_dest; + const String *from = (const String *)p_from; + memnew_placement(dest, NodePath(*from)); +} + +void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src) { + NodePath *dest = (NodePath *)r_dest; + const NodePath *src = (const NodePath *)p_src; + memnew_placement(dest, NodePath(*src)); +} + +void GDAPI godot_node_path_destroy(godot_node_path *p_self) { + NodePath *self = (NodePath *)p_self; + self->~NodePath(); +} + +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self) { + godot_string ret; + const NodePath *self = (const NodePath *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->is_absolute(); +} + +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->get_name_count(); +} + +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + + memnew_placement(&dest, String(self->get_name(p_idx))); + return dest; +} + +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->get_subname_count(); +} + +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + + memnew_placement(&dest, String(self->get_subname(p_idx))); + return dest; +} + +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + memnew_placement(&dest, String(self->get_property())); + return dest; +} + +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->is_empty(); +} + +godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b) { + const NodePath *self = (const NodePath *)p_self; + const NodePath *b = (const NodePath *)p_b; + return *self == *b; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/node_path.h b/modules/gdnative/godot/node_path.h new file mode 100644 index 0000000000..4d3dc4e0ee --- /dev/null +++ b/modules/gdnative/godot/node_path.h @@ -0,0 +1,77 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_NODE_PATH_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_NODE_PATH_SIZE]; +} godot_node_path; +#endif + +#include <godot/gdnative.h> +#include <godot/string.h> + +void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from); +void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src); +void GDAPI godot_node_path_destroy(godot_node_path *p_self); + +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self); + +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self); + +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self); + +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx); + +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self); + +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx); + +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self); + +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self); + +godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_NODE_PATH_H diff --git a/modules/gdnative/godot/plane.cpp b/modules/gdnative/godot/plane.cpp new file mode 100644 index 0000000000..5c5b302345 --- /dev/null +++ b/modules/gdnative/godot/plane.cpp @@ -0,0 +1,178 @@ +/*************************************************************************/ +/* 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 "core/math/plane.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _plane_api_anchor() {} + +void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) { + + Plane *dest = (Plane *)r_dest; + *dest = Plane(p_a, p_b, p_c, p_d); +} + +void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3) { + const Vector3 *v1 = (const Vector3 *)p_v1; + const Vector3 *v2 = (const Vector3 *)p_v2; + const Vector3 *v3 = (const Vector3 *)p_v3; + Plane *dest = (Plane *)r_dest; + *dest = Plane(*v1, *v2, *v3); +} + +void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d) { + const Vector3 *normal = (const Vector3 *)p_normal; + Plane *dest = (Plane *)r_dest; + *dest = Plane(*normal, p_d); +} + +godot_string GDAPI godot_plane_as_string(const godot_plane *p_self) { + godot_string ret; + const Plane *self = (const Plane *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self) { + godot_plane dest; + const Plane *self = (const Plane *)p_self; + *((Plane *)&dest) = self->normalized(); + return dest; +} + +godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + *((Vector3 *)&dest) = self->center(); + return dest; +} + +godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + *((Vector3 *)&dest) = self->get_any_point(); + return dest; +} + +godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->is_point_over(*point); +} + +godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->distance_to(*point); +} + +godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->has_point(*point, p_epsilon); +} + +godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + *((Vector3 *)&dest) = self->project(*point); + return dest; +} + +godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c) { + const Plane *self = (const Plane *)p_self; + const Plane *b = (const Plane *)p_b; + const Plane *c = (const Plane *)p_c; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersect_3(*b, *c, dest); +} + +godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir) { + const Plane *self = (const Plane *)p_self; + const Vector3 *from = (const Vector3 *)p_from; + const Vector3 *dir = (const Vector3 *)p_dir; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersects_ray(*from, *dir, dest); +} + +godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end) { + const Plane *self = (const Plane *)p_self; + const Vector3 *begin = (const Vector3 *)p_begin; + const Vector3 *end = (const Vector3 *)p_end; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersects_segment(*begin, *end, dest); +} + +godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Plane *self = (const Plane *)p_self; + *dest = -(*self); + return raw_dest; +} + +godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b) { + const Plane *self = (const Plane *)p_self; + const Plane *b = (const Plane *)p_b; + return *self == *b; +} + +void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal) { + Plane *self = (Plane *)p_self; + const Vector3 *normal = (const Vector3 *)p_normal; + self->set_normal(*normal); +} + +godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self) { + const Plane *self = (const Plane *)p_self; + const Vector3 normal = self->get_normal(); + godot_vector3 *v3 = (godot_vector3 *)&normal; + return *v3; +} + +godot_real GDAPI godot_plane_get_d(const godot_plane *p_self) { + const Plane *self = (const Plane *)p_self; + return self->d; +} + +void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d) { + Plane *self = (Plane *)p_self; + self->d = p_d; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/plane.h b/modules/gdnative/godot/plane.h new file mode 100644 index 0000000000..8519ac60c4 --- /dev/null +++ b/modules/gdnative/godot/plane.h @@ -0,0 +1,93 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_PLANE_SIZE 16 + +#ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_PLANE_SIZE]; +} godot_plane; +#endif + +#include <godot/gdnative.h> +#include <godot/vector3.h> + +void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d); +void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3); +void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d); + +godot_string GDAPI godot_plane_as_string(const godot_plane *p_self); + +godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self); + +godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self); + +godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self); + +godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon); + +godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c); + +godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir); + +godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end); + +godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self); + +godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b); + +void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal); + +godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self); + +godot_real GDAPI godot_plane_get_d(const godot_plane *p_self); + +void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_PLANE_H diff --git a/modules/gdnative/godot/pool_arrays.cpp b/modules/gdnative/godot/pool_arrays.cpp new file mode 100644 index 0000000000..fa460be8bc --- /dev/null +++ b/modules/gdnative/godot/pool_arrays.cpp @@ -0,0 +1,633 @@ +/*************************************************************************/ +/* 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 "core/variant.h" +#include "dvector.h" + +#include "core/color.h" +#include "core/math/math_2d.h" +#include "core/math/vector3.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 *r_dest) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; + memnew_placement(dest, PoolVector<uint8_t>); +} + +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *r_dest, const godot_pool_byte_array *p_src) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; + const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src; + memnew_placement(dest, PoolVector<uint8_t>(*src)); +} + +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *r_dest, const godot_array *p_a) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<uint8_t>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->append(p_data); +} + +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_self, const godot_pool_byte_array *p_array) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + PoolVector<uint8_t> *array = (PoolVector<uint8_t> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + return (godot_error)self->insert(p_idx, p_data); +} + +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_self) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_self, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->push_back(p_data); +} + +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_self, const godot_int p_idx) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_self, const godot_int p_size) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->set(p_idx, p_data); +} + +uint8_t GDAPI godot_pool_byte_array_get(const godot_pool_byte_array *p_self, const godot_int p_idx) { + const PoolVector<uint8_t> *self = (const PoolVector<uint8_t> *)p_self; + return self->get(p_idx); +} + +godot_int GDAPI godot_pool_byte_array_size(const godot_pool_byte_array *p_self) { + const PoolVector<uint8_t> *self = (const PoolVector<uint8_t> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_self) { + ((PoolVector<uint8_t> *)p_self)->~PoolVector(); +} + +// int + +void GDAPI godot_pool_int_array_new(godot_pool_int_array *r_dest) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; + memnew_placement(dest, PoolVector<godot_int>); +} + +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *r_dest, const godot_pool_int_array *p_src) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; + const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src; + memnew_placement(dest, PoolVector<godot_int>(*src)); +} + +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *r_dest, const godot_array *p_a) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<godot_int>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_self, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->append(p_data); +} + +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_self, const godot_pool_int_array *p_array) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + PoolVector<godot_int> *array = (PoolVector<godot_int> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + return (godot_error)self->insert(p_idx, p_data); +} + +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_self) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_self, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->push_back(p_data); +} + +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_self, const godot_int p_idx) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_self, const godot_int p_size) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->set(p_idx, p_data); +} + +godot_int GDAPI godot_pool_int_array_get(const godot_pool_int_array *p_self, const godot_int p_idx) { + const PoolVector<godot_int> *self = (const PoolVector<godot_int> *)p_self; + return self->get(p_idx); +} + +godot_int GDAPI godot_pool_int_array_size(const godot_pool_int_array *p_self) { + const PoolVector<godot_int> *self = (const PoolVector<godot_int> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_self) { + ((PoolVector<godot_int> *)p_self)->~PoolVector(); +} + +// real + +void GDAPI godot_pool_real_array_new(godot_pool_real_array *r_dest) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; + memnew_placement(dest, PoolVector<godot_real>); +} + +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *r_dest, const godot_pool_real_array *p_src) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; + const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src; + memnew_placement(dest, PoolVector<godot_real>(*src)); +} + +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *r_dest, const godot_array *p_a) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<godot_real>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->append(p_data); +} + +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_self, const godot_pool_real_array *p_array) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + PoolVector<godot_real> *array = (PoolVector<godot_real> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + return (godot_error)self->insert(p_idx, p_data); +} + +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_self) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_self, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->push_back(p_data); +} + +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_self, const godot_int p_idx) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_self, const godot_int p_size) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->set(p_idx, p_data); +} + +godot_real GDAPI godot_pool_real_array_get(const godot_pool_real_array *p_self, const godot_int p_idx) { + const PoolVector<godot_real> *self = (const PoolVector<godot_real> *)p_self; + return self->get(p_idx); +} + +godot_int GDAPI godot_pool_real_array_size(const godot_pool_real_array *p_self) { + const PoolVector<godot_real> *self = (const PoolVector<godot_real> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_self) { + ((PoolVector<godot_real> *)p_self)->~PoolVector(); +} + +// string + +void GDAPI godot_pool_string_array_new(godot_pool_string_array *r_dest) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; + memnew_placement(dest, PoolVector<String>); +} + +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *r_dest, const godot_pool_string_array *p_src) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; + const PoolVector<String> *src = (const PoolVector<String> *)p_src; + memnew_placement(dest, PoolVector<String>(*src)); +} + +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *r_dest, const godot_array *p_a) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<String>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + String &s = *(String *)p_data; + self->append(s); +} + +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_self, const godot_pool_string_array *p_array) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + PoolVector<String> *array = (PoolVector<String> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + String &s = *(String *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_self) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_self, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + String &s = *(String *)p_data; + self->push_back(s); +} + +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_self, const godot_int p_idx) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_self, const godot_int p_size) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + String &s = *(String *)p_data; + self->set(p_idx, s); +} + +godot_string GDAPI godot_pool_string_array_get(const godot_pool_string_array *p_self, const godot_int p_idx) { + const PoolVector<String> *self = (const PoolVector<String> *)p_self; + godot_string str; + String *s = (String *)&str; + memnew_placement(s, String); + *s = self->get(p_idx); + return str; +} + +godot_int GDAPI godot_pool_string_array_size(const godot_pool_string_array *p_self) { + const PoolVector<String> *self = (const PoolVector<String> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_self) { + ((PoolVector<String> *)p_self)->~PoolVector(); +} + +// vector2 + +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *r_dest) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; + memnew_placement(dest, PoolVector<Vector2>); +} + +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *r_dest, const godot_pool_vector2_array *p_src) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; + const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src; + memnew_placement(dest, PoolVector<Vector2>(*src)); +} + +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *r_dest, const godot_array *p_a) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<Vector2>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_self, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + Vector2 &s = *(Vector2 *)p_data; + self->append(s); +} + +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_self, const godot_pool_vector2_array *p_array) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + PoolVector<Vector2> *array = (PoolVector<Vector2> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + Vector2 &s = *(Vector2 *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_self) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_self, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + Vector2 &s = *(Vector2 *)p_data; + self->push_back(s); +} + +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_self, const godot_int p_idx) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_self, const godot_int p_size) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + Vector2 &s = *(Vector2 *)p_data; + self->set(p_idx, s); +} + +godot_vector2 GDAPI godot_pool_vector2_array_get(const godot_pool_vector2_array *p_self, const godot_int p_idx) { + const PoolVector<Vector2> *self = (const PoolVector<Vector2> *)p_self; + godot_vector2 v; + Vector2 *s = (Vector2 *)&v; + *s = self->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_vector2_array_size(const godot_pool_vector2_array *p_self) { + const PoolVector<Vector2> *self = (const PoolVector<Vector2> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_self) { + ((PoolVector<Vector2> *)p_self)->~PoolVector(); +} + +// vector3 + +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *r_dest) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; + memnew_placement(dest, PoolVector<Vector3>); +} + +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *r_dest, const godot_pool_vector3_array *p_src) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; + const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src; + memnew_placement(dest, PoolVector<Vector3>(*src)); +} + +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *r_dest, const godot_array *p_a) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<Vector3>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + Vector3 &s = *(Vector3 *)p_data; + self->append(s); +} + +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_self, const godot_pool_vector3_array *p_array) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + PoolVector<Vector3> *array = (PoolVector<Vector3> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + Vector3 &s = *(Vector3 *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_self) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_self, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + Vector3 &s = *(Vector3 *)p_data; + self->push_back(s); +} + +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_self, const godot_int p_idx) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_self, const godot_int p_size) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + Vector3 &s = *(Vector3 *)p_data; + self->set(p_idx, s); +} + +godot_vector3 GDAPI godot_pool_vector3_array_get(const godot_pool_vector3_array *p_self, const godot_int p_idx) { + const PoolVector<Vector3> *self = (const PoolVector<Vector3> *)p_self; + godot_vector3 v; + Vector3 *s = (Vector3 *)&v; + *s = self->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_vector3_array_size(const godot_pool_vector3_array *p_self) { + const PoolVector<Vector3> *self = (const PoolVector<Vector3> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_self) { + ((PoolVector<Vector3> *)p_self)->~PoolVector(); +} + +// color + +void GDAPI godot_pool_color_array_new(godot_pool_color_array *r_dest) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; + memnew_placement(dest, PoolVector<Color>); +} + +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *r_dest, const godot_pool_color_array *p_src) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; + const PoolVector<Color> *src = (const PoolVector<Color> *)p_src; + memnew_placement(dest, PoolVector<Color>(*src)); +} + +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *r_dest, const godot_array *p_a) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; + Array *a = (Array *)p_a; + memnew_placement(dest, PoolVector<Color>); + + dest->resize(a->size()); + for (size_t i = 0; i < a->size(); i++) { + dest->set(i, (*a)[i]); + } +} + +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + Color &s = *(Color *)p_data; + self->append(s); +} + +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_self, const godot_pool_color_array *p_array) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + PoolVector<Color> *array = (PoolVector<Color> *)p_array; + self->append_array(*array); +} + +godot_error GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + Color &s = *(Color *)p_data; + return (godot_error)self->insert(p_idx, s); +} + +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_self) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->invert(); +} + +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_self, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + Color &s = *(Color *)p_data; + self->push_back(s); +} + +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_self, const godot_int p_idx) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->remove(p_idx); +} + +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_self, const godot_int p_size) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->resize(p_size); +} + +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + Color &s = *(Color *)p_data; + self->set(p_idx, s); +} + +godot_color GDAPI godot_pool_color_array_get(const godot_pool_color_array *p_self, const godot_int p_idx) { + const PoolVector<Color> *self = (const PoolVector<Color> *)p_self; + godot_color v; + Color *s = (Color *)&v; + *s = self->get(p_idx); + return v; +} + +godot_int GDAPI godot_pool_color_array_size(const godot_pool_color_array *p_self) { + const PoolVector<Color> *self = (const PoolVector<Color> *)p_self; + return self->size(); +} + +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_self) { + ((PoolVector<Color> *)p_self)->~PoolVector(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/pool_arrays.h b/modules/gdnative/godot/pool_arrays.h new file mode 100644 index 0000000000..29517d21ac --- /dev/null +++ b/modules/gdnative/godot/pool_arrays.h @@ -0,0 +1,316 @@ +/*************************************************************************/ +/* 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 + +#define GODOT_POOL_BYTE_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_BYTE_ARRAY_SIZE]; +} godot_pool_byte_array; +#endif + +/////// PoolIntArray + +#define GODOT_POOL_INT_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_INT_ARRAY_SIZE]; +} godot_pool_int_array; +#endif + +/////// PoolRealArray + +#define GODOT_POOL_REAL_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_REAL_ARRAY_SIZE]; +} godot_pool_real_array; +#endif + +/////// PoolStringArray + +#define GODOT_POOL_STRING_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_STRING_ARRAY_SIZE]; +} godot_pool_string_array; +#endif + +/////// PoolVector2Array + +#define GODOT_POOL_VECTOR2_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_VECTOR2_ARRAY_SIZE]; +} godot_pool_vector2_array; +#endif + +/////// PoolVector3Array + +#define GODOT_POOL_VECTOR3_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_VECTOR3_ARRAY_SIZE]; +} godot_pool_vector3_array; +#endif + +/////// PoolColorArray + +#define GODOT_POOL_COLOR_ARRAY_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_POOL_COLOR_ARRAY_SIZE]; +} godot_pool_color_array; +#endif + +#include <godot/array.h> +#include <godot/color.h> +#include <godot/vector2.h> +#include <godot/vector3.h> + +#include <godot/gdnative.h> + +// byte + +void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *r_dest); +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *r_dest, const godot_pool_byte_array *p_src); +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_self, const godot_pool_byte_array *p_array); + +godot_error GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_self); + +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_self, const uint8_t p_data); + +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data); +uint8_t GDAPI godot_pool_byte_array_get(const godot_pool_byte_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_byte_array_size(const godot_pool_byte_array *p_self); + +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_self); + +// int + +void GDAPI godot_pool_int_array_new(godot_pool_int_array *r_dest); +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *r_dest, const godot_pool_int_array *p_src); +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_self, const godot_int p_data); + +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_self, const godot_pool_int_array *p_array); + +godot_error GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data); + +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_self); + +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_self, const godot_int p_data); + +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data); +godot_int GDAPI godot_pool_int_array_get(const godot_pool_int_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_int_array_size(const godot_pool_int_array *p_self); + +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_self); + +// real + +void GDAPI godot_pool_real_array_new(godot_pool_real_array *r_dest); +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *r_dest, const godot_pool_real_array *p_src); +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data); + +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_self, const godot_pool_real_array *p_array); + +godot_error GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data); + +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_self); + +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_self, const godot_real p_data); + +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data); +godot_real GDAPI godot_pool_real_array_get(const godot_pool_real_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_real_array_size(const godot_pool_real_array *p_self); + +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_self); + +// string + +void GDAPI godot_pool_string_array_new(godot_pool_string_array *r_dest); +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *r_dest, const godot_pool_string_array *p_src); +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data); + +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_self, const godot_pool_string_array *p_array); + +godot_error GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data); + +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_self); + +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_self, const godot_string *p_data); + +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data); +godot_string GDAPI godot_pool_string_array_get(const godot_pool_string_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_string_array_size(const godot_pool_string_array *p_self); + +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_self); + +// vector2 + +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *r_dest); +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *r_dest, const godot_pool_vector2_array *p_src); +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_self, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_self, const godot_pool_vector2_array *p_array); + +godot_error GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_self); + +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_self, const godot_vector2 *p_data); + +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data); +godot_vector2 GDAPI godot_pool_vector2_array_get(const godot_pool_vector2_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_vector2_array_size(const godot_pool_vector2_array *p_self); + +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_self); + +// vector3 + +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *r_dest); +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *r_dest, const godot_pool_vector3_array *p_src); +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_self, const godot_pool_vector3_array *p_array); + +godot_error GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_self); + +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_self, const godot_vector3 *p_data); + +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data); +godot_vector3 GDAPI godot_pool_vector3_array_get(const godot_pool_vector3_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_vector3_array_size(const godot_pool_vector3_array *p_self); + +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_self); + +// color + +void GDAPI godot_pool_color_array_new(godot_pool_color_array *r_dest); +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *r_dest, const godot_pool_color_array *p_src); +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *r_dest, const godot_array *p_a); + +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data); + +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_self, const godot_pool_color_array *p_array); + +godot_error GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data); + +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_self); + +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_self, const godot_color *p_data); + +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_self, const godot_int p_idx); + +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_self, const godot_int p_size); + +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data); +godot_color GDAPI godot_pool_color_array_get(const godot_pool_color_array *p_self, const godot_int p_idx); + +godot_int GDAPI godot_pool_color_array_size(const godot_pool_color_array *p_self); + +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_POOL_ARRAYS_H diff --git a/modules/gdnative/godot/quat.cpp b/modules/gdnative/godot/quat.cpp new file mode 100644 index 0000000000..37ee4d6b15 --- /dev/null +++ b/modules/gdnative/godot/quat.cpp @@ -0,0 +1,219 @@ +/*************************************************************************/ +/* 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 "core/math/quat.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _quat_api_anchor() {} + +void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) { + + Quat *dest = (Quat *)r_dest; + *dest = Quat(p_x, p_y, p_z, p_w); +} + +void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle) { + const Vector3 *axis = (const Vector3 *)p_axis; + Quat *dest = (Quat *)r_dest; + *dest = Quat(*axis, p_angle); +} + +godot_real GDAPI godot_quat_get_x(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->x; +} + +void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->x = val; +} + +godot_real GDAPI godot_quat_get_y(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->y; +} + +void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->y = val; +} + +godot_real GDAPI godot_quat_get_z(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->z; +} + +void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->z = val; +} + +godot_real GDAPI godot_quat_get_w(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->w; +} + +void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->w = val; +} + +godot_string GDAPI godot_quat_as_string(const godot_quat *p_self) { + godot_string ret; + const Quat *self = (const Quat *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_quat_length(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->length(); +} + +godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->length_squared(); +} + +godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + *((Quat *)&dest) = self->normalized(); + return dest; +} + +godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->is_normalized(); +} + +godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + *((Quat *)&dest) = self->inverse(); + return dest; +} + +godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b) { + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + return self->dot(*b); +} + +godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Quat *self = (const Quat *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform(*v); + return dest; +} + +godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *((Quat *)&dest) = self->slerp(*b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *((Quat *)&dest) = self->slerpni(*b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + const Quat *pre_a = (const Quat *)p_pre_a; + const Quat *post_b = (const Quat *)p_post_b; + *((Quat *)&dest) = self->cubic_slerp(*b, *pre_a, *post_b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = *self * p_b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_substract(const godot_quat *p_self, const godot_quat *p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = *self / p_b; + return raw_dest; +} + +godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b) { + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + return *self == *b; +} + +godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = -(*self); + return raw_dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/quat.h b/modules/gdnative/godot/quat.h new file mode 100644 index 0000000000..0979653d93 --- /dev/null +++ b/modules/gdnative/godot/quat.h @@ -0,0 +1,104 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_QUAT_SIZE 16 + +#ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_QUAT_SIZE]; +} godot_quat; +#endif + +#include <godot/gdnative.h> +#include <godot/vector3.h> + +void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w); +void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle); + +godot_real GDAPI godot_quat_get_x(const godot_quat *p_self); +void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val); + +godot_real GDAPI godot_quat_get_y(const godot_quat *p_self); +void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val); + +godot_real GDAPI godot_quat_get_z(const godot_quat *p_self); +void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val); + +godot_real GDAPI godot_quat_get_w(const godot_quat *p_self); +void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val); + +godot_string GDAPI godot_quat_as_string(const godot_quat *p_self); + +godot_real GDAPI godot_quat_length(const godot_quat *p_self); + +godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self); + +godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self); + +godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self); + +godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self); + +godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b); + +godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v); + +godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b); + +godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_substract(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b); + +godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_QUAT_H diff --git a/modules/gdnative/godot/rect2.cpp b/modules/gdnative/godot/rect2.cpp new file mode 100644 index 0000000000..023584c4f6 --- /dev/null +++ b/modules/gdnative/godot/rect2.cpp @@ -0,0 +1,157 @@ +/*************************************************************************/ +/* 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 "core/math/math_2d.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rect2_api_anchor() {} + +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { + const Vector2 *position = (const Vector2 *)p_pos; + const Vector2 *size = (const Vector2 *)p_size; + Rect2 *dest = (Rect2 *)r_dest; + *dest = Rect2(*position, *size); +} + +void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) { + + Rect2 *dest = (Rect2 *)r_dest; + *dest = Rect2(p_x, p_y, p_width, p_height); +} + +godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self) { + godot_string ret; + const Rect2 *self = (const Rect2 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self) { + const Rect2 *self = (const Rect2 *)p_self; + return self->get_area(); +} + +godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return self->intersects(*b); +} + +godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return self->encloses(*b); +} + +godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self) { + const Rect2 *self = (const Rect2 *)p_self; + return self->has_no_area(); +} + +godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + *((Rect2 *)&dest) = self->clip(*b); + return dest; +} + +godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + *((Rect2 *)&dest) = self->merge(*b); + return dest; +} + +godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point) { + const Rect2 *self = (const Rect2 *)p_self; + const Vector2 *point = (const Vector2 *)p_point; + return self->has_point(*point); +} + +godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + + *((Rect2 *)&dest) = self->grow(p_by); + return dest; +} + +godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + *((Rect2 *)&dest) = self->expand(*to); + return dest; +} + +godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return *self == *b; +} + +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Rect2 *self = (const Rect2 *)p_self; + *d = self->get_position(); + return dest; +} + +godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Rect2 *self = (const Rect2 *)p_self; + *d = self->get_size(); + return dest; +} + +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) { + Rect2 *self = (Rect2 *)p_self; + const Vector2 *position = (const Vector2 *)p_pos; + self->set_position(*position); +} + +void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) { + Rect2 *self = (Rect2 *)p_self; + const Vector2 *size = (const Vector2 *)p_size; + self->set_size(*size); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/rect2.h b/modules/gdnative/godot/rect2.h new file mode 100644 index 0000000000..cb1ddb58cf --- /dev/null +++ b/modules/gdnative/godot/rect2.h @@ -0,0 +1,86 @@ +/*************************************************************************/ +/* 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 +#define GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED +typedef struct godot_rect2 { + uint8_t _dont_touch_that[16]; +} godot_rect2; +#endif + +#include <godot/gdnative.h> +#include <godot/vector2.h> + +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); +void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height); + +godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self); + +godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self); + +godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self); + +godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point); + +godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by); + +godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to); + +godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self); + +godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self); + +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos); + +void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RECT2_H diff --git a/modules/gdnative/godot/rect3.cpp b/modules/gdnative/godot/rect3.cpp new file mode 100644 index 0000000000..708d2987f2 --- /dev/null +++ b/modules/gdnative/godot/rect3.cpp @@ -0,0 +1,219 @@ +/*************************************************************************/ +/* 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 "core/math/rect3.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rect3_api_anchor() {} + +void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) { + const Vector3 *pos = (const Vector3 *)p_pos; + const Vector3 *size = (const Vector3 *)p_size; + Rect3 *dest = (Rect3 *)r_dest; + *dest = Rect3(*pos, *size); +} + +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self) { + godot_vector3 raw_ret; + const Rect3 *self = (const Rect3 *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->position; + return raw_ret; +} + +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v) { + Rect3 *self = (Rect3 *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->position = *v; +} + +godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self) { + godot_vector3 raw_ret; + const Rect3 *self = (const Rect3 *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->size; + return raw_ret; +} + +void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v) { + Rect3 *self = (Rect3 *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->size = *v; +} + +godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self) { + godot_string ret; + const Rect3 *self = (const Rect3 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_area(); +} + +godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->has_no_area(); +} + +godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->has_no_surface(); +} + +godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + return self->intersects(*with); +} + +godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + return self->encloses(*with); +} + +godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + *((Rect3 *)&dest) = self->merge(*with); + return dest; +} + +godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + *((Rect3 *)&dest) = self->intersection(*with); + return dest; +} + +godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane) { + const Rect3 *self = (const Rect3 *)p_self; + const Plane *plane = (const Plane *)p_plane; + return self->intersects_plane(*plane); +} + +godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to) { + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *from = (const Vector3 *)p_from; + const Vector3 *to = (const Vector3 *)p_to; + return self->intersects_segment(*from, *to); +} + +godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point) { + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->has_point(*point); +} + +godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *dir = (const Vector3 *)p_dir; + *((Vector3 *)&dest) = self->get_support(*dir); + return dest; +} + +godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + *((Vector3 *)&dest) = self->get_longest_axis(); + return dest; +} + +godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_longest_axis_index(); +} + +godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_longest_axis_size(); +} + +godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + *((Vector3 *)&dest) = self->get_shortest_axis(); + return dest; +} + +godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_shortest_axis_index(); +} + +godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_shortest_axis_size(); +} + +godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *to_point = (const Vector3 *)p_to_point; + *((Rect3 *)&dest) = self->expand(*to_point); + return dest; +} + +godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + + *((Rect3 *)&dest) = self->grow(p_by); + return dest; +} + +godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + + *((Vector3 *)&dest) = self->get_endpoint(p_idx); + return dest; +} + +godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *b = (const Rect3 *)p_b; + return *self == *b; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/rect3.h b/modules/gdnative/godot/rect3.h new file mode 100644 index 0000000000..69279351c4 --- /dev/null +++ b/modules/gdnative/godot/rect3.h @@ -0,0 +1,108 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_RECT3_SIZE 24 + +#ifndef GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_RECT3_SIZE]; +} godot_rect3; +#endif + +#include <godot/gdnative.h> +#include <godot/plane.h> +#include <godot/vector3.h> + +void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size); + +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self); +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self); +void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v); + +godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane); + +godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to); + +godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point); + +godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir); + +godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self); + +godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self); + +godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self); + +godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self); + +godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point); + +godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by); + +godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx); + +godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RECT3_H diff --git a/modules/gdnative/godot/rid.cpp b/modules/gdnative/godot/rid.cpp new file mode 100644 index 0000000000..eb9538e692 --- /dev/null +++ b/modules/gdnative/godot/rid.cpp @@ -0,0 +1,75 @@ +/*************************************************************************/ +/* 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 "core/resource.h" +#include "core/rid.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _rid_api_anchor() {} + +void GDAPI godot_rid_new(godot_rid *r_dest) { + RID *dest = (RID *)r_dest; + memnew_placement(dest, RID); +} + +godot_int GDAPI godot_rid_get_id(const godot_rid *p_self) { + const RID *self = (const RID *)p_self; + return self->get_id(); +} + +void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from) { + const Resource *res_from = ((const Object *)p_from)->cast_to<Resource>(); + godot_rid_new(r_dest); + if (res_from) { + RID *dest = (RID *)r_dest; + *dest = RID(res_from->get_rid()); + } +} + +godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b) { + const RID *self = (const RID *)p_self; + const RID *b = (const RID *)p_b; + return *self == *b; +} + +godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b) { + const RID *self = (const RID *)p_self; + const RID *b = (const RID *)p_b; + return *self < *b; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/rid.h b/modules/gdnative/godot/rid.h new file mode 100644 index 0000000000..ac5b5383d9 --- /dev/null +++ b/modules/gdnative/godot/rid.h @@ -0,0 +1,64 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_RID_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_RID_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_RID_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_RID_SIZE]; +} godot_rid; +#endif + +#include <godot/gdnative.h> + +void GDAPI godot_rid_new(godot_rid *r_dest); + +godot_int GDAPI godot_rid_get_id(const godot_rid *p_self); + +void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from); + +godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b); + +godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_RID_H diff --git a/modules/gdnative/godot/string.cpp b/modules/gdnative/godot/string.cpp new file mode 100644 index 0000000000..2235c12a2d --- /dev/null +++ b/modules/gdnative/godot/string.cpp @@ -0,0 +1,1267 @@ +/*************************************************************************/ +/* 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 "core/variant.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 *r_dest) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); +} + +void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src) { + String *dest = (String *)r_dest; + const String *src = (const String *)p_src; + memnew_placement(dest, String(*src)); +} + +void GDAPI godot_string_new_data(godot_string *r_dest, const char *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String(String::utf8(p_contents, p_size))); +} + +void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String(p_contents, p_size)); +} + +void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *p_size) { + String *self = (String *)p_self; + if (p_size != NULL) { + *p_size = self->utf8().length(); + } + if (p_dest != NULL) { + memcpy(p_dest, self->utf8().get_data(), *p_size); + } +} + +wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx) { + String *self = (String *)p_self; + return &(self->operator[](p_idx)); +} + +const char GDAPI *godot_string_c_str(const godot_string *p_self) { + const String *self = (const String *)p_self; + return self->utf8().get_data(); +} + +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) { + const String *self = (const String *)p_self; + return self->c_str(); +} + +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b) { + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + return *self == *b; +} + +godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b) { + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + return *self < *b; +} + +godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const godot_string *p_b) { + godot_string ret; + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + memnew_placement(&ret, String(*self + *b)); + return ret; +} + +void GDAPI godot_string_destroy(godot_string *p_self) { + String *self = (String *)p_self; + self->~String(); +} + +/* Standard size stuff */ + +godot_int GDAPI godot_string_length(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->length(); +} + +/* Helpers */ + +godot_bool GDAPI godot_string_begins_with(const godot_string *p_self, const godot_string *p_string) { + const String *self = (const String *)p_self; + const String *string = (const String *)p_string; + + return self->begins_with(*string); +} + +godot_bool GDAPI godot_string_begins_with_char_array(const godot_string *p_self, const char *p_char_array) { + const String *self = (const String *)p_self; + + return self->begins_with(p_char_array); +} + +godot_array GDAPI godot_string_bigrams(const godot_string *p_self) { + const String *self = (const String *)p_self; + Vector<String> return_value = self->bigrams(); + + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_string GDAPI godot_string_chr(wchar_t p_character) { + godot_string result; + memnew_placement(&result, String(String::chr(p_character))); + + return result; +} + +godot_bool GDAPI godot_string_ends_with(const godot_string *p_self, const godot_string *p_string) { + const String *self = (const String *)p_self; + const String *string = (const String *)p_string; + + return self->ends_with(*string); +} + +godot_int GDAPI godot_string_find(const godot_string *p_self, godot_string p_what) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->find(*what); +} + +godot_int GDAPI godot_string_find_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->find(*what, p_from); +} + +godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_array *p_keys) { + const String *self = (const String *)p_self; + + Vector<String> keys; + Array *keys_proxy = (Array *)p_keys; + keys.resize(keys_proxy->size()); + for (int i = 0; i < keys_proxy->size(); i++) { + keys[i] = (*keys_proxy)[i]; + } + + return self->findmk(keys); +} + +godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_array *p_keys, godot_int p_from) { + const String *self = (const String *)p_self; + + Vector<String> keys; + Array *keys_proxy = (Array *)p_keys; + keys.resize(keys_proxy->size()); + for (int i = 0; i < keys_proxy->size(); i++) { + keys[i] = (*keys_proxy)[i]; + } + + return self->findmk(keys, p_from); +} + +godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key) { + const String *self = (const String *)p_self; + + Vector<String> keys; + Array *keys_proxy = (Array *)p_keys; + keys.resize(keys_proxy->size()); + for (int i = 0; i < keys_proxy->size(); i++) { + keys[i] = (*keys_proxy)[i]; + } + + return self->findmk(keys, p_from, r_key); +} + +godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->findn(*what); +} + +godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->findn(*what, p_from); +} + +godot_int GDAPI find_last(const godot_string *p_self, godot_string p_what) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->find_last(*what); +} + +godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values) { + const String *self = (const String *)p_self; + const Variant *values = (const Variant *)p_values; + godot_string result; + memnew_placement(&result, String(self->format(*values))); + + return result; +} + +godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder) { + const String *self = (const String *)p_self; + const Variant *values = (const Variant *)p_values; + String placeholder = String(p_placeholder); + godot_string result; + memnew_placement(&result, String(self->format(*values, placeholder))); + + return result; +} + +godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len) { + godot_string result; + memnew_placement(&result, String(String::hex_encode_buffer(p_buffer, p_len))); + + return result; +} + +godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hex_to_int(); +} + +godot_int GDAPI godot_string_hex_to_int_without_prefix(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hex_to_int(true); +} + +godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, godot_string p_string) { + const String *self = (const String *)p_self; + String *content = (String *)&p_string; + godot_string result; + memnew_placement(&result, String(self->insert(p_at_pos, *content))); + + return result; +} + +godot_bool GDAPI godot_string_is_numeric(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_numeric(); +} + +godot_bool GDAPI godot_string_is_subsequence_of(const godot_string *p_self, const godot_string *p_string) { + const String *self = (const String *)p_self; + const String *string = (const String *)p_string; + + return self->is_subsequence_of(*string); +} + +godot_bool GDAPI godot_string_is_subsequence_ofi(const godot_string *p_self, const godot_string *p_string) { + const String *self = (const String *)p_self; + const String *string = (const String *)p_string; + + return self->is_subsequence_ofi(*string); +} + +godot_string GDAPI godot_string_lpad(const godot_string *p_self, godot_int p_min_length) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->lpad(p_min_length))); + + return result; +} + +godot_string GDAPI godot_string_lpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character) { + const String *self = (const String *)p_self; + const String *character = (const String *)p_character; + godot_string result; + memnew_placement(&result, String(self->lpad(p_min_length, *character))); + + return result; +} + +godot_bool GDAPI godot_string_match(const godot_string *p_self, const godot_string *p_wildcard) { + const String *self = (const String *)p_self; + const String *wildcard = (const String *)p_wildcard; + + return self->match(*wildcard); +} + +godot_bool GDAPI godot_string_matchn(const godot_string *p_self, const godot_string *p_wildcard) { + const String *self = (const String *)p_self; + const String *wildcard = (const String *)p_wildcard; + + return self->matchn(*wildcard); +} + +godot_string GDAPI godot_string_md5(const uint8_t *p_md5) { + godot_string result; + memnew_placement(&result, String(String::md5(p_md5))); + + return result; +} + +godot_string GDAPI godot_string_num(double p_num) { + godot_string result; + memnew_placement(&result, String(String::num(p_num))); + + return result; +} + +godot_string GDAPI godot_string_num_int64(int64_t p_num, godot_int p_base) { + godot_string result; + memnew_placement(&result, String(String::num_int64(p_num, p_base))); + + return result; +} + +godot_string GDAPI godot_string_num_int64_capitalized(int64_t p_num, godot_int p_base, godot_bool p_capitalize_hex) { + godot_string result; + memnew_placement(&result, String(String::num_int64(p_num, p_base, true))); + + return result; +} + +godot_string GDAPI godot_string_num_real(double p_num) { + godot_string result; + memnew_placement(&result, String(String::num_real(p_num))); + + return result; +} + +godot_string GDAPI godot_string_num_scientific(double p_num) { + godot_string result; + memnew_placement(&result, String(String::num_scientific(p_num))); + + return result; +} + +godot_string GDAPI godot_string_num_with_decimals(double p_num, godot_int p_decimals) { + godot_string result; + memnew_placement(&result, String(String::num(p_num, p_decimals))); + + return result; +} + +godot_string GDAPI godot_string_pad_decimals(const godot_string *p_self, godot_int p_digits) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->pad_decimals(p_digits))); + + return result; +} + +godot_string GDAPI godot_string_pad_zeros(const godot_string *p_self, godot_int p_digits) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->pad_zeros(p_digits))); + + return result; +} + +godot_string GDAPI godot_string_replace(const godot_string *p_self, godot_string p_key, godot_string p_with) { + const String *self = (const String *)p_self; + String *key = (String *)&p_key; + String *with = (String *)&p_with; + godot_string result; + memnew_placement(&result, String(self->replace(*key, *with))); + + return result; +} + +godot_string GDAPI godot_string_replacen(const godot_string *p_self, godot_string p_key, godot_string p_with) { + const String *self = (const String *)p_self; + String *key = (String *)&p_key; + String *with = (String *)&p_with; + godot_string result; + memnew_placement(&result, String(self->replacen(*key, *with))); + + return result; +} + +godot_int GDAPI godot_string_rfind(const godot_string *p_self, godot_string p_what) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->rfind(*what); +} + +godot_int GDAPI godot_string_rfindn(const godot_string *p_self, godot_string p_what) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->rfindn(*what); +} + +godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->rfind(*what, p_from); +} + +godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, godot_string p_what, godot_int p_from) { + const String *self = (const String *)p_self; + String *what = (String *)&p_what; + + return self->rfindn(*what, p_from); +} + +godot_string GDAPI godot_string_replace_first(const godot_string *p_self, godot_string p_key, godot_string p_with) { + const String *self = (const String *)p_self; + String *key = (String *)&p_key; + String *with = (String *)&p_with; + godot_string result; + memnew_placement(&result, String(self->replace_first(*key, *with))); + + return result; +} + +godot_string GDAPI godot_string_rpad(const godot_string *p_self, godot_int p_min_length) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->rpad(p_min_length))); + + return result; +} + +godot_string GDAPI godot_string_rpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character) { + const String *self = (const String *)p_self; + const String *character = (const String *)p_character; + godot_string result; + memnew_placement(&result, String(self->rpad(p_min_length, *character))); + + return result; +} + +godot_real GDAPI godot_string_similarity(const godot_string *p_self, const godot_string *p_string) { + const String *self = (const String *)p_self; + const String *string = (const String *)p_string; + + return self->similarity(*string); +} + +godot_string GDAPI godot_string_sprintf(const godot_string *p_self, const godot_array *p_values, godot_bool *p_error) { + const String *self = (const String *)p_self; + const Array *values = (const Array *)p_values; + + godot_string result; + String return_value = self->sprintf(*values, p_error); + memnew_placement(&result, String(return_value)); + + return result; +} + +godot_string GDAPI godot_string_substr(const godot_string *p_self, godot_int p_from, godot_int p_chars) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->substr(p_from, p_chars))); + + return result; +} + +double GDAPI godot_string_to_double(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->to_double(); +} + +godot_real GDAPI godot_string_to_float(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->to_float(); +} + +godot_int GDAPI godot_string_to_int(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->to_int(); +} + +godot_string GDAPI godot_string_capitalize(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->capitalize())); + + return result; +}; + +godot_string GDAPI godot_string_camelcase_to_underscore(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->camelcase_to_underscore(false))); + + return result; +}; + +godot_string GDAPI godot_string_camelcase_to_underscore_lowercased(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->camelcase_to_underscore())); + + return result; +}; + +double GDAPI godot_string_char_to_double(const char *p_what) { + return String::to_double(p_what); +}; + +godot_int GDAPI godot_string_char_to_int(const char *p_what) { + return String::to_int(p_what); +}; + +int64_t GDAPI godot_string_wchar_to_int(const wchar_t *p_str) { + return String::to_int(p_str); +}; + +godot_int GDAPI godot_string_char_to_int_with_len(const char *p_what, godot_int p_len) { + return String::to_int(p_what, p_len); +}; + +int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_len) { + return String::to_int(p_str, p_len); +}; + +int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hex_to_int64(false); +}; + +int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hex_to_int64(); +}; + +int64_t GDAPI godot_string_to_int64(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->to_int64(); +}; + +double GDAPI godot_string_unicode_char_to_double(const wchar_t *p_str, const wchar_t **r_end) { + return String::to_double(p_str, r_end); +} + +godot_string GDAPI godot_string_get_slice(const godot_string *p_self, godot_string p_splitter, godot_int p_slice) { + const String *self = (const String *)p_self; + String *splitter = (String *)&p_splitter; + godot_string result; + memnew_placement(&result, String(self->get_slice(*splitter, p_slice))); + + return result; +}; + +godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p_splitter, godot_int p_slice) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->get_slicec(p_splitter, p_slice))); + + return result; +}; + +godot_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<String> return_value = self->split(*splitter, false); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<String> return_value = self->split(*splitter); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<float> return_value = self->split_floats(*splitter, false); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_floats_allows_empty(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<float> return_value = self->split_floats(*splitter); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_array *p_splitters) { + const String *self = (const String *)p_self; + + Vector<String> splitters; + Array *splitter_proxy = (Array *)p_splitters; + splitters.resize(splitter_proxy->size()); + for (int i = 0; i < splitter_proxy->size(); i++) { + splitters[i] = (*splitter_proxy)[i]; + } + + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<float> return_value = self->split_floats_mk(splitters, false); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters) { + const String *self = (const String *)p_self; + + Vector<String> splitters; + Array *splitter_proxy = (Array *)p_splitters; + splitters.resize(splitter_proxy->size()); + for (int i = 0; i < splitter_proxy->size(); i++) { + splitters[i] = (*splitter_proxy)[i]; + } + + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<float> return_value = self->split_floats_mk(splitters); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<int> return_value = self->split_ints(*splitter, false); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_ints_allows_empty(const godot_string *p_self, const godot_string *p_splitter) { + const String *self = (const String *)p_self; + const String *splitter = (const String *)p_splitter; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<int> return_value = self->split_ints(*splitter); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_array *p_splitters) { + const String *self = (const String *)p_self; + + Vector<String> splitters; + Array *splitter_proxy = (Array *)p_splitters; + splitters.resize(splitter_proxy->size()); + for (int i = 0; i < splitter_proxy->size(); i++) { + splitters[i] = (*splitter_proxy)[i]; + } + + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<int> return_value = self->split_ints_mk(splitters, false); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters) { + const String *self = (const String *)p_self; + + Vector<String> splitters; + Array *splitter_proxy = (Array *)p_splitters; + splitters.resize(splitter_proxy->size()); + for (int i = 0; i < splitter_proxy->size(); i++) { + splitters[i] = (*splitter_proxy)[i]; + } + + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<int> return_value = self->split_ints_mk(splitters); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_array GDAPI godot_string_split_spaces(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_array result; + memnew_placement(&result, Array); + Array *proxy = (Array *)&result; + Vector<String> return_value = self->split_spaces(); + + proxy->resize(return_value.size()); + for (int i = 0; i < return_value.size(); i++) { + (*proxy)[i] = return_value[i]; + } + + return result; +}; + +godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, godot_string p_splitter) { + const String *self = (const String *)p_self; + String *splitter = (String *)&p_splitter; + + return self->get_slice_count(*splitter); +}; + +wchar_t GDAPI godot_string_char_lowercase(wchar_t p_char) { + return String::char_lowercase(p_char); +}; + +wchar_t GDAPI godot_string_char_uppercase(wchar_t p_char) { + return String::char_uppercase(p_char); +}; + +godot_string GDAPI godot_string_to_lower(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->to_lower())); + + return result; +}; + +godot_string GDAPI godot_string_to_upper(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->to_upper())); + + return result; +}; + +godot_string GDAPI godot_string_get_basename(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->get_basename())); + + return result; +}; + +godot_string GDAPI godot_string_get_extension(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->get_extension())); + + return result; +}; + +godot_string GDAPI godot_string_left(const godot_string *p_self, godot_int p_pos) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->left(p_pos))); + + return result; +}; + +wchar_t GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx) { + const String *self = (const String *)p_self; + + return self->ord_at(p_idx); +}; + +godot_string GDAPI godot_string_plus_file(const godot_string *p_self, const godot_string *p_file) { + const String *self = (const String *)p_self; + const String *file = (const String *)p_file; + godot_string result; + memnew_placement(&result, String(self->plus_file(*file))); + + return result; +}; + +godot_string GDAPI godot_string_right(const godot_string *p_self, godot_int p_pos) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->right(p_pos))); + + return result; +}; + +godot_string GDAPI godot_string_strip_edges(const godot_string *p_self, godot_bool p_left, godot_bool p_right) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->strip_edges(p_left, p_right))); + + return result; +}; + +godot_string GDAPI godot_string_strip_escapes(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->strip_escapes())); + + return result; +}; + +void GDAPI godot_string_erase(godot_string *p_self, godot_int p_pos, godot_int p_chars) { + String *self = (String *)p_self; + + return self->erase(p_pos, p_chars); +}; + +void GDAPI godot_string_ascii(godot_string *p_self, char *result) { + String *self = (String *)p_self; + Vector<char> return_value = self->ascii(); + + for (int i = 0; i < return_value.size(); i++) { + result[i] = return_value[i]; + } +} + +void GDAPI godot_string_ascii_extended(godot_string *p_self, char *result) { + String *self = (String *)p_self; + Vector<char> return_value = self->ascii(true); + + for (int i = 0; i < return_value.size(); i++) { + result[i] = return_value[i]; + } +} + +void GDAPI godot_string_utf8(godot_string *p_self, char *result) { + String *self = (String *)p_self; + Vector<char> return_value = self->utf8(); + + for (int i = 0; i < return_value.size(); i++) { + result[i] = return_value[i]; + } +} + +godot_bool GDAPI godot_string_parse_utf8(godot_string *p_self, const char *p_utf8) { + String *self = (String *)p_self; + + return self->parse_utf8(p_utf8); +}; + +godot_bool GDAPI godot_string_parse_utf8_with_len(godot_string *p_self, const char *p_utf8, godot_int p_len) { + String *self = (String *)p_self; + + return self->parse_utf8(p_utf8, p_len); +}; + +godot_string GDAPI godot_string_chars_to_utf8(const char *p_utf8) { + godot_string result; + memnew_placement(&result, String(String::utf8(p_utf8))); + + return result; +}; + +godot_string GDAPI godot_string_chars_to_utf8_with_len(const char *p_utf8, godot_int p_len) { + godot_string result; + memnew_placement(&result, String(String::utf8(p_utf8, p_len))); + + return result; +}; + +uint32_t GDAPI godot_string_hash(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hash(); +}; + +uint64_t GDAPI godot_string_hash64(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->hash64(); +}; + +uint32_t GDAPI godot_string_hash_chars(const char *p_cstr) { + return String::hash(p_cstr); +}; + +uint32_t GDAPI godot_string_hash_chars_with_len(const char *p_cstr, godot_int p_len) { + return String::hash(p_cstr, p_len); +}; + +uint32_t GDAPI godot_string_hash_utf8_chars(const wchar_t *p_str) { + return String::hash(p_str); +}; + +uint32_t GDAPI godot_string_hash_utf8_chars_with_len(const wchar_t *p_str, godot_int p_len) { + return String::hash(p_str, p_len); +}; + +godot_pool_byte_array GDAPI godot_string_md5_buffer(const godot_string *p_self) { + const String *self = (const String *)p_self; + Vector<uint8_t> tmp_result = self->md5_buffer(); + + godot_pool_byte_array result; + memnew_placement(&result, PoolByteArray); + PoolByteArray *proxy = (PoolByteArray *)&result; + PoolByteArray::Write proxy_writer = proxy->write(); + proxy->resize(tmp_result.size()); + + for (int i = 0; i < tmp_result.size(); i++) { + proxy_writer[i] = tmp_result[i]; + } + + return result; +}; + +godot_string GDAPI godot_string_md5_text(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->md5_text())); + + return result; +}; + +godot_pool_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self) { + const String *self = (const String *)p_self; + Vector<uint8_t> tmp_result = self->sha256_buffer(); + + godot_pool_byte_array result; + memnew_placement(&result, PoolByteArray); + PoolByteArray *proxy = (PoolByteArray *)&result; + PoolByteArray::Write proxy_writer = proxy->write(); + proxy->resize(tmp_result.size()); + + for (int i = 0; i < tmp_result.size(); i++) { + proxy_writer[i] = tmp_result[i]; + } + + return result; +}; + +godot_string GDAPI godot_string_sha256_text(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + memnew_placement(&result, String(self->sha256_text())); + + return result; +}; + +godot_bool godot_string_empty(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->empty(); +}; + +// path functions +godot_string GDAPI godot_string_get_base_dir(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->get_base_dir(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_get_file(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->get_file(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_humanize_size(size_t p_size) { + godot_string result; + String return_value = String::humanize_size(p_size); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_bool GDAPI godot_string_is_abs_path(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_abs_path(); +}; + +godot_bool GDAPI godot_string_is_rel_path(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_rel_path(); +}; + +godot_bool GDAPI godot_string_is_resource_file(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_resource_file(); +}; + +godot_string GDAPI godot_string_path_to(const godot_string *p_self, const godot_string *p_path) { + const String *self = (const String *)p_self; + String *path = (String *)p_path; + godot_string result; + String return_value = self->path_to(*path); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_path_to_file(const godot_string *p_self, const godot_string *p_path) { + const String *self = (const String *)p_self; + String *path = (String *)p_path; + godot_string result; + String return_value = self->path_to_file(*path); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_simplify_path(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->simplify_path(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_c_escape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->c_escape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_c_escape_multiline(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->c_escape_multiline(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_c_unescape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->c_unescape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_http_escape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->http_escape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_http_unescape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->http_unescape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_json_escape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->json_escape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_word_wrap(const godot_string *p_self, godot_int p_chars_per_line) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->word_wrap(p_chars_per_line); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_xml_escape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->xml_escape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_xml_escape_with_quotes(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->xml_escape(true); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_xml_unescape(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->xml_unescape(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_percent_decode(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->percent_decode(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_string GDAPI godot_string_percent_encode(const godot_string *p_self) { + const String *self = (const String *)p_self; + godot_string result; + String return_value = self->percent_encode(); + memnew_placement(&result, String(return_value)); + + return result; +}; + +godot_bool GDAPI godot_string_is_valid_float(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_float(); +}; + +godot_bool GDAPI godot_string_is_valid_hex_number(const godot_string *p_self, godot_bool p_with_prefix) { + const String *self = (const String *)p_self; + + return self->is_valid_hex_number(p_with_prefix); +}; + +godot_bool GDAPI godot_string_is_valid_html_color(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_html_color(); +}; + +godot_bool GDAPI godot_string_is_valid_identifier(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_identifier(); +}; + +godot_bool GDAPI godot_string_is_valid_integer(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_integer(); +}; + +godot_bool GDAPI godot_string_is_valid_ip_address(const godot_string *p_self) { + const String *self = (const String *)p_self; + + return self->is_valid_ip_address(); +}; + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/string.h b/modules/gdnative/godot/string.h new file mode 100644 index 0000000000..c901ce36e6 --- /dev/null +++ b/modules/gdnative/godot/string.h @@ -0,0 +1,228 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_STRING_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_STRING_SIZE]; +} godot_string; +#endif + +#include <godot/gdnative.h> +#include <godot/variant.h> + +void GDAPI godot_string_new(godot_string *r_dest); +void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src); +void GDAPI godot_string_new_data(godot_string *r_dest, const char *p_contents, const int p_size); +void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_contents, const int p_size); + +void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *p_size); + +wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); +const char GDAPI *godot_string_c_str(const godot_string *p_self); +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self); + +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b); +godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b); +godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const godot_string *p_b); + +/* Standard size stuff */ + +godot_int GDAPI godot_string_length(const godot_string *p_self); + +/* Helpers */ + +godot_bool GDAPI godot_string_begins_with(const godot_string *p_self, const godot_string *p_string); +godot_bool GDAPI godot_string_begins_with_char_array(const godot_string *p_self, const char *p_char_array); +godot_array GDAPI godot_string_bigrams(const godot_string *p_self); +godot_string GDAPI godot_string_chr(wchar_t p_character); +godot_bool GDAPI godot_string_ends_with(const godot_string *p_self, const godot_string *p_string); +godot_int GDAPI godot_string_find(const godot_string *p_self, godot_string p_what); +godot_int GDAPI godot_string_find_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_array *p_keys); +godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot_array *p_keys, godot_int p_from); +godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key); +godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what); +godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_int GDAPI find_last(const godot_string *p_self, godot_string p_what); +godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values); +godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder); +godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len); +godot_int GDAPI godot_string_hex_to_int(const godot_string *p_self); +godot_int GDAPI godot_string_hex_to_int_without_prefix(const godot_string *p_self); +godot_string GDAPI godot_string_insert(const godot_string *p_self, godot_int p_at_pos, godot_string p_string); +godot_bool GDAPI godot_string_is_numeric(const godot_string *p_self); +godot_bool GDAPI godot_string_is_subsequence_of(const godot_string *p_self, const godot_string *p_string); +godot_bool GDAPI godot_string_is_subsequence_ofi(const godot_string *p_self, const godot_string *p_string); +godot_string GDAPI godot_string_lpad(const godot_string *p_self, godot_int p_min_length); +godot_string GDAPI godot_string_lpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character); +godot_bool GDAPI godot_string_match(const godot_string *p_self, const godot_string *p_wildcard); +godot_bool GDAPI godot_string_matchn(const godot_string *p_self, const godot_string *p_wildcard); +godot_string GDAPI godot_string_md5(const uint8_t *p_md5); +godot_string GDAPI godot_string_num(double p_num); +godot_string GDAPI godot_string_num_int64(int64_t p_num, godot_int p_base); +godot_string GDAPI godot_string_num_int64_capitalized(int64_t p_num, godot_int p_base, godot_bool p_capitalize_hex); +godot_string GDAPI godot_string_num_real(double p_num); +godot_string GDAPI godot_string_num_scientific(double p_num); +godot_string GDAPI godot_string_num_with_decimals(double p_num, godot_int p_decimals); +godot_string GDAPI godot_string_pad_decimals(const godot_string *p_self, godot_int p_digits); +godot_string GDAPI godot_string_pad_zeros(const godot_string *p_self, godot_int p_digits); +godot_string GDAPI godot_string_replace_first(const godot_string *p_self, godot_string p_key, godot_string p_with); +godot_string GDAPI godot_string_replace(const godot_string *p_self, godot_string p_key, godot_string p_with); +godot_string GDAPI godot_string_replacen(const godot_string *p_self, godot_string p_key, godot_string p_with); +godot_int GDAPI godot_string_rfind(const godot_string *p_self, godot_string p_what); +godot_int GDAPI godot_string_rfindn(const godot_string *p_self, godot_string p_what); +godot_int GDAPI godot_string_rfind_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_int GDAPI godot_string_rfindn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); +godot_string GDAPI godot_string_rpad(const godot_string *p_self, godot_int p_min_length); +godot_string GDAPI godot_string_rpad_with_custom_character(const godot_string *p_self, godot_int p_min_length, const godot_string *p_character); +godot_real GDAPI godot_string_similarity(const godot_string *p_self, const godot_string *p_string); +godot_string GDAPI godot_string_sprintf(const godot_string *p_self, const godot_array *p_values, godot_bool *p_error); +godot_string GDAPI godot_string_substr(const godot_string *p_self, godot_int p_from, godot_int p_chars); +double GDAPI godot_string_to_double(const godot_string *p_self); +godot_real GDAPI godot_string_to_float(const godot_string *p_self); +godot_int GDAPI godot_string_to_int(const godot_string *p_self); + +godot_string GDAPI godot_string_camelcase_to_underscore(const godot_string *p_self); +godot_string GDAPI godot_string_camelcase_to_underscore_lowercased(const godot_string *p_self); +godot_string GDAPI godot_string_capitalize(const godot_string *p_self); +double GDAPI godot_string_char_to_double(const char *p_what); +godot_int GDAPI godot_string_char_to_int(const char *p_what); +int64_t GDAPI godot_string_wchar_to_int(const wchar_t *p_str); +godot_int GDAPI godot_string_char_to_int_with_len(const char *p_what, godot_int p_len); +int64_t GDAPI godot_string_char_to_int64_with_len(const wchar_t *p_str, int p_len); +int64_t GDAPI godot_string_hex_to_int64(const godot_string *p_self); +int64_t GDAPI godot_string_hex_to_int64_with_prefix(const godot_string *p_self); +int64_t GDAPI godot_string_to_int64(const godot_string *p_self); +double GDAPI godot_string_unicode_char_to_double(const wchar_t *p_str, const wchar_t **r_end); + +godot_int GDAPI godot_string_get_slice_count(const godot_string *p_self, godot_string p_splitter); +godot_string GDAPI godot_string_get_slice(const godot_string *p_self, godot_string p_splitter, godot_int p_slice); +godot_string GDAPI godot_string_get_slicec(const godot_string *p_self, wchar_t p_splitter, godot_int p_slice); + +godot_array GDAPI godot_string_split(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_allow_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_floats(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_floats_allows_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const godot_array *p_splitters); +godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters); +godot_array GDAPI godot_string_split_ints(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_ints_allows_empty(const godot_string *p_self, const godot_string *p_splitter); +godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const godot_array *p_splitters); +godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_self, const godot_array *p_splitters); +godot_array GDAPI godot_string_split_spaces(const godot_string *p_self); + +wchar_t GDAPI godot_string_char_lowercase(wchar_t p_char); +wchar_t GDAPI godot_string_char_uppercase(wchar_t p_char); +godot_string GDAPI godot_string_to_lower(const godot_string *p_self); +godot_string GDAPI godot_string_to_upper(const godot_string *p_self); + +godot_string GDAPI godot_string_get_basename(const godot_string *p_self); +godot_string GDAPI godot_string_get_extension(const godot_string *p_self); +godot_string GDAPI godot_string_left(const godot_string *p_self, godot_int p_pos); +wchar_t GDAPI godot_string_ord_at(const godot_string *p_self, godot_int p_idx); +godot_string GDAPI godot_string_plus_file(const godot_string *p_self, const godot_string *p_file); +godot_string GDAPI godot_string_right(const godot_string *p_self, godot_int p_pos); +godot_string GDAPI godot_string_strip_edges(const godot_string *p_self, godot_bool p_left, godot_bool p_right); +godot_string GDAPI godot_string_strip_escapes(const godot_string *p_self); + +void GDAPI godot_string_erase(godot_string *p_self, godot_int p_pos, godot_int p_chars); + +void GDAPI godot_string_ascii(godot_string *p_self, char *result); +void GDAPI godot_string_ascii_extended(godot_string *p_self, char *result); +void GDAPI godot_string_utf8(godot_string *p_self, char *result); +godot_bool GDAPI godot_string_parse_utf8(godot_string *p_self, const char *p_utf8); +godot_bool GDAPI godot_string_parse_utf8_with_len(godot_string *p_self, const char *p_utf8, godot_int p_len); +godot_string GDAPI godot_string_chars_to_utf8(const char *p_utf8); +godot_string GDAPI godot_string_chars_utf8_with_len(const char *p_utf8, godot_int p_len); + +uint32_t GDAPI godot_string_hash(const godot_string *p_self); +uint64_t GDAPI godot_string_hash64(const godot_string *p_self); +uint32_t GDAPI godot_string_hash_chars(const char *p_cstr); +uint32_t GDAPI godot_string_hash_chars_with_len(const char *p_cstr, godot_int p_len); +uint32_t GDAPI godot_string_hash_utf8_chars(const wchar_t *p_str); +uint32_t GDAPI godot_string_hash_utf8_chars_with_len(const wchar_t *p_str, godot_int p_len); +godot_pool_byte_array GDAPI godot_string_md5_buffer(const godot_string *p_self); +godot_string GDAPI godot_string_md5_text(const godot_string *p_self); +godot_pool_byte_array GDAPI godot_string_sha256_buffer(const godot_string *p_self); +godot_string GDAPI godot_string_sha256_text(const godot_string *p_self); + +godot_bool godot_string_empty(const godot_string *p_self); + +// path functions +godot_string GDAPI godot_string_get_base_dir(const godot_string *p_self); +godot_string GDAPI godot_string_get_file(const godot_string *p_self); +godot_string GDAPI godot_string_humanize_size(size_t p_size); +godot_bool GDAPI godot_string_is_abs_path(const godot_string *p_self); +godot_bool GDAPI godot_string_is_rel_path(const godot_string *p_self); +godot_bool GDAPI godot_string_is_resource_file(const godot_string *p_self); +godot_string GDAPI godot_string_path_to(const godot_string *p_self, const godot_string *p_path); +godot_string GDAPI godot_string_path_to_file(const godot_string *p_self, const godot_string *p_path); +godot_string GDAPI godot_string_simplify_path(const godot_string *p_self); + +godot_string GDAPI godot_string_c_escape(const godot_string *p_self); +godot_string GDAPI godot_string_c_escape_multiline(const godot_string *p_self); +godot_string GDAPI godot_string_c_unescape(const godot_string *p_self); +godot_string GDAPI godot_string_http_escape(const godot_string *p_self); +godot_string GDAPI godot_string_http_unescape(const godot_string *p_self); +godot_string GDAPI godot_string_json_escape(const godot_string *p_self); +godot_string GDAPI godot_string_word_wrap(const godot_string *p_self, godot_int p_chars_per_line); +godot_string GDAPI godot_string_xml_escape(const godot_string *p_self); +godot_string GDAPI godot_string_xml_escape_with_quotes(const godot_string *p_self); +godot_string GDAPI godot_string_xml_unescape(const godot_string *p_self); + +godot_string GDAPI godot_string_percent_decode(const godot_string *p_self); +godot_string GDAPI godot_string_percent_encode(const godot_string *p_self); + +godot_bool GDAPI godot_string_is_valid_float(const godot_string *p_self); +godot_bool GDAPI godot_string_is_valid_hex_number(const godot_string *p_self, godot_bool p_with_prefix); +godot_bool GDAPI godot_string_is_valid_html_color(const godot_string *p_self); +godot_bool GDAPI godot_string_is_valid_identifier(const godot_string *p_self); +godot_bool GDAPI godot_string_is_valid_integer(const godot_string *p_self); +godot_bool GDAPI godot_string_is_valid_ip_address(const godot_string *p_self); + +void GDAPI godot_string_destroy(godot_string *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_STRING_H diff --git a/modules/gdnative/godot/transform.cpp b/modules/gdnative/godot/transform.cpp new file mode 100644 index 0000000000..87fee918bd --- /dev/null +++ b/modules/gdnative/godot/transform.cpp @@ -0,0 +1,223 @@ +/*************************************************************************/ +/* 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 "core/math/transform.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _transform_api_anchor() {} + +void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin) { + const Vector3 *x_axis = (const Vector3 *)p_x_axis; + const Vector3 *y_axis = (const Vector3 *)p_y_axis; + const Vector3 *z_axis = (const Vector3 *)p_z_axis; + const Vector3 *origin = (const Vector3 *)p_origin; + Transform *dest = (Transform *)r_dest; + dest->basis.set_axis(0, *x_axis); + dest->basis.set_axis(1, *y_axis); + dest->basis.set_axis(2, *z_axis); + dest->origin = *origin; +} + +void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin) { + const Basis *basis = (const Basis *)p_basis; + const Vector3 *origin = (const Vector3 *)p_origin; + Transform *dest = (Transform *)r_dest; + *dest = Transform(*basis, *origin); +} + +godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self) { + godot_basis dest; + const Transform *self = (const Transform *)p_self; + *((Basis *)&dest) = self->basis; + return dest; +} + +void GDAPI godot_transform_set_basis(godot_transform *p_self, godot_basis *p_v) { + Transform *self = (Transform *)p_self; + const Basis *v = (const Basis *)p_v; + self->basis = *v; +} + +godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self) { + godot_vector3 dest; + const Transform *self = (const Transform *)p_self; + *((Vector3 *)&dest) = self->origin; + return dest; +} + +void GDAPI godot_transform_set_origin(godot_transform *p_self, godot_vector3 *p_v) { + Transform *self = (Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->origin = *v; +} + +godot_string GDAPI godot_transform_as_string(const godot_transform *p_self) { + godot_string ret; + const Transform *self = (const Transform *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->inverse(); + return dest; +} + +godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->affine_inverse(); + return dest; +} + +godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->orthonormalized(); + return dest; +} + +godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Transform *)&dest) = self->rotated(*axis, p_phi); + return dest; +} + +godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + *((Transform *)&dest) = self->scaled(*scale); + return dest; +} + +godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *ofs = (const Vector3 *)p_ofs; + *((Transform *)&dest) = self->translated(*ofs); + return dest; +} + +godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *target = (const Vector3 *)p_target; + const Vector3 *up = (const Vector3 *)p_up; + *((Transform *)&dest) = self->looking_at(*target, *up); + return dest; +} + +godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Plane *v = (const Plane *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Plane *v = (const Plane *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +void GDAPI godot_transform_new_identity(godot_transform *r_dest) { + Transform *dest = (Transform *)r_dest; + *dest = Transform(); +} + +godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b) { + const Transform *self = (const Transform *)p_self; + const Transform *b = (const Transform *)p_b; + return *self == *b; +} + +godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b) { + godot_transform raw_dest; + Transform *dest = (Transform *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Transform *b = (const Transform *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { + godot_rect3 raw_dest; + Rect3 *dest = (Rect3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Rect3 *v = (const Rect3 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { + godot_rect3 raw_dest; + Rect3 *dest = (Rect3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Rect3 *v = (const Rect3 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/transform.h b/modules/gdnative/godot/transform.h new file mode 100644 index 0000000000..30b9970f67 --- /dev/null +++ b/modules/gdnative/godot/transform.h @@ -0,0 +1,100 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_TRANSFORM_SIZE 48 + +#ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_TRANSFORM_SIZE]; +} godot_transform; +#endif + +#include <godot/basis.h> +#include <godot/gdnative.h> +#include <godot/variant.h> +#include <godot/vector3.h> + +void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin); +void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin); + +godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self); +void GDAPI godot_transform_set_basis(godot_transform *p_self, godot_basis *p_v); + +godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self); +void GDAPI godot_transform_set_origin(godot_transform *p_self, godot_vector3 *p_v); + +godot_string GDAPI godot_transform_as_string(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale); + +godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs); + +godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up); + +godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v); + +godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v); + +void GDAPI godot_transform_new_identity(godot_transform *r_dest); + +godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b); + +godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b); + +godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v); + +godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v); + +godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_TRANSFORM_H diff --git a/modules/gdnative/godot/transform2d.cpp b/modules/gdnative/godot/transform2d.cpp new file mode 100644 index 0000000000..65f9f8ee32 --- /dev/null +++ b/modules/gdnative/godot/transform2d.cpp @@ -0,0 +1,210 @@ +/*************************************************************************/ +/* 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 "core/math/math_2d.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _transform2d_api_anchor() {} + +void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) { + const Vector2 *pos = (const Vector2 *)p_pos; + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(p_rot, *pos); +} + +void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin) { + const Vector2 *x_axis = (const Vector2 *)p_x_axis; + const Vector2 *y_axis = (const Vector2 *)p_y_axis; + const Vector2 *origin = (const Vector2 *)p_origin; + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(x_axis->x, x_axis->y, y_axis->x, y_axis->y, origin->x, origin->y); +} + +godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self) { + godot_string ret; + const Transform2D *self = (const Transform2D *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->inverse(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->affine_inverse(); + return dest; +} + +godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self) { + const Transform2D *self = (const Transform2D *)p_self; + return self->get_rotation(); +} + +godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self) { + godot_vector2 dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Vector2 *)&dest) = self->get_origin(); + return dest; +} + +godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self) { + godot_vector2 dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Vector2 *)&dest) = self->get_scale(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->orthonormalized(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + + *((Transform2D *)&dest) = self->rotated(p_phi); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *scale = (const Vector2 *)p_scale; + *((Transform2D *)&dest) = self->scaled(*scale); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *offset = (const Vector2 *)p_offset; + *((Transform2D *)&dest) = self->translated(*offset); + return dest; +} + +godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->basis_xform(*v); + return raw_dest; +} + +godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->basis_xform_inv(*v); + return raw_dest; +} + +godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *m = (const Transform2D *)p_m; + *((Transform2D *)&dest) = self->interpolate_with(*m, p_c); + return dest; +} + +godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b) { + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *b = (const Transform2D *)p_b; + return *self == *b; +} + +godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b) { + godot_transform2d raw_dest; + Transform2D *dest = (Transform2D *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *b = (const Transform2D *)p_b; + *dest = *self * *b; + return raw_dest; +} + +void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest) { + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(); +} + +godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) { + godot_rect2 raw_dest; + Rect2 *dest = (Rect2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Rect2 *v = (const Rect2 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) { + godot_rect2 raw_dest; + Rect2 *dest = (Rect2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Rect2 *v = (const Rect2 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/transform2d.h b/modules/gdnative/godot/transform2d.h new file mode 100644 index 0000000000..41c8ba982c --- /dev/null +++ b/modules/gdnative/godot/transform2d.h @@ -0,0 +1,99 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_TRANSFORM2D_SIZE 24 + +#ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_TRANSFORM2D_SIZE]; +} godot_transform2d; +#endif + +#include <godot/gdnative.h> +#include <godot/variant.h> +#include <godot/vector2.h> + +void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos); +void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin); + +godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self); + +godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self); + +godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self); + +godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi); + +godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale); + +godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset); + +godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c); + +godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b); + +godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b); + +void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest); + +godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v); + +godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_TRANSFORM2D_H diff --git a/modules/gdnative/godot/variant.cpp b/modules/gdnative/godot/variant.cpp new file mode 100644 index 0000000000..d814ef913c --- /dev/null +++ b/modules/gdnative/godot/variant.cpp @@ -0,0 +1,481 @@ +/*************************************************************************/ +/* 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 "core/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) + +// Constructors + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return (godot_variant_type)self->get_type(); +} + +void GDAPI godot_variant_new_copy(godot_variant *p_dest, const godot_variant *p_src) { + Variant *dest = (Variant *)p_dest; + Variant *src = (Variant *)p_src; + memnew_placement(dest, Variant(*src)); +} + +void GDAPI godot_variant_new_nil(godot_variant *r_dest) { + Variant *dest = (Variant *)r_dest; + memnew_placement(dest, Variant); +} + +void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_b)); +} + +void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_i)); +} + +void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_i)); +} + +void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_r)); +} + +void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s) { + Variant *dest = (Variant *)r_dest; + String *s = (String *)p_s; + memnew_placement_custom(dest, Variant, Variant(*s)); +} + +void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2) { + Variant *dest = (Variant *)r_dest; + Vector2 *v2 = (Vector2 *)p_v2; + memnew_placement_custom(dest, Variant, Variant(*v2)); +} + +void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2) { + Variant *dest = (Variant *)r_dest; + Rect2 *rect2 = (Rect2 *)p_rect2; + memnew_placement_custom(dest, Variant, Variant(*rect2)); +} + +void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3) { + Variant *dest = (Variant *)r_dest; + Vector3 *v3 = (Vector3 *)p_v3; + memnew_placement_custom(dest, Variant, Variant(*v3)); +} + +void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d) { + Variant *dest = (Variant *)r_dest; + Transform2D *t2d = (Transform2D *)p_t2d; + memnew_placement_custom(dest, Variant, Variant(*t2d)); +} + +void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane) { + Variant *dest = (Variant *)r_dest; + Plane *plane = (Plane *)p_plane; + memnew_placement_custom(dest, Variant, Variant(*plane)); +} + +void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat) { + Variant *dest = (Variant *)r_dest; + Quat *quat = (Quat *)p_quat; + memnew_placement_custom(dest, Variant, Variant(*quat)); +} + +void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3) { + Variant *dest = (Variant *)r_dest; + Rect3 *rect3 = (Rect3 *)p_rect3; + memnew_placement_custom(dest, Variant, Variant(*rect3)); +} + +void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis) { + Variant *dest = (Variant *)r_dest; + Basis *basis = (Basis *)p_basis; + memnew_placement_custom(dest, Variant, Variant(*basis)); +} + +void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans) { + Variant *dest = (Variant *)r_dest; + Transform *trans = (Transform *)p_trans; + memnew_placement_custom(dest, Variant, Variant(*trans)); +} + +void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color) { + Variant *dest = (Variant *)r_dest; + Color *color = (Color *)p_color; + memnew_placement_custom(dest, Variant, Variant(*color)); +} + +void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np) { + Variant *dest = (Variant *)r_dest; + NodePath *np = (NodePath *)p_np; + memnew_placement_custom(dest, Variant, Variant(*np)); +} + +void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid) { + Variant *dest = (Variant *)r_dest; + RID *rid = (RID *)p_rid; + memnew_placement_custom(dest, Variant, Variant(*rid)); +} + +void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) { + Variant *dest = (Variant *)r_dest; + Object *obj = (Object *)p_obj; + memnew_placement_custom(dest, Variant, Variant(obj)); +} + +void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) { + Variant *dest = (Variant *)r_dest; + Dictionary *dict = (Dictionary *)p_dict; + memnew_placement_custom(dest, Variant, Variant(*dict)); +} + +void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr) { + Variant *dest = (Variant *)r_dest; + Array *arr = (Array *)p_arr; + memnew_placement_custom(dest, Variant, Variant(*arr)); +} + +void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba) { + Variant *dest = (Variant *)r_dest; + PoolByteArray *pba = (PoolByteArray *)p_pba; + memnew_placement_custom(dest, Variant, Variant(*pba)); +} + +void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia) { + Variant *dest = (Variant *)r_dest; + PoolIntArray *pia = (PoolIntArray *)p_pia; + memnew_placement_custom(dest, Variant, Variant(*pia)); +} + +void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra) { + Variant *dest = (Variant *)r_dest; + PoolRealArray *pra = (PoolRealArray *)p_pra; + memnew_placement_custom(dest, Variant, Variant(*pra)); +} + +void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa) { + Variant *dest = (Variant *)r_dest; + PoolStringArray *psa = (PoolStringArray *)p_psa; + memnew_placement_custom(dest, Variant, Variant(*psa)); +} + +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a) { + Variant *dest = (Variant *)r_dest; + PoolVector2Array *pv2a = (PoolVector2Array *)p_pv2a; + memnew_placement_custom(dest, Variant, Variant(*pv2a)); +} + +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a) { + Variant *dest = (Variant *)r_dest; + PoolVector3Array *pv3a = (PoolVector3Array *)p_pv3a; + memnew_placement_custom(dest, Variant, Variant(*pv3a)); +} + +void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca) { + Variant *dest = (Variant *)r_dest; + PoolColorArray *pca = (PoolColorArray *)p_pca; + memnew_placement_custom(dest, Variant, Variant(*pca)); +} + +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator bool(); +} + +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator uint64_t(); +} + +int64_t GDAPI godot_variant_as_int(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator int64_t(); +} + +double GDAPI godot_variant_as_real(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator double(); +} + +godot_string GDAPI godot_variant_as_string(const godot_variant *p_self) { + godot_string raw_dest; + const Variant *self = (const Variant *)p_self; + String *dest = (String *)&raw_dest; + memnew_placement(dest, String(self->operator String())); // operator = is overloaded by String + return raw_dest; +} + +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self) { + godot_vector2 raw_dest; + const Variant *self = (const Variant *)p_self; + Vector2 *dest = (Vector2 *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self) { + godot_rect2 raw_dest; + const Variant *self = (const Variant *)p_self; + Rect2 *dest = (Rect2 *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self) { + godot_vector3 raw_dest; + const Variant *self = (const Variant *)p_self; + Vector3 *dest = (Vector3 *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self) { + godot_transform2d raw_dest; + const Variant *self = (const Variant *)p_self; + Transform2D *dest = (Transform2D *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self) { + godot_plane raw_dest; + const Variant *self = (const Variant *)p_self; + Plane *dest = (Plane *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self) { + godot_quat raw_dest; + const Variant *self = (const Variant *)p_self; + Quat *dest = (Quat *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self) { + godot_rect3 raw_dest; + const Variant *self = (const Variant *)p_self; + Rect3 *dest = (Rect3 *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self) { + godot_basis raw_dest; + const Variant *self = (const Variant *)p_self; + Basis *dest = (Basis *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self) { + godot_transform raw_dest; + const Variant *self = (const Variant *)p_self; + Transform *dest = (Transform *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_color GDAPI godot_variant_as_color(const godot_variant *p_self) { + godot_color raw_dest; + const Variant *self = (const Variant *)p_self; + Color *dest = (Color *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self) { + godot_node_path raw_dest; + const Variant *self = (const Variant *)p_self; + NodePath *dest = (NodePath *)&raw_dest; + memnew_placement(dest, NodePath(self->operator NodePath())); // operator = is overloaded by NodePath + return raw_dest; +} + +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self) { + godot_rid raw_dest; + const Variant *self = (const Variant *)p_self; + RID *dest = (RID *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + Object *dest; + dest = *self; + return (godot_object *)dest; +} + +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self) { + godot_dictionary raw_dest; + const Variant *self = (const Variant *)p_self; + Dictionary *dest = (Dictionary *)&raw_dest; + memnew_placement(dest, Dictionary(self->operator Dictionary())); // operator = is overloaded by Dictionary + return raw_dest; +} + +godot_array GDAPI godot_variant_as_array(const godot_variant *p_self) { + godot_array raw_dest; + const Variant *self = (const Variant *)p_self; + Array *dest = (Array *)&raw_dest; + memnew_placement(dest, Array(self->operator Array())); // operator = is overloaded by Array + return raw_dest; +} + +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self) { + godot_pool_byte_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolByteArray *dest = (PoolByteArray *)&raw_dest; + memnew_placement(dest, PoolByteArray(self->operator PoolByteArray())); // operator = is overloaded by PoolByteArray + *dest = *self; + return raw_dest; +} + +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self) { + godot_pool_int_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolIntArray *dest = (PoolIntArray *)&raw_dest; + memnew_placement(dest, PoolIntArray(self->operator PoolIntArray())); // operator = is overloaded by PoolIntArray + *dest = *self; + return raw_dest; +} + +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self) { + godot_pool_real_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolRealArray *dest = (PoolRealArray *)&raw_dest; + memnew_placement(dest, PoolRealArray(self->operator PoolRealArray())); // operator = is overloaded by PoolRealArray + *dest = *self; + return raw_dest; +} + +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self) { + godot_pool_string_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolStringArray *dest = (PoolStringArray *)&raw_dest; + memnew_placement(dest, PoolStringArray(self->operator PoolStringArray())); // operator = is overloaded by PoolStringArray + *dest = *self; + return raw_dest; +} + +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self) { + godot_pool_vector2_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolVector2Array *dest = (PoolVector2Array *)&raw_dest; + memnew_placement(dest, PoolVector2Array(self->operator PoolVector2Array())); // operator = is overloaded by PoolVector2Array + *dest = *self; + return raw_dest; +} + +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self) { + godot_pool_vector3_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolVector3Array *dest = (PoolVector3Array *)&raw_dest; + memnew_placement(dest, PoolVector3Array(self->operator PoolVector3Array())); // operator = is overloaded by PoolVector3Array + *dest = *self; + return raw_dest; +} + +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self) { + godot_pool_color_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolColorArray *dest = (PoolColorArray *)&raw_dest; + memnew_placement(dest, PoolColorArray(self->operator PoolColorArray())); // operator = is overloaded by PoolColorArray + *dest = *self; + return raw_dest; +} + +godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error) { + Variant *self = (Variant *)p_self; + String *method = (String *)p_method; + const Variant **args = (const Variant **)p_args; + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + Variant::CallError error; + memnew_placement_custom(dest, Variant, Variant(self->call(*method, args, p_argcount, error))); + if (r_error) { + r_error->error = (godot_variant_call_error_error)error.error; + r_error->argument = error.argument; + r_error->expected = (godot_variant_type)error.expected; + } + return raw_dest; +} + +godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method) { + const Variant *self = (const Variant *)p_self; + const String *method = (const String *)p_method; + return self->has_method(*method); +} + +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->operator==(*other); +} + +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->operator<(*other); +} + +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->hash_compare(*other); +} + +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self, godot_bool *r_valid) { + const Variant *self = (const Variant *)p_self; + bool &valid = *r_valid; + return self->booleanize(valid); +} + +void GDAPI godot_variant_destroy(godot_variant *p_self) { + Variant *self = (Variant *)p_self; + self->~Variant(); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/variant.h b/modules/gdnative/godot/variant.h new file mode 100644 index 0000000000..1c19d2a25b --- /dev/null +++ b/modules/gdnative/godot/variant.h @@ -0,0 +1,201 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_VARIANT_SIZE 24 + +#ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_VARIANT_SIZE]; +} godot_variant; +#endif + +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, + GODOT_VARIANT_TYPE_BASIS, + GODOT_VARIANT_TYPE_TRANSFORM, + + // misc types + GODOT_VARIANT_TYPE_COLOR, + GODOT_VARIANT_TYPE_NODE_PATH, // 15 + GODOT_VARIANT_TYPE_RID, + GODOT_VARIANT_TYPE_OBJECT, + GODOT_VARIANT_TYPE_DICTIONARY, + GODOT_VARIANT_TYPE_ARRAY, // 20 + + // 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, + GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, // 25 + GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY, + GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY, +} godot_variant_type; + +typedef enum godot_variant_call_error_error { + GODOT_CALL_ERROR_CALL_OK, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT, + GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL, +} godot_variant_call_error_error; + +typedef struct godot_variant_call_error { + godot_variant_call_error_error error; + int argument; + godot_variant_type expected; +} godot_variant_call_error; + +#include <godot/array.h> +#include <godot/basis.h> +#include <godot/color.h> +#include <godot/dictionary.h> +#include <godot/node_path.h> +#include <godot/plane.h> +#include <godot/pool_arrays.h> +#include <godot/quat.h> +#include <godot/rect2.h> +#include <godot/rect3.h> +#include <godot/rid.h> +#include <godot/string.h> +#include <godot/transform.h> +#include <godot/transform2d.h> +#include <godot/variant.h> +#include <godot/vector2.h> +#include <godot/vector3.h> + +#include <godot/gdnative.h> + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v); + +void GDAPI godot_variant_new_copy(godot_variant *r_dest, const godot_variant *p_src); + +void GDAPI godot_variant_new_nil(godot_variant *r_dest); + +void GDAPI godot_variant_new_bool(godot_variant *p_v, const godot_bool p_b); +void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i); +void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i); +void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r); +void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s); +void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2); +void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2); +void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3); +void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d); +void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane); +void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat); +void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3); +void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis); +void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans); +void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color); +void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np); +void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid); +void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj); +void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict); +void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr); +void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba); +void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia); +void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra); +void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa); +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca); + +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self); +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self); +int64_t GDAPI godot_variant_as_int(const godot_variant *p_self); +double GDAPI godot_variant_as_real(const godot_variant *p_self); +godot_string GDAPI godot_variant_as_string(const godot_variant *p_self); +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self); +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self); +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self); +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self); +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self); +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self); +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self); +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self); +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self); +godot_color GDAPI godot_variant_as_color(const godot_variant *p_self); +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self); +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self); +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self); +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self); +godot_array GDAPI godot_variant_as_array(const godot_variant *p_self); +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self); +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self); +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self); +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self); +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self); +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self); +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self); + +godot_variant GDAPI godot_variant_call(godot_variant *p_self, 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(const godot_variant *p_self, const godot_string *p_method); + +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other); +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other); + +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other); + +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self, godot_bool *r_valid); + +void GDAPI godot_variant_destroy(godot_variant *p_self); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/modules/gdnative/godot/vector2.cpp b/modules/gdnative/godot/vector2.cpp new file mode 100644 index 0000000000..05d4b1acc8 --- /dev/null +++ b/modules/gdnative/godot/vector2.cpp @@ -0,0 +1,297 @@ +/*************************************************************************/ +/* 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 "core/math/math_2d.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _vector2_api_anchor() {} + +void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) { + + Vector2 *dest = (Vector2 *)r_dest; + *dest = Vector2(p_x, p_y); +} + +godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self) { + godot_string ret; + const Vector2 *self = (const Vector2 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->normalized(); + return dest; +} + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->length(); +} + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->angle(); +} + +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->length_squared(); +} + +godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->is_normalized(); +} + +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->distance_to(*to); +} + +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->distance_squared_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->angle_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->angle_to_point(*to); +} + +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *((Vector2 *)&dest) = self->linear_interpolate(*b, p_t); + return dest; +} + +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + const Vector2 *pre_a = (const Vector2 *)p_pre_a; + const Vector2 *post_b = (const Vector2 *)p_post_b; + *((Vector2 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t); + return dest; +} + +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + + *((Vector2 *)&dest) = self->rotated(p_phi); + return dest; +} + +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->tangent(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->floor(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *by = (const Vector2 *)p_by; + *((Vector2 *)&dest) = self->snapped(*by); + return dest; +} + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->aspect(); +} + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *with = (const Vector2 *)p_with; + return self->dot(*with); +} + +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->slide(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->bounce(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->reflect(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->abs(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + + *((Vector2 *)&dest) = self->clamped(p_length); + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_vector2 GDAPI godot_vector2_operator_substract(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = *self * p_b; + return raw_dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self / *b; + return raw_dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = *self / p_b; + return raw_dest; +} + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + return *self == *b; +} + +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + return *self < *b; +} + +godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = -(*self); + return raw_dest; +} + +void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x) { + Vector2 *self = (Vector2 *)p_self; + self->x = p_x; +} + +void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y) { + Vector2 *self = (Vector2 *)p_self; + self->y = p_y; +} + +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->x; +} + +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->y; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/vector2.h b/modules/gdnative/godot/vector2.h new file mode 100644 index 0000000000..9db238b4fd --- /dev/null +++ b/modules/gdnative/godot/vector2.h @@ -0,0 +1,128 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_VECTOR2_SIZE 8 + +#ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_VECTOR2_SIZE]; +} godot_vector2; +#endif + +#include <godot/gdnative.h> + +void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y); + +godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self); + +godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t); + +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t); + +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi); + +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by); + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with); + +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length); + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_substract(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b); + +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b); + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self); + +void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x); + +void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y); + +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_VECTOR2_H diff --git a/modules/gdnative/godot/vector3.cpp b/modules/gdnative/godot/vector3.cpp new file mode 100644 index 0000000000..fe27e740e2 --- /dev/null +++ b/modules/gdnative/godot/vector3.cpp @@ -0,0 +1,304 @@ +/*************************************************************************/ +/* 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 "core/variant.h" +#include "core/vector.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _vector3_api_anchor() {} + +void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) { + + Vector3 *dest = (Vector3 *)r_dest; + *dest = Vector3(p_x, p_y, p_z); +} + +godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self) { + godot_string ret; + const Vector3 *self = (const Vector3 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->min_axis(); +} + +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->max_axis(); +} + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->length(); +} + +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->length_squared(); +} + +godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->is_normalized(); +} + +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->normalized(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->inverse(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_vector3 *p_by) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *snap_axis = (const Vector3 *)p_by; + + *((Vector3 *)&dest) = self->snapped(*snap_axis); + return dest; +} + +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Vector3 *)&dest) = self->rotated(*axis, p_phi); + return dest; +} + +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Vector3 *)&dest) = self->linear_interpolate(*b, p_t); + return dest; +} + +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + const Vector3 *pre_a = (const Vector3 *)p_pre_a; + const Vector3 *post_b = (const Vector3 *)p_post_b; + *((Vector3 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t); + return dest; +} + +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->dot(*b); +} + +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Vector3 *)&dest) = self->cross(*b); + return dest; +} + +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_basis dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Basis *)&dest) = self->outer(*b); + return dest; +} + +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self) { + godot_basis dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Basis *)&dest) = self->to_diagonal_matrix(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->abs(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->floor(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->ceil(); + return dest; +} + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->distance_to(*b); +} + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->distance_squared_to(*b); +} + +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *to = (const Vector3 *)p_to; + return self->angle_to(*to); +} + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->slide(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->bounce(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->reflect(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_substract(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + *dest = *self * p_b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self / *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + *dest = *self / p_b; + return raw_dest; +} + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b) { + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return *self == *b; +} + +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b) { + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return *self < *b; +} + +godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Vector3 *self = (const Vector3 *)p_self; + *dest = -(*self); + return raw_dest; +} + +void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val) { + Vector3 *self = (Vector3 *)p_self; + self->set_axis(p_axis, p_val); +} + +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis) { + const Vector3 *self = (const Vector3 *)p_self; + return self->get_axis(p_axis); +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/godot/vector3.h b/modules/gdnative/godot/vector3.h new file mode 100644 index 0000000000..8aba1d9a85 --- /dev/null +++ b/modules/gdnative/godot/vector3.h @@ -0,0 +1,135 @@ +/*************************************************************************/ +/* 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> + +#define GODOT_VECTOR3_SIZE 12 + +#ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_VECTOR3_SIZE]; +} godot_vector3; +#endif + +#include <godot/basis.h> +#include <godot/gdnative.h> + +typedef enum { + GODOT_VECTOR3_AXIS_X, + GODOT_VECTOR3_AXIS_Y, + GODOT_VECTOR3_AXIS_Z, +} godot_vector3_axis; + +void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z); + +godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self); + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self); + +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self); + +godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_vector3 *p_by); + +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t); + +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t); + +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to); + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_substract(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b); + +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b); + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self); + +void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val); + +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis); + +#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..da50104e26 --- /dev/null +++ b/modules/gdnative/register_types.cpp @@ -0,0 +1,101 @@ +/*************************************************************************/ +/* 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" + +#include "core/os/os.h" + +godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, godot_array *p_args) { + if (handle == NULL) { + ERR_PRINT("No valid library handle, can't call standard varcall procedure"); + godot_variant ret; + godot_variant_new_nil(&ret); + return ret; + } + + void *library_proc; + Error err = OS::get_singleton()->get_dynamic_library_symbol_handle( + handle, + *(String *)p_procedure, + library_proc, + true); // we roll our own message + if (err != OK) { + ERR_PRINT((String("GDNative procedure \"" + *(String *)p_procedure) + "\" does not exists and can't be called").utf8().get_data()); + godot_variant ret; + godot_variant_new_nil(&ret); + return ret; + } + + godot_gdnative_procedure_fn proc; + proc = (godot_gdnative_procedure_fn)library_proc; + + return proc(NULL, p_args); +} + +GDNativeCallRegistry *GDNativeCallRegistry::singleton; + +void register_gdnative_types() { + + ClassDB::register_class<GDNativeLibrary>(); + ClassDB::register_class<GDNative>(); + + GDNativeCallRegistry::singleton = memnew(GDNativeCallRegistry); + + GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); +} + +void unregister_gdnative_types() { + memdelete(GDNativeCallRegistry::singleton); + + // This is for printing out the sizes of the core types + + /* + print_line(String("array:\t") + itos(sizeof(Array))); + print_line(String("basis:\t") + itos(sizeof(Basis))); + print_line(String("color:\t") + itos(sizeof(Color))); + print_line(String("dict:\t" ) + itos(sizeof(Dictionary))); + print_line(String("node_path:\t") + itos(sizeof(NodePath))); + print_line(String("plane:\t") + itos(sizeof(Plane))); + print_line(String("poolarray:\t") + itos(sizeof(PoolByteArray))); + print_line(String("quat:\t") + itos(sizeof(Quat))); + print_line(String("rect2:\t") + itos(sizeof(Rect2))); + print_line(String("rect3:\t") + itos(sizeof(Rect3))); + print_line(String("rid:\t") + itos(sizeof(RID))); + print_line(String("string:\t") + itos(sizeof(String))); + print_line(String("transform:\t") + itos(sizeof(Transform))); + print_line(String("transfo2D:\t") + itos(sizeof(Transform2D))); + print_line(String("variant:\t") + itos(sizeof(Variant))); + print_line(String("vector2:\t") + itos(sizeof(Vector2))); + print_line(String("vector3:\t") + itos(sizeof(Vector3))); + */ +} diff --git a/modules/gdnative/register_types.h b/modules/gdnative/register_types.h new file mode 100644 index 0000000000..48e778cb2c --- /dev/null +++ b/modules/gdnative/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* 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 */ +/* "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. */ +/*************************************************************************/ +void register_gdnative_types(); +void unregister_gdnative_types(); diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 245f44887c..d4ede4cb17 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 */ @@ -1013,7 +1014,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } } break; - case GDParser::OperatorNode::OP_EXTENDS: { + case GDParser::OperatorNode::OP_IS: { ERR_FAIL_COND_V(on->arguments.size() != 2, false); 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 1499f167c4..f8b45af85a 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,10 +27,15 @@ /* 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" #include "os/file_access.h" +#include "project_settings.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_file_system.h" +#include "editor/editor_settings.h" +#endif void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { @@ -49,11 +55,12 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str "# var a = 2\n" + "# var b = \"textvar\"\n\n" + "func _ready():\n" + - "\t# Called every time the node is added to the scene.\n" + - "\t# Initialization here\n" + - "\tpass\n"; + "%TS%# Called every time the node is added to the scene.\n" + + "%TS%# Initialization here\n" + + "%TS%pass\n"; _template = _template.replace("%BASE%", p_base_class_name); + _template = _template.replace("%TS%", _get_indentation()); Ref<GDScript> script; script.instance(); @@ -62,6 +69,19 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str return script; } +bool GDScriptLanguage::is_using_templates() { + + return true; +} + +void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { + + String src = p_script->get_source_code(); + src = src.replace("%BASE%", p_base_class_name); + src = src.replace("%TS%", _get_indentation()); + p_script->set_source_code(src); +} + bool GDScriptLanguage::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 { GDParser parser; @@ -137,7 +157,7 @@ Script *GDScriptLanguage::create_script() const { bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) { //break because of parse error - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; @@ -151,7 +171,7 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = -1; _debug_parse_err_file = ""; @@ -618,7 +638,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: String which = arg1.get_slice("/", 2); if (which != "") { List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); //print_line("find singleton"); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -630,7 +650,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: String name = s.get_slice("/", 1); //print_line("name: "+name+", which: "+which); if (name == which) { - String script = GlobalConfig::get_singleton()->get(s); + String script = ProjectSettings::get_singleton()->get(s); if (!script.begins_with("res://")) { script = "res://" + script; @@ -1085,7 +1105,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con //autoloads as singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1095,7 +1115,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con String name = s.get_slice("/", 1); if (name == String(p_identifier)) { - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { String script = path.substr(1, path.length()); @@ -1256,7 +1276,7 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat } } List<MethodInfo> methods; - ClassDB::get_method_list(type, &methods); + ClassDB::get_method_list(type, &methods, false, true); for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { if (E->get().name.begins_with("_")) continue; @@ -1314,8 +1334,8 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o static const char *_type_names[Variant::VARIANT_MAX] = { "null", "bool", "int", "float", "String", "Vector2", "Rect2", "Vector3", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform", - "Color", "Image", "NodePath", "RID", "Object", "InputEvent", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray", - "Vector2Array", "Vector3Array", "ColorArray" + "Color", "NodePath", "RID", "Object", "Dictionary", "Array", "PoolByteArray", "PoolIntArray", "PoolRealArray", "PoolStringArray", + "PoolVector2Array", "PoolVector3Array", "PoolColorArray" }; for (int i = 0; i < Variant::VARIANT_MAX; i++) { @@ -1324,7 +1344,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o //autoload singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1332,7 +1352,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o if (!s.begins_with("autoload/")) continue; String name = s.get_slice("/", 1); - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { result.insert(name); } @@ -1404,25 +1424,21 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi arghint += ")"; } -static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - - //print_line("find type arguments?"); - if (id.type == Variant::INPUT_EVENT && String(p_method) == "is_action" && p_argidx == 0) { - - List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); +void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_list) { - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + get_directory_contents(p_dir->get_subdir(i), r_list); + } - if (!pi.name.begins_with("input/")) - continue; + for (int i = 0; i < p_dir->get_file_count(); i++) { + r_list.insert("\"" + p_dir->get_file_path(i) + "\""); + } +} - String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); - result.insert("\"" + name + "\""); - } +static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - } else if (id.type == Variant::OBJECT && id.obj_type != StringName()) { + //print_line("find type arguments?"); + if (id.type == Variant::OBJECT && id.obj_type != StringName()) { MethodBind *m = ClassDB::get_method(id.obj_type, p_method); if (!m) { @@ -1627,7 +1643,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } else { //regular method - if (p_method.operator String() == "connect") { + if (p_method.operator String() == "connect" || (p_method.operator String() == "emit_signal" && p_argidx == 0)) { if (p_argidx == 0) { List<MethodInfo> sigs; @@ -1669,7 +1685,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (p_argidx == 0 && (String(p_method) == "get_node" || String(p_method) == "has_node") && ClassDB::is_parent_class(id.obj_type, "Node")) { List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1752,6 +1768,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]); MethodInfo mi = GDFunctions::get_info(fn->function); + if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) { + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result); + } + arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("("); for (int i = 0; i < mi.arguments.size(); i++) { if (i > 0) @@ -2231,7 +2251,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } List<MethodInfo> mi; - ClassDB::get_method_list(t.obj_type, &mi); + ClassDB::get_method_list(t.obj_type, &mi, false, true); for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { if (E->get().name.begins_with("_")) @@ -2244,54 +2264,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } else { - if (t.type == Variant::INPUT_EVENT) { - - //this is hardcoded otherwise it's not obvious - Set<String> exclude; - - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - - InputEvent ie; - ie.type = InputEvent::Type(i); - static const char *evnames[] = { - "# Common", - "# Key", - "# MouseMotion", - "# MouseButton", - "# JoypadMotion", - "# JoypadButton", - "# ScreenTouch", - "# ScreenDrag", - "# Action" - }; - - r_options->push_back(evnames[i]); - - Variant v = ie; - - if (i == 0) { - List<MethodInfo> mi; - v.get_method_list(&mi); - for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { - r_options->push_back(E->get().name + "("); - } - } - - List<PropertyInfo> pi; - v.get_property_list(&pi); - - for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - - if (i == 0) - exclude.insert(E->get().name); - else if (exclude.has(E->get().name)) - continue; - - r_options->push_back(E->get().name); - } - } - return OK; - } else { + //check InputEvent hint + { if (t.value.get_type() == Variant::NIL) { Variant::CallError ce; t.value = Variant::construct(t.type, NULL, 0, ce); @@ -2373,6 +2347,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; + case GDParser::COMPLETION_RESOURCE_PATH: { + + if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths")) + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options); + } break; } for (Set<String>::Element *E = options.front(); E; E = E->next()) { @@ -2390,8 +2369,29 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + if (SceneTree::get_singleton()->is_editor_hint()) { + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", 0); + + 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 +2431,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) { @@ -2659,7 +2660,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol //guess in autoloads as singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -2669,7 +2670,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol String name = s.get_slice("/", 1); if (name == String(p_symbol)) { - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { String script = path.substr(1, path.length()); diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 0e7ba981f4..13a7480a36 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 */ @@ -357,12 +358,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (a->get_type() != Variant::OBJECT || a->operator Object *() == NULL) { - err_text = "Left operand of 'extends' is not an instance of anything."; + err_text = "Left operand of 'is' is not an instance of anything."; break; } if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) { - err_text = "Right operand of 'extends' is not a class."; + err_text = "Right operand of 'is' is not a class."; break; } #endif @@ -400,7 +401,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (!nc) { - err_text = "Right operand of 'extends' is not a class (type: '" + obj_B->get_class() + "')."; + err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "')."; break; } @@ -887,8 +888,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a gdfs->state._class = _class; gdfs->state.ip = ip + ipofs; gdfs->state.line = line; - gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_ID() : 0; - gdfs->state.script_id = _class->get_instance_ID(); + gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : 0; + gdfs->state.script_id = _class->get_instance_id(); //gdfs->state.result_pos=ip+ipofs-1; gdfs->state.defarg = defarg; gdfs->state.instance = p_instance; @@ -1232,10 +1233,10 @@ int GDFunction::get_default_argument_count() const { return default_arguments.size(); } -int GDFunction::get_default_argument_addr(int p_arg) const { +int GDFunction::get_default_argument_addr(int p_idx) const { - ERR_FAIL_INDEX_V(p_arg, default_arguments.size(), -1); - return default_arguments[p_arg]; + ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), -1); + return default_arguments[p_idx]; } StringName GDFunction::get_name() const { @@ -1427,14 +1428,42 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount state.result = arg; Variant ret = function->call(NULL, NULL, 0, r_error, &state); + + bool completed = true; + + // If the return value is a GDFunctionState reference, + // then the function did yield again after resuming. + if (ret.is_ref()) { + GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + if (gdfs && gdfs->function == function) + completed = false; + } + function = NULL; //cleaned up; state.result = Variant(); + + if (completed) { + emit_signal("completed", ret); + } + return ret; } -bool GDFunctionState::is_valid() const { +bool GDFunctionState::is_valid(bool p_extended_check) const { + + if (function == NULL) + return false; + + if (p_extended_check) { + //class instance gone? + if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) + return false; + //script gone? + if (state.script_id && !ObjectDB::get_instance(state.script_id)) + return false; + } - return function != NULL; + return true; } Variant GDFunctionState::resume(const Variant &p_arg) { @@ -1455,16 +1484,34 @@ Variant GDFunctionState::resume(const Variant &p_arg) { state.result = p_arg; Variant::CallError err; Variant ret = function->call(NULL, NULL, 0, err, &state); + + bool completed = true; + + // If the return value is a GDFunctionState reference, + // then the function did yield again after resuming. + if (ret.is_ref()) { + GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + if (gdfs && gdfs->function == function) + completed = false; + } + function = NULL; //cleaned up; state.result = Variant(); + + if (completed) { + emit_signal("completed", ret); + } + return ret; } void GDFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("resume:Variant", "arg"), &GDFunctionState::resume, DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("is_valid"), &GDFunctionState::is_valid); + ClassDB::bind_method(D_METHOD("resume", "arg"), &GDFunctionState::resume, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDFunctionState::is_valid, DEFVAL(false)); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDFunctionState::_signal_callback, MethodInfo("_signal_callback")); + + ADD_SIGNAL(MethodInfo("completed", PropertyInfo(Variant::NIL, "result"))); } GDFunctionState::GDFunctionState() { diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h index 321b3b6cfa..6d20b19777 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 */ @@ -236,7 +237,7 @@ protected: static void _bind_methods(); public: - bool is_valid() const; + bool is_valid(bool p_extended_check = false) const; Variant resume(const Variant &p_arg = Variant()); GDFunctionState(); ~GDFunctionState(); diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index fa92f0a194..209bdadd67 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 */ @@ -112,6 +113,7 @@ const char *GDFunctions::get_func_name(Function p_func) { "ColorN", "print_stack", "instance_from_id", + "len", }; return _names[p_func]; @@ -1153,6 +1155,62 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, r_ret = ObjectDB::get_instance(id); } break; + case LEN: { + + VALIDATE_ARG_COUNT(1); + switch (p_args[0]->get_type()) { + case Variant::DICTIONARY: { + Dictionary d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::ARRAY: { + Array d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_BYTE_ARRAY: { + PoolVector<uint8_t> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_INT_ARRAY: { + PoolVector<int> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_REAL_ARRAY: { + + PoolVector<real_t> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_STRING_ARRAY: { + PoolVector<String> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_VECTOR2_ARRAY: { + PoolVector<Vector2> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_VECTOR3_ARRAY: { + + PoolVector<Vector3> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_COLOR_ARRAY: { + + PoolVector<Color> d = *p_args[0]; + r_ret = d.size(); + } break; + default: { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + r_ret = Variant(); + r_ret = RTR("Object can't provide a length."); + } + } + + } break; case FUNC_MAX: { ERR_FAIL(); @@ -1209,6 +1267,7 @@ bool GDFunctions::is_deterministic(Function p_func) { case TEXT_CHAR: case TEXT_STR: case COLOR8: + case LEN: // enable for debug only, otherwise not desirable - case GEN_RANGE: return true; default: @@ -1586,13 +1645,13 @@ MethodInfo GDFunctions::get_info(Function p_func) { } break; case TO_JSON: { - MethodInfo mi("to_json", PropertyInfo(Variant::NIL, "var:Variant")); + MethodInfo mi("to_json", PropertyInfo(Variant::NIL, "var")); mi.return_val.type = Variant::STRING; return mi; } break; case HASH: { - MethodInfo mi("hash", PropertyInfo(Variant::NIL, "var:Variant")); + MethodInfo mi("hash", PropertyInfo(Variant::NIL, "var")); mi.return_val.type = Variant::INT; return mi; } break; @@ -1620,6 +1679,11 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type = Variant::OBJECT; return mi; } break; + case LEN: { + MethodInfo mi("len", PropertyInfo(Variant::NIL, "var")); + mi.return_val.type = Variant::INT; + return mi; + } break; case FUNC_MAX: { diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h index cde1a9210d..93cb524118 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 */ @@ -104,6 +105,7 @@ public: COLORN, PRINT_STACK, INSTANCE_FROM_ID, + LEN, FUNC_MAX }; diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 1540bb51f8..9023fd4bf4 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 */ @@ -184,8 +185,8 @@ void GDParser::_make_completable_call(int p_arg) { bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &identifier) { identifier = StringName(); - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) { - identifier = tokenizer->get_token_identifier(); + if (tokenizer->is_token_literal()) { + identifier = tokenizer->get_token_literal(); tokenizer->advance(); } if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { @@ -200,8 +201,8 @@ bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &id completion_ident_is_call = false; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) { - identifier = identifier.operator String() + tokenizer->get_token_identifier().operator String(); + if (tokenizer->is_token_literal()) { + identifier = identifier.operator String() + tokenizer->get_token_literal().operator String(); tokenizer->advance(); } @@ -295,17 +296,6 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool need_identifier = false; } break; - case GDTokenizer::TK_IDENTIFIER: { - if (!need_identifier) { - done = true; - break; - } - - path += String(tokenizer->get_token_identifier()); - tokenizer->advance(); - need_identifier = false; - - } break; case GDTokenizer::TK_OP_DIV: { if (need_identifier) { @@ -319,7 +309,15 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } break; default: { - done = true; + // Instead of checking for TK_IDENTIFIER, we check with is_token_literal, as this allows us to use match/sync/etc. as a name + if (need_identifier && tokenizer->is_token_literal()) { + path += String(tokenizer->get_token_literal()); + tokenizer->advance(); + need_identifier = false; + } else { + done = true; + } + break; } } @@ -388,6 +386,19 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } tokenizer->advance(); + if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + completion_cursor = StringName(); + completion_node = p_parent; + completion_type = COMPLETION_RESOURCE_PATH; + completion_class = current_class; + completion_function = current_function; + completion_line = tokenizer->get_token_line(); + completion_block = current_block; + completion_argument = 0; + completion_found = true; + tokenizer->advance(); + } + String path; bool found_constant = false; bool valid = false; @@ -459,10 +470,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool _set_error("Expected ')' after 'preload' path"); return NULL; } + tokenizer->advance(); ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = res; - tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDTokenizer::TK_PR_YIELD) { @@ -571,7 +582,8 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool cn->value = Variant::get_numeric_constant_value(bi_type, identifier); expr = cn; - } else if (tokenizer->get_token(1) == GDTokenizer::TK_PARENTHESIS_OPEN && (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE || tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER || tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC)) { + } else if (tokenizer->get_token(1) == GDTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) { + // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //function or constructor OperatorNode *op = alloc_node<OperatorNode>(); @@ -613,7 +625,8 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = op; - } else if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) { + } else if (tokenizer->is_token_literal(0, true)) { + // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //identifier (reference) const ClassNode *cln = current_class; @@ -813,10 +826,11 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool if (expecting == DICT_EXPECT_KEY) { - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1) == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->is_token_literal() && tokenizer->get_token(1) == GDTokenizer::TK_OP_ASSIGN) { + // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //lua style identifier, easier to write ConstantNode *cn = alloc_node<ConstantNode>(); - cn->value = tokenizer->get_token_identifier(); + cn->value = tokenizer->get_token_literal(); key = cn; tokenizer->advance(2); expecting = DICT_EXPECT_VALUE; @@ -856,7 +870,8 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = dict; - } else if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && (tokenizer->get_token(1) == GDTokenizer::TK_IDENTIFIER || tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) { + } else if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && (tokenizer->is_token_literal(1) || tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) { + // We check with is_token_literal, as this allows us to use match/sync/etc. as a name // parent call tokenizer->advance(); //goto identifier @@ -908,7 +923,8 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool //indexing using "." - if (tokenizer->get_token(1) != GDTokenizer::TK_CURSOR && tokenizer->get_token(1) != GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1) != GDTokenizer::TK_BUILT_IN_FUNC) { + if (tokenizer->get_token(1) != GDTokenizer::TK_CURSOR && !tokenizer->is_token_literal(1)) { + // We check with is_token_literal, as this allows us to use match/sync/etc. as a name _set_error("Expected identifier as member"); return NULL; } else if (tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) { @@ -1063,7 +1079,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break; case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break; case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break; - case GDTokenizer::TK_PR_EXTENDS: op = OperatorNode::OP_EXTENDS; break; + case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break; case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break; case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break; default: valid = false; break; @@ -1103,7 +1119,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool switch (expression[i].op) { - case OperatorNode::OP_EXTENDS: + case OperatorNode::OP_IS: priority = -1; break; //before anything @@ -1406,7 +1422,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { } } - if (op->op == OperatorNode::OP_EXTENDS) { + if (op->op == OperatorNode::OP_IS) { //nothing much return op; } @@ -2264,6 +2280,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { 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; @@ -2326,12 +2343,12 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { //variale declaration and (eventual) initialization tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("Expected identifier for local variable name."); return; } - StringName n = tokenizer->get_token_identifier(); + StringName n = tokenizer->get_token_literal(); tokenizer->advance(); if (current_function) { for (int i = 0; i < current_function->arguments.size(); i++) { @@ -2352,8 +2369,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { check_block = check_block->parent_block; } - p_block->variables.push_back(n); //line? - p_block->variable_lines.push_back(tokenizer->get_token_line()); + int var_line = tokenizer->get_token_line(); //must know when the local variable is declared LocalVarNode *lv = alloc_node<LocalVarNode>(); @@ -2383,6 +2399,10 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { c->value = Variant(); assigned = c; } + //must be added later, to avoid self-referencing. + p_block->variables.push_back(n); //line? + p_block->variable_lines.push_back(var_line); + IdentifierNode *id = alloc_node<IdentifierNode>(); id->name = n; @@ -2420,7 +2440,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; } @@ -2435,9 +2455,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(); @@ -2557,7 +2576,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("identifier expected after 'for'"); } @@ -2612,7 +2631,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { ConstantNode *cn = alloc_node<ConstantNode>(); switch (args.size()) { - case 1: cn->value = constants[0]; break; + case 1: cn->value = (int)constants[0]; break; case 2: cn->value = Vector2(constants[0], constants[1]); break; case 3: cn->value = Vector3(constants[0], constants[1], constants[2]); break; } @@ -2625,7 +2644,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { on->arguments.push_back(tn); switch (args.size()) { - case 1: tn->vtype = Variant::REAL; break; + case 1: tn->vtype = Variant::INT; break; case 2: tn->vtype = Variant::VECTOR2; break; case 3: tn->vtype = Variant::VECTOR3; break; } @@ -3094,7 +3113,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); //var before the identifier is allowed } - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("Expected identifier for argument."); return; @@ -3246,7 +3265,7 @@ void GDParser::_parse_class(ClassNode *p_class) { case GDTokenizer::TK_PR_SIGNAL: { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal()) { _set_error("Expected identifier after 'signal'."); return; } @@ -3268,7 +3287,7 @@ void GDParser::_parse_class(ClassNode *p_class) { break; } - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("Expected identifier in signal argument."); return; } @@ -3833,13 +3852,13 @@ void GDParser::_parse_class(ClassNode *p_class) { bool onready = tokenizer->get_token(-1) == GDTokenizer::TK_PR_ONREADY; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("Expected identifier for member variable name."); return; } - member.identifier = tokenizer->get_token_identifier(); + member.identifier = tokenizer->get_token_literal(); member.expression = NULL; member._export.name = member.identifier; member.line = tokenizer->get_token_line(); @@ -3965,11 +3984,11 @@ void GDParser::_parse_class(ClassNode *p_class) { if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { //just comma means using only getter - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { - _set_error("Expected identifier for setter function after 'notify'."); + if (!tokenizer->is_token_literal()) { + _set_error("Expected identifier for setter function after 'setget'."); } - member.setter = tokenizer->get_token_identifier(); + member.setter = tokenizer->get_token_literal(); tokenizer->advance(); } @@ -3978,11 +3997,11 @@ void GDParser::_parse_class(ClassNode *p_class) { //there is a getter tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal()) { _set_error("Expected identifier for getter function after ','."); } - member.getter = tokenizer->get_token_identifier(); + member.getter = tokenizer->get_token_literal(); tokenizer->advance(); } } @@ -4000,13 +4019,13 @@ void GDParser::_parse_class(ClassNode *p_class) { ClassNode::Constant constant; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (!tokenizer->is_token_literal(0, true)) { _set_error("Expected name (identifier) for constant."); return; } - constant.identifier = tokenizer->get_token_identifier(); + constant.identifier = tokenizer->get_token_literal(); tokenizer->advance(); if (tokenizer->get_token() != GDTokenizer::TK_OP_ASSIGN) { @@ -4047,8 +4066,8 @@ void GDParser::_parse_class(ClassNode *p_class) { Dictionary enum_dict; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) { - enum_name = tokenizer->get_token_identifier(); + if (tokenizer->is_token_literal(0, true)) { + enum_name = tokenizer->get_token_literal(); tokenizer->advance(); } if (tokenizer->get_token() != GDTokenizer::TK_CURLY_BRACKET_OPEN) { @@ -4065,7 +4084,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); break; // End of enum - } else if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + } else if (!tokenizer->is_token_literal(0, true)) { if (tokenizer->get_token() == GDTokenizer::TK_EOF) { _set_error("Unexpected end of file."); @@ -4074,10 +4093,10 @@ void GDParser::_parse_class(ClassNode *p_class) { } return; - } else { // tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER + } else { // tokenizer->is_token_literal(0, true) ClassNode::Constant constant; - constant.identifier = tokenizer->get_token_identifier(); + constant.identifier = tokenizer->get_token_literal(); tokenizer->advance(); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 8d2c136818..3ad3466624 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 */ @@ -215,7 +216,7 @@ public: OP_CALL, OP_PARENT_CALL, OP_YIELD, - OP_EXTENDS, + OP_IS, //indexing operator OP_INDEX, OP_INDEX_NAMED, @@ -436,6 +437,7 @@ public: COMPLETION_PARENT_FUNCTION, COMPLETION_METHOD, COMPLETION_CALL_ARGUMENTS, + COMPLETION_RESOURCE_PATH, COMPLETION_INDEX, COMPLETION_VIRTUAL_FUNC, COMPLETION_YIELD, diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 9aafe41a0c..2d06c0f5d2 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 */ @@ -28,11 +29,11 @@ /*************************************************************************/ #include "gd_script.h" #include "gd_compiler.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 "project_settings.h" /////////////////////////// @@ -478,7 +479,7 @@ bool GDScript::_update_exports() { const GDParser::ClassNode *c = static_cast<const GDParser::ClassNode *>(root); if (base_cache.is_valid()) { - base_cache->inheriters_cache.erase(get_instance_ID()); + base_cache->inheriters_cache.erase(get_instance_id()); base_cache = Ref<GDScript>(); } @@ -504,7 +505,7 @@ bool GDScript::_update_exports() { //print_line("parent is: "+bf->get_path()); base_cache = bf; - bf->inheriters_cache.insert(get_instance_ID()); + bf->inheriters_cache.insert(get_instance_id()); //bf->_update_exports(p_instances,true,false); } @@ -614,6 +615,11 @@ Error GDScript::reload(bool p_keep_state) { if (basedir != "") basedir = basedir.get_base_dir(); + if (basedir != "" && basedir.find("res://") == -1 && basedir.find("user://") == -1) { + //loading a template, don't parse + return OK; + } + valid = false; GDParser parser; Error err = parser.parse(source, basedir, false, path); @@ -1448,9 +1454,9 @@ void GDScriptLanguage::init() { //populate singletons - List<GlobalConfig::Singleton> singletons; - GlobalConfig::get_singleton()->get_singletons(&singletons); - for (List<GlobalConfig::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + List<ProjectSettings::Singleton> singletons; + ProjectSettings::get_singleton()->get_singletons(&singletons); + for (List<ProjectSettings::Singleton>::Element *E = singletons.front(); E; E = E->next()) { _add_global(E->get().name, E->get().ptr); } @@ -1687,7 +1693,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so if (obj->get_script_instance()) { obj->get_script_instance()->get_property_state(state); - map[obj->get_instance_ID()] = state; + map[obj->get_instance_id()] = state; obj->set_script(RefPtr()); } } @@ -1696,15 +1702,18 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #ifdef TOOLS_ENABLED while (E->get()->placeholders.size()) { - Object *obj = E->get()->placeholders.front()->get()->get_owner(); + //save instance info List<Pair<StringName, Variant> > state; if (obj->get_script_instance()) { obj->get_script_instance()->get_property_state(state); - map[obj->get_instance_ID()] = state; + map[obj->get_instance_id()] = state; obj->set_script(RefPtr()); + } else { + // no instance found. Let's remove it so we don't loop forever + E->get()->placeholders.erase(E->get()->placeholders.front()->get()); } } #endif @@ -1734,8 +1743,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so obj->set_script(scr.get_ref_ptr()); if (!obj->get_script_instance()) { //failed, save reload state for next time if not saved - if (!scr->pending_reload_state.has(obj->get_instance_ID())) { - scr->pending_reload_state[obj->get_instance_ID()] = F->get(); + if (!scr->pending_reload_state.has(obj->get_instance_id())) { + scr->pending_reload_state[obj->get_instance_id()] = F->get(); } continue; } @@ -1744,7 +1753,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so obj->get_script_instance()->set(G->get().first, G->get().second); } - scr->pending_reload_state.erase(obj->get_instance_ID()); //as it reloaded, remove pending state + scr->pending_reload_state.erase(obj->get_instance_id()); //as it reloaded, remove pending state } //if instance states were saved, set them! @@ -1808,6 +1817,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "breakpoint", "class", "extends", + "is", "func", "preload", "setget", @@ -1875,7 +1885,7 @@ GDScriptLanguage::GDScriptLanguage() { script_frame_time = 0; _debug_call_stack_pos = 0; - int dmcs = GLOBAL_DEF("debug/script/max_call_stack", 1024); + int dmcs = GLOBAL_DEF("debug/settings/gdscript/max_call_stack", 1024); if (ScriptDebugger::get_singleton()) { //debugging enabled! diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index d64cc9798d..17e7b0bc03 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 */ @@ -297,7 +298,7 @@ public: _FORCE_INLINE_ void enter_function(GDInstance *p_instance, GDFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) { - if (Thread::get_main_ID() != Thread::get_caller_ID()) + if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) @@ -320,7 +321,7 @@ public: _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_ID() != Thread::get_caller_ID()) + if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) @@ -337,7 +338,7 @@ public: } virtual Vector<StackInfo> debug_get_current_stack_info() { - if (Thread::get_main_ID() != Thread::get_caller_ID()) + if (Thread::get_main_id() != Thread::get_caller_id()) return Vector<StackInfo>(); Vector<StackInfo> csi; @@ -380,15 +381,20 @@ public: 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 is_using_templates(); + virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); 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 bool can_inherit_from_file() { return true; } 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 open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return OK; } virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint); #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..5803046185 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 */ @@ -89,6 +90,7 @@ const char *GDTokenizer::token_names[TK_MAX] = { "func", "class", "extends", + "is", "onready", "tool", "static", @@ -117,6 +119,7 @@ const char *GDTokenizer::token_names[TK_MAX] = { "'.'", "'?'", "':'", + "'$'", "'\\n'", "PI", "_", @@ -127,12 +130,222 @@ const char *GDTokenizer::token_names[TK_MAX] = { "Cursor" }; +struct _bit { + Variant::Type type; + const char *text; +}; +//built in types + +static const _bit _type_list[] = { + //types + { Variant::BOOL, "bool" }, + { Variant::INT, "int" }, + { Variant::REAL, "float" }, + { Variant::STRING, "String" }, + { Variant::VECTOR2, "Vector2" }, + { Variant::RECT2, "Rect2" }, + { Variant::TRANSFORM2D, "Transform2D" }, + { Variant::VECTOR3, "Vector3" }, + { Variant::RECT3, "Rect3" }, + { Variant::PLANE, "Plane" }, + { Variant::QUAT, "Quat" }, + { Variant::BASIS, "Basis" }, + { Variant::TRANSFORM, "Transform" }, + { Variant::COLOR, "Color" }, + { Variant::_RID, "RID" }, + { Variant::OBJECT, "Object" }, + { Variant::NODE_PATH, "NodePath" }, + { Variant::DICTIONARY, "Dictionary" }, + { Variant::ARRAY, "Array" }, + { Variant::POOL_BYTE_ARRAY, "PoolByteArray" }, + { Variant::POOL_INT_ARRAY, "PoolIntArray" }, + { Variant::POOL_REAL_ARRAY, "PoolRealArray" }, + { Variant::POOL_STRING_ARRAY, "PoolStringArray" }, + { Variant::POOL_VECTOR2_ARRAY, "PoolVector2Array" }, + { Variant::POOL_VECTOR3_ARRAY, "PoolVector3Array" }, + { Variant::POOL_COLOR_ARRAY, "PoolColorArray" }, + { Variant::VARIANT_MAX, NULL }, +}; + +struct _kws { + GDTokenizer::Token token; + const char *text; +}; + +static const _kws _keyword_list[] = { + //ops + { GDTokenizer::TK_OP_IN, "in" }, + { GDTokenizer::TK_OP_NOT, "not" }, + { GDTokenizer::TK_OP_OR, "or" }, + { GDTokenizer::TK_OP_AND, "and" }, + //func + { GDTokenizer::TK_PR_FUNCTION, "func" }, + { GDTokenizer::TK_PR_CLASS, "class" }, + { GDTokenizer::TK_PR_EXTENDS, "extends" }, + { GDTokenizer::TK_PR_IS, "is" }, + { GDTokenizer::TK_PR_ONREADY, "onready" }, + { GDTokenizer::TK_PR_TOOL, "tool" }, + { GDTokenizer::TK_PR_STATIC, "static" }, + { GDTokenizer::TK_PR_EXPORT, "export" }, + { GDTokenizer::TK_PR_SETGET, "setget" }, + { GDTokenizer::TK_PR_VAR, "var" }, + { GDTokenizer::TK_PR_PRELOAD, "preload" }, + { GDTokenizer::TK_PR_ASSERT, "assert" }, + { GDTokenizer::TK_PR_YIELD, "yield" }, + { GDTokenizer::TK_PR_SIGNAL, "signal" }, + { GDTokenizer::TK_PR_BREAKPOINT, "breakpoint" }, + { GDTokenizer::TK_PR_REMOTE, "remote" }, + { GDTokenizer::TK_PR_MASTER, "master" }, + { GDTokenizer::TK_PR_SLAVE, "slave" }, + { GDTokenizer::TK_PR_SYNC, "sync" }, + { GDTokenizer::TK_PR_CONST, "const" }, + { GDTokenizer::TK_PR_ENUM, "enum" }, + //controlflow + { GDTokenizer::TK_CF_IF, "if" }, + { GDTokenizer::TK_CF_ELIF, "elif" }, + { GDTokenizer::TK_CF_ELSE, "else" }, + { GDTokenizer::TK_CF_FOR, "for" }, + { GDTokenizer::TK_CF_WHILE, "while" }, + { GDTokenizer::TK_CF_DO, "do" }, + { GDTokenizer::TK_CF_SWITCH, "switch" }, + { GDTokenizer::TK_CF_CASE, "case" }, + { GDTokenizer::TK_CF_BREAK, "break" }, + { GDTokenizer::TK_CF_CONTINUE, "continue" }, + { GDTokenizer::TK_CF_RETURN, "return" }, + { GDTokenizer::TK_CF_MATCH, "match" }, + { GDTokenizer::TK_CF_PASS, "pass" }, + { GDTokenizer::TK_SELF, "self" }, + { GDTokenizer::TK_CONST_PI, "PI" }, + { GDTokenizer::TK_WILDCARD, "_" }, + { GDTokenizer::TK_CONST_INF, "INF" }, + { GDTokenizer::TK_CONST_NAN, "NAN" }, + { GDTokenizer::TK_ERROR, NULL } +}; + const char *GDTokenizer::get_token_name(Token p_token) { ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>"); return token_names[p_token]; } +bool GDTokenizer::is_token_literal(int p_offset, bool variable_safe) const { + switch (get_token(p_offset)) { + // Can always be literal: + case TK_IDENTIFIER: + + case TK_PR_ONREADY: + case TK_PR_TOOL: + case TK_PR_STATIC: + case TK_PR_EXPORT: + case TK_PR_SETGET: + case TK_PR_SIGNAL: + case TK_PR_REMOTE: + case TK_PR_MASTER: + case TK_PR_SLAVE: + case TK_PR_SYNC: + return true; + + // Literal for non-variables only: + case TK_BUILT_IN_TYPE: + case TK_BUILT_IN_FUNC: + + case TK_OP_IN: + //case TK_OP_NOT: + //case TK_OP_OR: + //case TK_OP_AND: + + case TK_PR_CLASS: + case TK_PR_CONST: + case TK_PR_ENUM: + case TK_PR_PRELOAD: + case TK_PR_FUNCTION: + case TK_PR_EXTENDS: + case TK_PR_ASSERT: + case TK_PR_YIELD: + case TK_PR_VAR: + + case TK_CF_IF: + case TK_CF_ELIF: + case TK_CF_ELSE: + case TK_CF_FOR: + case TK_CF_WHILE: + case TK_CF_DO: + case TK_CF_SWITCH: + case TK_CF_CASE: + case TK_CF_BREAK: + case TK_CF_CONTINUE: + case TK_CF_RETURN: + case TK_CF_MATCH: + case TK_CF_PASS: + case TK_SELF: + case TK_CONST_PI: + case TK_WILDCARD: + case TK_CONST_INF: + case TK_CONST_NAN: + case TK_ERROR: + return !variable_safe; + + case TK_CONSTANT: { + switch (get_token_constant(p_offset).get_type()) { + case Variant::NIL: + case Variant::BOOL: + return true; + default: + return false; + } + } + default: + return false; + } +} + +StringName GDTokenizer::get_token_literal(int p_offset) const { + Token token = get_token(p_offset); + switch (token) { + case TK_IDENTIFIER: + return get_token_identifier(p_offset); + case TK_BUILT_IN_TYPE: { + Variant::Type type = get_token_type(p_offset); + int idx = 0; + + while (_type_list[idx].text) { + if (type == _type_list[idx].type) { + return _type_list[idx].text; + } + idx++; + } + } break; // Shouldn't get here, stuff happens + case TK_BUILT_IN_FUNC: + return GDFunctions::get_func_name(get_token_built_in_func(p_offset)); + case TK_CONSTANT: { + const Variant value = get_token_constant(p_offset); + + switch (value.get_type()) { + case Variant::NIL: + return "null"; + case Variant::BOOL: + return value ? "true" : "false"; + default: {} + } + } + case TK_OP_AND: + case TK_OP_OR: + break; // Don't get into default, since they can be non-literal + default: { + int idx = 0; + + while (_keyword_list[idx].text) { + if (token == _keyword_list[idx].token) { + return _keyword_list[idx].text; + } + idx++; + } + } + } + ERR_EXPLAIN("Failed to get token literal"); + ERR_FAIL_V(""); +} + static bool _is_text_char(CharType c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; @@ -776,53 +989,14 @@ void GDTokenizerText::_advance() { bool found = false; - struct _bit { - Variant::Type type; - const char *text; - }; - //built in types - - static const _bit type_list[] = { - //types - { Variant::BOOL, "bool" }, - { Variant::INT, "int" }, - { Variant::REAL, "float" }, - { Variant::STRING, "String" }, - { Variant::VECTOR2, "Vector2" }, - { Variant::RECT2, "Rect2" }, - { Variant::TRANSFORM2D, "Transform2D" }, - { Variant::VECTOR3, "Vector3" }, - { Variant::RECT3, "Rect3" }, - { Variant::PLANE, "Plane" }, - { Variant::QUAT, "Quat" }, - { Variant::BASIS, "Basis" }, - { Variant::TRANSFORM, "Transform" }, - { Variant::COLOR, "Color" }, - { Variant::IMAGE, "Image" }, - { Variant::_RID, "RID" }, - { Variant::OBJECT, "Object" }, - { Variant::INPUT_EVENT, "InputEvent" }, - { Variant::NODE_PATH, "NodePath" }, - { Variant::DICTIONARY, "Dictionary" }, - { Variant::ARRAY, "Array" }, - { Variant::POOL_BYTE_ARRAY, "PoolByteArray" }, - { Variant::POOL_INT_ARRAY, "PoolIntArray" }, - { Variant::POOL_REAL_ARRAY, "PoolFloatArray" }, - { Variant::POOL_STRING_ARRAY, "PoolStringArray" }, - { Variant::POOL_VECTOR2_ARRAY, "PoolVector2Array" }, - { Variant::POOL_VECTOR3_ARRAY, "PoolVector3Array" }, - { Variant::POOL_COLOR_ARRAY, "PoolColorArray" }, - { Variant::VARIANT_MAX, NULL }, - }; - { int idx = 0; - while (type_list[idx].text) { + while (_type_list[idx].text) { - if (str == type_list[idx].text) { - _make_type(type_list[idx].type); + if (str == _type_list[idx].text) { + _make_type(_type_list[idx].type); found = true; break; } @@ -843,73 +1017,18 @@ void GDTokenizerText::_advance() { break; } } - - //keywor } if (!found) { - - struct _kws { - Token token; - const char *text; - }; - - static const _kws keyword_list[] = { - //ops - { TK_OP_IN, "in" }, - { TK_OP_NOT, "not" }, - { TK_OP_OR, "or" }, - { TK_OP_AND, "and" }, - //func - { TK_PR_FUNCTION, "func" }, - { TK_PR_CLASS, "class" }, - { TK_PR_EXTENDS, "extends" }, - { TK_PR_ONREADY, "onready" }, - { TK_PR_TOOL, "tool" }, - { TK_PR_STATIC, "static" }, - { TK_PR_EXPORT, "export" }, - { TK_PR_SETGET, "setget" }, - { TK_PR_VAR, "var" }, - { TK_PR_PRELOAD, "preload" }, - { TK_PR_ASSERT, "assert" }, - { TK_PR_YIELD, "yield" }, - { TK_PR_SIGNAL, "signal" }, - { TK_PR_BREAKPOINT, "breakpoint" }, - { TK_PR_REMOTE, "remote" }, - { TK_PR_MASTER, "master" }, - { TK_PR_SLAVE, "slave" }, - { TK_PR_SYNC, "sync" }, - { TK_PR_CONST, "const" }, - { TK_PR_ENUM, "enum" }, - //controlflow - { TK_CF_IF, "if" }, - { TK_CF_ELIF, "elif" }, - { TK_CF_ELSE, "else" }, - { TK_CF_FOR, "for" }, - { TK_CF_WHILE, "while" }, - { TK_CF_DO, "do" }, - { TK_CF_SWITCH, "switch" }, - { TK_CF_CASE, "case" }, - { TK_CF_BREAK, "break" }, - { TK_CF_CONTINUE, "continue" }, - { TK_CF_RETURN, "return" }, - { TK_CF_MATCH, "match" }, - { TK_CF_PASS, "pass" }, - { TK_SELF, "self" }, - { TK_CONST_PI, "PI" }, - { TK_WILDCARD, "_" }, - { TK_CONST_INF, "INF" }, - { TK_CONST_NAN, "NAN" }, - { TK_ERROR, NULL } - }; + //keyword int idx = 0; found = false; - while (keyword_list[idx].text) { + while (_keyword_list[idx].text) { - if (str == keyword_list[idx].text) { - _make_token(keyword_list[idx].token); + if (str == _keyword_list[idx].text) { + _make_token(_keyword_list[idx].token); found = true; break; } @@ -990,6 +1109,7 @@ const Variant &GDTokenizerText::get_token_constant(int p_offset) const { ERR_FAIL_COND_V(tk_rb[ofs].type != TK_CONSTANT, tk_rb[0].constant); return tk_rb[ofs].constant; } + StringName GDTokenizerText::get_token_identifier(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, StringName()); diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index c1ed8ad92e..4e868301a3 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 */ @@ -95,6 +96,7 @@ public: TK_PR_FUNCTION, TK_PR_CLASS, TK_PR_EXTENDS, + TK_PR_IS, TK_PR_ONREADY, TK_PR_TOOL, TK_PR_STATIC, @@ -147,6 +149,9 @@ protected: public: static const char *get_token_name(Token p_token); + bool is_token_literal(int p_offset = 0, bool variable_safe = false) const; + StringName get_token_literal(int p_offset = 0) const; + virtual const Variant &get_token_constant(int p_offset = 0) const = 0; virtual Token get_token(int p_offset = 0) const = 0; virtual StringName get_token_identifier(int p_offset = 0) const = 0; 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..1205776882 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 */ @@ -344,7 +345,7 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { Octant *g = memnew(Octant); g->dirty = true; g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC); - PhysicsServer::get_singleton()->body_attach_object_instance_ID(g->static_body, get_instance_ID()); + PhysicsServer::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id()); if (is_inside_world()) PhysicsServer::get_singleton()->body_set_space(g->static_body, get_world()->get_space()); @@ -379,6 +380,7 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { ii.multimesh->set_mesh(ii.mesh); ii.multimesh_instance = VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(ii.multimesh_instance, ii.multimesh->get_rid()); + VS::get_singleton()->instance_geometry_set_flag(ii.multimesh_instance, VS::INSTANCE_FLAG_USE_BAKED_LIGHT, true); g.items[p_item] = ii; } @@ -828,8 +830,8 @@ void GridMap::_update_dirty_map_callback() { void GridMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_theme", "theme:MeshLibrary"), &GridMap::set_theme); - ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"), &GridMap::get_theme); + ClassDB::bind_method(D_METHOD("set_theme", "theme"), &GridMap::set_theme); + ClassDB::bind_method(D_METHOD("get_theme"), &GridMap::get_theme); ClassDB::bind_method(D_METHOD("set_cell_size", "size"), &GridMap::set_cell_size); ClassDB::bind_method(D_METHOD("get_cell_size"), &GridMap::get_cell_size); @@ -855,7 +857,7 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_clip", "enabled", "clipabove", "floor", "axis"), &GridMap::set_clip, DEFVAL(true), DEFVAL(0), DEFVAL(Vector3::AXIS_X)); ClassDB::bind_method(D_METHOD("create_area", "id", "area"), &GridMap::create_area); - ClassDB::bind_method(D_METHOD("area_get_bounds", "area", "bounds"), &GridMap::area_get_bounds); + ClassDB::bind_method(D_METHOD("area_get_bounds", "area"), &GridMap::area_get_bounds); ClassDB::bind_method(D_METHOD("area_set_exterior_portal", "area", "enable"), &GridMap::area_set_exterior_portal); ClassDB::bind_method(D_METHOD("area_set_name", "area", "name"), &GridMap::area_set_name); ClassDB::bind_method(D_METHOD("area_get_name", "area"), &GridMap::area_get_name); @@ -865,7 +867,7 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("area_set_portal_disable_color", "area", "color"), &GridMap::area_set_portal_disable_color); ClassDB::bind_method(D_METHOD("area_get_portal_disable_color", "area"), &GridMap::area_get_portal_disable_color); ClassDB::bind_method(D_METHOD("erase_area", "area"), &GridMap::erase_area); - ClassDB::bind_method(D_METHOD("get_unused_area_id", "area"), &GridMap::get_unused_area_id); + ClassDB::bind_method(D_METHOD("get_unused_area_id"), &GridMap::get_unused_area_id); ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear); @@ -1047,21 +1049,21 @@ void GridMap::_update_area_instances() { } } -Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { +Error GridMap::create_area(int p_id, const Rect3 &p_area) { ERR_FAIL_COND_V(area_map.has(p_id), ERR_ALREADY_EXISTS); ERR_EXPLAIN("ID 0 is taken as global area, start from 1"); ERR_FAIL_COND_V(p_id == 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(p_bounds.has_no_area(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_area.has_no_area(), ERR_INVALID_PARAMETER); // FIRST VALIDATE AREA IndexKey from, to; - from.x = p_bounds.pos.x; - from.y = p_bounds.pos.y; - from.z = p_bounds.pos.z; - to.x = p_bounds.pos.x + p_bounds.size.x; - to.y = p_bounds.pos.y + p_bounds.size.y; - to.z = p_bounds.pos.z + p_bounds.size.z; + from.x = p_area.position.x; + from.y = p_area.position.y; + from.z = p_area.position.z; + to.x = p_area.position.x + p_area.size.x; + to.y = p_area.position.y + p_area.size.y; + to.z = p_area.position.z + p_area.size.z; for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... @@ -1100,8 +1102,8 @@ Rect3 GridMap::area_get_bounds(int p_area) const { const Area *a = area_map[p_area]; Rect3 aabb; - aabb.pos = Vector3(a->from.x, a->from.y, a->from.z); - aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.pos; + aabb.position = Vector3(a->from.x, a->from.y, a->from.z); + aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.position; return aabb; } diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 2a0c2b9646..106bf82dc2 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 */ @@ -241,7 +242,7 @@ public: void set_center_z(bool p_enable); bool get_center_z() const; - void set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_orientation = 0); + void set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot = 0); int get_cell_item(int p_x, int p_y, int p_z) const; int get_cell_item_orientation(int p_x, int p_y, int p_z) const; diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index a6a3a03503..38f58799df 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 */ @@ -507,146 +508,150 @@ void GridMapEditor::_duplicate_paste() { } } -bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { +bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { if (!node) { return false; } if (edit_mode->get_selected() == 0) { // regular click - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { - if (p_event.mouse_button.button_index == BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() + 1); + Ref<InputEventMouseButton> mb = p_event; - return true; //eaten - } else if (p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() - 1); - return true; - } + if (mb.is_valid()) { - if (p_event.mouse_button.pressed) { + if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() + mb->get_factor()); - if (p_event.mouse_button.button_index == BUTTON_LEFT) { + return true; //eaten + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() - mb->get_factor()); + return true; + } - if (input_action == INPUT_DUPLICATE) { + if (mb->is_pressed()) { - //paste - _duplicate_paste(); - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else if (p_event.mouse_button.mod.shift) { - input_action = INPUT_SELECT; - } else if (p_event.mouse_button.mod.command) - input_action = INPUT_COPY; - else { - input_action = INPUT_PAINT; - set_items.clear(); - } - } else if (p_event.mouse_button.button_index == BUTTON_RIGHT) - if (input_action == INPUT_DUPLICATE) { - - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else { - input_action = INPUT_ERASE; - set_items.clear(); - } - else - return false; + if (mb->get_button_index() == BUTTON_LEFT) { - return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true); - } else { + if (input_action == INPUT_DUPLICATE) { - if ( - (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) || - (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) { + //paste + _duplicate_paste(); + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else if (mb->get_shift()) { + input_action = INPUT_SELECT; + } else if (mb->get_command()) + input_action = INPUT_COPY; + else { + input_action = INPUT_PAINT; + set_items.clear(); + } + } else if (mb->get_button_index() == BUTTON_RIGHT) + if (input_action == INPUT_DUPLICATE) { - if (set_items.size()) { - undo_redo->create_action("GridMap Paint"); - for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else { + input_action = INPUT_ERASE; + set_items.clear(); + } + else + return false; + + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); + } else { - const SetItem &si = E->get(); - undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); - } - for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { + if ( + (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || + (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - const SetItem &si = E->get(); - undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); - } + if (set_items.size()) { + undo_redo->create_action("GridMap Paint"); + for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - undo_redo->commit_action(); + const SetItem &si = E->get(); + undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } + for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) { + const SetItem &si = E->get(); + undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); + } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } - if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { - input_action = INPUT_NONE; - return true; + undo_redo->commit_action(); } + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + + if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { + + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + input_action = INPUT_NONE; + return true; } - } break; - case InputEvent::MOUSE_MOTION: { + } + } + + Ref<InputEventMouseMotion> mm = p_event; - return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false); - } break; + if (mm.is_valid()) { + + return do_input_action(p_camera, mm->get_position(), false); } } else if (edit_mode->get_selected() == 1) { //area mode, select an area - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { + Ref<InputEventMouseButton> mb = p_event; - if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) { + if (mb.is_valid()) { - Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); + if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Camera *camera = p_camera; - Vector3 from = camera->project_ray_origin(point); - Vector3 normal = camera->project_ray_normal(point); - Transform local_xform = node->get_global_transform().affine_inverse(); - from = local_xform.xform(from); - normal = local_xform.basis.xform(normal).normalized(); + Point2 point = mb->get_position(); - List<int> areas; - node->get_area_list(&areas); + Camera *camera = p_camera; + Vector3 from = camera->project_ray_origin(point); + Vector3 normal = camera->project_ray_normal(point); + Transform local_xform = node->get_global_transform().affine_inverse(); + from = local_xform.xform(from); + normal = local_xform.basis.xform(normal).normalized(); - float min_d = 1e10; - int min_area = -1; + List<int> areas; + node->get_area_list(&areas); - for (List<int>::Element *E = areas.front(); E; E = E->next()) { + float min_d = 1e10; + int min_area = -1; - int area = E->get(); - Rect3 aabb = node->area_get_bounds(area); - aabb.pos *= node->get_cell_size(); - aabb.size *= node->get_cell_size(); + for (List<int>::Element *E = areas.front(); E; E = E->next()) { - Vector3 rclip, rnormal; - if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) - continue; + int area = E->get(); + Rect3 aabb = node->area_get_bounds(area); + aabb.position *= node->get_cell_size(); + aabb.size *= node->get_cell_size(); - float d = normal.dot(rclip); - if (d < min_d) { - min_d = d; - min_area = area; - } - } + Vector3 rclip, rnormal; + if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) + continue; - selected_area = min_area; - update_areas(); + float d = normal.dot(rclip); + if (d < min_d) { + min_d = d; + min_area = area; + } } - } break; + + selected_area = min_area; + update_areas(); + } } } @@ -834,9 +839,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]; @@ -1198,7 +1203,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { edit_mode = memnew(OptionButton); edit_mode->set_area_as_parent_rect(); edit_mode->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 24); - edit_mode->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 14); + edit_mode->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -14); edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); hb->add_child(edit_mode); @@ -1309,9 +1314,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 +1324,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..a1b2c96ccd 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; @@ -219,7 +220,7 @@ protected: static void _bind_methods(); public: - bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event); + bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event); void edit(GridMap *p_gridmap); GridMapEditor() {} @@ -235,11 +236,11 @@ class GridMapEditorPlugin : public EditorPlugin { EditorNode *editor; public: - virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } + virtual bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } virtual String get_name() const { return "GridMap"; } bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; virtual void make_visible(bool p_visible); GridMapEditorPlugin(EditorNode *p_node); 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/hdr/SCsub b/modules/hdr/SCsub new file mode 100644 index 0000000000..c960e8126b --- /dev/null +++ b/modules/hdr/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_hdr = env_modules.Clone() + +# Godot's own source files +env_hdr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/etc1/config.py b/modules/hdr/config.py index fb920482f5..fb920482f5 100644 --- a/modules/etc1/config.py +++ b/modules/hdr/config.py diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp new file mode 100644 index 0000000000..19df27b962 --- /dev/null +++ b/modules/hdr/image_loader_hdr.cpp @@ -0,0 +1,161 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 "image_loader_hdr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + String header = f->get_token(); + + print_line("HEADER: " + header); + ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED); + + while (true) { + String format = f->get_token(); + ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED); + if (format.begins_with("FORMAT=") && format != "FORMAT=32-bit_rle_rgbe") { + ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for .hdr files."); + return ERR_FILE_UNRECOGNIZED; + } + if (format == "FORMAT=32-bit_rle_rgbe") + break; + } + + String token = f->get_token(); + + ERR_FAIL_COND_V(token != "-Y", ERR_FILE_CORRUPT); + + int height = f->get_token().to_int(); + + token = f->get_token(); + + ERR_FAIL_COND_V(token != "+X", ERR_FILE_CORRUPT); + + int width = f->get_line().to_int(); + + print_line("HDR w: " + itos(width) + " h:" + itos(height)); + + PoolVector<uint8_t> imgdata; + + imgdata.resize(height * width * sizeof(uint32_t)); + + { + + PoolVector<uint8_t>::Write w = imgdata.write(); + + uint8_t *ptr = (uint8_t *)w.ptr(); + + if (width < 8 || width >= 32768) { + // Read flat data + + f->get_buffer(ptr, width * height * 4); + } else { + // Read RLE-encoded data + + for (int j = 0; j < height; ++j) { + int c1 = f->get_8(); + int c2 = f->get_8(); + int len = f->get_8(); + if (c1 != 2 || c2 != 2 || (len & 0x80)) { + // not run-length encoded, so we have to actually use THIS data as a decoded + // pixel (note this can't be a valid pixel--one of RGB must be >= 128) + + ptr[(j * width) * 4 + 0] = uint8_t(c1); + ptr[(j * width) * 4 + 1] = uint8_t(c2); + ptr[(j * width) * 4 + 2] = uint8_t(len); + ptr[(j * width) * 4 + 3] = f->get_8(); + + f->get_buffer(&ptr[(j * width + 1) * 4], (width - 1) * 4); + continue; + } + len <<= 8; + len |= f->get_8(); + + print_line("line: " + itos(len)); + if (len != width) { + ERR_EXPLAIN("invalid decoded scanline length, corrupt HDR"); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + + for (int k = 0; k < 4; ++k) { + int i = 0; + while (i < width) { + int count = f->get_8(); + if (count > 128) { + // Run + int value = f->get_8(); + count -= 128; + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = uint8_t(value); + } else { + // Dump + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = f->get_8(); + } + } + } + } + } + + //convert + for (int i = 0; i < width * height; i++) { + + float exp = pow(2.0f, ptr[3] - 128.0f); + + Color c( + ptr[0] * exp / 255.0, + ptr[1] * exp / 255.0, + ptr[2] * exp / 255.0); + + if (p_force_linear) { + c = c.to_linear(); + } + + *(uint32_t *)ptr = c.to_rgbe9995(); + ptr += 4; + } + } + + p_image->create(width, height, false, Image::FORMAT_RGBE9995, imgdata); + + return OK; +} + +void ImageLoaderHDR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("hdr"); +} + +ImageLoaderHDR::ImageLoaderHDR() { +} diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h new file mode 100644 index 0000000000..127833ebd0 --- /dev/null +++ b/modules/hdr/image_loader_hdr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 IMAGE_LOADER_HDR_H +#define IMAGE_LOADER_HDR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderHDR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderHDR(); +}; + +#endif diff --git a/modules/hdr/register_types.cpp b/modules/hdr/register_types.cpp new file mode 100644 index 0000000000..e4f7c14aa7 --- /dev/null +++ b/modules/hdr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* 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 "image_loader_hdr.h" + +static ImageLoaderHDR *image_loader_hdr = NULL; + +void register_hdr_types() { + + image_loader_hdr = memnew(ImageLoaderHDR); + ImageLoader::add_image_format_loader(image_loader_hdr); +} + +void unregister_hdr_types() { + + memdelete(image_loader_hdr); +} diff --git a/modules/cscript/register_types.h b/modules/hdr/register_types.h index 6614ee3a19..3d901ea003 100644 --- a/modules/cscript/register_types.h +++ b/modules/hdr/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_hdr_types(); +void unregister_hdr_types(); diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index ca928c4fe6..8c73b69f1b 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 */ @@ -88,7 +89,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p return OK; } -Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) { +Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { PoolVector<uint8_t> src_image; int src_image_len = f->get_len(); @@ -101,7 +102,7 @@ Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) { f->close(); - Error err = jpeg_load_image_from_buffer(p_image, w.ptr(), src_image_len); + Error err = jpeg_load_image_from_buffer(p_image.ptr(), w.ptr(), src_image_len); w = PoolVector<uint8_t>::Write(); @@ -114,10 +115,11 @@ void ImageLoaderJPG::get_recognized_extensions(List<String> *p_extensions) const p_extensions->push_back("jpeg"); } -static Image _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { +static Ref<Image> _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { - Image img; - Error err = jpeg_load_image_from_buffer(&img, p_png, p_size); + Ref<Image> img; + img.instance(); + Error err = jpeg_load_image_from_buffer(img.ptr(), p_png, p_size); if (err) ERR_PRINT("Couldn't initialize ImageLoaderJPG with the given resource."); diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index 0803cfba1e..aa073b493d 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 */ @@ -37,7 +38,7 @@ class ImageLoaderJPG : public ImageFormatLoader { public: - virtual Error load_image(Image *p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderJPG(); }; 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/nativescript/SCsub b/modules/nativescript/SCsub new file mode 100644 index 0000000000..e980e40e8e --- /dev/null +++ b/modules/nativescript/SCsub @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +Import('env') + +mod_env = env.Clone() +mod_env.add_source_files(env.modules_sources, "*.cpp") +mod_env.Append(CPPPATH='#modules/gdnative') +mod_env.Append(CPPFLAGS=['-DGDAPI_BUILT_IN']) + +Export('mod_env') diff --git a/modules/nativescript/api_generator.cpp b/modules/nativescript/api_generator.cpp new file mode 100644 index 0000000000..47162bfc49 --- /dev/null +++ b/modules/nativescript/api_generator.cpp @@ -0,0 +1,444 @@ +/*************************************************************************/ +/* 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_constants.h" +#include "core/project_settings.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 = ProjectSettings::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 if (m->get().return_val.name != "") { + method_api.return_type = m->get().return_val.name; + } 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/register_types.cpp b/modules/nativescript/api_generator.h index 2477bc51e2..a108d7a7b6 100644 --- a/modules/cscript/register_types.cpp +++ b/modules/nativescript/api_generator.h @@ -1,11 +1,12 @@ /*************************************************************************/ -/* register_types.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,9 +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 "register_types.h" +#ifndef API_GENERATOR_H +#define API_GENERATOR_H -void register_cscript_types() { -} -void unregister_cscript_types() { -} +#include "core/ustring.h" +#include "typedefs.h" + +Error generate_c_api(const String &p_path); + +#endif // API_GENERATOR_H diff --git a/modules/nativescript/config.py b/modules/nativescript/config.py new file mode 100644 index 0000000000..9f57b9bb74 --- /dev/null +++ b/modules/nativescript/config.py @@ -0,0 +1,8 @@ + + +def can_build(platform): + return True + + +def configure(env): + env.use_ptrcall = True diff --git a/modules/nativescript/godot_nativescript.cpp b/modules/nativescript/godot_nativescript.cpp new file mode 100644 index 0000000000..453cee3a18 --- /dev/null +++ b/modules/nativescript/godot_nativescript.cpp @@ -0,0 +1,205 @@ +/*************************************************************************/ +/* godot_nativescript.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_nativescript.h" + +#include "nativescript.h" + +#include "class_db.h" +#include "error_macros.h" +#include "gdnative.h" +#include "global_constants.h" +#include "project_settings.h" +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern "C" void _native_script_hook() { +} + +#define NSL NativeScriptLanguage::get_singleton() + +// Script API + +void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { + + String *s = (String *)p_gdnative_handle; + + Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s]; + + NativeScriptDesc desc; + + desc.create_func = p_create_func; + desc.destroy_func = p_destroy_func; + desc.is_tool = false; + + desc.base = p_base; + + if (classes->has(p_base)) { + desc.base_data = &(*classes)[p_base]; + desc.base_native_type = desc.base_data->base_native_type; + } else { + desc.base_data = NULL; + desc.base_native_type = p_base; + } + + classes->insert(p_name, desc); +} + +void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { + + String *s = (String *)p_gdnative_handle; + + Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s]; + + NativeScriptDesc desc; + + desc.create_func = p_create_func; + desc.destroy_func = p_destroy_func; + desc.is_tool = true; + desc.base = p_base; + + if (classes->has(p_base)) { + desc.base_data = &(*classes)[p_base]; + desc.base_native_type = desc.base_data->base_native_type; + } else { + desc.base_data = NULL; + desc.base_native_type = p_base; + } + + classes->insert(p_name, desc); +} + +void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) { + + String *s = (String *)p_gdnative_handle; + + Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); + + if (!E) { + ERR_EXPLAIN("Attempt to register method on non-existant class!"); + ERR_FAIL(); + } + + NativeScriptDesc::Method method; + method.method = p_method; + method.rpc_mode = p_attr.rpc_type; + method.info = MethodInfo(p_function_name); + + E->get().methods.insert(p_function_name, method); +} + +void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, 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) { + + String *s = (String *)p_gdnative_handle; + + Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); + + if (!E) { + ERR_EXPLAIN("Attempt to register method on non-existant class!"); + ERR_FAIL(); + } + + NativeScriptDesc::Property property; + property.default_value = *(Variant *)&p_attr->default_value; + property.getter = p_get_func; + property.rset_mode = p_attr->rset_type; + property.setter = p_set_func; + property.info = PropertyInfo((Variant::Type)p_attr->type, + p_path, + (PropertyHint)p_attr->hint, + *(String *)&p_attr->hint_string, + (PropertyUsageFlags)p_attr->usage); + + E->get().properties.insert(p_path, property); +} + +void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) { + + String *s = (String *)p_gdnative_handle; + + Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); + + if (!E) { + ERR_EXPLAIN("Attempt to register method on non-existant class!"); + ERR_FAIL(); + } + + List<PropertyInfo> args; + Vector<Variant> default_args; + + for (int i = 0; i < p_signal->num_args; i++) { + PropertyInfo info; + + godot_signal_argument arg = p_signal->args[i]; + + info.hint = (PropertyHint)arg.hint; + info.hint_string = *(String *)&arg.hint_string; + info.name = *(String *)&arg.name; + info.type = (Variant::Type)arg.type; + info.usage = (PropertyUsageFlags)arg.usage; + + args.push_back(info); + } + + 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_args.push_back(*v); + } + + MethodInfo method_info; + method_info.name = *(String *)&p_signal->name; + method_info.arguments = args; + method_info.default_arguments = default_args; + + NativeScriptDesc::Signal signal; + signal.signal = method_info; + + E->get().signals_.insert(*(String *)&p_signal->name, signal); +} + +void GDAPI *godot_nativescript_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() == NativeScriptLanguage::get_singleton()) { + return ((NativeScriptInstance *)instance->get_script_instance())->userdata; + } + return NULL; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/nativescript/godot_nativescript.h b/modules/nativescript/godot_nativescript.h new file mode 100644 index 0000000000..cfd445086b --- /dev/null +++ b/modules/nativescript/godot_nativescript.h @@ -0,0 +1,227 @@ +/*************************************************************************/ +/* 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_NATIVESCRIPT_H +#define GODOT_NATIVESCRIPT_H + +#include <godot/gdnative.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 + +// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! +#ifdef _WIN32 +#define GDN_EXPORT __declspec(dllexport) +#else +#define GDN_EXPORT +#endif + +#include <stdbool.h> +#include <stdint.h> + +typedef enum { + 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 enum { + 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_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_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 { + // 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 { + // 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_nativescript_register_class(void *p_gdnative_handle, 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_nativescript_register_tool_class(void *p_gdnative_handle, 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_method_rpc_mode rpc_type; +} godot_method_attributes; + +typedef struct { + // 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_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method); + +typedef struct { + // 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 { + // 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_nativescript_register_property(void *p_gdnative_handle, 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_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_string name; + int num_args; + godot_signal_argument *args; + int num_default_args; + godot_variant *default_args; +} godot_signal; + +void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal); + +void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp new file mode 100644 index 0000000000..d428834d59 --- /dev/null +++ b/modules/nativescript/nativescript.cpp @@ -0,0 +1,1213 @@ +/*************************************************************************/ +/* nativescript.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 "nativescript.h" + +#include "modules/gdnative/godot/gdnative.h" + +#include "global_constants.h" +#include "io/file_access_encrypted.h" +#include "os/file_access.h" +#include "os/os.h" +#include "project_settings.h" + +#include "scene/main/scene_tree.h" +#include "scene/resources/scene_format_text.h" + +#ifndef NO_THREADS +#include "os/thread.h" +#endif + +#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) +#include "api_generator.h" +#endif + +#ifdef TOOLS_ENABLED +#include "editor/editor_node.h" +#endif + +////// Script stuff + +void NativeScript::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_class_name", "class_name"), &NativeScript::set_class_name); + ClassDB::bind_method(D_METHOD("get_class_name"), &NativeScript::get_class_name); + + ClassDB::bind_method(D_METHOD("set_library", "library"), &NativeScript::set_library); + ClassDB::bind_method(D_METHOD("get_library"), &NativeScript::get_library); + + ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name"); + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); + + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &NativeScript::_new, MethodInfo(Variant::OBJECT, "new")); +} + +#define NSL NativeScriptLanguage::get_singleton() + +#ifdef TOOLS_ENABLED + +void NativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { + NativeScriptDesc *script_data = get_script_desc(); + + ERR_FAIL_COND(!script_data); + + List<PropertyInfo> info; + get_script_property_list(&info); + Map<StringName, Variant> values; + for (List<PropertyInfo>::Element *E = info.front(); E; E = E->next()) { + Variant value; + get_property_default_value(E->get().name, value); + values[E->get().name] = value; + } + + p_placeholder->update(info, values); +} + +void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { + placeholders.erase(p_placeholder); +} + +#endif + +void NativeScript::set_class_name(String p_class_name) { + class_name = p_class_name; +} + +String NativeScript::get_class_name() const { + return class_name; +} + +void NativeScript::set_library(Ref<GDNativeLibrary> p_library) { + if (!library.is_null()) { + WARN_PRINT("library on NativeScript already set. Do nothing."); + return; + } + library = p_library; + lib_path = library->get_active_library_path(); + +#ifndef NO_THREADS + if (Thread::get_caller_id() != Thread::get_main_id()) { + NSL->defer_init_library(p_library, this); + } else +#endif + { + NSL->init_library(p_library); + NSL->register_script(this); + } +} + +Ref<GDNativeLibrary> NativeScript::get_library() const { + return library; +} + +bool NativeScript::can_instance() const { + + NativeScriptDesc *script_data = get_script_desc(); + +#ifdef TOOLS_ENABLED + + return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled()); +#else + return script_data; +#endif +} + +// TODO(karroffel): implement this +Ref<Script> NativeScript::get_base_script() const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return Ref<Script>(); + + Ref<NativeScript> ns = Ref<NativeScript>(NSL->create_script()); + ns->set_class_name(script_data->base); + ns->set_library(get_library()); + return ns; +} + +StringName NativeScript::get_instance_base_type() const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return ""; + + return script_data->base_native_type; +} + +ScriptInstance *NativeScript::instance_create(Object *p_this) { + + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) { + return NULL; + } + +#ifdef TOOLS_ENABLED + if (!ScriptServer::is_scripting_enabled() && !is_tool()) { + // placeholder for nodes. For tools we want the rool thing. + + PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this)); + placeholders.insert(sins); + + if (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 + + NativeScriptInstance *nsi = memnew(NativeScriptInstance); + + nsi->owner = p_this; + nsi->script = Ref<NativeScript>(this); + +#ifndef TOOLS_ENABLED + if (!ScriptServer::is_scripting_enabled()) { + nsi->userdata = NULL; + } else { + nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); + } +#else + nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); +#endif + +#ifndef NO_THREADS + owners_lock->lock(); +#endif + + instance_owners.insert(p_this); + +#ifndef NO_THREADS + owners_lock->unlock(); +#endif + + return nsi; +} + +bool NativeScript::instance_has(const Object *p_this) const { + return instance_owners.has((Object *)p_this); +} + +bool NativeScript::has_source_code() const { + return false; +} + +String NativeScript::get_source_code() const { + return ""; +} + +void NativeScript::set_source_code(const String &p_code) { +} + +Error NativeScript::reload(bool p_keep_state) { + return FAILED; +} + +bool NativeScript::has_method(const StringName &p_method) const { + NativeScriptDesc *script_data = get_script_desc(); + + while (script_data) { + if (script_data->methods.has(p_method)) + return true; + + script_data = script_data->base_data; + } + return false; +} + +MethodInfo NativeScript::get_method_info(const StringName &p_method) const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return MethodInfo(); + + while (script_data) { + Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method); + + if (M) + return M->get().info; + + script_data = script_data->base_data; + } + return MethodInfo(); +} + +bool NativeScript::is_tool() const { + NativeScriptDesc *script_data = get_script_desc(); + + if (script_data) + return script_data->is_tool; + + return false; +} + +String NativeScript::get_node_type() const { + return ""; // NOTE(karroffel): uhm? +} + +ScriptLanguage *NativeScript::get_language() const { + return NativeScriptLanguage::get_singleton(); +} + +bool NativeScript::has_script_signal(const StringName &p_signal) const { + NativeScriptDesc *script_data = get_script_desc(); + + while (script_data) { + if (script_data->signals_.has(p_signal)) + return true; + script_data = script_data->base_data; + } + return false; +} + +void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return; + + Set<MethodInfo> signals_; + + while (script_data) { + + for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) { + signals_.insert(S->get().signal); + } + + script_data = script_data->base_data; + } + + for (Set<MethodInfo>::Element *E = signals_.front(); E; E = E->next()) { + r_signals->push_back(E->get()); + } +} + +bool NativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { + NativeScriptDesc *script_data = get_script_desc(); + + Map<StringName, NativeScriptDesc::Property>::Element *P = NULL; + while (!P && script_data) { + P = script_data->properties.find(p_property); + script_data = script_data->base_data; + } + if (!P) + return false; + + r_value = P->get().default_value; + return true; +} + +void NativeScript::update_exports() { +} + +void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return; + + Set<MethodInfo> methods; + + while (script_data) { + + for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { + methods.insert(E->get().info); + } + + script_data = script_data->base_data; + } + + for (Set<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { + p_list->push_back(E->get()); + } +} + +void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) + return; + + Set<PropertyInfo> properties; + + while (script_data) { + + for (Map<StringName, NativeScriptDesc::Property>::Element *E = script_data->properties.front(); E; E = E->next()) { + properties.insert(E->get().info); + } + + script_data = script_data->base_data; + } + + for (Set<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + p_list->push_back(E->get()); + } +} + +Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + if (lib_path.empty() || class_name.empty() || library.is_null()) { + r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; + return Variant(); + } + + NativeScriptDesc *script_data = get_script_desc(); + + if (!script_data) { + r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; + return Variant(); + } + + r_error.error = Variant::CallError::CALL_OK; + + REF ref; + Object *owner = NULL; + + if (!(script_data->base_native_type == "")) { + owner = ClassDB::instance(script_data->base_native_type); + } else { + owner = memnew(Reference); + } + + Reference *r = owner->cast_to<Reference>(); + if (r) { + ref = REF(r); + } + + NativeScriptInstance *instance = (NativeScriptInstance *)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; + } +} + +// TODO(karroffel): implement this +NativeScript::NativeScript() { + library = Ref<GDNative>(); + lib_path = ""; + class_name = ""; +#ifndef NO_THREADS + owners_lock = Mutex::create(); +#endif +} + +// TODO(karroffel): implement this +NativeScript::~NativeScript() { + NSL->unregister_script(this); + +#ifndef NO_THREADS + memdelete(owners_lock); +#endif +} + +////// ScriptInstance stuff + +#define GET_SCRIPT_DESC() script->get_script_desc() + +void NativeScriptInstance::_ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount) { + if (script_data->base_data) { + _ml_call_reversed(script_data->base_data, p_method, p_args, p_argcount); + } + + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); + if (E) { + godot_variant res = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); + godot_variant_destroy(&res); + } +} + +bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) { + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + Map<StringName, NativeScriptDesc::Property>::Element *P = script_data->properties.find(p_name); + if (P) { + P->get().setter.set_func((godot_object *)owner, + P->get().setter.method_data, + userdata, + (godot_variant *)&p_value); + return true; + } + + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_set"); + if (E) { + Variant name = p_name; + const Variant *args[2] = { &name, &p_value }; + + E->get().method.method((godot_object *)owner, + E->get().method.method_data, + userdata, + 2, + (godot_variant **)args); + return true; + } + + script_data = script_data->base_data; + } + return false; +} +bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + Map<StringName, NativeScriptDesc::Property>::Element *P = script_data->properties.find(p_name); + if (P) { + godot_variant value; + value = P->get().getter.get_func((godot_object *)owner, + P->get().getter.method_data, + userdata); + r_ret = *(Variant *)&value; + godot_variant_destroy(&value); + return true; + } + + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get"); + if (E) { + Variant name = p_name; + const Variant *args[1] = { &name }; + + godot_variant result; + result = E->get().method.method((godot_object *)owner, + E->get().method.method_data, + userdata, + 1, + (godot_variant **)args); + r_ret = *(Variant *)&result; + godot_variant_destroy(&result); + if (r_ret.get_type() == Variant::NIL) { + return false; + } + return true; + } + + script_data = script_data->base_data; + } + return false; +} + +void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { + script->get_script_property_list(p_properties); + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list"); + if (E) { + + godot_variant result; + result = E->get().method.method((godot_object *)owner, + E->get().method.method_data, + userdata, + 0, + NULL); + Variant res = *(Variant *)&result; + godot_variant_destroy(&result); + + if (res.get_type() != Variant::ARRAY) { + ERR_EXPLAIN("_get_property_list must return an array of dictionaries"); + ERR_FAIL(); + } + + Array arr = res; + for (int i = 0; i < arr.size(); i++) { + Dictionary d = arr[i]; + + ERR_CONTINUE(!d.has("name")); + ERR_CONTINUE(!d.has("type")); + + PropertyInfo info; + + info.type = Variant::Type(d["type"].operator int64_t()); + ERR_CONTINUE(info.type < 0 || info.type >= Variant::VARIANT_MAX); + + info.name = d["name"]; + ERR_CONTINUE(info.name == ""); + + if (d.has("hint")) { + info.hint = PropertyHint(d["hint"].operator int64_t()); + } + + if (d.has("hint_string")) { + info.hint_string = d["hint_string"]; + } + + if (d.has("usage")) { + info.usage = d["usage"]; + } + + p_properties->push_back(info); + } + } + + script_data = script_data->base_data; + } + return; +} + +Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + + Map<StringName, NativeScriptDesc::Property>::Element *P = script_data->properties.find(p_name); + if (P) { + *r_is_valid = true; + return P->get().info.type; + } + + script_data = script_data->base_data; + } + return Variant::NIL; +} + +void NativeScriptInstance::get_method_list(List<MethodInfo> *p_list) const { + script->get_method_list(p_list); +} + +bool NativeScriptInstance::has_method(const StringName &p_method) const { + return script->has_method(p_method); +} + +Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); + if (E) { + godot_variant result; + result = E->get().method.method((godot_object *)owner, + E->get().method.method_data, + userdata, + p_argcount, + (godot_variant **)p_args); + Variant res = *(Variant *)&result; + godot_variant_destroy(&result); + r_error.error = Variant::CallError::CALL_OK; + return res; + } + + script_data = script_data->base_data; + } + + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); +} + +void NativeScriptInstance::notification(int p_notification) { + Variant value = p_notification; + const Variant *args[1] = { &value }; + call_multilevel("_notification", args, 1); +} + +void NativeScriptInstance::refcount_incremented() { + Variant::CallError err; + call("_refcount_incremented", NULL, 0, err); + if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { + ERR_PRINT("Failed to invoke _refcount_incremented - should not happen"); + } +} + +bool NativeScriptInstance::refcount_decremented() { + Variant::CallError err; + Variant ret = call("_refcount_decremented", NULL, 0, err); + if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { + ERR_PRINT("Failed to invoke _refcount_decremented - should not happen"); + return true; // assume we can destroy the object + } + if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) { + // the method does not exist, default is true + return true; + } + return ret; +} + +Ref<Script> NativeScriptInstance::get_script() const { + return script; +} + +NativeScriptInstance::RPCMode NativeScriptInstance::get_rpc_mode(const StringName &p_method) const { + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); + if (E) { + switch (E->get().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; + } + } + + script_data = script_data->base_data; + } + + return RPC_MODE_DISABLED; +} + +// TODO(karroffel): implement this +NativeScriptInstance::RPCMode NativeScriptInstance::get_rset_mode(const StringName &p_variable) const { + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + + Map<StringName, NativeScriptDesc::Property>::Element *E = script_data->properties.find(p_variable); + if (E) { + switch (E->get().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; + } + } + + script_data = script_data->base_data; + } + + return RPC_MODE_DISABLED; +} + +ScriptLanguage *NativeScriptInstance::get_language() { + return NativeScriptLanguage::get_singleton(); +} + +void NativeScriptInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + while (script_data) { + Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); + if (E) { + godot_variant res = E->get().method.method((godot_object *)owner, + E->get().method.method_data, + userdata, + p_argcount, + (godot_variant **)p_args); + godot_variant_destroy(&res); + } + script_data = script_data->base_data; + } +} + +void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + if (script_data) { + _ml_call_reversed(script_data, p_method, p_args, p_argcount); + } +} + +NativeScriptInstance::~NativeScriptInstance() { + + NativeScriptDesc *script_data = GET_SCRIPT_DESC(); + + if (!script_data) + return; + + script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); + + if (owner) { + +#ifndef NO_THREADS + script->owners_lock->lock(); +#endif + + script->instance_owners.erase(owner); + +#ifndef NO_THREADS + script->owners_lock->unlock(); +#endif + } +} + +////// ScriptingLanguage stuff + +NativeScriptLanguage *NativeScriptLanguage::singleton; + +extern "C" void _native_script_hook(); +void NativeScriptLanguage::_hacky_api_anchor() { + _native_script_hook(); +} + +void NativeScriptLanguage::_unload_stuff() { + for (Map<String, Map<StringName, NativeScriptDesc> >::Element *L = library_classes.front(); L; L = L->next()) { + for (Map<StringName, NativeScriptDesc>::Element *C = L->get().front(); C; C = C->next()) { + + // free property stuff first + for (Map<StringName, NativeScriptDesc::Property>::Element *P = C->get().properties.front(); P; P = P->next()) { + if (P->get().getter.free_func) + P->get().getter.free_func(P->get().getter.method_data); + + if (P->get().setter.free_func) + P->get().setter.free_func(P->get().setter.method_data); + } + + // free method stuff + for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { + if (M->get().method.free_func) + M->get().method.free_func(M->get().method.method_data); + } + + // free constructor/destructor + if (C->get().create_func.free_func) + C->get().create_func.free_func(C->get().create_func.method_data); + + if (C->get().destroy_func.free_func) + C->get().destroy_func.free_func(C->get().destroy_func.method_data); + } + } +} + +NativeScriptLanguage::NativeScriptLanguage() { + NativeScriptLanguage::singleton = this; +#ifndef NO_THREADS + mutex = Mutex::create(); +#endif +} + +// TODO(karroffel): implement this +NativeScriptLanguage::~NativeScriptLanguage() { + // _unload_stuff(); // NOTE(karroffel): This gets called in ::finish() + + for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { + + L->get()->terminate(); + NSL->library_classes.clear(); + NSL->library_gdnatives.clear(); + NSL->library_script_users.clear(); + } + +#ifndef NO_THREADS + memdelete(mutex); +#endif +} + +String NativeScriptLanguage::get_name() const { + return "NativeScript"; +} + +void _add_reload_node() { +#ifdef TOOLS_ENABLED + NativeReloadNode *rn = memnew(NativeReloadNode); + EditorNode::get_singleton()->add_child(rn); +#endif +} + +// TODO(karroffel): implement this +void NativeScriptLanguage::init() { + +#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 + EditorNode::add_init_callback(&_add_reload_node); +#endif +} +String NativeScriptLanguage::get_type() const { + return "NativeScript"; +} +String NativeScriptLanguage::get_extension() const { + return "gdns"; +} +Error NativeScriptLanguage::execute_file(const String &p_path) { + return OK; // Qué? +} +void NativeScriptLanguage::finish() { + _unload_stuff(); +} +void NativeScriptLanguage::get_reserved_words(List<String> *p_words) const { +} +void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { +} +void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { +} + +// TODO(karroffel): implement this +Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { + NativeScript *s = memnew(NativeScript); + s->set_class_name(p_class_name); + // TODO(karroffel): use p_base_class_name + return Ref<NativeScript>(s); +} +bool NativeScriptLanguage::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; +} + +Script *NativeScriptLanguage::create_script() const { + NativeScript *script = memnew(NativeScript); + return script; +} +bool NativeScriptLanguage::has_named_classes() const { + return true; +} +int NativeScriptLanguage::find_function(const String &p_function, const String &p_code) const { + return -1; +} +String NativeScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const { + return ""; +} +void NativeScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { +} +void NativeScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { +} + +// Debugging stuff here. Not used for now. +String NativeScriptLanguage::debug_get_error() const { + return ""; +} +int NativeScriptLanguage::debug_get_stack_level_count() const { + return -1; +} +int NativeScriptLanguage::debug_get_stack_level_line(int p_level) const { + return -1; +} +String NativeScriptLanguage::debug_get_stack_level_function(int p_level) const { + return ""; +} +String NativeScriptLanguage::debug_get_stack_level_source(int p_level) const { + return ""; +} +void NativeScriptLanguage::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 NativeScriptLanguage::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 NativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { +} +String NativeScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { + return ""; +} +// Debugging stuff end. + +void NativeScriptLanguage::reload_all_scripts() { +} + +void NativeScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { +} +void NativeScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdns"); +} + +void NativeScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { +} + +void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const { +} + +void NativeScriptLanguage::profiling_start() { +} + +void NativeScriptLanguage::profiling_stop() { +} + +int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { + return 0; +} + +#ifndef NO_THREADS +void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script) { + MutexLock lock(mutex); + libs_to_init.insert(lib); + scripts_to_register.insert(script); + has_objects_to_register = true; +} +#endif + +void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { +#ifndef NO_THREADS + MutexLock lock(mutex); +#endif + // See if this library was "registered" already. + const String &lib_path = lib->get_active_library_path(); + Map<String, Ref<GDNative> >::Element *E = library_gdnatives.find(lib_path); + + if (!E) { + Ref<GDNative> gdn; + gdn.instance(); + gdn->set_library(lib); + + // TODO(karroffel): check the return value? + gdn->initialize(); + + library_gdnatives.insert(lib_path, gdn); + + library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>()); + + if (!library_script_users.has(lib_path)) + library_script_users.insert(lib_path, Set<NativeScript *>()); + + void *args[1] = { + (void *)&lib_path + }; + + // here the library registers all the classes and stuff. + gdn->call_native_raw(_init_call_type, + _init_call_name, + NULL, + 1, + args, + NULL); + } else { + // already initialized. Nice. + } +} + +void NativeScriptLanguage::register_script(NativeScript *script) { +#ifndef NO_THREADS + MutexLock lock(mutex); +#endif + library_script_users[script->lib_path].insert(script); +} + +void NativeScriptLanguage::unregister_script(NativeScript *script) { +#ifndef NO_THREADS + MutexLock lock(mutex); +#endif + Map<String, Set<NativeScript *> >::Element *S = library_script_users.find(script->lib_path); + if (S) { + S->get().erase(script); + if (S->get().size() == 0) { + library_script_users.erase(S); + } + } +#ifndef NO_THREADS + scripts_to_register.erase(script); +#endif +} + +void NativeScriptLanguage::call_libraries_cb(const StringName &name) { + // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here + for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) { + if (L->get()->is_initialized()) { + L->get()->call_native_raw( + _noarg_call_type, + name, + NULL, + 0, + NULL, + NULL); + } + } +} + +void NativeScriptLanguage::frame() { +#ifndef NO_THREADS + if (has_objects_to_register) { + MutexLock lock(mutex); + for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) { + init_library(L->get()); + } + libs_to_init.clear(); + for (Set<NativeScript *>::Element *S = scripts_to_register.front(); S; S = S->next()) { + register_script(S->get()); + } + scripts_to_register.clear(); + has_objects_to_register = false; + } +#endif + call_libraries_cb(_frame_call_name); +} + +#ifndef NO_THREADS + +void NativeScriptLanguage::thread_enter() { + call_libraries_cb(_thread_enter_call_name); +} + +void NativeScriptLanguage::thread_exit() { + call_libraries_cb(_thread_exit_call_name); +} + +#endif // NO_THREADS + +void NativeReloadNode::_bind_methods() { + ClassDB::bind_method(D_METHOD("_notification"), &NativeReloadNode::_notification); +} + +void NativeReloadNode::_notification(int p_what) { +#ifdef TOOLS_ENABLED + + switch (p_what) { + case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { + + if (unloaded) + break; +#ifndef NO_THREADS + MutexLock lock(NSL->mutex); +#endif + NSL->_unload_stuff(); + for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { + + L->get()->terminate(); + NSL->library_classes.erase(L->key()); + } + + unloaded = true; + + } break; + + case MainLoop::NOTIFICATION_WM_FOCUS_IN: { + + if (!unloaded) + break; +#ifndef NO_THREADS + MutexLock lock(NSL->mutex); +#endif + Set<StringName> libs_to_remove; + for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { + + if (!L->get()->initialize()) { + libs_to_remove.insert(L->key()); + continue; + } + + NSL->library_classes.insert(L->key(), Map<StringName, NativeScriptDesc>()); + + void *args[1] = { + (void *)&L->key() + }; + + // here the library registers all the classes and stuff. + L->get()->call_native_raw(NSL->_init_call_type, + NSL->_init_call_name, + NULL, + 1, + args, + NULL); + + for (Map<String, Set<NativeScript *> >::Element *U = NSL->library_script_users.front(); U; U = U->next()) { + for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) { + NativeScript *script = S->get(); + + if (script->placeholders.size() == 0) + continue; + + for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { + script->_update_placeholder(P->get()); + } + } + } + } + + unloaded = false; + + for (Set<StringName>::Element *R = libs_to_remove.front(); R; R = R->next()) { + NSL->library_gdnatives.erase(R->get()); + } + + } break; + default: { + }; + } +#endif +} + +RES ResourceFormatLoaderNativeScript::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 ResourceFormatLoaderNativeScript::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdns"); +} + +bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const { + return (p_type == "Script" || p_type == "NativeScript"); +} + +String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const { + String el = p_path.get_extension().to_lower(); + if (el == "gdns") + return "NativeScript"; + return ""; +} + +Error ResourceFormatSaverNativeScript::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 ResourceFormatSaverNativeScript::recognize(const RES &p_resource) const { + return p_resource->cast_to<NativeScript>() != NULL; +} + +void ResourceFormatSaverNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { + if (p_resource->cast_to<NativeScript>()) { + p_extensions->push_back("gdns"); + } +} diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h new file mode 100644 index 0000000000..b62fefec40 --- /dev/null +++ b/modules/nativescript/nativescript.h @@ -0,0 +1,325 @@ +/*************************************************************************/ +/* nativescript.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 NATIVE_SCRIPT_H +#define NATIVE_SCRIPT_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_nativescript.h" +#include "modules/gdnative/gdnative.h" + +#ifndef NO_THREADS +#include "os/mutex.h" +#endif + +struct NativeScriptDesc { + + struct Method { + godot_instance_method method; + MethodInfo info; + int rpc_mode; + }; + struct Property { + godot_property_set_func setter; + godot_property_get_func getter; + PropertyInfo info; + Variant default_value; + int 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; + NativeScriptDesc *base_data; + godot_instance_create_func create_func; + godot_instance_destroy_func destroy_func; + + bool is_tool; + + inline NativeScriptDesc() + : methods(), + properties(), + signals_(), + base(), + base_native_type() { + zeromem(&create_func, sizeof(godot_instance_create_func)); + zeromem(&destroy_func, sizeof(godot_instance_destroy_func)); + } +}; + +class NativeScript : public Script { + GDCLASS(NativeScript, Script) + +#ifdef TOOLS_ENABLED + Set<PlaceHolderScriptInstance *> placeholders; + void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); +#endif + + friend class NativeScriptInstance; + friend class NativeScriptLanguage; + friend class NativeReloadNode; + friend class GDNativeLibrary; + + Ref<GDNativeLibrary> library; + + String lib_path; + + String class_name; + +#ifndef NO_THREADS + Mutex *owners_lock; +#endif + Set<Object *> instance_owners; + +protected: + static void _bind_methods(); + +public: + inline NativeScriptDesc *get_script_desc() const; + + void set_class_name(String p_class_name); + String get_class_name() const; + + void set_library(Ref<GDNativeLibrary> p_library); + Ref<GDNativeLibrary> get_library() const; + + 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); + + NativeScript(); + ~NativeScript(); +}; + +class NativeScriptInstance : public ScriptInstance { + + friend class NativeScript; + + Object *owner; + Ref<NativeScript> script; + + void _ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount); + +public: + void *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) 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 notification(int p_notification); + virtual Ref<Script> get_script() const; + virtual RPCMode get_rpc_mode(const StringName &p_method) const; + virtual RPCMode get_rset_mode(const StringName &p_variable) const; + virtual ScriptLanguage *get_language(); + + 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); + + virtual void refcount_incremented(); + virtual bool refcount_decremented(); + + ~NativeScriptInstance(); +}; + +class NativeReloadNode; + +class NativeScriptLanguage : public ScriptLanguage { + + friend class NativeScript; + friend class NativeScriptInstance; + friend class NativeReloadNode; + +private: + static NativeScriptLanguage *singleton; + + void _unload_stuff(); + +#ifndef NO_THREADS + Mutex *mutex; + + Set<Ref<GDNativeLibrary> > libs_to_init; + Set<NativeScript *> scripts_to_register; + volatile bool has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed + void defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script); +#endif + + void init_library(const Ref<GDNativeLibrary> &lib); + void register_script(NativeScript *script); + void unregister_script(NativeScript *script); + + void call_libraries_cb(const StringName &name); + +public: + // These two maps must only be touched on the main thread + Map<String, Map<StringName, NativeScriptDesc> > library_classes; + Map<String, Ref<GDNative> > library_gdnatives; + + Map<String, Set<NativeScript *> > library_script_users; + + const StringName _init_call_type = "nativescript_init"; + const StringName _init_call_name = "godot_nativescript_init"; + + const StringName _noarg_call_type = "nativescript_no_arg"; + + const StringName _frame_call_name = "godot_nativescript_frame"; + +#ifndef NO_THREADS + const StringName _thread_enter_call_name = "godot_nativescript_thread_enter"; + const StringName _thread_exit_call_name = "godot_nativescript_thread_exit"; +#endif + + NativeScriptLanguage(); + ~NativeScriptLanguage(); + + inline static NativeScriptLanguage *get_singleton() { + return singleton; + } + + void _hacky_api_anchor(); + +#ifndef NO_THREADS + virtual void thread_enter(); + virtual void thread_exit(); +#endif + + virtual void frame(); + + virtual String get_name() const; + virtual void init(); + virtual String get_type() const; + virtual String get_extension() const; + virtual Error execute_file(const String &p_path); + virtual void finish(); + 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) 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 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); + 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, int p_max_depth); + virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth); + virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth); + virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth); + virtual void reload_all_scripts(); + virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload); + 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; + 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); +}; + +inline NativeScriptDesc *NativeScript::get_script_desc() const { + Map<StringName, NativeScriptDesc>::Element *E = NativeScriptLanguage::singleton->library_classes[lib_path].find(class_name); + return E ? &E->get() : NULL; +} + +class NativeReloadNode : public Node { + GDCLASS(NativeReloadNode, Node) + bool unloaded = false; + +public: + static void _bind_methods(); + void _notification(int p_what); +}; + +class ResourceFormatLoaderNativeScript : 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 ResourceFormatSaverNativeScript : 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/nativescript/register_types.cpp b/modules/nativescript/register_types.cpp new file mode 100644 index 0000000000..c28b982884 --- /dev/null +++ b/modules/nativescript/register_types.cpp @@ -0,0 +1,118 @@ +/*************************************************************************/ +/* 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 "io/resource_loader.h" +#include "io/resource_saver.h" + +#include "nativescript.h" + +#include "core/os/os.h" + +NativeScriptLanguage *native_script_language; + +typedef void (*native_script_init_fn)(void *); + +void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) { + if (p_handle == NULL) { + ERR_PRINT("No valid library handle, can't call nativescript init procedure"); + return; + } + + void *library_proc; + Error err = OS::get_singleton()->get_dynamic_library_symbol_handle( + p_handle, + *(String *)p_proc_name, + library_proc, + true); // we print our own message + if (err != OK) { + ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data()); + return; + } + + native_script_init_fn fn = (native_script_init_fn)library_proc; + + fn(args[0]); +} + +typedef void (*native_script_empty_callback)(); + +void noarg_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) { + if (p_handle == NULL) { + ERR_PRINT("No valid library handle, can't call nativescript callback"); + return; + } + + void *library_proc; + Error err = OS::get_singleton()->get_dynamic_library_symbol_handle( + p_handle, + *(String *)p_proc_name, + library_proc, + true); + if (err != OK) { + // it's fine if thread callbacks are not present in the library. + return; + } + + native_script_empty_callback fn = (native_script_empty_callback)library_proc; + fn(); +} + +ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL; +ResourceFormatSaverNativeScript *resource_saver_gdns = NULL; + +void register_nativescript_types() { + native_script_language = memnew(NativeScriptLanguage); + + ClassDB::register_class<NativeScript>(); + + ScriptServer::register_language(native_script_language); + + GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb); + GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_noarg_call_type, noarg_call_cb); + + resource_saver_gdns = memnew(ResourceFormatSaverNativeScript); + ResourceSaver::add_resource_format_saver(resource_saver_gdns); + + resource_loader_gdns = memnew(ResourceFormatLoaderNativeScript); + ResourceLoader::add_resource_format_loader(resource_loader_gdns); +} + +void unregister_nativescript_types() { + + memdelete(resource_loader_gdns); + + memdelete(resource_saver_gdns); + + if (native_script_language) { + ScriptServer::unregister_language(native_script_language); + memdelete(native_script_language); + } +} diff --git a/modules/nativescript/register_types.h b/modules/nativescript/register_types.h new file mode 100644 index 0000000000..319da9c42f --- /dev/null +++ b/modules/nativescript/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* 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 */ +/* "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. */ +/*************************************************************************/ +void register_nativescript_types(); +void unregister_nativescript_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/SCsub b/modules/openssl/SCsub index 0e811ce8c9..add7d4dcfc 100644 --- a/modules/openssl/SCsub +++ b/modules/openssl/SCsub @@ -677,7 +677,16 @@ if (env['builtin_openssl'] != 'no'): # Module sources env_openssl.add_source_files(env.modules_sources, "*.cpp") -env_openssl.add_source_files(env.modules_sources, "*.c") + + +# Other thirdparty dependencies +thirdparty_misc_dir = "#thirdparty/misc/" +thirdparty_misc_sources = [ + "curl_hostcheck.c", +] +thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources] +env_openssl.add_source_files(env.modules_sources, thirdparty_misc_sources) + # platform/uwp need to know openssl is available, pass to main env if "platform" in env and env["platform"] == "uwp": diff --git a/modules/openssl/curl_hostcheck.c b/modules/openssl/curl_hostcheck.c deleted file mode 100644 index feef232619..0000000000 --- a/modules/openssl/curl_hostcheck.c +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ***************************************************************************/ - -/* This file is an amalgamation of hostcheck.c and most of rawstr.c - from cURL. The contents of the COPYING file mentioned above are: - -COPYRIGHT AND PERMISSION NOTICE - -Copyright (c) 1996 - 2013, Daniel Stenberg, <daniel@haxx.se>. - -All rights reserved. - -Permission to use, copy, modify, and distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright -notice and this permission notice appear in all copies. - -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 OF THIRD PARTY RIGHTS. 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. - -Except as contained in this notice, the name of a copyright holder shall not -be used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization of the copyright holder. -*/ - -#include "curl_hostcheck.h" -#include <string.h> - -/* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because - its behavior is altered by the current locale. */ -static char Curl_raw_toupper(char in) -{ - switch (in) { - case 'a': - return 'A'; - case 'b': - return 'B'; - case 'c': - return 'C'; - case 'd': - return 'D'; - case 'e': - return 'E'; - case 'f': - return 'F'; - case 'g': - return 'G'; - case 'h': - return 'H'; - case 'i': - return 'I'; - case 'j': - return 'J'; - case 'k': - return 'K'; - case 'l': - return 'L'; - case 'm': - return 'M'; - case 'n': - return 'N'; - case 'o': - return 'O'; - case 'p': - return 'P'; - case 'q': - return 'Q'; - case 'r': - return 'R'; - case 's': - return 'S'; - case 't': - return 'T'; - case 'u': - return 'U'; - case 'v': - return 'V'; - case 'w': - return 'W'; - case 'x': - return 'X'; - case 'y': - return 'Y'; - case 'z': - return 'Z'; - } - return in; -} - -/* - * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant - * to be locale independent and only compare strings we know are safe for - * this. See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for - * some further explanation to why this function is necessary. - * - * The function is capable of comparing a-z case insensitively even for - * non-ascii. - */ - -static int Curl_raw_equal(const char *first, const char *second) -{ - while(*first && *second) { - if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) - /* get out of the loop as soon as they don't match */ - break; - first++; - second++; - } - /* we do the comparison here (possibly again), just to make sure that if the - loop above is skipped because one of the strings reached zero, we must not - return this as a successful match */ - return (Curl_raw_toupper(*first) == Curl_raw_toupper(*second)); -} - -static int Curl_raw_nequal(const char *first, const char *second, size_t max) -{ - while(*first && *second && max) { - if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) { - break; - } - max--; - first++; - second++; - } - if(0 == max) - return 1; /* they are equal this far */ - - return Curl_raw_toupper(*first) == Curl_raw_toupper(*second); -} - -/* - * Match a hostname against a wildcard pattern. - * E.g. - * "foo.host.com" matches "*.host.com". - * - * We use the matching rule described in RFC6125, section 6.4.3. - * http://tools.ietf.org/html/rfc6125#section-6.4.3 - */ - -static int hostmatch(const char *hostname, const char *pattern) -{ - const char *pattern_label_end, *pattern_wildcard, *hostname_label_end; - int wildcard_enabled; - size_t prefixlen, suffixlen; - pattern_wildcard = strchr(pattern, '*'); - if(pattern_wildcard == NULL) - return Curl_raw_equal(pattern, hostname) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; - - /* We require at least 2 dots in pattern to avoid too wide wildcard - match. */ - wildcard_enabled = 1; - pattern_label_end = strchr(pattern, '.'); - if(pattern_label_end == NULL || strchr(pattern_label_end+1, '.') == NULL || - pattern_wildcard > pattern_label_end || - Curl_raw_nequal(pattern, "xn--", 4)) { - wildcard_enabled = 0; - } - if(!wildcard_enabled) - return Curl_raw_equal(pattern, hostname) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; - - hostname_label_end = strchr(hostname, '.'); - if(hostname_label_end == NULL || - !Curl_raw_equal(pattern_label_end, hostname_label_end)) - return CURL_HOST_NOMATCH; - - /* The wildcard must match at least one character, so the left-most - label of the hostname is at least as large as the left-most label - of the pattern. */ - if(hostname_label_end - hostname < pattern_label_end - pattern) - return CURL_HOST_NOMATCH; - - prefixlen = pattern_wildcard - pattern; - suffixlen = pattern_label_end - (pattern_wildcard+1); - return Curl_raw_nequal(pattern, hostname, prefixlen) && - Curl_raw_nequal(pattern_wildcard+1, hostname_label_end - suffixlen, - suffixlen) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; -} - -int Tool_Curl_cert_hostcheck(const char *match_pattern, const char *hostname) -{ - if(!match_pattern || !*match_pattern || - !hostname || !*hostname) /* sanity check */ - return 0; - - if(Curl_raw_equal(hostname, match_pattern)) /* trivial case */ - return 1; - - if(hostmatch(hostname,match_pattern) == CURL_HOST_MATCH) - return 1; - return 0; -} diff --git a/modules/openssl/curl_hostcheck.h b/modules/openssl/curl_hostcheck.h deleted file mode 100644 index 1b7fbe81e3..0000000000 --- a/modules/openssl/curl_hostcheck.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef HEADER_TOOL_CURL_HOSTCHECK_H -#define HEADER_TOOL_CURL_HOSTCHECK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ***************************************************************************/ - -#define CURL_HOST_NOMATCH 0 -#define CURL_HOST_MATCH 1 -int Tool_Curl_cert_hostcheck(const char *match_pattern, const char *hostname); - -#ifdef __cplusplus -} -#endif - -#endif /* HEADER_CURL_HOSTCHECK_H */ - 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..7a9d5195a9 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 */ @@ -559,7 +560,7 @@ void StreamPeerOpenSSL::initialize_ssl() { ERR_load_BIO_strings(); // Load BIO error strings OpenSSL_add_all_algorithms(); // Load all available encryption algorithms String certs_path = GLOBAL_DEF("network/ssl/certificates", ""); - GlobalConfig::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt")); + ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt")); if (certs_path != "") { FileAccess *f = FileAccess::open(certs_path, FileAccess::READ); @@ -580,7 +581,7 @@ void StreamPeerOpenSSL::initialize_ssl() { } } String config_path = GLOBAL_DEF("network/ssl/config", ""); - GlobalConfig::get_singleton()->set_custom_property_info("network/ssl/config", PropertyInfo(Variant::STRING, "network/ssl/config", PROPERTY_HINT_FILE, "*.cnf")); + ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/config", PropertyInfo(Variant::STRING, "network/ssl/config", PROPERTY_HINT_FILE, "*.cnf")); if (config_path != "") { Vector<uint8_t> data = FileAccess::get_file_as_array(config_path); diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h index 56b45802df..b1da5e1d95 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 */ @@ -29,17 +30,19 @@ #ifndef STREAM_PEER_OPEN_SSL_H #define STREAM_PEER_OPEN_SSL_H -#include "curl_hostcheck.h" -#include "global_config.h" #include "io/stream_peer_ssl.h" #include "os/file_access.h" -#include <stdio.h> // If you don't know what this is for stop reading now. +#include "project_settings.h" + +#include "thirdparty/misc/curl_hostcheck.h" #include <openssl/bio.h> // BIO objects for I/O #include <openssl/err.h> // Error reporting #include <openssl/ssl.h> // SSL and SSL_CTX for SSL connections #include <openssl/x509v3.h> +#include <stdio.h> + class StreamPeerOpenSSL : public StreamPeerSSL { private: static int _bio_create(BIO *b); 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..bdd4779e28 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 */ @@ -163,8 +164,8 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, print_line("flip: " + itos(flags & PVR_VFLIP)); - Image image(width, height, mipmaps, format, data); - ERR_FAIL_COND_V(image.empty(), RES()); + Ref<Image> image = memnew(Image(width, height, mipmaps, format, data)); + ERR_FAIL_COND_V(image->empty(), RES()); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(image, tex_flags); @@ -192,30 +193,32 @@ String ResourceFormatPVR::get_resource_type(const String &p_path) const { static void _compress_pvrtc4(Image *p_img) { - Image img = *p_img; + Ref<Image> img = p_img->duplicate(); bool make_mipmaps = false; - if (img.get_width() % 8 || img.get_height() % 8) { - make_mipmaps = img.has_mipmaps(); - img.resize(img.get_width() + (8 - (img.get_width() % 8)), img.get_height() + (8 - (img.get_height() % 8))); + if (img->get_width() % 8 || img->get_height() % 8) { + make_mipmaps = img->has_mipmaps(); + img->resize(img->get_width() + (8 - (img->get_width() % 8)), img->get_height() + (8 - (img->get_height() % 8))); } - img.convert(Image::FORMAT_RGBA8); - if (!img.has_mipmaps() && make_mipmaps) - img.generate_mipmaps(); + img->convert(Image::FORMAT_RGBA8); + if (!img->has_mipmaps() && make_mipmaps) + img->generate_mipmaps(); - bool use_alpha = img.detect_alpha(); + bool use_alpha = img->detect_alpha(); - Image new_img; - new_img.create(img.get_width(), img.get_height(), true, use_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4); - PoolVector<uint8_t> data = new_img.get_data(); + Ref<Image> new_img; + new_img.instance(); + new_img->create(img->get_width(), img->get_height(), true, use_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4); + + PoolVector<uint8_t> data = new_img->get_data(); { PoolVector<uint8_t>::Write wr = data.write(); - PoolVector<uint8_t>::Read r = img.get_data().read(); + PoolVector<uint8_t>::Read r = img->get_data().read(); - for (int i = 0; i <= new_img.get_mipmap_count(); i++) { + for (int i = 0; i <= new_img->get_mipmap_count(); i++) { int ofs, size, w, h; - img.get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); + img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::RgbaBitmap bm(w, h); copymem(bm.GetData(), &r[ofs], size); { @@ -225,12 +228,12 @@ static void _compress_pvrtc4(Image *p_img) { } } - new_img.get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); + new_img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::PvrTcEncoder::EncodeRgba4Bpp(&wr[ofs], bm); } } - *p_img = Image(new_img.get_width(), new_img.get_height(), new_img.has_mipmaps(), new_img.get_format(), data); + p_img->create(new_img->get_width(), new_img->get_height(), new_img->has_mipmaps(), new_img->get_format(), data); } ResourceFormatPVR::ResourceFormatPVR() { @@ -675,8 +678,7 @@ static void _pvrtc_decompress(Image *p_img) { r = PoolVector<uint8_t>::Read(); bool make_mipmaps = p_img->has_mipmaps(); - Image newimg(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); + p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); if (make_mipmaps) - newimg.generate_mipmaps(); - *p_img = newimg; + p_img->generate_mipmaps(); } 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..c728657d6b 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 */ @@ -589,6 +590,11 @@ struct RegExNodeGroup : public RegExNode { memdelete(childset[i]); } + virtual void test_success(RegExSearch &s, int pos) const { + + return; + } + virtual int test(RegExSearch &s, int pos) const { for (int i = 0; i < childset.size(); ++i) { @@ -597,10 +603,8 @@ struct RegExNodeGroup : public RegExNode { int res = childset[i]->test(s, pos); - if (s.complete) - return res; - if (inverse) { + s.complete = false; if (res < 0) res = pos + 1; else @@ -610,9 +614,13 @@ struct RegExNodeGroup : public RegExNode { continue; } + if (s.complete) + return res; + if (res >= 0) { if (reset_pos) res = pos; + this->test_success(s, res); return next ? next->test(s, res) : res; } } @@ -667,6 +675,12 @@ struct RegExNodeCapturing : public RegExNodeGroup { id = p_id; } + virtual void test_success(RegExSearch &s, int pos) const { + + RegExMatch::Group &ref = s.match->captures[id]; + ref.length = pos - ref.start; + } + virtual int test(RegExSearch &s, int pos) const { RegExMatch::Group &ref = s.match->captures[id]; @@ -675,13 +689,8 @@ struct RegExNodeCapturing : public RegExNodeGroup { int res = RegExNodeGroup::test(s, pos); - if (res >= 0) { - if (!s.complete) - ref.length = res - pos; - } else { + if (res < 0) ref.start = old_start; - } - return res; } 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..efce76c805 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 */ @@ -30,65 +31,143 @@ #include "print_string.h" -#include <squish.h> +#if defined(__SSE2__) +#define SQUISH_USE_SSE 2 +#elif defined(__SSE__) +#define SQUISH_USE_SSE 1 +#endif -void image_compress_squish(Image *p_image) { +#include <squish.h> +void image_decompress_squish(Image *p_image) { int w = p_image->get_width(); int h = p_image->get_height(); - if (!p_image->has_mipmaps()) { - ERR_FAIL_COND(!w || w % 4 != 0); - ERR_FAIL_COND(!h || h % 4 != 0); + Image::Format target_format = Image::FORMAT_RGBA8; + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); + int mm_count = p_image->get_mipmap_count(); + data.resize(target_size); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + PoolVector<uint8_t>::Write wb = data.write(); + + int squish_flags = Image::FORMAT_MAX; + if (p_image->get_format() == Image::FORMAT_DXT1) { + squish_flags = squish::kDxt1; + } else if (p_image->get_format() == Image::FORMAT_DXT3) { + squish_flags = squish::kDxt3; + } else if (p_image->get_format() == Image::FORMAT_DXT5) { + squish_flags = squish::kDxt5; + } else if (p_image->get_format() == Image::FORMAT_RGTC_R) { + squish_flags = squish::kBc4; + } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { + squish_flags = squish::kBc5; } else { - ERR_FAIL_COND(!w || w != nearest_power_of_2(w)); - ERR_FAIL_COND(!h || h != nearest_power_of_2(h)); - }; + print_line("wtf askd to decompress.. " + itos(p_image->get_format())); + ERR_FAIL_COND(true); + return; + } + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + int src_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; + p_image->get_mipmap_offset_size_and_dimensions(i, src_ofs, mipmap_size, mipmap_w, mipmap_h); + squish::DecompressImage(&wb[dst_ofs], mipmap_w, mipmap_h, &rb[src_ofs], squish_flags); + } + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); +} + +void image_compress_squish(Image *p_image, Image::CompressSource p_source) { if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed - int shift = 0; - int squish_comp = squish::kColourRangeFit; - Image::Format target_format; + int w = p_image->get_width(); + int h = p_image->get_height(); - if (p_image->get_format() == Image::FORMAT_LA8) { - //compressed normalmap - target_format = Image::FORMAT_DXT5; - squish_comp |= squish::kDxt5; - } else if (p_image->detect_alpha() != Image::ALPHA_NONE) { + if (p_image->get_format() <= Image::FORMAT_RGBA8) { - target_format = Image::FORMAT_DXT3; - squish_comp |= squish::kDxt3; - } else { - target_format = Image::FORMAT_DXT1; - shift = 1; - squish_comp |= squish::kDxt1; - } + int squish_comp = squish::kColourRangeFit; + Image::Format target_format; - p_image->convert(Image::FORMAT_RGBA8); //always expects rgba + Image::DetectChannels dc = p_image->get_detected_channels(); - PoolVector<uint8_t> data; - int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); - int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; - data.resize(target_size); + p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - PoolVector<uint8_t>::Read rb = p_image->get_data().read(); - PoolVector<uint8_t>::Write wb = data.write(); + if (p_source == Image::COMPRESS_SOURCE_SRGB && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + //R and RG do not support SRGB + dc = Image::DETECTED_RGB; + } - int dst_ofs = 0; + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //R and RG do not support SRGB + dc = Image::DETECTED_RG; + } - for (int i = 0; i <= mm_count; i++) { + switch (dc) { + case Image::DETECTED_L: { - int src_ofs = p_image->get_mipmap_offset(i); - squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); - dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift; - w >>= 1; - h >>= 1; - } + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_LA: { - rb = PoolVector<uint8_t>::Read(); - wb = PoolVector<uint8_t>::Write(); + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; + } break; + case Image::DETECTED_R: { - p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + target_format = Image::FORMAT_RGTC_R; + squish_comp |= squish::kBc4; + } break; + case Image::DETECTED_RG: { + + target_format = Image::FORMAT_RGTC_RG; + squish_comp |= squish::kBc5; + } break; + case Image::DETECTED_RGB: { + + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_RGBA: { + + //TODO, should convert both, then measure which one does a better job + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; + + } break; + } + + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; + data.resize(target_size); + int shift = Image::get_format_pixel_rshift(target_format); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + PoolVector<uint8_t>::Write wb = data.write(); + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + + int bw = w % 4 != 0 ? w + (4 - w % 4) : w; + int bh = h % 4 != 0 ? h + (4 - h % 4) : h; + + int src_ofs = p_image->get_mipmap_offset(i); + squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; + w >>= 1; + h >>= 1; + } + + rb = PoolVector<uint8_t>::Read(); + wb = PoolVector<uint8_t>::Write(); + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + } } diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 198889402a..68aaeefc30 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 */ @@ -31,6 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image); +void image_compress_squish(Image *p_image, Image::CompressSource p_source); +void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H diff --git a/modules/squish/register_types.cpp b/modules/squish/register_types.cpp index 995711c758..2eeea59836 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 */ @@ -35,6 +36,7 @@ void register_squish_types() { Image::set_compress_bc_func(image_compress_squish); + Image::_image_decompress_bc = image_decompress_squish; } void unregister_squish_types() {} 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 1c6e7e461d..7b8b2abebb 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 */ @@ -29,7 +30,8 @@ #include "audio_stream_ogg_vorbis.h" #include "os/file_access.h" -#include "thirdparty/stb_vorbis/stb_vorbis.c" + +#include "thirdparty/misc/stb_vorbis.c" void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { @@ -37,10 +39,11 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra int todo = p_frames; - while (todo) { + while (todo && active) { int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2); todo -= mixed; + frames_mixed += mixed; if (todo) { //end of file! @@ -65,8 +68,8 @@ float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { - seek_pos(p_from_pos); active = true; + seek_pos(p_from_pos); loops = 0; _begin_resample(); } @@ -94,7 +97,12 @@ void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) { if (!active) return; - stb_vorbis_seek(ogg_stream, uint32_t(p_time * vorbis_stream->sample_rate)); + if (p_time >= get_length()) { + p_time = 0; + } + frames_mixed = uint32_t(vorbis_stream->sample_rate * p_time); + + stb_vorbis_seek(ogg_stream, frames_mixed); } float AudioStreamPlaybackOGGVorbis::get_length() const { diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index c32b3e578d..46cdfd3f2d 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 */ @@ -33,7 +34,7 @@ #include "servers/audio/audio_stream.h" #define STB_VORBIS_HEADER_ONLY -#include "thirdparty/stb_vorbis/stb_vorbis.c" +#include "thirdparty/misc/stb_vorbis.c" #undef STB_VORBIS_HEADER_ONLY class AudioStreamOGGVorbis; @@ -76,7 +77,7 @@ class AudioStreamOGGVorbis : public AudioStream { GDCLASS(AudioStreamOGGVorbis, AudioStream) OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged - RES_BASE_EXTENSION("asogg"); + RES_BASE_EXTENSION("oggstr"); friend class AudioStreamPlaybackOGGVorbis; 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..f0a7ee1ec6 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 */ @@ -47,7 +48,7 @@ void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extens } String ResourceImporterOGGVorbis::get_save_extension() const { - return "asogg"; + return "oggstr"; } String ResourceImporterOGGVorbis::get_resource_type() const { @@ -98,7 +99,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); - return ResourceSaver::save(p_save_path + ".asogg", ogg_stream); + return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); } ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() { 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/tga/SCsub b/modules/tga/SCsub new file mode 100644 index 0000000000..7e405f405c --- /dev/null +++ b/modules/tga/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tga = env_modules.Clone() + +# Godot's own source files +env_tga.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/cscript/config.py b/modules/tga/config.py index 5698a37295..fb920482f5 100644 --- a/modules/cscript/config.py +++ b/modules/tga/config.py @@ -1,5 +1,4 @@ - def can_build(platform): return True diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp new file mode 100644 index 0000000000..5b8610b975 --- /dev/null +++ b/modules/tga/image_loader_tga.cpp @@ -0,0 +1,314 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 "image_loader_tga.h" + +#include "os/os.h" +#include "print_string.h" + +Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size) { + Error error; + + PoolVector<uint8_t> pixels; + error = pixels.resize(p_pixel_size); + if (error != OK) + return error; + + PoolVector<uint8_t>::Write pixels_w = pixels.write(); + + size_t compressed_pos = 0; + size_t output_pos = 0; + size_t c = 0; + size_t count = 0; + + while (output_pos < p_output_size) { + c = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + count = (c & 0x7f) + 1; + + if (c & 0x80) { + for (int i = 0; i < p_pixel_size; i++) { + pixels_w.ptr()[i] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < p_pixel_size; j++) { + p_uncompressed_buffer[output_pos + j] = pixels_w.ptr()[j]; + } + output_pos += p_pixel_size; + } + } else { + count *= p_pixel_size; + for (int i = 0; i < count; i++) { + p_uncompressed_buffer[output_pos] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + output_pos += 1; + } + } + } + return OK; +} + +Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { + +#define TGA_PUT_PIXEL(r, g, b, a) \ + int image_data_ofs = ((y * width) + x); \ + image_data_w[image_data_ofs * 4 + 0] = r; \ + image_data_w[image_data_ofs * 4 + 1] = g; \ + image_data_w[image_data_ofs * 4 + 2] = b; \ + image_data_w[image_data_ofs * 4 + 3] = a; + + uint32_t width = p_header.image_width; + uint32_t height = p_header.image_height; + tga_origin_e origin = static_cast<tga_origin_e>((p_header.image_descriptor & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT); + + uint32_t x_start; + int32_t x_step; + uint32_t x_end; + uint32_t y_start; + int32_t y_step; + uint32_t y_end; + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_TOP_RIGHT) { + y_start = 0; + y_step = 1; + y_end = height; + } else { + y_start = height - 1; + y_step = -1; + y_end = -1; + } + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_BOTTOM_LEFT) { + x_start = 0; + x_step = 1; + x_end = width; + } else { + x_start = width - 1; + x_step = -1; + x_end = -1; + } + + PoolVector<uint8_t> image_data; + image_data.resize(width * height * sizeof(uint32_t)); + PoolVector<uint8_t>::Write image_data_w = image_data.write(); + + size_t i = 0; + uint32_t x = x_start; + uint32_t y = y_start; + + if (p_header.pixel_depth == 8) { + if (p_is_monochrome) { + while (y != y_end) { + while (x != x_end) { + uint8_t shade = p_buffer[i]; + + TGA_PUT_PIXEL(shade, shade, shade, 0xff) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } else { + while (y != y_end) { + while (x != x_end) { + uint8_t index = p_buffer[i]; + uint8_t r = 0x00; + uint8_t g = 0x00; + uint8_t b = 0x00; + uint8_t a = 0xff; + + if (p_header.color_map_depth == 24) { + r = (p_palette[(index * 3) + 0]); + g = (p_palette[(index * 3) + 1]); + b = (p_palette[(index * 3) + 2]); + } else { + return ERR_INVALID_DATA; + } + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } + } else if (p_header.pixel_depth == 24) { + while (y != y_end) { + while (x != x_end) { + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, 0xff) + + x += x_step; + i += 3; + } + x = x_start; + y += y_step; + } + } else if (p_header.pixel_depth == 32) { + while (y != y_end) { + while (x != x_end) { + uint8_t a = p_buffer[i + 3]; + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 4; + } + x = x_start; + y += y_step; + } + } + + image_data_w = PoolVector<uint8_t>::Write(); + + p_image->create(width, height, 0, Image::FORMAT_RGBA8, image_data); + + return OK; +} + +Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(src_image_len < sizeof(tga_header_s), ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + Error err = OK; + + tga_header_s tga_header; + tga_header.id_length = f->get_8(); + tga_header.color_map_type = f->get_8(); + tga_header.image_type = static_cast<tga_type_e>(f->get_8()); + + tga_header.first_color_entry = f->get_16(); + tga_header.color_map_length = f->get_16(); + tga_header.color_map_depth = f->get_8(); + + tga_header.x_origin = f->get_16(); + tga_header.y_origin = f->get_16(); + tga_header.image_width = f->get_16(); + tga_header.image_height = f->get_16(); + tga_header.pixel_depth = f->get_8(); + tga_header.image_descriptor = f->get_8(); + + bool is_encoded = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_RLE_RGB || tga_header.image_type == TGA_TYPE_RLE_MONOCHROME); + bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED); + bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME); + + if (tga_header.image_type == TGA_TYPE_NO_DATA) + err = FAILED; + + if (has_color_map) { + if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) { + err = FAILED; + } + } else { + if (tga_header.color_map_type) { + err = FAILED; + } + } + + if (tga_header.image_width <= 0 || tga_header.image_height <= 0) + err = FAILED; + + if (tga_header.pixel_depth != 8 && tga_header.pixel_depth != 24 && tga_header.pixel_depth != 32) + err = FAILED; + + if (err == OK) { + f->seek(f->get_pos() + tga_header.id_length); + + PoolVector<uint8_t> palette; + + if (has_color_map) { + size_t color_map_size = tga_header.color_map_length * (tga_header.color_map_depth >> 3); + err = palette.resize(color_map_size); + if (err == OK) { + PoolVector<uint8_t>::Write palette_w = palette.write(); + f->get_buffer(&palette_w[0], color_map_size); + } else { + return OK; + } + } + + PoolVector<uint8_t>::Write src_image_w = src_image.write(); + f->get_buffer(&src_image_w[0], src_image_len - f->get_pos()); + + PoolVector<uint8_t>::Read src_image_r = src_image.read(); + + const size_t pixel_size = tga_header.pixel_depth >> 3; + const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; + + PoolVector<uint8_t> uncompressed_buffer; + uncompressed_buffer.resize(buffer_size); + PoolVector<uint8_t>::Write uncompressed_buffer_w = uncompressed_buffer.write(); + PoolVector<uint8_t>::Read uncompressed_buffer_r; + + const uint8_t *buffer = NULL; + + if (is_encoded) { + + err = decode_tga_rle(src_image_r.ptr(), pixel_size, uncompressed_buffer_w.ptr(), buffer_size); + + if (err == OK) { + uncompressed_buffer_r = uncompressed_buffer.read(); + buffer = uncompressed_buffer_r.ptr(); + } + } else { + buffer = src_image_r.ptr(); + }; + + if (err == OK) { + PoolVector<uint8_t>::Read palette_r = palette.read(); + err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome); + } + } + + f->close(); + return err; +} + +void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("tga"); +} + +ImageLoaderTGA::ImageLoaderTGA() { +} diff --git a/modules/tga/image_loader_tga.h b/modules/tga/image_loader_tga.h new file mode 100644 index 0000000000..11329ec68a --- /dev/null +++ b/modules/tga/image_loader_tga.h @@ -0,0 +1,83 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 IMAGE_LOADER_TGA_H +#define IMAGE_LOADER_TGA_H + +#include "io/image_loader.h" + +/** + @author SaracenOne +*/ +class ImageLoaderTGA : public ImageFormatLoader { + enum tga_type_e { + TGA_TYPE_NO_DATA = 0, + TGA_TYPE_INDEXED = 1, + TGA_TYPE_RGB = 2, + TGA_TYPE_MONOCHROME = 3, + TGA_TYPE_RLE_INDEXED = 9, + TGA_TYPE_RLE_RGB = 10, + TGA_TYPE_RLE_MONOCHROME = 11 + }; + + enum tga_origin_e { + TGA_ORIGIN_BOTTOM_LEFT = 0x00, + TGA_ORIGIN_BOTTOM_RIGHT = 0x01, + TGA_ORIGIN_TOP_LEFT = 0x02, + TGA_ORIGIN_TOP_RIGHT = 0x03, + TGA_ORIGIN_SHIFT = 0x04, + TGA_ORIGIN_MASK = 0x30 + }; + + struct tga_header_s { + uint8_t id_length; + uint8_t color_map_type; + tga_type_e image_type; + + uint16_t first_color_entry; + uint16_t color_map_length; + uint8_t color_map_depth; + + uint16_t x_origin; + uint16_t y_origin; + uint16_t image_width; + uint16_t image_height; + uint8_t pixel_depth; + uint8_t image_descriptor; + }; + static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size); + static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome); + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTGA(); +}; + +#endif diff --git a/modules/tga/register_types.cpp b/modules/tga/register_types.cpp new file mode 100644 index 0000000000..6e120fa3bf --- /dev/null +++ b/modules/tga/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* 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 "image_loader_tga.h" + +static ImageLoaderTGA *image_loader_tga = NULL; + +void register_tga_types() { + + image_loader_tga = memnew(ImageLoaderTGA); + ImageLoader::add_image_format_loader(image_loader_tga); +} + +void unregister_tga_types() { + + memdelete(image_loader_tga); +} diff --git a/modules/cscript/godot_c.cpp b/modules/tga/register_types.h index f754f2bb21..079b7bf291 100644 --- a/modules/cscript/godot_c.cpp +++ b/modules/tga/register_types.h @@ -1,11 +1,12 @@ /*************************************************************************/ -/* godot_c.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,4 +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 "godot_c.h" +void register_tga_types(); +void unregister_tga_types(); 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..977062dd14 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 */ @@ -28,9 +29,10 @@ /*************************************************************************/ #include "video_stream_theora.h" -#include "global_config.h" #include "os/os.h" -#include "yuv2rgb.h" +#include "project_settings.h" + +#include "thirdparty/misc/yuv2rgb.h" int VideoStreamPlaybackTheora::buffer_data() { @@ -136,7 +138,7 @@ void VideoStreamPlaybackTheora::video_write(void) { format = Image::FORMAT_RGBA8; } - Image img(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data); //zero copy image creation + Ref<Image> img = memnew(Image(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation texture->set_data(img); //zero copy send to visual server @@ -726,7 +728,7 @@ void VideoStreamPlaybackTheora::play() { } playing = true; - delay_compensation = GlobalConfig::get_singleton()->get("audio/video_delay_compensation_ms"); + delay_compensation = ProjectSettings::get_singleton()->get("audio/video_delay_compensation_ms"); delay_compensation /= 1000.0; }; 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/theora/yuv2rgb.h b/modules/theora/yuv2rgb.h deleted file mode 100644 index a9bef76da8..0000000000 --- a/modules/theora/yuv2rgb.h +++ /dev/null @@ -1,1123 +0,0 @@ -/* Thirdparty code presumably from http://wss.co.uk/pinknoise/yuv2rgb/ */ -/* FIXME: Move to thirdparty dir */ - -#ifndef YUV2RGB_H -#define YUV2RGB_H - -#include "typedefs.h" - -static const uint32_t tables[256*3] = { - /* y_table */ - 0x7FFFFFEDU, - 0x7FFFFFEFU, - 0x7FFFFFF0U, - 0x7FFFFFF1U, - 0x7FFFFFF2U, - 0x7FFFFFF3U, - 0x7FFFFFF4U, - 0x7FFFFFF6U, - 0x7FFFFFF7U, - 0x7FFFFFF8U, - 0x7FFFFFF9U, - 0x7FFFFFFAU, - 0x7FFFFFFBU, - 0x7FFFFFFDU, - 0x7FFFFFFEU, - 0x7FFFFFFFU, - 0x80000000U, - 0x80400801U, - 0x80A01002U, - 0x80E01803U, - 0x81202805U, - 0x81803006U, - 0x81C03807U, - 0x82004008U, - 0x82604809U, - 0x82A0500AU, - 0x82E0600CU, - 0x8340680DU, - 0x8380700EU, - 0x83C0780FU, - 0x84208010U, - 0x84608811U, - 0x84A09813U, - 0x8500A014U, - 0x8540A815U, - 0x8580B016U, - 0x85E0B817U, - 0x8620C018U, - 0x8660D01AU, - 0x86C0D81BU, - 0x8700E01CU, - 0x8740E81DU, - 0x87A0F01EU, - 0x87E0F81FU, - 0x88210821U, - 0x88811022U, - 0x88C11823U, - 0x89012024U, - 0x89412825U, - 0x89A13026U, - 0x89E14028U, - 0x8A214829U, - 0x8A81502AU, - 0x8AC1582BU, - 0x8B01602CU, - 0x8B61682DU, - 0x8BA1782FU, - 0x8BE18030U, - 0x8C418831U, - 0x8C819032U, - 0x8CC19833U, - 0x8D21A034U, - 0x8D61B036U, - 0x8DA1B837U, - 0x8E01C038U, - 0x8E41C839U, - 0x8E81D03AU, - 0x8EE1D83BU, - 0x8F21E83DU, - 0x8F61F03EU, - 0x8FC1F83FU, - 0x90020040U, - 0x90420841U, - 0x90A21042U, - 0x90E22044U, - 0x91222845U, - 0x91823046U, - 0x91C23847U, - 0x92024048U, - 0x92624849U, - 0x92A2504AU, - 0x92E2604CU, - 0x9342684DU, - 0x9382704EU, - 0x93C2784FU, - 0x94228050U, - 0x94628851U, - 0x94A29853U, - 0x9502A054U, - 0x9542A855U, - 0x9582B056U, - 0x95E2B857U, - 0x9622C058U, - 0x9662D05AU, - 0x96C2D85BU, - 0x9702E05CU, - 0x9742E85DU, - 0x97A2F05EU, - 0x97E2F85FU, - 0x98230861U, - 0x98831062U, - 0x98C31863U, - 0x99032064U, - 0x99632865U, - 0x99A33066U, - 0x99E34068U, - 0x9A434869U, - 0x9A83506AU, - 0x9AC3586BU, - 0x9B23606CU, - 0x9B63686DU, - 0x9BA3786FU, - 0x9BE38070U, - 0x9C438871U, - 0x9C839072U, - 0x9CC39873U, - 0x9D23A074U, - 0x9D63B076U, - 0x9DA3B877U, - 0x9E03C078U, - 0x9E43C879U, - 0x9E83D07AU, - 0x9EE3D87BU, - 0x9F23E87DU, - 0x9F63F07EU, - 0x9FC3F87FU, - 0xA0040080U, - 0xA0440881U, - 0xA0A41082U, - 0xA0E42084U, - 0xA1242885U, - 0xA1843086U, - 0xA1C43887U, - 0xA2044088U, - 0xA2644889U, - 0xA2A4588BU, - 0xA2E4608CU, - 0xA344688DU, - 0xA384708EU, - 0xA3C4788FU, - 0xA4248090U, - 0xA4649092U, - 0xA4A49893U, - 0xA504A094U, - 0xA544A895U, - 0xA584B096U, - 0xA5E4B897U, - 0xA624C098U, - 0xA664D09AU, - 0xA6C4D89BU, - 0xA704E09CU, - 0xA744E89DU, - 0xA7A4F09EU, - 0xA7E4F89FU, - 0xA82508A1U, - 0xA88510A2U, - 0xA8C518A3U, - 0xA90520A4U, - 0xA96528A5U, - 0xA9A530A6U, - 0xA9E540A8U, - 0xAA4548A9U, - 0xAA8550AAU, - 0xAAC558ABU, - 0xAB2560ACU, - 0xAB6568ADU, - 0xABA578AFU, - 0xAC0580B0U, - 0xAC4588B1U, - 0xAC8590B2U, - 0xACE598B3U, - 0xAD25A0B4U, - 0xAD65B0B6U, - 0xADA5B8B7U, - 0xAE05C0B8U, - 0xAE45C8B9U, - 0xAE85D0BAU, - 0xAEE5D8BBU, - 0xAF25E8BDU, - 0xAF65F0BEU, - 0xAFC5F8BFU, - 0xB00600C0U, - 0xB04608C1U, - 0xB0A610C2U, - 0xB0E620C4U, - 0xB12628C5U, - 0xB18630C6U, - 0xB1C638C7U, - 0xB20640C8U, - 0xB26648C9U, - 0xB2A658CBU, - 0xB2E660CCU, - 0xB34668CDU, - 0xB38670CEU, - 0xB3C678CFU, - 0xB42680D0U, - 0xB46690D2U, - 0xB4A698D3U, - 0xB506A0D4U, - 0xB546A8D5U, - 0xB586B0D6U, - 0xB5E6B8D7U, - 0xB626C8D9U, - 0xB666D0DAU, - 0xB6C6D8DBU, - 0xB706E0DCU, - 0xB746E8DDU, - 0xB7A6F0DEU, - 0xB7E6F8DFU, - 0xB82708E1U, - 0xB88710E2U, - 0xB8C718E3U, - 0xB90720E4U, - 0xB96728E5U, - 0xB9A730E6U, - 0xB9E740E8U, - 0xBA4748E9U, - 0xBA8750EAU, - 0xBAC758EBU, - 0xBB2760ECU, - 0xBB6768EDU, - 0xBBA778EFU, - 0xBC0780F0U, - 0xBC4788F1U, - 0xBC8790F2U, - 0xBCE798F3U, - 0xBD27A0F4U, - 0xBD67B0F6U, - 0xBDC7B8F7U, - 0xBE07C0F8U, - 0xBE47C8F9U, - 0xBEA7D0FAU, - 0xBEE7D8FBU, - 0xBF27E8FDU, - 0xBF87F0FEU, - 0xBFC7F8FFU, - 0xC0080100U, - 0xC0480901U, - 0xC0A81102U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - /* u_table */ - 0x0C400103U, - 0x0C200105U, - 0x0C200107U, - 0x0C000109U, - 0x0BE0010BU, - 0x0BC0010DU, - 0x0BA0010FU, - 0x0BA00111U, - 0x0B800113U, - 0x0B600115U, - 0x0B400117U, - 0x0B400119U, - 0x0B20011BU, - 0x0B00011DU, - 0x0AE0011FU, - 0x0AE00121U, - 0x0AC00123U, - 0x0AA00125U, - 0x0A800127U, - 0x0A600129U, - 0x0A60012BU, - 0x0A40012DU, - 0x0A20012FU, - 0x0A000131U, - 0x0A000132U, - 0x09E00134U, - 0x09C00136U, - 0x09A00138U, - 0x09A0013AU, - 0x0980013CU, - 0x0960013EU, - 0x09400140U, - 0x09400142U, - 0x09200144U, - 0x09000146U, - 0x08E00148U, - 0x08C0014AU, - 0x08C0014CU, - 0x08A0014EU, - 0x08800150U, - 0x08600152U, - 0x08600154U, - 0x08400156U, - 0x08200158U, - 0x0800015AU, - 0x0800015CU, - 0x07E0015EU, - 0x07C00160U, - 0x07A00162U, - 0x07A00164U, - 0x07800166U, - 0x07600168U, - 0x0740016AU, - 0x0720016CU, - 0x0720016EU, - 0x07000170U, - 0x06E00172U, - 0x06C00174U, - 0x06C00176U, - 0x06A00178U, - 0x0680017AU, - 0x0660017CU, - 0x0660017EU, - 0x06400180U, - 0x06200182U, - 0x06000184U, - 0x05E00185U, - 0x05E00187U, - 0x05C00189U, - 0x05A0018BU, - 0x0580018DU, - 0x0580018FU, - 0x05600191U, - 0x05400193U, - 0x05200195U, - 0x05200197U, - 0x05000199U, - 0x04E0019BU, - 0x04C0019DU, - 0x04C0019FU, - 0x04A001A1U, - 0x048001A3U, - 0x046001A5U, - 0x044001A7U, - 0x044001A9U, - 0x042001ABU, - 0x040001ADU, - 0x03E001AFU, - 0x03E001B1U, - 0x03C001B3U, - 0x03A001B5U, - 0x038001B7U, - 0x038001B9U, - 0x036001BBU, - 0x034001BDU, - 0x032001BFU, - 0x032001C1U, - 0x030001C3U, - 0x02E001C5U, - 0x02C001C7U, - 0x02A001C9U, - 0x02A001CBU, - 0x028001CDU, - 0x026001CFU, - 0x024001D1U, - 0x024001D3U, - 0x022001D5U, - 0x020001D7U, - 0x01E001D8U, - 0x01E001DAU, - 0x01C001DCU, - 0x01A001DEU, - 0x018001E0U, - 0x016001E2U, - 0x016001E4U, - 0x014001E6U, - 0x012001E8U, - 0x010001EAU, - 0x010001ECU, - 0x00E001EEU, - 0x00C001F0U, - 0x00A001F2U, - 0x00A001F4U, - 0x008001F6U, - 0x006001F8U, - 0x004001FAU, - 0x004001FCU, - 0x002001FEU, - 0x00000200U, - 0xFFE00202U, - 0xFFC00204U, - 0xFFC00206U, - 0xFFA00208U, - 0xFF80020AU, - 0xFF60020CU, - 0xFF60020EU, - 0xFF400210U, - 0xFF200212U, - 0xFF000214U, - 0xFF000216U, - 0xFEE00218U, - 0xFEC0021AU, - 0xFEA0021CU, - 0xFEA0021EU, - 0xFE800220U, - 0xFE600222U, - 0xFE400224U, - 0xFE200226U, - 0xFE200228U, - 0xFE000229U, - 0xFDE0022BU, - 0xFDC0022DU, - 0xFDC0022FU, - 0xFDA00231U, - 0xFD800233U, - 0xFD600235U, - 0xFD600237U, - 0xFD400239U, - 0xFD20023BU, - 0xFD00023DU, - 0xFCE0023FU, - 0xFCE00241U, - 0xFCC00243U, - 0xFCA00245U, - 0xFC800247U, - 0xFC800249U, - 0xFC60024BU, - 0xFC40024DU, - 0xFC20024FU, - 0xFC200251U, - 0xFC000253U, - 0xFBE00255U, - 0xFBC00257U, - 0xFBC00259U, - 0xFBA0025BU, - 0xFB80025DU, - 0xFB60025FU, - 0xFB400261U, - 0xFB400263U, - 0xFB200265U, - 0xFB000267U, - 0xFAE00269U, - 0xFAE0026BU, - 0xFAC0026DU, - 0xFAA0026FU, - 0xFA800271U, - 0xFA800273U, - 0xFA600275U, - 0xFA400277U, - 0xFA200279U, - 0xFA20027BU, - 0xFA00027CU, - 0xF9E0027EU, - 0xF9C00280U, - 0xF9A00282U, - 0xF9A00284U, - 0xF9800286U, - 0xF9600288U, - 0xF940028AU, - 0xF940028CU, - 0xF920028EU, - 0xF9000290U, - 0xF8E00292U, - 0xF8E00294U, - 0xF8C00296U, - 0xF8A00298U, - 0xF880029AU, - 0xF860029CU, - 0xF860029EU, - 0xF84002A0U, - 0xF82002A2U, - 0xF80002A4U, - 0xF80002A6U, - 0xF7E002A8U, - 0xF7C002AAU, - 0xF7A002ACU, - 0xF7A002AEU, - 0xF78002B0U, - 0xF76002B2U, - 0xF74002B4U, - 0xF74002B6U, - 0xF72002B8U, - 0xF70002BAU, - 0xF6E002BCU, - 0xF6C002BEU, - 0xF6C002C0U, - 0xF6A002C2U, - 0xF68002C4U, - 0xF66002C6U, - 0xF66002C8U, - 0xF64002CAU, - 0xF62002CCU, - 0xF60002CEU, - 0xF60002CFU, - 0xF5E002D1U, - 0xF5C002D3U, - 0xF5A002D5U, - 0xF5A002D7U, - 0xF58002D9U, - 0xF56002DBU, - 0xF54002DDU, - 0xF52002DFU, - 0xF52002E1U, - 0xF50002E3U, - 0xF4E002E5U, - 0xF4C002E7U, - 0xF4C002E9U, - 0xF4A002EBU, - 0xF48002EDU, - 0xF46002EFU, - 0xF46002F1U, - 0xF44002F3U, - 0xF42002F5U, - 0xF40002F7U, - 0xF3E002F9U, - 0xF3E002FBU, - /* v_table */ - 0x1A09A000U, - 0x19E9A800U, - 0x19A9B800U, - 0x1969C800U, - 0x1949D000U, - 0x1909E000U, - 0x18C9E800U, - 0x18A9F800U, - 0x186A0000U, - 0x182A1000U, - 0x180A2000U, - 0x17CA2800U, - 0x17AA3800U, - 0x176A4000U, - 0x172A5000U, - 0x170A6000U, - 0x16CA6800U, - 0x168A7800U, - 0x166A8000U, - 0x162A9000U, - 0x160AA000U, - 0x15CAA800U, - 0x158AB800U, - 0x156AC000U, - 0x152AD000U, - 0x14EAE000U, - 0x14CAE800U, - 0x148AF800U, - 0x146B0000U, - 0x142B1000U, - 0x13EB2000U, - 0x13CB2800U, - 0x138B3800U, - 0x134B4000U, - 0x132B5000U, - 0x12EB6000U, - 0x12CB6800U, - 0x128B7800U, - 0x124B8000U, - 0x122B9000U, - 0x11EBA000U, - 0x11ABA800U, - 0x118BB800U, - 0x114BC000U, - 0x112BD000U, - 0x10EBE000U, - 0x10ABE800U, - 0x108BF800U, - 0x104C0000U, - 0x100C1000U, - 0x0FEC2000U, - 0x0FAC2800U, - 0x0F8C3800U, - 0x0F4C4000U, - 0x0F0C5000U, - 0x0EEC5800U, - 0x0EAC6800U, - 0x0E6C7800U, - 0x0E4C8000U, - 0x0E0C9000U, - 0x0DEC9800U, - 0x0DACA800U, - 0x0D6CB800U, - 0x0D4CC000U, - 0x0D0CD000U, - 0x0CCCD800U, - 0x0CACE800U, - 0x0C6CF800U, - 0x0C4D0000U, - 0x0C0D1000U, - 0x0BCD1800U, - 0x0BAD2800U, - 0x0B6D3800U, - 0x0B2D4000U, - 0x0B0D5000U, - 0x0ACD5800U, - 0x0AAD6800U, - 0x0A6D7800U, - 0x0A2D8000U, - 0x0A0D9000U, - 0x09CD9800U, - 0x098DA800U, - 0x096DB800U, - 0x092DC000U, - 0x090DD000U, - 0x08CDD800U, - 0x088DE800U, - 0x086DF800U, - 0x082E0000U, - 0x07EE1000U, - 0x07CE1800U, - 0x078E2800U, - 0x076E3800U, - 0x072E4000U, - 0x06EE5000U, - 0x06CE5800U, - 0x068E6800U, - 0x064E7800U, - 0x062E8000U, - 0x05EE9000U, - 0x05CE9800U, - 0x058EA800U, - 0x054EB800U, - 0x052EC000U, - 0x04EED000U, - 0x04AED800U, - 0x048EE800U, - 0x044EF000U, - 0x042F0000U, - 0x03EF1000U, - 0x03AF1800U, - 0x038F2800U, - 0x034F3000U, - 0x030F4000U, - 0x02EF5000U, - 0x02AF5800U, - 0x028F6800U, - 0x024F7000U, - 0x020F8000U, - 0x01EF9000U, - 0x01AF9800U, - 0x016FA800U, - 0x014FB000U, - 0x010FC000U, - 0x00EFD000U, - 0x00AFD800U, - 0x006FE800U, - 0x004FF000U, - 0x00100000U, - 0xFFD01000U, - 0xFFB01800U, - 0xFF702800U, - 0xFF303000U, - 0xFF104000U, - 0xFED05000U, - 0xFEB05800U, - 0xFE706800U, - 0xFE307000U, - 0xFE108000U, - 0xFDD09000U, - 0xFD909800U, - 0xFD70A800U, - 0xFD30B000U, - 0xFD10C000U, - 0xFCD0D000U, - 0xFC90D800U, - 0xFC70E800U, - 0xFC30F000U, - 0xFBF10000U, - 0xFBD11000U, - 0xFB911800U, - 0xFB712800U, - 0xFB313000U, - 0xFAF14000U, - 0xFAD14800U, - 0xFA915800U, - 0xFA516800U, - 0xFA317000U, - 0xF9F18000U, - 0xF9D18800U, - 0xF9919800U, - 0xF951A800U, - 0xF931B000U, - 0xF8F1C000U, - 0xF8B1C800U, - 0xF891D800U, - 0xF851E800U, - 0xF831F000U, - 0xF7F20000U, - 0xF7B20800U, - 0xF7921800U, - 0xF7522800U, - 0xF7123000U, - 0xF6F24000U, - 0xF6B24800U, - 0xF6925800U, - 0xF6526800U, - 0xF6127000U, - 0xF5F28000U, - 0xF5B28800U, - 0xF5729800U, - 0xF552A800U, - 0xF512B000U, - 0xF4F2C000U, - 0xF4B2C800U, - 0xF472D800U, - 0xF452E800U, - 0xF412F000U, - 0xF3D30000U, - 0xF3B30800U, - 0xF3731800U, - 0xF3532800U, - 0xF3133000U, - 0xF2D34000U, - 0xF2B34800U, - 0xF2735800U, - 0xF2336800U, - 0xF2137000U, - 0xF1D38000U, - 0xF1B38800U, - 0xF1739800U, - 0xF133A800U, - 0xF113B000U, - 0xF0D3C000U, - 0xF093C800U, - 0xF073D800U, - 0xF033E000U, - 0xF013F000U, - 0xEFD40000U, - 0xEF940800U, - 0xEF741800U, - 0xEF342000U, - 0xEEF43000U, - 0xEED44000U, - 0xEE944800U, - 0xEE745800U, - 0xEE346000U, - 0xEDF47000U, - 0xEDD48000U, - 0xED948800U, - 0xED549800U, - 0xED34A000U, - 0xECF4B000U, - 0xECD4C000U, - 0xEC94C800U, - 0xEC54D800U, - 0xEC34E000U, - 0xEBF4F000U, - 0xEBB50000U, - 0xEB950800U, - 0xEB551800U, - 0xEB352000U, - 0xEAF53000U, - 0xEAB54000U, - 0xEA954800U, - 0xEA555800U, - 0xEA156000U, - 0xE9F57000U, - 0xE9B58000U, - 0xE9958800U, - 0xE9559800U, - 0xE915A000U, - 0xE8F5B000U, - 0xE8B5C000U, - 0xE875C800U, - 0xE855D800U, - 0xE815E000U, - 0xE7F5F000U, - 0xE7B60000U, - 0xE7760800U, - 0xE7561800U, - 0xE7162000U, - 0xE6D63000U, - 0xE6B64000U, - 0xE6764800U, - 0xE6365800U -}; - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ - *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ -} while (0 == 1) - -static void yuv422_2_rgb8888(uint8_t *dst_ptr, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do top row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y0); - FIXUP(y1); - STORE(y0, dst_ptr); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing top row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr,*v_ptr); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 1; - if (height == 0) - break; - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do second row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y0); - FIXUP(y1); - STORE(y0, dst_ptr); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing bottom row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr,*v_ptr); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 1; - } -} - - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - (DSTPTR) = 0xFF000000 | (Y & 0xFF) | (0xFF00 & (Y>>14)) | (0xFF0000 & (Y<<5));\ -} while (0 == 1) - -static void yuv420_2_rgb8888(uint8_t *dst_ptr_, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - uint32_t *dst_ptr = (uint32_t *)(void *)dst_ptr_; - dst_span >>= 2; - - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do 2 column pairs */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing column pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr,*v_ptr); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y0, dst_ptr[dst_span]); - STORE(y1, *dst_ptr++); - } - dst_ptr += dst_span*2-width; - y_ptr += y_span*2-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 2; - } - if (height == 0) - { - /* Trail row */ - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do a row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, *dst_ptr++); - STORE(y0, *dst_ptr++); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, *dst_ptr++); - } - } -} - - - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ - *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ -} while (0 == 1) - -static void yuv444_2_rgb8888(uint8_t *dst_ptr, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do top row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y1); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing top row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-width; - v_ptr += uv_span-width; - height = (height<<16)>>16; - height -= 1; - if (height == 0) - break; - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do second row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y1); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing bottom row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-width; - v_ptr += uv_span-width; - height = (height<<16)>>16; - height -= 1; - } -} -#endif // YUV2RGB_H diff --git a/modules/tinyexr/SCsub b/modules/tinyexr/SCsub new file mode 100644 index 0000000000..38fd00cc65 --- /dev/null +++ b/modules/tinyexr/SCsub @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tinyexr = env_modules.Clone() + +# Thirdparty source files +# Not unbundled for now as they are not commonly available as shared library +thirdparty_dir = "#thirdparty/tinyexr/" +thirdparty_sources = [ + "tinyexr.cc", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_tinyexr.add_source_files(env.modules_sources, thirdparty_sources) +env_tinyexr.Append(CPPPATH=[thirdparty_dir]) + +# Godot's own source files +env_tinyexr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tinyexr/config.py b/modules/tinyexr/config.py new file mode 100644 index 0000000000..2e4b96a6b0 --- /dev/null +++ b/modules/tinyexr/config.py @@ -0,0 +1,11 @@ + +def can_build(platform): + return True + + +def configure(env): + # Tools only, disabled for non-tools + # TODO: Find a cleaner way to achieve that + if (env["tools"] == "no"): + env["module_tinyexr_enabled"] = "no" + env.disabled_modules.append("tinyexr") diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp new file mode 100644 index 0000000000..4eb91da10b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -0,0 +1,168 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 "image_loader_tinyexr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + PoolVector<uint8_t>::Write w = src_image.write(); + + f->get_buffer(&w[0], src_image_len); + + f->close(); + + EXRVersion exr_version; + EXRImage exr_image; + EXRHeader exr_header; + const char *err = NULL; + + InitEXRHeader(&exr_header); + + int ret = ParseEXRVersionFromMemory(&exr_version, w.ptr(), src_image_len); + if (ret != TINYEXR_SUCCESS) { + + return ERR_FILE_CORRUPT; + } + + ret = ParseEXRHeaderFromMemory(&exr_header, &exr_version, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + InitEXRImage(&exr_image); + ret = LoadEXRImageFromMemory(&exr_image, &exr_header, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + // RGBA + int idxR = -1; + int idxG = -1; + int idxB = -1; + int idxA = -1; + for (int c = 0; c < exr_header.num_channels; c++) { + if (strcmp(exr_header.channels[c].name, "R") == 0) { + idxR = c; + } else if (strcmp(exr_header.channels[c].name, "G") == 0) { + idxG = c; + } else if (strcmp(exr_header.channels[c].name, "B") == 0) { + idxB = c; + } else if (strcmp(exr_header.channels[c].name, "A") == 0) { + idxA = c; + } + } + + if (idxR == -1) { + ERR_PRINT("R channel not found"); + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxG == -1) { + ERR_PRINT("G channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxB == -1) { + ERR_PRINT("B channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + PoolVector<uint8_t> imgdata; + Image::Format format; + + if (idxA > 0) { + + imgdata.resize(exr_image.width * exr_image.height * 8); //RGBA16 + format = Image::FORMAT_RGBAH; + } else { + + imgdata.resize(exr_image.width * exr_image.height * 6); //RGB16 + format = Image::FORMAT_RGBH; + } + + { + + PoolVector<uint8_t>::Write wd = imgdata.write(); + uint16_t *iw = (uint16_t *)wd.ptr(); + + // Assume `out_rgba` have enough memory allocated. + for (int i = 0; i < exr_image.width * exr_image.height; i++) { + + Color color( + reinterpret_cast<float **>(exr_image.images)[idxR][i], + reinterpret_cast<float **>(exr_image.images)[idxG][i], + reinterpret_cast<float **>(exr_image.images)[idxB][i]); + + if (p_force_linear) + color = color.to_linear(); + + *iw++ = Math::make_half_float(color.r); + *iw++ = Math::make_half_float(color.g); + *iw++ = Math::make_half_float(color.b); + + if (idxA > 0) { + *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxA][i]); + } + } + } + + print_line("EXR w: " + itos(exr_image.width) + " h:" + itos(exr_image.height) + " format " + Image::get_format_name(format)); + p_image->create(exr_image.width, exr_image.height, false, format, imgdata); + + w = PoolVector<uint8_t>::Write(); + + return OK; +} + +void ImageLoaderTinyEXR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("exr"); +} + +ImageLoaderTinyEXR::ImageLoaderTinyEXR() { +} diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h new file mode 100644 index 0000000000..a52894b12b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.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 IMAGE_LOADER_TINYEXR_H +#define IMAGE_LOADER_TINYEXR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderTinyEXR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTinyEXR(); +}; + +#endif diff --git a/modules/tinyexr/register_types.cpp b/modules/tinyexr/register_types.cpp new file mode 100644 index 0000000000..73f3131276 --- /dev/null +++ b/modules/tinyexr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* 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 "image_loader_tinyexr.h" + +static ImageLoaderTinyEXR *image_loader_tinyexr = NULL; + +void register_tinyexr_types() { + + image_loader_tinyexr = memnew(ImageLoaderTinyEXR); + ImageLoader::add_image_format_loader(image_loader_tinyexr); +} + +void unregister_tinyexr_types() { + + memdelete(image_loader_tinyexr); +} diff --git a/modules/tinyexr/register_types.h b/modules/tinyexr/register_types.h new file mode 100644 index 0000000000..f3c7372359 --- /dev/null +++ b/modules/tinyexr/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* 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 */ +/* "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. */ +/*************************************************************************/ +void register_tinyexr_types(); +void unregister_tinyexr_types(); diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index b05ea716ed..a54d306aff 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 */ @@ -87,8 +88,9 @@ void register_visual_script_types() { ClassDB::register_class<VisualScriptWhile>(); ClassDB::register_class<VisualScriptIterator>(); ClassDB::register_class<VisualScriptSequence>(); - ClassDB::register_class<VisualScriptInputFilter>(); + //ClassDB::register_class<VisualScriptInputFilter>(); ClassDB::register_class<VisualScriptSwitch>(); + ClassDB::register_class<VisualScriptSelect>(); ClassDB::register_class<VisualScriptYield>(); ClassDB::register_class<VisualScriptYieldSignal>(); 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 610309afca..d1cf0f1dce 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 */ @@ -28,8 +29,8 @@ /*************************************************************************/ #include "visual_script.h" -#include "global_config.h" #include "os/os.h" +#include "project_settings.h" #include "scene/main/node.h" #include "visual_script_nodes.h" @@ -121,9 +122,9 @@ Array VisualScriptNode::_get_default_input_values() const { void VisualScriptNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_visual_script:VisualScript"), &VisualScriptNode::get_visual_script); - ClassDB::bind_method(D_METHOD("set_default_input_value", "port_idx", "value:Variant"), &VisualScriptNode::set_default_input_value); - ClassDB::bind_method(D_METHOD("get_default_input_value:Variant", "port_idx"), &VisualScriptNode::get_default_input_value); + ClassDB::bind_method(D_METHOD("get_visual_script"), &VisualScriptNode::get_visual_script); + ClassDB::bind_method(D_METHOD("set_default_input_value", "port_idx", "value"), &VisualScriptNode::set_default_input_value); + ClassDB::bind_method(D_METHOD("get_default_input_value", "port_idx"), &VisualScriptNode::get_default_input_value); ClassDB::bind_method(D_METHOD("_set_default_input_values", "values"), &VisualScriptNode::_set_default_input_values); ClassDB::bind_method(D_METHOD("_get_default_input_values"), &VisualScriptNode::_get_default_input_values); @@ -139,7 +140,7 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp tg.type = pinfo.type; if (pinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) { - tg.GDCLASS = pinfo.hint_string; + tg.gdclass = pinfo.hint_string; } return tg; @@ -659,6 +660,9 @@ void VisualScript::set_variable_export(const StringName &p_name, bool p_export) ERR_FAIL_COND(!variables.has(p_name)); variables[p_name]._export = p_export; +#ifdef TOOLS_ENABLED + _update_placeholders(); +#endif } bool VisualScript::get_variable_export(const StringName &p_name) const { @@ -1054,6 +1058,10 @@ MethodInfo VisualScript::get_method_info(const StringName &p_method) const { arg.type = func->get_argument_type(i); mi.arguments.push_back(arg); } + + if (!func->is_sequenced()) { + mi.flags |= METHOD_FLAG_CONST; + } } } @@ -1066,12 +1074,26 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { get_variable_list(&vars); for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (!variables[E->get()]._export) - continue; - p_list->push_back(variables[E->get()].info); + //if (!variables[E->get()]._export) + // continue; + PropertyInfo pi = variables[E->get()].info; + pi.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; + p_list->push_back(pi); } } +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 { @@ -1246,8 +1268,8 @@ void VisualScript::_bind_methods() { ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function); ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function); ClassDB::bind_method(D_METHOD("rename_function", "name", "new_name"), &VisualScript::rename_function); - ClassDB::bind_method(D_METHOD("set_function_scroll", "ofs"), &VisualScript::set_function_scroll); - ClassDB::bind_method(D_METHOD("get_function_scroll"), &VisualScript::get_function_scroll); + ClassDB::bind_method(D_METHOD("set_function_scroll", "name", "ofs"), &VisualScript::set_function_scroll); + ClassDB::bind_method(D_METHOD("get_function_scroll", "name"), &VisualScript::get_function_scroll); ClassDB::bind_method(D_METHOD("add_node", "func", "id", "node", "pos"), &VisualScript::add_node, DEFVAL(Point2())); ClassDB::bind_method(D_METHOD("remove_node", "func", "id"), &VisualScript::remove_node); @@ -1284,7 +1306,7 @@ void VisualScript::_bind_methods() { ClassDB::bind_method(D_METHOD("custom_signal_get_argument_type", "name", "argidx"), &VisualScript::custom_signal_get_argument_type); ClassDB::bind_method(D_METHOD("custom_signal_set_argument_name", "name", "argidx", "argname"), &VisualScript::custom_signal_set_argument_name); ClassDB::bind_method(D_METHOD("custom_signal_get_argument_name", "name", "argidx"), &VisualScript::custom_signal_get_argument_name); - ClassDB::bind_method(D_METHOD("custom_signal_remove_argument", "argidx"), &VisualScript::custom_signal_remove_argument); + ClassDB::bind_method(D_METHOD("custom_signal_remove_argument", "name", "argidx"), &VisualScript::custom_signal_remove_argument); ClassDB::bind_method(D_METHOD("custom_signal_get_argument_count", "name"), &VisualScript::custom_signal_get_argument_count); ClassDB::bind_method(D_METHOD("custom_signal_swap_argument", "name", "argidx", "withidx"), &VisualScript::custom_signal_swap_argument); ClassDB::bind_method(D_METHOD("remove_custom_signal", "name"), &VisualScript::remove_custom_signal); @@ -1345,6 +1367,7 @@ void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c continue; PropertyInfo p = E->get().info; p.name = String(E->key()); + p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; p_properties->push_back(p); } } @@ -1382,6 +1405,10 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { mi.arguments.push_back(arg); } + if (!vsf->is_sequenced()) { //assumed constant if not sequenced + mi.flags |= METHOD_FLAG_CONST; + } + //vsf->Get_ for now at least it does not return.. } } @@ -1588,8 +1615,8 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } //step 1, capture all state - state->instance_id = get_owner_ptr()->get_instance_ID(); - state->script_id = get_script()->get_instance_ID(); + state->instance_id = get_owner_ptr()->get_instance_id(); + state->script_id = get_script()->get_instance_id(); state->instance = this; state->function = p_method; state->working_mem_index = node->working_mem_idx; @@ -2299,7 +2326,7 @@ Variant VisualScriptFunctionState::resume(Array p_args) { void VisualScriptFunctionState::_bind_methods() { ClassDB::bind_method(D_METHOD("connect_to_signal", "obj", "signals", "args"), &VisualScriptFunctionState::connect_to_signal); - ClassDB::bind_method(D_METHOD("resume:Array", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("is_valid"), &VisualScriptFunctionState::is_valid); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &VisualScriptFunctionState::_signal_callback, MethodInfo("_signal_callback")); } @@ -2356,6 +2383,17 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const script->set_instance_base_type(p_base_class_name); return script; } + +bool VisualScriptLanguage::is_using_templates() { + + return true; +} + +void VisualScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { + Ref<VisualScript> script = p_script; + script->set_instance_base_type(p_base_class_name); +} + bool VisualScriptLanguage::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; @@ -2387,7 +2425,7 @@ void VisualScriptLanguage::add_global_constant(const StringName &p_variable, con bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, const String &p_error) { //break because of parse error - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; @@ -2401,7 +2439,7 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_node = -1; _debug_parse_err_file = ""; @@ -2628,7 +2666,7 @@ VisualScriptLanguage::VisualScriptLanguage() { _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_call_stack_pos = 0; - int dmcs = GLOBAL_DEF("debug/script/max_call_stack", 1024); + int dmcs = GLOBAL_DEF("debug/settings/visual_script/max_call_stack", 1024); if (ScriptDebugger::get_singleton()) { //debugging enabled! _debug_max_call_stack = dmcs; diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index e3af3f4a1b..b61b67a890 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 */ @@ -88,13 +89,11 @@ public: struct TypeGuess { Variant::Type type; - InputEvent::Type ev_type; - StringName GDCLASS; + StringName gdclass; Ref<Script> script; TypeGuess() { type = Variant::NIL; - ev_type = InputEvent::NONE; } }; @@ -292,8 +291,8 @@ public: void data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port); bool has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const; void get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const; - bool is_input_value_port_connected(const StringName &p_name, int p_node, int p_port) const; - bool get_input_value_port_connection_source(const StringName &p_name, int p_node, int p_port, int *r_node, int *r_port) const; + bool is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const; + bool get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const; void add_variable(const StringName &p_name, const Variant &p_default_value = Variant(), bool p_export = false); bool has_variable(const StringName &p_name) const; @@ -355,6 +354,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 @@ -508,7 +509,7 @@ public: _FORCE_INLINE_ void enter_function(VisualScriptInstance *p_instance, const StringName *p_function, Variant *p_stack, Variant **p_work_mem, int *current_id) { - if (Thread::get_main_ID() != Thread::get_caller_ID()) + if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) @@ -531,7 +532,7 @@ public: _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_ID() != Thread::get_caller_ID()) + if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) @@ -563,11 +564,14 @@ public: 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 is_using_templates(); + virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); 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 open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { 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); 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..0f6b47c56d 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 */ @@ -51,11 +52,13 @@ public: protected: static void _bind_methods() { ClassDB::bind_method("_sig_changed", &VisualScriptEditorSignalEdit::_sig_changed); + ADD_SIGNAL(MethodInfo("changed")); } void _sig_changed() { _change_notify(); + emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { @@ -190,15 +193,18 @@ protected: static void _bind_methods() { ClassDB::bind_method("_var_changed", &VisualScriptEditorVariableEdit::_var_changed); ClassDB::bind_method("_var_value_changed", &VisualScriptEditorVariableEdit::_var_value_changed); + ADD_SIGNAL(MethodInfo("changed")); } void _var_changed() { _change_notify(); + emit_signal("changed"); } void _var_value_changed() { _change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general + emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { @@ -260,6 +266,7 @@ protected: if (String(p_name) == "export") { script->set_variable_export(var, p_value); + EditorNode::get_singleton()->get_property_editor()->update_tree(); return true; } @@ -345,11 +352,9 @@ static Color _color_from_type(Variant::Type p_type) { case Variant::TRANSFORM: color = Color::html("f6a86e"); break; case Variant::COLOR: color = Color::html("9dff70"); break; - case Variant::IMAGE: color = Color::html("93f1b9"); break; case Variant::NODE_PATH: color = Color::html("6993ec"); break; case Variant::_RID: color = Color::html("69ec9a"); break; case Variant::OBJECT: color = Color::html("79f3e8"); break; - case Variant::INPUT_EVENT: color = Color::html("adf18f"); break; case Variant::DICTIONARY: color = Color::html("77edb1"); break; case Variant::ARRAY: color = Color::html("e0e0e0"); break; @@ -450,11 +455,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { Control::get_icon("MiniBasis", "EditorIcons"), Control::get_icon("MiniTransform", "EditorIcons"), Control::get_icon("MiniColor", "EditorIcons"), - Control::get_icon("MiniImage", "EditorIcons"), Control::get_icon("MiniPath", "EditorIcons"), Control::get_icon("MiniRid", "EditorIcons"), Control::get_icon("MiniObject", "EditorIcons"), - Control::get_icon("MiniInput", "EditorIcons"), Control::get_icon("MiniDictionary", "EditorIcons"), Control::get_icon("MiniArray", "EditorIcons"), Control::get_icon("MiniRawArray", "EditorIcons"), @@ -489,7 +492,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (EditorSettings::get_singleton()->has("editors/visual_script/color_" + node->get_category())) { - gnode->set_modulate(EditorSettings::get_singleton()->get("editors/visual_script/color_" + node->get_category())); + Color c = EditorSettings::get_singleton()->get("editors/visual_script/color_" + node->get_category()); + gnode->set_self_modulate(c); } gnode->set_meta("__vnode", node); @@ -611,7 +615,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { Ref<Resource> res = value; Array arr; - arr.push_back(button->get_instance_ID()); + arr.push_back(button->get_instance_id()); arr.push_back(String(value)); EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr); @@ -702,7 +706,7 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); //ti->add_button(0,Control::get_icon("Edit","EditorIcons"),0); function arguments are in the node now - ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); + //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); ti->set_metadata(0, E->get()); if (E->get() == edited_func) { ti->set_custom_bg_color(0, get_color("prop_category", "Editor")); @@ -734,11 +738,9 @@ void VisualScriptEditor::_update_members() { Control::get_icon("MiniMatrix3", "EditorIcons"), Control::get_icon("MiniTransform", "EditorIcons"), Control::get_icon("MiniColor", "EditorIcons"), - Control::get_icon("MiniImage", "EditorIcons"), Control::get_icon("MiniPath", "EditorIcons"), Control::get_icon("MiniRid", "EditorIcons"), Control::get_icon("MiniObject", "EditorIcons"), - Control::get_icon("MiniInput", "EditorIcons"), Control::get_icon("MiniDictionary", "EditorIcons"), Control::get_icon("MiniArray", "EditorIcons"), Control::get_icon("MiniRawArray", "EditorIcons"), @@ -762,8 +764,8 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); - ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0); - ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); + //ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0); + //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); ti->set_metadata(0, E->get()); if (selected == E->get()) ti->select(0); @@ -782,8 +784,8 @@ void VisualScriptEditor::_update_members() { ti->set_text(0, E->get()); ti->set_selectable(0, true); ti->set_editable(0, true); - ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0); - ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); + //ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0); + //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1); ti->set_metadata(0, E->get()); if (selected == E->get()) ti->select(0); @@ -867,15 +869,27 @@ void VisualScriptEditor::_member_edited() { } selected = new_name; - _update_graph(); - + int node_id = script->get_function_node_id(name); + Ref<VisualScriptFunction> func; + if (script->has_node(name, node_id)) { + func = script->get_node(name, node_id); + } undo_redo->create_action(TTR("Rename Function")); undo_redo->add_do_method(script.ptr(), "rename_function", name, new_name); undo_redo->add_undo_method(script.ptr(), "rename_function", new_name, name); + if (func.is_valid()) { + + undo_redo->add_do_method(func.ptr(), "set_name", new_name); + undo_redo->add_undo_method(func.ptr(), "set_name", name); + } undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); + // _update_graph(); + return; //or crash because it will become invalid } @@ -1016,7 +1030,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.position + Vector2(0, pos.size.y)); new_function_menu->popup(); return; } else if (p_button == 0) { @@ -1073,105 +1087,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->commit_action(); return; //or crash because it will become invalid } - - } else { - - if (ti->get_parent() == root->get_children()) { - //edit/remove function - String name = ti->get_metadata(0); - - if (p_button == 1) { - //delete the function - undo_redo->create_action(TTR("Remove Function")); - undo_redo->add_do_method(script.ptr(), "remove_function", name); - undo_redo->add_undo_method(script.ptr(), "add_function", name); - List<int> nodes; - script->get_node_list(name, &nodes); - for (List<int>::Element *E = nodes.front(); E; E = E->next()) { - undo_redo->add_undo_method(script.ptr(), "add_node", name, E->get(), script->get_node(name, E->get()), script->get_node_pos(name, E->get())); - } - - List<VisualScript::SequenceConnection> seq_connections; - - script->get_sequence_connection_list(name, &seq_connections); - - for (List<VisualScript::SequenceConnection>::Element *E = seq_connections.front(); E; E = E->next()) { - undo_redo->add_undo_method(script.ptr(), "sequence_connect", name, E->get().from_node, E->get().from_output, E->get().to_node); - } - - List<VisualScript::DataConnection> data_connections; - - script->get_data_connection_list(name, &data_connections); - - for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { - undo_redo->add_undo_method(script.ptr(), "data_connect", name, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - } - - /* - for(int i=0;i<script->function_get_argument_count(name);i++) { - undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); - } - */ - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); - - } else if (p_button == 0) { - } - return; //or crash because it will become invalid - } - - if (ti->get_parent() == root->get_children()->get_next()) { - //edit/remove variable - - String name = ti->get_metadata(0); - - if (p_button == 1) { - - undo_redo->create_action(TTR("Remove Variable")); - undo_redo->add_do_method(script.ptr(), "remove_variable", name); - undo_redo->add_undo_method(script.ptr(), "add_variable", name, script->get_variable_default_value(name)); - undo_redo->add_undo_method(script.ptr(), "set_variable_info", name, script->call("get_variable_info", name)); //return as dict - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->commit_action(); - return; //or crash because it will become invalid - } else if (p_button == 0) { - - variable_editor->edit(name); - edit_variable_dialog->set_title(TTR("Editing Variable:") + " " + name); - edit_variable_dialog->popup_centered_minsize(Size2(400, 200) * EDSCALE); - } - } - - if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - //edit/remove variable - String name = ti->get_metadata(0); - - if (p_button == 1) { - - undo_redo->create_action(TTR("Remove Signal")); - undo_redo->add_do_method(script.ptr(), "remove_custom_signal", name); - undo_redo->add_undo_method(script.ptr(), "add_custom_signal", name); - - for (int i = 0; i < script->custom_signal_get_argument_count(name); i++) { - undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", name, script->custom_signal_get_argument_name(name, i), script->custom_signal_get_argument_type(name, i)); - } - - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->commit_action(); - } else if (p_button == 0) { - - signal_editor->edit(name); - edit_signal_dialog->set_title(TTR("Editing Signal:") + " " + name); - edit_signal_dialog->popup_centered_minsize(Size2(400, 300) * EDSCALE); - } - - return; //or crash because it will become invalid - } } } @@ -1421,9 +1336,11 @@ void VisualScriptEditor::_on_nodes_duplicate() { } } -void VisualScriptEditor::_input(const InputEvent &p_event) { +void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) { - if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { revert_on_drag = String(); //so we can still drag functions } } @@ -2064,7 +1981,7 @@ String VisualScriptEditor::get_name() { } else if (script->get_name() != "") name = script->get_name(); else - name = script->get_class() + "(" + itos(script->get_instance_ID()) + ")"; + name = script->get_class() + "(" + itos(script->get_instance_id()) + ")"; return name; } @@ -2152,7 +2069,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 +2079,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 +2114,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)) { @@ -2249,6 +2160,10 @@ void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray //undo_redo->clear_history(); } +bool VisualScriptEditor::show_members_overview() { + return false; +} + void VisualScriptEditor::update_settings() { _update_graph(); @@ -2274,6 +2189,11 @@ void VisualScriptEditor::_change_base_type() { select_base_type->popup_create(true); } +void VisualScriptEditor::clear_edit_menu() { + memdelete(edit_menu); + memdelete(left_vsplit); +} + void VisualScriptEditor::_change_base_type_callback() { String bt = select_base_type->get_selected_type(); @@ -2420,6 +2340,16 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int()); undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int()); } else { + + // disconect current, and connect the new one + if (script->is_input_value_port_connected(edited_func, p_to.to_int(), to_port)) { + int conn_from; + int conn_port; + script->get_input_value_port_connection_source(edited_func, p_to.to_int(), to_port, &conn_from, &conn_port); + undo_redo->add_do_method(script.ptr(), "data_disconnect", edited_func, conn_from, conn_port, p_to.to_int(), to_port); + undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, conn_from, conn_port, p_to.to_int(), to_port); + } + undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port); undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port); //update nodes in sgraph @@ -2516,21 +2446,21 @@ 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(); } -VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, int p_output, Set<int> &visited_nodes) { +VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) { VisualScriptNode::TypeGuess tg; tg.type = Variant::NIL; - if (visited_nodes.has(p_node)) + if (visited_nodes.has(p_port_action_node)) return tg; //no loop - visited_nodes.insert(p_node); + visited_nodes.insert(p_port_action_node); - Ref<VisualScriptNode> node = script->get_node(edited_func, p_node); + Ref<VisualScriptNode> node = script->get_node(edited_func, p_port_action_node); if (!node.is_valid()) { @@ -2549,7 +2479,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, i int from_node; int from_port; - if (script->get_input_value_port_connection_source(edited_func, p_node, i, &from_node, &from_port)) { + if (script->get_input_value_port_connection_source(edited_func, p_port_action_node, i, &from_node, &from_port)) { g = _guess_output_type(from_node, from_port, visited_nodes); } else { @@ -2561,7 +2491,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, i if (obj) { g.type = Variant::OBJECT; - g.GDCLASS = obj->get_class(); + g.gdclass = obj->get_class(); g.script = obj->get_script(); } } @@ -2571,7 +2501,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, i in_guesses.push_back(g); } - return node->guess_output_type(in_guesses.ptr(), p_output); + return node->guess_output_type(in_guesses.ptr(), p_port_action_output); } void VisualScriptEditor::_port_action_menu(int p_option) { @@ -2601,8 +2531,8 @@ void VisualScriptEditor::_port_action_menu(int p_option) { if (tg.type == Variant::OBJECT) { n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_INSTANCE); - if (tg.GDCLASS != StringName()) { - n->set_base_type(tg.GDCLASS); + if (tg.gdclass != StringName()) { + n->set_base_type(tg.gdclass); } else { n->set_base_type("Object"); } @@ -2632,8 +2562,8 @@ void VisualScriptEditor::_port_action_menu(int p_option) { if (tg.type == Variant::OBJECT) { n->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); - if (tg.GDCLASS != StringName()) { - n->set_base_type(tg.GDCLASS); + if (tg.gdclass != StringName()) { + n->set_base_type(tg.gdclass); } else { n->set_base_type("Object"); } @@ -2648,7 +2578,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) { } else { n->set_call_mode(VisualScriptPropertySet::CALL_MODE_BASIC_TYPE); n->set_basic_type(tg.type); - new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type); + new_connect_node_select->select_property_from_basic_type(tg.type); } } break; case CREATE_GET: { @@ -2662,8 +2592,8 @@ void VisualScriptEditor::_port_action_menu(int p_option) { if (tg.type == Variant::OBJECT) { n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); - if (tg.GDCLASS != StringName()) { - n->set_base_type(tg.GDCLASS); + if (tg.gdclass != StringName()) { + n->set_base_type(tg.gdclass); } else { n->set_base_type("Object"); } @@ -2678,7 +2608,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) { } else { n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE); n->set_basic_type(tg.type); - new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type); + new_connect_node_select->select_property_from_basic_type(tg.type); } } break; @@ -2805,7 +2735,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) @@ -2838,13 +2768,18 @@ void VisualScriptEditor::_node_filter_changed(const String &p_text) { void VisualScriptEditor::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - node_filter_icon->set_texture(Control::get_icon("Zoom", "EditorIcons")); + node_filter->add_icon_override("right_icon", Control::get_icon("Search", "EditorIcons")); + variable_editor->connect("changed", this, "_update_members"); + signal_editor->connect("changed", this, "_update_members"); + } + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + left_vsplit->set_visible(is_visible_in_tree()); } } void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { - if (updating_graph) + if (updating_graph || !script.is_valid()) return; updating_graph = true; @@ -3058,6 +2993,142 @@ void VisualScriptEditor::_menu_option(int p_what) { } } +void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { + + TreeItem *ti = members->get_selected(); + ERR_FAIL_COND(!ti); + + member_popup->clear(); + member_popup->set_position(members->get_global_position() + p_pos); + member_popup->set_size(Vector2()); + + TreeItem *root = members->get_root(); + + Ref<Texture> del_icon = Control::get_icon("Del", "EditorIcons"); + + Ref<Texture> edit_icon = Control::get_icon("Edit", "EditorIcons"); + + if (ti->get_parent() == root->get_children()) { + + member_type = MEMBER_FUNCTION; + member_name = ti->get_text(0); + member_popup->add_icon_item(del_icon, TTR("Remove Function"), MEMBER_REMOVE); + member_popup->popup(); + return; + } + + if (ti->get_parent() == root->get_children()->get_next()) { + + member_type = MEMBER_VARIABLE; + member_name = ti->get_text(0); + member_popup->add_icon_item(edit_icon, TTR("Edit Variable"), MEMBER_EDIT); + member_popup->add_separator(); + member_popup->add_icon_item(del_icon, TTR("Remove Variable"), MEMBER_REMOVE); + member_popup->popup(); + return; + } + + if (ti->get_parent() == root->get_children()->get_next()->get_next()) { + + member_type = MEMBER_SIGNAL; + member_name = ti->get_text(0); + member_popup->add_icon_item(edit_icon, TTR("Edit Signal"), MEMBER_EDIT); + member_popup->add_separator(); + member_popup->add_icon_item(del_icon, TTR("Remove Signal"), MEMBER_REMOVE); + member_popup->popup(); + return; + } +} + +void VisualScriptEditor::_member_option(int p_option) { + + switch (member_type) { + case MEMBER_FUNCTION: { + + if (p_option == MEMBER_REMOVE) { + //delete the function + String name = member_name; + + undo_redo->create_action(TTR("Remove Function")); + undo_redo->add_do_method(script.ptr(), "remove_function", name); + undo_redo->add_undo_method(script.ptr(), "add_function", name); + List<int> nodes; + script->get_node_list(name, &nodes); + for (List<int>::Element *E = nodes.front(); E; E = E->next()) { + undo_redo->add_undo_method(script.ptr(), "add_node", name, E->get(), script->get_node(name, E->get()), script->get_node_pos(name, E->get())); + } + + List<VisualScript::SequenceConnection> seq_connections; + + script->get_sequence_connection_list(name, &seq_connections); + + for (List<VisualScript::SequenceConnection>::Element *E = seq_connections.front(); E; E = E->next()) { + undo_redo->add_undo_method(script.ptr(), "sequence_connect", name, E->get().from_node, E->get().from_output, E->get().to_node); + } + + List<VisualScript::DataConnection> data_connections; + + script->get_data_connection_list(name, &data_connections); + + for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { + undo_redo->add_undo_method(script.ptr(), "data_connect", name, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + } + + /* + for(int i=0;i<script->function_get_argument_count(name);i++) { + undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); + } + */ + undo_redo->add_do_method(this, "_update_members"); + undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); + } + } break; + case MEMBER_VARIABLE: { + + String name = member_name; + + if (p_option == MEMBER_REMOVE) { + undo_redo->create_action(TTR("Remove Variable")); + undo_redo->add_do_method(script.ptr(), "remove_variable", name); + undo_redo->add_undo_method(script.ptr(), "add_variable", name, script->get_variable_default_value(name)); + undo_redo->add_undo_method(script.ptr(), "set_variable_info", name, script->call("get_variable_info", name)); //return as dict + undo_redo->add_do_method(this, "_update_members"); + undo_redo->add_undo_method(this, "_update_members"); + undo_redo->commit_action(); + } else if (p_option == MEMBER_EDIT) { + variable_editor->edit(name); + edit_variable_dialog->set_title(TTR("Editing Variable:") + " " + name); + edit_variable_dialog->popup_centered_minsize(Size2(400, 200) * EDSCALE); + } + } break; + case MEMBER_SIGNAL: { + String name = member_name; + + if (p_option == MEMBER_REMOVE) { + undo_redo->create_action(TTR("Remove Signal")); + undo_redo->add_do_method(script.ptr(), "remove_custom_signal", name); + undo_redo->add_undo_method(script.ptr(), "add_custom_signal", name); + + for (int i = 0; i < script->custom_signal_get_argument_count(name); i++) { + undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", name, script->custom_signal_get_argument_name(name, i), script->custom_signal_get_argument_type(name, i)); + } + + undo_redo->add_do_method(this, "_update_members"); + undo_redo->add_undo_method(this, "_update_members"); + undo_redo->commit_action(); + } else if (p_option == MEMBER_EDIT) { + + signal_editor->edit(name); + edit_signal_dialog->set_title(TTR("Editing Signal:") + " " + name); + edit_signal_dialog->popup_centered_minsize(Size2(400, 300) * EDSCALE); + } + } break; + } +} + void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_member_button", &VisualScriptEditor::_member_button); @@ -3106,6 +3177,10 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_selected_method", &VisualScriptEditor::_selected_method); ClassDB::bind_method("_draw_color_over_button", &VisualScriptEditor::_draw_color_over_button); + + ClassDB::bind_method("_member_rmb_selected", &VisualScriptEditor::_member_rmb_selected); + + ClassDB::bind_method("_member_option", &VisualScriptEditor::_member_option); } VisualScriptEditor::VisualScriptEditor() { @@ -3127,17 +3202,16 @@ VisualScriptEditor::VisualScriptEditor() { edit_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - main_hsplit = memnew(HSplitContainer); - add_child(main_hsplit); - main_hsplit->set_area_as_parent_rect(); - left_vsplit = memnew(VSplitContainer); - main_hsplit->add_child(left_vsplit); + ScriptEditor::get_singleton()->get_left_list_split()->call_deferred("add_child", left_vsplit); //add but wait until done settig up this + left_vsplit->set_v_size_flags(SIZE_EXPAND_FILL); + left_vsplit->set_stretch_ratio(2); + left_vsplit->hide(); VBoxContainer *left_vb = memnew(VBoxContainer); left_vsplit->add_child(left_vb); left_vb->set_v_size_flags(SIZE_EXPAND_FILL); - left_vb->set_custom_minimum_size(Size2(230, 1) * EDSCALE); + //left_vb->set_custom_minimum_size(Size2(230, 1) * EDSCALE); base_type_select = memnew(Button); left_vb->add_margin_child(TTR("Base Type:"), base_type_select); @@ -3163,9 +3237,6 @@ VisualScriptEditor::VisualScriptEditor() { node_filter->connect("text_changed", this, "_node_filter_changed"); hbc_nodes->add_child(node_filter); node_filter->set_h_size_flags(SIZE_EXPAND_FILL); - node_filter_icon = memnew(TextureRect); - node_filter_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); - hbc_nodes->add_child(node_filter_icon); vbc_nodes->add_child(hbc_nodes); nodes = memnew(Tree); @@ -3179,7 +3250,8 @@ VisualScriptEditor::VisualScriptEditor() { nodes->set_drag_forwarding(this); graph = memnew(GraphEdit); - main_hsplit->add_child(graph); + add_child(graph); + graph->set_area_as_parent_rect(); graph->set_h_size_flags(SIZE_EXPAND_FILL); graph->connect("node_selected", this, "_node_selected"); graph->connect("_begin_node_move", this, "_begin_node_move"); @@ -3195,10 +3267,11 @@ VisualScriptEditor::VisualScriptEditor() { select_func_text->set_align(Label::ALIGN_CENTER); select_func_text->set_valign(Label::VALIGN_CENTER); select_func_text->set_h_size_flags(SIZE_EXPAND_FILL); - main_hsplit->add_child(select_func_text); + add_child(select_func_text); + graph->set_area_as_parent_rect(); hint_text = memnew(Label); - hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, 100); + hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -100); hint_text->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); hint_text->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); hint_text->set_align(Label::ALIGN_CENTER); @@ -3285,6 +3358,12 @@ VisualScriptEditor::VisualScriptEditor() { port_action_popup = memnew(PopupMenu); add_child(port_action_popup); port_action_popup->connect("id_pressed", this, "_port_action_menu"); + + member_popup = memnew(PopupMenu); + add_child(member_popup); + members->connect("item_rmb_selected", this, "_member_rmb_selected"); + members->set_allow_rmb_select(true); + member_popup->connect("id_pressed", this, "_member_option"); } VisualScriptEditor::~VisualScriptEditor() { @@ -3316,7 +3395,7 @@ static void register_editor_callback() { EditorSettings::get_singleton()->set("editors/visual_script/color_functions", Color(1, 0.9, 0.9)); EditorSettings::get_singleton()->set("editors/visual_script/color_data", Color(0.9, 1.0, 0.9)); EditorSettings::get_singleton()->set("editors/visual_script/color_operators", Color(0.9, 0.9, 1.0)); - EditorSettings::get_singleton()->set("editors/visual_script/color_flow_control", Color(1.0, 1.0, 0.8)); + EditorSettings::get_singleton()->set("editors/visual_script/color_flow_control", Color(1.0, 1.0, 1.0)); EditorSettings::get_singleton()->set("editors/visual_script/color_custom", Color(0.8, 1.0, 1.0)); EditorSettings::get_singleton()->set("editors/visual_script/color_constants", Color(1.0, 0.8, 1.0)); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 5ece1c9e2c..fee4e27bd5 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 */ @@ -71,15 +72,25 @@ class VisualScriptEditor : public ScriptEditorBase { CREATE_RETURN, }; + enum MemberAction { + MEMBER_EDIT, + MEMBER_REMOVE + + }; + + enum MemberType { + MEMBER_FUNCTION, + MEMBER_VARIABLE, + MEMBER_SIGNAL + }; + + VSplitContainer *left_vsplit; MenuButton *edit_menu; Ref<VisualScript> script; Button *base_type_select; - HSplitContainer *main_hsplit; - VSplitContainer *left_vsplit; - GraphEdit *graph; LineEdit *node_filter; @@ -153,6 +164,10 @@ class VisualScriptEditor : public ScriptEditorBase { static Clipboard *clipboard; PopupMenu *port_action_popup; + PopupMenu *member_popup; + + MemberType member_type; + String member_name; PortAction port_action; int port_action_node; @@ -195,7 +210,7 @@ class VisualScriptEditor : public ScriptEditorBase { String revert_on_drag; - void _input(const InputEvent &p_event); + void _input(const Ref<InputEvent> &p_event); void _on_nodes_delete(); void _on_nodes_duplicate(); @@ -222,6 +237,9 @@ class VisualScriptEditor : public ScriptEditorBase { VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes); + void _member_rmb_selected(const Vector2 &p_pos); + void _member_option(int p_option); + protected: void _notification(int p_what); static void _bind_methods(); @@ -239,16 +257,19 @@ 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 bool show_members_overview(); virtual void set_debugger_active(bool p_active); virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual Control *get_edit_menu(); + virtual void clear_edit_menu(); virtual bool can_lose_focus_on_node_selection() { return false; } static void register_editor(); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 96864b4bf6..78b70934c0 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 */ @@ -67,12 +68,12 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val return true; } - if (String(p_name).begins_with("input/")) { + if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slice("/", 1).to_int(); + int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); - String what = String(p_name).get_slice("/", 2); + String what = String(p_name).get_slice("/", 1); if (what == "type") { @@ -114,12 +115,12 @@ bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) cons return true; } - if (String(p_name).begins_with("input/")) { + if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slice("/", 1).to_int(); + int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); - String what = String(p_name).get_slice("/", 2); + String what = String(p_name).get_slice("/", 1); if (what == "type") { @@ -150,8 +151,8 @@ void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) cons for (int i = 0; i < inputs.size(); i++) { - p_list->push_back(PropertyInfo(Variant::INT, "input/" + itos(i) + "/type", PROPERTY_HINT_ENUM, argt)); - p_list->push_back(PropertyInfo(Variant::STRING, "input/" + itos(i) + "/name")); + p_list->push_back(PropertyInfo(Variant::INT, "input_" + itos(i) + "/type", PROPERTY_HINT_ENUM, argt)); + p_list->push_back(PropertyInfo(Variant::STRING, "input_" + itos(i) + "/name")); } } 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..77f3111d94 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 */ @@ -28,8 +29,9 @@ /*************************************************************************/ #include "visual_script_flow_control.h" -#include "global_config.h" +#include "io/resource_loader.h" #include "os/keyboard.h" +#include "project_settings.h" ////////////////////////////////////////// ////////////////RETURN//////////////////// @@ -118,8 +120,8 @@ void VisualScriptReturn::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "return_value/enabled"), "set_enable_return_value", "is_return_value_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "return_value/type", PROPERTY_HINT_ENUM, argt), "set_return_type", "get_return_type"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "return_enabled"), "set_enable_return_value", "is_return_value_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "return_type", PROPERTY_HINT_ENUM, argt), "set_return_type", "get_return_type"); } class VisualScriptNodeInstanceReturn : public VisualScriptNodeInstance { @@ -136,11 +138,11 @@ public: if (with_value) { *p_working_mem = *p_inputs[0]; + return STEP_EXIT_FUNCTION_BIT; } else { *p_working_mem = Variant(); + return 0; } - - return 0; } }; @@ -733,6 +735,7 @@ VisualScriptSwitch::VisualScriptSwitch() { ////////////////EVENT ACTION FILTER/////////// ////////////////////////////////////////// +#if 0 int VisualScriptInputFilter::get_output_sequence_port_count() const { return filters.size(); @@ -757,86 +760,86 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const String text; switch (filters[p_port].type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { text = "None"; } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { InputEventKey k = filters[p_port].key; - if (k.scancode == 0 && k.unicode == 0) { + if (k->get_scancode() == 0 && k.unicode == 0) { text = "No Key"; } else { - if (k.scancode != 0) { - text = "KeyCode: " + keycode_get_string(k.scancode); + if (k->get_scancode() != 0) { + text = "KeyCode: " + keycode_get_string(k->get_scancode()); } else if (k.unicode != 0) { text = "Uniode: " + String::chr(k.unicode); } - if (k.pressed) + if (k->is_pressed()) text += ", Pressed"; else text += ", Released"; if (k.echo) text += ", Echo"; - if (k.mod.alt) + if (k->get_alt()) text = "Alt+" + text; - if (k.mod.shift) + if (k->get_shift()) text = "Shift+" + text; - if (k.mod.control) + if (k->get_control()) text = "Ctrl+" + text; - if (k.mod.meta) + if (k->get_metakey()) text = "Meta+" + text; } } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { InputEventMouseMotion mm = filters[p_port].mouse_motion; text = "Mouse Motion"; String b = "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"; for (int i = 0; i < 7; i++) { - if (mm.button_mask & (1 << i)) { + if (mm->get_button_mask() & (1 << i)) { text = b.get_slice(",", i) + "+" + text; } } - if (mm.mod.alt) + if (mm->get_alt()) text = "Alt+" + text; - if (mm.mod.shift) + if (mm->get_shift()) text = "Shift+" + text; - if (mm.mod.control) + if (mm->get_control()) text = "Ctrl+" + text; - if (mm.mod.meta) + if (mm->get_metakey()) text = "Meta+" + text; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { InputEventMouseButton mb = filters[p_port].mouse_button; String b = "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"; - text = b.get_slice(",", mb.button_index) + " Mouse Button"; + text = b.get_slice(",", mb->get_button_index()) + " Mouse Button"; - if (mb.pressed) + if (mb->is_pressed()) text += ", Pressed"; else text += ", Released"; if (mb.doubleclick) text += ", DblClick"; - if (mb.mod.alt) + if (mb->get_alt()) text = "Alt+" + text; - if (mb.mod.shift) + if (mb->get_shift()) text = "Shift+" + text; - if (mb.mod.control) + if (mb->get_control()) text = "Ctrl+" + text; - if (mb.mod.meta) + if (mb->get_metakey()) text = "Meta+" + text; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { InputEventJoypadMotion jm = filters[p_port].joy_motion; @@ -847,32 +850,32 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const text += " < " + rtos(-jm.axis_value); } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { InputEventJoypadButton jb = filters[p_port].joy_button; - text = "JoyButton " + itos(jb.button_index); - if (jb.pressed) + text = "JoyButton " + itos(jb->get_button_index()); + if (jb->is_pressed()) text += ", Pressed"; else text += ", Released"; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { InputEventScreenTouch sd = filters[p_port].screen_touch; text = "Touch Finger " + itos(sd.index); - if (sd.pressed) + if (sd->is_pressed()) text += ", Pressed"; else text += ", Released"; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { InputEventScreenDrag sd = filters[p_port].screen_drag; text = "Drag Finger " + itos(sd.index); } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); int index = 1; text = "No Action"; @@ -889,7 +892,7 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const index++; } - if (filters[p_port].action.pressed) + if (filters[p_port].action->is_pressed()) text += ", Pressed"; else text += ", Released"; @@ -938,20 +941,20 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va String what = String(p_name).get_slice("/", 1); if (what == "type") { - filters[idx] = InputEvent(); - filters[idx].type = InputEvent::Type(int(p_value)); - if (filters[idx].type == InputEvent::JOYPAD_MOTION) { - filters[idx].joy_motion.axis_value = 0.5; //for treshold - } else if (filters[idx].type == InputEvent::KEY) { - filters[idx].key.pressed = true; //put these as true to make it more user friendly - } else if (filters[idx].type == InputEvent::MOUSE_BUTTON) { - filters[idx].mouse_button.pressed = true; - } else if (filters[idx].type == InputEvent::JOYPAD_BUTTON) { - filters[idx].joy_button.pressed = true; - } else if (filters[idx].type == InputEvent::SCREEN_TOUCH) { - filters[idx].screen_touch.pressed = true; - } else if (filters[idx].type == InputEvent::ACTION) { - filters[idx].action.pressed = true; + filters[idx] = Ref<InputEvent>(); + filters[idx].type = Ref<InputEvent>::Type(int(p_value)); + if (filters[idx].type == Ref<InputEvent>::JOYPAD_MOTION) { + filters[idx].joy_motion.axis_value = 0.5; //for threshold + } else if (filters[idx].type == Ref<InputEvent>::KEY) { + filters[idx]->is_pressed() = true; //put these as true to make it more user friendly + } else if (filters[idx].type == Ref<InputEvent>::MOUSE_BUTTON) { + filters[idx]->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::JOYPAD_BUTTON) { + filters[idx].joy_button->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::SCREEN_TOUCH) { + filters[idx].screen_touch->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::ACTION) { + filters[idx].action->is_pressed() = true; } _change_notify(); ports_changed_notify(); @@ -966,14 +969,14 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va switch (filters[idx].type) { - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (what == "scancode") { String sc = p_value; if (sc == String()) { - filters[idx].key.scancode = 0; + filters[idx]->get_scancode() = 0; } else { - filters[idx].key.scancode = find_keycode(p_value); + filters[idx]->get_scancode() = find_keycode(p_value); } } else if (what == "unicode") { @@ -988,22 +991,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va } else if (what == "pressed") { - filters[idx].key.pressed = p_value; + filters[idx]->is_pressed() = p_value; } else if (what == "echo") { - filters[idx].key.echo = p_value; + filters[idx]->is_echo() = p_value; } else if (what == "mod_alt") { - filters[idx].key.mod.alt = p_value; + filters[idx]->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].key.mod.shift = p_value; + filters[idx]->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].key.mod.control = p_value; + filters[idx]->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].key.mod.meta = p_value; + filters[idx]->get_metakey() = p_value; } else { return false; } @@ -1011,22 +1014,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { if (what == "button_mask") { - filters[idx].mouse_motion.button_mask = p_value; + filters[idx]->get_button_mask() = p_value; } else if (what == "mod_alt") { - filters[idx].mouse_motion.mod.alt = p_value; + filters[idx].mouse_motion->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].mouse_motion.mod.shift = p_value; + filters[idx].mouse_motion->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].mouse_motion.mod.control = p_value; + filters[idx].mouse_motion->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].mouse_motion.mod.meta = p_value; + filters[idx].mouse_motion->get_metakey() = p_value; } else { return false; } @@ -1035,26 +1038,26 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { if (what == "button_index") { - filters[idx].mouse_button.button_index = p_value; + filters[idx]->get_button_index() = p_value; } else if (what == "pressed") { - filters[idx].mouse_button.pressed = p_value; + filters[idx]->is_pressed() = p_value; } else if (what == "doubleclicked") { filters[idx].mouse_button.doubleclick = p_value; } else if (what == "mod_alt") { - filters[idx].mouse_button.mod.alt = p_value; + filters[idx].mouse_button->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].mouse_button.mod.shift = p_value; + filters[idx].mouse_button->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].mouse_button.mod.control = p_value; + filters[idx].mouse_button->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].mouse_button.mod.meta = p_value; + filters[idx].mouse_button->get_metakey() = p_value; } else { return false; } @@ -1062,13 +1065,13 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { if (what == "axis") { filters[idx].joy_motion.axis = int(p_value) << 1 | filters[idx].joy_motion.axis; } else if (what == "mode") { filters[idx].joy_motion.axis |= int(p_value); - } else if (what == "treshold") { + } else if (what == "threshold") { filters[idx].joy_motion.axis_value = p_value; } else { return false; @@ -1077,12 +1080,12 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { if (what == "button_index") { - filters[idx].joy_button.button_index = p_value; + filters[idx].joy_button->get_button_index() = p_value; } else if (what == "pressed") { - filters[idx].joy_button.pressed = p_value; + filters[idx].joy_button->is_pressed() = p_value; } else { return false; } @@ -1090,19 +1093,19 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { if (what == "finger_index") { filters[idx].screen_touch.index = p_value; } else if (what == "pressed") { - filters[idx].screen_touch.pressed = p_value; + filters[idx].screen_touch->is_pressed() = p_value; } else { return false; } ports_changed_notify(); return true; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { if (what == "finger_index") { filters[idx].screen_drag.index = p_value; } else { @@ -1111,12 +1114,12 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va ports_changed_notify(); return true; } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (what == "action_name") { List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); int index = 1; for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { @@ -1143,7 +1146,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va } else if (what == "pressed") { - filters[idx].action.pressed = p_value; + filters[idx].action->is_pressed() = p_value; ports_changed_notify(); return true; } @@ -1180,14 +1183,14 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con switch (filters[idx].type) { - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (what == "scancode") { - if (filters[idx].key.scancode == 0) + if (filters[idx]->get_scancode() == 0) r_ret = String(); else { - r_ret = keycode_get_string(filters[idx].key.scancode); + r_ret = keycode_get_string(filters[idx]->get_scancode()); } } else if (what == "unicode") { @@ -1201,44 +1204,44 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } else if (what == "pressed") { - r_ret = filters[idx].key.pressed; + r_ret = filters[idx]->is_pressed(); } else if (what == "echo") { - r_ret = filters[idx].key.echo; + r_ret = filters[idx]->is_echo(); } else if (what == "mod_alt") { - r_ret = filters[idx].key.mod.alt; + r_ret = filters[idx]->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].key.mod.shift; + r_ret = filters[idx]->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].key.mod.control; + r_ret = filters[idx]->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].key.mod.meta; + r_ret = filters[idx]->get_metakey(); } else { return false; } return true; } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { if (what == "button_mask") { - r_ret = filters[idx].mouse_motion.button_mask; + r_ret = filters[idx]->get_button_mask(); } else if (what == "mod_alt") { - r_ret = filters[idx].mouse_motion.mod.alt; + r_ret = filters[idx].mouse_motion->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].mouse_motion.mod.shift; + r_ret = filters[idx].mouse_motion->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].mouse_motion.mod.control; + r_ret = filters[idx].mouse_motion->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].mouse_motion.mod.meta; + r_ret = filters[idx].mouse_motion->get_metakey(); } else { return false; } @@ -1246,39 +1249,39 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return true; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { if (what == "button_index") { - r_ret = filters[idx].mouse_button.button_index; + r_ret = filters[idx]->get_button_index(); } else if (what == "pressed") { - r_ret = filters[idx].mouse_button.pressed; + r_ret = filters[idx]->is_pressed(); } else if (what == "doubleclicked") { r_ret = filters[idx].mouse_button.doubleclick; } else if (what == "mod_alt") { - r_ret = filters[idx].mouse_button.mod.alt; + r_ret = filters[idx].mouse_button->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].mouse_button.mod.shift; + r_ret = filters[idx].mouse_button->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].mouse_button.mod.control; + r_ret = filters[idx].mouse_button->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].mouse_button.mod.meta; + r_ret = filters[idx].mouse_button->get_metakey(); } else { return false; } return true; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { if (what == "axis_index") { r_ret = filters[idx].joy_motion.axis >> 1; } else if (what == "mode") { r_ret = filters[idx].joy_motion.axis & 1; - } else if (what == "treshold") { + } else if (what == "threshold") { r_ret = filters[idx].joy_motion.axis_value; } else { return false; @@ -1286,30 +1289,30 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return true; } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { if (what == "button_index") { - r_ret = filters[idx].joy_button.button_index; + r_ret = filters[idx].joy_button->get_button_index(); } else if (what == "pressed") { - r_ret = filters[idx].joy_button.pressed; + r_ret = filters[idx].joy_button->is_pressed(); } else { return false; } return true; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { if (what == "finger_index") { r_ret = filters[idx].screen_touch.index; } else if (what == "pressed") { - r_ret = filters[idx].screen_touch.pressed; + r_ret = filters[idx].screen_touch->is_pressed(); } else { return false; } return true; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { if (what == "finger_index") { r_ret = filters[idx].screen_drag.index; } else { @@ -1317,12 +1320,12 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } return true; } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (what == "action_name") { List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); int index = 1; for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { @@ -1343,7 +1346,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } else if (what == "pressed") { - r_ret = filters[idx].action.pressed; + r_ret = filters[idx].action->is_pressed(); return true; } @@ -1353,7 +1356,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return false; } -static const char *event_type_names[InputEvent::TYPE_MAX] = { +static const char *event_type_names[Ref<InputEvent>::TYPE_MAX] = { "None", "Key", "MouseMotion", @@ -1370,7 +1373,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::INT, "filter_count", PROPERTY_HINT_RANGE, "0,64")); String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { + for (int i = 0; i < Ref<InputEvent>::TYPE_MAX; i++) { if (i > 0) et += ","; @@ -1387,10 +1390,10 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::INT, base + "device")); switch (filters[i].type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (kc == String()) { int kcc = keycode_get_count(); kc = "None"; @@ -1409,7 +1412,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_mask", PROPERTY_HINT_FLAGS, "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_alt")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_shift")); @@ -1417,7 +1420,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_index", PROPERTY_HINT_ENUM, "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "doubleclicked")); @@ -1427,33 +1430,33 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { p_list->push_back(PropertyInfo(Variant::INT, base + "axis_index")); p_list->push_back(PropertyInfo(Variant::INT, base + "mode", PROPERTY_HINT_ENUM, "Min,Max")); - p_list->push_back(PropertyInfo(Variant::REAL, base + "treshold", PROPERTY_HINT_RANGE, "0,1,0.01")); + p_list->push_back(PropertyInfo(Variant::REAL, base + "threshold", PROPERTY_HINT_RANGE, "0,1,0.01")); } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_index")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index")); } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (actions == String()) { actions = "None"; List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); Vector<String> al; for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { @@ -1484,7 +1487,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con class VisualScriptNodeInstanceInputFilter : public VisualScriptNodeInstance { public: VisualScriptInstance *instance; - Vector<InputEvent> filters; + Vector<Ref<InputEvent>> filters; //virtual int get_working_memory_size() const { return 0; } //virtual bool is_output_port_unsequenced(int p_idx) const { return false; } @@ -1498,11 +1501,11 @@ public: return 0; } - InputEvent event = *p_inputs[0]; + Ref<InputEvent> event = *p_inputs[0]; for (int i = 0; i < filters.size(); i++) { - const InputEvent &ie = filters[i]; + const Ref<InputEvent> &ie = filters[i]; if (ie.type != event.type) continue; @@ -1510,25 +1513,25 @@ public: switch (ie.type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { match = true; } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { InputEventKey k = ie.key; InputEventKey k2 = event.key; - if (k.scancode == 0 && k.unicode == 0 && k2.scancode == 0 && k2.unicode == 0) { + if (k->get_scancode() == 0 && k.unicode == 0 && k2->get_scancode() == 0 && k2.unicode == 0) { match = true; } else { - if ((k.scancode != 0 && k.scancode == k2.scancode) || (k.unicode != 0 && k.unicode == k2.unicode)) { + if ((k->get_scancode() != 0 && k->get_scancode() == k2->get_scancode()) || (k.unicode != 0 && k.unicode == k2.unicode)) { //key valid if ( - k.pressed == k2.pressed && + k->is_pressed() == k2->is_pressed() && k.echo == k2.echo && k.mod == k2.mod) { match = true; @@ -1537,30 +1540,30 @@ public: } } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { InputEventMouseMotion mm = ie.mouse_motion; InputEventMouseMotion mm2 = event.mouse_motion; - if (mm.button_mask == mm2.button_mask && + if (mm->get_button_mask() == mm2->get_button_mask() && mm.mod == mm2.mod) { match = true; } } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { InputEventMouseButton mb = ie.mouse_button; InputEventMouseButton mb2 = event.mouse_button; - if (mb.button_index == mb2.button_index && - mb.pressed == mb2.pressed && + if (mb->get_button_index() == mb2->get_button_index() && + mb->is_pressed() == mb2->is_pressed() && mb.doubleclick == mb2.doubleclick && mb.mod == mb2.mod) { match = true; } } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { InputEventJoypadMotion jm = ie.joy_motion; InputEventJoypadMotion jm2 = event.joy_motion; @@ -1583,26 +1586,26 @@ public: } } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { InputEventJoypadButton jb = ie.joy_button; InputEventJoypadButton jb2 = event.joy_button; - if (jb.button_index == jb2.button_index && - jb.pressed == jb2.pressed) { + if (jb->get_button_index() == jb2->get_button_index() && + jb->is_pressed() == jb2->is_pressed()) { match = true; } } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { InputEventScreenTouch st = ie.screen_touch; InputEventScreenTouch st2 = event.screen_touch; if (st.index == st2.index && - st.pressed == st2.pressed) { + st->is_pressed() == st2->is_pressed()) { match = true; } } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { InputEventScreenDrag sd = ie.screen_drag; InputEventScreenDrag sd2 = event.screen_drag; @@ -1610,13 +1613,13 @@ public: match = true; } } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { InputEventAction ia = ie.action; InputEventAction ia2 = event.action; if (ia.action == ia2.action && - ia.pressed == ia2.pressed) { + ia->is_pressed() == ia2->is_pressed()) { match = true; } } break; @@ -1642,7 +1645,7 @@ VisualScriptNodeInstance *VisualScriptInputFilter::instance(VisualScriptInstance VisualScriptInputFilter::VisualScriptInputFilter() { } - +#endif ////////////////////////////////////////// ////////////////TYPE CAST/////////// ////////////////////////////////////////// @@ -1723,6 +1726,20 @@ String VisualScriptTypeCast::get_base_script() const { return script; } +VisualScriptTypeCast::TypeGuess VisualScriptTypeCast::guess_output_type(TypeGuess *p_inputs, int p_output) const { + + TypeGuess tg; + tg.type = Variant::OBJECT; + if (script != String()) { + tg.script = ResourceLoader::load(script); + } + //if (!tg.script.is_valid()) { + // tg.gdclass = base_type; + //} + + return tg; +} + class VisualScriptNodeInstanceTypeCast : public VisualScriptNodeInstance { public: VisualScriptInstance *instance; @@ -1813,8 +1830,8 @@ void VisualScriptTypeCast::_bind_methods() { script_ext_hint += "*." + E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "function/base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); } VisualScriptTypeCast::VisualScriptTypeCast() { @@ -1831,6 +1848,6 @@ void register_visual_script_flow_control_nodes() { VisualScriptLanguage::singleton->add_register_func("flow_control/iterator", create_node_generic<VisualScriptIterator>); VisualScriptLanguage::singleton->add_register_func("flow_control/sequence", create_node_generic<VisualScriptSequence>); VisualScriptLanguage::singleton->add_register_func("flow_control/switch", create_node_generic<VisualScriptSwitch>); - VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>); + //VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>); VisualScriptLanguage::singleton->add_register_func("flow_control/type_cast", create_node_generic<VisualScriptTypeCast>); } diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 1739f67b5b..d27fd47f84 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 */ @@ -227,11 +228,12 @@ public: VisualScriptSwitch(); }; +#if 0 class VisualScriptInputFilter : public VisualScriptNode { GDCLASS(VisualScriptInputFilter, VisualScriptNode) - Vector<InputEvent> filters; + Vector<Ref<InputEvent>> filters; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -258,6 +260,7 @@ public: VisualScriptInputFilter(); }; +#endif class VisualScriptTypeCast : public VisualScriptNode { @@ -291,6 +294,8 @@ public: void set_base_script(const String &p_path); String get_base_script() const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); VisualScriptTypeCast(); diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 3cd20050ce..afdf50027e 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 */ @@ -28,11 +29,11 @@ /*************************************************************************/ #include "visual_script_func_nodes.h" -#include "global_config.h" #include "io/resource_loader.h" #include "os/os.h" +#include "project_settings.h" #include "scene/main/node.h" -#include "scene/main/scene_main_loop.h" +#include "scene/main/scene_tree.h" #include "visual_script_nodes.h" ////////////////////////////////////////// @@ -340,13 +341,13 @@ String VisualScriptFunctionCall::get_base_script() const { return base_script; } -void VisualScriptFunctionCall::set_singleton(const StringName &p_path) { +void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { - if (singleton == p_path) + if (singleton == p_type) return; - singleton = p_path; - Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton); + singleton = p_type; + Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); if (obj) { base_type = obj->get_class(); } @@ -382,7 +383,7 @@ void VisualScriptFunctionCall::_update_method_cache() { } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton); + Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); if (obj) { type = obj->get_class(); script = obj->get_script(); @@ -545,33 +546,33 @@ Dictionary VisualScriptFunctionCall::_get_argument_cache() const { void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const { - if (property.name == "function/base_type") { + if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; } } - if (property.name == "function/base_script") { + if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = 0; } } - if (property.name == "function/basic_type") { + if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { property.usage = 0; } } - if (property.name == "function/singleton") { + if (property.name == "singleton") { if (call_mode != CALL_MODE_SINGLETON) { property.usage = 0; } else { - List<GlobalConfig::Singleton> names; - GlobalConfig::get_singleton()->get_singletons(&names); + List<ProjectSettings::Singleton> names; + ProjectSettings::get_singleton()->get_singletons(&names); property.hint = PROPERTY_HINT_ENUM; String sl; - for (List<GlobalConfig::Singleton>::Element *E = names.front(); E; E = E->next()) { + for (List<ProjectSettings::Singleton>::Element *E = names.front(); E; E = E->next()) { if (sl != String()) sl += ","; sl += E->get().name; @@ -580,7 +581,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } } - if (property.name == "function/node_path") { + if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { @@ -593,7 +594,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } } - if (property.name == "function/function") { + if (property.name == "function") { if (call_mode == CALL_MODE_BASIC_TYPE) { @@ -602,13 +603,13 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; - property.hint_string = itos(get_visual_script()->get_instance_ID()); + property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton); + Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); if (obj) { property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE; - property.hint_string = itos(obj->get_instance_ID()); + property.hint_string = itos(obj->get_instance_id()); } else { property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE; @@ -630,7 +631,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (script.is_valid()) { property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; - property.hint_string = itos(script->get_instance_ID()); + property.hint_string = itos(script->get_instance_id()); } } } @@ -639,7 +640,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const Node *node = _get_base_node(); if (node) { property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE; - property.hint_string = itos(node->get_instance_ID()); + property.hint_string = itos(node->get_instance_id()); } else { property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE; property.hint_string = get_base_type(); @@ -647,7 +648,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } } - if (property.name == "function/use_default_args") { + if (property.name == "use_default_args") { property.hint = PROPERTY_HINT_RANGE; @@ -672,7 +673,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } } - if (property.name == "rpc/call_mode") { + if (property.name == "rpc_call_mode") { if (call_mode == CALL_MODE_BASIC_TYPE) { property.usage = 0; } @@ -734,17 +735,17 @@ void VisualScriptFunctionCall::_bind_methods() { script_ext_hint += "*." + E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "function/call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type,Singleton"), "set_call_mode", "get_call_mode"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "function/base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "function/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "function/singleton"), "set_singleton", "get_singleton"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "function/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "function/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); - ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "function/argument_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_argument_cache", "_get_argument_cache"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "function/function"), "set_function", "get_function"); //when set, if loaded properly, will override argument count. - ADD_PROPERTY(PropertyInfo(Variant::INT, "function/use_default_args"), "set_use_default_args", "get_use_default_args"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "function/validate"), "set_validate", "get_validate"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "rpc/call_mode", PROPERTY_HINT_ENUM, "Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"), "set_rpc_call_mode", "get_rpc_call_mode"); //when set, if loaded properly, will override argument count. + ADD_PROPERTY(PropertyInfo(Variant::INT, "call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type,Singleton"), "set_call_mode", "get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "singleton"), "set_singleton", "get_singleton"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "argument_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_argument_cache", "_get_argument_cache"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "function"), "set_function", "get_function"); //when set, if loaded properly, will override argument count. + ADD_PROPERTY(PropertyInfo(Variant::INT, "use_default_args"), "set_use_default_args", "get_use_default_args"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "validate"), "set_validate", "get_validate"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "rpc_call_mode", PROPERTY_HINT_ENUM, "Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"), "set_rpc_call_mode", "get_rpc_call_mode"); //when set, if loaded properly, will override argument count. BIND_CONSTANT(CALL_MODE_SELF); BIND_CONSTANT(CALL_MODE_NODE_PATH); @@ -866,7 +867,7 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_SINGLETON: { - Object *object = GlobalConfig::get_singleton()->get_singleton_object(singleton); + Object *object = ProjectSettings::get_singleton()->get_singleton_object(singleton); if (!object) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Invalid singleton name: '" + String(singleton) + "'"; @@ -942,18 +943,6 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { ////////////////SET////////////////////// ////////////////////////////////////////// -static const char *event_type_names[InputEvent::TYPE_MAX] = { - "None", - "Key", - "MouseMotion", - "MouseButton", - "JoypadMotion", - "JoypadButton", - "ScreenTouch", - "ScreenDrag", - "Action" -}; - int VisualScriptPropertySet::get_output_sequence_port_count() const { return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0; @@ -1031,6 +1020,18 @@ String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const return String(); } +void VisualScriptPropertySet::_adjust_input_index(PropertyInfo &pinfo) const { + + if (index != StringName()) { + + Variant v; + Variant::CallError ce; + v = Variant::construct(pinfo.type, NULL, 0, ce); + Variant i = v.get(index); + pinfo.type = i.get_type(); + } +} + PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const { if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) { @@ -1038,6 +1039,7 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const PropertyInfo pi; pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type); pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower()); + _adjust_input_index(pi); return pi; } else { p_idx--; @@ -1046,6 +1048,7 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const PropertyInfo pinfo = type_cache; pinfo.name = "value"; + _adjust_input_index(pinfo); return pinfo; } @@ -1062,13 +1065,16 @@ PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) cons String VisualScriptPropertySet::get_caption() const { static const char *cname[4] = { - "SelfSet", - "NodeSet", - "InstanceSet", - "BasicSet" + "Self", + "Node", + "Instance", + "Basic" }; - return cname[call_mode]; + static const char *opname[ASSIGN_OP_MAX] = { + "Set", "Add", "Sub", "Mul", "Div", "Mod", "ShiftLeft", "ShiftRight", "BitAnd", "BitOr", "BitXor" + }; + return String(cname[call_mode]) + opname[assign_op]; } String VisualScriptPropertySet::get_text() const { @@ -1084,6 +1090,9 @@ String VisualScriptPropertySet::get_text() const { else if (call_mode == CALL_MODE_INSTANCE) prop = String(base_type) + ":" + property; + if (index != StringName()) { + prop += "." + String(index); + } return prop; } @@ -1118,24 +1127,6 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const { return basic_type; } -void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) { - - if (event_type == p_type) - return; - event_type = p_type; - if (call_mode == CALL_MODE_BASIC_TYPE) { - _update_cache(); - } - _change_notify(); - _update_base_type(); - ports_changed_notify(); -} - -InputEvent::Type VisualScriptPropertySet::get_event_type() const { - - return event_type; -} - void VisualScriptPropertySet::set_base_type(const StringName &p_type) { if (base_type == p_type) @@ -1181,14 +1172,8 @@ void VisualScriptPropertySet::_update_cache() { //not super efficient.. Variant v; - if (basic_type == Variant::INPUT_EVENT) { - InputEvent ev; - ev.type = event_type; - v = ev; - } else { - Variant::CallError ce; - v = Variant::construct(basic_type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(basic_type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -1271,6 +1256,7 @@ void VisualScriptPropertySet::set_property(const StringName &p_type) { return; property = p_type; + index = StringName(); _update_cache(); _change_notify(); ports_changed_notify(); @@ -1320,33 +1306,58 @@ Dictionary VisualScriptPropertySet::_get_type_cache() const { return type_cache; } +void VisualScriptPropertySet::set_index(const StringName &p_type) { + + if (index == p_type) + return; + index = p_type; + _update_cache(); + _change_notify(); + ports_changed_notify(); +} + +StringName VisualScriptPropertySet::get_index() const { + + return index; +} + +void VisualScriptPropertySet::set_assign_op(AssignOp p_op) { + + ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX); + if (assign_op == p_op) + return; + + assign_op = p_op; + _update_cache(); + _change_notify(); + ports_changed_notify(); +} + +VisualScriptPropertySet::AssignOp VisualScriptPropertySet::get_assign_op() const { + return assign_op; +} + void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { - if (property.name == "property/base_type") { + if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; } } - if (property.name == "property/base_script") { + if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = 0; } } - if (property.name == "property/basic_type") { + if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { property.usage = 0; } } - if (property.name == "property/event_type") { - if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } - - if (property.name == "property/node_path") { + if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { @@ -1359,7 +1370,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } } - if (property.name == "property/property") { + if (property.name == "property") { if (call_mode == CALL_MODE_BASIC_TYPE) { @@ -1368,7 +1379,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; - property.hint_string = itos(get_visual_script()->get_instance_ID()); + property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_INSTANCE) { property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; property.hint_string = base_type; @@ -1385,7 +1396,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (script.is_valid()) { property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; - property.hint_string = itos(script->get_instance_ID()); + property.hint_string = itos(script->get_instance_id()); } } } @@ -1394,13 +1405,31 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { Node *node = _get_base_node(); if (node) { property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE; - property.hint_string = itos(node->get_instance_ID()); + property.hint_string = itos(node->get_instance_id()); } else { property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; property.hint_string = get_base_type(); } } } + + if (property.name == "index") { + + Variant::CallError ce; + Variant v = Variant::construct(type_cache.type, NULL, 0, ce); + List<PropertyInfo> plist; + v.get_property_list(&plist); + String options = ""; + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + options += "," + E->get().name; + } + + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = options; + property.type = Variant::STRING; + if (options == "") + property.usage = 0; //hide if type has no usable index + } } void VisualScriptPropertySet::_bind_methods() { @@ -1417,9 +1446,6 @@ void VisualScriptPropertySet::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertySet::_set_type_cache); ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertySet::_get_type_cache); - ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertySet::set_event_type); - ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertySet::get_event_type); - ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertySet::set_property); ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertySet::get_property); @@ -1429,6 +1455,12 @@ void VisualScriptPropertySet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptPropertySet::set_base_path); ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptPropertySet::get_base_path); + ClassDB::bind_method(D_METHOD("set_index", "index"), &VisualScriptPropertySet::set_index); + ClassDB::bind_method(D_METHOD("get_index"), &VisualScriptPropertySet::get_index); + + ClassDB::bind_method(D_METHOD("set_assign_op", "assign_op"), &VisualScriptPropertySet::set_assign_op); + ClassDB::bind_method(D_METHOD("get_assign_op"), &VisualScriptPropertySet::get_assign_op); + String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (i > 0) @@ -1437,14 +1469,6 @@ void VisualScriptPropertySet::_bind_methods() { bt += Variant::get_type_name(Variant::Type(i)); } - String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - if (i > 0) - et += ","; - - et += event_type_names[i]; - } - List<String> script_extensions; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); @@ -1457,15 +1481,15 @@ void VisualScriptPropertySet::_bind_methods() { script_ext_hint += "*." + E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property"); - + ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "index"), "set_index", "get_index"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "assign_op", PROPERTY_HINT_ENUM, "Assign,Add,Sub,Mul,Div,Mod,ShiftLeft,ShiftRight,BitAnd,BitOr,Bitxor"), "set_assign_op", "get_assign_op"); BIND_CONSTANT(CALL_MODE_SELF); BIND_CONSTANT(CALL_MODE_NODE_PATH); BIND_CONSTANT(CALL_MODE_INSTANCE); @@ -1479,11 +1503,72 @@ public: VisualScriptPropertySet *node; VisualScriptInstance *instance; + VisualScriptPropertySet::AssignOp assign_op; + StringName index; + bool needs_get; //virtual int get_working_memory_size() const { return 0; } //virtual bool is_output_port_unsequenced(int p_idx) const { return false; } //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } + _FORCE_INLINE_ void _process_get(Variant &source, const Variant &p_argument, bool &valid) { + + if (index != StringName() && assign_op == VisualScriptPropertySet::ASSIGN_OP_NONE) { + source.set_named(index, p_argument, &valid); + } else { + + Variant value; + if (index != StringName()) { + value = source.get_named(index, &valid); + } else { + value = source; + } + + switch (assign_op) { + case VisualScriptPropertySet::ASSIGN_OP_NONE: { + //should never get here + } break; + case VisualScriptPropertySet::ASSIGN_OP_ADD: { + value = Variant::evaluate(Variant::OP_ADD, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_SUB: { + value = Variant::evaluate(Variant::OP_SUBSTRACT, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_MUL: { + value = Variant::evaluate(Variant::OP_MULTIPLY, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_DIV: { + value = Variant::evaluate(Variant::OP_DIVIDE, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_MOD: { + value = Variant::evaluate(Variant::OP_MODULE, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_SHIFT_LEFT: { + value = Variant::evaluate(Variant::OP_SHIFT_LEFT, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_SHIFT_RIGHT: { + value = Variant::evaluate(Variant::OP_SHIFT_RIGHT, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_BIT_AND: { + value = Variant::evaluate(Variant::OP_BIT_AND, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_BIT_OR: { + value = Variant::evaluate(Variant::OP_BIT_OR, value, p_argument); + } break; + case VisualScriptPropertySet::ASSIGN_OP_BIT_XOR: { + value = Variant::evaluate(Variant::OP_BIT_XOR, value, p_argument); + } break; + default: {} + } + + if (index != StringName()) { + source.set_named(index, value, &valid); + } else { + source = value; + } + } + } + virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { switch (call_mode) { @@ -1494,7 +1579,13 @@ public: bool valid; - object->set(property, *p_inputs[0], &valid); + if (needs_get) { + Variant value = object->get(property, &valid); + _process_get(value, *p_inputs[0], valid); + object->set(property, value, &valid); + } else { + object->set(property, *p_inputs[0], &valid); + } if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -1519,7 +1610,14 @@ public: bool valid; - another->set(property, *p_inputs[0], &valid); + if (needs_get) { + + Variant value = another->get(property, &valid); + _process_get(value, *p_inputs[0], valid); + another->set(property, value, &valid); + } else { + another->set(property, *p_inputs[0], &valid); + } if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -1534,7 +1632,14 @@ public: bool valid; - v.set(property, *p_inputs[1], &valid); + if (needs_get) { + Variant value = v.get_named(property, &valid); + _process_get(value, *p_inputs[1], valid); + v.set_named(property, value, &valid); + + } else { + v.set_named(property, *p_inputs[1], &valid); + } if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -1557,6 +1662,9 @@ VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance instance->property = property; instance->call_mode = call_mode; instance->node_path = base_path; + instance->assign_op = assign_op; + instance->index = index; + instance->needs_get = index != StringName() || assign_op != ASSIGN_OP_NONE; return instance; } @@ -1570,10 +1678,10 @@ VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(Ty } VisualScriptPropertySet::VisualScriptPropertySet() { + assign_op = ASSIGN_OP_NONE; call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; - event_type = InputEvent::NONE; } template <VisualScriptPropertySet::CallMode cmode> @@ -1695,6 +1803,15 @@ PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const { + if (index != StringName()) { + + Variant v; + Variant::CallError ce; + v = Variant::construct(type_cache, NULL, 0, ce); + Variant i = v.get(index); + return PropertyInfo(i.get_type(), "value." + String(index)); + } + return PropertyInfo(type_cache, "value"); } @@ -1763,14 +1880,8 @@ void VisualScriptPropertyGet::_update_cache() { //not super efficient.. Variant v; - if (basic_type == Variant::INPUT_EVENT) { - InputEvent ev; - ev.type = event_type; - v = ev; - } else { - Variant::CallError ce; - v = Variant::construct(basic_type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(basic_type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -1918,59 +2029,51 @@ Variant::Type VisualScriptPropertyGet::get_basic_type() const { return basic_type; } -void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) { - - if (event_type == p_type) - return; - event_type = p_type; - if (call_mode == CALL_MODE_BASIC_TYPE) { - _update_cache(); - } - _change_notify(); - _update_base_type(); - ports_changed_notify(); +void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { + type_cache = p_type; } -InputEvent::Type VisualScriptPropertyGet::get_event_type() const { +Variant::Type VisualScriptPropertyGet::_get_type_cache() const { - return event_type; + return type_cache; } -void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { - type_cache = p_type; +void VisualScriptPropertyGet::set_index(const StringName &p_type) { + + if (index == p_type) + return; + index = p_type; + _update_cache(); + _change_notify(); + ports_changed_notify(); } -Variant::Type VisualScriptPropertyGet::_get_type_cache() const { +StringName VisualScriptPropertyGet::get_index() const { - return type_cache; + return index; } void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { - if (property.name == "property/base_type") { + if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; } } - if (property.name == "property/base_script") { + if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = 0; } } - if (property.name == "property/basic_type") { + if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { property.usage = 0; } } - if (property.name == "property/event_type") { - if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } - if (property.name == "property/node_path") { + if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { @@ -1983,7 +2086,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } } - if (property.name == "property/property") { + if (property.name == "property") { if (call_mode == CALL_MODE_BASIC_TYPE) { @@ -1992,7 +2095,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) { property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; - property.hint_string = itos(get_visual_script()->get_instance_ID()); + property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_INSTANCE) { property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; property.hint_string = base_type; @@ -2009,7 +2112,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (script.is_valid()) { property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; - property.hint_string = itos(script->get_instance_ID()); + property.hint_string = itos(script->get_instance_id()); } } } @@ -2017,13 +2120,31 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { Node *node = _get_base_node(); if (node) { property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE; - property.hint_string = itos(node->get_instance_ID()); + property.hint_string = itos(node->get_instance_id()); } else { property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; property.hint_string = get_base_type(); } } } + + if (property.name == "index") { + + Variant::CallError ce; + Variant v = Variant::construct(type_cache, NULL, 0, ce); + List<PropertyInfo> plist; + v.get_property_list(&plist); + String options = ""; + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + options += "," + E->get().name; + } + + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = options; + property.type = Variant::STRING; + if (options == "") + property.usage = 0; //hide if type has no usable index + } } void VisualScriptPropertyGet::_bind_methods() { @@ -2040,9 +2161,6 @@ void VisualScriptPropertyGet::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertyGet::_set_type_cache); ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertyGet::_get_type_cache); - ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertyGet::set_event_type); - ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertyGet::get_event_type); - ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertyGet::set_property); ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertyGet::get_property); @@ -2052,6 +2170,9 @@ void VisualScriptPropertyGet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptPropertyGet::set_base_path); ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptPropertyGet::get_base_path); + ClassDB::bind_method(D_METHOD("set_index", "index"), &VisualScriptPropertyGet::set_index); + ClassDB::bind_method(D_METHOD("get_index"), &VisualScriptPropertyGet::get_index); + String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (i > 0) @@ -2060,14 +2181,6 @@ void VisualScriptPropertyGet::_bind_methods() { bt += Variant::get_type_name(Variant::Type(i)); } - String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - if (i > 0) - et += ","; - - et += event_type_names[i]; - } - List<String> script_extensions; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); @@ -2080,14 +2193,14 @@ void VisualScriptPropertyGet::_bind_methods() { script_ext_hint += "." + E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "index", PROPERTY_HINT_ENUM), "set_index", "get_index"); BIND_CONSTANT(CALL_MODE_SELF); BIND_CONSTANT(CALL_MODE_NODE_PATH); @@ -2099,6 +2212,7 @@ public: VisualScriptPropertyGet::CallMode call_mode; NodePath node_path; StringName property; + StringName index; VisualScriptPropertyGet *node; VisualScriptInstance *instance; @@ -2115,6 +2229,10 @@ public: *p_outputs[0] = object->get(property, &valid); + if (index != StringName()) { + *p_outputs[0] = p_outputs[0]->get_named(index); + } + if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("Invalid index property name."); @@ -2141,6 +2259,10 @@ public: *p_outputs[0] = another->get(property, &valid); + if (index != StringName()) { + *p_outputs[0] = p_outputs[0]->get_named(index); + } + if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = vformat(RTR("Invalid index property name '%s' in node %s."), String(property), another->get_name()); @@ -2154,6 +2276,9 @@ public: Variant v = *p_inputs[0]; *p_outputs[0] = v.get(property, &valid); + if (index != StringName()) { + *p_outputs[0] = p_outputs[0]->get_named(index); + } if (!valid) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -2174,6 +2299,7 @@ VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance instance->property = property; instance->call_mode = call_mode; instance->node_path = base_path; + instance->index = index; return instance; } @@ -2183,7 +2309,6 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; - event_type = InputEvent::NONE; type_cache = Variant::NIL; } @@ -2278,7 +2403,7 @@ StringName VisualScriptEmitSignal::get_signal() const { void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "signal/signal") { + if (property.name == "signal") { property.hint = PROPERTY_HINT_ENUM; List<StringName> sigs; @@ -2306,7 +2431,7 @@ void VisualScriptEmitSignal::_bind_methods() { ClassDB::bind_method(D_METHOD("set_signal", "name"), &VisualScriptEmitSignal::set_signal); ClassDB::bind_method(D_METHOD("get_signal"), &VisualScriptEmitSignal::get_signal); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal/signal"), "set_signal", "get_signal"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal"), "set_signal", "get_signal"); } class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance { diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 3f82edc5f0..3b38d0d08f 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 */ @@ -69,7 +70,7 @@ private: MethodInfo method_cache; void _update_method_cache(); - void _set_argument_cache(const Dictionary &p_args); + void _set_argument_cache(const Dictionary &p_cache); Dictionary _get_argument_cache() const; protected: @@ -145,6 +146,21 @@ public: }; + enum AssignOp { + ASSIGN_OP_NONE, + ASSIGN_OP_ADD, + ASSIGN_OP_SUB, + ASSIGN_OP_MUL, + ASSIGN_OP_DIV, + ASSIGN_OP_MOD, + ASSIGN_OP_SHIFT_LEFT, + ASSIGN_OP_SHIFT_RIGHT, + ASSIGN_OP_BIT_AND, + ASSIGN_OP_BIT_OR, + ASSIGN_OP_BIT_XOR, + ASSIGN_OP_MAX + }; + private: PropertyInfo type_cache; @@ -154,7 +170,8 @@ private: String base_script; NodePath base_path; StringName property; - InputEvent::Type event_type; + StringName index; + AssignOp assign_op; Node *_get_base_node() const; StringName _get_base_type() const; @@ -166,6 +183,8 @@ private: void _set_type_cache(const Dictionary &p_type); Dictionary _get_type_cache() const; + void _adjust_input_index(PropertyInfo &pinfo) const; + protected: virtual void _validate_property(PropertyInfo &property) const; @@ -196,9 +215,6 @@ public: void set_basic_type(Variant::Type p_type); Variant::Type get_basic_type() const; - void set_event_type(InputEvent::Type p_type); - InputEvent::Type get_event_type() const; - void set_property(const StringName &p_type); StringName get_property() const; @@ -208,6 +224,12 @@ public: void set_call_mode(CallMode p_mode); CallMode get_call_mode() const; + void set_index(const StringName &p_type); + StringName get_index() const; + + void set_assign_op(AssignOp p_op); + AssignOp get_assign_op() const; + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; @@ -215,6 +237,7 @@ public: }; VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode); +VARIANT_ENUM_CAST(VisualScriptPropertySet::AssignOp); class VisualScriptPropertyGet : public VisualScriptNode { @@ -237,7 +260,7 @@ private: String base_script; NodePath base_path; StringName property; - InputEvent::Type event_type; + StringName index; void _update_base_type(); Node *_get_base_node() const; @@ -278,9 +301,6 @@ public: void set_basic_type(Variant::Type p_type); Variant::Type get_basic_type() const; - void set_event_type(InputEvent::Type p_type); - InputEvent::Type get_event_type() const; - void set_property(const StringName &p_type); StringName get_property() const; @@ -290,6 +310,9 @@ public: void set_call_mode(CallMode p_mode); CallMode get_call_mode() const; + void set_index(const StringName &p_type); + StringName get_index() const; + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); VisualScriptPropertyGet(); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 68bd1e6d4c..4f9cd4a33b 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 */ @@ -28,12 +29,12 @@ /*************************************************************************/ #include "visual_script_nodes.h" -#include "global_config.h" #include "global_constants.h" #include "os/input.h" #include "os/os.h" +#include "project_settings.h" #include "scene/main/node.h" -#include "scene/main/scene_main_loop.h" +#include "scene/main/scene_tree.h" ////////////////////////////////////////// ////////////////FUNCTION////////////////// @@ -58,10 +59,10 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value _change_notify(); return true; } - if (String(p_name).begins_with("argument/")) { - int idx = String(p_name).get_slice("/", 1).to_int() - 1; + if (String(p_name).begins_with("argument_")) { + int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1; ERR_FAIL_INDEX_V(idx, arguments.size(), false); - String what = String(p_name).get_slice("/", 2); + String what = String(p_name).get_slice("/", 1); if (what == "type") { Variant::Type new_type = Variant::Type(int(p_value)); @@ -94,6 +95,12 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value return true; } + if (p_name == "sequenced/sequenced") { + sequenced = p_value; + ports_changed_notify(); + return true; + } + return false; } @@ -103,10 +110,10 @@ bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const r_ret = arguments.size(); return true; } - if (String(p_name).begins_with("argument/")) { - int idx = String(p_name).get_slice("/", 1).to_int() - 1; + if (String(p_name).begins_with("argument_")) { + int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1; ERR_FAIL_INDEX_V(idx, arguments.size(), false); - String what = String(p_name).get_slice("/", 2); + String what = String(p_name).get_slice("/", 1); if (what == "type") { r_ret = arguments[idx].type; return true; @@ -132,6 +139,11 @@ bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const return true; } + if (p_name == "sequenced/sequenced") { + r_ret = sequenced; + return true; + } + return false; } void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { @@ -143,9 +155,12 @@ void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const } for (int i = 0; i < arguments.size(); i++) { - p_list->push_back(PropertyInfo(Variant::INT, "argument/" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt)); - p_list->push_back(PropertyInfo(Variant::STRING, "argument/" + itos(i + 1) + "/name")); + p_list->push_back(PropertyInfo(Variant::INT, "argument_" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt)); + p_list->push_back(PropertyInfo(Variant::STRING, "argument_" + itos(i + 1) + "/name")); } + + p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced/sequenced")); + if (!stack_less) { p_list->push_back(PropertyInfo(Variant::INT, "stack/size", PROPERTY_HINT_RANGE, "1,100000")); } @@ -301,6 +316,7 @@ VisualScriptFunction::VisualScriptFunction() { stack_size = 256; stack_less = false; + sequenced = true; rpc_mode = ScriptInstance::RPC_MODE_DISABLED; } @@ -313,6 +329,16 @@ bool VisualScriptFunction::is_stack_less() const { return stack_less; } +void VisualScriptFunction::set_sequenced(bool p_enable) { + + sequenced = p_enable; +} + +bool VisualScriptFunction::is_sequenced() const { + + return sequenced; +} + void VisualScriptFunction::set_stack_size(int p_size) { ERR_FAIL_COND(p_size < 1 || p_size > 100000); @@ -558,8 +584,8 @@ void VisualScriptOperator::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "operator_value/type", PROPERTY_HINT_ENUM, types), "set_operator", "get_operator"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "typed_value/typed", PROPERTY_HINT_ENUM, argt), "set_typed", "get_typed"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, types), "set_operator", "get_operator"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_typed", "get_typed"); } class VisualScriptNodeInstanceOperator : public VisualScriptNodeInstance { @@ -620,6 +646,113 @@ static Ref<VisualScriptNode> create_op_node(const String &p_name) { } ////////////////////////////////////////// +////////////////OPERATOR////////////////// +////////////////////////////////////////// + +int VisualScriptSelect::get_output_sequence_port_count() const { + + return 0; +} + +bool VisualScriptSelect::has_input_sequence_port() const { + + return false; +} + +int VisualScriptSelect::get_input_value_port_count() const { + + return 3; +} +int VisualScriptSelect::get_output_value_port_count() const { + + return 1; +} + +String VisualScriptSelect::get_output_sequence_port_text(int p_port) const { + + return String(); +} + +PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { + + if (p_idx == 0) { + return PropertyInfo(Variant::BOOL, "cond"); + } else if (p_idx == 1) { + return PropertyInfo(typed, "a"); + } else { + return PropertyInfo(typed, "b"); + } +} +PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { + + return PropertyInfo(typed, "out"); +} + +String VisualScriptSelect::get_caption() const { + + return "Select"; +} + +String VisualScriptSelect::get_text() const { + + return "a if cond, else b"; +} + +void VisualScriptSelect::set_typed(Variant::Type p_op) { + + if (typed == p_op) + return; + + typed = p_op; + ports_changed_notify(); +} + +Variant::Type VisualScriptSelect::get_typed() const { + + return typed; +} + +void VisualScriptSelect::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptSelect::set_typed); + ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptSelect::get_typed); + + String argt = "Any"; + for (int i = 1; i < Variant::VARIANT_MAX; i++) { + argt += "," + Variant::get_type_name(Variant::Type(i)); + } + + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_typed", "get_typed"); +} + +class VisualScriptNodeInstanceSelect : public VisualScriptNodeInstance { +public: + //virtual int get_working_memory_size() const { return 0; } + + virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { + + bool cond = *p_inputs[0]; + if (cond) + *p_outputs[0] = *p_inputs[1]; + else + *p_outputs[0] = *p_inputs[2]; + + return 0; + } +}; + +VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) { + + VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect); + return instance; +} + +VisualScriptSelect::VisualScriptSelect() { + + typed = Variant::NIL; +} + +////////////////////////////////////////// ////////////////VARIABLE GET////////////////// ////////////////////////////////////////// @@ -690,7 +823,7 @@ StringName VisualScriptVariableGet::get_variable() const { void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { - if (property.name == "variable/name" && get_visual_script().is_valid()) { + if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; vs->get_variable_list(&vars); @@ -713,7 +846,7 @@ void VisualScriptVariableGet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableGet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableGet::get_variable); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable/name"), "set_variable", "get_variable"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable"); } class VisualScriptNodeInstanceVariableGet : public VisualScriptNodeInstance { @@ -815,7 +948,7 @@ StringName VisualScriptVariableSet::get_variable() const { void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { - if (property.name == "variable/name" && get_visual_script().is_valid()) { + if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; vs->get_variable_list(&vars); @@ -838,7 +971,7 @@ void VisualScriptVariableSet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableSet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableSet::get_variable); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable/name"), "set_variable", "get_variable"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable"); } class VisualScriptNodeInstanceVariableSet : public VisualScriptNodeInstance { @@ -955,7 +1088,7 @@ Variant VisualScriptConstant::get_constant_value() const { void VisualScriptConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant/value") { + if (property.name == "value") { property.type = type; if (type == Variant::NIL) property.usage = 0; //do not save if nil @@ -975,8 +1108,8 @@ void VisualScriptConstant::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "constant/type", PROPERTY_HINT_ENUM, argt), "set_constant_type", "get_constant_type"); - ADD_PROPERTY(PropertyInfo(Variant::NIL, "constant/value"), "set_constant_value", "get_constant_value"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_constant_type", "get_constant_type"); + ADD_PROPERTY(PropertyInfo(Variant::NIL, "value"), "set_constant_value", "get_constant_value"); } class VisualScriptNodeInstanceConstant : public VisualScriptNodeInstance { @@ -1075,6 +1208,7 @@ void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { preload = p_preload; ports_changed_notify(); } + Ref<Resource> VisualScriptPreload::get_preload() const { return preload; @@ -1359,7 +1493,7 @@ void VisualScriptGlobalConstant::_bind_methods() { cc += ","; cc += GlobalConstants::get_global_constant_name(i); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant/constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { @@ -1464,7 +1598,7 @@ VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstan void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { + if (property.name == "constant/constant") { List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -1488,7 +1622,7 @@ void VisualScriptClassConstant::_bind_methods() { ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptClassConstant::get_base_type); ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_class_constant", "get_class_constant"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/constant", PROPERTY_HINT_ENUM, ""), "set_class_constant", "get_class_constant"); } VisualScriptClassConstant::VisualScriptClassConstant() { @@ -1593,7 +1727,7 @@ VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptIn void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { + if (property.name == "constant/constant") { List<StringName> constants; Variant::get_numeric_constants_for_type(type, &constants); @@ -1626,7 +1760,7 @@ void VisualScriptBasicTypeConstant::_bind_methods() { } ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, argt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_basic_type_constant", "get_basic_type_constant"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/constant", PROPERTY_HINT_ENUM, ""), "set_basic_type_constant", "get_basic_type_constant"); } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { @@ -1747,7 +1881,7 @@ void VisualScriptMathConstant::_bind_methods() { cc += ","; cc += const_name[i]; } - ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant/constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); } VisualScriptMathConstant::VisualScriptMathConstant() { @@ -1831,17 +1965,17 @@ public: VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); - instance->singleton = GlobalConfig::get_singleton()->get_singleton_object(singleton); + instance->singleton = ProjectSettings::get_singleton()->get_singleton_object(singleton); return instance; } VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const { - Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton); + Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); TypeGuess tg; tg.type = Variant::OBJECT; if (obj) { - tg.GDCLASS = obj->get_class(); + tg.gdclass = obj->get_class(); tg.script = obj->get_script(); } @@ -1855,11 +1989,11 @@ void VisualScriptEngineSingleton::_bind_methods() { String cc; - List<GlobalConfig::Singleton> singletons; + List<ProjectSettings::Singleton> singletons; - GlobalConfig::get_singleton()->get_singletons(&singletons); + ProjectSettings::get_singleton()->get_singletons(&singletons); - for (List<GlobalConfig::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + for (List<ProjectSettings::Singleton>::Element *E = singletons.front(); E; E = E->next()) { if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") continue; //skip these, too simple named @@ -1868,7 +2002,7 @@ void VisualScriptEngineSingleton::_bind_methods() { cc += E->get().name; } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, cc), "set_singleton", "get_singleton"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/constant", PROPERTY_HINT_ENUM, cc), "set_singleton", "get_singleton"); } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { @@ -2001,7 +2135,7 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; - tg.GDCLASS = "Node"; + tg.gdclass = "Node"; #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); @@ -2030,7 +2164,7 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu Node *another = script_node->get_node(path); if (another) { - tg.GDCLASS = another->get_class(); + tg.gdclass = another->get_class(); tg.script = another->get_script(); } #endif @@ -2172,7 +2306,7 @@ VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGu TypeGuess tg; tg.type = Variant::OBJECT; - tg.GDCLASS = "SceneTree"; + tg.gdclass = "SceneTree"; return tg; } @@ -2352,13 +2486,13 @@ VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inp VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; - tg.GDCLASS = "Object"; + tg.gdclass = "Object"; Ref<Script> script = get_visual_script(); if (!script.is_valid()) return tg; - tg.GDCLASS = script->get_instance_base_type(); + tg.gdclass = script->get_instance_base_type(); tg.script = script; return tg; @@ -2488,10 +2622,10 @@ public: in_values.resize(in_count); for (int i = 0; i < in_count; i++) { - in_values[i] = p_inputs[i]; + in_values[i] = *p_inputs[i]; } - out_values.resize(in_count); + out_values.resize(out_count); work_mem.resize(work_mem_size); @@ -2537,6 +2671,7 @@ VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode); instance->instance = p_instance; + instance->node = this; instance->in_count = get_input_value_port_count(); instance->out_count = get_output_value_port_count(); @@ -2549,6 +2684,10 @@ VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance return instance; } +void VisualScriptCustomNode::_script_changed() { + ports_changed_notify(); +} + void VisualScriptCustomNode::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count")); @@ -2571,6 +2710,8 @@ void VisualScriptCustomNode::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::INT, "_get_working_memory_size")); BIND_VMETHOD(MethodInfo(Variant::NIL, "_step:Variant", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem"))); + ClassDB::bind_method(D_METHOD("_script_changed"), &VisualScriptCustomNode::_script_changed); + BIND_CONSTANT(START_MODE_BEGIN_SEQUENCE); BIND_CONSTANT(START_MODE_CONTINUE_SEQUENCE); BIND_CONSTANT(START_MODE_RESUME_YIELD); @@ -2583,6 +2724,7 @@ void VisualScriptCustomNode::_bind_methods() { } VisualScriptCustomNode::VisualScriptCustomNode() { + connect("script_changed", this, "_script_changed"); } ////////////////////////////////////////// @@ -2682,7 +2824,7 @@ public: r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; return 0; } - *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error_str); + *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error); return 0; } }; @@ -2703,7 +2845,7 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_ void VisualScriptSubCall::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments:Variant"))); + BIND_VMETHOD(MethodInfo(Variant::NIL, "_subcall:Variant", PropertyInfo(Variant::NIL, "arguments:Variant"))); } VisualScriptSubCall::VisualScriptSubCall() { @@ -3087,8 +3229,8 @@ void VisualScriptLocalVar::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable/name"), "set_var_name", "get_var_name"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "variable/type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_var_name", "get_var_name"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type"); } VisualScriptLocalVar::VisualScriptLocalVar() { @@ -3209,8 +3351,8 @@ void VisualScriptLocalVarSet::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable/name"), "set_var_name", "get_var_name"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "variable/type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_var_name", "get_var_name"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type"); } VisualScriptLocalVarSet::VisualScriptLocalVarSet() { @@ -3252,32 +3394,33 @@ PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::BOOL, "pressed"); -} - -String VisualScriptInputAction::get_caption() const { - - return "Action"; -} - -String VisualScriptInputAction::get_text() const { - + String mstr; switch (mode) { case MODE_PRESSED: { - return name; + mstr = "pressed"; } break; case MODE_RELEASED: { - return "not " + name; + mstr = "not pressed"; } break; case MODE_JUST_PRESSED: { - return String(name) + " " + TTR("just pressed"); + mstr = "just pressed"; } break; case MODE_JUST_RELEASED: { - return String(name) + " " + TTR("just released"); + mstr = "just released"; } break; } - return String(); + return PropertyInfo(Variant::BOOL, mstr); +} + +String VisualScriptInputAction::get_caption() const { + + return "Action"; +} + +String VisualScriptInputAction::get_text() const { + + return name; } String VisualScriptInputAction::get_category() const { @@ -3318,8 +3461,6 @@ public: StringName action; VisualScriptInputAction::Mode mode; - virtual int get_working_memory_size() const { return 1; } - virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { switch (mode) { @@ -3359,7 +3500,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { String actions; List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); + ProjectSettings::get_singleton()->get_property_list(&pinfo); Vector<String> al; for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { @@ -3459,14 +3600,8 @@ void VisualScriptDeconstruct::_update_elements() { elements.clear(); Variant v; - if (type == Variant::INPUT_EVENT) { - InputEvent ie; - ie.type = input_type; - v = ie; - } else { - Variant::CallError ce; - v = Variant::construct(type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -3496,21 +3631,6 @@ Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { return type; } -void VisualScriptDeconstruct::set_deconstruct_input_type(InputEvent::Type p_input_type) { - - if (input_type == p_input_type) - return; - - input_type = p_input_type; - _update_elements(); - ports_changed_notify(); -} - -InputEvent::Type VisualScriptDeconstruct::get_deconstruct_input_type() const { - - return input_type; -} - void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { ERR_FAIL_COND(p_elements.size() % 2 == 1); @@ -3569,12 +3689,6 @@ VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance } void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const { - - if (property.name == "input_type") { - if (type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } } void VisualScriptDeconstruct::_bind_methods() { @@ -3582,9 +3696,6 @@ void VisualScriptDeconstruct::_bind_methods() { ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type); ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type); - ClassDB::bind_method(D_METHOD("set_deconstruct_input_type", "input_type"), &VisualScriptDeconstruct::set_deconstruct_input_type); - ClassDB::bind_method(D_METHOD("get_deconstruct_input_type"), &VisualScriptDeconstruct::get_deconstruct_input_type); - ClassDB::bind_method(D_METHOD("_set_elem_cache", "_cache"), &VisualScriptDeconstruct::_set_elem_cache); ClassDB::bind_method(D_METHOD("_get_elem_cache"), &VisualScriptDeconstruct::_get_elem_cache); @@ -3593,17 +3704,13 @@ void VisualScriptDeconstruct::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - String iet = "None,Key,MouseMotion,MouseButton,JoypadMotion,JoypadButton,ScreenTouch,ScreenDrag,Action"; - ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_deconstruct_type", "get_deconstruct_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "input_type", PROPERTY_HINT_ENUM, iet), "set_deconstruct_input_type", "get_deconstruct_input_type"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_elem_cache", "_get_elem_cache"); } VisualScriptDeconstruct::VisualScriptDeconstruct() { type = Variant::NIL; - input_type = InputEvent::NONE; } void register_visual_script_nodes() { @@ -3621,11 +3728,11 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("data/preload", create_node_generic<VisualScriptPreload>); VisualScriptLanguage::singleton->add_register_func("data/action", create_node_generic<VisualScriptInputAction>); - VisualScriptLanguage::singleton->add_register_func("constants/constant", create_node_generic<VisualScriptConstant>); - VisualScriptLanguage::singleton->add_register_func("constants/math_constant", create_node_generic<VisualScriptMathConstant>); - VisualScriptLanguage::singleton->add_register_func("constants/class_constant", create_node_generic<VisualScriptClassConstant>); - VisualScriptLanguage::singleton->add_register_func("constants/global_constant", create_node_generic<VisualScriptGlobalConstant>); - VisualScriptLanguage::singleton->add_register_func("constants/basic_type_constant", create_node_generic<VisualScriptBasicTypeConstant>); + VisualScriptLanguage::singleton->add_register_func("constant/constants/constant", create_node_generic<VisualScriptConstant>); + VisualScriptLanguage::singleton->add_register_func("constant/constants/math_constant", create_node_generic<VisualScriptMathConstant>); + VisualScriptLanguage::singleton->add_register_func("constant/constants/class_constant", create_node_generic<VisualScriptClassConstant>); + VisualScriptLanguage::singleton->add_register_func("constant/constants/global_constant", create_node_generic<VisualScriptGlobalConstant>); + VisualScriptLanguage::singleton->add_register_func("constant/constants/basic_type_constant", create_node_generic<VisualScriptBasicTypeConstant>); VisualScriptLanguage::singleton->add_register_func("custom/custom_node", create_node_generic<VisualScriptCustomNode>); VisualScriptLanguage::singleton->add_register_func("custom/sub_call", create_node_generic<VisualScriptSubCall>); @@ -3661,6 +3768,7 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("operators/logic/xor", create_op_node<Variant::OP_XOR>); VisualScriptLanguage::singleton->add_register_func("operators/logic/not", create_op_node<Variant::OP_NOT>); VisualScriptLanguage::singleton->add_register_func("operators/logic/in", create_op_node<Variant::OP_IN>); + VisualScriptLanguage::singleton->add_register_func("operators/logic/select", create_node_generic<VisualScriptSelect>); VisualScriptLanguage::singleton->add_register_func("functions/deconstruct", create_node_generic<VisualScriptDeconstruct>); diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index b2fc115660..6ce906efe0 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 */ @@ -45,6 +46,7 @@ class VisualScriptFunction : public VisualScriptNode { bool stack_less; int stack_size; ScriptInstance::RPCMode rpc_mode; + bool sequenced; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -78,9 +80,18 @@ public: void set_stack_less(bool p_enable); bool is_stack_less() const; + void set_sequenced(bool p_enable); + bool is_sequenced() const; + void set_stack_size(int p_size); int get_stack_size() const; + void set_return_type_enabled(bool p_returns); + bool is_return_type_enabled() const; + + void set_return_type(Variant::Type p_type); + Variant::Type get_return_type() const; + void set_rpc_mode(ScriptInstance::RPCMode p_mode); ScriptInstance::RPCMode get_rpc_mode() const; @@ -126,6 +137,39 @@ public: VisualScriptOperator(); }; +class VisualScriptSelect : public VisualScriptNode { + + GDCLASS(VisualScriptSelect, VisualScriptNode) + + Variant::Type typed; + +protected: + static void _bind_methods(); + +public: + virtual int get_output_sequence_port_count() const; + virtual bool has_input_sequence_port() const; + + virtual String get_output_sequence_port_text(int p_port) const; + + virtual int get_input_value_port_count() const; + virtual int get_output_value_port_count() const; + + virtual PropertyInfo get_input_value_port_info(int p_idx) const; + virtual PropertyInfo get_output_value_port_info(int p_idx) const; + + virtual String get_caption() const; + virtual String get_text() const; + virtual String get_category() const { return "operators"; } + + void set_typed(Variant::Type p_op); + Variant::Type get_typed() const; + + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + + VisualScriptSelect(); +}; + class VisualScriptVariableGet : public VisualScriptNode { GDCLASS(VisualScriptVariableGet, VisualScriptNode) @@ -152,7 +196,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_variable(StringName p_var); + void set_variable(StringName p_variable); StringName get_variable() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -186,7 +230,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_variable(StringName p_var); + void set_variable(StringName p_variable); StringName get_variable() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -257,7 +301,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_preload(const Ref<Resource> &p_value); + void set_preload(const Ref<Resource> &p_preload); Ref<Resource> get_preload() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -678,6 +722,8 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + void _script_changed(); + VisualScriptCustomNode(); }; @@ -922,7 +968,6 @@ class VisualScriptDeconstruct : public VisualScriptNode { void _update_elements(); Variant::Type type; - InputEvent::Type input_type; void _set_elem_cache(const Array &p_elements); Array _get_elem_cache() const; @@ -951,9 +996,6 @@ public: void set_deconstruct_type(Variant::Type p_type); Variant::Type get_deconstruct_type() const; - void set_deconstruct_input_type(InputEvent::Type p_input_type); - InputEvent::Type get_deconstruct_input_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); VisualScriptDeconstruct(); diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 919ced74b9..2e111511b7 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 */ @@ -30,7 +31,7 @@ #include "os/os.h" #include "scene/main/node.h" -#include "scene/main/scene_main_loop.h" +#include "scene/main/scene_tree.h" #include "visual_script_nodes.h" ////////////////////////////////////////// @@ -418,13 +419,13 @@ VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "signal/base_type") { + if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; } } - if (property.name == "signal/node_path") { + if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { @@ -437,7 +438,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { } } - if (property.name == "signal/signal") { + if (property.name == "signal") { property.hint = PROPERTY_HINT_ENUM; List<MethodInfo> methods; @@ -487,10 +488,10 @@ void VisualScriptYieldSignal::_bind_methods() { bt += Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "signal/call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance"), "set_call_mode", "get_call_mode"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal/base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "signal/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal/signal"), "set_signal", "get_signal"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance"), "set_call_mode", "get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal"), "set_signal", "get_signal"); BIND_CONSTANT(CALL_MODE_SELF); BIND_CONSTANT(CALL_MODE_NODE_PATH); 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/libvpx/SCsub b/modules/webm/libvpx/SCsub index 241d6e30cd..0ee2ed45b8 100644 --- a/modules/webm/libvpx/SCsub +++ b/modules/webm/libvpx/SCsub @@ -273,7 +273,7 @@ else: webm_cpu_x86 = True else: webm_cpu_x86 = not is_x11_or_server_arm and (cpu_bits == '32' or cpu_bits == '64') and (env["platform"] == 'windows' or env["platform"] == 'x11' or env["platform"] == 'osx' or env["platform"] == 'haiku' or is_android_x86 or is_ios_x86) - webm_cpu_arm = is_x11_or_server_arm or (not is_ios_x86 and env["platform"] == 'iphone') or env["platform"] == 'bb10' or (not is_android_x86 and env["platform"] == 'android') + webm_cpu_arm = is_x11_or_server_arm or (not is_ios_x86 and env["platform"] == 'iphone') or (not is_android_x86 and env["platform"] == 'android') if webm_cpu_x86: import subprocess 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..72f10b4f45 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 */ @@ -31,11 +32,12 @@ #include "OpusVorbisDecoder.hpp" #include "VPXDecoder.hpp" -#include "../theora/yuv2rgb.h" #include "mkvparser/mkvparser.h" -#include "global_config.h" #include "os/file_access.h" +#include "project_settings.h" + +#include "thirdparty/misc/yuv2rgb.h" #include <string.h> @@ -166,7 +168,7 @@ void VideoStreamPlaybackWebm::play() { stop(); - delay_compensation = GlobalConfig::get_singleton()->get("audio/video_delay_compensation_ms"); + delay_compensation = ProjectSettings::get_singleton()->get("audio/video_delay_compensation_ms"); delay_compensation /= 1000.0; playing = true; 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..87c2e811b3 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 */ @@ -36,23 +37,23 @@ #include <webp/decode.h> #include <webp/encode.h> -static PoolVector<uint8_t> _webp_lossy_pack(const Image &p_image, float p_quality) { +static PoolVector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quality) { - ERR_FAIL_COND_V(p_image.empty(), PoolVector<uint8_t>()); + ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), PoolVector<uint8_t>()); - Image img = p_image; - if (img.detect_alpha()) - img.convert(Image::FORMAT_RGBA8); + Ref<Image> img = p_image->duplicate(); + if (img->detect_alpha()) + img->convert(Image::FORMAT_RGBA8); else - img.convert(Image::FORMAT_RGB8); + img->convert(Image::FORMAT_RGB8); - Size2 s(img.get_width(), img.get_height()); - PoolVector<uint8_t> data = img.get_data(); + Size2 s(img->get_width(), img->get_height()); + PoolVector<uint8_t> data = img->get_data(); PoolVector<uint8_t>::Read r = data.read(); uint8_t *dst_buff = NULL; size_t dst_size = 0; - if (img.get_format() == Image::FORMAT_RGB8) { + if (img->get_format() == Image::FORMAT_RGB8) { dst_size = WebPEncodeRGB(r.ptr(), s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff); } else { @@ -73,22 +74,24 @@ static PoolVector<uint8_t> _webp_lossy_pack(const Image &p_image, float p_qualit return dst; } -static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { +static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { int size = p_buffer.size() - 4; - ERR_FAIL_COND_V(size <= 0, Image()); + ERR_FAIL_COND_V(size <= 0, Ref<Image>()); PoolVector<uint8_t>::Read r = p_buffer.read(); - ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Image()); + ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Ref<Image>()); WebPBitstreamFeatures features; if (WebPGetFeatures(&r[4], size, &features) != VP8_STATUS_OK) { ERR_EXPLAIN("Error unpacking WEBP image:"); - ERR_FAIL_V(Image()); + ERR_FAIL_V(Ref<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); @@ -104,14 +107,15 @@ static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { } //ERR_EXPLAIN("Error decoding webp! - "+p_file); - ERR_FAIL_COND_V(errdec, Image()); + ERR_FAIL_COND_V(errdec, Ref<Image>()); dst_w = PoolVector<uint8_t>::Write(); - return Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); + Ref<Image> img = memnew(Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image)); + return img; } -Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { +Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { uint32_t size = f->get_len(); PoolVector<uint8_t> src_image; @@ -129,9 +133,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(); @@ -155,7 +161,7 @@ Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { src_r = PoolVector<uint8_t>::Read(); dst_w = PoolVector<uint8_t>::Write(); - *p_image = Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); + p_image->create(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); return OK; } diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index ccf22bae13..1ac2196a71 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 */ @@ -37,7 +38,7 @@ class ImageLoaderWEBP : public ImageFormatLoader { public: - virtual Error load_image(Image *p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderWEBP(); }; 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 */ |