diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/cscript/SCsub | 5 | ||||
| -rw-r--r-- | modules/cscript/config.py | 11 | ||||
| -rw-r--r-- | modules/cscript/godot_c.cpp | 2 | ||||
| -rw-r--r-- | modules/cscript/godot_c.h | 568 | ||||
| -rw-r--r-- | modules/cscript/register_types.cpp | 37 | ||||
| -rw-r--r-- | modules/cscript/register_types.h | 30 | ||||
| -rw-r--r-- | modules/gdscript/gd_compiler.cpp | 24 | ||||
| -rw-r--r-- | modules/gdscript/gd_editor.cpp | 59 | ||||
| -rw-r--r-- | modules/gdscript/gd_function.cpp | 25 | ||||
| -rw-r--r-- | modules/gdscript/gd_function.h | 4 | ||||
| -rw-r--r-- | modules/gdscript/gd_functions.cpp | 1 | ||||
| -rw-r--r-- | modules/gdscript/gd_parser.cpp | 44 | ||||
| -rw-r--r-- | modules/gdscript/gd_parser.h | 2 | ||||
| -rw-r--r-- | modules/gdscript/gd_script.cpp | 18 | ||||
| -rw-r--r-- | modules/gdscript/gd_script.h | 2 | ||||
| -rw-r--r-- | modules/gdscript/gd_tokenizer.cpp | 1 | ||||
| -rw-r--r-- | modules/gdscript/register_types.cpp | 2 | ||||
| -rw-r--r-- | modules/gridmap/grid_map.cpp | 1 | ||||
| -rw-r--r-- | modules/ik/ik.cpp | 2 |
19 files changed, 752 insertions, 86 deletions
diff --git a/modules/cscript/SCsub b/modules/cscript/SCsub new file mode 100644 index 0000000000..403fe68f66 --- /dev/null +++ b/modules/cscript/SCsub @@ -0,0 +1,5 @@ +Import('env') + +env.add_source_files(env.modules_sources,"*.cpp") + +Export('env') diff --git a/modules/cscript/config.py b/modules/cscript/config.py new file mode 100644 index 0000000000..ea7e83378a --- /dev/null +++ b/modules/cscript/config.py @@ -0,0 +1,11 @@ + + +def can_build(platform): + return True + + +def configure(env): + pass + + + diff --git a/modules/cscript/godot_c.cpp b/modules/cscript/godot_c.cpp new file mode 100644 index 0000000000..d5c1b53dfe --- /dev/null +++ b/modules/cscript/godot_c.cpp @@ -0,0 +1,2 @@ +#include "godot_c.h" + diff --git a/modules/cscript/godot_c.h b/modules/cscript/godot_c.h new file mode 100644 index 0000000000..b0465d8524 --- /dev/null +++ b/modules/cscript/godot_c.h @@ -0,0 +1,568 @@ +#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_JOYSTICK_MOTION 4 +#define INPUT_EVENT_TYPE_JOYSTICK_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_joystick_motion_get_axis(godot_input_event p_event); +float GDAPI godot_input_event_joystick_motion_get_axis_value(godot_input_event p_event); + +int GDAPI godot_input_event_joystick_button_get_button_index(godot_input_event p_event); +godot_bool GDAPI godot_input_event_joystick_button_is_pressed(godot_input_event p_event); +float GDAPI godot_input_event_joystick_button_get_pressure(godot_input_event p_event); + + +int GDAPI godot_input_event_screen_touch_get_index(godot_input_event p_event); +int GDAPI godot_input_event_screen_touch_get_x(godot_input_event p_event); +int GDAPI godot_input_event_screen_touch_get_y(godot_input_event p_event); +int GDAPI godot_input_event_screen_touch_is_pressed(godot_input_event p_event); + +int GDAPI godot_input_event_screen_drag_get_index(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_x(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_y(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_relative_x(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_relative_y(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_speed_x(godot_input_event p_event); +int GDAPI godot_input_event_screen_drag_get_speed_y(godot_input_event p_event); + +int GDAPI godot_input_event_is_action(godot_input_event p_event,char *p_action); +int GDAPI godot_input_event_is_action_pressed(godot_input_event p_event,char *p_action); + +////// ByteArray + +typedef void* godot_byte_array; + +godot_byte_array GDAPI godot_byte_array_create(); +godot_byte_array GDAPI godot_byte_array_copy(godot_byte_array p_byte_array); +void GDAPI godot_byte_array_free(godot_byte_array p_byte_array); + +int GDAPI godot_byte_array_get_size(godot_byte_array p_byte_array); +unsigned char GDAPI godot_byte_array_get(godot_byte_array p_byte_array,int p_index); +void GDAPI godot_byte_array_set(godot_byte_array p_byte_array,int p_index,unsigned char p_value); +void GDAPI godot_byte_array_remove(godot_byte_array p_byte_array,int p_index); +void GDAPI godot_byte_array_clear(godot_byte_array p_byte_array); + +typedef void* godot_byte_array_lock; + +godot_byte_array_lock GDAPI godot_byte_array_get_lock(godot_byte_array p_byte_array); +unsigned char GDAPI *godot_byte_array_lock_get_pointer(godot_byte_array_lock p_byte_array_lock); +void GDAPI godot_byte_array_lock_free(godot_byte_array_lock p_byte_array_lock); + + +godot_image GDAPI godot_image_create_with_array(int p_width,int p_height,int p_format,int p_use_mipmaps,godot_array p_array); +godot_byte_array GDAPI godot_image_get_data(godot_image p_image); + + +////// IntArray + +typedef void* godot_int_array; + +godot_int_array GDAPI godot_int_array_create(); +godot_int_array GDAPI godot_int_array_copy(godot_int_array p_int_array); +void GDAPI godot_int_array_free(godot_int_array p_int_array); + +int GDAPI godot_int_array_get_size(godot_int_array p_int_array); +int GDAPI godot_int_array_get(godot_int_array p_int_array,int p_index); +void GDAPI godot_int_array_set(godot_int_array p_int_array,int p_index,int p_value); +void GDAPI godot_int_array_remove(godot_int_array p_int_array,int p_index); +void GDAPI godot_int_array_clear(godot_int_array p_int_array); + +typedef void* godot_int_array_lock; + +godot_int_array_lock GDAPI godot_int_array_get_lock(godot_int_array p_int_array); +int GDAPI *godot_int_array_lock_get_pointer(godot_int_array_lock p_int_array_lock); +void GDAPI godot_int_array_lock_free(godot_int_array_lock p_int_array_lock); + +////// RealArray + +typedef void* godot_real_array; + + +godot_real_array GDAPI godot_real_array_create(); +godot_real_array GDAPI godot_real_array_copy(godot_real_array p_real_array); +void GDAPI godot_real_array_free(godot_real_array p_real_array); + +int GDAPI godot_real_array_get_size(godot_real_array p_real_array); +float GDAPI godot_real_array_get(godot_real_array p_real_array,int p_index); +void GDAPI godot_real_array_set(godot_real_array p_real_array,int p_index,float p_value); +void GDAPI godot_real_array_remove(godot_real_array p_real_array,int p_index); +void GDAPI godot_real_array_clear(godot_real_array p_real_array); + +typedef void* godot_real_array_lock; + +godot_real_array_lock GDAPI godot_real_array_get_lock(godot_real_array p_real_array); +float GDAPI *godot_real_array_lock_get_pointer(godot_real_array_lock p_real_array_lock); +void GDAPI godot_real_array_lock_free(godot_real_array_lock p_real_array_lock); + + +////// StringArray + +typedef void* godot_string_array; + + +godot_string_array GDAPI godot_string_array_create(); +godot_string_array GDAPI godot_string_array_copy(godot_string_array p_string_array); +void GDAPI godot_string_array_free(godot_string_array p_string_array); + +int GDAPI godot_string_array_get_size(godot_string_array p_string_array); +int GDAPI godot_string_array_get(godot_string_array p_string_array,int p_index,unsigned char* p_string,int p_max_len); +void GDAPI godot_string_array_set(godot_string_array p_string_array,int p_index,unsigned char *p_string); +void GDAPI godot_string_array_remove(godot_string_array p_string_array,int p_index); +void GDAPI godot_string_array_clear(godot_string_array p_string_array); + +////// Vector2Array + +typedef void* godot_vector2_array; + +godot_vector2_array GDAPI godot_vector2_array_create(); +godot_vector2_array GDAPI godot_vector2_array_copy(godot_vector2_array p_vector2_array); +void GDAPI godot_vector2_array_free(godot_vector2_array p_vector2_array); + +int GDAPI godot_vector2_array_get_size(godot_vector2_array p_vector2_array); +int GDAPI godot_vector2_array_get_stride(godot_vector2_array p_vector2_array); +void GDAPI godot_vector2_array_get(godot_vector2_array p_vector2_array,int p_index,float* p_vector2); +void GDAPI godot_vector2_array_set(godot_vector2_array p_vector2_array,int p_index,float *p_vector2); +void GDAPI godot_vector2_array_remove(godot_vector2_array p_vector2_array,int p_index); +void GDAPI godot_vector2_array_clear(godot_vector2_array p_vector2_array); + + +typedef void* godot_vector2_array_lock; + +godot_vector2_array_lock GDAPI godot_vector2_array_get_lock(godot_vector2_array p_vector2_array); +float GDAPI *godot_vector2_array_lock_get_pointer(godot_vector2_array_lock p_vector2_array_lock); +void GDAPI godot_vector2_array_lock_free(godot_vector2_array_lock p_vector2_array_lock); + +////// Vector3Array + +typedef void* godot_vector3_array; + +godot_vector3_array GDAPI godot_vector3_array_create(); +godot_vector3_array GDAPI godot_vector3_array_copy(godot_vector3_array p_vector3_array); +void GDAPI godot_vector3_array_free(godot_vector3_array p_vector3_array); + +int GDAPI godot_vector3_array_get_size(godot_vector3_array p_vector3_array); +int GDAPI godot_vector3_array_get_stride(godot_vector3_array p_vector3_array); +void GDAPI godot_vector3_array_get(godot_vector3_array p_vector3_array,int p_index,float* p_vector3); +void GDAPI godot_vector3_array_set(godot_vector3_array p_vector3_array,int p_index,float *p_vector3); +void GDAPI godot_vector3_array_remove(godot_vector3_array p_vector3_array,int p_index); +void GDAPI godot_vector3_array_clear(godot_vector3_array p_vector3_array); + + +typedef void* godot_vector3_array_lock; + +godot_vector3_array_lock GDAPI godot_vector3_array_get_lock(godot_vector3_array p_vector3_array); +float GDAPI *godot_vector3_array_lock_get_pointer(godot_vector3_array_lock p_vector3_array_lock); +void GDAPI godot_vector3_array_lock_free(godot_vector3_array_lock p_vector3_array_lock); + +////// ColorArray + +typedef void* godot_color_array; + +godot_color_array GDAPI godot_color_array_create(); +godot_color_array GDAPI godot_color_array_copy(godot_color_array p_color_array); +void GDAPI godot_color_array_free(godot_color_array p_color_array); + +int GDAPI godot_color_array_get_size(godot_color_array p_color_array); +int GDAPI godot_color_array_get_stride(godot_color_array p_color_array); +void GDAPI godot_color_array_get(godot_color_array p_color_array,int p_index,float* p_color); +void GDAPI godot_color_array_set(godot_color_array p_color_array,int p_index,float *p_color); +void GDAPI godot_color_array_remove(godot_color_array p_color_array,int p_index); +void GDAPI godot_color_array_clear(godot_color_array p_color_array); + + +typedef void* godot_color_array_lock; + +godot_color_array_lock GDAPI godot_color_array_get_lock(godot_color_array p_color_array); +float GDAPI *godot_color_array_lock_get_pointer(godot_color_array_lock p_color_array_lock); +void GDAPI godot_color_array_lock_free(godot_color_array_lock p_color_array_lock); + + +////// Instance (forward declared) + +typedef void *godot_instance; + +////// Variant + +#define GODOT_VARIANT_NIL 0 +#define GODOT_VARIANT_BOOL 1 +#define GODOT_VARIANT_INT 2 +#define GODOT_VARIANT_REAL 3 +#define GODOT_VARIANT_STRING 4 +#define GODOT_VARIANT_VECTOR2 5 +#define GODOT_VARIANT_RECT2 6 +#define GODOT_VARIANT_VECTOR3 7 +#define GODOT_VARIANT_MATRIX32 8 +#define GODOT_VARIANT_PLANE 9 +#define GODOT_VARIANT_QUAT 10 +#define GODOT_VARIANT_AABB 11 +#define GODOT_VARIANT_MATRIX3 12 +#define GODOT_VARIANT_TRANSFORM 13 +#define GODOT_VARIANT_COLOR 14 +#define GODOT_VARIANT_IMAGE 15 +#define GODOT_VARIANT_NODE_PATH 16 +#define GODOT_VARIANT_RID 17 +#define GODOT_VARIANT_OBJECT 18 +#define GODOT_VARIANT_INPUT_EVENT 19 +#define GODOT_VARIANT_DICTIONARY 20 +#define GODOT_VARIANT_ARRAY 21 +#define GODOT_VARIANT_BYTE_ARRAY 22 +#define GODOT_VARIANT_INT_ARRAY 23 +#define GODOT_VARIANT_REAL_ARRAY 24 +#define GODOT_VARIANT_STRING_ARRAY 25 +#define GODOT_VARIANT_VECTOR2_ARRAY 26 +#define GODOT_VARIANT_VECTOR3_ARRAY 27 +#define GODOT_VARIANT_COLOR_ARRAY 28 +#define GODOT_VARIANT_MAX 29 + +godot_variant *godot_variant_new(); + +int GDAPI godot_variant_get_type(godot_variant p_variant); + +void GDAPI godot_variant_set_null(godot_variant p_variant); +void GDAPI godot_variant_set_bool(godot_variant p_variant,godot_bool p_bool); +void GDAPI godot_variant_set_int(godot_variant p_variant,int p_int); +void GDAPI godot_variant_set_float(godot_variant p_variant,int p_float); +void GDAPI godot_variant_set_string(godot_variant p_variant,char *p_string); +void GDAPI godot_variant_set_vector2(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_rect2(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_vector3(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_matrix32(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_plane(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_aabb(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_matrix3(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_transform(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_color(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_set_image(godot_variant p_variant,godot_image *p_image); +void GDAPI godot_variant_set_node_path(godot_variant p_variant,char *p_path); +void GDAPI godot_variant_set_rid(godot_variant p_variant,char *p_path); +void GDAPI godot_variant_set_instance(godot_variant p_variant,godot_instance p_instance); +void GDAPI godot_variant_set_input_event(godot_variant p_variant,godot_input_event p_instance); +void GDAPI godot_variant_set_dictionary(godot_variant p_variant,godot_dictionary p_dictionary); +void GDAPI godot_variant_set_array(godot_variant p_variant,godot_array p_array); +void GDAPI godot_variant_set_byte_array(godot_variant p_variant,godot_byte_array p_array); +void GDAPI godot_variant_set_int_array(godot_variant p_variant,godot_byte_array p_array); +void GDAPI godot_variant_set_string_array(godot_variant p_variant,godot_string_array p_array); +void GDAPI godot_variant_set_vector2_array(godot_variant p_variant,godot_vector2_array p_array); +void GDAPI godot_variant_set_vector3_array(godot_variant p_variant,godot_vector3_array p_array); +void GDAPI godot_variant_set_color_array(godot_variant p_variant,godot_color_array p_array); + +godot_bool GDAPI godot_variant_get_bool(godot_variant p_variant); +int GDAPI godot_variant_get_int(godot_variant p_variant); +float GDAPI godot_variant_get_float(godot_variant p_variant); +int GDAPI godot_variant_get_string(godot_variant p_variant,char *p_string,int p_bufsize); +void GDAPI godot_variant_get_vector2(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_rect2(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_vector3(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_matrix32(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_plane(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_aabb(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_matrix3(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_transform(godot_variant p_variant,float *p_elems); +void GDAPI godot_variant_get_color(godot_variant p_variant,float *p_elems); +godot_image GDAPI *godot_variant_get_image(godot_variant p_variant); +int GDAPI godot_variant_get_node_path(godot_variant p_variant,char *p_path, int p_bufsize); +godot_rid GDAPI godot_variant_get_rid(godot_variant p_variant); +godot_instance GDAPI godot_variant_get_instance(godot_variant p_variant); +void GDAPI godot_variant_get_input_event(godot_variant p_variant,godot_input_event); +void GDAPI godot_variant_get_dictionary(godot_variant p_variant,godot_dictionary); +godot_array GDAPI godot_variant_get_array(godot_variant p_variant); +godot_byte_array GDAPI godot_variant_get_byte_array(godot_variant p_variant); +godot_byte_array GDAPI godot_variant_get_int_array(godot_variant p_variant); +godot_string_array GDAPI godot_variant_get_string_array(godot_variant p_variant); +godot_vector2_array GDAPI godot_variant_get_vector2_array(godot_variant p_variant); +godot_vector3_array GDAPI godot_variant_get_vector3_array(godot_variant p_variant); +godot_color_array GDAPI godot_variant_get_color_array(godot_variant p_variant); + + +void GDAPI godot_variant_delete(godot_variant p_variant); + +////// Class +/// + +char GDAPI **godot_class_get_list(); //get list of classes in array to array of strings, must be freed, use godot_list_free() + +int GDAPI godot_class_get_base(char* p_class,char *p_base,int p_max_len); +int GDAPI godot_class_get_name(char* p_class,char *p_base,int p_max_len); + +char GDAPI **godot_class_get_method_list(char* p_class); //free with godot_list_free() +int GDAPI godot_class_method_get_argument_count(char* p_class,char *p_method); +int GDAPI godot_class_method_get_argument_type(char* p_class,char *p_method,int p_argument); +godot_variant GDAPI godot_class_method_get_argument_default_value(char* p_class,char *p_method,int p_argument); + +char GDAPI **godot_class_get_constant_list(char* p_class); //free with godot_list_free() +int GDAPI godot_class_constant_get_value(char* p_class,char *p_constant); + + +////// Instance + +typedef int godot_call_error; + +#define GODOT_CALL_OK +#define GODOT_CALL_ERROR_WRONG_ARGUMENTS +#define GODOT_CALL_ERROR_INVALID_INSTANCE + +godot_instance GDAPI godot_instance_new(char* p_class); +int GDAPI godot_instance_get_class(godot_instance p_instance,char* p_class,int p_max_len); + +typedef struct { + char *name; + int hint; + char *hint_string; + int usage; +} godot_property_info; + +godot_call_error GDAPI godot_instance_call(godot_instance p_instance, char* p_method, ...); +godot_call_error GDAPI godot_instance_call_ret(godot_instance p_instance, godot_variant r_return, char* p_method, ...); +godot_bool GDAPI godot_instance_set(godot_instance p_instance, char* p_prop,godot_variant p_value); +godot_variant GDAPI godot_instance_get(godot_instance p_instance, char* p_prop); + + +#define GODOT_PROPERTY_HINT_NONE 0 ///< no hint provided. +#define GODOT_PROPERTY_HINT_RANGE 1///< hint_text = "min,max,step,slider; //slider is optional" +#define GODOT_PROPERTY_HINT_EXP_RANGE 2///< hint_text = "min,max,step", exponential edit +#define GODOT_PROPERTY_HINT_ENUM 3///< hint_text= "val1,val2,val3,etc" +#define GODOT_PROPERTY_HINT_EXP_EASING 4/// exponential easing funciton (Math::ease) +#define GODOT_PROPERTY_HINT_LENGTH 5///< hint_text= "length" (as integer) +#define GODOT_PROPERTY_HINT_SPRITE_FRAME 6 +#define GODOT_PROPERTY_HINT_KEY_ACCEL 7///< hint_text= "length" (as integer) +#define GODOT_PROPERTY_HINT_FLAGS 8///< hint_text= "flag1,flag2,etc" (as bit flags) +#define GODOT_PROPERTY_HINT_ALL_FLAGS 9 +#define GODOT_PROPERTY_HINT_FILE 10 ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," +#define GODOT_PROPERTY_HINT_DIR 11 ///< a directort path must be passed +#define GODOT_PROPERTY_HINT_GLOBAL_FILE 12///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," +#define GODOT_PROPERTY_HINT_GLOBAL_DIR 13 ///< a directort path must be passed +#define GODOT_PROPERTY_HINT_RESOURCE_TYPE 14///< a resource object type +#define GODOT_PROPERTY_HINT_MULTILINE_TEXT 15///< used for string properties that can contain multiple lines +#define GODOT_PROPERTY_HINT_COLOR_NO_ALPHA 16///< used for ignoring alpha component when editing a color +#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY 17 +#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS 18 +#define GODOT_PROPERTY_HINT_OBJECT_ID 19 + + +#define GODOT_PROPERTY_USAGE_STORAGE 1 +#define GODOT_PROPERTY_USAGE_EDITOR 2 +#define GODOT_PROPERTY_USAGE_NETWORK 4 +#define GODOT_PROPERTY_USAGE_EDITOR_HELPER 8 +#define GODOT_PROPERTY_USAGE_CHECKABLE 16 //used for editing global variables +#define GODOT_PROPERTY_USAGE_CHECKED 32 //used for editing global variables +#define GODOT_PROPERTY_USAGE_INTERNATIONALIZED 64 //hint for internationalized strings +#define GODOT_PROPERTY_USAGE_BUNDLE 128 //used for optimized bundles +#define GODOT_PROPERTY_USAGE_CATEGORY 256 +#define GODOT_PROPERTY_USAGE_STORE_IF_NONZERO 512 //only store if nonzero +#define GODOT_PROPERTY_USAGE_STORE_IF_NONONE 1024 //only store if false +#define GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE 2048 +#define GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED 4096 +#define GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE 8192 +#define GODOT_PROPERTY_USAGE_STORE_IF_NULL 16384 +#define GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER 32768 + +#define GODOT_PROPERTY_USAGE_DEFAULT GODOT_PROPERTY_USAGE_STORAGE|GODOT_PROPERTY_USAGE_EDITOR|GODOT_PROPERTY_USAGE_NETWORK +#define GODOT_PROPERTY_USAGE_DEFAULT_INTL GODOT_PROPERTY_USAGE_STORAGE|GODOT_PROPERTY_USAGE_EDITOR|GODOT_PROPERTY_USAGE_NETWORK|GODOT_PROPERTY_USAGE_INTERNATIONALIZED +#define GODOT_PROPERTY_USAGE_NOEDITOR GODOT_PROPERTY_USAGE_STORAGE|GODOT_PROPERTY_USAGE_NETWORK + + +godot_property_info GDAPI **godot_instance_get_property_list(godot_instance p_instance); +void GDAPI godot_instance_free_property_list(godot_instance p_instance,godot_property_info** p_list); + + + +void GDAPI godot_list_free(char **p_name); //helper to free all the class list + + +////// Script API + +typedef void* (godot_script_instance_func)(godot_instance); //passed an instance, return a pointer to your userdata +typedef void (godot_script_free_func)(godot_instance,void*); //passed an instance, please free your userdata + +void GDAPI godot_script_register(char* p_base,char* p_name,godot_script_instance_func p_instance_func,godot_script_free_func p_free_func); +void GDAPI godot_script_unregister(char* p_name); + +typedef GDAPI godot_variant (godot_script_func)(godot_instance,void*,godot_variant*,int); //instance,userdata,arguments,argument count. Return something or NULL. Arguments must not be freed. + + +void GDAPI godot_script_add_function(char* p_name,char* p_function_name,godot_script_func p_func); +void GDAPI godot_script_add_validated_function(char* p_name,char* p_function_name,godot_script_func p_func,int* p_arg_types,int p_arg_count,godot_variant* p_default_args,int p_default_arg_count); + +typedef void (godot_set_property_func)(godot_instance,void*,godot_variant); //instance,userdata,value. Value must not be freed. +typedef godot_variant (godot_get_property_func)(godot_instance,void*); //instance,userdata. Return a value or NULL. + +void GDAPI godot_script_add_property(char* p_name,char* p_path,godot_set_property_func p_set_func,godot_get_property_func p_get_func); +void GDAPI godot_script_add_listed_property(char* p_name,char* p_path,godot_set_property_func p_set_func,godot_get_property_func p_get_func,int p_type,int p_hint,char* p_hint_string,int p_usage); + + +////// System Functions + +//using these will help Godot track how much memory is in use in debug mode +void GDAPI *godot_alloc(int p_bytes); +void GDAPI *godot_realloc(void* p_ptr,int p_bytes); +void GDAPI godot_free(void* p_ptr); + + +#ifdef __cplusplus +} +#endif + + +#endif // GODOT_C_H diff --git a/modules/cscript/register_types.cpp b/modules/cscript/register_types.cpp new file mode 100644 index 0000000000..267e5245ed --- /dev/null +++ b/modules/cscript/register_types.cpp @@ -0,0 +1,37 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 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 "register_types.h" + + +void register_cscript_types() { + +} +void unregister_cscript_types() { + +} diff --git a/modules/cscript/register_types.h b/modules/cscript/register_types.h new file mode 100644 index 0000000000..a0f41eee5d --- /dev/null +++ b/modules/cscript/register_types.h @@ -0,0 +1,30 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 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. */ +/*************************************************************************/ +void register_cscript_types(); +void unregister_cscript_types(); diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 7481eac620..304ed6b100 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -460,7 +460,6 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre const GDParser::Node *instance = on->arguments[0]; - bool in_static=false; if (instance->type==GDParser::Node::TYPE_SELF) { //room for optimization @@ -550,17 +549,25 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre int index; if (named) { -#ifdef DEBUG_ENABLED if (on->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { - const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name); + GDParser::IdentifierNode* identifier = static_cast<GDParser::IdentifierNode*>(on->arguments[1]); + const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(identifier->name); + +#ifdef DEBUG_ENABLED if (MI && MI->get().getter==codegen.function_node->name) { String n = static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name; _set_error("Must use '"+n+"' instead of 'self."+n+"' in getter.",on); return -1; } - } #endif + + if (MI && MI->get().getter=="") { + // Faster than indexing self (as if no self. had been used) + return (MI->get().index)|(GDFunction::ADDR_TYPE_MEMBER<<GDFunction::ADDR_BITS); + } + } + index=codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode*>(on->arguments[1])->name); } else { @@ -763,8 +770,6 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre Vector<int> setchain; - int prev_key_idx=-1; - for(List<GDParser::OperatorNode*>::Element *E=chain.back();E;E=E->prev()) { @@ -814,7 +819,6 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre setchain.push_back(named ? GDFunction::OPCODE_SET_NAMED : GDFunction::OPCODE_SET); prev_pos=dst_pos; - prev_key_idx=key_idx; } @@ -1203,7 +1207,6 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * if (p_func) { for(int i=0;i<p_func->arguments.size();i++) { - int idx = i; codegen.add_stack_identifier(p_func->arguments[i],i); #ifdef TOOLS_ENABLED argnames.push_back(p_func->arguments[i]); @@ -1441,7 +1444,6 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa p_script->name=p_class->name; - int index_from=0; Ref<GDNativeClass> native; if (p_class->extends_used) { @@ -1497,7 +1499,8 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa String sub = p_class->extends_class[i]; if (script->subclasses.has(sub)) { - script=script->subclasses[sub]; + Ref<Script> subclass = script->subclasses[sub]; //avoid reference from dissapearing + script=subclass; } else { _set_error("Could not find subclass: "+sub,p_class); @@ -1683,6 +1686,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa if (err) return err; + p_script->constants.insert(name,subclass); //once parsed, goes to the list of constants p_script->subclasses.insert(name,subclass); diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index b1da7e782c..520a8b18d8 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -212,7 +212,7 @@ String GDScriptLanguage::debug_get_stack_level_source(int p_level) const { ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,""); int l = _debug_call_stack_pos - p_level -1; - return _call_stack[l].function->get_script()->get_path(); + return _call_stack[l].function->get_source(); } void GDScriptLanguage::debug_get_stack_level_locals(int p_level,List<String> *p_locals, List<Variant> *p_values, int p_max_subitems,int p_max_depth) { @@ -449,57 +449,21 @@ static Ref<Reference> _get_parent_class(GDCompletionContext& context) { } String base=context._class->extends_class[0]; - const GDParser::ClassNode *p = context._class->owner; - Ref<GDScript> base_class; -#if 0 - while(p) { - - if (p->subclasses.has(base)) { - - base_class=p->subclasses[base]; - break; - } - p=p->_owner; - } -#endif - if (base_class.is_valid()) { -#if 0 - for(int i=1;i<context._class->extends_class.size();i++) { - - String subclass=context._class->extends_class[i]; - - if (base_class->subclasses.has(subclass)) { - - base_class=base_class->subclasses[subclass]; - } else { - - //print_line("Could not find subclass: "+subclass); - return _get_type_from_class(context); //fail please - } - } - - script=base_class; -#endif - - } else { - - if (context._class->extends_class.size()>1) { - return REF(); + if (context._class->extends_class.size()>1) { + return REF(); - } - //if not found, try engine classes - if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) { - - return REF(); - } + } + //if not found, try engine classes + if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) { - int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base]; - native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx]; - return native; + return REF(); } + int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base]; + native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx]; + return native; } @@ -2100,10 +2064,8 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No } Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) { - //print_line( p_code.replace(String::chr(0xFFFF),"<cursor>")); GDParser p; - //Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); Error err = p.parse(p_code,p_base_path,false,"",true); bool isfunction=false; @@ -2204,7 +2166,6 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base if (code!="") { //if there is code, parse it. This way is slower but updates in real-time GDParser p; - //Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); Error err = p.parse(scr->get_source_code(),scr->get_path().get_base_dir(),true,"",false); diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 6e52686de4..de86eb2ab9 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -846,6 +846,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.result_pos=ip+ipofs-1; gdfs->state.defarg=defarg; gdfs->state.instance=p_instance; @@ -1352,6 +1354,18 @@ GDFunction::~GDFunction() { Variant GDFunctionState::_signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { +#ifdef DEBUG_ENABLED + if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { + ERR_EXPLAIN("Resumed after yield, but class instance is gone"); + ERR_FAIL_V(Variant()); + } + + if (state.script_id && !ObjectDB::get_instance(state.script_id)) { + ERR_EXPLAIN("Resumed after yield, but script is gone"); + ERR_FAIL_V(Variant()); + } +#endif + Variant arg; r_error.error=Variant::CallError::CALL_OK; @@ -1398,6 +1412,17 @@ bool GDFunctionState::is_valid() const { Variant GDFunctionState::resume(const Variant& p_arg) { ERR_FAIL_COND_V(!function,Variant()); +#ifdef DEBUG_ENABLED + if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { + ERR_EXPLAIN("Resumed after yield, but class instance is gone"); + ERR_FAIL_V(Variant()); + } + + if (state.script_id && !ObjectDB::get_instance(state.script_id)) { + ERR_EXPLAIN("Resumed after yield, but script is gone"); + ERR_FAIL_V(Variant()); + } +#endif state.result=p_arg; Variant::CallError err; diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h index 1f790eaadc..e09c6509dd 100644 --- a/modules/gdscript/gd_function.h +++ b/modules/gdscript/gd_function.h @@ -136,6 +136,9 @@ public: struct CallState { + ObjectID instance_id; //by debug only + ObjectID script_id; + GDInstance *instance; Vector<uint8_t> stack; int stack_size; @@ -160,6 +163,7 @@ public: int get_default_argument_count() const; int get_default_argument_addr(int p_idx) const; GDScript *get_script() const { return _script; } + StringName get_source() const { return source; } void debug_get_stack_member_state(int p_line,List<Pair<StringName,int> > *r_stackvars) const; diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index ec66841662..b9815a5efd 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -502,7 +502,6 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va Ref<FuncRef> fr = memnew( FuncRef); - Object *obj = *p_args[0]; fr->set_instance(*p_args[0]); fr->set_function(*p_args[1]); diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index ac96a2117c..e87bd99e4f 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -31,6 +31,7 @@ #include "io/resource_loader.h" #include "os/file_access.h" #include "script_language.h" +#include "gd_script.h" template<class T> T* GDParser::alloc_node() { @@ -216,7 +217,7 @@ bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& ide } -GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign) { +GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign,bool p_parsing_constant) { // Vector<Node*> expressions; // Vector<OperatorNode::Operator> operators; @@ -243,7 +244,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ //subexpression () tokenizer->advance(); parenthesis++; - Node* subexpr = _parse_expression(p_parent,p_static); + Node* subexpr = _parse_expression(p_parent,p_static,p_allow_assign,p_parsing_constant); parenthesis--; if (!subexpr) return NULL; @@ -477,20 +478,30 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ } else if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) { //identifier (reference) - const ClassNode* cln = static_cast<const ClassNode*>(get_parse_tree()); + const ClassNode* cln = current_class; bool bfn = false; StringName identifier; if (_get_completable_identifier(COMPLETION_IDENTIFIER,identifier)) { } - for( int i=0; i<cln->constant_expressions.size(); ++i ) { + if (p_parsing_constant) { + for( int i=0; i<cln->constant_expressions.size(); ++i ) { - if( cln->constant_expressions[i].identifier == identifier ) { + if( cln->constant_expressions[i].identifier == identifier ) { - expr = cln->constant_expressions[i].expression; - bfn = true; - break; + expr = cln->constant_expressions[i].expression; + bfn = true; + break; + } + } + + if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) { + //check from constants + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value = GDScriptLanguage::get_singleton()->get_global_array()[ GDScriptLanguage::get_singleton()->get_global_map()[identifier] ]; + expr=constant; + bfn = true; } } @@ -503,8 +514,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ } else if (/*tokenizer->get_token()==GDTokenizer::TK_OP_ADD ||*/ tokenizer->get_token()==GDTokenizer::TK_OP_SUB || tokenizer->get_token()==GDTokenizer::TK_OP_NOT || tokenizer->get_token()==GDTokenizer::TK_OP_BIT_INVERT) { //single prefix operators like !expr -expr ++expr --expr - OperatorNode *op = alloc_node<OperatorNode>(); - + alloc_node<OperatorNode>(); Expression e; e.is_op=true; @@ -567,7 +577,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ _set_error("',' or ']' expected"); return NULL; } - Node *n = _parse_expression(arr,p_static); + Node *n = _parse_expression(arr,p_static,p_allow_assign,p_parsing_constant); if (!n) return NULL; arr->elements.push_back(n); @@ -674,7 +684,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ expecting=DICT_EXPECT_VALUE; } else { //python/js style more flexible - key = _parse_expression(dict,p_static); + key = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant); if (!key) return NULL; expecting=DICT_EXPECT_COLON; @@ -682,7 +692,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ } if (expecting==DICT_EXPECT_VALUE) { - Node *value = _parse_expression(dict,p_static); + Node *value = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant); if (!value) return NULL; expecting=DICT_EXPECT_COMMA; @@ -833,7 +843,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ tokenizer->advance(1); - Node *subexpr = _parse_expression(op,p_static); + Node *subexpr = _parse_expression(op,p_static,p_allow_assign,p_parsing_constant); if (!subexpr) { return NULL; } @@ -1069,8 +1079,8 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ // can be followed by an unary op in a valid combination, // due to how precedence works, unaries will always dissapear first - _set_error("Parser bug.."); - + _set_error("Unexpected two consecutive operators."); + return NULL; } @@ -1432,7 +1442,7 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) { GDParser::Node* GDParser::_parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const,bool p_allow_assign) { - Node* expr=_parse_expression(p_parent,p_static,p_allow_assign); + Node* expr=_parse_expression(p_parent,p_static,p_allow_assign,p_reduce_const); if (!expr || error_set) return NULL; expr = _reduce_expression(expr,p_reduce_const); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 6c49c1df52..4afc534a8c 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -435,7 +435,7 @@ private: bool _parse_arguments(Node* p_parent, Vector<Node*>& p_args, bool p_static, bool p_can_codecomplete=false); bool _enter_indent_block(BlockNode *p_block=NULL); bool _parse_newline(); - Node* _parse_expression(Node *p_parent,bool p_static,bool p_allow_assign=false); + Node* _parse_expression(Node *p_parent, bool p_static, bool p_allow_assign=false, bool p_parsing_constant=false); Node* _reduce_expression(Node *p_node,bool p_to_const=false); Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false); diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 026fd04869..d9783c218a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -874,6 +874,10 @@ GDScript::~GDScript() { memdelete( E->get() ); } + for (Map<StringName,Ref<GDScript> >::Element *E=subclasses.front();E;E=E->next()) { + E->get()->_owner=NULL; //bye, you are no longer owned cause I died + } + #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->lock) { GDScriptLanguage::get_singleton()->lock->lock(); @@ -960,11 +964,16 @@ bool GDInstance::get(const StringName& p_name, Variant &r_ret) const { } { - const Map<StringName,Variant>::Element *E = script->constants.find(p_name); - if (E) { - r_ret=E->get(); - return true; //index found + const GDScript *sl = sptr; + while(sl) { + const Map<StringName,Variant>::Element *E = sl->constants.find(p_name); + if (E) { + r_ret=E->get(); + return true; //index found + + } + sl=sl->_base; } } @@ -1709,6 +1718,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "false", "float", "int", + "bool", "null", "PI", "self", diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 166e29ad70..723761c3a9 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -202,6 +202,8 @@ friend class GDCompiler; public: + _FORCE_INLINE_ Object* get_owner() { return owner; } + 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; diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 0a77b96569..93863c4eb2 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -1156,7 +1156,6 @@ Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String& p_code) { GDTokenizerText tt; tt.set_code(p_code); int line=-1; - int col=0; while(true) { diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 6aa53f03ef..95b18cae4d 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -158,7 +158,7 @@ void register_gdscript_types() { void unregister_gdscript_types() { - + ScriptServer::unregister_language(script_language_gd); if (script_language_gd) memdelete( script_language_gd ); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 5e30416641..37a3fb2b25 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -912,7 +912,6 @@ void GridMap::_octant_bake(const OctantKey &p_key, const Ref<TriangleMesh>& p_tm int lc = p_lights.size(); const BakeLight* bl = p_lights.ptr(); float ofs = cell_size*0.02; - float att = 0.2; for(;V;V=V->next()) { diff --git a/modules/ik/ik.cpp b/modules/ik/ik.cpp index 172e16459e..35b3ba7e83 100644 --- a/modules/ik/ik.cpp +++ b/modules/ik/ik.cpp @@ -241,7 +241,7 @@ void InverseKinematics::_notification(int p_what) } } break; case NOTIFICATION_PROCESS: { - float delta = get_process_delta_time(); + Spatial *sksp = skel->cast_to<Spatial>(); if (!bound) break; |