summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/cscript/godot_c.cpp1
-rw-r--r--modules/cscript/godot_c.h309
-rw-r--r--modules/cscript/register_types.cpp3
-rw-r--r--modules/dds/register_types.cpp2
-rw-r--r--modules/dds/texture_loader_dds.cpp345
-rw-r--r--modules/dds/texture_loader_dds.h9
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp446
-rw-r--r--modules/enet/networked_multiplayer_enet.h31
-rw-r--r--modules/enet/register_types.cpp7
-rw-r--r--modules/etc1/image_etc.cpp153
-rw-r--r--modules/etc1/image_etc.h1
-rw-r--r--modules/etc1/register_types.cpp2
-rw-r--r--modules/etc1/texture_loader_pkm.cpp46
-rw-r--r--modules/etc1/texture_loader_pkm.h9
-rw-r--r--modules/gdscript/gd_compiler.cpp1303
-rw-r--r--modules/gdscript/gd_compiler.h144
-rw-r--r--modules/gdscript/gd_editor.cpp2016
-rw-r--r--modules/gdscript/gd_function.cpp991
-rw-r--r--modules/gdscript/gd_function.h84
-rw-r--r--modules/gdscript/gd_functions.cpp1044
-rw-r--r--modules/gdscript/gd_functions.h4
-rw-r--r--modules/gdscript/gd_parser.cpp2682
-rw-r--r--modules/gdscript/gd_parser.h164
-rw-r--r--modules/gdscript/gd_script.cpp1069
-rw-r--r--modules/gdscript/gd_script.h270
-rw-r--r--modules/gdscript/gd_tokenizer.cpp1163
-rw-r--r--modules/gdscript/gd_tokenizer.h122
-rw-r--r--modules/gdscript/register_types.cpp28
-rw-r--r--modules/gridmap/grid_map.cpp974
-rw-r--r--modules/gridmap/grid_map.h88
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp958
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h36
-rw-r--r--modules/gridmap/register_types.cpp4
-rw-r--r--modules/jpg/image_loader_jpegd.cpp54
-rw-r--r--modules/jpg/image_loader_jpegd.h8
-rw-r--r--modules/jpg/register_types.cpp4
-rw-r--r--modules/openssl/stream_peer_openssl.cpp360
-rw-r--r--modules/openssl/stream_peer_openssl.h50
-rw-r--r--modules/opus/audio_stream_opus.cpp222
-rw-r--r--modules/opus/audio_stream_opus.h36
-rw-r--r--modules/opus/register_types.cpp4
-rw-r--r--modules/pbm/bitmap_loader_pbm.cpp154
-rw-r--r--modules/pbm/bitmap_loader_pbm.h8
-rw-r--r--modules/pbm/register_types.cpp6
-rw-r--r--modules/pvr/register_types.cpp2
-rw-r--r--modules/pvr/texture_loader_pvr.cpp447
-rw-r--r--modules/pvr/texture_loader_pvr.h12
-rw-r--r--modules/regex/regex.cpp461
-rw-r--r--modules/regex/regex.h29
-rw-r--r--modules/regex/register_types.cpp2
-rw-r--r--modules/squish/image_compress_squish.cpp53
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp134
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.h31
-rw-r--r--modules/stb_vorbis/register_types.cpp1
-rw-r--r--modules/stb_vorbis/resource_importer_ogg_vorbis.cpp31
-rw-r--r--modules/stb_vorbis/resource_importer_ogg_vorbis.h11
-rw-r--r--modules/theora/register_types.cpp6
-rw-r--r--modules/theora/video_stream_theora.cpp458
-rw-r--r--modules/theora/video_stream_theora.h56
-rw-r--r--modules/visual_script/register_types.cpp26
-rw-r--r--modules/visual_script/visual_script.cpp1841
-rw-r--r--modules/visual_script/visual_script.h435
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp713
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.h20
-rw-r--r--modules/visual_script/visual_script_editor.cpp2441
-rw-r--r--modules/visual_script/visual_script_editor.h91
-rw-r--r--modules/visual_script/visual_script_expression.cpp1158
-rw-r--r--modules/visual_script/visual_script_expression.h107
-rw-r--r--modules/visual_script/visual_script_flow_control.cpp1235
-rw-r--r--modules/visual_script/visual_script_flow_control.h138
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp1611
-rw-r--r--modules/visual_script/visual_script_func_nodes.h113
-rw-r--r--modules/visual_script/visual_script_nodes.cpp2142
-rw-r--r--modules/visual_script/visual_script_nodes.h387
-rw-r--r--modules/visual_script/visual_script_yield_nodes.cpp355
-rw-r--r--modules/visual_script/visual_script_yield_nodes.h39
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.cpp269
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.h35
-rw-r--r--modules/vorbis/register_types.cpp4
-rw-r--r--modules/webm/video_stream_webm.cpp55
-rw-r--r--modules/webm/video_stream_webm.h2
-rw-r--r--modules/webp/image_loader_webp.cpp103
-rw-r--r--modules/webp/image_loader_webp.h8
-rw-r--r--modules/webp/register_types.cpp4
84 files changed, 13900 insertions, 16580 deletions
diff --git a/modules/cscript/godot_c.cpp b/modules/cscript/godot_c.cpp
index 85ee28d6d2..f754f2bb21 100644
--- a/modules/cscript/godot_c.cpp
+++ b/modules/cscript/godot_c.cpp
@@ -27,4 +27,3 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_c.h"
-
diff --git a/modules/cscript/godot_c.h b/modules/cscript/godot_c.h
index 97a63a439f..e38de1e489 100644
--- a/modules/cscript/godot_c.h
+++ b/modules/cscript/godot_c.h
@@ -33,7 +33,6 @@
extern "C" {
#endif
-
#if defined(GDAPI_BUILT_IN) || !defined(WINDOWS_ENABLED)
#define GDAPI
#elif defined(GDAPI_EXPORTS)
@@ -42,10 +41,8 @@ extern "C" {
#define GDAPI __declspec(dllimport)
#endif
-
#define GODOT_API_VERSION 1
-
typedef int godot_bool;
#define GODOT_FALSE 0
@@ -53,7 +50,6 @@ typedef int godot_bool;
////// Image
-
#define GODOT_IMAGE_FORMAT_GRAYSCALE 0
#define GODOT_IMAGE_FORMAT_INTENSITY 1
#define GODOT_IMAGE_FORMAT_GRAYSCALE_ALPHA 2
@@ -77,11 +73,11 @@ typedef int godot_bool;
#define GODOT_IMAGE_FORMAT_ATC_ALPHA_EXPLICIT 20
#define GODOT_IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED 21
-typedef void* godot_image;
+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);
+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);
@@ -89,10 +85,9 @@ 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;
+typedef void *godot_rid;
godot_rid GDAPI godot_rid_create();
godot_rid GDAPI godot_rid_copy(godot_rid p_rid);
@@ -100,37 +95,36 @@ void GDAPI godot_rid_free(godot_rid p_rid);
////// Variant (forward declared)
-typedef void* godot_variant;
-
+typedef void *godot_variant;
////// Dictionary
-typedef void* godot_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_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);
+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;
+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);
+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);
+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);
@@ -143,9 +137,9 @@ void GDAPI godot_array_free(godot_array p_array);
#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_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
@@ -157,8 +151,7 @@ void GDAPI godot_array_free(godot_array p_array);
#define INPUT_EVENT_TYPE_SCREEN_DRAG 7
#define INPUT_EVENT_TYPE_ACTION 8
-typedef void* godot_input_event;
-
+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);
@@ -201,7 +194,6 @@ int GDAPI godot_input_event_joypad_button_get_button_index(godot_input_event p_e
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);
@@ -215,49 +207,47 @@ 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);
+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;
+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);
+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;
+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_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;
+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);
+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;
+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);
@@ -265,44 +255,41 @@ void GDAPI godot_int_array_lock_free(godot_int_array_lock p_int_array_lock);
////// RealArray
-typedef void* godot_real_array;
-
+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);
+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;
+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;
-
+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);
+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;
+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);
@@ -310,13 +297,12 @@ 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_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;
+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);
@@ -324,7 +310,7 @@ void GDAPI godot_vector2_array_lock_free(godot_vector2_array_lock p_vector2_arra
////// Vector3Array
-typedef void* godot_vector3_array;
+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);
@@ -332,13 +318,12 @@ 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_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;
+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);
@@ -346,7 +331,7 @@ void GDAPI godot_vector3_array_lock_free(godot_vector3_array_lock p_vector3_arra
////// ColorArray
-typedef void* godot_color_array;
+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);
@@ -354,19 +339,17 @@ 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_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;
+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;
@@ -409,52 +392,52 @@ 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);
+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);
+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);
+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);
+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);
@@ -463,7 +446,6 @@ godot_vector2_array GDAPI godot_variant_get_vector2_array(godot_variant p_varian
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
@@ -471,17 +453,16 @@ void GDAPI godot_variant_delete(godot_variant p_variant);
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);
+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_constant_list(char* p_class); //free with godot_list_free()
-int GDAPI godot_class_constant_get_value(char* p_class,char *p_constant);
+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
@@ -491,8 +472,8 @@ typedef int godot_call_error;
#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);
+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;
@@ -501,34 +482,32 @@ typedef struct {
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);
-
+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_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_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_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_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
@@ -546,51 +525,43 @@ godot_variant GDAPI godot_instance_get(godot_instance p_instance, char* p_prop);
#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
-
+#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_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 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
-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_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);
+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);
+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);
-
+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
index d2101bbd49..2477bc51e2 100644
--- a/modules/cscript/register_types.cpp
+++ b/modules/cscript/register_types.cpp
@@ -28,10 +28,7 @@
/*************************************************************************/
#include "register_types.h"
-
void register_cscript_types() {
-
}
void unregister_cscript_types() {
-
}
diff --git a/modules/dds/register_types.cpp b/modules/dds/register_types.cpp
index 917305f543..d0eaf3f995 100644
--- a/modules/dds/register_types.cpp
+++ b/modules/dds/register_types.cpp
@@ -34,7 +34,7 @@ static ResourceFormatDDS *resource_loader_dds = NULL;
void register_dds_types() {
- resource_loader_dds = memnew( ResourceFormatDDS );
+ resource_loader_dds = memnew(ResourceFormatDDS);
ResourceLoader::add_resource_format_loader(resource_loader_dds);
}
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp
index 600cae991e..9c976179fa 100644
--- a/modules/dds/texture_loader_dds.cpp
+++ b/modules/dds/texture_loader_dds.cpp
@@ -29,18 +29,17 @@
#include "texture_loader_dds.h"
#include "os/file_access.h"
-
enum {
- DDS_MAGIC=0x20534444,
- DDSD_CAPS=0x00000001,
- DDSD_PIXELFORMAT=0x00001000,
- DDSD_PITCH=0x00000008,
- DDSD_LINEARSIZE=0x00080000,
- DDSD_MIPMAPCOUNT=0x00020000,
- DDPF_FOURCC=0x00000004,
- DDPF_ALPHAPIXELS=0x00000001,
- DDPF_INDEXED=0x00000020,
- DDPF_RGB=0x00000040,
+ DDS_MAGIC = 0x20534444,
+ DDSD_CAPS = 0x00000001,
+ DDSD_PIXELFORMAT = 0x00001000,
+ DDSD_PITCH = 0x00000008,
+ DDSD_LINEARSIZE = 0x00080000,
+ DDSD_MIPMAPCOUNT = 0x00020000,
+ DDPF_FOURCC = 0x00000004,
+ DDPF_ALPHAPIXELS = 0x00000001,
+ DDPF_INDEXED = 0x00000020,
+ DDPF_RGB = 0x00000040,
};
enum DDSFormat {
@@ -72,41 +71,39 @@ struct DDSFormatInfo {
Image::Format format;
};
-
-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},
- {"RGB8",false,false,1,3,Image::FORMAT_RGB8},
- {"BGR5A1",false,false,1,2,Image::FORMAT_RGBA8},
- {"BGR565",false,false,1,2,Image::FORMAT_RGB8},
- {"BGR10A2",false,false,1,4,Image::FORMAT_RGBA8},
- {"GRAYSCALE",false,false,1,1,Image::FORMAT_L8},
- {"GRAYSCALE_ALPHA",false,false,1,2,Image::FORMAT_LA8}
+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 },
+ { "RGB8", false, false, 1, 3, Image::FORMAT_RGB8 },
+ { "BGR5A1", false, false, 1, 2, Image::FORMAT_RGBA8 },
+ { "BGR565", false, false, 1, 2, Image::FORMAT_RGB8 },
+ { "BGR10A2", false, false, 1, 4, Image::FORMAT_RGBA8 },
+ { "GRAYSCALE", false, false, 1, 1, Image::FORMAT_L8 },
+ { "GRAYSCALE_ALPHA", false, false, 1, 2, Image::FORMAT_LA8 }
};
-
-RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_CANT_OPEN;
+ *r_error = ERR_CANT_OPEN;
Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (!f)
return RES();
FileAccessRef fref(f);
if (r_error)
- *r_error=ERR_FILE_CORRUPT;
+ *r_error = ERR_FILE_CORRUPT;
- ERR_EXPLAIN("Unable to open DDS texture file: "+p_path);
- ERR_FAIL_COND_V(err!=OK,RES());
+ ERR_EXPLAIN("Unable to open DDS texture file: " + p_path);
+ ERR_FAIL_COND_V(err != OK, RES());
uint32_t magic = f->get_32();
uint32_t hsize = f->get_32();
@@ -118,18 +115,17 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
uint32_t mipmaps = f->get_32();
//skip 11
- for(int i=0;i<11;i++)
+ for (int i = 0; i < 11; i++)
f->get_32();
//validate
- if (magic!=DDS_MAGIC || hsize!=124 || !(flags&DDSD_PIXELFORMAT) || !(flags&DDSD_CAPS)) {
+ if (magic != DDS_MAGIC || hsize != 124 || !(flags & DDSD_PIXELFORMAT) || !(flags & DDSD_CAPS)) {
- ERR_EXPLAIN("Invalid or Unsupported DDS texture file: "+p_path);
+ ERR_EXPLAIN("Invalid or Unsupported DDS texture file: " + p_path);
ERR_FAIL_V(RES());
}
-
/* uint32_t format_size = */ f->get_32();
uint32_t format_flags = f->get_32();
uint32_t format_fourcc = f->get_32();
@@ -155,258 +151,249 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
//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)
+ while (f->get_pos() < 128)
f->get_8();
-
DDSFormat dds_format;
- if (format_flags&DDPF_FOURCC && format_fourcc==0x31545844) { //'1TXD'
+ if (format_flags & DDPF_FOURCC && format_fourcc == 0x31545844) { //'1TXD'
- dds_format=DDS_DXT1;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x33545844) { //'3TXD'
+ dds_format = DDS_DXT1;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x33545844) { //'3TXD'
- dds_format=DDS_DXT3;
+ dds_format = DDS_DXT3;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x35545844) { //'5TXD'
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x35545844) { //'5TXD'
- dds_format=DDS_DXT5;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x31495441) { //'1ITA'
+ dds_format = DDS_DXT5;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x31495441) { //'1ITA'
- dds_format=DDS_ATI1;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x32495441) { //'2ITA'
+ dds_format = DDS_ATI1;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x32495441) { //'2ITA'
- dds_format=DDS_ATI2;
+ dds_format = DDS_ATI2;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0xff0000 && format_green_mask==0xff00 && format_blue_mask==0xff && format_alpha_mask==0xff000000) {
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff && format_alpha_mask == 0xff000000) {
- dds_format=DDS_BGRA8;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS ) && format_rgb_bits==24 && format_red_mask==0xff0000 && format_green_mask==0xff00 && format_blue_mask==0xff) {
+ dds_format = DDS_BGRA8;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff) {
- dds_format=DDS_BGR8;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0xff && format_green_mask==0xff00 && format_blue_mask==0xff0000 && format_alpha_mask==0xff000000) {
+ dds_format = DDS_BGR8;
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000 && format_alpha_mask == 0xff000000) {
- dds_format=DDS_RGBA8;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS ) && format_rgb_bits==24 && format_red_mask==0xff && format_green_mask==0xff00 && format_blue_mask==0xff0000) {
+ dds_format = DDS_RGBA8;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000) {
- dds_format=DDS_RGB8;
+ dds_format = DDS_RGB8;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==16 && format_red_mask==0x00007c00 && format_green_mask==0x000003e0 && format_blue_mask==0x0000001f && format_alpha_mask==0x00008000) {
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 16 && format_red_mask == 0x00007c00 && format_green_mask == 0x000003e0 && format_blue_mask == 0x0000001f && format_alpha_mask == 0x00008000) {
- dds_format=DDS_BGR5A1;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0x3ff00000 && format_green_mask==0xffc00 && format_blue_mask==0x3ff && format_alpha_mask==0xc0000000) {
+ dds_format = DDS_BGR5A1;
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0x3ff00000 && format_green_mask == 0xffc00 && format_blue_mask == 0x3ff && format_alpha_mask == 0xc0000000) {
- dds_format=DDS_BGR10A2;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==16 && format_red_mask==0x0000f800 && format_green_mask==0x000007e0 && format_blue_mask==0x0000001f) {
+ dds_format = DDS_BGR10A2;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0x0000f800 && format_green_mask == 0x000007e0 && format_blue_mask == 0x0000001f) {
- dds_format=DDS_BGR565;
- } else if (!(format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==8 && format_red_mask==0xff && format_green_mask==0xff && format_blue_mask==0xff) {
+ dds_format = DDS_BGR565;
+ } else if (!(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 8 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff) {
- dds_format=DDS_LUMINANCE;
- } else if ((format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==16 && format_red_mask==0xff && format_green_mask==0xff && format_blue_mask==0xff && format_alpha_mask==0xff00) {
+ dds_format = DDS_LUMINANCE;
+ } else if ((format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff && format_alpha_mask == 0xff00) {
- dds_format=DDS_LUMINANCE_ALPHA;
- } else if (format_flags&DDPF_INDEXED && format_rgb_bits==8) {
+ dds_format = DDS_LUMINANCE_ALPHA;
+ } else if (format_flags & DDPF_INDEXED && format_rgb_bits == 8) {
- dds_format=DDS_BGR565;
+ dds_format = DDS_BGR565;
} else {
- printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n",format_fourcc,format_flags,format_rgb_bits,format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask);
- ERR_EXPLAIN("Unrecognized or Unsupported color layout in DDS: "+p_path);
+ printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n", format_fourcc, format_flags, format_rgb_bits, format_red_mask, format_green_mask, format_blue_mask, format_alpha_mask);
+ ERR_EXPLAIN("Unrecognized or Unsupported color layout in DDS: " + p_path);
ERR_FAIL_V(RES());
-
}
- if (!(flags&DDSD_MIPMAPCOUNT))
- mipmaps=1;
+ if (!(flags & DDSD_MIPMAPCOUNT))
+ mipmaps = 1;
//print_line("found format: "+String(dds_format_info[dds_format].name));
PoolVector<uint8_t> src_data;
- const DDSFormatInfo &info=dds_format_info[dds_format];
+ const DDSFormatInfo &info = dds_format_info[dds_format];
uint32_t w = width;
uint32_t h = height;
-
if (info.compressed) {
//compressed bc
- uint32_t size = MAX( info.divisor, w )/info.divisor * MAX( info.divisor, h )/info.divisor * info.block_size;
- ERR_FAIL_COND_V( size!=pitch, RES() );
- ERR_FAIL_COND_V( !(flags&DDSD_LINEARSIZE), RES() );
+ uint32_t size = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size;
+ ERR_FAIL_COND_V(size != pitch, RES());
+ ERR_FAIL_COND_V(!(flags & DDSD_LINEARSIZE), RES());
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=MAX(1,w>>1);
- h=MAX(1,h>>1);
- uint32_t bsize = MAX( info.divisor, w )/info.divisor * MAX( info.divisor, h )/info.divisor * info.block_size;
+ w = MAX(1, w >> 1);
+ h = MAX(1, h >> 1);
+ uint32_t bsize = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size;
//printf("%i x %i - block: %i\n",w,h,bsize);
- size+= bsize;
+ size += bsize;
}
src_data.resize(size);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
- wb=PoolVector<uint8_t>::Write();
+ f->get_buffer(wb.ptr(), size);
+ wb = PoolVector<uint8_t>::Write();
} else if (info.palette) {
//indexed
- ERR_FAIL_COND_V( !(flags&DDSD_PITCH), RES());
- ERR_FAIL_COND_V( format_rgb_bits!=8, RES() );
+ ERR_FAIL_COND_V(!(flags & DDSD_PITCH), RES());
+ ERR_FAIL_COND_V(format_rgb_bits != 8, RES());
- uint32_t size = pitch*height;
- ERR_FAIL_COND_V( size != width*height * info.block_size, RES());
+ uint32_t size = pitch * height;
+ ERR_FAIL_COND_V(size != width * height * info.block_size, RES());
- uint8_t pallete[256*4];
- f->get_buffer(pallete,256*4);
+ uint8_t pallete[256 * 4];
+ f->get_buffer(pallete, 256 * 4);
- int colsize=3;
- for(int i=0;i<256;i++) {
+ int colsize = 3;
+ for (int i = 0; i < 256; i++) {
- if (pallete[i*4+3]<255)
- colsize=4;
+ if (pallete[i * 4 + 3] < 255)
+ colsize = 4;
}
int w = width;
int h = height;
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=(w+1)>>1;
- h=(h+1)>>1;
- size+= w*h*info.block_size;
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ size += w * h * info.block_size;
}
- src_data.resize(size + 256*colsize );
+ src_data.resize(size + 256 * colsize);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
+ f->get_buffer(wb.ptr(), size);
- for(int i=0;i<256;i++) {
+ for (int i = 0; i < 256; i++) {
- int dst_ofs = size+i*colsize;
- int src_ofs = i*4;
- wb[dst_ofs+0]=pallete[src_ofs+2];
- wb[dst_ofs+1]=pallete[src_ofs+1];
- wb[dst_ofs+2]=pallete[src_ofs+0];
- if (colsize==4)
- wb[dst_ofs+3]=pallete[src_ofs+3];
+ int dst_ofs = size + i * colsize;
+ int src_ofs = i * 4;
+ wb[dst_ofs + 0] = pallete[src_ofs + 2];
+ wb[dst_ofs + 1] = pallete[src_ofs + 1];
+ wb[dst_ofs + 2] = pallete[src_ofs + 0];
+ if (colsize == 4)
+ wb[dst_ofs + 3] = pallete[src_ofs + 3];
}
-
- wb=PoolVector<uint8_t>::Write();
+ wb = PoolVector<uint8_t>::Write();
} else {
//uncompressed generic...
- uint32_t size = width*height*info.block_size;
-
+ uint32_t size = width * height * info.block_size;
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=(w+1)>>1;
- h=(h+1)>>1;
- size+= w*h*info.block_size;
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ size += w * h * info.block_size;
}
- if (dds_format==DDS_BGR565)
- size=size*3/2;
- else if (dds_format==DDS_BGR5A1)
- size=size*2;
+ if (dds_format == DDS_BGR565)
+ size = size * 3 / 2;
+ else if (dds_format == DDS_BGR5A1)
+ size = size * 2;
src_data.resize(size);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
-
+ f->get_buffer(wb.ptr(), size);
- switch(dds_format) {
+ switch (dds_format) {
case DDS_BGR5A1: {
// TO RGBA
- int colcount = size/4;
+ int colcount = size / 4;
- for(int i=colcount-1;i>=0;i--) {
+ for (int i = colcount - 1; i >= 0; i--) {
- int src_ofs = i*2;
- int dst_ofs = i*4;
+ int src_ofs = i * 2;
+ int dst_ofs = i * 4;
- uint8_t a=wb[src_ofs+1]&0x80;
- uint8_t b= wb[src_ofs]&0x1F;
- uint8_t g= (wb[src_ofs]>>5) | ((wb[src_ofs+1]&0x3)<<3);
- uint8_t r= (wb[src_ofs+1]>>2)&0x1F;
- wb[dst_ofs+0]=r<<3;
- wb[dst_ofs+1]=g<<3;
- wb[dst_ofs+2]=b<<3;
- wb[dst_ofs+3]=a?255:0;
+ uint8_t a = wb[src_ofs + 1] & 0x80;
+ uint8_t b = wb[src_ofs] & 0x1F;
+ uint8_t g = (wb[src_ofs] >> 5) | ((wb[src_ofs + 1] & 0x3) << 3);
+ uint8_t r = (wb[src_ofs + 1] >> 2) & 0x1F;
+ wb[dst_ofs + 0] = r << 3;
+ wb[dst_ofs + 1] = g << 3;
+ wb[dst_ofs + 2] = b << 3;
+ wb[dst_ofs + 3] = a ? 255 : 0;
}
} break;
case DDS_BGR565: {
- int colcount = size/3;
-
- for(int i=colcount-1;i>=0;i--) {
+ int colcount = size / 3;
- int src_ofs = i*2;
- int dst_ofs = i*3;
+ for (int i = colcount - 1; i >= 0; i--) {
- uint8_t b= wb[src_ofs]&0x1F;
- uint8_t g= (wb[src_ofs]>>5) | ((wb[src_ofs+1]&0x7)<<3);
- uint8_t r= wb[src_ofs+1]>>3;
- wb[dst_ofs+0]=r<<3;
- wb[dst_ofs+1]=g<<2;
- wb[dst_ofs+2]=b<<3;//b<<3;
+ int src_ofs = i * 2;
+ int dst_ofs = i * 3;
+ uint8_t b = wb[src_ofs] & 0x1F;
+ uint8_t g = (wb[src_ofs] >> 5) | ((wb[src_ofs + 1] & 0x7) << 3);
+ uint8_t r = wb[src_ofs + 1] >> 3;
+ wb[dst_ofs + 0] = r << 3;
+ wb[dst_ofs + 1] = g << 2;
+ wb[dst_ofs + 2] = b << 3; //b<<3;
}
} break;
case DDS_BGR10A2: {
// TO RGBA
- int colcount = size/4;
-
- for(int i=colcount-1;i>=0;i--) {
-
- int ofs = i*4;
+ int colcount = size / 4;
- uint32_t w32 = uint32_t(wb[ofs+0]) | (uint32_t(wb[ofs+1])<<8) | (uint32_t(wb[ofs+2])<<16) | (uint32_t(wb[ofs+3])<<24);
+ for (int i = colcount - 1; i >= 0; i--) {
- uint8_t a= (w32&0xc0000000) >> 24;
- uint8_t r= (w32&0x3ff00000) >> 22;
- uint8_t g= (w32&0xffc00) >> 12;
- uint8_t b= (w32&0x3ff) >> 2;
+ int ofs = i * 4;
+ uint32_t w32 = uint32_t(wb[ofs + 0]) | (uint32_t(wb[ofs + 1]) << 8) | (uint32_t(wb[ofs + 2]) << 16) | (uint32_t(wb[ofs + 3]) << 24);
- wb[ofs+0]=r;
- wb[ofs+1]=g;
- wb[ofs+2]=b;
- wb[ofs+3]=a==0xc0 ? 255 : a; //0xc0 should be opaque
+ uint8_t a = (w32 & 0xc0000000) >> 24;
+ uint8_t r = (w32 & 0x3ff00000) >> 22;
+ uint8_t g = (w32 & 0xffc00) >> 12;
+ uint8_t b = (w32 & 0x3ff) >> 2;
+ wb[ofs + 0] = r;
+ wb[ofs + 1] = g;
+ wb[ofs + 2] = b;
+ wb[ofs + 3] = a == 0xc0 ? 255 : a; //0xc0 should be opaque
}
} break;
case DDS_BGRA8: {
- int colcount = size/4;
+ int colcount = size / 4;
- for(int i=0;i<colcount;i++) {
+ for (int i = 0; i < colcount; i++) {
- SWAP( wb[i*4+0],wb[i*4+2] );
+ SWAP(wb[i * 4 + 0], wb[i * 4 + 2]);
}
} break;
case DDS_BGR8: {
- int colcount = size/3;
+ int colcount = size / 3;
- for(int i=0;i<colcount;i++) {
+ for (int i = 0; i < colcount; i++) {
- SWAP( wb[i*3+0],wb[i*3+2] );
+ SWAP(wb[i * 3 + 0], wb[i * 3 + 2]);
}
} break;
case DDS_RGBA8: {
- /* do nothing either
+ /* do nothing either
int colcount = size/4;
for(int i=0;i<colcount;i++) {
@@ -446,24 +433,20 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
} break;
default: {}
-
}
- wb=PoolVector<uint8_t>::Write();
+ wb = PoolVector<uint8_t>::Write();
}
+ Image img(width, height, mipmaps - 1, info.format, src_data);
- Image img(width,height,mipmaps-1,info.format,src_data);
-
- Ref<ImageTexture> texture = memnew( ImageTexture );
+ Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(img);
if (r_error)
- *r_error=OK;
-
+ *r_error = OK;
return texture;
-
}
void ResourceFormatDDS::get_recognized_extensions(List<String> *p_extensions) const {
@@ -471,14 +454,14 @@ void ResourceFormatDDS::get_recognized_extensions(List<String> *p_extensions) co
p_extensions->push_back("dds");
}
-bool ResourceFormatDDS::handles_type(const String& p_type) const {
+bool ResourceFormatDDS::handles_type(const String &p_type) const {
- return ClassDB::is_parent_class(p_type,"Texture");
+ return ClassDB::is_parent_class(p_type, "Texture");
}
String ResourceFormatDDS::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="dds")
+ if (p_path.get_extension().to_lower() == "dds")
return "ImageTexture";
return "";
}
diff --git a/modules/dds/texture_loader_dds.h b/modules/dds/texture_loader_dds.h
index d09af680c7..c347937cd5 100644
--- a/modules/dds/texture_loader_dds.h
+++ b/modules/dds/texture_loader_dds.h
@@ -29,15 +29,14 @@
#ifndef TEXTURE_LOADER_DDS_H
#define TEXTURE_LOADER_DDS_H
-#include "scene/resources/texture.h"
#include "io/resource_loader.h"
+#include "scene/resources/texture.h"
-class ResourceFormatDDS : public ResourceFormatLoader{
+class ResourceFormatDDS : public ResourceFormatLoader {
public:
-
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual ~ResourceFormatDDS() {}
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index af555b7eb6..2dfb0b4a6a 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -26,98 +26,96 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "os/os.h"
-#include "io/marshalls.h"
#include "networked_multiplayer_enet.h"
+#include "io/marshalls.h"
+#include "os/os.h"
void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) {
- transfer_mode=p_mode;
+ transfer_mode = p_mode;
}
-void NetworkedMultiplayerENet::set_target_peer(int p_peer){
+void NetworkedMultiplayerENet::set_target_peer(int p_peer) {
- target_peer=p_peer;
+ target_peer = p_peer;
}
-int NetworkedMultiplayerENet::get_packet_peer() const{
+int NetworkedMultiplayerENet::get_packet_peer() const {
- ERR_FAIL_COND_V(!active,1);
- ERR_FAIL_COND_V(incoming_packets.size()==0,1);
+ ERR_FAIL_COND_V(!active, 1);
+ ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
return incoming_packets.front()->get().from;
-
}
-Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth){
+Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) {
- ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
ENetAddress address;
address.host = bind_ip;
address.port = p_port;
- host = enet_host_create (& address /* the address to bind the server host to */,
- p_max_clients /* allow up to 32 clients and/or outgoing connections */,
- SYSCH_MAX /* allow up to SYSCH_MAX channels to be used */,
- p_in_bandwidth /* assume any amount of incoming bandwidth */,
- p_out_bandwidth /* assume any amount of outgoing bandwidth */);
+ host = enet_host_create(&address /* the address to bind the server host to */,
+ p_max_clients /* allow up to 32 clients and/or outgoing connections */,
+ SYSCH_MAX /* allow up to SYSCH_MAX channels to be used */,
+ p_in_bandwidth /* assume any amount of incoming bandwidth */,
+ p_out_bandwidth /* assume any amount of outgoing bandwidth */);
- ERR_FAIL_COND_V(!host,ERR_CANT_CREATE);
+ ERR_FAIL_COND_V(!host, ERR_CANT_CREATE);
_setup_compressor();
- active=true;
- server=true;
- refuse_connections=false;
- unique_id=1;
- connection_status=CONNECTION_CONNECTED;
+ active = true;
+ server = true;
+ refuse_connections = false;
+ unique_id = 1;
+ connection_status = CONNECTION_CONNECTED;
return OK;
}
-Error NetworkedMultiplayerENet::create_client(const IP_Address& p_ip, int p_port, int p_in_bandwidth, int p_out_bandwidth){
+Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port, int p_in_bandwidth, int p_out_bandwidth) {
- ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER);
- host = enet_host_create (NULL /* create a client host */,
- 1 /* only allow 1 outgoing connection */,
- SYSCH_MAX /* allow up to SYSCH_MAX channels to be used */,
- p_in_bandwidth /* 56K modem with 56 Kbps downstream bandwidth */,
- p_out_bandwidth /* 56K modem with 14 Kbps upstream bandwidth */);
-
- ERR_FAIL_COND_V(!host,ERR_CANT_CREATE);
+ host = enet_host_create(NULL /* create a client host */,
+ 1 /* only allow 1 outgoing connection */,
+ SYSCH_MAX /* allow up to SYSCH_MAX channels to be used */,
+ p_in_bandwidth /* 56K modem with 56 Kbps downstream bandwidth */,
+ p_out_bandwidth /* 56K modem with 14 Kbps upstream bandwidth */);
+ ERR_FAIL_COND_V(!host, ERR_CANT_CREATE);
_setup_compressor();
ENetAddress address;
- address.host=*((uint32_t *)p_ip.get_ipv4());
- address.port=p_port;
+ address.host = *((uint32_t *)p_ip.get_ipv4());
+ address.port = p_port;
//enet_address_set_host (& address, "localhost");
//address.port = p_port;
- unique_id=_gen_unique_id();
+ unique_id = _gen_unique_id();
/* Initiate the connection, allocating the enough channels */
- ENetPeer *peer = enet_host_connect (host, & address, SYSCH_MAX, unique_id);
+ ENetPeer *peer = enet_host_connect(host, &address, SYSCH_MAX, unique_id);
if (peer == NULL) {
enet_host_destroy(host);
- ERR_FAIL_COND_V(!peer,ERR_CANT_CREATE);
+ ERR_FAIL_COND_V(!peer, ERR_CANT_CREATE);
}
//technically safe to ignore the peer or anything else.
- connection_status=CONNECTION_CONNECTING;
- active=true;
- server=false;
- refuse_connections=false;
+ connection_status = CONNECTION_CONNECTING;
+ active = true;
+ server = false;
+ refuse_connections = false;
return OK;
}
-void NetworkedMultiplayerENet::poll(){
+void NetworkedMultiplayerENet::poll() {
ERR_FAIL_COND(!active);
@@ -130,17 +128,16 @@ void NetworkedMultiplayerENet::poll(){
if (!host || !active) //might have been disconnected while emitting a notification
return;
- int ret = enet_host_service (host, & event, 1);
+ int ret = enet_host_service(host, &event, 1);
- if (ret<0) {
+ if (ret < 0) {
//error, do something?
break;
- } else if (ret==0) {
+ } else if (ret == 0) {
break;
}
- switch (event.type)
- {
+ switch (event.type) {
case ENET_EVENT_TYPE_CONNECT: {
/* Store any relevant client information here. */
@@ -150,39 +147,39 @@ void NetworkedMultiplayerENet::poll(){
}
IP_Address ip;
- ip.set_ipv4((uint8_t *)&(event.peer -> address.host));
+ ip.set_ipv4((uint8_t *)&(event.peer->address.host));
- int *new_id = memnew( int );
+ int *new_id = memnew(int);
*new_id = event.data;
- if (*new_id==0) { //data zero is sent by server (enet won't let you configure this). Server is always 1
- *new_id=1;
+ if (*new_id == 0) { //data zero is sent by server (enet won't let you configure this). Server is always 1
+ *new_id = 1;
}
- event.peer->data=new_id;
+ event.peer->data = new_id;
- peer_map[*new_id]=event.peer;
+ peer_map[*new_id] = event.peer;
- connection_status=CONNECTION_CONNECTED; //if connecting, this means it connected t something!
+ connection_status = CONNECTION_CONNECTED; //if connecting, this means it connected t something!
- emit_signal("peer_connected",*new_id);
+ emit_signal("peer_connected", *new_id);
if (server) {
//someone connected, let it know of all the peers available
- for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
+ for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key()==*new_id)
+ if (E->key() == *new_id)
continue;
//send existing peers to new peer
- ENetPacket * packet = enet_packet_create (NULL,8,ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_ADD_PEER,&packet->data[0]);
- encode_uint32(E->key(),&packet->data[4]);
- enet_peer_send(event.peer,SYSCH_CONFIG,packet);
+ ENetPacket *packet = enet_packet_create(NULL, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
+ encode_uint32(E->key(), &packet->data[4]);
+ enet_peer_send(event.peer, SYSCH_CONFIG, packet);
//send the new peer to existing peers
- packet = enet_packet_create (NULL,8,ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_ADD_PEER,&packet->data[0]);
- encode_uint32(*new_id,&packet->data[4]);
- enet_peer_send(E->get(),SYSCH_CONFIG,packet);
+ packet = enet_packet_create(NULL, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
+ encode_uint32(*new_id, &packet->data[4]);
+ enet_peer_send(E->get(), SYSCH_CONFIG, packet);
}
} else {
@@ -194,9 +191,7 @@ void NetworkedMultiplayerENet::poll(){
/* Reset the peer's client information. */
- int *id = (int*)event.peer -> data;
-
-
+ int *id = (int *)event.peer->data;
if (!id) {
if (!server) {
@@ -206,15 +201,15 @@ void NetworkedMultiplayerENet::poll(){
if (server) {
//someone disconnected, let it know to everyone else
- for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
+ for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key()==*id)
+ if (E->key() == *id)
continue;
//send the new peer to existing peers
- ENetPacket* packet = enet_packet_create (NULL,8,ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_REMOVE_PEER,&packet->data[0]);
- encode_uint32(*id,&packet->data[4]);
- enet_peer_send(E->get(),SYSCH_CONFIG,packet);
+ ENetPacket *packet = enet_packet_create(NULL, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]);
+ encode_uint32(*id, &packet->data[4]);
+ enet_peer_send(E->get(), SYSCH_CONFIG, packet);
}
} else if (!server) {
emit_signal("server_disconnected");
@@ -222,91 +217,87 @@ void NetworkedMultiplayerENet::poll(){
return;
}
- emit_signal("peer_disconnected",*id);
+ emit_signal("peer_disconnected", *id);
peer_map.erase(*id);
- memdelete( id );
-
+ memdelete(id);
}
-
} break;
case ENET_EVENT_TYPE_RECEIVE: {
-
- if (event.channelID==SYSCH_CONFIG) {
+ if (event.channelID == SYSCH_CONFIG) {
//some config message
- ERR_CONTINUE( event.packet->dataLength < 8);
+ ERR_CONTINUE(event.packet->dataLength < 8);
// Only server can send config messages
- ERR_CONTINUE( server );
+ ERR_CONTINUE(server);
int msg = decode_uint32(&event.packet->data[0]);
int id = decode_uint32(&event.packet->data[4]);
- switch(msg) {
+ switch (msg) {
case SYSMSG_ADD_PEER: {
- peer_map[id]=NULL;
- emit_signal("peer_connected",id);
+ peer_map[id] = NULL;
+ emit_signal("peer_connected", id);
} break;
case SYSMSG_REMOVE_PEER: {
peer_map.erase(id);
- emit_signal("peer_disconnected",id);
+ emit_signal("peer_disconnected", id);
} break;
}
enet_packet_destroy(event.packet);
- } else if (event.channelID < SYSCH_MAX){
+ } else if (event.channelID < SYSCH_MAX) {
Packet packet;
packet.packet = event.packet;
- uint32_t *id = (uint32_t*)event.peer->data;
-
- ERR_CONTINUE(event.packet->dataLength<12)
+ uint32_t *id = (uint32_t *)event.peer->data;
+ ERR_CONTINUE(event.packet->dataLength < 12)
uint32_t source = decode_uint32(&event.packet->data[0]);
int target = decode_uint32(&event.packet->data[4]);
uint32_t flags = decode_uint32(&event.packet->data[8]);
- packet.from=source;
+ packet.from = source;
if (server) {
// Someone is cheating and trying to fake the source!
- ERR_CONTINUE(source!=*id);
+ ERR_CONTINUE(source != *id);
- packet.from=*id;
+ packet.from = *id;
- if (target==0) {
+ if (target == 0) {
//re-send the everyone but sender :|
incoming_packets.push_back(packet);
//and make copies for sending
- for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
+ for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key())==source) //do not resend to self
+ if (uint32_t(E->key()) == source) //do not resend to self
continue;
- ENetPacket* packet2 = enet_packet_create (packet.packet->data,packet.packet->dataLength,flags);
+ ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, flags);
- enet_peer_send(E->get(),event.channelID,packet2);
+ enet_peer_send(E->get(), event.channelID, packet2);
}
- } else if (target<0) {
+ } else if (target < 0) {
//to all but one
//and make copies for sending
- for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
+ for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key())==source || E->key()==-target) //do not resend to self, also do not send to excluded
+ if (uint32_t(E->key()) == source || E->key() == -target) //do not resend to self, also do not send to excluded
continue;
- ENetPacket* packet2 = enet_packet_create (packet.packet->data,packet.packet->dataLength,flags);
+ ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, flags);
- enet_peer_send(E->get(),event.channelID,packet2);
+ enet_peer_send(E->get(), event.channelID, packet2);
}
if (-target != 1) {
@@ -317,27 +308,25 @@ void NetworkedMultiplayerENet::poll(){
enet_packet_destroy(packet.packet);
}
- } else if (target==1) {
+ } else if (target == 1) {
//to myself and only myself
incoming_packets.push_back(packet);
} else {
//to someone else, specifically
ERR_CONTINUE(!peer_map.has(target));
- enet_peer_send(peer_map[target],event.channelID,packet.packet);
+ enet_peer_send(peer_map[target], event.channelID, packet.packet);
}
} else {
incoming_packets.push_back(packet);
}
-
//destroy packet later..
} else {
ERR_CONTINUE(true);
}
-
- }break;
+ } break;
case ENET_EVENT_TYPE_NONE: {
//do nothing
} break;
@@ -346,7 +335,7 @@ void NetworkedMultiplayerENet::poll(){
}
bool NetworkedMultiplayerENet::is_server() const {
- ERR_FAIL_COND_V(!active,false);
+ ERR_FAIL_COND_V(!active, false);
return server;
}
@@ -358,115 +347,112 @@ void NetworkedMultiplayerENet::close_connection() {
_pop_current_packet();
- bool peers_disconnected=false;
- for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
+ bool peers_disconnected = false;
+ for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
if (E->get()) {
- enet_peer_disconnect_now(E->get(),unique_id);
- peers_disconnected=true;
+ enet_peer_disconnect_now(E->get(), unique_id);
+ peers_disconnected = true;
}
}
if (peers_disconnected) {
enet_host_flush(host);
OS::get_singleton()->delay_usec(100); //wait 100ms for disconnection packets to send
-
}
enet_host_destroy(host);
- active=false;
+ active = false;
incoming_packets.clear();
- unique_id=1; //server is 1
- connection_status=CONNECTION_DISCONNECTED;
+ unique_id = 1; //server is 1
+ connection_status = CONNECTION_DISCONNECTED;
}
int NetworkedMultiplayerENet::get_available_packet_count() const {
return incoming_packets.size();
}
-Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer,int &r_buffer_size) const{
+Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buffer_size) const {
- ERR_FAIL_COND_V(incoming_packets.size()==0,ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(incoming_packets.size() == 0, ERR_UNAVAILABLE);
_pop_current_packet();
current_packet = incoming_packets.front()->get();
incoming_packets.pop_front();
- *r_buffer=(const uint8_t*)(&current_packet.packet->data[12]);
- r_buffer_size=current_packet.packet->dataLength-12;
+ *r_buffer = (const uint8_t *)(&current_packet.packet->data[12]);
+ r_buffer_size = current_packet.packet->dataLength - 12;
return OK;
}
-Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer,int p_buffer_size){
+Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
- ERR_FAIL_COND_V(!active,ERR_UNCONFIGURED);
- ERR_FAIL_COND_V(connection_status!=CONNECTION_CONNECTED,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!active, ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED);
- int packet_flags=0;
- int channel=SYSCH_RELIABLE;
+ int packet_flags = 0;
+ int channel = SYSCH_RELIABLE;
- switch(transfer_mode) {
+ switch (transfer_mode) {
case TRANSFER_MODE_UNRELIABLE: {
- packet_flags=ENET_PACKET_FLAG_UNSEQUENCED;
- channel=SYSCH_UNRELIABLE;
+ packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
+ channel = SYSCH_UNRELIABLE;
} break;
case TRANSFER_MODE_UNRELIABLE_ORDERED: {
- packet_flags=0;
- channel=SYSCH_UNRELIABLE;
+ packet_flags = 0;
+ channel = SYSCH_UNRELIABLE;
} break;
case TRANSFER_MODE_RELIABLE: {
- packet_flags=ENET_PACKET_FLAG_RELIABLE;
- channel=SYSCH_RELIABLE;
+ packet_flags = ENET_PACKET_FLAG_RELIABLE;
+ channel = SYSCH_RELIABLE;
} break;
}
- Map<int,ENetPeer*>::Element *E=NULL;
+ Map<int, ENetPeer *>::Element *E = NULL;
- if (target_peer!=0) {
+ if (target_peer != 0) {
E = peer_map.find(ABS(target_peer));
if (!E) {
- ERR_EXPLAIN("Invalid Target Peer: "+itos(target_peer));
+ ERR_EXPLAIN("Invalid Target Peer: " + itos(target_peer));
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}
}
- ENetPacket * packet = enet_packet_create (NULL,p_buffer_size+12,packet_flags);
- encode_uint32(unique_id,&packet->data[0]); //source ID
- encode_uint32(target_peer,&packet->data[4]); //dest ID
- encode_uint32(packet_flags,&packet->data[8]); //dest ID
- copymem(&packet->data[12],p_buffer,p_buffer_size);
+ ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 12, packet_flags);
+ encode_uint32(unique_id, &packet->data[0]); //source ID
+ encode_uint32(target_peer, &packet->data[4]); //dest ID
+ encode_uint32(packet_flags, &packet->data[8]); //dest ID
+ copymem(&packet->data[12], p_buffer, p_buffer_size);
if (server) {
- if (target_peer==0) {
- enet_host_broadcast(host,channel,packet);
- } else if (target_peer<0) {
+ if (target_peer == 0) {
+ enet_host_broadcast(host, channel, packet);
+ } else if (target_peer < 0) {
//send to all but one
//and make copies for sending
- int exclude=-target_peer;
+ int exclude = -target_peer;
- for (Map<int,ENetPeer*>::Element *F=peer_map.front();F;F=F->next()) {
+ for (Map<int, ENetPeer *>::Element *F = peer_map.front(); F; F = F->next()) {
- if (F->key()==exclude) // exclude packet
+ if (F->key() == exclude) // exclude packet
continue;
- ENetPacket* packet2 = enet_packet_create (packet->data,packet->dataLength,packet_flags);
+ ENetPacket *packet2 = enet_packet_create(packet->data, packet->dataLength, packet_flags);
- enet_peer_send(F->get(),channel,packet2);
+ enet_peer_send(F->get(), channel, packet2);
}
enet_packet_destroy(packet); //original packet no longer needed
} else {
- enet_peer_send (E->get(), channel, packet);
-
+ enet_peer_send(E->get(), channel, packet);
}
} else {
- ERR_FAIL_COND_V(!peer_map.has(1),ERR_BUG);
- enet_peer_send (peer_map[1], channel, packet); //send to server for broadcast..
-
+ ERR_FAIL_COND_V(!peer_map.has(1), ERR_BUG);
+ enet_peer_send(peer_map[1], channel, packet); //send to server for broadcast..
}
enet_host_flush(host);
@@ -476,17 +462,16 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer,int p_buffer_
int NetworkedMultiplayerENet::get_max_packet_size() const {
- return 1<<24; //anything is good
+ return 1 << 24; //anything is good
}
void NetworkedMultiplayerENet::_pop_current_packet() const {
if (current_packet.packet) {
enet_packet_destroy(current_packet.packet);
- current_packet.packet=NULL;
- current_packet.from=0;
+ current_packet.packet = NULL;
+ current_packet.from = 0;
}
-
}
NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerENet::get_connection_status() const {
@@ -498,24 +483,24 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const {
uint32_t hash = 0;
- while (hash==0 || hash==1) {
+ while (hash == 0 || hash == 1) {
hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_ticks_usec() );
+ (uint32_t)OS::get_singleton()->get_ticks_usec());
hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_unix_time(), hash );
+ (uint32_t)OS::get_singleton()->get_unix_time(), hash);
hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash );
+ (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 );
*/
hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)this), hash ); //rely on aslr heap
+ (uint32_t)((uint64_t)this), hash); //rely on aslr heap
hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)&hash), hash ); //rely on aslr stack
+ (uint32_t)((uint64_t)&hash), hash); //rely on aslr stack
- hash=hash&0x7FFFFFFF; // make it compatible with unsigned, since negatie id is used for exclusion
+ hash = hash & 0x7FFFFFFF; // make it compatible with unsigned, since negatie id is used for exclusion
}
return hash;
@@ -523,13 +508,13 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const {
int NetworkedMultiplayerENet::get_unique_id() const {
- ERR_FAIL_COND_V(!active,0);
+ ERR_FAIL_COND_V(!active, 0);
return unique_id;
}
void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) {
- refuse_connections=p_enable;
+ refuse_connections = p_enable;
}
bool NetworkedMultiplayerENet::is_refusing_new_connections() const {
@@ -539,79 +524,78 @@ bool NetworkedMultiplayerENet::is_refusing_new_connections() const {
void NetworkedMultiplayerENet::set_compression_mode(CompressionMode p_mode) {
- compression_mode=p_mode;
+ compression_mode = p_mode;
}
-NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::get_compression_mode() const{
+NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::get_compression_mode() const {
return compression_mode;
}
-size_t NetworkedMultiplayerENet::enet_compress(void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit) {
+size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
- NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet*)(context);
+ NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context);
- if (size_t(enet->src_compressor_mem.size())<inLimit) {
- enet->src_compressor_mem.resize( inLimit );
+ if (size_t(enet->src_compressor_mem.size()) < inLimit) {
+ enet->src_compressor_mem.resize(inLimit);
}
int total = inLimit;
- int ofs=0;
- while(total) {
- for(size_t i=0;i<inBufferCount;i++) {
- int to_copy = MIN(total,int(inBuffers[i].dataLength));
- copymem(&enet->src_compressor_mem[ofs],inBuffers[i].data,to_copy);
- ofs+=to_copy;
- total-=to_copy;
+ int ofs = 0;
+ while (total) {
+ for (size_t i = 0; i < inBufferCount; i++) {
+ int to_copy = MIN(total, int(inBuffers[i].dataLength));
+ copymem(&enet->src_compressor_mem[ofs], inBuffers[i].data, to_copy);
+ ofs += to_copy;
+ total -= to_copy;
}
}
Compression::Mode mode;
- switch(enet->compression_mode) {
+ switch (enet->compression_mode) {
case COMPRESS_FASTLZ: {
- mode=Compression::MODE_FASTLZ;
+ mode = Compression::MODE_FASTLZ;
} break;
case COMPRESS_ZLIB: {
- mode=Compression::MODE_DEFLATE;
+ mode = Compression::MODE_DEFLATE;
} break;
default: { ERR_FAIL_V(0); }
}
- int req_size = Compression::get_max_compressed_buffer_size(ofs,mode);
- if (enet->dst_compressor_mem.size()<req_size) {
+ int req_size = Compression::get_max_compressed_buffer_size(ofs, mode);
+ if (enet->dst_compressor_mem.size() < req_size) {
enet->dst_compressor_mem.resize(req_size);
}
- int ret=Compression::compress(enet->dst_compressor_mem.ptr(),enet->src_compressor_mem.ptr(),ofs,mode);
+ int ret = Compression::compress(enet->dst_compressor_mem.ptr(), enet->src_compressor_mem.ptr(), ofs, mode);
- if (ret<0)
+ if (ret < 0)
return 0;
-
- if (ret>int(outLimit))
+ if (ret > int(outLimit))
return 0; //do not bother
- copymem(outData,enet->dst_compressor_mem.ptr(),ret);
+ copymem(outData, enet->dst_compressor_mem.ptr(), ret);
return ret;
}
-size_t NetworkedMultiplayerENet::enet_decompress (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit){
+size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
- NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet*)(context);
+ NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context);
int ret = -1;
- switch(enet->compression_mode) {
+ switch (enet->compression_mode) {
case COMPRESS_FASTLZ: {
- ret=Compression::decompress(outData,outLimit,inData,inLimit,Compression::MODE_FASTLZ);
+ ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_FASTLZ);
} break;
case COMPRESS_ZLIB: {
- ret=Compression::decompress(outData,outLimit,inData,inLimit,Compression::MODE_DEFLATE);
+ ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE);
} break;
default: {}
}
- if (ret<0) {
+ if (ret < 0) {
return 0;
} else {
return ret;
@@ -620,11 +604,11 @@ size_t NetworkedMultiplayerENet::enet_decompress (void * context, const enet_uin
void NetworkedMultiplayerENet::_setup_compressor() {
- switch(compression_mode) {
+ switch (compression_mode) {
case COMPRESS_NONE: {
- enet_host_compress(host,NULL);
+ enet_host_compress(host, NULL);
} break;
case COMPRESS_RANGE_CODER: {
enet_host_compress_with_range_coder(host);
@@ -632,60 +616,58 @@ void NetworkedMultiplayerENet::_setup_compressor() {
case COMPRESS_FASTLZ:
case COMPRESS_ZLIB: {
- enet_host_compress(host,&enet_compressor);
+ enet_host_compress(host, &enet_compressor);
} break;
}
}
-void NetworkedMultiplayerENet::enet_compressor_destroy(void * context){
+void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) {
//do none
}
-
void NetworkedMultiplayerENet::_bind_methods() {
- ClassDB::bind_method(D_METHOD("create_server","port","max_clients","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_server,DEFVAL(32),DEFVAL(0),DEFVAL(0));
- ClassDB::bind_method(D_METHOD("create_client","ip","port","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_client,DEFVAL(0),DEFVAL(0));
- ClassDB::bind_method(D_METHOD("close_connection"),&NetworkedMultiplayerENet::close_connection);
- ClassDB::bind_method(D_METHOD("set_compression_mode","mode"),&NetworkedMultiplayerENet::set_compression_mode);
- ClassDB::bind_method(D_METHOD("get_compression_mode"),&NetworkedMultiplayerENet::get_compression_mode);
- ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"),&NetworkedMultiplayerENet::set_bind_ip);
-
- BIND_CONSTANT( COMPRESS_NONE );
- BIND_CONSTANT( COMPRESS_RANGE_CODER );
- BIND_CONSTANT( COMPRESS_FASTLZ );
- BIND_CONSTANT( COMPRESS_ZLIB );
+ ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &NetworkedMultiplayerENet::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("create_client", "ip", "port", "in_bandwidth", "out_bandwidth"), &NetworkedMultiplayerENet::create_client, DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("close_connection"), &NetworkedMultiplayerENet::close_connection);
+ ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode);
+ ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode);
+ ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip);
+
+ BIND_CONSTANT(COMPRESS_NONE);
+ BIND_CONSTANT(COMPRESS_RANGE_CODER);
+ BIND_CONSTANT(COMPRESS_FASTLZ);
+ BIND_CONSTANT(COMPRESS_ZLIB);
}
-
-NetworkedMultiplayerENet::NetworkedMultiplayerENet(){
-
- active=false;
- server=false;
- refuse_connections=false;
- unique_id=0;
- target_peer=0;
- current_packet.packet=NULL;
- transfer_mode=TRANSFER_MODE_RELIABLE;
- connection_status=CONNECTION_DISCONNECTED;
- compression_mode=COMPRESS_NONE;
- enet_compressor.context=this;
- enet_compressor.compress=enet_compress;
- enet_compressor.decompress=enet_decompress;
- enet_compressor.destroy=enet_compressor_destroy;
-
- bind_ip=ENET_HOST_ANY;
+NetworkedMultiplayerENet::NetworkedMultiplayerENet() {
+
+ active = false;
+ server = false;
+ refuse_connections = false;
+ unique_id = 0;
+ target_peer = 0;
+ current_packet.packet = NULL;
+ transfer_mode = TRANSFER_MODE_RELIABLE;
+ connection_status = CONNECTION_DISCONNECTED;
+ compression_mode = COMPRESS_NONE;
+ enet_compressor.context = this;
+ enet_compressor.compress = enet_compress;
+ enet_compressor.decompress = enet_decompress;
+ enet_compressor.destroy = enet_compressor_destroy;
+
+ bind_ip = ENET_HOST_ANY;
}
-NetworkedMultiplayerENet::~NetworkedMultiplayerENet(){
+NetworkedMultiplayerENet::~NetworkedMultiplayerENet() {
close_connection();
}
// sets IP for ENet to bind when using create_server
// if no IP is set, then ENet bind to ENET_HOST_ANY
-void NetworkedMultiplayerENet::set_bind_ip(const IP_Address& p_ip){
+void NetworkedMultiplayerENet::set_bind_ip(const IP_Address &p_ip) {
ERR_FAIL_COND(!p_ip.is_ipv4());
- bind_ip=*(uint32_t *)p_ip.get_ipv4();
+ bind_ip = *(uint32_t *)p_ip.get_ipv4();
}
diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h
index dcf8c2429b..4e95adec10 100644
--- a/modules/enet/networked_multiplayer_enet.h
+++ b/modules/enet/networked_multiplayer_enet.h
@@ -29,13 +29,13 @@
#ifndef NETWORKED_MULTIPLAYER_ENET_H
#define NETWORKED_MULTIPLAYER_ENET_H
-#include "io/networked_multiplayer_peer.h"
#include "enet/enet.h"
#include "io/compression.h"
+#include "io/networked_multiplayer_peer.h"
class NetworkedMultiplayerENet : public NetworkedMultiplayerPeer {
- GDCLASS(NetworkedMultiplayerENet,NetworkedMultiplayerPeer)
+ GDCLASS(NetworkedMultiplayerENet, NetworkedMultiplayerPeer)
public:
enum CompressionMode {
COMPRESS_NONE,
@@ -43,9 +43,8 @@ public:
COMPRESS_FASTLZ,
COMPRESS_ZLIB
};
-private:
-
+private:
enum {
SYSMSG_ADD_PEER,
SYSMSG_REMOVE_PEER
@@ -74,7 +73,7 @@ private:
ConnectionStatus connection_status;
- Map<int,ENetPeer*> peer_map;
+ Map<int, ENetPeer *> peer_map;
struct Packet {
@@ -95,25 +94,24 @@ private:
Vector<uint8_t> dst_compressor_mem;
ENetCompressor enet_compressor;
- static size_t enet_compress(void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
- static size_t enet_decompress (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
- static void enet_compressor_destroy(void * context);
+ static size_t enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit);
+ static size_t enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit);
+ static void enet_compressor_destroy(void *context);
void _setup_compressor();
enet_uint32 bind_ip;
+
protected:
static void _bind_methods();
-public:
+public:
virtual void set_transfer_mode(TransferMode p_mode);
virtual void set_target_peer(int p_peer);
-
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_client(const IP_Address& p_ip, int p_port, int p_in_bandwidth=0, int p_out_bandwidth=0);
+ Error create_server(int p_port, int p_max_peers = 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();
@@ -122,8 +120,8 @@ public:
virtual bool is_server() const;
virtual int get_available_packet_count() const;
- virtual Error get_packet(const uint8_t **r_buffer,int &r_buffer_size) const; ///< buffer is GONE after next get_packet
- virtual Error put_packet(const uint8_t *p_buffer,int p_buffer_size);
+ virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const; ///< buffer is GONE after next get_packet
+ virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const;
@@ -140,10 +138,9 @@ public:
NetworkedMultiplayerENet();
~NetworkedMultiplayerENet();
- void set_bind_ip(const IP_Address& p_ip);
+ void set_bind_ip(const IP_Address &p_ip);
};
VARIANT_ENUM_CAST(NetworkedMultiplayerENet::CompressionMode);
-
#endif // NETWORKED_MULTIPLAYER_ENET_H
diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp
index 2b4dd35d33..0dea038520 100644
--- a/modules/enet/register_types.cpp
+++ b/modules/enet/register_types.cpp
@@ -30,14 +30,14 @@
#include "error_macros.h"
#include "networked_multiplayer_enet.h"
-static bool enet_ok=false;
+static bool enet_ok = false;
void register_enet_types() {
- if (enet_initialize() !=0 ) {
+ if (enet_initialize() != 0) {
ERR_PRINT("ENet initialization failure");
} else {
- enet_ok=true;
+ enet_ok = true;
}
ClassDB::register_class<NetworkedMultiplayerENet>();
@@ -47,5 +47,4 @@ void unregister_enet_types() {
if (enet_ok)
enet_deinitialize();
-
}
diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp
index 2d883bff0f..642ec027f3 100644
--- a/modules/etc1/image_etc.cpp
+++ b/modules/etc1/image_etc.cpp
@@ -28,175 +28,154 @@
/*************************************************************************/
#include "image_etc.h"
#include "image.h"
-#include "rg_etc1.h"
-#include "print_string.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);
+ 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> src = p_img->get_data();
PoolVector<uint8_t> dst;
PoolVector<uint8_t>::Read r = src.read();
- int mmc=p_img->get_mipmap_count();
+ int mmc = p_img->get_mipmap_count();
+ for (int i = 0; i <= mmc; i++) {
- 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)];
+ 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++) {
+ uint8_t *wptr = &w[dst.size() - imgw * imgh * 3];
- for(int x=0;x<bw;x++) {
+ int bw = MAX(imgw / 4, 1);
+ int bh = MAX(imgh / 4, 1);
- uint8_t block[4*4*4];
+ for (int y = 0; y < bh; y++) {
+ for (int x = 0; x < bw; x++) {
- rg_etc1::unpack_etc1_block(srcbr,(unsigned int*)block);
- srcbr+=8;
+ uint8_t block[4 * 4 * 4];
- int maxx=MIN(imgw,4);
- int maxy=MIN(imgh,4);
+ rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block);
+ srcbr += 8;
- for(int yy=0;yy<maxy;yy++) {
+ int maxx = MIN(imgw, 4);
+ int maxy = MIN(imgh, 4);
- for(int xx=0;xx<maxx;xx++) {
+ for (int yy = 0; yy < maxy; yy++) {
- 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];
+ 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);
+ imgw = MAX(1, imgw / 2);
+ imgh = MAX(1, imgh / 2);
}
-
- r=PoolVector<uint8_t>::Read();
+ 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);
+ *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();
+ int imgw = img.get_width(), imgh = img.get_height();
- ERR_FAIL_COND( nearest_power_of_2(imgw)!=imgw || nearest_power_of_2(imgh)!=imgh );
+ ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh);
- if (img.get_format()!=Image::FORMAT_RGB8)
+ 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;
+ 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();
-
+ 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++) {
-
+ 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);
+ 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;
+ int mmsize = MAX(bw, 1) * MAX(bh, 1) * 8;
uint8_t *dst = &w[ofs];
- ofs+=mmsize;
-
+ ofs += mmsize;
//print_line("bh: "+itos(bh)+" bw: "+itos(bw));
- for(int y=0;y<bh;y++) {
+ for (int y = 0; y < bh; y++) {
- for(int x=0;x<bw;x++) {
+ 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 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++) {
+ int maxy = MIN(imgh, 4);
+ int maxx = MIN(imgw, 4);
+ for (int yy = 0; yy < maxy; yy++) {
- 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;
+ 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++) {
+ rg_etc1::pack_etc1_block(cblock, (const unsigned int *)block, pp);
+ for (int j = 0; j < 8; j++) {
- dst[j]=cblock[j];
+ dst[j] = cblock[j];
}
- dst+=8;
+ dst += 8;
}
-
}
- imgw=MAX(1,imgw/2);
- imgh=MAX(1,imgh/2);
+ 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);
-
-
+ *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;
-
-
+ Image::_image_compress_etc_func = _compress_etc;
+ Image::_image_decompress_etc = _decompress_etc;
}
diff --git a/modules/etc1/image_etc.h b/modules/etc1/image_etc.h
index 6ab10126f8..18461819d6 100644
--- a/modules/etc1/image_etc.h
+++ b/modules/etc1/image_etc.h
@@ -29,7 +29,6 @@
#ifndef IMAGE_ETC1_H
#define IMAGE_ETC1_H
-
void _register_etc1_compress_func();
#endif // IMAGE_ETC_H
diff --git a/modules/etc1/register_types.cpp b/modules/etc1/register_types.cpp
index d02ef83478..b3b6419d26 100644
--- a/modules/etc1/register_types.cpp
+++ b/modules/etc1/register_types.cpp
@@ -35,7 +35,7 @@ static ResourceFormatPKM *resource_loader_pkm = NULL;
void register_etc1_types() {
- resource_loader_pkm = memnew( ResourceFormatPKM );
+ resource_loader_pkm = memnew(ResourceFormatPKM);
ResourceLoader::add_resource_format_loader(resource_loader_pkm);
_register_etc1_compress_func();
diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp
index b00e71c485..bce10e691e 100644
--- a/modules/etc1/texture_loader_pkm.cpp
+++ b/modules/etc1/texture_loader_pkm.cpp
@@ -32,38 +32,38 @@
#include <string.h>
struct ETC1Header {
- char tag[6]; // "PKM 10"
- uint16_t format; // Format == number of mips (== zero)
- uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian)
- uint16_t texHeight;
- uint16_t origWidth; // Original dimensions (big-endian)
- uint16_t origHeight;
+ char tag[6]; // "PKM 10"
+ uint16_t format; // Format == number of mips (== zero)
+ uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian)
+ uint16_t texHeight;
+ uint16_t origWidth; // Original dimensions (big-endian)
+ uint16_t origHeight;
};
-RES ResourceFormatPKM::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_CANT_OPEN;
+ *r_error = ERR_CANT_OPEN;
Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (!f)
return RES();
FileAccessRef fref(f);
if (r_error)
- *r_error=ERR_FILE_CORRUPT;
+ *r_error = ERR_FILE_CORRUPT;
- ERR_EXPLAIN("Unable to open PKM texture file: "+p_path);
- ERR_FAIL_COND_V(err!=OK,RES());
+ ERR_EXPLAIN("Unable to open PKM texture file: " + p_path);
+ ERR_FAIL_COND_V(err != OK, RES());
// big endian
f->set_endian_swap(true);
ETC1Header h;
- ERR_EXPLAIN("Invalid or Unsupported PKM texture file: "+p_path);
- f->get_buffer((uint8_t *) &h.tag, sizeof(h.tag));
- if(strncmp(h.tag, "PKM 10", sizeof(h.tag)))
+ ERR_EXPLAIN("Invalid or Unsupported PKM texture file: " + p_path);
+ f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag));
+ if (strncmp(h.tag, "PKM 10", sizeof(h.tag)))
ERR_FAIL_V(RES());
h.format = f->get_16();
@@ -77,20 +77,20 @@ RES ResourceFormatPKM::load(const String &p_path, const String& p_original_path,
uint32_t size = h.texWidth * h.texHeight / 2;
src_data.resize(size);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
- wb=PoolVector<uint8_t>::Write();
+ f->get_buffer(wb.ptr(), size);
+ wb = PoolVector<uint8_t>::Write();
int mipmaps = h.format;
int width = h.origWidth;
int height = h.origHeight;
- Image img(width,height,mipmaps,Image::FORMAT_ETC,src_data);
+ Image img(width, height, mipmaps, Image::FORMAT_ETC, src_data);
- Ref<ImageTexture> texture = memnew( ImageTexture );
+ Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(img);
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return texture;
}
@@ -100,14 +100,14 @@ void ResourceFormatPKM::get_recognized_extensions(List<String> *p_extensions) co
p_extensions->push_back("pkm");
}
-bool ResourceFormatPKM::handles_type(const String& p_type) const {
+bool ResourceFormatPKM::handles_type(const String &p_type) const {
- return ClassDB::is_parent_class(p_type,"Texture");
+ return ClassDB::is_parent_class(p_type, "Texture");
}
String ResourceFormatPKM::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="pkm")
+ if (p_path.get_extension().to_lower() == "pkm")
return "ImageTexture";
return "";
}
diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc1/texture_loader_pkm.h
index 9be7b051d3..19d15d21fc 100644
--- a/modules/etc1/texture_loader_pkm.h
+++ b/modules/etc1/texture_loader_pkm.h
@@ -29,15 +29,14 @@
#ifndef TEXTURE_LOADER_PKM_H
#define TEXTURE_LOADER_PKM_H
-#include "scene/resources/texture.h"
#include "io/resource_loader.h"
+#include "scene/resources/texture.h"
-class ResourceFormatPKM : public ResourceFormatLoader{
+class ResourceFormatPKM : public ResourceFormatLoader {
public:
-
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual ~ResourceFormatPKM() {}
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index 398c2cf82a..9591740438 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -29,53 +29,51 @@
#include "gd_compiler.h"
#include "gd_script.h"
-bool GDCompiler::_is_class_member_property(CodeGen & codegen, const StringName & p_name) {
+bool GDCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) {
if (!codegen.function_node || codegen.function_node->_static)
return false;
- return _is_class_member_property(codegen.script,p_name);
+ return _is_class_member_property(codegen.script, p_name);
}
-bool GDCompiler::_is_class_member_property(GDScript *owner, const StringName & p_name) {
-
+bool GDCompiler::_is_class_member_property(GDScript *owner, const StringName &p_name) {
GDScript *scr = owner;
- GDNativeClass *nc=NULL;
- while(scr) {
+ GDNativeClass *nc = NULL;
+ while (scr) {
if (scr->native.is_valid())
- nc=scr->native.ptr();
- scr=scr->_base;
+ nc = scr->native.ptr();
+ scr = scr->_base;
}
- ERR_FAIL_COND_V(!nc,false);
+ ERR_FAIL_COND_V(!nc, false);
- return ClassDB::has_property(nc->get_name(),p_name);
+ return ClassDB::has_property(nc->get_name(), p_name);
}
+void GDCompiler::_set_error(const String &p_error, const GDParser::Node *p_node) {
-void GDCompiler::_set_error(const String& p_error,const GDParser::Node *p_node) {
-
- if (error!="")
+ if (error != "")
return;
- error=p_error;
+ error = p_error;
if (p_node) {
- err_line=p_node->line;
- err_column=p_node->column;
+ err_line = p_node->line;
+ err_column = p_node->column;
} else {
- err_line=0;
- err_column=0;
+ err_line = 0;
+ err_column = 0;
}
}
-bool GDCompiler::_create_unary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level) {
+bool GDCompiler::_create_unary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level) {
- ERR_FAIL_COND_V(on->arguments.size()!=1,false);
+ ERR_FAIL_COND_V(on->arguments.size() != 1, false);
- int src_address_a = _parse_expression(codegen,on->arguments[0],p_stack_level);
- if (src_address_a<0)
+ int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level);
+ if (src_address_a < 0)
return false;
codegen.opcodes.push_back(GDFunction::OPCODE_OPERATOR); // perform operator
@@ -86,22 +84,20 @@ bool GDCompiler::_create_unary_operator(CodeGen& codegen,const GDParser::Operato
return true;
}
-bool GDCompiler::_create_binary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level,bool p_initializer) {
-
- ERR_FAIL_COND_V(on->arguments.size()!=2,false);
+bool GDCompiler::_create_binary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer) {
+ ERR_FAIL_COND_V(on->arguments.size() != 2, false);
- int src_address_a = _parse_expression(codegen,on->arguments[0],p_stack_level,false,p_initializer);
- if (src_address_a<0)
+ int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level, false, p_initializer);
+ if (src_address_a < 0)
return false;
- if (src_address_a&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)
+ if (src_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)
p_stack_level++; //uses stack for return, increase stack
- int src_address_b = _parse_expression(codegen,on->arguments[1],p_stack_level,false,p_initializer);
- if (src_address_b<0)
+ int src_address_b = _parse_expression(codegen, on->arguments[1], p_stack_level, false, p_initializer);
+ if (src_address_b < 0)
return false;
-
codegen.opcodes.push_back(GDFunction::OPCODE_OPERATOR); // perform operator
codegen.opcodes.push_back(op); //which operator
codegen.opcodes.push_back(src_address_a); // argument 1
@@ -109,7 +105,6 @@ bool GDCompiler::_create_binary_operator(CodeGen& codegen,const GDParser::Operat
return true;
}
-
/*
int GDCompiler::_parse_subexpression(CodeGen& codegen,const GDParser::Node *p_expression) {
@@ -128,55 +123,52 @@ int GDCompiler::_parse_subexpression(CodeGen& codegen,const GDParser::Node *p_ex
}
*/
-int GDCompiler::_parse_assign_right_expression(CodeGen& codegen,const GDParser::OperatorNode *p_expression, int p_stack_level) {
+int GDCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDParser::OperatorNode *p_expression, int p_stack_level) {
- Variant::Operator var_op=Variant::OP_MAX;
+ Variant::Operator var_op = Variant::OP_MAX;
+ switch (p_expression->op) {
- switch(p_expression->op) {
-
- case GDParser::OperatorNode::OP_ASSIGN_ADD: var_op=Variant::OP_ADD; break;
- case GDParser::OperatorNode::OP_ASSIGN_SUB: var_op=Variant::OP_SUBSTRACT; break;
- case GDParser::OperatorNode::OP_ASSIGN_MUL: var_op=Variant::OP_MULTIPLY; break;
- case GDParser::OperatorNode::OP_ASSIGN_DIV: var_op=Variant::OP_DIVIDE; break;
- case GDParser::OperatorNode::OP_ASSIGN_MOD: var_op=Variant::OP_MODULE; break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: var_op=Variant::OP_SHIFT_LEFT; break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: var_op=Variant::OP_SHIFT_RIGHT; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: var_op=Variant::OP_BIT_AND; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: var_op=Variant::OP_BIT_OR; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: var_op=Variant::OP_BIT_XOR; break;
+ case GDParser::OperatorNode::OP_ASSIGN_ADD: var_op = Variant::OP_ADD; break;
+ case GDParser::OperatorNode::OP_ASSIGN_SUB: var_op = Variant::OP_SUBSTRACT; break;
+ case GDParser::OperatorNode::OP_ASSIGN_MUL: var_op = Variant::OP_MULTIPLY; break;
+ case GDParser::OperatorNode::OP_ASSIGN_DIV: var_op = Variant::OP_DIVIDE; break;
+ case GDParser::OperatorNode::OP_ASSIGN_MOD: var_op = Variant::OP_MODULE; break;
+ case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: var_op = Variant::OP_SHIFT_LEFT; break;
+ case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: var_op = Variant::OP_SHIFT_RIGHT; break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: var_op = Variant::OP_BIT_AND; break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: var_op = Variant::OP_BIT_OR; break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: var_op = Variant::OP_BIT_XOR; break;
case GDParser::OperatorNode::OP_INIT_ASSIGN:
case GDParser::OperatorNode::OP_ASSIGN: {
//none
} break;
- default: {
+ default: {
ERR_FAIL_V(-1);
}
}
- bool initializer = p_expression->op==GDParser::OperatorNode::OP_INIT_ASSIGN;
+ bool initializer = p_expression->op == GDParser::OperatorNode::OP_INIT_ASSIGN;
- if (var_op==Variant::OP_MAX) {
+ if (var_op == Variant::OP_MAX) {
- return _parse_expression(codegen,p_expression->arguments[1],p_stack_level,false,initializer);
+ return _parse_expression(codegen, p_expression->arguments[1], p_stack_level, false, initializer);
}
- if (!_create_binary_operator(codegen,p_expression,var_op,p_stack_level,initializer))
+ if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer))
return -1;
- int dst_addr=(p_stack_level)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
codegen.alloc_stack(p_stack_level);
return dst_addr;
-
}
-int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expression, int p_stack_level,bool p_root,bool p_initializer) {
+int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expression, int p_stack_level, bool p_root, bool p_initializer) {
-
- switch(p_expression->type) {
+ switch (p_expression->type) {
//should parse variable declaration and adjust stack accordingly...
case GDParser::Node::TYPE_IDENTIFIER: {
//return identifier
@@ -185,16 +177,15 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
//This could be made much simpler by just indexing "self", but done this way (with custom self-addressing modes) increases peformance a lot.
- const GDParser::IdentifierNode *in = static_cast<const GDParser::IdentifierNode*>(p_expression);
+ const GDParser::IdentifierNode *in = static_cast<const GDParser::IdentifierNode *>(p_expression);
StringName identifier = in->name;
-
- if (_is_class_member_property(codegen,identifier)) {
+ if (_is_class_member_property(codegen, identifier)) {
//get property
codegen.opcodes.push_back(GDFunction::OPCODE_GET_MEMBER); // perform operator
codegen.opcodes.push_back(codegen.get_name_map_pos(identifier)); // argument 2 (unary only takes one parameter)
- int dst_addr=(p_stack_level)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
codegen.alloc_stack(p_stack_level);
return dst_addr;
@@ -204,8 +195,7 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
if (!p_initializer && codegen.stack_identifiers.has(identifier)) {
int pos = codegen.stack_identifiers[identifier];
- return pos|(GDFunction::ADDR_TYPE_STACK_VARIABLE<<GDFunction::ADDR_BITS);
-
+ return pos | (GDFunction::ADDR_TYPE_STACK_VARIABLE << GDFunction::ADDR_BITS);
}
//TRY MEMBERS!
if (!codegen.function_node || !codegen.function_node->_static) {
@@ -215,7 +205,7 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
if (codegen.script->member_indices.has(identifier)) {
int idx = codegen.script->member_indices[identifier].index;
- return idx|(GDFunction::ADDR_TYPE_MEMBER<<GDFunction::ADDR_BITS); //argument (stack root)
+ return idx | (GDFunction::ADDR_TYPE_MEMBER << GDFunction::ADDR_BITS); //argument (stack root)
}
}
@@ -225,45 +215,44 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
while (owner) {
GDScript *scr = owner;
- GDNativeClass *nc=NULL;
- while(scr) {
+ GDNativeClass *nc = NULL;
+ while (scr) {
if (scr->constants.has(identifier)) {
//int idx=scr->constants[identifier];
int idx = codegen.get_name_map_pos(identifier);
- return idx|(GDFunction::ADDR_TYPE_CLASS_CONSTANT<<GDFunction::ADDR_BITS); //argument (stack root)
+ return idx | (GDFunction::ADDR_TYPE_CLASS_CONSTANT << GDFunction::ADDR_BITS); //argument (stack root)
}
if (scr->native.is_valid())
- nc=scr->native.ptr();
- scr=scr->_base;
+ nc = scr->native.ptr();
+ scr = scr->_base;
}
// CLASS C++ Integer Constant
if (nc) {
- bool success=false;
- int constant = ClassDB::get_integer_constant(nc->get_name(),identifier,&success);
+ bool success = false;
+ int constant = ClassDB::get_integer_constant(nc->get_name(), identifier, &success);
if (success) {
- Variant key=constant;
+ Variant key = constant;
int idx;
if (!codegen.constant_map.has(key)) {
- idx=codegen.constant_map.size();
- codegen.constant_map[key]=idx;
+ idx = codegen.constant_map.size();
+ codegen.constant_map[key] = idx;
} else {
- idx=codegen.constant_map[key];
+ idx = codegen.constant_map[key];
}
- return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
+ return idx | (GDFunction::ADDR_TYPE_LOCAL_CONSTANT << GDFunction::ADDR_BITS); //make it a local constant (faster access)
}
-
}
- owner=owner->_owner;
+ owner = owner->_owner;
}
/*
@@ -278,58 +267,55 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
int idx = GDScriptLanguage::get_singleton()->get_global_map()[identifier];
- return idx|(GDFunction::ADDR_TYPE_GLOBAL<<GDFunction::ADDR_BITS); //argument (stack root)
+ return idx | (GDFunction::ADDR_TYPE_GLOBAL << GDFunction::ADDR_BITS); //argument (stack root)
}
//not found, error
- _set_error("Identifier not found: "+String(identifier),p_expression);
+ _set_error("Identifier not found: " + String(identifier), p_expression);
return -1;
-
} break;
case GDParser::Node::TYPE_CONSTANT: {
//return constant
- const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode*>(p_expression);
-
+ const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(p_expression);
int idx;
if (!codegen.constant_map.has(cn->value)) {
- idx=codegen.constant_map.size();
- codegen.constant_map[cn->value]=idx;
+ idx = codegen.constant_map.size();
+ codegen.constant_map[cn->value] = idx;
} else {
- idx=codegen.constant_map[cn->value];
+ idx = codegen.constant_map[cn->value];
}
-
- return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //argument (stack root)
+ return idx | (GDFunction::ADDR_TYPE_LOCAL_CONSTANT << GDFunction::ADDR_BITS); //argument (stack root)
} break;
case GDParser::Node::TYPE_SELF: {
//return constant
if (codegen.function_node && codegen.function_node->_static) {
- _set_error("'self' not present in static function!",p_expression);
+ _set_error("'self' not present in static function!", p_expression);
return -1;
}
- return (GDFunction::ADDR_TYPE_SELF<<GDFunction::ADDR_BITS);
+ return (GDFunction::ADDR_TYPE_SELF << GDFunction::ADDR_BITS);
} break;
case GDParser::Node::TYPE_ARRAY: {
- const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode*>(p_expression);
+ const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(p_expression);
Vector<int> values;
- int slevel=p_stack_level;
+ int slevel = p_stack_level;
- for(int i=0;i<an->elements.size();i++) {
+ for (int i = 0; i < an->elements.size(); i++) {
- int ret = _parse_expression(codegen,an->elements[i],slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, an->elements[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -339,10 +325,10 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
codegen.opcodes.push_back(GDFunction::OPCODE_CONSTRUCT_ARRAY);
codegen.opcodes.push_back(values.size());
- for(int i=0;i<values.size();i++)
+ for (int i = 0; i < values.size(); i++)
codegen.opcodes.push_back(values[i]);
- int dst_addr=(p_stack_level)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
codegen.alloc_stack(p_stack_level);
return dst_addr;
@@ -350,27 +336,27 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
} break;
case GDParser::Node::TYPE_DICTIONARY: {
- const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode*>(p_expression);
+ const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode *>(p_expression);
Vector<int> values;
- int slevel=p_stack_level;
+ int slevel = p_stack_level;
- for(int i=0;i<dn->elements.size();i++) {
+ for (int i = 0; i < dn->elements.size(); i++) {
- int ret = _parse_expression(codegen,dn->elements[i].key,slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, dn->elements[i].key, slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
values.push_back(ret);
- ret = _parse_expression(codegen,dn->elements[i].value,slevel);
- if (ret<0)
+ ret = _parse_expression(codegen, dn->elements[i].value, slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -380,10 +366,10 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
codegen.opcodes.push_back(GDFunction::OPCODE_CONSTRUCT_DICTIONARY);
codegen.opcodes.push_back(dn->elements.size());
- for(int i=0;i<values.size();i++)
+ for (int i = 0; i < values.size(); i++)
codegen.opcodes.push_back(values[i]);
- int dst_addr=(p_stack_level)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
codegen.alloc_stack(p_stack_level);
return dst_addr;
@@ -392,27 +378,24 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
case GDParser::Node::TYPE_OPERATOR: {
//hell breaks loose
- const GDParser::OperatorNode *on = static_cast<const GDParser::OperatorNode*>(p_expression);
- switch(on->op) {
-
+ const GDParser::OperatorNode *on = static_cast<const GDParser::OperatorNode *>(p_expression);
+ switch (on->op) {
//call/constructor operator
case GDParser::OperatorNode::OP_PARENT_CALL: {
-
- ERR_FAIL_COND_V(on->arguments.size()<1,-1);
+ ERR_FAIL_COND_V(on->arguments.size() < 1, -1);
const GDParser::IdentifierNode *in = (const GDParser::IdentifierNode *)on->arguments[0];
-
Vector<int> arguments;
int slevel = p_stack_level;
- for(int i=1;i<on->arguments.size();i++) {
+ for (int i = 1; i < on->arguments.size(); i++) {
- int ret = _parse_expression(codegen,on->arguments[i],slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, on->arguments[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -425,27 +408,27 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
codegen.opcodes.push_back(codegen.get_name_map_pos(in->name)); //instance
codegen.opcodes.push_back(arguments.size()); //argument count
codegen.alloc_call(arguments.size());
- for(int i=0;i<arguments.size();i++)
+ for (int i = 0; i < arguments.size(); i++)
codegen.opcodes.push_back(arguments[i]); //arguments
} break;
case GDParser::OperatorNode::OP_CALL: {
- if (on->arguments[0]->type==GDParser::Node::TYPE_TYPE) {
+ if (on->arguments[0]->type == GDParser::Node::TYPE_TYPE) {
//construct a basic type
- ERR_FAIL_COND_V(on->arguments.size()<1,-1);
+ ERR_FAIL_COND_V(on->arguments.size() < 1, -1);
const GDParser::TypeNode *tn = (const GDParser::TypeNode *)on->arguments[0];
int vtype = tn->vtype;
Vector<int> arguments;
int slevel = p_stack_level;
- for(int i=1;i<on->arguments.size();i++) {
+ for (int i = 1; i < on->arguments.size(); i++) {
- int ret = _parse_expression(codegen,on->arguments[i],slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, on->arguments[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -457,24 +440,23 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
codegen.opcodes.push_back(vtype); //instance
codegen.opcodes.push_back(arguments.size()); //argument count
codegen.alloc_call(arguments.size());
- for(int i=0;i<arguments.size();i++)
+ for (int i = 0; i < arguments.size(); i++)
codegen.opcodes.push_back(arguments[i]); //arguments
- } else if (on->arguments[0]->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
+ } else if (on->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
//built in function
- ERR_FAIL_COND_V(on->arguments.size()<1,-1);
-
+ ERR_FAIL_COND_V(on->arguments.size() < 1, -1);
Vector<int> arguments;
int slevel = p_stack_level;
- for(int i=1;i<on->arguments.size();i++) {
+ for (int i = 1; i < on->arguments.size(); i++) {
- int ret = _parse_expression(codegen,on->arguments[i],slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, on->arguments[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -482,79 +464,74 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
arguments.push_back(ret);
}
-
codegen.opcodes.push_back(GDFunction::OPCODE_CALL_BUILT_IN);
- codegen.opcodes.push_back(static_cast<const GDParser::BuiltInFunctionNode*>(on->arguments[0])->function);
- codegen.opcodes.push_back(on->arguments.size()-1);
- codegen.alloc_call(on->arguments.size()-1);
- for(int i=0;i<arguments.size();i++)
+ codegen.opcodes.push_back(static_cast<const GDParser::BuiltInFunctionNode *>(on->arguments[0])->function);
+ codegen.opcodes.push_back(on->arguments.size() - 1);
+ codegen.alloc_call(on->arguments.size() - 1);
+ for (int i = 0; i < arguments.size(); i++)
codegen.opcodes.push_back(arguments[i]);
} else {
//regular function
- ERR_FAIL_COND_V(on->arguments.size()<2,-1);
+ ERR_FAIL_COND_V(on->arguments.size() < 2, -1);
const GDParser::Node *instance = on->arguments[0];
- if (instance->type==GDParser::Node::TYPE_SELF) {
+ if (instance->type == GDParser::Node::TYPE_SELF) {
//room for optimization
-
}
-
Vector<int> arguments;
int slevel = p_stack_level;
- for(int i=0;i<on->arguments.size();i++) {
+ for (int i = 0; i < on->arguments.size(); i++) {
int ret;
- if (i==0 && on->arguments[i]->type==GDParser::Node::TYPE_SELF && codegen.function_node && codegen.function_node->_static) {
+ if (i == 0 && on->arguments[i]->type == GDParser::Node::TYPE_SELF && codegen.function_node && codegen.function_node->_static) {
//static call to self
- ret=(GDFunction::ADDR_TYPE_CLASS<<GDFunction::ADDR_BITS);
- } else if (i==1) {
+ ret = (GDFunction::ADDR_TYPE_CLASS << GDFunction::ADDR_BITS);
+ } else if (i == 1) {
- if (on->arguments[i]->type!=GDParser::Node::TYPE_IDENTIFIER) {
- _set_error("Attempt to call a non-identifier.",on);
+ if (on->arguments[i]->type != GDParser::Node::TYPE_IDENTIFIER) {
+ _set_error("Attempt to call a non-identifier.", on);
return -1;
}
- GDParser::IdentifierNode *id = static_cast<GDParser::IdentifierNode*>(on->arguments[i]);
- ret=codegen.get_name_map_pos(id->name);
+ GDParser::IdentifierNode *id = static_cast<GDParser::IdentifierNode *>(on->arguments[i]);
+ ret = codegen.get_name_map_pos(id->name);
} else {
- ret = _parse_expression(codegen,on->arguments[i],slevel);
- if (ret<0)
+ ret = _parse_expression(codegen, on->arguments[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
}
arguments.push_back(ret);
-
}
- codegen.opcodes.push_back(p_root?GDFunction::OPCODE_CALL:GDFunction::OPCODE_CALL_RETURN); // perform operator
- codegen.opcodes.push_back(on->arguments.size()-2);
- codegen.alloc_call(on->arguments.size()-2);
- for(int i=0;i<arguments.size();i++)
+ codegen.opcodes.push_back(p_root ? GDFunction::OPCODE_CALL : GDFunction::OPCODE_CALL_RETURN); // perform operator
+ codegen.opcodes.push_back(on->arguments.size() - 2);
+ codegen.alloc_call(on->arguments.size() - 2);
+ for (int i = 0; i < arguments.size(); i++)
codegen.opcodes.push_back(arguments[i]);
}
} break;
case GDParser::OperatorNode::OP_YIELD: {
-
- ERR_FAIL_COND_V(on->arguments.size() && on->arguments.size()!=2,-1);
+ ERR_FAIL_COND_V(on->arguments.size() && on->arguments.size() != 2, -1);
Vector<int> arguments;
int slevel = p_stack_level;
- for(int i=0;i<on->arguments.size();i++) {
+ for (int i = 0; i < on->arguments.size(); i++) {
- int ret = _parse_expression(codegen,on->arguments[i],slevel);
- if (ret<0)
+ int ret = _parse_expression(codegen, on->arguments[i], slevel);
+ if (ret < 0)
return ret;
- if (ret&(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)) {
+ if (ret & (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -562,8 +539,8 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
}
//push call bytecode
- codegen.opcodes.push_back(arguments.size()==0?GDFunction::OPCODE_YIELD:GDFunction::OPCODE_YIELD_SIGNAL); // basic type constructor
- for(int i=0;i<arguments.size();i++)
+ codegen.opcodes.push_back(arguments.size() == 0 ? GDFunction::OPCODE_YIELD : GDFunction::OPCODE_YIELD_SIGNAL); // basic type constructor
+ for (int i = 0; i < arguments.size(); i++)
codegen.opcodes.push_back(arguments[i]); //arguments
codegen.opcodes.push_back(GDFunction::OPCODE_YIELD_RESUME);
//next will be where to place the result :)
@@ -574,60 +551,60 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
case GDParser::OperatorNode::OP_INDEX:
case GDParser::OperatorNode::OP_INDEX_NAMED: {
- ERR_FAIL_COND_V(on->arguments.size()!=2,-1);
+ ERR_FAIL_COND_V(on->arguments.size() != 2, -1);
int slevel = p_stack_level;
- bool named=(on->op==GDParser::OperatorNode::OP_INDEX_NAMED);
+ bool named = (on->op == GDParser::OperatorNode::OP_INDEX_NAMED);
- int from = _parse_expression(codegen,on->arguments[0],slevel);
- if (from<0)
+ int from = _parse_expression(codegen, on->arguments[0], slevel);
+ if (from < 0)
return from;
int index;
if (named) {
- if (on->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
+ if (on->arguments[0]->type == GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
- GDParser::IdentifierNode* identifier = static_cast<GDParser::IdentifierNode*>(on->arguments[1]);
- const Map<StringName,GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(identifier->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);
+ 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=="") {
+ 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);
+ 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);
+ index = codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode *>(on->arguments[1])->name);
} else {
- if (on->arguments[1]->type==GDParser::Node::TYPE_CONSTANT && static_cast<const GDParser::ConstantNode*>(on->arguments[1])->value.get_type()==Variant::STRING) {
+ if (on->arguments[1]->type == GDParser::Node::TYPE_CONSTANT && static_cast<const GDParser::ConstantNode *>(on->arguments[1])->value.get_type() == Variant::STRING) {
//also, somehow, named (speed up anyway)
- StringName name = static_cast<const GDParser::ConstantNode*>(on->arguments[1])->value;
- index=codegen.get_name_map_pos(name);
- named=true;
+ StringName name = static_cast<const GDParser::ConstantNode *>(on->arguments[1])->value;
+ index = codegen.get_name_map_pos(name);
+ named = true;
} else {
//regular indexing
- if (from&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (from & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
- index = _parse_expression(codegen,on->arguments[1],slevel);
- if (index<0)
+ index = _parse_expression(codegen, on->arguments[1], slevel);
+ if (index < 0)
return index;
}
}
- codegen.opcodes.push_back(named?GDFunction::OPCODE_GET_NAMED:GDFunction::OPCODE_GET); // perform operator
+ codegen.opcodes.push_back(named ? GDFunction::OPCODE_GET_NAMED : GDFunction::OPCODE_GET); // perform operator
codegen.opcodes.push_back(from); // argument 1
codegen.opcodes.push_back(index); // argument 2 (unary only takes one parameter)
@@ -636,66 +613,66 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
// AND operator with early out on failure
- int res = _parse_expression(codegen,on->arguments[0],p_stack_level);
- if (res<0)
+ int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
+ if (res < 0)
return res;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
- int jump_fail_pos=codegen.opcodes.size();
+ int jump_fail_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
- res = _parse_expression(codegen,on->arguments[1],p_stack_level);
- if (res<0)
+ res = _parse_expression(codegen, on->arguments[1], p_stack_level);
+ if (res < 0)
return res;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
- int jump_fail_pos2=codegen.opcodes.size();
+ int jump_fail_pos2 = codegen.opcodes.size();
codegen.opcodes.push_back(0);
codegen.alloc_stack(p_stack_level); //it will be used..
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_TRUE);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
- codegen.opcodes.push_back(codegen.opcodes.size()+3);
- codegen.opcodes[jump_fail_pos]=codegen.opcodes.size();
- codegen.opcodes[jump_fail_pos2]=codegen.opcodes.size();
+ codegen.opcodes.push_back(codegen.opcodes.size() + 3);
+ codegen.opcodes[jump_fail_pos] = codegen.opcodes.size();
+ codegen.opcodes[jump_fail_pos2] = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_FALSE);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
- return p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS;
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
+ return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS;
} break;
case GDParser::OperatorNode::OP_OR: {
// OR operator with early out on success
- int res = _parse_expression(codegen,on->arguments[0],p_stack_level);
- if (res<0)
+ int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
+ if (res < 0)
return res;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF);
codegen.opcodes.push_back(res);
- int jump_success_pos=codegen.opcodes.size();
+ int jump_success_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
- res = _parse_expression(codegen,on->arguments[1],p_stack_level);
- if (res<0)
+ res = _parse_expression(codegen, on->arguments[1], p_stack_level);
+ if (res < 0)
return res;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF);
codegen.opcodes.push_back(res);
- int jump_success_pos2=codegen.opcodes.size();
+ int jump_success_pos2 = codegen.opcodes.size();
codegen.opcodes.push_back(0);
codegen.alloc_stack(p_stack_level); //it will be used..
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_FALSE);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
- codegen.opcodes.push_back(codegen.opcodes.size()+3);
- codegen.opcodes[jump_success_pos]=codegen.opcodes.size();
- codegen.opcodes[jump_success_pos2]=codegen.opcodes.size();
+ codegen.opcodes.push_back(codegen.opcodes.size() + 3);
+ codegen.opcodes[jump_success_pos] = codegen.opcodes.size();
+ codegen.opcodes[jump_success_pos2] = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_TRUE);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
- return p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS;
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
+ return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS;
} break;
// ternary operators
@@ -703,70 +680,113 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
// x IF a ELSE y operator with early out on failure
- int res = _parse_expression(codegen,on->arguments[0],p_stack_level);
- if (res<0)
+ int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
+ if (res < 0)
return res;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
- int jump_fail_pos=codegen.opcodes.size();
+ int jump_fail_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
-
- res = _parse_expression(codegen,on->arguments[1],p_stack_level);
- if (res<0)
+ res = _parse_expression(codegen, on->arguments[1], p_stack_level);
+ if (res < 0)
return res;
-
+
codegen.alloc_stack(p_stack_level); //it will be used..
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(res);
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
- int jump_past_pos=codegen.opcodes.size();
+ int jump_past_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
-
- codegen.opcodes[jump_fail_pos]=codegen.opcodes.size();
- res = _parse_expression(codegen,on->arguments[2],p_stack_level);
- if (res<0)
+
+ codegen.opcodes[jump_fail_pos] = codegen.opcodes.size();
+ res = _parse_expression(codegen, on->arguments[2], p_stack_level);
+ if (res < 0)
return res;
-
+
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN);
- codegen.opcodes.push_back(p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(res);
-
- codegen.opcodes[jump_past_pos]=codegen.opcodes.size();
-
- return p_stack_level|GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS;
+
+ codegen.opcodes[jump_past_pos] = codegen.opcodes.size();
+
+ return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS;
} break;
//unary operators
- case GDParser::OperatorNode::OP_NEG: { if (!_create_unary_operator(codegen,on,Variant::OP_NEGATE,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_NOT: { if (!_create_unary_operator(codegen,on,Variant::OP_NOT,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_BIT_INVERT: { if (!_create_unary_operator(codegen,on,Variant::OP_BIT_NEGATE,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_PREINC: { } break; //?
- case GDParser::OperatorNode::OP_PREDEC: { } break;
- case GDParser::OperatorNode::OP_INC: { } break;
- case GDParser::OperatorNode::OP_DEC: { } break;
+ case GDParser::OperatorNode::OP_NEG: {
+ if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_NOT: {
+ if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_BIT_INVERT: {
+ if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_PREINC: {
+ } break; //?
+ case GDParser::OperatorNode::OP_PREDEC: {
+ } break;
+ case GDParser::OperatorNode::OP_INC: {
+ } break;
+ case GDParser::OperatorNode::OP_DEC: {
+ } break;
//binary operators (in precedence order)
- case GDParser::OperatorNode::OP_IN: { if (!_create_binary_operator(codegen,on,Variant::OP_IN,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_EQUAL: { if (!_create_binary_operator(codegen,on,Variant::OP_EQUAL,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_NOT_EQUAL: { if (!_create_binary_operator(codegen,on,Variant::OP_NOT_EQUAL,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_LESS: { if (!_create_binary_operator(codegen,on,Variant::OP_LESS,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_LESS_EQUAL: { if (!_create_binary_operator(codegen,on,Variant::OP_LESS_EQUAL,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_GREATER: { if (!_create_binary_operator(codegen,on,Variant::OP_GREATER,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_GREATER_EQUAL: { if (!_create_binary_operator(codegen,on,Variant::OP_GREATER_EQUAL,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_ADD: { if (!_create_binary_operator(codegen,on,Variant::OP_ADD,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_SUB: { if (!_create_binary_operator(codegen,on,Variant::OP_SUBSTRACT,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_MUL: { if (!_create_binary_operator(codegen,on,Variant::OP_MULTIPLY,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_DIV: { if (!_create_binary_operator(codegen,on,Variant::OP_DIVIDE,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_MOD: { if (!_create_binary_operator(codegen,on,Variant::OP_MODULE,p_stack_level)) return -1;} break;
+ case GDParser::OperatorNode::OP_IN: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_EQUAL: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_NOT_EQUAL: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_LESS: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_LESS_EQUAL: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_GREATER: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_GREATER_EQUAL: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_ADD: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_SUB: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_SUBSTRACT, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_MUL: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_DIV: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_MOD: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level)) return -1;
+ } break;
//case GDParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break;
//case GDParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_BIT_AND: { if (!_create_binary_operator(codegen,on,Variant::OP_BIT_AND,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_BIT_OR: { if (!_create_binary_operator(codegen,on,Variant::OP_BIT_OR,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_BIT_XOR: { if (!_create_binary_operator(codegen,on,Variant::OP_BIT_XOR,p_stack_level)) return -1;} break;
- //shift
- case GDParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break;
- case GDParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break;
+ case GDParser::OperatorNode::OP_BIT_AND: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_BIT_OR: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_BIT_XOR: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level)) return -1;
+ } break;
+ //shift
+ case GDParser::OperatorNode::OP_SHIFT_LEFT: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level)) return -1;
+ } break;
+ case GDParser::OperatorNode::OP_SHIFT_RIGHT: {
+ if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level)) return -1;
+ } break;
//assignment operators
case GDParser::OperatorNode::OP_ASSIGN_ADD:
case GDParser::OperatorNode::OP_ASSIGN_SUB:
@@ -781,63 +801,57 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
case GDParser::OperatorNode::OP_INIT_ASSIGN:
case GDParser::OperatorNode::OP_ASSIGN: {
- ERR_FAIL_COND_V(on->arguments.size()!=2,-1);
-
-
- if (on->arguments[0]->type==GDParser::Node::TYPE_OPERATOR && (static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX || static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED)) {
- //SET (chained) MODE!!
+ ERR_FAIL_COND_V(on->arguments.size() != 2, -1);
+ if (on->arguments[0]->type == GDParser::Node::TYPE_OPERATOR && (static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX || static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX_NAMED)) {
+//SET (chained) MODE!!
#ifdef DEBUG_ENABLED
- if (static_cast<GDParser::OperatorNode*>(on->arguments[0])->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
- const GDParser::OperatorNode* inon = static_cast<GDParser::OperatorNode*>(on->arguments[0]);
-
+ if (static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX_NAMED) {
+ const GDParser::OperatorNode *inon = static_cast<GDParser::OperatorNode *>(on->arguments[0]);
- if (inon->arguments[0]->type==GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) {
+ if (inon->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*>(inon->arguments[1])->name);
- if (MI && MI->get().setter==codegen.function_node->name) {
- String n = static_cast<GDParser::IdentifierNode*>(inon->arguments[1])->name;
- _set_error("Must use '"+n+"' instead of 'self."+n+"' in setter.",inon);
+ const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode *>(inon->arguments[1])->name);
+ if (MI && MI->get().setter == codegen.function_node->name) {
+ String n = static_cast<GDParser::IdentifierNode *>(inon->arguments[1])->name;
+ _set_error("Must use '" + n + "' instead of 'self." + n + "' in setter.", inon);
return -1;
}
}
}
#endif
+ int slevel = p_stack_level;
- int slevel=p_stack_level;
-
- GDParser::OperatorNode* op = static_cast<GDParser::OperatorNode*>(on->arguments[0]);
+ GDParser::OperatorNode *op = static_cast<GDParser::OperatorNode *>(on->arguments[0]);
/* Find chain of sets */
StringName assign_property;
- List<GDParser::OperatorNode*> chain;
+ List<GDParser::OperatorNode *> chain;
{
//create get/set chain
- GDParser::OperatorNode* n=op;
- while(true) {
+ GDParser::OperatorNode *n = op;
+ while (true) {
chain.push_back(n);
- if (n->arguments[0]->type!=GDParser::Node::TYPE_OPERATOR) {
+ if (n->arguments[0]->type != GDParser::Node::TYPE_OPERATOR) {
//check for a built-in property
- if (n->arguments[0]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ if (n->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) {
- GDParser::IdentifierNode *identifier = static_cast<GDParser::IdentifierNode*>(n->arguments[0]);
- if (_is_class_member_property(codegen,identifier->name)) {
+ GDParser::IdentifierNode *identifier = static_cast<GDParser::IdentifierNode *>(n->arguments[0]);
+ if (_is_class_member_property(codegen, identifier->name)) {
assign_property = identifier->name;
-
}
-
}
break;
}
- n = static_cast<GDParser::OperatorNode*>(n->arguments[0]);
- if (n->op!=GDParser::OperatorNode::OP_INDEX && n->op!=GDParser::OperatorNode::OP_INDEX_NAMED)
+ n = static_cast<GDParser::OperatorNode *>(n->arguments[0]);
+ if (n->op != GDParser::OperatorNode::OP_INDEX && n->op != GDParser::OperatorNode::OP_INDEX_NAMED)
break;
}
}
@@ -845,23 +859,21 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
/* Chain of gets */
//get at (potential) root stack pos, so it can be returned
- int prev_pos = _parse_expression(codegen,chain.back()->get()->arguments[0],slevel);
- if (prev_pos<0)
+ int prev_pos = _parse_expression(codegen, chain.back()->get()->arguments[0], slevel);
+ if (prev_pos < 0)
return prev_pos;
- int retval=prev_pos;
+ int retval = prev_pos;
//print_line("retval: "+itos(retval));
- if (retval&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (retval & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
-
Vector<int> setchain;
-
- if (assign_property!=StringName()) {
+ if (assign_property != StringName()) {
// recover and assign at the end, this allows stuff like
// position.x+=2.0
@@ -871,37 +883,34 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
setchain.push_back(GDFunction::OPCODE_SET_MEMBER);
}
- for(List<GDParser::OperatorNode*>::Element *E=chain.back();E;E=E->prev()) {
+ for (List<GDParser::OperatorNode *>::Element *E = chain.back(); E; E = E->prev()) {
-
- if (E==chain.front()) //ignore first
+ if (E == chain.front()) //ignore first
break;
- bool named = E->get()->op==GDParser::OperatorNode::OP_INDEX_NAMED;
+ bool named = E->get()->op == GDParser::OperatorNode::OP_INDEX_NAMED;
int key_idx;
if (named) {
- key_idx = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode*>(E->get()->arguments[1])->name);
+ key_idx = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode *>(E->get()->arguments[1])->name);
//printf("named key %x\n",key_idx);
} else {
- if (prev_pos&(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)) {
+ if (prev_pos & (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)) {
slevel++;
codegen.alloc_stack(slevel);
}
GDParser::Node *key = E->get()->arguments[1];
- key_idx = _parse_expression(codegen,key,slevel);
+ key_idx = _parse_expression(codegen, key, slevel);
//printf("expr key %x\n",key_idx);
-
//stack was raised here if retval was stack but..
-
}
- if (key_idx<0) //error
+ if (key_idx < 0) //error
return key_idx;
codegen.opcodes.push_back(named ? GDFunction::OPCODE_GET_NAMED : GDFunction::OPCODE_GET);
@@ -909,134 +918,116 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
codegen.opcodes.push_back(key_idx);
slevel++;
codegen.alloc_stack(slevel);
- int dst_pos = (GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)|slevel;
+ int dst_pos = (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) | slevel;
codegen.opcodes.push_back(dst_pos);
-
//add in reverse order, since it will be reverted
-
setchain.push_back(dst_pos);
setchain.push_back(key_idx);
setchain.push_back(prev_pos);
setchain.push_back(named ? GDFunction::OPCODE_SET_NAMED : GDFunction::OPCODE_SET);
- prev_pos=dst_pos;
-
+ prev_pos = dst_pos;
}
setchain.invert();
-
int set_index;
- bool named=false;
+ bool named = false;
+ if (static_cast<const GDParser::OperatorNode *>(op)->op == GDParser::OperatorNode::OP_INDEX_NAMED) {
- if (static_cast<const GDParser::OperatorNode*>(op)->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
-
-
- set_index=codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode*>(op->arguments[1])->name);
- named=true;
+ set_index = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name);
+ named = true;
} else {
- set_index = _parse_expression(codegen,op->arguments[1],slevel+1);
- named=false;
+ set_index = _parse_expression(codegen, op->arguments[1], slevel + 1);
+ named = false;
}
-
- if (set_index<0) //error
+ if (set_index < 0) //error
return set_index;
- if (set_index&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (set_index & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
-
- int set_value = _parse_assign_right_expression(codegen,on,slevel+1);
- if (set_value<0) //error
+ int set_value = _parse_assign_right_expression(codegen, on, slevel + 1);
+ if (set_value < 0) //error
return set_value;
- codegen.opcodes.push_back(named?GDFunction::OPCODE_SET_NAMED:GDFunction::OPCODE_SET);
+ codegen.opcodes.push_back(named ? GDFunction::OPCODE_SET_NAMED : GDFunction::OPCODE_SET);
codegen.opcodes.push_back(prev_pos);
codegen.opcodes.push_back(set_index);
codegen.opcodes.push_back(set_value);
- for(int i=0;i<setchain.size();i++) {
-
+ for (int i = 0; i < setchain.size(); i++) {
codegen.opcodes.push_back(setchain[i]);
}
return retval;
-
- } else if (on->arguments[0]->type==GDParser::Node::TYPE_IDENTIFIER && _is_class_member_property(codegen,static_cast<GDParser::IdentifierNode*>(on->arguments[0])->name)) {
+ } else if (on->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && _is_class_member_property(codegen, static_cast<GDParser::IdentifierNode *>(on->arguments[0])->name)) {
//assignment to member property
int slevel = p_stack_level;
- int src_address = _parse_assign_right_expression(codegen,on,slevel);
- if (src_address<0)
+ int src_address = _parse_assign_right_expression(codegen, on, slevel);
+ if (src_address < 0)
return -1;
- StringName name = static_cast<GDParser::IdentifierNode*>(on->arguments[0])->name;
+ StringName name = static_cast<GDParser::IdentifierNode *>(on->arguments[0])->name;
codegen.opcodes.push_back(GDFunction::OPCODE_SET_MEMBER);
codegen.opcodes.push_back(codegen.get_name_map_pos(name));
codegen.opcodes.push_back(src_address);
- return GDFunction::ADDR_TYPE_NIL<<GDFunction::ADDR_BITS;
+ return GDFunction::ADDR_TYPE_NIL << GDFunction::ADDR_BITS;
} else {
-
-
//REGULAR ASSIGNMENT MODE!!
int slevel = p_stack_level;
- int dst_address_a = _parse_expression(codegen,on->arguments[0],slevel,false,on->op==GDParser::OperatorNode::OP_INIT_ASSIGN);
- if (dst_address_a<0)
+ int dst_address_a = _parse_expression(codegen, on->arguments[0], slevel, false, on->op == GDParser::OperatorNode::OP_INIT_ASSIGN);
+ if (dst_address_a < 0)
return -1;
- if (dst_address_a&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (dst_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
}
- int src_address_b = _parse_assign_right_expression(codegen,on,slevel);
- if (src_address_b<0)
+ int src_address_b = _parse_assign_right_expression(codegen, on, slevel);
+ if (src_address_b < 0)
return -1;
-
-
-
codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN); // perform operator
codegen.opcodes.push_back(dst_address_a); // argument 1
codegen.opcodes.push_back(src_address_b); // argument 2 (unary only takes one parameter)
return dst_address_a; //if anything, returns wathever was assigned or correct stack position
-
}
-
} break;
case GDParser::OperatorNode::OP_EXTENDS: {
- ERR_FAIL_COND_V(on->arguments.size()!=2,false);
-
+ ERR_FAIL_COND_V(on->arguments.size() != 2, false);
int slevel = p_stack_level;
- int src_address_a = _parse_expression(codegen,on->arguments[0],slevel);
- if (src_address_a<0)
+ int src_address_a = _parse_expression(codegen, on->arguments[0], slevel);
+ if (src_address_a < 0)
return -1;
- if (src_address_a&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)
+ if (src_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)
slevel++; //uses stack for return, increase stack
- int src_address_b = _parse_expression(codegen,on->arguments[1],slevel);
- if (src_address_b<0)
+ int src_address_b = _parse_expression(codegen, on->arguments[1], slevel);
+ if (src_address_b < 0)
return -1;
codegen.opcodes.push_back(GDFunction::OPCODE_EXTENDS_TEST); // perform operator
@@ -1046,14 +1037,13 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
} break;
default: {
-
- ERR_EXPLAIN("Bug in bytecode compiler, unexpected operator #"+itos(on->op)+" in parse tree while parsing expression.");
+ ERR_EXPLAIN("Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression.");
ERR_FAIL_V(0); //unreachable code
} break;
}
- int dst_addr=(p_stack_level)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
codegen.alloc_stack(p_stack_level);
return dst_addr;
@@ -1064,47 +1054,43 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
ERR_EXPLAIN("Bug in bytecode compiler, unexpected node in parse tree while parsing expression.");
ERR_FAIL_V(-1); //unreachable code
} break;
-
-
}
ERR_FAIL_V(-1); //unreachable code
}
-
-Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_block,int p_stack_level,int p_break_addr,int p_continue_addr) {
+Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_block, int p_stack_level, int p_break_addr, int p_continue_addr) {
codegen.push_stack_identifiers();
- int new_identifiers=0;
- codegen.current_line=p_block->line;
+ int new_identifiers = 0;
+ codegen.current_line = p_block->line;
- for(int i=0;i<p_block->statements.size();i++) {
+ for (int i = 0; i < p_block->statements.size(); i++) {
const GDParser::Node *s = p_block->statements[i];
-
- switch(s->type) {
+ switch (s->type) {
case GDParser::Node::TYPE_NEWLINE: {
#ifdef DEBUG_ENABLED
- const GDParser::NewLineNode *nl = static_cast<const GDParser::NewLineNode*>(s);
+ const GDParser::NewLineNode *nl = static_cast<const GDParser::NewLineNode *>(s);
codegen.opcodes.push_back(GDFunction::OPCODE_LINE);
codegen.opcodes.push_back(nl->line);
- codegen.current_line=nl->line;
+ codegen.current_line = nl->line;
#endif
} break;
case GDParser::Node::TYPE_CONTROL_FLOW: {
// try subblocks
- const GDParser::ControlFlowNode *cf = static_cast<const GDParser::ControlFlowNode*>(s);
+ const GDParser::ControlFlowNode *cf = static_cast<const GDParser::ControlFlowNode *>(s);
- switch(cf->cf_type) {
+ switch (cf->cf_type) {
case GDParser::ControlFlowNode::CF_MATCH: {
GDParser::MatchNode *match = cf->match;
-
+
GDParser::IdentifierNode *id = memnew(GDParser::IdentifierNode);
id->name = "#match_value";
-
+
// var #match_value
// copied because there is no _parse_statement :(
codegen.add_stack_identifier(id->name, p_stack_level++);
@@ -1112,25 +1098,25 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
new_identifiers++;
GDParser::OperatorNode *op = memnew(GDParser::OperatorNode);
- op->op=GDParser::OperatorNode::OP_ASSIGN;
+ op->op = GDParser::OperatorNode::OP_ASSIGN;
op->arguments.push_back(id);
op->arguments.push_back(match->val_to_match);
-
+
int ret = _parse_expression(codegen, op, p_stack_level);
if (ret < 0) {
return ERR_PARSE_ERROR;
}
-
+
// break address
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(codegen.opcodes.size() + 3);
int break_addr = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(0); // break addr
-
+
for (int j = 0; j < match->compiled_pattern_branches.size(); j++) {
GDParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j];
-
+
// jump over continue
// jump unconditionally
// continue address
@@ -1139,87 +1125,81 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
if (ret < 0) {
return ERR_PARSE_ERROR;
}
-
+
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF);
codegen.opcodes.push_back(ret);
codegen.opcodes.push_back(codegen.opcodes.size() + 3);
int continue_addr = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(0);
-
-
-
+
Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr);
if (err) {
return ERR_PARSE_ERROR;
}
-
+
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(break_addr);
-
+
codegen.opcodes[continue_addr + 1] = codegen.opcodes.size();
}
-
+
codegen.opcodes[break_addr + 1] = codegen.opcodes.size();
-
-
+
} break;
-
+
case GDParser::ControlFlowNode::CF_IF: {
#ifdef DEBUG_ENABLED
codegen.opcodes.push_back(GDFunction::OPCODE_LINE);
codegen.opcodes.push_back(cf->line);
- codegen.current_line=cf->line;
+ codegen.current_line = cf->line;
#endif
- int ret = _parse_expression(codegen,cf->arguments[0],p_stack_level,false);
- if (ret<0)
+ int ret = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
+ if (ret < 0)
return ERR_PARSE_ERROR;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(ret);
- int else_addr=codegen.opcodes.size();
+ int else_addr = codegen.opcodes.size();
codegen.opcodes.push_back(0); //temporary
- Error err = _parse_block(codegen,cf->body,p_stack_level,p_break_addr,p_continue_addr);
+ Error err = _parse_block(codegen, cf->body, p_stack_level, p_break_addr, p_continue_addr);
if (err)
return err;
if (cf->body_else) {
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
- int end_addr=codegen.opcodes.size();
+ int end_addr = codegen.opcodes.size();
codegen.opcodes.push_back(0);
- codegen.opcodes[else_addr]=codegen.opcodes.size();
+ codegen.opcodes[else_addr] = codegen.opcodes.size();
- Error err = _parse_block(codegen,cf->body_else,p_stack_level,p_break_addr,p_continue_addr);
+ Error err = _parse_block(codegen, cf->body_else, p_stack_level, p_break_addr, p_continue_addr);
if (err)
return err;
- codegen.opcodes[end_addr]=codegen.opcodes.size();
+ codegen.opcodes[end_addr] = codegen.opcodes.size();
} else {
//end without else
- codegen.opcodes[else_addr]=codegen.opcodes.size();
-
+ codegen.opcodes[else_addr] = codegen.opcodes.size();
}
} break;
case GDParser::ControlFlowNode::CF_FOR: {
-
-
- int slevel=p_stack_level;
- int iter_stack_pos=slevel;
- int iterator_pos = (slevel++)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
- int counter_pos = (slevel++)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
- int container_pos = (slevel++)|(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS);
+ int slevel = p_stack_level;
+ int iter_stack_pos = slevel;
+ int iterator_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
+ int counter_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
+ int container_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS);
codegen.alloc_stack(slevel);
- codegen.push_stack_identifiers();
- codegen.add_stack_identifier(static_cast<const GDParser::IdentifierNode*>(cf->arguments[0])->name,iter_stack_pos);
+ codegen.push_stack_identifiers();
+ codegen.add_stack_identifier(static_cast<const GDParser::IdentifierNode *>(cf->arguments[0])->name, iter_stack_pos);
- int ret = _parse_expression(codegen,cf->arguments[1],slevel,false);
- if (ret<0)
+ int ret = _parse_expression(codegen, cf->arguments[1], slevel, false);
+ if (ret < 0)
return ERR_COMPILATION_FAILED;
//assign container
@@ -1231,32 +1211,29 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
codegen.opcodes.push_back(GDFunction::OPCODE_ITERATE_BEGIN);
codegen.opcodes.push_back(counter_pos);
codegen.opcodes.push_back(container_pos);
- codegen.opcodes.push_back(codegen.opcodes.size()+4);
+ codegen.opcodes.push_back(codegen.opcodes.size() + 4);
codegen.opcodes.push_back(iterator_pos);
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); //skip code for next
- codegen.opcodes.push_back(codegen.opcodes.size()+8);
+ codegen.opcodes.push_back(codegen.opcodes.size() + 8);
//break loop
- int break_pos=codegen.opcodes.size();
+ int break_pos = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); //skip code for next
codegen.opcodes.push_back(0); //skip code for next
//next loop
- int continue_pos=codegen.opcodes.size();
+ int continue_pos = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_ITERATE);
codegen.opcodes.push_back(counter_pos);
codegen.opcodes.push_back(container_pos);
codegen.opcodes.push_back(break_pos);
codegen.opcodes.push_back(iterator_pos);
-
- Error err = _parse_block(codegen,cf->body,slevel,break_pos,continue_pos);
+ Error err = _parse_block(codegen, cf->body, slevel, break_pos, continue_pos);
if (err)
return err;
-
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(continue_pos);
- codegen.opcodes[break_pos+1]=codegen.opcodes.size();
-
+ codegen.opcodes[break_pos + 1] = codegen.opcodes.size();
codegen.pop_stack_identifiers();
@@ -1264,25 +1241,25 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
case GDParser::ControlFlowNode::CF_WHILE: {
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
- codegen.opcodes.push_back(codegen.opcodes.size()+3);
- int break_addr=codegen.opcodes.size();
+ codegen.opcodes.push_back(codegen.opcodes.size() + 3);
+ int break_addr = codegen.opcodes.size();
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(0);
- int continue_addr=codegen.opcodes.size();
+ int continue_addr = codegen.opcodes.size();
- int ret = _parse_expression(codegen,cf->arguments[0],p_stack_level,false);
- if (ret<0)
+ int ret = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
+ if (ret < 0)
return ERR_PARSE_ERROR;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(ret);
codegen.opcodes.push_back(break_addr);
- Error err = _parse_block(codegen,cf->body,p_stack_level,break_addr,continue_addr);
+ Error err = _parse_block(codegen, cf->body, p_stack_level, break_addr, continue_addr);
if (err)
return err;
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
codegen.opcodes.push_back(continue_addr);
- codegen.opcodes[break_addr+1]=codegen.opcodes.size();
+ codegen.opcodes[break_addr + 1] = codegen.opcodes.size();
} break;
case GDParser::ControlFlowNode::CF_SWITCH: {
@@ -1290,9 +1267,9 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
} break;
case GDParser::ControlFlowNode::CF_BREAK: {
- if (p_break_addr<0) {
+ if (p_break_addr < 0) {
- _set_error("'break'' not within loop",cf);
+ _set_error("'break'' not within loop", cf);
return ERR_COMPILATION_FAILED;
}
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
@@ -1301,9 +1278,9 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
} break;
case GDParser::ControlFlowNode::CF_CONTINUE: {
- if (p_continue_addr<0) {
+ if (p_continue_addr < 0) {
- _set_error("'continue' not within loop",cf);
+ _set_error("'continue' not within loop", cf);
return ERR_COMPILATION_FAILED;
}
@@ -1317,29 +1294,28 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
if (cf->arguments.size()) {
- ret = _parse_expression(codegen,cf->arguments[0],p_stack_level,false);
- if (ret<0)
+ ret = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
+ if (ret < 0)
return ERR_PARSE_ERROR;
} else {
- ret=GDFunction::ADDR_TYPE_NIL << GDFunction::ADDR_BITS;
+ ret = GDFunction::ADDR_TYPE_NIL << GDFunction::ADDR_BITS;
}
codegen.opcodes.push_back(GDFunction::OPCODE_RETURN);
codegen.opcodes.push_back(ret);
} break;
-
}
} break;
case GDParser::Node::TYPE_ASSERT: {
// try subblocks
- const GDParser::AssertNode *as = static_cast<const GDParser::AssertNode*>(s);
+ const GDParser::AssertNode *as = static_cast<const GDParser::AssertNode *>(s);
- int ret = _parse_expression(codegen,as->condition,p_stack_level,false);
- if (ret<0)
+ int ret = _parse_expression(codegen, as->condition, p_stack_level, false);
+ if (ret < 0)
return ERR_PARSE_ERROR;
codegen.opcodes.push_back(GDFunction::OPCODE_ASSERT);
@@ -1353,99 +1329,91 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
} break;
case GDParser::Node::TYPE_LOCAL_VAR: {
+ const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(s);
- const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode*>(s);
-
- if (_is_class_member_property(codegen,lv->name)) {
- _set_error("Name for local variable '"+String(lv->name)+"' can't shadow class property of the same name.",lv);
+ if (_is_class_member_property(codegen, lv->name)) {
+ _set_error("Name for local variable '" + String(lv->name) + "' can't shadow class property of the same name.", lv);
return ERR_ALREADY_EXISTS;
}
- codegen.add_stack_identifier(lv->name,p_stack_level++);
+ codegen.add_stack_identifier(lv->name, p_stack_level++);
codegen.alloc_stack(p_stack_level);
new_identifiers++;
} break;
default: {
//expression
- int ret = _parse_expression(codegen,s,p_stack_level,true);
- if (ret<0)
+ int ret = _parse_expression(codegen, s, p_stack_level, true);
+ if (ret < 0)
return ERR_PARSE_ERROR;
} break;
-
}
-
}
codegen.pop_stack_identifiers();
return OK;
}
-
-Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready) {
+Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode *p_class, const GDParser::FunctionNode *p_func, bool p_for_ready) {
Vector<int> bytecode;
CodeGen codegen;
- codegen.class_node=p_class;
- codegen.script=p_script;
- codegen.function_node=p_func;
- codegen.stack_max=0;
- codegen.current_line=0;
- codegen.call_max=0;
- codegen.debug_stack=ScriptDebugger::get_singleton()!=NULL;
+ codegen.class_node = p_class;
+ codegen.script = p_script;
+ codegen.function_node = p_func;
+ codegen.stack_max = 0;
+ codegen.current_line = 0;
+ codegen.call_max = 0;
+ codegen.debug_stack = ScriptDebugger::get_singleton() != NULL;
Vector<StringName> argnames;
- int stack_level=0;
+ int stack_level = 0;
if (p_func) {
- for(int i=0;i<p_func->arguments.size();i++) {
- if (_is_class_member_property(p_script,p_func->arguments[i])) {
- _set_error("Name for argument '"+String(p_func->arguments[i])+"' can't shadow class property of the same name.",p_func);
+ for (int i = 0; i < p_func->arguments.size(); i++) {
+ if (_is_class_member_property(p_script, p_func->arguments[i])) {
+ _set_error("Name for argument '" + String(p_func->arguments[i]) + "' can't shadow class property of the same name.", p_func);
return ERR_ALREADY_EXISTS;
}
- codegen.add_stack_identifier(p_func->arguments[i],i);
+ codegen.add_stack_identifier(p_func->arguments[i], i);
#ifdef TOOLS_ENABLED
argnames.push_back(p_func->arguments[i]);
#endif
}
- stack_level=p_func->arguments.size();
+ stack_level = p_func->arguments.size();
}
codegen.alloc_stack(stack_level);
/* Parse initializer -if applies- */
- bool is_initializer=!p_for_ready && !p_func;
+ bool is_initializer = !p_for_ready && !p_func;
- if (is_initializer || (p_func && String(p_func->name)=="_init")) {
+ if (is_initializer || (p_func && String(p_func->name) == "_init")) {
//parse initializer for class members
- if (!p_func && p_class->extends_used && p_script->native.is_null()){
+ if (!p_func && p_class->extends_used && p_script->native.is_null()) {
//call implicit parent constructor
codegen.opcodes.push_back(GDFunction::OPCODE_CALL_SELF_BASE);
codegen.opcodes.push_back(codegen.get_name_map_pos("_init"));
codegen.opcodes.push_back(0);
- codegen.opcodes.push_back((GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)|0);
-
+ codegen.opcodes.push_back((GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) | 0);
}
- Error err = _parse_block(codegen,p_class->initializer,stack_level);
+ Error err = _parse_block(codegen, p_class->initializer, stack_level);
if (err)
return err;
- is_initializer=true;
-
+ is_initializer = true;
}
- if (p_for_ready || (p_func && String(p_func->name)=="_ready")) {
+ if (p_for_ready || (p_func && String(p_func->name) == "_ready")) {
//parse initializer for class members
if (p_class->ready->statements.size()) {
- Error err = _parse_block(codegen,p_class->ready,stack_level);
+ Error err = _parse_block(codegen, p_class->ready, stack_level);
if (err)
return err;
}
-
}
-
/* Parse default argument code -if applies- */
Vector<int> defarg_addr;
@@ -1457,196 +1425,185 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT);
defarg_addr.push_back(codegen.opcodes.size());
- for(int i=0;i<p_func->default_values.size();i++) {
+ for (int i = 0; i < p_func->default_values.size(); i++) {
- _parse_expression(codegen,p_func->default_values[i],stack_level,true);
+ _parse_expression(codegen, p_func->default_values[i], stack_level, true);
defarg_addr.push_back(codegen.opcodes.size());
}
-
defarg_addr.invert();
}
-
-
- Error err = _parse_block(codegen,p_func->body,stack_level);
+ Error err = _parse_block(codegen, p_func->body, stack_level);
if (err)
return err;
- func_name=p_func->name;
+ func_name = p_func->name;
} else {
if (p_for_ready)
- func_name="_ready";
+ func_name = "_ready";
else
- func_name="_init";
+ func_name = "_init";
}
codegen.opcodes.push_back(GDFunction::OPCODE_END);
- GDFunction *gdfunc=NULL;
+ GDFunction *gdfunc = NULL;
/*
if (String(p_func->name)=="") { //initializer func
gdfunc = &p_script->initializer;
*/
//} else { //regular func
- p_script->member_functions[func_name]=memnew(GDFunction);
- gdfunc = p_script->member_functions[func_name];
+ p_script->member_functions[func_name] = memnew(GDFunction);
+ gdfunc = p_script->member_functions[func_name];
//}
if (p_func) {
- gdfunc->_static=p_func->_static;
- gdfunc->rpc_mode=p_func->rpc_mode;
+ gdfunc->_static = p_func->_static;
+ gdfunc->rpc_mode = p_func->rpc_mode;
}
#ifdef TOOLS_ENABLED
- gdfunc->arg_names=argnames;
+ gdfunc->arg_names = argnames;
#endif
//constants
if (codegen.constant_map.size()) {
- gdfunc->_constant_count=codegen.constant_map.size();
+ gdfunc->_constant_count = codegen.constant_map.size();
gdfunc->constants.resize(codegen.constant_map.size());
- gdfunc->_constants_ptr=&gdfunc->constants[0];
- const Variant *K=NULL;
- while((K=codegen.constant_map.next(K))) {
+ gdfunc->_constants_ptr = &gdfunc->constants[0];
+ const Variant *K = NULL;
+ while ((K = codegen.constant_map.next(K))) {
int idx = codegen.constant_map[*K];
- gdfunc->constants[idx]=*K;
+ gdfunc->constants[idx] = *K;
}
} else {
- gdfunc->_constants_ptr=NULL;
- gdfunc->_constant_count=0;
+ gdfunc->_constants_ptr = NULL;
+ gdfunc->_constant_count = 0;
}
//global names
if (codegen.name_map.size()) {
gdfunc->global_names.resize(codegen.name_map.size());
gdfunc->_global_names_ptr = &gdfunc->global_names[0];
- for(Map<StringName,int>::Element *E=codegen.name_map.front();E;E=E->next()) {
+ for (Map<StringName, int>::Element *E = codegen.name_map.front(); E; E = E->next()) {
- gdfunc->global_names[E->get()]=E->key();
+ gdfunc->global_names[E->get()] = E->key();
}
- gdfunc->_global_names_count=gdfunc->global_names.size();
+ gdfunc->_global_names_count = gdfunc->global_names.size();
} else {
gdfunc->_global_names_ptr = NULL;
- gdfunc->_global_names_count =0;
+ gdfunc->_global_names_count = 0;
}
-
if (codegen.opcodes.size()) {
- gdfunc->code=codegen.opcodes;
- gdfunc->_code_ptr=&gdfunc->code[0];
- gdfunc->_code_size=codegen.opcodes.size();
+ gdfunc->code = codegen.opcodes;
+ gdfunc->_code_ptr = &gdfunc->code[0];
+ gdfunc->_code_size = codegen.opcodes.size();
} else {
- gdfunc->_code_ptr=NULL;
- gdfunc->_code_size=0;
+ gdfunc->_code_ptr = NULL;
+ gdfunc->_code_size = 0;
}
if (defarg_addr.size()) {
- gdfunc->default_arguments=defarg_addr;
- gdfunc->_default_arg_count=defarg_addr.size()-1;
- gdfunc->_default_arg_ptr=&gdfunc->default_arguments[0];
+ gdfunc->default_arguments = defarg_addr;
+ gdfunc->_default_arg_count = defarg_addr.size() - 1;
+ gdfunc->_default_arg_ptr = &gdfunc->default_arguments[0];
} else {
- gdfunc->_default_arg_count=0;
- gdfunc->_default_arg_ptr=NULL;
+ gdfunc->_default_arg_count = 0;
+ gdfunc->_default_arg_ptr = NULL;
}
- gdfunc->_argument_count=p_func ? p_func->arguments.size() : 0;
- gdfunc->_stack_size=codegen.stack_max;
- gdfunc->_call_size=codegen.call_max;
- gdfunc->name=func_name;
+ gdfunc->_argument_count = p_func ? p_func->arguments.size() : 0;
+ gdfunc->_stack_size = codegen.stack_max;
+ gdfunc->_call_size = codegen.call_max;
+ gdfunc->name = func_name;
#ifdef DEBUG_ENABLED
- if (ScriptDebugger::get_singleton()){
+ if (ScriptDebugger::get_singleton()) {
String signature;
//path
- if (p_script->get_path()!=String())
- signature+=p_script->get_path();
+ if (p_script->get_path() != String())
+ signature += p_script->get_path();
//loc
if (p_func) {
- signature+="::"+itos(p_func->body->line);
+ signature += "::" + itos(p_func->body->line);
} else {
- signature+="::0";
+ signature += "::0";
}
//funciton and class
if (p_class->name) {
- signature+="::"+String(p_class->name)+"."+String(func_name);
+ signature += "::" + String(p_class->name) + "." + String(func_name);
} else {
- signature+="::"+String(func_name);
+ signature += "::" + String(func_name);
}
-
-
- gdfunc->profile.signature=signature;
+ gdfunc->profile.signature = signature;
}
#endif
- gdfunc->_script=p_script;
- gdfunc->source=source;
+ gdfunc->_script = p_script;
+ gdfunc->source = source;
#ifdef DEBUG_ENABLED
{
- gdfunc->func_cname=(String(source)+" - "+String(func_name)).utf8();
- gdfunc->_func_cname=gdfunc->func_cname.get_data();
-
+ gdfunc->func_cname = (String(source) + " - " + String(func_name)).utf8();
+ gdfunc->_func_cname = gdfunc->func_cname.get_data();
}
#endif
if (p_func) {
- gdfunc->_initial_line=p_func->line;
+ gdfunc->_initial_line = p_func->line;
#ifdef TOOLS_ENABLED
- p_script->member_lines[func_name]=p_func->line;
+ p_script->member_lines[func_name] = p_func->line;
#endif
} else {
- gdfunc->_initial_line=0;
+ gdfunc->_initial_line = 0;
}
if (codegen.debug_stack)
- gdfunc->stack_debug=codegen.stack_debug;
+ gdfunc->stack_debug = codegen.stack_debug;
if (is_initializer)
- p_script->initializer=gdfunc;
-
+ p_script->initializer = gdfunc;
return OK;
}
-
-
Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDParser::ClassNode *p_class, bool p_keep_state) {
- Map<StringName,Ref<GDScript> > old_subclasses;
+ Map<StringName, Ref<GDScript> > old_subclasses;
if (p_keep_state) {
- old_subclasses=p_script->subclasses;
+ old_subclasses = p_script->subclasses;
}
- p_script->native=Ref<GDNativeClass>();
- p_script->base=Ref<GDScript>();
- p_script->_base=NULL;
+ p_script->native = Ref<GDNativeClass>();
+ p_script->base = Ref<GDScript>();
+ p_script->_base = NULL;
p_script->members.clear();
p_script->constants.clear();
- for (Map<StringName,GDFunction*>::Element *E=p_script->member_functions.front();E;E=E->next()) {
+ for (Map<StringName, GDFunction *>::Element *E = p_script->member_functions.front(); E; E = E->next()) {
memdelete(E->get());
}
p_script->member_functions.clear();
p_script->member_indices.clear();
p_script->member_info.clear();
p_script->_signals.clear();
- p_script->initializer=NULL;
+ p_script->initializer = NULL;
p_script->subclasses.clear();
- p_script->_owner=p_owner;
- p_script->tool=p_class->tool;
- p_script->name=p_class->name;
-
+ p_script->_owner = p_owner;
+ p_script->tool = p_class->tool;
+ p_script->name = p_class->name;
Ref<GDNativeClass> native;
@@ -1656,8 +1613,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
Ref<GDScript> script;
-
- if (path!="") {
+ if (path != "") {
//path (and optionally subclasses)
if (path.is_rel_path()) {
@@ -1667,47 +1623,46 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
if (p_owner) {
GDScript *current_class = p_owner;
while (current_class != NULL) {
- base=current_class->get_path();
- if (base=="")
+ base = current_class->get_path();
+ if (base == "")
current_class = current_class->_owner;
else
break;
}
- }
- else {
+ } else {
base = p_script->get_path();
}
- if (base=="" || base.is_rel_path()) {
- _set_error("Could not resolve relative path for parent class: "+path,p_class);
+ if (base == "" || base.is_rel_path()) {
+ _set_error("Could not resolve relative path for parent class: " + path, p_class);
return ERR_FILE_NOT_FOUND;
}
- path=base.get_base_dir().plus_file(path).simplify_path();
+ path = base.get_base_dir().plus_file(path).simplify_path();
}
script = ResourceLoader::load(path);
if (script.is_null()) {
- _set_error("Could not load base class: "+path,p_class);
+ _set_error("Could not load base class: " + path, p_class);
return ERR_FILE_NOT_FOUND;
}
if (!script->valid) {
- _set_error("Script not fully loaded (cyclic preload?): "+path,p_class);
+ _set_error("Script not fully loaded (cyclic preload?): " + path, p_class);
return ERR_BUSY;
}
//print_line("EXTENDS PATH: "+path+" script is "+itos(script.is_valid())+" indices is "+itos(script->member_indices.size())+" valid? "+itos(script->valid));
if (p_class->extends_class.size()) {
- for(int i=0;i<p_class->extends_class.size();i++) {
+ for (int i = 0; i < p_class->extends_class.size(); i++) {
String sub = p_class->extends_class[i];
if (script->subclasses.has(sub)) {
Ref<Script> subclass = script->subclasses[sub]; //avoid reference from dissapearing
- script=subclass;
+ script = subclass;
} else {
- _set_error("Could not find subclass: "+sub,p_class);
+ _set_error("Could not find subclass: " + sub, p_class);
return ERR_FILE_NOT_FOUND;
}
}
@@ -1715,54 +1670,52 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
} else {
- ERR_FAIL_COND_V(p_class->extends_class.size()==0,ERR_BUG);
+ ERR_FAIL_COND_V(p_class->extends_class.size() == 0, ERR_BUG);
//look around for the subclasses
- String base=p_class->extends_class[0];
+ String base = p_class->extends_class[0];
GDScript *p = p_owner;
Ref<GDScript> base_class;
- while(p) {
+ while (p) {
if (p->subclasses.has(base)) {
- base_class=p->subclasses[base];
+ base_class = p->subclasses[base];
break;
}
- p=p->_owner;
+ p = p->_owner;
}
if (base_class.is_valid()) {
- for(int i=1;i<p_class->extends_class.size();i++) {
+ for (int i = 1; i < p_class->extends_class.size(); i++) {
- String subclass=p_class->extends_class[i];
+ String subclass = p_class->extends_class[i];
if (base_class->subclasses.has(subclass)) {
- base_class=base_class->subclasses[subclass];
+ base_class = base_class->subclasses[subclass];
} else {
- _set_error("Could not find subclass: "+subclass,p_class);
+ _set_error("Could not find subclass: " + subclass, p_class);
return ERR_FILE_NOT_FOUND;
}
}
- script=base_class;
-
+ script = base_class;
} else {
- if (p_class->extends_class.size()>1) {
+ if (p_class->extends_class.size() > 1) {
- _set_error("Invalid inheritance (unknown class+subclasses)",p_class);
+ _set_error("Invalid inheritance (unknown class+subclasses)", p_class);
return ERR_FILE_NOT_FOUND;
-
}
//if not found, try engine classes
if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
- _set_error("Unknown class: '"+base+"'",p_class);
+ _set_error("Unknown class: '" + base + "'", p_class);
return ERR_FILE_NOT_FOUND;
}
@@ -1770,66 +1723,62 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx];
if (!native.is_valid()) {
- _set_error("Global not a class: '"+base+"'",p_class);
+ _set_error("Global not a class: '" + base + "'", p_class);
return ERR_FILE_NOT_FOUND;
}
}
-
-
}
if (script.is_valid()) {
- p_script->base=script;
- p_script->_base=p_script->base.ptr();
- p_script->member_indices=script->member_indices;
+ p_script->base = script;
+ p_script->_base = p_script->base.ptr();
+ p_script->member_indices = script->member_indices;
} else if (native.is_valid()) {
- p_script->native=native;
+ p_script->native = native;
} else {
- _set_error("Could not determine inheritance",p_class);
+ _set_error("Could not determine inheritance", p_class);
return ERR_FILE_NOT_FOUND;
}
-
- }else {
+ } else {
// without extends, implicitly extend Reference
int native_idx = GDScriptLanguage::get_singleton()->get_global_map()["Reference"];
native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx];
ERR_FAIL_COND_V(native.is_null(), ERR_BUG);
- p_script->native=native;
+ p_script->native = native;
}
//print_line("Script: "+p_script->get_path()+" indices: "+itos(p_script->member_indices.size()));
-
- for(int i=0;i<p_class->variables.size();i++) {
+ for (int i = 0; i < p_class->variables.size(); i++) {
StringName name = p_class->variables[i].identifier;
if (p_script->member_indices.has(name)) {
- _set_error("Member '"+name+"' already exists (in current or parent class)",p_class);
+ _set_error("Member '" + name + "' already exists (in current or parent class)", p_class);
return ERR_ALREADY_EXISTS;
}
- if (_is_class_member_property(p_script,name)) {
- _set_error("Member '"+name+"' already exists as a class property.",p_class);
+ if (_is_class_member_property(p_script, name)) {
+ _set_error("Member '" + name + "' already exists as a class property.", p_class);
return ERR_ALREADY_EXISTS;
}
- if (p_class->variables[i]._export.type!=Variant::NIL) {
+ if (p_class->variables[i]._export.type != Variant::NIL) {
- p_script->member_info[name]=p_class->variables[i]._export;
+ p_script->member_info[name] = p_class->variables[i]._export;
#ifdef TOOLS_ENABLED
- if (p_class->variables[i].default_value.get_type()!=Variant::NIL) {
+ if (p_class->variables[i].default_value.get_type() != Variant::NIL) {
- p_script->member_default_values[name]=p_class->variables[i].default_value;
+ p_script->member_default_values[name] = p_class->variables[i].default_value;
}
#endif
} else {
- p_script->member_info[name]=PropertyInfo(Variant::NIL,name,PROPERTY_HINT_NONE,"",PROPERTY_USAGE_SCRIPT_VARIABLE);
+ p_script->member_info[name] = PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_SCRIPT_VARIABLE);
}
//int new_idx = p_script->member_indices.size();
@@ -1837,176 +1786,168 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
minfo.index = p_script->member_indices.size();
minfo.setter = p_class->variables[i].setter;
minfo.getter = p_class->variables[i].getter;
- minfo.rpc_mode=p_class->variables[i].rpc_mode;
+ minfo.rpc_mode = p_class->variables[i].rpc_mode;
- p_script->member_indices[name]=minfo;
+ p_script->member_indices[name] = minfo;
p_script->members.insert(name);
#ifdef TOOLS_ENABLED
- p_script->member_lines[name]=p_class->variables[i].line;
+ p_script->member_lines[name] = p_class->variables[i].line;
#endif
-
-
}
- for(int i=0;i<p_class->constant_expressions.size();i++) {
+ for (int i = 0; i < p_class->constant_expressions.size(); i++) {
StringName name = p_class->constant_expressions[i].identifier;
- ERR_CONTINUE( p_class->constant_expressions[i].expression->type!=GDParser::Node::TYPE_CONSTANT );
+ ERR_CONTINUE(p_class->constant_expressions[i].expression->type != GDParser::Node::TYPE_CONSTANT);
- if (_is_class_member_property(p_script,name)) {
- _set_error("Member '"+name+"' already exists as a class property.",p_class);
+ if (_is_class_member_property(p_script, name)) {
+ _set_error("Member '" + name + "' already exists as a class property.", p_class);
return ERR_ALREADY_EXISTS;
}
- GDParser::ConstantNode *constant = static_cast<GDParser::ConstantNode*>(p_class->constant_expressions[i].expression);
+ GDParser::ConstantNode *constant = static_cast<GDParser::ConstantNode *>(p_class->constant_expressions[i].expression);
- p_script->constants.insert(name,constant->value);
- //p_script->constants[constant->value].make_const();
+ p_script->constants.insert(name, constant->value);
+//p_script->constants[constant->value].make_const();
#ifdef TOOLS_ENABLED
- p_script->member_lines[name]=p_class->constant_expressions[i].expression->line;
+ p_script->member_lines[name] = p_class->constant_expressions[i].expression->line;
#endif
-
}
- for(int i=0;i<p_class->_signals.size();i++) {
+ for (int i = 0; i < p_class->_signals.size(); i++) {
StringName name = p_class->_signals[i].name;
GDScript *c = p_script;
- while(c) {
+ while (c) {
if (c->_signals.has(name)) {
- _set_error("Signal '"+name+"' redefined (in current or parent class)",p_class);
+ _set_error("Signal '" + name + "' redefined (in current or parent class)", p_class);
return ERR_ALREADY_EXISTS;
}
if (c->base.is_valid()) {
- c=c->base.ptr();
+ c = c->base.ptr();
} else {
- c=NULL;
+ c = NULL;
}
}
if (native.is_valid()) {
- if (ClassDB::has_signal(native->get_name(),name)) {
- _set_error("Signal '"+name+"' redefined (original in native class '"+String(native->get_name())+"')",p_class);
+ if (ClassDB::has_signal(native->get_name(), name)) {
+ _set_error("Signal '" + name + "' redefined (original in native class '" + String(native->get_name()) + "')", p_class);
return ERR_ALREADY_EXISTS;
}
}
- p_script->_signals[name]=p_class->_signals[i].arguments;
+ p_script->_signals[name] = p_class->_signals[i].arguments;
}
//parse sub-classes
- for(int i=0;i<p_class->subclasses.size();i++) {
+ for (int i = 0; i < p_class->subclasses.size(); i++) {
StringName name = p_class->subclasses[i]->name;
Ref<GDScript> subclass;
if (old_subclasses.has(name)) {
- subclass=old_subclasses[name];
+ subclass = old_subclasses[name];
} else {
subclass.instance();
}
- Error err = _parse_class(subclass.ptr(),p_script,p_class->subclasses[i],p_keep_state);
+ Error err = _parse_class(subclass.ptr(), p_script, p_class->subclasses[i], p_keep_state);
if (err)
return err;
#ifdef TOOLS_ENABLED
- p_script->member_lines[name]=p_class->subclasses[i]->line;
+ p_script->member_lines[name] = p_class->subclasses[i]->line;
#endif
- p_script->constants.insert(name,subclass); //once parsed, goes to the list of constants
- p_script->subclasses.insert(name,subclass);
-
+ p_script->constants.insert(name, subclass); //once parsed, goes to the list of constants
+ p_script->subclasses.insert(name, subclass);
}
-
//parse methods
- bool has_initializer=false;
- bool has_ready=false;
+ bool has_initializer = false;
+ bool has_ready = false;
- for(int i=0;i<p_class->functions.size();i++) {
+ for (int i = 0; i < p_class->functions.size(); i++) {
- if (!has_initializer && p_class->functions[i]->name=="_init")
- has_initializer=true;
- if (!has_ready && p_class->functions[i]->name=="_ready")
- has_ready=true;
- Error err = _parse_function(p_script,p_class,p_class->functions[i]);
+ if (!has_initializer && p_class->functions[i]->name == "_init")
+ has_initializer = true;
+ if (!has_ready && p_class->functions[i]->name == "_ready")
+ has_ready = true;
+ Error err = _parse_function(p_script, p_class, p_class->functions[i]);
if (err)
return err;
}
//parse static methods
- for(int i=0;i<p_class->static_functions.size();i++) {
+ for (int i = 0; i < p_class->static_functions.size(); i++) {
- Error err = _parse_function(p_script,p_class,p_class->static_functions[i]);
+ Error err = _parse_function(p_script, p_class, p_class->static_functions[i]);
if (err)
return err;
}
-
if (!has_initializer) {
//create a constructor
- Error err = _parse_function(p_script,p_class,NULL);
+ Error err = _parse_function(p_script, p_class, NULL);
if (err)
return err;
}
if (!has_ready && p_class->ready->statements.size()) {
//create a constructor
- Error err = _parse_function(p_script,p_class,NULL,true);
+ Error err = _parse_function(p_script, p_class, NULL, true);
if (err)
return err;
}
#ifdef DEBUG_ENABLED
//validate setters/getters if debug is enabled
- for(int i=0;i<p_class->variables.size();i++) {
+ for (int i = 0; i < p_class->variables.size(); i++) {
if (p_class->variables[i].setter) {
- const Map<StringName,GDFunction*>::Element *E=p_script->get_member_functions().find(p_class->variables[i].setter);
+ const Map<StringName, GDFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].setter);
if (!E) {
- _set_error("Setter function '"+String(p_class->variables[i].setter)+"' not found in class.",NULL);
- err_line=p_class->variables[i].line;
- err_column=0;
+ _set_error("Setter function '" + String(p_class->variables[i].setter) + "' not found in class.", NULL);
+ err_line = p_class->variables[i].line;
+ err_column = 0;
return ERR_PARSE_ERROR;
}
if (E->get()->is_static()) {
- _set_error("Setter function '"+String(p_class->variables[i].setter)+"' is static.",NULL);
- err_line=p_class->variables[i].line;
- err_column=0;
+ _set_error("Setter function '" + String(p_class->variables[i].setter) + "' is static.", NULL);
+ err_line = p_class->variables[i].line;
+ err_column = 0;
return ERR_PARSE_ERROR;
}
-
}
if (p_class->variables[i].getter) {
- const Map<StringName,GDFunction*>::Element *E=p_script->get_member_functions().find(p_class->variables[i].getter);
+ const Map<StringName, GDFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].getter);
if (!E) {
- _set_error("Getter function '"+String(p_class->variables[i].getter)+"' not found in class.",NULL);
- err_line=p_class->variables[i].line;
- err_column=0;
+ _set_error("Getter function '" + String(p_class->variables[i].getter) + "' not found in class.", NULL);
+ err_line = p_class->variables[i].line;
+ err_column = 0;
return ERR_PARSE_ERROR;
}
if (E->get()->is_static()) {
- _set_error("Getter function '"+String(p_class->variables[i].getter)+"' is static.",NULL);
- err_line=p_class->variables[i].line;
- err_column=0;
+ _set_error("Getter function '" + String(p_class->variables[i].getter) + "' is static.", NULL);
+ err_line = p_class->variables[i].line;
+ err_column = 0;
return ERR_PARSE_ERROR;
}
-
}
}
@@ -2014,96 +1955,88 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
if (p_keep_state) {
- print_line("RELOAD KEEP "+p_script->path);
- for (Set<Object*>::Element *E=p_script->instances.front();E;) {
+ print_line("RELOAD KEEP " + p_script->path);
+ for (Set<Object *>::Element *E = p_script->instances.front(); E;) {
- Set<Object*>::Element *N = E->next();
+ Set<Object *>::Element *N = E->next();
ScriptInstance *si = E->get()->get_script_instance();
if (si->is_placeholder()) {
#ifdef TOOLS_ENABLED
- PlaceHolderScriptInstance *psi = static_cast<PlaceHolderScriptInstance*>(si);
+ PlaceHolderScriptInstance *psi = static_cast<PlaceHolderScriptInstance *>(si);
if (p_script->is_tool()) {
//re-create as an instance
p_script->placeholders.erase(psi); //remove placeholder
- GDInstance* instance = memnew( GDInstance );
- instance->base_ref=E->get()->cast_to<Reference>();
+ GDInstance *instance = memnew(GDInstance);
+ instance->base_ref = E->get()->cast_to<Reference>();
instance->members.resize(p_script->member_indices.size());
- instance->script=Ref<GDScript>(p_script);
- instance->owner=E->get();
+ instance->script = Ref<GDScript>(p_script);
+ instance->owner = E->get();
//needed for hot reloading
- for(Map<StringName,GDScript::MemberInfo>::Element *E=p_script->member_indices.front();E;E=E->next()) {
- instance->member_indices_cache[E->key()]=E->get().index;
+ for (Map<StringName, GDScript::MemberInfo>::Element *E = p_script->member_indices.front(); E; E = E->next()) {
+ instance->member_indices_cache[E->key()] = E->get().index;
}
instance->owner->set_script_instance(instance);
-
/* STEP 2, INITIALIZE AND CONSRTUCT */
Variant::CallError ce;
- p_script->initializer->call(instance,NULL,0,ce);
+ p_script->initializer->call(instance, NULL, 0, ce);
- if (ce.error!=Variant::CallError::CALL_OK) {
+ if (ce.error != Variant::CallError::CALL_OK) {
//well, tough luck, not goinna do anything here
}
}
#endif
} else {
- GDInstance *gi = static_cast<GDInstance*>(si);
+ GDInstance *gi = static_cast<GDInstance *>(si);
gi->reload_members();
}
- E=N;
-
+ E = N;
}
-
-
}
#endif
- p_script->valid=true;
+ p_script->valid = true;
return OK;
}
-Error GDCompiler::compile(const GDParser *p_parser,GDScript *p_script,bool p_keep_state) {
+Error GDCompiler::compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state) {
- err_line=-1;
- err_column=-1;
- error="";
- parser=p_parser;
- const GDParser::Node* root = parser->get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,ERR_INVALID_DATA);
+ err_line = -1;
+ err_column = -1;
+ error = "";
+ parser = p_parser;
+ const GDParser::Node *root = parser->get_parse_tree();
+ ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, ERR_INVALID_DATA);
- source=p_script->get_path();
+ source = p_script->get_path();
- Error err = _parse_class(p_script,NULL,static_cast<const GDParser::ClassNode*>(root),p_keep_state);
+ Error err = _parse_class(p_script, NULL, static_cast<const GDParser::ClassNode *>(root), p_keep_state);
if (err)
return err;
return OK;
-
}
String GDCompiler::get_error() const {
return error;
}
-int GDCompiler::get_error_line() const{
+int GDCompiler::get_error_line() const {
return err_line;
}
-int GDCompiler::get_error_column() const{
+int GDCompiler::get_error_column() const {
return err_column;
}
-GDCompiler::GDCompiler()
-{
+GDCompiler::GDCompiler() {
}
-
-
diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h
index eb6079e8e0..c84bd97246 100644
--- a/modules/gdscript/gd_compiler.h
+++ b/modules/gdscript/gd_compiler.h
@@ -32,7 +32,6 @@
#include "gd_parser.h"
#include "gd_script.h"
-
class GDCompiler {
const GDParser *parser;
@@ -43,83 +42,86 @@ class GDCompiler {
const GDParser::FunctionNode *function_node;
bool debug_stack;
- List< Map<StringName,int> > stack_id_stack;
- Map<StringName,int> stack_identifiers;
-
- List<GDFunction::StackDebug> stack_debug;
- List< Map<StringName,int> > block_identifier_stack;
- Map<StringName,int> block_identifiers;
-
- void add_stack_identifier(const StringName& p_id,int p_stackpos) {
- stack_identifiers[p_id]=p_stackpos;
- if (debug_stack) {
- block_identifiers[p_id]=p_stackpos;
- GDFunction::StackDebug sd;
- sd.added=true;
- sd.line=current_line;
- sd.identifier=p_id;
- sd.pos=p_stackpos;
- stack_debug.push_back(sd);
- }
- }
-
- void push_stack_identifiers() {
- stack_id_stack.push_back( stack_identifiers );
- if (debug_stack) {
-
- block_identifier_stack.push_back(block_identifiers);
- block_identifiers.clear();
- }
- }
-
- void pop_stack_identifiers() {
- stack_identifiers = stack_id_stack.back()->get();
- stack_id_stack.pop_back();
-
- if (debug_stack) {
- for (Map<StringName,int>::Element *E=block_identifiers.front();E;E=E->next()) {
-
- GDFunction::StackDebug sd;
- sd.added=false;
- sd.identifier=E->key();
- sd.line=current_line;
- sd.pos=E->get();
- stack_debug.push_back(sd);
- }
- block_identifiers=block_identifier_stack.back()->get();
- block_identifier_stack.pop_back();
- }
- }
+ List<Map<StringName, int> > stack_id_stack;
+ Map<StringName, int> stack_identifiers;
+
+ List<GDFunction::StackDebug> stack_debug;
+ List<Map<StringName, int> > block_identifier_stack;
+ Map<StringName, int> block_identifiers;
+
+ void add_stack_identifier(const StringName &p_id, int p_stackpos) {
+ stack_identifiers[p_id] = p_stackpos;
+ if (debug_stack) {
+ block_identifiers[p_id] = p_stackpos;
+ GDFunction::StackDebug sd;
+ sd.added = true;
+ sd.line = current_line;
+ sd.identifier = p_id;
+ sd.pos = p_stackpos;
+ stack_debug.push_back(sd);
+ }
+ }
+ void push_stack_identifiers() {
+ stack_id_stack.push_back(stack_identifiers);
+ if (debug_stack) {
+
+ block_identifier_stack.push_back(block_identifiers);
+ block_identifiers.clear();
+ }
+ }
+
+ void pop_stack_identifiers() {
+ stack_identifiers = stack_id_stack.back()->get();
+ stack_id_stack.pop_back();
+
+ if (debug_stack) {
+ for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) {
+
+ GDFunction::StackDebug sd;
+ sd.added = false;
+ sd.identifier = E->key();
+ sd.line = current_line;
+ sd.pos = E->get();
+ stack_debug.push_back(sd);
+ }
+ block_identifiers = block_identifier_stack.back()->get();
+ block_identifier_stack.pop_back();
+ }
+ }
//int get_identifier_pos(const StringName& p_dentifier) const;
- HashMap<Variant,int,VariantHasher,VariantComparator> constant_map;
- Map<StringName,int> name_map;
+ HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
+ Map<StringName, int> name_map;
- int get_name_map_pos(const StringName& p_identifier) {
+ int get_name_map_pos(const StringName &p_identifier) {
int ret;
if (!name_map.has(p_identifier)) {
- ret=name_map.size();
- name_map[p_identifier]=ret;
+ ret = name_map.size();
+ name_map[p_identifier] = ret;
} else {
- ret=name_map[p_identifier];
+ ret = name_map[p_identifier];
}
return ret;
}
- int get_constant_pos(const Variant& p_constant) {
+ int get_constant_pos(const Variant &p_constant) {
if (constant_map.has(p_constant))
return constant_map[p_constant];
int pos = constant_map.size();
- constant_map[p_constant]=pos;
+ constant_map[p_constant] = pos;
return pos;
}
Vector<int> opcodes;
- void alloc_stack(int p_level) { if (p_level >= stack_max) stack_max=p_level+1; }
- void alloc_call(int p_params) { if (p_params >= call_max) call_max=p_params; }
+ void alloc_stack(int p_level) {
+ if (p_level >= stack_max) stack_max = p_level + 1;
+ }
+ void alloc_call(int p_params) {
+ if (p_params >= call_max) call_max = p_params;
+ }
- int current_line;
+ int current_line;
int stack_max;
int call_max;
};
@@ -135,28 +137,27 @@ class GDCompiler {
Ref<GDScript> _parse_class(GDParser::ClassNode *p_class);
#endif
- bool _is_class_member_property(CodeGen & codegen, const StringName & p_name);
- bool _is_class_member_property(GDScript *owner, const StringName & p_name);
+ bool _is_class_member_property(CodeGen &codegen, const StringName &p_name);
+ bool _is_class_member_property(GDScript *owner, const StringName &p_name);
- void _set_error(const String& p_error,const GDParser::Node *p_node);
+ void _set_error(const String &p_error, const GDParser::Node *p_node);
- bool _create_unary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level);
- bool _create_binary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level,bool p_initializer=false);
+ bool _create_unary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level);
+ bool _create_binary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer = false);
//int _parse_subexpression(CodeGen& codegen,const GDParser::BlockNode *p_block,const GDParser::Node *p_expression);
- int _parse_assign_right_expression(CodeGen& codegen,const GDParser::OperatorNode *p_expression, int p_stack_level);
- int _parse_expression(CodeGen& codegen,const GDParser::Node *p_expression, int p_stack_level,bool p_root=false,bool p_initializer=false);
- Error _parse_block(CodeGen& codegen,const GDParser::BlockNode *p_block,int p_stack_level=0,int p_break_addr=-1,int p_continue_addr=-1);
- Error _parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready=false);
- Error _parse_class(GDScript *p_script,GDScript *p_owner,const GDParser::ClassNode *p_class,bool p_keep_state);
+ int _parse_assign_right_expression(CodeGen &codegen, const GDParser::OperatorNode *p_expression, int p_stack_level);
+ int _parse_expression(CodeGen &codegen, const GDParser::Node *p_expression, int p_stack_level, bool p_root = false, bool p_initializer = false);
+ Error _parse_block(CodeGen &codegen, const GDParser::BlockNode *p_block, int p_stack_level = 0, int p_break_addr = -1, int p_continue_addr = -1);
+ Error _parse_function(GDScript *p_script, const GDParser::ClassNode *p_class, const GDParser::FunctionNode *p_func, bool p_for_ready = false);
+ Error _parse_class(GDScript *p_script, GDScript *p_owner, const GDParser::ClassNode *p_class, bool p_keep_state);
int err_line;
int err_column;
StringName source;
String error;
public:
-
- Error compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state=false);
+ Error compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state = false);
String get_error() const;
int get_error_line() const;
@@ -165,5 +166,4 @@ public:
GDCompiler();
};
-
#endif // COMPILER_H
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index 9dd41847d7..bd428941e0 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "gd_script.h"
#include "gd_compiler.h"
+#include "gd_script.h"
#include "global_config.h"
#include "os/file_access.h"
@@ -35,73 +35,64 @@ void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const
p_delimiters->push_back("#");
p_delimiters->push_back("\"\"\" \"\"\"");
-
}
void GDScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
p_delimiters->push_back("\" \"");
p_delimiters->push_back("' '");
-
-
}
-Ref<Script> GDScriptLanguage::get_template(const String& p_class_name, const String& p_base_class_name) const {
+Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const {
- String _template = String()+
- "extends %BASE%\n\n"+
- "# class member variables go here, for example:\n"+
- "# 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";
+ String _template = String() +
+ "extends %BASE%\n\n" +
+ "# class member variables go here, for example:\n" +
+ "# 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";
- _template = _template.replace("%BASE%",p_base_class_name);
+ _template = _template.replace("%BASE%", p_base_class_name);
Ref<GDScript> script;
script.instance();
script->set_source_code(_template);
return script;
-
}
-
-
-
-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 {
+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;
- Error err = parser.parse(p_script,p_path.get_base_dir(),true,p_path);
+ Error err = parser.parse(p_script, p_path.get_base_dir(), true, p_path);
if (err) {
- r_line_error=parser.get_error_line();
- r_col_error=parser.get_error_column();
- r_test_error=parser.get_error();
+ r_line_error = parser.get_error_line();
+ r_col_error = parser.get_error_column();
+ r_test_error = parser.get_error();
return false;
} else {
const GDParser::Node *root = parser.get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,false);
+ ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, false);
- const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
- Map<int,String> funcs;
- for(int i=0;i<cl->functions.size();i++) {
+ const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root);
+ Map<int, String> funcs;
+ for (int i = 0; i < cl->functions.size(); i++) {
- funcs[cl->functions[i]->line]=cl->functions[i]->name;
+ funcs[cl->functions[i]->line] = cl->functions[i]->name;
}
- for(int i=0;i<cl->static_functions.size();i++) {
+ for (int i = 0; i < cl->static_functions.size(); i++) {
- funcs[cl->static_functions[i]->line]=cl->static_functions[i]->name;
+ funcs[cl->static_functions[i]->line] = cl->static_functions[i]->name;
}
- for (Map<int,String>::Element *E=funcs.front();E;E=E->next()) {
+ for (Map<int, String>::Element *E = funcs.front(); E; E = E->next()) {
- r_functions->push_back(E->get()+":"+itos(E->key()));
+ r_functions->push_back(E->get() + ":" + itos(E->key()));
}
-
-
}
return true;
@@ -112,142 +103,133 @@ bool GDScriptLanguage::has_named_classes() const {
return false;
}
-int GDScriptLanguage::find_function(const String& p_function,const String& p_code) const {
+int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const {
GDTokenizerText tokenizer;
tokenizer.set_code(p_code);
- int indent=0;
- while(tokenizer.get_token()!=GDTokenizer::TK_EOF && tokenizer.get_token()!=GDTokenizer::TK_ERROR) {
+ int indent = 0;
+ while (tokenizer.get_token() != GDTokenizer::TK_EOF && tokenizer.get_token() != GDTokenizer::TK_ERROR) {
- if (tokenizer.get_token()==GDTokenizer::TK_NEWLINE) {
- indent=tokenizer.get_token_line_indent();
+ if (tokenizer.get_token() == GDTokenizer::TK_NEWLINE) {
+ indent = tokenizer.get_token_line_indent();
}
//print_line("TOKEN: "+String(GDTokenizer::get_token_name(tokenizer.get_token())));
- if (indent==0 && tokenizer.get_token()==GDTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1)==GDTokenizer::TK_IDENTIFIER) {
+ if (indent == 0 && tokenizer.get_token() == GDTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1) == GDTokenizer::TK_IDENTIFIER) {
String identifier = tokenizer.get_token_identifier(1);
- if (identifier==p_function) {
+ if (identifier == p_function) {
return tokenizer.get_token_line();
}
}
tokenizer.advance();
//print_line("NEXT: "+String(GDTokenizer::get_token_name(tokenizer.get_token())));
-
}
return -1;
}
Script *GDScriptLanguage::create_script() const {
- return memnew( GDScript );
+ return memnew(GDScript);
}
/* DEBUGGER FUNCTIONS */
-
-bool GDScriptLanguage::debug_break_parse(const String& p_file, int p_line,const String& p_error) {
+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()) {
-
- _debug_parse_err_line=p_line;
- _debug_parse_err_file=p_file;
- _debug_error=p_error;
- ScriptDebugger::get_singleton()->debug(this,false);
- return true;
- } else {
- return false;
- }
+ if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) {
+ _debug_parse_err_line = p_line;
+ _debug_parse_err_file = p_file;
+ _debug_error = p_error;
+ ScriptDebugger::get_singleton()->debug(this, false);
+ return true;
+ } else {
+ return false;
+ }
}
-bool GDScriptLanguage::debug_break(const String& p_error,bool p_allow_continue) {
-
- if (ScriptDebugger::get_singleton() && Thread::get_caller_ID()==Thread::get_main_ID()) {
+bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) {
- _debug_parse_err_line=-1;
- _debug_parse_err_file="";
- _debug_error=p_error;
- ScriptDebugger::get_singleton()->debug(this,p_allow_continue);
- return true;
- } else {
- return false;
- }
+ if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) {
+ _debug_parse_err_line = -1;
+ _debug_parse_err_file = "";
+ _debug_error = p_error;
+ ScriptDebugger::get_singleton()->debug(this, p_allow_continue);
+ return true;
+ } else {
+ return false;
+ }
}
String GDScriptLanguage::debug_get_error() const {
- return _debug_error;
+ return _debug_error;
}
int GDScriptLanguage::debug_get_stack_level_count() const {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return 1;
-
return _debug_call_stack_pos;
}
int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return _debug_parse_err_line;
- ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,-1);
+ ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1);
- int l = _debug_call_stack_pos - p_level -1;
-
- return *(_call_stack[l].line);
+ int l = _debug_call_stack_pos - p_level - 1;
+ return *(_call_stack[l].line);
}
String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return "";
- 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_name();
+ 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_name();
}
String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return _debug_parse_err_file;
- 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_source();
-
+ 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_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) {
+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) {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return;
- ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
- int l = _debug_call_stack_pos - p_level -1;
+ ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
+ int l = _debug_call_stack_pos - p_level - 1;
- GDFunction *f = _call_stack[l].function;
+ GDFunction *f = _call_stack[l].function;
- List<Pair<StringName,int> > locals;
+ List<Pair<StringName, int> > locals;
- f->debug_get_stack_member_state(*_call_stack[l].line,&locals);
- for( List<Pair<StringName,int> >::Element *E = locals.front();E;E=E->next() ) {
-
- p_locals->push_back(E->get().first);
- p_values->push_back(_call_stack[l].stack[E->get().second]);
- }
+ f->debug_get_stack_member_state(*_call_stack[l].line, &locals);
+ for (List<Pair<StringName, int> >::Element *E = locals.front(); E; E = E->next()) {
+ p_locals->push_back(E->get().first);
+ p_values->push_back(_call_stack[l].stack[E->get().second]);
+ }
}
-void GDScriptLanguage::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 GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return;
- ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
- int l = _debug_call_stack_pos - p_level -1;
-
+ ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
+ int l = _debug_call_stack_pos - p_level - 1;
GDInstance *instance = _call_stack[l].instance;
@@ -255,25 +237,23 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level,List<String> *p
return;
Ref<GDScript> script = instance->get_script();
- ERR_FAIL_COND( script.is_null() );
-
+ ERR_FAIL_COND(script.is_null());
- const Map<StringName,GDScript::MemberInfo>& mi = script->debug_get_member_indices();
+ const Map<StringName, GDScript::MemberInfo> &mi = script->debug_get_member_indices();
- for(const Map<StringName,GDScript::MemberInfo>::Element *E=mi.front();E;E=E->next()) {
+ for (const Map<StringName, GDScript::MemberInfo>::Element *E = mi.front(); E; E = E->next()) {
p_members->push_back(E->key());
- p_values->push_back( instance->debug_get_member_by_index(E->get().index));
+ p_values->push_back(instance->debug_get_member_by_index(E->get().index));
}
-
}
-void GDScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems,int p_max_depth) {
+void GDScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- //no globals are really reachable in gdscript
+ //no globals are really reachable in gdscript
}
-String GDScriptLanguage::debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems,int p_max_depth) {
+String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line>=0)
+ if (_debug_parse_err_line >= 0)
return "";
return "";
}
@@ -283,11 +263,9 @@ void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) con
p_extensions->push_back("gd");
}
-
void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {
-
- for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
+ for (int i = 0; i < GDFunctions::FUNC_MAX; i++) {
p_functions->push_back(GDFunctions::get_info(GDFunctions::Function(i)));
}
@@ -295,33 +273,33 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const
//not really "functions", but..
{
MethodInfo mi;
- mi.name="preload:Resource";
- mi.arguments.push_back(PropertyInfo(Variant::STRING,"path"));
- mi.return_val=PropertyInfo(Variant::OBJECT,"",PROPERTY_HINT_RESOURCE_TYPE,"Resource");
+ mi.name = "preload:Resource";
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "path"));
+ mi.return_val = PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_RESOURCE_TYPE, "Resource");
p_functions->push_back(mi);
}
{
MethodInfo mi;
- mi.name="yield:GDFunctionState";
- mi.arguments.push_back(PropertyInfo(Variant::OBJECT,"object"));
- mi.arguments.push_back(PropertyInfo(Variant::STRING,"signal"));
+ mi.name = "yield:GDFunctionState";
+ mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object"));
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "signal"));
mi.default_arguments.push_back(Variant::NIL);
mi.default_arguments.push_back(Variant::STRING);
p_functions->push_back(mi);
}
{
MethodInfo mi;
- mi.name="assert";
- mi.arguments.push_back(PropertyInfo(Variant::BOOL,"condition"));
+ mi.name = "assert";
+ mi.arguments.push_back(PropertyInfo(Variant::BOOL, "condition"));
p_functions->push_back(mi);
}
}
-void GDScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_constants) const {
+void GDScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const {
- Pair<String,Variant> pi;
- pi.first="PI";
- pi.second=Math_PI;
+ Pair<String, Variant> pi;
+ pi.first = "PI";
+ pi.second = Math_PI;
p_constants->push_back(pi);
Pair<String, Variant> infinity;
@@ -335,22 +313,21 @@ void GDScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_const
p_constants->push_back(nan);
}
-String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const {
+String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const {
- String s="func "+p_name+"(";
+ String s = "func " + p_name + "(";
if (p_args.size()) {
- s+=" ";
- for(int i=0;i<p_args.size();i++) {
- if (i>0)
- s+=", ";
- s+=p_args[i].get_slice(":",0);
+ s += " ";
+ for (int i = 0; i < p_args.size(); i++) {
+ if (i > 0)
+ s += ", ";
+ s += p_args[i].get_slice(":", 0);
}
- s+=" ";
+ s += " ";
}
- s+="):\n\tpass # replace with function body\n";
+ s += "):\n\tpass # replace with function body\n";
return s;
-
}
#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED)
@@ -361,17 +338,14 @@ struct GDCompletionIdentifier {
Ref<GDScript> script;
Variant::Type type;
Variant value; //im case there is a value, also return it
-
};
-
-
-static GDCompletionIdentifier _get_type_from_variant(const Variant& p_variant) {
+static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant) {
GDCompletionIdentifier t;
- t.type=p_variant.get_type();
- t.value=p_variant;
- if (p_variant.get_type()==Variant::OBJECT) {
+ t.type = p_variant.get_type();
+ t.value = p_variant;
+ if (p_variant.get_type() == Variant::OBJECT) {
Object *obj = p_variant;
if (obj) {
/*
@@ -380,19 +354,19 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant& p_variant) {
t.value=Variant();
} else {
*/
- t.obj_type=obj->get_class();
+ t.obj_type = obj->get_class();
//}
}
}
return t;
}
-static GDCompletionIdentifier _get_type_from_pinfo(const PropertyInfo& p_info) {
+static GDCompletionIdentifier _get_type_from_pinfo(const PropertyInfo &p_info) {
GDCompletionIdentifier t;
- t.type=p_info.type;
- if (p_info.hint==PROPERTY_HINT_RESOURCE_TYPE) {
- t.obj_type=p_info.hint_string;
+ t.type = p_info.type;
+ if (p_info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ t.obj_type = p_info.hint_string;
}
return t;
}
@@ -402,15 +376,11 @@ struct GDCompletionContext {
const GDParser::ClassNode *_class;
const GDParser::FunctionNode *function;
const GDParser::BlockNode *block;
- Object* base;
+ Object *base;
String base_path;
-
};
-
-static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
-
-
+static Ref<Reference> _get_parent_class(GDCompletionContext &context) {
if (context._class->extends_used) {
//do inheritance
@@ -419,12 +389,12 @@ static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
Ref<GDScript> script;
Ref<GDNativeClass> native;
- if (path!="") {
+ if (path != "") {
//path (and optionally subclasses)
if (path.is_rel_path()) {
- path=context.base_path.plus_file(path);
+ path = context.base_path.plus_file(path);
}
if (ScriptCodeCompletionCache::get_sigleton())
@@ -443,12 +413,12 @@ static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
if (context._class->extends_class.size()) {
- for(int i=0;i<context._class->extends_class.size();i++) {
+ for (int i = 0; i < context._class->extends_class.size(); i++) {
String sub = context._class->extends_class[i];
if (script->get_subclasses().has(sub)) {
- script=script->get_subclasses()[sub];
+ script = script->get_subclasses()[sub];
} else {
return REF();
@@ -461,17 +431,16 @@ static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
} else {
- if (context._class->extends_class.size()==0) {
+ if (context._class->extends_class.size() == 0) {
ERR_PRINT("BUG");
return REF();
}
- String base=context._class->extends_class[0];
+ String base = context._class->extends_class[0];
- if (context._class->extends_class.size()>1) {
+ if (context._class->extends_class.size() > 1) {
return REF();
-
}
//if not found, try engine classes
if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
@@ -482,22 +451,19 @@ static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base];
native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx];
return native;
-
}
-
}
return Ref<Reference>();
}
-
-static GDCompletionIdentifier _get_native_class(GDCompletionContext& context) {
+static GDCompletionIdentifier _get_native_class(GDCompletionContext &context) {
//eeh...
GDCompletionIdentifier id;
- id.type=Variant::NIL;
+ id.type = Variant::NIL;
- REF pc = _get_parent_class(context);
+ REF pc = _get_parent_class(context);
if (!pc.is_valid()) {
return id;
}
@@ -507,204 +473,191 @@ static GDCompletionIdentifier _get_native_class(GDCompletionContext& context) {
if (s.is_null() && nc.is_null()) {
return id;
}
- while(!s.is_null()) {
- nc=s->get_native();
- s=s->get_base();
+ while (!s.is_null()) {
+ nc = s->get_native();
+ s = s->get_base();
}
if (nc.is_null()) {
return id;
}
-
-
- id.type=Variant::OBJECT;
+ id.type = Variant::OBJECT;
if (context.base)
- id.value=context.base;
- id.obj_type=nc->get_name();
+ id.value = context.base;
+ id.obj_type = nc->get_name();
return id;
}
-static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type);
-
+static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type);
-static bool _guess_expression_type(GDCompletionContext& context,const GDParser::Node* p_node,int p_line,GDCompletionIdentifier &r_type) {
+static bool _guess_expression_type(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, GDCompletionIdentifier &r_type) {
+ if (p_node->type == GDParser::Node::TYPE_CONSTANT) {
- if (p_node->type==GDParser::Node::TYPE_CONSTANT) {
+ const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(p_node);
- const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(p_node);
-
- r_type=_get_type_from_variant(cn->value);
+ r_type = _get_type_from_variant(cn->value);
return true;
- } else if (p_node->type==GDParser::Node::TYPE_DICTIONARY) {
-
- r_type.type=Variant::DICTIONARY;
+ } else if (p_node->type == GDParser::Node::TYPE_DICTIONARY) {
+ r_type.type = Variant::DICTIONARY;
//what the heck, fill it anyway
const GDParser::DictionaryNode *an = static_cast<const GDParser::DictionaryNode *>(p_node);
Dictionary d;
- for(int i=0;i<an->elements.size();i++) {
+ for (int i = 0; i < an->elements.size(); i++) {
GDCompletionIdentifier k;
- if (_guess_expression_type(context,an->elements[i].key,p_line,k) && k.value.get_type()!=Variant::NIL) {
+ if (_guess_expression_type(context, an->elements[i].key, p_line, k) && k.value.get_type() != Variant::NIL) {
GDCompletionIdentifier v;
- if (_guess_expression_type(context,an->elements[i].value,p_line,v)) {
- d[k.value]=v.value;
+ if (_guess_expression_type(context, an->elements[i].value, p_line, v)) {
+ d[k.value] = v.value;
}
-
}
}
- r_type.value=d;
+ r_type.value = d;
return true;
- } else if (p_node->type==GDParser::Node::TYPE_ARRAY) {
+ } else if (p_node->type == GDParser::Node::TYPE_ARRAY) {
- r_type.type=Variant::ARRAY;
+ r_type.type = Variant::ARRAY;
//what the heck, fill it anyway
const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(p_node);
Array arr;
arr.resize(an->elements.size());
- for(int i=0;i<an->elements.size();i++) {
+ for (int i = 0; i < an->elements.size(); i++) {
GDCompletionIdentifier ci;
- if (_guess_expression_type(context,an->elements[i],p_line,ci)) {
- arr[i]=ci.value;
+ if (_guess_expression_type(context, an->elements[i], p_line, ci)) {
+ arr[i] = ci.value;
}
}
- r_type.value=arr;
+ r_type.value = arr;
return true;
- } else if (p_node->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
+ } else if (p_node->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
- MethodInfo mi = GDFunctions::get_info(static_cast<const GDParser::BuiltInFunctionNode*>(p_node)->function);
- r_type=_get_type_from_pinfo(mi.return_val);
+ MethodInfo mi = GDFunctions::get_info(static_cast<const GDParser::BuiltInFunctionNode *>(p_node)->function);
+ r_type = _get_type_from_pinfo(mi.return_val);
return true;
- } else if (p_node->type==GDParser::Node::TYPE_IDENTIFIER) {
+ } else if (p_node->type == GDParser::Node::TYPE_IDENTIFIER) {
- return _guess_identifier_type(context,p_line-1,static_cast<const GDParser::IdentifierNode *>(p_node)->name,r_type);
- } else if (p_node->type==GDParser::Node::TYPE_SELF) {
+ return _guess_identifier_type(context, p_line - 1, static_cast<const GDParser::IdentifierNode *>(p_node)->name, r_type);
+ } else if (p_node->type == GDParser::Node::TYPE_SELF) {
//eeh...
- r_type=_get_native_class(context);
- return r_type.type!=Variant::NIL;
-
- } else if (p_node->type==GDParser::Node::TYPE_OPERATOR) {
+ r_type = _get_native_class(context);
+ return r_type.type != Variant::NIL;
+ } else if (p_node->type == GDParser::Node::TYPE_OPERATOR) {
const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node);
- if (op->op==GDParser::OperatorNode::OP_CALL) {
- if (op->arguments[0]->type==GDParser::Node::TYPE_TYPE) {
+ if (op->op == GDParser::OperatorNode::OP_CALL) {
+ if (op->arguments[0]->type == GDParser::Node::TYPE_TYPE) {
const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode *>(op->arguments[0]);
- r_type.type=tn->vtype;
+ r_type.type = tn->vtype;
return true;
- } else if (op->arguments[0]->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
-
+ } else if (op->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
const GDParser::BuiltInFunctionNode *bin = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
- return _guess_expression_type(context,bin,p_line,r_type);
-
- } else if (op->arguments.size()>1 && op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ return _guess_expression_type(context, bin, p_line, r_type);
+ } else if (op->arguments.size() > 1 && op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) {
GDCompletionIdentifier base;
- if (!_guess_expression_type(context,op->arguments[0],p_line,base))
+ if (!_guess_expression_type(context, op->arguments[0], p_line, base))
return false;
StringName id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name;
- if (base.type==Variant::OBJECT) {
+ if (base.type == Variant::OBJECT) {
- if (id.operator String()=="new" && base.value.get_type()==Variant::OBJECT) {
+ if (id.operator String() == "new" && base.value.get_type() == Variant::OBJECT) {
Object *obj = base.value;
if (obj && obj->cast_to<GDNativeClass>()) {
GDNativeClass *gdnc = obj->cast_to<GDNativeClass>();
- r_type.type=Variant::OBJECT;
- r_type.value=Variant();
- r_type.obj_type=gdnc->get_name();
+ r_type.type = Variant::OBJECT;
+ r_type.value = Variant();
+ r_type.obj_type = gdnc->get_name();
return true;
}
}
- if (ClassDB::has_method(base.obj_type,id)) {
+ if (ClassDB::has_method(base.obj_type, id)) {
#ifdef TOOLS_ENABLED
- MethodBind *mb = ClassDB::get_method(base.obj_type,id);
+ MethodBind *mb = ClassDB::get_method(base.obj_type, id);
PropertyInfo pi = mb->get_argument_info(-1);
//try calling the function if constant and all args are constant, should not crash..
Object *baseptr = base.value;
+ if (mb->is_const() && pi.type == Variant::OBJECT) {
- if (mb->is_const() && pi.type==Variant::OBJECT) {
-
- bool all_valid=true;
+ bool all_valid = true;
Vector<Variant> args;
- for(int i=2;i<op->arguments.size();i++) {
+ for (int i = 2; i < op->arguments.size(); i++) {
GDCompletionIdentifier arg;
- if (_guess_expression_type(context,op->arguments[i],p_line,arg)) {
- if (arg.value.get_type()!=Variant::NIL && arg.value.get_type()!=Variant::OBJECT) { // calling with object seems dangerous, i don' t know
+ if (_guess_expression_type(context, op->arguments[i], p_line, arg)) {
+ if (arg.value.get_type() != Variant::NIL && arg.value.get_type() != Variant::OBJECT) { // calling with object seems dangerous, i don' t know
args.push_back(arg.value);
} else {
- all_valid=false;
+ all_valid = false;
break;
}
} else {
- all_valid=false;
+ all_valid = false;
}
}
- if (all_valid && String(id)=="get_node" && ClassDB::is_parent_class(base.obj_type,"Node") && args.size()) {
+ if (all_valid && String(id) == "get_node" && ClassDB::is_parent_class(base.obj_type, "Node") && args.size()) {
- String arg1=args[0];
+ String arg1 = args[0];
if (arg1.begins_with("/root/")) {
- String which = arg1.get_slice("/",2);
- if (which!="") {
+ String which = arg1.get_slice("/", 2);
+ if (which != "") {
List<PropertyInfo> props;
GlobalConfig::get_singleton()->get_property_list(&props);
//print_line("find singleton");
- for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
//print_line("found "+s);
- String name = s.get_slice("/",1);
+ String name = s.get_slice("/", 1);
//print_line("name: "+name+", which: "+which);
- if (name==which) {
+ if (name == which) {
String script = GlobalConfig::get_singleton()->get(s);
if (!script.begins_with("res://")) {
- script="res://"+script;
+ script = "res://" + script;
}
if (!script.ends_with(".gd")) {
//not a script, try find the script anyway,
//may have some success
- script=script.get_basename()+".gd";
+ script = script.get_basename() + ".gd";
}
if (FileAccess::exists(script)) {
//print_line("is a script");
-
Ref<Script> scr;
if (ScriptCodeCompletionCache::get_sigleton())
scr = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(script);
else
scr = ResourceLoader::load(script);
-
- r_type.obj_type="Node";
- r_type.type=Variant::OBJECT;
- r_type.script=scr;
- r_type.value=Variant();
+ r_type.obj_type = "Node";
+ r_type.type = Variant::OBJECT;
+ r_type.script = scr;
+ r_type.value = Variant();
return true;
-
}
}
}
@@ -712,40 +665,34 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser::
}
}
-
-
if (baseptr) {
if (all_valid) {
- Vector<const Variant*> argptr;
- for(int i=0;i<args.size();i++) {
+ Vector<const Variant *> argptr;
+ for (int i = 0; i < args.size(); i++) {
argptr.push_back(&args[i]);
}
Variant::CallError ce;
- Variant ret=mb->call(baseptr,argptr.ptr(),argptr.size(),ce);
+ Variant ret = mb->call(baseptr, argptr.ptr(), argptr.size(), ce);
+ if (ce.error == Variant::CallError::CALL_OK && ret.get_type() != Variant::NIL) {
- if (ce.error==Variant::CallError::CALL_OK && ret.get_type()!=Variant::NIL) {
+ if (ret.get_type() != Variant::OBJECT || ret.operator Object *() != NULL) {
- if (ret.get_type()!=Variant::OBJECT || ret.operator Object*()!=NULL) {
-
- r_type=_get_type_from_variant(ret);
+ r_type = _get_type_from_variant(ret);
return true;
}
}
-
}
}
}
- r_type.type=pi.type;
- if (pi.hint==PROPERTY_HINT_RESOURCE_TYPE) {
- r_type.obj_type=pi.hint_string;
+ r_type.type = pi.type;
+ if (pi.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ r_type.obj_type = pi.hint_string;
}
-
-
return true;
#else
return false;
@@ -756,115 +703,108 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser::
} else {
//method for some variant..
Variant::CallError ce;
- Variant v = Variant::construct(base.type,NULL,0,ce);
+ Variant v = Variant::construct(base.type, NULL, 0, ce);
List<MethodInfo> mi;
v.get_method_list(&mi);
- for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
-
- if (!E->get().name.begins_with("_") && E->get().name==id.operator String()) {
+ for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) {
+ if (!E->get().name.begins_with("_") && E->get().name == id.operator String()) {
MethodInfo mi = E->get();
- r_type.type=mi.return_val.type;
- if (mi.return_val.hint==PROPERTY_HINT_RESOURCE_TYPE) {
- r_type.obj_type=mi.return_val.hint_string;
+ r_type.type = mi.return_val.type;
+ if (mi.return_val.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ r_type.obj_type = mi.return_val.hint_string;
}
return true;
}
}
-
}
-
-
}
- } else if (op->op==GDParser::OperatorNode::OP_INDEX || op->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
+ } else if (op->op == GDParser::OperatorNode::OP_INDEX || op->op == GDParser::OperatorNode::OP_INDEX_NAMED) {
GDCompletionIdentifier p1;
GDCompletionIdentifier p2;
+ if (op->op == GDParser::OperatorNode::OP_INDEX_NAMED) {
-
- if (op->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
-
- if (op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
- String id = static_cast<const GDParser::IdentifierNode*>(op->arguments[1])->name;
- p2.type=Variant::STRING;
- p2.value=id;
+ if (op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) {
+ String id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name;
+ p2.type = Variant::STRING;
+ p2.value = id;
}
} else {
if (op->arguments[1]) {
- if (!_guess_expression_type(context,op->arguments[1],p_line,p2)) {
+ if (!_guess_expression_type(context, op->arguments[1], p_line, p2)) {
return false;
}
}
}
- if (op->arguments[0]->type==GDParser::Node::TYPE_ARRAY) {
+ if (op->arguments[0]->type == GDParser::Node::TYPE_ARRAY) {
const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(op->arguments[0]);
if (p2.value.is_num()) {
int index = p2.value;
- if (index<0 || index>=an->elements.size())
+ if (index < 0 || index >= an->elements.size())
return false;
- return _guess_expression_type(context,an->elements[index],p_line,r_type);
+ return _guess_expression_type(context, an->elements[index], p_line, r_type);
}
- } else if (op->arguments[0]->type==GDParser::Node::TYPE_DICTIONARY) {
+ } else if (op->arguments[0]->type == GDParser::Node::TYPE_DICTIONARY) {
const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode *>(op->arguments[0]);
- if (p2.value.get_type()==Variant::NIL)
+ if (p2.value.get_type() == Variant::NIL)
return false;
- for(int i=0;i<dn->elements.size();i++) {
+ for (int i = 0; i < dn->elements.size(); i++) {
GDCompletionIdentifier k;
- if (!_guess_expression_type(context,dn->elements[i].key,p_line,k)) {
+ if (!_guess_expression_type(context, dn->elements[i].key, p_line, k)) {
return false;
}
- if (k.value.get_type()==Variant::NIL)
+ if (k.value.get_type() == Variant::NIL)
return false;
- if (k.value==p2.value) {
+ if (k.value == p2.value) {
- return _guess_expression_type(context,dn->elements[i].value,p_line,r_type);
+ return _guess_expression_type(context, dn->elements[i].value, p_line, r_type);
}
}
} else {
if (op->arguments[0]) {
- if (!_guess_expression_type(context,op->arguments[0],p_line,p1)) {
+ if (!_guess_expression_type(context, op->arguments[0], p_line, p1)) {
return false;
}
-
}
- if (p1.value.get_type()==Variant::OBJECT) {
+ if (p1.value.get_type() == Variant::OBJECT) {
//??
- } else if (p1.value.get_type()!=Variant::NIL) {
+ } else if (p1.value.get_type() != Variant::NIL) {
bool valid;
- Variant ret = p1.value.get(p2.value,&valid);
+ Variant ret = p1.value.get(p2.value, &valid);
if (valid) {
- r_type=_get_type_from_variant(ret);
+ r_type = _get_type_from_variant(ret);
return true;
}
} else {
- if (p1.type!=Variant::NIL) {
+ if (p1.type != Variant::NIL) {
Variant::CallError ce;
- Variant base = Variant::construct(p1.type,NULL,0,ce);
+ Variant base = Variant::construct(p1.type, NULL, 0, ce);
bool valid;
- Variant ret = base.get(p2.value,&valid);
+ Variant ret = base.get(p2.value, &valid);
if (valid) {
- r_type=_get_type_from_variant(ret);
+ r_type = _get_type_from_variant(ret);
return true;
}
}
@@ -873,127 +813,115 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser::
} else {
-
Variant::Operator vop = Variant::OP_MAX;
- switch(op->op) {
- case GDParser::OperatorNode::OP_ADD: vop=Variant::OP_ADD; break;
- case GDParser::OperatorNode::OP_SUB: vop=Variant::OP_SUBSTRACT; break;
- case GDParser::OperatorNode::OP_MUL: vop=Variant::OP_MULTIPLY; break;
- case GDParser::OperatorNode::OP_DIV: vop=Variant::OP_DIVIDE; break;
- case GDParser::OperatorNode::OP_MOD: vop=Variant::OP_MODULE; break;
- case GDParser::OperatorNode::OP_SHIFT_LEFT: vop=Variant::OP_SHIFT_LEFT; break;
- case GDParser::OperatorNode::OP_SHIFT_RIGHT: vop=Variant::OP_SHIFT_RIGHT; break;
- case GDParser::OperatorNode::OP_BIT_AND: vop=Variant::OP_BIT_AND; break;
- case GDParser::OperatorNode::OP_BIT_OR: vop=Variant::OP_BIT_OR; break;
- case GDParser::OperatorNode::OP_BIT_XOR: vop=Variant::OP_BIT_XOR; break;
- default:{}
-
+ switch (op->op) {
+ case GDParser::OperatorNode::OP_ADD: vop = Variant::OP_ADD; break;
+ case GDParser::OperatorNode::OP_SUB: vop = Variant::OP_SUBSTRACT; break;
+ case GDParser::OperatorNode::OP_MUL: vop = Variant::OP_MULTIPLY; break;
+ case GDParser::OperatorNode::OP_DIV: vop = Variant::OP_DIVIDE; break;
+ case GDParser::OperatorNode::OP_MOD: vop = Variant::OP_MODULE; break;
+ case GDParser::OperatorNode::OP_SHIFT_LEFT: vop = Variant::OP_SHIFT_LEFT; break;
+ case GDParser::OperatorNode::OP_SHIFT_RIGHT: vop = Variant::OP_SHIFT_RIGHT; break;
+ case GDParser::OperatorNode::OP_BIT_AND: vop = Variant::OP_BIT_AND; break;
+ case GDParser::OperatorNode::OP_BIT_OR: vop = Variant::OP_BIT_OR; break;
+ case GDParser::OperatorNode::OP_BIT_XOR: vop = Variant::OP_BIT_XOR; break;
+ default: {}
}
-
-
- if (vop==Variant::OP_MAX)
+ if (vop == Variant::OP_MAX)
return false;
-
-
GDCompletionIdentifier p1;
GDCompletionIdentifier p2;
if (op->arguments[0]) {
- if (!_guess_expression_type(context,op->arguments[0],p_line,p1)) {
+ if (!_guess_expression_type(context, op->arguments[0], p_line, p1)) {
return false;
}
-
}
- if (op->arguments.size()>1) {
- if (!_guess_expression_type(context,op->arguments[1],p_line,p2)) {
+ if (op->arguments.size() > 1) {
+ if (!_guess_expression_type(context, op->arguments[1], p_line, p2)) {
return false;
}
}
Variant::CallError ce;
- bool v1_use_value = p1.value.get_type()!=Variant::NIL && p1.value.get_type()!=Variant::OBJECT;
- Variant v1 = (v1_use_value)?p1.value:Variant::construct(p1.type,NULL,0,ce);
- bool v2_use_value = p2.value.get_type()!=Variant::NIL && p2.value.get_type()!=Variant::OBJECT;
- Variant v2 = (v2_use_value)?p2.value:Variant::construct(p2.type,NULL,0,ce);
+ bool v1_use_value = p1.value.get_type() != Variant::NIL && p1.value.get_type() != Variant::OBJECT;
+ Variant v1 = (v1_use_value) ? p1.value : Variant::construct(p1.type, NULL, 0, ce);
+ bool v2_use_value = p2.value.get_type() != Variant::NIL && p2.value.get_type() != Variant::OBJECT;
+ Variant v2 = (v2_use_value) ? p2.value : Variant::construct(p2.type, NULL, 0, ce);
// avoid potential invalid ops
- if ((vop==Variant::OP_DIVIDE || vop==Variant::OP_MODULE) && v2.get_type()==Variant::INT) {
- v2=1;
- v2_use_value=false;
+ if ((vop == Variant::OP_DIVIDE || vop == Variant::OP_MODULE) && v2.get_type() == Variant::INT) {
+ v2 = 1;
+ v2_use_value = false;
}
- if (vop==Variant::OP_DIVIDE && v2.get_type()==Variant::REAL) {
- v2=1.0;
- v2_use_value=false;
+ if (vop == Variant::OP_DIVIDE && v2.get_type() == Variant::REAL) {
+ v2 = 1.0;
+ v2_use_value = false;
}
Variant r;
bool valid;
- Variant::evaluate(vop,v1,v2,r,valid);
+ Variant::evaluate(vop, v1, v2, r, valid);
if (!valid)
return false;
- r_type.type=r.get_type();
+ r_type.type = r.get_type();
if (v1_use_value && v2_use_value)
- r_type.value=r;
+ r_type.value = r;
return true;
-
}
-
}
return false;
}
-
-static bool _guess_identifier_type_in_block(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type) {
-
+static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) {
GDCompletionIdentifier gdi = _get_native_class(context);
- if (gdi.obj_type!=StringName()) {
+ if (gdi.obj_type != StringName()) {
bool valid;
- Variant::Type t = ClassDB::get_property_type(gdi.obj_type,p_identifier,&valid);
- if (t!=Variant::NIL && valid) {
- r_type.type=t;
+ Variant::Type t = ClassDB::get_property_type(gdi.obj_type, p_identifier, &valid);
+ if (t != Variant::NIL && valid) {
+ r_type.type = t;
return true;
}
}
- const GDParser::Node *last_assign=NULL;
- int last_assign_line=-1;
+ const GDParser::Node *last_assign = NULL;
+ int last_assign_line = -1;
- for (int i=0;i<context.block->statements.size();i++) {
+ for (int i = 0; i < context.block->statements.size(); i++) {
- if (context.block->statements[i]->line>p_line)
+ if (context.block->statements[i]->line > p_line)
continue;
+ if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) {
- if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
-
- const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
+ const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
- if (lv->assign && lv->name==p_identifier) {
+ if (lv->assign && lv->name == p_identifier) {
- last_assign=lv->assign;
- last_assign_line=context.block->statements[i]->line;
+ last_assign = lv->assign;
+ last_assign_line = context.block->statements[i]->line;
}
}
- if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_OPERATOR) {
+ if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_OPERATOR) {
const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->statements[i]);
- if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
+ if (op->op == GDParser::OperatorNode::OP_ASSIGN) {
- if (op->arguments.size() && op->arguments[0]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ if (op->arguments.size() && op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) {
const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[0]);
- if (id->name==p_identifier) {
+ if (id->name == p_identifier) {
- last_assign=op->arguments[1];
- last_assign_line=context.block->statements[i]->line;
+ last_assign = op->arguments[1];
+ last_assign_line = context.block->statements[i]->line;
}
}
}
@@ -1003,20 +931,18 @@ static bool _guess_identifier_type_in_block(GDCompletionContext& context,int p_l
//use the last assignment, (then backwards?)
if (last_assign) {
- return _guess_expression_type(context,last_assign,last_assign_line,r_type);
+ return _guess_expression_type(context, last_assign, last_assign_line, r_type);
}
-
return false;
}
+static bool _guess_identifier_from_assignment_in_function(GDCompletionContext &context, int p_src_line, const StringName &p_identifier, const StringName &p_function, GDCompletionIdentifier &r_type) {
-static bool _guess_identifier_from_assignment_in_function(GDCompletionContext& context, int p_src_line, const StringName& p_identifier, const StringName& p_function,GDCompletionIdentifier &r_type) {
-
- const GDParser::FunctionNode* func=NULL;
- for(int i=0;i<context._class->functions.size();i++) {
- if (context._class->functions[i]->name==p_function) {
- func=context._class->functions[i];
+ const GDParser::FunctionNode *func = NULL;
+ for (int i = 0; i < context._class->functions.size(); i++) {
+ if (context._class->functions[i]->name == p_function) {
+ func = context._class->functions[i];
break;
}
}
@@ -1024,23 +950,23 @@ static bool _guess_identifier_from_assignment_in_function(GDCompletionContext& c
if (!func)
return false;
- for(int i=0;i<func->body->statements.size();i++) {
+ for (int i = 0; i < func->body->statements.size(); i++) {
if (func->body->statements[i]->line == p_src_line) {
break;
}
- if (func->body->statements[i]->type==GDParser::BlockNode::TYPE_OPERATOR) {
+ if (func->body->statements[i]->type == GDParser::BlockNode::TYPE_OPERATOR) {
const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(func->body->statements[i]);
- if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
+ if (op->op == GDParser::OperatorNode::OP_ASSIGN) {
- if (op->arguments.size() && op->arguments[0]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ if (op->arguments.size() && op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) {
const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[0]);
- if (id->name==p_identifier) {
+ if (id->name == p_identifier) {
- return _guess_expression_type(context,op->arguments[1],func->body->statements[i]->line,r_type);
+ return _guess_expression_type(context, op->arguments[1], func->body->statements[i]->line, r_type);
}
}
}
@@ -1050,66 +976,62 @@ static bool _guess_identifier_from_assignment_in_function(GDCompletionContext& c
return false;
}
-static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type) {
+static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) {
//go to block first
+ const GDParser::BlockNode *block = context.block;
- const GDParser::BlockNode *block=context.block;
-
- while(block) {
+ while (block) {
GDCompletionContext c = context;
- c.block=block;
+ c.block = block;
- if (_guess_identifier_type_in_block(c,p_line,p_identifier,r_type)) {
+ if (_guess_identifier_type_in_block(c, p_line, p_identifier, r_type)) {
return true;
}
- block=block->parent_block;
+ block = block->parent_block;
}
//guess from argument if virtual
- if (context.function && context.function->name!=StringName()) {
+ if (context.function && context.function->name != StringName()) {
int argindex = -1;
- for(int i=0;i<context.function->arguments.size();i++) {
+ for (int i = 0; i < context.function->arguments.size(); i++) {
- if (context.function->arguments[i]==p_identifier) {
- argindex=i;
+ if (context.function->arguments[i] == p_identifier) {
+ argindex = i;
break;
}
-
}
- if (argindex!=-1) {
- GDCompletionIdentifier id =_get_native_class(context);
- if (id.type==Variant::OBJECT && id.obj_type!=StringName()) {
+ if (argindex != -1) {
+ GDCompletionIdentifier id = _get_native_class(context);
+ if (id.type == Variant::OBJECT && id.obj_type != StringName()) {
//this kinda sucks but meh
List<MethodInfo> vmethods;
- ClassDB::get_virtual_methods(id.obj_type,&vmethods);
- for (List<MethodInfo>::Element *E=vmethods.front();E;E=E->next()) {
-
+ ClassDB::get_virtual_methods(id.obj_type, &vmethods);
+ for (List<MethodInfo>::Element *E = vmethods.front(); E; E = E->next()) {
- if (E->get().name==context.function->name && argindex<E->get().arguments.size()) {
+ if (E->get().name == context.function->name && argindex < E->get().arguments.size()) {
- PropertyInfo arg=E->get().arguments[argindex];
+ PropertyInfo arg = E->get().arguments[argindex];
int scp = arg.name.find(":");
- if (scp!=-1) {
+ if (scp != -1) {
-
- r_type.type=Variant::OBJECT;
- r_type.obj_type=arg.name.substr(scp+1,arg.name.length());
+ r_type.type = Variant::OBJECT;
+ r_type.obj_type = arg.name.substr(scp + 1, arg.name.length());
return true;
} else {
- r_type.type=arg.type;
- if (arg.hint==PROPERTY_HINT_RESOURCE_TYPE)
- r_type.obj_type=arg.hint_string;
+ r_type.type = arg.type;
+ if (arg.hint == PROPERTY_HINT_RESOURCE_TYPE)
+ r_type.obj_type = arg.hint_string;
return true;
}
}
@@ -1120,40 +1042,40 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
//guess type in constant
- for(int i=0;i<context._class->constant_expressions.size();i++) {
+ for (int i = 0; i < context._class->constant_expressions.size(); i++) {
- if (context._class->constant_expressions[i].identifier==p_identifier) {
+ if (context._class->constant_expressions[i].identifier == p_identifier) {
- ERR_FAIL_COND_V( context._class->constant_expressions[i].expression->type!=GDParser::Node::TYPE_CONSTANT, false );
- r_type=_get_type_from_variant(static_cast<const GDParser::ConstantNode*>(context._class->constant_expressions[i].expression)->value );
+ ERR_FAIL_COND_V(context._class->constant_expressions[i].expression->type != GDParser::Node::TYPE_CONSTANT, false);
+ r_type = _get_type_from_variant(static_cast<const GDParser::ConstantNode *>(context._class->constant_expressions[i].expression)->value);
return true;
}
}
if (!(context.function && context.function->_static)) {
- for(int i=0;i<context._class->variables.size();i++) {
+ for (int i = 0; i < context._class->variables.size(); i++) {
- if (context._class->variables[i].identifier==p_identifier) {
+ if (context._class->variables[i].identifier == p_identifier) {
- if (context._class->variables[i]._export.type!=Variant::NIL) {
+ if (context._class->variables[i]._export.type != Variant::NIL) {
- r_type=_get_type_from_pinfo(context._class->variables[i]._export);
+ r_type = _get_type_from_pinfo(context._class->variables[i]._export);
return true;
} else if (context._class->variables[i].expression) {
- bool rtype = _guess_expression_type(context,context._class->variables[i].expression,context._class->variables[i].line,r_type);
- if (rtype && r_type.type!=Variant::NIL)
+ bool rtype = _guess_expression_type(context, context._class->variables[i].expression, context._class->variables[i].line, r_type);
+ if (rtype && r_type.type != Variant::NIL)
return true;
//return _guess_expression_type(context,context._class->variables[i].expression,context._class->variables[i].line,r_type);
}
//try to guess from assignment in construtor or _ready
- if (_guess_identifier_from_assignment_in_function(context,p_line+1,p_identifier,"_ready",r_type))
+ if (_guess_identifier_from_assignment_in_function(context, p_line + 1, p_identifier, "_ready", r_type))
return true;
- if (_guess_identifier_from_assignment_in_function(context,p_line+1,p_identifier,"_enter_tree",r_type))
+ if (_guess_identifier_from_assignment_in_function(context, p_line + 1, p_identifier, "_enter_tree", r_type))
return true;
- if (_guess_identifier_from_assignment_in_function(context,p_line+1,p_identifier,"_init",r_type))
+ if (_guess_identifier_from_assignment_in_function(context, p_line + 1, p_identifier, "_init", r_type))
return true;
return false;
@@ -1165,115 +1087,107 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
List<PropertyInfo> props;
GlobalConfig::get_singleton()->get_property_list(&props);
- for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
- String name = s.get_slice("/",1);
- if (name==String(p_identifier)) {
+ String name = s.get_slice("/", 1);
+ if (name == String(p_identifier)) {
String path = GlobalConfig::get_singleton()->get(s);
if (path.begins_with("*")) {
- String script =path.substr(1,path.length());
+ String script = path.substr(1, path.length());
if (!script.ends_with(".gd")) {
//not a script, try find the script anyway,
//may have some success
- script=script.get_basename()+".gd";
+ script = script.get_basename() + ".gd";
}
if (FileAccess::exists(script)) {
//print_line("is a script");
-
Ref<Script> scr;
if (ScriptCodeCompletionCache::get_sigleton())
scr = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(script);
else
scr = ResourceLoader::load(script);
-
- r_type.obj_type="Node";
- r_type.type=Variant::OBJECT;
- r_type.script=scr;
- r_type.value=Variant();
+ r_type.obj_type = "Node";
+ r_type.type = Variant::OBJECT;
+ r_type.script = scr;
+ r_type.value = Variant();
return true;
-
}
}
}
-
}
//global
- for(Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
- if (E->key()==p_identifier) {
+ for (Map<StringName, int>::Element *E = GDScriptLanguage::get_singleton()->get_global_map().front(); E; E = E->next()) {
+ if (E->key() == p_identifier) {
- r_type=_get_type_from_variant(GDScriptLanguage::get_singleton()->get_global_array()[E->get()]);
+ r_type = _get_type_from_variant(GDScriptLanguage::get_singleton()->get_global_array()[E->get()]);
return true;
}
-
}
return false;
}
-
-static void _find_identifiers_in_block(GDCompletionContext& context,int p_line,bool p_only_functions,Set<String>& result) {
+static void _find_identifiers_in_block(GDCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) {
if (p_only_functions)
return;
- for (int i=0;i<context.block->statements.size();i++) {
+ for (int i = 0; i < context.block->statements.size(); i++) {
- if (context.block->statements[i]->line>p_line)
+ if (context.block->statements[i]->line > p_line)
continue;
+ if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) {
- if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
-
- const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
+ const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
result.insert(lv->name.operator String());
}
}
}
-static void _find_identifiers_in_class(GDCompletionContext& context,bool p_static,bool p_only_functions,Set<String>& result) {
+static void _find_identifiers_in_class(GDCompletionContext &context, bool p_static, bool p_only_functions, Set<String> &result) {
if (!p_static && !p_only_functions) {
- for(int i=0;i<context._class->variables.size();i++) {
+ for (int i = 0; i < context._class->variables.size(); i++) {
result.insert(context._class->variables[i].identifier);
}
}
if (!p_only_functions) {
- for(int i=0;i<context._class->constant_expressions.size();i++) {
+ for (int i = 0; i < context._class->constant_expressions.size(); i++) {
result.insert(context._class->constant_expressions[i].identifier);
}
- for(int i=0;i<context._class->subclasses.size();i++) {
+ for (int i = 0; i < context._class->subclasses.size(); i++) {
result.insert(context._class->subclasses[i]->name);
}
-
}
- for(int i=0;i<context._class->static_functions.size();i++) {
+ for (int i = 0; i < context._class->static_functions.size(); i++) {
if (context._class->static_functions[i]->arguments.size())
- result.insert(context._class->static_functions[i]->name.operator String()+"(");
+ result.insert(context._class->static_functions[i]->name.operator String() + "(");
else
- result.insert(context._class->static_functions[i]->name.operator String()+"()");
+ result.insert(context._class->static_functions[i]->name.operator String() + "()");
}
if (!p_static) {
- for(int i=0;i<context._class->functions.size();i++) {
+ for (int i = 0; i < context._class->functions.size(); i++) {
if (context._class->functions[i]->arguments.size())
- result.insert(context._class->functions[i]->name.operator String()+"(");
+ result.insert(context._class->functions[i]->name.operator String() + "(");
else
- result.insert(context._class->functions[i]->name.operator String()+"()");
+ result.insert(context._class->functions[i]->name.operator String() + "()");
}
}
@@ -1281,135 +1195,130 @@ static void _find_identifiers_in_class(GDCompletionContext& context,bool p_stati
Ref<Reference> base = _get_parent_class(context);
- while(true) {
+ while (true) {
Ref<GDScript> script = base;
Ref<GDNativeClass> nc = base;
if (script.is_valid()) {
if (!p_static && !p_only_functions) {
- for (const Set<StringName>::Element *E=script->get_members().front();E;E=E->next()) {
+ for (const Set<StringName>::Element *E = script->get_members().front(); E; E = E->next()) {
result.insert(E->get().operator String());
}
}
if (!p_only_functions) {
- for (const Map<StringName,Variant>::Element *E=script->get_constants().front();E;E=E->next()) {
+ for (const Map<StringName, Variant>::Element *E = script->get_constants().front(); E; E = E->next()) {
result.insert(E->key().operator String());
}
}
- for (const Map<StringName,GDFunction*>::Element *E=script->get_member_functions().front();E;E=E->next()) {
+ for (const Map<StringName, GDFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) {
if (!p_static || E->get()->is_static()) {
if (E->get()->get_argument_count())
- result.insert(E->key().operator String()+"(");
+ result.insert(E->key().operator String() + "(");
else
- result.insert(E->key().operator String()+"()");
+ result.insert(E->key().operator String() + "()");
}
}
- if (!p_only_functions) {
- for (const Map<StringName,Ref<GDScript> >::Element *E=script->get_subclasses().front();E;E=E->next()) {
+ if (!p_only_functions) {
+ for (const Map<StringName, Ref<GDScript> >::Element *E = script->get_subclasses().front(); E; E = E->next()) {
result.insert(E->key().operator String());
}
}
- base=script->get_base();
+ base = script->get_base();
if (base.is_null())
- base=script->get_native();
+ base = script->get_native();
} else if (nc.is_valid()) {
StringName type = nc->get_name();
if (!p_only_functions) {
-
List<String> constants;
- ClassDB::get_integer_constant_list(type,&constants);
- for(List<String>::Element *E=constants.front();E;E=E->next()) {
+ ClassDB::get_integer_constant_list(type, &constants);
+ for (List<String>::Element *E = constants.front(); E; E = E->next()) {
result.insert(E->get());
}
List<PropertyInfo> pinfo;
- ClassDB::get_property_list(type,&pinfo);
+ ClassDB::get_property_list(type, &pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- if (E->get().usage&(PROPERTY_USAGE_GROUP|PROPERTY_USAGE_CATEGORY))
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY))
continue;
- if (E->get().name.find("/")!=-1)
+ if (E->get().name.find("/") != -1)
continue;
result.insert(E->get().name);
}
-
}
List<MethodInfo> methods;
- ClassDB::get_method_list(type,&methods);
- for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ ClassDB::get_method_list(type, &methods);
+ for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().name.begins_with("_"))
continue;
if (E->get().arguments.size())
- result.insert(E->get().name+"(");
+ result.insert(E->get().name + "(");
else
- result.insert(E->get().name+"()");
+ result.insert(E->get().name + "()");
}
-
-
break;
} else
break;
-
}
-
}
-static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_only_functions,Set<String>& result) {
+static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) {
- const GDParser::BlockNode *block=context.block;
+ const GDParser::BlockNode *block = context.block;
if (context.function) {
- const GDParser::FunctionNode* f = context.function;
+ const GDParser::FunctionNode *f = context.function;
- for (int i=0;i<f->arguments.size();i++) {
+ for (int i = 0; i < f->arguments.size(); i++) {
result.insert(f->arguments[i].operator String());
}
}
- while(block) {
+ while (block) {
GDCompletionContext c = context;
- c.block=block;
+ c.block = block;
- _find_identifiers_in_block(c,p_line,p_only_functions,result);
- block=block->parent_block;
+ _find_identifiers_in_block(c, p_line, p_only_functions, result);
+ block = block->parent_block;
}
- const GDParser::ClassNode *clss=context._class;
+ const GDParser::ClassNode *clss = context._class;
- bool _static=context.function && context.function->_static;
+ bool _static = context.function && context.function->_static;
- while(clss) {
+ while (clss) {
GDCompletionContext c = context;
- c._class=clss;
- c.block=NULL;
- c.function=NULL;
- _find_identifiers_in_class(c,_static,p_only_functions,result);
- clss=clss->owner;
+ c._class = clss;
+ c.block = NULL;
+ c.function = NULL;
+ _find_identifiers_in_class(c, _static, p_only_functions, result);
+ clss = clss->owner;
}
- for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
+ for (int i = 0; i < GDFunctions::FUNC_MAX; i++) {
result.insert(GDFunctions::get_func_name(GDFunctions::Function(i)));
}
- 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"};
+ 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"
+ };
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
result.insert(_type_names[i]);
}
@@ -1417,37 +1326,34 @@ static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_onl
List<PropertyInfo> props;
GlobalConfig::get_singleton()->get_property_list(&props);
- for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
- String name = s.get_slice("/",1);
+ String name = s.get_slice("/", 1);
String path = GlobalConfig::get_singleton()->get(s);
if (path.begins_with("*")) {
result.insert(name);
}
-
}
-
- for(const Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
+ for (const Map<StringName, int>::Element *E = GDScriptLanguage::get_singleton()->get_global_map().front(); E; E = E->next()) {
result.insert(E->key().operator String());
}
}
-
-static String _get_visual_datatype(const PropertyInfo& p_info,bool p_isarg=true) {
+static String _get_visual_datatype(const PropertyInfo &p_info, bool p_isarg = true) {
String n = p_info.name;
int idx = n.find(":");
- if (idx!=-1) {
- return n.substr(idx+1,n.length());
+ if (idx != -1) {
+ return n.substr(idx + 1, n.length());
}
- if (p_info.type==Variant::OBJECT && p_info.hint==PROPERTY_HINT_RESOURCE_TYPE)
+ if (p_info.type == Variant::OBJECT && p_info.hint == PROPERTY_HINT_RESOURCE_TYPE)
return p_info.hint_string;
- if (p_info.type==Variant::NIL) {
+ if (p_info.type == Variant::NIL) {
if (p_isarg)
return "var";
else
@@ -1457,74 +1363,68 @@ static String _get_visual_datatype(const PropertyInfo& p_info,bool p_isarg=true)
return Variant::get_type_name(p_info.type);
}
-static void _make_function_hint(const GDParser::FunctionNode* p_func,int p_argidx,String& arghint) {
+static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argidx, String &arghint) {
- arghint="func "+p_func->name+"(";
- for (int i=0;i<p_func->arguments.size();i++) {
- if (i>0)
- arghint+=", ";
+ arghint = "func " + p_func->name + "(";
+ for (int i = 0; i < p_func->arguments.size(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
+ arghint += " ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+=p_func->arguments[i].operator String();
- int deffrom = p_func->arguments.size()-p_func->default_values.size();
+ arghint += p_func->arguments[i].operator String();
+ int deffrom = p_func->arguments.size() - p_func->default_values.size();
- if (i>=deffrom) {
- int defidx = deffrom-i;
+ if (i >= deffrom) {
+ int defidx = deffrom - i;
- if (defidx>=0 && defidx<p_func->default_values.size()) {
+ if (defidx >= 0 && defidx < p_func->default_values.size()) {
- if (p_func->default_values[defidx]->type==GDParser::Node::TYPE_OPERATOR) {
-
- const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(p_func->default_values[defidx]);
- if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
- const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(op->arguments[1]);
- arghint+="="+cn->value.get_construct_string();
+ if (p_func->default_values[defidx]->type == GDParser::Node::TYPE_OPERATOR) {
+ const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_func->default_values[defidx]);
+ if (op->op == GDParser::OperatorNode::OP_ASSIGN) {
+ const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(op->arguments[1]);
+ arghint += "=" + cn->value.get_construct_string();
}
} else {
-
}
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
}
- if (p_func->arguments.size()>0)
- arghint+=" ";
- arghint+=")";
+ if (p_func->arguments.size() > 0)
+ arghint += " ";
+ 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) {
-
+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) {
+ if (id.type == Variant::INPUT_EVENT && String(p_method) == "is_action" && p_argidx == 0) {
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
- String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
- result.insert("\""+name+"\"");
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
+ result.insert("\"" + name + "\"");
}
+ } else if (id.type == Variant::OBJECT && id.obj_type != StringName()) {
- } else if (id.type==Variant::OBJECT && id.obj_type!=StringName()) {
-
-
- MethodBind *m = ClassDB::get_method(id.obj_type,p_method);
+ MethodBind *m = ClassDB::get_method(id.obj_type, p_method);
if (!m) {
//not in static method, see script
@@ -1532,51 +1432,49 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No
Ref<GDScript> on_script;
if (id.value.get_type()) {
- Object *obj=id.value;
-
+ Object *obj = id.value;
if (obj) {
-
GDScript *scr = obj->cast_to<GDScript>();
if (scr) {
while (scr) {
- for (const Map<StringName,GDFunction*>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
- if (E->get()->is_static() && p_method==E->get()->get_name()) {
- arghint="static func "+String(p_method)+"(";
- for(int i=0;i<E->get()->get_argument_count();i++) {
- if (i>0)
- arghint+=", ";
+ for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) {
+ if (E->get()->is_static() && p_method == E->get()->get_name()) {
+ arghint = "static func " + String(p_method) + "(";
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+="var "+E->get()->get_argument_name(i);
- int deffrom = E->get()->get_argument_count()-E->get()->get_default_argument_count();
- if (i>=deffrom) {
- int defidx = deffrom-i;
- if (defidx>=0 && defidx<E->get()->get_default_argument_count()) {
- arghint+="="+E->get()->get_default_argument(defidx).get_construct_string();
+ arghint += "var " + E->get()->get_argument_name(i);
+ int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count();
+ if (i >= deffrom) {
+ int defidx = deffrom - i;
+ if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) {
+ arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string();
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
}
- arghint+=")";
+ arghint += ")";
return; //found
}
}
if (scr->get_base().is_valid())
- scr=scr->get_base().ptr();
+ scr = scr->get_base().ptr();
else
- scr=NULL;
+ scr = NULL;
}
} else {
- on_script=obj->get_script();
+ on_script = obj->get_script();
}
}
}
@@ -1584,7 +1482,7 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No
//print_line("but it has a script?");
if (!on_script.is_valid() && id.script.is_valid()) {
//print_line("yes");
- on_script=id.script;
+ on_script = id.script;
}
if (on_script.is_valid()) {
@@ -1596,110 +1494,108 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No
String code = scr->get_source_code();
//print_line("has source code!");
- if (code!="") {
+ 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);
+ Error err = p.parse(scr->get_source_code(), scr->get_path().get_base_dir(), true, "", false);
- if (err==OK) {
+ if (err == OK) {
//print_line("checking the functions...");
//only if ok, otherwise use what is cached on the script
//GDParser::ClassNode *base = p.
const GDParser::Node *root = p.get_parse_tree();
- ERR_FAIL_COND(root->type!=GDParser::Node::TYPE_CLASS);
+ ERR_FAIL_COND(root->type != GDParser::Node::TYPE_CLASS);
- const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
+ const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root);
- const GDParser::FunctionNode* func=NULL;
- bool st=false;
+ const GDParser::FunctionNode *func = NULL;
+ bool st = false;
- for(int i=0;i<cl->functions.size();i++) {
+ for (int i = 0; i < cl->functions.size(); i++) {
//print_line(String(cl->functions[i]->name)+" vs "+String(p_method));
- if (cl->functions[i]->name==p_method) {
- func=cl->functions[i];
+ if (cl->functions[i]->name == p_method) {
+ func = cl->functions[i];
}
}
- for(int i=0;i<cl->static_functions.size();i++) {
+ for (int i = 0; i < cl->static_functions.size(); i++) {
//print_line(String(cl->static_functions[i]->name)+" vs "+String(p_method));
- if (cl->static_functions[i]->name==p_method) {
- func=cl->static_functions[i];
- st=true;
+ if (cl->static_functions[i]->name == p_method) {
+ func = cl->static_functions[i];
+ st = true;
}
-
}
if (func) {
- arghint="func "+String(p_method)+"(";
+ arghint = "func " + String(p_method) + "(";
if (st)
- arghint="static "+arghint;
- for(int i=0;i<func->arguments.size();i++) {
- if (i>0)
- arghint+=", ";
+ arghint = "static " + arghint;
+ for (int i = 0; i < func->arguments.size(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+="var "+String(func->arguments[i]);
- int deffrom = func->arguments.size()-func->default_values.size();
- if (i>=deffrom) {
+ arghint += "var " + String(func->arguments[i]);
+ int deffrom = func->arguments.size() - func->default_values.size();
+ if (i >= deffrom) {
- int defidx = deffrom-i;
+ int defidx = deffrom - i;
- if (defidx>=0 && defidx<func->default_values.size() && func->default_values[defidx]->type==GDParser::Node::TYPE_OPERATOR) {
- const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(func->default_values[defidx]);
- if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
- const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(op->arguments[1]);
- arghint+="="+cn->value.get_construct_string();
+ if (defidx >= 0 && defidx < func->default_values.size() && func->default_values[defidx]->type == GDParser::Node::TYPE_OPERATOR) {
+ const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(func->default_values[defidx]);
+ if (op->op == GDParser::OperatorNode::OP_ASSIGN) {
+ const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(op->arguments[1]);
+ arghint += "=" + cn->value.get_construct_string();
}
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
}
- arghint+=" )";
+ arghint += " )";
return;
}
} else {
//print_line("failed parsing?");
- code="";
+ code = "";
}
-
}
- if (code=="") {
+ if (code == "") {
- for (const Map<StringName,GDFunction*>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
- if (p_method==E->get()->get_name()) {
- arghint="func "+String(p_method)+"(";
- for(int i=0;i<E->get()->get_argument_count();i++) {
- if (i>0)
- arghint+=", ";
+ for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) {
+ if (p_method == E->get()->get_name()) {
+ arghint = "func " + String(p_method) + "(";
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+="var "+E->get()->get_argument_name(i);
- int deffrom = E->get()->get_argument_count()-E->get()->get_default_argument_count();
- if (i>=deffrom) {
- int defidx = deffrom-i;
- if (defidx>=0 && defidx<E->get()->get_default_argument_count()) {
- arghint+="="+E->get()->get_default_argument(defidx).get_construct_string();
+ arghint += "var " + E->get()->get_argument_name(i);
+ int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count();
+ if (i >= deffrom) {
+ int defidx = deffrom - i;
+ if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) {
+ arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string();
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
}
- arghint+=")";
+ arghint += ")";
return; //found
}
}
@@ -1721,46 +1617,43 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No
}
if (scr->get_base().is_valid())
- scr=scr->get_base().ptr();
+ scr = scr->get_base().ptr();
else
- scr=NULL;
+ scr = NULL;
}
}
}
-
} else {
//regular method
- if (p_method.operator String()=="connect") {
-
+ if (p_method.operator String() == "connect") {
- if (p_argidx==0) {
+ if (p_argidx == 0) {
List<MethodInfo> sigs;
- ClassDB::get_signal_list(id.obj_type,&sigs);
+ ClassDB::get_signal_list(id.obj_type, &sigs);
if (id.script.is_valid()) {
id.script->get_script_signal_list(&sigs);
- } else if (id.value.get_type()==Variant::OBJECT) {
+ } else if (id.value.get_type() == Variant::OBJECT) {
Object *obj = id.value;
if (obj && !obj->get_script().is_null()) {
- Ref<Script> scr=obj->get_script();
+ Ref<Script> scr = obj->get_script();
if (scr.is_valid()) {
scr->get_script_signal_list(&sigs);
}
}
}
- for (List<MethodInfo>::Element *E=sigs.front();E;E=E->next()) {
- result.insert("\""+E->get().name+"\"");
+ for (List<MethodInfo>::Element *E = sigs.front(); E; E = E->next()) {
+ result.insert("\"" + E->get().name + "\"");
}
- } else if (p_argidx==2){
-
+ } else if (p_argidx == 2) {
if (context._class) {
- for(int i=0;i<context._class->functions.size();i++) {
- result.insert("\""+context._class->functions[i]->name+"\"");
+ for (int i = 0; i < context._class->functions.size(); i++) {
+ result.insert("\"" + context._class->functions[i]->name + "\"");
}
}
}
@@ -1773,173 +1666,163 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No
}*/
} else {
- if (p_argidx==0 && (String(p_method)=="get_node" || String(p_method)=="has_node") && ClassDB::is_parent_class(id.obj_type,"Node")) {
+ 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);
- for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
//print_line("found "+s);
- String name = s.get_slice("/",1);
- result.insert("\"/root/"+name+"\"");
+ String name = s.get_slice("/", 1);
+ result.insert("\"/root/" + name + "\"");
}
}
- Object *obj=id.value;
+ Object *obj = id.value;
if (obj) {
List<String> options;
- obj->get_argument_options(p_method,p_argidx,&options);
+ obj->get_argument_options(p_method, p_argidx, &options);
- for(List<String>::Element *E=options.front();E;E=E->next()) {
+ for (List<String>::Element *E = options.front(); E; E = E->next()) {
result.insert(E->get());
}
}
-
}
- arghint = _get_visual_datatype(m->get_argument_info(-1),false)+" "+p_method.operator String()+String("(");
+ arghint = _get_visual_datatype(m->get_argument_info(-1), false) + " " + p_method.operator String() + String("(");
- for(int i=0;i<m->get_argument_count();i++) {
- if (i>0)
- arghint+=", ";
+ for (int i = 0; i < m->get_argument_count(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
+ arghint += " ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
String n = m->get_argument_info(i).name;
int dp = n.find(":");
- if (dp!=-1)
- n=n.substr(0,dp);
- arghint+=_get_visual_datatype(m->get_argument_info(i))+" "+n;
- int deffrom = m->get_argument_count()-m->get_default_argument_count();
+ if (dp != -1)
+ n = n.substr(0, dp);
+ arghint += _get_visual_datatype(m->get_argument_info(i)) + " " + n;
+ int deffrom = m->get_argument_count() - m->get_default_argument_count();
+ if (i >= deffrom) {
+ int defidx = i - deffrom;
- if (i>=deffrom) {
- int defidx = i-deffrom;
-
- if (defidx>=0 && defidx<m->get_default_argument_count()) {
- Variant v= m->get_default_argument(i);
- arghint+="="+v.get_construct_string();
+ if (defidx >= 0 && defidx < m->get_default_argument_count()) {
+ Variant v = m->get_default_argument(i);
+ arghint += "=" + v.get_construct_string();
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
-
}
- if (m->get_argument_count()>0)
- arghint+=" ";
-
+ if (m->get_argument_count() > 0)
+ arghint += " ";
- arghint+=")";
+ arghint += ")";
}
-
}
}
+static void _find_call_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, int p_argidx, Set<String> &result, String &arghint) {
-static void _find_call_arguments(GDCompletionContext& context,const GDParser::Node* p_node, int p_line,int p_argidx, Set<String>& result, String& arghint) {
-
-
-
- if (!p_node || p_node->type!=GDParser::Node::TYPE_OPERATOR) {
+ if (!p_node || p_node->type != GDParser::Node::TYPE_OPERATOR) {
return;
}
const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node);
- if (op->op!=GDParser::OperatorNode::OP_CALL) {
+ if (op->op != GDParser::OperatorNode::OP_CALL) {
return;
}
- if (op->arguments[0]->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
+ if (op->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
//complete built-in function
- const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode*>(op->arguments[0]);
+ const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
MethodInfo mi = GDFunctions::get_info(fn->function);
- 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)
- arghint+=", ";
+ 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)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+=_get_visual_datatype(mi.arguments[i])+" "+mi.arguments[i].name;
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += _get_visual_datatype(mi.arguments[i]) + " " + mi.arguments[i].name;
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
-
}
- if (mi.arguments.size()>0)
- arghint+=" ";
- arghint+=")";
+ if (mi.arguments.size() > 0)
+ arghint += " ";
+ arghint += ")";
- } else if (op->arguments[0]->type==GDParser::Node::TYPE_TYPE) {
+ } else if (op->arguments[0]->type == GDParser::Node::TYPE_TYPE) {
//complete constructor
- const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode*>(op->arguments[0]);
+ const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode *>(op->arguments[0]);
List<MethodInfo> mil;
- Variant::get_constructor_list(tn->vtype,&mil);
+ Variant::get_constructor_list(tn->vtype, &mil);
- for(List<MethodInfo>::Element *E=mil.front();E;E=E->next()) {
+ for (List<MethodInfo>::Element *E = mil.front(); E; E = E->next()) {
MethodInfo mi = E->get();
- if (mi.arguments.size()==0)
+ if (mi.arguments.size() == 0)
continue;
if (E->prev())
- arghint+="\n";
- arghint += Variant::get_type_name(tn->vtype)+" "+Variant::get_type_name(tn->vtype)+String("(");
- for(int i=0;i<mi.arguments.size();i++) {
- if (i>0)
- arghint+=", ";
+ arghint += "\n";
+ arghint += Variant::get_type_name(tn->vtype) + " " + Variant::get_type_name(tn->vtype) + String("(");
+ for (int i = 0; i < mi.arguments.size(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+=_get_visual_datatype(mi.arguments[i])+" "+mi.arguments[i].name;
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += _get_visual_datatype(mi.arguments[i]) + " " + mi.arguments[i].name;
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
-
}
- if (mi.arguments.size()>0)
- arghint+=" ";
- arghint+=")";
+ if (mi.arguments.size() > 0)
+ arghint += " ";
+ arghint += ")";
}
- } else if (op->arguments.size()>=2 && op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ } else if (op->arguments.size() >= 2 && op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) {
//make sure identifier exists...
- const GDParser::IdentifierNode *id=static_cast<const GDParser::IdentifierNode *>(op->arguments[1]);
+ const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1]);
- if (op->arguments[0]->type==GDParser::Node::TYPE_SELF) {
+ if (op->arguments[0]->type == GDParser::Node::TYPE_SELF) {
//self, look up
- for(int i=0;i<context._class->static_functions.size();i++) {
- if (context._class->static_functions[i]->name==id->name) {
- _make_function_hint(context._class->static_functions[i],p_argidx,arghint);
+ for (int i = 0; i < context._class->static_functions.size(); i++) {
+ if (context._class->static_functions[i]->name == id->name) {
+ _make_function_hint(context._class->static_functions[i], p_argidx, arghint);
return;
}
}
if (context.function && !context.function->_static) {
- for(int i=0;i<context._class->functions.size();i++) {
- if (context._class->functions[i]->name==id->name) {
- _make_function_hint(context._class->functions[i],p_argidx,arghint);
+ for (int i = 0; i < context._class->functions.size(); i++) {
+ if (context._class->functions[i]->name == id->name) {
+ _make_function_hint(context._class->functions[i], p_argidx, arghint);
return;
}
}
@@ -1947,64 +1830,61 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No
Ref<Reference> base = _get_parent_class(context);
- while(true) {
+ while (true) {
Ref<GDScript> script = base;
Ref<GDNativeClass> nc = base;
if (script.is_valid()) {
+ for (const Map<StringName, GDFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) {
- for (const Map<StringName,GDFunction*>::Element *E=script->get_member_functions().front();E;E=E->next()) {
-
- if (E->key()==id->name) {
+ if (E->key() == id->name) {
if (context.function && context.function->_static && !E->get()->is_static())
continue;
-
- arghint = "func "+id->name.operator String()+String("(");
- for(int i=0;i<E->get()->get_argument_count();i++) {
- if (i>0)
- arghint+=", ";
+ arghint = "func " + id->name.operator String() + String("(");
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
+ if (i > 0)
+ arghint += ", ";
else
- arghint+=" ";
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ arghint += " ";
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
- arghint+=E->get()->get_argument_name(i);
- int deffrom = E->get()->get_argument_count()-E->get()->get_default_argument_count();
- if (i>=deffrom) {
- int defidx = deffrom-i;
- if (defidx>=0 && defidx<E->get()->get_default_argument_count()) {
- arghint+="="+E->get()->get_default_argument(defidx).get_construct_string();
+ arghint += E->get()->get_argument_name(i);
+ int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count();
+ if (i >= deffrom) {
+ int defidx = deffrom - i;
+ if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) {
+ arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string();
}
}
- if (i==p_argidx) {
- arghint+=String::chr(0xFFFF);
+ if (i == p_argidx) {
+ arghint += String::chr(0xFFFF);
}
-
}
- if (E->get()->get_argument_count()>0)
- arghint+=" ";
- arghint+=")";
+ if (E->get()->get_argument_count() > 0)
+ arghint += " ";
+ arghint += ")";
return;
}
}
- base=script->get_base();
+ base = script->get_base();
if (base.is_null())
- base=script->get_native();
+ base = script->get_native();
} else if (nc.is_valid()) {
if (context.function && !context.function->_static) {
GDCompletionIdentifier ci;
- ci.type=Variant::OBJECT;
- ci.obj_type=nc->get_name();
+ ci.type = Variant::OBJECT;
+ ci.obj_type = nc->get_name();
if (!context._class->owner)
- ci.value=context.base;
+ ci.value = context.base;
- _find_type_arguments(context,p_node,p_line,id->name,ci,p_argidx,result,arghint);
+ _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, arghint);
//guess type..
/*
List<MethodInfo> methods;
@@ -2019,20 +1899,17 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No
break;
} else
break;
-
}
} else {
//indexed lookup
GDCompletionIdentifier ci;
- if (_guess_expression_type(context,op->arguments[0],p_line,ci)) {
+ if (_guess_expression_type(context, op->arguments[0], p_line, ci)) {
- _find_type_arguments(context,p_node,p_line,id->name,ci,p_argidx,result,arghint);
+ _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, arghint);
return;
}
-
}
-
}
#if 0
bool _static=context.function->_static;
@@ -2127,42 +2004,40 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No
}
#endif
-
}
-Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) {
+Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) {
GDParser p;
- p.parse(p_code,p_base_path,false,"",true);
- bool isfunction=false;
+ p.parse(p_code, p_base_path, false, "", true);
+ bool isfunction = false;
Set<String> options;
GDCompletionContext context;
- context._class=p.get_completion_class();
- context.block=p.get_completion_block();
- context.function=p.get_completion_function();
- context.base=p_owner;
- context.base_path=p_base_path;
+ context._class = p.get_completion_class();
+ context.block = p.get_completion_block();
+ context.function = p.get_completion_function();
+ context.base = p_owner;
+ context.base_path = p_base_path;
- switch(p.get_completion_type()) {
+ switch (p.get_completion_type()) {
case GDParser::COMPLETION_NONE: {
} break;
case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: {
List<StringName> constants;
- Variant::get_numeric_constants_for_type(p.get_completion_built_in_constant(),&constants);
- for(List<StringName>::Element *E=constants.front();E;E=E->next()) {
+ Variant::get_numeric_constants_for_type(p.get_completion_built_in_constant(), &constants);
+ for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
options.insert(E->get().operator String());
}
-
} break;
case GDParser::COMPLETION_FUNCTION:
- isfunction=true;
+ isfunction = true;
case GDParser::COMPLETION_IDENTIFIER: {
- _find_identifiers(context,p.get_completion_line(),isfunction,options);
+ _find_identifiers(context, p.get_completion_line(), isfunction, options);
} break;
case GDParser::COMPLETION_PARENT_FUNCTION: {
@@ -2171,98 +2046,91 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
if (p_owner) {
List<String> opts;
- p_owner->get_argument_options("get_node",0,&opts);
+ p_owner->get_argument_options("get_node", 0, &opts);
- for (List<String>::Element *E=opts.front();E;E=E->next()) {
+ for (List<String>::Element *E = opts.front(); E; E = E->next()) {
String opt = E->get().strip_edges();
if (opt.begins_with("\"") && opt.ends_with("\"")) {
- String idopt=opt.substr(1,opt.length()-2);
- if (idopt.replace("/","_").is_valid_identifier()) {
+ String idopt = opt.substr(1, opt.length() - 2);
+ if (idopt.replace("/", "_").is_valid_identifier()) {
options.insert(idopt);
} else {
options.insert(opt);
}
}
}
-
}
} break;
case GDParser::COMPLETION_METHOD:
- isfunction=true;
+ isfunction = true;
case GDParser::COMPLETION_INDEX: {
const GDParser::Node *node = p.get_completion_node();
- if (node->type!=GDParser::Node::TYPE_OPERATOR)
+ if (node->type != GDParser::Node::TYPE_OPERATOR)
break;
-
-
-
GDCompletionIdentifier t;
- if (_guess_expression_type(context,static_cast<const GDParser::OperatorNode *>(node)->arguments[0],p.get_completion_line(),t)) {
+ if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t)) {
- if (t.type==Variant::OBJECT && t.obj_type=="GDNativeClass") {
+ if (t.type == Variant::OBJECT && t.obj_type == "GDNativeClass") {
//native enum
Ref<GDNativeClass> gdn = t.value;
if (gdn.is_valid()) {
StringName cn = gdn->get_name();
List<String> cnames;
- ClassDB::get_integer_constant_list(cn,&cnames);
- for (List<String>::Element *E=cnames.front();E;E=E->next()) {
+ ClassDB::get_integer_constant_list(cn, &cnames);
+ for (List<String>::Element *E = cnames.front(); E; E = E->next()) {
options.insert(E->get());
}
List<PropertyInfo> pinfo;
- ClassDB::get_property_list(cn,&pinfo);
+ ClassDB::get_property_list(cn, &pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- if (E->get().usage&(PROPERTY_USAGE_GROUP|PROPERTY_USAGE_CATEGORY))
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY))
continue;
- if (E->get().name.find("/")!=-1)
+ if (E->get().name.find("/") != -1)
continue;
options.insert(E->get().name);
}
}
- } else if (t.type==Variant::OBJECT && t.obj_type!=StringName()) {
+ } else if (t.type == Variant::OBJECT && t.obj_type != StringName()) {
Ref<GDScript> on_script;
if (t.value.get_type()) {
- Object *obj=t.value;
-
+ Object *obj = t.value;
if (obj) {
-
GDScript *scr = obj->cast_to<GDScript>();
if (scr) {
while (scr) {
if (!isfunction) {
- for (const Map<StringName,Variant>::Element *E=scr->get_constants().front();E;E=E->next()) {
+ for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) {
options.insert(E->key());
}
}
- for (const Map<StringName,GDFunction*>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
+ for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) {
if (E->get()->is_static())
options.insert(E->key());
}
if (scr->get_base().is_valid())
- scr=scr->get_base().ptr();
+ scr = scr->get_base().ptr();
else
- scr=NULL;
+ scr = NULL;
}
} else {
- on_script=obj->get_script();
+ on_script = obj->get_script();
}
}
}
-
if (!on_script.is_valid() && t.script.is_valid()) {
- on_script=t.script;
+ on_script = t.script;
}
if (on_script.is_valid()) {
@@ -2273,132 +2141,119 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
String code = scr->get_source_code();
- if (code!="") {
+ if (code != "") {
//if there is code, parse it. This way is slower but updates in real-time
GDParser p;
- Error err = p.parse(scr->get_source_code(),scr->get_path().get_base_dir(),true,"",false);
+ Error err = p.parse(scr->get_source_code(), scr->get_path().get_base_dir(), true, "", false);
- if (err==OK) {
+ if (err == OK) {
//only if ok, otherwise use what is cached on the script
//GDParser::ClassNode *base = p.
const GDParser::Node *root = p.get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,ERR_PARSE_ERROR);
+ ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, ERR_PARSE_ERROR);
- const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
+ const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root);
- for(int i=0;i<cl->functions.size();i++) {
+ for (int i = 0; i < cl->functions.size(); i++) {
if (cl->functions[i]->arguments.size())
- options.insert(String(cl->functions[i]->name)+"(");
+ options.insert(String(cl->functions[i]->name) + "(");
else
- options.insert(String(cl->functions[i]->name)+"()");
+ options.insert(String(cl->functions[i]->name) + "()");
}
- for(int i=0;i<cl->static_functions.size();i++) {
+ for (int i = 0; i < cl->static_functions.size(); i++) {
if (cl->static_functions[i]->arguments.size())
- options.insert(String(cl->static_functions[i]->name)+"(");
+ options.insert(String(cl->static_functions[i]->name) + "(");
else
- options.insert(String(cl->static_functions[i]->name)+"()");
-
+ options.insert(String(cl->static_functions[i]->name) + "()");
}
if (!isfunction) {
- for(int i=0;i<cl->variables.size();i++) {
+ for (int i = 0; i < cl->variables.size(); i++) {
options.insert(String(cl->variables[i].identifier));
}
- for(int i=0;i<cl->constant_expressions.size();i++) {
+ for (int i = 0; i < cl->constant_expressions.size(); i++) {
options.insert(String(cl->constant_expressions[i].identifier));
}
-
}
-
} else {
- code=""; //well, then no code
+ code = ""; //well, then no code
}
-
}
- if (code=="") {
+ if (code == "") {
//use class directly, no code was found
if (!isfunction) {
- for (const Map<StringName,Variant>::Element *E=scr->get_constants().front();E;E=E->next()) {
+ for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) {
options.insert(E->key());
}
}
- for (const Map<StringName,GDFunction*>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
+ for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) {
if (E->get()->get_argument_count())
- options.insert(String(E->key())+"()");
+ options.insert(String(E->key()) + "()");
else
- options.insert(String(E->key())+"(");
-
+ options.insert(String(E->key()) + "(");
}
- for (const Set<StringName>::Element *E=scr->get_members().front();E;E=E->next()) {
+ for (const Set<StringName>::Element *E = scr->get_members().front(); E; E = E->next()) {
options.insert(E->get());
}
}
if (scr->get_base().is_valid())
- scr=scr->get_base().ptr();
+ scr = scr->get_base().ptr();
else
- scr=NULL;
+ scr = NULL;
}
}
}
-
-
-
-
-
if (!isfunction) {
- ClassDB::get_integer_constant_list(t.obj_type,r_options);
+ ClassDB::get_integer_constant_list(t.obj_type, r_options);
List<PropertyInfo> pinfo;
- ClassDB::get_property_list(t.obj_type,&pinfo);
+ ClassDB::get_property_list(t.obj_type, &pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- if (E->get().usage&(PROPERTY_USAGE_GROUP|PROPERTY_USAGE_CATEGORY))
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY))
continue;
- if (E->get().name.find("/")!=-1)
+ if (E->get().name.find("/") != -1)
continue;
r_options->push_back(E->get().name);
}
}
-
List<MethodInfo> mi;
- ClassDB::get_method_list(t.obj_type,&mi);
- for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+ ClassDB::get_method_list(t.obj_type, &mi);
+ for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) {
if (E->get().name.begins_with("_"))
continue;
if (E->get().arguments.size())
- options.insert(E->get().name+"(");
+ options.insert(E->get().name + "(");
else
- options.insert(E->get().name+"()");
-
+ options.insert(E->get().name + "()");
}
} else {
-
- if (t.type==Variant::INPUT_EVENT) {
+ 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++) {
+ for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
InputEvent ie;
- ie.type=InputEvent::Type(i);
- static const char*evnames[]={
+ ie.type = InputEvent::Type(i);
+ static const char *evnames[] = {
"# Common",
"# Key",
"# MouseMotion",
@@ -2414,22 +2269,20 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
Variant v = ie;
- if (i==0) {
+ 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+"(");
-
+ 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()) {
+ for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
- if (i==0)
+ if (i == 0)
exclude.insert(E->get().name);
else if (exclude.has(E->get().name))
continue;
@@ -2439,67 +2292,64 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
}
return OK;
} else {
- if (t.value.get_type()==Variant::NIL) {
+ if (t.value.get_type() == Variant::NIL) {
Variant::CallError ce;
- t.value=Variant::construct(t.type,NULL,0,ce);
+ t.value = Variant::construct(t.type, NULL, 0, ce);
}
-
if (!isfunction) {
List<PropertyInfo> pl;
t.value.get_property_list(&pl);
- for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) {
- if (E->get().name.find("/")==-1)
+ if (E->get().name.find("/") == -1)
options.insert(E->get().name);
}
}
List<MethodInfo> mi;
t.value.get_method_list(&mi);
- for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+ for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) {
if (E->get().arguments.size())
- options.insert(E->get().name+"(");
+ options.insert(E->get().name + "(");
else
- options.insert(E->get().name+"()");
-
+ options.insert(E->get().name + "()");
}
}
}
}
-
} break;
case GDParser::COMPLETION_CALL_ARGUMENTS: {
- _find_call_arguments(context,p.get_completion_node(),p.get_completion_line(),p.get_completion_argument_index(),options,r_call_hint);
+ _find_call_arguments(context, p.get_completion_node(), p.get_completion_line(), p.get_completion_argument_index(), options, r_call_hint);
} break;
case GDParser::COMPLETION_VIRTUAL_FUNC: {
GDCompletionIdentifier cid = _get_native_class(context);
- if (cid.obj_type!=StringName()) {
+ if (cid.obj_type != StringName()) {
List<MethodInfo> vm;
- ClassDB::get_virtual_methods(cid.obj_type,&vm);
- for(List<MethodInfo>::Element *E=vm.front();E;E=E->next()) {
+ ClassDB::get_virtual_methods(cid.obj_type, &vm);
+ for (List<MethodInfo>::Element *E = vm.front(); E; E = E->next()) {
- MethodInfo &mi=E->get();
+ MethodInfo &mi = E->get();
String m = mi.name;
- if (m.find(":")!=-1)
- m=m.substr(0,m.find(":"));
- m+="(";
+ if (m.find(":") != -1)
+ m = m.substr(0, m.find(":"));
+ m += "(";
if (mi.arguments.size()) {
- for(int i=0;i<mi.arguments.size();i++) {
- if (i>0)
- m+=", ";
- String n =mi.arguments[i].name;
- if (n.find(":")!=-1)
- n=n.substr(0,n.find(":"));
- m+=n;
+ for (int i = 0; i < mi.arguments.size(); i++) {
+ if (i > 0)
+ m += ", ";
+ String n = mi.arguments[i].name;
+ if (n.find(":") != -1)
+ n = n.substr(0, n.find(":"));
+ m += n;
}
}
- m+="):";
+ m += "):";
options.insert(m);
}
@@ -2510,24 +2360,22 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
const GDParser::Node *node = p.get_completion_node();
GDCompletionIdentifier t;
- if (!_guess_expression_type(context,node,p.get_completion_line(),t))
+ if (!_guess_expression_type(context, node, p.get_completion_line(), t))
break;
- if (t.type==Variant::OBJECT && t.obj_type!=StringName()) {
+ if (t.type == Variant::OBJECT && t.obj_type != StringName()) {
List<MethodInfo> sigs;
- ClassDB::get_signal_list(t.obj_type,&sigs);
- for (List<MethodInfo>::Element *E=sigs.front();E;E=E->next()) {
- options.insert("\""+E->get().name+"\"");
+ ClassDB::get_signal_list(t.obj_type, &sigs);
+ for (List<MethodInfo>::Element *E = sigs.front(); E; E = E->next()) {
+ options.insert("\"" + E->get().name + "\"");
}
}
} break;
-
}
-
- for(Set<String>::Element *E=options.front();E;E=E->next()) {
+ for (Set<String>::Element *E = options.front(); E; E = E->next()) {
r_options->push_back(E->get());
}
@@ -2536,25 +2384,23 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
#else
-Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) {
+Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) {
return OK;
}
#endif
-
-void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const {
-
+void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {
Vector<String> lines = p_code.split("\n");
List<int> indent_stack;
- for(int i=0;i<lines.size();i++) {
+ for (int i = 0; i < lines.size(); i++) {
String l = lines[i];
- int tc=0;
- for(int j=0;j<l.length();j++) {
- if (l[j]==' ' || l[j]=='\t') {
+ int tc = 0;
+ for (int j = 0; j < l.length(); j++) {
+ if (l[j] == ' ' || l[j] == '\t') {
tc++;
} else {
@@ -2562,252 +2408,237 @@ void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_
}
}
-
- String st = l.substr(tc,l.length()).strip_edges();
- if (st=="" || st.begins_with("#"))
+ String st = l.substr(tc, l.length()).strip_edges();
+ if (st == "" || st.begins_with("#"))
continue; //ignore!
- int ilevel=0;
+ int ilevel = 0;
if (indent_stack.size()) {
- ilevel=indent_stack.back()->get();
+ ilevel = indent_stack.back()->get();
}
- if (tc>ilevel) {
+ if (tc > ilevel) {
indent_stack.push_back(tc);
- } else if (tc<ilevel) {
- while(indent_stack.size() && indent_stack.back()->get()>tc) {
+ } else if (tc < ilevel) {
+ while (indent_stack.size() && indent_stack.back()->get() > tc) {
indent_stack.pop_back();
}
- if (indent_stack.size() && indent_stack.back()->get()!=tc)
+ if (indent_stack.size() && indent_stack.back()->get() != tc)
indent_stack.push_back(tc); //this is not right but gets the job done
}
- if (i>=p_from_line) {
+ if (i >= p_from_line) {
- l="";
- for(int j=0;j<indent_stack.size();j++)
- l+="\t";
- l+=st;
+ l = "";
+ for (int j = 0; j < indent_stack.size(); j++)
+ l += "\t";
+ l += st;
-
- } else if (i>p_to_line) {
+ } else if (i > p_to_line) {
break;
}
//print_line(itos(indent_stack.size())+","+itos(tc)+": "+l);
- lines[i]=l;
+ lines[i] = l;
}
- p_code="";
- for(int i=0;i<lines.size();i++) {
- if (i>0)
- p_code+="\n";
- p_code+=lines[i];
+ p_code = "";
+ for (int i = 0; i < lines.size(); i++) {
+ if (i > 0)
+ p_code += "\n";
+ p_code += lines[i];
}
-
}
#ifdef TOOLS_ENABLED
-Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol,const String& p_base_path, Object*p_owner,LookupResult& r_result) {
-
+Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) {
//before parsing, try the usual stuff
if (ClassDB::class_exists(p_symbol)) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS;
- r_result.class_name=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
+ r_result.class_name = p_symbol;
return OK;
}
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
Variant::Type t = Variant::Type(i);
- if (Variant::get_type_name(t)==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS;
- r_result.class_name=Variant::get_type_name(t);
+ if (Variant::get_type_name(t) == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
+ r_result.class_name = Variant::get_type_name(t);
return OK;
}
}
- for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
- if (GDFunctions::get_func_name(GDFunctions::Function(i))==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name="@GDScript";
- r_result.class_member=p_symbol;
+ for (int i = 0; i < GDFunctions::FUNC_MAX; i++) {
+ if (GDFunctions::get_func_name(GDFunctions::Function(i)) == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = "@GDScript";
+ r_result.class_member = p_symbol;
return OK;
}
}
GDParser p;
- p.parse(p_code,p_base_path,false,"",true);
+ p.parse(p_code, p_base_path, false, "", true);
- if (p.get_completion_type()==GDParser::COMPLETION_NONE)
+ if (p.get_completion_type() == GDParser::COMPLETION_NONE)
return ERR_CANT_RESOLVE;
GDCompletionContext context;
- context._class=p.get_completion_class();
- context.block=p.get_completion_block();
- context.function=p.get_completion_function();
- context.base=p_owner;
- context.base_path=p_base_path;
- bool isfunction=false;
+ context._class = p.get_completion_class();
+ context.block = p.get_completion_block();
+ context.function = p.get_completion_function();
+ context.base = p_owner;
+ context.base_path = p_base_path;
+ bool isfunction = false;
- switch(p.get_completion_type()) {
+ switch (p.get_completion_type()) {
case GDParser::COMPLETION_GET_NODE:
case GDParser::COMPLETION_NONE: {
} break;
case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
- r_result.class_name=Variant::get_type_name(p.get_completion_built_in_constant());
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
+ r_result.class_name = Variant::get_type_name(p.get_completion_built_in_constant());
+ r_result.class_member = p_symbol;
return OK;
} break;
case GDParser::COMPLETION_FUNCTION: {
-
if (context._class && context._class->functions.size()) {
- for(int i=0;i<context._class->functions.size();i++) {
- if (context._class->functions[i]->name==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=context._class->functions[i]->line;
+ for (int i = 0; i < context._class->functions.size(); i++) {
+ if (context._class->functions[i]->name == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = context._class->functions[i]->line;
return OK;
}
}
}
Ref<GDScript> parent = _get_parent_class(context);
- while(parent.is_valid()) {
+ while (parent.is_valid()) {
int line = parent->get_member_line(p_symbol);
- if (line>=0) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=line;
- r_result.script=parent;
+ if (line >= 0) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = line;
+ r_result.script = parent;
return OK;
-
}
- parent=parent->get_base();
+ parent = parent->get_base();
}
GDCompletionIdentifier identifier = _get_native_class(context);
- print_line("identifier: "+String(identifier.obj_type));
+ print_line("identifier: " + String(identifier.obj_type));
- if (ClassDB::has_method(identifier.obj_type,p_symbol)) {
+ if (ClassDB::has_method(identifier.obj_type, p_symbol)) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name=identifier.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = identifier.obj_type;
+ r_result.class_member = p_symbol;
return OK;
}
-
} break;
case GDParser::COMPLETION_IDENTIFIER: {
//check if a function
if (p.get_completion_identifier_is_function()) {
if (context._class && context._class->functions.size()) {
- for(int i=0;i<context._class->functions.size();i++) {
- if (context._class->functions[i]->name==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=context._class->functions[i]->line;
+ for (int i = 0; i < context._class->functions.size(); i++) {
+ if (context._class->functions[i]->name == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = context._class->functions[i]->line;
return OK;
}
}
}
Ref<GDScript> parent = _get_parent_class(context);
- while(parent.is_valid()) {
+ while (parent.is_valid()) {
int line = parent->get_member_line(p_symbol);
- if (line>=0) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=line;
- r_result.script=parent;
+ if (line >= 0) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = line;
+ r_result.script = parent;
return OK;
-
}
- parent=parent->get_base();
+ parent = parent->get_base();
}
GDCompletionIdentifier identifier = _get_native_class(context);
+ if (ClassDB::has_method(identifier.obj_type, p_symbol)) {
- if (ClassDB::has_method(identifier.obj_type,p_symbol)) {
-
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name=identifier.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = identifier.obj_type;
+ r_result.class_member = p_symbol;
return OK;
}
} else {
-
GDCompletionIdentifier gdi = _get_native_class(context);
- if (gdi.obj_type!=StringName()) {
+ if (gdi.obj_type != StringName()) {
bool valid;
- Variant::Type t = ClassDB::get_property_type(gdi.obj_type,p_symbol,&valid);
- if (t!=Variant::NIL && valid) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
- r_result.class_name=gdi.obj_type;
- r_result.class_member=p_symbol;
+ Variant::Type t = ClassDB::get_property_type(gdi.obj_type, p_symbol, &valid);
+ if (t != Variant::NIL && valid) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
+ r_result.class_name = gdi.obj_type;
+ r_result.class_member = p_symbol;
return OK;
-
}
}
- const GDParser::BlockNode *block=context.block;
+ const GDParser::BlockNode *block = context.block;
//search in blocks going up (local var?)
- while(block) {
-
+ while (block) {
+ for (int i = 0; i < block->statements.size(); i++) {
- for (int i=0;i<block->statements.size();i++) {
-
- if (block->statements[i]->line>p.get_completion_line())
+ if (block->statements[i]->line > p.get_completion_line())
continue;
+ if (block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) {
- if (block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
-
- const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(block->statements[i]);
+ const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(block->statements[i]);
- if (lv->assign && lv->name==p_symbol) {
+ if (lv->assign && lv->name == p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=block->statements[i]->line;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = block->statements[i]->line;
return OK;
}
}
}
- block=block->parent_block;
+ block = block->parent_block;
}
//guess from function arguments
- if (context.function && context.function->name!=StringName()) {
+ if (context.function && context.function->name != StringName()) {
- for(int i=0;i<context.function->arguments.size();i++) {
+ for (int i = 0; i < context.function->arguments.size(); i++) {
- if (context.function->arguments[i]==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=context.function->line;
+ if (context.function->arguments[i] == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = context.function->line;
return OK;
}
-
}
}
//guess in class constants
- for(int i=0;i<context._class->constant_expressions.size();i++) {
+ for (int i = 0; i < context._class->constant_expressions.size(); i++) {
- if (context._class->constant_expressions[i].identifier==p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=context._class->constant_expressions[i].expression->line;
+ if (context._class->constant_expressions[i].identifier == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = context._class->constant_expressions[i].expression->line;
return OK;
}
}
@@ -2815,12 +2646,12 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
//guess in class variables
if (!(context.function && context.function->_static)) {
- for(int i=0;i<context._class->variables.size();i++) {
+ for (int i = 0; i < context._class->variables.size(); i++) {
- if (context._class->variables[i].identifier==p_symbol) {
+ if (context._class->variables[i].identifier == p_symbol) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=context._class->variables[i].line;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = context._class->variables[i].line;
return OK;
}
}
@@ -2830,29 +2661,29 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
List<PropertyInfo> props;
GlobalConfig::get_singleton()->get_property_list(&props);
- for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
if (!s.begins_with("autoload/"))
continue;
- String name = s.get_slice("/",1);
- if (name==String(p_symbol)) {
+ String name = s.get_slice("/", 1);
+ if (name == String(p_symbol)) {
String path = GlobalConfig::get_singleton()->get(s);
if (path.begins_with("*")) {
- String script =path.substr(1,path.length());
+ String script = path.substr(1, path.length());
if (!script.ends_with(".gd")) {
//not a script, try find the script anyway,
//may have some success
- script=script.get_basename()+".gd";
+ script = script.get_basename() + ".gd";
}
if (FileAccess::exists(script)) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=0;
- r_result.script=ResourceLoader::load(script);
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = 0;
+ r_result.script = ResourceLoader::load(script);
return OK;
}
}
@@ -2860,33 +2691,32 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
}
//global
- for(Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
- if (E->key()==p_symbol) {
+ for (Map<StringName, int>::Element *E = GDScriptLanguage::get_singleton()->get_global_map().front(); E; E = E->next()) {
+ if (E->key() == p_symbol) {
Variant value = GDScriptLanguage::get_singleton()->get_global_array()[E->get()];
- if (value.get_type()==Variant::OBJECT) {
+ if (value.get_type() == Variant::OBJECT) {
Object *obj = value;
if (obj) {
if (obj->cast_to<GDNativeClass>()) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS;
- r_result.class_name=obj->cast_to<GDNativeClass>()->get_name();
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
+ r_result.class_name = obj->cast_to<GDNativeClass>()->get_name();
} else {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS;
- r_result.class_name=obj->get_class();
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
+ r_result.class_name = obj->get_class();
}
return OK;
}
} else {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
- r_result.class_name="@Global Scope";
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
+ r_result.class_name = "@Global Scope";
+ r_result.class_member = p_symbol;
return OK;
}
}
-
}
#if 0
GDCompletionIdentifier identifier;
@@ -2907,122 +2737,109 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
} break;
case GDParser::COMPLETION_METHOD:
- isfunction=true;
+ isfunction = true;
case GDParser::COMPLETION_INDEX: {
const GDParser::Node *node = p.get_completion_node();
- if (node->type!=GDParser::Node::TYPE_OPERATOR)
+ if (node->type != GDParser::Node::TYPE_OPERATOR)
break;
-
-
-
GDCompletionIdentifier t;
- if (_guess_expression_type(context,static_cast<const GDParser::OperatorNode *>(node)->arguments[0],p.get_completion_line(),t)) {
+ if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t)) {
- if (t.type==Variant::OBJECT && t.obj_type=="GDNativeClass") {
+ if (t.type == Variant::OBJECT && t.obj_type == "GDNativeClass") {
//native enum
Ref<GDNativeClass> gdn = t.value;
if (gdn.is_valid()) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
- r_result.class_name=gdn->get_name();
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
+ r_result.class_name = gdn->get_name();
+ r_result.class_member = p_symbol;
return OK;
-
}
- } else if (t.type==Variant::OBJECT && t.obj_type!=StringName()) {
+ } else if (t.type == Variant::OBJECT && t.obj_type != StringName()) {
Ref<GDScript> on_script;
if (t.value.get_type()) {
- Object *obj=t.value;
-
+ Object *obj = t.value;
if (obj) {
-
- on_script=obj->get_script();
+ on_script = obj->get_script();
if (on_script.is_valid()) {
int loc = on_script->get_member_line(p_symbol);
- if (loc>=0) {
- r_result.script=on_script;
- r_result.type=ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
- r_result.location=loc;
+ if (loc >= 0) {
+ r_result.script = on_script;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = loc;
return OK;
}
}
}
}
- if (ClassDB::has_method(t.obj_type,p_symbol)) {
+ if (ClassDB::has_method(t.obj_type, p_symbol)) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name=t.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = t.obj_type;
+ r_result.class_member = p_symbol;
return OK;
-
}
bool success;
- ClassDB::get_integer_constant(t.obj_type,p_symbol,&success);
+ ClassDB::get_integer_constant(t.obj_type, p_symbol, &success);
if (success) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
- r_result.class_name=t.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
+ r_result.class_name = t.obj_type;
+ r_result.class_member = p_symbol;
return OK;
}
-
- ClassDB::get_property_type(t.obj_type,p_symbol,&success);
+ ClassDB::get_property_type(t.obj_type, p_symbol, &success);
if (success) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
- r_result.class_name=t.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
+ r_result.class_name = t.obj_type;
+ r_result.class_member = p_symbol;
return OK;
}
-
} else {
Variant::CallError ce;
- Variant v = Variant::construct(t.type,NULL,0,ce);
+ Variant v = Variant::construct(t.type, NULL, 0, ce);
bool valid;
- v.get_numeric_constant_value(t.type,p_symbol,&valid);
+ v.get_numeric_constant_value(t.type, p_symbol, &valid);
if (valid) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
- r_result.class_name=Variant::get_type_name(t.type);
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
+ r_result.class_name = Variant::get_type_name(t.type);
+ r_result.class_member = p_symbol;
return OK;
}
//todo check all inputevent types for property
- v.get(p_symbol,&valid);
+ v.get(p_symbol, &valid);
if (valid) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
- r_result.class_name=Variant::get_type_name(t.type);
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY;
+ r_result.class_name = Variant::get_type_name(t.type);
+ r_result.class_member = p_symbol;
return OK;
}
if (v.has_method(p_symbol)) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name=Variant::get_type_name(t.type);
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = Variant::get_type_name(t.type);
+ r_result.class_member = p_symbol;
return OK;
-
}
-
-
}
}
-
} break;
case GDParser::COMPLETION_CALL_ARGUMENTS: {
@@ -3032,18 +2849,17 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
GDCompletionIdentifier cid = _get_native_class(context);
- if (cid.obj_type!=StringName()) {
+ if (cid.obj_type != StringName()) {
List<MethodInfo> vm;
- ClassDB::get_virtual_methods(cid.obj_type,&vm);
- for(List<MethodInfo>::Element *E=vm.front();E;E=E->next()) {
+ ClassDB::get_virtual_methods(cid.obj_type, &vm);
+ for (List<MethodInfo>::Element *E = vm.front(); E; E = E->next()) {
- if (p_symbol==E->get().name) {
+ if (p_symbol == E->get().name) {
- r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
- r_result.class_name=cid.obj_type;
- r_result.class_member=p_symbol;
+ r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
+ r_result.class_name = cid.obj_type;
+ r_result.class_member = p_symbol;
return OK;
-
}
}
}
@@ -3053,10 +2869,8 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
return ERR_CANT_RESOLVE;
} break;
-
}
-
return ERR_CANT_RESOLVE;
}
diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp
index 519fb1cd8c..aaf97001e9 100644
--- a/modules/gdscript/gd_function.cpp
+++ b/modules/gdscript/gd_function.cpp
@@ -28,21 +28,21 @@
/*************************************************************************/
#include "gd_function.h"
+#include "gd_functions.h"
#include "gd_script.h"
#include "os/os.h"
-#include "gd_functions.h"
-Variant *GDFunction::_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self, Variant *p_stack,String& r_error) const{
+Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const {
- int address = p_address&ADDR_MASK;
+ int address = p_address & ADDR_MASK;
//sequential table (jump table generated by compiler)
- switch((p_address&ADDR_TYPE_MASK)>>ADDR_BITS) {
+ switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) {
case ADDR_TYPE_SELF: {
if (!p_instance) {
- r_error="Cannot access self without instance.";
+ r_error = "Cannot access self without instance.";
return NULL;
}
return &self;
@@ -54,7 +54,7 @@ Variant *GDFunction::_get_variant(int p_address,GDInstance *p_instance,GDScript
case ADDR_TYPE_MEMBER: {
//member indexing is O(1)
if (!p_instance) {
- r_error="Cannot access member without instance.";
+ r_error = "Cannot access member without instance.";
return NULL;
}
return &p_instance->members[address];
@@ -62,41 +62,38 @@ Variant *GDFunction::_get_variant(int p_address,GDInstance *p_instance,GDScript
case ADDR_TYPE_CLASS_CONSTANT: {
//todo change to index!
- GDScript *o=p_script;
- ERR_FAIL_INDEX_V(address,_global_names_count,NULL);
+ GDScript *o = p_script;
+ ERR_FAIL_INDEX_V(address, _global_names_count, NULL);
const StringName *sn = &_global_names_ptr[address];
- while(o) {
- GDScript *s=o;
- while(s) {
+ while (o) {
+ GDScript *s = o;
+ while (s) {
- Map<StringName,Variant>::Element *E=s->constants.find(*sn);
+ Map<StringName, Variant>::Element *E = s->constants.find(*sn);
if (E) {
return &E->get();
}
- s=s->_base;
+ s = s->_base;
}
- o=o->_owner;
+ o = o->_owner;
}
-
ERR_EXPLAIN("GDCompiler bug..");
ERR_FAIL_V(NULL);
} break;
case ADDR_TYPE_LOCAL_CONSTANT: {
- ERR_FAIL_INDEX_V(address,_constant_count,NULL);
+ ERR_FAIL_INDEX_V(address, _constant_count, NULL);
return &_constants_ptr[address];
} break;
case ADDR_TYPE_STACK:
case ADDR_TYPE_STACK_VARIABLE: {
- ERR_FAIL_INDEX_V(address,_stack_size,NULL);
+ ERR_FAIL_INDEX_V(address, _stack_size, NULL);
return &p_stack[address];
} break;
case ADDR_TYPE_GLOBAL: {
-
- ERR_FAIL_INDEX_V(address,GDScriptLanguage::get_singleton()->get_global_array_size(),NULL);
-
+ ERR_FAIL_INDEX_V(address, GDScriptLanguage::get_singleton()->get_global_array_size(), NULL);
return &GDScriptLanguage::get_singleton()->get_global_array()[address];
} break;
@@ -110,37 +107,33 @@ Variant *GDFunction::_get_variant(int p_address,GDInstance *p_instance,GDScript
return NULL;
}
-
-String GDFunction::_get_call_error(const Variant::CallError& p_err, const String& p_where,const Variant**argptrs) const {
-
-
+String GDFunction::_get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const {
String err_text;
- if (p_err.error==Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- int errorarg=p_err.argument;
- err_text="Invalid type in "+p_where+". Cannot convert argument "+itos(errorarg+1)+" from "+Variant::get_type_name(argptrs[errorarg]->get_type())+" to "+Variant::get_type_name(p_err.expected)+".";
- } else if (p_err.error==Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
- err_text="Invalid call to "+p_where+". Expected "+itos(p_err.argument)+" arguments.";
- } else if (p_err.error==Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
- err_text="Invalid call to "+p_where+". Expected "+itos(p_err.argument)+" arguments.";
- } else if (p_err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) {
- err_text="Invalid call. Nonexistent "+p_where+".";
- } else if (p_err.error==Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
- err_text="Attempt to call "+p_where+" on a null instance.";
+ if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ int errorarg = p_err.argument;
+ err_text = "Invalid type in " + p_where + ". Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(p_err.expected) + ".";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ err_text = "Invalid call to " + p_where + ". Expected " + itos(p_err.argument) + " arguments.";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ err_text = "Invalid call. Nonexistent " + p_where + ".";
+ } else if (p_err.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ err_text = "Attempt to call " + p_where + " on a null instance.";
} else {
- err_text="Bug, call error: #"+itos(p_err.error);
+ err_text = "Bug, call error: #" + itos(p_err.error);
}
return err_text;
-
}
-static String _get_var_type(const Variant* p_type) {
+static String _get_var_type(const Variant *p_type) {
String basestr;
- if (p_type->get_type()==Variant::OBJECT) {
+ if (p_type->get_type() == Variant::OBJECT) {
Object *bobj = *p_type;
if (!bobj) {
basestr = "null instance";
@@ -148,15 +141,15 @@ static String _get_var_type(const Variant* p_type) {
#ifdef DEBUG_ENABLED
if (ObjectDB::instance_validate(bobj)) {
if (bobj->get_script_instance())
- basestr= bobj->get_class()+" ("+bobj->get_script_instance()->get_script()->get_path().get_file()+")";
+ basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
else
basestr = bobj->get_class();
} else {
- basestr="previously freed instance";
+ basestr = "previously freed instance";
}
#else
- basestr="Object";
+ basestr = "Object";
#endif
}
@@ -165,114 +158,108 @@ static String _get_var_type(const Variant* p_type) {
}
return basestr;
-
}
-Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError& r_err, CallState *p_state) {
-
+Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state) {
if (!_code_ptr) {
return Variant();
}
- r_err.error=Variant::CallError::CALL_OK;
+ r_err.error = Variant::CallError::CALL_OK;
Variant self;
Variant retvalue;
Variant *stack = NULL;
Variant **call_args;
- int defarg=0;
+ int defarg = 0;
#ifdef DEBUG_ENABLED
- //GDScriptLanguage::get_singleton()->calls++;
+//GDScriptLanguage::get_singleton()->calls++;
#endif
- uint32_t alloca_size=0;
+ uint32_t alloca_size = 0;
GDScript *_class;
- int ip=0;
- int line=_initial_line;
-
-
+ int ip = 0;
+ int line = _initial_line;
if (p_state) {
//use existing (supplied) state (yielded)
- stack=(Variant*)p_state->stack.ptr();
- call_args=(Variant**)stack + sizeof(Variant)*p_state->stack_size;
- line=p_state->line;
- ip=p_state->ip;
- alloca_size=p_state->stack.size();
- _class=p_state->_class;
- p_instance=p_state->instance;
- defarg=p_state->defarg;
- self=p_state->self;
+ stack = (Variant *)p_state->stack.ptr();
+ call_args = (Variant **)stack + sizeof(Variant) * p_state->stack_size;
+ line = p_state->line;
+ ip = p_state->ip;
+ alloca_size = p_state->stack.size();
+ _class = p_state->_class;
+ p_instance = p_state->instance;
+ defarg = p_state->defarg;
+ self = p_state->self;
//stack[p_state->result_pos]=p_state->result; //assign stack with result
} else {
- if (p_argcount!=_argument_count) {
-
- if (p_argcount>_argument_count) {
+ if (p_argcount != _argument_count) {
- r_err.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_err.argument=_argument_count;
+ if (p_argcount > _argument_count) {
+ r_err.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_err.argument = _argument_count;
return Variant();
} else if (p_argcount < _argument_count - _default_arg_count) {
- r_err.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_err.argument=_argument_count - _default_arg_count;
+ r_err.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_err.argument = _argument_count - _default_arg_count;
return Variant();
} else {
- defarg=_argument_count-p_argcount;
+ defarg = _argument_count - p_argcount;
}
}
- alloca_size = sizeof(Variant*)*_call_size + sizeof(Variant)*_stack_size;
+ alloca_size = sizeof(Variant *) * _call_size + sizeof(Variant) * _stack_size;
if (alloca_size) {
- uint8_t *aptr = (uint8_t*)alloca(alloca_size);
+ uint8_t *aptr = (uint8_t *)alloca(alloca_size);
if (_stack_size) {
- stack=(Variant*)aptr;
- for(int i=0;i<p_argcount;i++)
- memnew_placement(&stack[i],Variant(*p_args[i]));
- for(int i=p_argcount;i<_stack_size;i++)
- memnew_placement(&stack[i],Variant);
+ stack = (Variant *)aptr;
+ for (int i = 0; i < p_argcount; i++)
+ memnew_placement(&stack[i], Variant(*p_args[i]));
+ for (int i = p_argcount; i < _stack_size; i++)
+ memnew_placement(&stack[i], Variant);
} else {
- stack=NULL;
+ stack = NULL;
}
if (_call_size) {
- call_args = (Variant**)&aptr[sizeof(Variant)*_stack_size];
+ call_args = (Variant **)&aptr[sizeof(Variant) * _stack_size];
} else {
- call_args=NULL;
+ call_args = NULL;
}
-
} else {
- stack=NULL;
- call_args=NULL;
+ stack = NULL;
+ call_args = NULL;
}
if (p_instance) {
- if (p_instance->base_ref && static_cast<Reference*>(p_instance->owner)->is_referenced()) {
+ if (p_instance->base_ref && static_cast<Reference *>(p_instance->owner)->is_referenced()) {
- self=REF(static_cast<Reference*>(p_instance->owner));
+ self = REF(static_cast<Reference *>(p_instance->owner));
} else {
- self=p_instance->owner;
+ self = p_instance->owner;
}
- _class=p_instance->script.ptr();
+ _class = p_instance->script.ptr();
} else {
- _class=_script;
+ _class = _script;
}
}
@@ -281,537 +268,519 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
#ifdef DEBUG_ENABLED
if (ScriptDebugger::get_singleton())
- GDScriptLanguage::get_singleton()->enter_function(p_instance,this,stack,&ip,&line);
-
-#define CHECK_SPACE(m_space)\
- ERR_BREAK((ip+m_space)>_code_size)
+ GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line);
-#define GET_VARIANT_PTR(m_v,m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip+m_code_ofs],p_instance,_class,self,stack,err_text);\
- if (!m_v)\
- break;
+#define CHECK_SPACE(m_space) \
+ ERR_BREAK((ip + m_space) > _code_size)
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, _class, self, stack, err_text); \
+ if (!m_v) \
+ break;
#else
#define CHECK_SPACE(m_space)
-#define GET_VARIANT_PTR(m_v,m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip+m_code_ofs],p_instance,_class,self,stack,err_text);
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, _class, self, stack, err_text);
#endif
-
#ifdef DEBUG_ENABLED
uint64_t function_start_time;
uint64_t function_call_time;
if (GDScriptLanguage::get_singleton()->profiling) {
- function_start_time=OS::get_singleton()->get_ticks_usec();
- function_call_time=0;
+ function_start_time = OS::get_singleton()->get_ticks_usec();
+ function_call_time = 0;
profile.call_count++;
profile.frame_call_count++;
}
#endif
- bool exit_ok=false;
+ bool exit_ok = false;
- while(ip<_code_size) {
+ while (ip < _code_size) {
-
- int last_opcode=_code_ptr[ip];
- switch(_code_ptr[ip]) {
+ int last_opcode = _code_ptr[ip];
+ switch (_code_ptr[ip]) {
case OPCODE_OPERATOR: {
CHECK_SPACE(5);
bool valid;
- Variant::Operator op = (Variant::Operator)_code_ptr[ip+1];
- ERR_BREAK(op>=Variant::OP_MAX);
+ Variant::Operator op = (Variant::Operator)_code_ptr[ip + 1];
+ ERR_BREAK(op >= Variant::OP_MAX);
- GET_VARIANT_PTR(a,2);
- GET_VARIANT_PTR(b,3);
- GET_VARIANT_PTR(dst,4);
+ GET_VARIANT_PTR(a, 2);
+ GET_VARIANT_PTR(b, 3);
+ GET_VARIANT_PTR(dst, 4);
#ifdef DEBUG_ENABLED
Variant ret;
- Variant::evaluate(op,*a,*b,ret,valid);
+ Variant::evaluate(op, *a, *b, ret, valid);
#else
- Variant::evaluate(op,*a,*b,*dst,valid);
+ Variant::evaluate(op, *a, *b, *dst, valid);
#endif
if (!valid) {
#ifdef DEBUG_ENABLED
- if (ret.get_type()==Variant::STRING) {
+ if (ret.get_type() == Variant::STRING) {
//return a string when invalid with the error
- err_text=ret;
- err_text += " in operator '"+Variant::get_operator_name(op)+"'.";
+ err_text = ret;
+ err_text += " in operator '" + Variant::get_operator_name(op) + "'.";
} else {
- err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'.";
+ err_text = "Invalid operands '" + Variant::get_type_name(a->get_type()) + "' and '" + Variant::get_type_name(b->get_type()) + "' in operator '" + Variant::get_operator_name(op) + "'.";
}
#endif
break;
-
}
#ifdef DEBUG_ENABLED
- *dst=ret;
+ *dst = ret;
#endif
- ip+=5;
+ ip += 5;
continue;
}
case OPCODE_EXTENDS_TEST: {
CHECK_SPACE(4);
- GET_VARIANT_PTR(a,1);
- GET_VARIANT_PTR(b,2);
- GET_VARIANT_PTR(dst,3);
+ GET_VARIANT_PTR(a, 1);
+ GET_VARIANT_PTR(b, 2);
+ GET_VARIANT_PTR(dst, 3);
#ifdef DEBUG_ENABLED
- if (a->get_type()!=Variant::OBJECT || a->operator Object*()==NULL) {
+ 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 'extends' is not an instance of anything.";
break;
-
}
- if (b->get_type()!=Variant::OBJECT || b->operator Object*()==NULL) {
+ 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 'extends' is not a class.";
break;
-
}
#endif
-
Object *obj_A = *a;
Object *obj_B = *b;
-
GDScript *scr_B = obj_B->cast_to<GDScript>();
- bool extends_ok=false;
+ bool extends_ok = false;
if (scr_B) {
//if B is a script, the only valid condition is that A has an instance which inherits from the script
//in other situation, this shoul return false.
- if (obj_A->get_script_instance() && obj_A->get_script_instance()->get_language()==GDScriptLanguage::get_singleton()) {
+ if (obj_A->get_script_instance() && obj_A->get_script_instance()->get_language() == GDScriptLanguage::get_singleton()) {
- GDScript *cmp = static_cast<GDScript*>(obj_A->get_script_instance()->get_script().ptr());
+ GDScript *cmp = static_cast<GDScript *>(obj_A->get_script_instance()->get_script().ptr());
//bool found=false;
- while(cmp) {
+ while (cmp) {
- if (cmp==scr_B) {
+ if (cmp == scr_B) {
//inherits from script, all ok
- extends_ok=true;
+ extends_ok = true;
break;
-
}
- cmp=cmp->_base;
+ cmp = cmp->_base;
}
-
}
-
} else {
- GDNativeClass *nc= obj_B->cast_to<GDNativeClass>();
+ GDNativeClass *nc = obj_B->cast_to<GDNativeClass>();
if (!nc) {
- err_text="Right operand of 'extends' is not a class (type: '"+obj_B->get_class()+"').";
+ err_text = "Right operand of 'extends' is not a class (type: '" + obj_B->get_class() + "').";
break;
}
- extends_ok=ClassDB::is_parent_class(obj_A->get_class_name(),nc->get_name());
+ extends_ok = ClassDB::is_parent_class(obj_A->get_class_name(), nc->get_name());
}
- *dst=extends_ok;
- ip+=4;
+ *dst = extends_ok;
+ ip += 4;
continue;
}
case OPCODE_SET: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(dst,1);
- GET_VARIANT_PTR(index,2);
- GET_VARIANT_PTR(value,3);
+ GET_VARIANT_PTR(dst, 1);
+ GET_VARIANT_PTR(index, 2);
+ GET_VARIANT_PTR(value, 3);
bool valid;
- dst->set(*index,*value,&valid);
+ dst->set(*index, *value, &valid);
if (!valid) {
String v = index->operator String();
- if (v!="") {
- v="'"+v+"'";
+ if (v != "") {
+ v = "'" + v + "'";
} else {
- v="of type '"+_get_var_type(index)+"'";
+ v = "of type '" + _get_var_type(index) + "'";
}
- err_text="Invalid set index "+v+" (on base: '"+_get_var_type(dst)+"').";
+ err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "').";
break;
}
- ip+=4;
+ ip += 4;
continue;
}
case OPCODE_GET: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(src,1);
- GET_VARIANT_PTR(index,2);
- GET_VARIANT_PTR(dst,3);
+ GET_VARIANT_PTR(src, 1);
+ GET_VARIANT_PTR(index, 2);
+ GET_VARIANT_PTR(dst, 3);
bool valid;
#ifdef DEBUG_ENABLED
//allow better error message in cases where src and dst are the same stack position
- Variant ret = src->get(*index,&valid);
+ Variant ret = src->get(*index, &valid);
#else
- *dst = src->get(*index,&valid);
+ *dst = src->get(*index, &valid);
#endif
if (!valid) {
String v = index->operator String();
- if (v!="") {
- v="'"+v+"'";
+ if (v != "") {
+ v = "'" + v + "'";
} else {
- v="of type '"+_get_var_type(index)+"'";
+ v = "of type '" + _get_var_type(index) + "'";
}
- err_text="Invalid get index "+v+" (on base: '"+_get_var_type(src)+"').";
+ err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "').";
break;
}
#ifdef DEBUG_ENABLED
- *dst=ret;
+ *dst = ret;
#endif
- ip+=4;
+ ip += 4;
continue;
}
case OPCODE_SET_NAMED: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(dst,1);
- GET_VARIANT_PTR(value,3);
+ GET_VARIANT_PTR(dst, 1);
+ GET_VARIANT_PTR(value, 3);
- int indexname = _code_ptr[ip+2];
+ int indexname = _code_ptr[ip + 2];
- ERR_BREAK(indexname<0 || indexname>=_global_names_count);
+ ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
bool valid;
- dst->set_named(*index,*value,&valid);
+ dst->set_named(*index, *value, &valid);
if (!valid) {
String err_type;
- err_text="Invalid set index '"+String(*index)+"' (on base: '"+_get_var_type(dst)+"').";
+ err_text = "Invalid set index '" + String(*index) + "' (on base: '" + _get_var_type(dst) + "').";
break;
}
- ip+=4;
+ ip += 4;
continue;
}
case OPCODE_GET_NAMED: {
-
CHECK_SPACE(4);
- GET_VARIANT_PTR(src,1);
- GET_VARIANT_PTR(dst,3);
+ GET_VARIANT_PTR(src, 1);
+ GET_VARIANT_PTR(dst, 3);
- int indexname = _code_ptr[ip+2];
+ int indexname = _code_ptr[ip + 2];
- ERR_BREAK(indexname<0 || indexname>=_global_names_count);
+ ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
bool valid;
#ifdef DEBUG_ENABLED
//allow better error message in cases where src and dst are the same stack position
- Variant ret = src->get_named(*index,&valid);
+ Variant ret = src->get_named(*index, &valid);
#else
- *dst = src->get_named(*index,&valid);
+ *dst = src->get_named(*index, &valid);
#endif
if (!valid) {
if (src->has_method(*index)) {
- err_text="Invalid get index '"+index->operator String()+"' (on base: '"+_get_var_type(src)+"'). Did you mean '."+index->operator String()+"()' ?";
+ err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "'). Did you mean '." + index->operator String() + "()' ?";
} else {
- err_text="Invalid get index '"+index->operator String()+"' (on base: '"+_get_var_type(src)+"').";
+ err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "').";
}
break;
}
#ifdef DEBUG_ENABLED
- *dst=ret;
+ *dst = ret;
#endif
- ip+=4;
+ ip += 4;
continue;
}
case OPCODE_SET_MEMBER: {
CHECK_SPACE(3);
- int indexname = _code_ptr[ip+1];
- ERR_BREAK(indexname<0 || indexname>=_global_names_count);
+ int indexname = _code_ptr[ip + 1];
+ ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
- GET_VARIANT_PTR(src,2);
+ GET_VARIANT_PTR(src, 2);
bool valid;
- bool ok = ClassDB::set_property(p_instance->owner,*index,*src,&valid);
+ bool ok = ClassDB::set_property(p_instance->owner, *index, *src, &valid);
#ifdef DEBUG_ENABLED
if (!ok) {
- err_text="Internal error setting property: "+String(*index);
+ err_text = "Internal error setting property: " + String(*index);
break;
} else if (!valid) {
- err_text="Error setting property '"+String(*index)+"' with value of type "+Variant::get_type_name(src->get_type())+".";
+ err_text = "Error setting property '" + String(*index) + "' with value of type " + Variant::get_type_name(src->get_type()) + ".";
break;
-
}
#endif
- ip+=3;
+ ip += 3;
continue;
}
case OPCODE_GET_MEMBER: {
CHECK_SPACE(3);
- int indexname = _code_ptr[ip+1];
- ERR_BREAK(indexname<0 || indexname>=_global_names_count);
+ int indexname = _code_ptr[ip + 1];
+ ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
- GET_VARIANT_PTR(dst,2);
- bool ok = ClassDB::get_property(p_instance->owner,*index,*dst);
+ GET_VARIANT_PTR(dst, 2);
+ bool ok = ClassDB::get_property(p_instance->owner, *index, *dst);
#ifdef DEBUG_ENABLED
if (!ok) {
- err_text="Internal error getting property: "+String(*index);
+ err_text = "Internal error getting property: " + String(*index);
break;
}
#endif
- ip+=3;
+ ip += 3;
continue;
}
case OPCODE_ASSIGN: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(dst,1);
- GET_VARIANT_PTR(src,2);
+ GET_VARIANT_PTR(dst, 1);
+ GET_VARIANT_PTR(src, 2);
*dst = *src;
- ip+=3;
+ ip += 3;
continue;
}
case OPCODE_ASSIGN_TRUE: {
CHECK_SPACE(2);
- GET_VARIANT_PTR(dst,1);
+ GET_VARIANT_PTR(dst, 1);
*dst = true;
- ip+=2;
+ ip += 2;
continue;
}
case OPCODE_ASSIGN_FALSE: {
CHECK_SPACE(2);
- GET_VARIANT_PTR(dst,1);
+ GET_VARIANT_PTR(dst, 1);
*dst = false;
- ip+=2;
+ ip += 2;
continue;
}
case OPCODE_CONSTRUCT: {
CHECK_SPACE(2);
- Variant::Type t=Variant::Type(_code_ptr[ip+1]);
- int argc=_code_ptr[ip+2];
- CHECK_SPACE(argc+2);
+ Variant::Type t = Variant::Type(_code_ptr[ip + 1]);
+ int argc = _code_ptr[ip + 2];
+ CHECK_SPACE(argc + 2);
Variant **argptrs = call_args;
- for(int i=0;i<argc;i++) {
- GET_VARIANT_PTR(v,3+i);
- argptrs[i]=v;
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(v, 3 + i);
+ argptrs[i] = v;
}
- GET_VARIANT_PTR(dst,3+argc);
+ GET_VARIANT_PTR(dst, 3 + argc);
Variant::CallError err;
- *dst = Variant::construct(t,(const Variant**)argptrs,argc,err);
+ *dst = Variant::construct(t, (const Variant **)argptrs, argc, err);
- if (err.error!=Variant::CallError::CALL_OK) {
+ if (err.error != Variant::CallError::CALL_OK) {
- err_text=_get_call_error(err,"'"+Variant::get_type_name(t)+"' constructor",(const Variant**)argptrs);
+ err_text = _get_call_error(err, "'" + Variant::get_type_name(t) + "' constructor", (const Variant **)argptrs);
break;
}
- ip+=4+argc;
+ ip += 4 + argc;
//construct a basic type
continue;
}
case OPCODE_CONSTRUCT_ARRAY: {
CHECK_SPACE(1);
- int argc=_code_ptr[ip+1];
+ int argc = _code_ptr[ip + 1];
Array array; //arrays are always shared
array.resize(argc);
- CHECK_SPACE(argc+2);
-
- for(int i=0;i<argc;i++) {
- GET_VARIANT_PTR(v,2+i);
- array[i]=*v;
+ CHECK_SPACE(argc + 2);
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(v, 2 + i);
+ array[i] = *v;
}
- GET_VARIANT_PTR(dst,2+argc);
+ GET_VARIANT_PTR(dst, 2 + argc);
- *dst=array;
+ *dst = array;
- ip+=3+argc;
+ ip += 3 + argc;
continue;
}
case OPCODE_CONSTRUCT_DICTIONARY: {
CHECK_SPACE(1);
- int argc=_code_ptr[ip+1];
+ int argc = _code_ptr[ip + 1];
Dictionary dict; //arrays are always shared
- CHECK_SPACE(argc*2+2);
+ CHECK_SPACE(argc * 2 + 2);
- for(int i=0;i<argc;i++) {
-
- GET_VARIANT_PTR(k,2+i*2+0);
- GET_VARIANT_PTR(v,2+i*2+1);
- dict[*k]=*v;
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(k, 2 + i * 2 + 0);
+ GET_VARIANT_PTR(v, 2 + i * 2 + 1);
+ dict[*k] = *v;
}
- GET_VARIANT_PTR(dst,2+argc*2);
+ GET_VARIANT_PTR(dst, 2 + argc * 2);
- *dst=dict;
+ *dst = dict;
- ip+=3+argc*2;
+ ip += 3 + argc * 2;
continue;
}
case OPCODE_CALL_RETURN:
case OPCODE_CALL: {
-
CHECK_SPACE(4);
- bool call_ret = _code_ptr[ip]==OPCODE_CALL_RETURN;
+ bool call_ret = _code_ptr[ip] == OPCODE_CALL_RETURN;
- int argc=_code_ptr[ip+1];
- GET_VARIANT_PTR(base,2);
- int nameg=_code_ptr[ip+3];
+ int argc = _code_ptr[ip + 1];
+ GET_VARIANT_PTR(base, 2);
+ int nameg = _code_ptr[ip + 3];
- ERR_BREAK(nameg<0 || nameg>=_global_names_count);
+ ERR_BREAK(nameg < 0 || nameg >= _global_names_count);
const StringName *methodname = &_global_names_ptr[nameg];
- ERR_BREAK(argc<0);
- ip+=4;
- CHECK_SPACE(argc+1);
+ ERR_BREAK(argc < 0);
+ ip += 4;
+ CHECK_SPACE(argc + 1);
Variant **argptrs = call_args;
- for(int i=0;i<argc;i++) {
- GET_VARIANT_PTR(v,i);
- argptrs[i]=v;
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(v, i);
+ argptrs[i] = v;
}
#ifdef DEBUG_ENABLED
uint64_t call_time;
if (GDScriptLanguage::get_singleton()->profiling) {
- call_time=OS::get_singleton()->get_ticks_usec();
+ call_time = OS::get_singleton()->get_ticks_usec();
}
#endif
Variant::CallError err;
if (call_ret) {
- GET_VARIANT_PTR(ret,argc);
- base->call_ptr(*methodname,(const Variant**)argptrs,argc,ret,err);
+ GET_VARIANT_PTR(ret, argc);
+ base->call_ptr(*methodname, (const Variant **)argptrs, argc, ret, err);
} else {
- base->call_ptr(*methodname,(const Variant**)argptrs,argc,NULL,err);
+ base->call_ptr(*methodname, (const Variant **)argptrs, argc, NULL, err);
}
#ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->profiling) {
- function_call_time+=OS::get_singleton()->get_ticks_usec() - call_time;
+ function_call_time += OS::get_singleton()->get_ticks_usec() - call_time;
}
#endif
- if (err.error!=Variant::CallError::CALL_OK) {
-
+ if (err.error != Variant::CallError::CALL_OK) {
String methodstr = *methodname;
String basestr = _get_var_type(base);
- if (methodstr=="call") {
- if (argc>=1) {
- methodstr=String(*argptrs[0])+" (via call)";
- if (err.error==Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- err.argument-=1;
+ if (methodstr == "call") {
+ if (argc >= 1) {
+ methodstr = String(*argptrs[0]) + " (via call)";
+ if (err.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ err.argument -= 1;
}
}
- } else if (methodstr=="free") {
+ } else if (methodstr == "free") {
- if (err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
if (base->is_ref()) {
- err_text="Attempted to free a reference.";
+ err_text = "Attempted to free a reference.";
break;
- } else if (base->get_type()==Variant::OBJECT) {
+ } else if (base->get_type() == Variant::OBJECT) {
- err_text="Attempted to free a locked object (calling or emitting).";
+ err_text = "Attempted to free a locked object (calling or emitting).";
break;
}
}
}
- err_text=_get_call_error(err,"function '"+methodstr+"' in base '"+basestr+"'",(const Variant**)argptrs);
+ err_text = _get_call_error(err, "function '" + methodstr + "' in base '" + basestr + "'", (const Variant **)argptrs);
break;
}
//_call_func(NULL,base,*methodname,ip,argc,p_instance,stack);
- ip+=argc+1;
+ ip += argc + 1;
continue;
}
case OPCODE_CALL_BUILT_IN: {
CHECK_SPACE(4);
- GDFunctions::Function func = GDFunctions::Function(_code_ptr[ip+1]);
- int argc=_code_ptr[ip+2];
- ERR_BREAK(argc<0);
+ GDFunctions::Function func = GDFunctions::Function(_code_ptr[ip + 1]);
+ int argc = _code_ptr[ip + 2];
+ ERR_BREAK(argc < 0);
- ip+=3;
- CHECK_SPACE(argc+1);
+ ip += 3;
+ CHECK_SPACE(argc + 1);
Variant **argptrs = call_args;
- for(int i=0;i<argc;i++) {
- GET_VARIANT_PTR(v,i);
- argptrs[i]=v;
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(v, i);
+ argptrs[i] = v;
}
- GET_VARIANT_PTR(dst,argc);
+ GET_VARIANT_PTR(dst, argc);
Variant::CallError err;
- GDFunctions::call(func,(const Variant**)argptrs,argc,*dst,err);
-
- if (err.error!=Variant::CallError::CALL_OK) {
+ GDFunctions::call(func, (const Variant **)argptrs, argc, *dst, err);
+ if (err.error != Variant::CallError::CALL_OK) {
String methodstr = GDFunctions::get_func_name(func);
- if (dst->get_type()==Variant::STRING) {
+ if (dst->get_type() == Variant::STRING) {
//call provided error string
- err_text="Error calling built-in function '"+methodstr+"': "+String(*dst);
+ err_text = "Error calling built-in function '" + methodstr + "': " + String(*dst);
} else {
- err_text=_get_call_error(err,"built-in function '"+methodstr+"'",(const Variant**)argptrs);
+ err_text = _get_call_error(err, "built-in function '" + methodstr + "'", (const Variant **)argptrs);
}
break;
}
- ip+=argc+1;
+ ip += argc + 1;
continue;
}
case OPCODE_CALL_SELF: {
@@ -821,37 +790,36 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
case OPCODE_CALL_SELF_BASE: {
CHECK_SPACE(2);
- int self_fun = _code_ptr[ip+1];
+ int self_fun = _code_ptr[ip + 1];
#ifdef DEBUG_ENABLED
- if (self_fun<0 || self_fun>=_global_names_count) {
+ if (self_fun < 0 || self_fun >= _global_names_count) {
- err_text="compiler bug, function name not found";
+ err_text = "compiler bug, function name not found";
break;
}
#endif
const StringName *methodname = &_global_names_ptr[self_fun];
- int argc=_code_ptr[ip+2];
+ int argc = _code_ptr[ip + 2];
- CHECK_SPACE(2+argc+1);
+ CHECK_SPACE(2 + argc + 1);
Variant **argptrs = call_args;
- for(int i=0;i<argc;i++) {
- GET_VARIANT_PTR(v,i+3);
- argptrs[i]=v;
+ for (int i = 0; i < argc; i++) {
+ GET_VARIANT_PTR(v, i + 3);
+ argptrs[i] = v;
}
- GET_VARIANT_PTR(dst,argc+3);
+ GET_VARIANT_PTR(dst, argc + 3);
const GDScript *gds = _script;
-
- const Map<StringName,GDFunction*>::Element *E=NULL;
+ const Map<StringName, GDFunction *>::Element *E = NULL;
while (gds->base.ptr()) {
- gds=gds->base.ptr();
- E=gds->member_functions.find(*methodname);
+ gds = gds->base.ptr();
+ E = gds->member_functions.find(*methodname);
if (E)
break;
}
@@ -860,344 +828,332 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
if (E) {
- *dst=E->get()->call(p_instance,(const Variant**)argptrs,argc,err);
+ *dst = E->get()->call(p_instance, (const Variant **)argptrs, argc, err);
} else if (gds->native.ptr()) {
- if (*methodname!=GDScriptLanguage::get_singleton()->strings._init) {
+ if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
- MethodBind *mb = ClassDB::get_method(gds->native->get_name(),*methodname);
+ MethodBind *mb = ClassDB::get_method(gds->native->get_name(), *methodname);
if (!mb) {
- err.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ err.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
} else {
- *dst=mb->call(p_instance->owner,(const Variant**)argptrs,argc,err);
+ *dst = mb->call(p_instance->owner, (const Variant **)argptrs, argc, err);
}
} else {
- err.error=Variant::CallError::CALL_OK;
+ err.error = Variant::CallError::CALL_OK;
}
} else {
- if (*methodname!=GDScriptLanguage::get_singleton()->strings._init) {
- err.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ if (*methodname != GDScriptLanguage::get_singleton()->strings._init) {
+ err.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
} else {
- err.error=Variant::CallError::CALL_OK;
+ err.error = Variant::CallError::CALL_OK;
}
}
-
- if (err.error!=Variant::CallError::CALL_OK) {
-
+ if (err.error != Variant::CallError::CALL_OK) {
String methodstr = *methodname;
- err_text=_get_call_error(err,"function '"+methodstr+"'",(const Variant**)argptrs);
+ err_text = _get_call_error(err, "function '" + methodstr + "'", (const Variant **)argptrs);
break;
}
- ip+=4+argc;
+ ip += 4 + argc;
continue;
}
case OPCODE_YIELD:
case OPCODE_YIELD_SIGNAL: {
- int ipofs=1;
- if (_code_ptr[ip]==OPCODE_YIELD_SIGNAL) {
+ int ipofs = 1;
+ if (_code_ptr[ip] == OPCODE_YIELD_SIGNAL) {
CHECK_SPACE(4);
- ipofs+=2;
+ ipofs += 2;
} else {
CHECK_SPACE(2);
-
}
- Ref<GDFunctionState> gdfs = memnew( GDFunctionState );
- gdfs->function=this;
+ Ref<GDFunctionState> gdfs = memnew(GDFunctionState);
+ gdfs->function = this;
gdfs->state.stack.resize(alloca_size);
//copy variant stack
- for(int i=0;i<_stack_size;i++) {
- memnew_placement(&gdfs->state.stack[sizeof(Variant)*i],Variant(stack[i]));
+ for (int i = 0; i < _stack_size; i++) {
+ memnew_placement(&gdfs->state.stack[sizeof(Variant) * i], Variant(stack[i]));
}
- gdfs->state.stack_size=_stack_size;
- gdfs->state.self=self;
- gdfs->state.alloca_size=alloca_size;
- 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.stack_size = _stack_size;
+ gdfs->state.self = self;
+ gdfs->state.alloca_size = alloca_size;
+ 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;
- gdfs->function=this;
+ gdfs->state.defarg = defarg;
+ gdfs->state.instance = p_instance;
+ gdfs->function = this;
- retvalue=gdfs;
+ retvalue = gdfs;
- if (_code_ptr[ip]==OPCODE_YIELD_SIGNAL) {
- GET_VARIANT_PTR(argobj,1);
- GET_VARIANT_PTR(argname,2);
+ if (_code_ptr[ip] == OPCODE_YIELD_SIGNAL) {
+ GET_VARIANT_PTR(argobj, 1);
+ GET_VARIANT_PTR(argname, 2);
//do the oneshot connect
- if (argobj->get_type()!=Variant::OBJECT) {
- err_text="First argument of yield() not of type object.";
+ if (argobj->get_type() != Variant::OBJECT) {
+ err_text = "First argument of yield() not of type object.";
break;
}
- if (argname->get_type()!=Variant::STRING) {
- err_text="Second argument of yield() not a string (for signal name).";
+ if (argname->get_type() != Variant::STRING) {
+ err_text = "Second argument of yield() not a string (for signal name).";
break;
}
- Object *obj=argobj->operator Object *();
+ Object *obj = argobj->operator Object *();
String signal = argname->operator String();
#ifdef DEBUG_ENABLED
if (!obj) {
- err_text="First argument of yield() is null.";
+ err_text = "First argument of yield() is null.";
break;
}
if (ScriptDebugger::get_singleton()) {
if (!ObjectDB::instance_validate(obj)) {
- err_text="First argument of yield() is a previously freed instance.";
+ err_text = "First argument of yield() is a previously freed instance.";
break;
}
}
- if (signal.length()==0) {
+ if (signal.length() == 0) {
- err_text="Second argument of yield() is an empty string (for signal name).";
+ err_text = "Second argument of yield() is an empty string (for signal name).";
break;
}
#endif
- Error err = obj->connect(signal,gdfs.ptr(),"_signal_callback",varray(gdfs),Object::CONNECT_ONESHOT);
- if (err!=OK) {
- err_text="Error connecting to signal: "+signal+" during yield().";
+ Error err = obj->connect(signal, gdfs.ptr(), "_signal_callback", varray(gdfs), Object::CONNECT_ONESHOT);
+ if (err != OK) {
+ err_text = "Error connecting to signal: " + signal + " during yield().";
break;
}
-
-
}
- exit_ok=true;
+ exit_ok = true;
break;
}
case OPCODE_YIELD_RESUME: {
CHECK_SPACE(2);
if (!p_state) {
- err_text=("Invalid Resume (bug?)");
+ err_text = ("Invalid Resume (bug?)");
break;
}
- GET_VARIANT_PTR(result,1);
- *result=p_state->result;
- ip+=2;
+ GET_VARIANT_PTR(result, 1);
+ *result = p_state->result;
+ ip += 2;
continue;
}
case OPCODE_JUMP: {
CHECK_SPACE(2);
- int to = _code_ptr[ip+1];
+ int to = _code_ptr[ip + 1];
- ERR_BREAK(to<0 || to>_code_size);
- ip=to;
+ ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
continue;
}
case OPCODE_JUMP_IF: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(test,1);
+ GET_VARIANT_PTR(test, 1);
bool valid;
bool result = test->booleanize(valid);
#ifdef DEBUG_ENABLED
if (!valid) {
- err_text="cannot evaluate conditional expression of type: "+Variant::get_type_name(test->get_type());
+ err_text = "cannot evaluate conditional expression of type: " + Variant::get_type_name(test->get_type());
break;
}
#endif
if (result) {
- int to = _code_ptr[ip+2];
- ERR_BREAK(to<0 || to>_code_size);
- ip=to;
+ int to = _code_ptr[ip + 2];
+ ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
continue;
}
- ip+=3;
+ ip += 3;
continue;
}
case OPCODE_JUMP_IF_NOT: {
CHECK_SPACE(3);
- GET_VARIANT_PTR(test,1);
+ GET_VARIANT_PTR(test, 1);
bool valid;
bool result = test->booleanize(valid);
#ifdef DEBUG_ENABLED
if (!valid) {
- err_text="cannot evaluate conditional expression of type: "+Variant::get_type_name(test->get_type());
+ err_text = "cannot evaluate conditional expression of type: " + Variant::get_type_name(test->get_type());
break;
}
#endif
if (!result) {
- int to = _code_ptr[ip+2];
- ERR_BREAK(to<0 || to>_code_size);
- ip=to;
+ int to = _code_ptr[ip + 2];
+ ERR_BREAK(to < 0 || to > _code_size);
+ ip = to;
continue;
}
- ip+=3;
+ ip += 3;
continue;
}
case OPCODE_JUMP_TO_DEF_ARGUMENT: {
CHECK_SPACE(2);
- ip=_default_arg_ptr[defarg];
+ ip = _default_arg_ptr[defarg];
continue;
}
case OPCODE_RETURN: {
CHECK_SPACE(2);
- GET_VARIANT_PTR(r,1);
- retvalue=*r;
- exit_ok=true;
+ GET_VARIANT_PTR(r, 1);
+ retvalue = *r;
+ exit_ok = true;
break;
}
case OPCODE_ITERATE_BEGIN: {
CHECK_SPACE(8); //space for this an regular iterate
- GET_VARIANT_PTR(counter,1);
- GET_VARIANT_PTR(container,2);
+ GET_VARIANT_PTR(counter, 1);
+ GET_VARIANT_PTR(container, 2);
bool valid;
- if (!container->iter_init(*counter,valid)) {
+ if (!container->iter_init(*counter, valid)) {
if (!valid) {
- err_text="Unable to iterate on object of type "+Variant::get_type_name(container->get_type())+"'.";
+ err_text = "Unable to iterate on object of type " + Variant::get_type_name(container->get_type()) + "'.";
break;
}
- int jumpto=_code_ptr[ip+3];
- ERR_BREAK(jumpto<0 || jumpto>_code_size);
- ip=jumpto;
+ int jumpto = _code_ptr[ip + 3];
+ ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
continue;
}
- GET_VARIANT_PTR(iterator,4);
+ GET_VARIANT_PTR(iterator, 4);
-
- *iterator=container->iter_get(*counter,valid);
+ *iterator = container->iter_get(*counter, valid);
if (!valid) {
- err_text="Unable to obtain iterator object of type "+Variant::get_type_name(container->get_type())+"'.";
+ err_text = "Unable to obtain iterator object of type " + Variant::get_type_name(container->get_type()) + "'.";
break;
}
-
- ip+=5; //skip regular iterate which is always next
+ ip += 5; //skip regular iterate which is always next
continue;
}
case OPCODE_ITERATE: {
CHECK_SPACE(4);
- GET_VARIANT_PTR(counter,1);
- GET_VARIANT_PTR(container,2);
+ GET_VARIANT_PTR(counter, 1);
+ GET_VARIANT_PTR(container, 2);
bool valid;
- if (!container->iter_next(*counter,valid)) {
+ if (!container->iter_next(*counter, valid)) {
if (!valid) {
- err_text="Unable to iterate on object of type "+Variant::get_type_name(container->get_type())+"' (type changed since first iteration?).";
+ err_text = "Unable to iterate on object of type " + Variant::get_type_name(container->get_type()) + "' (type changed since first iteration?).";
break;
}
- int jumpto=_code_ptr[ip+3];
- ERR_BREAK(jumpto<0 || jumpto>_code_size);
- ip=jumpto;
+ int jumpto = _code_ptr[ip + 3];
+ ERR_BREAK(jumpto < 0 || jumpto > _code_size);
+ ip = jumpto;
continue;
}
- GET_VARIANT_PTR(iterator,4);
+ GET_VARIANT_PTR(iterator, 4);
- *iterator=container->iter_get(*counter,valid);
+ *iterator = container->iter_get(*counter, valid);
if (!valid) {
- err_text="Unable to obtain iterator object of type "+Variant::get_type_name(container->get_type())+"' (but was obtained on first iteration?).";
+ err_text = "Unable to obtain iterator object of type " + Variant::get_type_name(container->get_type()) + "' (but was obtained on first iteration?).";
break;
}
- ip+=5; //loop again
+ ip += 5; //loop again
continue;
}
case OPCODE_ASSERT: {
CHECK_SPACE(2);
- GET_VARIANT_PTR(test,1);
+ GET_VARIANT_PTR(test, 1);
#ifdef DEBUG_ENABLED
bool valid;
bool result = test->booleanize(valid);
-
if (!valid) {
- err_text="cannot evaluate conditional expression of type: "+Variant::get_type_name(test->get_type());
+ err_text = "cannot evaluate conditional expression of type: " + Variant::get_type_name(test->get_type());
break;
}
-
if (!result) {
- err_text="Assertion failed.";
+ err_text = "Assertion failed.";
break;
}
#endif
- ip+=2;
+ ip += 2;
continue;
}
case OPCODE_BREAKPOINT: {
#ifdef DEBUG_ENABLED
if (ScriptDebugger::get_singleton()) {
- GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement",true);
+ GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement", true);
}
#endif
- ip+=1;
+ ip += 1;
continue;
}
case OPCODE_LINE: {
CHECK_SPACE(2);
- line=_code_ptr[ip+1];
- ip+=2;
+ line = _code_ptr[ip + 1];
+ ip += 2;
if (ScriptDebugger::get_singleton()) {
// line
- bool do_break=false;
+ bool do_break = false;
- if (ScriptDebugger::get_singleton()->get_lines_left()>0) {
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0) {
- if (ScriptDebugger::get_singleton()->get_depth()<=0)
- ScriptDebugger::get_singleton()->set_lines_left( ScriptDebugger::get_singleton()->get_lines_left() -1 );
- if (ScriptDebugger::get_singleton()->get_lines_left()<=0)
- do_break=true;
+ if (ScriptDebugger::get_singleton()->get_depth() <= 0)
+ ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1);
+ if (ScriptDebugger::get_singleton()->get_lines_left() <= 0)
+ do_break = true;
}
- if (ScriptDebugger::get_singleton()->is_breakpoint(line,source))
- do_break=true;
+ if (ScriptDebugger::get_singleton()->is_breakpoint(line, source))
+ do_break = true;
if (do_break) {
- GDScriptLanguage::get_singleton()->debug_break("Breakpoint",true);
+ GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true);
}
ScriptDebugger::get_singleton()->line_poll();
-
}
continue;
}
case OPCODE_END: {
- exit_ok=true;
+ exit_ok = true;
break;
-
}
default: {
- err_text="Illegal opcode "+itos(_code_ptr[ip])+" at address "+itos(ip);
+ err_text = "Illegal opcode " + itos(_code_ptr[ip]) + " at address " + itos(ip);
break;
}
-
}
if (exit_ok)
@@ -1206,73 +1162,69 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
// function, file, line, error, explanation
String err_file;
if (p_instance)
- err_file=p_instance->script->path;
+ err_file = p_instance->script->path;
else if (_class)
- err_file=_class->path;
- if (err_file=="")
- err_file="<built-in>";
+ err_file = _class->path;
+ if (err_file == "")
+ err_file = "<built-in>";
String err_func = name;
- if (p_instance && p_instance->script->name!="")
- err_func=p_instance->script->name+"."+err_func;
- int err_line=line;
- if (err_text=="") {
- err_text="Internal Script Error! - opcode #"+itos(last_opcode)+" (report please).";
+ if (p_instance && p_instance->script->name != "")
+ err_func = p_instance->script->name + "." + err_func;
+ int err_line = line;
+ if (err_text == "") {
+ err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please).";
}
- if (!GDScriptLanguage::get_singleton()->debug_break(err_text,false)) {
+ if (!GDScriptLanguage::get_singleton()->debug_break(err_text, false)) {
// debugger break did not happen
- _err_print_error(err_func.utf8().get_data(),err_file.utf8().get_data(),err_line,err_text.utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, err_text.utf8().get_data(), ERR_HANDLER_SCRIPT);
}
-
break;
}
#ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->profiling) {
uint64_t time_taken = OS::get_singleton()->get_ticks_usec() - function_start_time;
- profile.total_time+=time_taken;
- profile.self_time+=time_taken-function_call_time;
- profile.frame_total_time+=time_taken;
- profile.frame_self_time+=time_taken-function_call_time;
- GDScriptLanguage::get_singleton()->script_frame_time+=time_taken-function_call_time;
-
+ profile.total_time += time_taken;
+ profile.self_time += time_taken - function_call_time;
+ profile.frame_total_time += time_taken;
+ profile.frame_self_time += time_taken - function_call_time;
+ GDScriptLanguage::get_singleton()->script_frame_time += time_taken - function_call_time;
}
#endif
if (ScriptDebugger::get_singleton())
GDScriptLanguage::get_singleton()->exit_function();
-
if (_stack_size) {
//free stack
- for(int i=0;i<_stack_size;i++)
+ for (int i = 0; i < _stack_size; i++)
stack[i].~Variant();
}
return retvalue;
-
}
-const int* GDFunction::get_code() const {
+const int *GDFunction::get_code() const {
return _code_ptr;
}
-int GDFunction::get_code_size() const{
+int GDFunction::get_code_size() const {
return _code_size;
}
Variant GDFunction::get_constant(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx,constants.size(),"<errconst>");
+ ERR_FAIL_INDEX_V(p_idx, constants.size(), "<errconst>");
return constants[p_idx];
}
StringName GDFunction::get_global_name(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx,global_names.size(),"<errgname>");
+ ERR_FAIL_INDEX_V(p_idx, global_names.size(), "<errgname>");
return global_names[p_idx];
}
@@ -1280,13 +1232,12 @@ 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_arg) const {
- ERR_FAIL_INDEX_V(p_arg,default_arguments.size(),-1);
+ ERR_FAIL_INDEX_V(p_arg, default_arguments.size(), -1);
return default_arguments[p_arg];
}
-
StringName GDFunction::get_name() const {
return name;
@@ -1311,66 +1262,60 @@ struct _GDFKCS {
bool operator<(const _GDFKCS &p_r) const {
- return order<p_r.order;
+ return order < p_r.order;
}
};
-void GDFunction::debug_get_stack_member_state(int p_line,List<Pair<StringName,int> > *r_stackvars) const {
+void GDFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, int> > *r_stackvars) const {
+ int oc = 0;
+ Map<StringName, _GDFKC> sdmap;
+ for (const List<StackDebug>::Element *E = stack_debug.front(); E; E = E->next()) {
- int oc=0;
- Map<StringName,_GDFKC> sdmap;
- for( const List<StackDebug>::Element *E=stack_debug.front();E;E=E->next()) {
-
- const StackDebug &sd=E->get();
- if (sd.line>p_line)
+ const StackDebug &sd = E->get();
+ if (sd.line > p_line)
break;
if (sd.added) {
if (!sdmap.has(sd.identifier)) {
_GDFKC d;
- d.order=oc++;
+ d.order = oc++;
d.pos.push_back(sd.pos);
- sdmap[sd.identifier]=d;
+ sdmap[sd.identifier] = d;
} else {
sdmap[sd.identifier].pos.push_back(sd.pos);
}
} else {
-
ERR_CONTINUE(!sdmap.has(sd.identifier));
sdmap[sd.identifier].pos.pop_back();
if (sdmap[sd.identifier].pos.empty())
sdmap.erase(sd.identifier);
}
-
}
-
List<_GDFKCS> stackpositions;
- for(Map<StringName,_GDFKC>::Element *E=sdmap.front();E;E=E->next() ) {
+ for (Map<StringName, _GDFKC>::Element *E = sdmap.front(); E; E = E->next()) {
_GDFKCS spp;
- spp.id=E->key();
- spp.order=E->get().order;
- spp.pos=E->get().pos.back()->get();
+ spp.id = E->key();
+ spp.order = E->get().order;
+ spp.pos = E->get().pos.back()->get();
stackpositions.push_back(spp);
}
stackpositions.sort();
- for(List<_GDFKCS>::Element *E=stackpositions.front();E;E=E->next()) {
+ for (List<_GDFKCS>::Element *E = stackpositions.front(); E; E = E->next()) {
- Pair<StringName,int> p;
- p.first=E->get().id;
- p.second=E->get().pos;
+ Pair<StringName, int> p;
+ p.first = E->get().id;
+ p.second = E->get().pos;
r_stackvars->push_back(p);
}
-
-
}
#if 0
@@ -1389,14 +1334,15 @@ void GDFunction::clear() {
}
#endif
-GDFunction::GDFunction() : function_list(this) {
+GDFunction::GDFunction()
+ : function_list(this) {
- _stack_size=0;
- _call_size=0;
- rpc_mode=ScriptInstance::RPC_MODE_DISABLED;
- name="<anonymous>";
+ _stack_size = 0;
+ _call_size = 0;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
+ name = "<anonymous>";
#ifdef DEBUG_ENABLED
- _func_cname=NULL;
+ _func_cname = NULL;
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->lock();
@@ -1407,20 +1353,20 @@ GDFunction::GDFunction() : function_list(this) {
GDScriptLanguage::get_singleton()->lock->unlock();
}
- profile.call_count=0;
- profile.self_time=0;
- profile.total_time=0;
- profile.frame_call_count=0;
- profile.frame_self_time=0;
- profile.frame_total_time=0;
- profile.last_frame_call_count=0;
- profile.last_frame_self_time=0;
- profile.last_frame_total_time=0;
+ profile.call_count = 0;
+ profile.self_time = 0;
+ profile.total_time = 0;
+ profile.frame_call_count = 0;
+ profile.frame_self_time = 0;
+ profile.frame_total_time = 0;
+ profile.last_frame_call_count = 0;
+ profile.last_frame_self_time = 0;
+ profile.last_frame_total_time = 0;
#endif
}
-GDFunction::~GDFunction() {
+GDFunction::~GDFunction() {
#ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->lock();
@@ -1435,8 +1381,7 @@ GDFunction::~GDFunction() {
/////////////////////
-
-Variant GDFunctionState::_signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
+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)) {
@@ -1451,51 +1396,50 @@ Variant GDFunctionState::_signal_callback(const Variant** p_args, int p_argcount
#endif
Variant arg;
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
- ERR_FAIL_COND_V(!function,Variant());
+ ERR_FAIL_COND_V(!function, Variant());
- if (p_argcount==0) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
+ if (p_argcount == 0) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
return Variant();
- } else if (p_argcount==1) {
+ } else if (p_argcount == 1) {
//noooneee
- } else if (p_argcount==2) {
- arg=*p_args[0];
+ } else if (p_argcount == 2) {
+ arg = *p_args[0];
} else {
Array extra_args;
- for(int i=0;i<p_argcount-1;i++) {
+ for (int i = 0; i < p_argcount - 1; i++) {
extra_args.push_back(*p_args[i]);
}
- arg=extra_args;
+ arg = extra_args;
}
- Ref<GDFunctionState> self = *p_args[p_argcount-1];
+ Ref<GDFunctionState> self = *p_args[p_argcount - 1];
if (self.is_null()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=p_argcount-1;
- r_error.expected=Variant::OBJECT;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = p_argcount - 1;
+ r_error.expected = Variant::OBJECT;
return Variant();
}
- state.result=arg;
- Variant ret = function->call(NULL,NULL,0,r_error,&state);
- function=NULL; //cleaned up;
- state.result=Variant();
+ state.result = arg;
+ Variant ret = function->call(NULL, NULL, 0, r_error, &state);
+ function = NULL; //cleaned up;
+ state.result = Variant();
return ret;
}
-
bool GDFunctionState::is_valid() const {
- return function!=NULL;
+ return function != NULL;
}
-Variant GDFunctionState::resume(const Variant& p_arg) {
+Variant GDFunctionState::resume(const Variant &p_arg) {
- ERR_FAIL_COND_V(!function,Variant());
+ 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");
@@ -1508,36 +1452,33 @@ Variant GDFunctionState::resume(const Variant& p_arg) {
}
#endif
- state.result=p_arg;
+ state.result = p_arg;
Variant::CallError err;
- Variant ret = function->call(NULL,NULL,0,err,&state);
- function=NULL; //cleaned up;
- state.result=Variant();
+ Variant ret = function->call(NULL, NULL, 0, err, &state);
+ function = NULL; //cleaned up;
+ state.result = Variant();
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_vararg_method(METHOD_FLAGS_DEFAULT,"_signal_callback",&GDFunctionState::_signal_callback,MethodInfo("_signal_callback"));
-
+ ClassDB::bind_method(D_METHOD("resume:Variant", "arg"), &GDFunctionState::resume, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("is_valid"), &GDFunctionState::is_valid);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDFunctionState::_signal_callback, MethodInfo("_signal_callback"));
}
GDFunctionState::GDFunctionState() {
- function=NULL;
+ function = NULL;
}
GDFunctionState::~GDFunctionState() {
- if (function!=NULL) {
+ if (function != NULL) {
//never called, deinitialize stack
- for(int i=0;i<state.stack_size;i++) {
- Variant *v=(Variant*)&state.stack[sizeof(Variant)*i];
+ for (int i = 0; i < state.stack_size; i++) {
+ Variant *v = (Variant *)&state.stack[sizeof(Variant) * i];
v->~Variant();
}
}
}
-
diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h
index aff6341601..321b3b6cfa 100644
--- a/modules/gdscript/gd_function.h
+++ b/modules/gdscript/gd_function.h
@@ -29,21 +29,19 @@
#ifndef GD_FUNCTION_H
#define GD_FUNCTION_H
-#include "self_list.h"
#include "os/thread.h"
#include "pair.h"
-#include "variant.h"
-#include "string_db.h"
#include "reference.h"
#include "script_language.h"
+#include "self_list.h"
+#include "string_db.h"
+#include "variant.h"
class GDInstance;
class GDScript;
-
class GDFunction {
public:
-
enum Opcode {
OPCODE_OPERATOR,
OPCODE_EXTENDS_TEST,
@@ -81,18 +79,18 @@ public:
};
enum Address {
- ADDR_BITS=24,
- ADDR_MASK=((1<<ADDR_BITS)-1),
- ADDR_TYPE_MASK=~ADDR_MASK,
- ADDR_TYPE_SELF=0,
- ADDR_TYPE_CLASS=1,
- ADDR_TYPE_MEMBER=2,
- ADDR_TYPE_CLASS_CONSTANT=3,
- ADDR_TYPE_LOCAL_CONSTANT=4,
- ADDR_TYPE_STACK=5,
- ADDR_TYPE_STACK_VARIABLE=6,
- ADDR_TYPE_GLOBAL=7,
- ADDR_TYPE_NIL=8
+ ADDR_BITS = 24,
+ ADDR_MASK = ((1 << ADDR_BITS) - 1),
+ ADDR_TYPE_MASK = ~ADDR_MASK,
+ ADDR_TYPE_SELF = 0,
+ ADDR_TYPE_CLASS = 1,
+ ADDR_TYPE_MEMBER = 2,
+ ADDR_TYPE_CLASS_CONSTANT = 3,
+ ADDR_TYPE_LOCAL_CONSTANT = 4,
+ ADDR_TYPE_STACK = 5,
+ ADDR_TYPE_STACK_VARIABLE = 6,
+ ADDR_TYPE_GLOBAL = 7,
+ ADDR_TYPE_NIL = 8
};
enum RPCMode {
@@ -103,16 +101,16 @@ public:
RPC_SYNC_SLAVE
};
- struct StackDebug {
+ struct StackDebug {
- int line;
- int pos;
- bool added;
- StringName identifier;
- };
+ int line;
+ int pos;
+ bool added;
+ StringName identifier;
+ };
private:
-friend class GDCompiler;
+ friend class GDCompiler;
StringName source;
@@ -146,15 +144,15 @@ friend class GDCompiler;
List<StackDebug> stack_debug;
- _FORCE_INLINE_ Variant *_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self,Variant *p_stack,String& r_error) const;
- _FORCE_INLINE_ String _get_call_error(const Variant::CallError& p_err, const String& p_where,const Variant**argptrs) const;
+ _FORCE_INLINE_ Variant *_get_variant(int p_address, GDInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const;
+ _FORCE_INLINE_ String _get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const;
-friend class GDScriptLanguage;
+ friend class GDScriptLanguage;
SelfList<GDFunction> function_list;
#ifdef DEBUG_ENABLED
CharString func_cname;
- const char*_func_cname;
+ const char *_func_cname;
struct Profile {
StringName signature;
@@ -172,9 +170,6 @@ friend class GDScriptLanguage;
#endif
public:
-
-
-
struct CallState {
ObjectID instance_id; //by debug only
@@ -190,12 +185,11 @@ public:
int line;
int defarg;
Variant result;
-
};
_FORCE_INLINE_ bool is_static() const { return _static; }
- const int* get_code() const; //used for debug
+ const int *get_code() const; //used for debug
int get_code_size() const;
Variant get_constant(int p_idx) const;
StringName get_global_name(int p_idx) const;
@@ -206,48 +200,46 @@ public:
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;
+ void debug_get_stack_member_state(int p_line, List<Pair<StringName, int> > *r_stackvars) const;
- _FORCE_INLINE_ bool is_empty() const { return _code_size==0; }
+ _FORCE_INLINE_ bool is_empty() const { return _code_size == 0; }
int get_argument_count() const { return _argument_count; }
StringName get_argument_name(int p_idx) const {
#ifdef TOOLS_ENABLED
- ERR_FAIL_INDEX_V(p_idx,arg_names.size(),StringName());
+ ERR_FAIL_INDEX_V(p_idx, arg_names.size(), StringName());
return arg_names[p_idx];
#endif
return StringName();
-
}
Variant get_default_argument(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx,default_arguments.size(),Variant());
+ ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), Variant());
return default_arguments[p_idx];
}
- Variant call(GDInstance *p_instance,const Variant **p_args, int p_argcount,Variant::CallError& r_err,CallState *p_state=NULL);
+ Variant call(GDInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state = NULL);
_FORCE_INLINE_ ScriptInstance::RPCMode get_rpc_mode() const { return rpc_mode; }
GDFunction();
~GDFunction();
};
-
class GDFunctionState : public Reference {
- GDCLASS(GDFunctionState,Reference);
-friend class GDFunction;
+ GDCLASS(GDFunctionState, Reference);
+ friend class GDFunction;
GDFunction *function;
GDFunction::CallState state;
- Variant _signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
+ Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+
protected:
static void _bind_methods();
-public:
+public:
bool is_valid() const;
- Variant resume(const Variant& p_arg=Variant());
+ Variant resume(const Variant &p_arg = Variant());
GDFunctionState();
~GDFunctionState();
};
-
#endif // GD_FUNCTION_H
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index d0fc241734..fa92f0a194 100644
--- a/modules/gdscript/gd_functions.cpp
+++ b/modules/gdscript/gd_functions.cpp
@@ -27,21 +27,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "gd_functions.h"
-#include "math_funcs.h"
#include "class_db.h"
-#include "reference.h"
-#include "gd_script.h"
#include "func_ref.h"
+#include "gd_script.h"
+#include "io/json.h"
+#include "io/marshalls.h"
+#include "math_funcs.h"
#include "os/os.h"
+#include "reference.h"
#include "variant_parser.h"
-#include "io/marshalls.h"
-#include "io/json.h"
const char *GDFunctions::get_func_name(Function p_func) {
- ERR_FAIL_INDEX_V(p_func,FUNC_MAX,"");
+ ERR_FAIL_INDEX_V(p_func, FUNC_MAX, "");
- static const char *_names[FUNC_MAX]={
+ static const char *_names[FUNC_MAX] = {
"sin",
"cos",
"tan",
@@ -115,35 +115,34 @@ const char *GDFunctions::get_func_name(Function p_func) {
};
return _names[p_func];
-
}
-void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Variant &r_ret,Variant::CallError &r_error) {
+void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Variant::CallError &r_error) {
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
#ifdef DEBUG_ENABLED
-#define VALIDATE_ARG_COUNT(m_count) \
- if (p_arg_count<m_count) {\
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;\
- r_error.argument=m_count;\
- r_ret=Variant();\
- return;\
- }\
- if (p_arg_count>m_count) {\
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;\
- r_error.argument=m_count;\
- r_ret=Variant();\
- return;\
+#define VALIDATE_ARG_COUNT(m_count) \
+ if (p_arg_count < m_count) { \
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; \
+ r_error.argument = m_count; \
+ r_ret = Variant(); \
+ return; \
+ } \
+ if (p_arg_count > m_count) { \
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; \
+ r_error.argument = m_count; \
+ r_ret = Variant(); \
+ return; \
}
-#define VALIDATE_ARG_NUM(m_arg) \
- if (!p_args[m_arg]->is_num()) {\
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\
- r_error.argument=m_arg;\
- r_error.expected=Variant::REAL;\
- r_ret=Variant();\
- return;\
+#define VALIDATE_ARG_NUM(m_arg) \
+ if (!p_args[m_arg]->is_num()) { \
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \
+ r_error.argument = m_arg; \
+ r_error.expected = Variant::REAL; \
+ r_ret = Variant(); \
+ return; \
}
#else
@@ -154,245 +153,245 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
//using a switch, so the compiler generates a jumptable
- switch(p_func) {
+ switch (p_func) {
case MATH_SIN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::sin((double)*p_args[0]);
+ r_ret = Math::sin((double)*p_args[0]);
} break;
case MATH_COS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::cos((double)*p_args[0]);
+ r_ret = Math::cos((double)*p_args[0]);
} break;
case MATH_TAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::tan((double)*p_args[0]);
+ r_ret = Math::tan((double)*p_args[0]);
} break;
case MATH_SINH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::sinh((double)*p_args[0]);
+ r_ret = Math::sinh((double)*p_args[0]);
} break;
case MATH_COSH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::cosh((double)*p_args[0]);
+ r_ret = Math::cosh((double)*p_args[0]);
} break;
case MATH_TANH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::tanh((double)*p_args[0]);
+ r_ret = Math::tanh((double)*p_args[0]);
} break;
case MATH_ASIN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::asin((double)*p_args[0]);
+ r_ret = Math::asin((double)*p_args[0]);
} break;
case MATH_ACOS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::acos((double)*p_args[0]);
+ r_ret = Math::acos((double)*p_args[0]);
} break;
case MATH_ATAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::atan((double)*p_args[0]);
+ r_ret = Math::atan((double)*p_args[0]);
} break;
case MATH_ATAN2: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::atan2((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::atan2((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_SQRT: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::sqrt((double)*p_args[0]);
+ r_ret = Math::sqrt((double)*p_args[0]);
} break;
case MATH_FMOD: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::fmod((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::fmod((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_FPOSMOD: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::fposmod((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::fposmod((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_FLOOR: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::floor((double)*p_args[0]);
- } break;
+ r_ret = Math::floor((double)*p_args[0]);
+ } break;
case MATH_CEIL: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::ceil((double)*p_args[0]);
+ r_ret = Math::ceil((double)*p_args[0]);
} break;
case MATH_ROUND: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::round((double)*p_args[0]);
+ r_ret = Math::round((double)*p_args[0]);
} break;
case MATH_ABS: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()==Variant::INT) {
+ if (p_args[0]->get_type() == Variant::INT) {
int64_t i = *p_args[0];
- r_ret=ABS(i);
- } else if (p_args[0]->get_type()==Variant::REAL) {
+ r_ret = ABS(i);
+ } else if (p_args[0]->get_type() == Variant::REAL) {
double r = *p_args[0];
- r_ret=Math::abs(r);
+ r_ret = Math::abs(r);
} else {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::REAL;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::REAL;
+ r_ret = Variant();
}
} break;
case MATH_SIGN: {
- VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()==Variant::INT) {
+ VALIDATE_ARG_COUNT(1);
+ if (p_args[0]->get_type() == Variant::INT) {
- int64_t i = *p_args[0];
- r_ret= i < 0 ? -1 : ( i > 0 ? +1 : 0);
- } else if (p_args[0]->get_type()==Variant::REAL) {
+ int64_t i = *p_args[0];
+ r_ret = i < 0 ? -1 : (i > 0 ? +1 : 0);
+ } else if (p_args[0]->get_type() == Variant::REAL) {
- real_t r = *p_args[0];
- r_ret= r < 0.0 ? -1.0 : ( r > 0.0 ? +1.0 : 0.0);
- } else {
+ real_t r = *p_args[0];
+ r_ret = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0);
+ } else {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::REAL;
- r_ret=Variant();
- }
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::REAL;
+ r_ret = Variant();
+ }
} break;
case MATH_POW: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::pow((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::pow((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_LOG: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::log((double)*p_args[0]);
+ r_ret = Math::log((double)*p_args[0]);
} break;
case MATH_EXP: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::exp((double)*p_args[0]);
+ r_ret = Math::exp((double)*p_args[0]);
} break;
case MATH_ISNAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::is_nan((double)*p_args[0]);
+ r_ret = Math::is_nan((double)*p_args[0]);
} break;
case MATH_ISINF: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::is_inf((double)*p_args[0]);
+ r_ret = Math::is_inf((double)*p_args[0]);
} break;
case MATH_EASE: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::ease((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::ease((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_DECIMALS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::step_decimals((double)*p_args[0]);
+ r_ret = Math::step_decimals((double)*p_args[0]);
} break;
case MATH_STEPIFY: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::stepify((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::stepify((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_LERP: {
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- r_ret=Math::lerp((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]);
+ r_ret = Math::lerp((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]);
} break;
case MATH_DECTIME: {
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- r_ret=Math::dectime((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]);
+ r_ret = Math::dectime((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]);
} break;
case MATH_RANDOMIZE: {
Math::randomize();
- r_ret=Variant();
+ r_ret = Variant();
} break;
case MATH_RAND: {
- r_ret=Math::rand();
+ r_ret = Math::rand();
} break;
case MATH_RANDF: {
- r_ret=Math::randf();
+ r_ret = Math::randf();
} break;
case MATH_RANDOM: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- r_ret=Math::random((double)*p_args[0],(double)*p_args[1]);
+ r_ret = Math::random((double)*p_args[0], (double)*p_args[1]);
} break;
case MATH_SEED: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- uint64_t seed=*p_args[0];
+ uint64_t seed = *p_args[0];
Math::seed(seed);
- r_ret=Variant();
+ r_ret = Variant();
} break;
case MATH_RANDSEED: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- uint64_t seed=*p_args[0];
+ uint64_t seed = *p_args[0];
int ret = Math::rand_from_seed(&seed);
Array reta;
reta.push_back(ret);
reta.push_back(seed);
- r_ret=reta;
+ r_ret = reta;
} break;
case MATH_DEG2RAD: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::deg2rad((double)*p_args[0]);
+ r_ret = Math::deg2rad((double)*p_args[0]);
} break;
case MATH_RAD2DEG: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::rad2deg((double)*p_args[0]);
+ r_ret = Math::rad2deg((double)*p_args[0]);
} break;
case MATH_LINEAR2DB: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::linear2db((double)*p_args[0]);
+ r_ret = Math::linear2db((double)*p_args[0]);
} break;
case MATH_DB2LINEAR: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- r_ret=Math::db2linear((double)*p_args[0]);
+ r_ret = Math::db2linear((double)*p_args[0]);
} break;
case LOGIC_MAX: {
VALIDATE_ARG_COUNT(2);
- if (p_args[0]->get_type()==Variant::INT && p_args[1]->get_type()==Variant::INT) {
+ if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT) {
int64_t a = *p_args[0];
int64_t b = *p_args[1];
- r_ret=MAX(a,b);
+ r_ret = MAX(a, b);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -400,17 +399,17 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
real_t a = *p_args[0];
real_t b = *p_args[1];
- r_ret=MAX(a,b);
+ r_ret = MAX(a, b);
}
} break;
case LOGIC_MIN: {
VALIDATE_ARG_COUNT(2);
- if (p_args[0]->get_type()==Variant::INT && p_args[1]->get_type()==Variant::INT) {
+ if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT) {
int64_t a = *p_args[0];
int64_t b = *p_args[1];
- r_ret=MIN(a,b);
+ r_ret = MIN(a, b);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -418,17 +417,17 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
real_t a = *p_args[0];
real_t b = *p_args[1];
- r_ret=MIN(a,b);
+ r_ret = MIN(a, b);
}
} break;
case LOGIC_CLAMP: {
VALIDATE_ARG_COUNT(3);
- if (p_args[0]->get_type()==Variant::INT && p_args[1]->get_type()==Variant::INT && p_args[2]->get_type()==Variant::INT) {
+ if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT && p_args[2]->get_type() == Variant::INT) {
int64_t a = *p_args[0];
int64_t b = *p_args[1];
int64_t c = *p_args[2];
- r_ret=CLAMP(a,b,c);
+ r_ret = CLAMP(a, b, c);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -438,7 +437,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
real_t b = *p_args[1];
real_t c = *p_args[2];
- r_ret=CLAMP(a,b,c);
+ r_ret = CLAMP(a, b, c);
}
} break;
case LOGIC_NEAREST_PO2: {
@@ -449,87 +448,80 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
} break;
case OBJ_WEAKREF: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::OBJECT) {
+ if (p_args[0]->get_type() != Variant::OBJECT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = Variant();
return;
-
}
if (p_args[0]->is_ref()) {
REF r = *p_args[0];
if (!r.is_valid()) {
- r_ret=Variant();
+ r_ret = Variant();
return;
}
- Ref<WeakRef> wref = memnew( WeakRef );
+ Ref<WeakRef> wref = memnew(WeakRef);
wref->set_ref(r);
- r_ret=wref;
+ r_ret = wref;
} else {
Object *obj = *p_args[0];
if (!obj) {
- r_ret=Variant();
+ r_ret = Variant();
return;
}
- Ref<WeakRef> wref = memnew( WeakRef );
+ Ref<WeakRef> wref = memnew(WeakRef);
wref->set_obj(obj);
- r_ret=wref;
+ r_ret = wref;
}
-
-
-
} break;
case FUNC_FUNCREF: {
VALIDATE_ARG_COUNT(2);
- if (p_args[0]->get_type()!=Variant::OBJECT) {
+ if (p_args[0]->get_type() != Variant::OBJECT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = Variant();
return;
-
}
- if (p_args[1]->get_type()!=Variant::STRING && p_args[1]->get_type()!=Variant::NODE_PATH) {
+ if (p_args[1]->get_type() != Variant::STRING && p_args[1]->get_type() != Variant::NODE_PATH) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=1;
- r_error.expected=Variant::STRING;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 1;
+ r_error.expected = Variant::STRING;
+ r_ret = Variant();
return;
-
}
- Ref<FuncRef> fr = memnew( FuncRef);
+ Ref<FuncRef> fr = memnew(FuncRef);
fr->set_instance(*p_args[0]);
fr->set_function(*p_args[1]);
- r_ret=fr;
+ r_ret = fr;
} break;
case TYPE_CONVERT: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(1);
- int type=*p_args[1];
- if (type<0 || type>=Variant::VARIANT_MAX) {
+ int type = *p_args[1];
+ if (type < 0 || type >= Variant::VARIANT_MAX) {
- r_ret=RTR("Invalid type argument to convert(), use TYPE_* constants.");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::INT;
+ r_ret = RTR("Invalid type argument to convert(), use TYPE_* constants.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::INT;
return;
} else {
-
- r_ret=Variant::construct(Variant::Type(type),p_args,1,r_error);
+ r_ret = Variant::construct(Variant::Type(type), p_args, 1, r_error);
}
} break;
case TYPE_OF: {
@@ -547,125 +539,122 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
case TEXT_CHAR: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
- CharType result[2] = {*p_args[0], 0};
- r_ret=String(result);
+ CharType result[2] = { *p_args[0], 0 };
+ r_ret = String(result);
} break;
case TEXT_STR: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
String os = p_args[i]->operator String();
- if (i==0)
- str=os;
+ if (i == 0)
+ str = os;
else
- str+=os;
+ str += os;
}
- r_ret=str;
+ r_ret = str;
} break;
case TEXT_PRINT: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
- str+=p_args[i]->operator String();
+ str += p_args[i]->operator String();
}
//str+="\n";
print_line(str);
- r_ret=Variant();
-
+ r_ret = Variant();
} break;
case TEXT_PRINT_TABBED: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
if (i)
- str+="\t";
- str+=p_args[i]->operator String();
+ str += "\t";
+ str += p_args[i]->operator String();
}
//str+="\n";
print_line(str);
- r_ret=Variant();
-
+ r_ret = Variant();
} break;
case TEXT_PRINT_SPACED: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
if (i)
- str+=" ";
- str+=p_args[i]->operator String();
+ str += " ";
+ str += p_args[i]->operator String();
}
//str+="\n";
print_line(str);
- r_ret=Variant();
-
+ r_ret = Variant();
} break;
case TEXT_PRINTERR: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
- str+=p_args[i]->operator String();
+ str += p_args[i]->operator String();
}
//str+="\n";
- OS::get_singleton()->printerr("%s\n",str.utf8().get_data());
- r_ret=Variant();
+ OS::get_singleton()->printerr("%s\n", str.utf8().get_data());
+ r_ret = Variant();
} break;
case TEXT_PRINTRAW: {
String str;
- for(int i=0;i<p_arg_count;i++) {
+ for (int i = 0; i < p_arg_count; i++) {
- str+=p_args[i]->operator String();
+ str += p_args[i]->operator String();
}
//str+="\n";
- OS::get_singleton()->print("%s",str.utf8().get_data());
- r_ret=Variant();
+ OS::get_singleton()->print("%s", str.utf8().get_data());
+ r_ret = Variant();
} break;
case VAR_TO_STR: {
VALIDATE_ARG_COUNT(1);
String vars;
- VariantWriter::write_to_string(*p_args[0],vars);
- r_ret=vars;
+ VariantWriter::write_to_string(*p_args[0], vars);
+ r_ret = vars;
} break;
case STR_TO_VAR: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ r_ret = Variant();
return;
}
VariantParser::StreamString ss;
- ss.s=*p_args[0];
+ ss.s = *p_args[0];
String errs;
int line;
- Error err = VariantParser::parse(&ss,r_ret,errs,line);
+ Error err = VariantParser::parse(&ss, r_ret, errs, line);
- if (err!=OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- r_ret="Parse error at line "+itos(line)+": "+errs;
+ if (err != OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ r_ret = "Parse error at line " + itos(line) + ": " + errs;
return;
}
@@ -675,106 +664,104 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
PoolByteArray barr;
int len;
- Error err = encode_variant(*p_args[0],NULL,len);
+ Error err = encode_variant(*p_args[0], NULL, len);
if (err) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::NIL;
- r_ret="Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID).";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::NIL;
+ r_ret = "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID).";
return;
}
barr.resize(len);
{
PoolByteArray::Write w = barr.write();
- encode_variant(*p_args[0],w.ptr(),len);
-
+ encode_variant(*p_args[0], w.ptr(), len);
}
- r_ret=barr;
+ r_ret = barr;
} break;
case BYTES_TO_VAR: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::POOL_BYTE_ARRAY) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::POOL_BYTE_ARRAY;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::POOL_BYTE_ARRAY) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::POOL_BYTE_ARRAY;
+ r_ret = Variant();
return;
}
- PoolByteArray varr=*p_args[0];
+ PoolByteArray varr = *p_args[0];
Variant ret;
{
- PoolByteArray::Read r=varr.read();
- Error err = decode_variant(ret,r.ptr(),varr.size(),NULL);
- if (err!=OK) {
- r_ret=RTR("Not enough bytes for decoding bytes, or invalid format.");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::POOL_BYTE_ARRAY;
+ PoolByteArray::Read r = varr.read();
+ Error err = decode_variant(ret, r.ptr(), varr.size(), NULL);
+ if (err != OK) {
+ r_ret = RTR("Not enough bytes for decoding bytes, or invalid format.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::POOL_BYTE_ARRAY;
return;
}
-
}
- r_ret=ret;
+ r_ret = ret;
} break;
case GEN_RANGE: {
- switch(p_arg_count) {
+ switch (p_arg_count) {
case 0: {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
+ r_ret = Variant();
} break;
case 1: {
VALIDATE_ARG_NUM(0);
- int count=*p_args[0];
+ int count = *p_args[0];
Array arr;
- if (count<=0) {
- r_ret=arr;
+ if (count <= 0) {
+ r_ret = arr;
return;
}
Error err = arr.resize(count);
- if (err!=OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_ret=Variant();
+ if (err != OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_ret = Variant();
return;
}
- for(int i=0;i<count;i++) {
- arr[i]=i;
+ for (int i = 0; i < count; i++) {
+ arr[i] = i;
}
- r_ret=arr;
+ r_ret = arr;
} break;
case 2: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- int from=*p_args[0];
- int to=*p_args[1];
+ int from = *p_args[0];
+ int to = *p_args[1];
Array arr;
- if (from>=to) {
- r_ret=arr;
+ if (from >= to) {
+ r_ret = arr;
return;
}
- Error err = arr.resize(to-from);
- if (err!=OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_ret=Variant();
+ Error err = arr.resize(to - from);
+ if (err != OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_ret = Variant();
return;
}
- for(int i=from;i<to;i++)
- arr[i-from]=i;
- r_ret=arr;
+ for (int i = from; i < to; i++)
+ arr[i - from] = i;
+ r_ret = arr;
} break;
case 3: {
@@ -782,65 +769,64 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- int from=*p_args[0];
- int to=*p_args[1];
- int incr=*p_args[2];
- if (incr==0) {
+ int from = *p_args[0];
+ int to = *p_args[1];
+ int incr = *p_args[2];
+ if (incr == 0) {
- r_ret=RTR("step argument is zero!");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_ret = RTR("step argument is zero!");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return;
}
Array arr;
- if (from>=to && incr>0) {
- r_ret=arr;
+ if (from >= to && incr > 0) {
+ r_ret = arr;
return;
}
- if (from<=to && incr<0) {
- r_ret=arr;
+ if (from <= to && incr < 0) {
+ r_ret = arr;
return;
}
//calculate how many
- int count=0;
- if (incr>0) {
+ int count = 0;
+ if (incr > 0) {
- count=((to-from-1)/incr)+1;
+ count = ((to - from - 1) / incr) + 1;
} else {
- count=((from-to-1)/-incr)+1;
+ count = ((from - to - 1) / -incr) + 1;
}
-
Error err = arr.resize(count);
- if (err!=OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_ret=Variant();
+ if (err != OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_ret = Variant();
return;
}
- if (incr>0) {
- int idx=0;
- for(int i=from;i<to;i+=incr) {
- arr[idx++]=i;
+ if (incr > 0) {
+ int idx = 0;
+ for (int i = from; i < to; i += incr) {
+ arr[idx++] = i;
}
} else {
- int idx=0;
- for(int i=from;i>to;i+=incr) {
- arr[idx++]=i;
+ int idx = 0;
+ for (int i = from; i > to; i += incr) {
+ arr[idx++] = i;
}
}
- r_ret=arr;
+ r_ret = arr;
} break;
default: {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument=3;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = 3;
+ r_ret = Variant();
} break;
}
@@ -848,13 +834,13 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
} break;
case RESOURCE_LOAD: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ r_ret = Variant();
} else {
- r_ret=ResourceLoader::load(*p_args[0]);
+ r_ret = ResourceLoader::load(*p_args[0]);
}
} break;
@@ -862,91 +848,85 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()==Variant::NIL) {
- r_ret=Variant();
- } else if (p_args[0]->get_type()!=Variant::OBJECT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_ret=Variant();
+ if (p_args[0]->get_type() == Variant::NIL) {
+ r_ret = Variant();
+ } else if (p_args[0]->get_type() != Variant::OBJECT) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_ret = Variant();
} else {
Object *obj = *p_args[0];
if (!obj) {
- r_ret=Variant();
+ r_ret = Variant();
- } else if (!obj->get_script_instance() || obj->get_script_instance()->get_language()!=GDScriptLanguage::get_singleton()) {
+ } else if (!obj->get_script_instance() || obj->get_script_instance()->get_language() != GDScriptLanguage::get_singleton()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::DICTIONARY;
- r_ret=RTR("Not a script with an instance");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::DICTIONARY;
+ r_ret = RTR("Not a script with an instance");
return;
} else {
- GDInstance *ins = static_cast<GDInstance*>(obj->get_script_instance());
+ GDInstance *ins = static_cast<GDInstance *>(obj->get_script_instance());
Ref<GDScript> base = ins->get_script();
if (base.is_null()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::DICTIONARY;
- r_ret=RTR("Not based on a script");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::DICTIONARY;
+ r_ret = RTR("Not based on a script");
return;
-
}
-
GDScript *p = base.ptr();
Vector<StringName> sname;
- while(p->_owner) {
+ while (p->_owner) {
sname.push_back(p->name);
- p=p->_owner;
+ p = p->_owner;
}
sname.invert();
-
if (!p->path.is_resource_file()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::DICTIONARY;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::DICTIONARY;
+ r_ret = Variant();
-
- r_ret=RTR("Not based on a resource file");
+ r_ret = RTR("Not based on a resource file");
return;
}
- NodePath cp(sname,Vector<StringName>(),false);
+ NodePath cp(sname, Vector<StringName>(), false);
Dictionary d;
- d["@subpath"]=cp;
- d["@path"]=p->path;
-
+ d["@subpath"] = cp;
+ d["@path"] = p->path;
p = base.ptr();
- while(p) {
+ while (p) {
- for(Set<StringName>::Element *E=p->members.front();E;E=E->next()) {
+ for (Set<StringName>::Element *E = p->members.front(); E; E = E->next()) {
Variant value;
- if (ins->get(E->get(),value)) {
+ if (ins->get(E->get(), value)) {
String k = E->get();
if (!d.has(k)) {
- d[k]=value;
+ d[k] = value;
}
}
}
- p=p->_base;
+ p = p->_base;
}
- r_ret=d;
-
+ r_ret = d;
}
}
@@ -955,12 +935,12 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::DICTIONARY) {
+ if (p_args[0]->get_type() != Variant::DICTIONARY) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::DICTIONARY;
- r_ret=Variant();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::DICTIONARY;
+ r_ret = Variant();
return;
}
@@ -969,10 +949,10 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
if (!d.has("@path")) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=RTR("Invalid instance dictionary format (missing @path)");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = RTR("Invalid instance dictionary format (missing @path)");
return;
}
@@ -980,10 +960,10 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
Ref<Script> scr = ResourceLoader::load(d["@path"]);
if (!scr.is_valid()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=RTR("Invalid instance dictionary format (can't load script at @path)");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = RTR("Invalid instance dictionary format (can't load script at @path)");
return;
}
@@ -991,40 +971,40 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
if (!gdscr.is_valid()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=Variant();
- r_ret=RTR("Invalid instance dictionary format (invalid script at @path)");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = Variant();
+ r_ret = RTR("Invalid instance dictionary format (invalid script at @path)");
return;
}
NodePath sub;
if (d.has("@subpath")) {
- sub=d["@subpath"];
+ sub = d["@subpath"];
}
- for(int i=0;i<sub.get_name_count();i++) {
+ for (int i = 0; i < sub.get_name_count(); i++) {
- gdscr = gdscr->subclasses[ sub.get_name(i)];
+ gdscr = gdscr->subclasses[sub.get_name(i)];
if (!gdscr.is_valid()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
- r_ret=Variant();
- r_ret=RTR("Invalid instance dictionary (invalid subclasses)");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
+ r_ret = Variant();
+ r_ret = RTR("Invalid instance dictionary (invalid subclasses)");
return;
}
}
- r_ret = gdscr->_new(NULL,0,r_error);
+ r_ret = gdscr->_new(NULL, 0, r_error);
- GDInstance *ins = static_cast<GDInstance*>(static_cast<Object*>(r_ret)->get_script_instance());
+ GDInstance *ins = static_cast<GDInstance *>(static_cast<Object *>(r_ret)->get_script_instance());
Ref<GDScript> gd_ref = ins->get_script();
- for(Map<StringName,GDScript::MemberInfo>::Element *E = gd_ref->member_indices.front(); E; E = E->next()) {
- if(d.has(E->key())) {
+ for (Map<StringName, GDScript::MemberInfo>::Element *E = gd_ref->member_indices.front(); E; E = E->next()) {
+ if (d.has(E->key())) {
ins->members[E->get().index] = d[E->key()];
}
}
@@ -1034,23 +1014,23 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ r_ret = Variant();
return;
}
String errs;
int errl;
- Error err = JSON::parse(*p_args[0],r_ret,errs,errl);
+ Error err = JSON::parse(*p_args[0], r_ret, errs, errl);
- if (err!=OK) {
- r_ret=itos(errl)+":"+errs;
+ if (err != OK) {
+ r_ret = itos(errl) + ":" + errs;
} else {
- r_ret="";
+ r_ret = "";
}
} break;
@@ -1058,21 +1038,21 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ r_ret = Variant();
return;
}
String errs;
int errl;
- Error err = JSON::parse(*p_args[0],r_ret,errs,errl);
+ Error err = JSON::parse(*p_args[0], r_ret, errs, errl);
- if (err!=OK) {
- r_ret=Variant();
+ if (err != OK) {
+ r_ret = Variant();
}
} break;
@@ -1084,22 +1064,22 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
case HASH: {
VALIDATE_ARG_COUNT(1);
- r_ret=p_args[0]->hash();
+ r_ret = p_args[0]->hash();
} break;
case COLOR8: {
- if (p_arg_count<3) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=3;
- r_ret=Variant();
+ if (p_arg_count < 3) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 3;
+ r_ret = Variant();
return;
}
- if (p_arg_count>4) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument=4;
- r_ret=Variant();
+ if (p_arg_count > 4) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = 4;
+ r_ret = Variant();
return;
}
@@ -1108,78 +1088,76 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- Color color((float)*p_args[0]/255.0f,(float)*p_args[1]/255.0f,(float)*p_args[2]/255.0f);
+ Color color((float)*p_args[0] / 255.0f, (float)*p_args[1] / 255.0f, (float)*p_args[2] / 255.0f);
- if (p_arg_count==4) {
+ if (p_arg_count == 4) {
VALIDATE_ARG_NUM(3);
- color.a=(float)*p_args[3]/255.0f;
+ color.a = (float)*p_args[3] / 255.0f;
}
- r_ret=color;
+ r_ret = color;
} break;
case COLORN: {
- if (p_arg_count<1) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
- r_ret=Variant();
+ if (p_arg_count < 1) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
+ r_ret = Variant();
return;
}
- if (p_arg_count>2) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument=2;
- r_ret=Variant();
+ if (p_arg_count > 2) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = 2;
+ r_ret = Variant();
return;
}
-
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_ret=Variant();
+
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_ret = Variant();
} else {
Color color = Color::named(*p_args[0]);
- if (p_arg_count==2) {
+ if (p_arg_count == 2) {
VALIDATE_ARG_NUM(1);
- color.a=*p_args[1];
+ color.a = *p_args[1];
}
- r_ret=color;
+ r_ret = color;
}
} break;
case PRINT_STACK: {
- ScriptLanguage* script = GDScriptLanguage::get_singleton();
- for (int i=0; i < script->debug_get_stack_level_count(); i++) {
+ ScriptLanguage *script = GDScriptLanguage::get_singleton();
+ for (int i = 0; i < script->debug_get_stack_level_count(); i++) {
- print_line("Frame "+itos(i)+" - "+script->debug_get_stack_level_source(i)+":"+itos(script->debug_get_stack_level_line(i))+" in function '"+script->debug_get_stack_level_function(i)+"'");
+ print_line("Frame " + itos(i) + " - " + script->debug_get_stack_level_source(i) + ":" + itos(script->debug_get_stack_level_line(i)) + " in function '" + script->debug_get_stack_level_function(i) + "'");
};
} break;
case INSTANCE_FROM_ID: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::INT;
- r_ret=Variant();
+ if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::REAL) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::INT;
+ r_ret = Variant();
break;
}
- uint32_t id=*p_args[0];
- r_ret=ObjectDB::get_instance(id);
+ uint32_t id = *p_args[0];
+ r_ret = ObjectDB::get_instance(id);
} break;
case FUNC_MAX: {
ERR_FAIL();
} break;
-
}
-
}
bool GDFunctions::is_deterministic(Function p_func) {
@@ -1187,7 +1165,7 @@ bool GDFunctions::is_deterministic(Function p_func) {
//man i couldn't have chosen a worse function name,
//way too controversial..
- switch(p_func) {
+ switch (p_func) {
case MATH_SIN:
case MATH_COS:
@@ -1231,16 +1209,13 @@ bool GDFunctions::is_deterministic(Function p_func) {
case TEXT_CHAR:
case TEXT_STR:
case COLOR8:
-// enable for debug only, otherwise not desirable - case GEN_RANGE:
+ // enable for debug only, otherwise not desirable - case GEN_RANGE:
return true;
default:
return false;
-
}
return false;
-
-
}
MethodInfo GDFunctions::get_info(Function p_func) {
@@ -1248,401 +1223,401 @@ MethodInfo GDFunctions::get_info(Function p_func) {
#ifdef TOOLS_ENABLED
//using a switch, so the compiler generates a jumptable
- switch(p_func) {
+ switch (p_func) {
case MATH_SIN: {
- MethodInfo mi("sin",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("sin", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_COS: {
- MethodInfo mi("cos",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("cos", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_TAN: {
- MethodInfo mi("tan",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("tan", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_SINH: {
- MethodInfo mi("sinh",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("sinh", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_COSH: {
- MethodInfo mi("cosh",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("cosh", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_TANH: {
- MethodInfo mi("tanh",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("tanh", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ASIN: {
- MethodInfo mi("asin",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("asin", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ACOS: {
- MethodInfo mi("acos",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("acos", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ATAN: {
- MethodInfo mi("atan",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("atan", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ATAN2: {
- MethodInfo mi("atan2",PropertyInfo(Variant::REAL,"x"),PropertyInfo(Variant::REAL,"y"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("atan2", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_SQRT: {
- MethodInfo mi("sqrt",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("sqrt", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_FMOD: {
- MethodInfo mi("fmod",PropertyInfo(Variant::REAL,"x"),PropertyInfo(Variant::REAL,"y"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("fmod", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_FPOSMOD: {
- MethodInfo mi("fposmod",PropertyInfo(Variant::REAL,"x"),PropertyInfo(Variant::REAL,"y"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("fposmod", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_FLOOR: {
- MethodInfo mi("floor",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("floor", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
- } break;
+ } break;
case MATH_CEIL: {
- MethodInfo mi("ceil",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("ceil", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ROUND: {
- MethodInfo mi("round",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("round", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ABS: {
- MethodInfo mi("abs",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("abs", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_SIGN: {
- MethodInfo mi("sign",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("sign", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_POW: {
- MethodInfo mi("pow",PropertyInfo(Variant::REAL,"x"),PropertyInfo(Variant::REAL,"y"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("pow", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_LOG: {
- MethodInfo mi("log",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("log", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_EXP: {
- MethodInfo mi("exp",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("exp", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ISNAN: {
- MethodInfo mi("is_nan",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("is_nan", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_ISINF: {
- MethodInfo mi("is_inf",PropertyInfo(Variant::REAL,"s"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("is_inf", PropertyInfo(Variant::REAL, "s"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_EASE: {
- MethodInfo mi("ease",PropertyInfo(Variant::REAL,"s"),PropertyInfo(Variant::REAL,"curve"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("ease", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "curve"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_DECIMALS: {
- MethodInfo mi("decimals",PropertyInfo(Variant::REAL,"step"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("decimals", PropertyInfo(Variant::REAL, "step"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_STEPIFY: {
- MethodInfo mi("stepify",PropertyInfo(Variant::REAL,"s"),PropertyInfo(Variant::REAL,"step"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("stepify", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "step"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_LERP: {
- MethodInfo mi("lerp",PropertyInfo(Variant::REAL,"from"),PropertyInfo(Variant::REAL,"to"), PropertyInfo(Variant::REAL,"weight"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("lerp", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_DECTIME: {
- MethodInfo mi("dectime",PropertyInfo(Variant::REAL,"value"),PropertyInfo(Variant::REAL,"amount"),PropertyInfo(Variant::REAL,"step"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("dectime", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "amount"), PropertyInfo(Variant::REAL, "step"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_RANDOMIZE: {
MethodInfo mi("randomize");
- mi.return_val.type=Variant::NIL;
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case MATH_RAND: {
MethodInfo mi("randi");
- mi.return_val.type=Variant::INT;
+ mi.return_val.type = Variant::INT;
return mi;
} break;
case MATH_RANDF: {
MethodInfo mi("randf");
- mi.return_val.type=Variant::REAL;
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_RANDOM: {
- MethodInfo mi("rand_range",PropertyInfo(Variant::REAL,"from"),PropertyInfo(Variant::REAL,"to"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("rand_range", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_SEED: {
- MethodInfo mi("seed",PropertyInfo(Variant::INT,"seed"));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("seed", PropertyInfo(Variant::INT, "seed"));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case MATH_RANDSEED: {
- MethodInfo mi("rand_seed",PropertyInfo(Variant::INT,"seed"));
- mi.return_val.type=Variant::ARRAY;
+ MethodInfo mi("rand_seed", PropertyInfo(Variant::INT, "seed"));
+ mi.return_val.type = Variant::ARRAY;
return mi;
} break;
case MATH_DEG2RAD: {
- MethodInfo mi("deg2rad",PropertyInfo(Variant::REAL,"deg"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("deg2rad", PropertyInfo(Variant::REAL, "deg"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_RAD2DEG: {
- MethodInfo mi("rad2deg",PropertyInfo(Variant::REAL,"rad"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("rad2deg", PropertyInfo(Variant::REAL, "rad"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_LINEAR2DB: {
- MethodInfo mi("linear2db",PropertyInfo(Variant::REAL,"nrg"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("linear2db", PropertyInfo(Variant::REAL, "nrg"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case MATH_DB2LINEAR: {
- MethodInfo mi("db2linear",PropertyInfo(Variant::REAL,"db"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("db2linear", PropertyInfo(Variant::REAL, "db"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case LOGIC_MAX: {
- MethodInfo mi("max",PropertyInfo(Variant::REAL,"a"),PropertyInfo(Variant::REAL,"b"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("max", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case LOGIC_MIN: {
- MethodInfo mi("min",PropertyInfo(Variant::REAL,"a"),PropertyInfo(Variant::REAL,"b"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("min", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case LOGIC_CLAMP: {
- MethodInfo mi("clamp",PropertyInfo(Variant::REAL,"val"),PropertyInfo(Variant::REAL,"min"),PropertyInfo(Variant::REAL,"max"));
- mi.return_val.type=Variant::REAL;
+ MethodInfo mi("clamp", PropertyInfo(Variant::REAL, "val"), PropertyInfo(Variant::REAL, "min"), PropertyInfo(Variant::REAL, "max"));
+ mi.return_val.type = Variant::REAL;
return mi;
} break;
case LOGIC_NEAREST_PO2: {
- MethodInfo mi("nearest_po2",PropertyInfo(Variant::INT,"val"));
- mi.return_val.type=Variant::INT;
+ MethodInfo mi("nearest_po2", PropertyInfo(Variant::INT, "val"));
+ mi.return_val.type = Variant::INT;
return mi;
} break;
case OBJ_WEAKREF: {
- MethodInfo mi("weakref",PropertyInfo(Variant::OBJECT,"obj"));
- mi.return_val.type=Variant::OBJECT;
- mi.return_val.name="WeakRef";
+ MethodInfo mi("weakref", PropertyInfo(Variant::OBJECT, "obj"));
+ mi.return_val.type = Variant::OBJECT;
+ mi.return_val.name = "WeakRef";
return mi;
} break;
case FUNC_FUNCREF: {
- MethodInfo mi("funcref",PropertyInfo(Variant::OBJECT,"instance"),PropertyInfo(Variant::STRING,"funcname"));
- mi.return_val.type=Variant::OBJECT;
- mi.return_val.name="FuncRef";
+ MethodInfo mi("funcref", PropertyInfo(Variant::OBJECT, "instance"), PropertyInfo(Variant::STRING, "funcname"));
+ mi.return_val.type = Variant::OBJECT;
+ mi.return_val.name = "FuncRef";
return mi;
} break;
case TYPE_CONVERT: {
- MethodInfo mi("convert",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::INT,"type"));
- mi.return_val.type=Variant::OBJECT;
+ MethodInfo mi("convert", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::INT, "type"));
+ mi.return_val.type = Variant::OBJECT;
return mi;
} break;
case TYPE_OF: {
- MethodInfo mi("typeof",PropertyInfo(Variant::NIL,"what"));
- mi.return_val.type=Variant::INT;
+ MethodInfo mi("typeof", PropertyInfo(Variant::NIL, "what"));
+ mi.return_val.type = Variant::INT;
return mi;
} break;
case TYPE_EXISTS: {
- MethodInfo mi("type_exists",PropertyInfo(Variant::STRING,"type"));
- mi.return_val.type=Variant::BOOL;
+ MethodInfo mi("type_exists", PropertyInfo(Variant::STRING, "type"));
+ mi.return_val.type = Variant::BOOL;
return mi;
} break;
case TEXT_CHAR: {
- MethodInfo mi("char",PropertyInfo(Variant::INT,"ascii"));
- mi.return_val.type=Variant::STRING;
+ MethodInfo mi("char", PropertyInfo(Variant::INT, "ascii"));
+ mi.return_val.type = Variant::STRING;
return mi;
} break;
case TEXT_STR: {
- MethodInfo mi("str",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::STRING;
+ MethodInfo mi("str", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::STRING;
return mi;
} break;
case TEXT_PRINT: {
- MethodInfo mi("print",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("print", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case TEXT_PRINT_TABBED: {
- MethodInfo mi("printt",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("printt", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case TEXT_PRINT_SPACED: {
- MethodInfo mi("prints",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("prints", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case TEXT_PRINTERR: {
- MethodInfo mi("printerr",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("printerr", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case TEXT_PRINTRAW: {
- MethodInfo mi("printraw",PropertyInfo(Variant::NIL,"what"),PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("printraw", PropertyInfo(Variant::NIL, "what"), PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case VAR_TO_STR: {
- MethodInfo mi("var2str",PropertyInfo(Variant::NIL,"var"));
- mi.return_val.type=Variant::STRING;
+ MethodInfo mi("var2str", PropertyInfo(Variant::NIL, "var"));
+ mi.return_val.type = Variant::STRING;
return mi;
} break;
case STR_TO_VAR: {
- MethodInfo mi("str2var:Variant",PropertyInfo(Variant::STRING,"string"));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("str2var:Variant", PropertyInfo(Variant::STRING, "string"));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case VAR_TO_BYTES: {
- MethodInfo mi("var2bytes",PropertyInfo(Variant::NIL,"var"));
- mi.return_val.type=Variant::POOL_BYTE_ARRAY;
+ MethodInfo mi("var2bytes", PropertyInfo(Variant::NIL, "var"));
+ mi.return_val.type = Variant::POOL_BYTE_ARRAY;
return mi;
} break;
case BYTES_TO_VAR: {
- MethodInfo mi("bytes2var:Variant",PropertyInfo(Variant::POOL_BYTE_ARRAY,"bytes"));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("bytes2var:Variant", PropertyInfo(Variant::POOL_BYTE_ARRAY, "bytes"));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case GEN_RANGE: {
- MethodInfo mi("range",PropertyInfo(Variant::NIL,"..."));
- mi.return_val.type=Variant::ARRAY;
+ MethodInfo mi("range", PropertyInfo(Variant::NIL, "..."));
+ mi.return_val.type = Variant::ARRAY;
return mi;
} break;
case RESOURCE_LOAD: {
- MethodInfo mi("load",PropertyInfo(Variant::STRING,"path"));
- mi.return_val.type=Variant::OBJECT;
- mi.return_val.name="Resource";
+ MethodInfo mi("load", PropertyInfo(Variant::STRING, "path"));
+ mi.return_val.type = Variant::OBJECT;
+ mi.return_val.name = "Resource";
return mi;
} break;
case INST2DICT: {
- MethodInfo mi("inst2dict",PropertyInfo(Variant::OBJECT,"inst"));
- mi.return_val.type=Variant::DICTIONARY;
+ MethodInfo mi("inst2dict", PropertyInfo(Variant::OBJECT, "inst"));
+ mi.return_val.type = Variant::DICTIONARY;
return mi;
} break;
case DICT2INST: {
- MethodInfo mi("dict2inst",PropertyInfo(Variant::DICTIONARY,"dict"));
- mi.return_val.type=Variant::OBJECT;
+ MethodInfo mi("dict2inst", PropertyInfo(Variant::DICTIONARY, "dict"));
+ mi.return_val.type = Variant::OBJECT;
return mi;
} break;
case VALIDATE_JSON: {
- MethodInfo mi("validate_json:Variant",PropertyInfo(Variant::STRING,"json"));
- mi.return_val.type=Variant::STRING;
+ MethodInfo mi("validate_json:Variant", PropertyInfo(Variant::STRING, "json"));
+ mi.return_val.type = Variant::STRING;
return mi;
} break;
case PARSE_JSON: {
- MethodInfo mi("parse_json:Variant",PropertyInfo(Variant::STRING,"json"));
- mi.return_val.type=Variant::NIL;
+ MethodInfo mi("parse_json:Variant", PropertyInfo(Variant::STRING, "json"));
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case TO_JSON: {
- MethodInfo mi("to_json",PropertyInfo(Variant::NIL,"var:Variant"));
- mi.return_val.type=Variant::STRING;
+ MethodInfo mi("to_json", PropertyInfo(Variant::NIL, "var:Variant"));
+ mi.return_val.type = Variant::STRING;
return mi;
} break;
case HASH: {
- MethodInfo mi("hash",PropertyInfo(Variant::NIL,"var:Variant"));
- mi.return_val.type=Variant::INT;
+ MethodInfo mi("hash", PropertyInfo(Variant::NIL, "var:Variant"));
+ mi.return_val.type = Variant::INT;
return mi;
} break;
case COLOR8: {
- MethodInfo mi("Color8",PropertyInfo(Variant::INT,"r8"),PropertyInfo(Variant::INT,"g8"),PropertyInfo(Variant::INT,"b8"),PropertyInfo(Variant::INT,"a8"));
- mi.return_val.type=Variant::COLOR;
+ MethodInfo mi("Color8", PropertyInfo(Variant::INT, "r8"), PropertyInfo(Variant::INT, "g8"), PropertyInfo(Variant::INT, "b8"), PropertyInfo(Variant::INT, "a8"));
+ mi.return_val.type = Variant::COLOR;
return mi;
} break;
case COLORN: {
- MethodInfo mi("ColorN",PropertyInfo(Variant::STRING,"name"),PropertyInfo(Variant::REAL,"alpha"));
- mi.return_val.type=Variant::COLOR;
+ MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::REAL, "alpha"));
+ mi.return_val.type = Variant::COLOR;
return mi;
} break;
case PRINT_STACK: {
MethodInfo mi("print_stack");
- mi.return_val.type=Variant::NIL;
+ mi.return_val.type = Variant::NIL;
return mi;
} break;
case INSTANCE_FROM_ID: {
- MethodInfo mi("instance_from_id",PropertyInfo(Variant::INT,"instance_id"));
- mi.return_val.type=Variant::OBJECT;
+ MethodInfo mi("instance_from_id", PropertyInfo(Variant::INT, "instance_id"));
+ mi.return_val.type = Variant::OBJECT;
return mi;
} break;
@@ -1650,7 +1625,6 @@ MethodInfo GDFunctions::get_info(Function p_func) {
ERR_FAIL_V(MethodInfo());
} break;
-
}
#endif
diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h
index 6e30b4dbb5..cde1a9210d 100644
--- a/modules/gdscript/gd_functions.h
+++ b/modules/gdscript/gd_functions.h
@@ -33,7 +33,6 @@
class GDFunctions {
public:
-
enum Function {
MATH_SIN,
MATH_COS,
@@ -110,10 +109,9 @@ public:
};
static const char *get_func_name(Function p_func);
- static void call(Function p_func,const Variant **p_args,int p_arg_count,Variant &r_ret,Variant::CallError &r_error);
+ static void call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Variant::CallError &r_error);
static bool is_deterministic(Function p_func);
static MethodInfo get_info(Function p_func);
-
};
#endif // GD_FUNCTIONS_H
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 5147ccd63f..86b97e27a9 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -27,74 +27,72 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "gd_parser.h"
-#include "print_string.h"
+#include "gd_script.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
+#include "print_string.h"
#include "script_language.h"
-#include "gd_script.h"
-template<class T>
-T* GDParser::alloc_node() {
+template <class T>
+T *GDParser::alloc_node() {
- T *t = memnew( T);
+ T *t = memnew(T);
- t->next=list;
- list=t;
+ t->next = list;
+ list = t;
if (!head)
- head=t;
+ head = t;
- t->line=tokenizer->get_token_line();
- t->column=tokenizer->get_token_column();
+ t->line = tokenizer->get_token_line();
+ t->column = tokenizer->get_token_column();
return t;
-
}
bool GDParser::_end_statement() {
- if (tokenizer->get_token()==GDTokenizer::TK_SEMICOLON) {
+ if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON) {
tokenizer->advance();
return true; //handle next
- } else if (tokenizer->get_token()==GDTokenizer::TK_NEWLINE || tokenizer->get_token()==GDTokenizer::TK_EOF) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE || tokenizer->get_token() == GDTokenizer::TK_EOF) {
return true; //will be handled properly
}
return false;
}
-bool GDParser::_enter_indent_block(BlockNode* p_block) {
-
+bool GDParser::_enter_indent_block(BlockNode *p_block) {
- if (tokenizer->get_token()!=GDTokenizer::TK_COLON) {
+ if (tokenizer->get_token() != GDTokenizer::TK_COLON) {
// report location at the previous token (on the previous line)
int error_line = tokenizer->get_token_line(-1);
int error_column = tokenizer->get_token_column(-1);
- _set_error("':' expected at end of line.",error_line,error_column);
+ _set_error("':' expected at end of line.", error_line, error_column);
return false;
}
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_NEWLINE) {
// be more python-like
int current = tab_level.back()->get();
- tab_level.push_back(current+1);
+ tab_level.push_back(current + 1);
return true;
//_set_error("newline expected after ':'.");
//return false;
}
- while(true) {
+ while (true) {
- if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_NEWLINE) {
return false; //wtf
- } else if (tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE) {
+ } else if (tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE) {
int indent = tokenizer->get_token_line_indent();
int current = tab_level.back()->get();
- if (indent<=current) {
- print_line("current: "+itos(current)+" indent: "+itos(indent));
+ if (indent <= current) {
+ print_line("current: " + itos(current) + " indent: " + itos(indent));
print_line("less than current");
return false;
}
@@ -106,52 +104,51 @@ bool GDParser::_enter_indent_block(BlockNode* p_block) {
} else if (p_block) {
NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line=tokenizer->get_token_line();
+ nl->line = tokenizer->get_token_line();
p_block->statements.push_back(nl);
-
}
tokenizer->advance(); // go to next newline
}
}
-bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_static,bool p_can_codecomplete) {
+bool GDParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete) {
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
tokenizer->advance();
} else {
- parenthesis ++;
- int argidx=0;
+ parenthesis++;
+ int argidx = 0;
- while(true) {
+ while (true) {
- if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
_make_completable_call(argidx);
- completion_node=p_parent;
- } else if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type()==Variant::STRING && tokenizer->get_token(1)==GDTokenizer::TK_CURSOR) {
+ completion_node = p_parent;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING && tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) {
//completing a string argument..
- completion_cursor=tokenizer->get_token_constant();
+ completion_cursor = tokenizer->get_token_constant();
_make_completable_call(argidx);
- completion_node=p_parent;
+ completion_node = p_parent;
tokenizer->advance(1);
return false;
}
- Node*arg = _parse_expression(p_parent,p_static);
+ Node *arg = _parse_expression(p_parent, p_static);
if (!arg)
return false;
p_args.push_back(arg);
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
tokenizer->advance();
break;
- } else if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
- if (tokenizer->get_token(1)==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token(1) == GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expression expected");
return false;
@@ -164,57 +161,52 @@ bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_stat
_set_error("Expected ',' or ')'");
return false;
}
-
}
- parenthesis --;
+ parenthesis--;
}
return true;
-
}
-
void GDParser::_make_completable_call(int p_arg) {
- completion_cursor=StringName();
- completion_type=COMPLETION_CALL_ARGUMENTS;
- completion_class=current_class;
- completion_function=current_function;
- completion_line=tokenizer->get_token_line();
- completion_argument=p_arg;
- completion_block=current_block;
- completion_found=true;
+ completion_cursor = StringName();
+ completion_type = COMPLETION_CALL_ARGUMENTS;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_argument = p_arg;
+ completion_block = current_block;
+ completion_found = true;
tokenizer->advance();
-
}
+bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &identifier) {
-bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& identifier) {
-
- identifier=StringName();
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) {
- identifier=tokenizer->get_token_identifier();
+ identifier = StringName();
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) {
+ identifier = tokenizer->get_token_identifier();
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
-
- completion_cursor=identifier;
- completion_type=p_type;
- completion_class=current_class;
- completion_function=current_function;
- completion_line=tokenizer->get_token_line();
- completion_block=current_block;
- completion_found=true;
- completion_ident_is_call=false;
+ if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
+
+ completion_cursor = identifier;
+ completion_type = p_type;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_block = current_block;
+ completion_found = true;
+ 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->get_token() == GDTokenizer::TK_IDENTIFIER) {
+ identifier = identifier.operator String() + tokenizer->get_token_identifier().operator String();
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_OPEN) {
- completion_ident_is_call=true;
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) {
+ completion_ident_is_call = true;
}
return true;
}
@@ -222,132 +214,129 @@ bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& ide
return false;
}
-
-GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign,bool p_parsing_constant) {
+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;
Vector<Expression> expression;
- Node *expr=NULL;
+ Node *expr = NULL;
int op_line = tokenizer->get_token_line(); // when operators are created at the bottom, the line might have been changed (\n found)
- while(true) {
-
+ while (true) {
/*****************/
/* Parse Operand */
/*****************/
- if (parenthesis>0) {
+ if (parenthesis > 0) {
//remove empty space (only allowed if inside parenthesis
- while(tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
}
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) {
//subexpression ()
tokenizer->advance();
parenthesis++;
- Node* subexpr = _parse_expression(p_parent,p_static,p_allow_assign,p_parsing_constant);
+ Node *subexpr = _parse_expression(p_parent, p_static, p_allow_assign, p_parsing_constant);
parenthesis--;
if (!subexpr)
return NULL;
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in expression");
return NULL;
}
tokenizer->advance();
- expr=subexpr;
- } else if (tokenizer->get_token()==GDTokenizer::TK_DOLLAR) {
+ expr = subexpr;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_DOLLAR) {
tokenizer->advance();
String path;
- bool need_identifier=true;
- bool done=false;
+ bool need_identifier = true;
+ bool done = false;
- while(!done) {
+ while (!done) {
- switch(tokenizer->get_token()) {
+ switch (tokenizer->get_token()) {
case GDTokenizer::TK_CURSOR: {
- completion_cursor=StringName();
- completion_type=COMPLETION_GET_NODE;
- completion_class=current_class;
- completion_function=current_function;
- completion_line=tokenizer->get_token_line();
- completion_cursor=path;
- completion_argument=0;
- completion_block=current_block;
- completion_found=true;
+ completion_cursor = StringName();
+ completion_type = COMPLETION_GET_NODE;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_cursor = path;
+ completion_argument = 0;
+ completion_block = current_block;
+ completion_found = true;
tokenizer->advance();
} break;
case GDTokenizer::TK_CONSTANT: {
if (!need_identifier) {
- done=true;
+ done = true;
break;
}
- if (tokenizer->get_token_constant().get_type()!=Variant::STRING) {
+ if (tokenizer->get_token_constant().get_type() != Variant::STRING) {
_set_error("Expected string constant or identifier after '$' or '/'.");
return NULL;
}
- path+=String(tokenizer->get_token_constant());
+ path += String(tokenizer->get_token_constant());
tokenizer->advance();
- need_identifier=false;
+ need_identifier = false;
} break;
case GDTokenizer::TK_IDENTIFIER: {
if (!need_identifier) {
- done=true;
+ done = true;
break;
}
- path+=String(tokenizer->get_token_identifier());
+ path += String(tokenizer->get_token_identifier());
tokenizer->advance();
- need_identifier=false;
+ need_identifier = false;
} break;
case GDTokenizer::TK_OP_DIV: {
if (need_identifier) {
- done=true;
+ done = true;
break;
}
- path+="/";
+ path += "/";
tokenizer->advance();
- need_identifier=true;
+ need_identifier = true;
} break;
default: {
- done=true;
+ done = true;
break;
}
}
}
- if (path=="") {
+ if (path == "") {
_set_error("Path expected after $.");
return NULL;
-
}
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_CALL;
+ op->op = OperatorNode::OP_CALL;
op->arguments.push_back(alloc_node<SelfNode>());
IdentifierNode *funcname = alloc_node<IdentifierNode>();
- funcname->name="get_node";
+ funcname->name = "get_node";
op->arguments.push_back(funcname);
@@ -355,47 +344,45 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
nodepath->value = NodePath(StringName(path));
op->arguments.push_back(nodepath);
- expr=op;
+ expr = op;
- } else if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
tokenizer->advance();
continue; //no point in cursor in the middle of expression
- } else if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT) {
//constant defined by tokenizer
ConstantNode *constant = alloc_node<ConstantNode>();
- constant->value=tokenizer->get_token_constant();
+ constant->value = tokenizer->get_token_constant();
tokenizer->advance();
- expr=constant;
- } else if (tokenizer->get_token()==GDTokenizer::TK_CONST_PI) {
+ expr = constant;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_PI) {
//constant defined by tokenizer
ConstantNode *constant = alloc_node<ConstantNode>();
- constant->value=Math_PI;
+ constant->value = Math_PI;
tokenizer->advance();
- expr=constant;
- }
- else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) {
+ expr = constant;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) {
//constant defined by tokenizer
ConstantNode *constant = alloc_node<ConstantNode>();
constant->value = Math_INF;
tokenizer->advance();
expr = constant;
- }
- else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) {
//constant defined by tokenizer
ConstantNode *constant = alloc_node<ConstantNode>();
constant->value = Math_NAN;
tokenizer->advance();
expr = constant;
- } else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_PR_PRELOAD) {
//constant defined by tokenizer
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) {
_set_error("Expected '(' after 'preload'");
return NULL;
}
@@ -409,18 +396,18 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
Node *subexpr = _parse_and_reduce_expression(p_parent, p_static);
if (subexpr) {
if (subexpr->type == Node::TYPE_CONSTANT) {
- cn = static_cast<ConstantNode*>(subexpr);
+ cn = static_cast<ConstantNode *>(subexpr);
found_constant = true;
}
if (subexpr->type == Node::TYPE_IDENTIFIER) {
- IdentifierNode *in = static_cast<IdentifierNode*>(subexpr);
+ IdentifierNode *in = static_cast<IdentifierNode *>(subexpr);
Vector<ClassNode::Constant> ce = current_class->constant_expressions;
// Try to find the constant expression by the identifier
- for(int i=0; i < ce.size(); ++i){
- if(ce[i].identifier == in->name) {
- if(ce[i].expression->type == Node::TYPE_CONSTANT) {
- cn = static_cast<ConstantNode*>(ce[i].expression);
+ for (int i = 0; i < ce.size(); ++i) {
+ if (ce[i].identifier == in->name) {
+ if (ce[i].expression->type == Node::TYPE_CONSTANT) {
+ cn = static_cast<ConstantNode *>(ce[i].expression);
found_constant = true;
}
}
@@ -429,7 +416,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
if (found_constant && cn->value.get_type() == Variant::STRING) {
valid = true;
- path = (String) cn->value;
+ path = (String)cn->value;
}
}
@@ -438,17 +425,15 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
return NULL;
}
- if (!path.is_abs_path() && base_path!="")
- path=base_path+"/"+path;
- path = path.replace("///","//").simplify_path();
- if (path==self_path) {
+ if (!path.is_abs_path() && base_path != "")
+ path = base_path + "/" + path;
+ path = path.replace("///", "//").simplify_path();
+ if (path == self_path) {
_set_error("Can't preload itself (use 'get_script()').");
return NULL;
-
}
-
Ref<Resource> res;
if (!validating) {
@@ -459,33 +444,33 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
res = ResourceLoader::load(path);
}
if (!res.is_valid()) {
- _set_error("Can't preload resource at path: "+path);
+ _set_error("Can't preload resource at path: " + path);
return NULL;
}
} else {
if (!FileAccess::exists(path)) {
- _set_error("Can't preload resource at path: "+path);
+ _set_error("Can't preload resource at path: " + path);
return NULL;
}
}
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' after 'preload' path");
return NULL;
}
ConstantNode *constant = alloc_node<ConstantNode>();
- constant->value=res;
+ constant->value = res;
tokenizer->advance();
- expr=constant;
- } else if (tokenizer->get_token()==GDTokenizer::TK_PR_YIELD) {
+ expr = constant;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_PR_YIELD) {
//constant defined by tokenizer
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) {
_set_error("Expected '(' after 'yield'");
return NULL;
}
@@ -493,65 +478,63 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
tokenizer->advance();
OperatorNode *yield = alloc_node<OperatorNode>();
- yield->op=OperatorNode::OP_YIELD;
+ yield->op = OperatorNode::OP_YIELD;
- while (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
- expr=yield;
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ expr = yield;
tokenizer->advance();
} else {
- parenthesis ++;
+ parenthesis++;
- Node *object = _parse_and_reduce_expression(p_parent,p_static);
+ Node *object = _parse_and_reduce_expression(p_parent, p_static);
if (!object)
return NULL;
yield->arguments.push_back(object);
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
_set_error("Expected ',' after first argument of 'yield'");
return NULL;
}
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
-
-
- completion_cursor=StringName();
- completion_node=object;
- completion_type=COMPLETION_YIELD;
- completion_class=current_class;
- completion_function=current_function;
- completion_line=tokenizer->get_token_line();
- completion_argument=0;
- completion_block=current_block;
- completion_found=true;
+ if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
+
+ completion_cursor = StringName();
+ completion_node = object;
+ completion_type = COMPLETION_YIELD;
+ completion_class = current_class;
+ completion_function = current_function;
+ completion_line = tokenizer->get_token_line();
+ completion_argument = 0;
+ completion_block = current_block;
+ completion_found = true;
tokenizer->advance();
}
- Node *signal = _parse_and_reduce_expression(p_parent,p_static);
+ Node *signal = _parse_and_reduce_expression(p_parent, p_static);
if (!signal)
return NULL;
yield->arguments.push_back(signal);
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' after second argument of 'yield'");
return NULL;
}
- parenthesis --;
+ parenthesis--;
tokenizer->advance();
- expr=yield;
+ expr = yield;
}
-
- } else if (tokenizer->get_token()==GDTokenizer::TK_SELF) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_SELF) {
if (p_static) {
_set_error("'self'' not allowed in static function or constant expression");
@@ -560,51 +543,50 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//constant defined by tokenizer
SelfNode *self = alloc_node<SelfNode>();
tokenizer->advance();
- expr=self;
- } else if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token(1)==GDTokenizer::TK_PERIOD) {
+ expr = self;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) {
Variant::Type bi_type = tokenizer->get_token_type();
tokenizer->advance(2);
StringName identifier;
- if (_get_completable_identifier(COMPLETION_BUILT_IN_TYPE_CONSTANT,identifier)) {
+ if (_get_completable_identifier(COMPLETION_BUILT_IN_TYPE_CONSTANT, identifier)) {
- completion_built_in_constant=bi_type;
+ completion_built_in_constant = bi_type;
}
- if (identifier==StringName()) {
+ if (identifier == StringName()) {
_set_error("Built-in type constant expected after '.'");
return NULL;
}
- if (!Variant::has_numeric_constant(bi_type,identifier)) {
+ if (!Variant::has_numeric_constant(bi_type, identifier)) {
- _set_error("Static constant '"+identifier.operator String()+"' not present in built-in type "+Variant::get_type_name(bi_type)+".");
+ _set_error("Static constant '" + identifier.operator String() + "' not present in built-in type " + Variant::get_type_name(bi_type) + ".");
return NULL;
}
ConstantNode *cn = alloc_node<ConstantNode>();
- cn->value=Variant::get_numeric_constant_value(bi_type,identifier);
- expr=cn;
+ 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->get_token() == GDTokenizer::TK_BUILT_IN_TYPE || tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER || tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC)) {
//function or constructor
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_CALL;
+ op->op = OperatorNode::OP_CALL;
- if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) {
TypeNode *tn = alloc_node<TypeNode>();
- tn->vtype=tokenizer->get_token_type();
+ tn->vtype = tokenizer->get_token_type();
op->arguments.push_back(tn);
tokenizer->advance(2);
- } else if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_FUNC) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC) {
BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>();
- bn->function=tokenizer->get_token_built_in_func();
+ bn->function = tokenizer->get_token_built_in_func();
op->arguments.push_back(bn);
tokenizer->advance(2);
} else {
@@ -613,43 +595,40 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
op->arguments.push_back(self);
StringName identifier;
- if (_get_completable_identifier(COMPLETION_FUNCTION,identifier)) {
-
+ if (_get_completable_identifier(COMPLETION_FUNCTION, identifier)) {
}
- IdentifierNode* id = alloc_node<IdentifierNode>();
- id->name=identifier;
+ IdentifierNode *id = alloc_node<IdentifierNode>();
+ id->name = identifier;
op->arguments.push_back(id);
tokenizer->advance(1);
}
- if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
_make_completable_call(0);
- completion_node=op;
-
+ completion_node = op;
}
- if (!_parse_arguments(op,op->arguments,p_static,true))
+ if (!_parse_arguments(op, op->arguments, p_static, true))
return NULL;
- expr=op;
+ expr = op;
- } else if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) {
//identifier (reference)
- const ClassNode* cln = current_class;
- bool bfn = false;
- StringName identifier;
- if (_get_completable_identifier(COMPLETION_IDENTIFIER,identifier)) {
-
+ const ClassNode *cln = current_class;
+ bool bfn = false;
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_IDENTIFIER, identifier)) {
}
if (p_parsing_constant) {
- for( int i=0; i<cln->constant_expressions.size(); ++i ) {
+ 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;
+ bfn = true;
break;
}
}
@@ -657,37 +636,36 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
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;
+ constant->value = GDScriptLanguage::get_singleton()->get_global_array()[GDScriptLanguage::get_singleton()->get_global_map()[identifier]];
+ expr = constant;
bfn = true;
}
}
- if ( !bfn ) {
+ if (!bfn) {
IdentifierNode *id = alloc_node<IdentifierNode>();
id->name = identifier;
expr = id;
}
- } 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) {
+ } 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 --expr
alloc_node<OperatorNode>();
Expression e;
- e.is_op=true;
+ e.is_op = true;
- switch(tokenizer->get_token()) {
- case GDTokenizer::TK_OP_ADD: e.op=OperatorNode::OP_POS; break;
- case GDTokenizer::TK_OP_SUB: e.op=OperatorNode::OP_NEG; break;
- case GDTokenizer::TK_OP_NOT: e.op=OperatorNode::OP_NOT; break;
- case GDTokenizer::TK_OP_BIT_INVERT: e.op=OperatorNode::OP_BIT_INVERT; break;
+ switch (tokenizer->get_token()) {
+ case GDTokenizer::TK_OP_ADD: e.op = OperatorNode::OP_POS; break;
+ case GDTokenizer::TK_OP_SUB: e.op = OperatorNode::OP_NEG; break;
+ case GDTokenizer::TK_OP_NOT: e.op = OperatorNode::OP_NOT; break;
+ case GDTokenizer::TK_OP_BIT_INVERT: e.op = OperatorNode::OP_BIT_INVERT; break;
default: {}
}
-
tokenizer->advance();
- if (e.op!=OperatorNode::OP_NOT && tokenizer->get_token()==GDTokenizer::TK_OP_NOT) {
+ if (e.op != OperatorNode::OP_NOT && tokenizer->get_token() == GDTokenizer::TK_OP_NOT) {
_set_error("Misplaced 'not'.");
return NULL;
}
@@ -702,33 +680,33 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
op->arguments.push_back(subexpr);
expr=op;*/
- } else if (tokenizer->get_token()==GDTokenizer::TK_BRACKET_OPEN) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_OPEN) {
// array
tokenizer->advance();
ArrayNode *arr = alloc_node<ArrayNode>();
- bool expecting_comma=false;
+ bool expecting_comma = false;
- while(true) {
+ while (true) {
- if (tokenizer->get_token()==GDTokenizer::TK_EOF) {
+ if (tokenizer->get_token() == GDTokenizer::TK_EOF) {
_set_error("Unterminated array");
return NULL;
- } else if (tokenizer->get_token()==GDTokenizer::TK_BRACKET_CLOSE) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) {
tokenizer->advance();
break;
- } else if (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance(); //ignore newline
- } else if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
if (!expecting_comma) {
_set_error("expression or ']' expected");
return NULL;
}
- expecting_comma=false;
+ expecting_comma = false;
tokenizer->advance(); //ignore newline
} else {
//parse expression
@@ -736,16 +714,16 @@ 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,p_allow_assign,p_parsing_constant);
+ Node *n = _parse_expression(arr, p_static, p_allow_assign, p_parsing_constant);
if (!n)
return NULL;
arr->elements.push_back(n);
- expecting_comma=true;
+ expecting_comma = true;
}
}
- expr=arr;
- } else if (tokenizer->get_token()==GDTokenizer::TK_CURLY_BRACKET_OPEN) {
+ expr = arr;
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_OPEN) {
// array
tokenizer->advance();
@@ -760,105 +738,105 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
};
- Node *key=NULL;
+ Node *key = NULL;
Set<Variant> keys;
- DictExpect expecting=DICT_EXPECT_KEY;
+ DictExpect expecting = DICT_EXPECT_KEY;
- while(true) {
+ while (true) {
- if (tokenizer->get_token()==GDTokenizer::TK_EOF) {
+ if (tokenizer->get_token() == GDTokenizer::TK_EOF) {
_set_error("Unterminated dictionary");
return NULL;
- } else if (tokenizer->get_token()==GDTokenizer::TK_CURLY_BRACKET_CLOSE) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) {
- if (expecting==DICT_EXPECT_COLON) {
+ if (expecting == DICT_EXPECT_COLON) {
_set_error("':' expected");
return NULL;
}
- if (expecting==DICT_EXPECT_VALUE) {
+ if (expecting == DICT_EXPECT_VALUE) {
_set_error("value expected");
return NULL;
}
tokenizer->advance();
break;
- } else if (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance(); //ignore newline
- } else if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
- if (expecting==DICT_EXPECT_KEY) {
+ if (expecting == DICT_EXPECT_KEY) {
_set_error("key or '}' expected");
return NULL;
}
- if (expecting==DICT_EXPECT_VALUE) {
+ if (expecting == DICT_EXPECT_VALUE) {
_set_error("value expected");
return NULL;
}
- if (expecting==DICT_EXPECT_COLON) {
+ if (expecting == DICT_EXPECT_COLON) {
_set_error("':' expected");
return NULL;
}
- expecting=DICT_EXPECT_KEY;
+ expecting = DICT_EXPECT_KEY;
tokenizer->advance(); //ignore newline
- } else if (tokenizer->get_token()==GDTokenizer::TK_COLON) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_COLON) {
- if (expecting==DICT_EXPECT_KEY) {
+ if (expecting == DICT_EXPECT_KEY) {
_set_error("key or '}' expected");
return NULL;
}
- if (expecting==DICT_EXPECT_VALUE) {
+ if (expecting == DICT_EXPECT_VALUE) {
_set_error("value expected");
return NULL;
}
- if (expecting==DICT_EXPECT_COMMA) {
+ if (expecting == DICT_EXPECT_COMMA) {
_set_error("',' or '}' expected");
return NULL;
}
- expecting=DICT_EXPECT_VALUE;
+ expecting = DICT_EXPECT_VALUE;
tokenizer->advance(); //ignore newline
} else {
- if (expecting==DICT_EXPECT_COMMA) {
+ if (expecting == DICT_EXPECT_COMMA) {
_set_error("',' or '}' expected");
return NULL;
}
- if (expecting==DICT_EXPECT_COLON) {
+ if (expecting == DICT_EXPECT_COLON) {
_set_error("':' expected");
return NULL;
}
- if (expecting==DICT_EXPECT_KEY) {
+ if (expecting == DICT_EXPECT_KEY) {
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1)==GDTokenizer::TK_OP_ASSIGN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1) == GDTokenizer::TK_OP_ASSIGN) {
//lua style identifier, easier to write
ConstantNode *cn = alloc_node<ConstantNode>();
cn->value = tokenizer->get_token_identifier();
key = cn;
tokenizer->advance(2);
- expecting=DICT_EXPECT_VALUE;
+ expecting = DICT_EXPECT_VALUE;
} else {
//python/js style more flexible
- key = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant);
+ key = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant);
if (!key)
return NULL;
- expecting=DICT_EXPECT_COLON;
+ expecting = DICT_EXPECT_COLON;
}
}
- if (expecting==DICT_EXPECT_VALUE) {
- Node *value = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant);
+ if (expecting == DICT_EXPECT_VALUE) {
+ Node *value = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant);
if (!value)
return NULL;
- expecting=DICT_EXPECT_COMMA;
+ expecting = DICT_EXPECT_COMMA;
if (key->type == GDParser::Node::TYPE_CONSTANT) {
- Variant const& keyName = static_cast<const GDParser::ConstantNode*>(key)->value;
+ Variant const &keyName = static_cast<const GDParser::ConstantNode *>(key)->value;
if (keys.has(keyName)) {
_set_error("Duplicate key found in Dictionary literal");
@@ -868,43 +846,40 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
}
DictionaryNode::Pair pair;
- pair.key=key;
- pair.value=value;
+ pair.key = key;
+ pair.value = value;
dict->elements.push_back(pair);
- key=NULL;
-
+ key = NULL;
}
-
}
}
- expr=dict;
+ 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->get_token(1) == GDTokenizer::TK_IDENTIFIER || tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) {
// parent call
tokenizer->advance(); //goto identifier
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_PARENT_CALL;
-
+ op->op = OperatorNode::OP_PARENT_CALL;
/*SelfNode *self = alloc_node<SelfNode>();
op->arguments.push_back(self);
forbidden for now */
StringName identifier;
- if (_get_completable_identifier(COMPLETION_PARENT_FUNCTION,identifier)) {
+ if (_get_completable_identifier(COMPLETION_PARENT_FUNCTION, identifier)) {
//indexing stuff
}
IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name=identifier;
+ id->name = identifier;
op->arguments.push_back(id);
tokenizer->advance(1);
- if (!_parse_arguments(op,op->arguments,p_static))
+ if (!_parse_arguments(op, op->arguments, p_static))
return NULL;
- expr=op;
+ expr = op;
} else {
@@ -912,113 +887,106 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//print_line("found bug?");
- _set_error("Error parsing expression, misplaced: "+String(tokenizer->get_token_name(tokenizer->get_token())));
- return NULL; //nothing
+ _set_error("Error parsing expression, misplaced: " + String(tokenizer->get_token_name(tokenizer->get_token())));
+ return NULL; //nothing
}
if (!expr) {
ERR_EXPLAIN("GDParser bug, couldn't figure out what expression is..");
- ERR_FAIL_COND_V(!expr,NULL);
+ ERR_FAIL_COND_V(!expr, NULL);
}
-
/******************/
/* Parse Indexing */
/******************/
-
while (true) {
//expressions can be indexed any number of times
- if (tokenizer->get_token()==GDTokenizer::TK_PERIOD) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) {
//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->get_token(1) != GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1) != GDTokenizer::TK_BUILT_IN_FUNC) {
_set_error("Expected identifier as member");
return NULL;
- } else if (tokenizer->get_token(2)==GDTokenizer::TK_PARENTHESIS_OPEN) {
+ } else if (tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) {
//call!!
- OperatorNode * op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_CALL;
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op = OperatorNode::OP_CALL;
tokenizer->advance();
- IdentifierNode * id = alloc_node<IdentifierNode>();
- if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_FUNC ) {
+ IdentifierNode *id = alloc_node<IdentifierNode>();
+ if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC) {
//small hack so built in funcs don't obfuscate methods
- id->name=GDFunctions::get_func_name(tokenizer->get_token_built_in_func());
+ id->name = GDFunctions::get_func_name(tokenizer->get_token_built_in_func());
tokenizer->advance();
} else {
StringName identifier;
- if (_get_completable_identifier(COMPLETION_METHOD,identifier)) {
- completion_node=op;
+ if (_get_completable_identifier(COMPLETION_METHOD, identifier)) {
+ completion_node = op;
//indexing stuff
}
- id->name=identifier;
+ id->name = identifier;
}
op->arguments.push_back(expr); // call what
op->arguments.push_back(id); // call func
//get arguments
tokenizer->advance(1);
- if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) {
_make_completable_call(0);
- completion_node=op;
-
+ completion_node = op;
}
- if (!_parse_arguments(op,op->arguments,p_static,true))
+ if (!_parse_arguments(op, op->arguments, p_static, true))
return NULL;
- expr=op;
+ expr = op;
} else {
//simple indexing!
-
- OperatorNode * op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_INDEX_NAMED;
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op = OperatorNode::OP_INDEX_NAMED;
tokenizer->advance();
-
StringName identifier;
- if (_get_completable_identifier(COMPLETION_INDEX,identifier)) {
+ if (_get_completable_identifier(COMPLETION_INDEX, identifier)) {
- if (identifier==StringName()) {
- identifier="@temp"; //so it parses allright
+ if (identifier == StringName()) {
+ identifier = "@temp"; //so it parses allright
}
- completion_node=op;
+ completion_node = op;
//indexing stuff
}
- IdentifierNode * id = alloc_node<IdentifierNode>();
- id->name=identifier;
+ IdentifierNode *id = alloc_node<IdentifierNode>();
+ id->name = identifier;
op->arguments.push_back(expr);
op->arguments.push_back(id);
- expr=op;
-
-
+ expr = op;
}
- } else if (tokenizer->get_token()==GDTokenizer::TK_BRACKET_OPEN) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_OPEN) {
//indexing using "[]"
- OperatorNode * op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_INDEX;
+ OperatorNode *op = alloc_node<OperatorNode>();
+ op->op = OperatorNode::OP_INDEX;
tokenizer->advance(1);
- Node *subexpr = _parse_expression(op,p_static,p_allow_assign,p_parsing_constant);
+ Node *subexpr = _parse_expression(op, p_static, p_allow_assign, p_parsing_constant);
if (!subexpr) {
return NULL;
}
- if (tokenizer->get_token()!=GDTokenizer::TK_BRACKET_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_BRACKET_CLOSE) {
_set_error("Expected ']'");
return NULL;
}
@@ -1026,7 +994,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
op->arguments.push_back(expr);
op->arguments.push_back(subexpr);
tokenizer->advance(1);
- expr=op;
+ expr = op;
} else
break;
@@ -1036,88 +1004,91 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
/* Parse Operator */
/******************/
- if (parenthesis>0) {
+ if (parenthesis > 0) {
//remove empty space (only allowed if inside parenthesis
- while(tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
}
Expression e;
- e.is_op=false;
- e.node=expr;
+ e.is_op = false;
+ e.node = expr;
expression.push_back(e);
// determine which operator is next
OperatorNode::Operator op;
- bool valid=true;
+ bool valid = true;
//assign, if allowed is only alowed on the first operator
-#define _VALIDATE_ASSIGN if (!p_allow_assign) { _set_error("Unexpected assign."); return NULL; } p_allow_assign=false;
- switch(tokenizer->get_token()) { //see operator
-
- case GDTokenizer::TK_OP_IN: op=OperatorNode::OP_IN; break;
- case GDTokenizer::TK_OP_EQUAL: op=OperatorNode::OP_EQUAL ; break;
- case GDTokenizer::TK_OP_NOT_EQUAL: op=OperatorNode::OP_NOT_EQUAL ; break;
- case GDTokenizer::TK_OP_LESS: op=OperatorNode::OP_LESS ; break;
- case GDTokenizer::TK_OP_LESS_EQUAL: op=OperatorNode::OP_LESS_EQUAL ; break;
- case GDTokenizer::TK_OP_GREATER: op=OperatorNode::OP_GREATER ; break;
- case GDTokenizer::TK_OP_GREATER_EQUAL: op=OperatorNode::OP_GREATER_EQUAL ; break;
- case GDTokenizer::TK_OP_AND: op=OperatorNode::OP_AND ; break;
- case GDTokenizer::TK_OP_OR: op=OperatorNode::OP_OR ; break;
- case GDTokenizer::TK_OP_ADD: op=OperatorNode::OP_ADD ; break;
- case GDTokenizer::TK_OP_SUB: op=OperatorNode::OP_SUB ; break;
- case GDTokenizer::TK_OP_MUL: op=OperatorNode::OP_MUL ; break;
- case GDTokenizer::TK_OP_DIV: op=OperatorNode::OP_DIV ; break;
- case GDTokenizer::TK_OP_MOD: op=OperatorNode::OP_MOD ; break;
+#define _VALIDATE_ASSIGN \
+ if (!p_allow_assign) { \
+ _set_error("Unexpected assign."); \
+ return NULL; \
+ } \
+ p_allow_assign = false;
+ switch (tokenizer->get_token()) { //see operator
+
+ case GDTokenizer::TK_OP_IN: op = OperatorNode::OP_IN; break;
+ case GDTokenizer::TK_OP_EQUAL: op = OperatorNode::OP_EQUAL; break;
+ case GDTokenizer::TK_OP_NOT_EQUAL: op = OperatorNode::OP_NOT_EQUAL; break;
+ case GDTokenizer::TK_OP_LESS: op = OperatorNode::OP_LESS; break;
+ case GDTokenizer::TK_OP_LESS_EQUAL: op = OperatorNode::OP_LESS_EQUAL; break;
+ case GDTokenizer::TK_OP_GREATER: op = OperatorNode::OP_GREATER; break;
+ case GDTokenizer::TK_OP_GREATER_EQUAL: op = OperatorNode::OP_GREATER_EQUAL; break;
+ case GDTokenizer::TK_OP_AND: op = OperatorNode::OP_AND; break;
+ case GDTokenizer::TK_OP_OR: op = OperatorNode::OP_OR; break;
+ case GDTokenizer::TK_OP_ADD: op = OperatorNode::OP_ADD; break;
+ case GDTokenizer::TK_OP_SUB: op = OperatorNode::OP_SUB; break;
+ case GDTokenizer::TK_OP_MUL: op = OperatorNode::OP_MUL; break;
+ case GDTokenizer::TK_OP_DIV: op = OperatorNode::OP_DIV; break;
+ case GDTokenizer::TK_OP_MOD:
+ op = OperatorNode::OP_MOD;
+ break;
//case GDTokenizer::TK_OP_NEG: op=OperatorNode::OP_NEG ; break;
- case GDTokenizer::TK_OP_SHIFT_LEFT: op=OperatorNode::OP_SHIFT_LEFT ; break;
- case GDTokenizer::TK_OP_SHIFT_RIGHT: op=OperatorNode::OP_SHIFT_RIGHT ; break;
- case GDTokenizer::TK_OP_ASSIGN: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN ; break;
- case GDTokenizer::TK_OP_ASSIGN_ADD: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_ADD ; break;
- case GDTokenizer::TK_OP_ASSIGN_SUB: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SUB ; break;
- case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MUL ; break;
- case GDTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_DIV ; break;
- case GDTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MOD ; break;
- case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_LEFT; break;
- case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break;
- case GDTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_AND ; break;
- case GDTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_OR ; break;
- case GDTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_XOR ; break;
- 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_CF_IF: op=OperatorNode::OP_TERNARY_IF; break;
- case GDTokenizer::TK_CF_ELSE: op=OperatorNode::OP_TERNARY_ELSE; break;
- default: valid=false; break;
+ case GDTokenizer::TK_OP_SHIFT_LEFT: op = OperatorNode::OP_SHIFT_LEFT; break;
+ case GDTokenizer::TK_OP_SHIFT_RIGHT: op = OperatorNode::OP_SHIFT_RIGHT; break;
+ case GDTokenizer::TK_OP_ASSIGN: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN; break;
+ case GDTokenizer::TK_OP_ASSIGN_ADD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_ADD; break;
+ case GDTokenizer::TK_OP_ASSIGN_SUB: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SUB; break;
+ case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MUL; break;
+ case GDTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_DIV; break;
+ case GDTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MOD; break;
+ case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_LEFT; break;
+ case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break;
+ case GDTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_AND; break;
+ case GDTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_OR; break;
+ case GDTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_XOR; break;
+ 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_CF_IF: op = OperatorNode::OP_TERNARY_IF; break;
+ case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break;
+ default: valid = false; break;
}
if (valid) {
- e.is_op=true;
- e.op=op;
+ e.is_op = true;
+ e.op = op;
expression.push_back(e);
tokenizer->advance();
} else {
break;
}
-
}
/* Reduce the set set of expressions and place them in an operator tree, respecting precedence */
+ while (expression.size() > 1) {
- while(expression.size()>1) {
-
- int next_op=-1;
- int min_priority=0xFFFFF;
- bool is_unary=false;
- bool is_ternary=false;
-
- for(int i=0;i<expression.size();i++) {
-
+ int next_op = -1;
+ int min_priority = 0xFFFFF;
+ bool is_unary = false;
+ bool is_ternary = false;
+ for (int i = 0; i < expression.size(); i++) {
if (!expression[i].is_op) {
@@ -1126,102 +1097,115 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
int priority;
- bool unary=false;
- bool ternary=false;
- bool error=false;
+ bool unary = false;
+ bool ternary = false;
+ bool error = false;
- switch(expression[i].op) {
+ switch (expression[i].op) {
- case OperatorNode::OP_EXTENDS: priority=-1; break; //before anything
+ case OperatorNode::OP_EXTENDS:
+ priority = -1;
+ break; //before anything
- case OperatorNode::OP_BIT_INVERT: priority=0; unary=true; break;
- case OperatorNode::OP_NEG: priority=1; unary=true; break;
- case OperatorNode::OP_POS: priority=1; unary=true; break;
+ case OperatorNode::OP_BIT_INVERT:
+ priority = 0;
+ unary = true;
+ break;
+ case OperatorNode::OP_NEG:
+ priority = 1;
+ unary = true;
+ break;
+ case OperatorNode::OP_POS:
+ priority = 1;
+ unary = true;
+ break;
- case OperatorNode::OP_MUL: priority=2; break;
- case OperatorNode::OP_DIV: priority=2; break;
- case OperatorNode::OP_MOD: priority=2; break;
+ case OperatorNode::OP_MUL: priority = 2; break;
+ case OperatorNode::OP_DIV: priority = 2; break;
+ case OperatorNode::OP_MOD: priority = 2; break;
- case OperatorNode::OP_ADD: priority=3; break;
- case OperatorNode::OP_SUB: priority=3; break;
+ case OperatorNode::OP_ADD: priority = 3; break;
+ case OperatorNode::OP_SUB: priority = 3; break;
- case OperatorNode::OP_SHIFT_LEFT: priority=4; break;
- case OperatorNode::OP_SHIFT_RIGHT: priority=4; break;
+ case OperatorNode::OP_SHIFT_LEFT: priority = 4; break;
+ case OperatorNode::OP_SHIFT_RIGHT: priority = 4; break;
- case OperatorNode::OP_BIT_AND: priority=5; break;
- case OperatorNode::OP_BIT_XOR: priority=6; break;
- case OperatorNode::OP_BIT_OR: priority=7; break;
+ case OperatorNode::OP_BIT_AND: priority = 5; break;
+ case OperatorNode::OP_BIT_XOR: priority = 6; break;
+ case OperatorNode::OP_BIT_OR: priority = 7; break;
- case OperatorNode::OP_LESS: priority=8; break;
- case OperatorNode::OP_LESS_EQUAL: priority=8; break;
- case OperatorNode::OP_GREATER: priority=8; break;
- case OperatorNode::OP_GREATER_EQUAL: priority=8; break;
+ case OperatorNode::OP_LESS: priority = 8; break;
+ case OperatorNode::OP_LESS_EQUAL: priority = 8; break;
+ case OperatorNode::OP_GREATER: priority = 8; break;
+ case OperatorNode::OP_GREATER_EQUAL: priority = 8; break;
- case OperatorNode::OP_EQUAL: priority=8; break;
- case OperatorNode::OP_NOT_EQUAL: priority=8; break;
+ case OperatorNode::OP_EQUAL: priority = 8; break;
+ case OperatorNode::OP_NOT_EQUAL: priority = 8; break;
-
- case OperatorNode::OP_IN: priority=10; break;
-
- case OperatorNode::OP_NOT: priority=11; unary=true; break;
- case OperatorNode::OP_AND: priority=12; break;
- case OperatorNode::OP_OR: priority=13; break;
-
- case OperatorNode::OP_TERNARY_IF: priority=14; ternary=true; break;
- case OperatorNode::OP_TERNARY_ELSE: priority=14; error=true; break; // Errors out when found without IF (since IF would consume it)
+ case OperatorNode::OP_IN: priority = 10; break;
- case OperatorNode::OP_ASSIGN: priority=15; break;
- case OperatorNode::OP_ASSIGN_ADD: priority=15; break;
- case OperatorNode::OP_ASSIGN_SUB: priority=15; break;
- case OperatorNode::OP_ASSIGN_MUL: priority=15; break;
- case OperatorNode::OP_ASSIGN_DIV: priority=15; break;
- case OperatorNode::OP_ASSIGN_MOD: priority=15; break;
- case OperatorNode::OP_ASSIGN_SHIFT_LEFT: priority=15; break;
- case OperatorNode::OP_ASSIGN_SHIFT_RIGHT: priority=15; break;
- case OperatorNode::OP_ASSIGN_BIT_AND: priority=15; break;
- case OperatorNode::OP_ASSIGN_BIT_OR: priority=15; break;
- case OperatorNode::OP_ASSIGN_BIT_XOR: priority=15; break;
+ case OperatorNode::OP_NOT:
+ priority = 11;
+ unary = true;
+ break;
+ case OperatorNode::OP_AND: priority = 12; break;
+ case OperatorNode::OP_OR: priority = 13; break;
+ case OperatorNode::OP_TERNARY_IF:
+ priority = 14;
+ ternary = true;
+ break;
+ case OperatorNode::OP_TERNARY_ELSE:
+ priority = 14;
+ error = true;
+ break; // Errors out when found without IF (since IF would consume it)
+
+ case OperatorNode::OP_ASSIGN: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_ADD: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_SUB: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_MUL: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_DIV: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_MOD: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_SHIFT_LEFT: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_SHIFT_RIGHT: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_BIT_AND: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_BIT_OR: priority = 15; break;
+ case OperatorNode::OP_ASSIGN_BIT_XOR: priority = 15; break;
default: {
- _set_error("GDParser bug, invalid operator in expression: "+itos(expression[i].op));
+ _set_error("GDParser bug, invalid operator in expression: " + itos(expression[i].op));
return NULL;
}
-
}
- if (priority<min_priority) {
- if(error) {
+ if (priority < min_priority) {
+ if (error) {
_set_error("Unexpected operator");
return NULL;
}
// < is used for left to right (default)
// <= is used for right to left
- next_op=i;
- min_priority=priority;
- is_unary=unary;
- is_ternary=ternary;
+ next_op = i;
+ min_priority = priority;
+ is_unary = unary;
+ is_ternary = ternary;
}
-
}
-
- if (next_op==-1) {
-
+ if (next_op == -1) {
_set_error("Yet another parser bug....");
- ERR_FAIL_COND_V(next_op==-1,NULL);
+ ERR_FAIL_COND_V(next_op == -1, NULL);
}
-
// OK! create operator..
if (is_unary) {
- int expr_pos=next_op;
- while(expression[expr_pos].is_op) {
+ int expr_pos = next_op;
+ while (expression[expr_pos].is_op) {
expr_pos++;
- if (expr_pos==expression.size()) {
+ if (expr_pos == expression.size()) {
//can happen..
_set_error("Unexpected end of expression..");
return NULL;
@@ -1229,44 +1213,43 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
}
//consecutively do unary opeators
- for(int i=expr_pos-1;i>=next_op;i--) {
+ for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=expression[i].op;
- op->arguments.push_back(expression[i+1].node);
- op->line=op_line; //line might have been changed from a \n
- expression[i].is_op=false;
- expression[i].node=op;
- expression.remove(i+1);
+ op->op = expression[i].op;
+ op->arguments.push_back(expression[i + 1].node);
+ op->line = op_line; //line might have been changed from a \n
+ expression[i].is_op = false;
+ expression[i].node = op;
+ expression.remove(i + 1);
}
-
- } else if(is_ternary) {
- if (next_op <1 || next_op>=(expression.size()-1)) {
+ } else if (is_ternary) {
+ if (next_op < 1 || next_op >= (expression.size() - 1)) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
-
- if(next_op>=(expression.size()-2) || expression[next_op+2].op != OperatorNode::OP_TERNARY_ELSE) {
+
+ if (next_op >= (expression.size() - 2) || expression[next_op + 2].op != OperatorNode::OP_TERNARY_ELSE) {
_set_error("Expected else after ternary if.");
ERR_FAIL_V(NULL);
}
- if(next_op>=(expression.size()-3)) {
+ if (next_op >= (expression.size() - 3)) {
_set_error("Expected value after ternary else.");
ERR_FAIL_V(NULL);
}
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=expression[next_op].op;
- op->line=op_line; //line might have been changed from a \n
+ op->op = expression[next_op].op;
+ op->line = op_line; //line might have been changed from a \n
- if (expression[next_op-1].is_op) {
+ if (expression[next_op - 1].is_op) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
- if (expression[next_op+1].is_op) {
+ if (expression[next_op + 1].is_op) {
// this is not invalid and can really appear
// but it becomes invalid anyway because no binary op
// can be followed by an unary op in a valid combination,
@@ -1276,7 +1259,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
return NULL;
}
- if (expression[next_op+3].is_op) {
+ if (expression[next_op + 3].is_op) {
// this is not invalid and can really appear
// but it becomes invalid anyway because no binary op
// can be followed by an unary op in a valid combination,
@@ -1286,35 +1269,34 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
return NULL;
}
-
- op->arguments.push_back(expression[next_op+1].node); //next expression goes as first
- op->arguments.push_back(expression[next_op-1].node); //left expression goes as when-true
- op->arguments.push_back(expression[next_op+3].node); //expression after next goes as when-false
+ op->arguments.push_back(expression[next_op + 1].node); //next expression goes as first
+ op->arguments.push_back(expression[next_op - 1].node); //left expression goes as when-true
+ op->arguments.push_back(expression[next_op + 3].node); //expression after next goes as when-false
//replace all 3 nodes by this operator and make it an expression
- expression[next_op-1].node=op;
+ expression[next_op - 1].node = op;
expression.remove(next_op);
expression.remove(next_op);
expression.remove(next_op);
expression.remove(next_op);
} else {
- if (next_op <1 || next_op>=(expression.size()-1)) {
+ if (next_op < 1 || next_op >= (expression.size() - 1)) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=expression[next_op].op;
- op->line=op_line; //line might have been changed from a \n
+ op->op = expression[next_op].op;
+ op->line = op_line; //line might have been changed from a \n
- if (expression[next_op-1].is_op) {
+ if (expression[next_op - 1].is_op) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
- if (expression[next_op+1].is_op) {
+ if (expression[next_op + 1].is_op) {
// this is not invalid and can really appear
// but it becomes invalid anyway because no binary op
// can be followed by an unary op in a valid combination,
@@ -1324,26 +1306,22 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
return NULL;
}
-
- op->arguments.push_back(expression[next_op-1].node); //expression goes as left
- op->arguments.push_back(expression[next_op+1].node); //next expression goes as right
+ op->arguments.push_back(expression[next_op - 1].node); //expression goes as left
+ op->arguments.push_back(expression[next_op + 1].node); //next expression goes as right
//replace all 3 nodes by this operator and make it an expression
- expression[next_op-1].node=op;
+ expression[next_op - 1].node = op;
expression.remove(next_op);
expression.remove(next_op);
}
-
}
return expression[0].node;
-
}
+GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) {
-GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
-
- switch(p_node->type) {
+ switch (p_node->type) {
case Node::TYPE_BUILT_IN_FUNCTION: {
//many may probably be optimizable
@@ -1351,14 +1329,14 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
} break;
case Node::TYPE_ARRAY: {
- ArrayNode *an = static_cast<ArrayNode*>(p_node);
- bool all_constants=true;
+ ArrayNode *an = static_cast<ArrayNode *>(p_node);
+ bool all_constants = true;
- for(int i=0;i<an->elements.size();i++) {
+ for (int i = 0; i < an->elements.size(); i++) {
- an->elements[i]=_reduce_expression(an->elements[i],p_to_const);
- if (an->elements[i]->type!=Node::TYPE_CONSTANT)
- all_constants=false;
+ an->elements[i] = _reduce_expression(an->elements[i], p_to_const);
+ if (an->elements[i]->type != Node::TYPE_CONSTANT)
+ all_constants = false;
}
if (all_constants && p_to_const) {
@@ -1368,12 +1346,11 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
Array arr;
//print_line("mk array "+itos(!p_to_const));
arr.resize(an->elements.size());
- for(int i=0;i<an->elements.size();i++) {
- ConstantNode *acn = static_cast<ConstantNode*>(an->elements[i]);
- arr[i]=acn->value;
-
+ for (int i = 0; i < an->elements.size(); i++) {
+ ConstantNode *acn = static_cast<ConstantNode *>(an->elements[i]);
+ arr[i] = acn->value;
}
- cn->value=arr;
+ cn->value = arr;
return cn;
}
@@ -1382,18 +1359,17 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
} break;
case Node::TYPE_DICTIONARY: {
- DictionaryNode *dn = static_cast<DictionaryNode*>(p_node);
- bool all_constants=true;
-
- for(int i=0;i<dn->elements.size();i++) {
+ DictionaryNode *dn = static_cast<DictionaryNode *>(p_node);
+ bool all_constants = true;
- dn->elements[i].key=_reduce_expression(dn->elements[i].key,p_to_const);
- if (dn->elements[i].key->type!=Node::TYPE_CONSTANT)
- all_constants=false;
- dn->elements[i].value=_reduce_expression(dn->elements[i].value,p_to_const);
- if (dn->elements[i].value->type!=Node::TYPE_CONSTANT)
- all_constants=false;
+ for (int i = 0; i < dn->elements.size(); i++) {
+ dn->elements[i].key = _reduce_expression(dn->elements[i].key, p_to_const);
+ if (dn->elements[i].key->type != Node::TYPE_CONSTANT)
+ all_constants = false;
+ dn->elements[i].value = _reduce_expression(dn->elements[i].value, p_to_const);
+ if (dn->elements[i].value->type != Node::TYPE_CONSTANT)
+ all_constants = false;
}
if (all_constants && p_to_const) {
@@ -1401,157 +1377,143 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
ConstantNode *cn = alloc_node<ConstantNode>();
Dictionary dict;
- for(int i=0;i<dn->elements.size();i++) {
- ConstantNode *key_c = static_cast<ConstantNode*>(dn->elements[i].key);
- ConstantNode *value_c = static_cast<ConstantNode*>(dn->elements[i].value);
-
- dict[key_c->value]=value_c->value;
+ for (int i = 0; i < dn->elements.size(); i++) {
+ ConstantNode *key_c = static_cast<ConstantNode *>(dn->elements[i].key);
+ ConstantNode *value_c = static_cast<ConstantNode *>(dn->elements[i].value);
+ dict[key_c->value] = value_c->value;
}
- cn->value=dict;
+ cn->value = dict;
return cn;
}
return dn;
-
} break;
case Node::TYPE_OPERATOR: {
- OperatorNode *op=static_cast<OperatorNode*>(p_node);
+ OperatorNode *op = static_cast<OperatorNode *>(p_node);
- bool all_constants=true;
- int last_not_constant=-1;
+ bool all_constants = true;
+ int last_not_constant = -1;
- for(int i=0;i<op->arguments.size();i++) {
+ for (int i = 0; i < op->arguments.size(); i++) {
- op->arguments[i]=_reduce_expression(op->arguments[i],p_to_const);
- if (op->arguments[i]->type!=Node::TYPE_CONSTANT) {
- all_constants=false;
- last_not_constant=i;
+ op->arguments[i] = _reduce_expression(op->arguments[i], p_to_const);
+ if (op->arguments[i]->type != Node::TYPE_CONSTANT) {
+ all_constants = false;
+ last_not_constant = i;
}
}
- if (op->op==OperatorNode::OP_EXTENDS) {
+ if (op->op == OperatorNode::OP_EXTENDS) {
//nothing much
return op;
-
- } if (op->op==OperatorNode::OP_PARENT_CALL) {
+ }
+ if (op->op == OperatorNode::OP_PARENT_CALL) {
//nothing much
return op;
- } else if (op->op==OperatorNode::OP_CALL) {
+ } else if (op->op == OperatorNode::OP_CALL) {
//can reduce base type constructors
- if ((op->arguments[0]->type==Node::TYPE_TYPE || (op->arguments[0]->type==Node::TYPE_BUILT_IN_FUNCTION && GDFunctions::is_deterministic( static_cast<BuiltInFunctionNode*>(op->arguments[0])->function))) && last_not_constant==0) {
+ if ((op->arguments[0]->type == Node::TYPE_TYPE || (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && GDFunctions::is_deterministic(static_cast<BuiltInFunctionNode *>(op->arguments[0])->function))) && last_not_constant == 0) {
//native type constructor or intrinsic function
- const Variant **vptr=NULL;
- Vector<Variant*> ptrs;
- if (op->arguments.size()>1) {
-
- ptrs.resize(op->arguments.size()-1);
- for(int i=0;i<ptrs.size();i++) {
+ const Variant **vptr = NULL;
+ Vector<Variant *> ptrs;
+ if (op->arguments.size() > 1) {
+ ptrs.resize(op->arguments.size() - 1);
+ for (int i = 0; i < ptrs.size(); i++) {
- ConstantNode *cn = static_cast<ConstantNode*>(op->arguments[i+1]);
- ptrs[i]=&cn->value;
+ ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[i + 1]);
+ ptrs[i] = &cn->value;
}
- vptr=(const Variant**)&ptrs[0];
-
-
+ vptr = (const Variant **)&ptrs[0];
}
Variant::CallError ce;
Variant v;
- if (op->arguments[0]->type==Node::TYPE_TYPE) {
- TypeNode *tn = static_cast<TypeNode*>(op->arguments[0]);
- v = Variant::construct(tn->vtype,vptr,ptrs.size(),ce);
+ if (op->arguments[0]->type == Node::TYPE_TYPE) {
+ TypeNode *tn = static_cast<TypeNode *>(op->arguments[0]);
+ v = Variant::construct(tn->vtype, vptr, ptrs.size(), ce);
} else {
- GDFunctions::Function func = static_cast<BuiltInFunctionNode*>(op->arguments[0])->function;
- GDFunctions::call(func,vptr,ptrs.size(),v,ce);
+ GDFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function;
+ GDFunctions::call(func, vptr, ptrs.size(), v, ce);
}
-
- if (ce.error!=Variant::CallError::CALL_OK) {
+ if (ce.error != Variant::CallError::CALL_OK) {
String errwhere;
- if (op->arguments[0]->type==Node::TYPE_TYPE) {
- TypeNode *tn = static_cast<TypeNode*>(op->arguments[0]);
- errwhere="'"+Variant::get_type_name(tn->vtype)+"'' constructor";
+ if (op->arguments[0]->type == Node::TYPE_TYPE) {
+ TypeNode *tn = static_cast<TypeNode *>(op->arguments[0]);
+ errwhere = "'" + Variant::get_type_name(tn->vtype) + "'' constructor";
} else {
- GDFunctions::Function func = static_cast<BuiltInFunctionNode*>(op->arguments[0])->function;
- errwhere=String("'")+GDFunctions::get_func_name(func)+"'' intrinsic function";
-
+ GDFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function;
+ errwhere = String("'") + GDFunctions::get_func_name(func) + "'' intrinsic function";
}
- switch(ce.error) {
+ switch (ce.error) {
case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: {
- _set_error("Invalid argument (#"+itos(ce.argument+1)+") for "+errwhere+".");
+ _set_error("Invalid argument (#" + itos(ce.argument + 1) + ") for " + errwhere + ".");
} break;
case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
- _set_error("Too many arguments for "+errwhere+".");
+ _set_error("Too many arguments for " + errwhere + ".");
} break;
case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
- _set_error("Too few arguments for "+errwhere+".");
+ _set_error("Too few arguments for " + errwhere + ".");
} break;
default: {
- _set_error("Invalid arguments for "+errwhere+".");
+ _set_error("Invalid arguments for " + errwhere + ".");
} break;
}
- error_line=op->line;
+ error_line = op->line;
return p_node;
}
ConstantNode *cn = alloc_node<ConstantNode>();
- cn->value=v;
+ cn->value = v;
return cn;
- } else if (op->arguments[0]->type==Node::TYPE_BUILT_IN_FUNCTION && last_not_constant==0) {
-
-
-
-
-
+ } else if (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && last_not_constant == 0) {
}
return op; //don't reduce yet
- } else if (op->op==OperatorNode::OP_YIELD) {
+ } else if (op->op == OperatorNode::OP_YIELD) {
return op;
- } else if (op->op==OperatorNode::OP_INDEX) {
+ } else if (op->op == OperatorNode::OP_INDEX) {
//can reduce indices into constant arrays or dictionaries
if (all_constants) {
- ConstantNode *ca = static_cast<ConstantNode*>(op->arguments[0]);
- ConstantNode *cb = static_cast<ConstantNode*>(op->arguments[1]);
-
-
+ ConstantNode *ca = static_cast<ConstantNode *>(op->arguments[0]);
+ ConstantNode *cb = static_cast<ConstantNode *>(op->arguments[1]);
bool valid;
- Variant v = ca->value.get(cb->value,&valid);
+ Variant v = ca->value.get(cb->value, &valid);
if (!valid) {
_set_error("invalid index in constant expression");
- error_line=op->line;
+ error_line = op->line;
return op;
}
ConstantNode *cn = alloc_node<ConstantNode>();
- cn->value=v;
+ cn->value = v;
return cn;
} /*else if (op->arguments[0]->type==Node::TYPE_CONSTANT && op->arguments[1]->type==Node::TYPE_IDENTIFIER) {
@@ -1573,32 +1535,31 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
return op;
- } else if (op->op==OperatorNode::OP_INDEX_NAMED) {
+ } else if (op->op == OperatorNode::OP_INDEX_NAMED) {
- if (op->arguments[0]->type==Node::TYPE_CONSTANT && op->arguments[1]->type==Node::TYPE_IDENTIFIER) {
+ if (op->arguments[0]->type == Node::TYPE_CONSTANT && op->arguments[1]->type == Node::TYPE_IDENTIFIER) {
- ConstantNode *ca = static_cast<ConstantNode*>(op->arguments[0]);
- IdentifierNode *ib = static_cast<IdentifierNode*>(op->arguments[1]);
+ ConstantNode *ca = static_cast<ConstantNode *>(op->arguments[0]);
+ IdentifierNode *ib = static_cast<IdentifierNode *>(op->arguments[1]);
bool valid;
- Variant v = ca->value.get_named(ib->name,&valid);
+ Variant v = ca->value.get_named(ib->name, &valid);
if (!valid) {
- _set_error("invalid index '"+String(ib->name)+"' in constant expression");
- error_line=op->line;
+ _set_error("invalid index '" + String(ib->name) + "' in constant expression");
+ error_line = op->line;
return op;
}
ConstantNode *cn = alloc_node<ConstantNode>();
- cn->value=v;
+ cn->value = v;
return cn;
}
return op;
-
}
//validate assignment (don't assign to cosntant expression
- switch(op->op) {
+ switch (op->op) {
case OperatorNode::OP_ASSIGN:
case OperatorNode::OP_ASSIGN_ADD:
@@ -1612,17 +1573,17 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
case OperatorNode::OP_ASSIGN_BIT_OR:
case OperatorNode::OP_ASSIGN_BIT_XOR: {
- if (op->arguments[0]->type==Node::TYPE_CONSTANT) {
- _set_error("Can't assign to constant",tokenizer->get_token_line()-1);
- error_line=op->line;
+ if (op->arguments[0]->type == Node::TYPE_CONSTANT) {
+ _set_error("Can't assign to constant", tokenizer->get_token_line() - 1);
+ error_line = op->line;
return op;
}
- if (op->arguments[0]->type==Node::TYPE_OPERATOR) {
- OperatorNode *on = static_cast<OperatorNode*>(op->arguments[0]);
+ if (op->arguments[0]->type == Node::TYPE_OPERATOR) {
+ OperatorNode *on = static_cast<OperatorNode *>(op->arguments[0]);
if (on->op != OperatorNode::OP_INDEX && on->op != OperatorNode::OP_INDEX_NAMED) {
- _set_error("Can't assign to an expression",tokenizer->get_token_line()-1);
- error_line=op->line;
+ _set_error("Can't assign to an expression", tokenizer->get_token_line() - 1);
+ error_line = op->line;
return op;
}
}
@@ -1633,59 +1594,105 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
//now se if all are constants
if (!all_constants)
return op; //nothing to reduce from here on
-#define _REDUCE_UNARY(m_vop)\
- bool valid=false;\
- Variant res;\
- Variant::evaluate(m_vop,static_cast<ConstantNode*>(op->arguments[0])->value,Variant(),res,valid);\
- if (!valid) {\
- _set_error("Invalid operand for unary operator");\
- error_line=op->line;\
- return p_node;\
- }\
- ConstantNode *cn = alloc_node<ConstantNode>();\
- cn->value=res;\
+#define _REDUCE_UNARY(m_vop) \
+ bool valid = false; \
+ Variant res; \
+ Variant::evaluate(m_vop, static_cast<ConstantNode *>(op->arguments[0])->value, Variant(), res, valid); \
+ if (!valid) { \
+ _set_error("Invalid operand for unary operator"); \
+ error_line = op->line; \
+ return p_node; \
+ } \
+ ConstantNode *cn = alloc_node<ConstantNode>(); \
+ cn->value = res; \
return cn;
-#define _REDUCE_BINARY(m_vop)\
- bool valid=false;\
- Variant res;\
- Variant::evaluate(m_vop,static_cast<ConstantNode*>(op->arguments[0])->value,static_cast<ConstantNode*>(op->arguments[1])->value,res,valid);\
- if (!valid) {\
- _set_error("Invalid operands for operator");\
- error_line=op->line;\
- return p_node;\
- }\
- ConstantNode *cn = alloc_node<ConstantNode>();\
- cn->value=res;\
+#define _REDUCE_BINARY(m_vop) \
+ bool valid = false; \
+ Variant res; \
+ Variant::evaluate(m_vop, static_cast<ConstantNode *>(op->arguments[0])->value, static_cast<ConstantNode *>(op->arguments[1])->value, res, valid); \
+ if (!valid) { \
+ _set_error("Invalid operands for operator"); \
+ error_line = op->line; \
+ return p_node; \
+ } \
+ ConstantNode *cn = alloc_node<ConstantNode>(); \
+ cn->value = res; \
return cn;
- switch(op->op) {
+ switch (op->op) {
//unary operators
- case OperatorNode::OP_NEG: { _REDUCE_UNARY(Variant::OP_NEGATE); } break;
- case OperatorNode::OP_POS: { _REDUCE_UNARY(Variant::OP_POSITIVE); } break;
- case OperatorNode::OP_NOT: { _REDUCE_UNARY(Variant::OP_NOT); } break;
- case OperatorNode::OP_BIT_INVERT: { _REDUCE_UNARY(Variant::OP_BIT_NEGATE); } break;
+ case OperatorNode::OP_NEG: {
+ _REDUCE_UNARY(Variant::OP_NEGATE);
+ } break;
+ case OperatorNode::OP_POS: {
+ _REDUCE_UNARY(Variant::OP_POSITIVE);
+ } break;
+ case OperatorNode::OP_NOT: {
+ _REDUCE_UNARY(Variant::OP_NOT);
+ } break;
+ case OperatorNode::OP_BIT_INVERT: {
+ _REDUCE_UNARY(Variant::OP_BIT_NEGATE);
+ } break;
//binary operators (in precedence order)
- case OperatorNode::OP_IN: { _REDUCE_BINARY(Variant::OP_IN); } break;
- case OperatorNode::OP_EQUAL: { _REDUCE_BINARY(Variant::OP_EQUAL); } break;
- case OperatorNode::OP_NOT_EQUAL: { _REDUCE_BINARY(Variant::OP_NOT_EQUAL); } break;
- case OperatorNode::OP_LESS: { _REDUCE_BINARY(Variant::OP_LESS); } break;
- case OperatorNode::OP_LESS_EQUAL: { _REDUCE_BINARY(Variant::OP_LESS_EQUAL); } break;
- case OperatorNode::OP_GREATER: { _REDUCE_BINARY(Variant::OP_GREATER); } break;
- case OperatorNode::OP_GREATER_EQUAL: { _REDUCE_BINARY(Variant::OP_GREATER_EQUAL); } break;
- case OperatorNode::OP_AND: { _REDUCE_BINARY(Variant::OP_AND); } break;
- case OperatorNode::OP_OR: { _REDUCE_BINARY(Variant::OP_OR); } break;
- case OperatorNode::OP_ADD: { _REDUCE_BINARY(Variant::OP_ADD); } break;
- case OperatorNode::OP_SUB: { _REDUCE_BINARY(Variant::OP_SUBSTRACT); } break;
- case OperatorNode::OP_MUL: { _REDUCE_BINARY(Variant::OP_MULTIPLY); } break;
- case OperatorNode::OP_DIV: { _REDUCE_BINARY(Variant::OP_DIVIDE); } break;
- case OperatorNode::OP_MOD: { _REDUCE_BINARY(Variant::OP_MODULE); } break;
- case OperatorNode::OP_SHIFT_LEFT: { _REDUCE_BINARY(Variant::OP_SHIFT_LEFT); } break;
- case OperatorNode::OP_SHIFT_RIGHT: { _REDUCE_BINARY(Variant::OP_SHIFT_RIGHT); } break;
- case OperatorNode::OP_BIT_AND: { _REDUCE_BINARY(Variant::OP_BIT_AND); } break;
- case OperatorNode::OP_BIT_OR: { _REDUCE_BINARY(Variant::OP_BIT_OR); } break;
- case OperatorNode::OP_BIT_XOR: { _REDUCE_BINARY(Variant::OP_BIT_XOR); } break;
+ case OperatorNode::OP_IN: {
+ _REDUCE_BINARY(Variant::OP_IN);
+ } break;
+ case OperatorNode::OP_EQUAL: {
+ _REDUCE_BINARY(Variant::OP_EQUAL);
+ } break;
+ case OperatorNode::OP_NOT_EQUAL: {
+ _REDUCE_BINARY(Variant::OP_NOT_EQUAL);
+ } break;
+ case OperatorNode::OP_LESS: {
+ _REDUCE_BINARY(Variant::OP_LESS);
+ } break;
+ case OperatorNode::OP_LESS_EQUAL: {
+ _REDUCE_BINARY(Variant::OP_LESS_EQUAL);
+ } break;
+ case OperatorNode::OP_GREATER: {
+ _REDUCE_BINARY(Variant::OP_GREATER);
+ } break;
+ case OperatorNode::OP_GREATER_EQUAL: {
+ _REDUCE_BINARY(Variant::OP_GREATER_EQUAL);
+ } break;
+ case OperatorNode::OP_AND: {
+ _REDUCE_BINARY(Variant::OP_AND);
+ } break;
+ case OperatorNode::OP_OR: {
+ _REDUCE_BINARY(Variant::OP_OR);
+ } break;
+ case OperatorNode::OP_ADD: {
+ _REDUCE_BINARY(Variant::OP_ADD);
+ } break;
+ case OperatorNode::OP_SUB: {
+ _REDUCE_BINARY(Variant::OP_SUBSTRACT);
+ } break;
+ case OperatorNode::OP_MUL: {
+ _REDUCE_BINARY(Variant::OP_MULTIPLY);
+ } break;
+ case OperatorNode::OP_DIV: {
+ _REDUCE_BINARY(Variant::OP_DIVIDE);
+ } break;
+ case OperatorNode::OP_MOD: {
+ _REDUCE_BINARY(Variant::OP_MODULE);
+ } break;
+ case OperatorNode::OP_SHIFT_LEFT: {
+ _REDUCE_BINARY(Variant::OP_SHIFT_LEFT);
+ } break;
+ case OperatorNode::OP_SHIFT_RIGHT: {
+ _REDUCE_BINARY(Variant::OP_SHIFT_RIGHT);
+ } break;
+ case OperatorNode::OP_BIT_AND: {
+ _REDUCE_BINARY(Variant::OP_BIT_AND);
+ } break;
+ case OperatorNode::OP_BIT_OR: {
+ _REDUCE_BINARY(Variant::OP_BIT_OR);
+ } break;
+ case OperatorNode::OP_BIT_XOR: {
+ _REDUCE_BINARY(Variant::OP_BIT_XOR);
+ } break;
default: { ERR_FAIL_V(op); }
}
@@ -1694,16 +1701,15 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
default: {
return p_node;
} break;
-
}
}
-GDParser::Node* GDParser::_parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const,bool p_allow_assign) {
+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,p_reduce_const);
+ 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);
+ expr = _reduce_expression(expr, p_reduce_const);
if (!expr || error_set)
return NULL;
return expr;
@@ -1715,43 +1721,42 @@ bool GDParser::_recover_from_completion() {
return false; //can't recover if no completion
}
//skip stuff until newline
- while(tokenizer->get_token()!=GDTokenizer::TK_NEWLINE && tokenizer->get_token()!=GDTokenizer::TK_EOF && tokenizer->get_token()!=GDTokenizer::TK_ERROR) {
+ while (tokenizer->get_token() != GDTokenizer::TK_NEWLINE && tokenizer->get_token() != GDTokenizer::TK_EOF && tokenizer->get_token() != GDTokenizer::TK_ERROR) {
tokenizer->advance();
}
- completion_found=false;
- error_set=false;
- if(tokenizer->get_token() == GDTokenizer::TK_ERROR){
+ completion_found = false;
+ error_set = false;
+ if (tokenizer->get_token() == GDTokenizer::TK_ERROR) {
error_set = true;
}
return true;
}
-GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
-{
-
+GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) {
+
PatternNode *pattern = alloc_node<PatternNode>();
-
+
GDTokenizer::Token token = tokenizer->get_token();
if (error_set)
return NULL;
-
+
if (token == GDTokenizer::TK_EOF) {
return NULL;
}
-
+
switch (token) {
// array
case GDTokenizer::TK_BRACKET_OPEN: {
tokenizer->advance();
pattern->pt_type = GDParser::PatternNode::PT_ARRAY;
while (true) {
-
+
if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) {
tokenizer->advance();
break;
}
-
+
if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) {
// match everything
tokenizer->advance(2);
@@ -1769,14 +1774,14 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
return NULL;
}
}
-
+
PatternNode *sub_pattern = _parse_pattern(p_static);
if (!sub_pattern) {
return NULL;
}
-
+
pattern->array.push_back(sub_pattern);
-
+
if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
continue;
@@ -1801,12 +1806,12 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
tokenizer->advance();
pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY;
while (true) {
-
+
if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) {
tokenizer->advance();
break;
}
-
+
if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) {
// match everything
tokenizer->advance(2);
@@ -1824,33 +1829,32 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
return NULL;
}
}
-
+
Node *key = _parse_and_reduce_expression(pattern, p_static);
if (!key) {
_set_error("Not a valid key in pattern");
return NULL;
}
-
+
if (key->type != GDParser::Node::TYPE_CONSTANT) {
_set_error("Not a constant expression as key");
return NULL;
}
-
+
if (tokenizer->get_token() == GDTokenizer::TK_COLON) {
tokenizer->advance();
-
+
PatternNode *value = _parse_pattern(p_static);
if (!value) {
_set_error("Expected pattern in dictionary value");
return NULL;
}
-
- pattern->dictionary.insert(static_cast<ConstantNode*>(key), value);
+
+ pattern->dictionary.insert(static_cast<ConstantNode *>(key), value);
} else {
- pattern->dictionary.insert(static_cast<ConstantNode*>(key), NULL);
+ pattern->dictionary.insert(static_cast<ConstantNode *>(key), NULL);
}
-
-
+
if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
continue;
@@ -1873,47 +1877,47 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
if (error_set) {
return NULL;
}
-
+
if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) {
_set_error("Only constant expressions or variables allowed in a pattern");
return NULL;
}
-
+
pattern->pt_type = PatternNode::PT_CONSTANT;
pattern->constant = value;
} break;
}
-
+
return pattern;
}
-void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static)
-{
+void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static) {
int indent_level = tab_level.back()->get();
-
+
while (true) {
-
- while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline());
-
+
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline())
+ ;
+
// GDTokenizer::Token token = tokenizer->get_token();
if (error_set)
return;
-
+
if (indent_level > tab_level.back()->get()) {
return; // go back a level
}
-
- if (pending_newline!=-1) {
- pending_newline=-1;
+
+ if (pending_newline != -1) {
+ pending_newline = -1;
}
-
+
PatternBranchNode *branch = alloc_node<PatternBranchNode>();
-
+
branch->patterns.push_back(_parse_pattern(p_static));
if (!branch->patterns[0]) {
return;
}
-
+
while (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
branch->patterns.push_back(_parse_pattern(p_static));
@@ -1921,263 +1925,249 @@ void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode
return;
}
}
-
- if(!_enter_indent_block()) {
+
+ if (!_enter_indent_block()) {
_set_error("Expected block in pattern branch");
return;
}
-
+
branch->body = alloc_node<BlockNode>();
branch->body->parent_block = p_block;
p_block->sub_blocks.push_back(branch->body);
current_block = branch->body;
-
+
_parse_block(branch->body, p_static);
-
+
current_block = p_block;
-
+
p_branches.push_back(branch);
}
}
-
-void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings)
-{
+void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings) {
switch (p_pattern->pt_type) {
case PatternNode::PT_CONSTANT: {
-
+
// typecheck
BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>();
typeof_node->function = GDFunctions::TYPE_OF;
-
+
OperatorNode *typeof_match_value = alloc_node<OperatorNode>();
typeof_match_value->op = OperatorNode::OP_CALL;
typeof_match_value->arguments.push_back(typeof_node);
typeof_match_value->arguments.push_back(p_node_to_match);
-
+
OperatorNode *typeof_pattern_value = alloc_node<OperatorNode>();
typeof_pattern_value->op = OperatorNode::OP_CALL;
typeof_pattern_value->arguments.push_back(typeof_node);
typeof_pattern_value->arguments.push_back(p_pattern->constant);
-
+
OperatorNode *type_comp = alloc_node<OperatorNode>();
type_comp->op = OperatorNode::OP_EQUAL;
type_comp->arguments.push_back(typeof_match_value);
type_comp->arguments.push_back(typeof_pattern_value);
-
-
+
// comare the actual values
OperatorNode *value_comp = alloc_node<OperatorNode>();
value_comp->op = OperatorNode::OP_EQUAL;
value_comp->arguments.push_back(p_pattern->constant);
value_comp->arguments.push_back(p_node_to_match);
-
-
+
OperatorNode *comparison = alloc_node<OperatorNode>();
comparison->op = OperatorNode::OP_AND;
comparison->arguments.push_back(type_comp);
comparison->arguments.push_back(value_comp);
-
+
p_resulting_node = comparison;
-
+
} break;
case PatternNode::PT_BIND: {
p_bindings[p_pattern->bind] = p_node_to_match;
-
+
// a bind always matches
ConstantNode *true_value = alloc_node<ConstantNode>();
true_value->value = Variant(true);
p_resulting_node = true_value;
} break;
case PatternNode::PT_ARRAY: {
-
+
bool open_ended = false;
-
+
if (p_pattern->array.size() > 0) {
if (p_pattern->array[p_pattern->array.size() - 1]->pt_type == PatternNode::PT_IGNORE_REST) {
open_ended = true;
}
}
-
+
// typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() >= length
// typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() == length
-
+
{
// typecheck
BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>();
typeof_node->function = GDFunctions::TYPE_OF;
-
+
OperatorNode *typeof_match_value = alloc_node<OperatorNode>();
typeof_match_value->op = OperatorNode::OP_CALL;
typeof_match_value->arguments.push_back(typeof_node);
typeof_match_value->arguments.push_back(p_node_to_match);
-
+
IdentifierNode *typeof_array = alloc_node<IdentifierNode>();
typeof_array->name = "TYPE_ARRAY";
-
+
OperatorNode *type_comp = alloc_node<OperatorNode>();
type_comp->op = OperatorNode::OP_EQUAL;
type_comp->arguments.push_back(typeof_match_value);
type_comp->arguments.push_back(typeof_array);
-
-
+
// size
ConstantNode *length = alloc_node<ConstantNode>();
length->value = Variant(open_ended ? p_pattern->array.size() - 1 : p_pattern->array.size());
-
+
OperatorNode *call = alloc_node<OperatorNode>();
call->op = OperatorNode::OP_CALL;
call->arguments.push_back(p_node_to_match);
-
+
IdentifierNode *size = alloc_node<IdentifierNode>();
size->name = "size";
call->arguments.push_back(size);
-
+
OperatorNode *length_comparison = alloc_node<OperatorNode>();
length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL;
length_comparison->arguments.push_back(call);
length_comparison->arguments.push_back(length);
-
+
OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>();
type_and_length_comparison->op = OperatorNode::OP_AND;
type_and_length_comparison->arguments.push_back(type_comp);
type_and_length_comparison->arguments.push_back(length_comparison);
-
+
p_resulting_node = type_and_length_comparison;
}
-
-
-
+
for (int i = 0; i < p_pattern->array.size(); i++) {
PatternNode *pattern = p_pattern->array[i];
-
+
Node *condition = NULL;
-
+
ConstantNode *index = alloc_node<ConstantNode>();
index->value = Variant(i);
-
+
OperatorNode *indexed_value = alloc_node<OperatorNode>();
indexed_value->op = OperatorNode::OP_INDEX;
indexed_value->arguments.push_back(p_node_to_match);
indexed_value->arguments.push_back(index);
-
+
_generate_pattern(pattern, indexed_value, condition, p_bindings);
-
+
// concatenate all the patterns with &&
OperatorNode *and_node = alloc_node<OperatorNode>();
and_node->op = OperatorNode::OP_AND;
and_node->arguments.push_back(p_resulting_node);
and_node->arguments.push_back(condition);
-
+
p_resulting_node = and_node;
}
-
-
+
} break;
case PatternNode::PT_DICTIONARY: {
-
+
bool open_ended = false;
-
+
if (p_pattern->array.size() > 0) {
open_ended = true;
}
-
+
// typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() >= length
// typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() == length
-
-
+
{
// typecheck
BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>();
typeof_node->function = GDFunctions::TYPE_OF;
-
+
OperatorNode *typeof_match_value = alloc_node<OperatorNode>();
typeof_match_value->op = OperatorNode::OP_CALL;
typeof_match_value->arguments.push_back(typeof_node);
typeof_match_value->arguments.push_back(p_node_to_match);
-
+
IdentifierNode *typeof_dictionary = alloc_node<IdentifierNode>();
typeof_dictionary->name = "TYPE_DICTIONARY";
-
+
OperatorNode *type_comp = alloc_node<OperatorNode>();
type_comp->op = OperatorNode::OP_EQUAL;
type_comp->arguments.push_back(typeof_match_value);
type_comp->arguments.push_back(typeof_dictionary);
-
+
// size
ConstantNode *length = alloc_node<ConstantNode>();
length->value = Variant(open_ended ? p_pattern->dictionary.size() - 1 : p_pattern->dictionary.size());
-
+
OperatorNode *call = alloc_node<OperatorNode>();
call->op = OperatorNode::OP_CALL;
call->arguments.push_back(p_node_to_match);
-
+
IdentifierNode *size = alloc_node<IdentifierNode>();
size->name = "size";
call->arguments.push_back(size);
-
+
OperatorNode *length_comparison = alloc_node<OperatorNode>();
length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL;
length_comparison->arguments.push_back(call);
length_comparison->arguments.push_back(length);
-
+
OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>();
type_and_length_comparison->op = OperatorNode::OP_AND;
type_and_length_comparison->arguments.push_back(type_comp);
type_and_length_comparison->arguments.push_back(length_comparison);
-
+
p_resulting_node = type_and_length_comparison;
}
-
-
-
- for (Map<ConstantNode*, PatternNode*>::Element *e = p_pattern->dictionary.front(); e; e = e->next()) {
-
+
+ for (Map<ConstantNode *, PatternNode *>::Element *e = p_pattern->dictionary.front(); e; e = e->next()) {
+
Node *condition = NULL;
-
+
// chech for has, then for pattern
-
+
IdentifierNode *has = alloc_node<IdentifierNode>();
has->name = "has";
-
+
OperatorNode *has_call = alloc_node<OperatorNode>();
has_call->op = OperatorNode::OP_CALL;
has_call->arguments.push_back(p_node_to_match);
has_call->arguments.push_back(has);
has_call->arguments.push_back(e->key());
-
-
+
if (e->value()) {
-
+
OperatorNode *indexed_value = alloc_node<OperatorNode>();
indexed_value->op = OperatorNode::OP_INDEX;
indexed_value->arguments.push_back(p_node_to_match);
indexed_value->arguments.push_back(e->key());
-
+
_generate_pattern(e->value(), indexed_value, condition, p_bindings);
-
+
OperatorNode *has_and_pattern = alloc_node<OperatorNode>();
has_and_pattern->op = OperatorNode::OP_AND;
has_and_pattern->arguments.push_back(has_call);
has_and_pattern->arguments.push_back(condition);
-
+
condition = has_and_pattern;
} else {
condition = has_call;
}
-
-
-
+
// concatenate all the patterns with &&
OperatorNode *and_node = alloc_node<OperatorNode>();
and_node->op = OperatorNode::OP_AND;
and_node->arguments.push_back(p_resulting_node);
and_node->arguments.push_back(condition);
-
+
p_resulting_node = and_node;
}
-
+
} break;
case PatternNode::PT_IGNORE_REST:
case PatternNode::PT_WILDCARD: {
@@ -2187,119 +2177,110 @@ void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match,
p_resulting_node = true_value;
} break;
default: {
-
+
} break;
}
}
-void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement)
-{
+void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement) {
IdentifierNode *id = alloc_node<IdentifierNode>();
id->name = "#match_value";
-
+
for (int i = 0; i < p_match_statement->branches.size(); i++) {
-
+
PatternBranchNode *branch = p_match_statement->branches[i];
-
+
MatchNode::CompiledPatternBranch compiled_branch;
compiled_branch.compiled_pattern = NULL;
-
- Map<StringName, Node*> binding;
-
+
+ Map<StringName, Node *> binding;
+
for (int j = 0; j < branch->patterns.size(); j++) {
PatternNode *pattern = branch->patterns[j];
-
- Map<StringName, Node*> bindings;
+
+ Map<StringName, Node *> bindings;
Node *resulting_node;
_generate_pattern(pattern, id, resulting_node, bindings);
-
+
if (!binding.empty() && !bindings.empty()) {
_set_error("Multipatterns can't contain bindings");
return;
} else {
binding = bindings;
}
-
+
if (compiled_branch.compiled_pattern) {
OperatorNode *or_node = alloc_node<OperatorNode>();
or_node->op = OperatorNode::OP_OR;
or_node->arguments.push_back(compiled_branch.compiled_pattern);
or_node->arguments.push_back(resulting_node);
-
+
compiled_branch.compiled_pattern = or_node;
} else {
// single pattern | first one
compiled_branch.compiled_pattern = resulting_node;
}
-
}
-
-
+
// prepare the body ...hehe
- for (Map<StringName, Node*>::Element *e = binding.front(); e; e = e->next()) {
+ for (Map<StringName, Node *>::Element *e = binding.front(); e; e = e->next()) {
LocalVarNode *local_var = alloc_node<LocalVarNode>();
local_var->name = e->key();
local_var->assign = e->value();
-
IdentifierNode *id = alloc_node<IdentifierNode>();
id->name = local_var->name;
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_ASSIGN;
+ op->op = OperatorNode::OP_ASSIGN;
op->arguments.push_back(id);
op->arguments.push_back(local_var->assign);
-
+
branch->body->statements.push_front(op);
branch->body->statements.push_front(local_var);
}
-
+
compiled_branch.body = branch->body;
-
-
+
p_match_statement->compiled_pattern_branches.push_back(compiled_branch);
}
-
}
-void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
+void GDParser::_parse_block(BlockNode *p_block, bool p_static) {
int indent_level = tab_level.back()->get();
-
#ifdef DEBUG_ENABLED
NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line=tokenizer->get_token_line();
+ nl->line = tokenizer->get_token_line();
p_block->statements.push_back(nl);
#endif
- while(true) {
+ while (true) {
GDTokenizer::Token token = tokenizer->get_token();
if (error_set)
return;
- if (indent_level>tab_level.back()->get()) {
- p_block->end_line=tokenizer->get_token_line();
+ if (indent_level > tab_level.back()->get()) {
+ p_block->end_line = tokenizer->get_token_line();
return; //go back a level
}
- if (pending_newline!=-1) {
+ if (pending_newline != -1) {
NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line=pending_newline;
+ nl->line = pending_newline;
p_block->statements.push_back(nl);
- pending_newline=-1;
-
+ pending_newline = -1;
}
- switch(token) {
-
+ switch (token) {
case GDTokenizer::TK_EOF:
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
case GDTokenizer::TK_ERROR: {
return; //go back
@@ -2310,26 +2291,25 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
if (!_parse_newline()) {
if (!error_set) {
- p_block->end_line=tokenizer->get_token_line();
- pending_newline=p_block->end_line;
-
+ p_block->end_line = tokenizer->get_token_line();
+ pending_newline = p_block->end_line;
}
return;
}
NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line=tokenizer->get_token_line();
+ nl->line = tokenizer->get_token_line();
p_block->statements.push_back(nl);
} break;
case GDTokenizer::TK_CF_PASS: {
- if (tokenizer->get_token(1)!=GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE && tokenizer->get_token(1)!=GDTokenizer::TK_EOF) {
+ if (tokenizer->get_token(1) != GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE && tokenizer->get_token(1) != GDTokenizer::TK_EOF) {
_set_error("Expected ';' or <NewLine>.");
return;
}
tokenizer->advance();
- if(tokenizer->get_token()==GDTokenizer::TK_SEMICOLON) {
+ if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON) {
// Ignore semicolon after 'pass'
tokenizer->advance();
}
@@ -2338,26 +2318,26 @@ 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->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier for local variable name.");
return;
}
StringName n = tokenizer->get_token_identifier();
tokenizer->advance();
- if (current_function){
- for (int i=0;i<current_function->arguments.size();i++){
- if (n == current_function->arguments[i]){
- _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(current_function->line)+").");
+ if (current_function) {
+ for (int i = 0; i < current_function->arguments.size(); i++) {
+ if (n == current_function->arguments[i]) {
+ _set_error("Variable '" + String(n) + "' already defined in the scope (at line: " + itos(current_function->line) + ").");
return;
}
}
}
BlockNode *check_block = p_block;
- while (check_block){
- for (int i=0;i<check_block->variables.size();i++){
- if (n == check_block->variables[i]){
- _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(check_block->variable_lines[i])+").");
+ while (check_block) {
+ for (int i = 0; i < check_block->variables.size(); i++) {
+ if (n == check_block->variables[i]) {
+ _set_error("Variable '" + String(n) + "' already defined in the scope (at line: " + itos(check_block->variable_lines[i]) + ").");
return;
}
}
@@ -2367,20 +2347,19 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
p_block->variables.push_back(n); //line?
p_block->variable_lines.push_back(tokenizer->get_token_line());
-
//must know when the local variable is declared
LocalVarNode *lv = alloc_node<LocalVarNode>();
- lv->name=n;
+ lv->name = n;
p_block->statements.push_back(lv);
- Node *assigned=NULL;
+ Node *assigned = NULL;
- if (tokenizer->get_token()==GDTokenizer::TK_OP_ASSIGN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) {
tokenizer->advance();
- Node *subexpr=NULL;
+ Node *subexpr = NULL;
- subexpr = _parse_and_reduce_expression(p_block,p_static);
+ subexpr = _parse_and_reduce_expression(p_block, p_static);
if (!subexpr) {
if (_recover_from_completion()) {
break;
@@ -2388,23 +2367,19 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
-
-
- lv->assign=subexpr;
- assigned=subexpr;
+ lv->assign = subexpr;
+ assigned = subexpr;
} else {
ConstantNode *c = alloc_node<ConstantNode>();
- c->value=Variant();
+ c->value = Variant();
assigned = c;
-
}
IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name=n;
-
+ id->name = n;
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_ASSIGN;
+ op->op = OperatorNode::OP_ASSIGN;
op->arguments.push_back(id);
op->arguments.push_back(assigned);
p_block->statements.push_back(op);
@@ -2418,8 +2393,8 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
case GDTokenizer::TK_CF_IF: {
tokenizer->advance();
-
- Node *condition = _parse_and_reduce_expression(p_block,p_static);
+
+ Node *condition = _parse_and_reduce_expression(p_block, p_static);
if (!condition) {
if (_recover_from_completion()) {
break;
@@ -2429,39 +2404,39 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
ControlFlowNode *cf_if = alloc_node<ControlFlowNode>();
- cf_if->cf_type=ControlFlowNode::CF_IF;
+ cf_if->cf_type = ControlFlowNode::CF_IF;
cf_if->arguments.push_back(condition);
cf_if->body = alloc_node<BlockNode>();
- cf_if->body->parent_block=p_block;
+ cf_if->body->parent_block = p_block;
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
_set_error("Expected intended block after 'if'");
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- current_block=cf_if->body;
- _parse_block(cf_if->body,p_static);
- current_block=p_block;
+ current_block = cf_if->body;
+ _parse_block(cf_if->body, p_static);
+ current_block = p_block;
if (error_set)
return;
p_block->statements.push_back(cf_if);
- while(true) {
+ while (true) {
- while(tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
if (tab_level.back()->get() < indent_level) { //not at current indent level
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- if (tokenizer->get_token()==GDTokenizer::TK_CF_ELIF) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CF_ELIF) {
if (tab_level.back()->get() > indent_level) {
@@ -2471,15 +2446,15 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
- cf_if->body_else=alloc_node<BlockNode>();
- cf_if->body_else->parent_block=p_block;
+ cf_if->body_else = alloc_node<BlockNode>();
+ cf_if->body_else->parent_block = p_block;
p_block->sub_blocks.push_back(cf_if->body_else);
ControlFlowNode *cf_else = alloc_node<ControlFlowNode>();
- cf_else->cf_type=ControlFlowNode::CF_IF;
+ cf_else->cf_type = ControlFlowNode::CF_IF;
//condition
- Node *condition = _parse_and_reduce_expression(p_block,p_static);
+ Node *condition = _parse_and_reduce_expression(p_block, p_static);
if (!condition) {
if (_recover_from_completion()) {
break;
@@ -2487,66 +2462,60 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
cf_else->arguments.push_back(condition);
- cf_else->cf_type=ControlFlowNode::CF_IF;
+ cf_else->cf_type = ControlFlowNode::CF_IF;
cf_if->body_else->statements.push_back(cf_else);
- cf_if=cf_else;
- cf_if->body=alloc_node<BlockNode>();
- cf_if->body->parent_block=p_block;
+ cf_if = cf_else;
+ cf_if->body = alloc_node<BlockNode>();
+ cf_if->body->parent_block = p_block;
p_block->sub_blocks.push_back(cf_if->body);
-
if (!_enter_indent_block(cf_if->body)) {
_set_error("Expected indented block after 'elif'");
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- current_block=cf_else->body;
- _parse_block(cf_else->body,p_static);
- current_block=p_block;
+ current_block = cf_else->body;
+ _parse_block(cf_else->body, p_static);
+ current_block = p_block;
if (error_set)
return;
-
- } else if (tokenizer->get_token()==GDTokenizer::TK_CF_ELSE) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CF_ELSE) {
if (tab_level.back()->get() > indent_level) {
_set_error("Invalid indent");
return;
}
-
tokenizer->advance();
- cf_if->body_else=alloc_node<BlockNode>();
- cf_if->body_else->parent_block=p_block;
+ cf_if->body_else = alloc_node<BlockNode>();
+ cf_if->body_else->parent_block = p_block;
p_block->sub_blocks.push_back(cf_if->body_else);
if (!_enter_indent_block(cf_if->body_else)) {
_set_error("Expected indented block after 'else'");
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- current_block=cf_if->body_else;
- _parse_block(cf_if->body_else,p_static);
- current_block=p_block;
+ current_block = cf_if->body_else;
+ _parse_block(cf_if->body_else, p_static);
+ current_block = p_block;
if (error_set)
return;
-
break; //after else, exit
} else
break;
-
}
-
} break;
case GDTokenizer::TK_CF_WHILE: {
tokenizer->advance();
- Node *condition = _parse_and_reduce_expression(p_block,p_static);
+ Node *condition = _parse_and_reduce_expression(p_block, p_static);
if (!condition) {
if (_recover_from_completion()) {
break;
@@ -2556,22 +2525,22 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
ControlFlowNode *cf_while = alloc_node<ControlFlowNode>();
- cf_while->cf_type=ControlFlowNode::CF_WHILE;
+ cf_while->cf_type = ControlFlowNode::CF_WHILE;
cf_while->arguments.push_back(condition);
cf_while->body = alloc_node<BlockNode>();
- cf_while->body->parent_block=p_block;
+ cf_while->body->parent_block = p_block;
p_block->sub_blocks.push_back(cf_while->body);
if (!_enter_indent_block(cf_while->body)) {
_set_error("Expected indented block after 'while'");
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- current_block=cf_while->body;
- _parse_block(cf_while->body,p_static);
- current_block=p_block;
+ current_block = cf_while->body;
+ _parse_block(cf_while->body, p_static);
+ current_block = p_block;
if (error_set)
return;
p_block->statements.push_back(cf_while);
@@ -2580,24 +2549,24 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("identifier expected after 'for'");
}
IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name=tokenizer->get_token_identifier();
+ id->name = tokenizer->get_token_identifier();
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_OP_IN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_OP_IN) {
_set_error("'in' expected after identifier");
return;
}
tokenizer->advance();
- Node *container = _parse_and_reduce_expression(p_block,p_static);
+ Node *container = _parse_and_reduce_expression(p_block, p_static);
if (!container) {
if (_recover_from_completion()) {
break;
@@ -2605,91 +2574,90 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
- if (container->type==Node::TYPE_OPERATOR) {
+ if (container->type == Node::TYPE_OPERATOR) {
- OperatorNode* op = static_cast<OperatorNode*>(container);
- if (op->op==OperatorNode::OP_CALL && op->arguments[0]->type==Node::TYPE_BUILT_IN_FUNCTION && static_cast<BuiltInFunctionNode*>(op->arguments[0])->function==GDFunctions::GEN_RANGE) {
+ OperatorNode *op = static_cast<OperatorNode *>(container);
+ if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && static_cast<BuiltInFunctionNode *>(op->arguments[0])->function == GDFunctions::GEN_RANGE) {
//iterating a range, so see if range() can be optimized without allocating memory, by replacing it by vectors (which can work as iterable too!)
- Vector<Node*> args;
+ Vector<Node *> args;
Vector<double> constants;
- bool constant=false;
+ bool constant = false;
- for(int i=1;i<op->arguments.size();i++) {
+ for (int i = 1; i < op->arguments.size(); i++) {
args.push_back(op->arguments[i]);
- if (constant && op->arguments[i]->type==Node::TYPE_CONSTANT) {
- ConstantNode *c = static_cast<ConstantNode*>(op->arguments[i]);
- if (c->value.get_type()==Variant::REAL || c->value.get_type()==Variant::INT) {
+ if (constant && op->arguments[i]->type == Node::TYPE_CONSTANT) {
+ ConstantNode *c = static_cast<ConstantNode *>(op->arguments[i]);
+ if (c->value.get_type() == Variant::REAL || c->value.get_type() == Variant::INT) {
constants.push_back(c->value);
- constant=true;
+ constant = true;
}
} else {
- constant=false;
+ constant = false;
}
}
- if (args.size()>0 && args.size()<4) {
+ if (args.size() > 0 && args.size() < 4) {
if (constant) {
ConstantNode *cn = alloc_node<ConstantNode>();
- switch(args.size()) {
- case 1: cn->value=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;
+ switch (args.size()) {
+ case 1: cn->value = 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;
}
- container=cn;
+ container = cn;
} else {
OperatorNode *on = alloc_node<OperatorNode>();
- on->op=OperatorNode::OP_CALL;
+ on->op = OperatorNode::OP_CALL;
TypeNode *tn = alloc_node<TypeNode>();
on->arguments.push_back(tn);
- switch(args.size()) {
- case 1: tn->vtype=Variant::REAL; break;
- case 2: tn->vtype=Variant::VECTOR2; break;
- case 3: tn->vtype=Variant::VECTOR3; break;
+ switch (args.size()) {
+ case 1: tn->vtype = Variant::REAL; break;
+ case 2: tn->vtype = Variant::VECTOR2; break;
+ case 3: tn->vtype = Variant::VECTOR3; break;
}
- for(int i=0;i<args.size();i++) {
+ for (int i = 0; i < args.size(); i++) {
on->arguments.push_back(args[i]);
}
- container=on;
+ container = on;
}
}
}
-
}
ControlFlowNode *cf_for = alloc_node<ControlFlowNode>();
- cf_for->cf_type=ControlFlowNode::CF_FOR;
+ cf_for->cf_type = ControlFlowNode::CF_FOR;
cf_for->arguments.push_back(id);
cf_for->arguments.push_back(container);
cf_for->body = alloc_node<BlockNode>();
- cf_for->body->parent_block=p_block;
+ cf_for->body->parent_block = p_block;
p_block->sub_blocks.push_back(cf_for->body);
if (!_enter_indent_block(cf_for->body)) {
_set_error("Expected indented block after 'for'");
- p_block->end_line=tokenizer->get_token_line();
+ p_block->end_line = tokenizer->get_token_line();
return;
}
- current_block=cf_for->body;
+ current_block = cf_for->body;
// this is for checking variable for redefining
// inside this _parse_block
cf_for->body->variables.push_back(id->name);
cf_for->body->variable_lines.push_back(id->line);
- _parse_block(cf_for->body,p_static);
+ _parse_block(cf_for->body, p_static);
cf_for->body->variables.remove(0);
cf_for->body->variable_lines.remove(0);
- current_block=p_block;
+ current_block = p_block;
if (error_set)
return;
@@ -2699,7 +2667,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
ControlFlowNode *cf_continue = alloc_node<ControlFlowNode>();
- cf_continue->cf_type=ControlFlowNode::CF_CONTINUE;
+ cf_continue->cf_type = ControlFlowNode::CF_CONTINUE;
p_block->statements.push_back(cf_continue);
if (!_end_statement()) {
_set_error("Expected end of statement (continue)");
@@ -2710,7 +2678,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
ControlFlowNode *cf_break = alloc_node<ControlFlowNode>();
- cf_break->cf_type=ControlFlowNode::CF_BREAK;
+ cf_break->cf_type = ControlFlowNode::CF_BREAK;
p_block->statements.push_back(cf_break);
if (!_end_statement()) {
_set_error("Expected end of statement (break)");
@@ -2721,11 +2689,9 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
ControlFlowNode *cf_return = alloc_node<ControlFlowNode>();
- cf_return->cf_type=ControlFlowNode::CF_RETURN;
+ cf_return->cf_type = ControlFlowNode::CF_RETURN;
-
-
- if (tokenizer->get_token()==GDTokenizer::TK_SEMICOLON || tokenizer->get_token()==GDTokenizer::TK_NEWLINE || tokenizer->get_token()==GDTokenizer::TK_EOF) {
+ if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON || tokenizer->get_token() == GDTokenizer::TK_NEWLINE || tokenizer->get_token() == GDTokenizer::TK_EOF) {
//expect end of statement
p_block->statements.push_back(cf_return);
if (!_end_statement()) {
@@ -2733,7 +2699,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
}
} else {
//expect expression
- Node *retexpr = _parse_and_reduce_expression(p_block,p_static);
+ Node *retexpr = _parse_and_reduce_expression(p_block, p_static);
if (!retexpr) {
if (_recover_from_completion()) {
break;
@@ -2748,52 +2714,51 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
}
}
-
} break;
case GDTokenizer::TK_CF_MATCH: {
-
+
tokenizer->advance();
-
+
MatchNode *match_node = alloc_node<MatchNode>();
-
+
Node *val_to_match = _parse_and_reduce_expression(p_block, p_static);
-
+
if (!val_to_match) {
if (_recover_from_completion()) {
break;
}
return;
}
-
+
match_node->val_to_match = val_to_match;
-
+
if (!_enter_indent_block()) {
_set_error("Expected indented pattern matching block after 'match'");
return;
}
-
+
BlockNode *compiled_branches = alloc_node<BlockNode>();
compiled_branches->parent_block = p_block;
compiled_branches->parent_class = p_block->parent_class;
-
+
p_block->sub_blocks.push_back(compiled_branches);
-
+
_parse_pattern_block(compiled_branches, match_node->branches, p_static);
-
+
_transform_match_statment(compiled_branches, match_node);
-
+
ControlFlowNode *match_cf_node = alloc_node<ControlFlowNode>();
match_cf_node->cf_type = ControlFlowNode::CF_MATCH;
match_cf_node->match = match_node;
-
+
p_block->statements.push_back(match_cf_node);
-
+
_end_statement();
} break;
case GDTokenizer::TK_PR_ASSERT: {
tokenizer->advance();
- Node *condition = _parse_and_reduce_expression(p_block,p_static);
+ Node *condition = _parse_and_reduce_expression(p_block, p_static);
if (!condition) {
if (_recover_from_completion()) {
break;
@@ -2801,7 +2766,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
AssertNode *an = alloc_node<AssertNode>();
- an->condition=condition;
+ an->condition = condition;
p_block->statements.push_back(an);
if (!_end_statement()) {
@@ -2822,7 +2787,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
} break;
default: {
- Node *expression = _parse_and_reduce_expression(p_block,p_static,false,true);
+ Node *expression = _parse_and_reduce_expression(p_block, p_static, false, true);
if (!expression) {
if (_recover_from_completion()) {
break;
@@ -2836,7 +2801,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
}
} break;
- /*
+ /*
case GDTokenizer::TK_CF_LOCAL: {
if (tokenizer->get_token(1)!=GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE ) {
@@ -2846,37 +2811,35 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
} break;
*/
-
}
}
-
}
bool GDParser::_parse_newline() {
- if (tokenizer->get_token(1)!=GDTokenizer::TK_EOF && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE) {
+ if (tokenizer->get_token(1) != GDTokenizer::TK_EOF && tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE) {
int indent = tokenizer->get_token_line_indent();
int current_indent = tab_level.back()->get();
- if (indent>current_indent) {
+ if (indent > current_indent) {
_set_error("Unexpected indent.");
return false;
}
- if (indent<current_indent) {
+ if (indent < current_indent) {
- while(indent<current_indent) {
+ while (indent < current_indent) {
//exit block
- if (tab_level.size()==1) {
+ if (tab_level.size() == 1) {
_set_error("Invalid indent. BUG?");
return false;
}
tab_level.pop_back();
- if (tab_level.back()->get()<indent) {
+ if (tab_level.back()->get() < indent) {
_set_error("Unindent does not match any outer indentation level.");
return false;
@@ -2891,13 +2854,10 @@ bool GDParser::_parse_newline() {
tokenizer->advance();
return true;
-
}
-
void GDParser::_parse_extends(ClassNode *p_class) {
-
if (p_class->extends_used) {
_set_error("'extends' already used for this class.");
@@ -2910,73 +2870,70 @@ void GDParser::_parse_extends(ClassNode *p_class) {
return;
}
- p_class->extends_used=true;
+ p_class->extends_used = true;
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token_type()==Variant::OBJECT) {
+ if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token_type() == Variant::OBJECT) {
p_class->extends_class.push_back(Variant::get_type_name(Variant::OBJECT));
tokenizer->advance();
return;
}
// see if inheritance happens from a file
- if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT) {
Variant constant = tokenizer->get_token_constant();
- if (constant.get_type()!=Variant::STRING) {
+ if (constant.get_type() != Variant::STRING) {
_set_error("'extends' constant must be a string.");
return;
}
- p_class->extends_file=constant;
+ p_class->extends_file = constant;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PERIOD) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PERIOD) {
return;
} else
tokenizer->advance();
-
}
- while(true) {
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ while (true) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class).");
return;
}
- StringName identifier=tokenizer->get_token_identifier();
+ StringName identifier = tokenizer->get_token_identifier();
p_class->extends_class.push_back(identifier);
tokenizer->advance(1);
- if (tokenizer->get_token()!=GDTokenizer::TK_PERIOD)
+ if (tokenizer->get_token() != GDTokenizer::TK_PERIOD)
return;
}
-
}
void GDParser::_parse_class(ClassNode *p_class) {
int indent_level = tab_level.back()->get();
- while(true) {
+ while (true) {
GDTokenizer::Token token = tokenizer->get_token();
if (error_set)
return;
-
- if (indent_level>tab_level.back()->get()) {
- p_class->end_line=tokenizer->get_token_line();
+ if (indent_level > tab_level.back()->get()) {
+ p_class->end_line = tokenizer->get_token_line();
return; //go back a level
}
- switch(token) {
+ switch (token) {
case GDTokenizer::TK_EOF:
- p_class->end_line=tokenizer->get_token_line();
+ p_class->end_line = tokenizer->get_token_line();
case GDTokenizer::TK_ERROR: {
return; //go back
//end of file!
@@ -2984,7 +2941,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
case GDTokenizer::TK_NEWLINE: {
if (!_parse_newline()) {
if (!error_set) {
- p_class->end_line=tokenizer->get_token_line();
+ p_class->end_line = tokenizer->get_token_line();
}
return;
}
@@ -3008,7 +2965,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
- p_class->tool=true;
+ p_class->tool = true;
tokenizer->advance();
} break;
@@ -3018,7 +2975,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
StringName name;
StringName extends;
- if (tokenizer->get_token(1)!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token(1) != GDTokenizer::TK_IDENTIFIER) {
_set_error("'class' syntax: 'class <Name>:' or 'class <Name> extends <BaseClass>:'");
return;
@@ -3028,16 +2985,15 @@ void GDParser::_parse_class(ClassNode *p_class) {
ClassNode *newclass = alloc_node<ClassNode>();
newclass->initializer = alloc_node<BlockNode>();
- newclass->initializer->parent_class=newclass;
+ newclass->initializer->parent_class = newclass;
newclass->ready = alloc_node<BlockNode>();
- newclass->ready->parent_class=newclass;
- newclass->name=name;
- newclass->owner=p_class;
+ newclass->ready->parent_class = newclass;
+ newclass->name = name;
+ newclass->owner = p_class;
p_class->subclasses.push_back(newclass);
-
- if (tokenizer->get_token()==GDTokenizer::TK_PR_EXTENDS) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PR_EXTENDS) {
_parse_extends(newclass);
if (error_set)
@@ -3049,9 +3005,9 @@ void GDParser::_parse_class(ClassNode *p_class) {
_set_error("Indented block expected.");
return;
}
- current_class=newclass;
+ current_class = newclass;
_parse_class(newclass);
- current_class=p_class;
+ current_class = p_class;
} break;
/* this is for functions....
@@ -3062,7 +3018,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
*/
case GDTokenizer::TK_PR_STATIC: {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_FUNCTION) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) {
_set_error("Expected 'func'.");
return;
@@ -3071,42 +3027,38 @@ void GDParser::_parse_class(ClassNode *p_class) {
}; //fallthrough to function
case GDTokenizer::TK_PR_FUNCTION: {
- bool _static=false;
- pending_newline=-1;
+ bool _static = false;
+ pending_newline = -1;
- if (tokenizer->get_token(-1)==GDTokenizer::TK_PR_STATIC) {
+ if (tokenizer->get_token(-1) == GDTokenizer::TK_PR_STATIC) {
- _static=true;
+ _static = true;
}
-
tokenizer->advance();
StringName name;
- if (_get_completable_identifier(COMPLETION_VIRTUAL_FUNC,name)) {
-
+ if (_get_completable_identifier(COMPLETION_VIRTUAL_FUNC, name)) {
}
-
- if (name==StringName()) {
+ if (name == StringName()) {
_set_error("Expected identifier after 'func' (syntax: 'func <identifier>([arguments]):' ).");
return;
}
- for(int i=0;i<p_class->functions.size();i++) {
- if (p_class->functions[i]->name==name) {
- _set_error("Function '"+String(name)+"' already exists in this class (at line: "+itos(p_class->functions[i]->line)+").");
+ for (int i = 0; i < p_class->functions.size(); i++) {
+ if (p_class->functions[i]->name == name) {
+ _set_error("Function '" + String(name) + "' already exists in this class (at line: " + itos(p_class->functions[i]->line) + ").");
}
}
- for(int i=0;i<p_class->static_functions.size();i++) {
- if (p_class->static_functions[i]->name==name) {
- _set_error("Function '"+String(name)+"' already exists in this class (at line: "+itos(p_class->static_functions[i]->line)+").");
+ for (int i = 0; i < p_class->static_functions.size(); i++) {
+ if (p_class->static_functions[i]->name == name) {
+ _set_error("Function '" + String(name) + "' already exists in this class (at line: " + itos(p_class->static_functions[i]->line) + ").");
}
}
-
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) {
_set_error("Expected '(' after identifier (syntax: 'func <identifier>([arguments]):' ).");
return;
@@ -3115,39 +3067,37 @@ void GDParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
Vector<StringName> arguments;
- Vector<Node*> default_values;
+ Vector<Node *> default_values;
int fnline = tokenizer->get_token_line();
-
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
//has arguments
- bool defaulting=false;
- while(true) {
+ bool defaulting = false;
+ while (true) {
- if (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
continue;
}
- if (tokenizer->get_token()==GDTokenizer::TK_PR_VAR) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PR_VAR) {
tokenizer->advance(); //var before the identifier is allowed
}
-
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier for argument.");
return;
}
- StringName argname=tokenizer->get_token_identifier();
+ StringName argname = tokenizer->get_token_identifier();
arguments.push_back(argname);
tokenizer->advance();
- if (defaulting && tokenizer->get_token()!=GDTokenizer::TK_OP_ASSIGN) {
+ if (defaulting && tokenizer->get_token() != GDTokenizer::TK_OP_ASSIGN) {
_set_error("Default parameter expected.");
return;
@@ -3155,21 +3105,20 @@ void GDParser::_parse_class(ClassNode *p_class) {
//tokenizer->advance();
-
- if (tokenizer->get_token()==GDTokenizer::TK_OP_ASSIGN) {
- defaulting=true;
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) {
+ defaulting = true;
tokenizer->advance(1);
- Node *defval=NULL;
+ Node *defval = NULL;
- defval=_parse_and_reduce_expression(p_class,_static);
+ defval = _parse_and_reduce_expression(p_class, _static);
if (!defval || error_set)
return;
OperatorNode *on = alloc_node<OperatorNode>();
- on->op=OperatorNode::OP_ASSIGN;
+ on->op = OperatorNode::OP_ASSIGN;
IdentifierNode *in = alloc_node<IdentifierNode>();
- in->name=argname;
+ in->name = argname;
on->arguments.push_back(in);
on->arguments.push_back(defval);
@@ -3182,14 +3131,14 @@ void GDParser::_parse_class(ClassNode *p_class) {
default_values.push_back(on);
}
- while (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
continue;
- } else if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ',' or ')'.");
return;
@@ -3197,68 +3146,63 @@ void GDParser::_parse_class(ClassNode *p_class) {
break;
}
-
-
}
tokenizer->advance();
BlockNode *block = alloc_node<BlockNode>();
- block->parent_class=p_class;
+ block->parent_class = p_class;
- if (name=="_init") {
+ if (name == "_init") {
if (p_class->extends_used) {
OperatorNode *cparent = alloc_node<OperatorNode>();
- cparent->op=OperatorNode::OP_PARENT_CALL;
+ cparent->op = OperatorNode::OP_PARENT_CALL;
block->statements.push_back(cparent);
IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name="_init";
+ id->name = "_init";
cparent->arguments.push_back(id);
- if (tokenizer->get_token()==GDTokenizer::TK_PERIOD) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) {
_set_error("expected '(' for parent constructor arguments.");
}
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
//has arguments
- parenthesis ++;
- while(true) {
+ parenthesis++;
+ while (true) {
- Node *arg = _parse_and_reduce_expression(p_class,_static);
+ Node *arg = _parse_and_reduce_expression(p_class, _static);
cparent->arguments.push_back(arg);
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
continue;
- } else if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ',' or ')'.");
return;
}
break;
-
}
- parenthesis --;
+ parenthesis--;
}
tokenizer->advance();
}
} else {
-
- if (tokenizer->get_token()==GDTokenizer::TK_PERIOD) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) {
_set_error("Parent constructor call found for a class without inheritance.");
return;
}
-
}
}
@@ -3269,34 +3213,32 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
FunctionNode *function = alloc_node<FunctionNode>();
- function->name=name;
- function->arguments=arguments;
- function->default_values=default_values;
- function->_static=_static;
- function->line=fnline;
-
- function->rpc_mode=rpc_mode;
- rpc_mode=ScriptInstance::RPC_MODE_DISABLED;
+ function->name = name;
+ function->arguments = arguments;
+ function->default_values = default_values;
+ function->_static = _static;
+ function->line = fnline;
+ function->rpc_mode = rpc_mode;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
if (_static)
p_class->static_functions.push_back(function);
else
p_class->functions.push_back(function);
-
- current_function=function;
- function->body=block;
- current_block=block;
- _parse_block(block,_static);
- current_block=NULL;
+ current_function = function;
+ function->body = block;
+ current_block = block;
+ _parse_block(block, _static);
+ current_block = NULL;
//arguments
} break;
case GDTokenizer::TK_PR_SIGNAL: {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier after 'signal'.");
return;
}
@@ -3305,22 +3247,20 @@ void GDParser::_parse_class(ClassNode *p_class) {
sig.name = tokenizer->get_token_identifier();
tokenizer->advance();
-
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) {
tokenizer->advance();
- while(true) {
- if (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (true) {
+ if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
continue;
}
-
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
tokenizer->advance();
break;
}
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier in signal argument.");
return;
}
@@ -3328,13 +3268,13 @@ void GDParser::_parse_class(ClassNode *p_class) {
sig.arguments.push_back(tokenizer->get_token_identifier());
tokenizer->advance();
- while (tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
- } else if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ',' or ')' after signal parameter identifier.");
return;
}
@@ -3352,33 +3292,33 @@ void GDParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_OPEN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) {
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) {
Variant::Type type = tokenizer->get_token_type();
- if (type==Variant::NIL) {
+ if (type == Variant::NIL) {
_set_error("Can't export null type.");
return;
}
- current_export.type=type;
- current_export.usage|=PROPERTY_USAGE_SCRIPT_VARIABLE;
+ current_export.type = type;
+ current_export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
tokenizer->advance();
-
- String hint_prefix ="";
-
- if(type == Variant::ARRAY && tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+
+ String hint_prefix = "";
+
+ if (type == Variant::ARRAY && tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
- while(tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE) {
+ while (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) {
type = tokenizer->get_token_type();
-
+
tokenizer->advance();
- if(type == Variant::ARRAY) {
- hint_prefix += itos(Variant::ARRAY)+":";
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (type == Variant::ARRAY) {
+ hint_prefix += itos(Variant::ARRAY) + ":";
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
}
} else {
@@ -3387,56 +3327,54 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
}
}
-
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
// hint expected next!
tokenizer->advance();
- switch(type) {
-
+ switch (type) {
case Variant::INT: {
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="FLAGS") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FLAGS") {
//current_export.hint=PROPERTY_HINT_ALL_FLAGS;
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
break;
}
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA)
- {
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
_set_error("Expected ')' or ',' in bit flags hint.");
return;
}
- current_export.hint=PROPERTY_HINT_FLAGS;
+ current_export.hint = PROPERTY_HINT_FLAGS;
tokenizer->advance();
bool first = true;
- while(true) {
+ while (true) {
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
- current_export=PropertyInfo();
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
+ current_export = PropertyInfo();
_set_error("Expected a string constant in named bit flags hint.");
return;
}
String c = tokenizer->get_token_constant();
if (!first)
- current_export.hint_string+=",";
+ current_export.hint_string += ",";
else
- first=false;
+ first = false;
- current_export.hint_string+=c.xml_escape();
+ current_export.hint_string += c.xml_escape();
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
- current_export=PropertyInfo();
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
+ current_export = PropertyInfo();
_set_error("Expected ')' or ',' in named bit flags hint.");
return;
}
@@ -3446,39 +3384,38 @@ void GDParser::_parse_class(ClassNode *p_class) {
break;
}
- if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type()==Variant::STRING) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) {
//enumeration
- current_export.hint=PROPERTY_HINT_ENUM;
- bool first=true;
- while(true) {
+ current_export.hint = PROPERTY_HINT_ENUM;
+ bool first = true;
+ while (true) {
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected a string constant in enumeration hint.");
return;
}
String c = tokenizer->get_token_constant();
if (!first)
- current_export.hint_string+=",";
+ current_export.hint_string += ",";
else
- first=false;
+ first = false;
- current_export.hint_string+=c.xml_escape();
+ current_export.hint_string += c.xml_escape();
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
- current_export=PropertyInfo();
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
+ current_export = PropertyInfo();
_set_error("Expected ')' or ',' in enumeration hint.");
return;
}
tokenizer->advance();
-
}
break;
@@ -3487,10 +3424,10 @@ void GDParser::_parse_class(ClassNode *p_class) {
}; //fallthrough to use the same
case Variant::REAL: {
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="EASE") {
- current_export.hint=PROPERTY_HINT_EXP_EASING;
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") {
+ current_export.hint = PROPERTY_HINT_EXP_EASING;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in hint.");
return;
}
@@ -3498,146 +3435,143 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
// range
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="EXP") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EXP") {
- current_export.hint=PROPERTY_HINT_EXP_RANGE;
+ current_export.hint = PROPERTY_HINT_EXP_RANGE;
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- else if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ else if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
_set_error("Expected ')' or ',' in exponential range hint.");
return;
}
tokenizer->advance();
- }
- else
- current_export.hint=PROPERTY_HINT_RANGE;
+ } else
+ current_export.hint = PROPERTY_HINT_RANGE;
- float sign=1.0;
+ float sign = 1.0;
- if (tokenizer->get_token()==GDTokenizer::TK_OP_SUB) {
- sign=-1;
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) {
+ sign = -1;
tokenizer->advance();
}
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected a range in numeric hint.");
return;
-
}
- current_export.hint_string=rtos(sign*double(tokenizer->get_token_constant()));
+ current_export.hint_string = rtos(sign * double(tokenizer->get_token_constant()));
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
- current_export.hint_string="0,"+current_export.hint_string;
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ current_export.hint_string = "0," + current_export.hint_string;
break;
}
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected ',' or ')' in numeric range hint.");
return;
}
tokenizer->advance();
- sign=1.0;
- if (tokenizer->get_token()==GDTokenizer::TK_OP_SUB) {
- sign=-1;
+ sign = 1.0;
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) {
+ sign = -1;
tokenizer->advance();
}
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected a number as upper bound in numeric range hint.");
return;
}
- current_export.hint_string+=","+rtos(sign*double(tokenizer->get_token_constant()));
+ current_export.hint_string += "," + rtos(sign * double(tokenizer->get_token_constant()));
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected ',' or ')' in numeric range hint.");
return;
}
tokenizer->advance();
- sign=1.0;
- if (tokenizer->get_token()==GDTokenizer::TK_OP_SUB) {
- sign=-1;
+ sign = 1.0;
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) {
+ sign = -1;
tokenizer->advance();
}
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected a number as step in numeric range hint.");
return;
}
- current_export.hint_string+=","+rtos(sign*double(tokenizer->get_token_constant()));
+ current_export.hint_string += "," + rtos(sign * double(tokenizer->get_token_constant()));
tokenizer->advance();
} break;
case Variant::STRING: {
- if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type()==Variant::STRING) {
+ if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) {
//enumeration
- current_export.hint=PROPERTY_HINT_ENUM;
- bool first=true;
- while(true) {
+ current_export.hint = PROPERTY_HINT_ENUM;
+ bool first = true;
+ while (true) {
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected a string constant in enumeration hint.");
return;
}
String c = tokenizer->get_token_constant();
if (!first)
- current_export.hint_string+=",";
+ current_export.hint_string += ",";
else
- first=false;
+ first = false;
- current_export.hint_string+=c.xml_escape();
+ current_export.hint_string += c.xml_escape();
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
- current_export=PropertyInfo();
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
+ current_export = PropertyInfo();
_set_error("Expected ')' or ',' in enumeration hint.");
return;
}
tokenizer->advance();
-
}
break;
}
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="DIR") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "DIR") {
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
- current_export.hint=PROPERTY_HINT_DIR;
- else if (tokenizer->get_token()==GDTokenizer::TK_COMMA ) {
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
+ current_export.hint = PROPERTY_HINT_DIR;
+ else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier()=="GLOBAL")) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) {
_set_error("Expected 'GLOBAL' after comma in directory hint.");
return;
}
@@ -3645,42 +3579,41 @@ void GDParser::_parse_class(ClassNode *p_class) {
_set_error("Global filesystem hints may only be used in tool scripts.");
return;
}
- current_export.hint=PROPERTY_HINT_GLOBAL_DIR;
+ current_export.hint = PROPERTY_HINT_GLOBAL_DIR;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in hint.");
return;
}
- }
- else {
+ } else {
_set_error("Expected ')' or ',' in hint.");
return;
}
break;
}
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="FILE") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FILE") {
- current_export.hint=PROPERTY_HINT_FILE;
+ current_export.hint = PROPERTY_HINT_FILE;
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="GLOBAL") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "GLOBAL") {
if (!p_class->tool) {
_set_error("Global filesystem hints may only be used in tool scripts.");
return;
}
- current_export.hint=PROPERTY_HINT_GLOBAL_FILE;
+ current_export.hint = PROPERTY_HINT_GLOBAL_FILE;
tokenizer->advance();
- if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE)
break;
- else if (tokenizer->get_token()==GDTokenizer::TK_COMMA)
+ else if (tokenizer->get_token() == GDTokenizer::TK_COMMA)
tokenizer->advance();
else {
_set_error("Expected ')' or ',' in hint.");
@@ -3688,31 +3621,30 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
}
- if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
- if (current_export.hint==PROPERTY_HINT_GLOBAL_FILE)
+ if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE)
_set_error("Expected string constant with filter");
else
_set_error("Expected 'GLOBAL' or string constant with filter");
return;
}
- current_export.hint_string=tokenizer->get_token_constant();
+ current_export.hint_string = tokenizer->get_token_constant();
tokenizer->advance();
-
}
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in hint.");
return;
}
break;
}
- if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier()=="MULTILINE") {
+ if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "MULTILINE") {
- current_export.hint=PROPERTY_HINT_MULTILINE_TEXT;
+ current_export.hint = PROPERTY_HINT_MULTILINE_TEXT;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in hint.");
return;
}
@@ -3721,20 +3653,20 @@ void GDParser::_parse_class(ClassNode *p_class) {
} break;
case Variant::COLOR: {
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER ) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Color type hint expects RGB or RGBA as hints");
return;
}
String identifier = tokenizer->get_token_identifier();
- if (identifier=="RGB") {
- current_export.hint=PROPERTY_HINT_COLOR_NO_ALPHA;
- } else if (identifier=="RGBA") {
+ if (identifier == "RGB") {
+ current_export.hint = PROPERTY_HINT_COLOR_NO_ALPHA;
+ } else if (identifier == "RGBA") {
//none
} else {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Color type hint expects RGB or RGBA as hints");
return;
}
@@ -3743,54 +3675,51 @@ void GDParser::_parse_class(ClassNode *p_class) {
} break;
default: {
- current_export=PropertyInfo();
- _set_error("Type '"+Variant::get_type_name(type)+"' can't take hints.");
+ current_export = PropertyInfo();
+ _set_error("Type '" + Variant::get_type_name(type) + "' can't take hints.");
return;
} break;
}
-
}
- if(current_export.type == Variant::ARRAY && !hint_prefix.empty()) {
- if(current_export.hint) {
- hint_prefix += "/"+itos(current_export.hint);
+ if (current_export.type == Variant::ARRAY && !hint_prefix.empty()) {
+ if (current_export.hint) {
+ hint_prefix += "/" + itos(current_export.hint);
}
- current_export.hint_string=hint_prefix+":"+current_export.hint_string;
- current_export.hint=PROPERTY_HINT_NONE;
+ current_export.hint_string = hint_prefix + ":" + current_export.hint_string;
+ current_export.hint = PROPERTY_HINT_NONE;
}
- } else if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) {
+ } else if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER) {
String identifier = tokenizer->get_token_identifier();
- if (!ClassDB::is_parent_class(identifier,"Resource")) {
+ if (!ClassDB::is_parent_class(identifier, "Resource")) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Export hint not a type or resource.");
}
- current_export.type=Variant::OBJECT;
- current_export.hint=PROPERTY_HINT_RESOURCE_TYPE;
- current_export.usage|=PROPERTY_USAGE_SCRIPT_VARIABLE;
+ current_export.type = Variant::OBJECT;
+ current_export.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ current_export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
- current_export.hint_string=identifier;
+ current_export.hint_string = identifier;
tokenizer->advance();
}
- if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected ')' or ',' after export hint.");
return;
-
}
tokenizer->advance();
-
}
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR && tokenizer->get_token()!=GDTokenizer::TK_PR_ONREADY && tokenizer->get_token()!=GDTokenizer::TK_PR_REMOTE && tokenizer->get_token()!=GDTokenizer::TK_PR_MASTER && tokenizer->get_token()!=GDTokenizer::TK_PR_SLAVE && tokenizer->get_token()!=GDTokenizer::TK_PR_SYNC) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDTokenizer::TK_PR_SLAVE && tokenizer->get_token() != GDTokenizer::TK_PR_SYNC) {
- current_export=PropertyInfo();
+ current_export = PropertyInfo();
_set_error("Expected 'var', 'onready', 'remote', 'master', 'slave' or 'sync'.");
return;
}
@@ -3801,7 +3730,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) {
_set_error("Expected 'var'.");
return;
}
@@ -3812,19 +3741,19 @@ void GDParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
- if (current_export.type) {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) {
+ if (current_export.type) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) {
_set_error("Expected 'var'.");
return;
}
} else {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR && tokenizer->get_token()!=GDTokenizer::TK_PR_FUNCTION) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) {
_set_error("Expected 'var' or 'func'.");
return;
}
}
- rpc_mode=ScriptInstance::RPC_MODE_REMOTE;
+ rpc_mode = ScriptInstance::RPC_MODE_REMOTE;
continue;
} break;
@@ -3832,47 +3761,47 @@ void GDParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
- if (current_export.type) {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) {
+ if (current_export.type) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) {
_set_error("Expected 'var'.");
return;
}
} else {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR && tokenizer->get_token()!=GDTokenizer::TK_PR_FUNCTION) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) {
_set_error("Expected 'var' or 'func'.");
return;
}
}
- rpc_mode=ScriptInstance::RPC_MODE_MASTER;
+ rpc_mode = ScriptInstance::RPC_MODE_MASTER;
continue;
} break;
case GDTokenizer::TK_PR_SLAVE: {
//may be fallthrough from export, ignore if so
tokenizer->advance();
- if (current_export.type) {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) {
+ if (current_export.type) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) {
_set_error("Expected 'var'.");
return;
}
} else {
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR && tokenizer->get_token()!=GDTokenizer::TK_PR_FUNCTION) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) {
_set_error("Expected 'var' or 'func'.");
return;
}
}
- rpc_mode=ScriptInstance::RPC_MODE_SLAVE;
+ rpc_mode = ScriptInstance::RPC_MODE_SLAVE;
continue;
} break;
case GDTokenizer::TK_PR_SYNC: {
//may be fallthrough from export, ignore if so
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR && tokenizer->get_token()!=GDTokenizer::TK_PR_FUNCTION) {
+ if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) {
if (current_export.type)
_set_error("Expected 'var'.");
else
@@ -3880,48 +3809,48 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
- rpc_mode=ScriptInstance::RPC_MODE_SYNC;
+ rpc_mode = ScriptInstance::RPC_MODE_SYNC;
continue;
} break;
case GDTokenizer::TK_PR_VAR: {
//variale declaration and (eventual) initialization
ClassNode::Member member;
- bool autoexport = tokenizer->get_token(-1)==GDTokenizer::TK_PR_EXPORT;
- if (current_export.type!=Variant::NIL) {
- member._export=current_export;
- current_export=PropertyInfo();
+ bool autoexport = tokenizer->get_token(-1) == GDTokenizer::TK_PR_EXPORT;
+ if (current_export.type != Variant::NIL) {
+ member._export = current_export;
+ current_export = PropertyInfo();
}
- bool onready = tokenizer->get_token(-1)==GDTokenizer::TK_PR_ONREADY;
+ bool onready = tokenizer->get_token(-1) == GDTokenizer::TK_PR_ONREADY;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier for member variable name.");
return;
}
- member.identifier=tokenizer->get_token_identifier();
- member.expression=NULL;
- member._export.name=member.identifier;
- member.line=tokenizer->get_token_line();
- member.rpc_mode=rpc_mode;
+ member.identifier = tokenizer->get_token_identifier();
+ member.expression = NULL;
+ member._export.name = member.identifier;
+ member.line = tokenizer->get_token_line();
+ member.rpc_mode = rpc_mode;
tokenizer->advance();
- rpc_mode=ScriptInstance::RPC_MODE_DISABLED;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
- if (tokenizer->get_token()==GDTokenizer::TK_OP_ASSIGN) {
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) {
#ifdef DEBUG_ENABLED
int line = tokenizer->get_token_line();
#endif
tokenizer->advance();
- Node *subexpr=NULL;
+ Node *subexpr = NULL;
- subexpr = _parse_and_reduce_expression(p_class,false,autoexport);
+ subexpr = _parse_and_reduce_expression(p_class, false, autoexport);
if (!subexpr) {
if (_recover_from_completion()) {
break;
@@ -3930,24 +3859,23 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
//discourage common error
- if (!onready && subexpr->type==Node::TYPE_OPERATOR) {
+ if (!onready && subexpr->type == Node::TYPE_OPERATOR) {
- OperatorNode *op=static_cast<OperatorNode*>(subexpr);
- if (op->op==OperatorNode::OP_CALL && op->arguments[0]->type==Node::TYPE_SELF && op->arguments[1]->type==Node::TYPE_IDENTIFIER) {
- IdentifierNode *id=static_cast<IdentifierNode*>(op->arguments[1]);
- if (id->name=="get_node") {
+ OperatorNode *op = static_cast<OperatorNode *>(subexpr);
+ if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_SELF && op->arguments[1]->type == Node::TYPE_IDENTIFIER) {
+ IdentifierNode *id = static_cast<IdentifierNode *>(op->arguments[1]);
+ if (id->name == "get_node") {
- _set_error("Use 'onready var "+String(member.identifier)+" = get_node(..)' instead");
+ _set_error("Use 'onready var " + String(member.identifier) + " = get_node(..)' instead");
return;
-
}
}
}
- member.expression=subexpr;
+ member.expression = subexpr;
if (autoexport) {
- if (1)/*(subexpr->type==Node::TYPE_ARRAY) {
+ if (1) /*(subexpr->type==Node::TYPE_ARRAY) {
member._export.type=Variant::ARRAY;
@@ -3957,54 +3885,53 @@ void GDParser::_parse_class(ClassNode *p_class) {
} else*/ {
- if (subexpr->type!=Node::TYPE_CONSTANT) {
+ if (subexpr->type != Node::TYPE_CONSTANT) {
_set_error("Type-less export needs a constant expression assigned to infer type.");
return;
}
- ConstantNode *cn = static_cast<ConstantNode*>(subexpr);
- if (cn->value.get_type()==Variant::NIL) {
+ ConstantNode *cn = static_cast<ConstantNode *>(subexpr);
+ if (cn->value.get_type() == Variant::NIL) {
_set_error("Can't accept a null constant expression for infering export type.");
return;
}
- member._export.type=cn->value.get_type();
- member._export.usage|=PROPERTY_USAGE_SCRIPT_VARIABLE;
- if (cn->value.get_type()==Variant::OBJECT) {
+ member._export.type = cn->value.get_type();
+ member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
+ if (cn->value.get_type() == Variant::OBJECT) {
Object *obj = cn->value;
Resource *res = obj->cast_to<Resource>();
- if(res==NULL) {
+ if (res == NULL) {
_set_error("Exported constant not a type or resource.");
return;
}
- member._export.hint=PROPERTY_HINT_RESOURCE_TYPE;
- member._export.hint_string=res->get_class();
+ member._export.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ member._export.hint_string = res->get_class();
}
}
}
#ifdef TOOLS_ENABLED
- if (subexpr->type==Node::TYPE_CONSTANT && member._export.type!=Variant::NIL) {
+ if (subexpr->type == Node::TYPE_CONSTANT && member._export.type != Variant::NIL) {
- ConstantNode *cn = static_cast<ConstantNode*>(subexpr);
- if (cn->value.get_type()!=Variant::NIL) {
- member.default_value=cn->value;
+ ConstantNode *cn = static_cast<ConstantNode *>(subexpr);
+ if (cn->value.get_type() != Variant::NIL) {
+ member.default_value = cn->value;
}
}
#endif
IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name=member.identifier;
+ id->name = member.identifier;
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=OperatorNode::OP_INIT_ASSIGN;
+ op->op = OperatorNode::OP_INIT_ASSIGN;
op->arguments.push_back(id);
op->arguments.push_back(subexpr);
-
#ifdef DEBUG_ENABLED
NewLineNode *nl = alloc_node<NewLineNode>();
- nl->line=line;
+ nl->line = line;
if (onready)
p_class->ready->statements.push_back(nl);
else
@@ -4015,8 +3942,6 @@ void GDParser::_parse_class(ClassNode *p_class) {
else
p_class->initializer->statements.push_back(op);
-
-
} else {
if (autoexport) {
@@ -4024,36 +3949,33 @@ void GDParser::_parse_class(ClassNode *p_class) {
_set_error("Type-less export needs a constant expression assigned to infer type.");
return;
}
-
}
- if (tokenizer->get_token()==GDTokenizer::TK_PR_SETGET) {
-
+ if (tokenizer->get_token() == GDTokenizer::TK_PR_SETGET) {
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() != GDTokenizer::TK_COMMA) {
//just comma means using only getter
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier for setter function after 'notify'.");
}
- member.setter=tokenizer->get_token_identifier();
+ member.setter = tokenizer->get_token_identifier();
tokenizer->advance();
}
- if (tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
//there is a getter
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected identifier for getter function after ','.");
}
- member.getter=tokenizer->get_token_identifier();
+ member.getter = tokenizer->get_token_identifier();
tokenizer->advance();
-
}
}
@@ -4070,25 +3992,25 @@ void GDParser::_parse_class(ClassNode *p_class) {
ClassNode::Constant constant;
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+ if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
_set_error("Expected name (identifier) for constant.");
return;
}
- constant.identifier=tokenizer->get_token_identifier();
+ constant.identifier = tokenizer->get_token_identifier();
tokenizer->advance();
- if (tokenizer->get_token()!=GDTokenizer::TK_OP_ASSIGN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_OP_ASSIGN) {
_set_error("Constant expects assignment.");
return;
}
tokenizer->advance();
- Node *subexpr=NULL;
+ Node *subexpr = NULL;
- subexpr = _parse_and_reduce_expression(p_class,true,true);
+ subexpr = _parse_and_reduce_expression(p_class, true, true);
if (!subexpr) {
if (_recover_from_completion()) {
break;
@@ -4096,10 +4018,10 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
- if (subexpr->type!=Node::TYPE_CONSTANT) {
+ if (subexpr->type != Node::TYPE_CONSTANT) {
_set_error("Expected constant expression");
}
- constant.expression=subexpr;
+ constant.expression = subexpr;
p_class->constant_expressions.push_back(constant);
@@ -4117,46 +4039,46 @@ 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->get_token() == GDTokenizer::TK_IDENTIFIER) {
+ enum_name = tokenizer->get_token_identifier();
tokenizer->advance();
}
- if (tokenizer->get_token()!=GDTokenizer::TK_CURLY_BRACKET_OPEN) {
+ if (tokenizer->get_token() != GDTokenizer::TK_CURLY_BRACKET_OPEN) {
_set_error("Expected '{' in enum declaration");
return;
}
tokenizer->advance();
-
- while(true) {
- if(tokenizer->get_token()==GDTokenizer::TK_NEWLINE) {
-
+
+ while (true) {
+ if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) {
+
tokenizer->advance(); // Ignore newlines
- } else if (tokenizer->get_token()==GDTokenizer::TK_CURLY_BRACKET_CLOSE) {
-
+ } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) {
+
tokenizer->advance();
break; // End of enum
- } else if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
-
- if(tokenizer->get_token()==GDTokenizer::TK_EOF) {
+ } else if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) {
+
+ if (tokenizer->get_token() == GDTokenizer::TK_EOF) {
_set_error("Unexpected end of file.");
} else {
_set_error(String("Unexpected ") + GDTokenizer::get_token_name(tokenizer->get_token()) + ", expected identifier");
}
-
+
return;
} else { // tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER
ClassNode::Constant constant;
-
- constant.identifier=tokenizer->get_token_identifier();
-
+
+ constant.identifier = tokenizer->get_token_identifier();
+
tokenizer->advance();
-
- if (tokenizer->get_token()==GDTokenizer::TK_OP_ASSIGN) {
+
+ if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) {
tokenizer->advance();
- Node *subexpr=NULL;
+ Node *subexpr = NULL;
- subexpr = _parse_and_reduce_expression(p_class,true,true);
+ subexpr = _parse_and_reduce_expression(p_class, true, true);
if (!subexpr) {
if (_recover_from_completion()) {
break;
@@ -4164,19 +4086,19 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
- if (subexpr->type!=Node::TYPE_CONSTANT) {
+ if (subexpr->type != Node::TYPE_CONSTANT) {
_set_error("Expected constant expression");
}
-
- const ConstantNode *subexpr_const = static_cast<const ConstantNode*>(subexpr);
-
- if(subexpr_const->value.get_type() != Variant::INT) {
+
+ const ConstantNode *subexpr_const = static_cast<const ConstantNode *>(subexpr);
+
+ if (subexpr_const->value.get_type() != Variant::INT) {
_set_error("Expected an int value for enum");
}
-
+
last_assign = subexpr_const->value;
-
- constant.expression=subexpr;
+
+ constant.expression = subexpr;
} else {
last_assign = last_assign + 1;
@@ -4184,27 +4106,26 @@ void GDParser::_parse_class(ClassNode *p_class) {
cn->value = last_assign;
constant.expression = cn;
}
-
- if(tokenizer->get_token()==GDTokenizer::TK_COMMA) {
+
+ if (tokenizer->get_token() == GDTokenizer::TK_COMMA) {
tokenizer->advance();
}
- if(enum_name != "") {
- const ConstantNode *cn = static_cast<const ConstantNode*>(constant.expression);
+ if (enum_name != "") {
+ const ConstantNode *cn = static_cast<const ConstantNode *>(constant.expression);
enum_dict[constant.identifier] = cn->value;
}
p_class->constant_expressions.push_back(constant);
}
-
}
-
- if(enum_name != "") {
+
+ if (enum_name != "") {
ClassNode::Constant enum_constant;
- enum_constant.identifier=enum_name;
+ enum_constant.identifier = enum_name;
ConstantNode *cn = alloc_node<ConstantNode>();
cn->value = enum_dict;
- enum_constant.expression=cn;
+ enum_constant.expression = cn;
p_class->constant_expressions.push_back(enum_constant);
}
@@ -4213,46 +4134,37 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
-
-
-
} break;
-
+
case GDTokenizer::TK_CONSTANT: {
- if(tokenizer->get_token_constant().get_type() == Variant::STRING) {
+ if (tokenizer->get_token_constant().get_type() == Variant::STRING) {
tokenizer->advance();
// Ignore
} else {
- _set_error(String()+"Unexpected constant of type: "+Variant::get_type_name(tokenizer->get_token_constant().get_type()));
+ _set_error(String() + "Unexpected constant of type: " + Variant::get_type_name(tokenizer->get_token_constant().get_type()));
return;
}
} break;
default: {
- _set_error(String()+"Unexpected token: "+tokenizer->get_token_name(tokenizer->get_token())+":"+tokenizer->get_token_identifier());
+ _set_error(String() + "Unexpected token: " + tokenizer->get_token_name(tokenizer->get_token()) + ":" + tokenizer->get_token_identifier());
return;
} break;
-
}
-
}
-
-
}
-
-void GDParser::_set_error(const String& p_error, int p_line, int p_column) {
-
+void GDParser::_set_error(const String &p_error, int p_line, int p_column) {
if (error_set)
return; //allow no further errors
- error=p_error;
- error_line=p_line<0?tokenizer->get_token_line():p_line;
- error_column=p_column<0?tokenizer->get_token_column():p_column;
- error_set=true;
+ error = p_error;
+ error_line = p_line < 0 ? tokenizer->get_token_line() : p_line;
+ error_column = p_column < 0 ? tokenizer->get_token_column() : p_column;
+ error_set = true;
}
String GDParser::get_error() const {
@@ -4269,27 +4181,25 @@ int GDParser::get_error_column() const {
return error_column;
}
+Error GDParser::_parse(const String &p_base_path) {
-Error GDParser::_parse(const String& p_base_path) {
-
-
- base_path=p_base_path;
+ base_path = p_base_path;
clear();
//assume class
ClassNode *main_class = alloc_node<ClassNode>();
main_class->initializer = alloc_node<BlockNode>();
- main_class->initializer->parent_class=main_class;
+ main_class->initializer->parent_class = main_class;
main_class->ready = alloc_node<BlockNode>();
- main_class->ready->parent_class=main_class;
- current_class=main_class;
+ main_class->ready->parent_class = main_class;
+ current_class = main_class;
_parse_class(main_class);
- if (tokenizer->get_token()==GDTokenizer::TK_ERROR) {
- error_set=false;
- _set_error("Parse Error: "+tokenizer->get_token_error());
+ if (tokenizer->get_token() == GDTokenizer::TK_ERROR) {
+ error_set = false;
+ _set_error("Parse Error: " + tokenizer->get_token_error());
}
if (error_set) {
@@ -4299,60 +4209,59 @@ Error GDParser::_parse(const String& p_base_path) {
return OK;
}
-Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode,const String& p_base_path, const String &p_self_path) {
-
- for_completion=false;
- validating=false;
- completion_type=COMPLETION_NONE;
- completion_node=NULL;
- completion_class=NULL;
- completion_function=NULL;
- completion_block=NULL;
- completion_found=false;
- current_block=NULL;
- current_class=NULL;
- current_function=NULL;
-
- self_path=p_self_path;
- GDTokenizerBuffer *tb = memnew( GDTokenizerBuffer );
+Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path, const String &p_self_path) {
+
+ for_completion = false;
+ validating = false;
+ completion_type = COMPLETION_NONE;
+ completion_node = NULL;
+ completion_class = NULL;
+ completion_function = NULL;
+ completion_block = NULL;
+ completion_found = false;
+ current_block = NULL;
+ current_class = NULL;
+ current_function = NULL;
+
+ self_path = p_self_path;
+ GDTokenizerBuffer *tb = memnew(GDTokenizerBuffer);
tb->set_code_buffer(p_bytecode);
- tokenizer=tb;
+ tokenizer = tb;
Error ret = _parse(p_base_path);
memdelete(tb);
- tokenizer=NULL;
+ tokenizer = NULL;
return ret;
}
+Error GDParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion) {
-Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_just_validate, const String &p_self_path,bool p_for_completion) {
-
- completion_type=COMPLETION_NONE;
- completion_node=NULL;
- completion_class=NULL;
- completion_function=NULL;
- completion_block=NULL;
- completion_found=false;
- current_block=NULL;
- current_class=NULL;
+ completion_type = COMPLETION_NONE;
+ completion_node = NULL;
+ completion_class = NULL;
+ completion_function = NULL;
+ completion_block = NULL;
+ completion_found = false;
+ current_block = NULL;
+ current_class = NULL;
- current_function=NULL;
+ current_function = NULL;
- self_path=p_self_path;
- GDTokenizerText *tt = memnew( GDTokenizerText );
+ self_path = p_self_path;
+ GDTokenizerText *tt = memnew(GDTokenizerText);
tt->set_code(p_code);
- validating=p_just_validate;
- for_completion=p_for_completion;
- tokenizer=tt;
+ validating = p_just_validate;
+ for_completion = p_for_completion;
+ tokenizer = tt;
Error ret = _parse(p_base_path);
memdelete(tt);
- tokenizer=NULL;
+ tokenizer = NULL;
return ret;
}
bool GDParser::is_tool_script() const {
- return (head && head->type==Node::TYPE_CLASS && static_cast<const ClassNode*>(head)->tool);
+ return (head && head->type == Node::TYPE_CLASS && static_cast<const ClassNode *>(head)->tool);
}
const GDParser::Node *GDParser::get_parse_tree() const {
@@ -4362,44 +4271,42 @@ const GDParser::Node *GDParser::get_parse_tree() const {
void GDParser::clear() {
- while(list) {
+ while (list) {
- Node *l=list;
- list=list->next;
+ Node *l = list;
+ list = list->next;
memdelete(l);
}
- head=NULL;
- list=NULL;
+ head = NULL;
+ list = NULL;
- completion_type=COMPLETION_NONE;
- completion_node=NULL;
- completion_class=NULL;
- completion_function=NULL;
- completion_block=NULL;
- current_block=NULL;
- current_class=NULL;
+ completion_type = COMPLETION_NONE;
+ completion_node = NULL;
+ completion_class = NULL;
+ completion_function = NULL;
+ completion_block = NULL;
+ current_block = NULL;
+ current_class = NULL;
- completion_found=false;
- rpc_mode=ScriptInstance::RPC_MODE_DISABLED;
+ completion_found = false;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
- current_function=NULL;
+ current_function = NULL;
- validating=false;
- for_completion=false;
- error_set=false;
+ validating = false;
+ for_completion = false;
+ error_set = false;
tab_level.clear();
tab_level.push_back(0);
- error_line=0;
- error_column=0;
- pending_newline=-1;
- parenthesis=0;
- current_export.type=Variant::NIL;
- error="";
-
+ error_line = 0;
+ error_column = 0;
+ pending_newline = -1;
+ parenthesis = 0;
+ current_export.type = Variant::NIL;
+ error = "";
}
-
GDParser::CompletionType GDParser::get_completion_type() {
return completion_type;
@@ -4415,12 +4322,12 @@ int GDParser::get_completion_line() {
return completion_line;
}
-Variant::Type GDParser::get_completion_built_in_constant(){
+Variant::Type GDParser::get_completion_built_in_constant() {
return completion_built_in_constant;
}
-GDParser::Node *GDParser::get_completion_node(){
+GDParser::Node *GDParser::get_completion_node() {
return completion_node;
}
@@ -4430,12 +4337,12 @@ GDParser::BlockNode *GDParser::get_completion_block() {
return completion_block;
}
-GDParser::ClassNode *GDParser::get_completion_class(){
+GDParser::ClassNode *GDParser::get_completion_class() {
return completion_class;
}
-GDParser::FunctionNode *GDParser::get_completion_function(){
+GDParser::FunctionNode *GDParser::get_completion_function() {
return completion_function;
}
@@ -4452,12 +4359,11 @@ int GDParser::get_completion_identifier_is_function() {
GDParser::GDParser() {
- head=NULL;
- list=NULL;
- tokenizer=NULL;
- pending_newline=-1;
+ head = NULL;
+ list = NULL;
+ tokenizer = NULL;
+ pending_newline = -1;
clear();
-
}
GDParser::~GDParser() {
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 7968bf85df..8d2c136818 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -29,15 +29,14 @@
#ifndef GD_PARSER_H
#define GD_PARSER_H
-#include "gd_tokenizer.h"
#include "gd_functions.h"
+#include "gd_tokenizer.h"
#include "map.h"
#include "object.h"
#include "script_language.h"
class GDParser {
public:
-
struct Node {
enum Type {
@@ -59,7 +58,7 @@ public:
TYPE_NEWLINE,
};
- Node * next;
+ Node *next;
int line;
int column;
Type type;
@@ -78,7 +77,6 @@ public:
StringName extends_file;
Vector<StringName> extends_class;
-
struct Member {
PropertyInfo _export;
#ifdef TOOLS_ENABLED
@@ -101,11 +99,11 @@ public:
Vector<StringName> arguments;
};
- Vector<ClassNode*> subclasses;
+ Vector<ClassNode *> subclasses;
Vector<Member> variables;
Vector<Constant> constant_expressions;
- Vector<FunctionNode*> functions;
- Vector<FunctionNode*> static_functions;
+ Vector<FunctionNode *> functions;
+ Vector<FunctionNode *> static_functions;
Vector<Signal> _signals;
BlockNode *initializer;
BlockNode *ready;
@@ -113,74 +111,88 @@ public:
//Vector<Node*> initializers;
int end_line;
- ClassNode() { tool=false; type=TYPE_CLASS; extends_used=false; end_line=-1; owner=NULL;}
+ ClassNode() {
+ tool = false;
+ type = TYPE_CLASS;
+ extends_used = false;
+ end_line = -1;
+ owner = NULL;
+ }
};
-
-
struct FunctionNode : public Node {
bool _static;
ScriptInstance::RPCMode rpc_mode;
StringName name;
Vector<StringName> arguments;
- Vector<Node*> default_values;
+ Vector<Node *> default_values;
BlockNode *body;
- FunctionNode() { type=TYPE_FUNCTION; _static=false; rpc_mode=ScriptInstance::RPC_MODE_DISABLED; }
-
+ FunctionNode() {
+ type = TYPE_FUNCTION;
+ _static = false;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
+ }
};
struct BlockNode : public Node {
ClassNode *parent_class;
BlockNode *parent_block;
- Map<StringName,int> locals;
- List<Node*> statements;
+ Map<StringName, int> locals;
+ List<Node *> statements;
Vector<StringName> variables;
Vector<int> variable_lines;
//the following is useful for code completion
- List<BlockNode*> sub_blocks;
+ List<BlockNode *> sub_blocks;
int end_line;
- BlockNode() { type=TYPE_BLOCK; end_line=-1; parent_block=NULL; parent_class=NULL; }
+ BlockNode() {
+ type = TYPE_BLOCK;
+ end_line = -1;
+ parent_block = NULL;
+ parent_class = NULL;
+ }
};
struct TypeNode : public Node {
Variant::Type vtype;
- TypeNode() { type=TYPE_TYPE; }
+ TypeNode() { type = TYPE_TYPE; }
};
struct BuiltInFunctionNode : public Node {
GDFunctions::Function function;
- BuiltInFunctionNode() { type=TYPE_BUILT_IN_FUNCTION; }
+ BuiltInFunctionNode() { type = TYPE_BUILT_IN_FUNCTION; }
};
struct IdentifierNode : public Node {
StringName name;
- IdentifierNode() { type=TYPE_IDENTIFIER; }
+ IdentifierNode() { type = TYPE_IDENTIFIER; }
};
struct LocalVarNode : public Node {
StringName name;
Node *assign;
- LocalVarNode() { type=TYPE_LOCAL_VAR; assign=NULL;}
+ LocalVarNode() {
+ type = TYPE_LOCAL_VAR;
+ assign = NULL;
+ }
};
struct ConstantNode : public Node {
Variant value;
- ConstantNode() { type=TYPE_CONSTANT; }
+ ConstantNode() { type = TYPE_CONSTANT; }
};
struct ArrayNode : public Node {
- Vector<Node*> elements;
- ArrayNode() { type=TYPE_ARRAY; }
+ Vector<Node *> elements;
+ ArrayNode() { type = TYPE_ARRAY; }
};
-
struct DictionaryNode : public Node {
struct Pair {
@@ -190,11 +202,11 @@ public:
};
Vector<Pair> elements;
- DictionaryNode() { type=TYPE_DICTIONARY; }
+ DictionaryNode() { type = TYPE_DICTIONARY; }
};
struct SelfNode : public Node {
- SelfNode() { type=TYPE_SELF; }
+ SelfNode() { type = TYPE_SELF; }
};
struct OperatorNode : public Node {
@@ -255,13 +267,12 @@ public:
Operator op;
- Vector<Node*> arguments;
- OperatorNode() { type=TYPE_OPERATOR; }
+ Vector<Node *> arguments;
+ OperatorNode() { type = TYPE_OPERATOR; }
};
-
-
+
struct PatternNode : public Node {
-
+
enum PatternType {
PT_CONSTANT,
PT_BIND,
@@ -270,30 +281,29 @@ public:
PT_IGNORE_REST,
PT_WILDCARD
};
-
+
PatternType pt_type;
-
+
Node *constant;
StringName bind;
- Map<ConstantNode*, PatternNode*> dictionary;
- Vector<PatternNode*> array;
-
+ Map<ConstantNode *, PatternNode *> dictionary;
+ Vector<PatternNode *> array;
};
-
+
struct PatternBranchNode : public Node {
- Vector<PatternNode*> patterns;
+ Vector<PatternNode *> patterns;
BlockNode *body;
};
-
+
struct MatchNode : public Node {
Node *val_to_match;
- Vector<PatternBranchNode*> branches;
-
+ Vector<PatternBranchNode *> branches;
+
struct CompiledPatternBranch {
Node *compiled_pattern;
BlockNode *body;
};
-
+
Vector<CompiledPatternBranch> compiled_pattern_branches;
};
@@ -310,30 +320,34 @@ public:
};
CFType cf_type;
- Vector<Node*> arguments;
+ Vector<Node *> arguments;
BlockNode *body;
BlockNode *body_else;
-
+
MatchNode *match;
ControlFlowNode *_else; //used for if
- ControlFlowNode() { type=TYPE_CONTROL_FLOW; cf_type=CF_IF; body=NULL; body_else=NULL;}
+ ControlFlowNode() {
+ type = TYPE_CONTROL_FLOW;
+ cf_type = CF_IF;
+ body = NULL;
+ body_else = NULL;
+ }
};
struct AssertNode : public Node {
- Node* condition;
- AssertNode() { type=TYPE_ASSERT; }
+ Node *condition;
+ AssertNode() { type = TYPE_ASSERT; }
};
struct BreakpointNode : public Node {
- BreakpointNode() { type=TYPE_BREAKPOINT; }
+ BreakpointNode() { type = TYPE_BREAKPOINT; }
};
struct NewLineNode : public Node {
- NewLineNode() { type=TYPE_NEWLINE; }
+ NewLineNode() { type = TYPE_NEWLINE; }
};
-
struct Expression {
bool is_op;
@@ -343,8 +357,7 @@ public:
};
};
-
-/*
+ /*
struct OperatorNode : public Node {
DataType return_cache;
@@ -428,18 +441,13 @@ public:
COMPLETION_YIELD,
};
-
-
private:
-
-
GDTokenizer *tokenizer;
-
Node *head;
Node *list;
- template<class T>
- T* alloc_node();
+ template <class T>
+ T *alloc_node();
bool validating;
bool for_completion;
@@ -456,12 +464,11 @@ private:
String base_path;
String self_path;
-
ClassNode *current_class;
FunctionNode *current_function;
BlockNode *current_block;
- bool _get_completable_identifier(CompletionType p_type,StringName& identifier);
+ bool _get_completable_identifier(CompletionType p_type, StringName &identifier);
void _make_completable_call(int p_arg);
CompletionType completion_type;
@@ -481,41 +488,34 @@ private:
ScriptInstance::RPCMode rpc_mode;
-
- void _set_error(const String& p_error, int p_line=-1, int p_column=-1);
+ void _set_error(const String &p_error, int p_line = -1, int p_column = -1);
bool _recover_from_completion();
-
- 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_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, 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);
+ 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);
-
-
-
PatternNode *_parse_pattern(bool p_static);
- void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static);
+ void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static);
void _transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement);
- void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings);
-
-
- void _parse_block(BlockNode *p_block,bool p_static);
+ void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings);
+
+ void _parse_block(BlockNode *p_block, bool p_static);
void _parse_extends(ClassNode *p_class);
void _parse_class(ClassNode *p_class);
bool _end_statement();
- Error _parse(const String& p_base_path);
+ Error _parse(const String &p_base_path);
public:
-
String get_error() const;
int get_error_line() const;
int get_error_column() const;
- 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 parse_bytecode(const Vector<uint8_t> &p_bytecode,const String& p_base_path="",const String& p_self_path="");
+ 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 parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path = "", const String &p_self_path = "");
bool is_tool_script() const;
const Node *get_parse_tree() const;
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index 4e72bc39a4..e1cc75acfc 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.cpp
@@ -27,18 +27,18 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "gd_script.h"
+#include "gd_compiler.h"
#include "global_config.h"
#include "global_constants.h"
-#include "gd_compiler.h"
-#include "os/file_access.h"
#include "io/file_access_encrypted.h"
+#include "os/file_access.h"
#include "os/os.h"
///////////////////////////
-GDNativeClass::GDNativeClass(const StringName& p_name) {
+GDNativeClass::GDNativeClass(const StringName &p_name) {
- name=p_name;
+ name = p_name;
}
/*void GDNativeClass::call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount){
@@ -46,33 +46,30 @@ GDNativeClass::GDNativeClass(const StringName& p_name) {
}*/
-
-bool GDNativeClass::_get(const StringName& p_name,Variant &r_ret) const {
+bool GDNativeClass::_get(const StringName &p_name, Variant &r_ret) const {
bool ok;
int v = ClassDB::get_integer_constant(name, p_name, &ok);
if (ok) {
- r_ret=v;
+ r_ret = v;
return true;
} else {
return false;
}
}
-
void GDNativeClass::_bind_methods() {
- ClassDB::bind_method(D_METHOD("new"),&GDNativeClass::_new);
-
+ ClassDB::bind_method(D_METHOD("new"), &GDNativeClass::_new);
}
Variant GDNativeClass::_new() {
Object *o = instance();
if (!o) {
- ERR_EXPLAIN("Class type: '"+String(name)+"' is not instantiable.");
- ERR_FAIL_COND_V(!o,Variant());
+ ERR_EXPLAIN("Class type: '" + String(name) + "' is not instantiable.");
+ ERR_FAIL_COND_V(!o, Variant());
}
Reference *ref = o->cast_to<Reference>();
@@ -81,7 +78,6 @@ Variant GDNativeClass::_new() {
} else {
return o;
}
-
}
Object *GDNativeClass::instance() {
@@ -89,27 +85,24 @@ Object *GDNativeClass::instance() {
return ClassDB::instance(name);
}
-
-
-GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Object *p_owner,bool p_isref,Variant::CallError& r_error) {
-
+GDInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) {
/* STEP 1, CREATE */
- GDInstance* instance = memnew( GDInstance );
- instance->base_ref=p_isref;
+ GDInstance *instance = memnew(GDInstance);
+ instance->base_ref = p_isref;
instance->members.resize(member_indices.size());
- instance->script=Ref<GDScript>(this);
- instance->owner=p_owner;
+ instance->script = Ref<GDScript>(this);
+ instance->owner = p_owner;
#ifdef DEBUG_ENABLED
//needed for hot reloading
- for(Map<StringName,MemberInfo>::Element *E=member_indices.front();E;E=E->next()) {
- instance->member_indices_cache[E->key()]=E->get().index;
+ for (Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) {
+ instance->member_indices_cache[E->key()] = E->get().index;
}
#endif
instance->owner->set_script_instance(instance);
- /* STEP 2, INITIALIZE AND CONSRTUCT */
+/* STEP 2, INITIALIZE AND CONSRTUCT */
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->lock();
@@ -121,10 +114,10 @@ GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Obj
GDScriptLanguage::singleton->lock->unlock();
#endif
- initializer->call(instance,p_args,p_argcount,r_error);
+ initializer->call(instance, p_args, p_argcount, r_error);
- if (r_error.error!=Variant::CallError::CALL_OK) {
- instance->script=Ref<GDScript>();
+ if (r_error.error != Variant::CallError::CALL_OK) {
+ instance->script = Ref<GDScript>();
instance->owner->set_script_instance(NULL);
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->lock();
@@ -134,47 +127,45 @@ GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Obj
GDScriptLanguage::singleton->lock->unlock();
#endif
- ERR_FAIL_COND_V(r_error.error!=Variant::CallError::CALL_OK, NULL); //error constructing
+ ERR_FAIL_COND_V(r_error.error != Variant::CallError::CALL_OK, NULL); //error constructing
}
//@TODO make thread safe
return instance;
-
}
-Variant GDScript::_new(const Variant** p_args,int p_argcount,Variant::CallError& r_error) {
+Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
/* STEP 1, CREATE */
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
REF ref;
- Object *owner=NULL;
+ Object *owner = NULL;
- GDScript *_baseptr=this;
+ GDScript *_baseptr = this;
while (_baseptr->_base) {
- _baseptr=_baseptr->_base;
+ _baseptr = _baseptr->_base;
}
ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant());
if (_baseptr->native.ptr()) {
- owner=_baseptr->native->instance();
+ owner = _baseptr->native->instance();
} else {
- owner=memnew( Reference ); //by default, no base means use reference
+ owner = memnew(Reference); //by default, no base means use reference
}
- Reference *r=owner->cast_to<Reference>();
+ Reference *r = owner->cast_to<Reference>();
if (r) {
- ref=REF(r);
+ ref = REF(r);
}
-
- GDInstance* instance = _create_instance(p_args,p_argcount,owner,r!=NULL,r_error);
+ GDInstance *instance = _create_instance(p_args, p_argcount, owner, r != NULL, r_error);
if (!instance) {
if (ref.is_null()) {
memdelete(owner); //no owner, sorry
@@ -193,13 +184,12 @@ bool GDScript::can_instance() const {
//return valid; //any script in GDscript can instance
return valid || (!tool && !ScriptServer::is_scripting_enabled());
-
}
Ref<Script> GDScript::get_base_script() const {
if (_base) {
- return Ref<GDScript>( _base );
+ return Ref<GDScript>(_base);
} else {
return Ref<Script>();
}
@@ -218,14 +208,11 @@ struct _GDScriptMemberSort {
int index;
StringName name;
- _FORCE_INLINE_ bool operator<(const _GDScriptMemberSort& p_member) const { return index < p_member.index; }
-
+ _FORCE_INLINE_ bool operator<(const _GDScriptMemberSort &p_member) const { return index < p_member.index; }
};
-
#ifdef TOOLS_ENABLED
-
void GDScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {
placeholders.erase(p_placeholder);
@@ -275,86 +262,80 @@ void GDScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) {
}*/
#endif
-
void GDScript::get_script_method_list(List<MethodInfo> *p_list) const {
- for (const Map<StringName,GDFunction*>::Element *E=member_functions.front();E;E=E->next()) {
+ for (const Map<StringName, GDFunction *>::Element *E = member_functions.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- for(int i=0;i<E->get()->get_argument_count();i++) {
+ mi.name = E->key();
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
PropertyInfo arg;
- arg.type=Variant::NIL; //variant
- arg.name=E->get()->get_argument_name(i);
+ arg.type = Variant::NIL; //variant
+ arg.name = E->get()->get_argument_name(i);
mi.arguments.push_back(arg);
}
- mi.return_val.name="Variant";
+ mi.return_val.name = "Variant";
p_list->push_back(mi);
}
}
void GDScript::get_script_property_list(List<PropertyInfo> *p_list) const {
- const GDScript *sptr=this;
+ const GDScript *sptr = this;
List<PropertyInfo> props;
- while(sptr) {
+ while (sptr) {
Vector<_GDScriptMemberSort> msort;
- for(Map<StringName,PropertyInfo>::Element *E=sptr->member_info.front();E;E=E->next()) {
+ for (Map<StringName, PropertyInfo>::Element *E = sptr->member_info.front(); E; E = E->next()) {
_GDScriptMemberSort ms;
ERR_CONTINUE(!sptr->member_indices.has(E->key()));
- ms.index=sptr->member_indices[E->key()].index;
- ms.name=E->key();
+ ms.index = sptr->member_indices[E->key()].index;
+ ms.name = E->key();
msort.push_back(ms);
-
}
msort.sort();
msort.invert();
- for(int i=0;i<msort.size();i++) {
+ for (int i = 0; i < msort.size(); i++) {
props.push_front(sptr->member_info[msort[i].name]);
-
}
sptr = sptr->_base;
}
- for (List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
p_list->push_back(E->get());
}
-
}
-bool GDScript::has_method(const StringName& p_method) const {
+bool GDScript::has_method(const StringName &p_method) const {
return member_functions.has(p_method);
}
-MethodInfo GDScript::get_method_info(const StringName& p_method) const {
+MethodInfo GDScript::get_method_info(const StringName &p_method) const {
- const Map<StringName,GDFunction*>::Element *E=member_functions.find(p_method);
+ const Map<StringName, GDFunction *>::Element *E = member_functions.find(p_method);
if (!E)
return MethodInfo();
MethodInfo mi;
- mi.name=E->key();
- for(int i=0;i<E->get()->get_argument_count();i++) {
+ mi.name = E->key();
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
PropertyInfo arg;
- arg.type=Variant::NIL; //variant
- arg.name=E->get()->get_argument_name(i);
+ arg.type = Variant::NIL; //variant
+ arg.name = E->get()->get_argument_name(i);
mi.arguments.push_back(arg);
}
- mi.return_val.name="Variant";
+ mi.return_val.name = "Variant";
return mi;
-
}
-
-bool GDScript::get_property_default_value(const StringName& p_property, Variant &r_value) const {
+bool GDScript::get_property_default_value(const StringName &p_property, Variant &r_value) const {
#ifdef TOOLS_ENABLED
@@ -363,26 +344,23 @@ bool GDScript::get_property_default_value(const StringName& p_property, Variant
print_line("\t"+String(String(I->key())+":"+String(I->get())));
}
*/
- const Map<StringName,Variant>::Element *E=member_default_values_cache.find(p_property);
+ const Map<StringName, Variant>::Element *E = member_default_values_cache.find(p_property);
if (E) {
- r_value=E->get();
+ r_value = E->get();
return true;
}
if (base_cache.is_valid()) {
- return base_cache->get_property_default_value(p_property,r_value);
+ return base_cache->get_property_default_value(p_property, r_value);
}
#endif
return false;
-
}
-ScriptInstance* GDScript::instance_create(Object *p_this) {
-
+ScriptInstance *GDScript::instance_create(Object *p_this) {
if (!tool && !ScriptServer::is_scripting_enabled()) {
-
#ifdef TOOLS_ENABLED
//instance a fake script for editing the values
@@ -392,7 +370,7 @@ ScriptInstance* GDScript::instance_create(Object *p_this) {
for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
print_line(E->get().name);
}*/
- PlaceHolderScriptInstance *si = memnew( PlaceHolderScriptInstance(GDScriptLanguage::get_singleton(),Ref<Script>(this),p_this) );
+ PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(GDScriptLanguage::get_singleton(), Ref<Script>(this), p_this));
placeholders.insert(si);
//_update_placeholder(si);
_update_exports();
@@ -402,32 +380,30 @@ ScriptInstance* GDScript::instance_create(Object *p_this) {
#endif
}
- GDScript *top=this;
- while(top->_base)
- top=top->_base;
+ GDScript *top = this;
+ while (top->_base)
+ top = top->_base;
if (top->native.is_valid()) {
- if (!ClassDB::is_parent_class(p_this->get_class_name(),top->native->get_name())) {
+ if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) {
if (ScriptDebugger::get_singleton()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),0,"Script inherits from native type '"+String(top->native->get_name())+"', so it can't be instanced in object of type: '"+p_this->get_class()+"'");
+ GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'");
}
- ERR_EXPLAIN("Script inherits from native type '"+String(top->native->get_name())+"', so it can't be instanced in object of type: '"+p_this->get_class()+"'");
+ ERR_EXPLAIN("Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'");
ERR_FAIL_V(NULL);
-
}
}
Variant::CallError unchecked_error;
- return _create_instance(NULL,0,p_this,p_this->cast_to<Reference>(),unchecked_error);
-
+ return _create_instance(NULL, 0, p_this, p_this->cast_to<Reference>(), unchecked_error);
}
bool GDScript::instance_has(const Object *p_this) const {
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->lock();
#endif
- bool hasit = instances.has((Object*)p_this);
+ bool hasit = instances.has((Object *)p_this);
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->unlock();
@@ -438,39 +414,37 @@ bool GDScript::instance_has(const Object *p_this) const {
bool GDScript::has_source_code() const {
- return source!="";
+ return source != "";
}
String GDScript::get_source_code() const {
return source;
}
-void GDScript::set_source_code(const String& p_code) {
+void GDScript::set_source_code(const String &p_code) {
- if (source==p_code)
+ if (source == p_code)
return;
- source=p_code;
+ source = p_code;
#ifdef TOOLS_ENABLED
- source_changed_cache=true;
- //print_line("SC CHANGED "+get_path());
+ source_changed_cache = true;
+//print_line("SC CHANGED "+get_path());
#endif
-
}
#ifdef TOOLS_ENABLED
-void GDScript::_update_exports_values(Map<StringName,Variant>& values, List<PropertyInfo> &propnames) {
+void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<PropertyInfo> &propnames) {
if (base_cache.is_valid()) {
- base_cache->_update_exports_values(values,propnames);
+ base_cache->_update_exports_values(values, propnames);
}
- for(Map<StringName,Variant>::Element *E=member_default_values_cache.front();E;E=E->next()) {
- values[E->key()]=E->get();
+ for (Map<StringName, Variant>::Element *E = member_default_values_cache.front(); E; E = E->next()) {
+ values[E->key()] = E->get();
}
- for (List<PropertyInfo>::Element *E=members_cache.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = members_cache.front(); E; E = E->next()) {
propnames.push_back(E->get());
}
-
}
#endif
@@ -478,90 +452,87 @@ bool GDScript::_update_exports() {
#ifdef TOOLS_ENABLED
- bool changed=false;
+ bool changed = false;
if (source_changed_cache) {
//print_line("updating source for "+get_path());
- source_changed_cache=false;
- changed=true;
+ source_changed_cache = false;
+ changed = true;
- String basedir=path;
+ String basedir = path;
- if (basedir=="")
- basedir=get_path();
+ if (basedir == "")
+ basedir = get_path();
- if (basedir!="")
- basedir=basedir.get_base_dir();
+ if (basedir != "")
+ basedir = basedir.get_base_dir();
GDParser parser;
- Error err = parser.parse(source,basedir,true,path);
+ Error err = parser.parse(source, basedir, true, path);
- if (err==OK) {
+ if (err == OK) {
- const GDParser::Node* root = parser.get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,false);
+ const GDParser::Node *root = parser.get_parse_tree();
+ ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, false);
- const GDParser::ClassNode *c = static_cast<const GDParser::ClassNode*>(root);
+ 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=Ref<GDScript>();
+ base_cache = Ref<GDScript>();
}
-
- if (c->extends_used && String(c->extends_file)!="" && String(c->extends_file) != get_path()) {
+ if (c->extends_used && String(c->extends_file) != "" && String(c->extends_file) != get_path()) {
String path = c->extends_file;
if (path.is_rel_path()) {
String base = get_path();
- if (base=="" || base.is_rel_path()) {
+ if (base == "" || base.is_rel_path()) {
- ERR_PRINT(("Could not resolve relative path for parent class: "+path).utf8().get_data());
+ ERR_PRINT(("Could not resolve relative path for parent class: " + path).utf8().get_data());
} else {
- path=base.get_base_dir().plus_file(path);
+ path = base.get_base_dir().plus_file(path);
}
}
- if (path!=get_path()) {
+ if (path != get_path()) {
Ref<GDScript> bf = ResourceLoader::load(path);
if (bf.is_valid()) {
//print_line("parent is: "+bf->get_path());
- base_cache=bf;
+ base_cache = bf;
bf->inheriters_cache.insert(get_instance_ID());
//bf->_update_exports(p_instances,true,false);
-
}
} else {
- ERR_PRINT(("Path extending itself in "+path).utf8().get_data());
+ ERR_PRINT(("Path extending itself in " + path).utf8().get_data());
}
}
members_cache.clear();
member_default_values_cache.clear();
- for(int i=0;i<c->variables.size();i++) {
- if (c->variables[i]._export.type==Variant::NIL)
+ for (int i = 0; i < c->variables.size(); i++) {
+ if (c->variables[i]._export.type == Variant::NIL)
continue;
members_cache.push_back(c->variables[i]._export);
//print_line("found "+c->variables[i]._export.name);
- member_default_values_cache[c->variables[i].identifier]=c->variables[i].default_value;
+ member_default_values_cache[c->variables[i].identifier] = c->variables[i].default_value;
}
_signals.clear();
- for(int i=0;i<c->_signals.size();i++) {
- _signals[c->_signals[i].name]=c->_signals[i].arguments;
+ for (int i = 0; i < c->_signals.size(); i++) {
+ _signals[c->_signals[i].name] = c->_signals[i].arguments;
}
}
} else {
//print_line("unchaged is "+get_path());
-
}
if (base_cache.is_valid()) {
@@ -575,13 +546,13 @@ bool GDScript::_update_exports() {
//print_line("updating placeholders for "+get_path());
//update placeholders if any
- Map<StringName,Variant> values;
+ Map<StringName, Variant> values;
List<PropertyInfo> propnames;
- _update_exports_values(values,propnames);
+ _update_exports_values(values, propnames);
- for (Set<PlaceHolderScriptInstance*>::Element *E=placeholders.front();E;E=E->next()) {
+ for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
- E->get()->update(propnames,values);
+ E->get()->update(propnames, values);
}
}
@@ -597,14 +568,14 @@ void GDScript::update_exports() {
_update_exports();
- Set<ObjectID> copy=inheriters_cache; //might get modified
+ Set<ObjectID> copy = inheriters_cache; //might get modified
//print_line("update exports for "+get_path()+" ic: "+itos(copy.size()));
- for(Set<ObjectID>::Element *E=copy.front();E;E=E->next()) {
- Object *id=ObjectDB::get_instance(E->get());
+ for (Set<ObjectID>::Element *E = copy.front(); E; E = E->next()) {
+ Object *id = ObjectDB::get_instance(E->get());
if (!id)
continue;
- GDScript *s=id->cast_to<GDScript>();
+ GDScript *s = id->cast_to<GDScript>();
if (!s)
continue;
s->update_exports();
@@ -613,12 +584,12 @@ void GDScript::update_exports() {
#endif
}
-void GDScript::_set_subclass_path(Ref<GDScript>& p_sc,const String& p_path) {
+void GDScript::_set_subclass_path(Ref<GDScript> &p_sc, const String &p_path) {
- p_sc->path=p_path;
- for(Map<StringName,Ref<GDScript> >::Element *E=p_sc->subclasses.front();E;E=E->next()) {
+ p_sc->path = p_path;
+ for (Map<StringName, Ref<GDScript> >::Element *E = p_sc->subclasses.front(); E; E = E->next()) {
- _set_subclass_path(E->get(),p_path);
+ _set_subclass_path(E->get(), p_path);
}
}
@@ -633,58 +604,54 @@ Error GDScript::reload(bool p_keep_state) {
GDScriptLanguage::singleton->lock->unlock();
#endif
- ERR_FAIL_COND_V(!p_keep_state && has_instances,ERR_ALREADY_IN_USE);
-
- String basedir=path;
-
- if (basedir=="")
- basedir=get_path();
+ ERR_FAIL_COND_V(!p_keep_state && has_instances, ERR_ALREADY_IN_USE);
- if (basedir!="")
- basedir=basedir.get_base_dir();
+ String basedir = path;
+ if (basedir == "")
+ basedir = get_path();
+ if (basedir != "")
+ basedir = basedir.get_base_dir();
-
- valid=false;
+ valid = false;
GDParser parser;
- Error err = parser.parse(source,basedir,false,path);
+ Error err = parser.parse(source, basedir, false, path);
if (err) {
if (ScriptDebugger::get_singleton()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),parser.get_error_line(),"Parser Error: "+parser.get_error());
+ GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_error_line(), "Parser Error: " + parser.get_error());
}
- _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
ERR_FAIL_V(ERR_PARSE_ERROR);
}
-
bool can_run = ScriptServer::is_scripting_enabled() || parser.is_tool_script();
GDCompiler compiler;
- err = compiler.compile(&parser,this,p_keep_state);
+ err = compiler.compile(&parser, this, p_keep_state);
if (err) {
if (can_run) {
if (ScriptDebugger::get_singleton()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),compiler.get_error_line(),"Parser Error: "+compiler.get_error());
+ GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error());
}
- _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
ERR_FAIL_V(ERR_COMPILATION_FAILED);
} else {
return err;
}
}
- valid=true;
+ valid = true;
- for(Map<StringName,Ref<GDScript> >::Element *E=subclasses.front();E;E=E->next()) {
+ for (Map<StringName, Ref<GDScript> >::Element *E = subclasses.front(); E; E = E->next()) {
- _set_subclass_path(E->get(),path);
+ _set_subclass_path(E->get(), path);
}
#ifdef TOOLS_ENABLED
- /*for (Set<PlaceHolderScriptInstance*>::Element *E=placeholders.front();E;E=E->next()) {
+/*for (Set<PlaceHolderScriptInstance*>::Element *E=placeholders.front();E;E=E->next()) {
_update_placeholder(E->get());
}*/
@@ -702,74 +669,67 @@ ScriptLanguage *GDScript::get_language() const {
return GDScriptLanguage::get_singleton();
}
+Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant GDScript::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
+ GDScript *top = this;
+ while (top) {
-
- GDScript *top=this;
- while(top) {
-
- Map<StringName,GDFunction*>::Element *E=top->member_functions.find(p_method);
+ Map<StringName, GDFunction *>::Element *E = top->member_functions.find(p_method);
if (E) {
if (!E->get()->is_static()) {
- WARN_PRINT(String("Can't call non-static function: '"+String(p_method)+"' in script.").utf8().get_data());
+ WARN_PRINT(String("Can't call non-static function: '" + String(p_method) + "' in script.").utf8().get_data());
}
- return E->get()->call(NULL,p_args,p_argcount,r_error);
+ return E->get()->call(NULL, p_args, p_argcount, r_error);
}
- top=top->_base;
+ top = top->_base;
}
//none found, regular
- return Script::call(p_method,p_args,p_argcount,r_error);
-
+ return Script::call(p_method, p_args, p_argcount, r_error);
}
-bool GDScript::_get(const StringName& p_name,Variant &r_ret) const {
+bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
{
-
- const GDScript *top=this;
- while(top) {
+ const GDScript *top = this;
+ while (top) {
{
- const Map<StringName,Variant>::Element *E=top->constants.find(p_name);
+ const Map<StringName, Variant>::Element *E = top->constants.find(p_name);
if (E) {
- r_ret= E->get();
+ r_ret = E->get();
return true;
}
}
{
- const Map<StringName,Ref<GDScript> >::Element *E=subclasses.find(p_name);
+ const Map<StringName, Ref<GDScript> >::Element *E = subclasses.find(p_name);
if (E) {
- r_ret=E->get();
+ r_ret = E->get();
return true;
}
}
- top=top->_base;
+ top = top->_base;
}
- if (p_name==GDScriptLanguage::get_singleton()->strings._script_source) {
+ if (p_name == GDScriptLanguage::get_singleton()->strings._script_source) {
- r_ret=get_source_code();
+ r_ret = get_source_code();
return true;
}
}
-
-
return false;
-
}
-bool GDScript::_set(const StringName& p_name, const Variant& p_value) {
+bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
- if (p_name==GDScriptLanguage::get_singleton()->strings._script_source) {
+ if (p_name == GDScriptLanguage::get_singleton()->strings._script_source) {
set_source_code(p_value);
reload();
@@ -781,159 +741,147 @@ bool GDScript::_set(const StringName& p_name, const Variant& p_value) {
void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const {
- p_properties->push_back( PropertyInfo(Variant::STRING,"script/source",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
+ p_properties->push_back(PropertyInfo(Variant::STRING, "script/source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
-
void GDScript::_bind_methods() {
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"new",&GDScript::_new,MethodInfo(Variant::OBJECT,"new"));
-
- ClassDB::bind_method(D_METHOD("get_as_byte_code"),&GDScript::get_as_byte_code);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo(Variant::OBJECT, "new"));
+ ClassDB::bind_method(D_METHOD("get_as_byte_code"), &GDScript::get_as_byte_code);
}
-
Vector<uint8_t> GDScript::get_as_byte_code() const {
GDTokenizerBuffer tokenizer;
return tokenizer.parse_code_string(source);
};
-
-Error GDScript::load_byte_code(const String& p_path) {
+Error GDScript::load_byte_code(const String &p_path) {
Vector<uint8_t> bytecode;
if (p_path.ends_with("gde")) {
- FileAccess *fa = FileAccess::open(p_path,FileAccess::READ);
- ERR_FAIL_COND_V(!fa,ERR_CANT_OPEN);
- FileAccessEncrypted *fae = memnew( FileAccessEncrypted );
- ERR_FAIL_COND_V(!fae,ERR_CANT_OPEN);
+ FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V(!fa, ERR_CANT_OPEN);
+ FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
+ ERR_FAIL_COND_V(!fae, ERR_CANT_OPEN);
Vector<uint8_t> key;
key.resize(32);
- for(int i=0;i<key.size();i++) {
- key[i]=script_encryption_key[i];
+ for (int i = 0; i < key.size(); i++) {
+ key[i] = script_encryption_key[i];
}
- Error err = fae->open_and_parse(fa,key,FileAccessEncrypted::MODE_READ);
- ERR_FAIL_COND_V(err,err);
+ Error err = fae->open_and_parse(fa, key, FileAccessEncrypted::MODE_READ);
+ ERR_FAIL_COND_V(err, err);
bytecode.resize(fae->get_len());
- fae->get_buffer(bytecode.ptr(),bytecode.size());
+ fae->get_buffer(bytecode.ptr(), bytecode.size());
memdelete(fae);
} else {
bytecode = FileAccess::get_file_as_array(p_path);
}
- ERR_FAIL_COND_V(bytecode.size()==0,ERR_PARSE_ERROR);
- path=p_path;
+ ERR_FAIL_COND_V(bytecode.size() == 0, ERR_PARSE_ERROR);
+ path = p_path;
- String basedir=path;
+ String basedir = path;
- if (basedir=="")
- basedir=get_path();
+ if (basedir == "")
+ basedir = get_path();
- if (basedir!="")
- basedir=basedir.get_base_dir();
+ if (basedir != "")
+ basedir = basedir.get_base_dir();
- valid=false;
+ valid = false;
GDParser parser;
- Error err = parser.parse_bytecode(bytecode,basedir,get_path());
+ Error err = parser.parse_bytecode(bytecode, basedir, get_path());
if (err) {
- _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error("GDScript::load_byte_code", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
ERR_FAIL_V(ERR_PARSE_ERROR);
}
GDCompiler compiler;
- err = compiler.compile(&parser,this);
+ err = compiler.compile(&parser, this);
if (err) {
- _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error("GDScript::load_byte_code", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
ERR_FAIL_V(ERR_COMPILATION_FAILED);
}
- valid=true;
+ valid = true;
- for(Map<StringName,Ref<GDScript> >::Element *E=subclasses.front();E;E=E->next()) {
+ for (Map<StringName, Ref<GDScript> >::Element *E = subclasses.front(); E; E = E->next()) {
- _set_subclass_path(E->get(),path);
+ _set_subclass_path(E->get(), path);
}
return OK;
}
-
-Error GDScript::load_source_code(const String& p_path) {
-
+Error GDScript::load_source_code(const String &p_path) {
PoolVector<uint8_t> sourcef;
Error err;
- FileAccess *f=FileAccess::open(p_path,FileAccess::READ,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (err) {
- ERR_FAIL_COND_V(err,err);
+ ERR_FAIL_COND_V(err, err);
}
int len = f->get_len();
- sourcef.resize(len+1);
+ sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write();
- int r = f->get_buffer(w.ptr(),len);
+ int r = f->get_buffer(w.ptr(), len);
f->close();
memdelete(f);
- ERR_FAIL_COND_V(r!=len,ERR_CANT_OPEN);
- w[len]=0;
+ ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);
+ w[len] = 0;
String s;
- if (s.parse_utf8((const char*)w.ptr())) {
+ if (s.parse_utf8((const char *)w.ptr())) {
- ERR_EXPLAIN("Script '"+p_path+"' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode.");
+ ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode.");
ERR_FAIL_V(ERR_INVALID_DATA);
}
- source=s;
+ source = s;
#ifdef TOOLS_ENABLED
- source_changed_cache=true;
+ source_changed_cache = true;
#endif
//print_line("LSC :"+get_path());
- path=p_path;
+ path = p_path;
return OK;
-
}
-
-const Map<StringName,GDFunction*>& GDScript::debug_get_member_functions() const {
+const Map<StringName, GDFunction *> &GDScript::debug_get_member_functions() const {
return member_functions;
}
-
-
StringName GDScript::debug_get_member_by_index(int p_idx) const {
+ for (const Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) {
- for(const Map<StringName,MemberInfo>::Element *E=member_indices.front();E;E=E->next()) {
-
- if (E->get().index==p_idx)
+ if (E->get().index == p_idx)
return E->key();
}
return "<error>";
}
-
Ref<GDScript> GDScript::get_base() const {
return base;
}
-bool GDScript::has_script_signal(const StringName& p_signal) const {
+bool GDScript::has_script_signal(const StringName &p_signal) const {
if (_signals.has(p_signal))
return true;
if (base.is_valid()) {
return base->has_script_signal(p_signal);
}
#ifdef TOOLS_ENABLED
- else if (base_cache.is_valid()){
+ else if (base_cache.is_valid()) {
return base_cache->has_script_signal(p_signal);
}
@@ -942,13 +890,13 @@ bool GDScript::has_script_signal(const StringName& p_signal) const {
}
void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
- for(const Map<StringName,Vector<StringName> >::Element *E=_signals.front();E;E=E->next()) {
+ for (const Map<StringName, Vector<StringName> >::Element *E = _signals.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- for(int i=0;i<E->get().size();i++) {
+ mi.name = E->key();
+ for (int i = 0; i < E->get().size(); i++) {
PropertyInfo arg;
- arg.name=E->get()[i];
+ arg.name = E->get()[i];
mi.arguments.push_back(arg);
}
r_signals->push_back(mi);
@@ -958,27 +906,25 @@ void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
base->get_script_signal_list(r_signals);
}
#ifdef TOOLS_ENABLED
- else if (base_cache.is_valid()){
+ else if (base_cache.is_valid()) {
base_cache->get_script_signal_list(r_signals);
}
#endif
-
}
+GDScript::GDScript()
+ : script_list(this) {
-GDScript::GDScript() : script_list(this) {
-
-
- _static_ref=this;
- valid=false;
- subclass_count=0;
- initializer=NULL;
- _base=NULL;
- _owner=NULL;
- tool=false;
+ _static_ref = this;
+ valid = false;
+ subclass_count = 0;
+ initializer = NULL;
+ _base = NULL;
+ _owner = NULL;
+ tool = false;
#ifdef TOOLS_ENABLED
- source_changed_cache=false;
+ source_changed_cache = false;
#endif
#ifdef DEBUG_ENABLED
@@ -994,12 +940,12 @@ GDScript::GDScript() : script_list(this) {
}
GDScript::~GDScript() {
- for (Map<StringName,GDFunction*>::Element *E=member_functions.front();E;E=E->next()) {
- memdelete( E->get() );
+ for (Map<StringName, GDFunction *>::Element *E = member_functions.front(); E; E = E->next()) {
+ 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
+ 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
@@ -1014,48 +960,41 @@ GDScript::~GDScript() {
#endif
}
-
-
-
-
//////////////////////////////
// INSTANCE //
//////////////////////////////
-
-bool GDInstance::set(const StringName& p_name, const Variant& p_value) {
+bool GDInstance::set(const StringName &p_name, const Variant &p_value) {
//member
{
- const Map<StringName,GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name);
+ const Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name);
if (E) {
if (E->get().setter) {
- const Variant *val=&p_value;
+ const Variant *val = &p_value;
Variant::CallError err;
- call(E->get().setter,&val,1,err);
- if (err.error==Variant::CallError::CALL_OK) {
+ call(E->get().setter, &val, 1, err);
+ if (err.error == Variant::CallError::CALL_OK) {
return true; //function exists, call was successful
}
- }
- else
+ } else
members[E->get().index] = p_value;
return true;
}
}
- GDScript *sptr=script.ptr();
- while(sptr) {
-
+ GDScript *sptr = script.ptr();
+ while (sptr) {
- Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set);
+ Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set);
if (E) {
- Variant name=p_name;
- const Variant *args[2]={&name,&p_value};
+ Variant name = p_name;
+ const Variant *args[2] = { &name, &p_value };
Variant::CallError err;
- Variant ret = E->get()->call(this,(const Variant**)args,2,err);
- if (err.error==Variant::CallError::CALL_OK && ret.get_type()==Variant::BOOL && ret.operator bool())
+ Variant ret = E->get()->call(this, (const Variant **)args, 2, err);
+ if (err.error == Variant::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool())
return true;
}
sptr = sptr->_base;
@@ -1064,54 +1003,50 @@ bool GDInstance::set(const StringName& p_name, const Variant& p_value) {
return false;
}
-bool GDInstance::get(const StringName& p_name, Variant &r_ret) const {
+bool GDInstance::get(const StringName &p_name, Variant &r_ret) const {
-
-
- const GDScript *sptr=script.ptr();
- while(sptr) {
+ const GDScript *sptr = script.ptr();
+ while (sptr) {
{
- const Map<StringName,GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name);
+ const Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name);
if (E) {
if (E->get().getter) {
Variant::CallError err;
- r_ret=const_cast<GDInstance*>(this)->call(E->get().getter,NULL,0,err);
- if (err.error==Variant::CallError::CALL_OK) {
+ r_ret = const_cast<GDInstance *>(this)->call(E->get().getter, NULL, 0, err);
+ if (err.error == Variant::CallError::CALL_OK) {
return true;
}
}
- r_ret=members[E->get().index];
+ r_ret = members[E->get().index];
return true; //index found
-
}
}
{
const GDScript *sl = sptr;
- while(sl) {
- const Map<StringName,Variant>::Element *E = sl->constants.find(p_name);
+ while (sl) {
+ const Map<StringName, Variant>::Element *E = sl->constants.find(p_name);
if (E) {
- r_ret=E->get();
+ r_ret = E->get();
return true; //index found
-
}
- sl=sl->_base;
+ sl = sl->_base;
}
}
{
- const Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get);
+ const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get);
if (E) {
- Variant name=p_name;
- const Variant *args[1]={&name};
+ Variant name = p_name;
+ const Variant *args[1] = { &name };
Variant::CallError err;
- Variant ret = const_cast<GDFunction*>(E->get())->call(const_cast<GDInstance*>(this),(const Variant**)args,1,err);
- if (err.error==Variant::CallError::CALL_OK && ret.get_type()!=Variant::NIL) {
- r_ret=ret;
+ Variant ret = const_cast<GDFunction *>(E->get())->call(const_cast<GDInstance *>(this), (const Variant **)args, 1, err);
+ if (err.error == Variant::CallError::CALL_OK && ret.get_type() != Variant::NIL) {
+ r_ret = ret;
return true;
}
}
@@ -1120,94 +1055,86 @@ bool GDInstance::get(const StringName& p_name, Variant &r_ret) const {
}
return false;
-
}
-Variant::Type GDInstance::get_property_type(const StringName& p_name,bool *r_is_valid) const {
+Variant::Type GDInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
-
- const GDScript *sptr=script.ptr();
- while(sptr) {
+ const GDScript *sptr = script.ptr();
+ while (sptr) {
if (sptr->member_info.has(p_name)) {
if (r_is_valid)
- *r_is_valid=true;
+ *r_is_valid = true;
return sptr->member_info[p_name].type;
}
sptr = sptr->_base;
}
if (r_is_valid)
- *r_is_valid=false;
+ *r_is_valid = false;
return Variant::NIL;
}
void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const {
// exported members, not doen yet!
- const GDScript *sptr=script.ptr();
+ const GDScript *sptr = script.ptr();
List<PropertyInfo> props;
- while(sptr) {
-
+ while (sptr) {
- const Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list);
+ const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list);
if (E) {
-
Variant::CallError err;
- Variant ret = const_cast<GDFunction*>(E->get())->call(const_cast<GDInstance*>(this),NULL,0,err);
- if (err.error==Variant::CallError::CALL_OK) {
+ Variant ret = const_cast<GDFunction *>(E->get())->call(const_cast<GDInstance *>(this), NULL, 0, err);
+ if (err.error == Variant::CallError::CALL_OK) {
- if (ret.get_type()!=Variant::ARRAY) {
+ if (ret.get_type() != Variant::ARRAY) {
ERR_EXPLAIN("Wrong type for _get_property list, must be an array of dictionaries.");
ERR_FAIL();
}
Array arr = ret;
- for(int i=0;i<arr.size();i++) {
+ for (int i = 0; i < arr.size(); i++) {
Dictionary d = arr[i];
ERR_CONTINUE(!d.has("name"));
ERR_CONTINUE(!d.has("type"));
PropertyInfo pinfo;
- pinfo.type = Variant::Type( d["type"].operator int());
- ERR_CONTINUE(pinfo.type<0 || pinfo.type>=Variant::VARIANT_MAX );
+ pinfo.type = Variant::Type(d["type"].operator int());
+ ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
pinfo.name = d["name"];
- ERR_CONTINUE(pinfo.name=="");
+ ERR_CONTINUE(pinfo.name == "");
if (d.has("hint"))
- pinfo.hint=PropertyHint(d["hint"].operator int());
+ pinfo.hint = PropertyHint(d["hint"].operator int());
if (d.has("hint_string"))
- pinfo.hint_string=d["hint_string"];
+ pinfo.hint_string = d["hint_string"];
if (d.has("usage"))
- pinfo.usage=d["usage"];
+ pinfo.usage = d["usage"];
props.push_back(pinfo);
-
}
-
}
}
//instance a fake script for editing the values
Vector<_GDScriptMemberSort> msort;
- for(Map<StringName,PropertyInfo>::Element *E=sptr->member_info.front();E;E=E->next()) {
+ for (Map<StringName, PropertyInfo>::Element *E = sptr->member_info.front(); E; E = E->next()) {
_GDScriptMemberSort ms;
ERR_CONTINUE(!sptr->member_indices.has(E->key()));
- ms.index=sptr->member_indices[E->key()].index;
- ms.name=E->key();
+ ms.index = sptr->member_indices[E->key()].index;
+ ms.name = E->key();
msort.push_back(ms);
-
}
msort.sort();
msort.invert();
- for(int i=0;i<msort.size();i++) {
+ for (int i = 0; i < msort.size(); i++) {
props.push_front(sptr->member_info[msort[i].name]);
-
}
#if 0
if (sptr->member_functions.has("_get_property_list")) {
@@ -1256,7 +1183,7 @@ void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const {
//props.invert();
- for (List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
p_properties->push_back(E->get());
}
@@ -1264,28 +1191,27 @@ void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const {
void GDInstance::get_method_list(List<MethodInfo> *p_list) const {
- const GDScript *sptr=script.ptr();
- while(sptr) {
+ const GDScript *sptr = script.ptr();
+ while (sptr) {
- for (Map<StringName,GDFunction*>::Element *E = sptr->member_functions.front();E;E=E->next()) {
+ for (Map<StringName, GDFunction *>::Element *E = sptr->member_functions.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- mi.flags|=METHOD_FLAG_FROM_SCRIPT;
- for(int i=0;i<E->get()->get_argument_count();i++)
- mi.arguments.push_back(PropertyInfo(Variant::NIL,"arg"+itos(i)));
+ mi.name = E->key();
+ mi.flags |= METHOD_FLAG_FROM_SCRIPT;
+ for (int i = 0; i < E->get()->get_argument_count(); i++)
+ mi.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i)));
p_list->push_back(mi);
}
sptr = sptr->_base;
}
-
}
-bool GDInstance::has_method(const StringName& p_method) const {
+bool GDInstance::has_method(const StringName &p_method) const {
- const GDScript *sptr=script.ptr();
- while(sptr) {
- const Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(p_method);
+ const GDScript *sptr = script.ptr();
+ while (sptr) {
+ const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method);
if (E)
return true;
sptr = sptr->_base;
@@ -1293,81 +1219,74 @@ bool GDInstance::has_method(const StringName& p_method) const {
return false;
}
-Variant GDInstance::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
+Variant GDInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
//printf("calling %ls:%i method %ls\n", script->get_path().c_str(), -1, String(p_method).c_str());
- GDScript *sptr=script.ptr();
- while(sptr) {
- Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(p_method);
+ GDScript *sptr = script.ptr();
+ while (sptr) {
+ Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method);
if (E) {
- return E->get()->call(this,p_args,p_argcount,r_error);
+ return E->get()->call(this, p_args, p_argcount, r_error);
}
sptr = sptr->_base;
}
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}
-void GDInstance::call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount) {
+void GDInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) {
- GDScript *sptr=script.ptr();
+ GDScript *sptr = script.ptr();
Variant::CallError ce;
- while(sptr) {
- Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(p_method);
+ while (sptr) {
+ Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method);
if (E) {
- E->get()->call(this,p_args,p_argcount,ce);
+ E->get()->call(this, p_args, p_argcount, ce);
}
sptr = sptr->_base;
}
-
}
-
-void GDInstance::_ml_call_reversed(GDScript *sptr,const StringName& p_method,const Variant** p_args,int p_argcount) {
+void GDInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount) {
if (sptr->_base)
- _ml_call_reversed(sptr->_base,p_method,p_args,p_argcount);
+ _ml_call_reversed(sptr->_base, p_method, p_args, p_argcount);
Variant::CallError ce;
- Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(p_method);
+ Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method);
if (E) {
- E->get()->call(this,p_args,p_argcount,ce);
+ E->get()->call(this, p_args, p_argcount, ce);
}
-
}
-void GDInstance::call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount) {
+void GDInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) {
if (script.ptr()) {
- _ml_call_reversed(script.ptr(),p_method,p_args,p_argcount);
+ _ml_call_reversed(script.ptr(), p_method, p_args, p_argcount);
}
}
-
-
void GDInstance::notification(int p_notification) {
//notification is not virutal, it gets called at ALL levels just like in C.
- Variant value=p_notification;
- const Variant *args[1]={&value };
+ Variant value = p_notification;
+ const Variant *args[1] = { &value };
- GDScript *sptr=script.ptr();
- while(sptr) {
- Map<StringName,GDFunction*>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification);
+ GDScript *sptr = script.ptr();
+ while (sptr) {
+ Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification);
if (E) {
Variant::CallError err;
- E->get()->call(this,args,1,err);
- if (err.error!=Variant::CallError::CALL_OK) {
+ E->get()->call(this, args, 1, err);
+ if (err.error != Variant::CallError::CALL_OK) {
//print error about notification call
-
}
}
sptr = sptr->_base;
}
-
}
Ref<Script> GDInstance::get_script() const {
@@ -1380,46 +1299,42 @@ ScriptLanguage *GDInstance::get_language() {
return GDScriptLanguage::get_singleton();
}
-GDInstance::RPCMode GDInstance::get_rpc_mode(const StringName& p_method) const {
+GDInstance::RPCMode GDInstance::get_rpc_mode(const StringName &p_method) const {
const GDScript *cscript = script.ptr();
- while(cscript) {
- const Map<StringName,GDFunction*>::Element *E=cscript->member_functions.find(p_method);
+ while (cscript) {
+ const Map<StringName, GDFunction *>::Element *E = cscript->member_functions.find(p_method);
if (E) {
- if (E->get()->get_rpc_mode()!=RPC_MODE_DISABLED) {
+ if (E->get()->get_rpc_mode() != RPC_MODE_DISABLED) {
return E->get()->get_rpc_mode();
}
-
}
- cscript=cscript->_base;
+ cscript = cscript->_base;
}
return RPC_MODE_DISABLED;
}
-GDInstance::RPCMode GDInstance::get_rset_mode(const StringName& p_variable) const {
+GDInstance::RPCMode GDInstance::get_rset_mode(const StringName &p_variable) const {
const GDScript *cscript = script.ptr();
- while(cscript) {
- const Map<StringName,GDScript::MemberInfo>::Element *E=cscript->member_indices.find(p_variable);
+ while (cscript) {
+ const Map<StringName, GDScript::MemberInfo>::Element *E = cscript->member_indices.find(p_variable);
if (E) {
if (E->get().rpc_mode) {
return E->get().rpc_mode;
}
-
}
- cscript=cscript->_base;
+ cscript = cscript->_base;
}
return RPC_MODE_DISABLED;
}
-
-
void GDInstance::reload_members() {
#ifdef DEBUG_ENABLED
@@ -1430,44 +1345,42 @@ void GDInstance::reload_members() {
new_members.resize(script->member_indices.size());
//pass the values to the new indices
- for(Map<StringName,GDScript::MemberInfo>::Element *E=script->member_indices.front();E;E=E->next()) {
+ for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) {
if (member_indices_cache.has(E->key())) {
Variant value = members[member_indices_cache[E->key()]];
- new_members[E->get().index]=value;
+ new_members[E->get().index] = value;
}
-
}
//apply
- members=new_members;
+ members = new_members;
//pass the values to the new indices
member_indices_cache.clear();
- for(Map<StringName,GDScript::MemberInfo>::Element *E=script->member_indices.front();E;E=E->next()) {
+ for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) {
- member_indices_cache[E->key()]=E->get().index;
+ member_indices_cache[E->key()] = E->get().index;
}
#endif
}
GDInstance::GDInstance() {
- owner=NULL;
- base_ref=false;
+ owner = NULL;
+ base_ref = false;
}
GDInstance::~GDInstance() {
if (script.is_valid() && owner) {
#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
+ GDScriptLanguage::singleton->lock->lock();
#endif
- script->instances.erase(owner);
+ script->instances.erase(owner);
#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
+ GDScriptLanguage::singleton->lock->unlock();
#endif
-
}
}
@@ -1477,8 +1390,7 @@ GDInstance::~GDInstance() {
/************* SCRIPT LANGUAGE **************/
/************* SCRIPT LANGUAGE **************/
-GDScriptLanguage *GDScriptLanguage::singleton=NULL;
-
+GDScriptLanguage *GDScriptLanguage::singleton = NULL;
String GDScriptLanguage::get_name() const {
@@ -1487,63 +1399,60 @@ String GDScriptLanguage::get_name() const {
/* LANGUAGE FUNCTIONS */
-void GDScriptLanguage::_add_global(const StringName& p_name,const Variant& p_value) {
-
+void GDScriptLanguage::_add_global(const StringName &p_name, const Variant &p_value) {
if (globals.has(p_name)) {
//overwrite existing
- global_array[globals[p_name]]=p_value;
+ global_array[globals[p_name]] = p_value;
return;
}
- globals[p_name]=global_array.size();
+ globals[p_name] = global_array.size();
global_array.push_back(p_value);
- _global_array=global_array.ptr();
+ _global_array = global_array.ptr();
}
-void GDScriptLanguage::add_global_constant(const StringName& p_variable,const Variant& p_value) {
+void GDScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) {
- _add_global(p_variable,p_value);
+ _add_global(p_variable, p_value);
}
-
void GDScriptLanguage::init() {
-
//populate global constants
- int gcc=GlobalConstants::get_global_constant_count();
- for(int i=0;i<gcc;i++) {
+ int gcc = GlobalConstants::get_global_constant_count();
+ for (int i = 0; i < gcc; i++) {
- _add_global(StaticCString::create(GlobalConstants::get_global_constant_name(i)),GlobalConstants::get_global_constant_value(i));
+ _add_global(StaticCString::create(GlobalConstants::get_global_constant_name(i)), GlobalConstants::get_global_constant_value(i));
}
- _add_global(StaticCString::create("PI"),Math_PI);
- _add_global(StaticCString::create("INF"),Math_INF);
- _add_global(StaticCString::create("NAN"),Math_NAN);
+ _add_global(StaticCString::create("PI"), Math_PI);
+ _add_global(StaticCString::create("INF"), Math_INF);
+ _add_global(StaticCString::create("NAN"), Math_NAN);
//populate native classes
List<StringName> class_list;
ClassDB::get_class_list(&class_list);
- for(List<StringName>::Element *E=class_list.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) {
StringName n = E->get();
String s = String(n);
if (s.begins_with("_"))
- n=s.substr(1,s.length());
+ n = s.substr(1, s.length());
if (globals.has(n))
continue;
- Ref<GDNativeClass> nc = memnew( GDNativeClass(E->get()) );
- _add_global(n,nc);
+ Ref<GDNativeClass> nc = memnew(GDNativeClass(E->get()));
+ _add_global(n, nc);
}
//populate singletons
List<GlobalConfig::Singleton> singletons;
GlobalConfig::get_singleton()->get_singletons(&singletons);
- for(List<GlobalConfig::Singleton>::Element *E=singletons.front();E;E=E->next()) {
+ for (List<GlobalConfig::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
- _add_global(E->get().name,E->get().ptr);
+ _add_global(E->get().name, E->get().ptr);
}
}
@@ -1555,14 +1464,12 @@ String GDScriptLanguage::get_extension() const {
return "gd";
}
-Error GDScriptLanguage::execute_file(const String& p_path) {
+Error GDScriptLanguage::execute_file(const String &p_path) {
// ??
return OK;
}
-void GDScriptLanguage::finish() {
-
-
+void GDScriptLanguage::finish() {
}
void GDScriptLanguage::profiling_start() {
@@ -1572,27 +1479,26 @@ void GDScriptLanguage::profiling_start() {
lock->lock();
}
- SelfList<GDFunction> *elem=function_list.first();
- while(elem) {
- elem->self()->profile.call_count=0;
- elem->self()->profile.self_time=0;
- elem->self()->profile.total_time=0;
- elem->self()->profile.frame_call_count=0;
- elem->self()->profile.frame_self_time=0;
- elem->self()->profile.frame_total_time=0;
- elem->self()->profile.last_frame_call_count=0;
- elem->self()->profile.last_frame_self_time=0;
- elem->self()->profile.last_frame_total_time=0;
- elem=elem->next();
+ SelfList<GDFunction> *elem = function_list.first();
+ while (elem) {
+ elem->self()->profile.call_count = 0;
+ elem->self()->profile.self_time = 0;
+ elem->self()->profile.total_time = 0;
+ elem->self()->profile.frame_call_count = 0;
+ elem->self()->profile.frame_self_time = 0;
+ elem->self()->profile.frame_total_time = 0;
+ elem->self()->profile.last_frame_call_count = 0;
+ elem->self()->profile.last_frame_self_time = 0;
+ elem->self()->profile.last_frame_total_time = 0;
+ elem = elem->next();
}
- profiling=true;
+ profiling = true;
if (lock) {
lock->unlock();
}
#endif
-
}
void GDScriptLanguage::profiling_stop() {
@@ -1602,7 +1508,7 @@ void GDScriptLanguage::profiling_stop() {
lock->lock();
}
- profiling=false;
+ profiling = false;
if (lock) {
lock->unlock();
}
@@ -1610,95 +1516,83 @@ void GDScriptLanguage::profiling_stop() {
#endif
}
-int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr,int p_info_max) {
+int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) {
- int current=0;
+ int current = 0;
#ifdef DEBUG_ENABLED
if (lock) {
lock->lock();
}
-
- SelfList<GDFunction> *elem=function_list.first();
- while(elem) {
- if (current>=p_info_max)
+ SelfList<GDFunction> *elem = function_list.first();
+ while (elem) {
+ if (current >= p_info_max)
break;
- p_info_arr[current].call_count=elem->self()->profile.call_count;
- p_info_arr[current].self_time=elem->self()->profile.self_time;
- p_info_arr[current].total_time=elem->self()->profile.total_time;
- p_info_arr[current].signature=elem->self()->profile.signature;
- elem=elem->next();
+ p_info_arr[current].call_count = elem->self()->profile.call_count;
+ p_info_arr[current].self_time = elem->self()->profile.self_time;
+ p_info_arr[current].total_time = elem->self()->profile.total_time;
+ p_info_arr[current].signature = elem->self()->profile.signature;
+ elem = elem->next();
current++;
}
-
-
if (lock) {
lock->unlock();
}
-
#endif
return current;
-
-
}
-int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr,int p_info_max) {
+int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) {
- int current=0;
+ int current = 0;
#ifdef DEBUG_ENABLED
if (lock) {
lock->lock();
}
-
- SelfList<GDFunction> *elem=function_list.first();
- while(elem) {
- if (current>=p_info_max)
+ SelfList<GDFunction> *elem = function_list.first();
+ while (elem) {
+ if (current >= p_info_max)
break;
- if (elem->self()->profile.last_frame_call_count>0) {
- p_info_arr[current].call_count=elem->self()->profile.last_frame_call_count;
- p_info_arr[current].self_time=elem->self()->profile.last_frame_self_time;
- p_info_arr[current].total_time=elem->self()->profile.last_frame_total_time;
- p_info_arr[current].signature=elem->self()->profile.signature;
+ if (elem->self()->profile.last_frame_call_count > 0) {
+ p_info_arr[current].call_count = elem->self()->profile.last_frame_call_count;
+ p_info_arr[current].self_time = elem->self()->profile.last_frame_self_time;
+ p_info_arr[current].total_time = elem->self()->profile.last_frame_total_time;
+ p_info_arr[current].signature = elem->self()->profile.signature;
//print_line(String(elem->self()->profile.signature)+": "+itos(elem->self()->profile.last_frame_call_count));
current++;
}
- elem=elem->next();
-
+ elem = elem->next();
}
-
if (lock) {
lock->unlock();
}
-
#endif
return current;
-
}
-
struct GDScriptDepSort {
//must support sorting so inheritance works properly (parent must be reloaded first)
- bool operator()(const Ref<GDScript> &A, const Ref<GDScript>& B) const {
+ bool operator()(const Ref<GDScript> &A, const Ref<GDScript> &B) const {
- if (A==B)
+ if (A == B)
return false; //shouldn't happen but..
- const GDScript *I=B->get_base().ptr();
- while(I) {
- if (I==A.ptr()) {
+ const GDScript *I = B->get_base().ptr();
+ while (I) {
+ if (I == A.ptr()) {
// A is a base of B
return true;
}
- I=I->get_base().ptr();
+ I = I->get_base().ptr();
}
return false; //not a base
@@ -1707,8 +1601,6 @@ struct GDScriptDepSort {
void GDScriptLanguage::reload_all_scripts() {
-
-
#ifdef DEBUG_ENABLED
print_line("RELOAD ALL SCRIPTS");
if (lock) {
@@ -1717,13 +1609,13 @@ void GDScriptLanguage::reload_all_scripts() {
List<Ref<GDScript> > scripts;
- SelfList<GDScript> *elem=script_list.first();
- while(elem) {
+ SelfList<GDScript> *elem = script_list.first();
+ while (elem) {
if (elem->self()->get_path().is_resource_file()) {
- print_line("FOUND: "+elem->self()->get_path());
+ print_line("FOUND: " + elem->self()->get_path());
scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
}
- elem=elem->next();
+ elem = elem->next();
}
if (lock) {
@@ -1734,18 +1626,16 @@ void GDScriptLanguage::reload_all_scripts() {
scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order
- for(List<Ref<GDScript> >::Element *E=scripts.front();E;E=E->next()) {
+ for (List<Ref<GDScript> >::Element *E = scripts.front(); E; E = E->next()) {
- print_line("RELOADING: "+E->get()->get_path());
+ print_line("RELOADING: " + E->get()->get_path());
E->get()->load_source_code(E->get()->get_path());
E->get()->reload(true);
}
#endif
}
-
-void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_soft_reload) {
-
+void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) {
#ifdef DEBUG_ENABLED
@@ -1755,13 +1645,13 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
List<Ref<GDScript> > scripts;
- SelfList<GDScript> *elem=script_list.first();
- while(elem) {
+ SelfList<GDScript> *elem = script_list.first();
+ while (elem) {
if (elem->self()->get_path().is_resource_file()) {
scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
}
- elem=elem->next();
+ elem = elem->next();
}
if (lock) {
@@ -1770,68 +1660,68 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
//when someone asks you why dynamically typed languages are easier to write....
- Map< Ref<GDScript>, Map<ObjectID,List<Pair<StringName,Variant> > > > to_reload;
+ Map<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant> > > > to_reload;
//as scripts are going to be reloaded, must proceed without locking here
scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order
- for(List<Ref<GDScript> >::Element *E=scripts.front();E;E=E->next()) {
+ for (List<Ref<GDScript> >::Element *E = scripts.front(); E; E = E->next()) {
- bool reload = E->get()==p_script || to_reload.has(E->get()->get_base());
+ bool reload = E->get() == p_script || to_reload.has(E->get()->get_base());
if (!reload)
continue;
- to_reload.insert(E->get(),Map<ObjectID,List<Pair<StringName,Variant> > >());
+ to_reload.insert(E->get(), Map<ObjectID, List<Pair<StringName, Variant> > >());
if (!p_soft_reload) {
//save state and remove script from instances
- Map<ObjectID,List<Pair<StringName,Variant> > >& map = to_reload[E->get()];
+ Map<ObjectID, List<Pair<StringName, Variant> > > &map = to_reload[E->get()];
- while(E->get()->instances.front()) {
+ while (E->get()->instances.front()) {
Object *obj = E->get()->instances.front()->get();
//save instance info
- List<Pair<StringName,Variant> > state;
+ 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());
}
}
- //same thing for placeholders
+//same thing for placeholders
#ifdef TOOLS_ENABLED
- while(E->get()->placeholders.size()) {
+ while (E->get()->placeholders.size()) {
Object *obj = E->get()->placeholders.front()->get()->get_owner();
//save instance info
- List<Pair<StringName,Variant> > state;
+ 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());
}
}
#endif
- for(Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get()->pending_reload_state.front();F;F=F->next()) {
- map[F->key()]=F->get(); //pending to reload, use this one instead
+ for (Map<ObjectID, List<Pair<StringName, Variant> > >::Element *F = E->get()->pending_reload_state.front(); F; F = F->next()) {
+ map[F->key()] = F->get(); //pending to reload, use this one instead
}
}
}
- for(Map< Ref<GDScript>, Map<ObjectID,List<Pair<StringName,Variant> > > >::Element *E=to_reload.front();E;E=E->next()) {
+ for (Map<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant> > > >::Element *E = to_reload.front(); E; E = E->next()) {
Ref<GDScript> scr = E->key();
scr->reload(p_soft_reload);
//restore state if saved
- for (Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get().front();F;F=F->next()) {
+ for (Map<ObjectID, List<Pair<StringName, Variant> > >::Element *F = E->get().front(); F; F = F->next()) {
Object *obj = ObjectDB::get_instance(F->key());
if (!obj)
@@ -1845,13 +1735,13 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
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();
+ scr->pending_reload_state[obj->get_instance_ID()] = F->get();
}
continue;
}
- for (List<Pair<StringName,Variant> >::Element *G=F->get().front();G;G=G->next()) {
- obj->get_script_instance()->set(G->get().first,G->get().second);
+ for (List<Pair<StringName, Variant> >::Element *G = F->get().front(); G; G = G->next()) {
+ 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
@@ -1860,14 +1750,13 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
//if instance states were saved, set them!
}
-
#endif
}
void GDScriptLanguage::frame() {
//print_line("calls: "+itos(calls));
- calls=0;
+ calls = 0;
#ifdef DEBUG_ENABLED
if (profiling) {
@@ -1875,18 +1764,17 @@ void GDScriptLanguage::frame() {
lock->lock();
}
- SelfList<GDFunction> *elem=function_list.first();
- while(elem) {
- elem->self()->profile.last_frame_call_count=elem->self()->profile.frame_call_count;
- elem->self()->profile.last_frame_self_time=elem->self()->profile.frame_self_time;
- elem->self()->profile.last_frame_total_time=elem->self()->profile.frame_total_time;
- elem->self()->profile.frame_call_count=0;
- elem->self()->profile.frame_self_time=0;
- elem->self()->profile.frame_total_time=0;
- elem=elem->next();
+ SelfList<GDFunction> *elem = function_list.first();
+ while (elem) {
+ elem->self()->profile.last_frame_call_count = elem->self()->profile.frame_call_count;
+ elem->self()->profile.last_frame_self_time = elem->self()->profile.frame_self_time;
+ elem->self()->profile.last_frame_total_time = elem->self()->profile.frame_total_time;
+ elem->self()->profile.frame_call_count = 0;
+ elem->self()->profile.frame_self_time = 0;
+ elem->self()->profile.frame_total_time = 0;
+ elem = elem->next();
}
-
if (lock) {
lock->unlock();
}
@@ -1896,9 +1784,9 @@ void GDScriptLanguage::frame() {
}
/* EDITOR FUNCTIONS */
-void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
+void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
- static const char *_reserved_words[]={
+ static const char *_reserved_words[] = {
// operators
"and",
"in",
@@ -1948,11 +1836,10 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"sync",
"master",
"slave",
- 0};
-
-
- const char **w=_reserved_words;
+ 0
+ };
+ const char **w = _reserved_words;
while (*w) {
@@ -1960,73 +1847,69 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
w++;
}
- for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
+ for (int i = 0; i < GDFunctions::FUNC_MAX; i++) {
p_words->push_back(GDFunctions::get_func_name(GDFunctions::Function(i)));
}
-
}
GDScriptLanguage::GDScriptLanguage() {
- calls=0;
+ calls = 0;
ERR_FAIL_COND(singleton);
- singleton=this;
+ singleton = this;
strings._init = StaticCString::create("_init");
strings._notification = StaticCString::create("_notification");
- strings._set= StaticCString::create("_set");
- strings._get= StaticCString::create("_get");
- strings._get_property_list= StaticCString::create("_get_property_list");
- strings._script_source=StaticCString::create("script/source");
- _debug_parse_err_line=-1;
- _debug_parse_err_file="";
+ strings._set = StaticCString::create("_set");
+ strings._get = StaticCString::create("_get");
+ strings._get_property_list = StaticCString::create("_get_property_list");
+ strings._script_source = StaticCString::create("script/source");
+ _debug_parse_err_line = -1;
+ _debug_parse_err_file = "";
#ifdef NO_THREADS
- lock=NULL;
+ lock = NULL;
#else
lock = Mutex::create();
#endif
- profiling=false;
- script_frame_time=0;
+ profiling = false;
+ script_frame_time = 0;
- _debug_call_stack_pos=0;
- int dmcs=GLOBAL_DEF("debug/script/max_call_stack",1024);
+ _debug_call_stack_pos = 0;
+ int dmcs = GLOBAL_DEF("debug/script/max_call_stack", 1024);
if (ScriptDebugger::get_singleton()) {
//debugging enabled!
_debug_max_call_stack = dmcs;
- if (_debug_max_call_stack<1024)
- _debug_max_call_stack=1024;
- _call_stack = memnew_arr( CallLevel, _debug_max_call_stack+1 );
+ if (_debug_max_call_stack < 1024)
+ _debug_max_call_stack = 1024;
+ _call_stack = memnew_arr(CallLevel, _debug_max_call_stack + 1);
} else {
- _debug_max_call_stack=0;
- _call_stack=NULL;
+ _debug_max_call_stack = 0;
+ _call_stack = NULL;
}
-
}
-
GDScriptLanguage::~GDScriptLanguage() {
-
if (lock) {
memdelete(lock);
- lock=NULL;
+ lock = NULL;
}
- if (_call_stack) {
+ if (_call_stack) {
memdelete_arr(_call_stack);
}
- singleton=NULL;
+ singleton = NULL;
}
/*************** RESOURCE ***************/
-RES ResourceFormatLoaderGDScript::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_FILE_CANT_OPEN;
+ *r_error = ERR_FILE_CANT_OPEN;
- GDScript *script = memnew( GDScript );
+ GDScript *script = memnew(GDScript);
Ref<GDScript> scriptres(script);
@@ -2036,18 +1919,17 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String& p_ori
script->set_path(p_original_path);
Error err = script->load_byte_code(p_path);
+ if (err != OK) {
- if (err!=OK) {
-
- ERR_FAIL_COND_V(err!=OK, RES());
+ ERR_FAIL_COND_V(err != OK, RES());
}
} else {
Error err = script->load_source_code(p_path);
- if (err!=OK) {
+ if (err != OK) {
- ERR_FAIL_COND_V(err!=OK, RES());
+ ERR_FAIL_COND_V(err != OK, RES());
}
script->set_script_path(p_original_path); // script needs this.
@@ -2057,7 +1939,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String& p_ori
script->reload();
}
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return scriptres;
}
@@ -2068,38 +1950,36 @@ void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_ext
p_extensions->push_back("gde");
}
-bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const {
+bool ResourceFormatLoaderGDScript::handles_type(const String &p_type) const {
- return (p_type=="Script" || p_type=="GDScript");
+ return (p_type == "Script" || p_type == "GDScript");
}
String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el=="gd" || el=="gdc" || el=="gde")
+ if (el == "gd" || el == "gdc" || el == "gde")
return "GDScript";
return "";
}
-
-Error ResourceFormatSaverGDScript::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
+Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<GDScript> sqscr = p_resource;
- ERR_FAIL_COND_V(sqscr.is_null(),ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER);
String source = sqscr->get_source_code();
Error err;
- FileAccess *file = FileAccess::open(p_path,FileAccess::WRITE,&err);
-
+ FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
- ERR_FAIL_COND_V(err,err);
+ ERR_FAIL_COND_V(err, err);
}
file->store_string(source);
- if (file->get_error()!=OK && file->get_error()!=ERR_FILE_EOF) {
+ if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
memdelete(file);
return ERR_CANT_CREATE;
}
@@ -2107,20 +1987,19 @@ Error ResourceFormatSaverGDScript::save(const String &p_path,const RES& p_resour
memdelete(file);
if (ScriptServer::is_reload_scripts_on_save_enabled()) {
- GDScriptLanguage::get_singleton()->reload_tool_script(p_resource,false);
+ GDScriptLanguage::get_singleton()->reload_tool_script(p_resource, false);
}
return OK;
}
-void ResourceFormatSaverGDScript::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const {
+void ResourceFormatSaverGDScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (p_resource->cast_to<GDScript>()) {
p_extensions->push_back("gd");
}
-
}
-bool ResourceFormatSaverGDScript::recognize(const RES& p_resource) const {
+bool ResourceFormatSaverGDScript::recognize(const RES &p_resource) const {
- return p_resource->cast_to<GDScript>()!=NULL;
+ return p_resource->cast_to<GDScript>() != NULL;
}
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h
index 4d3baa5bc0..d64cc9798d 100644
--- a/modules/gdscript/gd_script.h
+++ b/modules/gdscript/gd_script.h
@@ -29,50 +29,45 @@
#ifndef GD_SCRIPT_H
#define GD_SCRIPT_H
-#include "script_language.h"
+#include "gd_function.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
-#include "gd_function.h"
+#include "script_language.h"
class GDNativeClass : public Reference {
- GDCLASS(GDNativeClass,Reference);
+ GDCLASS(GDNativeClass, Reference);
StringName name;
-protected:
- bool _get(const StringName& p_name,Variant &r_ret) const;
+protected:
+ bool _get(const StringName &p_name, Variant &r_ret) const;
static void _bind_methods();
public:
-
- _FORCE_INLINE_ const StringName& get_name() const { return name; }
+ _FORCE_INLINE_ const StringName &get_name() const { return name; }
Variant _new();
Object *instance();
- GDNativeClass(const StringName& p_name);
+ GDNativeClass(const StringName &p_name);
};
-
class GDScript : public Script {
-
- GDCLASS(GDScript,Script);
+ GDCLASS(GDScript, Script);
bool tool;
bool valid;
-
struct MemberInfo {
int index;
StringName setter;
StringName getter;
ScriptInstance::RPCMode rpc_mode;
-
};
-friend class GDInstance;
-friend class GDFunction;
-friend class GDCompiler;
-friend class GDFunctions;
-friend class GDScriptLanguage;
+ friend class GDInstance;
+ friend class GDFunction;
+ friend class GDCompiler;
+ friend class GDFunctions;
+ friend class GDScriptLanguage;
Variant _static_ref; //used for static call
Ref<GDNativeClass> native;
@@ -81,130 +76,125 @@ friend class GDScriptLanguage;
GDScript *_owner; //for subclasses
Set<StringName> members; //members are just indices to the instanced script.
- Map<StringName,Variant> constants;
- Map<StringName,GDFunction*> member_functions;
- Map<StringName,MemberInfo> member_indices; //members are just indices to the instanced script.
- Map<StringName,Ref<GDScript> > subclasses;
- Map<StringName,Vector<StringName> > _signals;
-
+ Map<StringName, Variant> constants;
+ Map<StringName, GDFunction *> member_functions;
+ Map<StringName, MemberInfo> member_indices; //members are just indices to the instanced script.
+ Map<StringName, Ref<GDScript> > subclasses;
+ Map<StringName, Vector<StringName> > _signals;
#ifdef TOOLS_ENABLED
- Map<StringName,int> member_lines;
+ Map<StringName, int> member_lines;
- Map<StringName,Variant> member_default_values;
+ Map<StringName, Variant> member_default_values;
List<PropertyInfo> members_cache;
- Map<StringName,Variant> member_default_values_cache;
+ Map<StringName, Variant> member_default_values_cache;
Ref<GDScript> base_cache;
Set<ObjectID> inheriters_cache;
bool source_changed_cache;
- void _update_exports_values(Map<StringName,Variant>& values, List<PropertyInfo> &propnames);
+ void _update_exports_values(Map<StringName, Variant> &values, List<PropertyInfo> &propnames);
#endif
- Map<StringName,PropertyInfo> member_info;
+ Map<StringName, PropertyInfo> member_info;
GDFunction *initializer; //direct pointer to _init , faster to locate
int subclass_count;
- Set<Object*> instances;
+ Set<Object *> instances;
//exported members
String source;
String path;
String name;
SelfList<GDScript> script_list;
+ GDInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error);
- GDInstance* _create_instance(const Variant** p_args,int p_argcount,Object *p_owner,bool p_isref,Variant::CallError &r_error);
-
- void _set_subclass_path(Ref<GDScript>& p_sc,const String& p_path);
+ void _set_subclass_path(Ref<GDScript> &p_sc, const String &p_path);
#ifdef TOOLS_ENABLED
- Set<PlaceHolderScriptInstance*> placeholders;
+ Set<PlaceHolderScriptInstance *> placeholders;
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
#endif
#ifdef DEBUG_ENABLED
- Map<ObjectID,List<Pair<StringName,Variant> > > pending_reload_state;
+ Map<ObjectID, List<Pair<StringName, Variant> > > pending_reload_state;
#endif
bool _update_exports();
protected:
- bool _get(const StringName& p_name,Variant &r_ret) const;
- bool _set(const StringName& p_name, const Variant& p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
void _get_property_list(List<PropertyInfo> *p_properties) const;
- Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
+ Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
//void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
static void _bind_methods();
-public:
+public:
bool is_valid() const { return valid; }
- const Map<StringName,Ref<GDScript> >& get_subclasses() const { return subclasses; }
- const Map<StringName,Variant >& get_constants() const { return constants; }
- const Set<StringName>& get_members() const { return members; }
- const Map<StringName,GDFunction*>& get_member_functions() const { return member_functions; }
- const Ref<GDNativeClass>& get_native() const { return native; }
+ const Map<StringName, Ref<GDScript> > &get_subclasses() const { return subclasses; }
+ const Map<StringName, Variant> &get_constants() const { return constants; }
+ const Set<StringName> &get_members() const { return members; }
+ const Map<StringName, GDFunction *> &get_member_functions() const { return member_functions; }
+ const Ref<GDNativeClass> &get_native() const { return native; }
- virtual bool has_script_signal(const StringName& p_signal) const;
+ virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
-
bool is_tool() const { return tool; }
Ref<GDScript> get_base() const;
- const Map<StringName,MemberInfo>& debug_get_member_indices() const { return member_indices; }
- const Map<StringName,GDFunction*>& debug_get_member_functions() const; //this is debug only
+ const Map<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; }
+ const Map<StringName, GDFunction *> &debug_get_member_functions() const; //this is debug only
StringName debug_get_member_by_index(int p_idx) const;
- Variant _new(const Variant** p_args,int p_argcount,Variant::CallError& r_error);
+ Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
virtual bool can_instance() const;
virtual Ref<Script> get_base_script() const;
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 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 void set_source_code(const String &p_code);
virtual void update_exports();
- virtual Error reload(bool p_keep_state=false);
+ virtual Error reload(bool p_keep_state = false);
virtual String get_node_type() const;
- void set_script_path(const String& p_path) { path=p_path; } //because subclasses need a path too...
- Error load_source_code(const String& p_path);
- Error load_byte_code(const String& p_path);
+ void set_script_path(const String &p_path) { path = p_path; } //because subclasses need a path too...
+ Error load_source_code(const String &p_path);
+ Error load_byte_code(const String &p_path);
Vector<uint8_t> get_as_byte_code() const;
- bool get_property_default_value(const StringName& p_property,Variant& r_value) const;
+ bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
- virtual bool has_method(const StringName& p_method) const;
- virtual MethodInfo get_method_info(const StringName& p_method) const;
+ virtual bool has_method(const StringName &p_method) const;
+ virtual MethodInfo get_method_info(const StringName &p_method) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
-
virtual ScriptLanguage *get_language() const;
- virtual int get_member_line(const StringName& p_member) const {
+ virtual int get_member_line(const StringName &p_member) const {
#ifdef TOOLS_ENABLED
if (member_lines.has(p_member))
return member_lines[p_member];
else
#endif
return -1;
-
}
GDScript();
@@ -212,37 +202,34 @@ public:
};
class GDInstance : public ScriptInstance {
-friend class GDScript;
-friend class GDFunction;
-friend class GDFunctions;
-friend class GDCompiler;
+ friend class GDScript;
+ friend class GDFunction;
+ friend class GDFunctions;
+ friend class GDCompiler;
Object *owner;
Ref<GDScript> script;
#ifdef DEBUG_ENABLED
- Map<StringName,int> member_indices_cache; //used only for hot script reloading
+ Map<StringName, int> member_indices_cache; //used only for hot script reloading
#endif
Vector<Variant> members;
bool base_ref;
-
- void _ml_call_reversed(GDScript *sptr,const StringName& p_method,const Variant** p_args,int p_argcount);
+ void _ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount);
public:
+ _FORCE_INLINE_ Object *get_owner() { return owner; }
- _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 bool set(const StringName &p_name, const Variant &p_value);
+ virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
- virtual Variant::Type get_property_type(const StringName& p_name,bool *r_is_valid=NULL) const;
-
+ virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
- virtual bool has_method(const StringName& p_method) const;
- virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
- virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
- virtual void call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount);
+ virtual bool has_method(const StringName &p_method) const;
+ virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
+ virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
@@ -252,27 +239,24 @@ public:
virtual ScriptLanguage *get_language();
- void set_path(const String& p_path);
+ void set_path(const String &p_path);
void reload_members();
- virtual RPCMode get_rpc_mode(const StringName& p_method) const;
- virtual RPCMode get_rset_mode(const StringName& p_variable) const;
-
+ virtual RPCMode get_rpc_mode(const StringName &p_method) const;
+ virtual RPCMode get_rset_mode(const StringName &p_variable) const;
GDInstance();
~GDInstance();
-
};
class GDScriptLanguage : public ScriptLanguage {
static GDScriptLanguage *singleton;
- Variant* _global_array;
+ Variant *_global_array;
Vector<Variant> global_array;
- Map<StringName,int> globals;
-
+ Map<StringName, int> globals;
struct CallLevel {
@@ -281,10 +265,8 @@ class GDScriptLanguage : public ScriptLanguage {
GDInstance *instance;
int *ip;
int *line;
-
};
-
int _debug_parse_err_line;
String _debug_parse_err_file;
String _debug_error;
@@ -292,65 +274,61 @@ class GDScriptLanguage : public ScriptLanguage {
int _debug_max_call_stack;
CallLevel *_call_stack;
- void _add_global(const StringName& p_name,const Variant& p_value);
+ void _add_global(const StringName &p_name, const Variant &p_value);
-friend class GDInstance;
+ friend class GDInstance;
Mutex *lock;
-
-
-
-friend class GDScript;
+ friend class GDScript;
SelfList<GDScript>::List script_list;
-friend class GDFunction;
+ friend class GDFunction;
SelfList<GDFunction>::List function_list;
bool profiling;
uint64_t script_frame_time;
-public:
-
+public:
int calls;
- bool debug_break(const String& p_error,bool p_allow_continue=true);
- bool debug_break_parse(const String& p_file, int p_line,const String& p_error);
+ bool debug_break(const String &p_error, bool p_allow_continue = true);
+ bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
- _FORCE_INLINE_ void enter_function(GDInstance *p_instance,GDFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
+ _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)
- ScriptDebugger::get_singleton()->set_depth( ScriptDebugger::get_singleton()->get_depth() +1 );
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
+ ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1);
if (_debug_call_stack_pos >= _debug_max_call_stack) {
//stack overflow
- _debug_error="Stack Overflow (Stack Size: "+itos(_debug_max_call_stack)+")";
+ _debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")";
ScriptDebugger::get_singleton()->debug(this);
return;
}
- _call_stack[_debug_call_stack_pos].stack=p_stack;
- _call_stack[_debug_call_stack_pos].instance=p_instance;
- _call_stack[_debug_call_stack_pos].function=p_function;
- _call_stack[_debug_call_stack_pos].ip=p_ip;
- _call_stack[_debug_call_stack_pos].line=p_line;
+ _call_stack[_debug_call_stack_pos].stack = p_stack;
+ _call_stack[_debug_call_stack_pos].instance = p_instance;
+ _call_stack[_debug_call_stack_pos].function = p_function;
+ _call_stack[_debug_call_stack_pos].ip = p_ip;
+ _call_stack[_debug_call_stack_pos].line = p_line;
_debug_call_stack_pos++;
}
_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)
- ScriptDebugger::get_singleton()->set_depth( ScriptDebugger::get_singleton()->get_depth() -1 );
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
+ ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1);
- if (_debug_call_stack_pos==0) {
+ if (_debug_call_stack_pos == 0) {
- _debug_error="Stack Underflow (Engine Bug)";
+ _debug_error = "Stack Underflow (Engine Bug)";
ScriptDebugger::get_singleton()->debug(this);
return;
}
@@ -358,16 +336,15 @@ public:
_debug_call_stack_pos--;
}
-
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;
csi.resize(_debug_call_stack_pos);
- for(int i=0;i<_debug_call_stack_pos;i++) {
- csi[_debug_call_stack_pos-i-1].line=_call_stack[i].line?*_call_stack[i].line:0;
- csi[_debug_call_stack_pos-i-1].script=Ref<GDScript>(_call_stack[i].function->get_script());
+ for (int i = 0; i < _debug_call_stack_pos; i++) {
+ csi[_debug_call_stack_pos - i - 1].line = _call_stack[i].line ? *_call_stack[i].line : 0;
+ csi[_debug_call_stack_pos - i - 1].script = Ref<GDScript>(_call_stack[i].function->get_script());
}
return csi;
}
@@ -383,10 +360,9 @@ public:
} strings;
-
_FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
- _FORCE_INLINE_ Variant* get_global_array() { return _global_array; }
- _FORCE_INLINE_ const Map<StringName,int>& get_global_map() { return globals; }
+ _FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
+ _FORCE_INLINE_ const Map<StringName, int> &get_global_map() { return globals; }
_FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; }
@@ -396,26 +372,25 @@ public:
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
- virtual Error execute_file(const String& p_path) ;
+ virtual Error execute_file(const String &p_path);
virtual void finish();
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const;
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
- virtual Ref<Script> get_template(const String& p_class_name, const String& p_base_class_name) const;
- virtual bool validate(const String& p_script,int &r_line_error,int &r_col_error,String& r_test_error, const String& p_path="",List<String> *r_functions=NULL) const;
+ virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
+ virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
- virtual int find_function(const String& p_function,const String& p_code) const;
- virtual String make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const;
- virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint);
+ virtual int find_function(const String &p_function, const String &p_code) const;
+ virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
+ virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint);
#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);
+ 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 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 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);
/* DEBUGGER FUNCTIONS */
@@ -424,24 +399,24 @@ public:
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
- virtual void debug_get_stack_level_locals(int p_level,List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual void debug_get_stack_level_members(int p_level,List<String> *p_members, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual String debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems=-1,int p_max_depth=-1);
+ virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
virtual void reload_all_scripts();
- virtual void reload_tool_script(const Ref<Script>& p_script,bool p_soft_reload);
+ virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
virtual void frame();
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
- virtual void get_public_constants(List<Pair<String,Variant> > *p_constants) 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);
+ 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);
/* LOADER FUNCTIONS */
@@ -451,24 +426,19 @@ public:
~GDScriptLanguage();
};
-
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
public:
-
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
-
};
class ResourceFormatSaverGDScript : public ResourceFormatSaver {
public:
-
- virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
- virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
- virtual bool recognize(const RES& p_resource) const;
-
+ virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
+ virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
+ virtual bool recognize(const RES &p_resource) const;
};
#endif // GD_SCRIPT_H
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index 54b9624e8e..981924191f 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -27,212 +27,205 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "gd_tokenizer.h"
-#include "print_string.h"
#include "gd_functions.h"
#include "io/marshalls.h"
#include "map.h"
+#include "print_string.h"
-const char* GDTokenizer::token_names[TK_MAX]={
-"Empty",
-"Identifier",
-"Constant",
-"Self",
-"Built-In Type",
-"Built-In Func",
-"In",
-"'=='",
-"'!='",
-"'<'",
-"'<='",
-"'>'",
-"'>='",
-"'and'",
-"'or'",
-"'not'",
-"'+'",
-"'-'",
-"'*'",
-"'/'",
-"'%'",
-"'<<'",
-"'>>'",
-"'='",
-"'+='",
-"'-='",
-"'*='",
-"'/='",
-"'%='",
-"'<<='",
-"'>>='",
-"'&='",
-"'|='",
-"'^='",
-"'&'",
-"'|'",
-"'^'",
-"'~'",
-//"Plus Plus",
-//"Minus Minus",
-"if",
-"elif",
-"else",
-"for",
-"do",
-"while",
-"switch (reserved)",
-"case (reserved)",
-"break",
-"continue",
-"pass",
-"return",
-"match",
-"func",
-"class",
-"extends",
-"onready",
-"tool",
-"static",
-"export",
-"setget",
-"const",
-"var",
-"enum",
-"preload",
-"assert",
-"yield",
-"signal",
-"breakpoint",
-"rpc",
-"sync",
-"master",
-"slave",
-"'['",
-"']'",
-"'{'",
-"'}'",
-"'('",
-"')'",
-"','",
-"';'",
-"'.'",
-"'?'",
-"':'",
-"'\\n'",
-"PI",
-"_",
-"INF",
-"NAN",
-"Error",
-"EOF",
-"Cursor"};
+const char *GDTokenizer::token_names[TK_MAX] = {
+ "Empty",
+ "Identifier",
+ "Constant",
+ "Self",
+ "Built-In Type",
+ "Built-In Func",
+ "In",
+ "'=='",
+ "'!='",
+ "'<'",
+ "'<='",
+ "'>'",
+ "'>='",
+ "'and'",
+ "'or'",
+ "'not'",
+ "'+'",
+ "'-'",
+ "'*'",
+ "'/'",
+ "'%'",
+ "'<<'",
+ "'>>'",
+ "'='",
+ "'+='",
+ "'-='",
+ "'*='",
+ "'/='",
+ "'%='",
+ "'<<='",
+ "'>>='",
+ "'&='",
+ "'|='",
+ "'^='",
+ "'&'",
+ "'|'",
+ "'^'",
+ "'~'",
+ //"Plus Plus",
+ //"Minus Minus",
+ "if",
+ "elif",
+ "else",
+ "for",
+ "do",
+ "while",
+ "switch (reserved)",
+ "case (reserved)",
+ "break",
+ "continue",
+ "pass",
+ "return",
+ "match",
+ "func",
+ "class",
+ "extends",
+ "onready",
+ "tool",
+ "static",
+ "export",
+ "setget",
+ "const",
+ "var",
+ "enum",
+ "preload",
+ "assert",
+ "yield",
+ "signal",
+ "breakpoint",
+ "rpc",
+ "sync",
+ "master",
+ "slave",
+ "'['",
+ "']'",
+ "'{'",
+ "'}'",
+ "'('",
+ "')'",
+ "','",
+ "';'",
+ "'.'",
+ "'?'",
+ "':'",
+ "'\\n'",
+ "PI",
+ "_",
+ "INF",
+ "NAN",
+ "Error",
+ "EOF",
+ "Cursor"
+};
const char *GDTokenizer::get_token_name(Token p_token) {
- ERR_FAIL_INDEX_V(p_token,TK_MAX,"<error>");
+ ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>");
return token_names[p_token];
}
static bool _is_text_char(CharType c) {
- return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}
static bool _is_number(CharType c) {
- return (c>='0' && c<='9');
+ return (c >= '0' && c <= '9');
}
static bool _is_hex(CharType c) {
- return (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F');
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
-void GDTokenizerText::_make_token(Token p_type) {
+void GDTokenizerText::_make_token(Token p_type) {
- TokenData &tk=tk_rb[tk_rb_pos];
+ TokenData &tk = tk_rb[tk_rb_pos];
- tk.type=p_type;
- tk.line=line;
- tk.col=column;
+ tk.type = p_type;
+ tk.line = line;
+ tk.col = column;
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
-void GDTokenizerText::_make_identifier(const StringName& p_identifier) {
+void GDTokenizerText::_make_identifier(const StringName &p_identifier) {
- TokenData &tk=tk_rb[tk_rb_pos];
+ TokenData &tk = tk_rb[tk_rb_pos];
- tk.type=TK_IDENTIFIER;
- tk.identifier=p_identifier;
- tk.line=line;
- tk.col=column;
-
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ tk.type = TK_IDENTIFIER;
+ tk.identifier = p_identifier;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
-void GDTokenizerText::_make_built_in_func(GDFunctions::Function p_func) {
-
- TokenData &tk=tk_rb[tk_rb_pos];
+void GDTokenizerText::_make_built_in_func(GDFunctions::Function p_func) {
- tk.type=TK_BUILT_IN_FUNC;
- tk.func=p_func;
- tk.line=line;
- tk.col=column;
+ TokenData &tk = tk_rb[tk_rb_pos];
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ tk.type = TK_BUILT_IN_FUNC;
+ tk.func = p_func;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
-void GDTokenizerText::_make_constant(const Variant& p_constant) {
+void GDTokenizerText::_make_constant(const Variant &p_constant) {
- TokenData &tk=tk_rb[tk_rb_pos];
+ TokenData &tk = tk_rb[tk_rb_pos];
- tk.type=TK_CONSTANT;
- tk.constant=p_constant;
- tk.line=line;
- tk.col=column;
-
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ tk.type = TK_CONSTANT;
+ tk.constant = p_constant;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
-void GDTokenizerText::_make_type(const Variant::Type& p_type) {
-
-
- TokenData &tk=tk_rb[tk_rb_pos];
+void GDTokenizerText::_make_type(const Variant::Type &p_type) {
- tk.type=TK_BUILT_IN_TYPE;
- tk.vtype=p_type;
- tk.line=line;
- tk.col=column;
+ TokenData &tk = tk_rb[tk_rb_pos];
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ tk.type = TK_BUILT_IN_TYPE;
+ tk.vtype = p_type;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
+void GDTokenizerText::_make_error(const String &p_error) {
-void GDTokenizerText::_make_error(const String& p_error) {
-
- error_flag=true;
- last_error=p_error;
-
- TokenData &tk=tk_rb[tk_rb_pos];
- tk.type=TK_ERROR;
- tk.constant=p_error;
- tk.line=line;
- tk.col=column;
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ error_flag = true;
+ last_error = p_error;
+ TokenData &tk = tk_rb[tk_rb_pos];
+ tk.type = TK_ERROR;
+ tk.constant = p_error;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
-
void GDTokenizerText::_make_newline(int p_spaces) {
- TokenData &tk=tk_rb[tk_rb_pos];
- tk.type=TK_NEWLINE;
- tk.constant=p_spaces;
- tk.line=line;
- tk.col=column;
- tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
+ TokenData &tk = tk_rb[tk_rb_pos];
+ tk.type = TK_NEWLINE;
+ tk.constant = p_spaces;
+ tk.line = line;
+ tk.col = column;
+ tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE;
}
void GDTokenizerText::_advance() {
@@ -243,29 +236,32 @@ void GDTokenizerText::_advance() {
return;
}
- if (code_pos>=len) {
+ if (code_pos >= len) {
_make_token(TK_EOF);
return;
}
-#define GETCHAR(m_ofs) ((m_ofs+code_pos)>=len?0:_code[m_ofs+code_pos])
-#define INCPOS(m_amount) { code_pos+=m_amount; column+=m_amount; }
+#define GETCHAR(m_ofs) ((m_ofs + code_pos) >= len ? 0 : _code[m_ofs + code_pos])
+#define INCPOS(m_amount) \
+ { \
+ code_pos += m_amount; \
+ column += m_amount; \
+ }
while (true) {
+ bool is_node_path = false;
+ StringMode string_mode = STRING_DOUBLE_QUOTE;
- bool is_node_path = false;
- StringMode string_mode=STRING_DOUBLE_QUOTE;
-
- switch(GETCHAR(0)) {
+ switch (GETCHAR(0)) {
case 0:
_make_token(TK_EOF);
break;
case '\\':
INCPOS(1);
- if (GETCHAR(0)=='\r') {
+ if (GETCHAR(0) == '\r') {
INCPOS(1);
}
- if (GETCHAR(0)!='\n') {
+ if (GETCHAR(0) != '\n') {
_make_error("Expected newline after '\\'.");
return;
}
@@ -273,7 +269,7 @@ void GDTokenizerText::_advance() {
INCPOS(1);
line++;
- while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') {
+ while (GETCHAR(0) == ' ' || GETCHAR(0) == '\t') {
INCPOS(1);
}
@@ -286,9 +282,9 @@ void GDTokenizerText::_advance() {
case '\n': {
line++;
INCPOS(1);
- column=1;
- int i=0;
- while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
+ column = 1;
+ int i = 0;
+ while (GETCHAR(i) == ' ' || GETCHAR(i) == '\t') {
i++;
}
@@ -298,19 +294,19 @@ void GDTokenizerText::_advance() {
#if 1 //py style tokenizer
case '#': { // line comment skip
- while(GETCHAR(0)!='\n') {
+ while (GETCHAR(0) != '\n') {
code_pos++;
- if (GETCHAR(0)==0) { //end of file
+ if (GETCHAR(0) == 0) { //end of file
//_make_error("Unterminated Comment");
_make_token(TK_EOF);
return;
}
}
INCPOS(1);
- column=1;
+ column = 1;
line++;
- int i=0;
- while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
+ int i = 0;
+ while (GETCHAR(i) == ' ' || GETCHAR(i) == '\t') {
i++;
}
_make_newline(i);
@@ -320,7 +316,7 @@ void GDTokenizerText::_advance() {
#endif
case '/': {
- switch(GETCHAR(1)) {
+ switch (GETCHAR(1)) {
#if 0 // c style tokenizer
case '*': { // block comment
int pos = code_pos+2;
@@ -376,11 +372,10 @@ void GDTokenizerText::_advance() {
} break;
default:
_make_token(TK_OP_DIV);
-
}
} break;
case '=': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_EQUAL);
INCPOS(1);
@@ -389,12 +384,12 @@ void GDTokenizerText::_advance() {
} break;
case '<': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_LESS_EQUAL);
INCPOS(1);
- } else if (GETCHAR(1)=='<') {
- if (GETCHAR(2)=='=') {
+ } else if (GETCHAR(1) == '<') {
+ if (GETCHAR(2) == '=') {
_make_token(TK_OP_ASSIGN_SHIFT_LEFT);
INCPOS(1);
} else {
@@ -406,11 +401,11 @@ void GDTokenizerText::_advance() {
} break;
case '>': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_GREATER_EQUAL);
INCPOS(1);
- } else if (GETCHAR(1)=='>') {
- if (GETCHAR(2)=='=') {
+ } else if (GETCHAR(1) == '>') {
+ if (GETCHAR(2) == '=') {
_make_token(TK_OP_ASSIGN_SHIFT_RIGHT);
INCPOS(1);
@@ -424,7 +419,7 @@ void GDTokenizerText::_advance() {
} break;
case '!': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_NOT_EQUAL);
INCPOS(1);
} else {
@@ -468,7 +463,7 @@ void GDTokenizerText::_advance() {
_make_token(TK_DOLLAR); //for the get_node() shortener
break;
case '^': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_BIT_XOR);
INCPOS(1);
} else {
@@ -480,11 +475,11 @@ void GDTokenizerText::_advance() {
_make_token(TK_OP_BIT_INVERT);
break;
case '&': {
- if (GETCHAR(1)=='&') {
+ if (GETCHAR(1) == '&') {
_make_token(TK_OP_AND);
INCPOS(1);
- } else if (GETCHAR(1)=='=') {
+ } else if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_BIT_AND);
INCPOS(1);
} else {
@@ -492,11 +487,11 @@ void GDTokenizerText::_advance() {
}
} break;
case '|': {
- if (GETCHAR(1)=='|') {
+ if (GETCHAR(1) == '|') {
_make_token(TK_OP_OR);
INCPOS(1);
- } else if (GETCHAR(1)=='=') {
+ } else if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_BIT_OR);
INCPOS(1);
} else {
@@ -505,7 +500,7 @@ void GDTokenizerText::_advance() {
} break;
case '*': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_MUL);
INCPOS(1);
} else {
@@ -514,10 +509,10 @@ void GDTokenizerText::_advance() {
} break;
case '+': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_ADD);
INCPOS(1);
- /*
+ /*
} else if (GETCHAR(1)=='+') {
_make_token(TK_OP_PLUS_PLUS);
INCPOS(1);
@@ -529,10 +524,10 @@ void GDTokenizerText::_advance() {
} break;
case '-': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_SUB);
INCPOS(1);
- /*
+ /*
} else if (GETCHAR(1)=='-') {
_make_token(TK_OP_MINUS_MINUS);
INCPOS(1);
@@ -543,7 +538,7 @@ void GDTokenizerText::_advance() {
} break;
case '%': {
- if (GETCHAR(1)=='=') {
+ if (GETCHAR(1) == '=') {
_make_token(TK_OP_ASSIGN_MOD);
INCPOS(1);
} else {
@@ -551,106 +546,103 @@ void GDTokenizerText::_advance() {
}
} break;
case '@':
- if( CharType(GETCHAR(1))!='"' && CharType(GETCHAR(1))!='\'' ) {
+ if (CharType(GETCHAR(1)) != '"' && CharType(GETCHAR(1)) != '\'') {
_make_error("Unexpected '@'");
return;
}
INCPOS(1);
- is_node_path=true;
+ is_node_path = true;
case '\'':
case '"': {
- if (GETCHAR(0)=='\'')
- string_mode=STRING_SINGLE_QUOTE;
-
-
- int i=1;
- if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') {
- i+=2;
- string_mode=STRING_MULTILINE;
+ if (GETCHAR(0) == '\'')
+ string_mode = STRING_SINGLE_QUOTE;
+ int i = 1;
+ if (string_mode == STRING_DOUBLE_QUOTE && GETCHAR(i) == '"' && GETCHAR(i + 1) == '"') {
+ i += 2;
+ string_mode = STRING_MULTILINE;
}
-
String str;
- while(true) {
- if (CharType(GETCHAR(i))==0) {
+ while (true) {
+ if (CharType(GETCHAR(i)) == 0) {
_make_error("Unterminated String");
return;
- } else if( string_mode==STRING_DOUBLE_QUOTE && CharType(GETCHAR(i))=='"' ) {
+ } else if (string_mode == STRING_DOUBLE_QUOTE && CharType(GETCHAR(i)) == '"') {
break;
- } else if( string_mode==STRING_SINGLE_QUOTE && CharType(GETCHAR(i))=='\'' ) {
+ } else if (string_mode == STRING_SINGLE_QUOTE && CharType(GETCHAR(i)) == '\'') {
break;
- } else if( string_mode==STRING_MULTILINE && CharType(GETCHAR(i))=='\"' && CharType(GETCHAR(i+1))=='\"' && CharType(GETCHAR(i+2))=='\"') {
- i+=2;
+ } else if (string_mode == STRING_MULTILINE && CharType(GETCHAR(i)) == '\"' && CharType(GETCHAR(i + 1)) == '\"' && CharType(GETCHAR(i + 2)) == '\"') {
+ i += 2;
break;
- } else if( string_mode!=STRING_MULTILINE && CharType(GETCHAR(i))=='\n') {
+ } else if (string_mode != STRING_MULTILINE && CharType(GETCHAR(i)) == '\n') {
_make_error("Unexpected EOL at String.");
return;
- } else if( CharType(GETCHAR(i))==0xFFFF) {
+ } else if (CharType(GETCHAR(i)) == 0xFFFF) {
//string ends here, next will be TK
i--;
break;
- } else if (CharType(GETCHAR(i))=='\\') {
+ } else if (CharType(GETCHAR(i)) == '\\') {
//escaped characters...
i++;
CharType next = GETCHAR(i);
- if (next==0) {
+ if (next == 0) {
_make_error("Unterminated String");
return;
}
- CharType res=0;
-
- switch(next) {
-
- case 'a': res=7; break;
- case 'b': res=8; break;
- case 't': res=9; break;
- case 'n': res=10; break;
- case 'v': res=11; break;
- case 'f': res=12; break;
- case 'r': res=13; break;
- case '\'': res='\''; break;
- case '\"': res='\"'; break;
- case '\\': res='\\'; break;
- case '/': res='/'; break; //wtf
+ CharType res = 0;
+
+ switch (next) {
+
+ case 'a': res = 7; break;
+ case 'b': res = 8; break;
+ case 't': res = 9; break;
+ case 'n': res = 10; break;
+ case 'v': res = 11; break;
+ case 'f': res = 12; break;
+ case 'r': res = 13; break;
+ case '\'': res = '\''; break;
+ case '\"': res = '\"'; break;
+ case '\\': res = '\\'; break;
+ case '/':
+ res = '/';
+ break; //wtf
case 'u': {
//hexnumbarh - oct is deprecated
- i+=1;
- for(int j=0;j<4;j++) {
- CharType c = GETCHAR(i+j);
- if (c==0) {
+ i += 1;
+ for (int j = 0; j < 4; j++) {
+ CharType c = GETCHAR(i + j);
+ if (c == 0) {
_make_error("Unterminated String");
return;
}
- if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) {
+ if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
_make_error("Malformed hex constant in string");
return;
}
CharType v;
- if (c>='0' && c<='9') {
- v=c-'0';
- } else if (c>='a' && c<='f') {
- v=c-'a';
- v+=10;
- } else if (c>='A' && c<='F') {
- v=c-'A';
- v+=10;
+ if (c >= '0' && c <= '9') {
+ v = c - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ v = c - 'a';
+ v += 10;
+ } else if (c >= 'A' && c <= 'F') {
+ v = c - 'A';
+ v += 10;
} else {
ERR_PRINT("BUG");
- v=0;
+ v = 0;
}
- res<<=4;
- res|=v;
-
-
+ res <<= 4;
+ res |= v;
}
- i+=3;
+ i += 3;
} break;
default: {
@@ -660,15 +652,15 @@ void GDTokenizerText::_advance() {
} break;
}
- str+=res;
+ str += res;
} else {
- if (CharType(GETCHAR(i))=='\n') {
+ if (CharType(GETCHAR(i)) == '\n') {
line++;
- column=1;
+ column = 1;
}
- str+=CharType(GETCHAR(i));
+ str += CharType(GETCHAR(i));
}
i++;
}
@@ -686,54 +678,54 @@ void GDTokenizerText::_advance() {
} break;
default: {
- if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
+ if (_is_number(GETCHAR(0)) || (GETCHAR(0) == '.' && _is_number(GETCHAR(1)))) {
// parse number
- bool period_found=false;
- bool exponent_found=false;
- bool hexa_found=false;
- bool sign_found=false;
+ bool period_found = false;
+ bool exponent_found = false;
+ bool hexa_found = false;
+ bool sign_found = false;
String str;
- int i=0;
+ int i = 0;
- while(true) {
- if (GETCHAR(i)=='.') {
+ while (true) {
+ if (GETCHAR(i) == '.') {
if (period_found || exponent_found) {
_make_error("Invalid numeric constant at '.'");
return;
}
- period_found=true;
- } else if (GETCHAR(i)=='x') {
- if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) {
+ period_found = true;
+ } else if (GETCHAR(i) == 'x') {
+ if (hexa_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
_make_error("Invalid numeric constant at 'x'");
return;
}
- hexa_found=true;
- } else if (!hexa_found && GETCHAR(i)=='e') {
+ hexa_found = true;
+ } else if (!hexa_found && GETCHAR(i) == 'e') {
if (hexa_found || exponent_found) {
_make_error("Invalid numeric constant at 'e'");
return;
}
- exponent_found=true;
+ exponent_found = true;
} else if (_is_number(GETCHAR(i))) {
//all ok
} else if (hexa_found && _is_hex(GETCHAR(i))) {
- } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) {
+ } else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
if (sign_found) {
_make_error("Invalid numeric constant at '-'");
return;
}
- sign_found=true;
+ sign_found = true;
} else
break;
- str+=CharType(GETCHAR(i));
+ str += CharType(GETCHAR(i));
i++;
}
- if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) {
- _make_error("Invalid numeric constant: "+str);
+ if (!(_is_number(str[str.length() - 1]) || (hexa_found && _is_hex(str[str.length() - 1])))) {
+ _make_error("Invalid numeric constant: " + str);
return;
}
@@ -748,13 +740,12 @@ void GDTokenizerText::_advance() {
} else {
int64_t val = str.to_int64();
_make_constant(val);
-
}
return;
}
- if (GETCHAR(0)=='.') {
+ if (GETCHAR(0) == '.') {
//parse period
_make_token(TK_PERIOD);
break;
@@ -763,74 +754,76 @@ void GDTokenizerText::_advance() {
if (_is_text_char(GETCHAR(0))) {
// parse identifier
String str;
- str+=CharType(GETCHAR(0));
+ str += CharType(GETCHAR(0));
- int i=1;
- while(_is_text_char(GETCHAR(i))) {
- str+=CharType(GETCHAR(i));
+ int i = 1;
+ while (_is_text_char(GETCHAR(i))) {
+ str += CharType(GETCHAR(i));
i++;
}
- bool identifier=false;
+ bool identifier = false;
- if (str=="null") {
+ if (str == "null") {
_make_constant(Variant());
- } else if (str=="true") {
+ } else if (str == "true") {
_make_constant(true);
- } else if (str=="false") {
+ } else if (str == "false") {
_make_constant(false);
} else {
- bool found=false;
+ bool found = false;
- struct _bit { Variant::Type type; const char *text;};
+ struct _bit {
+ Variant::Type type;
+ const char *text;
+ };
//built in types
- static const _bit type_list[]={
+ 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},
+ { 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;
- int idx=0;
-
- while(type_list[idx].text) {
+ while (type_list[idx].text) {
- if (str==type_list[idx].text) {
+ if (str == type_list[idx].text) {
_make_type(type_list[idx].type);
- found=true;
+ found = true;
break;
}
idx++;
@@ -841,12 +834,12 @@ void GDTokenizerText::_advance() {
//built in func?
- for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
+ for (int i = 0; i < GDFunctions::FUNC_MAX; i++) {
- if (str==GDFunctions::get_func_name(GDFunctions::Function(i))) {
+ if (str == GDFunctions::get_func_name(GDFunctions::Function(i))) {
_make_built_in_func(GDFunctions::Function(i));
- found=true;
+ found = true;
break;
}
}
@@ -856,66 +849,68 @@ void GDTokenizerText::_advance() {
if (!found) {
+ struct _kws {
+ Token token;
+ const char *text;
+ };
- struct _kws { Token token; const char *text;};
-
- static const _kws keyword_list[]={
+ static const _kws keyword_list[] = {
//ops
- {TK_OP_IN,"in"},
- {TK_OP_NOT,"not"},
- {TK_OP_OR,"or"},
- {TK_OP_AND,"and"},
+ { 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"},
+ { 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}
+ { 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 }
};
- int idx=0;
- found=false;
+ int idx = 0;
+ found = false;
- while(keyword_list[idx].text) {
+ while (keyword_list[idx].text) {
- if (str==keyword_list[idx].text) {
+ if (str == keyword_list[idx].text) {
_make_token(keyword_list[idx].token);
- found=true;
+ found = true;
break;
}
idx++;
@@ -923,10 +918,9 @@ void GDTokenizerText::_advance() {
}
if (!found)
- identifier=true;
+ identifier = true;
}
-
if (identifier) {
_make_identifier(str);
}
@@ -943,381 +937,358 @@ void GDTokenizerText::_advance() {
INCPOS(1);
break;
}
-
}
-void GDTokenizerText::set_code(const String& p_code) {
+void GDTokenizerText::set_code(const String &p_code) {
- code=p_code;
+ code = p_code;
len = p_code.length();
if (len) {
- _code=&code[0];
+ _code = &code[0];
} else {
- _code=NULL;
+ _code = NULL;
}
- code_pos=0;
- line=1; //it is stand-ar-ized that lines begin in 1 in code..
- column=1; //the same holds for columns
- tk_rb_pos=0;
- error_flag=false;
- last_error="";
- for(int i=0;i<MAX_LOOKAHEAD+1;i++)
+ code_pos = 0;
+ line = 1; //it is stand-ar-ized that lines begin in 1 in code..
+ column = 1; //the same holds for columns
+ tk_rb_pos = 0;
+ error_flag = false;
+ last_error = "";
+ for (int i = 0; i < MAX_LOOKAHEAD + 1; i++)
_advance();
}
GDTokenizerText::Token GDTokenizerText::get_token(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, TK_ERROR);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, TK_ERROR);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, TK_ERROR);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, TK_ERROR);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
return tk_rb[ofs].type;
}
int GDTokenizerText::get_token_line(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, -1);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, -1);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, -1);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, -1);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
return tk_rb[ofs].line;
}
int GDTokenizerText::get_token_column(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, -1);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, -1);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, -1);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, -1);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
return tk_rb[ofs].col;
}
-const Variant& GDTokenizerText::get_token_constant(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, tk_rb[0].constant);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, tk_rb[0].constant);
+const Variant &GDTokenizerText::get_token_constant(int p_offset) const {
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, tk_rb[0].constant);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, tk_rb[0].constant);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_CONSTANT,tk_rb[0].constant);
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ 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());
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, StringName());
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, StringName());
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, StringName());
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_IDENTIFIER,StringName());
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ ERR_FAIL_COND_V(tk_rb[ofs].type != TK_IDENTIFIER, StringName());
return tk_rb[ofs].identifier;
-
}
GDFunctions::Function GDTokenizerText::get_token_built_in_func(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_BUILT_IN_FUNC,GDFunctions::FUNC_MAX);
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ ERR_FAIL_COND_V(tk_rb[ofs].type != TK_BUILT_IN_FUNC, GDFunctions::FUNC_MAX);
return tk_rb[ofs].func;
-
}
Variant::Type GDTokenizerText::get_token_type(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, Variant::NIL);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, Variant::NIL);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, Variant::NIL);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, Variant::NIL);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_BUILT_IN_TYPE,Variant::NIL);
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ ERR_FAIL_COND_V(tk_rb[ofs].type != TK_BUILT_IN_TYPE, Variant::NIL);
return tk_rb[ofs].vtype;
-
}
-
int GDTokenizerText::get_token_line_indent(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, 0);
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, 0);
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, 0);
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, 0);
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_NEWLINE,0);
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ ERR_FAIL_COND_V(tk_rb[ofs].type != TK_NEWLINE, 0);
return tk_rb[ofs].constant;
-
}
String GDTokenizerText::get_token_error(int p_offset) const {
- ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, String());
- ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, String());
+ ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, String());
+ ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, String());
- int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
- ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_ERROR,String());
+ int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE;
+ ERR_FAIL_COND_V(tk_rb[ofs].type != TK_ERROR, String());
return tk_rb[ofs].constant;
}
void GDTokenizerText::advance(int p_amount) {
- ERR_FAIL_COND( p_amount <=0 );
- for(int i=0;i<p_amount;i++)
+ ERR_FAIL_COND(p_amount <= 0);
+ for (int i = 0; i < p_amount; i++)
_advance();
}
-
-
-
-
-
-
-
-
-
-
//////////////////////////////////////////////////////////////////////////////////////////////////////
#define BYTECODE_VERSION 12
-Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) {
-
+Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) {
- const uint8_t *buf=p_buffer.ptr();
- int total_len=p_buffer.size();
- ERR_FAIL_COND_V( p_buffer.size()<24 || p_buffer[0]!='G' || p_buffer[1]!='D' || p_buffer[2]!='S' || p_buffer[3]!='C',ERR_INVALID_DATA);
+ const uint8_t *buf = p_buffer.ptr();
+ int total_len = p_buffer.size();
+ ERR_FAIL_COND_V(p_buffer.size() < 24 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA);
int version = decode_uint32(&buf[4]);
- if (version>BYTECODE_VERSION) {
+ if (version > BYTECODE_VERSION) {
ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version.");
- ERR_FAIL_COND_V(version>BYTECODE_VERSION,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(version > BYTECODE_VERSION, ERR_INVALID_DATA);
}
int identifier_count = decode_uint32(&buf[8]);
int constant_count = decode_uint32(&buf[12]);
int line_count = decode_uint32(&buf[16]);
int token_count = decode_uint32(&buf[20]);
- const uint8_t *b=buf;
+ const uint8_t *b = buf;
- b=&buf[24];
- total_len-=24;
+ b = &buf[24];
+ total_len -= 24;
identifiers.resize(identifier_count);
- for(int i=0;i<identifier_count;i++) {
+ for (int i = 0; i < identifier_count; i++) {
int len = decode_uint32(b);
- ERR_FAIL_COND_V(len>total_len,ERR_INVALID_DATA);
- b+=4;
+ ERR_FAIL_COND_V(len > total_len, ERR_INVALID_DATA);
+ b += 4;
Vector<uint8_t> cs;
cs.resize(len);
- for(int j=0;j<len;j++) {
- cs[j]=b[j]^0xb6;
+ for (int j = 0; j < len; j++) {
+ cs[j] = b[j] ^ 0xb6;
}
- cs[cs.size()-1]=0;
+ cs[cs.size() - 1] = 0;
String s;
- s.parse_utf8((const char*)cs.ptr());
- b+=len;
- total_len-=len+4;
- identifiers[i]=s;
+ s.parse_utf8((const char *)cs.ptr());
+ b += len;
+ total_len -= len + 4;
+ identifiers[i] = s;
}
constants.resize(constant_count);
- for(int i=0;i<constant_count;i++) {
+ for (int i = 0; i < constant_count; i++) {
Variant v;
int len;
- Error err = decode_variant(v,b,total_len,&len);
+ Error err = decode_variant(v, b, total_len, &len);
if (err)
return err;
- b+=len;
- total_len-=len;
- constants[i]=v;
-
+ b += len;
+ total_len -= len;
+ constants[i] = v;
}
- ERR_FAIL_COND_V(line_count*8>total_len,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(line_count * 8 > total_len, ERR_INVALID_DATA);
- for(int i=0;i<line_count;i++) {
+ for (int i = 0; i < line_count; i++) {
- uint32_t token=decode_uint32(b);
- b+=4;
- uint32_t linecol=decode_uint32(b);
- b+=4;
+ uint32_t token = decode_uint32(b);
+ b += 4;
+ uint32_t linecol = decode_uint32(b);
+ b += 4;
- lines.insert(token,linecol);
- total_len-=8;
+ lines.insert(token, linecol);
+ total_len -= 8;
}
tokens.resize(token_count);
- for(int i=0;i<token_count;i++) {
+ for (int i = 0; i < token_count; i++) {
- ERR_FAIL_COND_V( total_len < 1, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(total_len < 1, ERR_INVALID_DATA);
- if ((*b)&TOKEN_BYTE_MASK) { //little endian always
- ERR_FAIL_COND_V( total_len < 4, ERR_INVALID_DATA);
+ if ((*b) & TOKEN_BYTE_MASK) { //little endian always
+ ERR_FAIL_COND_V(total_len < 4, ERR_INVALID_DATA);
- tokens[i]=decode_uint32(b)&~TOKEN_BYTE_MASK;
- b+=4;
+ tokens[i] = decode_uint32(b) & ~TOKEN_BYTE_MASK;
+ b += 4;
} else {
- tokens[i]=*b;
- b+=1;
+ tokens[i] = *b;
+ b += 1;
total_len--;
}
}
- token=0;
+ token = 0;
return OK;
-
}
-
-Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String& p_code) {
+Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String &p_code) {
Vector<uint8_t> buf;
-
- Map<StringName,int> identifier_map;
- HashMap<Variant,int,VariantHasher,VariantComparator> constant_map;
- Map<uint32_t,int> line_map;
+ Map<StringName, int> identifier_map;
+ HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
+ Map<uint32_t, int> line_map;
Vector<uint32_t> token_array;
GDTokenizerText tt;
tt.set_code(p_code);
- int line=-1;
+ int line = -1;
- while(true) {
+ while (true) {
- if (tt.get_token_line()!=line) {
+ if (tt.get_token_line() != line) {
- line=tt.get_token_line();
- line_map[line]=token_array.size();
+ line = tt.get_token_line();
+ line_map[line] = token_array.size();
}
- uint32_t token=tt.get_token();
- switch(tt.get_token()) {
+ uint32_t token = tt.get_token();
+ switch (tt.get_token()) {
case TK_IDENTIFIER: {
StringName id = tt.get_token_identifier();
if (!identifier_map.has(id)) {
int idx = identifier_map.size();
- identifier_map[id]=idx;
+ identifier_map[id] = idx;
}
- token|=identifier_map[id]<<TOKEN_BITS;
+ token |= identifier_map[id] << TOKEN_BITS;
} break;
case TK_CONSTANT: {
Variant c = tt.get_token_constant();
if (!constant_map.has(c)) {
int idx = constant_map.size();
- constant_map[c]=idx;
+ constant_map[c] = idx;
}
- token|=constant_map[c]<<TOKEN_BITS;
+ token |= constant_map[c] << TOKEN_BITS;
} break;
case TK_BUILT_IN_TYPE: {
- token|=tt.get_token_type()<<TOKEN_BITS;
+ token |= tt.get_token_type() << TOKEN_BITS;
} break;
case TK_BUILT_IN_FUNC: {
- token|=tt.get_token_built_in_func()<<TOKEN_BITS;
+ token |= tt.get_token_built_in_func() << TOKEN_BITS;
} break;
case TK_NEWLINE: {
- token|=tt.get_token_line_indent()<<TOKEN_BITS;
+ token |= tt.get_token_line_indent() << TOKEN_BITS;
} break;
case TK_ERROR: {
ERR_FAIL_V(Vector<uint8_t>());
} break;
default: {}
-
};
token_array.push_back(token);
- if (tt.get_token()==TK_EOF)
+ if (tt.get_token() == TK_EOF)
break;
tt.advance();
-
}
//reverse maps
- Map<int,StringName> rev_identifier_map;
- for(Map<StringName,int>::Element *E=identifier_map.front();E;E=E->next()) {
- rev_identifier_map[E->get()]=E->key();
+ Map<int, StringName> rev_identifier_map;
+ for (Map<StringName, int>::Element *E = identifier_map.front(); E; E = E->next()) {
+ rev_identifier_map[E->get()] = E->key();
}
- Map<int,Variant> rev_constant_map;
- const Variant *K =NULL;
- while((K=constant_map.next(K))) {
- rev_constant_map[constant_map[*K]]=*K;
+ Map<int, Variant> rev_constant_map;
+ const Variant *K = NULL;
+ while ((K = constant_map.next(K))) {
+ rev_constant_map[constant_map[*K]] = *K;
}
- Map<int,uint32_t> rev_line_map;
- for(Map<uint32_t,int>::Element *E=line_map.front();E;E=E->next()) {
- rev_line_map[E->get()]=E->key();
+ Map<int, uint32_t> rev_line_map;
+ for (Map<uint32_t, int>::Element *E = line_map.front(); E; E = E->next()) {
+ rev_line_map[E->get()] = E->key();
}
//save header
buf.resize(24);
- buf[0]='G';
- buf[1]='D';
- buf[2]='S';
- buf[3]='C';
- encode_uint32(BYTECODE_VERSION,&buf[4]);
- encode_uint32(identifier_map.size(),&buf[8]);
- encode_uint32(constant_map.size(),&buf[12]);
- encode_uint32(line_map.size(),&buf[16]);
- encode_uint32(token_array.size(),&buf[20]);
+ buf[0] = 'G';
+ buf[1] = 'D';
+ buf[2] = 'S';
+ buf[3] = 'C';
+ encode_uint32(BYTECODE_VERSION, &buf[4]);
+ encode_uint32(identifier_map.size(), &buf[8]);
+ encode_uint32(constant_map.size(), &buf[12]);
+ encode_uint32(line_map.size(), &buf[16]);
+ encode_uint32(token_array.size(), &buf[20]);
//save identifiers
- for(Map<int,StringName>::Element *E=rev_identifier_map.front();E;E=E->next()) {
+ for (Map<int, StringName>::Element *E = rev_identifier_map.front(); E; E = E->next()) {
CharString cs = String(E->get()).utf8();
- int len = cs.length()+1;
- int extra = 4-(len%4);
- if (extra==4)
- extra=0;
+ int len = cs.length() + 1;
+ int extra = 4 - (len % 4);
+ if (extra == 4)
+ extra = 0;
uint8_t ibuf[4];
- encode_uint32(len+extra,ibuf);
- for(int i=0;i<4;i++) {
+ encode_uint32(len + extra, ibuf);
+ for (int i = 0; i < 4; i++) {
buf.push_back(ibuf[i]);
}
- for(int i=0;i<len;i++) {
- buf.push_back(cs[i]^0xb6);
+ for (int i = 0; i < len; i++) {
+ buf.push_back(cs[i] ^ 0xb6);
}
- for(int i=0;i<extra;i++) {
- buf.push_back(0^0xb6);
+ for (int i = 0; i < extra; i++) {
+ buf.push_back(0 ^ 0xb6);
}
}
- for(Map<int,Variant>::Element *E=rev_constant_map.front();E;E=E->next()) {
+ for (Map<int, Variant>::Element *E = rev_constant_map.front(); E; E = E->next()) {
int len;
- Error err = encode_variant(E->get(),NULL,len);
- ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
- int pos=buf.size();
- buf.resize(pos+len);
- encode_variant(E->get(),&buf[pos],len);
+ Error err = encode_variant(E->get(), NULL, len);
+ ERR_FAIL_COND_V(err != OK, Vector<uint8_t>());
+ int pos = buf.size();
+ buf.resize(pos + len);
+ encode_variant(E->get(), &buf[pos], len);
}
- for(Map<int,uint32_t>::Element *E=rev_line_map.front();E;E=E->next()) {
+ for (Map<int, uint32_t>::Element *E = rev_line_map.front(); E; E = E->next()) {
uint8_t ibuf[8];
- encode_uint32(E->key(),&ibuf[0]);
- encode_uint32(E->get(),&ibuf[4]);
- for(int i=0;i<8;i++)
+ encode_uint32(E->key(), &ibuf[0]);
+ encode_uint32(E->get(), &ibuf[4]);
+ for (int i = 0; i < 8; i++)
buf.push_back(ibuf[i]);
}
- for(int i=0;i<token_array.size();i++) {
+ for (int i = 0; i < token_array.size(); i++) {
uint32_t token = token_array[i];
- if (token&~TOKEN_MASK) {
+ if (token & ~TOKEN_MASK) {
uint8_t buf4[4];
- encode_uint32(token_array[i]|TOKEN_BYTE_MASK,&buf4[0]);
- for(int j=0;j<4;j++) {
+ encode_uint32(token_array[i] | TOKEN_BYTE_MASK, &buf4[0]);
+ for (int j = 0; j < 4; j++) {
buf.push_back(buf4[j]);
}
} else {
@@ -1326,102 +1297,94 @@ Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String& p_code) {
}
return buf;
-
}
GDTokenizerBuffer::Token GDTokenizerBuffer::get_token(int p_offset) const {
- int offset = token+p_offset;
+ int offset = token + p_offset;
- if (offset<0 || offset>=tokens.size())
+ if (offset < 0 || offset >= tokens.size())
return TK_EOF;
- return GDTokenizerBuffer::Token(tokens[offset]&TOKEN_MASK);
+ return GDTokenizerBuffer::Token(tokens[offset] & TOKEN_MASK);
}
+StringName GDTokenizerBuffer::get_token_identifier(int p_offset) const {
-StringName GDTokenizerBuffer::get_token_identifier(int p_offset) const{
+ int offset = token + p_offset;
- int offset = token+p_offset;
-
- ERR_FAIL_INDEX_V(offset,tokens.size(),StringName());
- uint32_t identifier = tokens[offset]>>TOKEN_BITS;
- ERR_FAIL_INDEX_V(identifier,(uint32_t)identifiers.size(),StringName());
+ ERR_FAIL_INDEX_V(offset, tokens.size(), StringName());
+ uint32_t identifier = tokens[offset] >> TOKEN_BITS;
+ ERR_FAIL_INDEX_V(identifier, (uint32_t)identifiers.size(), StringName());
return identifiers[identifier];
}
-GDFunctions::Function GDTokenizerBuffer::get_token_built_in_func(int p_offset) const{
+GDFunctions::Function GDTokenizerBuffer::get_token_built_in_func(int p_offset) const {
- int offset = token+p_offset;
- ERR_FAIL_INDEX_V(offset,tokens.size(),GDFunctions::FUNC_MAX);
- return GDFunctions::Function(tokens[offset]>>TOKEN_BITS);
+ int offset = token + p_offset;
+ ERR_FAIL_INDEX_V(offset, tokens.size(), GDFunctions::FUNC_MAX);
+ return GDFunctions::Function(tokens[offset] >> TOKEN_BITS);
}
-Variant::Type GDTokenizerBuffer::get_token_type(int p_offset) const{
+Variant::Type GDTokenizerBuffer::get_token_type(int p_offset) const {
- int offset = token+p_offset;
- ERR_FAIL_INDEX_V(offset,tokens.size(),Variant::NIL);
+ int offset = token + p_offset;
+ ERR_FAIL_INDEX_V(offset, tokens.size(), Variant::NIL);
- return Variant::Type(tokens[offset]>>TOKEN_BITS);
+ return Variant::Type(tokens[offset] >> TOKEN_BITS);
}
-int GDTokenizerBuffer::get_token_line(int p_offset) const{
+int GDTokenizerBuffer::get_token_line(int p_offset) const {
- int offset = token+p_offset;
+ int offset = token + p_offset;
int pos = lines.find_nearest(offset);
- if (pos<0)
+ if (pos < 0)
return -1;
- if (pos>=lines.size())
- pos=lines.size()-1;
+ if (pos >= lines.size())
+ pos = lines.size() - 1;
uint32_t l = lines.getv(pos);
- return l&TOKEN_LINE_MASK;
-
+ return l & TOKEN_LINE_MASK;
}
-int GDTokenizerBuffer::get_token_column(int p_offset) const{
+int GDTokenizerBuffer::get_token_column(int p_offset) const {
- int offset = token+p_offset;
+ int offset = token + p_offset;
int pos = lines.find_nearest(offset);
- if (pos<0)
+ if (pos < 0)
return -1;
- if (pos>=lines.size())
- pos=lines.size()-1;
+ if (pos >= lines.size())
+ pos = lines.size() - 1;
uint32_t l = lines.getv(pos);
- return l>>TOKEN_LINE_BITS;
-
+ return l >> TOKEN_LINE_BITS;
}
-int GDTokenizerBuffer::get_token_line_indent(int p_offset) const{
+int GDTokenizerBuffer::get_token_line_indent(int p_offset) const {
- int offset = token+p_offset;
- ERR_FAIL_INDEX_V(offset,tokens.size(),0);
- return tokens[offset]>>TOKEN_BITS;
+ int offset = token + p_offset;
+ ERR_FAIL_INDEX_V(offset, tokens.size(), 0);
+ return tokens[offset] >> TOKEN_BITS;
}
-const Variant& GDTokenizerBuffer::get_token_constant(int p_offset) const{
-
+const Variant &GDTokenizerBuffer::get_token_constant(int p_offset) const {
- int offset = token+p_offset;
- ERR_FAIL_INDEX_V(offset,tokens.size(),nil);
- uint32_t constant = tokens[offset]>>TOKEN_BITS;
- ERR_FAIL_INDEX_V(constant,(uint32_t)constants.size(),nil);
+ int offset = token + p_offset;
+ ERR_FAIL_INDEX_V(offset, tokens.size(), nil);
+ uint32_t constant = tokens[offset] >> TOKEN_BITS;
+ ERR_FAIL_INDEX_V(constant, (uint32_t)constants.size(), nil);
return constants[constant];
-
}
-String GDTokenizerBuffer::get_token_error(int p_offset) const{
+String GDTokenizerBuffer::get_token_error(int p_offset) const {
ERR_FAIL_V(String());
}
-void GDTokenizerBuffer::advance(int p_amount){
+void GDTokenizerBuffer::advance(int p_amount) {
- ERR_FAIL_INDEX(p_amount+token,tokens.size());
- token+=p_amount;
+ ERR_FAIL_INDEX(p_amount + token, tokens.size());
+ token += p_amount;
}
-GDTokenizerBuffer::GDTokenizerBuffer(){
-
- token=0;
+GDTokenizerBuffer::GDTokenizerBuffer() {
+ token = 0;
}
-
diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h
index 1e9eda7947..c1ed8ad92e 100644
--- a/modules/gdscript/gd_tokenizer.h
+++ b/modules/gdscript/gd_tokenizer.h
@@ -29,15 +29,14 @@
#ifndef GD_TOKENIZER_H
#define GD_TOKENIZER_H
+#include "gd_functions.h"
+#include "string_db.h"
#include "ustring.h"
#include "variant.h"
-#include "string_db.h"
-#include "gd_functions.h"
#include "vmap.h"
class GDTokenizer {
public:
-
enum Token {
TK_EMPTY,
@@ -137,37 +136,36 @@ public:
};
protected:
-
enum StringMode {
STRING_SINGLE_QUOTE,
STRING_DOUBLE_QUOTE,
STRING_MULTILINE
};
- static const char* token_names[TK_MAX];
+ static const char *token_names[TK_MAX];
+
public:
static const char *get_token_name(Token p_token);
- 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;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const=0;
- virtual Variant::Type get_token_type(int p_offset=0) const=0;
- virtual int get_token_line(int p_offset=0) const=0;
- virtual int get_token_column(int p_offset=0) const=0;
- virtual int get_token_line_indent(int p_offset=0) const=0;
- virtual String get_token_error(int p_offset=0) const=0;
- virtual void advance(int p_amount=1)=0;
+ 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;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const = 0;
+ virtual Variant::Type get_token_type(int p_offset = 0) const = 0;
+ virtual int get_token_line(int p_offset = 0) const = 0;
+ virtual int get_token_column(int p_offset = 0) const = 0;
+ virtual int get_token_line_indent(int p_offset = 0) const = 0;
+ virtual String get_token_error(int p_offset = 0) const = 0;
+ virtual void advance(int p_amount = 1) = 0;
virtual ~GDTokenizer(){};
-
};
class GDTokenizerText : public GDTokenizer {
enum {
- MAX_LOOKAHEAD=4,
- TK_RB_SIZE=MAX_LOOKAHEAD*2+1
+ MAX_LOOKAHEAD = 4,
+ TK_RB_SIZE = MAX_LOOKAHEAD * 2 + 1
};
@@ -179,17 +177,21 @@ class GDTokenizerText : public GDTokenizer {
Variant::Type vtype; //for type types
GDFunctions::Function func; //function for built in functions
};
- int line,col;
- TokenData() { type = TK_EMPTY; line=col=0; vtype=Variant::NIL; }
+ int line, col;
+ TokenData() {
+ type = TK_EMPTY;
+ line = col = 0;
+ vtype = Variant::NIL;
+ }
};
void _make_token(Token p_type);
- void _make_newline(int p_spaces=0);
- void _make_identifier(const StringName& p_identifier);
+ void _make_newline(int p_spaces = 0);
+ void _make_identifier(const StringName &p_identifier);
void _make_built_in_func(GDFunctions::Function p_func);
- void _make_constant(const Variant& p_constant);
- void _make_type(const Variant::Type& p_type);
- void _make_error(const String& p_error);
+ void _make_constant(const Variant &p_constant);
+ void _make_type(const Variant::Type &p_type);
+ void _make_error(const String &p_error);
String code;
int len;
@@ -197,66 +199,58 @@ class GDTokenizerText : public GDTokenizer {
const CharType *_code;
int line;
int column;
- TokenData tk_rb[TK_RB_SIZE*2+1];
+ TokenData tk_rb[TK_RB_SIZE * 2 + 1];
int tk_rb_pos;
String last_error;
bool error_flag;
void _advance();
-public:
-
- void set_code(const String& p_code);
- virtual Token get_token(int p_offset=0) const;
- virtual StringName get_token_identifier(int p_offset=0) const;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const;
- virtual Variant::Type get_token_type(int p_offset=0) const;
- virtual int get_token_line(int p_offset=0) const;
- virtual int get_token_column(int p_offset=0) const;
- virtual int get_token_line_indent(int p_offset=0) const;
- virtual const Variant& get_token_constant(int p_offset=0) const;
- virtual String get_token_error(int p_offset=0) const;
- virtual void advance(int p_amount=1);
+public:
+ void set_code(const String &p_code);
+ virtual Token get_token(int p_offset = 0) const;
+ virtual StringName get_token_identifier(int p_offset = 0) const;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const;
+ virtual Variant::Type get_token_type(int p_offset = 0) const;
+ virtual int get_token_line(int p_offset = 0) const;
+ virtual int get_token_column(int p_offset = 0) const;
+ virtual int get_token_line_indent(int p_offset = 0) const;
+ virtual const Variant &get_token_constant(int p_offset = 0) const;
+ virtual String get_token_error(int p_offset = 0) const;
+ virtual void advance(int p_amount = 1);
};
-
-
-
class GDTokenizerBuffer : public GDTokenizer {
-
enum {
- TOKEN_BYTE_MASK=0x80,
- TOKEN_BITS=8,
- TOKEN_MASK=(1<<TOKEN_BITS)-1,
- TOKEN_LINE_BITS=24,
- TOKEN_LINE_MASK=(1<<TOKEN_LINE_BITS)-1,
+ TOKEN_BYTE_MASK = 0x80,
+ TOKEN_BITS = 8,
+ TOKEN_MASK = (1 << TOKEN_BITS) - 1,
+ TOKEN_LINE_BITS = 24,
+ TOKEN_LINE_MASK = (1 << TOKEN_LINE_BITS) - 1,
};
-
Vector<StringName> identifiers;
Vector<Variant> constants;
- VMap<uint32_t,uint32_t> lines;
+ VMap<uint32_t, uint32_t> lines;
Vector<uint32_t> tokens;
Variant nil;
int token;
public:
-
-
- Error set_code_buffer(const Vector<uint8_t> & p_buffer);
- static Vector<uint8_t> parse_code_string(const String& p_code);
- virtual Token get_token(int p_offset=0) const;
- virtual StringName get_token_identifier(int p_offset=0) const;
- virtual GDFunctions::Function get_token_built_in_func(int p_offset=0) const;
- virtual Variant::Type get_token_type(int p_offset=0) const;
- virtual int get_token_line(int p_offset=0) const;
- virtual int get_token_column(int p_offset=0) const;
- virtual int get_token_line_indent(int p_offset=0) const;
- virtual const Variant& get_token_constant(int p_offset=0) const;
- virtual String get_token_error(int p_offset=0) const;
- virtual void advance(int p_amount=1);
+ Error set_code_buffer(const Vector<uint8_t> &p_buffer);
+ static Vector<uint8_t> parse_code_string(const String &p_code);
+ virtual Token get_token(int p_offset = 0) const;
+ virtual StringName get_token_identifier(int p_offset = 0) const;
+ virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const;
+ virtual Variant::Type get_token_type(int p_offset = 0) const;
+ virtual int get_token_line(int p_offset = 0) const;
+ virtual int get_token_column(int p_offset = 0) const;
+ virtual int get_token_line_indent(int p_offset = 0) const;
+ virtual const Variant &get_token_constant(int p_offset = 0) const;
+ virtual String get_token_error(int p_offset = 0) const;
+ virtual void advance(int p_amount = 1);
GDTokenizerBuffer();
};
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp
index d1d69c6709..5acd412f7e 100644
--- a/modules/gdscript/register_types.cpp
+++ b/modules/gdscript/register_types.cpp
@@ -29,22 +29,20 @@
#include "register_types.h"
#include "gd_script.h"
+#include "io/file_access_encrypted.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
-#include "io/file_access_encrypted.h"
-
-
-GDScriptLanguage *script_language_gd=NULL;
-ResourceFormatLoaderGDScript *resource_loader_gd=NULL;
-ResourceFormatSaverGDScript *resource_saver_gd=NULL;
+GDScriptLanguage *script_language_gd = NULL;
+ResourceFormatLoaderGDScript *resource_loader_gd = NULL;
+ResourceFormatSaverGDScript *resource_saver_gd = NULL;
#if 0
#ifdef TOOLS_ENABLED
#include "editor/editor_import_export.h"
-#include "gd_tokenizer.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
+#include "gd_tokenizer.h"
class EditorExportGDScript : public EditorExportPlugin {
@@ -133,7 +131,6 @@ static void register_editor_plugin() {
EditorImportExport::get_singleton()->add_export_plugin(egd);
}
-
#endif
#endif
void register_gdscript_types() {
@@ -141,12 +138,12 @@ void register_gdscript_types() {
ClassDB::register_class<GDScript>();
ClassDB::register_virtual_class<GDFunctionState>();
- script_language_gd=memnew( GDScriptLanguage );
+ script_language_gd = memnew(GDScriptLanguage);
//script_language_gd->init();
ScriptServer::register_language(script_language_gd);
- resource_loader_gd=memnew( ResourceFormatLoaderGDScript );
+ resource_loader_gd = memnew(ResourceFormatLoaderGDScript);
ResourceLoader::add_resource_format_loader(resource_loader_gd);
- resource_saver_gd=memnew( ResourceFormatSaverGDScript );
+ resource_saver_gd = memnew(ResourceFormatSaverGDScript);
ResourceSaver::add_resource_format_saver(resource_saver_gd);
#if 0
#ifdef TOOLS_ENABLED
@@ -154,18 +151,15 @@ void register_gdscript_types() {
EditorNode::add_init_callback(register_editor_plugin);
#endif
#endif
-
}
void unregister_gdscript_types() {
-
ScriptServer::unregister_language(script_language_gd);
if (script_language_gd)
- memdelete( script_language_gd );
+ memdelete(script_language_gd);
if (resource_loader_gd)
- memdelete( resource_loader_gd );
+ memdelete(resource_loader_gd);
if (resource_saver_gd)
- memdelete( resource_saver_gd );
-
+ memdelete(resource_saver_gd);
}
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index d4fb174bfe..128592fa29 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -27,36 +27,36 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "grid_map.h"
-#include "servers/visual_server.h"
-#include "scene/resources/surface_tool.h"
#include "message_queue.h"
#include "scene/3d/light.h"
+#include "scene/resources/surface_tool.h"
+#include "servers/visual_server.h"
#include "io/marshalls.h"
-#include "scene/scene_string_names.h"
#include "os/os.h"
#include "scene/resources/mesh_library.h"
+#include "scene/scene_string_names.h"
-bool GridMap::_set(const StringName& p_name, const Variant& p_value) {
+bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
- String name=p_name;
+ String name = p_name;
- if (name=="theme") {
+ if (name == "theme") {
set_theme(p_value);
- } else if (name=="cell_size") {
+ } else if (name == "cell_size") {
set_cell_size(p_value);
- } else if (name=="cell_octant_size") {
+ } else if (name == "cell_octant_size") {
set_octant_size(p_value);
- } else if (name=="cell_center_x") {
+ } else if (name == "cell_center_x") {
set_center_x(p_value);
- } else if (name=="cell_center_y") {
+ } else if (name == "cell_center_y") {
set_center_y(p_value);
- } else if (name=="cell_center_z") {
+ } else if (name == "cell_center_z") {
set_center_z(p_value);
- } else if (name=="cell_scale") {
+ } else if (name == "cell_scale") {
set_cell_scale(p_value);
-/* } else if (name=="cells") {
+ /* } else if (name=="cells") {
PoolVector<int> cells = p_value;
int amount=cells.size();
PoolVector<int>::Read r = cells.read();
@@ -73,146 +73,138 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) {
}
_recreate_octant_data();*/
- } else if (name=="data") {
+ } else if (name == "data") {
Dictionary d = p_value;
if (d.has("cells")) {
PoolVector<int> cells = d["cells"];
- int amount=cells.size();
+ int amount = cells.size();
PoolVector<int>::Read r = cells.read();
- ERR_FAIL_COND_V(amount%3,false); // not even
+ ERR_FAIL_COND_V(amount % 3, false); // not even
cell_map.clear();
- for(int i=0;i<amount/3;i++) {
+ for (int i = 0; i < amount / 3; i++) {
IndexKey ik;
- ik.key=decode_uint64((const uint8_t*)&r[i*3]);
+ ik.key = decode_uint64((const uint8_t *)&r[i * 3]);
Cell cell;
- cell.cell=decode_uint32((const uint8_t*)&r[i*3+2]);
- cell_map[ik]=cell;
-
+ cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]);
+ cell_map[ik] = cell;
}
}
_recreate_octant_data();
-
} else if (name.begins_with("areas/")) {
- int which = name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="bounds") {
- ERR_FAIL_COND_V(area_map.has(which),false);
- create_area(which,p_value);
+ int which = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "bounds") {
+ ERR_FAIL_COND_V(area_map.has(which), false);
+ create_area(which, p_value);
return true;
}
- ERR_FAIL_COND_V(!area_map.has(which),false);
+ ERR_FAIL_COND_V(!area_map.has(which), false);
- if (what=="name")
- area_set_name(which,p_value);
- else if (what=="disable_distance")
- area_set_portal_disable_distance(which,p_value);
- else if (what=="exterior_portal")
- area_set_portal_disable_color(which,p_value);
+ if (what == "name")
+ area_set_name(which, p_value);
+ else if (what == "disable_distance")
+ area_set_portal_disable_distance(which, p_value);
+ else if (what == "exterior_portal")
+ area_set_portal_disable_color(which, p_value);
else
return false;
} else
return false;
return true;
-
-
}
-bool GridMap::_get(const StringName& p_name,Variant &r_ret) const {
-
- String name=p_name;
-
- if (name=="theme") {
- r_ret= get_theme();
- } else if (name=="cell_size") {
- r_ret= get_cell_size();
- } else if (name=="cell_octant_size") {
- r_ret= get_octant_size();
- } else if (name=="cell_center_x") {
- r_ret= get_center_x();
- } else if (name=="cell_center_y") {
- r_ret= get_center_y();
- } else if (name=="cell_center_z") {
- r_ret= get_center_z();
- } else if (name=="cell_scale") {
- r_ret= cell_scale;
- } else if (name=="data") {
+bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {
+
+ String name = p_name;
+
+ if (name == "theme") {
+ r_ret = get_theme();
+ } else if (name == "cell_size") {
+ r_ret = get_cell_size();
+ } else if (name == "cell_octant_size") {
+ r_ret = get_octant_size();
+ } else if (name == "cell_center_x") {
+ r_ret = get_center_x();
+ } else if (name == "cell_center_y") {
+ r_ret = get_center_y();
+ } else if (name == "cell_center_z") {
+ r_ret = get_center_z();
+ } else if (name == "cell_scale") {
+ r_ret = cell_scale;
+ } else if (name == "data") {
Dictionary d;
PoolVector<int> cells;
- cells.resize(cell_map.size()*3);
+ cells.resize(cell_map.size() * 3);
{
PoolVector<int>::Write w = cells.write();
- int i=0;
- for (Map<IndexKey,Cell>::Element *E=cell_map.front();E;E=E->next(),i++) {
+ int i = 0;
+ for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) {
- encode_uint64(E->key().key,(uint8_t*)&w[i*3]);
- encode_uint32(E->get().cell,(uint8_t*)&w[i*3+2]);
+ encode_uint64(E->key().key, (uint8_t *)&w[i * 3]);
+ encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]);
}
}
- d["cells"]=cells;
-
+ d["cells"] = cells;
-
- r_ret= d;
+ r_ret = d;
} else if (name.begins_with("areas/")) {
- int which = name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="bounds")
- r_ret= area_get_bounds(which);
- else if (what=="name")
- r_ret= area_get_name(which);
- else if (what=="disable_distance")
- r_ret= area_get_portal_disable_distance(which);
- else if (what=="exterior_portal")
- r_ret= area_is_exterior_portal(which);
+ int which = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "bounds")
+ r_ret = area_get_bounds(which);
+ else if (what == "name")
+ r_ret = area_get_name(which);
+ else if (what == "disable_distance")
+ r_ret = area_get_portal_disable_distance(which);
+ else if (what == "exterior_portal")
+ r_ret = area_is_exterior_portal(which);
else
return false;
} else
return false;
return true;
-
}
-void GridMap::_get_property_list( List<PropertyInfo> *p_list) const {
+void GridMap::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo( Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"));
- p_list->push_back( PropertyInfo( Variant::NIL, "Cell", PROPERTY_HINT_NONE,"cell_",PROPERTY_USAGE_GROUP));
- p_list->push_back( PropertyInfo( Variant::REAL, "cell_size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") );
- p_list->push_back( PropertyInfo( Variant::INT, "cell_octant_size",PROPERTY_HINT_RANGE,"1,1024,1") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_x") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_y") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_z") );
- p_list->push_back( PropertyInfo( Variant::REAL, "cell_scale") );
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"));
+ p_list->push_back(PropertyInfo(Variant::NIL, "Cell", PROPERTY_HINT_NONE, "cell_", PROPERTY_USAGE_GROUP));
+ p_list->push_back(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_RANGE, "0.01,16384,0.01"));
+ p_list->push_back(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_x"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_y"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_z"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale"));
- p_list->push_back( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
+ p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- for(const Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
+ for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- String base="areas/"+itos(E->key())+"/";
- p_list->push_back( PropertyInfo( Variant::RECT3, base+"bounds", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
- p_list->push_back( PropertyInfo( Variant::STRING, base+"name", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
- p_list->push_back( PropertyInfo( Variant::REAL, base+"disable_distance", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
- p_list->push_back( PropertyInfo( Variant::COLOR, base+"disable_color", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
- p_list->push_back( PropertyInfo( Variant::BOOL, base+"exterior_portal", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) );
+ String base = "areas/" + itos(E->key()) + "/";
+ p_list->push_back(PropertyInfo(Variant::RECT3, base + "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
+ p_list->push_back(PropertyInfo(Variant::STRING, base + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
+ p_list->push_back(PropertyInfo(Variant::REAL, base + "disable_distance", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
+ p_list->push_back(PropertyInfo(Variant::COLOR, base + "disable_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "exterior_portal", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
}
}
-
-void GridMap::set_theme(const Ref<MeshLibrary>& p_theme) {
+void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) {
if (!theme.is_null())
theme->unregister_owner(this);
- theme=p_theme;
+ theme = p_theme;
if (!theme.is_null())
theme->register_owner(this);
@@ -220,35 +212,34 @@ void GridMap::set_theme(const Ref<MeshLibrary>& p_theme) {
_change_notify("theme");
}
-Ref<MeshLibrary> GridMap::get_theme() const{
+Ref<MeshLibrary> GridMap::get_theme() const {
return theme;
}
-void GridMap::set_cell_size(float p_size){
+void GridMap::set_cell_size(float p_size) {
- cell_size=p_size;
+ cell_size = p_size;
_recreate_octant_data();
-
}
-float GridMap::get_cell_size() const{
+float GridMap::get_cell_size() const {
return cell_size;
}
-void GridMap::set_octant_size(int p_size){
+void GridMap::set_octant_size(int p_size) {
- octant_size=p_size;
+ octant_size = p_size;
_recreate_octant_data();
}
-int GridMap::get_octant_size() const{
+int GridMap::get_octant_size() const {
return octant_size;
}
void GridMap::set_center_x(bool p_enable) {
- center_x=p_enable;
+ center_x = p_enable;
_recreate_octant_data();
}
@@ -258,7 +249,7 @@ bool GridMap::get_center_x() const {
void GridMap::set_center_y(bool p_enable) {
- center_y=p_enable;
+ center_y = p_enable;
_recreate_octant_data();
}
@@ -268,7 +259,7 @@ bool GridMap::get_center_y() const {
void GridMap::set_center_z(bool p_enable) {
- center_z=p_enable;
+ center_z = p_enable;
_recreate_octant_data();
}
@@ -276,56 +267,52 @@ bool GridMap::get_center_z() const {
return center_z;
}
+int GridMap::_find_area(const IndexKey &p_pos) const {
-int GridMap::_find_area(const IndexKey& p_pos) const {
-
- for(const Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
- //this should somehow be faster...
- const Area& a=*E->get();
- if ( p_pos.x>=a.from.x && p_pos.x<a.to.x &&
- p_pos.y>=a.from.y && p_pos.y<a.to.y &&
- p_pos.z>=a.from.z && p_pos.z<a.to.z ) {
+ for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
+ //this should somehow be faster...
+ const Area &a = *E->get();
+ if (p_pos.x >= a.from.x && p_pos.x < a.to.x &&
+ p_pos.y >= a.from.y && p_pos.y < a.to.y &&
+ p_pos.z >= a.from.z && p_pos.z < a.to.z) {
return E->key();
}
}
return 0;
}
-void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){
+void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
- ERR_FAIL_INDEX(ABS(p_x),1<<20);
- ERR_FAIL_INDEX(ABS(p_y),1<<20);
- ERR_FAIL_INDEX(ABS(p_z),1<<20);
+ ERR_FAIL_INDEX(ABS(p_x), 1 << 20);
+ ERR_FAIL_INDEX(ABS(p_y), 1 << 20);
+ ERR_FAIL_INDEX(ABS(p_z), 1 << 20);
IndexKey key;
- key.x=p_x;
- key.y=p_y;
- key.z=p_z;
+ key.x = p_x;
+ key.y = p_y;
+ key.z = p_z;
OctantKey ok;
- ok.x=p_x/octant_size;
- ok.y=p_y/octant_size;
- ok.z=p_z/octant_size;
+ ok.x = p_x / octant_size;
+ ok.y = p_y / octant_size;
+ ok.z = p_z / octant_size;
ok.area = _find_area(key);
-
if (cell_map.has(key)) {
- int prev_item=cell_map[key].item;
+ int prev_item = cell_map[key].item;
- OctantKey octantkey=ok;
+ OctantKey octantkey = ok;
ERR_FAIL_COND(!octant_map.has(octantkey));
- Octant& g = *octant_map[octantkey];
+ Octant &g = *octant_map[octantkey];
ERR_FAIL_COND(!g.items.has(prev_item));
ERR_FAIL_COND(!g.items[prev_item].cells.has(key));
-
g.items[prev_item].cells.erase(key);
- if (g.items[prev_item].cells.size()==0) {
+ if (g.items[prev_item].cells.size() == 0) {
VS::get_singleton()->free(g.items[prev_item].multimesh_instance);
g.items.erase(prev_item);
-
}
if (g.items.empty()) {
@@ -339,136 +326,129 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){
octant_map.erase(octantkey);
} else {
-
- g.dirty=true;
+ g.dirty = true;
}
cell_map.erase(key);
_queue_dirty_map();
}
- if (p_item<0)
+ if (p_item < 0)
return;
- OctantKey octantkey=ok;
+ OctantKey octantkey = ok;
//add later
if (!octant_map.has(octantkey)) {
-
- Octant *g = memnew( Octant );
- g->dirty=true;
+ 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());
+ PhysicsServer::get_singleton()->body_set_space(g->static_body, get_world()->get_space());
- SceneTree *st=SceneTree::get_singleton();
+ SceneTree *st = SceneTree::get_singleton();
if (st && st->is_debugging_collisions_hint()) {
- g->collision_debug=VisualServer::get_singleton()->mesh_create();
- g->collision_debug_instance=VisualServer::get_singleton()->instance_create();
- VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance,g->collision_debug);
+ g->collision_debug = VisualServer::get_singleton()->mesh_create();
+ g->collision_debug_instance = VisualServer::get_singleton()->instance_create();
+ VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
if (is_inside_world()) {
- VisualServer::get_singleton()->instance_set_scenario(g->collision_debug_instance,get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(g->collision_debug_instance,get_global_transform());
+ VisualServer::get_singleton()->instance_set_scenario(g->collision_debug_instance, get_world()->get_scenario());
+ VisualServer::get_singleton()->instance_set_transform(g->collision_debug_instance, get_global_transform());
}
-
}
- octant_map[octantkey]=g;
+ octant_map[octantkey] = g;
}
- Octant& g = *octant_map[octantkey];
+ Octant &g = *octant_map[octantkey];
if (!g.items.has(p_item)) {
Octant::ItemInstances ii;
if (theme.is_valid() && theme->has_item(p_item)) {
- ii.mesh=theme->get_item_mesh(p_item);
- ii.shape=theme->get_item_shape(p_item);
- ii.navmesh=theme->get_item_navmesh(p_item);
+ ii.mesh = theme->get_item_mesh(p_item);
+ ii.shape = theme->get_item_shape(p_item);
+ ii.navmesh = theme->get_item_navmesh(p_item);
}
- ii.multimesh = Ref<MultiMesh>( memnew( MultiMesh ) );
+ ii.multimesh = Ref<MultiMesh>(memnew(MultiMesh));
ii.multimesh->set_color_format(MultiMesh::COLOR_NONE);
ii.multimesh->set_transform_format(MultiMesh::TRANSFORM_3D);
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_set_base(ii.multimesh_instance, ii.multimesh->get_rid());
- g.items[p_item]=ii;
+ g.items[p_item] = ii;
}
Octant::ItemInstances &ii = g.items[p_item];
ii.cells.insert(key);
- g.dirty=true;
+ g.dirty = true;
_queue_dirty_map();
- cell_map[key]=Cell();
- Cell &c=cell_map[key];
- c.item=p_item;
- c.rot=p_rot;
-
+ cell_map[key] = Cell();
+ Cell &c = cell_map[key];
+ c.item = p_item;
+ c.rot = p_rot;
}
-int GridMap::get_cell_item(int p_x,int p_y,int p_z) const{
-
- ERR_FAIL_INDEX_V(ABS(p_x),1<<20,INVALID_CELL_ITEM);
- ERR_FAIL_INDEX_V(ABS(p_y),1<<20,INVALID_CELL_ITEM);
- ERR_FAIL_INDEX_V(ABS(p_z),1<<20,INVALID_CELL_ITEM);
+int GridMap::get_cell_item(int p_x, int p_y, int p_z) const {
+ ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, INVALID_CELL_ITEM);
+ ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, INVALID_CELL_ITEM);
+ ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, INVALID_CELL_ITEM);
IndexKey key;
- key.x=p_x;
- key.y=p_y;
- key.z=p_z;
+ key.x = p_x;
+ key.y = p_y;
+ key.z = p_z;
if (!cell_map.has(key))
return INVALID_CELL_ITEM;
return cell_map[key].item;
-
}
-int GridMap::get_cell_item_orientation(int p_x,int p_y,int p_z) const{
+int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const {
- ERR_FAIL_INDEX_V(ABS(p_x),1<<20,-1);
- ERR_FAIL_INDEX_V(ABS(p_y),1<<20,-1);
- ERR_FAIL_INDEX_V(ABS(p_z),1<<20,-1);
+ ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, -1);
+ ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, -1);
+ ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, -1);
IndexKey key;
- key.x=p_x;
- key.y=p_y;
- key.z=p_z;
+ key.x = p_x;
+ key.y = p_y;
+ key.z = p_z;
if (!cell_map.has(key))
return -1;
return cell_map[key].rot;
-
}
-void GridMap::_octant_enter_tree(const OctantKey &p_key){
+void GridMap::_octant_enter_tree(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
- if(navigation){
- Octant&g = *octant_map[p_key];
+ if (navigation) {
+ Octant &g = *octant_map[p_key];
- Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z));
+ Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z));
_octant_clear_navmesh(p_key);
- for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) {
- Octant::ItemInstances &ii=E->get();
+ for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
+ Octant::ItemInstances &ii = E->get();
- for(Set<IndexKey>::Element *F=ii.cells.front();F;F=F->next()) {
+ for (Set<IndexKey>::Element *F = ii.cells.front(); F; F = F->next()) {
- IndexKey ik=F->get();
- Map<IndexKey,Cell>::Element *C=cell_map.find(ik);
+ IndexKey ik = F->get();
+ Map<IndexKey, Cell>::Element *C = cell_map.find(ik);
ERR_CONTINUE(!C);
- Vector3 cellpos = Vector3(ik.x,ik.y,ik.z );
+ Vector3 cellpos = Vector3(ik.x, ik.y, ik.z);
Transform xform;
- if (clip && ( (clip_above && cellpos[clip_axis]>clip_floor) || (!clip_above && cellpos[clip_axis]<clip_floor))) {
+ if (clip && ((clip_above && cellpos[clip_axis] > clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) {
xform.basis.set_zero();
@@ -477,16 +457,15 @@ void GridMap::_octant_enter_tree(const OctantKey &p_key){
xform.basis.set_orthogonal_index(C->get().rot);
}
-
- xform.set_origin( cellpos*cell_size+ofs);
- xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale));
+ xform.set_origin(cellpos * cell_size + ofs);
+ xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
// add the item's navmesh at given xform to GridMap's Navigation ancestor
- if(ii.navmesh.is_valid()){
- int nm_id = navigation->navmesh_create(ii.navmesh,xform,this);
+ if (ii.navmesh.is_valid()) {
+ int nm_id = navigation->navmesh_create(ii.navmesh, xform, this);
Octant::NavMesh nm;
- nm.id=nm_id;
- nm.xform=xform;
- g.navmesh_ids[ik]=nm;
+ nm.id = nm_id;
+ nm.xform = xform;
+ g.navmesh_ids[ik] = nm;
}
}
}
@@ -496,56 +475,53 @@ void GridMap::_octant_enter_tree(const OctantKey &p_key){
void GridMap::_octant_enter_world(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
- Octant&g = *octant_map[p_key];
- PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
- PhysicsServer::get_singleton()->body_set_space(g.static_body,get_world()->get_space());
+ Octant &g = *octant_map[p_key];
+ PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
+ PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world()->get_space());
//print_line("BODYPOS: "+get_global_transform());
-
if (g.collision_debug_instance.is_valid()) {
- VS::get_singleton()->instance_set_scenario(g.collision_debug_instance,get_world()->get_scenario());
- VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform());
+ VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario());
+ VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
if (area_map.has(p_key.area)) {
- VS::get_singleton()->instance_set_room(g.collision_debug_instance,area_map[p_key.area]->instance);
+ VS::get_singleton()->instance_set_room(g.collision_debug_instance, area_map[p_key.area]->instance);
}
}
- for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) {
+ for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
- VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario());
- VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform());
+ VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, get_world()->get_scenario());
+ VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform());
//print_line("INSTANCEPOS: "+get_global_transform());
if (area_map.has(p_key.area)) {
- VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance);
+ VS::get_singleton()->instance_set_room(E->get().multimesh_instance, area_map[p_key.area]->instance);
}
}
}
-
void GridMap::_octant_transform(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
- Octant&g = *octant_map[p_key];
- PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
+ Octant &g = *octant_map[p_key];
+ PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
if (g.collision_debug_instance.is_valid()) {
- VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform());
+ VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
}
- for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) {
+ for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
- VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform());
+ VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform());
//print_line("UPDATEPOS: "+get_global_transform());
}
-
}
-void GridMap::_octant_clear_navmesh(const OctantKey &p_key){
- Octant&g = *octant_map[p_key];
+void GridMap::_octant_clear_navmesh(const OctantKey &p_key) {
+ Octant &g = *octant_map[p_key];
if (navigation) {
- for(Map<IndexKey,Octant::NavMesh>::Element *E=g.navmesh_ids.front();E;E=E->next()) {
+ for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) {
Octant::NavMesh *nvm = &E->get();
- if(nvm && nvm->id){
+ if (nvm && nvm->id) {
navigation->navmesh_remove(E->get().id);
}
}
@@ -555,7 +531,7 @@ void GridMap::_octant_clear_navmesh(const OctantKey &p_key){
void GridMap::_octant_update(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
- Octant&g = *octant_map[p_key];
+ Octant &g = *octant_map[p_key];
if (!g.dirty)
return;
@@ -576,31 +552,30 @@ void GridMap::_octant_update(const OctantKey &p_key) {
* set item's multimesh's instance count to number of cells which have this item
* and set said multimesh bounding box to one containing all cells which have this item
*/
- for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) {
+ for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
- Octant::ItemInstances &ii=E->get();
+ Octant::ItemInstances &ii = E->get();
ii.multimesh->set_instance_count(ii.cells.size());
Rect3 aabb;
- Rect3 mesh_aabb = ii.mesh.is_null()?Rect3():ii.mesh->get_aabb();
-
- Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z));
+ Rect3 mesh_aabb = ii.mesh.is_null() ? Rect3() : ii.mesh->get_aabb();
+ Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z));
//print_line("OCTANT, CELLS: "+itos(ii.cells.size()));
- int idx=0;
+ int idx = 0;
// foreach cell containing this item type
- for(Set<IndexKey>::Element *F=ii.cells.front();F;F=F->next()) {
- IndexKey ik=F->get();
- Map<IndexKey,Cell>::Element *C=cell_map.find(ik);
+ for (Set<IndexKey>::Element *F = ii.cells.front(); F; F = F->next()) {
+ IndexKey ik = F->get();
+ Map<IndexKey, Cell>::Element *C = cell_map.find(ik);
ERR_CONTINUE(!C);
- Vector3 cellpos = Vector3(ik.x,ik.y,ik.z );
+ Vector3 cellpos = Vector3(ik.x, ik.y, ik.z);
Transform xform;
- if (clip && ( (clip_above && cellpos[clip_axis]>clip_floor) || (!clip_above && cellpos[clip_axis]<clip_floor))) {
+ if (clip && ((clip_above && cellpos[clip_axis] > clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) {
xform.basis.set_zero();
@@ -609,19 +584,17 @@ void GridMap::_octant_update(const OctantKey &p_key) {
xform.basis.set_orthogonal_index(C->get().rot);
}
+ xform.set_origin(cellpos * cell_size + ofs);
+ xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
- xform.set_origin( cellpos*cell_size+ofs);
- xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale));
-
- ii.multimesh->set_instance_transform(idx,xform);
+ ii.multimesh->set_instance_transform(idx, xform);
//ii.multimesh->set_instance_transform(idx,Transform() );
//ii.multimesh->set_instance_color(idx,Color(1,1,1,1));
//print_line("MMINST: "+xform);
+ if (idx == 0) {
- if(idx==0) {
-
- aabb=xform.xform(mesh_aabb);
+ aabb = xform.xform(mesh_aabb);
} else {
aabb.merge_with(xform.xform(mesh_aabb));
@@ -630,22 +603,22 @@ void GridMap::_octant_update(const OctantKey &p_key) {
// add the item's shape at given xform to octant's static_body
if (ii.shape.is_valid()) {
// add the item's shape
- PhysicsServer::get_singleton()->body_add_shape(g.static_body,ii.shape->get_rid(),xform);
+ PhysicsServer::get_singleton()->body_add_shape(g.static_body, ii.shape->get_rid(), xform);
if (g.collision_debug.is_valid()) {
- ii.shape->add_vertices_to_array(col_debug,xform);
+ ii.shape->add_vertices_to_array(col_debug, xform);
}
//print_line("PHIS x: "+xform);
}
// add the item's navmesh at given xform to GridMap's Navigation ancestor
- if(navigation){
- if(ii.navmesh.is_valid()){
- int nm_id = navigation->navmesh_create(ii.navmesh,xform,this);
+ if (navigation) {
+ if (ii.navmesh.is_valid()) {
+ int nm_id = navigation->navmesh_create(ii.navmesh, xform, this);
Octant::NavMesh nm;
- nm.id=nm_id;
- nm.xform=xform;
- g.navmesh_ids[ik]=nm;
+ nm.id = nm_id;
+ nm.xform = xform;
+ g.navmesh_ids[ik] = nm;
}
}
@@ -653,95 +626,84 @@ void GridMap::_octant_update(const OctantKey &p_key) {
}
//ii.multimesh->set_aabb(aabb);
-
-
}
if (col_debug.size()) {
-
Array arr;
arr.resize(VS::ARRAY_MAX);
- arr[VS::ARRAY_VERTEX]=col_debug;
+ arr[VS::ARRAY_VERTEX] = col_debug;
- VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug,VS::PRIMITIVE_LINES,arr);
- SceneTree *st=SceneTree::get_singleton();
+ VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug, VS::PRIMITIVE_LINES, arr);
+ SceneTree *st = SceneTree::get_singleton();
if (st) {
- VS::get_singleton()->mesh_surface_set_material( g.collision_debug, 0,st->get_debug_collision_material()->get_rid() );
+ VS::get_singleton()->mesh_surface_set_material(g.collision_debug, 0, st->get_debug_collision_material()->get_rid());
}
}
- g.dirty=false;
-
+ g.dirty = false;
}
-
void GridMap::_octant_exit_world(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
- Octant&g = *octant_map[p_key];
- PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
- PhysicsServer::get_singleton()->body_set_space(g.static_body,RID());
-
+ Octant &g = *octant_map[p_key];
+ PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
+ PhysicsServer::get_singleton()->body_set_space(g.static_body, RID());
if (g.collision_debug_instance.is_valid()) {
- VS::get_singleton()->instance_set_room(g.collision_debug_instance,RID());
- VS::get_singleton()->instance_set_scenario(g.collision_debug_instance,RID());
+ VS::get_singleton()->instance_set_room(g.collision_debug_instance, RID());
+ VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID());
}
- for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) {
+ for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
- VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,RID());
+ VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, RID());
//VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform());
- VS::get_singleton()->instance_set_room(E->get().multimesh_instance,RID());
+ VS::get_singleton()->instance_set_room(E->get().multimesh_instance, RID());
}
-
}
-
void GridMap::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
_update_area_instances();
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
//IndexKey ik;
//ik.key = E->key().indexkey;
_octant_enter_world(E->key());
_octant_update(E->key());
}
- awaiting_update=false;
-
- last_transform=get_global_transform();
+ awaiting_update = false;
+ last_transform = get_global_transform();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform new_xform = get_global_transform();
- if (new_xform==last_transform)
+ if (new_xform == last_transform)
break;
//update run
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_transform(E->key());
}
- last_transform=new_xform;
+ last_transform = new_xform;
} break;
case NOTIFICATION_EXIT_WORLD: {
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_exit_world(E->key());
}
-
//_queue_dirty_map(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
//_update_dirty_map_callback();
//_update_area_instances();
@@ -749,41 +711,39 @@ void GridMap::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
- Spatial *c=this;
- while(c) {
- navigation=c->cast_to<Navigation>();
+ Spatial *c = this;
+ while (c) {
+ navigation = c->cast_to<Navigation>();
if (navigation) {
break;
}
- c=c->get_parent()->cast_to<Spatial>();
+ c = c->get_parent()->cast_to<Spatial>();
}
- if(navigation){
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ if (navigation) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
if (navigation) {
_octant_enter_tree(E->key());
}
}
}
- _queue_dirty_map();
+ _queue_dirty_map();
} break;
case NOTIFICATION_EXIT_TREE: {
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
if (navigation) {
_octant_clear_navmesh(E->key());
}
}
- navigation=NULL;
+ navigation = NULL;
} break;
}
}
-
-
void GridMap::_queue_dirty_map() {
if (awaiting_update)
@@ -791,34 +751,32 @@ void GridMap::_queue_dirty_map() {
if (is_inside_world()) {
- MessageQueue::get_singleton()->push_call(this,"_update_dirty_map_callback");
- awaiting_update=true;
+ MessageQueue::get_singleton()->push_call(this, "_update_dirty_map_callback");
+ awaiting_update = true;
}
}
void GridMap::_recreate_octant_data() {
- Map<IndexKey,Cell> cell_copy=cell_map;
+ Map<IndexKey, Cell> cell_copy = cell_map;
_clear_internal(true);
- for (Map<IndexKey,Cell>::Element *E=cell_copy.front();E;E=E->next()) {
+ for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) {
- set_cell_item(E->key().x,E->key().y,E->key().z,E->get().item,E->get().rot);
+ set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot);
}
-
}
void GridMap::_clear_internal(bool p_keep_areas) {
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
if (is_inside_world())
_octant_exit_world(E->key());
- for (Map<int,Octant::ItemInstances>::Element *F=E->get()->items.front();F;F=F->next()) {
+ for (Map<int, Octant::ItemInstances>::Element *F = E->get()->items.front(); F; F = F->next()) {
VS::get_singleton()->free(F->get().multimesh_instance);
}
-
if (E->get()->collision_debug.is_valid())
VS::get_singleton()->free(E->get()->collision_debug);
if (E->get()->collision_debug_instance.is_valid())
@@ -826,7 +784,6 @@ void GridMap::_clear_internal(bool p_keep_areas) {
PhysicsServer::get_singleton()->free(E->get()->static_body);
memdelete(E->get());
-
}
octant_map.clear();
@@ -835,253 +792,231 @@ void GridMap::_clear_internal(bool p_keep_areas) {
if (p_keep_areas)
return;
- for (Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
-
+ for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
VS::get_singleton()->free(E->get()->base_portal);
VS::get_singleton()->free(E->get()->instance);
- for(int i=0;i<E->get()->portals.size();i++) {
+ for (int i = 0; i < E->get()->portals.size(); i++) {
VS::get_singleton()->free(E->get()->portals[i].instance);
}
memdelete(E->get());
}
-
}
void GridMap::clear() {
_clear_internal();
-
}
-void GridMap::resource_changed(const RES& p_res) {
+void GridMap::resource_changed(const RES &p_res) {
_recreate_octant_data();
}
-
void GridMap::_update_dirty_map_callback() {
if (!awaiting_update)
return;
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_update(E->key());
}
-
- awaiting_update=false;
-
+ awaiting_update = false;
}
-
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:MeshLibrary"), &GridMap::set_theme);
+ ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"), &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);
+ 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);
- ClassDB::bind_method(D_METHOD("set_octant_size","size"),&GridMap::set_octant_size);
- ClassDB::bind_method(D_METHOD("get_octant_size"),&GridMap::get_octant_size);
+ ClassDB::bind_method(D_METHOD("set_octant_size", "size"), &GridMap::set_octant_size);
+ ClassDB::bind_method(D_METHOD("get_octant_size"), &GridMap::get_octant_size);
- ClassDB::bind_method(D_METHOD("set_cell_item","x","y","z","item","orientation"),&GridMap::set_cell_item,DEFVAL(0));
- ClassDB::bind_method(D_METHOD("get_cell_item","x","y","z"),&GridMap::get_cell_item);
- ClassDB::bind_method(D_METHOD("get_cell_item_orientation","x","y","z"),&GridMap::get_cell_item_orientation);
+ ClassDB::bind_method(D_METHOD("set_cell_item", "x", "y", "z", "item", "orientation"), &GridMap::set_cell_item, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_cell_item", "x", "y", "z"), &GridMap::get_cell_item);
+ ClassDB::bind_method(D_METHOD("get_cell_item_orientation", "x", "y", "z"), &GridMap::get_cell_item_orientation);
//ClassDB::bind_method(D_METHOD("_recreate_octants"),&GridMap::_recreate_octants);
- ClassDB::bind_method(D_METHOD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback);
- ClassDB::bind_method(D_METHOD("resource_changed","resource"),&GridMap::resource_changed);
-
- ClassDB::bind_method(D_METHOD("set_center_x","enable"),&GridMap::set_center_x);
- ClassDB::bind_method(D_METHOD("get_center_x"),&GridMap::get_center_x);
- ClassDB::bind_method(D_METHOD("set_center_y","enable"),&GridMap::set_center_y);
- ClassDB::bind_method(D_METHOD("get_center_y"),&GridMap::get_center_y);
- ClassDB::bind_method(D_METHOD("set_center_z","enable"),&GridMap::set_center_z);
- ClassDB::bind_method(D_METHOD("get_center_z"),&GridMap::get_center_z);
-
- 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_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);
- ClassDB::bind_method(D_METHOD("area_is_exterior_portal","area"),&GridMap::area_is_exterior_portal);
- ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance","area","distance"),&GridMap::area_set_portal_disable_distance);
- ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance","area"),&GridMap::area_get_portal_disable_distance);
- 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("clear"),&GridMap::clear);
-
- ClassDB::bind_method(D_METHOD("get_meshes"),&GridMap::get_meshes);
-
- BIND_CONSTANT( INVALID_CELL_ITEM );
-
+ ClassDB::bind_method(D_METHOD("_update_dirty_map_callback"), &GridMap::_update_dirty_map_callback);
+ ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &GridMap::resource_changed);
+
+ ClassDB::bind_method(D_METHOD("set_center_x", "enable"), &GridMap::set_center_x);
+ ClassDB::bind_method(D_METHOD("get_center_x"), &GridMap::get_center_x);
+ ClassDB::bind_method(D_METHOD("set_center_y", "enable"), &GridMap::set_center_y);
+ ClassDB::bind_method(D_METHOD("get_center_y"), &GridMap::get_center_y);
+ ClassDB::bind_method(D_METHOD("set_center_z", "enable"), &GridMap::set_center_z);
+ ClassDB::bind_method(D_METHOD("get_center_z"), &GridMap::get_center_z);
+
+ 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_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);
+ ClassDB::bind_method(D_METHOD("area_is_exterior_portal", "area"), &GridMap::area_is_exterior_portal);
+ ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance", "area", "distance"), &GridMap::area_set_portal_disable_distance);
+ ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance", "area"), &GridMap::area_get_portal_disable_distance);
+ 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("clear"), &GridMap::clear);
+
+ ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes);
+
+ BIND_CONSTANT(INVALID_CELL_ITEM);
}
void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::Axis p_axis) {
if (!p_enabled && !clip)
return;
- if (clip && p_enabled && clip_floor==p_floor && p_clip_above==clip_above && p_axis==clip_axis)
+ if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis)
return;
- clip=p_enabled;
- clip_floor=p_floor;
- clip_axis=p_axis;
- clip_above=p_clip_above;
+ clip = p_enabled;
+ clip_floor = p_floor;
+ clip_axis = p_axis;
+ clip_above = p_clip_above;
//make it all update
- for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) {
-
- Octant *g=E->get();
- g->dirty=true;
+ for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
+ Octant *g = E->get();
+ g->dirty = true;
}
- awaiting_update=true;
+ awaiting_update = true;
_update_dirty_map_callback();
}
-
void GridMap::_update_areas() {
//clear the portals
- for(Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
+ for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
//this should somehow be faster...
- Area& a=*E->get();
+ Area &a = *E->get();
a.portals.clear();
if (a.instance.is_valid()) {
VisualServer::get_singleton()->free(a.instance);
- a.instance=RID();
+ a.instance = RID();
}
}
//test all areas against all areas and create portals - this sucks (slow :( )
- for(Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
- Area& a=*E->get();
+ for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
+ Area &a = *E->get();
if (a.exterior_portal) //that's pretty much all it does... yes it is
continue;
- Vector3 from_a(a.from.x,a.from.y,a.from.z);
- Vector3 to_a(a.to.x,a.to.y,a.to.z);
+ Vector3 from_a(a.from.x, a.from.y, a.from.z);
+ Vector3 to_a(a.to.x, a.to.y, a.to.z);
- for(Map<int,Area*>::Element *F=area_map.front();F;F=F->next()) {
+ for (Map<int, Area *>::Element *F = area_map.front(); F; F = F->next()) {
- Area& b=*F->get();
- Vector3 from_b(b.from.x,b.from.y,b.from.z);
- Vector3 to_b(b.to.x,b.to.y,b.to.z);
+ Area &b = *F->get();
+ Vector3 from_b(b.from.x, b.from.y, b.from.z);
+ Vector3 to_b(b.to.x, b.to.y, b.to.z);
// initially test intersection and discards
- int axis=-1;
- float sign=0;
- bool valid=true;
- Vector3 axmin,axmax;
-
+ int axis = -1;
+ float sign = 0;
+ bool valid = true;
+ Vector3 axmin, axmax;
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
- if (from_a[i]==to_b[i]) {
+ if (from_a[i] == to_b[i]) {
- if (axis!=-1) {
- valid=false;
+ if (axis != -1) {
+ valid = false;
break;
}
- axis=i;
- sign=-1;
- } else if (from_b[i]==to_a[i]) {
+ axis = i;
+ sign = -1;
+ } else if (from_b[i] == to_a[i]) {
- if (axis!=-1) {
- valid=false;
+ if (axis != -1) {
+ valid = false;
break;
}
- axis=i;
- sign=+1;
+ axis = i;
+ sign = +1;
}
-
- if (from_a[i] > to_b[i] || to_a[i] < from_b[i] ) {
- valid=false;
+ if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) {
+ valid = false;
break;
} else {
- axmin[i]= ( from_a[i] > from_b[i] ) ? from_a[i] :from_b[i];
- axmax[i]= ( to_a[i] < to_b[i] ) ? to_a[i] :to_b[i];
-
+ axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i];
+ axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i];
}
-
-
}
- if (axis==-1 || !valid)
+ if (axis == -1 || !valid)
continue;
Transform xf;
+ for (int i = 0; i < 3; i++) {
- for(int i=0;i<3;i++) {
-
-
-
- int ax=(axis+i)%3;
+ int ax = (axis + i) % 3;
Vector3 axis_vec;
- float scale = (i==0)?sign:((axmax[ax]-axmin[ax])*cell_size);
- axis_vec[ax]=scale;
- xf.basis.set_axis((2+i)%3,axis_vec);
- xf.origin[i]=axmin[i]*cell_size;
-
+ float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size);
+ axis_vec[ax] = scale;
+ xf.basis.set_axis((2 + i) % 3, axis_vec);
+ xf.origin[i] = axmin[i] * cell_size;
}
-
-
Area::Portal portal;
- portal.xform=xf;
+ portal.xform = xf;
a.portals.push_back(portal);
}
}
_update_area_instances();
-
}
void GridMap::_update_area_instances() {
Transform base_xform;
if (_in_tree)
- base_xform=get_global_transform();
+ base_xform = get_global_transform();
- for(Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
+ for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
//this should somehow be faster...
- Area& a=*E->get();
- if (a.instance.is_valid()!=_in_tree) {
+ Area &a = *E->get();
+ if (a.instance.is_valid() != _in_tree) {
if (!_in_tree) {
- for(int i=0;i<a.portals.size();i++) {
+ for (int i = 0; i < a.portals.size(); i++) {
- Area::Portal&p=a.portals[i];
+ Area::Portal &p = a.portals[i];
ERR_CONTINUE(!p.instance.is_valid());
VisualServer::get_singleton()->free(p.instance);
- p.instance=RID();
+ p.instance = RID();
}
VisualServer::get_singleton()->free(a.instance);
- a.instance=RID();
+ a.instance = RID();
} else {
//a.instance = VisualServer::get_singleton()->instance_create2(base_room,get_world()->get_scenario());
- for(int i=0;i<a.portals.size();i++) {
+ for (int i = 0; i < a.portals.size(); i++) {
- Area::Portal&p=a.portals[i];
+ Area::Portal &p = a.portals[i];
ERR_CONTINUE(p.instance.is_valid());
- p.instance=VisualServer::get_singleton()->instance_create2(a.base_portal,get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_room(p.instance,a.instance);
+ p.instance = VisualServer::get_singleton()->instance_create2(a.base_portal, get_world()->get_scenario());
+ VisualServer::get_singleton()->instance_set_room(p.instance, a.instance);
}
}
}
@@ -1089,62 +1024,57 @@ void GridMap::_update_area_instances() {
if (a.instance.is_valid()) {
Transform xform;
- Vector3 from_a(a.from.x,a.from.y,a.from.z);
- Vector3 to_a(a.to.x,a.to.y,a.to.z);
+ Vector3 from_a(a.from.x, a.from.y, a.from.z);
+ Vector3 to_a(a.to.x, a.to.y, a.to.z);
- for(int i=0;i<3;i++) {
- xform.origin[i]=from_a[i]*cell_size;
+ for (int i = 0; i < 3; i++) {
+ xform.origin[i] = from_a[i] * cell_size;
Vector3 s;
- s[i]=(to_a[i]-from_a[i])*cell_size;
- xform.basis.set_axis(i,s);
+ s[i] = (to_a[i] - from_a[i]) * cell_size;
+ xform.basis.set_axis(i, s);
}
+ VisualServer::get_singleton()->instance_set_transform(a.instance, base_xform * xform);
- VisualServer::get_singleton()->instance_set_transform(a.instance,base_xform * xform);
-
- for(int i=0;i<a.portals.size();i++) {
+ for (int i = 0; i < a.portals.size(); i++) {
- Area::Portal&p=a.portals[i];
+ Area::Portal &p = a.portals[i];
ERR_CONTINUE(!p.instance.is_valid());
- VisualServer::get_singleton()->instance_set_transform(p.instance,base_xform * xform);
-
+ VisualServer::get_singleton()->instance_set_transform(p.instance, base_xform * xform);
}
-
}
}
-
}
-Error GridMap::create_area(int p_id,const Rect3& p_bounds) {
+Error GridMap::create_area(int p_id, const Rect3 &p_bounds) {
- ERR_FAIL_COND_V(area_map.has(p_id),ERR_ALREADY_EXISTS);
+ 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_id == 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(p_bounds.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;
-
-
- for(Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
+ 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;
+
+ for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
//this should somehow be faster...
- Area& a=*E->get();
+ Area &a = *E->get();
//does it interset with anything else?
- if ( from.x >= a.to.x ||
- to.x <= a.from.x ||
- from.y >= a.to.y ||
- to.y <= a.from.y ||
- from.z >= a.to.z ||
- to.z <= a.from.z ) {
+ if (from.x >= a.to.x ||
+ to.x <= a.from.x ||
+ from.y >= a.to.y ||
+ to.y <= a.from.y ||
+ from.z >= a.to.z ||
+ to.z <= a.from.z) {
// all good
} else {
@@ -1153,62 +1083,60 @@ Error GridMap::create_area(int p_id,const Rect3& p_bounds) {
}
}
-
- Area *area = memnew( Area );
- area->from=from;
- area->to=to;
- area->portal_disable_distance=0;
- area->exterior_portal=false;
- area->name="Area "+itos(p_id);
- area_map[p_id]=area;
+ Area *area = memnew(Area);
+ area->from = from;
+ area->to = to;
+ area->portal_disable_distance = 0;
+ area->exterior_portal = false;
+ area->name = "Area " + itos(p_id);
+ area_map[p_id] = area;
_recreate_octant_data();
return OK;
}
Rect3 GridMap::area_get_bounds(int p_area) const {
- ERR_FAIL_COND_V(!area_map.has(p_area),Rect3());
+ ERR_FAIL_COND_V(!area_map.has(p_area), Rect3());
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.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;
return aabb;
}
-void GridMap::area_set_name(int p_area,const String& p_name) {
+void GridMap::area_set_name(int p_area, const String &p_name) {
ERR_FAIL_COND(!area_map.has(p_area));
Area *a = area_map[p_area];
- a->name=p_name;
+ a->name = p_name;
}
String GridMap::area_get_name(int p_area) const {
- ERR_FAIL_COND_V(!area_map.has(p_area),"");
+ ERR_FAIL_COND_V(!area_map.has(p_area), "");
const Area *a = area_map[p_area];
return a->name;
}
-
-void GridMap::area_set_exterior_portal(int p_area,bool p_enable) {
+void GridMap::area_set_exterior_portal(int p_area, bool p_enable) {
ERR_FAIL_COND(!area_map.has(p_area));
Area *a = area_map[p_area];
- if (a->exterior_portal==p_enable)
+ if (a->exterior_portal == p_enable)
return;
- a->exterior_portal=p_enable;
+ a->exterior_portal = p_enable;
_recreate_octant_data();
}
bool GridMap::area_is_exterior_portal(int p_area) const {
- ERR_FAIL_COND_V(!area_map.has(p_area),false);
+ ERR_FAIL_COND_V(!area_map.has(p_area), false);
const Area *a = area_map[p_area];
return a->exterior_portal;
@@ -1219,13 +1147,12 @@ void GridMap::area_set_portal_disable_distance(int p_area, float p_distance) {
ERR_FAIL_COND(!area_map.has(p_area));
Area *a = area_map[p_area];
- a->portal_disable_distance=p_distance;
-
+ a->portal_disable_distance = p_distance;
}
float GridMap::area_get_portal_disable_distance(int p_area) const {
- ERR_FAIL_COND_V(!area_map.has(p_area),0);
+ ERR_FAIL_COND_V(!area_map.has(p_area), 0);
const Area *a = area_map[p_area];
return a->portal_disable_distance;
@@ -1236,13 +1163,12 @@ void GridMap::area_set_portal_disable_color(int p_area, Color p_color) {
ERR_FAIL_COND(!area_map.has(p_area));
Area *a = area_map[p_area];
- a->portal_disable_color=p_color;
-
+ a->portal_disable_color = p_color;
}
Color GridMap::area_get_portal_disable_color(int p_area) const {
- ERR_FAIL_COND_V(!area_map.has(p_area),Color());
+ ERR_FAIL_COND_V(!area_map.has(p_area), Color());
const Area *a = area_map[p_area];
return a->portal_disable_color;
@@ -1250,34 +1176,29 @@ Color GridMap::area_get_portal_disable_color(int p_area) const {
void GridMap::get_area_list(List<int> *p_areas) const {
- for(const Map<int,Area*>::Element *E=area_map.front();E;E=E->next()) {
+ for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
p_areas->push_back(E->key());
}
-
}
-
GridMap::Area::Portal::~Portal() {
if (instance.is_valid())
VisualServer::get_singleton()->free(instance);
}
-
GridMap::Area::Area() {
- base_portal=VisualServer::get_singleton()->portal_create();
- Vector< Point2 > points;
- points.push_back( Point2( 0, 1 ) );
- points.push_back( Point2( 1, 1 ) );
- points.push_back( Point2( 1, 0 ) );
- points.push_back( Point2( 0, 0 ) );
- VisualServer::get_singleton()->portal_set_shape(base_portal,points);
-
+ base_portal = VisualServer::get_singleton()->portal_create();
+ Vector<Point2> points;
+ points.push_back(Point2(0, 1));
+ points.push_back(Point2(1, 1));
+ points.push_back(Point2(1, 0));
+ points.push_back(Point2(0, 0));
+ VisualServer::get_singleton()->portal_set_shape(base_portal, points);
}
-
GridMap::Area::~Area() {
if (instance.is_valid())
@@ -1289,7 +1210,7 @@ void GridMap::erase_area(int p_area) {
ERR_FAIL_COND(!area_map.has(p_area));
- Area* a=area_map[p_area];
+ Area *a = area_map[p_area];
memdelete(a);
area_map.erase(p_area);
_recreate_octant_data();
@@ -1300,92 +1221,79 @@ int GridMap::get_unused_area_id() const {
if (area_map.empty())
return 1;
else
- return area_map.back()->key()+1;
+ return area_map.back()->key() + 1;
}
void GridMap::set_cell_scale(float p_scale) {
- cell_scale=p_scale;
+ cell_scale = p_scale;
_queue_dirty_map();
}
-float GridMap::get_cell_scale() const{
+float GridMap::get_cell_scale() const {
return cell_scale;
}
-
-
-
Array GridMap::get_meshes() {
if (theme.is_null())
return Array();
- Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z));
+ Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z));
Array meshes;
- for (Map<IndexKey,Cell>::Element *E=cell_map.front();E;E=E->next()) {
-
+ for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) {
int id = E->get().item;
if (!theme->has_item(id))
continue;
- Ref<Mesh> mesh=theme->get_item_mesh(id);
+ Ref<Mesh> mesh = theme->get_item_mesh(id);
if (mesh.is_null())
continue;
- IndexKey ik=E->key();
+ IndexKey ik = E->key();
- Vector3 cellpos = Vector3(ik.x,ik.y,ik.z );
+ Vector3 cellpos = Vector3(ik.x, ik.y, ik.z);
Transform xform;
xform.basis.set_orthogonal_index(E->get().rot);
-
- xform.set_origin( cellpos*cell_size+ofs);
- xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale));
+ xform.set_origin(cellpos * cell_size + ofs);
+ xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
meshes.push_back(xform);
meshes.push_back(mesh);
-
}
return meshes;
}
-
-
-
GridMap::GridMap() {
- cell_size=2;
- octant_size=4;
- awaiting_update=false;
- _in_tree=false;
- center_x=true;
- center_y=true;
- center_z=true;
-
- clip=false;
- clip_floor=0;
- clip_axis=Vector3::AXIS_Z;
- clip_above=true;
- cell_scale=1.0;
+ cell_size = 2;
+ octant_size = 4;
+ awaiting_update = false;
+ _in_tree = false;
+ center_x = true;
+ center_y = true;
+ center_z = true;
+ clip = false;
+ clip_floor = 0;
+ clip_axis = Vector3::AXIS_Z;
+ clip_above = true;
+ cell_scale = 1.0;
navigation = NULL;
set_notify_transform(true);
}
-
GridMap::~GridMap() {
if (!theme.is_null())
theme->unregister_owner(this);
clear();
-
}
-
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index 5d4133383b..2a0c2b9646 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -29,26 +29,23 @@
#ifndef GRID_MAP_H
#define GRID_MAP_H
-
-#include "scene/resources/mesh_library.h"
-#include "scene/3d/spatial.h"
#include "scene/3d/navigation.h"
+#include "scene/3d/spatial.h"
+#include "scene/resources/mesh_library.h"
#include "scene/resources/multimesh.h"
//heh heh, godotsphir!! this shares no code and the design is completely different with previous projects i've done..
//should scale better with hardware that supports instancing
-
class BakedLightInstance;
class GridMap : public Spatial {
-
- GDCLASS( GridMap, Spatial );
+ GDCLASS(GridMap, Spatial);
enum {
- MAP_DIRTY_TRANSFORMS=1,
- MAP_DIRTY_INSTANCES=2,
+ MAP_DIRTY_TRANSFORMS = 1,
+ MAP_DIRTY_INSTANCES = 2,
};
union IndexKey {
@@ -60,12 +57,12 @@ class GridMap : public Spatial {
};
uint64_t key;
- _FORCE_INLINE_ bool operator<(const IndexKey& p_key) const {
+ _FORCE_INLINE_ bool operator<(const IndexKey &p_key) const {
return key < p_key.key;
}
- IndexKey() { key=0; }
+ IndexKey() { key = 0; }
};
/**
@@ -75,12 +72,16 @@ class GridMap : public Spatial {
struct {
unsigned int item : 16;
- unsigned int rot:5;
- unsigned int layer:8;
+ unsigned int rot : 5;
+ unsigned int layer : 8;
};
uint32_t cell;
- Cell() { item=0; rot=0; layer=0; }
+ Cell() {
+ item = 0;
+ rot = 0;
+ layer = 0;
+ }
};
/**
@@ -108,8 +109,8 @@ class GridMap : public Spatial {
bool dirty;
RID static_body;
- Map<int,ItemInstances> items;
- Map<IndexKey,NavMesh> navmesh_ids;
+ Map<int, ItemInstances> items;
+ Map<IndexKey, NavMesh> navmesh_ids;
};
union OctantKey {
@@ -123,13 +124,13 @@ class GridMap : public Spatial {
uint64_t key;
- _FORCE_INLINE_ bool operator<(const OctantKey& p_key) const {
+ _FORCE_INLINE_ bool operator<(const OctantKey &p_key) const {
return key < p_key.key;
}
//OctantKey(const IndexKey& p_k, int p_item) { indexkey=p_k.key; item=p_item; }
- OctantKey() { key=0; }
+ OctantKey() { key = 0; }
};
Transform last_transform;
@@ -137,7 +138,7 @@ class GridMap : public Spatial {
bool _in_tree;
float cell_size;
int octant_size;
- bool center_x,center_y,center_z;
+ bool center_x, center_y, center_z;
float cell_scale;
Navigation *navigation;
@@ -146,7 +147,6 @@ class GridMap : public Spatial {
int clip_floor;
Vector3::Axis clip_axis;
-
/**
* @brief An Area is something like a room: it has doors, and Octants can choose to belong to it.
*/
@@ -173,11 +173,9 @@ class GridMap : public Spatial {
Ref<MeshLibrary> theme;
- Map<OctantKey,Octant*> octant_map;
- Map<IndexKey,Cell> cell_map;
- Map<int,Area*> area_map;
-
-
+ Map<OctantKey, Octant *> octant_map;
+ Map<IndexKey, Cell> cell_map;
+ Map<int, Area *> area_map;
void _recreate_octant_data();
@@ -189,11 +187,11 @@ class GridMap : public Spatial {
float param[VS::LIGHT_PARAM_MAX];
};
- _FORCE_INLINE_ int _find_area(const IndexKey& p_pos) const;
+ _FORCE_INLINE_ int _find_area(const IndexKey &p_pos) const;
_FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const {
- return Vector3(p_key.x,p_key.y,p_key.z)*cell_size*octant_size;
+ return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size;
}
void _octant_enter_world(const OctantKey &p_key);
@@ -201,37 +199,33 @@ class GridMap : public Spatial {
void _octant_exit_world(const OctantKey &p_key);
void _octant_update(const OctantKey &p_key);
void _octant_transform(const OctantKey &p_key);
- void _octant_clear_navmesh(const GridMap::OctantKey&);
+ void _octant_clear_navmesh(const GridMap::OctantKey &);
bool awaiting_update;
void _queue_dirty_map();
void _update_dirty_map_callback();
- void resource_changed(const RES& p_res);
-
+ void resource_changed(const RES &p_res);
void _update_areas();
void _update_area_instances();
- void _clear_internal(bool p_keep_areas=false);
+ void _clear_internal(bool p_keep_areas = false);
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;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
-
public:
-
enum {
- INVALID_CELL_ITEM=-1
+ INVALID_CELL_ITEM = -1
};
- void set_theme(const Ref<MeshLibrary>& p_theme);
+ void set_theme(const Ref<MeshLibrary> &p_theme);
Ref<MeshLibrary> get_theme() const;
void set_cell_size(float p_size);
@@ -240,7 +234,6 @@ public:
void set_octant_size(int p_size);
int get_octant_size() const;
-
void set_center_x(bool p_enable);
bool get_center_x() const;
void set_center_y(bool p_enable);
@@ -248,16 +241,16 @@ 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);
- 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;
+ void set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_orientation = 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;
- void set_clip(bool p_enabled, bool p_clip_above=true, int p_floor=0, Vector3::Axis p_axis=Vector3::AXIS_X);
+ void set_clip(bool p_enabled, bool p_clip_above = true, int p_floor = 0, Vector3::Axis p_axis = Vector3::AXIS_X);
- Error create_area(int p_id,const Rect3& p_area);
+ Error create_area(int p_id, const Rect3 &p_area);
Rect3 area_get_bounds(int p_area) const;
- void area_set_exterior_portal(int p_area,bool p_enable);
- void area_set_name(int p_area,const String& p_name);
+ void area_set_exterior_portal(int p_area, bool p_enable);
+ void area_set_name(int p_area, const String &p_name);
String area_get_name(int p_area) const;
bool area_is_exterior_portal(int p_area) const;
void area_set_portal_disable_distance(int p_area, float p_distance);
@@ -271,11 +264,8 @@ public:
void set_cell_scale(float p_scale);
float get_cell_scale() const;
-
-
Array get_meshes();
-
void clear();
GridMap();
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index a5d2f84c68..a6a3a03503 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -27,59 +27,53 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "grid_map_editor_plugin.h"
+#include "editor/editor_settings.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "scene/3d/camera.h"
-#include "editor/editor_settings.h"
-#include "os/keyboard.h"
#include "geometry.h"
+#include "os/keyboard.h"
void GridMapEditor::_node_removed(Node *p_node) {
- if(p_node==node) {
- node=NULL;
+ if (p_node == node) {
+ node = NULL;
hide();
theme_pallete->hide();
}
-
}
-
void GridMapEditor::_configure() {
- if(!node)
+ if (!node)
return;
update_grid();
-
}
-void GridMapEditor::_menu_option(int p_option) {
+void GridMapEditor::_menu_option(int p_option) {
-
- switch(p_option) {
+ switch (p_option) {
case MENU_OPTION_CONFIGURE: {
-
} break;
case MENU_OPTION_LOCK_VIEW: {
- int index=options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW);
- lock_view=!options->get_popup()->is_item_checked(index);
+ int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW);
+ lock_view = !options->get_popup()->is_item_checked(index);
- options->get_popup()->set_item_checked(index,lock_view);
+ options->get_popup()->set_item_checked(index, lock_view);
} break;
case MENU_OPTION_CLIP_DISABLED:
case MENU_OPTION_CLIP_ABOVE:
case MENU_OPTION_CLIP_BELOW: {
- clip_mode=ClipMode(p_option-MENU_OPTION_CLIP_DISABLED);
- for(int i=0;i<3;i++) {
-
- int index=options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED+i);
- options->get_popup()->set_item_checked(index,i==clip_mode);
+ clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED);
+ for (int i = 0; i < 3; i++) {
+ int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i);
+ options->get_popup()->set_item_checked(index, i == clip_mode);
}
_update_clip();
@@ -88,102 +82,100 @@ void GridMapEditor::_menu_option(int p_option) {
case MENU_OPTION_Y_AXIS:
case MENU_OPTION_Z_AXIS: {
- int new_axis = p_option-MENU_OPTION_X_AXIS;
- for(int i=0;i<3;i++) {
- int idx=options->get_popup()->get_item_index(MENU_OPTION_X_AXIS+i);
- options->get_popup()->set_item_checked(idx,i==new_axis);
+ int new_axis = p_option - MENU_OPTION_X_AXIS;
+ for (int i = 0; i < 3; i++) {
+ int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i);
+ options->get_popup()->set_item_checked(idx, i == new_axis);
}
- edit_axis=Vector3::Axis(new_axis);
+ edit_axis = Vector3::Axis(new_axis);
update_grid();
_update_clip();
} break;
case MENU_OPTION_CURSOR_ROTATE_Y: {
Basis r;
- if (input_action==INPUT_DUPLICATE) {
+ if (input_action == INPUT_DUPLICATE) {
r.set_orthogonal_index(selection.duplicate_rot);
- r.rotate(Vector3(0,1,0),-Math_PI/2.0);
- selection.duplicate_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
+ selection.duplicate_rot = r.get_orthogonal_index();
_update_duplicate_indicator();
break;
}
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(0,1,0),-Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_ROTATE_X: {
Basis r;
- if (input_action==INPUT_DUPLICATE) {
+ if (input_action == INPUT_DUPLICATE) {
r.set_orthogonal_index(selection.duplicate_rot);
- r.rotate(Vector3(1,0,0),-Math_PI/2.0);
- selection.duplicate_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
+ selection.duplicate_rot = r.get_orthogonal_index();
_update_duplicate_indicator();
break;
}
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(1,0,0),-Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_ROTATE_Z: {
Basis r;
- if (input_action==INPUT_DUPLICATE) {
+ if (input_action == INPUT_DUPLICATE) {
r.set_orthogonal_index(selection.duplicate_rot);
- r.rotate(Vector3(0,0,1),-Math_PI/2.0);
- selection.duplicate_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
+ selection.duplicate_rot = r.get_orthogonal_index();
_update_duplicate_indicator();
break;
}
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(0,0,1),-Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
Basis r;
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(0,1,0),Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
Basis r;
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(1,0,0),Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
Basis r;
r.set_orthogonal_index(cursor_rot);
- r.rotate(Vector3(0,0,1),Math_PI/2.0);
- cursor_rot=r.get_orthogonal_index();
+ r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
+ cursor_rot = r.get_orthogonal_index();
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_CLEAR_ROTATION: {
- if (input_action==INPUT_DUPLICATE) {
-
+ if (input_action == INPUT_DUPLICATE) {
- selection.duplicate_rot=0;
+ selection.duplicate_rot = 0;
_update_duplicate_indicator();
break;
}
- cursor_rot=0;
+ cursor_rot = 0;
_update_cursor_transform();
} break;
-
case MENU_OPTION_DUPLICATE_SELECTS: {
int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS);
- options->get_popup()->set_item_checked( idx, !options->get_popup()->is_item_checked( idx ) );
+ options->get_popup()->set_item_checked(idx, !options->get_popup()->is_item_checked(idx));
} break;
case MENU_OPTION_SELECTION_MAKE_AREA:
case MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR: {
@@ -191,37 +183,34 @@ void GridMapEditor::_menu_option(int p_option) {
if (!selection.active)
break;
int area = node->get_unused_area_id();
- Error err = node->create_area(area,Rect3(selection.begin,selection.end-selection.begin+Vector3(1,1,1)));
- if (err!=OK) {
-
-
+ Error err = node->create_area(area, Rect3(selection.begin, selection.end - selection.begin + Vector3(1, 1, 1)));
+ if (err != OK) {
}
- if (p_option==MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) {
+ if (p_option == MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) {
- node->area_set_exterior_portal(area,true);
+ node->area_set_exterior_portal(area, true);
}
_update_areas_display();
update_areas();
-
} break;
case MENU_OPTION_REMOVE_AREA: {
- if (selected_area<1)
+ if (selected_area < 1)
return;
node->erase_area(selected_area);
_update_areas_display();
update_areas();
} break;
case MENU_OPTION_SELECTION_DUPLICATE:
- if (!(selection.active && input_action==INPUT_NONE))
+ if (!(selection.active && input_action == INPUT_NONE))
return;
- if (last_mouseover==Vector3(-1,-1,-1)) //nono mouseovering anythin
+ if (last_mouseover == Vector3(-1, -1, -1)) //nono mouseovering anythin
break;
- input_action=INPUT_DUPLICATE;
- selection.click=last_mouseover;
- selection.current=last_mouseover;
- selection.duplicate_rot=0;
+ input_action = INPUT_DUPLICATE;
+ selection.click = last_mouseover;
+ selection.current = last_mouseover;
+ selection.duplicate_rot = 0;
_update_duplicate_indicator();
break;
case MENU_OPTION_SELECTION_CLEAR: {
@@ -230,28 +219,24 @@ void GridMapEditor::_menu_option(int p_option) {
_delete_selection();
-
} break;
case MENU_OPTION_GRIDMAP_SETTINGS: {
settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50));
} break;
-
}
}
void GridMapEditor::_update_cursor_transform() {
- cursor_transform=Transform();
- cursor_transform.origin=cursor_origin;
+ cursor_transform = Transform();
+ cursor_transform.origin = cursor_origin;
cursor_transform.basis.set_orthogonal_index(cursor_rot);
cursor_transform = node->get_transform() * cursor_transform;
-
if (cursor_instance.is_valid()) {
- VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform);
- VisualServer::get_singleton()->instance_set_visible(cursor_instance,cursor_visible);
+ VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
+ VisualServer::get_singleton()->instance_set_visible(cursor_instance, cursor_visible);
}
-
}
void GridMapEditor::_update_selection_transform() {
@@ -260,93 +245,87 @@ void GridMapEditor::_update_selection_transform() {
Transform xf;
xf.basis.set_zero();
- VisualServer::get_singleton()->instance_set_transform(selection_instance,xf);
+ VisualServer::get_singleton()->instance_set_transform(selection_instance, xf);
return;
}
Transform xf;
- xf.scale(Vector3(1,1,1)*(Vector3(1,1,1)+(selection.end-selection.begin))*node->get_cell_size());
- xf.origin=selection.begin*node->get_cell_size();
-
- VisualServer::get_singleton()->instance_set_transform(selection_instance,node->get_global_transform() * xf);
+ xf.scale(Vector3(1, 1, 1) * (Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size());
+ xf.origin = selection.begin * node->get_cell_size();
+ VisualServer::get_singleton()->instance_set_transform(selection_instance, node->get_global_transform() * xf);
}
void GridMapEditor::_validate_selection() {
if (!selection.active)
return;
- selection.begin=selection.click;
- selection.end=selection.current;
-
- if (selection.begin.x>selection.end.x)
- SWAP(selection.begin.x,selection.end.x);
- if (selection.begin.y>selection.end.y)
- SWAP(selection.begin.y,selection.end.y);
- if (selection.begin.z>selection.end.z)
- SWAP(selection.begin.z,selection.end.z);
+ selection.begin = selection.click;
+ selection.end = selection.current;
+ if (selection.begin.x > selection.end.x)
+ SWAP(selection.begin.x, selection.end.x);
+ if (selection.begin.y > selection.end.y)
+ SWAP(selection.begin.y, selection.end.y);
+ if (selection.begin.z > selection.end.z)
+ SWAP(selection.begin.z, selection.end.z);
_update_selection_transform();
}
-bool GridMapEditor::do_input_action(Camera* p_camera,const Point2& p_point,bool p_click) {
+bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
if (!spatial_editor)
return false;
-
- if (selected_pallete<0 && input_action!=INPUT_COPY && input_action!=INPUT_SELECT && input_action!=INPUT_DUPLICATE)
+ if (selected_pallete < 0 && input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE)
return false;
Ref<MeshLibrary> theme = node->get_theme();
if (theme.is_null())
return false;
- if (input_action!=INPUT_COPY && input_action!=INPUT_SELECT && input_action!=INPUT_DUPLICATE && !theme->has_item(selected_pallete))
+ if (input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE && !theme->has_item(selected_pallete))
return false;
Camera *camera = p_camera;
Vector3 from = camera->project_ray_origin(p_point);
Vector3 normal = camera->project_ray_normal(p_point);
Transform local_xform = node->get_global_transform().affine_inverse();
- Vector<Plane> planes=camera->get_frustum();
- from=local_xform.xform(from);
- normal=local_xform.basis.xform(normal).normalized();
-
+ Vector<Plane> planes = camera->get_frustum();
+ from = local_xform.xform(from);
+ normal = local_xform.basis.xform(normal).normalized();
Plane p;
- p.normal[edit_axis]=1.0;
- p.d=edit_floor[edit_axis]*node->get_cell_size();
+ p.normal[edit_axis] = 1.0;
+ p.d = edit_floor[edit_axis] * node->get_cell_size();
Vector3 inters;
if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters))
return false;
-
//make sure the intersection is inside the frustum planes, to avoid
//painting on invisible regions
- for(int i=0;i<planes.size();i++) {
+ for (int i = 0; i < planes.size(); i++) {
Plane fp = local_xform.xform(planes[i]);
if (fp.is_point_over(inters))
return false;
}
-
int cell[3];
- float cell_size[3]={node->get_cell_size(),node->get_cell_size(),node->get_cell_size()};
+ float cell_size[3] = { node->get_cell_size(), node->get_cell_size(), node->get_cell_size() };
- last_mouseover=Vector3(-1,-1,-1);
+ last_mouseover = Vector3(-1, -1, -1);
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
- if (i==edit_axis)
- cell[i]=edit_floor[i];
+ if (i == edit_axis)
+ cell[i] = edit_floor[i];
else {
- cell[i]=inters[i]/node->get_cell_size();
- if (inters[i]<0)
- cell[i]-=1; //compensate negative
- grid_ofs[i]=cell[i]*cell_size[i];
+ cell[i] = inters[i] / node->get_cell_size();
+ if (inters[i] < 0)
+ cell[i] -= 1; //compensate negative
+ grid_ofs[i] = cell[i] * cell_size[i];
}
/*if (cell[i]<0 || cell[i]>=grid_size[i]) {
@@ -357,68 +336,65 @@ bool GridMapEditor::do_input_action(Camera* p_camera,const Point2& p_point,bool
}*/
}
- last_mouseover=Vector3(cell[0],cell[1],cell[2]);
- VS::get_singleton()->instance_set_transform(grid_instance[edit_axis],Transform(Basis(),grid_ofs));
-
+ last_mouseover = Vector3(cell[0], cell[1], cell[2]);
+ VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], Transform(Basis(), grid_ofs));
if (cursor_instance.is_valid()) {
- cursor_origin=(Vector3(cell[0],cell[1],cell[2])+Vector3(0.5*node->get_center_x(),0.5*node->get_center_y(),0.5*node->get_center_z()))*node->get_cell_size();
- cursor_visible=true;
+ cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size();
+ cursor_visible = true;
_update_cursor_transform();
-
}
- if (input_action==INPUT_DUPLICATE) {
+ if (input_action == INPUT_DUPLICATE) {
- selection.current=Vector3(cell[0],cell[1],cell[2]);
+ selection.current = Vector3(cell[0], cell[1], cell[2]);
_update_duplicate_indicator();
- } else if (input_action==INPUT_SELECT) {
+ } else if (input_action == INPUT_SELECT) {
- selection.current=Vector3(cell[0],cell[1],cell[2]);
+ selection.current = Vector3(cell[0], cell[1], cell[2]);
if (p_click)
- selection.click=selection.current;
- selection.active=true;
+ selection.click = selection.current;
+ selection.active = true;
_validate_selection();
return true;
- } else if (input_action==INPUT_COPY) {
+ } else if (input_action == INPUT_COPY) {
- int item=node->get_cell_item(cell[0],cell[1],cell[2]);
- if (item>=0) {
- selected_pallete=item;
+ int item = node->get_cell_item(cell[0], cell[1], cell[2]);
+ if (item >= 0) {
+ selected_pallete = item;
theme_pallete->set_current(item);
update_pallete();
_update_cursor_instance();
}
return true;
- } if (input_action==INPUT_PAINT) {
+ }
+ if (input_action == INPUT_PAINT) {
SetItem si;
- si.pos=Vector3(cell[0],cell[1],cell[2]);
- si.new_value=selected_pallete;
- si.new_orientation=cursor_rot;
- si.old_value=node->get_cell_item(cell[0],cell[1],cell[2]);
- si.old_orientation=node->get_cell_item_orientation(cell[0],cell[1],cell[2]);
+ si.pos = Vector3(cell[0], cell[1], cell[2]);
+ si.new_value = selected_pallete;
+ si.new_orientation = cursor_rot;
+ si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]);
+ si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
set_items.push_back(si);
- node->set_cell_item(cell[0],cell[1],cell[2],selected_pallete,cursor_rot);
+ node->set_cell_item(cell[0], cell[1], cell[2], selected_pallete, cursor_rot);
return true;
- } else if (input_action==INPUT_ERASE) {
+ } else if (input_action == INPUT_ERASE) {
SetItem si;
- si.pos=Vector3(cell[0],cell[1],cell[2]);
- si.new_value=-1;
- si.new_orientation=0;
- si.old_value=node->get_cell_item(cell[0],cell[1],cell[2]);
- si.old_orientation=node->get_cell_item_orientation(cell[0],cell[1],cell[2]);
+ si.pos = Vector3(cell[0], cell[1], cell[2]);
+ si.new_value = -1;
+ si.new_orientation = 0;
+ si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]);
+ si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
set_items.push_back(si);
- node->set_cell_item(cell[0],cell[1],cell[2],-1);
+ node->set_cell_item(cell[0], cell[1], cell[2], -1);
return true;
}
-
return false;
-
}
void GridMapEditor::_delete_selection() {
@@ -427,269 +403,253 @@ void GridMapEditor::_delete_selection() {
return;
undo_redo->create_action("GridMap Delete Selection");
- for(int i=selection.begin.x;i<=selection.end.x;i++) {
+ for (int i = selection.begin.x; i <= selection.end.x; i++) {
- for(int j=selection.begin.y;j<=selection.end.y;j++) {
+ for (int j = selection.begin.y; j <= selection.end.y; j++) {
- for(int k=selection.begin.z;k<=selection.end.z;k++) {
+ for (int k = selection.begin.z; k <= selection.end.z; k++) {
- undo_redo->add_do_method(node,"set_cell_item",i,j,k,GridMap::INVALID_CELL_ITEM);
- undo_redo->add_undo_method(node,"set_cell_item",i,j,k,node->get_cell_item(i,j,k),node->get_cell_item_orientation(i,j,k));
+ undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM);
+ undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k));
}
-
}
}
undo_redo->commit_action();
- selection.active=false;
+ selection.active = false;
_validate_selection();
-
}
void GridMapEditor::_update_duplicate_indicator() {
- if (!selection.active || input_action!=INPUT_DUPLICATE) {
+ if (!selection.active || input_action != INPUT_DUPLICATE) {
Transform xf;
xf.basis.set_zero();
- VisualServer::get_singleton()->instance_set_transform(duplicate_instance,xf);
+ VisualServer::get_singleton()->instance_set_transform(duplicate_instance, xf);
return;
}
Transform xf;
- xf.scale(Vector3(1,1,1)*(Vector3(1,1,1)+(selection.end-selection.begin))*node->get_cell_size());
- xf.origin=(selection.begin+(selection.current-selection.click))*node->get_cell_size();
+ xf.scale(Vector3(1, 1, 1) * (Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size());
+ xf.origin = (selection.begin + (selection.current - selection.click)) * node->get_cell_size();
Basis rot;
rot.set_orthogonal_index(selection.duplicate_rot);
xf.basis = rot * xf.basis;
- VisualServer::get_singleton()->instance_set_transform(duplicate_instance,node->get_global_transform() * xf);
-
-
+ VisualServer::get_singleton()->instance_set_transform(duplicate_instance, node->get_global_transform() * xf);
}
-struct __Item { Vector3 pos; int rot; int item ; };
+struct __Item {
+ Vector3 pos;
+ int rot;
+ int item;
+};
void GridMapEditor::_duplicate_paste() {
if (!selection.active)
return;
int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS);
- bool reselect = options->get_popup()->is_item_checked( idx );
+ bool reselect = options->get_popup()->is_item_checked(idx);
-
-
- List< __Item > items;
+ List<__Item> items;
Basis rot;
rot.set_orthogonal_index(selection.duplicate_rot);
- for(int i=selection.begin.x;i<=selection.end.x;i++) {
+ for (int i = selection.begin.x; i <= selection.end.x; i++) {
- for(int j=selection.begin.y;j<=selection.end.y;j++) {
+ for (int j = selection.begin.y; j <= selection.end.y; j++) {
- for(int k=selection.begin.z;k<=selection.end.z;k++) {
+ for (int k = selection.begin.z; k <= selection.end.z; k++) {
- int itm = node->get_cell_item(i,j,k);
- if (itm==GridMap::INVALID_CELL_ITEM)
+ int itm = node->get_cell_item(i, j, k);
+ if (itm == GridMap::INVALID_CELL_ITEM)
continue;
- int orientation = node->get_cell_item_orientation(i,j,k);
+ int orientation = node->get_cell_item_orientation(i, j, k);
__Item item;
- Vector3 rel=Vector3(i,j,k)-selection.begin;
+ Vector3 rel = Vector3(i, j, k) - selection.begin;
rel = rot.xform(rel);
Basis orm;
orm.set_orthogonal_index(orientation);
orm = rot * orm;
- item.pos=selection.begin+rel;
- item.item=itm;
- item.rot=orm.get_orthogonal_index();
+ item.pos = selection.begin + rel;
+ item.item = itm;
+ item.rot = orm.get_orthogonal_index();
items.push_back(item);
}
-
}
}
- Vector3 ofs=selection.current-selection.click;
+ Vector3 ofs = selection.current - selection.click;
if (items.size()) {
undo_redo->create_action("GridMap Duplicate Selection");
- for(List< __Item >::Element *E=items.front();E;E=E->next()) {
- __Item &it=E->get();
- Vector3 pos = it.pos+ofs;
-
- undo_redo->add_do_method(node,"set_cell_item",pos.x,pos.y,pos.z,it.item,it.rot);
- undo_redo->add_undo_method(node,"set_cell_item",pos.x,pos.y,pos.z,node->get_cell_item(pos.x,pos.y,pos.z),node->get_cell_item_orientation(pos.x,pos.y,pos.z));
+ for (List<__Item>::Element *E = items.front(); E; E = E->next()) {
+ __Item &it = E->get();
+ Vector3 pos = it.pos + ofs;
+ undo_redo->add_do_method(node, "set_cell_item", pos.x, pos.y, pos.z, it.item, it.rot);
+ undo_redo->add_undo_method(node, "set_cell_item", pos.x, pos.y, pos.z, node->get_cell_item(pos.x, pos.y, pos.z), node->get_cell_item_orientation(pos.x, pos.y, pos.z));
}
undo_redo->commit_action();
}
-
if (reselect) {
- selection.begin+=ofs;
- selection.end+=ofs;
- selection.click=selection.begin;
- selection.current=selection.end;
+ selection.begin += ofs;
+ selection.end += ofs;
+ selection.click = selection.begin;
+ selection.current = selection.end;
_validate_selection();
}
-
}
-bool GridMapEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) {
+bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) {
if (!node) {
return false;
}
- if (edit_mode->get_selected()==0) { // regular click
+ 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.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);
+ floor->set_value(floor->get_value() + 1);
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)) {
+ } 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);
+ floor->set_value(floor->get_value() - 1);
return true;
}
if (p_event.mouse_button.pressed) {
- if (p_event.mouse_button.button_index==BUTTON_LEFT) {
+ if (p_event.mouse_button.button_index == BUTTON_LEFT) {
- if (input_action==INPUT_DUPLICATE) {
+ if (input_action == INPUT_DUPLICATE) {
//paste
_duplicate_paste();
- input_action=INPUT_NONE;
+ input_action = INPUT_NONE;
_update_duplicate_indicator();
} else if (p_event.mouse_button.mod.shift) {
- input_action=INPUT_SELECT;
+ input_action = INPUT_SELECT;
} else if (p_event.mouse_button.mod.command)
- input_action=INPUT_COPY;
+ input_action = INPUT_COPY;
else {
- input_action=INPUT_PAINT;
+ input_action = INPUT_PAINT;
set_items.clear();
}
- } else if (p_event.mouse_button.button_index==BUTTON_RIGHT)
- if (input_action==INPUT_DUPLICATE) {
+ } else if (p_event.mouse_button.button_index == BUTTON_RIGHT)
+ if (input_action == INPUT_DUPLICATE) {
- input_action=INPUT_NONE;
+ input_action = INPUT_NONE;
_update_duplicate_indicator();
} else {
- input_action=INPUT_ERASE;
+ input_action = INPUT_ERASE;
set_items.clear();
}
else
return false;
- return do_input_action(p_camera,Point2(p_event.mouse_button.x,p_event.mouse_button.y),true);
+ return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true);
} else {
-
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) ) {
+ (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
+ (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) {
if (set_items.size()) {
undo_redo->create_action("GridMap Paint");
- for(List<SetItem>::Element *E=set_items.front();E;E=E->next()) {
+ for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
- 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);
+ 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()) {
+ for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
- 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);
+ 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);
}
-
undo_redo->commit_action();
}
set_items.clear();
- input_action=INPUT_NONE;
+ input_action = INPUT_NONE;
return true;
-
}
-
-
- if (p_event.mouse_button.button_index==BUTTON_LEFT && input_action!=INPUT_NONE) {
+ if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) {
set_items.clear();
- input_action=INPUT_NONE;
+ 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;
+ if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) {
+ input_action = INPUT_NONE;
return true;
}
}
} break;
case InputEvent::MOUSE_MOTION: {
- return do_input_action(p_camera,Point2(p_event.mouse_motion.x,p_event.mouse_motion.y),false);
+ return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false);
} break;
}
- } else if (edit_mode->get_selected()==1) {
+ } else if (edit_mode->get_selected() == 1) {
//area mode, select an area
switch (p_event.type) {
case InputEvent::MOUSE_BUTTON: {
- if (p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) {
+ if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) {
- Point2 point = Point2(p_event.mouse_motion.x,p_event.mouse_motion.y);
+ Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y);
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();
+ from = local_xform.xform(from);
+ normal = local_xform.basis.xform(normal).normalized();
List<int> areas;
node->get_area_list(&areas);
- float min_d=1e10;
- int min_area=-1;
+ float min_d = 1e10;
+ int min_area = -1;
-
- for(List<int>::Element *E=areas.front();E;E=E->next()) {
+ for (List<int>::Element *E = areas.front(); E; E = E->next()) {
int area = E->get();
Rect3 aabb = node->area_get_bounds(area);
- aabb.pos*=node->get_cell_size();
- aabb.size*=node->get_cell_size();
-
+ aabb.pos *= node->get_cell_size();
+ aabb.size *= node->get_cell_size();
- Vector3 rclip,rnormal;
- if (!aabb.intersects_segment(from,from+normal*10000,&rclip,&rnormal))
+ Vector3 rclip, rnormal;
+ if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal))
continue;
float d = normal.dot(rclip);
- if (d<min_d) {
- min_d=d;
- min_area=area;
+ if (d < min_d) {
+ min_d = d;
+ min_area = area;
}
}
- selected_area=min_area;
+ selected_area = min_area;
update_areas();
-
}
} break;
}
-
}
-
return false;
}
@@ -697,12 +657,11 @@ struct _CGMEItemSort {
String name;
int id;
- _FORCE_INLINE_ bool operator<(const _CGMEItemSort& r_it) const { return name < r_it.name; }
-
+ _FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; }
};
void GridMapEditor::_set_display_mode(int p_mode) {
- if (display_mode==p_mode) {
+ if (display_mode == p_mode) {
return;
}
@@ -714,32 +673,32 @@ void GridMapEditor::_set_display_mode(int p_mode) {
mode_thumbnail->set_pressed(true);
}
- display_mode=p_mode;
+ display_mode = p_mode;
update_pallete();
}
-void GridMapEditor::update_pallete() {
+void GridMapEditor::update_pallete() {
int selected = theme_pallete->get_current();
theme_pallete->clear();
if (display_mode == DISPLAY_THUMBNAIL) {
theme_pallete->set_max_columns(0);
theme_pallete->set_icon_mode(ItemList::ICON_MODE_TOP);
- } else if (display_mode == DISPLAY_LIST){
+ } else if (display_mode == DISPLAY_LIST) {
theme_pallete->set_max_columns(1);
theme_pallete->set_icon_mode(ItemList::ICON_MODE_LEFT);
}
- float min_size = EDITOR_DEF("editors/grid_map/preview_size",64);
+ float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64);
theme_pallete->set_fixed_icon_size(Size2(min_size, min_size));
- theme_pallete->set_fixed_column_width(min_size*3/2);
+ theme_pallete->set_fixed_column_width(min_size * 3 / 2);
theme_pallete->set_max_text_lines(2);
Ref<MeshLibrary> theme = node->get_theme();
if (theme.is_null()) {
- last_theme=NULL;
+ last_theme = NULL;
return;
}
@@ -747,65 +706,63 @@ void GridMapEditor::update_pallete() {
ids = theme->get_item_list();
List<_CGMEItemSort> il;
- for(int i=0;i<ids.size();i++) {
+ for (int i = 0; i < ids.size(); i++) {
_CGMEItemSort is;
- is.id=ids[i];
- is.name=theme->get_item_name(ids[i]);
+ is.id = ids[i];
+ is.name = theme->get_item_name(ids[i]);
il.push_back(is);
}
il.sort();
int item = 0;
- for(List<_CGMEItemSort>::Element *E=il.front();E;E=E->next()) {
+ for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) {
int id = E->get().id;
theme_pallete->add_item("");
- String name=theme->get_item_name(id);
+ String name = theme->get_item_name(id);
Ref<Texture> preview = theme->get_item_preview(id);
if (!preview.is_null()) {
theme_pallete->set_item_icon(item, preview);
theme_pallete->set_item_tooltip(item, name);
}
- if (name!="") {
- theme_pallete->set_item_text(item,name);
+ if (name != "") {
+ theme_pallete->set_item_text(item, name);
}
theme_pallete->set_item_metadata(item, id);
item++;
}
- if (selected!=-1) {
+ if (selected != -1) {
theme_pallete->select(selected);
}
- last_theme=theme.operator->();
+ last_theme = theme.operator->();
}
-
void GridMapEditor::_area_renamed() {
- TreeItem * it = area_list->get_selected();
+ TreeItem *it = area_list->get_selected();
int area = it->get_metadata(0);
- if (area<1)
+ if (area < 1)
return;
- node->area_set_name(area,it->get_text(0));
+ node->area_set_name(area, it->get_text(0));
}
-
void GridMapEditor::_area_selected() {
- TreeItem * it = area_list->get_selected();
+ TreeItem *it = area_list->get_selected();
int area = it->get_metadata(0);
- if (area<1)
+ if (area < 1)
return;
- selected_area=area;
+ selected_area = area;
}
-void GridMapEditor::update_areas() {
+void GridMapEditor::update_areas() {
area_list->clear();
@@ -814,246 +771,221 @@ void GridMapEditor::update_areas() {
TreeItem *root = area_list->create_item(NULL);
area_list->set_hide_root(true);
- TreeItem *selected=NULL;
-
+ TreeItem *selected = NULL;
- for (List<int>::Element *E=areas.front();E;E=E->next()) {
+ for (List<int>::Element *E = areas.front(); E; E = E->next()) {
int area = E->get();
TreeItem *ti = area_list->create_item(root);
- String name=node->area_get_name(area);
+ String name = node->area_get_name(area);
- ti->set_metadata(0,area);
- ti->set_text(0,name);
- ti->set_editable(0,true);
- if (area==selected_area)
- selected=ti;
+ ti->set_metadata(0, area);
+ ti->set_text(0, name);
+ ti->set_editable(0, true);
+ if (area == selected_area)
+ selected = ti;
}
-
if (selected)
selected->select(0);
-
}
void GridMapEditor::edit(GridMap *p_gridmap) {
- node=p_gridmap;
+ node = p_gridmap;
VS *vs = VS::get_singleton();
- last_mouseover=Vector3(-1,-1,-1);
- input_action=INPUT_NONE;
- selection.active=false;
+ last_mouseover = Vector3(-1, -1, -1);
+ input_action = INPUT_NONE;
+ selection.active = false;
_update_selection_transform();
_update_duplicate_indicator();
- spatial_editor = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>();
+ spatial_editor = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>();
if (!node) {
set_process(false);
- for(int i=0;i<3;i++) {
- VisualServer::get_singleton()->instance_set_visible(grid_instance[i],false);
-
+ for (int i = 0; i < 3; i++) {
+ VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false);
}
- VisualServer::get_singleton()->instance_set_visible(cursor_instance,false);
+ VisualServer::get_singleton()->instance_set_visible(cursor_instance, false);
_clear_areas();
return;
}
-
update_pallete();
update_areas();
set_process(true);
Vector3 edited_floor = p_gridmap->get_meta("_editor_floor_");
- clip_mode=p_gridmap->has_meta("_editor_clip_")?ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()):CLIP_DISABLED;
-
-
-
- for(int i=0;i<3;i++) {
- if (vs->mesh_get_surface_count(grid[i])>0)
- vs->mesh_remove_surface(grid[i],0);
- edit_floor[i]=edited_floor[i];
+ clip_mode = p_gridmap->has_meta("_editor_clip_") ? ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()) : CLIP_DISABLED;
+ for (int i = 0; i < 3; i++) {
+ if (vs->mesh_get_surface_count(grid[i]) > 0)
+ vs->mesh_remove_surface(grid[i], 0);
+ edit_floor[i] = edited_floor[i];
}
{
//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_albedo(Color(0.8,0.5,0.1));
-
+ 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_albedo(Color(0.8, 0.5, 0.1));
Vector<Vector3> grid_points[3];
Vector<Color> grid_colors[3];
- float cell_size[3]={p_gridmap->get_cell_size(),p_gridmap->get_cell_size(),p_gridmap->get_cell_size()};
+ float cell_size[3] = { p_gridmap->get_cell_size(), p_gridmap->get_cell_size(), p_gridmap->get_cell_size() };
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
Vector3 axis;
- axis[i]=1;
+ axis[i] = 1;
Vector3 axis_n1;
- axis_n1[(i+1)%3]=cell_size[(i+1)%3];
+ axis_n1[(i + 1) % 3] = cell_size[(i + 1) % 3];
Vector3 axis_n2;
- axis_n2[(i+2)%3]=cell_size[(i+2)%3];
+ axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3];
- for(int j=-GRID_CURSOR_SIZE;j<=GRID_CURSOR_SIZE;j++) {
+ for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) {
- for(int k=-GRID_CURSOR_SIZE;k<=GRID_CURSOR_SIZE;k++) {
+ for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) {
- Vector3 p = axis_n1*j + axis_n2 *k;
- float trans = Math::pow(MAX(0,1.0-(Vector2(j,k).length()/GRID_CURSOR_SIZE)),2);
+ Vector3 p = axis_n1 * j + axis_n2 * k;
+ float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2);
- Vector3 pj = axis_n1*(j+1) + axis_n2 *k;
- float transj = Math::pow(MAX(0,1.0-(Vector2(j+1,k).length()/GRID_CURSOR_SIZE)),2);
+ Vector3 pj = axis_n1 * (j + 1) + axis_n2 * k;
+ float transj = Math::pow(MAX(0, 1.0 - (Vector2(j + 1, k).length() / GRID_CURSOR_SIZE)), 2);
- Vector3 pk = axis_n1*j + axis_n2 *(k+1);
- float transk = Math::pow(MAX(0,1.0-(Vector2(j,k+1).length()/GRID_CURSOR_SIZE)),2);
+ Vector3 pk = axis_n1 * j + axis_n2 * (k + 1);
+ float transk = Math::pow(MAX(0, 1.0 - (Vector2(j, k + 1).length() / GRID_CURSOR_SIZE)), 2);
grid_points[i].push_back(p);
grid_points[i].push_back(pk);
- grid_colors[i].push_back(Color(1,1,1,trans));
- grid_colors[i].push_back(Color(1,1,1,transk));
+ grid_colors[i].push_back(Color(1, 1, 1, trans));
+ grid_colors[i].push_back(Color(1, 1, 1, transk));
grid_points[i].push_back(p);
grid_points[i].push_back(pj);
- grid_colors[i].push_back(Color(1,1,1,trans));
- grid_colors[i].push_back(Color(1,1,1,transj));
+ grid_colors[i].push_back(Color(1, 1, 1, trans));
+ grid_colors[i].push_back(Color(1, 1, 1, transj));
}
-
}
Array d;
d.resize(VS::ARRAY_MAX);
- d[VS::ARRAY_VERTEX]=grid_points[i];
- d[VS::ARRAY_COLOR]=grid_colors[i];
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d);
- VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat->get_rid());
-
-
+ d[VS::ARRAY_VERTEX] = grid_points[i];
+ d[VS::ARRAY_COLOR] = grid_colors[i];
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d);
+ VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid());
}
-
}
update_grid();
_update_clip();
_update_areas_display();
-
-
}
void GridMapEditor::_update_clip() {
-
- node->set_meta("_editor_clip_",clip_mode);
- if (clip_mode==CLIP_DISABLED)
+ node->set_meta("_editor_clip_", clip_mode);
+ if (clip_mode == CLIP_DISABLED)
node->set_clip(false);
else
- node->set_clip(true,clip_mode==CLIP_ABOVE,edit_floor[edit_axis],edit_axis);
+ node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis);
}
-
void GridMapEditor::update_grid() {
- grid_xform.origin.x-=1; //force update in hackish way.. what do i care
+ grid_xform.origin.x -= 1; //force update in hackish way.. what do i care
//VS *vs = VS::get_singleton();
- grid_ofs[edit_axis]=edit_floor[edit_axis]*node->get_cell_size();
-
- edit_grid_xform.origin=grid_ofs;
- edit_grid_xform.basis=Basis();
+ grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size();
+ edit_grid_xform.origin = grid_ofs;
+ edit_grid_xform.basis = Basis();
- for(int i=0;i<3;i++) {
- VisualServer::get_singleton()->instance_set_visible(grid_instance[i],i==edit_axis);
-
+ for (int i = 0; i < 3; i++) {
+ VisualServer::get_singleton()->instance_set_visible(grid_instance[i], i == edit_axis);
}
- updating=true;
+ updating = true;
floor->set_value(edit_floor[edit_axis]);
- updating=false;
-
+ updating = false;
}
-
-
void GridMapEditor::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
- theme_pallete->connect("item_selected", this,"_item_selected_cbk");
- edit_mode->connect("item_selected", this,"_edit_mode_changed");
- area_list->connect("item_edited", this,"_area_renamed");
- area_list->connect("item_selected", this,"_area_selected");
- for(int i=0;i<3;i++) {
+ theme_pallete->connect("item_selected", this, "_item_selected_cbk");
+ edit_mode->connect("item_selected", this, "_edit_mode_changed");
+ area_list->connect("item_edited", this, "_area_renamed");
+ area_list->connect("item_selected", this, "_area_selected");
+ for (int i = 0; i < 3; i++) {
- grid[i]=VS::get_singleton()->mesh_create();
- grid_instance[i]=VS::get_singleton()->instance_create2(grid[i],get_tree()->get_root()->get_world()->get_scenario());
+ grid[i] = VS::get_singleton()->mesh_create();
+ grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario());
}
- selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh,get_tree()->get_root()->get_world()->get_scenario());
- duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh,get_tree()->get_root()->get_world()->get_scenario());
+ selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario());
+ duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh, get_tree()->get_root()->get_world()->get_scenario());
_update_selection_transform();
_update_duplicate_indicator();
- } else if (p_what==NOTIFICATION_EXIT_TREE) {
+ } else if (p_what == NOTIFICATION_EXIT_TREE) {
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
VS::get_singleton()->free(grid_instance[i]);
VS::get_singleton()->free(grid[i]);
- grid_instance[i]=RID();
- grid[i]=RID();
+ grid_instance[i] = RID();
+ grid[i] = RID();
}
VisualServer::get_singleton()->free(selection_instance);
VisualServer::get_singleton()->free(duplicate_instance);
- selection_instance=RID();
- duplicate_instance=RID();
+ selection_instance = RID();
+ duplicate_instance = RID();
- } else if (p_what==NOTIFICATION_PROCESS) {
+ } else if (p_what == NOTIFICATION_PROCESS) {
Transform xf = node->get_global_transform();
- if (xf!=grid_xform) {
- for(int i=0;i<3;i++) {
-
+ if (xf != grid_xform) {
+ for (int i = 0; i < 3; i++) {
- VS::get_singleton()->instance_set_transform(grid_instance[i],xf * edit_grid_xform);
+ VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
}
- grid_xform=xf;
+ grid_xform = xf;
}
Ref<MeshLibrary> cgmt = node->get_theme();
- if (cgmt.operator->()!=last_theme)
+ if (cgmt.operator->() != last_theme)
update_pallete();
if (lock_view) {
- EditorNode*editor = get_tree()->get_root()->get_child(0)->cast_to<EditorNode>();
+ EditorNode *editor = get_tree()->get_root()->get_child(0)->cast_to<EditorNode>();
Plane p;
- p.normal[edit_axis]=1.0;
- p.d=edit_floor[edit_axis]*node->get_cell_size();
+ p.normal[edit_axis] = 1.0;
+ p.d = edit_floor[edit_axis] * node->get_cell_size();
p = node->get_transform().xform(p); // plane to snap
SpatialEditorPlugin *sep = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>();
if (sep)
sep->snap_cursor_to_plane(p);
- //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p);
-
+ //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p);
}
}
-
}
void GridMapEditor::_update_cursor_instance() {
@@ -1063,32 +995,30 @@ void GridMapEditor::_update_cursor_instance() {
if (cursor_instance.is_valid())
VisualServer::get_singleton()->free(cursor_instance);
- cursor_instance=RID();
+ cursor_instance = RID();
- if (selected_pallete>=0) {
+ if (selected_pallete >= 0) {
if (node && !node->get_theme().is_null()) {
Ref<Mesh> mesh = node->get_theme()->get_item_mesh(selected_pallete);
if (!mesh.is_null() && mesh->get_rid().is_valid()) {
- cursor_instance=VisualServer::get_singleton()->instance_create2(mesh->get_rid(),get_tree()->get_root()->get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform);
+ cursor_instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
+ VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
}
}
}
-
}
void GridMapEditor::_item_selected_cbk(int idx) {
- selected_pallete=theme_pallete->get_item_metadata(idx);
+ selected_pallete = theme_pallete->get_item_metadata(idx);
_update_cursor_instance();
-
}
void GridMapEditor::_clear_areas() {
- for(int i=0;i<areas.size();i++) {
+ for (int i = 0; i < areas.size(); i++) {
VisualServer::get_singleton()->free(areas[i].instance);
VisualServer::get_singleton()->free(areas[i].mesh);
@@ -1154,7 +1084,7 @@ void GridMapEditor::_update_areas_display() {
void GridMapEditor::_edit_mode_changed(int p_what) {
- if (p_what==0) {
+ if (p_what == 0) {
theme_pallete->show();
area_list->hide();
@@ -1162,89 +1092,82 @@ void GridMapEditor::_edit_mode_changed(int p_what) {
theme_pallete->hide();
area_list->show();
-
}
}
void GridMapEditor::_floor_changed(float p_value) {
-
if (updating)
return;
- edit_floor[edit_axis]=p_value;
- node->set_meta("_editor_floor_",Vector3(edit_floor[0],edit_floor[1],edit_floor[2]));
+ edit_floor[edit_axis] = p_value;
+ node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2]));
update_grid();
_update_clip();
-
}
void GridMapEditor::_bind_methods() {
- ClassDB::bind_method("_menu_option",&GridMapEditor::_menu_option);
- ClassDB::bind_method("_configure",&GridMapEditor::_configure);
- ClassDB::bind_method("_item_selected_cbk",&GridMapEditor::_item_selected_cbk);
- ClassDB::bind_method("_edit_mode_changed",&GridMapEditor::_edit_mode_changed);
- ClassDB::bind_method("_area_renamed",&GridMapEditor::_area_renamed);
- ClassDB::bind_method("_area_selected",&GridMapEditor::_area_selected);
- ClassDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed);
+ ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option);
+ ClassDB::bind_method("_configure", &GridMapEditor::_configure);
+ ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk);
+ ClassDB::bind_method("_edit_mode_changed", &GridMapEditor::_edit_mode_changed);
+ ClassDB::bind_method("_area_renamed", &GridMapEditor::_area_renamed);
+ ClassDB::bind_method("_area_selected", &GridMapEditor::_area_selected);
+ ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed);
- ClassDB::bind_method(D_METHOD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode);
+ ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode);
}
-
-
GridMapEditor::GridMapEditor(EditorNode *p_editor) {
+ input_action = INPUT_NONE;
+ editor = p_editor;
+ undo_redo = p_editor->get_undo_redo();
- input_action=INPUT_NONE;
- editor=p_editor;
- undo_redo=p_editor->get_undo_redo();
-
- int mw = EDITOR_DEF("editors/grid_map/palette_min_width",230);
- Control *ec = memnew( Control);
- ec->set_custom_minimum_size(Size2(mw,0));
+ int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
+ Control *ec = memnew(Control);
+ ec->set_custom_minimum_size(Size2(mw, 0));
add_child(ec);
-
- spatial_editor_hb = memnew( HBoxContainer );
+ spatial_editor_hb = memnew(HBoxContainer);
SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
- options = memnew( MenuButton );
+ options = memnew(MenuButton);
spatial_editor_hb->add_child(options);
spatial_editor_hb->hide();
options->set_text("Grid");
- options->get_popup()->add_check_item("Snap View",MENU_OPTION_LOCK_VIEW);
+ options->get_popup()->add_check_item("Snap View", MENU_OPTION_LOCK_VIEW);
options->get_popup()->add_separator();
- options->get_popup()->add_item("Prev Level ("+keycode_get_string(KEY_MASK_CMD)+"Down Wheel)",MENU_OPTION_PREV_LEVEL);
- options->get_popup()->add_item("Next Level ("+keycode_get_string(KEY_MASK_CMD)+"Up Wheel)",MENU_OPTION_NEXT_LEVEL);
+ options->get_popup()->add_item("Prev Level (" + keycode_get_string(KEY_MASK_CMD) + "Down Wheel)", MENU_OPTION_PREV_LEVEL);
+ options->get_popup()->add_item("Next Level (" + keycode_get_string(KEY_MASK_CMD) + "Up Wheel)", MENU_OPTION_NEXT_LEVEL);
options->get_popup()->add_separator();
- options->get_popup()->add_check_item("Clip Disabled",MENU_OPTION_CLIP_DISABLED);
- options->get_popup()->set_item_checked( options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true );
- options->get_popup()->add_check_item("Clip Above",MENU_OPTION_CLIP_ABOVE);
- options->get_popup()->add_check_item("Clip Below",MENU_OPTION_CLIP_BELOW);
+ options->get_popup()->add_check_item("Clip Disabled", MENU_OPTION_CLIP_DISABLED);
+ options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
+ options->get_popup()->add_check_item("Clip Above", MENU_OPTION_CLIP_ABOVE);
+ options->get_popup()->add_check_item("Clip Below", MENU_OPTION_CLIP_BELOW);
options->get_popup()->add_separator();
- options->get_popup()->add_check_item("Edit X Axis",MENU_OPTION_X_AXIS,KEY_Z);
- options->get_popup()->add_check_item("Edit Y Axis",MENU_OPTION_Y_AXIS,KEY_X);
- options->get_popup()->add_check_item("Edit Z Axis",MENU_OPTION_Z_AXIS,KEY_C);
- options->get_popup()->set_item_checked( options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true );
+ options->get_popup()->add_check_item("Edit X Axis", MENU_OPTION_X_AXIS, KEY_Z);
+ options->get_popup()->add_check_item("Edit Y Axis", MENU_OPTION_Y_AXIS, KEY_X);
+ options->get_popup()->add_check_item("Edit Z Axis", MENU_OPTION_Z_AXIS, KEY_C);
+ options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true);
options->get_popup()->add_separator();
- options->get_popup()->add_item("Cursor Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_A);
- options->get_popup()->add_item("Cursor Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_S);
- options->get_popup()->add_item("Cursor Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_D);
- options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_BACK_ROTATE_X,KEY_MASK_SHIFT+KEY_A);
- options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_BACK_ROTATE_Y,KEY_MASK_SHIFT+KEY_S);
- options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_BACK_ROTATE_Z,KEY_MASK_SHIFT+KEY_D);
- options->get_popup()->add_item("Cursor Clear Rotation",MENU_OPTION_CURSOR_CLEAR_ROTATION,KEY_W);
+ options->get_popup()->add_item("Cursor Rotate X", MENU_OPTION_CURSOR_ROTATE_X, KEY_A);
+ options->get_popup()->add_item("Cursor Rotate Y", MENU_OPTION_CURSOR_ROTATE_Y, KEY_S);
+ options->get_popup()->add_item("Cursor Rotate Z", MENU_OPTION_CURSOR_ROTATE_Z, KEY_D);
+ options->get_popup()->add_item("Cursor Back Rotate X", MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A);
+ options->get_popup()->add_item("Cursor Back Rotate Y", MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S);
+ options->get_popup()->add_item("Cursor Back Rotate Z", MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D);
+ options->get_popup()->add_item("Cursor Clear Rotation", MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W);
options->get_popup()->add_separator();
- options->get_popup()->add_check_item("Duplicate Selects",MENU_OPTION_DUPLICATE_SELECTS);
+ options->get_popup()->add_check_item("Duplicate Selects", MENU_OPTION_DUPLICATE_SELECTS);
options->get_popup()->add_separator();
- options->get_popup()->add_item("Create Area",MENU_OPTION_SELECTION_MAKE_AREA,KEY_CONTROL+KEY_C);
- options->get_popup()->add_item("Create Exterior Connector",MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR);
- options->get_popup()->add_item("Erase Area",MENU_OPTION_REMOVE_AREA);
+ options->get_popup()->add_item("Create Area", MENU_OPTION_SELECTION_MAKE_AREA, KEY_CONTROL + KEY_C);
+ options->get_popup()->add_item("Create Exterior Connector", MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR);
+ options->get_popup()->add_item("Erase Area", MENU_OPTION_REMOVE_AREA);
options->get_popup()->add_separator();
- options->get_popup()->add_item("Selection -> Duplicate",MENU_OPTION_SELECTION_DUPLICATE,KEY_MASK_SHIFT+KEY_INSERT);
- options->get_popup()->add_item("Selection -> Clear",MENU_OPTION_SELECTION_CLEAR,KEY_MASK_SHIFT+KEY_DELETE);
+ options->get_popup()->add_item("Selection -> Duplicate", MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT);
+ options->get_popup()->add_item("Selection -> Clear", MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE);
//options->get_popup()->add_separator();
//options->get_popup()->add_item("Configure",MENU_OPTION_CONFIGURE);
@@ -1265,46 +1188,46 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0));
settings_vbc->add_margin_child("Pick Distance:", settings_pick_distance);
- clip_mode=CLIP_DISABLED;
- options->get_popup()->connect("id_pressed", this,"_menu_option");
+ clip_mode = CLIP_DISABLED;
+ options->get_popup()->connect("id_pressed", this, "_menu_option");
- HBoxContainer *hb = memnew( HBoxContainer );
+ HBoxContainer *hb = memnew(HBoxContainer);
add_child(hb);
hb->set_h_size_flags(SIZE_EXPAND_FILL);
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_BOTTOM, ANCHOR_BEGIN, 24);
+ 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);
edit_mode->set_h_size_flags(SIZE_EXPAND_FILL);
- mode_thumbnail = memnew( ToolButton );
+ mode_thumbnail = memnew(ToolButton);
mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true);
- mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons"));
+ mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons"));
hb->add_child(mode_thumbnail);
mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
- mode_list = memnew( ToolButton );
+ mode_list = memnew(ToolButton);
mode_list->set_toggle_mode(true);
mode_list->set_pressed(false);
mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons"));
hb->add_child(mode_list);
mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
- EDITOR_DEF("editors/grid_map/preview_size",64);
+ EDITOR_DEF("editors/grid_map/preview_size", 64);
display_mode = DISPLAY_THUMBNAIL;
- selected_area=-1;
+ selected_area = -1;
- theme_pallete = memnew( ItemList );
+ theme_pallete = memnew(ItemList);
add_child(theme_pallete);
theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);
- area_list = memnew( Tree );
+ area_list = memnew(Tree);
add_child(area_list);
area_list->set_v_size_flags(SIZE_EXPAND_FILL);
area_list->hide();
@@ -1314,26 +1237,25 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
fl->set_text(" Floor: ");
spatial_editor_hb->add_child(fl);
- floor = memnew( SpinBox );
+ floor = memnew(SpinBox);
floor->set_min(-32767);
floor->set_max(32767);
floor->set_step(1);
- floor->get_line_edit()->add_constant_override("minimum_spaces",16);
+ floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
spatial_editor_hb->add_child(floor);
- floor->connect("value_changed",this,"_floor_changed");
-
+ floor->connect("value_changed", this, "_floor_changed");
- edit_axis=Vector3::AXIS_Y;
- edit_floor[0]=-1;
- edit_floor[1]=-1;
- edit_floor[2]=-1;
+ edit_axis = Vector3::AXIS_Y;
+ edit_floor[0] = -1;
+ edit_floor[1] = -1;
+ edit_floor[2] = -1;
- cursor_visible=false;
- selected_pallete=-1;
- lock_view=false;
- cursor_rot=0;
- last_mouseover=Vector3(-1,-1,-1);
+ cursor_visible = false;
+ selected_pallete = -1;
+ lock_view = false;
+ cursor_rot = 0;
+ last_mouseover = Vector3(-1, -1, -1);
selection_mesh = VisualServer::get_singleton()->mesh_create();
duplicate_mesh = VisualServer::get_singleton()->mesh_create();
@@ -1341,45 +1263,43 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
{
//selection mesh create
-
PoolVector<Vector3> lines;
PoolVector<Vector3> triangles;
- for (int i=0;i<6;i++) {
-
+ for (int i = 0; i < 6; i++) {
Vector3 face_points[4];
- for (int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
float v[3];
- v[0]=1.0;
- v[1]=1-2*((j>>1)&1);
- v[2]=v[1]*(1-2*(j&1));
+ v[0] = 1.0;
+ v[1] = 1 - 2 * ((j >> 1) & 1);
+ v[2] = v[1] * (1 - 2 * (j & 1));
- for (int k=0;k<3;k++) {
+ for (int k = 0; k < 3; k++) {
- if (i<3)
- face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ if (i < 3)
+ face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
else
- face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
+ face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
}
}
- triangles.push_back(face_points[0]*0.5+Vector3(0.5,0.5,0.5));
- triangles.push_back(face_points[1]*0.5+Vector3(0.5,0.5,0.5));
- triangles.push_back(face_points[2]*0.5+Vector3(0.5,0.5,0.5));
+ triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
+ triangles.push_back(face_points[1] * 0.5 + Vector3(0.5, 0.5, 0.5));
+ triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
- triangles.push_back(face_points[2]*0.5+Vector3(0.5,0.5,0.5));
- triangles.push_back(face_points[3]*0.5+Vector3(0.5,0.5,0.5));
- triangles.push_back(face_points[0]*0.5+Vector3(0.5,0.5,0.5));
+ triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
+ triangles.push_back(face_points[3] * 0.5 + Vector3(0.5, 0.5, 0.5));
+ triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
}
- for(int i=0;i<12;i++) {
+ for (int i = 0; i < 12; i++) {
- Rect3 base(Vector3(0,0,0),Vector3(1,1,1));
- Vector3 a,b;
- base.get_edge(i,a,b);
+ Rect3 base(Vector3(0, 0, 0), Vector3(1, 1, 1));
+ Vector3 a, b;
+ base.get_edge(i, a, b);
lines.push_back(a);
lines.push_back(b);
}
@@ -1388,49 +1308,42 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
d.resize(VS::ARRAY_MAX);
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_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);
-
- d[VS::ARRAY_VERTEX]=triangles;
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_TRIANGLES,d);
- VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat->get_rid());
+ d[VS::ARRAY_VERTEX] = triangles;
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d);
+ VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid());
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_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_line_width(3.0);
- outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true);
-
-
- d[VS::ARRAY_VERTEX]=lines;
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_LINES,d);
- VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat->get_rid());
+ outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true);
- d[VS::ARRAY_VERTEX]=triangles;
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d);
- VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat->get_rid());
+ d[VS::ARRAY_VERTEX] = lines;
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d);
+ VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid());
- d[VS::ARRAY_VERTEX]=lines;
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_LINES,d);
- VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat->get_rid());
+ d[VS::ARRAY_VERTEX] = triangles;
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh, VS::PRIMITIVE_TRIANGLES, d);
+ VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh, 0, inner_mat->get_rid());
+ d[VS::ARRAY_VERTEX] = lines;
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh, VS::PRIMITIVE_LINES, d);
+ VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh, 1, outer_mat->get_rid());
}
- selection.active=false;
- updating=false;
-
+ selection.active = false;
+ updating = false;
}
-
-
-
GridMapEditor::~GridMapEditor() {
- for(int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
if (grid[i].is_valid())
VisualServer::get_singleton()->free(grid[i]);
@@ -1440,12 +1353,10 @@ GridMapEditor::~GridMapEditor() {
VisualServer::get_singleton()->free(cursor_instance);
}
-
VisualServer::get_singleton()->free(selection_mesh);
if (selection_instance.is_valid())
VisualServer::get_singleton()->free(selection_instance);
-
VisualServer::get_singleton()->free(duplicate_mesh);
if (duplicate_instance.is_valid())
VisualServer::get_singleton()->free(duplicate_instance);
@@ -1455,8 +1366,7 @@ GridMapEditor::~GridMapEditor() {
void GridMapEditorPlugin::edit(Object *p_object) {
-
- gridmap_editor->edit(p_object?p_object->cast_to<GridMap>():NULL);
+ gridmap_editor->edit(p_object ? p_object->cast_to<GridMap>() : NULL);
}
bool GridMapEditorPlugin::handles(Object *p_object) const {
@@ -1477,26 +1387,18 @@ void GridMapEditorPlugin::make_visible(bool p_visible) {
gridmap_editor->edit(NULL);
gridmap_editor->set_process(false);
}
-
}
-
GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) {
- editor=p_node;
- gridmap_editor = memnew( GridMapEditor(editor) );
+ editor = p_node;
+ gridmap_editor = memnew(GridMapEditor(editor));
SpatialEditor::get_singleton()->get_palette_split()->add_child(gridmap_editor);
- SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor,0);
+ SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 0);
gridmap_editor->hide();
-
-
-
}
-
-GridMapEditorPlugin::~GridMapEditorPlugin()
-{
+GridMapEditorPlugin::~GridMapEditorPlugin() {
}
-
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index 07ac34cd4e..27a063ee41 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -29,10 +29,10 @@
#ifndef GRID_MAP_EDITOR_PLUGIN_H
#define GRID_MAP_EDITOR_PLUGIN_H
-#include "editor/editor_plugin.h"
#include "editor/editor_node.h"
-#include "grid_map.h"
+#include "editor/editor_plugin.h"
#include "editor/pane_drag.h"
+#include "grid_map.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -40,11 +40,11 @@
class SpatialEditorPlugin;
class GridMapEditor : public VBoxContainer {
- GDCLASS(GridMapEditor, VBoxContainer );
+ GDCLASS(GridMapEditor, VBoxContainer);
enum {
- GRID_CURSOR_SIZE=50
+ GRID_CURSOR_SIZE = 50
};
enum InputAction {
@@ -65,14 +65,14 @@ class GridMapEditor : public VBoxContainer {
};
enum DisplayMode {
- DISPLAY_THUMBNAIL,
- DISPLAY_LIST
+ DISPLAY_THUMBNAIL,
+ DISPLAY_LIST
};
UndoRedo *undo_redo;
InputAction input_action;
Panel *panel;
- MenuButton * options;
+ MenuButton *options;
SpinBox *floor;
OptionButton *edit_mode;
ToolButton *mode_thumbnail;
@@ -94,7 +94,7 @@ class GridMapEditor : public VBoxContainer {
List<SetItem> set_items;
GridMap *node;
- MeshLibrary* last_theme;
+ MeshLibrary *last_theme;
ClipMode clip_mode;
bool lock_view;
@@ -118,10 +118,8 @@ class GridMapEditor : public VBoxContainer {
bool updating;
-
struct Selection {
-
Vector3 click;
Vector3 current;
Vector3 begin;
@@ -141,7 +139,6 @@ class GridMapEditor : public VBoxContainer {
int selected_area;
int cursor_rot;
-
enum Menu {
MENU_OPTION_CONFIGURE,
@@ -173,7 +170,6 @@ class GridMapEditor : public VBoxContainer {
SpatialEditorPlugin *spatial_editor;
-
struct AreaDisplay {
RID mesh;
@@ -212,20 +208,18 @@ class GridMapEditor : public VBoxContainer {
void update_areas();
EditorNode *editor;
- bool do_input_action(Camera* p_camera,const Point2& p_point,bool p_click);
+ bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
-friend class GridMapEditorPlugin;
+ friend class GridMapEditorPlugin;
Panel *theme_panel;
protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();
-public:
-
- bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event);
-
+public:
+ bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event);
void edit(GridMap *p_gridmap);
GridMapEditor() {}
@@ -235,14 +229,13 @@ public:
class GridMapEditorPlugin : public EditorPlugin {
- GDCLASS( GridMapEditorPlugin, EditorPlugin );
+ GDCLASS(GridMapEditorPlugin, EditorPlugin);
GridMapEditor *gridmap_editor;
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 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);
@@ -251,7 +244,6 @@ public:
GridMapEditorPlugin(EditorNode *p_node);
~GridMapEditorPlugin();
-
};
#endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H
diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp
index 9cd70a0f9b..4035caea78 100644
--- a/modules/gridmap/register_types.cpp
+++ b/modules/gridmap/register_types.cpp
@@ -43,9 +43,5 @@ void register_gridmap_types() {
#endif
}
-
-
void unregister_gridmap_types() {
-
-
}
diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp
index 1152d42e1b..ca928c4fe6 100644
--- a/modules/jpg/image_loader_jpegd.cpp
+++ b/modules/jpg/image_loader_jpegd.cpp
@@ -28,16 +28,15 @@
/*************************************************************************/
#include "image_loader_jpegd.h"
-#include "print_string.h"
#include "os/os.h"
+#include "print_string.h"
#include <jpgd.h>
#include <string.h>
+Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) {
-Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_buffer_len) {
-
- jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer,p_buffer_len);
+ jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer, p_buffer_len);
jpgd::jpeg_decoder decoder(&mem_stream);
@@ -48,8 +47,8 @@ Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_
const int image_width = decoder.get_width();
const int image_height = decoder.get_height();
int comps = decoder.get_num_components();
- if (comps==3)
- comps=4; //weird
+ if (comps == 3)
+ comps = 4; //weird
if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS)
return ERR_FILE_CORRUPT;
@@ -62,42 +61,34 @@ Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_
PoolVector<uint8_t>::Write dw = data.write();
- jpgd::uint8 *pImage_data = (jpgd::uint8*)dw.ptr();
+ jpgd::uint8 *pImage_data = (jpgd::uint8 *)dw.ptr();
- for (int y = 0; y < image_height; y++)
- {
- const jpgd::uint8* pScan_line;
+ for (int y = 0; y < image_height; y++) {
+ const jpgd::uint8 *pScan_line;
jpgd::uint scan_line_len;
- if (decoder.decode((const void**)&pScan_line, &scan_line_len) != jpgd::JPGD_SUCCESS)
- {
+ if (decoder.decode((const void **)&pScan_line, &scan_line_len) != jpgd::JPGD_SUCCESS) {
return ERR_FILE_CORRUPT;
}
jpgd::uint8 *pDst = pImage_data + y * dst_bpl;
memcpy(pDst, pScan_line, dst_bpl);
-
-
}
-
//all good
Image::Format fmt;
- if (comps==1)
- fmt=Image::FORMAT_L8;
+ if (comps == 1)
+ fmt = Image::FORMAT_L8;
else
- fmt=Image::FORMAT_RGBA8;
+ fmt = Image::FORMAT_RGBA8;
dw = PoolVector<uint8_t>::Write();
- p_image->create(image_width,image_height,0,fmt,data);
+ p_image->create(image_width, image_height, 0, fmt, data);
return OK;
-
}
-
-Error ImageLoaderJPG::load_image(Image *p_image,FileAccess *f) {
-
+Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) {
PoolVector<uint8_t> src_image;
int src_image_len = f->get_len();
@@ -106,30 +97,27 @@ Error ImageLoaderJPG::load_image(Image *p_image,FileAccess *f) {
PoolVector<uint8_t>::Write w = src_image.write();
- f->get_buffer(&w[0],src_image_len);
+ f->get_buffer(&w[0], src_image_len);
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, w.ptr(), src_image_len);
w = PoolVector<uint8_t>::Write();
return err;
-
}
void ImageLoaderJPG::get_recognized_extensions(List<String> *p_extensions) const {
-
+
p_extensions->push_back("jpg");
p_extensions->push_back("jpeg");
}
-
-static Image _jpegd_mem_loader_func(const uint8_t* p_png,int p_size) {
+static 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);
+ Error err = jpeg_load_image_from_buffer(&img, p_png, p_size);
if (err)
ERR_PRINT("Couldn't initialize ImageLoaderJPG with the given resource.");
@@ -138,7 +126,5 @@ static Image _jpegd_mem_loader_func(const uint8_t* p_png,int p_size) {
ImageLoaderJPG::ImageLoaderJPG() {
- Image::_jpg_mem_loader_func=_jpegd_mem_loader_func;
+ Image::_jpg_mem_loader_func = _jpegd_mem_loader_func;
}
-
-
diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h
index aeb219aa5d..0803cfba1e 100644
--- a/modules/jpg/image_loader_jpegd.h
+++ b/modules/jpg/image_loader_jpegd.h
@@ -36,14 +36,10 @@
*/
class ImageLoaderJPG : public ImageFormatLoader {
-
public:
-
- virtual Error load_image(Image *p_image,FileAccess *f);
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual Error load_image(Image *p_image, FileAccess *f);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderJPG();
};
-
-
#endif
diff --git a/modules/jpg/register_types.cpp b/modules/jpg/register_types.cpp
index bcd467f5fc..ce0330643a 100644
--- a/modules/jpg/register_types.cpp
+++ b/modules/jpg/register_types.cpp
@@ -34,11 +34,11 @@ static ImageLoaderJPG *image_loader_jpg = NULL;
void register_jpg_types() {
- image_loader_jpg = memnew( ImageLoaderJPG );
+ image_loader_jpg = memnew(ImageLoaderJPG);
ImageLoader::add_image_format_loader(image_loader_jpg);
}
void unregister_jpg_types() {
- memdelete( image_loader_jpg );
+ memdelete(image_loader_jpg);
}
diff --git a/modules/openssl/stream_peer_openssl.cpp b/modules/openssl/stream_peer_openssl.cpp
index 43a1f610d8..3b25b8a50e 100644
--- a/modules/openssl/stream_peer_openssl.cpp
+++ b/modules/openssl/stream_peer_openssl.cpp
@@ -29,12 +29,11 @@
#include "stream_peer_openssl.h"
//hostname matching code from curl
-
//#include <openssl/applink.c> // To prevent crashing (see the OpenSSL FAQ)
bool StreamPeerOpenSSL::_match_host_name(const char *name, const char *hostname) {
- return Tool_Curl_cert_hostcheck(name,hostname)==CURL_HOST_MATCH;
+ return Tool_Curl_cert_hostcheck(name, hostname) == CURL_HOST_MATCH;
//print_line("MATCH: "+String(name)+" vs "+String(hostname));
//return true;
}
@@ -47,36 +46,32 @@ Error StreamPeerOpenSSL::_match_common_name(const char *hostname, const X509 *se
char *common_name_str = NULL;
// Find the position of the CN field in the Subject field of the certificate
- common_name_loc = X509_NAME_get_index_by_NID(X509_get_subject_name((X509 *) server_cert), NID_commonName, -1);
+ common_name_loc = X509_NAME_get_index_by_NID(X509_get_subject_name((X509 *)server_cert), NID_commonName, -1);
- ERR_FAIL_COND_V(common_name_loc < 0, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(common_name_loc < 0, ERR_INVALID_PARAMETER);
// Extract the CN field
- common_name_entry = X509_NAME_get_entry(X509_get_subject_name((X509 *) server_cert), common_name_loc);
+ common_name_entry = X509_NAME_get_entry(X509_get_subject_name((X509 *)server_cert), common_name_loc);
- ERR_FAIL_COND_V(common_name_entry == NULL, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(common_name_entry == NULL, ERR_INVALID_PARAMETER);
// Convert the CN field to a C string
common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry);
- ERR_FAIL_COND_V(common_name_asn1 == NULL, ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(common_name_asn1 == NULL, ERR_INVALID_PARAMETER);
- common_name_str = (char *) ASN1_STRING_data(common_name_asn1);
+ common_name_str = (char *)ASN1_STRING_data(common_name_asn1);
// Make sure there isn't an embedded NUL character in the CN
bool malformed_certificate = (size_t)ASN1_STRING_length(common_name_asn1) != strlen(common_name_str);
- ERR_FAIL_COND_V(malformed_certificate, ERR_INVALID_PARAMETER );
-
+ ERR_FAIL_COND_V(malformed_certificate, ERR_INVALID_PARAMETER);
// Compare expected hostname with the CN
-
- return _match_host_name(common_name_str,hostname)?OK:FAILED;
-
+ return _match_host_name(common_name_str, hostname) ? OK : FAILED;
}
-
/**
* Tries to find a match for hostname in the certificate's Subject Alternative Name extension.
*
@@ -90,26 +85,25 @@ Error StreamPeerOpenSSL::_match_subject_alternative_name(const char *hostname, c
STACK_OF(GENERAL_NAME) *san_names = NULL;
// Try to extract the names within the SAN extension from the certificate
- san_names = (STACK_OF(GENERAL_NAME) *)X509_get_ext_d2i((X509 *) server_cert, NID_subject_alt_name, NULL, NULL);
+ san_names = (STACK_OF(GENERAL_NAME) *)X509_get_ext_d2i((X509 *)server_cert, NID_subject_alt_name, NULL, NULL);
if (san_names == NULL) {
return ERR_FILE_NOT_FOUND;
}
san_names_nb = sk_GENERAL_NAME_num(san_names);
// Check each name within the extension
- for (i=0; i<san_names_nb; i++) {
+ for (i = 0; i < san_names_nb; i++) {
const GENERAL_NAME *current_name = sk_GENERAL_NAME_value(san_names, i);
if (current_name->type == GEN_DNS) {
// Current name is a DNS name, let's check it
- char *dns_name = (char *) ASN1_STRING_data(current_name->d.dNSName);
+ char *dns_name = (char *)ASN1_STRING_data(current_name->d.dNSName);
// Make sure there isn't an embedded NUL character in the DNS name
if ((size_t)ASN1_STRING_length(current_name->d.dNSName) != strlen(dns_name)) {
result = ERR_INVALID_PARAMETER;
break;
- }
- else { // Compare expected hostname with the DNS name
+ } else { // Compare expected hostname with the DNS name
if (_match_host_name(dns_name, hostname)) {
result = OK;
break;
@@ -131,19 +125,19 @@ int StreamPeerOpenSSL::_cert_verify_callback(X509_STORE_CTX *x509_ctx, void *arg
bool base_cert_valid = X509_verify_cert(x509_ctx);
if (!base_cert_valid) {
- print_line("Cause: "+String(X509_verify_cert_error_string(X509_STORE_CTX_get_error(x509_ctx))));
+ print_line("Cause: " + String(X509_verify_cert_error_string(X509_STORE_CTX_get_error(x509_ctx))));
ERR_print_errors_fp(stdout);
}
X509 *server_cert = X509_STORE_CTX_get_current_cert(x509_ctx);
- ERR_FAIL_COND_V(!server_cert,0);
+ ERR_FAIL_COND_V(!server_cert, 0);
char cert_str[256];
- X509_NAME_oneline(X509_get_subject_name (server_cert),
- cert_str, sizeof (cert_str));
+ X509_NAME_oneline(X509_get_subject_name(server_cert),
+ cert_str, sizeof(cert_str));
- print_line("CERT STR: "+String(cert_str));
- print_line("VALID: "+itos(base_cert_valid));
+ print_line("CERT STR: " + String(cert_str));
+ print_line("VALID: " + itos(base_cert_valid));
if (!base_cert_valid)
return 0;
@@ -152,27 +146,24 @@ int StreamPeerOpenSSL::_cert_verify_callback(X509_STORE_CTX *x509_ctx, void *arg
if (ssl->validate_hostname) {
- Error err = _match_subject_alternative_name(ssl->hostname.utf8().get_data(),server_cert);
+ Error err = _match_subject_alternative_name(ssl->hostname.utf8().get_data(), server_cert);
- if (err==ERR_FILE_NOT_FOUND) {
+ if (err == ERR_FILE_NOT_FOUND) {
- err = _match_common_name(ssl->hostname.utf8().get_data(),server_cert);
+ err = _match_common_name(ssl->hostname.utf8().get_data(), server_cert);
}
- if (err!=OK) {
+ if (err != OK) {
- ssl->status=STATUS_ERROR_HOSTNAME_MISMATCH;
+ ssl->status = STATUS_ERROR_HOSTNAME_MISMATCH;
return 0;
}
}
return 1;
-
}
-
-
-int StreamPeerOpenSSL::_bio_create( BIO *b ) {
+int StreamPeerOpenSSL::_bio_create(BIO *b) {
b->init = 1;
b->num = 0;
b->ptr = NULL;
@@ -180,31 +171,29 @@ int StreamPeerOpenSSL::_bio_create( BIO *b ) {
return 1;
}
-int StreamPeerOpenSSL::_bio_destroy( BIO *b )
-{
- if ( b == NULL )
+int StreamPeerOpenSSL::_bio_destroy(BIO *b) {
+ if (b == NULL)
return 0;
- b->ptr = NULL; /* sb_tls_remove() will free it */
+ b->ptr = NULL; /* sb_tls_remove() will free it */
b->init = 0;
b->flags = 0;
return 1;
}
-int StreamPeerOpenSSL::_bio_read( BIO *b, char *buf, int len ) {
+int StreamPeerOpenSSL::_bio_read(BIO *b, char *buf, int len) {
-
- if ( buf == NULL || len <= 0 ) return 0;
+ if (buf == NULL || len <= 0) return 0;
StreamPeerOpenSSL *sp = (StreamPeerOpenSSL *)b->ptr;
- ERR_FAIL_COND_V( sp == NULL, 0);
+ ERR_FAIL_COND_V(sp == NULL, 0);
- BIO_clear_retry_flags( b );
+ BIO_clear_retry_flags(b);
if (sp->use_blocking) {
- Error err = sp->base->get_data((uint8_t*)buf,len);
- if (err!=OK) {
+ Error err = sp->base->get_data((uint8_t *)buf, len);
+ if (err != OK) {
return -1;
}
@@ -212,12 +201,12 @@ int StreamPeerOpenSSL::_bio_read( BIO *b, char *buf, int len ) {
} else {
int got;
- Error err = sp->base->get_partial_data((uint8_t*)buf,len,got);
- if (err!=OK) {
+ Error err = sp->base->get_partial_data((uint8_t *)buf, len, got);
+ if (err != OK) {
return -1;
}
- if (got==0) {
- BIO_set_retry_read( b );
+ if (got == 0) {
+ BIO_set_retry_read(b);
}
return got;
}
@@ -226,19 +215,19 @@ int StreamPeerOpenSSL::_bio_read( BIO *b, char *buf, int len ) {
return 0;
}
-int StreamPeerOpenSSL::_bio_write( BIO *b, const char *buf, int len ) {
+int StreamPeerOpenSSL::_bio_write(BIO *b, const char *buf, int len) {
- if ( buf == NULL || len <= 0 ) return 0;
+ if (buf == NULL || len <= 0) return 0;
StreamPeerOpenSSL *sp = (StreamPeerOpenSSL *)b->ptr;
- ERR_FAIL_COND_V( sp == NULL, 0);
+ ERR_FAIL_COND_V(sp == NULL, 0);
- BIO_clear_retry_flags( b );
+ BIO_clear_retry_flags(b);
if (sp->use_blocking) {
- Error err = sp->base->put_data((const uint8_t*)buf,len);
- if (err!=OK) {
+ Error err = sp->base->put_data((const uint8_t *)buf, len);
+ if (err != OK) {
return -1;
}
@@ -246,43 +235,39 @@ int StreamPeerOpenSSL::_bio_write( BIO *b, const char *buf, int len ) {
} else {
int sent;
- Error err = sp->base->put_partial_data((const uint8_t*)buf,len,sent);
- if (err!=OK) {
+ Error err = sp->base->put_partial_data((const uint8_t *)buf, len, sent);
+ if (err != OK) {
return -1;
}
- if (sent==0) {
- BIO_set_retry_write( b );
+ if (sent == 0) {
+ BIO_set_retry_write(b);
}
return sent;
-
}
//unreachable
return 0;
}
-long StreamPeerOpenSSL::_bio_ctrl( BIO *b, int cmd, long num, void *ptr )
-{
- if ( cmd == BIO_CTRL_FLUSH ) {
+long StreamPeerOpenSSL::_bio_ctrl(BIO *b, int cmd, long num, void *ptr) {
+ if (cmd == BIO_CTRL_FLUSH) {
/* The OpenSSL library needs this */
return 1;
}
return 0;
}
-int StreamPeerOpenSSL::_bio_gets( BIO *b, char *buf, int len )
-{
+int StreamPeerOpenSSL::_bio_gets(BIO *b, char *buf, int len) {
return -1;
}
-int StreamPeerOpenSSL::_bio_puts( BIO *b, const char *str )
-{
- return _bio_write( b, str, strlen( str ) );
+int StreamPeerOpenSSL::_bio_puts(BIO *b, const char *str) {
+ return _bio_write(b, str, strlen(str));
}
BIO_METHOD StreamPeerOpenSSL::_bio_method = {
/* it's a source/sink BIO */
- ( 100 | 0x400 ),
+ (100 | 0x400),
"streampeer glue",
_bio_write,
_bio_read,
@@ -293,35 +278,29 @@ BIO_METHOD StreamPeerOpenSSL::_bio_method = {
_bio_destroy
};
-Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String& p_for_hostname) {
+Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String &p_for_hostname) {
if (connected)
disconnect_from_stream();
-
- hostname=p_for_hostname;
- status=STATUS_DISCONNECTED;
+ hostname = p_for_hostname;
+ status = STATUS_DISCONNECTED;
// Set up a SSL_CTX object, which will tell our BIO object how to do its work
ctx = SSL_CTX_new(SSLv23_client_method());
- base=p_base;
- validate_certs=p_validate_certs;
- validate_hostname=p_for_hostname!="";
-
-
-
+ base = p_base;
+ validate_certs = p_validate_certs;
+ validate_hostname = p_for_hostname != "";
if (p_validate_certs) {
-
if (certs.size()) {
//yay for undocumented OpenSSL functions
X509_STORE *store = SSL_CTX_get_cert_store(ctx);
- for(int i=0;i<certs.size();i++) {
-
- X509_STORE_add_cert(store,certs[i]);
+ for (int i = 0; i < certs.size(); i++) {
+ X509_STORE_add_cert(store, certs[i]);
}
#if 0
const unsigned char *in=(const unsigned char *)certs.ptr();
@@ -343,7 +322,6 @@ Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida
//int res = SSL_CTX_load_verify_locations(ctx,"/etc/ssl/certs/ca-certificates.crt",NULL);
//print_line("verify locations res: "+itos(res));
-
/* Ask OpenSSL to verify the server certificate. Note that this
* does NOT include verifying that the hostname is correct.
* So, by itself, this means anyone with any legitimate
@@ -366,183 +344,176 @@ Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida
* OpenSSL's built-in routine which would have been called if
* we hadn't set the callback. Therefore, we're just
* "wrapping" OpenSSL's routine, not replacing it. */
- SSL_CTX_set_cert_verify_callback (ctx, _cert_verify_callback,this);
+ SSL_CTX_set_cert_verify_callback(ctx, _cert_verify_callback, this);
//Let the verify_callback catch the verify_depth error so that we get an appropriate error in the logfile. (??)
- SSL_CTX_set_verify_depth(ctx,max_cert_chain_depth + 1);
-
+ SSL_CTX_set_verify_depth(ctx, max_cert_chain_depth + 1);
}
-
-
-
-
- ssl = SSL_new( ctx );
- bio = BIO_new( &_bio_method );
+ ssl = SSL_new(ctx);
+ bio = BIO_new(&_bio_method);
bio->ptr = this;
- SSL_set_bio( ssl, bio, bio );
+ SSL_set_bio(ssl, bio, bio);
- if (p_for_hostname!=String()) {
- SSL_set_tlsext_host_name(ssl,p_for_hostname.utf8().get_data());
+ if (p_for_hostname != String()) {
+ SSL_set_tlsext_host_name(ssl, p_for_hostname.utf8().get_data());
}
- use_blocking=true; // let handshake use blocking
+ use_blocking = true; // let handshake use blocking
// Set the SSL to automatically retry on failure.
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
// Same as before, try to connect.
- int result = SSL_connect( ssl );
+ int result = SSL_connect(ssl);
- print_line("CONNECTION RESULT: "+itos(result));
- if (result<1) {
+ print_line("CONNECTION RESULT: " + itos(result));
+ if (result < 1) {
ERR_print_errors_fp(stdout);
_print_error(result);
}
- X509 * peer = SSL_get_peer_certificate(ssl);
+ X509 *peer = SSL_get_peer_certificate(ssl);
if (peer) {
bool cert_ok = SSL_get_verify_result(ssl) == X509_V_OK;
- print_line("cert_ok: "+itos(cert_ok));
+ print_line("cert_ok: " + itos(cert_ok));
- } else if (validate_certs){
- status=STATUS_ERROR_NO_CERTIFICATE;
+ } else if (validate_certs) {
+ status = STATUS_ERROR_NO_CERTIFICATE;
}
- connected=true;
- status=STATUS_CONNECTED;
+ connected = true;
+ status = STATUS_CONNECTED;
return OK;
}
Error StreamPeerOpenSSL::accept_stream(Ref<StreamPeer> p_base) {
-
return ERR_UNAVAILABLE;
}
void StreamPeerOpenSSL::_print_error(int err) {
- err = SSL_get_error(ssl,err);
- switch(err) {
+ err = SSL_get_error(ssl, err);
+ switch (err) {
case SSL_ERROR_NONE: ERR_PRINT("NO ERROR: The TLS/SSL I/O operation completed"); break;
case SSL_ERROR_ZERO_RETURN: ERR_PRINT("The TLS/SSL connection has been closed.");
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
- ERR_PRINT("The operation did not complete."); break;
+ ERR_PRINT("The operation did not complete.");
+ break;
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
- ERR_PRINT("The connect/accept operation did not complete"); break;
+ ERR_PRINT("The connect/accept operation did not complete");
+ break;
case SSL_ERROR_WANT_X509_LOOKUP:
- ERR_PRINT("The operation did not complete because an application callback set by SSL_CTX_set_client_cert_cb() has asked to be called again."); break;
+ ERR_PRINT("The operation did not complete because an application callback set by SSL_CTX_set_client_cert_cb() has asked to be called again.");
+ break;
case SSL_ERROR_SYSCALL:
- ERR_PRINT("Some I/O error occurred. The OpenSSL error queue may contain more information on the error."); break;
+ ERR_PRINT("Some I/O error occurred. The OpenSSL error queue may contain more information on the error.");
+ break;
case SSL_ERROR_SSL:
- ERR_PRINT("A failure in the SSL library occurred, usually a protocol error."); break;
-
+ ERR_PRINT("A failure in the SSL library occurred, usually a protocol error.");
+ break;
}
}
-Error StreamPeerOpenSSL::put_data(const uint8_t* p_data,int p_bytes) {
+Error StreamPeerOpenSSL::put_data(const uint8_t *p_data, int p_bytes) {
- ERR_FAIL_COND_V(!connected,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED);
- while(p_bytes>0) {
- int ret = SSL_write(ssl,p_data,p_bytes);
- if (ret<=0) {
+ while (p_bytes > 0) {
+ int ret = SSL_write(ssl, p_data, p_bytes);
+ if (ret <= 0) {
_print_error(ret);
disconnect_from_stream();
return ERR_CONNECTION_ERROR;
}
- p_data+=ret;
- p_bytes-=ret;
+ p_data += ret;
+ p_bytes -= ret;
}
return OK;
-
}
-Error StreamPeerOpenSSL::put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent){
+Error StreamPeerOpenSSL::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
- ERR_FAIL_COND_V(!connected,ERR_UNCONFIGURED);
- if (p_bytes==0)
+ ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED);
+ if (p_bytes == 0)
return OK;
- Error err = put_data(p_data,p_bytes);
- if (err!=OK)
+ Error err = put_data(p_data, p_bytes);
+ if (err != OK)
return err;
- r_sent=p_bytes;
+ r_sent = p_bytes;
return OK;
-
}
-Error StreamPeerOpenSSL::get_data(uint8_t* p_buffer, int p_bytes){
+Error StreamPeerOpenSSL::get_data(uint8_t *p_buffer, int p_bytes) {
- ERR_FAIL_COND_V(!connected,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED);
- while(p_bytes>0) {
+ while (p_bytes > 0) {
- int ret = SSL_read(ssl,p_buffer,p_bytes);
- if (ret<=0) {
+ int ret = SSL_read(ssl, p_buffer, p_bytes);
+ if (ret <= 0) {
_print_error(ret);
disconnect_from_stream();
return ERR_CONNECTION_ERROR;
}
- p_buffer+=ret;
- p_bytes-=ret;
+ p_buffer += ret;
+ p_bytes -= ret;
}
return OK;
}
-Error StreamPeerOpenSSL::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received){
+Error StreamPeerOpenSSL::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
- ERR_FAIL_COND_V(!connected,ERR_UNCONFIGURED);
- if (p_bytes==0) {
- r_received=0;
+ ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED);
+ if (p_bytes == 0) {
+ r_received = 0;
return OK;
}
- Error err = get_data(p_buffer,p_bytes);
- if (err!=OK)
+ Error err = get_data(p_buffer, p_bytes);
+ if (err != OK)
return err;
- r_received=p_bytes;
+ r_received = p_bytes;
return OK;
}
int StreamPeerOpenSSL::get_available_bytes() const {
- ERR_FAIL_COND_V(!connected,0);
+ ERR_FAIL_COND_V(!connected, 0);
return SSL_pending(ssl);
-
}
StreamPeerOpenSSL::StreamPeerOpenSSL() {
- ctx=NULL;
- ssl=NULL;
- bio=NULL;
- connected=false;
- use_blocking=true; //might be improved int the future, but for now it always blocks
- max_cert_chain_depth=9;
- flags=0;
+ ctx = NULL;
+ ssl = NULL;
+ bio = NULL;
+ connected = false;
+ use_blocking = true; //might be improved int the future, but for now it always blocks
+ max_cert_chain_depth = 9;
+ flags = 0;
}
void StreamPeerOpenSSL::disconnect_from_stream() {
if (!connected)
return;
- SSL_shutdown( ssl );
- SSL_free( ssl );
+ SSL_shutdown(ssl);
+ SSL_free(ssl);
SSL_CTX_free(ctx);
- base=Ref<StreamPeer>();
- connected=false;
- validate_certs=false;
- validate_hostname=false;
- status=STATUS_DISCONNECTED;
-
-
+ base = Ref<StreamPeer>();
+ connected = false;
+ validate_certs = false;
+ validate_hostname = false;
+ status = STATUS_DISCONNECTED;
}
StreamPeerOpenSSL::Status StreamPeerOpenSSL::get_status() const {
@@ -550,27 +521,24 @@ StreamPeerOpenSSL::Status StreamPeerOpenSSL::get_status() const {
return status;
}
-
StreamPeerOpenSSL::~StreamPeerOpenSSL() {
disconnect_from_stream();
}
-StreamPeerSSL* StreamPeerOpenSSL::_create_func() {
+StreamPeerSSL *StreamPeerOpenSSL::_create_func() {
- return memnew( StreamPeerOpenSSL );
+ return memnew(StreamPeerOpenSSL);
}
+Vector<X509 *> StreamPeerOpenSSL::certs;
-Vector<X509*> StreamPeerOpenSSL::certs;
-
-
-void StreamPeerOpenSSL::_load_certs(const PoolByteArray& p_array) {
+void StreamPeerOpenSSL::_load_certs(const PoolByteArray &p_array) {
PoolByteArray::Read r = p_array.read();
- BIO* mem = BIO_new(BIO_s_mem());
- BIO_puts(mem,(const char*)r.ptr());
- while(true) {
- X509*cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
+ BIO *mem = BIO_new(BIO_s_mem());
+ BIO_puts(mem, (const char *)r.ptr());
+ while (true) {
+ X509 *cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
if (!cert)
break;
certs.push_back(cert);
@@ -580,66 +548,62 @@ void StreamPeerOpenSSL::_load_certs(const PoolByteArray& p_array) {
void StreamPeerOpenSSL::initialize_ssl() {
- available=true;
+ available = true;
- load_certs_func=_load_certs;
+ load_certs_func = _load_certs;
- _create=_create_func;
+ _create = _create_func;
CRYPTO_malloc_init(); // Initialize malloc, free, etc for OpenSSL's use
SSL_library_init(); // Initialize OpenSSL's SSL libraries
SSL_load_error_strings(); // Load SSL error strings
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"));
- if (certs_path!="") {
-
-
+ 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"));
+ if (certs_path != "") {
- FileAccess *f=FileAccess::open(certs_path,FileAccess::READ);
+ FileAccess *f = FileAccess::open(certs_path, FileAccess::READ);
if (f) {
PoolByteArray arr;
int flen = f->get_len();
- arr.resize(flen+1);
+ arr.resize(flen + 1);
{
PoolByteArray::Write w = arr.write();
- f->get_buffer(w.ptr(),flen);
- w[flen]=0; //end f string
+ f->get_buffer(w.ptr(), flen);
+ w[flen] = 0; //end f string
}
memdelete(f);
_load_certs(arr);
- print_line("Loaded certs from '"+certs_path+"': "+itos(certs.size()));
+ print_line("Loaded certs from '" + certs_path + "': " + itos(certs.size()));
}
}
- 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"));
- if (config_path!="") {
+ 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"));
+ if (config_path != "") {
Vector<uint8_t> data = FileAccess::get_file_as_array(config_path);
if (data.size()) {
data.push_back(0);
- BIO* mem = BIO_new(BIO_s_mem());
- BIO_puts(mem,(const char*) data.ptr());
+ BIO *mem = BIO_new(BIO_s_mem());
+ BIO_puts(mem, (const char *)data.ptr());
- while(true) {
- X509*cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
+ while (true) {
+ X509 *cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
if (!cert)
break;
certs.push_back(cert);
}
BIO_free(mem);
}
- print_line("Loaded certs from '"+certs_path+"': "+itos(certs.size()));
-
+ print_line("Loaded certs from '" + certs_path + "': " + itos(certs.size()));
}
-
}
-void StreamPeerOpenSSL::finalize_ssl(){
+void StreamPeerOpenSSL::finalize_ssl() {
- for(int i=0;i<certs.size();i++) {
+ for (int i = 0; i < certs.size(); i++) {
X509_free(certs[i]);
}
certs.clear();
diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h
index 84ae03fe07..56b45802df 100644
--- a/modules/openssl/stream_peer_openssl.h
+++ b/modules/openssl/stream_peer_openssl.h
@@ -29,26 +29,26 @@
#ifndef STREAM_PEER_OPEN_SSL_H
#define STREAM_PEER_OPEN_SSL_H
-#include <stdio.h> // If you don't know what this is for stop reading now.
-#include "io/stream_peer_ssl.h"
+#include "curl_hostcheck.h"
#include "global_config.h"
+#include "io/stream_peer_ssl.h"
#include "os/file_access.h"
-#include "curl_hostcheck.h"
+#include <stdio.h> // If you don't know what this is for stop reading now.
#include <openssl/bio.h> // BIO objects for I/O
-#include <openssl/ssl.h> // SSL and SSL_CTX for SSL connections
#include <openssl/err.h> // Error reporting
+#include <openssl/ssl.h> // SSL and SSL_CTX for SSL connections
#include <openssl/x509v3.h>
class StreamPeerOpenSSL : public StreamPeerSSL {
private:
- static int _bio_create( BIO *b );
- static int _bio_destroy( BIO *b );
- static int _bio_read( BIO *b, char *buf, int len );
- static int _bio_write( BIO *b, const char *buf, int len );
- static long _bio_ctrl( BIO *b, int cmd, long num, void *ptr );
- static int _bio_gets( BIO *b, char *buf, int len );
- static int _bio_puts( BIO *b, const char *str );
+ static int _bio_create(BIO *b);
+ static int _bio_destroy(BIO *b);
+ static int _bio_read(BIO *b, char *buf, int len);
+ static int _bio_write(BIO *b, const char *buf, int len);
+ static long _bio_ctrl(BIO *b, int cmd, long num, void *ptr);
+ static int _bio_gets(BIO *b, char *buf, int len);
+ static int _bio_puts(BIO *b, const char *str);
static BIO_METHOD _bio_method;
@@ -56,16 +56,14 @@ private:
static Error _match_common_name(const char *hostname, const X509 *server_cert);
static Error _match_subject_alternative_name(const char *hostname, const X509 *server_cert);
-
static int _cert_verify_callback(X509_STORE_CTX *x509_ctx, void *arg);
-
Status status;
String hostname;
int max_cert_chain_depth;
- SSL_CTX* ctx;
- SSL* ssl;
- BIO* bio;
+ SSL_CTX *ctx;
+ SSL *ssl;
+ BIO *bio;
bool connected;
int flags;
bool use_blocking;
@@ -74,28 +72,28 @@ private:
Ref<StreamPeer> base;
- static StreamPeerSSL* _create_func();
+ static StreamPeerSSL *_create_func();
void _print_error(int err);
- static Vector<X509*> certs;
+ static Vector<X509 *> certs;
+
+ static void _load_certs(const PoolByteArray &p_array);
- static void _load_certs(const PoolByteArray& p_array);
protected:
static void _bind_methods();
-public:
-
+public:
virtual Error accept_stream(Ref<StreamPeer> p_base);
- virtual Error connect_to_stream(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String());
+ virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String());
virtual Status get_status() const;
virtual void disconnect_from_stream();
- virtual Error put_data(const uint8_t* p_data,int p_bytes);
- virtual Error put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent);
+ virtual Error put_data(const uint8_t *p_data, int p_bytes);
+ virtual Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
- virtual Error get_data(uint8_t* p_buffer, int p_bytes);
- virtual Error get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received);
+ virtual Error get_data(uint8_t *p_buffer, int p_bytes);
+ virtual Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
virtual int get_available_bytes() const;
diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp
index 4a6b2e224c..52b055ca82 100644
--- a/modules/opus/audio_stream_opus.cpp
+++ b/modules/opus/audio_stream_opus.cpp
@@ -30,32 +30,32 @@
/*************************************************************************/
#include "audio_stream_opus.h"
-const float AudioStreamPlaybackOpus::osrate=48000.0f;
+const float AudioStreamPlaybackOpus::osrate = 48000.0f;
int AudioStreamPlaybackOpus::_op_read_func(void *_stream, unsigned char *_ptr, int _nbytes) {
- FileAccess *fa=(FileAccess*)_stream;
+ FileAccess *fa = (FileAccess *)_stream;
- if(fa->eof_reached())
+ if (fa->eof_reached())
return 0;
- uint8_t *dst = (uint8_t*)_ptr;
+ uint8_t *dst = (uint8_t *)_ptr;
int read = fa->get_buffer(dst, _nbytes);
return read;
}
-int AudioStreamPlaybackOpus::_op_seek_func(void *_stream, opus_int64 _offset, int _whence){
+int AudioStreamPlaybackOpus::_op_seek_func(void *_stream, opus_int64 _offset, int _whence) {
#ifdef SEEK_SET
- FileAccess *fa=(FileAccess*)_stream;
+ FileAccess *fa = (FileAccess *)_stream;
switch (_whence) {
case SEEK_SET: {
fa->seek(_offset);
} break;
case SEEK_CUR: {
- fa->seek(fa->get_pos()+_offset);
+ fa->seek(fa->get_pos() + _offset);
} break;
case SEEK_END: {
fa->seek_end(_offset);
@@ -64,7 +64,7 @@ int AudioStreamPlaybackOpus::_op_seek_func(void *_stream, opus_int64 _offset, in
ERR_PRINT("BUG, wtf was whence set to?\n");
}
}
- int ret=fa->eof_reached()?-1:0;
+ int ret = fa->eof_reached() ? -1 : 0;
return ret;
#else
return -1; // no seeking
@@ -74,97 +74,100 @@ int AudioStreamPlaybackOpus::_op_seek_func(void *_stream, opus_int64 _offset, in
int AudioStreamPlaybackOpus::_op_close_func(void *_stream) {
if (!_stream)
return 0;
- FileAccess *fa=(FileAccess*)_stream;
+ FileAccess *fa = (FileAccess *)_stream;
if (fa->is_open())
fa->close();
return 0;
}
opus_int64 AudioStreamPlaybackOpus::_op_tell_func(void *_stream) {
- FileAccess *_fa = (FileAccess*)_stream;
+ FileAccess *_fa = (FileAccess *)_stream;
return (opus_int64)_fa->get_pos();
}
void AudioStreamPlaybackOpus::_clear_stream() {
- if(!stream_loaded)
+ if (!stream_loaded)
return;
op_free(opus_file);
_close_file();
- stream_loaded=false;
- stream_channels=1;
- playing=false;
+ stream_loaded = false;
+ stream_channels = 1;
+ playing = false;
}
void AudioStreamPlaybackOpus::_close_file() {
if (f) {
memdelete(f);
- f=NULL;
+ f = NULL;
}
}
Error AudioStreamPlaybackOpus::_load_stream() {
- ERR_FAIL_COND_V(!stream_valid,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!stream_valid, ERR_UNCONFIGURED);
_clear_stream();
- if (file=="")
+ if (file == "")
return ERR_INVALID_DATA;
Error err;
- f=FileAccess::open(file,FileAccess::READ,&err);
+ f = FileAccess::open(file, FileAccess::READ, &err);
if (err) {
- ERR_FAIL_COND_V( err, err );
+ ERR_FAIL_COND_V(err, err);
}
int _err = 0;
- opus_file = op_open_callbacks(f,&_op_callbacks,NULL,0,&_err);
+ opus_file = op_open_callbacks(f, &_op_callbacks, NULL, 0, &_err);
switch (_err) {
case OP_EREAD: { // - Can't read the file.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CANT_READ );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CANT_READ);
} break;
case OP_EVERSION: // - Unrecognized version number.
case OP_ENOTFORMAT: // - Stream is not Opus data.
- case OP_EIMPL : { // - Stream used non-implemented feature.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_UNRECOGNIZED );
+ case OP_EIMPL: { // - Stream used non-implemented feature.
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
} break;
case OP_EBADLINK: // - Failed to find old data after seeking.
case OP_EBADTIMESTAMP: // - Timestamp failed the validity checks.
case OP_EBADHEADER: { // - Invalid or mising Opus bitstream header.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CORRUPT );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
case OP_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_BUG );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_BUG);
} break;
}
- repeats=0;
- stream_loaded=true;
-
+ repeats = 0;
+ stream_loaded = true;
return OK;
}
AudioStreamPlaybackOpus::AudioStreamPlaybackOpus() {
- loops=false;
- playing=false;
+ loops = false;
+ playing = false;
f = NULL;
- stream_loaded=false;
- stream_valid=false;
- repeats=0;
- paused=true;
- stream_channels=0;
- current_section=0;
- length=0;
- loop_restart_time=0;
- pre_skip=0;
+ stream_loaded = false;
+ stream_valid = false;
+ repeats = 0;
+ paused = true;
+ stream_channels = 0;
+ current_section = 0;
+ length = 0;
+ loop_restart_time = 0;
+ pre_skip = 0;
_op_callbacks.read = _op_read_func;
_op_callbacks.seek = _op_seek_func;
@@ -173,59 +176,62 @@ AudioStreamPlaybackOpus::AudioStreamPlaybackOpus() {
}
Error AudioStreamPlaybackOpus::set_file(const String &p_file) {
- file=p_file;
- stream_valid=false;
+ file = p_file;
+ stream_valid = false;
Error err;
- f=FileAccess::open(file,FileAccess::READ,&err);
+ f = FileAccess::open(file, FileAccess::READ, &err);
if (err) {
- ERR_FAIL_COND_V( err, err );
+ ERR_FAIL_COND_V(err, err);
}
int _err;
- opus_file = op_open_callbacks(f,&_op_callbacks,NULL,0,&_err);
+ opus_file = op_open_callbacks(f, &_op_callbacks, NULL, 0, &_err);
switch (_err) {
case OP_EREAD: { // - Can't read the file.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CANT_READ );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CANT_READ);
} break;
case OP_EVERSION: // - Unrecognized version number.
case OP_ENOTFORMAT: // - Stream is not Opus data.
- case OP_EIMPL : { // - Stream used non-implemented feature.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_UNRECOGNIZED );
+ case OP_EIMPL: { // - Stream used non-implemented feature.
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
} break;
case OP_EBADLINK: // - Failed to find old data after seeking.
case OP_EBADTIMESTAMP: // - Timestamp failed the validity checks.
case OP_EBADHEADER: { // - Invalid or mising Opus bitstream header.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CORRUPT );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
case OP_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_BUG );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_BUG);
} break;
}
- const OpusHead *oinfo = op_head(opus_file,-1);
+ const OpusHead *oinfo = op_head(opus_file, -1);
- stream_channels=oinfo->channel_count;
- pre_skip=oinfo->pre_skip;
- frames_mixed=pre_skip;
- ogg_int64_t len = op_pcm_total(opus_file,-1);
- if(len < 0) {
+ stream_channels = oinfo->channel_count;
+ pre_skip = oinfo->pre_skip;
+ frames_mixed = pre_skip;
+ ogg_int64_t len = op_pcm_total(opus_file, -1);
+ if (len < 0) {
length = 0;
} else {
- length=(len/osrate);
+ length = (len / osrate);
}
op_free(opus_file);
memdelete(f);
- f=NULL;
- stream_valid=true;
-
+ f = NULL;
+ stream_valid = true;
return OK;
}
@@ -234,102 +240,100 @@ void AudioStreamPlaybackOpus::play(float p_from) {
if (playing)
stop();
- if (_load_stream()!=OK)
+ if (_load_stream() != OK)
return;
- frames_mixed=pre_skip;
- playing=true;
- if (p_from>0) {
+ frames_mixed = pre_skip;
+ playing = true;
+ if (p_from > 0) {
seek_pos(p_from);
}
}
void AudioStreamPlaybackOpus::stop() {
_clear_stream();
- playing=false;
+ playing = false;
}
void AudioStreamPlaybackOpus::seek_pos(float p_time) {
- if(!playing) return;
+ if (!playing) return;
ogg_int64_t pcm_offset = (ogg_int64_t)(p_time * osrate);
- bool ok = op_pcm_seek(opus_file,pcm_offset)==0;
- if(!ok) {
+ bool ok = op_pcm_seek(opus_file, pcm_offset) == 0;
+ if (!ok) {
ERR_PRINT("Seek time over stream size.");
return;
}
- frames_mixed=osrate*p_time;
+ frames_mixed = osrate * p_time;
}
-int AudioStreamPlaybackOpus::mix(int16_t* p_bufer,int p_frames) {
+int AudioStreamPlaybackOpus::mix(int16_t *p_bufer, int p_frames) {
if (!playing)
return 0;
- int total=p_frames;
+ int total = p_frames;
while (true) {
int todo = p_frames;
- if (todo==0 || todo<MIN_MIX) {
+ if (todo == 0 || todo < MIN_MIX) {
break;
}
- int ret=op_read(opus_file,(opus_int16*)p_bufer,todo*stream_channels,&current_section);
- if (ret<0) {
+ int ret = op_read(opus_file, (opus_int16 *)p_bufer, todo * stream_channels, &current_section);
+ if (ret < 0) {
playing = false;
- ERR_EXPLAIN("Error reading Opus File: "+file);
- ERR_BREAK(ret<0);
- } else if (ret==0) { // end of song, reload?
+ ERR_EXPLAIN("Error reading Opus File: " + file);
+ ERR_BREAK(ret < 0);
+ } else if (ret == 0) { // end of song, reload?
op_free(opus_file);
_close_file();
- f=FileAccess::open(file,FileAccess::READ);
+ f = FileAccess::open(file, FileAccess::READ);
int errv = 0;
- opus_file = op_open_callbacks(f,&_op_callbacks,NULL,0,&errv);
- if (errv!=0) {
- playing=false;
+ opus_file = op_open_callbacks(f, &_op_callbacks, NULL, 0, &errv);
+ if (errv != 0) {
+ playing = false;
break; // :(
}
if (!has_loop()) {
- playing=false;
- repeats=1;
+ playing = false;
+ repeats = 1;
break;
}
if (loop_restart_time) {
- bool ok = op_pcm_seek(opus_file, (loop_restart_time*osrate)+pre_skip)==0;
+ bool ok = op_pcm_seek(opus_file, (loop_restart_time * osrate) + pre_skip) == 0;
if (!ok) {
- playing=false;
+ playing = false;
ERR_PRINT("loop restart time rejected")
}
- frames_mixed=(loop_restart_time*osrate)+pre_skip;
+ frames_mixed = (loop_restart_time * osrate) + pre_skip;
} else {
- frames_mixed=pre_skip;
+ frames_mixed = pre_skip;
}
repeats++;
continue;
-
}
- stream_channels=op_head(opus_file,current_section)->channel_count;
-
- frames_mixed+=ret;
+ stream_channels = op_head(opus_file, current_section)->channel_count;
- p_bufer+=ret*stream_channels;
- p_frames-=ret;
+ frames_mixed += ret;
+ p_bufer += ret * stream_channels;
+ p_frames -= ret;
}
- return total-p_frames;
+ return total - p_frames;
}
float AudioStreamPlaybackOpus::get_length() const {
- if(!stream_loaded) {
- if(const_cast<AudioStreamPlaybackOpus*>(this)->_load_stream() != OK)
+ if (!stream_loaded) {
+ if (const_cast<AudioStreamPlaybackOpus *>(this)->_load_stream() != OK)
return 0;
}
return length;
@@ -339,7 +343,7 @@ float AudioStreamPlaybackOpus::get_pos() const {
int32_t frames = int32_t(frames_mixed);
if (frames < 0)
- frames=0;
+ frames = 0;
return double(frames) / osrate;
}
@@ -351,9 +355,9 @@ AudioStreamPlaybackOpus::~AudioStreamPlaybackOpus() {
_clear_stream();
}
-RES ResourceFormatLoaderAudioStreamOpus::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatLoaderAudioStreamOpus::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=OK;
+ *r_error = OK;
AudioStreamOpus *opus_stream = memnew(AudioStreamOpus);
opus_stream->set_file(p_path);
@@ -366,11 +370,11 @@ void ResourceFormatLoaderAudioStreamOpus::get_recognized_extensions(List<String>
}
String ResourceFormatLoaderAudioStreamOpus::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="opus")
+ if (p_path.get_extension().to_lower() == "opus")
return "AudioStreamOpus";
return "";
}
-bool ResourceFormatLoaderAudioStreamOpus::handles_type(const String& p_type) const {
- return (p_type=="AudioStream" || p_type=="AudioStreamOpus");
+bool ResourceFormatLoaderAudioStreamOpus::handles_type(const String &p_type) const {
+ return (p_type == "AudioStream" || p_type == "AudioStreamOpus");
}
diff --git a/modules/opus/audio_stream_opus.h b/modules/opus/audio_stream_opus.h
index 5093456ccd..f1bee121b2 100644
--- a/modules/opus/audio_stream_opus.h
+++ b/modules/opus/audio_stream_opus.h
@@ -40,10 +40,10 @@
class AudioStreamPlaybackOpus : public AudioStreamPlayback {
- GDCLASS(AudioStreamPlaybackOpus,AudioStreamPlayback)
+ GDCLASS(AudioStreamPlaybackOpus, AudioStreamPlayback)
enum {
- MIN_MIX=1024
+ MIN_MIX = 1024
};
FileAccess *f;
@@ -78,19 +78,19 @@ class AudioStreamPlaybackOpus : public AudioStreamPlayback {
float loop_restart_time;
public:
- Error set_file(const String& p_file);
+ Error set_file(const String &p_file);
- virtual void play(float p_from=0);
+ virtual void play(float p_from = 0);
virtual void stop();
virtual bool is_playing() const { return playing; }
- virtual void set_loop_restart_time(float p_time) { loop_restart_time=p_time; }
+ virtual void set_loop_restart_time(float p_time) { loop_restart_time = p_time; }
- virtual void set_paused(bool p_paused) { paused=p_paused; }
+ virtual void set_paused(bool p_paused) { paused = p_paused; }
virtual bool is_paused() const { return paused; }
- virtual void set_loop(bool p_enable) { loops=p_enable; }
- virtual bool has_loop() const {return loops; }
+ virtual void set_loop(bool p_enable) { loops = p_enable; }
+ virtual bool has_loop() const { return loops; }
virtual float get_length() const;
@@ -106,35 +106,33 @@ public:
virtual int get_minimum_buffer_size() const;
- virtual int mix(int16_t* p_bufer,int p_frames);
+ virtual int mix(int16_t *p_bufer, int p_frames);
AudioStreamPlaybackOpus();
~AudioStreamPlaybackOpus();
};
+class AudioStreamOpus : public AudioStream {
-class AudioStreamOpus: public AudioStream {
-
- GDCLASS(AudioStreamOpus,AudioStream)
+ GDCLASS(AudioStreamOpus, AudioStream)
String file;
-public:
+public:
Ref<AudioStreamPlayback> instance_playback() {
- Ref<AudioStreamPlaybackOpus> pb = memnew( AudioStreamPlaybackOpus );
+ Ref<AudioStreamPlaybackOpus> pb = memnew(AudioStreamPlaybackOpus);
pb->set_file(file);
return pb;
}
- void set_file(const String& p_file) { file=p_file; }
-
+ void set_file(const String &p_file) { file = p_file; }
};
-class ResourceFormatLoaderAudioStreamOpus: public ResourceFormatLoader {
+class ResourceFormatLoaderAudioStreamOpus : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
diff --git a/modules/opus/register_types.cpp b/modules/opus/register_types.cpp
index a177bc9463..8a48c5084e 100644
--- a/modules/opus/register_types.cpp
+++ b/modules/opus/register_types.cpp
@@ -34,12 +34,12 @@ static ResourceFormatLoaderAudioStreamOpus *opus_stream_loader = NULL;
void register_opus_types() {
- opus_stream_loader = memnew( ResourceFormatLoaderAudioStreamOpus );
+ opus_stream_loader = memnew(ResourceFormatLoaderAudioStreamOpus);
ResourceLoader::add_resource_format_loader(opus_stream_loader);
ClassDB::register_class<AudioStreamOpus>();
}
void unregister_opus_types() {
- memdelete( opus_stream_loader );
+ memdelete(opus_stream_loader);
}
diff --git a/modules/pbm/bitmap_loader_pbm.cpp b/modules/pbm/bitmap_loader_pbm.cpp
index ab0805a6b0..04051fc38f 100644
--- a/modules/pbm/bitmap_loader_pbm.cpp
+++ b/modules/pbm/bitmap_loader_pbm.cpp
@@ -30,30 +30,27 @@
#include "os/file_access.h"
#include "scene/resources/bit_mask.h"
-
-static bool _get_token(FileAccessRef& f,uint8_t &saved,PoolVector<uint8_t>& r_token,bool p_binary=false,bool p_single_chunk=false) {
-
+static bool _get_token(FileAccessRef &f, uint8_t &saved, PoolVector<uint8_t> &r_token, bool p_binary = false, bool p_single_chunk = false) {
int token_max = r_token.size();
PoolVector<uint8_t>::Write w;
if (token_max)
- w=r_token.write();
- int ofs=0;
- bool lf=false;
-
+ w = r_token.write();
+ int ofs = 0;
+ bool lf = false;
- while(true) {
+ while (true) {
uint8_t b;
if (saved) {
- b=saved;
- saved=0;
+ b = saved;
+ saved = 0;
} else {
b = f->get_8();
}
if (f->eof_reached()) {
if (ofs) {
- w=PoolVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
r_token.resize(ofs);
return true;
} else {
@@ -61,9 +58,9 @@ static bool _get_token(FileAccessRef& f,uint8_t &saved,PoolVector<uint8_t>& r_to
}
}
- if (!ofs && !p_binary && b=='#') {
+ if (!ofs && !p_binary && b == '#') {
//skip comment
- while(b!='\n') {
+ while (b != '\n') {
if (f->eof_reached()) {
return false;
}
@@ -71,182 +68,165 @@ static bool _get_token(FileAccessRef& f,uint8_t &saved,PoolVector<uint8_t>& r_to
b = f->get_8();
}
- lf=true;
+ lf = true;
- } else if (b<=32 && !(p_binary && (ofs || lf))) {
+ } else if (b <= 32 && !(p_binary && (ofs || lf))) {
- if (b=='\n') {
- lf=true;
+ if (b == '\n') {
+ lf = true;
}
-
if (ofs && !p_single_chunk) {
- w=PoolVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
r_token.resize(ofs);
- saved=b;
+ saved = b;
return true;
}
} else {
- bool resized=false;
- while (ofs>=token_max) {
+ bool resized = false;
+ while (ofs >= token_max) {
if (token_max)
- token_max<<=1;
+ token_max <<= 1;
else
- token_max=1;
- resized=true;
+ token_max = 1;
+ resized = true;
}
if (resized) {
- w=PoolVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
r_token.resize(token_max);
- w=r_token.write();
+ w = r_token.write();
}
- w[ofs++]=b;
+ w[ofs++] = b;
}
}
return false;
}
-static int _get_number_from_token(PoolVector<uint8_t>& r_token) {
+static int _get_number_from_token(PoolVector<uint8_t> &r_token) {
int len = r_token.size();
PoolVector<uint8_t>::Read r = r_token.read();
- return String::to_int((const char*)r.ptr(),len);
-
+ return String::to_int((const char *)r.ptr(), len);
}
+RES ResourceFormatPBM::load(const String &p_path, const String &p_original_path, Error *r_error) {
-RES ResourceFormatPBM::load(const String &p_path,const String& p_original_path,Error *r_error) {
-
-#define _RETURN(m_err)\
-{\
- if (r_error)\
- *r_error=m_err;\
- ERR_FAIL_V(RES());\
-}
-
+#define _RETURN(m_err) \
+ { \
+ if (r_error) \
+ *r_error = m_err; \
+ ERR_FAIL_V(RES()); \
+ }
- FileAccessRef f=FileAccess::open(p_path,FileAccess::READ);
- uint8_t saved=0;
+ FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
+ uint8_t saved = 0;
if (!f)
_RETURN(ERR_CANT_OPEN);
PoolVector<uint8_t> token;
- if (!_get_token(f,saved,token)) {
+ if (!_get_token(f, saved, token)) {
_RETURN(ERR_PARSE_ERROR);
}
- if (token.size()!=2) {
+ if (token.size() != 2) {
_RETURN(ERR_FILE_CORRUPT);
}
- if (token[0]!='P') {
+ if (token[0] != 'P') {
_RETURN(ERR_FILE_CORRUPT);
}
- if (token[1]!='1' && token[1]!='4') {
+ if (token[1] != '1' && token[1] != '4') {
_RETURN(ERR_FILE_CORRUPT);
}
- bool bits = token[1]=='4';
+ bool bits = token[1] == '4';
- if (!_get_token(f,saved,token)) {
+ if (!_get_token(f, saved, token)) {
_RETURN(ERR_PARSE_ERROR);
}
int width = _get_number_from_token(token);
- if (width<=0) {
+ if (width <= 0) {
_RETURN(ERR_FILE_CORRUPT);
}
-
- if (!_get_token(f,saved,token)) {
+ if (!_get_token(f, saved, token)) {
_RETURN(ERR_PARSE_ERROR);
}
int height = _get_number_from_token(token);
- if (height<=0) {
+ if (height <= 0) {
_RETURN(ERR_FILE_CORRUPT);
}
-
Ref<BitMap> bm;
bm.instance();
- bm->create(Size2i(width,height));
+ bm->create(Size2i(width, height));
if (!bits) {
- int required_bytes = width*height;
- if (!_get_token(f,saved,token,false,true)) {
+ int required_bytes = width * height;
+ if (!_get_token(f, saved, token, false, true)) {
_RETURN(ERR_PARSE_ERROR);
}
- if (token.size()<required_bytes) {
+ if (token.size() < required_bytes) {
_RETURN(ERR_FILE_CORRUPT);
}
- PoolVector<uint8_t>::Read r=token.read();
-
- for(int i=0;i<height;i++) {
- for(int j=0;j<width;j++) {
+ PoolVector<uint8_t>::Read r = token.read();
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
- char num = r[i*width+j];
- bm->set_bit(Point2i(j,i),num=='0');
+ char num = r[i * width + j];
+ bm->set_bit(Point2i(j, i), num == '0');
}
-
}
-
-
} else {
//a single, entire token of bits!
- if (!_get_token(f,saved,token,true)) {
+ if (!_get_token(f, saved, token, true)) {
_RETURN(ERR_PARSE_ERROR);
}
- int required_bytes = Math::ceil((width*height)/8.0);
- if (token.size()<required_bytes) {
+ int required_bytes = Math::ceil((width * height) / 8.0);
+ if (token.size() < required_bytes) {
_RETURN(ERR_FILE_CORRUPT);
}
- PoolVector<uint8_t>::Read r=token.read();
+ PoolVector<uint8_t>::Read r = token.read();
int bitwidth = width;
if (bitwidth % 8)
- bitwidth+=8-(bitwidth%8);
+ bitwidth += 8 - (bitwidth % 8);
- for(int i=0;i<height;i++) {
- for(int j=0;j<width;j++) {
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
- int ofs = bitwidth*i+j;
+ int ofs = bitwidth * i + j;
- uint8_t byte = r[ofs/8];
- bool bit = (byte>>(7-(ofs%8)))&1;
-
- bm->set_bit(Point2i(j,i),!bit);
+ uint8_t byte = r[ofs / 8];
+ bool bit = (byte >> (7 - (ofs % 8))) & 1;
+ bm->set_bit(Point2i(j, i), !bit);
}
-
}
-
}
return bm;
-
-
}
void ResourceFormatPBM::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("pbm");
}
-bool ResourceFormatPBM::handles_type(const String& p_type) const {
- return p_type=="BitMap";
+bool ResourceFormatPBM::handles_type(const String &p_type) const {
+ return p_type == "BitMap";
}
String ResourceFormatPBM::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="pbm")
+ if (p_path.get_extension().to_lower() == "pbm")
return "BitMap";
return "";
}
-
-
diff --git a/modules/pbm/bitmap_loader_pbm.h b/modules/pbm/bitmap_loader_pbm.h
index b60b38fcca..5e5062f435 100644
--- a/modules/pbm/bitmap_loader_pbm.h
+++ b/modules/pbm/bitmap_loader_pbm.h
@@ -36,15 +36,11 @@
*/
class ResourceFormatPBM : public ResourceFormatLoader {
-
public:
-
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
-
-
#endif
diff --git a/modules/pbm/register_types.cpp b/modules/pbm/register_types.cpp
index 0dd39ce1e4..abfc08c909 100644
--- a/modules/pbm/register_types.cpp
+++ b/modules/pbm/register_types.cpp
@@ -30,15 +30,15 @@
#include "bitmap_loader_pbm.h"
-static ResourceFormatPBM * pbm_loader = NULL;
+static ResourceFormatPBM *pbm_loader = NULL;
void register_pbm_types() {
- pbm_loader = memnew( ResourceFormatPBM );
+ pbm_loader = memnew(ResourceFormatPBM);
ResourceLoader::add_resource_format_loader(pbm_loader);
}
void unregister_pbm_types() {
- memdelete( pbm_loader );
+ memdelete(pbm_loader);
}
diff --git a/modules/pvr/register_types.cpp b/modules/pvr/register_types.cpp
index 2464e78984..76fe7970d3 100644
--- a/modules/pvr/register_types.cpp
+++ b/modules/pvr/register_types.cpp
@@ -34,7 +34,7 @@ static ResourceFormatPVR *resource_loader_pvr = NULL;
void register_pvr_types() {
- resource_loader_pvr = memnew( ResourceFormatPVR );
+ resource_loader_pvr = memnew(ResourceFormatPVR);
ResourceLoader::add_resource_format_loader(resource_loader_pvr);
}
diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp
index 9805675f2c..0409998408 100644
--- a/modules/pvr/texture_loader_pvr.cpp
+++ b/modules/pvr/texture_loader_pvr.cpp
@@ -27,49 +27,47 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "texture_loader_pvr.h"
-#include "os/file_access.h"
-#include <string.h>
#include "PvrTcEncoder.h"
#include "RgbaBitmap.h"
+#include "os/file_access.h"
+#include <string.h>
-static void _pvrtc_decompress(Image* p_img);
+static void _pvrtc_decompress(Image *p_img);
enum PVRFLags {
- PVR_HAS_MIPMAPS=0x00000100,
- PVR_TWIDDLED=0x00000200,
- PVR_NORMAL_MAP=0x00000400,
- PVR_BORDER=0x00000800,
- PVR_CUBE_MAP=0x00001000,
- PVR_FALSE_MIPMAPS=0x00002000,
- PVR_VOLUME_TEXTURES=0x00004000,
- PVR_HAS_ALPHA=0x00008000,
- PVR_VFLIP=0x00010000
+ PVR_HAS_MIPMAPS = 0x00000100,
+ PVR_TWIDDLED = 0x00000200,
+ PVR_NORMAL_MAP = 0x00000400,
+ PVR_BORDER = 0x00000800,
+ PVR_CUBE_MAP = 0x00001000,
+ PVR_FALSE_MIPMAPS = 0x00002000,
+ PVR_VOLUME_TEXTURES = 0x00004000,
+ PVR_HAS_ALPHA = 0x00008000,
+ PVR_VFLIP = 0x00010000
};
-
-
-RES ResourceFormatPVR::load(const String &p_path,const String& p_original_path,Error *r_error) {
+RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_CANT_OPEN;
+ *r_error = ERR_CANT_OPEN;
Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (!f)
return RES();
FileAccessRef faref(f);
- ERR_FAIL_COND_V(err,RES());
+ ERR_FAIL_COND_V(err, RES());
if (r_error)
- *r_error=ERR_FILE_CORRUPT;
+ *r_error = ERR_FILE_CORRUPT;
uint32_t hsize = f->get_32();
- ERR_FAIL_COND_V(hsize!=52,RES());
+ ERR_FAIL_COND_V(hsize != 52, RES());
uint32_t height = f->get_32();
uint32_t width = f->get_32();
uint32_t mipmaps = f->get_32();
@@ -80,12 +78,12 @@ RES ResourceFormatPVR::load(const String &p_path,const String& p_original_path,E
uint32_t gmask = f->get_32();
uint32_t bmask = f->get_32();
uint32_t amask = f->get_32();
- uint8_t pvrid[5]={0,0,0,0,0};
- f->get_buffer(pvrid,4);
- ERR_FAIL_COND_V(String((char*)pvrid)!="PVR!",RES());
+ uint8_t pvrid[5] = { 0, 0, 0, 0, 0 };
+ f->get_buffer(pvrid, 4);
+ ERR_FAIL_COND_V(String((char *)pvrid) != "PVR!", RES());
uint32_t surfcount = f->get_32();
-/*
+ /*
print_line("height: "+itos(height));
print_line("width: "+itos(width));
print_line("mipmaps: "+itos(mipmaps));
@@ -102,149 +100,144 @@ RES ResourceFormatPVR::load(const String &p_path,const String& p_original_path,E
PoolVector<uint8_t> data;
data.resize(surfsize);
- ERR_FAIL_COND_V(data.size()==0,RES());
-
+ ERR_FAIL_COND_V(data.size() == 0, RES());
PoolVector<uint8_t>::Write w = data.write();
- f->get_buffer(&w[0],surfsize);
+ f->get_buffer(&w[0], surfsize);
err = f->get_error();
- ERR_FAIL_COND_V(err!=OK,RES());
+ ERR_FAIL_COND_V(err != OK, RES());
- Image::Format format=Image::FORMAT_MAX;
+ Image::Format format = Image::FORMAT_MAX;
-
- switch(flags&0xFF) {
+ switch (flags & 0xFF) {
case 0x18:
- case 0xC: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC2A:Image::FORMAT_PVRTC2; break;
+ case 0xC: format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC2A : Image::FORMAT_PVRTC2; break;
case 0x19:
- case 0xD: format=(flags&PVR_HAS_ALPHA)?Image::FORMAT_PVRTC4A:Image::FORMAT_PVRTC4; break;
+ case 0xD: format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4; break;
case 0x16:
- format=Image::FORMAT_L8; break;
+ format = Image::FORMAT_L8;
+ break;
case 0x17:
- format=Image::FORMAT_LA8; break;
+ format = Image::FORMAT_LA8;
+ break;
case 0x20:
case 0x80:
case 0x81:
- format=Image::FORMAT_DXT1; break;
+ format = Image::FORMAT_DXT1;
+ break;
case 0x21:
case 0x22:
case 0x82:
case 0x83:
- format=Image::FORMAT_DXT3; break;
+ format = Image::FORMAT_DXT3;
+ break;
case 0x23:
case 0x24:
case 0x84:
case 0x85:
- format=Image::FORMAT_DXT5; break;
+ format = Image::FORMAT_DXT5;
+ break;
case 0x4:
case 0x15:
- format=Image::FORMAT_RGB8; break;
+ format = Image::FORMAT_RGB8;
+ break;
case 0x5:
case 0x12:
- format=Image::FORMAT_RGBA8; break;
+ format = Image::FORMAT_RGBA8;
+ break;
case 0x36:
- format=Image::FORMAT_ETC; break;
+ format = Image::FORMAT_ETC;
+ break;
default:
- ERR_EXPLAIN("Unsupported format in PVR texture: "+itos(flags&0xFF));
+ ERR_EXPLAIN("Unsupported format in PVR texture: " + itos(flags & 0xFF));
ERR_FAIL_V(RES());
-
}
w = PoolVector<uint8_t>::Write();
- int tex_flags=Texture::FLAG_FILTER|Texture::FLAG_REPEAT;
+ int tex_flags = Texture::FLAG_FILTER | Texture::FLAG_REPEAT;
if (mipmaps)
- tex_flags|=Texture::FLAG_MIPMAPS;
+ tex_flags |= Texture::FLAG_MIPMAPS;
+ print_line("flip: " + itos(flags & PVR_VFLIP));
- print_line("flip: "+itos(flags&PVR_VFLIP));
+ Image image(width, height, mipmaps, format, data);
+ ERR_FAIL_COND_V(image.empty(), RES());
- Image 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);
+ Ref<ImageTexture> texture = memnew(ImageTexture);
+ texture->create_from_image(image, tex_flags);
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return texture;
-
}
void ResourceFormatPVR::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("pvr");
}
-bool ResourceFormatPVR::handles_type(const String& p_type) const {
+bool ResourceFormatPVR::handles_type(const String &p_type) const {
- return ClassDB::is_parent_class(p_type,"Texture");
+ return ClassDB::is_parent_class(p_type, "Texture");
}
String ResourceFormatPVR::get_resource_type(const String &p_path) const {
-
- if (p_path.get_extension().to_lower()=="pvr")
+ if (p_path.get_extension().to_lower() == "pvr")
return "Texture";
return "";
}
-
-
-static void _compress_pvrtc4(Image * p_img) {
+static void _compress_pvrtc4(Image *p_img) {
Image img = *p_img;
- 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)));
+ 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)));
}
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();
+ 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>::Write wr = data.write();
+ 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);
- Javelin::RgbaBitmap bm(w,h);
- copymem(bm.GetData(),&r[ofs],size);
+ int 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);
{
Javelin::ColorRgba<unsigned char> *dp = bm.GetData();
- for(int j=0;j<size/4;j++) {
- SWAP(dp[j].r,dp[j].b);
+ for (int j = 0; j < size / 4; j++) {
+ SWAP(dp[j].r, dp[j].b);
}
}
- new_img.get_mipmap_offset_size_and_dimensions(i,ofs,size,w,h);
- Javelin::PvrTcEncoder::EncodeRgba4Bpp(&wr[ofs],bm);
+ 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 = Image(new_img.get_width(), new_img.get_height(), new_img.has_mipmaps(), new_img.get_format(), data);
}
ResourceFormatPVR::ResourceFormatPVR() {
-
- Image::_image_decompress_pvrtc=_pvrtc_decompress;
- Image::_image_compress_pvrtc4_func=_compress_pvrtc4;
- Image::_image_compress_pvrtc2_func=_compress_pvrtc4;
-
+ Image::_image_decompress_pvrtc = _pvrtc_decompress;
+ Image::_image_compress_pvrtc4_func = _compress_pvrtc4;
+ Image::_image_compress_pvrtc2_func = _compress_pvrtc4;
}
/////////////////////////////////////////////////////////
@@ -253,7 +246,6 @@ ResourceFormatPVR::ResourceFormatPVR() {
/////////////////////////////////////////////////////////
-
#define PT_INDEX 2
#define BLK_Y_SIZE 4
#define BLK_X_MAX 8
@@ -267,52 +259,48 @@ ResourceFormatPVR::ResourceFormatPVR() {
legal coordinate range
*/
#define LIMIT_COORD(Val, Size, p_tiled) \
- ((p_tiled)? WRAP_COORD((Val), (Size)): CLAMP((Val), 0, (Size)-1))
-
+ ((p_tiled) ? WRAP_COORD((Val), (Size)) : CLAMP((Val), 0, (Size)-1))
struct PVRTCBlock {
//blocks are 64 bits
uint32_t data[2];
};
+_FORCE_INLINE_ bool is_po2(uint32_t p_input) {
-
-_FORCE_INLINE_ bool is_po2( uint32_t p_input ) {
-
- if( p_input==0 )
- return 0;
- uint32_t minus1=p_input- 1;
- return ((p_input|minus1)==(p_input^minus1))?1:0;
+ if (p_input == 0)
+ return 0;
+ uint32_t minus1 = p_input - 1;
+ return ((p_input | minus1) == (p_input ^ minus1)) ? 1 : 0;
}
-
-static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
+static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
uint32_t raw_bits[2];
raw_bits[0] = p_block->data[1] & (0xFFFE);
raw_bits[1] = p_block->data[1] >> 16;
- for(int i=0;i<2;i++) {
+ for (int i = 0; i < 2; i++) {
- if(raw_bits[i] & (1<<15)) {
+ if (raw_bits[i] & (1 << 15)) {
- p_ab_colors[i][0]= (raw_bits[i] >> 10) & 0x1F;
- p_ab_colors[i][1]= (raw_bits[i] >> 5) & 0x1F;
- p_ab_colors[i][2]= raw_bits[i] & 0x1F;
- if(i==0)
- p_ab_colors[0][2]|= p_ab_colors[0][2] >> 4;
+ p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F;
+ p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F;
+ p_ab_colors[i][2] = raw_bits[i] & 0x1F;
+ if (i == 0)
+ p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
p_ab_colors[i][3] = 0xF;
} else {
- p_ab_colors[i][0] = (raw_bits[i] >> (8-1)) & 0x1E;
- p_ab_colors[i][1] = (raw_bits[i] >> (4-1)) & 0x1E;
+ p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E;
+ p_ab_colors[i][1] = (raw_bits[i] >> (4 - 1)) & 0x1E;
p_ab_colors[i][0] |= p_ab_colors[i][0] >> 4;
p_ab_colors[i][1] |= p_ab_colors[i][1] >> 4;
p_ab_colors[i][2] = (raw_bits[i] & 0xF) << 1;
- if(i==0)
+ if (i == 0)
p_ab_colors[0][2] |= p_ab_colors[0][2] >> 3;
else
p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
@@ -322,55 +310,52 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
}
}
-
-static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int p_modulation[8][16], int p_modulation_modes[8][16], int p_x, int p_y) {
+static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int p_modulation[8][16], int p_modulation_modes[8][16], int p_x, int p_y) {
int block_mod_mode = p_block->data[1] & 1;
uint32_t modulation_bits = p_block->data[0];
- if(p_2bit && block_mod_mode) {
+ if (p_2bit && block_mod_mode) {
- for(int y = 0; y < BLK_Y_SIZE; y++) {
- for(int x = 0; x < BLK_X_2BPP; x++) {
+ for (int y = 0; y < BLK_Y_SIZE; y++) {
+ for (int x = 0; x < BLK_X_2BPP; x++) {
- p_modulation_modes[y+p_y][x+p_x] = block_mod_mode;
+ p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
- if(((x^y)&1) == 0) {
- p_modulation[y+p_y][x+p_x] = modulation_bits & 3;
+ if (((x ^ y) & 1) == 0) {
+ p_modulation[y + p_y][x + p_x] = modulation_bits & 3;
modulation_bits >>= 2;
}
}
}
- } else if(p_2bit) {
+ } else if (p_2bit) {
- for(int y = 0; y < BLK_Y_SIZE; y++) {
- for(int x = 0; x < BLK_X_2BPP; x++) {
- p_modulation_modes[y+p_y][x+p_x] = block_mod_mode;
+ for (int y = 0; y < BLK_Y_SIZE; y++) {
+ for (int x = 0; x < BLK_X_2BPP; x++) {
+ p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
- if(modulation_bits & 1)
- p_modulation[y+p_y][x+p_x] = 0x3;
+ if (modulation_bits & 1)
+ p_modulation[y + p_y][x + p_x] = 0x3;
else
- p_modulation[y+p_y][x+p_x] = 0x0;
+ p_modulation[y + p_y][x + p_x] = 0x0;
modulation_bits >>= 1;
}
}
- } else {
- for(int y = 0; y < BLK_Y_SIZE; y++) {
- for(int x = 0; x < BLK_X_4BPP; x++) {
- p_modulation_modes[y+p_y][x+p_x] = block_mod_mode;
- p_modulation[y+p_y][x+p_x] = modulation_bits & 3;
+ } else {
+ for (int y = 0; y < BLK_Y_SIZE; y++) {
+ for (int x = 0; x < BLK_X_4BPP; x++) {
+ p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
+ p_modulation[y + p_y][x + p_x] = modulation_bits & 3;
modulation_bits >>= 2;
}
}
}
- ERR_FAIL_COND(modulation_bits!=0);
+ ERR_FAIL_COND(modulation_bits != 0);
}
-
-
static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], const int p_colorr[4], const int p_colors[4], bool p_2bit, const int x, const int y, int r_result[4]) {
int u, v, uscale;
int k;
@@ -379,7 +364,7 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con
int P[4], Q[4], R[4], S[4];
- for(k = 0; k < 4; k++) {
+ for (k = 0; k < 4; k++) {
P[k] = p_colorp[k];
Q[k] = p_colorq[k];
R[k] = p_colorr[k];
@@ -388,22 +373,22 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con
v = (y & 0x3) | ((~y & 0x2) << 1);
- if(p_2bit)
+ if (p_2bit)
u = (x & 0x7) | ((~x & 0x4) << 1);
else
u = (x & 0x3) | ((~x & 0x2) << 1);
- v = v - BLK_Y_SIZE/2;
+ v = v - BLK_Y_SIZE / 2;
- if(p_2bit) {
- u = u - BLK_X_2BPP/2;
+ if (p_2bit) {
+ u = u - BLK_X_2BPP / 2;
uscale = 8;
} else {
- u = u - BLK_X_4BPP/2;
+ u = u - BLK_X_4BPP / 2;
uscale = 4;
}
- for(k = 0; k < 4; k++) {
+ for (k = 0; k < 4; k++) {
tmp1 = P[k] * uscale + u * (Q[k] - P[k]);
tmp2 = R[k] * uscale + u * (S[k] - R[k]);
@@ -412,82 +397,77 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con
r_result[k] = tmp1;
}
- if(p_2bit) {
- for(k = 0; k < 3; k++) {
+ if (p_2bit) {
+ for (k = 0; k < 3; k++) {
r_result[k] >>= 2;
}
r_result[3] >>= 1;
} else {
- for(k = 0; k < 3; k++) {
+ for (k = 0; k < 3; k++) {
r_result[k] >>= 1;
}
}
- for(k = 0; k < 4; k++) {
+ for (k = 0; k < 4; k++) {
ERR_FAIL_COND(r_result[k] >= 256);
}
-
- for(k = 0; k < 3; k++) {
+ for (k = 0; k < 3; k++) {
r_result[k] += r_result[k] >> 5;
}
r_result[3] += r_result[3] >> 4;
- for(k = 0; k < 4; k++) {
+ for (k = 0; k < 4; k++) {
ERR_FAIL_COND(r_result[k] >= 256);
}
-
}
-
-static void get_modulation_value(int x, int y, const int p_2bit, const int p_modulation[8][16], const int p_modulation_modes[8][16], int *r_mod, int *p_dopt)
-{
- static const int rep_vals0[4] = {0, 3, 5, 8};
- static const int rep_vals1[4] = {0, 4, 4, 8};
+static void get_modulation_value(int x, int y, const int p_2bit, const int p_modulation[8][16], const int p_modulation_modes[8][16], int *r_mod, int *p_dopt) {
+ static const int rep_vals0[4] = { 0, 3, 5, 8 };
+ static const int rep_vals1[4] = { 0, 4, 4, 8 };
int mod_val;
y = (y & 0x3) | ((~y & 0x2) << 1);
- if(p_2bit)
+ if (p_2bit)
x = (x & 0x7) | ((~x & 0x4) << 1);
else
x = (x & 0x3) | ((~x & 0x2) << 1);
*p_dopt = 0;
- if(p_modulation_modes[y][x]==0) {
+ if (p_modulation_modes[y][x] == 0) {
mod_val = rep_vals0[p_modulation[y][x]];
- } else if(p_2bit) {
- if(((x^y)&1)==0)
+ } else if (p_2bit) {
+ if (((x ^ y) & 1) == 0)
mod_val = rep_vals0[p_modulation[y][x]];
- else if(p_modulation_modes[y][x] == 1) {
- mod_val = (
- rep_vals0[p_modulation[y-1][x]] +
- rep_vals0[p_modulation[y+1][x]] +
- rep_vals0[p_modulation[y][x-1]] +
- rep_vals0[p_modulation[y][x+1]] + 2) / 4;
- } else if(p_modulation_modes[y][x] == 2) {
- mod_val = (
- rep_vals0[p_modulation[y][x-1]] +
- rep_vals0[p_modulation[y][x+1]] + 1) / 2;
+ else if (p_modulation_modes[y][x] == 1) {
+ mod_val = (rep_vals0[p_modulation[y - 1][x]] +
+ rep_vals0[p_modulation[y + 1][x]] +
+ rep_vals0[p_modulation[y][x - 1]] +
+ rep_vals0[p_modulation[y][x + 1]] + 2) /
+ 4;
+ } else if (p_modulation_modes[y][x] == 2) {
+ mod_val = (rep_vals0[p_modulation[y][x - 1]] +
+ rep_vals0[p_modulation[y][x + 1]] + 1) /
+ 2;
} else {
- mod_val = (
- rep_vals0[p_modulation[y-1][x]] +
- rep_vals0[p_modulation[y+1][x]] + 1) / 2;
+ mod_val = (rep_vals0[p_modulation[y - 1][x]] +
+ rep_vals0[p_modulation[y + 1][x]] + 1) /
+ 2;
}
- } else {
+ } else {
mod_val = rep_vals1[p_modulation[y][x]];
*p_dopt = p_modulation[y][x] == PT_INDEX;
}
- *r_mod =mod_val;
+ *r_mod = mod_val;
}
-
static int disable_twiddling = 0;
static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, uint32_t p_x) {
@@ -502,51 +482,50 @@ static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, ui
int shift_count;
- ERR_FAIL_COND_V(p_y >= p_height,0);
- ERR_FAIL_COND_V(p_x >= p_width,0);
+ ERR_FAIL_COND_V(p_y >= p_height, 0);
+ ERR_FAIL_COND_V(p_x >= p_width, 0);
- ERR_FAIL_COND_V(!is_po2(p_height),0);
- ERR_FAIL_COND_V(!is_po2(p_width),0);
+ ERR_FAIL_COND_V(!is_po2(p_height), 0);
+ ERR_FAIL_COND_V(!is_po2(p_width), 0);
- if(p_height < p_width) {
+ if (p_height < p_width) {
min_dimension = p_height;
- max_value = p_x;
+ max_value = p_x;
} else {
min_dimension = p_width;
- max_value = p_y;
+ max_value = p_y;
}
- if(disable_twiddling)
- return (p_y* p_width + p_x);
+ if (disable_twiddling)
+ return (p_y * p_width + p_x);
scr_bit_pos = 1;
dst_bit_pos = 1;
- twiddled = 0;
+ twiddled = 0;
shift_count = 0;
- while(scr_bit_pos < min_dimension) {
- if(p_y & scr_bit_pos) {
+ while (scr_bit_pos < min_dimension) {
+ if (p_y & scr_bit_pos) {
twiddled |= dst_bit_pos;
}
- if(p_x & scr_bit_pos) {
+ if (p_x & scr_bit_pos) {
twiddled |= (dst_bit_pos << 1);
}
scr_bit_pos <<= 1;
dst_bit_pos <<= 2;
shift_count += 1;
-
}
max_value >>= shift_count;
- twiddled |= (max_value << (2*shift_count));
+ twiddled |= (max_value << (2 * shift_count));
return twiddled;
}
-static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int p_width, const int p_height, const int p_tiled, unsigned char* p_dst) {
+static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int p_width, const int p_height, const int p_tiled, unsigned char *p_dst) {
int x, y;
int i, j;
@@ -567,55 +546,50 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int
// local neighbourhood of blocks
PVRTCBlock *p_blocks[2][2];
- PVRTCBlock *prev[2][2] = {{NULL, NULL}, {NULL, NULL}};
+ PVRTCBlock *prev[2][2] = { { NULL, NULL }, { NULL, NULL } };
struct
{
int Reps[2][4];
- }colors5554[2][2];
-
+ } colors5554[2][2];
int ASig[4], BSig[4];
int r_result[4];
- if(p_2bit)
+ if (p_2bit)
x_block_size = BLK_X_2BPP;
else
x_block_size = BLK_X_4BPP;
-
block_width = MAX(2, p_width / x_block_size);
block_height = MAX(2, p_height / BLK_Y_SIZE);
- for(y = 0; y < p_height; y++)
- {
- for(x = 0; x < p_width; x++)
- {
+ for (y = 0; y < p_height; y++) {
+ for (x = 0; x < p_width; x++) {
- block_x = (x - x_block_size/2);
- blk_y = (y - BLK_Y_SIZE/2);
+ block_x = (x - x_block_size / 2);
+ blk_y = (y - BLK_Y_SIZE / 2);
block_x = LIMIT_COORD(block_x, p_width, p_tiled);
blk_y = LIMIT_COORD(blk_y, p_height, p_tiled);
-
block_x /= x_block_size;
blk_y /= BLK_Y_SIZE;
- block_xp1 = LIMIT_COORD(block_x+1, block_width, p_tiled);
- blk_yp1 = LIMIT_COORD(blk_y+1, block_height, p_tiled);
+ block_xp1 = LIMIT_COORD(block_x + 1, block_width, p_tiled);
+ blk_yp1 = LIMIT_COORD(blk_y + 1, block_height, p_tiled);
- p_blocks[0][0] = p_comp_img +twiddle_uv(block_height, block_width, blk_y, block_x);
- p_blocks[0][1] = p_comp_img +twiddle_uv(block_height, block_width, blk_y, block_xp1);
- p_blocks[1][0] = p_comp_img +twiddle_uv(block_height, block_width, blk_yp1, block_x);
- p_blocks[1][1] = p_comp_img +twiddle_uv(block_height, block_width, blk_yp1, block_xp1);
+ p_blocks[0][0] = p_comp_img + twiddle_uv(block_height, block_width, blk_y, block_x);
+ p_blocks[0][1] = p_comp_img + twiddle_uv(block_height, block_width, blk_y, block_xp1);
+ p_blocks[1][0] = p_comp_img + twiddle_uv(block_height, block_width, blk_yp1, block_x);
+ p_blocks[1][1] = p_comp_img + twiddle_uv(block_height, block_width, blk_yp1, block_xp1);
- if(memcmp(prev, p_blocks, 4*sizeof(void*)) != 0) {
+ if (memcmp(prev, p_blocks, 4 * sizeof(void *)) != 0) {
p_y = 0;
- for(i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++) {
p_x = 0;
- for(j = 0; j < 2; j++) {
+ for (j = 0; j < 2; j++) {
unpack_5554(p_blocks[i][j], colors5554[i][j].Reps);
unpack_modulations(
@@ -631,11 +605,9 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int
p_y += BLK_Y_SIZE;
}
-
- memcpy(prev, p_blocks, 4*sizeof(void*));
+ memcpy(prev, p_blocks, 4 * sizeof(void *));
}
-
interpolate_colors(
colors5554[0][0].Reps[0],
colors5554[0][1].Reps[0],
@@ -652,28 +624,27 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int
p_2bit, x, y,
BSig);
- get_modulation_value(x,y, p_2bit, (const int (*)[16])p_modulation, (const int (*)[16])p_modulation_modes,
- &Mod, &DoPT);
+ get_modulation_value(x, y, p_2bit, (const int(*)[16])p_modulation, (const int(*)[16])p_modulation_modes,
+ &Mod, &DoPT);
- for(i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++) {
r_result[i] = ASig[i] * 8 + Mod * (BSig[i] - ASig[i]);
r_result[i] >>= 3;
}
- if(DoPT)
+ if (DoPT)
r_result[3] = 0;
-
- u_pos = (x+y*p_width)<<2;
- p_dst[u_pos+0] = (uint8_t)r_result[0];
- p_dst[u_pos+1] = (uint8_t)r_result[1];
- p_dst[u_pos+2] = (uint8_t)r_result[2];
- p_dst[u_pos+3] = (uint8_t)r_result[3];
+ u_pos = (x + y * p_width) << 2;
+ p_dst[u_pos + 0] = (uint8_t)r_result[0];
+ p_dst[u_pos + 1] = (uint8_t)r_result[1];
+ p_dst[u_pos + 2] = (uint8_t)r_result[2];
+ p_dst[u_pos + 3] = (uint8_t)r_result[3];
}
}
}
-static void _pvrtc_decompress(Image* p_img) {
+static void _pvrtc_decompress(Image *p_img) {
/*
static void decompress_pvrtc(const void *p_comp_img, const int p_2bit, const int p_width, const int p_height, unsigned char* p_dst) {
@@ -681,19 +652,18 @@ static void _pvrtc_decompress(Image* p_img) {
}
*/
- ERR_FAIL_COND( p_img->get_format()!=Image::FORMAT_PVRTC2 && p_img->get_format()!=Image::FORMAT_PVRTC2A && p_img->get_format()!=Image::FORMAT_PVRTC4 && p_img->get_format()!=Image::FORMAT_PVRTC4A);
+ ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_PVRTC2 && p_img->get_format() != Image::FORMAT_PVRTC2A && p_img->get_format() != Image::FORMAT_PVRTC4 && p_img->get_format() != Image::FORMAT_PVRTC4A);
- bool _2bit = (p_img->get_format()==Image::FORMAT_PVRTC2 || p_img->get_format()==Image::FORMAT_PVRTC2A );
+ bool _2bit = (p_img->get_format() == Image::FORMAT_PVRTC2 || p_img->get_format() == Image::FORMAT_PVRTC2A);
PoolVector<uint8_t> data = p_img->get_data();
PoolVector<uint8_t>::Read r = data.read();
-
PoolVector<uint8_t> newdata;
- newdata.resize( p_img->get_width() * p_img->get_height() * 4);
- PoolVector<uint8_t>::Write w=newdata.write();
+ newdata.resize(p_img->get_width() * p_img->get_height() * 4);
+ PoolVector<uint8_t>::Write w = newdata.write();
- decompress_pvrtc((PVRTCBlock*)r.ptr(),_2bit,p_img->get_width(),p_img->get_height(),0,(unsigned char*)w.ptr());
+ decompress_pvrtc((PVRTCBlock *)r.ptr(), _2bit, p_img->get_width(), p_img->get_height(), 0, (unsigned char *)w.ptr());
/*
for(int i=0;i<newdata.size();i++) {
@@ -701,21 +671,12 @@ static void _pvrtc_decompress(Image* p_img) {
}
*/
- w=PoolVector<uint8_t>::Write();
- r=PoolVector<uint8_t>::Read();
+ w = PoolVector<uint8_t>::Write();
+ 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);
+ bool make_mipmaps = p_img->has_mipmaps();
+ Image newimg(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata);
if (make_mipmaps)
newimg.generate_mipmaps();
- *p_img=newimg;
-
+ *p_img = newimg;
}
-
-
-
-
-
-
-
-
diff --git a/modules/pvr/texture_loader_pvr.h b/modules/pvr/texture_loader_pvr.h
index bad48b4569..768070ee61 100644
--- a/modules/pvr/texture_loader_pvr.h
+++ b/modules/pvr/texture_loader_pvr.h
@@ -29,22 +29,18 @@
#ifndef TEXTURE_LOADER_PVR_H
#define TEXTURE_LOADER_PVR_H
-
-#include "scene/resources/texture.h"
#include "io/resource_loader.h"
+#include "scene/resources/texture.h"
-
-class ResourceFormatPVR : public ResourceFormatLoader{
+class ResourceFormatPVR : public ResourceFormatLoader {
public:
-
- virtual RES load(const String &p_path,const String& p_original_path,Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
ResourceFormatPVR();
virtual ~ResourceFormatPVR() {}
};
-
#endif // TEXTURE_LOADER_PVR_H
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp
index 3d1dd048a8..e8fed382b5 100644
--- a/modules/regex/regex.cpp
+++ b/modules/regex/regex.cpp
@@ -28,11 +28,10 @@
/*************************************************************************/
#include "regex.h"
-#include <wctype.h>
#include <wchar.h>
+#include <wctype.h>
-static int RegEx_hex2int(const CharType c)
-{
+static int RegEx_hex2int(const CharType c) {
if ('0' <= c && c <= '9')
return int(c - '0');
else if ('a' <= c && c <= 'f')
@@ -45,7 +44,7 @@ static int RegEx_hex2int(const CharType c)
struct RegExSearch {
Ref<RegExMatch> match;
- const CharType* str;
+ const CharType *str;
int end;
int eof;
@@ -63,7 +62,8 @@ struct RegExSearch {
return str[p_pos];
}
- RegExSearch(Ref<RegExMatch>& p_match, int p_end, int p_lookahead) : match(p_match) {
+ RegExSearch(Ref<RegExMatch> &p_match, int p_end, int p_lookahead)
+ : match(p_match) {
str = p_match->string.c_str();
end = p_end;
@@ -71,14 +71,13 @@ struct RegExSearch {
complete = false;
lookahead_pos.resize(p_lookahead);
}
-
};
struct RegExNode {
- RegExNode* next;
- RegExNode* previous;
- RegExNode* parent;
+ RegExNode *next;
+ RegExNode *previous;
+ RegExNode *parent;
bool quantifiable;
int length;
@@ -100,12 +99,12 @@ struct RegExNode {
// For avoiding RTTI
virtual bool is_look_behind() { return false; }
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
return next ? next->test(s, pos) : -1;
}
- virtual int test_parent(RegExSearch& s, int pos) const {
+ virtual int test_parent(RegExSearch &s, int pos) const {
if (next)
pos = next->test(s, pos);
@@ -135,9 +134,7 @@ struct RegExNode {
if (parent)
parent->increment_length(amount, subtract);
-
}
-
};
struct RegExNodeChar : public RegExNode {
@@ -151,7 +148,7 @@ struct RegExNodeChar : public RegExNode {
ch = p_char;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (s.end <= pos || 0 > pos || s.at(pos) != ch)
return -1;
@@ -159,7 +156,7 @@ struct RegExNodeChar : public RegExNode {
return next ? next->test(s, pos + 1) : pos + 1;
}
- static CharType parse_escape(const CharType*& c) {
+ static CharType parse_escape(const CharType *&c) {
int point = 0;
switch (c[1]) {
@@ -209,7 +206,7 @@ struct RegExNodeRange : public RegExNode {
end = p_end;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (s.end <= pos || 0 > pos)
return -1;
@@ -233,7 +230,7 @@ struct RegExNodeShorthand : public RegExNode {
repr = p_repr;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (s.end <= pos || 0 > pos)
return -1;
@@ -351,7 +348,7 @@ struct RegExNodeClass : public RegExNode {
type = p_type;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (s.end <= pos || 0 > pos)
return -1;
@@ -362,9 +359,10 @@ struct RegExNodeClass : public RegExNode {
return next ? next->test(s, pos + 1) : pos + 1;
}
-#define REGEX_CMP_CLASS(POS, NAME) if (cmp_class(POS, #NAME)) return Type_ ## NAME
+#define REGEX_CMP_CLASS(POS, NAME) \
+ if (cmp_class(POS, #NAME)) return Type_##NAME
- static Type parse_type(const CharType*& p_pos) {
+ static Type parse_type(const CharType *&p_pos) {
REGEX_CMP_CLASS(p_pos, alnum);
REGEX_CMP_CLASS(p_pos, alpha);
@@ -383,7 +381,7 @@ struct RegExNodeClass : public RegExNode {
return Type_none;
}
- static bool cmp_class(const CharType*& p_pos, const char* p_text) {
+ static bool cmp_class(const CharType *&p_pos, const char *p_text) {
unsigned int i = 0;
for (i = 0; p_text[i] != '\0'; ++i)
@@ -405,7 +403,7 @@ struct RegExNodeAnchorStart : public RegExNode {
length = 0;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (pos != 0)
return -1;
@@ -421,7 +419,7 @@ struct RegExNodeAnchorEnd : public RegExNode {
length = 0;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (pos != s.eof)
return -1;
@@ -440,7 +438,7 @@ struct RegExNodeWordBoundary : public RegExNode {
inverse = p_inverse;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
bool left = false;
bool right = false;
@@ -469,7 +467,7 @@ struct RegExNodeQuantifier : public RegExNode {
int min;
int max;
bool greedy;
- RegExNode* child;
+ RegExNode *child;
RegExNodeQuantifier(int p_min, int p_max) {
@@ -485,18 +483,18 @@ struct RegExNodeQuantifier : public RegExNode {
memdelete(child);
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
return test_step(s, pos, 0, pos);
}
- virtual int test_parent(RegExSearch& s, int pos) const {
+ virtual int test_parent(RegExSearch &s, int pos) const {
s.complete = false;
return pos;
}
- int test_step(RegExSearch& s, int pos, int level, int start) const {
+ int test_step(RegExSearch &s, int pos, int level, int start) const {
if (pos > s.end)
return -1;
@@ -554,9 +552,9 @@ struct RegExNodeBackReference : public RegExNode {
id = p_id;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
- RegExMatch::Group& ref = s.match->captures[id];
+ RegExMatch::Group &ref = s.match->captures[id];
for (int i = 0; i < ref.length; ++i) {
if (pos + i >= s.end)
@@ -569,13 +567,12 @@ struct RegExNodeBackReference : public RegExNode {
}
};
-
struct RegExNodeGroup : public RegExNode {
bool inverse;
bool reset_pos;
- Vector<RegExNode*> childset;
- RegExNode* back;
+ Vector<RegExNode *> childset;
+ RegExNode *back;
RegExNodeGroup() {
@@ -592,7 +589,7 @@ struct RegExNodeGroup : public RegExNode {
memdelete(childset[i]);
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
for (int i = 0; i < childset.size(); ++i) {
@@ -622,7 +619,7 @@ struct RegExNodeGroup : public RegExNode {
return -1;
}
- void add_child(RegExNode* node) {
+ void add_child(RegExNode *node) {
node->parent = this;
node->previous = back;
@@ -644,9 +641,9 @@ struct RegExNodeGroup : public RegExNode {
back = NULL;
}
- RegExNode* swap_back(RegExNode* node) {
+ RegExNode *swap_back(RegExNode *node) {
- RegExNode* old = back;
+ RegExNode *old = back;
if (old) {
if (!old->previous)
@@ -670,9 +667,9 @@ struct RegExNodeCapturing : public RegExNodeGroup {
id = p_id;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
- RegExMatch::Group& ref = s.match->captures[id];
+ RegExMatch::Group &ref = s.match->captures[id];
int old_start = ref.start;
ref.start = pos;
@@ -688,14 +685,14 @@ struct RegExNodeCapturing : public RegExNodeGroup {
return res;
}
- virtual int test_parent(RegExSearch& s, int pos) const {
+ virtual int test_parent(RegExSearch &s, int pos) const {
- RegExMatch::Group& ref = s.match->captures[id];
+ RegExMatch::Group &ref = s.match->captures[id];
ref.length = pos - ref.start;
return RegExNode::test_parent(s, pos);
}
- static Variant parse_name(const CharType*& c, bool p_allow_numeric) {
+ static Variant parse_name(const CharType *&c, bool p_allow_numeric) {
if (c[1] == '0') {
return -1;
@@ -732,13 +729,13 @@ struct RegExNodeLookAhead : public RegExNodeGroup {
id = p_id;
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
s.lookahead_pos[id] = pos;
return RegExNodeGroup::test(s, pos);
}
- virtual int test_parent(RegExSearch& s, int pos) const {
+ virtual int test_parent(RegExSearch &s, int pos) const {
return RegExNode::test_parent(s, s.lookahead_pos[id]);
}
@@ -755,7 +752,7 @@ struct RegExNodeLookBehind : public RegExNodeGroup {
virtual bool is_look_behind() { return true; }
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
if (pos < length)
return -1;
@@ -766,7 +763,7 @@ struct RegExNodeLookBehind : public RegExNodeGroup {
struct RegExNodeBracket : public RegExNode {
bool inverse;
- Vector<RegExNode*> children;
+ Vector<RegExNode *> children;
RegExNodeBracket() {
@@ -781,7 +778,7 @@ struct RegExNodeBracket : public RegExNode {
memdelete(children[i]);
}
- virtual int test(RegExSearch& s, int pos) const {
+ virtual int test(RegExSearch &s, int pos) const {
for (int i = 0; i < children.size(); ++i) {
@@ -803,7 +800,7 @@ struct RegExNodeBracket : public RegExNode {
return -1;
}
- void add_child(RegExNode* node) {
+ void add_child(RegExNode *node) {
node->parent = this;
children.push_back(node);
@@ -816,16 +813,16 @@ struct RegExNodeBracket : public RegExNode {
}
};
-#define REGEX_EXPAND_FAIL(MSG)\
-{\
- ERR_PRINT(MSG);\
- return String();\
-}
+#define REGEX_EXPAND_FAIL(MSG) \
+ { \
+ ERR_PRINT(MSG); \
+ return String(); \
+ }
-String RegExMatch::expand(const String& p_template) const {
+String RegExMatch::expand(const String &p_template) const {
String res;
- for (const CharType* c = p_template.c_str(); *c != '\0'; ++c) {
+ for (const CharType *c = p_template.c_str(); *c != '\0'; ++c) {
if (c[0] == '\\') {
if (('1' <= c[1] && c[1] <= '9') || (c[1] == 'g' && c[2] == '{')) {
@@ -850,9 +847,9 @@ String RegExMatch::expand(const String& p_template) const {
res += get_string(ref);
- } else if (c[1] =='g' && c[2] == '<') {
+ } else if (c[1] == 'g' && c[2] == '<') {
- const CharType* d = &c[2];
+ const CharType *d = &c[2];
Variant name = RegExNodeCapturing::parse_name(d, true);
if (name == Variant(-1))
@@ -864,7 +861,7 @@ String RegExMatch::expand(const String& p_template) const {
} else {
- const CharType* d = c;
+ const CharType *d = c;
CharType ch = RegExNodeChar::parse_escape(d);
if (c == d)
REGEX_EXPAND_FAIL("invalid escape token");
@@ -891,7 +888,7 @@ Array RegExMatch::get_group_array() const {
Array res;
for (int i = 1; i < captures.size(); ++i) {
- const RegExMatch::Group& capture = captures[i];
+ const RegExMatch::Group &capture = captures[i];
if (capture.name.get_type() != Variant::INT)
continue;
@@ -916,7 +913,7 @@ Dictionary RegExMatch::get_name_dict() const {
Dictionary res;
for (int i = 1; i < captures.size(); ++i) {
- const RegExMatch::Group& capture = captures[i];
+ const RegExMatch::Group &capture = captures[i];
if (capture.name.get_type() != Variant::STRING)
continue;
@@ -928,11 +925,11 @@ Dictionary RegExMatch::get_name_dict() const {
return res;
}
-String RegExMatch::get_string(const Variant& p_name) const {
+String RegExMatch::get_string(const Variant &p_name) const {
for (int i = 0; i < captures.size(); ++i) {
- const RegExMatch::Group& capture = captures[i];
+ const RegExMatch::Group &capture = captures[i];
if (capture.name != p_name)
continue;
@@ -945,7 +942,7 @@ String RegExMatch::get_string(const Variant& p_name) const {
return String();
}
-int RegExMatch::get_start(const Variant& p_name) const {
+int RegExMatch::get_start(const Variant &p_name) const {
for (int i = 0; i < captures.size(); ++i)
if (captures[i].name == p_name)
@@ -953,7 +950,7 @@ int RegExMatch::get_start(const Variant& p_name) const {
return -1;
}
-int RegExMatch::get_end(const Variant& p_name) const {
+int RegExMatch::get_end(const Variant &p_name) const {
for (int i = 0; i < captures.size(); ++i)
if (captures[i].name == p_name)
@@ -962,7 +959,6 @@ int RegExMatch::get_end(const Variant& p_name) const {
}
RegExMatch::RegExMatch() {
-
}
static bool RegEx_is_shorthand(CharType ch) {
@@ -981,14 +977,14 @@ static bool RegEx_is_shorthand(CharType ch) {
return false;
}
-#define REGEX_COMPILE_FAIL(MSG)\
-{\
- ERR_PRINT(MSG);\
- clear();\
- return FAILED;\
-}
+#define REGEX_COMPILE_FAIL(MSG) \
+ { \
+ ERR_PRINT(MSG); \
+ clear(); \
+ return FAILED; \
+ }
-Error RegEx::compile(const String& p_pattern) {
+Error RegEx::compile(const String &p_pattern) {
ERR_FAIL_COND_V(p_pattern.length() == 0, FAILED);
@@ -998,21 +994,21 @@ Error RegEx::compile(const String& p_pattern) {
clear();
pattern = p_pattern;
group_names.push_back(0);
- RegExNodeGroup* root_group = memnew(RegExNodeCapturing(0));
+ RegExNodeGroup *root_group = memnew(RegExNodeCapturing(0));
root = root_group;
- Vector<RegExNodeGroup*> stack;
+ Vector<RegExNodeGroup *> stack;
stack.push_back(root_group);
int lookahead_level = 0;
int numeric_groups = 0;
const int numeric_max = 9;
- for (const CharType* c = p_pattern.c_str(); *c != '\0'; ++c) {
+ for (const CharType *c = p_pattern.c_str(); *c != '\0'; ++c) {
switch (c[0]) {
case '(':
if (c[1] == '?') {
- RegExNodeGroup* group = NULL;
+ RegExNodeGroup *group = NULL;
switch (c[2]) {
case ':':
c = &c[2];
@@ -1033,7 +1029,7 @@ Error RegEx::compile(const String& p_pattern) {
break;
case 'P':
if (c[3] == '<') {
- const CharType* d = &c[3];
+ const CharType *d = &c[3];
Variant name = RegExNodeCapturing::parse_name(d, false);
if (name == Variant(-1))
REGEX_COMPILE_FAIL("unrecognised character for group name");
@@ -1051,14 +1047,14 @@ Error RegEx::compile(const String& p_pattern) {
} else if (numeric_groups < numeric_max) {
- RegExNodeCapturing* group = memnew(RegExNodeCapturing(group_names.size()));
+ RegExNodeCapturing *group = memnew(RegExNodeCapturing(group_names.size()));
group_names.push_back(++numeric_groups);
stack[0]->add_child(group);
stack.insert(0, group);
} else {
- RegExNodeGroup* group = memnew(RegExNodeGroup());
+ RegExNodeGroup *group = memnew(RegExNodeGroup());
stack[0]->add_child(group);
stack.insert(0, group);
}
@@ -1105,10 +1101,10 @@ Error RegEx::compile(const String& p_pattern) {
}
stack[0]->add_child(memnew(RegExNodeBackReference(ref)));
+ }
+ if (c[1] == 'g' && c[2] == '<') {
- } if (c[1] =='g' && c[2] == '<') {
-
- const CharType* d = &c[2];
+ const CharType *d = &c[2];
Variant name = RegExNodeCapturing::parse_name(d, true);
if (name == Variant(-1))
@@ -1144,103 +1140,100 @@ Error RegEx::compile(const String& p_pattern) {
} else {
- const CharType* d = c;
+ const CharType *d = c;
CharType ch = RegExNodeChar::parse_escape(d);
if (c == d)
REGEX_COMPILE_FAIL("invalid escape token");
stack[0]->add_child(memnew(RegExNodeChar(ch)));
c = d;
-
}
break;
- case '[':
- {
- RegExNodeBracket* bracket = memnew(RegExNodeBracket());
- stack[0]->add_child(bracket);
- if (c[1] == '^') {
- bracket->inverse = true;
- ++c;
- }
- bool first_child = true;
- CharType previous_child;
- bool previous_child_single = false;
- while (true) {
- ++c;
- if (!first_child && c[0] == ']') {
+ case '[': {
+ RegExNodeBracket *bracket = memnew(RegExNodeBracket());
+ stack[0]->add_child(bracket);
+ if (c[1] == '^') {
+ bracket->inverse = true;
+ ++c;
+ }
+ bool first_child = true;
+ CharType previous_child;
+ bool previous_child_single = false;
+ while (true) {
+ ++c;
+ if (!first_child && c[0] == ']') {
- break;
+ break;
- } else if (c[0] == '\0') {
+ } else if (c[0] == '\0') {
- REGEX_COMPILE_FAIL("unclosed bracket expression '['");
+ REGEX_COMPILE_FAIL("unclosed bracket expression '['");
- } else if (c[0] == '\\') {
+ } else if (c[0] == '\\') {
- if (RegEx_is_shorthand(c[1])) {
- bracket->add_child(memnew(RegExNodeShorthand(*(++c))));
- } else {
- const CharType* d = c;
- CharType ch = RegExNodeChar::parse_escape(d);
- if (c == d)
- REGEX_COMPILE_FAIL("invalid escape token");
- bracket->add_child(memnew(RegExNodeChar(ch)));
- c = d;
- previous_child = ch;
- previous_child_single = true;
- }
-
- } else if (c[0] == ']' && c[1] == ':') {
-
- const CharType* d = &c[2];
- RegExNodeClass::Type type = RegExNodeClass::parse_type(d);
- if (type != RegExNodeClass::Type_none) {
+ if (RegEx_is_shorthand(c[1])) {
+ bracket->add_child(memnew(RegExNodeShorthand(*(++c))));
+ } else {
+ const CharType *d = c;
+ CharType ch = RegExNodeChar::parse_escape(d);
+ if (c == d)
+ REGEX_COMPILE_FAIL("invalid escape token");
+ bracket->add_child(memnew(RegExNodeChar(ch)));
+ c = d;
+ previous_child = ch;
+ previous_child_single = true;
+ }
- c = d;
- previous_child_single = false;
+ } else if (c[0] == ']' && c[1] == ':') {
- } else {
+ const CharType *d = &c[2];
+ RegExNodeClass::Type type = RegExNodeClass::parse_type(d);
+ if (type != RegExNodeClass::Type_none) {
- bracket->add_child(memnew(RegExNodeChar('[')));
- previous_child = '[';
- previous_child_single = true;
- }
- } else if (previous_child_single && c[0] == '-') {
+ c = d;
+ previous_child_single = false;
- if (c[1] != '\0' && c[1] != ']') {
+ } else {
- CharType next;
+ bracket->add_child(memnew(RegExNodeChar('[')));
+ previous_child = '[';
+ previous_child_single = true;
+ }
+ } else if (previous_child_single && c[0] == '-') {
- if (c[1] == '\\') {
- const CharType* d = ++c;
- next = RegExNodeChar::parse_escape(d);
- if (c == d)
- REGEX_COMPILE_FAIL("invalid escape token");
- } else {
- next = *(++c);
- }
+ if (c[1] != '\0' && c[1] != ']') {
- if (next < previous_child)
- REGEX_COMPILE_FAIL("text range out of order");
+ CharType next;
- bracket->pop_back();
- bracket->add_child(memnew(RegExNodeRange(previous_child, next)));
- previous_child_single = false;
+ if (c[1] == '\\') {
+ const CharType *d = ++c;
+ next = RegExNodeChar::parse_escape(d);
+ if (c == d)
+ REGEX_COMPILE_FAIL("invalid escape token");
} else {
-
- bracket->add_child(memnew(RegExNodeChar('-')));
- previous_child = '-';
- previous_child_single = true;
+ next = *(++c);
}
+
+ if (next < previous_child)
+ REGEX_COMPILE_FAIL("text range out of order");
+
+ bracket->pop_back();
+ bracket->add_child(memnew(RegExNodeRange(previous_child, next)));
+ previous_child_single = false;
} else {
- bracket->add_child(memnew(RegExNodeChar(c[0])));
- previous_child = c[0];
+ bracket->add_child(memnew(RegExNodeChar('-')));
+ previous_child = '-';
previous_child_single = true;
}
- first_child = false;
+ } else {
+
+ bracket->add_child(memnew(RegExNodeChar(c[0])));
+ previous_child = c[0];
+ previous_child_single = true;
}
+ first_child = false;
}
- break;
+ } break;
case '|':
for (int i = 0; i < stack.size(); ++i)
if (stack[i]->is_look_behind())
@@ -1259,82 +1252,81 @@ Error RegEx::compile(const String& p_pattern) {
case '?':
case '*':
case '+':
- case '{':
- {
- int min_val = 0;
- int max_val = -1;
- bool valid = true;
- const CharType* d = c;
- bool max_set = true;
- switch (c[0]) {
- case '?':
- min_val = 0;
- max_val = 1;
- break;
- case '*':
- min_val = 0;
- max_val = -1;
- break;
- case '+':
- min_val = 1;
- max_val = -1;
- break;
- case '{':
- max_set = false;
- while (valid) {
- ++d;
- if (d[0] == '}') {
- break;
- } else if (d[0] == ',') {
- max_set = true;
- } else if ('0' <= d[0] && d[0] <= '9') {
- if (max_set) {
- if (max_val < 0)
- max_val = int(d[0] - '0');
- else
- max_val = max_val * 10 + int(d[0] - '0');
- } else {
- min_val = min_val * 10 + int(d[0] - '0');
- }
+ case '{': {
+ int min_val = 0;
+ int max_val = -1;
+ bool valid = true;
+ const CharType *d = c;
+ bool max_set = true;
+ switch (c[0]) {
+ case '?':
+ min_val = 0;
+ max_val = 1;
+ break;
+ case '*':
+ min_val = 0;
+ max_val = -1;
+ break;
+ case '+':
+ min_val = 1;
+ max_val = -1;
+ break;
+ case '{':
+ max_set = false;
+ while (valid) {
+ ++d;
+ if (d[0] == '}') {
+ break;
+ } else if (d[0] == ',') {
+ max_set = true;
+ } else if ('0' <= d[0] && d[0] <= '9') {
+ if (max_set) {
+ if (max_val < 0)
+ max_val = int(d[0] - '0');
+ else
+ max_val = max_val * 10 + int(d[0] - '0');
} else {
- valid = false;
+ min_val = min_val * 10 + int(d[0] - '0');
}
+ } else {
+ valid = false;
}
- break;
- default:
- break;
- }
+ }
+ break;
+ default:
+ break;
+ }
- if (!max_set)
- max_val = min_val;
+ if (!max_set)
+ max_val = min_val;
- if (valid) {
+ if (valid) {
- c = d;
+ c = d;
- if (stack[0]->back == NULL || !stack[0]->back->quantifiable)
- REGEX_COMPILE_FAIL("element not quantifiable");
+ if (stack[0]->back == NULL || !stack[0]->back->quantifiable)
+ REGEX_COMPILE_FAIL("element not quantifiable");
- if (min_val != max_val)
- for (int i = 0; i < stack.size(); ++i)
- if (stack[i]->is_look_behind())
- REGEX_COMPILE_FAIL("variable length quantifiers inside lookbehind not supported");
+ if (min_val != max_val)
+ for (int i = 0; i < stack.size(); ++i)
+ if (stack[i]->is_look_behind())
+ REGEX_COMPILE_FAIL("variable length quantifiers inside lookbehind not supported");
- RegExNodeQuantifier* quant = memnew(RegExNodeQuantifier(min_val, max_val));
- quant->child = stack[0]->swap_back(quant);
- quant->child->previous = NULL;
- quant->child->parent = quant;
+ RegExNodeQuantifier *quant = memnew(RegExNodeQuantifier(min_val, max_val));
+ quant->child = stack[0]->swap_back(quant);
+ quant->child->previous = NULL;
+ quant->child->parent = quant;
- if (min_val == max_val && quant->child->length >= 0)
- quant->length = max_val * quant->child->length;
+ if (min_val == max_val && quant->child->length >= 0)
+ quant->length = max_val * quant->child->length;
- if (c[1] == '?') {
- quant->greedy = false;
- ++c;
- }
- break;
+ if (c[1] == '?') {
+ quant->greedy = false;
+ ++c;
}
+ break;
}
+ }
default:
stack[0]->add_child(memnew(RegExNodeChar(c[0])));
break;
@@ -1345,7 +1337,7 @@ Error RegEx::compile(const String& p_pattern) {
return OK;
}
-Ref<RegExMatch> RegEx::search(const String& p_text, int p_start, int p_end) const {
+Ref<RegExMatch> RegEx::search(const String &p_text, int p_start, int p_end) const {
ERR_FAIL_COND_V(!is_valid(), NULL);
ERR_FAIL_COND_V(p_start < 0, NULL);
@@ -1382,7 +1374,7 @@ Ref<RegExMatch> RegEx::search(const String& p_text, int p_start, int p_end) cons
return NULL;
}
-String RegEx::sub(const String& p_text, const String& p_replacement, bool p_all, int p_start, int p_end) const {
+String RegEx::sub(const String &p_text, const String &p_replacement, bool p_all, int p_start, int p_end) const {
ERR_FAIL_COND_V(!is_valid(), p_text);
ERR_FAIL_COND_V(p_start < 0, p_text);
@@ -1400,7 +1392,7 @@ String RegEx::sub(const String& p_text, const String& p_replacement, bool p_all,
Ref<RegExMatch> m = search(text, start, p_end);
- RegExMatch::Group& s = m->captures[0];
+ RegExMatch::Group &s = m->captures[0];
if (s.start < 0)
break;
@@ -1467,7 +1459,7 @@ RegEx::RegEx() {
lookahead_depth = 0;
}
-RegEx::RegEx(const String& p_pattern) {
+RegEx::RegEx(const String &p_pattern) {
root = NULL;
compile(p_pattern);
@@ -1481,27 +1473,26 @@ RegEx::~RegEx() {
void RegExMatch::_bind_methods() {
- ClassDB::bind_method(D_METHOD("expand","template"),&RegExMatch::expand);
- ClassDB::bind_method(D_METHOD("get_group_count"),&RegExMatch::get_group_count);
- ClassDB::bind_method(D_METHOD("get_group_array"),&RegExMatch::get_group_array);
- ClassDB::bind_method(D_METHOD("get_names"),&RegExMatch::get_names);
- ClassDB::bind_method(D_METHOD("get_name_dict"),&RegExMatch::get_name_dict);
- ClassDB::bind_method(D_METHOD("get_string","name"),&RegExMatch::get_string, DEFVAL(0));
- ClassDB::bind_method(D_METHOD("get_start","name"),&RegExMatch::get_start, DEFVAL(0));
- ClassDB::bind_method(D_METHOD("get_end","name"),&RegExMatch::get_end, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("expand", "template"), &RegExMatch::expand);
+ ClassDB::bind_method(D_METHOD("get_group_count"), &RegExMatch::get_group_count);
+ ClassDB::bind_method(D_METHOD("get_group_array"), &RegExMatch::get_group_array);
+ ClassDB::bind_method(D_METHOD("get_names"), &RegExMatch::get_names);
+ ClassDB::bind_method(D_METHOD("get_name_dict"), &RegExMatch::get_name_dict);
+ ClassDB::bind_method(D_METHOD("get_string", "name"), &RegExMatch::get_string, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_start", "name"), &RegExMatch::get_start, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_end", "name"), &RegExMatch::get_end, DEFVAL(0));
}
void RegEx::_bind_methods() {
- ClassDB::bind_method(D_METHOD("clear"),&RegEx::clear);
- ClassDB::bind_method(D_METHOD("compile","pattern"),&RegEx::compile);
- ClassDB::bind_method(D_METHOD("search","text","start","end"),&RegEx::search, DEFVAL(0), DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("sub","text","replacement","all","start","end"),&RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("is_valid"),&RegEx::is_valid);
- ClassDB::bind_method(D_METHOD("get_pattern"),&RegEx::get_pattern);
- ClassDB::bind_method(D_METHOD("get_group_count"),&RegEx::get_group_count);
- ClassDB::bind_method(D_METHOD("get_names"),&RegEx::get_names);
+ ClassDB::bind_method(D_METHOD("clear"), &RegEx::clear);
+ ClassDB::bind_method(D_METHOD("compile", "pattern"), &RegEx::compile);
+ ClassDB::bind_method(D_METHOD("search", "text", "start", "end"), &RegEx::search, DEFVAL(0), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("sub", "text", "replacement", "all", "start", "end"), &RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("is_valid"), &RegEx::is_valid);
+ ClassDB::bind_method(D_METHOD("get_pattern"), &RegEx::get_pattern);
+ ClassDB::bind_method(D_METHOD("get_group_count"), &RegEx::get_group_count);
+ ClassDB::bind_method(D_METHOD("get_names"), &RegEx::get_names);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "pattern"), "compile", "get_pattern");
}
-
diff --git a/modules/regex/regex.h b/modules/regex/regex.h
index 193d818da3..7aecf9b3ec 100644
--- a/modules/regex/regex.h
+++ b/modules/regex/regex.h
@@ -30,11 +30,11 @@
#ifndef REGEX_H
#define REGEX_H
-#include "core/vector.h"
-#include "core/ustring.h"
#include "core/dictionary.h"
#include "core/reference.h"
#include "core/resource.h"
+#include "core/ustring.h"
+#include "core/vector.h"
class RegExNode;
@@ -57,12 +57,10 @@ class RegExMatch : public Reference {
friend class RegExNodeBackReference;
protected:
-
static void _bind_methods();
public:
-
- String expand(const String& p_template) const;
+ String expand(const String &p_template) const;
int get_group_count() const;
Array get_group_array() const;
@@ -70,34 +68,31 @@ public:
Array get_names() const;
Dictionary get_name_dict() const;
- String get_string(const Variant& p_name) const;
- int get_start(const Variant& p_name) const;
- int get_end(const Variant& p_name) const;
+ String get_string(const Variant &p_name) const;
+ int get_start(const Variant &p_name) const;
+ int get_end(const Variant &p_name) const;
RegExMatch();
-
};
class RegEx : public Resource {
GDCLASS(RegEx, Resource);
- RegExNode* root;
+ RegExNode *root;
Vector<Variant> group_names;
String pattern;
int lookahead_depth;
protected:
-
static void _bind_methods();
public:
-
void clear();
- Error compile(const String& p_pattern);
+ Error compile(const String &p_pattern);
- Ref<RegExMatch> search(const String& p_text, int p_start = 0, int p_end = -1) const;
- String sub(const String& p_text, const String& p_replacement, bool p_all = false, int p_start = 0, int p_end = -1) const;
+ Ref<RegExMatch> search(const String &p_text, int p_start = 0, int p_end = -1) const;
+ String sub(const String &p_text, const String &p_replacement, bool p_all = false, int p_start = 0, int p_end = -1) const;
bool is_valid() const;
String get_pattern() const;
@@ -105,10 +100,8 @@ public:
Array get_names() const;
RegEx();
- RegEx(const String& p_pattern);
+ RegEx(const String &p_pattern);
~RegEx();
-
};
#endif // REGEX_H
-
diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp
index c62a04d80f..2e24edcd84 100644
--- a/modules/regex/register_types.cpp
+++ b/modules/regex/register_types.cpp
@@ -38,6 +38,4 @@ void register_regex_types() {
}
void unregister_regex_types() {
-
}
-
diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp
index 28c200596b..dd46dac234 100644
--- a/modules/squish/image_compress_squish.cpp
+++ b/modules/squish/image_compress_squish.cpp
@@ -34,58 +34,61 @@
void image_compress_squish(Image *p_image) {
- int w=p_image->get_width();
- int h=p_image->get_height();
+ 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);
+ if (!p_image->has_mipmaps()) {
+ ERR_FAIL_COND(!w || w % 4 != 0);
+ ERR_FAIL_COND(!h || h % 4 != 0);
} else {
- ERR_FAIL_COND( !w || w !=nearest_power_of_2(w) );
- ERR_FAIL_COND( !h || h !=nearest_power_of_2(h) );
+ ERR_FAIL_COND(!w || w != nearest_power_of_2(w));
+ ERR_FAIL_COND(!h || h != nearest_power_of_2(h));
};
- if (p_image->get_format()>=Image::FORMAT_DXT1)
+ if (p_image->get_format() >= Image::FORMAT_DXT1)
return; //do not compress, already compressed
- int shift=0;
- int squish_comp=squish::kColourRangeFit;
+ int shift = 0;
+ int squish_comp = squish::kColourRangeFit;
Image::Format target_format;
- if (p_image->get_format()==Image::FORMAT_LA8) {
+ 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) {
+ target_format = Image::FORMAT_DXT5;
+ squish_comp |= squish::kDxt5;
+ } else if (p_image->detect_alpha() != Image::ALPHA_NONE) {
- target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3;
+ target_format = Image::FORMAT_DXT3;
+ squish_comp |= squish::kDxt3;
} else {
- target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1;
+ target_format = Image::FORMAT_DXT1;
+ shift = 1;
+ squish_comp |= squish::kDxt1;
}
p_image->convert(Image::FORMAT_RGBA8); //always expects rgba
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;
+ 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);
PoolVector<uint8_t>::Read rb = p_image->get_data().read();
PoolVector<uint8_t>::Write wb = data.write();
- int dst_ofs=0;
+ int dst_ofs = 0;
- for(int i=0;i<=mm_count;i++) {
+ for (int i = 0; i <= mm_count; i++) {
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;
+ 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;
}
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);
-
+ p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
}
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index d3d7ab2307..884eb905fa 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -28,20 +28,19 @@
/*************************************************************************/
#include "audio_stream_ogg_vorbis.h"
-#include "thirdparty/stb_vorbis/stb_vorbis.c"
#include "os/file_access.h"
+#include "thirdparty/stb_vorbis/stb_vorbis.c"
-
-void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_frames) {
+void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) {
ERR_FAIL_COND(!active);
- int todo=p_frames;
+ int todo = p_frames;
- while(todo) {
+ while (todo) {
- int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream,2,(float*)p_buffer,todo*2);
- todo-=mixed;
+ int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2);
+ todo -= mixed;
if (todo) {
//end of file!
@@ -50,15 +49,13 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_fram
seek_pos(0);
loops++;
} else {
- for(int i=mixed;i<p_frames;i++) {
- p_buffer[i]=AudioFrame(0,0);
+ for (int i = mixed; i < p_frames; i++) {
+ p_buffer[i] = AudioFrame(0, 0);
}
- active=false;
+ active = false;
}
}
}
-
-
}
float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() {
@@ -66,20 +63,17 @@ float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() {
return vorbis_stream->sample_rate;
}
-
void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) {
seek_pos(p_from_pos);
- active=true;
- loops=0;
+ active = true;
+ loops = 0;
_begin_resample();
-
-
}
void AudioStreamPlaybackOGGVorbis::stop() {
- active=false;
+ active = false;
}
bool AudioStreamPlaybackOGGVorbis::is_playing() const {
@@ -93,14 +87,14 @@ int AudioStreamPlaybackOGGVorbis::get_loop_count() const {
float AudioStreamPlaybackOGGVorbis::get_pos() const {
- return float(frames_mixed)/vorbis_stream->sample_rate;
+ return float(frames_mixed) / vorbis_stream->sample_rate;
}
void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) {
if (!active)
return;
- stb_vorbis_seek(ogg_stream, uint32_t(p_time*vorbis_stream->sample_rate));
+ stb_vorbis_seek(ogg_stream, uint32_t(p_time * vorbis_stream->sample_rate));
}
float AudioStreamPlaybackOGGVorbis::get_length() const {
@@ -117,27 +111,25 @@ AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() {
Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() {
-
-
Ref<AudioStreamPlaybackOGGVorbis> ovs;
- printf("instance at %p, data %p\n",this,data);
+ printf("instance at %p, data %p\n", this, data);
- ERR_FAIL_COND_V(data==NULL,ovs);
+ ERR_FAIL_COND_V(data == NULL, ovs);
ovs.instance();
- ovs->vorbis_stream=Ref<AudioStreamOGGVorbis>(this);
- ovs->ogg_alloc.alloc_buffer=(char*)AudioServer::get_singleton()->audio_data_alloc(decode_mem_size);
- ovs->ogg_alloc.alloc_buffer_length_in_bytes=decode_mem_size;
- ovs->frames_mixed=0;
- ovs->active=false;
- ovs->loops=0;
- int error ;
- ovs->ogg_stream = stb_vorbis_open_memory( (const unsigned char*)data, data_len, &error, &ovs->ogg_alloc );
+ ovs->vorbis_stream = Ref<AudioStreamOGGVorbis>(this);
+ ovs->ogg_alloc.alloc_buffer = (char *)AudioServer::get_singleton()->audio_data_alloc(decode_mem_size);
+ ovs->ogg_alloc.alloc_buffer_length_in_bytes = decode_mem_size;
+ ovs->frames_mixed = 0;
+ ovs->active = false;
+ ovs->loops = 0;
+ int error;
+ ovs->ogg_stream = stb_vorbis_open_memory((const unsigned char *)data, data_len, &error, &ovs->ogg_alloc);
if (!ovs->ogg_stream) {
AudioServer::get_singleton()->audio_data_free(ovs->ogg_alloc.alloc_buffer);
- ovs->ogg_alloc.alloc_buffer=NULL;
- ERR_FAIL_COND_V(!ovs->ogg_stream,Ref<AudioStreamPlaybackOGGVorbis>());
+ ovs->ogg_alloc.alloc_buffer = NULL;
+ ERR_FAIL_COND_V(!ovs->ogg_stream, Ref<AudioStreamPlaybackOGGVorbis>());
}
return ovs;
@@ -145,40 +137,40 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() {
String AudioStreamOGGVorbis::get_stream_name() const {
- return "";//return stream_name;
+ return ""; //return stream_name;
}
-void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) {
+void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
- int src_data_len=p_data.size();
-#define MAX_TEST_MEM (1<<20)
+ int src_data_len = p_data.size();
+#define MAX_TEST_MEM (1 << 20)
- uint32_t alloc_try=1024;
+ uint32_t alloc_try = 1024;
PoolVector<char> alloc_mem;
PoolVector<char>::Write w;
- stb_vorbis * ogg_stream=NULL;
+ stb_vorbis *ogg_stream = NULL;
stb_vorbis_alloc ogg_alloc;
- while(alloc_try<MAX_TEST_MEM) {
+ while (alloc_try < MAX_TEST_MEM) {
alloc_mem.resize(alloc_try);
w = alloc_mem.write();
- ogg_alloc.alloc_buffer=w.ptr();
- ogg_alloc.alloc_buffer_length_in_bytes=alloc_try;
+ ogg_alloc.alloc_buffer = w.ptr();
+ ogg_alloc.alloc_buffer_length_in_bytes = alloc_try;
PoolVector<uint8_t>::Read src_datar = p_data.read();
int error;
- ogg_stream = stb_vorbis_open_memory( (const unsigned char*)src_datar.ptr(), src_data_len, &error, &ogg_alloc );
+ ogg_stream = stb_vorbis_open_memory((const unsigned char *)src_datar.ptr(), src_data_len, &error, &ogg_alloc);
- if (!ogg_stream && error==VORBIS_outofmem) {
+ if (!ogg_stream && error == VORBIS_outofmem) {
w = PoolVector<char>::Write();
- alloc_try*=2;
+ alloc_try *= 2;
} else {
- ERR_FAIL_COND(alloc_try==MAX_TEST_MEM);
- ERR_FAIL_COND(ogg_stream==NULL);
+ ERR_FAIL_COND(alloc_try == MAX_TEST_MEM);
+ ERR_FAIL_COND(ogg_stream == NULL);
stb_vorbis_info info = stb_vorbis_get_info(ogg_stream);
@@ -190,19 +182,17 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) {
//print_line("succeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size));
- length=stb_vorbis_stream_length_in_seconds(ogg_stream);
+ length = stb_vorbis_stream_length_in_seconds(ogg_stream);
stb_vorbis_close(ogg_stream);
- data = AudioServer::get_singleton()->audio_data_alloc(src_data_len,src_datar.ptr());
- data_len=src_data_len;
+ data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr());
+ data_len = src_data_len;
break;
}
}
-
- printf("create at %p, data %p\n",this,data);
-
+ printf("create at %p, data %p\n", this, data);
}
PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const {
@@ -213,16 +203,15 @@ PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const {
vdata.resize(data_len);
{
PoolVector<uint8_t>::Write w = vdata.write();
- copymem(w.ptr(),data,data_len);
+ copymem(w.ptr(), data, data_len);
}
-
}
return vdata;
}
void AudioStreamOGGVorbis::set_loop(bool p_enable) {
- loop=p_enable;
+ loop = p_enable;
}
bool AudioStreamOGGVorbis::has_loop() const {
@@ -230,31 +219,24 @@ bool AudioStreamOGGVorbis::has_loop() const {
return loop;
}
-
void AudioStreamOGGVorbis::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_data","data"),&AudioStreamOGGVorbis::set_data);
- ClassDB::bind_method(D_METHOD("get_data"),&AudioStreamOGGVorbis::get_data);
-
- ClassDB::bind_method(D_METHOD("set_loop","enable"),&AudioStreamOGGVorbis::set_loop);
- ClassDB::bind_method(D_METHOD("has_loop"),&AudioStreamOGGVorbis::has_loop);
+ ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamOGGVorbis::set_data);
+ ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamOGGVorbis::get_data);
- ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_data","get_data");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"loop",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_loop","has_loop");
+ ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop);
+ ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop);
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop", "has_loop");
}
AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
-
- data=NULL;
- length=0;
- sample_rate=1;
- channels=1;
- decode_mem_size=0;
- loop=false;
+ data = NULL;
+ length = 0;
+ sample_rate = 1;
+ channels = 1;
+ decode_mem_size = 0;
+ loop = false;
}
-
-
-
-
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
index 2313fc4ae3..c32b3e578d 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
@@ -29,36 +29,35 @@
#ifndef AUDIO_STREAM_STB_VORBIS_H
#define AUDIO_STREAM_STB_VORBIS_H
-#include "servers/audio/audio_stream.h"
#include "io/resource_loader.h"
+#include "servers/audio/audio_stream.h"
#define STB_VORBIS_HEADER_ONLY
#include "thirdparty/stb_vorbis/stb_vorbis.c"
#undef STB_VORBIS_HEADER_ONLY
-
class AudioStreamOGGVorbis;
class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled {
- GDCLASS( AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled )
+ GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled)
- stb_vorbis * ogg_stream;
+ stb_vorbis *ogg_stream;
stb_vorbis_alloc ogg_alloc;
uint32_t frames_mixed;
bool active;
int loops;
-friend class AudioStreamOGGVorbis;
+ friend class AudioStreamOGGVorbis;
Ref<AudioStreamOGGVorbis> vorbis_stream;
-protected:
- virtual void _mix_internal(AudioFrame* p_buffer, int p_frames);
+protected:
+ virtual void _mix_internal(AudioFrame *p_buffer, int p_frames);
virtual float get_stream_sampling_rate();
public:
- virtual void start(float p_from_pos=0.0);
+ virtual void start(float p_from_pos = 0.0);
virtual void stop();
virtual bool is_playing() const;
@@ -69,17 +68,17 @@ public:
virtual float get_length() const; //if supported, otherwise return 0
- AudioStreamPlaybackOGGVorbis() { }
+ AudioStreamPlaybackOGGVorbis() {}
~AudioStreamPlaybackOGGVorbis();
};
class AudioStreamOGGVorbis : public AudioStream {
- GDCLASS( AudioStreamOGGVorbis, AudioStream )
- OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged
+ GDCLASS(AudioStreamOGGVorbis, AudioStream)
+ OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged
RES_BASE_EXTENSION("asogg");
-friend class AudioStreamPlaybackOGGVorbis;
+ friend class AudioStreamPlaybackOGGVorbis;
void *data;
uint32_t data_len;
@@ -89,23 +88,21 @@ friend class AudioStreamPlaybackOGGVorbis;
int channels;
float length;
bool loop;
-protected:
+protected:
static void _bind_methods();
-public:
+public:
void set_loop(bool p_enable);
bool has_loop() const;
virtual Ref<AudioStreamPlayback> instance_playback();
virtual String get_stream_name() const;
- void set_data(const PoolVector<uint8_t>& p_data);
+ void set_data(const PoolVector<uint8_t> &p_data);
PoolVector<uint8_t> get_data() const;
AudioStreamOGGVorbis();
};
-
-
#endif
diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp
index 41fbc6fbd7..36b7ebc11a 100644
--- a/modules/stb_vorbis/register_types.cpp
+++ b/modules/stb_vorbis/register_types.cpp
@@ -41,5 +41,4 @@ void register_stb_vorbis_types() {
}
void unregister_stb_vorbis_types() {
-
}
diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
index 03495652d4..11d8551db5 100644
--- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
@@ -37,11 +37,11 @@ String ResourceImporterOGGVorbis::get_importer_name() const {
return "ogg_vorbis";
}
-String ResourceImporterOGGVorbis::get_visible_name() const{
+String ResourceImporterOGGVorbis::get_visible_name() const {
return "OGGVorbis";
}
-void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const{
+void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("ogg");
}
@@ -50,12 +50,12 @@ String ResourceImporterOGGVorbis::get_save_extension() const {
return "asogg";
}
-String ResourceImporterOGGVorbis::get_resource_type() const{
+String ResourceImporterOGGVorbis::get_resource_type() const {
return "AudioStreamOGGVorbis";
}
-bool ResourceImporterOGGVorbis::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const {
+bool ResourceImporterOGGVorbis::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
return true;
}
@@ -68,23 +68,18 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const {
return String();
}
+void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const {
-void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options,int p_preset) const {
-
-
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"loop"),true));
-
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true));
}
-
-
-Error ResourceImporterOGGVorbis::import(const String& p_source_file, const String& p_save_path, const Map<StringName,Variant>& p_options, List<String>* r_platform_variants, List<String> *r_gen_files) {
+Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
bool loop = p_options["loop"];
- FileAccess *f = FileAccess::open(p_source_file,FileAccess::READ);
+ FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ);
if (!f) {
- ERR_FAIL_COND_V(!f,ERR_CANT_OPEN);
+ ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
}
size_t len = f->get_len();
@@ -93,7 +88,7 @@ Error ResourceImporterOGGVorbis::import(const String& p_source_file, const Strin
data.resize(len);
PoolVector<uint8_t>::Write w = data.write();
- f->get_buffer(w.ptr(),len);
+ f->get_buffer(w.ptr(), len);
memdelete(f);
@@ -103,10 +98,8 @@ 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 + ".asogg", ogg_stream);
}
-ResourceImporterOGGVorbis::ResourceImporterOGGVorbis()
-{
-
+ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() {
}
diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h
index 15fc2cd2f3..2f0fcbe9a1 100644
--- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h
+++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h
@@ -29,12 +29,11 @@
#ifndef RESOURCEIMPORTEROGGVORBIS_H
#define RESOURCEIMPORTEROGGVORBIS_H
-
-#include "io/resource_import.h"
#include "audio_stream_ogg_vorbis.h"
+#include "io/resource_import.h"
class ResourceImporterOGGVorbis : public ResourceImporter {
- GDCLASS(ResourceImporterOGGVorbis,ResourceImporter)
+ GDCLASS(ResourceImporterOGGVorbis, ResourceImporter)
public:
virtual String get_importer_name() const;
virtual String get_visible_name() const;
@@ -45,10 +44,10 @@ public:
virtual int get_preset_count() const;
virtual String get_preset_name(int p_idx) const;
- virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const;
- virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const;
+ virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
+ virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- virtual Error import(const String& p_source_file,const String& p_save_path,const Map<StringName,Variant>& p_options,List<String>* r_platform_variants,List<String>* r_gen_files=NULL);
+ virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL);
ResourceImporterOGGVorbis();
};
diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp
index 58f63465c9..deb54b5d80 100644
--- a/modules/theora/register_types.cpp
+++ b/modules/theora/register_types.cpp
@@ -30,16 +30,16 @@
#include "video_stream_theora.h"
-static ResourceFormatLoaderVideoStreamTheora* theora_stream_loader = NULL;
+static ResourceFormatLoaderVideoStreamTheora *theora_stream_loader = NULL;
void register_theora_types() {
- theora_stream_loader = memnew( ResourceFormatLoaderVideoStreamTheora );
+ theora_stream_loader = memnew(ResourceFormatLoaderVideoStreamTheora);
ResourceLoader::add_resource_format_loader(theora_stream_loader);
ClassDB::register_class<VideoStreamTheora>();
}
void unregister_theora_types() {
- memdelete( theora_stream_loader );
+ memdelete(theora_stream_loader);
}
diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp
index 2a7b2707bf..c390701adb 100644
--- a/modules/theora/video_stream_theora.cpp
+++ b/modules/theora/video_stream_theora.cpp
@@ -32,9 +32,9 @@
#include "os/os.h"
#include "yuv2rgb.h"
-int VideoStreamPlaybackTheora:: buffer_data() {
+int VideoStreamPlaybackTheora::buffer_data() {
- char *buffer=ogg_sync_buffer(&oy,4096);
+ char *buffer = ogg_sync_buffer(&oy, 4096);
#ifdef THEORA_USE_THREAD_STREAMING
@@ -42,44 +42,44 @@ int VideoStreamPlaybackTheora:: buffer_data() {
do {
thread_sem->post();
- read = MIN(ring_buffer.data_left(),4096);
+ read = MIN(ring_buffer.data_left(), 4096);
if (read) {
- ring_buffer.read((uint8_t*)buffer,read);
- ogg_sync_wrote(&oy,read);
+ ring_buffer.read((uint8_t *)buffer, read);
+ ogg_sync_wrote(&oy, read);
} else {
OS::get_singleton()->delay_usec(100);
}
- } while(read==0);
+ } while (read == 0);
return read;
#else
- int bytes=file->get_buffer((uint8_t*)buffer, 4096);
- ogg_sync_wrote(&oy,bytes);
- return(bytes);
+ int bytes = file->get_buffer((uint8_t *)buffer, 4096);
+ ogg_sync_wrote(&oy, bytes);
+ return (bytes);
#endif
}
-int VideoStreamPlaybackTheora::queue_page(ogg_page *page){
- if(theora_p) {
- ogg_stream_pagein(&to,page);
- if (to.e_o_s)
- theora_eos=true;
- }
- if(vorbis_p) {
- ogg_stream_pagein(&vo,page);
- if (vo.e_o_s)
- vorbis_eos=true;
- }
- return 0;
+int VideoStreamPlaybackTheora::queue_page(ogg_page *page) {
+ if (theora_p) {
+ ogg_stream_pagein(&to, page);
+ if (to.e_o_s)
+ theora_eos = true;
+ }
+ if (vorbis_p) {
+ ogg_stream_pagein(&vo, page);
+ if (vo.e_o_s)
+ vorbis_eos = true;
+ }
+ return 0;
}
-void VideoStreamPlaybackTheora::video_write(void){
+void VideoStreamPlaybackTheora::video_write(void) {
th_ycbcr_buffer yuv;
- th_decode_ycbcr_out(td,yuv);
+ th_decode_ycbcr_out(td, yuv);
// FIXME: The way stuff is commented out with `//*/` closing comments
// sounds very fishy...
@@ -116,27 +116,27 @@ void VideoStreamPlaybackTheora::video_write(void){
frame_data.resize(size.x * size.y * pitch);
{
PoolVector<uint8_t>::Write w = frame_data.write();
- char* dst = (char*)w.ptr();
+ char *dst = (char *)w.ptr();
//uv_offset=(ti.pic_x/2)+(yuv[1].stride)*(ti.pic_y/2);
if (px_fmt == TH_PF_444) {
- yuv444_2_rgb8888((uint8_t*)dst, (uint8_t*)yuv[0].data, (uint8_t*)yuv[1].data, (uint8_t*)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x<<2, 0);
+ yuv444_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2, 0);
} else if (px_fmt == TH_PF_422) {
- yuv422_2_rgb8888((uint8_t*)dst, (uint8_t*)yuv[0].data, (uint8_t*)yuv[1].data, (uint8_t*)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x<<2, 0);
+ yuv422_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2, 0);
} else if (px_fmt == TH_PF_420) {
- yuv420_2_rgb8888((uint8_t*)dst, (uint8_t*)yuv[0].data, (uint8_t*)yuv[2].data, (uint8_t*)yuv[1].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x<<2, 0);
+ yuv420_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[2].data, (uint8_t *)yuv[1].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2, 0);
};
format = Image::FORMAT_RGBA8;
}
- Image img(size.x,size.y,0,Image::FORMAT_RGBA8,frame_data); //zero copy image creation
+ Image img(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data); //zero copy image creation
texture->set_data(img); //zero copy send to visual server
@@ -241,7 +241,7 @@ void VideoStreamPlaybackTheora::clear() {
if (!file)
return;
- if(vorbis_p){
+ if (vorbis_p) {
ogg_stream_clear(&vo);
if (vorbis_p >= 3) {
vorbis_block_clear(&vb);
@@ -251,7 +251,7 @@ void VideoStreamPlaybackTheora::clear() {
vorbis_info_clear(&vi);
vorbis_p = 0;
}
- if(theora_p){
+ if (theora_p) {
ogg_stream_clear(&to);
th_decode_free(td);
th_comment_clear(&tc);
@@ -261,11 +261,11 @@ void VideoStreamPlaybackTheora::clear() {
ogg_sync_clear(&oy);
#ifdef THEORA_USE_THREAD_STREAMING
- thread_exit=true;
+ thread_exit = true;
thread_sem->post(); //just in case
Thread::wait_to_finish(thread);
memdelete(thread);
- thread=NULL;
+ thread = NULL;
ring_buffer.clear();
#endif
//file_name = "";
@@ -275,21 +275,21 @@ void VideoStreamPlaybackTheora::clear() {
videobuf_ready = 0;
frames_pending = 0;
videobuf_time = 0;
- theora_eos=false;
- vorbis_eos=false;
+ theora_eos = false;
+ vorbis_eos = false;
if (file) {
memdelete(file);
}
- file=NULL;
+ file = NULL;
playing = false;
};
-void VideoStreamPlaybackTheora::set_file(const String& p_file) {
+void VideoStreamPlaybackTheora::set_file(const String &p_file) {
ERR_FAIL_COND(playing);
ogg_packet op;
- th_setup_info *ts = NULL;
+ th_setup_info *ts = NULL;
file_name = p_file;
if (file) {
@@ -299,14 +299,14 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
ERR_FAIL_COND(!file);
#ifdef THEORA_USE_THREAD_STREAMING
- thread_exit=false;
- thread_eof=false;
+ thread_exit = false;
+ thread_eof = false;
//pre-fill buffer
int to_read = ring_buffer.space_left();
- int read = file->get_buffer(read_buffer.ptr(),to_read);
- ring_buffer.write(read_buffer.ptr(),read);
+ int read = file->get_buffer(read_buffer.ptr(), to_read);
+ ring_buffer.write(read_buffer.ptr(), read);
- thread=Thread::create(_streaming_thread,this);
+ thread = Thread::create(_streaming_thread, this);
#endif
@@ -320,42 +320,39 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
th_comment_init(&tc);
th_info_init(&ti);
- theora_eos=false;
- vorbis_eos=false;
+ theora_eos = false;
+ vorbis_eos = false;
/* Ogg file open; parse the headers */
/* Only interested in Vorbis/Theora streams */
int stateflag = 0;
- int audio_track_skip=audio_track;
-
+ int audio_track_skip = audio_track;
- while(!stateflag){
- int ret=buffer_data();
- if(ret==0)break;
- while(ogg_sync_pageout(&oy,&og)>0){
+ while (!stateflag) {
+ int ret = buffer_data();
+ if (ret == 0) break;
+ while (ogg_sync_pageout(&oy, &og) > 0) {
ogg_stream_state test;
/* is this a mandated initial header? If not, stop parsing */
- if(!ogg_page_bos(&og)){
+ if (!ogg_page_bos(&og)) {
/* don't leak the page; get it into the appropriate stream */
queue_page(&og);
- stateflag=1;
+ stateflag = 1;
break;
}
- ogg_stream_init(&test,ogg_page_serialno(&og));
- ogg_stream_pagein(&test,&og);
- ogg_stream_packetout(&test,&op);
-
+ ogg_stream_init(&test, ogg_page_serialno(&og));
+ ogg_stream_pagein(&test, &og);
+ ogg_stream_packetout(&test, &op);
/* identify the codec: try theora */
- if(!theora_p && th_decode_headerin(&ti,&tc,&ts,&op)>=0){
+ if (!theora_p && th_decode_headerin(&ti, &tc, &ts, &op) >= 0) {
/* it is theora */
- copymem(&to,&test,sizeof(test));
- theora_p=1;
- }else if(!vorbis_p && vorbis_synthesis_headerin(&vi,&vc,&op)>=0){
-
+ copymem(&to, &test, sizeof(test));
+ theora_p = 1;
+ } else if (!vorbis_p && vorbis_synthesis_headerin(&vi, &vc, &op) >= 0) {
/* it is vorbis */
if (audio_track_skip) {
@@ -367,10 +364,10 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
audio_track_skip--;
} else {
- copymem(&vo,&test,sizeof(test));
- vorbis_p=1;
+ copymem(&vo, &test, sizeof(test));
+ vorbis_p = 1;
}
- }else{
+ } else {
/* whatever it is, we don't care about it */
ogg_stream_clear(&test);
}
@@ -379,20 +376,20 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
}
/* we're expecting more header packets. */
- while((theora_p && theora_p<3) || (vorbis_p && vorbis_p<3)){
+ while ((theora_p && theora_p < 3) || (vorbis_p && vorbis_p < 3)) {
int ret;
/* look for further theora headers */
- while(theora_p && (theora_p<3) && (ret=ogg_stream_packetout(&to,&op))){
- if(ret<0){
- fprintf(stderr,"Error parsing Theora stream headers; "
- "corrupt stream?\n");
+ while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout(&to, &op))) {
+ if (ret < 0) {
+ fprintf(stderr, "Error parsing Theora stream headers; "
+ "corrupt stream?\n");
clear();
return;
}
- if(!th_decode_headerin(&ti,&tc,&ts,&op)){
- fprintf(stderr,"Error parsing Theora stream headers; "
- "corrupt stream?\n");
+ if (!th_decode_headerin(&ti, &tc, &ts, &op)) {
+ fprintf(stderr, "Error parsing Theora stream headers; "
+ "corrupt stream?\n");
clear();
return;
}
@@ -400,31 +397,31 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
}
/* look for more vorbis header packets */
- while(vorbis_p && (vorbis_p<3) && (ret=ogg_stream_packetout(&vo,&op))){
- if(ret<0){
- fprintf(stderr,"Error parsing Vorbis stream headers; corrupt stream?\n");
+ while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(&vo, &op))) {
+ if (ret < 0) {
+ fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n");
clear();
return;
}
- ret = vorbis_synthesis_headerin(&vi,&vc,&op);
- if(ret){
- fprintf(stderr,"Error parsing Vorbis stream headers; corrupt stream?\n");
+ ret = vorbis_synthesis_headerin(&vi, &vc, &op);
+ if (ret) {
+ fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n");
clear();
return;
}
vorbis_p++;
- if(vorbis_p==3)break;
+ if (vorbis_p == 3) break;
}
/* The header pages/packets will arrive before anything else we
care about, or the stream is not obeying spec */
- if(ogg_sync_pageout(&oy,&og)>0){
+ if (ogg_sync_pageout(&oy, &og) > 0) {
queue_page(&og); /* demux into the appropriate stream */
- }else{
- int ret=buffer_data(); /* someone needs more data */
- if(ret==0){
- fprintf(stderr,"End of file while searching for codec headers.\n");
+ } else {
+ int ret = buffer_data(); /* someone needs more data */
+ if (ret == 0) {
+ fprintf(stderr, "End of file while searching for codec headers.\n");
clear();
return;
}
@@ -432,30 +429,30 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
}
/* and now we have it all. initialize decoders */
- if(theora_p){
- td=th_decode_alloc(&ti,ts);
+ if (theora_p) {
+ td = th_decode_alloc(&ti, ts);
printf("Ogg logical stream %lx is Theora %dx%d %.02f fps",
- to.serialno,ti.pic_width,ti.pic_height,
- (double)ti.fps_numerator/ti.fps_denominator);
- px_fmt=ti.pixel_fmt;
- switch(ti.pixel_fmt){
- case TH_PF_420: printf(" 4:2:0 video\n"); break;
- case TH_PF_422: printf(" 4:2:2 video\n"); break;
- case TH_PF_444: printf(" 4:4:4 video\n"); break;
- case TH_PF_RSVD:
- default:
- printf(" video\n (UNKNOWN Chroma sampling!)\n");
- break;
+ to.serialno, ti.pic_width, ti.pic_height,
+ (double)ti.fps_numerator / ti.fps_denominator);
+ px_fmt = ti.pixel_fmt;
+ switch (ti.pixel_fmt) {
+ case TH_PF_420: printf(" 4:2:0 video\n"); break;
+ case TH_PF_422: printf(" 4:2:2 video\n"); break;
+ case TH_PF_444: printf(" 4:4:4 video\n"); break;
+ case TH_PF_RSVD:
+ default:
+ printf(" video\n (UNKNOWN Chroma sampling!)\n");
+ break;
}
- if(ti.pic_width!=ti.frame_width || ti.pic_height!=ti.frame_height)
+ if (ti.pic_width != ti.frame_width || ti.pic_height != ti.frame_height)
printf(" Frame content is %dx%d with offset (%d,%d).\n",
- ti.frame_width, ti.frame_height, ti.pic_x, ti.pic_y);
- th_decode_ctl(td,TH_DECCTL_GET_PPLEVEL_MAX,&pp_level_max,
- sizeof(pp_level_max));
- pp_level=pp_level_max;
- pp_level=0;
- th_decode_ctl(td,TH_DECCTL_SET_PPLEVEL,&pp_level,sizeof(pp_level));
- pp_inc=0;
+ ti.frame_width, ti.frame_height, ti.pic_x, ti.pic_y);
+ th_decode_ctl(td, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max,
+ sizeof(pp_level_max));
+ pp_level = pp_level_max;
+ pp_level = 0;
+ th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, sizeof(pp_level));
+ pp_inc = 0;
/*{
int arg = 0xffff;
@@ -468,14 +465,14 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
int w;
int h;
- w=(ti.pic_x+ti.frame_width+1&~1)-(ti.pic_x&~1);
- h=(ti.pic_y+ti.frame_height+1&~1)-(ti.pic_y&~1);
+ w = (ti.pic_x + ti.frame_width + 1 & ~1) - (ti.pic_x & ~1);
+ h = (ti.pic_y + ti.frame_height + 1 & ~1) - (ti.pic_y & ~1);
size.x = w;
size.y = h;
- texture->create(w,h,Image::FORMAT_RGBA8,Texture::FLAG_FILTER|Texture::FLAG_VIDEO_SURFACE);
+ texture->create(w, h, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE);
- }else{
+ } else {
/* tear down the partial theora setup */
th_info_clear(&ti);
th_comment_clear(&tc);
@@ -483,32 +480,30 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
th_setup_free(ts);
- if(vorbis_p){
- vorbis_synthesis_init(&vd,&vi);
- vorbis_block_init(&vd,&vb);
- fprintf(stderr,"Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.\n",
- vo.serialno,vi.channels,vi.rate);
+ if (vorbis_p) {
+ vorbis_synthesis_init(&vd, &vi);
+ vorbis_block_init(&vd, &vb);
+ fprintf(stderr, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.\n",
+ vo.serialno, vi.channels, vi.rate);
//_setup(vi.channels, vi.rate);
- }else{
+ } else {
/* tear down the partial vorbis setup */
vorbis_info_clear(&vi);
vorbis_comment_clear(&vc);
}
playing = false;
- buffering=true;
- time=0;
- audio_frames_wrote=0;
-
-
+ buffering = true;
+ time = 0;
+ audio_frames_wrote = 0;
};
float VideoStreamPlaybackTheora::get_time() const {
//print_line("total: "+itos(get_total())+" todo: "+itos(get_todo()));
//return MAX(0,time-((get_total())/(float)vi.rate));
- return time-AudioServer::get_singleton()->get_output_delay()-delay_compensation;//-((get_total())/(float)vi.rate);
+ return time - AudioServer::get_singleton()->get_output_delay() - delay_compensation; //-((get_total())/(float)vi.rate);
};
Ref<Texture> VideoStreamPlaybackTheora::get_texture() {
@@ -526,8 +521,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
return;
};
-
-
#ifdef THEORA_USE_THREAD_STREAMING
thread_sem->post();
#endif
@@ -535,112 +528,102 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
//double ctime =AudioServer::get_singleton()->get_mix_time();
//print_line("play "+rtos(p_delta));
- time+=p_delta;
+ time += p_delta;
- if (videobuf_time>get_time()) {
+ if (videobuf_time > get_time()) {
return; //no new frames need to be produced
}
- bool frame_done=false;
- bool audio_done=!vorbis_p;
+ bool frame_done = false;
+ bool audio_done = !vorbis_p;
while (!frame_done || (!audio_done && !vorbis_eos)) {
//a frame needs to be produced
ogg_packet op;
- bool no_theora=false;
-
+ bool no_theora = false;
while (vorbis_p) {
int ret;
float **pcm;
- bool buffer_full=false;
+ bool buffer_full = false;
/* if there's pending, decoded audio, grab it */
- if ((ret=vorbis_synthesis_pcmout(&vd,&pcm))>0) {
+ if ((ret = vorbis_synthesis_pcmout(&vd, &pcm)) > 0) {
-
-
- const int AUXBUF_LEN=4096;
+ const int AUXBUF_LEN = 4096;
int to_read = ret;
int16_t aux_buffer[AUXBUF_LEN];
- while(to_read) {
+ while (to_read) {
- int m = MIN(AUXBUF_LEN/vi.channels,to_read);
+ int m = MIN(AUXBUF_LEN / vi.channels, to_read);
int count = 0;
- for(int j=0;j<m;j++){
- for(int i=0;i<vi.channels;i++){
+ for (int j = 0; j < m; j++) {
+ for (int i = 0; i < vi.channels; i++) {
- int val=Math::fast_ftoi(pcm[i][j]*32767.f);
- if(val>32767)val=32767;
- if(val<-32768)val=-32768;
+ int val = Math::fast_ftoi(pcm[i][j] * 32767.f);
+ if (val > 32767) val = 32767;
+ if (val < -32768) val = -32768;
aux_buffer[count++] = val;
}
}
if (mix_callback) {
- int mixed = mix_callback(mix_udata,aux_buffer,m);
- to_read-=mixed;
- if (mixed!=m) { //could mix no more
- buffer_full=true;
+ int mixed = mix_callback(mix_udata, aux_buffer, m);
+ to_read -= mixed;
+ if (mixed != m) { //could mix no more
+ buffer_full = true;
break;
}
} else {
- to_read-=m; //just pretend we sent the audio
+ to_read -= m; //just pretend we sent the audio
}
-
-
}
+ int tr = vorbis_synthesis_read(&vd, ret - to_read);
- int tr = vorbis_synthesis_read(&vd, ret-to_read);
-
-
- if (vd.granulepos>=0) {
+ if (vd.granulepos >= 0) {
//print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos));
}
//print_line("mix audio!");
- audio_frames_wrote+=ret-to_read;
+ audio_frames_wrote += ret - to_read;
//print_line("AGP: "+itos(vd.granulepos)+" added "+itos(ret-to_read));
-
} else {
/* no pending audio; is there a pending packet to decode? */
- if (ogg_stream_packetout(&vo,&op)>0){
- if(vorbis_synthesis(&vb,&op)==0) { /* test for success! */
- vorbis_synthesis_blockin(&vd,&vb);
+ if (ogg_stream_packetout(&vo, &op) > 0) {
+ if (vorbis_synthesis(&vb, &op) == 0) { /* test for success! */
+ vorbis_synthesis_blockin(&vd, &vb);
}
- } else { /* we need more data; break out to suck in another page */
+ } else { /* we need more data; break out to suck in another page */
//printf("need moar data\n");
break;
};
}
-
- audio_done = videobuf_time < (audio_frames_wrote/float(vi.rate));
+ audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate));
if (buffer_full)
break;
}
- while(theora_p && !frame_done){
+ while (theora_p && !frame_done) {
/* theora is one in, one out... */
- if(ogg_stream_packetout(&to,&op)>0){
+ if (ogg_stream_packetout(&to, &op) > 0) {
-
- if(false && pp_inc){
- pp_level+=pp_inc;
- th_decode_ctl(td,TH_DECCTL_SET_PPLEVEL,&pp_level,
- sizeof(pp_level));
- pp_inc=0;
+ if (false && pp_inc) {
+ pp_level += pp_inc;
+ th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level,
+ sizeof(pp_level));
+ pp_inc = 0;
}
/*HACK: This should be set after a seek or a gap, but we might not have
a granulepos for the first packet (we only have them for the last
@@ -648,13 +631,13 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
To do this right, we should back-track from the last packet on the
page and compute the correct granulepos for the first packet after
a seek or a gap.*/
- if(op.granulepos>=0){
- th_decode_ctl(td,TH_DECCTL_SET_GRANPOS,&op.granulepos,
- sizeof(op.granulepos));
+ if (op.granulepos >= 0) {
+ th_decode_ctl(td, TH_DECCTL_SET_GRANPOS, &op.granulepos,
+ sizeof(op.granulepos));
}
ogg_int64_t videobuf_granulepos;
- if(th_decode_packetin(td,&op,&videobuf_granulepos)==0){
- videobuf_time=th_granule_time(td,videobuf_granulepos);
+ if (th_decode_packetin(td, &op, &videobuf_granulepos) == 0) {
+ videobuf_time = th_granule_time(td, videobuf_granulepos);
//printf("frame time %f, play time %f, ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);
@@ -664,27 +647,25 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
keyframing. Soon enough libtheora will be able to deal
with non-keyframe seeks. */
- if(videobuf_time>=get_time()) {
- frame_done=true;
- } else{
+ if (videobuf_time >= get_time()) {
+ frame_done = true;
+ } else {
/*If we are too slow, reduce the pp level.*/
- pp_inc=pp_level>0?-1:0;
+ pp_inc = pp_level > 0 ? -1 : 0;
}
} else {
-
}
} else {
- no_theora=true;
+ no_theora = true;
break;
}
}
-
- //print_line("no theora: "+itos(no_theora)+" theora eos: "+itos(theora_eos)+" frame done "+itos(frame_done));
+//print_line("no theora: "+itos(no_theora)+" theora eos: "+itos(theora_eos)+" frame done "+itos(frame_done));
#ifdef THEORA_USE_THREAD_STREAMING
- if (file && thread_eof && no_theora && theora_eos && ring_buffer.data_left()==0) {
+ if (file && thread_eof && no_theora && theora_eos && ring_buffer.data_left() == 0) {
#else
if (file && /*!videobuf_ready && */ no_theora && theora_eos) {
#endif
@@ -692,7 +673,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
stop();
return;
};
- #if 0
+#if 0
if (!videobuf_ready || audio_todo > 0){
/* no data yet for somebody. Grab another page */
@@ -701,23 +682,22 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
queue_page(&og);
}
}
- #else
-
+#else
- if (!frame_done || !audio_done){
+ if (!frame_done || !audio_done) {
//what's the point of waiting for audio to grab a page?
buffer_data();
- while(ogg_sync_pageout(&oy,&og)>0){
+ while (ogg_sync_pageout(&oy, &og) > 0) {
queue_page(&og);
}
}
- #endif
+#endif
/* If playback has begun, top audio buffer off immediately. */
//if(stateflag) audio_write_nonblocking();
/* are we at or past time for this video frame? */
- if(videobuf_ready && videobuf_time<=get_time()){
+ if (videobuf_ready && videobuf_time <= get_time()) {
//video_write();
//videobuf_ready=0;
@@ -725,35 +705,29 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
//printf("frame at %f not ready (time %f), ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);
}
- float tdiff=videobuf_time-get_time();
+ float tdiff = videobuf_time - get_time();
/*If we have lots of extra time, increase the post-processing level.*/
- if(tdiff>ti.fps_denominator*0.25/ti.fps_numerator){
- pp_inc=pp_level<pp_level_max?1:0;
- }
- else if(tdiff<ti.fps_denominator*0.05/ti.fps_numerator){
- pp_inc=pp_level>0?-1:0;
+ if (tdiff > ti.fps_denominator * 0.25 / ti.fps_numerator) {
+ pp_inc = pp_level < pp_level_max ? 1 : 0;
+ } else if (tdiff < ti.fps_denominator * 0.05 / ti.fps_numerator) {
+ pp_inc = pp_level > 0 ? -1 : 0;
}
-
}
video_write();
-
};
-
void VideoStreamPlaybackTheora::play() {
if (!playing)
- time=0;
+ time = 0;
else {
stop();
}
playing = true;
- delay_compensation=GlobalConfig::get_singleton()->get("audio/video_delay_compensation_ms");
- delay_compensation/=1000.0;
-
-
+ delay_compensation = GlobalConfig::get_singleton()->get("audio/video_delay_compensation_ms");
+ delay_compensation /= 1000.0;
};
void VideoStreamPlaybackTheora::stop() {
@@ -764,7 +738,7 @@ void VideoStreamPlaybackTheora::stop() {
set_file(file_name); //reset
}
playing = false;
- time=0;
+ time = 0;
};
bool VideoStreamPlaybackTheora::is_playing() const {
@@ -774,7 +748,7 @@ bool VideoStreamPlaybackTheora::is_playing() const {
void VideoStreamPlaybackTheora::set_paused(bool p_paused) {
- paused=p_paused;
+ paused = p_paused;
//pau = !p_paused;
};
@@ -783,7 +757,7 @@ bool VideoStreamPlaybackTheora::is_paused(bool p_paused) const {
return paused;
};
-void VideoStreamPlaybackTheora::set_loop(bool p_enable) {
+void VideoStreamPlaybackTheora::set_loop(bool p_enable){
};
@@ -812,52 +786,49 @@ float VideoStreamPlaybackTheora::get_pos() const {
return get_time();
};
-void VideoStreamPlaybackTheora::seek_pos(float p_time) {
+void VideoStreamPlaybackTheora::seek_pos(float p_time){
// no
};
-void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback,void *p_userdata) {
+void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) {
- mix_callback=p_callback;
- mix_udata=p_userdata;
+ mix_callback = p_callback;
+ mix_udata = p_userdata;
}
-int VideoStreamPlaybackTheora::get_channels() const{
+int VideoStreamPlaybackTheora::get_channels() const {
return vi.channels;
}
void VideoStreamPlaybackTheora::set_audio_track(int p_idx) {
- audio_track=p_idx;
+ audio_track = p_idx;
}
-int VideoStreamPlaybackTheora::get_mix_rate() const{
+int VideoStreamPlaybackTheora::get_mix_rate() const {
return vi.rate;
}
#ifdef THEORA_USE_THREAD_STREAMING
-
void VideoStreamPlaybackTheora::_streaming_thread(void *ud) {
- VideoStreamPlaybackTheora *vs=(VideoStreamPlaybackTheora*)ud;
+ VideoStreamPlaybackTheora *vs = (VideoStreamPlaybackTheora *)ud;
- while(!vs->thread_exit) {
+ while (!vs->thread_exit) {
//just fill back the buffer
if (!vs->thread_eof) {
int to_read = vs->ring_buffer.space_left();
if (to_read) {
- int read = vs->file->get_buffer(vs->read_buffer.ptr(),to_read);
- vs->ring_buffer.write(vs->read_buffer.ptr(),read);
- vs->thread_eof=vs->file->eof_reached();
+ int read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read);
+ vs->ring_buffer.write(vs->read_buffer.ptr(), read);
+ vs->thread_eof = vs->file->eof_reached();
}
-
-
}
vs->thread_sem->wait();
@@ -875,24 +846,24 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() {
playing = false;
frames_pending = 0;
videobuf_time = 0;
- paused=false;
+ paused = false;
- buffering=false;
- texture = Ref<ImageTexture>( memnew(ImageTexture ));
- mix_callback=NULL;
- mix_udata=NULL;
- audio_track=0;
- delay_compensation=0;
- audio_frames_wrote=0;
+ buffering = false;
+ texture = Ref<ImageTexture>(memnew(ImageTexture));
+ mix_callback = NULL;
+ mix_udata = NULL;
+ audio_track = 0;
+ delay_compensation = 0;
+ audio_frames_wrote = 0;
#ifdef THEORA_USE_THREAD_STREAMING
- int rb_power = nearest_shift(RB_SIZE_KB*1024);
+ int rb_power = nearest_shift(RB_SIZE_KB * 1024);
ring_buffer.resize(rb_power);
- read_buffer.resize(RB_SIZE_KB*1024);
- thread_sem=Semaphore::create();
- thread=NULL;
- thread_exit=false;
- thread_eof=false;
+ read_buffer.resize(RB_SIZE_KB * 1024);
+ thread_sem = Semaphore::create();
+ thread = NULL;
+ thread_exit = false;
+ thread_eof = false;
#endif
};
@@ -907,20 +878,17 @@ VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() {
if (file)
memdelete(file);
-
-
};
-
-RES ResourceFormatLoaderVideoStreamTheora::load(const String &p_path,const String& p_original_path, Error *r_error) {
+RES ResourceFormatLoaderVideoStreamTheora::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_FILE_CANT_OPEN;
+ *r_error = ERR_FILE_CANT_OPEN;
VideoStreamTheora *stream = memnew(VideoStreamTheora);
stream->set_file(p_path);
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return Ref<VideoStreamTheora>(stream);
}
@@ -930,14 +898,14 @@ void ResourceFormatLoaderVideoStreamTheora::get_recognized_extensions(List<Strin
p_extensions->push_back("ogm");
p_extensions->push_back("ogv");
}
-bool ResourceFormatLoaderVideoStreamTheora::handles_type(const String& p_type) const {
- return (p_type=="VideoStream" || p_type=="VideoStreamTheora");
+bool ResourceFormatLoaderVideoStreamTheora::handles_type(const String &p_type) const {
+ return (p_type == "VideoStream" || p_type == "VideoStreamTheora");
}
String ResourceFormatLoaderVideoStreamTheora::get_resource_type(const String &p_path) const {
- String exl=p_path.get_extension().to_lower();
- if (exl=="ogm" || exl=="ogv")
+ String exl = p_path.get_extension().to_lower();
+ if (exl == "ogm" || exl == "ogv")
return "VideoStreamTheora";
return "";
}
diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h
index 0e1f5fa864..ea568906da 100644
--- a/modules/theora/video_stream_theora.h
+++ b/modules/theora/video_stream_theora.h
@@ -31,8 +31,8 @@
#include "io/resource_loader.h"
#include "os/file_access.h"
-#include "os/thread.h"
#include "os/semaphore.h"
+#include "os/thread.h"
#include "ring_buffer.h"
#include "scene/resources/video_stream.h"
@@ -53,7 +53,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
Image::Format format;
PoolVector<uint8_t> frame_data;
int frames_pending;
- FileAccess* file;
+ FileAccess *file;
String file_name;
int audio_frames_wrote;
Point2i size;
@@ -66,18 +66,18 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
bool theora_eos;
bool vorbis_eos;
- ogg_sync_state oy;
- ogg_page og;
+ ogg_sync_state oy;
+ ogg_page og;
ogg_stream_state vo;
ogg_stream_state to;
- th_info ti;
- th_comment tc;
- th_dec_ctx *td;
- vorbis_info vi;
+ th_info ti;
+ th_comment tc;
+ th_dec_ctx *td;
+ vorbis_info vi;
vorbis_dsp_state vd;
- vorbis_block vb;
- vorbis_comment vc;
- th_pixel_fmt px_fmt;
+ vorbis_block vb;
+ vorbis_comment vc;
+ th_pixel_fmt px_fmt;
double videobuf_time;
int pp_inc;
@@ -97,13 +97,13 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
Ref<ImageTexture> texture;
AudioMixCallback mix_callback;
- void* mix_udata;
+ void *mix_udata;
bool paused;
#ifdef THEORA_USE_THREAD_STREAMING
enum {
- RB_SIZE_KB=1024
+ RB_SIZE_KB = 1024
};
RingBuffer<uint8_t> ring_buffer;
@@ -117,15 +117,12 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
#endif
-
int audio_track;
protected:
-
void clear();
-
-public:
+public:
virtual void play();
virtual void stop();
virtual bool is_playing() const;
@@ -145,13 +142,12 @@ public:
virtual float get_pos() const;
virtual void seek_pos(float p_time);
-
- void set_file(const String& p_file);
+ void set_file(const String &p_file);
virtual Ref<Texture> get_texture();
virtual void update(float p_delta);
- virtual void set_mix_callback(AudioMixCallback p_callback,void *p_userdata);
+ virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata);
virtual int get_channels() const;
virtual int get_mix_rate() const;
@@ -161,39 +157,33 @@ public:
~VideoStreamPlaybackTheora();
};
-
-
class VideoStreamTheora : public VideoStream {
- GDCLASS(VideoStreamTheora,VideoStream);
+ GDCLASS(VideoStreamTheora, VideoStream);
String file;
int audio_track;
-
public:
-
Ref<VideoStreamPlayback> instance_playback() {
- Ref<VideoStreamPlaybackTheora> pb = memnew( VideoStreamPlaybackTheora );
+ Ref<VideoStreamPlaybackTheora> pb = memnew(VideoStreamPlaybackTheora);
pb->set_audio_track(audio_track);
pb->set_file(file);
return pb;
}
- void set_file(const String& p_file) { file=p_file; }
- void set_audio_track(int p_track) { audio_track=p_track; }
-
- VideoStreamTheora() { audio_track=0; }
+ void set_file(const String &p_file) { file = p_file; }
+ void set_audio_track(int p_track) { audio_track = p_track; }
+ VideoStreamTheora() { audio_track = 0; }
};
class ResourceFormatLoaderVideoStreamTheora : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
-
};
#endif
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp
index 5fe87a4956..b05ea716ed 100644
--- a/modules/visual_script/register_types.cpp
+++ b/modules/visual_script/register_types.cpp
@@ -28,23 +28,21 @@
/*************************************************************************/
#include "register_types.h"
-#include "visual_script.h"
-#include "visual_script_editor.h"
#include "io/resource_loader.h"
-#include "visual_script_nodes.h"
-#include "visual_script_func_nodes.h"
+#include "visual_script.h"
#include "visual_script_builtin_funcs.h"
+#include "visual_script_editor.h"
+#include "visual_script_expression.h"
#include "visual_script_flow_control.h"
+#include "visual_script_func_nodes.h"
+#include "visual_script_nodes.h"
#include "visual_script_yield_nodes.h"
-#include "visual_script_expression.h"
-
-
-VisualScriptLanguage *visual_script_language=NULL;
+VisualScriptLanguage *visual_script_language = NULL;
void register_visual_script_types() {
- visual_script_language=memnew( VisualScriptLanguage );
+ visual_script_language = memnew(VisualScriptLanguage);
//script_language_gd->init();
ScriptServer::register_language(visual_script_language);
@@ -78,7 +76,6 @@ void register_visual_script_types() {
ClassDB::register_class<VisualScriptPreload>();
ClassDB::register_class<VisualScriptTypeCast>();
-
ClassDB::register_class<VisualScriptFunctionCall>();
ClassDB::register_class<VisualScriptPropertySet>();
ClassDB::register_class<VisualScriptPropertyGet>();
@@ -91,14 +88,13 @@ void register_visual_script_types() {
ClassDB::register_class<VisualScriptIterator>();
ClassDB::register_class<VisualScriptSequence>();
ClassDB::register_class<VisualScriptInputFilter>();
- ClassDB::register_class<VisualScriptSwitch >();
+ ClassDB::register_class<VisualScriptSwitch>();
ClassDB::register_class<VisualScriptYield>();
ClassDB::register_class<VisualScriptYieldSignal>();
ClassDB::register_class<VisualScriptBuiltinFunc>();
-
ClassDB::register_class<VisualScriptExpression>();
register_visual_script_nodes();
@@ -111,13 +107,10 @@ void register_visual_script_types() {
#ifdef TOOLS_ENABLED
VisualScriptEditor::register_editor();
#endif
-
-
}
void unregister_visual_script_types() {
-
unregister_visual_script_nodes();
ScriptServer::unregister_language(visual_script_language);
@@ -126,6 +119,5 @@ void unregister_visual_script_types() {
VisualScriptEditor::free_clipboard();
#endif
if (visual_script_language)
- memdelete( visual_script_language );
-
+ memdelete(visual_script_language);
}
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index 9f742591d5..2b884c34fb 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -28,16 +28,14 @@
/*************************************************************************/
#include "visual_script.h"
-#include "visual_script_nodes.h"
-#include "scene/main/node.h"
-#include "os/os.h"
#include "global_config.h"
-
-
+#include "os/os.h"
+#include "scene/main/node.h"
+#include "visual_script_nodes.h"
//used by editor, this is not really saved
void VisualScriptNode::set_breakpoint(bool p_breakpoint) {
- breakpoint=p_breakpoint;
+ breakpoint = p_breakpoint;
}
bool VisualScriptNode::is_breakpoint() const {
@@ -47,76 +45,68 @@ bool VisualScriptNode::is_breakpoint() const {
void VisualScriptNode::_notification(int p_what) {
- if (p_what==NOTIFICATION_POSTINITIALIZE) {
+ if (p_what == NOTIFICATION_POSTINITIALIZE) {
int dvc = get_input_value_port_count();
- for(int i=0;i<dvc;i++) {
+ for (int i = 0; i < dvc; i++) {
Variant::Type expected = get_input_value_port_info(i).type;
Variant::CallError ce;
- default_input_values.push_back(Variant::construct(expected,NULL,0,ce,false));
+ default_input_values.push_back(Variant::construct(expected, NULL, 0, ce, false));
}
}
}
-void VisualScriptNode::ports_changed_notify(){
+void VisualScriptNode::ports_changed_notify() {
-
- default_input_values.resize( MAX(default_input_values.size(),get_input_value_port_count()) ); //let it grow as big as possible, we don't want to lose values on resize
+ default_input_values.resize(MAX(default_input_values.size(), get_input_value_port_count())); //let it grow as big as possible, we don't want to lose values on resize
emit_signal("ports_changed");
-
}
-void VisualScriptNode::set_default_input_value(int p_port,const Variant& p_value) {
+void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) {
- ERR_FAIL_INDEX(p_port,default_input_values.size());
+ ERR_FAIL_INDEX(p_port, default_input_values.size());
- default_input_values[p_port]=p_value;
+ default_input_values[p_port] = p_value;
#ifdef TOOLS_ENABLED
- for (Set<VisualScript*>::Element *E=scripts_used.front();E;E=E->next()) {
+ for (Set<VisualScript *>::Element *E = scripts_used.front(); E; E = E->next()) {
E->get()->set_edited(true);
}
#endif
-
}
Variant VisualScriptNode::get_default_input_value(int p_port) const {
- ERR_FAIL_INDEX_V(p_port,default_input_values.size(),Variant());
+ ERR_FAIL_INDEX_V(p_port, default_input_values.size(), Variant());
return default_input_values[p_port];
}
void VisualScriptNode::_set_default_input_values(Array p_values) {
-
- default_input_values=p_values;
+ default_input_values = p_values;
}
-
void VisualScriptNode::validate_input_default_values() {
-
-
default_input_values.resize(get_input_value_port_count());
//actually validate on save
- for(int i=0;i<get_input_value_port_count();i++) {
+ for (int i = 0; i < get_input_value_port_count(); i++) {
Variant::Type expected = get_input_value_port_info(i).type;
-
- if (expected==Variant::NIL || expected==default_input_values[i].get_type()) {
+ if (expected == Variant::NIL || expected == default_input_values[i].get_type()) {
continue;
- } else {
+ } else {
//not the same, reconvert
Variant::CallError ce;
Variant existing = default_input_values[i];
- const Variant *existingp=&existing;
- default_input_values[i] = Variant::construct(expected,&existingp,1,ce,false);
- if (ce.error!=Variant::CallError::CALL_OK) {
+ const Variant *existingp = &existing;
+ default_input_values[i] = Variant::construct(expected, &existingp, 1, ce, false);
+ if (ce.error != Variant::CallError::CALL_OK) {
//could not convert? force..
- default_input_values[i] = Variant::construct(expected,NULL,0,ce,false);
+ default_input_values[i] = Variant::construct(expected, NULL, 0, ce, false);
}
}
}
@@ -129,29 +119,27 @@ Array VisualScriptNode::_get_default_input_values() const {
return default_input_values;
}
-
-
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("_set_default_input_values","values"),&VisualScriptNode::_set_default_input_values);
- ClassDB::bind_method(D_METHOD("_get_default_input_values"),&VisualScriptNode::_get_default_input_values);
+ 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("_set_default_input_values", "values"), &VisualScriptNode::_set_default_input_values);
+ ClassDB::bind_method(D_METHOD("_get_default_input_values"), &VisualScriptNode::_get_default_input_values);
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"_default_input_values",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_default_input_values","_get_default_input_values");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_default_input_values", "_get_default_input_values");
ADD_SIGNAL(MethodInfo("ports_changed"));
}
-VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess* p_inputs,int p_output) const {
+VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
PropertyInfo pinfo = get_output_value_port_info(p_output);
TypeGuess tg;
- tg.type=pinfo.type;
- if (pinfo.hint==PROPERTY_HINT_RESOURCE_TYPE) {
- tg.GDCLASS=pinfo.hint_string;
+ tg.type = pinfo.type;
+ if (pinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ tg.GDCLASS = pinfo.hint_string;
}
return tg;
@@ -166,7 +154,7 @@ Ref<VisualScript> VisualScriptNode::get_visual_script() const {
}
VisualScriptNode::VisualScriptNode() {
- breakpoint=false;
+ breakpoint = false;
}
////////////////
@@ -175,8 +163,8 @@ VisualScriptNode::VisualScriptNode() {
VisualScriptNodeInstance::VisualScriptNodeInstance() {
- sequence_outputs=NULL;
- input_ports=NULL;
+ sequence_outputs = NULL;
+ input_ports = NULL;
}
VisualScriptNodeInstance::~VisualScriptNodeInstance() {
@@ -192,44 +180,41 @@ VisualScriptNodeInstance::~VisualScriptNodeInstance() {
if (output_ports) {
memdelete_arr(output_ports);
}
-
}
-void VisualScript::add_function(const StringName& p_name) {
+void VisualScript::add_function(const StringName &p_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!String(p_name).is_valid_identifier());
ERR_FAIL_COND(functions.has(p_name));
- functions[p_name]=Function();
- functions[p_name].scroll=Vector2(-50,-100);
+ functions[p_name] = Function();
+ functions[p_name].scroll = Vector2(-50, -100);
}
-bool VisualScript::has_function(const StringName& p_name) const {
+bool VisualScript::has_function(const StringName &p_name) const {
return functions.has(p_name);
-
}
-void VisualScript::remove_function(const StringName& p_name) {
+void VisualScript::remove_function(const StringName &p_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_name));
- for (Map<int,Function::NodeData>::Element *E=functions[p_name].nodes.front();E;E=E->next()) {
+ for (Map<int, Function::NodeData>::Element *E = functions[p_name].nodes.front(); E; E = E->next()) {
- E->get().node->disconnect("ports_changed",this,"_node_ports_changed");
+ E->get().node->disconnect("ports_changed", this, "_node_ports_changed");
E->get().node->scripts_used.erase(this);
}
functions.erase(p_name);
-
}
-void VisualScript::rename_function(const StringName& p_name,const StringName& p_new_name) {
+void VisualScript::rename_function(const StringName &p_name, const StringName &p_new_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_name));
- if (p_new_name==p_name)
+ if (p_new_name == p_name)
return;
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -238,60 +223,51 @@ void VisualScript::rename_function(const StringName& p_name,const StringName& p_
ERR_FAIL_COND(variables.has(p_new_name));
ERR_FAIL_COND(custom_signals.has(p_new_name));
- functions[p_new_name]=functions[p_name];
+ functions[p_new_name] = functions[p_name];
functions.erase(p_name);
-
}
-void VisualScript::set_function_scroll(const StringName& p_name, const Vector2& p_scroll) {
+void VisualScript::set_function_scroll(const StringName &p_name, const Vector2 &p_scroll) {
ERR_FAIL_COND(!functions.has(p_name));
- functions[p_name].scroll=p_scroll;
-
+ functions[p_name].scroll = p_scroll;
}
-Vector2 VisualScript::get_function_scroll(const StringName& p_name) const {
+Vector2 VisualScript::get_function_scroll(const StringName &p_name) const {
- ERR_FAIL_COND_V(!functions.has(p_name),Vector2());
+ ERR_FAIL_COND_V(!functions.has(p_name), Vector2());
return functions[p_name].scroll;
-
}
-
void VisualScript::get_function_list(List<StringName> *r_functions) const {
- for (const Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
r_functions->push_back(E->key());
}
r_functions->sort_custom<StringName::AlphCompare>();
-
}
-int VisualScript::get_function_node_id(const StringName& p_name) const {
+int VisualScript::get_function_node_id(const StringName &p_name) const {
- ERR_FAIL_COND_V(!functions.has(p_name),-1);
+ ERR_FAIL_COND_V(!functions.has(p_name), -1);
return functions[p_name].function_id;
-
}
-
void VisualScript::_node_ports_changed(int p_id) {
-
-
StringName function;
- for (Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
if (E->get().nodes.has(p_id)) {
- function=E->key();
+ function = E->key();
break;
}
}
- ERR_FAIL_COND(function==StringName());
+ ERR_FAIL_COND(function == StringName());
Function &func = functions[function];
Ref<VisualScriptNode> vsn = func.nodes[p_id].node;
@@ -305,18 +281,18 @@ void VisualScript::_node_ports_changed(int p_id) {
{
List<SequenceConnection> to_remove;
- for (Set<SequenceConnection>::Element *E=func.sequence_connections.front();E;E=E->next()) {
- if (E->get().from_node==p_id && E->get().from_output>=vsn->get_output_sequence_port_count()) {
+ for (Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) {
+ if (E->get().from_node == p_id && E->get().from_output >= vsn->get_output_sequence_port_count()) {
to_remove.push_back(E->get());
}
- if (E->get().to_node==p_id && !vsn->has_input_sequence_port()) {
+ if (E->get().to_node == p_id && !vsn->has_input_sequence_port()) {
to_remove.push_back(E->get());
}
}
- while(to_remove.size()) {
+ while (to_remove.size()) {
func.sequence_connections.erase(to_remove.front()->get());
to_remove.pop_front();
}
@@ -326,17 +302,16 @@ void VisualScript::_node_ports_changed(int p_id) {
List<DataConnection> to_remove;
-
- for (Set<DataConnection>::Element *E=func.data_connections.front();E;E=E->next()) {
- if (E->get().from_node==p_id && E->get().from_port>=vsn->get_output_value_port_count()) {
+ for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
+ if (E->get().from_node == p_id && E->get().from_port >= vsn->get_output_value_port_count()) {
to_remove.push_back(E->get());
}
- if (E->get().to_node==p_id && E->get().to_port>=vsn->get_input_value_port_count()) {
+ if (E->get().to_node == p_id && E->get().to_port >= vsn->get_input_value_port_count()) {
to_remove.push_back(E->get());
}
}
- while(to_remove.size()) {
+ while (to_remove.size()) {
func.data_connections.erase(to_remove.front()->get());
to_remove.pop_front();
}
@@ -344,48 +319,44 @@ void VisualScript::_node_ports_changed(int p_id) {
#ifdef TOOLS_ENABLED
set_edited(true); //something changed, let's set as edited
- emit_signal("node_ports_changed",function,p_id);
+ emit_signal("node_ports_changed", function, p_id);
#endif
}
-void VisualScript::add_node(const StringName& p_func,int p_id, const Ref<VisualScriptNode>& p_node, const Point2 &p_pos) {
+void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_func));
-
- for (Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
ERR_FAIL_COND(E->get().nodes.has(p_id)); //id can exist only one in script, even for different functions
}
Function &func = functions[p_func];
-
if (p_node->cast_to<VisualScriptFunction>()) {
//the function indeed
ERR_EXPLAIN("A function node already has been set here.");
- ERR_FAIL_COND(func.function_id>=0);
+ ERR_FAIL_COND(func.function_id >= 0);
- func.function_id=p_id;
+ func.function_id = p_id;
}
Function::NodeData nd;
- nd.node=p_node;
- nd.pos=p_pos;
+ nd.node = p_node;
+ nd.pos = p_pos;
Ref<VisualScriptNode> vsn = p_node;
- vsn->connect("ports_changed",this,"_node_ports_changed",varray(p_id));
+ vsn->connect("ports_changed", this, "_node_ports_changed", varray(p_id));
vsn->scripts_used.insert(this);
-
-
- func.nodes[p_id]=nd;
+ func.nodes[p_id] = nd;
}
-void VisualScript::remove_node(const StringName& p_func,int p_id){
+void VisualScript::remove_node(const StringName &p_func, int p_id) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
@@ -393,13 +364,13 @@ void VisualScript::remove_node(const StringName& p_func,int p_id){
{
List<SequenceConnection> to_remove;
- for (Set<SequenceConnection>::Element *E=func.sequence_connections.front();E;E=E->next()) {
- if (E->get().from_node==p_id || E->get().to_node==p_id) {
+ for (Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) {
+ if (E->get().from_node == p_id || E->get().to_node == p_id) {
to_remove.push_back(E->get());
}
}
- while(to_remove.size()) {
+ while (to_remove.size()) {
func.sequence_connections.erase(to_remove.front()->get());
to_remove.pop_front();
}
@@ -409,254 +380,239 @@ void VisualScript::remove_node(const StringName& p_func,int p_id){
List<DataConnection> to_remove;
-
- for (Set<DataConnection>::Element *E=func.data_connections.front();E;E=E->next()) {
- if (E->get().from_node==p_id || E->get().to_node==p_id) {
+ for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
+ if (E->get().from_node == p_id || E->get().to_node == p_id) {
to_remove.push_back(E->get());
}
}
- while(to_remove.size()) {
+ while (to_remove.size()) {
func.data_connections.erase(to_remove.front()->get());
to_remove.pop_front();
}
}
if (func.nodes[p_id].node->cast_to<VisualScriptFunction>()) {
- func.function_id=-1; //revert to invalid
+ func.function_id = -1; //revert to invalid
}
- func.nodes[p_id].node->disconnect("ports_changed",this,"_node_ports_changed");
+ func.nodes[p_id].node->disconnect("ports_changed", this, "_node_ports_changed");
func.nodes[p_id].node->scripts_used.erase(this);
func.nodes.erase(p_id);
-
-
}
+bool VisualScript::has_node(const StringName &p_func, int p_id) const {
-bool VisualScript::has_node(const StringName& p_func,int p_id) const {
-
- ERR_FAIL_COND_V(!functions.has(p_func),false);
+ ERR_FAIL_COND_V(!functions.has(p_func), false);
const Function &func = functions[p_func];
return func.nodes.has(p_id);
}
-Ref<VisualScriptNode> VisualScript::get_node(const StringName& p_func,int p_id) const{
+Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) const {
- ERR_FAIL_COND_V(!functions.has(p_func),Ref<VisualScriptNode>());
+ ERR_FAIL_COND_V(!functions.has(p_func), Ref<VisualScriptNode>());
const Function &func = functions[p_func];
- ERR_FAIL_COND_V(!func.nodes.has(p_id),Ref<VisualScriptNode>());
+ ERR_FAIL_COND_V(!func.nodes.has(p_id), Ref<VisualScriptNode>());
return func.nodes[p_id].node;
}
-void VisualScript::set_node_pos(const StringName& p_func,int p_id,const Point2& p_pos) {
+void VisualScript::set_node_pos(const StringName &p_func, int p_id, const Point2 &p_pos) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
ERR_FAIL_COND(!func.nodes.has(p_id));
- func.nodes[p_id].pos=p_pos;
+ func.nodes[p_id].pos = p_pos;
}
-Point2 VisualScript::get_node_pos(const StringName& p_func,int p_id) const{
+Point2 VisualScript::get_node_pos(const StringName &p_func, int p_id) const {
- ERR_FAIL_COND_V(!functions.has(p_func),Point2());
+ ERR_FAIL_COND_V(!functions.has(p_func), Point2());
const Function &func = functions[p_func];
- ERR_FAIL_COND_V(!func.nodes.has(p_id),Point2());
+ ERR_FAIL_COND_V(!func.nodes.has(p_id), Point2());
return func.nodes[p_id].pos;
}
-
-void VisualScript::get_node_list(const StringName& p_func,List<int> *r_nodes) const{
+void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) const {
ERR_FAIL_COND(!functions.has(p_func));
const Function &func = functions[p_func];
- for (const Map<int,Function::NodeData>::Element *E=func.nodes.front();E;E=E->next()) {
+ for (const Map<int, Function::NodeData>::Element *E = func.nodes.front(); E; E = E->next()) {
r_nodes->push_back(E->key());
}
-
}
+void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) {
-void VisualScript::sequence_connect(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node){
-
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
-
SequenceConnection sc;
- sc.from_node=p_from_node;
- sc.from_output=p_from_output;
- sc.to_node=p_to_node;
+ sc.from_node = p_from_node;
+ sc.from_output = p_from_output;
+ sc.to_node = p_to_node;
ERR_FAIL_COND(func.sequence_connections.has(sc));
func.sequence_connections.insert(sc);
-
}
-void VisualScript::sequence_disconnect(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node){
+void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) {
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
SequenceConnection sc;
- sc.from_node=p_from_node;
- sc.from_output=p_from_output;
- sc.to_node=p_to_node;
+ sc.from_node = p_from_node;
+ sc.from_output = p_from_output;
+ sc.to_node = p_to_node;
ERR_FAIL_COND(!func.sequence_connections.has(sc));
func.sequence_connections.erase(sc);
-
}
-bool VisualScript::has_sequence_connection(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node) const{
+bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) const {
- ERR_FAIL_COND_V(!functions.has(p_func),false);
+ ERR_FAIL_COND_V(!functions.has(p_func), false);
const Function &func = functions[p_func];
SequenceConnection sc;
- sc.from_node=p_from_node;
- sc.from_output=p_from_output;
- sc.to_node=p_to_node;
+ sc.from_node = p_from_node;
+ sc.from_output = p_from_output;
+ sc.to_node = p_to_node;
return func.sequence_connections.has(sc);
}
-void VisualScript::get_sequence_connection_list(const StringName& p_func,List<SequenceConnection> *r_connection) const {
+void VisualScript::get_sequence_connection_list(const StringName &p_func, List<SequenceConnection> *r_connection) const {
ERR_FAIL_COND(!functions.has(p_func));
const Function &func = functions[p_func];
- for (const Set<SequenceConnection>::Element *E=func.sequence_connections.front();E;E=E->next()) {
+ for (const Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) {
r_connection->push_back(E->get());
}
}
+void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
-void VisualScript::data_connect(const StringName& p_func,int p_from_node,int p_from_port,int p_to_node,int p_to_port) {
-
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
DataConnection dc;
- dc.from_node=p_from_node;
- dc.from_port=p_from_port;
- dc.to_node=p_to_node;
- dc.to_port=p_to_port;
+ dc.from_node = p_from_node;
+ dc.from_port = p_from_port;
+ dc.to_node = p_to_node;
+ dc.to_port = p_to_port;
- ERR_FAIL_COND( func.data_connections.has(dc));
+ ERR_FAIL_COND(func.data_connections.has(dc));
func.data_connections.insert(dc);
}
-void VisualScript::data_disconnect(const StringName& p_func,int p_from_node,int p_from_port,int p_to_node,int p_to_port) {
+void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
ERR_FAIL_COND(!functions.has(p_func));
Function &func = functions[p_func];
DataConnection dc;
- dc.from_node=p_from_node;
- dc.from_port=p_from_port;
- dc.to_node=p_to_node;
- dc.to_port=p_to_port;
+ dc.from_node = p_from_node;
+ dc.from_port = p_from_port;
+ dc.to_node = p_to_node;
+ dc.to_port = p_to_port;
- ERR_FAIL_COND( !func.data_connections.has(dc));
+ ERR_FAIL_COND(!func.data_connections.has(dc));
func.data_connections.erase(dc);
-
}
-bool VisualScript::has_data_connection(const StringName& p_func,int p_from_node,int p_from_port,int p_to_node,int p_to_port) const {
+bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const {
- ERR_FAIL_COND_V(!functions.has(p_func),false);
+ ERR_FAIL_COND_V(!functions.has(p_func), false);
const Function &func = functions[p_func];
DataConnection dc;
- dc.from_node=p_from_node;
- dc.from_port=p_from_port;
- dc.to_node=p_to_node;
- dc.to_port=p_to_port;
+ dc.from_node = p_from_node;
+ dc.from_port = p_from_port;
+ dc.to_node = p_to_node;
+ dc.to_port = p_to_port;
return func.data_connections.has(dc);
-
}
-bool VisualScript::is_input_value_port_connected(const StringName& p_func,int p_node,int p_port) const {
+bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const {
- ERR_FAIL_COND_V(!functions.has(p_func),false);
+ ERR_FAIL_COND_V(!functions.has(p_func), false);
const Function &func = functions[p_func];
- for (const Set<DataConnection>::Element *E=func.data_connections.front();E;E=E->next()) {
- if (E->get().to_node==p_node && E->get().to_port==p_port)
+ for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
+ if (E->get().to_node == p_node && E->get().to_port == p_port)
return true;
}
return false;
}
-bool VisualScript::get_input_value_port_connection_source(const StringName& p_func,int p_node,int p_port,int *r_node,int *r_port) const {
+bool VisualScript::get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const {
- ERR_FAIL_COND_V(!functions.has(p_func),false);
+ ERR_FAIL_COND_V(!functions.has(p_func), false);
const Function &func = functions[p_func];
- for (const Set<DataConnection>::Element *E=func.data_connections.front();E;E=E->next()) {
- if (E->get().to_node==p_node && E->get().to_port==p_port) {
- *r_node=E->get().from_node;
- *r_port=E->get().from_port;
+ for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
+ if (E->get().to_node == p_node && E->get().to_port == p_port) {
+ *r_node = E->get().from_node;
+ *r_port = E->get().from_port;
return true;
}
}
return false;
-
}
-void VisualScript::get_data_connection_list(const StringName& p_func,List<DataConnection> *r_connection) const {
+void VisualScript::get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const {
ERR_FAIL_COND(!functions.has(p_func));
const Function &func = functions[p_func];
- for (const Set<DataConnection>::Element *E=func.data_connections.front();E;E=E->next()) {
+ for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
r_connection->push_back(E->get());
}
}
-void VisualScript::add_variable(const StringName& p_name,const Variant& p_default_value,bool p_export) {
+void VisualScript::add_variable(const StringName &p_name, const Variant &p_default_value, bool p_export) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!String(p_name).is_valid_identifier());
ERR_FAIL_COND(variables.has(p_name));
Variable v;
- v.default_value=p_default_value;
- v.info.type=p_default_value.get_type();
- v.info.name=p_name;
- v.info.hint=PROPERTY_HINT_NONE;
- v._export=p_export;
+ v.default_value = p_default_value;
+ v.info.type = p_default_value.get_type();
+ v.info.name = p_name;
+ v.info.hint = PROPERTY_HINT_NONE;
+ v._export = p_export;
- variables[p_name]=v;
+ variables[p_name] = v;
#ifdef TOOLS_ENABLED
_update_placeholders();
#endif
-
}
-bool VisualScript::has_variable(const StringName& p_name) const {
+bool VisualScript::has_variable(const StringName &p_name) const {
return variables.has(p_name);
}
-void VisualScript::remove_variable(const StringName& p_name) {
+void VisualScript::remove_variable(const StringName &p_name) {
ERR_FAIL_COND(!variables.has(p_name));
variables.erase(p_name);
@@ -666,111 +622,101 @@ void VisualScript::remove_variable(const StringName& p_name) {
#endif
}
-void VisualScript::set_variable_default_value(const StringName& p_name,const Variant& p_value){
+void VisualScript::set_variable_default_value(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_COND(!variables.has(p_name));
- variables[p_name].default_value=p_value;
+ variables[p_name].default_value = p_value;
#ifdef TOOLS_ENABLED
_update_placeholders();
#endif
-
-
}
-Variant VisualScript::get_variable_default_value(const StringName& p_name) const{
+Variant VisualScript::get_variable_default_value(const StringName &p_name) const {
- ERR_FAIL_COND_V(!variables.has(p_name),Variant());
+ ERR_FAIL_COND_V(!variables.has(p_name), Variant());
return variables[p_name].default_value;
-
}
-void VisualScript::set_variable_info(const StringName& p_name,const PropertyInfo& p_info){
+void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!variables.has(p_name));
- variables[p_name].info=p_info;
- variables[p_name].info.name=p_name;
+ variables[p_name].info = p_info;
+ variables[p_name].info.name = p_name;
#ifdef TOOLS_ENABLED
_update_placeholders();
#endif
-
-
}
-PropertyInfo VisualScript::get_variable_info(const StringName& p_name) const{
+PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const {
- ERR_FAIL_COND_V(!variables.has(p_name),PropertyInfo());
+ ERR_FAIL_COND_V(!variables.has(p_name), PropertyInfo());
return variables[p_name].info;
}
-void VisualScript::set_variable_export(const StringName& p_name,bool p_export) {
+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;
+ variables[p_name]._export = p_export;
}
-bool VisualScript::get_variable_export(const StringName& p_name) const {
+bool VisualScript::get_variable_export(const StringName &p_name) const {
- ERR_FAIL_COND_V(!variables.has(p_name),false);
+ ERR_FAIL_COND_V(!variables.has(p_name), false);
return variables[p_name]._export;
-
}
-
-void VisualScript::_set_variable_info(const StringName& p_name,const Dictionary& p_info) {
+void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) {
PropertyInfo pinfo;
if (p_info.has("type"))
- pinfo.type=Variant::Type(int(p_info["type"]));
+ pinfo.type = Variant::Type(int(p_info["type"]));
if (p_info.has("name"))
- pinfo.name=p_info["name"];
+ pinfo.name = p_info["name"];
if (p_info.has("hint"))
- pinfo.hint=PropertyHint(int(p_info["hint"]));
+ pinfo.hint = PropertyHint(int(p_info["hint"]));
if (p_info.has("hint_string"))
- pinfo.hint_string=p_info["hint_string"];
+ pinfo.hint_string = p_info["hint_string"];
if (p_info.has("usage"))
- pinfo.usage=p_info["usage"];
+ pinfo.usage = p_info["usage"];
- set_variable_info(p_name,pinfo);
+ set_variable_info(p_name, pinfo);
}
-Dictionary VisualScript::_get_variable_info(const StringName& p_name) const{
+Dictionary VisualScript::_get_variable_info(const StringName &p_name) const {
- PropertyInfo pinfo=get_variable_info(p_name);
+ PropertyInfo pinfo = get_variable_info(p_name);
Dictionary d;
- d["type"]=pinfo.type;
- d["name"]=pinfo.name;
- d["hint"]=pinfo.hint;
- d["hint_string"]=pinfo.hint_string;
- d["usage"]=pinfo.usage;
+ d["type"] = pinfo.type;
+ d["name"] = pinfo.name;
+ d["hint"] = pinfo.hint;
+ d["hint_string"] = pinfo.hint_string;
+ d["usage"] = pinfo.usage;
return d;
}
-void VisualScript::get_variable_list(List<StringName> *r_variables) const{
-
+void VisualScript::get_variable_list(List<StringName> *r_variables) const {
- for (Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) {
+ for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
r_variables->push_back(E->key());
}
r_variables->sort_custom<StringName::AlphCompare>();
}
+void VisualScript::set_instance_base_type(const StringName &p_type) {
-void VisualScript::set_instance_base_type(const StringName& p_type) {
-
- ERR_FAIL_COND( instances.size() );
- base_type=p_type;
+ ERR_FAIL_COND(instances.size());
+ base_type = p_type;
}
+void VisualScript::rename_variable(const StringName &p_name, const StringName &p_new_name) {
-void VisualScript::rename_variable(const StringName& p_name,const StringName& p_new_name) {
-
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!variables.has(p_name));
- if (p_new_name==p_name)
+ if (p_new_name == p_name)
return;
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -779,103 +725,94 @@ void VisualScript::rename_variable(const StringName& p_name,const StringName& p_
ERR_FAIL_COND(variables.has(p_new_name));
ERR_FAIL_COND(custom_signals.has(p_new_name));
- variables[p_new_name]=variables[p_name];
+ variables[p_new_name] = variables[p_name];
variables.erase(p_name);
-
}
-void VisualScript::add_custom_signal(const StringName& p_name) {
+void VisualScript::add_custom_signal(const StringName &p_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!String(p_name).is_valid_identifier());
ERR_FAIL_COND(custom_signals.has(p_name));
- custom_signals[p_name]=Vector<Argument>();
+ custom_signals[p_name] = Vector<Argument>();
}
-bool VisualScript::has_custom_signal(const StringName& p_name) const {
+bool VisualScript::has_custom_signal(const StringName &p_name) const {
return custom_signals.has(p_name);
-
}
-void VisualScript::custom_signal_add_argument(const StringName& p_func,Variant::Type p_type,const String& p_name,int p_index) {
+void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
Argument arg;
- arg.type=p_type;
- arg.name=p_name;
- if (p_index<0)
+ arg.type = p_type;
+ arg.name = p_name;
+ if (p_index < 0)
custom_signals[p_func].push_back(arg);
else
- custom_signals[p_func].insert(0,arg);
-
+ custom_signals[p_func].insert(0, arg);
}
-void VisualScript::custom_signal_set_argument_type(const StringName& p_func,int p_argidx,Variant::Type p_type) {
+void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
- ERR_FAIL_INDEX(p_argidx,custom_signals[p_func].size());
- custom_signals[p_func][p_argidx].type=p_type;
+ ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size());
+ custom_signals[p_func][p_argidx].type = p_type;
}
-Variant::Type VisualScript::custom_signal_get_argument_type(const StringName& p_func,int p_argidx) const {
+Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const {
- ERR_FAIL_COND_V(!custom_signals.has(p_func),Variant::NIL);
- ERR_FAIL_INDEX_V(p_argidx,custom_signals[p_func].size(),Variant::NIL);
+ ERR_FAIL_COND_V(!custom_signals.has(p_func), Variant::NIL);
+ ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), Variant::NIL);
return custom_signals[p_func][p_argidx].type;
}
-void VisualScript::custom_signal_set_argument_name(const StringName& p_func,int p_argidx,const String& p_name) {
- ERR_FAIL_COND( instances.size() );
+void VisualScript::custom_signal_set_argument_name(const StringName &p_func, int p_argidx, const String &p_name) {
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
- ERR_FAIL_INDEX(p_argidx,custom_signals[p_func].size());
- custom_signals[p_func][p_argidx].name=p_name;
-
+ ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size());
+ custom_signals[p_func][p_argidx].name = p_name;
}
-String VisualScript::custom_signal_get_argument_name(const StringName& p_func,int p_argidx) const {
+String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const {
- ERR_FAIL_COND_V(!custom_signals.has(p_func),String());
- ERR_FAIL_INDEX_V(p_argidx,custom_signals[p_func].size(),String());
+ ERR_FAIL_COND_V(!custom_signals.has(p_func), String());
+ ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), String());
return custom_signals[p_func][p_argidx].name;
-
}
-void VisualScript::custom_signal_remove_argument(const StringName& p_func,int p_argidx) {
+void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
- ERR_FAIL_INDEX(p_argidx,custom_signals[p_func].size());
+ ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size());
custom_signals[p_func].remove(p_argidx);
-
}
-int VisualScript::custom_signal_get_argument_count(const StringName& p_func) const {
+int VisualScript::custom_signal_get_argument_count(const StringName &p_func) const {
- ERR_FAIL_COND_V(!custom_signals.has(p_func),0);
+ ERR_FAIL_COND_V(!custom_signals.has(p_func), 0);
return custom_signals[p_func].size();
-
}
-void VisualScript::custom_signal_swap_argument(const StringName& p_func,int p_argidx,int p_with_argidx) {
+void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
- ERR_FAIL_INDEX(p_argidx,custom_signals[p_func].size());
- ERR_FAIL_INDEX(p_with_argidx,custom_signals[p_func].size());
-
- SWAP( custom_signals[p_func][p_argidx], custom_signals[p_func][p_with_argidx] );
+ ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size());
+ ERR_FAIL_INDEX(p_with_argidx, custom_signals[p_func].size());
+ SWAP(custom_signals[p_func][p_argidx], custom_signals[p_func][p_with_argidx]);
}
-void VisualScript::remove_custom_signal(const StringName& p_name) {
+void VisualScript::remove_custom_signal(const StringName &p_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_name));
custom_signals.erase(p_name);
-
}
-void VisualScript::rename_custom_signal(const StringName& p_name,const StringName& p_new_name) {
+void VisualScript::rename_custom_signal(const StringName &p_name, const StringName &p_new_name) {
- ERR_FAIL_COND( instances.size() );
+ ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_name));
- if (p_new_name==p_name)
+ if (p_new_name == p_name)
return;
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -884,30 +821,28 @@ void VisualScript::rename_custom_signal(const StringName& p_name,const StringNam
ERR_FAIL_COND(variables.has(p_new_name));
ERR_FAIL_COND(custom_signals.has(p_new_name));
- custom_signals[p_new_name]=custom_signals[p_name];
+ custom_signals[p_new_name] = custom_signals[p_name];
custom_signals.erase(p_name);
-
}
void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const {
- for (const Map<StringName,Vector<Argument> >::Element *E=custom_signals.front();E;E=E->next()) {
+ for (const Map<StringName, Vector<Argument> >::Element *E = custom_signals.front(); E; E = E->next()) {
r_custom_signals->push_back(E->key());
}
r_custom_signals->sort_custom<StringName::AlphCompare>();
-
}
int VisualScript::get_available_id() const {
- int max_id=0;
- for (Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ int max_id = 0;
+ for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
if (E->get().nodes.empty())
continue;
int last_id = E->get().nodes.back()->key();
- max_id=MAX(max_id,last_id+1);
+ max_id = MAX(max_id, last_id + 1);
}
return max_id;
@@ -915,14 +850,11 @@ int VisualScript::get_available_id() const {
/////////////////////////////////
-
bool VisualScript::can_instance() const {
- return true;//ScriptServer::is_scripting_enabled();
-
+ return true; //ScriptServer::is_scripting_enabled();
}
-
StringName VisualScript::get_instance_base_type() const {
return base_type;
@@ -932,84 +864,74 @@ Ref<Script> VisualScript::get_base_script() const {
return Ref<Script>(); // no inheritance in visual script
}
-
#ifdef TOOLS_ENABLED
void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {
-
placeholders.erase(p_placeholder);
}
-
void VisualScript::_update_placeholders() {
- if (placeholders.size()==0)
+ if (placeholders.size() == 0)
return; //no bother if no placeholders
List<PropertyInfo> pinfo;
- Map<StringName,Variant> values;
+ Map<StringName, Variant> values;
- for (Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) {
+ for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
if (!E->get()._export)
continue;
PropertyInfo p = E->get().info;
- p.name=String(E->key());
+ p.name = String(E->key());
pinfo.push_back(p);
- values[p.name]=E->get().default_value;
+ values[p.name] = E->get().default_value;
}
- for (Set<PlaceHolderScriptInstance*>::Element *E=placeholders.front();E;E=E->next()) {
+ for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
- E->get()->update(pinfo,values);
+ E->get()->update(pinfo, values);
}
-
}
#endif
-
-ScriptInstance* VisualScript::instance_create(Object *p_this) {
-
-
+ScriptInstance *VisualScript::instance_create(Object *p_this) {
#ifdef TOOLS_ENABLED
if (!ScriptServer::is_scripting_enabled()) {
-
- PlaceHolderScriptInstance *sins = memnew( PlaceHolderScriptInstance(VisualScriptLanguage::singleton,Ref<Script>((Script*)this),p_this));
+ PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(VisualScriptLanguage::singleton, Ref<Script>((Script *)this), p_this));
placeholders.insert(sins);
List<PropertyInfo> pinfo;
- Map<StringName,Variant> values;
+ Map<StringName, Variant> values;
- for (Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) {
+ for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
if (!E->get()._export)
continue;
PropertyInfo p = E->get().info;
- p.name=String(E->key());
+ p.name = String(E->key());
pinfo.push_back(p);
- values[p.name]=E->get().default_value;
+ values[p.name] = E->get().default_value;
}
- sins->update(pinfo,values);
+ sins->update(pinfo, values);
return sins;
}
#endif
-
- VisualScriptInstance *instance=memnew( VisualScriptInstance );
- instance->create(Ref<VisualScript>(this),p_this);
-
+ VisualScriptInstance *instance = memnew(VisualScriptInstance);
+ instance->create(Ref<VisualScript>(this), p_this);
if (VisualScriptLanguage::singleton->lock)
VisualScriptLanguage::singleton->lock->lock();
- instances[p_this]=instance;
+ instances[p_this] = instance;
if (VisualScriptLanguage::singleton->lock)
VisualScriptLanguage::singleton->lock->unlock();
@@ -1019,7 +941,7 @@ ScriptInstance* VisualScript::instance_create(Object *p_this) {
bool VisualScript::instance_has(const Object *p_this) const {
- return instances.has((Object*)p_this);
+ return instances.has((Object *)p_this);
}
bool VisualScript::has_source_code() const {
@@ -1032,8 +954,7 @@ String VisualScript::get_source_code() const {
return String();
}
-void VisualScript::set_source_code(const String& p_code) {
-
+void VisualScript::set_source_code(const String &p_code) {
}
Error VisualScript::reload(bool p_keep_state) {
@@ -1041,74 +962,66 @@ Error VisualScript::reload(bool p_keep_state) {
return OK;
}
-
bool VisualScript::is_tool() const {
return false;
}
-
String VisualScript::get_node_type() const {
return String();
}
-
ScriptLanguage *VisualScript::get_language() const {
return VisualScriptLanguage::singleton;
}
-
-bool VisualScript::has_script_signal(const StringName& p_signal) const {
+bool VisualScript::has_script_signal(const StringName &p_signal) const {
return custom_signals.has(p_signal);
}
void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
- for (const Map<StringName,Vector<Argument> >::Element *E=custom_signals.front();E;E=E->next()) {
+ for (const Map<StringName, Vector<Argument> >::Element *E = custom_signals.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- for(int i=0;i<E->get().size();i++) {
+ mi.name = E->key();
+ for (int i = 0; i < E->get().size(); i++) {
PropertyInfo arg;
- arg.type=E->get()[i].type;
- arg.name=E->get()[i].name;
+ arg.type = E->get()[i].type;
+ arg.name = E->get()[i].name;
mi.arguments.push_back(arg);
}
-
r_signals->push_back(mi);
}
-
-
}
-
-bool VisualScript::get_property_default_value(const StringName& p_property,Variant& r_value) const {
+bool VisualScript::get_property_default_value(const StringName &p_property, Variant &r_value) const {
if (!variables.has(p_property))
return false;
- r_value=variables[ p_property ].default_value;
+ r_value = variables[p_property].default_value;
return true;
}
void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const {
- for (Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- if (E->get().function_id>=0) {
+ mi.name = E->key();
+ if (E->get().function_id >= 0) {
- Ref<VisualScriptFunction> func=E->get().nodes[E->get().function_id].node;
+ Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node;
if (func.is_valid()) {
- for(int i=0;i<func->get_argument_count();i++) {
+ for (int i = 0; i < func->get_argument_count(); i++) {
PropertyInfo arg;
- arg.name=func->get_argument_name(i);
- arg.type=func->get_argument_type(i);
+ arg.name = func->get_argument_name(i);
+ arg.type = func->get_argument_type(i);
mi.arguments.push_back(arg);
}
}
@@ -1118,27 +1031,27 @@ void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const {
}
}
-bool VisualScript::has_method(const StringName& p_method) const {
+bool VisualScript::has_method(const StringName &p_method) const {
return functions.has(p_method);
}
-MethodInfo VisualScript::get_method_info(const StringName& p_method) const{
+MethodInfo VisualScript::get_method_info(const StringName &p_method) const {
- const Map<StringName,Function>::Element *E=functions.find(p_method);
+ const Map<StringName, Function>::Element *E = functions.find(p_method);
if (!E)
return MethodInfo();
MethodInfo mi;
- mi.name=E->key();
- if (E->get().function_id>=0) {
+ mi.name = E->key();
+ if (E->get().function_id >= 0) {
- Ref<VisualScriptFunction> func=E->get().nodes[E->get().function_id].node;
+ Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node;
if (func.is_valid()) {
- for(int i=0;i<func->get_argument_count();i++) {
+ for (int i = 0; i < func->get_argument_count(); i++) {
PropertyInfo arg;
- arg.name=func->get_argument_name(i);
- arg.type=func->get_argument_type(i);
+ arg.name = func->get_argument_name(i);
+ arg.type = func->get_argument_type(i);
mi.arguments.push_back(arg);
}
}
@@ -1152,7 +1065,7 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const {
List<StringName> vars;
get_variable_list(&vars);
- for (List<StringName>::Element *E=vars.front();E;E=E->next()) {
+ 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);
@@ -1162,9 +1075,9 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const {
#ifdef TOOLS_ENABLED
bool VisualScript::are_subnodes_edited() const {
- for(const Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
- for (const Map<int,Function::NodeData>::Element *F=E->get().nodes.front();F;F=F->next()) {
+ for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) {
if (F->get().node->is_edited()) {
return true;
}
@@ -1175,324 +1088,296 @@ bool VisualScript::are_subnodes_edited() const {
}
#endif
-void VisualScript::_set_data(const Dictionary& p_data) {
+void VisualScript::_set_data(const Dictionary &p_data) {
Dictionary d = p_data;
if (d.has("base_type"))
- base_type=d["base_type"];
+ base_type = d["base_type"];
variables.clear();
- Array vars=d["variables"];
- for (int i=0;i<vars.size();i++) {
+ Array vars = d["variables"];
+ for (int i = 0; i < vars.size(); i++) {
- Dictionary v=vars[i];
+ Dictionary v = vars[i];
StringName name = v["name"];
add_variable(name);
- _set_variable_info(name,v);
- set_variable_default_value(name,v["default_value"]);
- set_variable_export(name,v.has("export") && bool(v["export"]));
-
+ _set_variable_info(name, v);
+ set_variable_default_value(name, v["default_value"]);
+ set_variable_export(name, v.has("export") && bool(v["export"]));
}
-
custom_signals.clear();
- Array sigs=d["signals"];
- for (int i=0;i<sigs.size();i++) {
+ Array sigs = d["signals"];
+ for (int i = 0; i < sigs.size(); i++) {
- Dictionary cs=sigs[i];
+ Dictionary cs = sigs[i];
add_custom_signal(cs["name"]);
- Array args=cs["arguments"];
- for(int j=0;j<args.size();j+=2) {
- custom_signal_add_argument(cs["name"],Variant::Type(int(args[j+1])),args[j]);
+ Array args = cs["arguments"];
+ for (int j = 0; j < args.size(); j += 2) {
+ custom_signal_add_argument(cs["name"], Variant::Type(int(args[j + 1])), args[j]);
}
}
- Array funcs=d["functions"];
+ Array funcs = d["functions"];
functions.clear();
- for (int i=0;i<funcs.size();i++) {
+ for (int i = 0; i < funcs.size(); i++) {
- Dictionary func=funcs[i];
+ Dictionary func = funcs[i];
-
- StringName name=func["name"];
+ StringName name = func["name"];
//int id=func["function_id"];
add_function(name);
- set_function_scroll(name,func["scroll"]);
+ set_function_scroll(name, func["scroll"]);
Array nodes = func["nodes"];
- for(int i=0;i<nodes.size();i+=3) {
+ for (int i = 0; i < nodes.size(); i += 3) {
- add_node(name,nodes[i],nodes[i+2],nodes[i+1]);
+ add_node(name, nodes[i], nodes[i + 2], nodes[i + 1]);
}
+ Array sequence_connections = func["sequence_connections"];
- Array sequence_connections=func["sequence_connections"];
-
- for (int j=0;j<sequence_connections.size();j+=3) {
+ for (int j = 0; j < sequence_connections.size(); j += 3) {
- sequence_connect(name,sequence_connections[j+0],sequence_connections[j+1],sequence_connections[j+2]);
+ sequence_connect(name, sequence_connections[j + 0], sequence_connections[j + 1], sequence_connections[j + 2]);
}
+ Array data_connections = func["data_connections"];
- Array data_connections=func["data_connections"];
-
- for (int j=0;j<data_connections.size();j+=4) {
-
- data_connect(name,data_connections[j+0],data_connections[j+1],data_connections[j+2],data_connections[j+3]);
+ for (int j = 0; j < data_connections.size(); j += 4) {
+ data_connect(name, data_connections[j + 0], data_connections[j + 1], data_connections[j + 2], data_connections[j + 3]);
}
-
-
}
-
}
-Dictionary VisualScript::_get_data() const{
+Dictionary VisualScript::_get_data() const {
Dictionary d;
- d["base_type"]=base_type;
+ d["base_type"] = base_type;
Array vars;
- for (const Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) {
+ for (const Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
Dictionary var = _get_variable_info(E->key());
- var["name"]=E->key(); //make sure it's the right one
- var["default_value"]=E->get().default_value;
- var["export"]=E->get()._export;
+ var["name"] = E->key(); //make sure it's the right one
+ var["default_value"] = E->get().default_value;
+ var["export"] = E->get()._export;
vars.push_back(var);
}
- d["variables"]=vars;
+ d["variables"] = vars;
Array sigs;
- for (const Map<StringName,Vector<Argument> >::Element *E=custom_signals.front();E;E=E->next()) {
+ for (const Map<StringName, Vector<Argument> >::Element *E = custom_signals.front(); E; E = E->next()) {
Dictionary cs;
- cs["name"]=E->key();
+ cs["name"] = E->key();
Array args;
- for(int i=0;i<E->get().size();i++) {
+ for (int i = 0; i < E->get().size(); i++) {
args.push_back(E->get()[i].name);
args.push_back(E->get()[i].type);
}
- cs["arguments"]=args;
+ cs["arguments"] = args;
sigs.push_back(cs);
}
- d["signals"]=sigs;
+ d["signals"] = sigs;
Array funcs;
- for (const Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) {
+ for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
Dictionary func;
- func["name"]=E->key();
- func["function_id"]=E->get().function_id;
- func["scroll"]=E->get().scroll;
+ func["name"] = E->key();
+ func["function_id"] = E->get().function_id;
+ func["scroll"] = E->get().scroll;
Array nodes;
- for (const Map<int,Function::NodeData>::Element *F=E->get().nodes.front();F;F=F->next()) {
+ for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) {
nodes.push_back(F->key());
nodes.push_back(F->get().pos);
nodes.push_back(F->get().node);
-
}
- func["nodes"]=nodes;
+ func["nodes"] = nodes;
Array sequence_connections;
- for (const Set<SequenceConnection>::Element *F=E->get().sequence_connections.front();F;F=F->next()) {
+ for (const Set<SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) {
sequence_connections.push_back(F->get().from_node);
sequence_connections.push_back(F->get().from_output);
sequence_connections.push_back(F->get().to_node);
-
}
-
- func["sequence_connections"]=sequence_connections;
+ func["sequence_connections"] = sequence_connections;
Array data_connections;
- for (const Set<DataConnection>::Element *F=E->get().data_connections.front();F;F=F->next()) {
+ for (const Set<DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) {
data_connections.push_back(F->get().from_node);
data_connections.push_back(F->get().from_port);
data_connections.push_back(F->get().to_node);
data_connections.push_back(F->get().to_port);
-
}
-
- func["data_connections"]=data_connections;
+ func["data_connections"] = data_connections;
funcs.push_back(func);
-
}
- d["functions"]=funcs;
-
+ d["functions"] = funcs;
return d;
-
}
void VisualScript::_bind_methods() {
-
-
- ClassDB::bind_method(D_METHOD("_node_ports_changed"),&VisualScript::_node_ports_changed);
-
- ClassDB::bind_method(D_METHOD("add_function","name"),&VisualScript::add_function);
- 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("add_node","func","id","node","pos"),&VisualScript::add_node,DEFVAL(Point2()));
- ClassDB::bind_method(D_METHOD("remove_node","func","id"),&VisualScript::remove_node);
- ClassDB::bind_method(D_METHOD("get_function_node_id","name"),&VisualScript::get_function_node_id);
-
- ClassDB::bind_method(D_METHOD("get_node","func","id"),&VisualScript::get_node);
- ClassDB::bind_method(D_METHOD("has_node","func","id"),&VisualScript::has_node);
- ClassDB::bind_method(D_METHOD("set_node_pos","func","id","pos"),&VisualScript::set_node_pos);
- ClassDB::bind_method(D_METHOD("get_node_pos","func","id"),&VisualScript::get_node_pos);
-
- ClassDB::bind_method(D_METHOD("sequence_connect","func","from_node","from_output","to_node"),&VisualScript::sequence_connect);
- ClassDB::bind_method(D_METHOD("sequence_disconnect","func","from_node","from_output","to_node"),&VisualScript::sequence_disconnect);
- ClassDB::bind_method(D_METHOD("has_sequence_connection","func","from_node","from_output","to_node"),&VisualScript::has_sequence_connection);
-
- ClassDB::bind_method(D_METHOD("data_connect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_connect);
- ClassDB::bind_method(D_METHOD("data_disconnect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_disconnect);
- ClassDB::bind_method(D_METHOD("has_data_connection","func","from_node","from_port","to_node","to_port"),&VisualScript::has_data_connection);
-
- ClassDB::bind_method(D_METHOD("add_variable","name","default_value","export"),&VisualScript::add_variable,DEFVAL(Variant()),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("has_variable","name"),&VisualScript::has_variable);
- ClassDB::bind_method(D_METHOD("remove_variable","name"),&VisualScript::remove_variable);
- ClassDB::bind_method(D_METHOD("set_variable_default_value","name","value"),&VisualScript::set_variable_default_value);
- ClassDB::bind_method(D_METHOD("get_variable_default_value","name"),&VisualScript::get_variable_default_value);
- ClassDB::bind_method(D_METHOD("set_variable_info","name","value"),&VisualScript::_set_variable_info);
- ClassDB::bind_method(D_METHOD("get_variable_info","name"),&VisualScript::_get_variable_info);
- ClassDB::bind_method(D_METHOD("set_variable_export","name","enable"),&VisualScript::set_variable_export);
- ClassDB::bind_method(D_METHOD("get_variable_export","name"),&VisualScript::get_variable_export);
- ClassDB::bind_method(D_METHOD("rename_variable","name","new_name"),&VisualScript::rename_variable);
-
- ClassDB::bind_method(D_METHOD("add_custom_signal","name"),&VisualScript::add_custom_signal);
- ClassDB::bind_method(D_METHOD("has_custom_signal","name"),&VisualScript::has_custom_signal);
- ClassDB::bind_method(D_METHOD("custom_signal_add_argument","name","type","argname","index"),&VisualScript::custom_signal_add_argument,DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("custom_signal_set_argument_type","name","argidx","type"),&VisualScript::custom_signal_set_argument_type);
- 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_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);
- ClassDB::bind_method(D_METHOD("rename_custom_signal","name","new_name"),&VisualScript::rename_custom_signal);
+ ClassDB::bind_method(D_METHOD("_node_ports_changed"), &VisualScript::_node_ports_changed);
+
+ ClassDB::bind_method(D_METHOD("add_function", "name"), &VisualScript::add_function);
+ 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("add_node", "func", "id", "node", "pos"), &VisualScript::add_node, DEFVAL(Point2()));
+ ClassDB::bind_method(D_METHOD("remove_node", "func", "id"), &VisualScript::remove_node);
+ ClassDB::bind_method(D_METHOD("get_function_node_id", "name"), &VisualScript::get_function_node_id);
+
+ ClassDB::bind_method(D_METHOD("get_node", "func", "id"), &VisualScript::get_node);
+ ClassDB::bind_method(D_METHOD("has_node", "func", "id"), &VisualScript::has_node);
+ ClassDB::bind_method(D_METHOD("set_node_pos", "func", "id", "pos"), &VisualScript::set_node_pos);
+ ClassDB::bind_method(D_METHOD("get_node_pos", "func", "id"), &VisualScript::get_node_pos);
+
+ ClassDB::bind_method(D_METHOD("sequence_connect", "func", "from_node", "from_output", "to_node"), &VisualScript::sequence_connect);
+ ClassDB::bind_method(D_METHOD("sequence_disconnect", "func", "from_node", "from_output", "to_node"), &VisualScript::sequence_disconnect);
+ ClassDB::bind_method(D_METHOD("has_sequence_connection", "func", "from_node", "from_output", "to_node"), &VisualScript::has_sequence_connection);
+
+ ClassDB::bind_method(D_METHOD("data_connect", "func", "from_node", "from_port", "to_node", "to_port"), &VisualScript::data_connect);
+ ClassDB::bind_method(D_METHOD("data_disconnect", "func", "from_node", "from_port", "to_node", "to_port"), &VisualScript::data_disconnect);
+ ClassDB::bind_method(D_METHOD("has_data_connection", "func", "from_node", "from_port", "to_node", "to_port"), &VisualScript::has_data_connection);
+
+ ClassDB::bind_method(D_METHOD("add_variable", "name", "default_value", "export"), &VisualScript::add_variable, DEFVAL(Variant()), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("has_variable", "name"), &VisualScript::has_variable);
+ ClassDB::bind_method(D_METHOD("remove_variable", "name"), &VisualScript::remove_variable);
+ ClassDB::bind_method(D_METHOD("set_variable_default_value", "name", "value"), &VisualScript::set_variable_default_value);
+ ClassDB::bind_method(D_METHOD("get_variable_default_value", "name"), &VisualScript::get_variable_default_value);
+ ClassDB::bind_method(D_METHOD("set_variable_info", "name", "value"), &VisualScript::_set_variable_info);
+ ClassDB::bind_method(D_METHOD("get_variable_info", "name"), &VisualScript::_get_variable_info);
+ ClassDB::bind_method(D_METHOD("set_variable_export", "name", "enable"), &VisualScript::set_variable_export);
+ ClassDB::bind_method(D_METHOD("get_variable_export", "name"), &VisualScript::get_variable_export);
+ ClassDB::bind_method(D_METHOD("rename_variable", "name", "new_name"), &VisualScript::rename_variable);
+
+ ClassDB::bind_method(D_METHOD("add_custom_signal", "name"), &VisualScript::add_custom_signal);
+ ClassDB::bind_method(D_METHOD("has_custom_signal", "name"), &VisualScript::has_custom_signal);
+ ClassDB::bind_method(D_METHOD("custom_signal_add_argument", "name", "type", "argname", "index"), &VisualScript::custom_signal_add_argument, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("custom_signal_set_argument_type", "name", "argidx", "type"), &VisualScript::custom_signal_set_argument_type);
+ 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_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);
+ ClassDB::bind_method(D_METHOD("rename_custom_signal", "name", "new_name"), &VisualScript::rename_custom_signal);
//ClassDB::bind_method(D_METHOD("set_variable_info","name","info"),&VScript::set_variable_info);
//ClassDB::bind_method(D_METHOD("get_variable_info","name"),&VScript::set_variable_info);
- ClassDB::bind_method(D_METHOD("set_instance_base_type","type"),&VisualScript::set_instance_base_type);
+ ClassDB::bind_method(D_METHOD("set_instance_base_type", "type"), &VisualScript::set_instance_base_type);
- ClassDB::bind_method(D_METHOD("_set_data","data"),&VisualScript::_set_data);
- ClassDB::bind_method(D_METHOD("_get_data"),&VisualScript::_get_data);
+ ClassDB::bind_method(D_METHOD("_set_data", "data"), &VisualScript::_set_data);
+ ClassDB::bind_method(D_METHOD("_get_data"), &VisualScript::_get_data);
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_data","_get_data");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
- ADD_SIGNAL(MethodInfo("node_ports_changed",PropertyInfo(Variant::STRING,"function"),PropertyInfo(Variant::INT,"id")));
+ ADD_SIGNAL(MethodInfo("node_ports_changed", PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::INT, "id")));
}
VisualScript::VisualScript() {
- base_type="Object";
-
+ base_type = "Object";
}
VisualScript::~VisualScript() {
- while(!functions.empty()) {
+ while (!functions.empty()) {
remove_function(functions.front()->key());
}
-
}
////////////////////////////////////////////
+bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) {
-
-bool VisualScriptInstance::set(const StringName& p_name, const Variant& p_value) {
-
-
- Map<StringName,Variant>::Element *E=variables.find(p_name);
+ Map<StringName, Variant>::Element *E = variables.find(p_name);
if (!E)
return false;
- E->get()=p_value;
+ E->get() = p_value;
return true;
}
+bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
-bool VisualScriptInstance::get(const StringName& p_name, Variant &r_ret) const {
-
- const Map<StringName,Variant>::Element *E=variables.find(p_name);
+ const Map<StringName, Variant>::Element *E = variables.find(p_name);
if (!E)
return false;
- r_ret=E->get();
+ r_ret = E->get();
return true;
}
-void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const{
+void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
- for (const Map<StringName,VisualScript::Variable>::Element *E=script->variables.front();E;E=E->next()) {
+ for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) {
if (!E->get()._export)
continue;
PropertyInfo p = E->get().info;
- p.name=String(E->key());
+ p.name = String(E->key());
p_properties->push_back(p);
-
}
}
-Variant::Type VisualScriptInstance::get_property_type(const StringName& p_name,bool *r_is_valid) const{
-
+Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
- const Map<StringName,VisualScript::Variable>::Element *E=script->variables.find(p_name);
+ const Map<StringName, VisualScript::Variable>::Element *E = script->variables.find(p_name);
if (!E) {
if (r_is_valid)
- *r_is_valid=false;
+ *r_is_valid = false;
ERR_FAIL_V(Variant::NIL);
}
if (r_is_valid)
- *r_is_valid=true;
+ *r_is_valid = true;
return E->get().info.type;
-
}
-void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const{
+void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
- for (const Map<StringName,VisualScript::Function>::Element *E=script->functions.front();E;E=E->next()) {
+ for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) {
MethodInfo mi;
- mi.name=E->key();
- if (E->get().function_id>=0 && E->get().nodes.has(E->get().function_id)) {
+ mi.name = E->key();
+ if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) {
Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node;
if (vsf.is_valid()) {
- for(int i=0;i<vsf->get_argument_count();i++) {
+ for (int i = 0; i < vsf->get_argument_count(); i++) {
PropertyInfo arg;
- arg.name=vsf->get_argument_name(i);
- arg.type=vsf->get_argument_type(i);
+ arg.name = vsf->get_argument_name(i);
+ arg.type = vsf->get_argument_type(i);
mi.arguments.push_back(arg);
}
@@ -1503,136 +1388,127 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const{
p_list->push_back(mi);
}
-
}
-bool VisualScriptInstance::has_method(const StringName& p_method) const{
+bool VisualScriptInstance::has_method(const StringName &p_method) const {
return script->functions.has(p_method);
}
-
//#define VSDEBUG(m_text) print_line(m_text)
#define VSDEBUG(m_text)
-void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance* node,int p_pass,int *pass_stack,const Variant **input_args,Variant **output_args,Variant *variant_stack,Variant::CallError& r_error,String& error_str,VisualScriptNodeInstance** r_error_node) {
+void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Variant::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node) {
- ERR_FAIL_COND(node->pass_idx==-1);
+ ERR_FAIL_COND(node->pass_idx == -1);
- if (pass_stack[node->pass_idx]==p_pass)
+ if (pass_stack[node->pass_idx] == p_pass)
return;
- pass_stack[node->pass_idx]=p_pass;
+ pass_stack[node->pass_idx] = p_pass;
if (!node->dependencies.empty()) {
int dc = node->dependencies.size();
- VisualScriptNodeInstance **deps=node->dependencies.ptr();
+ VisualScriptNodeInstance **deps = node->dependencies.ptr();
- for(int i=0;i<dc;i++) {
+ for (int i = 0; i < dc; i++) {
- _dependency_step(deps[i],p_pass,pass_stack,input_args,output_args,variant_stack,r_error,error_str,r_error_node);
- if (r_error.error!=Variant::CallError::CALL_OK)
+ _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, r_error_node);
+ if (r_error.error != Variant::CallError::CALL_OK)
return;
-
}
}
-
- for(int i=0;i<node->input_port_count;i++) {
+ for (int i = 0; i < node->input_port_count; i++) {
int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK;
-
if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) {
//is a default value (unassigned input port)
- input_args[i]=&default_values[index];
+ input_args[i] = &default_values[index];
} else {
//regular temporary in stack
- input_args[i]=&variant_stack[index];
-
+ input_args[i] = &variant_stack[index];
}
}
- for(int i=0 ; i<node->output_port_count ; i++) {
- output_args[i] = &variant_stack[ node->output_ports[i] ];
+ for (int i = 0; i < node->output_port_count; i++) {
+ output_args[i] = &variant_stack[node->output_ports[i]];
}
- Variant *working_mem=node->working_mem_idx>=0 ? &variant_stack[node->working_mem_idx] : (Variant*)NULL;
+ Variant *working_mem = node->working_mem_idx >= 0 ? &variant_stack[node->working_mem_idx] : (Variant *)NULL;
- node->step(input_args,output_args,VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE,working_mem,r_error,error_str);
+ node->step(input_args, output_args, VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE, working_mem, r_error, error_str);
//ignore return
- if (r_error.error!=Variant::CallError::CALL_OK) {
- *r_error_node=node;
+ if (r_error.error != Variant::CallError::CALL_OK) {
+ *r_error_node = node;
}
-
}
-Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p_stack, int p_stack_size, VisualScriptNodeInstance* p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Variant::CallError &r_error) {
+Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Variant::CallError &r_error) {
- Map<StringName,Function>::Element *F = functions.find(p_method);
- ERR_FAIL_COND_V(!F,Variant());
- Function *f=&F->get();
+ Map<StringName, Function>::Element *F = functions.find(p_method);
+ ERR_FAIL_COND_V(!F, Variant());
+ Function *f = &F->get();
//this call goes separate, so it can e yielded and suspended
- Variant *variant_stack=(Variant*)p_stack;
- bool *sequence_bits = (bool*)(variant_stack + f->max_stack);
- const Variant **input_args=(const Variant**)(sequence_bits+f->node_count);
- Variant **output_args=(Variant**)(input_args + max_input_args);
+ Variant *variant_stack = (Variant *)p_stack;
+ bool *sequence_bits = (bool *)(variant_stack + f->max_stack);
+ const Variant **input_args = (const Variant **)(sequence_bits + f->node_count);
+ Variant **output_args = (Variant **)(input_args + max_input_args);
int flow_max = f->flow_stack_size;
- int* flow_stack = flow_max? (int*)(output_args + max_output_args) : (int*)NULL;
+ int *flow_stack = flow_max ? (int *)(output_args + max_output_args) : (int *)NULL;
int *pass_stack = flow_stack + flow_max;
String error_str;
- VisualScriptNodeInstance* node=p_node;
- bool error=false;
- int current_node_id=f->node;
+ VisualScriptNodeInstance *node = p_node;
+ bool error = false;
+ int current_node_id = f->node;
Variant return_value;
- Variant *working_mem=NULL;
+ Variant *working_mem = NULL;
- int flow_stack_pos=p_flow_stack_pos;
+ int flow_stack_pos = p_flow_stack_pos;
#ifdef DEBUG_ENABLED
if (ScriptDebugger::get_singleton()) {
- VisualScriptLanguage::singleton->enter_function(this,&p_method,variant_stack,&working_mem,&current_node_id);
+ VisualScriptLanguage::singleton->enter_function(this, &p_method, variant_stack, &working_mem, &current_node_id);
}
#endif
- while(true) {
+ while (true) {
p_pass++; //increment pass
- current_node_id=node->get_id();
-
- VSDEBUG("==========AT NODE: "+itos(current_node_id)+" base: "+node->get_base_node()->get_class_name());
- VSDEBUG("AT STACK POS: "+itos(flow_stack_pos));
+ current_node_id = node->get_id();
+ VSDEBUG("==========AT NODE: " + itos(current_node_id) + " base: " + node->get_base_node()->get_class_name());
+ VSDEBUG("AT STACK POS: " + itos(flow_stack_pos));
//setup working mem
- working_mem=node->working_mem_idx>=0 ? &variant_stack[node->working_mem_idx] : (Variant*)NULL;
+ working_mem = node->working_mem_idx >= 0 ? &variant_stack[node->working_mem_idx] : (Variant *)NULL;
- VSDEBUG("WORKING MEM: "+itos(node->working_mem_idx));
+ VSDEBUG("WORKING MEM: " + itos(node->working_mem_idx));
- if (current_node_id==f->node) {
+ if (current_node_id == f->node) {
//if function node, set up function arguments from begining of stack
- for(int i=0;i<f->argument_count;i++) {
- input_args[i]=&variant_stack[i];
+ for (int i = 0; i < f->argument_count; i++) {
+ input_args[i] = &variant_stack[i];
}
} else {
//run dependencies first
-
if (!node->dependencies.empty()) {
int dc = node->dependencies.size();
- VisualScriptNodeInstance **deps=node->dependencies.ptr();
+ VisualScriptNodeInstance **deps = node->dependencies.ptr();
- for(int i=0;i<dc;i++) {
+ for (int i = 0; i < dc; i++) {
- _dependency_step(deps[i],p_pass,pass_stack,input_args,output_args,variant_stack,r_error,error_str,&node);
- if (r_error.error!=Variant::CallError::CALL_OK) {
- error=true;
- current_node_id=node->id;
+ _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, &node);
+ if (r_error.error != Variant::CallError::CALL_OK) {
+ error = true;
+ current_node_id = node->id;
break;
}
}
@@ -1641,22 +1517,20 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
if (!error) {
//setup input pointers normally
- VSDEBUG("INPUT PORTS: "+itos(node->input_port_count));
-
- for(int i=0 ; i<node->input_port_count ; i++) {
+ VSDEBUG("INPUT PORTS: " + itos(node->input_port_count));
+ for (int i = 0; i < node->input_port_count; i++) {
int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK;
if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) {
//is a default value (unassigned input port)
- input_args[i]=&default_values[index];
- VSDEBUG("\tPORT "+itos(i)+" DEFAULT VAL");
+ input_args[i] = &default_values[index];
+ VSDEBUG("\tPORT " + itos(i) + " DEFAULT VAL");
} else {
//regular temporary in stack
- input_args[i]=&variant_stack[index];
- VSDEBUG("PORT "+itos(i)+" AT STACK "+itos(index));
-
+ input_args[i] = &variant_stack[index];
+ VSDEBUG("PORT " + itos(i) + " AT STACK " + itos(index));
}
}
}
@@ -1667,10 +1541,10 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
//setup output pointers
- VSDEBUG("OUTPUT PORTS: "+itos(node->output_port_count));
- for(int i=0 ; i<node->output_port_count ; i++) {
- output_args[i] = &variant_stack[ node->output_ports[i] ];
- VSDEBUG("PORT "+itos(i)+" AT STACK "+itos(node->output_ports[i]));
+ VSDEBUG("OUTPUT PORTS: " + itos(node->output_port_count));
+ for (int i = 0; i < node->output_port_count; i++) {
+ output_args[i] = &variant_stack[node->output_ports[i]];
+ VSDEBUG("PORT " + itos(i) + " AT STACK " + itos(node->output_ports[i]));
}
//do step
@@ -1678,57 +1552,55 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
VisualScriptNodeInstance::StartMode start_mode;
{
if (p_resuming_yield)
- start_mode=VisualScriptNodeInstance::START_MODE_RESUME_YIELD;
+ start_mode = VisualScriptNodeInstance::START_MODE_RESUME_YIELD;
else if (!flow_stack || !(flow_stack[flow_stack_pos] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT)) //if there is a push bit, it means we are continuing a sequence
- start_mode=VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE;
+ start_mode = VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE;
else
- start_mode=VisualScriptNodeInstance::START_MODE_CONTINUE_SEQUENCE;
+ start_mode = VisualScriptNodeInstance::START_MODE_CONTINUE_SEQUENCE;
}
- VSDEBUG("STEP - STARTSEQ: "+itos(start_mode));
+ VSDEBUG("STEP - STARTSEQ: " + itos(start_mode));
- int ret = node->step(input_args,output_args,start_mode,working_mem,r_error,error_str);
+ int ret = node->step(input_args, output_args, start_mode, working_mem, r_error, error_str);
- if (r_error.error!=Variant::CallError::CALL_OK) {
+ if (r_error.error != Variant::CallError::CALL_OK) {
//use error from step
- error=true;
+ error = true;
break;
}
- if (ret&VisualScriptNodeInstance::STEP_YIELD_BIT) {
+ if (ret & VisualScriptNodeInstance::STEP_YIELD_BIT) {
//yielded!
- if (node->get_working_memory_size()==0) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("A node yielded without working memory, please read the docs on how to yield properly!");
- error=true;
+ if (node->get_working_memory_size() == 0) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("A node yielded without working memory, please read the docs on how to yield properly!");
+ error = true;
break;
} else {
Ref<VisualScriptFunctionState> state = *working_mem;
if (!state.is_valid()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("Node yielded, but did not return a function state in the first working memory.");
- error=true;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("Node yielded, but did not return a function state in the first working memory.");
+ error = true;
break;
-
}
//step 1, capture all state
- 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;
- state->variant_stack_size=f->max_stack;
- state->node=node;
- state->flow_stack_pos=flow_stack_pos;
+ 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;
+ state->variant_stack_size = f->max_stack;
+ state->node = node;
+ state->flow_stack_pos = flow_stack_pos;
state->stack.resize(p_stack_size);
- state->pass=p_pass;
- copymem(state->stack.ptr(),p_stack,p_stack_size);
+ state->pass = p_pass;
+ copymem(state->stack.ptr(), p_stack, p_stack_size);
//step 2, run away, return directly
- r_error.error=Variant::CallError::CALL_OK;
-
+ r_error.error = Variant::CallError::CALL_OK;
#ifdef DEBUG_ENABLED
//will re-enter later, so exiting
@@ -1738,67 +1610,65 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
#endif
return state;
-
}
}
#ifdef DEBUG_ENABLED
if (ScriptDebugger::get_singleton()) {
// line
- bool do_break=false;
+ bool do_break = false;
- if (ScriptDebugger::get_singleton()->get_lines_left()>0) {
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0) {
- if (ScriptDebugger::get_singleton()->get_depth()<=0)
- ScriptDebugger::get_singleton()->set_lines_left( ScriptDebugger::get_singleton()->get_lines_left() -1 );
- if (ScriptDebugger::get_singleton()->get_lines_left()<=0)
- do_break=true;
+ if (ScriptDebugger::get_singleton()->get_depth() <= 0)
+ ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1);
+ if (ScriptDebugger::get_singleton()->get_lines_left() <= 0)
+ do_break = true;
}
- if (ScriptDebugger::get_singleton()->is_breakpoint(current_node_id,source))
- do_break=true;
+ if (ScriptDebugger::get_singleton()->is_breakpoint(current_node_id, source))
+ do_break = true;
if (do_break) {
- VisualScriptLanguage::singleton->debug_break("Breakpoint",true);
+ VisualScriptLanguage::singleton->debug_break("Breakpoint", true);
}
ScriptDebugger::get_singleton()->line_poll();
-
}
#endif
int output = ret & VisualScriptNodeInstance::STEP_MASK;
- VSDEBUG("STEP RETURN: "+itos(ret));
+ VSDEBUG("STEP RETURN: " + itos(ret));
if (ret & VisualScriptNodeInstance::STEP_EXIT_FUNCTION_BIT) {
- if (node->get_working_memory_size()==0) {
+ if (node->get_working_memory_size() == 0) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("Return value must be assigned to first element of node working memory! Fix your node please.");
- error=true;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("Return value must be assigned to first element of node working memory! Fix your node please.");
+ error = true;
} else {
//assign from working memory, first element
- return_value=*working_mem;
+ return_value = *working_mem;
}
- VSDEBUG("EXITING FUNCTION - VALUE "+String(return_value));
+ VSDEBUG("EXITING FUNCTION - VALUE " + String(return_value));
break; //exit function requested, bye
}
- VisualScriptNodeInstance *next=NULL; //next node
+ VisualScriptNodeInstance *next = NULL; //next node
- if ( (ret==output || ret&VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) && node->sequence_output_count) {
+ if ((ret == output || ret & VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) && node->sequence_output_count) {
//if no exit bit was set, and has sequence outputs, guess next node
- if (output<0 || output>=node->sequence_output_count) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("Node returned an invalid sequence output: ")+itos(output);
- error=true;
+ if (output < 0 || output >= node->sequence_output_count) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("Node returned an invalid sequence output: ") + itos(output);
+ error = true;
break;
}
next = node->sequence_outputs[output];
if (next) {
- VSDEBUG("GOT NEXT NODE - "+itos(next->get_id()));
+ VSDEBUG("GOT NEXT NODE - " + itos(next->get_id()));
} else {
VSDEBUG("GOT NEXT NODE - NULL");
}
@@ -1813,20 +1683,19 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
if (ret & VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) {
flow_stack[flow_stack_pos] |= VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT;
- sequence_bits[ node ->sequence_index ]=true; //remember sequence bit
+ sequence_bits[node->sequence_index] = true; //remember sequence bit
VSDEBUG("NEXT SEQ - FLAG BIT");
} else {
- sequence_bits[ node ->sequence_index ]=false; //forget sequence bit
+ sequence_bits[node->sequence_index] = false; //forget sequence bit
VSDEBUG("NEXT SEQ - NORMAL");
}
-
if (ret & VisualScriptNodeInstance::STEP_FLAG_GO_BACK_BIT) {
//go back request
- if (flow_stack_pos>0) {
+ if (flow_stack_pos > 0) {
flow_stack_pos--;
- node = instances[ flow_stack[flow_stack_pos] & VisualScriptNodeInstance::FLOW_STACK_MASK ];
+ node = instances[flow_stack[flow_stack_pos] & VisualScriptNodeInstance::FLOW_STACK_MASK];
VSDEBUG("NEXT IS GO BACK");
} else {
VSDEBUG("NEXT IS GO BACK, BUT NO NEXT SO EXIT");
@@ -1834,7 +1703,6 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
}
} else if (next) {
-
if (sequence_bits[next->sequence_index]) {
// what happened here is that we are entering a node that is in the middle of doing a sequence (pushed stack) from the front
// because each node has a working memory, we can't really do a sub-sequence
@@ -1843,43 +1711,41 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
bool found = false;
- for(int i=flow_stack_pos;i>=0;i--) {
-
+ for (int i = flow_stack_pos; i >= 0; i--) {
- if ( (flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK ) == next->get_id() ) {
- flow_stack_pos=i; //roll back and remove bit
- flow_stack[i]=next->get_id();
- sequence_bits[next->sequence_index]=false;
- found=true;
+ if ((flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK) == next->get_id()) {
+ flow_stack_pos = i; //roll back and remove bit
+ flow_stack[i] = next->get_id();
+ sequence_bits[next->sequence_index] = false;
+ found = true;
}
}
if (!found) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("Found sequence bit but not the node in the stack, report bug!");
- error=true;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("Found sequence bit but not the node in the stack, report bug!");
+ error = true;
break;
}
- node=next;
- VSDEBUG("RE-ENTERED A LOOP, RETURNED STACK POS TO - "+itos(flow_stack_pos));
+ node = next;
+ VSDEBUG("RE-ENTERED A LOOP, RETURNED STACK POS TO - " + itos(flow_stack_pos));
} else {
// check for stack overflow
- if (flow_stack_pos+1 >= flow_max) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- error_str=RTR("Stack overflow with stack depth: ")+itos(output);
- error=true;
+ if (flow_stack_pos + 1 >= flow_max) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ error_str = RTR("Stack overflow with stack depth: ") + itos(output);
+ error = true;
break;
}
node = next;
flow_stack_pos++;
- flow_stack[flow_stack_pos]=node->get_id();
+ flow_stack[flow_stack_pos] = node->get_id();
VSDEBUG("INCREASE FLOW STACK");
-
}
} else {
@@ -1887,14 +1753,14 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
bool found = false;
- for(int i=flow_stack_pos;i>=0;i--) {
+ for (int i = flow_stack_pos; i >= 0; i--) {
- VSDEBUG("FS "+itos(i)+" - "+itos(flow_stack[i]));
+ VSDEBUG("FS " + itos(i) + " - " + itos(flow_stack[i]));
if (flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT) {
- node = instances[ flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK ];
- flow_stack_pos=i;
- found=true;
+ node = instances[flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK];
+ flow_stack_pos = i;
+ found = true;
break;
}
}
@@ -1904,59 +1770,53 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
break; //done, couldn't find a push stack bit
}
- VSDEBUG("NO NEXT NODE, GO BACK TO: "+itos(flow_stack_pos));
-
+ VSDEBUG("NO NEXT NODE, GO BACK TO: " + itos(flow_stack_pos));
}
} else {
- node=next; //stackless mode, simply assign next node
+ node = next; //stackless mode, simply assign next node
}
-
}
-
-
if (error) {
//error
// function, file, line, error, explanation
String err_file = script->get_path();
String err_func = p_method;
- int err_line=current_node_id; //not a line but it works as one
+ int err_line = current_node_id; //not a line but it works as one
- if (node && (r_error.error!=Variant::CallError::CALL_ERROR_INVALID_METHOD || error_str==String())) {
+ if (node && (r_error.error != Variant::CallError::CALL_ERROR_INVALID_METHOD || error_str == String())) {
- if (error_str!=String()) {
- error_str+=" ";
+ if (error_str != String()) {
+ error_str += " ";
}
- if (r_error.error==Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
- int errorarg=r_error.argument;
- error_str+="Cannot convert argument "+itos(errorarg+1)+" to "+Variant::get_type_name(r_error.expected)+".";
- } else if (r_error.error==Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
- error_str+="Expected "+itos(r_error.argument)+" arguments.";
- } else if (r_error.error==Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
- error_str+="Expected "+itos(r_error.argument)+" arguments.";
- } else if (r_error.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) {
- error_str+="Invalid Call.";
- } else if (r_error.error==Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
- error_str+="Base Instance is null";
+ if (r_error.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) {
+ int errorarg = r_error.argument;
+ error_str += "Cannot convert argument " + itos(errorarg + 1) + " to " + Variant::get_type_name(r_error.expected) + ".";
+ } else if (r_error.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) {
+ error_str += "Expected " + itos(r_error.argument) + " arguments.";
+ } else if (r_error.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {
+ error_str += "Expected " + itos(r_error.argument) + " arguments.";
+ } else if (r_error.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) {
+ error_str += "Invalid Call.";
+ } else if (r_error.error == Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) {
+ error_str += "Base Instance is null";
}
}
-
//if (!GDScriptLanguage::get_singleton()->debug_break(err_text,false)) {
- // debugger break did not happen
+ // debugger break did not happen
- if (!VisualScriptLanguage::singleton->debug_break(error_str,false)) {
+ if (!VisualScriptLanguage::singleton->debug_break(error_str, false)) {
- _err_print_error(err_func.utf8().get_data(),err_file.utf8().get_data(),err_line,error_str.utf8().get_data(),ERR_HANDLER_SCRIPT);
+ _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), ERR_HANDLER_SCRIPT);
}
//}
} else {
-
//return_value=
}
@@ -1967,64 +1827,62 @@ Variant VisualScriptInstance::_call_internal(const StringName& p_method, void* p
#endif
//clean up variant stack
- for(int i=0;i<f->max_stack;i++) {
+ for (int i = 0; i < f->max_stack; i++) {
variant_stack[i].~Variant();
}
-
return return_value;
}
+Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant VisualScriptInstance::call(const StringName& p_method, const Variant** p_args, int p_argcount, Variant::CallError &r_error){
+ r_error.error = Variant::CallError::CALL_OK; //ok by default
- r_error.error=Variant::CallError::CALL_OK; //ok by default
-
- Map<StringName,Function>::Element *F = functions.find(p_method);
+ Map<StringName, Function>::Element *F = functions.find(p_method);
if (!F) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}
- VSDEBUG("CALLING: "+String(p_method));
+ VSDEBUG("CALLING: " + String(p_method));
- Function *f=&F->get();
+ Function *f = &F->get();
- int total_stack_size=0;
+ int total_stack_size = 0;
- total_stack_size+=f->max_stack*sizeof(Variant); //variants
- total_stack_size+=f->node_count*sizeof(bool);
- total_stack_size+=(max_input_args+max_output_args)*sizeof(Variant*); //arguments
- total_stack_size+=f->flow_stack_size*sizeof(int); //flow
- total_stack_size+=f->pass_stack_size*sizeof(int);
+ total_stack_size += f->max_stack * sizeof(Variant); //variants
+ total_stack_size += f->node_count * sizeof(bool);
+ total_stack_size += (max_input_args + max_output_args) * sizeof(Variant *); //arguments
+ total_stack_size += f->flow_stack_size * sizeof(int); //flow
+ total_stack_size += f->pass_stack_size * sizeof(int);
- VSDEBUG("STACK SIZE: "+itos(total_stack_size));
- VSDEBUG("STACK VARIANTS: : "+itos(f->max_stack));
- VSDEBUG("SEQBITS: : "+itos(f->node_count));
- VSDEBUG("MAX INPUT: "+itos(max_input_args));
- VSDEBUG("MAX OUTPUT: "+itos(max_output_args));
- VSDEBUG("FLOW STACK SIZE: "+itos(f->flow_stack_size));
- VSDEBUG("PASS STACK SIZE: "+itos(f->pass_stack_size));
+ VSDEBUG("STACK SIZE: " + itos(total_stack_size));
+ VSDEBUG("STACK VARIANTS: : " + itos(f->max_stack));
+ VSDEBUG("SEQBITS: : " + itos(f->node_count));
+ VSDEBUG("MAX INPUT: " + itos(max_input_args));
+ VSDEBUG("MAX OUTPUT: " + itos(max_output_args));
+ VSDEBUG("FLOW STACK SIZE: " + itos(f->flow_stack_size));
+ VSDEBUG("PASS STACK SIZE: " + itos(f->pass_stack_size));
void *stack = alloca(total_stack_size);
- Variant *variant_stack=(Variant*)stack;
- bool *sequence_bits = (bool*)(variant_stack + f->max_stack);
- const Variant **input_args=(const Variant**)(sequence_bits+f->node_count);
- Variant **output_args=(Variant**)(input_args + max_input_args);
+ Variant *variant_stack = (Variant *)stack;
+ bool *sequence_bits = (bool *)(variant_stack + f->max_stack);
+ const Variant **input_args = (const Variant **)(sequence_bits + f->node_count);
+ Variant **output_args = (Variant **)(input_args + max_input_args);
int flow_max = f->flow_stack_size;
- int* flow_stack = flow_max? (int*)(output_args + max_output_args) : (int*)NULL;
+ int *flow_stack = flow_max ? (int *)(output_args + max_output_args) : (int *)NULL;
int *pass_stack = flow_stack + flow_max;
- for(int i=0;i<f->node_count;i++) {
- sequence_bits[i]=false; //all starts as false
+ for (int i = 0; i < f->node_count; i++) {
+ sequence_bits[i] = false; //all starts as false
}
- zeromem(pass_stack,f->pass_stack_size*sizeof(int));
+ zeromem(pass_stack, f->pass_stack_size * sizeof(int));
- Map<int,VisualScriptNodeInstance*>::Element *E = instances.find(f->node);
+ Map<int, VisualScriptNodeInstance *>::Element *E = instances.find(f->node);
if (!E) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
ERR_EXPLAIN("No VisualScriptFunction node in function!");
ERR_FAIL_V(Variant());
@@ -2032,66 +1890,62 @@ Variant VisualScriptInstance::call(const StringName& p_method, const Variant** p
VisualScriptNodeInstance *node = E->get();
-
- if (flow_stack) {
- flow_stack[0]=node->get_id();
+ if (flow_stack) {
+ flow_stack[0] = node->get_id();
}
- VSDEBUG("ARGUMENTS: "+itos(f->argument_count)=" RECEIVED: "+itos(p_argcount));
+ VSDEBUG("ARGUMENTS: " + itos(f->argument_count) = " RECEIVED: " + itos(p_argcount));
- if (p_argcount<f->argument_count) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=node->get_input_port_count();
+ if (p_argcount < f->argument_count) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = node->get_input_port_count();
return Variant();
}
- if (p_argcount>f->argument_count) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument=node->get_input_port_count();
+ if (p_argcount > f->argument_count) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = node->get_input_port_count();
return Variant();
}
//allocate variant stack
- for(int i=0;i<f->max_stack;i++) {
- memnew_placement(&variant_stack[i],Variant);
+ for (int i = 0; i < f->max_stack; i++) {
+ memnew_placement(&variant_stack[i], Variant);
}
//allocate function arguments (must be copied for yield to work properly)
- for(int i=0;i<p_argcount;i++) {
- variant_stack[i]=*p_args[i];
+ for (int i = 0; i < p_argcount; i++) {
+ variant_stack[i] = *p_args[i];
}
- return _call_internal(p_method,stack,total_stack_size,node,0,0,false,r_error);
-
-
+ return _call_internal(p_method, stack, total_stack_size, node, 0, 0, false, r_error);
}
-void VisualScriptInstance::notification(int p_notification){
+void VisualScriptInstance::notification(int p_notification) {
//do nothing as this is called using virtual
- Variant what=p_notification;
- const Variant*whatp=&what;
+ Variant what = p_notification;
+ const Variant *whatp = &what;
Variant::CallError ce;
- call(VisualScriptLanguage::singleton->notification,&whatp,1,ce); //do as call
-
+ call(VisualScriptLanguage::singleton->notification, &whatp, 1, ce); //do as call
}
-Ref<Script> VisualScriptInstance::get_script() const{
+Ref<Script> VisualScriptInstance::get_script() const {
return script;
}
-ScriptInstance::RPCMode VisualScriptInstance::get_rpc_mode(const StringName& p_method) const {
+ScriptInstance::RPCMode VisualScriptInstance::get_rpc_mode(const StringName &p_method) const {
- const Map<StringName,VisualScript::Function>::Element *E = script->functions.find(p_method);
+ const Map<StringName, VisualScript::Function>::Element *E = script->functions.find(p_method);
if (!E) {
return RPC_MODE_DISABLED;
}
- if (E->get().function_id>=0 && E->get().nodes.has(E->get().function_id)) {
+ if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) {
Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node;
if (vsf.is_valid()) {
@@ -2103,24 +1957,23 @@ ScriptInstance::RPCMode VisualScriptInstance::get_rpc_mode(const StringName& p_m
return RPC_MODE_DISABLED;
}
-ScriptInstance::RPCMode VisualScriptInstance::get_rset_mode(const StringName& p_variable) const {
+ScriptInstance::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_variable) const {
return RPC_MODE_DISABLED;
}
+void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) {
-void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_owner) {
-
- script=p_script;
- owner=p_owner;
- source=p_script->get_path();
+ script = p_script;
+ owner = p_owner;
+ source = p_script->get_path();
max_input_args = 0;
max_output_args = 0;
if (p_owner->cast_to<Node>()) {
//turn on these if they exist and base is a node
- Node* node = p_owner->cast_to<Node>();
+ Node *node = p_owner->cast_to<Node>();
if (p_script->functions.has("_process"))
node->set_process(true);
if (p_script->functions.has("_fixed_process"))
@@ -2133,86 +1986,81 @@ void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_ow
node->set_process_unhandled_key_input(true);
}
- for(const Map<StringName,VisualScript::Variable>::Element *E=script->variables.front();E;E=E->next()) {
- variables[E->key()]=E->get().default_value;
+ for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) {
+ variables[E->key()] = E->get().default_value;
//no hacer que todo exporte, solo las que queres!
}
-
- for(const Map<StringName,VisualScript::Function>::Element *E=script->functions.front();E;E=E->next()) {
+ for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) {
Function function;
- function.node=E->get().function_id;
- function.max_stack=0;
- function.flow_stack_size=0;
- function.pass_stack_size=0;
- function.node_count=0;
- Map<StringName,int> local_var_indices;
+ function.node = E->get().function_id;
+ function.max_stack = 0;
+ function.flow_stack_size = 0;
+ function.pass_stack_size = 0;
+ function.node_count = 0;
+ Map<StringName, int> local_var_indices;
- if (function.node<0) {
- VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(),0,"No start node in function: "+String(E->key()));
+ if (function.node < 0) {
+ VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No start node in function: " + String(E->key()));
- ERR_CONTINUE( function.node < 0 );
+ ERR_CONTINUE(function.node < 0);
}
{
- Ref<VisualScriptFunction> func_node = script->get_node(E->key(),E->get().function_id);
+ Ref<VisualScriptFunction> func_node = script->get_node(E->key(), E->get().function_id);
if (func_node.is_null()) {
- VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(),0,"No VisualScriptFunction typed start node in function: "+String(E->key()));
+ VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No VisualScriptFunction typed start node in function: " + String(E->key()));
}
- ERR_CONTINUE( !func_node.is_valid() );
-
- function.argument_count=func_node->get_argument_count();
- function.max_stack+=function.argument_count;
- function.flow_stack_size= func_node->is_stack_less() ? 0 : func_node->get_stack_size();
+ ERR_CONTINUE(!func_node.is_valid());
+ function.argument_count = func_node->get_argument_count();
+ function.max_stack += function.argument_count;
+ function.flow_stack_size = func_node->is_stack_less() ? 0 : func_node->get_stack_size();
}
//multiple passes are required to set up this complex thing..
-
-
-
//first create the nodes
- for (const Map<int,VisualScript::Function::NodeData>::Element *F=E->get().nodes.front();F;F=F->next()) {
+ for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) {
Ref<VisualScriptNode> node = F->get().node;
VisualScriptNodeInstance *instance = node->instance(this); //create instance
ERR_FAIL_COND(!instance);
- instance->base=node.ptr();
+ instance->base = node.ptr();
- instance->id=F->key();
+ instance->id = F->key();
instance->input_port_count = node->get_input_value_port_count();
- instance->input_ports=NULL;
+ instance->input_ports = NULL;
instance->output_port_count = node->get_output_value_port_count();
- instance->output_ports=NULL;
+ instance->output_ports = NULL;
instance->sequence_output_count = node->get_output_sequence_port_count();
- instance->sequence_index=function.node_count++;
- instance->sequence_outputs=NULL;
- instance->pass_idx=-1;
+ instance->sequence_index = function.node_count++;
+ instance->sequence_outputs = NULL;
+ instance->pass_idx = -1;
if (instance->input_port_count) {
- instance->input_ports = memnew_arr(int,instance->input_port_count);
- for(int i=0;i<instance->input_port_count;i++) {
+ instance->input_ports = memnew_arr(int, instance->input_port_count);
+ for (int i = 0; i < instance->input_port_count; i++) {
- instance->input_ports[i]=-1; //if not assigned, will become default value
- }
+ instance->input_ports[i] = -1; //if not assigned, will become default value
+ }
}
if (instance->output_port_count) {
- instance->output_ports = memnew_arr(int,instance->output_port_count);
- for(int i=0;i<instance->output_port_count;i++) {
- instance->output_ports[i]=-1; //if not assigned, will output to trash
+ instance->output_ports = memnew_arr(int, instance->output_port_count);
+ for (int i = 0; i < instance->output_port_count; i++) {
+ instance->output_ports[i] = -1; //if not assigned, will output to trash
}
}
if (instance->sequence_output_count) {
- instance->sequence_outputs = memnew_arr(VisualScriptNodeInstance*,instance->sequence_output_count);
- for(int i=0;i<instance->sequence_output_count;i++) {
- instance->sequence_outputs[i]=NULL; //if it remains null, flow ends here
+ instance->sequence_outputs = memnew_arr(VisualScriptNodeInstance *, instance->sequence_output_count);
+ for (int i = 0; i < instance->sequence_output_count; i++) {
+ instance->sequence_outputs[i] = NULL; //if it remains null, flow ends here
}
}
@@ -2228,32 +2076,30 @@ void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_ow
var_name = String(node->cast_to<VisualScriptLocalVarSet>()->get_var_name()).strip_edges();
if (!local_var_indices.has(var_name)) {
- local_var_indices[var_name]=function.max_stack;
+ local_var_indices[var_name] = function.max_stack;
function.max_stack++;
}
- instance->working_mem_idx=local_var_indices[var_name];
+ instance->working_mem_idx = local_var_indices[var_name];
} else if (instance->get_working_memory_size()) {
instance->working_mem_idx = function.max_stack;
- function.max_stack+=instance->get_working_memory_size();
+ function.max_stack += instance->get_working_memory_size();
} else {
- instance->working_mem_idx=-1; //no working mem
+ instance->working_mem_idx = -1; //no working mem
}
- max_input_args = MAX( max_input_args, instance->input_port_count );
- max_output_args = MAX( max_output_args, instance->output_port_count );
-
- instances[F->key()]=instance;
-
+ max_input_args = MAX(max_input_args, instance->input_port_count);
+ max_output_args = MAX(max_output_args, instance->output_port_count);
+ instances[F->key()] = instance;
}
function.trash_pos = function.max_stack++; //create pos for trash
//second pass, do data connections
- for(const Set<VisualScript::DataConnection>::Element *F=E->get().data_connections.front();F;F=F->next()) {
+ for (const Set<VisualScript::DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) {
VisualScript::DataConnection dc = F->get();
ERR_CONTINUE(!instances.has(dc.from_node));
@@ -2263,29 +2109,27 @@ void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_ow
ERR_CONTINUE(dc.from_port >= from->output_port_count);
ERR_CONTINUE(dc.to_port >= to->input_port_count);
- if (from->output_ports[dc.from_port]==-1) {
+ if (from->output_ports[dc.from_port] == -1) {
int stack_pos = function.max_stack++;
from->output_ports[dc.from_port] = stack_pos;
}
-
- if (from->get_sequence_output_count()==0 && to->dependencies.find(from)==-1) {
+ if (from->get_sequence_output_count() == 0 && to->dependencies.find(from) == -1) {
//if the node we are reading from has no output sequence, we must call step() before reading from it.
- if (from->pass_idx==-1) {
- from->pass_idx=function.pass_stack_size;
+ if (from->pass_idx == -1) {
+ from->pass_idx = function.pass_stack_size;
function.pass_stack_size++;
}
to->dependencies.push_back(from);
}
to->input_ports[dc.to_port] = from->output_ports[dc.from_port]; //read from wherever the stack is
-
}
//third pass, do sequence connections
- for(const Set<VisualScript::SequenceConnection>::Element *F=E->get().sequence_connections.front();F;F=F->next()) {
+ for (const Set<VisualScript::SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) {
VisualScript::SequenceConnection sc = F->get();
ERR_CONTINUE(!instances.has(sc.from_node));
@@ -2294,16 +2138,14 @@ void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_ow
VisualScriptNodeInstance *to = instances[sc.to_node];
ERR_CONTINUE(sc.from_output >= from->sequence_output_count);
- from->sequence_outputs[sc.from_output]=to;
-
+ from->sequence_outputs[sc.from_output] = to;
}
//fourth pass:
// 1) unassigned input ports to default values
// 2) connect unassigned output ports to trash
-
- for (const Map<int,VisualScript::Function::NodeData>::Element *F=E->get().nodes.front();F;F=F->next()) {
+ for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) {
ERR_CONTINUE(!instances.has(F->key()));
@@ -2311,37 +2153,33 @@ void VisualScriptInstance::create(const Ref<VisualScript>& p_script,Object *p_ow
VisualScriptNodeInstance *instance = instances[F->key()];
// conect to default values
- for(int i=0;i<instance->input_port_count;i++) {
- if (instance->input_ports[i]==-1) {
+ for (int i = 0; i < instance->input_port_count; i++) {
+ if (instance->input_ports[i] == -1) {
//unassigned, connect to default val
instance->input_ports[i] = default_values.size() | VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT;
- default_values.push_back( node->get_default_input_value(i) );
+ default_values.push_back(node->get_default_input_value(i));
}
}
// conect to trash
- for(int i=0;i<instance->output_port_count;i++) {
- if (instance->output_ports[i]==-1) {
+ for (int i = 0; i < instance->output_port_count; i++) {
+ if (instance->output_ports[i] == -1) {
instance->output_ports[i] = function.trash_pos; //trash is same for all
}
}
}
-
- functions[E->key()]=function;
+ functions[E->key()] = function;
}
}
-ScriptLanguage *VisualScriptInstance::get_language(){
+ScriptLanguage *VisualScriptInstance::get_language() {
return VisualScriptLanguage::singleton;
}
-
VisualScriptInstance::VisualScriptInstance() {
-
-
}
VisualScriptInstance::~VisualScriptInstance() {
@@ -2354,22 +2192,18 @@ VisualScriptInstance::~VisualScriptInstance() {
if (VisualScriptLanguage::singleton->lock)
VisualScriptLanguage::singleton->lock->unlock();
- for (Map<int,VisualScriptNodeInstance*>::Element *E=instances.front();E;E=E->next()) {
+ for (Map<int, VisualScriptNodeInstance *>::Element *E = instances.front(); E; E = E->next()) {
memdelete(E->get());
}
}
-
-
/////////////////////////////////////////////
-
/////////////////////
+Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant VisualScriptFunctionState::_signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- ERR_FAIL_COND_V(function==StringName(),Variant());
+ ERR_FAIL_COND_V(function == StringName(), Variant());
#ifdef DEBUG_ENABLED
if (instance_id && !ObjectDB::get_instance(instance_id)) {
@@ -2383,61 +2217,61 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant** p_args, int
}
#endif
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
Array args;
- if (p_argcount==0) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
+ if (p_argcount == 0) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
return Variant();
- } else if (p_argcount==1) {
+ } else if (p_argcount == 1) {
//noooneee, reserved for me, me and only me.
} else {
- for(int i=0;i<p_argcount-1;i++) {
+ for (int i = 0; i < p_argcount - 1; i++) {
args.push_back(*p_args[i]);
}
}
- Ref<VisualScriptFunctionState> self = *p_args[p_argcount-1]; //hi, I'm myself, needed this to remain alive.
+ Ref<VisualScriptFunctionState> self = *p_args[p_argcount - 1]; //hi, I'm myself, needed this to remain alive.
if (self.is_null()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=p_argcount-1;
- r_error.expected=Variant::OBJECT;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = p_argcount - 1;
+ r_error.expected = Variant::OBJECT;
return Variant();
}
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
- Variant *working_mem = ((Variant*)stack.ptr()) + working_mem_index;
+ Variant *working_mem = ((Variant *)stack.ptr()) + working_mem_index;
- *working_mem=args; //arguments go to working mem.
+ *working_mem = args; //arguments go to working mem.
- Variant ret = instance->_call_internal(function,stack.ptr(),stack.size(),node,flow_stack_pos,pass,true,r_error);
- function=StringName(); //invalidate
+ Variant ret = instance->_call_internal(function, stack.ptr(), stack.size(), node, flow_stack_pos, pass, true, r_error);
+ function = StringName(); //invalidate
return ret;
}
-void VisualScriptFunctionState::connect_to_signal(Object* p_obj, const String& p_signal, Array p_binds) {
+void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds) {
Vector<Variant> binds;
- for(int i=0;i<p_binds.size();i++) {
+ for (int i = 0; i < p_binds.size(); i++) {
binds.push_back(p_binds[i]);
}
binds.push_back(Ref<VisualScriptFunctionState>(this)); //add myself on the back to avoid dying from unreferencing
- p_obj->connect(p_signal,this,"_signal_callback",binds);
+ p_obj->connect(p_signal, this, "_signal_callback", binds);
}
bool VisualScriptFunctionState::is_valid() const {
- return function!=StringName();
+ return function != StringName();
}
Variant VisualScriptFunctionState::resume(Array p_args) {
- ERR_FAIL_COND_V(function==StringName(),Variant());
+ ERR_FAIL_COND_V(function == StringName(), Variant());
#ifdef DEBUG_ENABLED
if (instance_id && !ObjectDB::get_instance(instance_id)) {
ERR_EXPLAIN("Resumed after yield, but class instance is gone");
@@ -2451,44 +2285,38 @@ Variant VisualScriptFunctionState::resume(Array p_args) {
#endif
Variant::CallError r_error;
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
- Variant *working_mem = ((Variant*)stack.ptr()) + working_mem_index;
+ Variant *working_mem = ((Variant *)stack.ptr()) + working_mem_index;
- *working_mem=p_args; //arguments go to working mem.
+ *working_mem = p_args; //arguments go to working mem.
- Variant ret= instance->_call_internal(function,stack.ptr(),stack.size(),node,flow_stack_pos,pass,true,r_error);
- function=StringName(); //invalidate
+ Variant ret = instance->_call_internal(function, stack.ptr(), stack.size(), node, flow_stack_pos, pass, true, r_error);
+ function = StringName(); //invalidate
return ret;
}
-
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("is_valid"),&VisualScriptFunctionState::is_valid);
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"_signal_callback",&VisualScriptFunctionState::_signal_callback,MethodInfo("_signal_callback"));
+ 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("is_valid"), &VisualScriptFunctionState::is_valid);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &VisualScriptFunctionState::_signal_callback, MethodInfo("_signal_callback"));
}
VisualScriptFunctionState::VisualScriptFunctionState() {
-
}
VisualScriptFunctionState::~VisualScriptFunctionState() {
- if (function!=StringName()) {
- Variant *s = ((Variant*)stack.ptr());
- for(int i=0;i<variant_stack_size;i++) {
+ if (function != StringName()) {
+ Variant *s = ((Variant *)stack.ptr());
+ for (int i = 0; i < variant_stack_size; i++) {
s[i].~Variant();
}
}
}
-
-
-
-
///////////////////////////////////////////////
String VisualScriptLanguage::get_name() const {
@@ -2498,8 +2326,6 @@ String VisualScriptLanguage::get_name() const {
/* LANGUAGE FUNCTIONS */
void VisualScriptLanguage::init() {
-
-
}
String VisualScriptLanguage::get_type() const {
@@ -2509,207 +2335,185 @@ String VisualScriptLanguage::get_extension() const {
return "vs";
}
-Error VisualScriptLanguage::execute_file(const String& p_path) {
+Error VisualScriptLanguage::execute_file(const String &p_path) {
return OK;
}
void VisualScriptLanguage::finish() {
-
-
}
/* EDITOR FUNCTIONS */
void VisualScriptLanguage::get_reserved_words(List<String> *p_words) const {
-
-
}
void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
-
-
}
void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
-
-
}
-Ref<Script> VisualScriptLanguage::get_template(const String& p_class_name, const String& p_base_class_name) const {
+Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const {
Ref<VisualScript> script;
script.instance();
script->set_instance_base_type(p_base_class_name);
return script;
}
-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 {
+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;
}
Script *VisualScriptLanguage::create_script() const {
- return memnew( VisualScript );
+ return memnew(VisualScript);
}
bool VisualScriptLanguage::has_named_classes() const {
return false;
}
-int VisualScriptLanguage::find_function(const String& p_function,const String& p_code) const {
+int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const {
return -1;
}
-String VisualScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const {
+String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const {
return String();
}
-void VisualScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const {
-
-
+void VisualScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {
}
-void VisualScriptLanguage::add_global_constant(const StringName& p_variable,const Variant& p_value) {
-
-
+void VisualScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) {
}
-
/* DEBUGGER FUNCTIONS */
-
-
-bool VisualScriptLanguage::debug_break_parse(const String& p_file, int p_node,const String& p_error) {
+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()) {
-
- _debug_parse_err_node=p_node;
- _debug_parse_err_file=p_file;
- _debug_error=p_error;
- ScriptDebugger::get_singleton()->debug(this,false);
- return true;
- } else {
- return false;
- }
+ if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) {
+ _debug_parse_err_node = p_node;
+ _debug_parse_err_file = p_file;
+ _debug_error = p_error;
+ ScriptDebugger::get_singleton()->debug(this, false);
+ return true;
+ } else {
+ return false;
+ }
}
-bool VisualScriptLanguage::debug_break(const String& p_error,bool p_allow_continue) {
-
- if (ScriptDebugger::get_singleton() && Thread::get_caller_ID()==Thread::get_main_ID()) {
+bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) {
- _debug_parse_err_node=-1;
- _debug_parse_err_file="";
- _debug_error=p_error;
- ScriptDebugger::get_singleton()->debug(this,p_allow_continue);
- return true;
- } else {
- return false;
- }
+ if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) {
+ _debug_parse_err_node = -1;
+ _debug_parse_err_file = "";
+ _debug_error = p_error;
+ ScriptDebugger::get_singleton()->debug(this, p_allow_continue);
+ return true;
+ } else {
+ return false;
+ }
}
-
String VisualScriptLanguage::debug_get_error() const {
- return _debug_error;
+ return _debug_error;
}
int VisualScriptLanguage::debug_get_stack_level_count() const {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return 1;
-
return _debug_call_stack_pos;
}
int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return _debug_parse_err_node;
- ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,-1);
-
- int l = _debug_call_stack_pos - p_level -1;
+ ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1);
- return *(_call_stack[l].current_id);
+ int l = _debug_call_stack_pos - p_level - 1;
+ return *(_call_stack[l].current_id);
}
String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return "";
- ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,"");
- int l = _debug_call_stack_pos - p_level -1;
- return *_call_stack[l].function;
+ ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
+ int l = _debug_call_stack_pos - p_level - 1;
+ return *_call_stack[l].function;
}
String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return _debug_parse_err_file;
- ERR_FAIL_INDEX_V(p_level,_debug_call_stack_pos,"");
- int l = _debug_call_stack_pos - p_level -1;
- return _call_stack[l].instance->get_script_ptr()->get_path();
-
+ ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
+ int l = _debug_call_stack_pos - p_level - 1;
+ return _call_stack[l].instance->get_script_ptr()->get_path();
}
-void VisualScriptLanguage::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 VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return;
- ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
+ ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
- int l = _debug_call_stack_pos - p_level -1;
+ int l = _debug_call_stack_pos - p_level - 1;
const StringName *f = _call_stack[l].function;
ERR_FAIL_COND(!_call_stack[l].instance->functions.has(*f));
//VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f];
- VisualScriptNodeInstance *node =_call_stack[l].instance->instances[*_call_stack[l].current_id];
+ VisualScriptNodeInstance *node = _call_stack[l].instance->instances[*_call_stack[l].current_id];
ERR_FAIL_COND(!node);
p_locals->push_back("node_name");
p_values->push_back(node->get_base_node()->get_text());
- for(int i=0;i<node->input_port_count;i++) {
+ for (int i = 0; i < node->input_port_count; i++) {
String name = node->get_base_node()->get_input_value_port_info(i).name;
- if (name==String()) {
- name="in_"+itos(i);
+ if (name == String()) {
+ name = "in_" + itos(i);
}
- p_locals->push_back("input/"+name);
+ p_locals->push_back("input/" + name);
//value is trickier
int in_from = node->input_ports[i];
- int in_value = in_from&VisualScriptNodeInstance::INPUT_MASK;
+ int in_value = in_from & VisualScriptNodeInstance::INPUT_MASK;
- if (in_from&VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) {
+ if (in_from & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) {
p_values->push_back(_call_stack[l].instance->default_values[in_value]);
} else {
- p_values->push_back( _call_stack[l].stack[ in_value] );
+ p_values->push_back(_call_stack[l].stack[in_value]);
}
}
- for(int i=0;i<node->output_port_count;i++) {
+ for (int i = 0; i < node->output_port_count; i++) {
String name = node->get_base_node()->get_output_value_port_info(i).name;
- if (name==String()) {
- name="out_"+itos(i);
+ if (name == String()) {
+ name = "out_" + itos(i);
}
- p_locals->push_back("output/"+name);
+ p_locals->push_back("output/" + name);
//value is trickier
int in_from = node->output_ports[i];
- p_values->push_back( _call_stack[l].stack[ in_from] );
-
+ p_values->push_back(_call_stack[l].stack[in_from]);
}
- for(int i=0;i<node->get_working_memory_size();i++) {
- p_locals->push_back("working_mem/mem_"+itos(i));
- p_values->push_back( (*_call_stack[l].work_mem)[i]);
+ for (int i = 0; i < node->get_working_memory_size(); i++) {
+ p_locals->push_back("working_mem/mem_" + itos(i));
+ p_values->push_back((*_call_stack[l].work_mem)[i]);
}
-/*
+ /*
ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
@@ -2725,14 +2529,13 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level,List<String>
}
*/
}
-void VisualScriptLanguage::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 VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return;
- ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
- int l = _debug_call_stack_pos - p_level -1;
-
+ ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
+ int l = _debug_call_stack_pos - p_level - 1;
Ref<VisualScript> vs = _call_stack[l].instance->get_script();
if (vs.is_null())
@@ -2740,123 +2543,103 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level,List<String
List<StringName> vars;
vs->get_variable_list(&vars);
- for (List<StringName>::Element *E=vars.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
Variant v;
- if (_call_stack[l].instance->get_variable(E->get(),&v)) {
- p_members->push_back("variables/"+E->get());
+ if (_call_stack[l].instance->get_variable(E->get(), &v)) {
+ p_members->push_back("variables/" + E->get());
p_values->push_back(v);
}
}
}
-void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems,int p_max_depth) {
+void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- //no globals are really reachable in gdscript
+ //no globals are really reachable in gdscript
}
-String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems,int p_max_depth) {
+String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_node>=0)
+ if (_debug_parse_err_node >= 0)
return "";
return "";
}
-
-
void VisualScriptLanguage::reload_all_scripts() {
-
-
}
-void VisualScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_soft_reload) {
-
-
+void VisualScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) {
}
/* LOADER FUNCTIONS */
void VisualScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("vs");
-
}
void VisualScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {
-
-
}
-void VisualScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_constants) const {
-
-
+void VisualScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const {
}
void VisualScriptLanguage::profiling_start() {
-
-
}
void VisualScriptLanguage::profiling_stop() {
-
-
}
-int VisualScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr,int p_info_max) {
+int VisualScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) {
return 0;
}
-int VisualScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr,int p_info_max) {
+int VisualScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) {
return 0;
}
+VisualScriptLanguage *VisualScriptLanguage::singleton = NULL;
-VisualScriptLanguage* VisualScriptLanguage::singleton=NULL;
-
-
-void VisualScriptLanguage::add_register_func(const String& p_name,VisualScriptNodeRegisterFunc p_func) {
+void VisualScriptLanguage::add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func) {
ERR_FAIL_COND(register_funcs.has(p_name));
- register_funcs[p_name]=p_func;
+ register_funcs[p_name] = p_func;
}
-Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String& p_name) {
+Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &p_name) {
- ERR_FAIL_COND_V(!register_funcs.has(p_name),Ref<VisualScriptNode>());
+ ERR_FAIL_COND_V(!register_funcs.has(p_name), Ref<VisualScriptNode>());
return register_funcs[p_name](p_name);
}
void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) {
- for (Map<String,VisualScriptNodeRegisterFunc>::Element *E=register_funcs.front();E;E=E->next()) {
+ for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) {
r_names->push_back(E->key());
}
}
-
VisualScriptLanguage::VisualScriptLanguage() {
- notification="_notification";
- _step="_step";
- _subcall="_subcall";
- singleton=this;
+ notification = "_notification";
+ _step = "_step";
+ _subcall = "_subcall";
+ singleton = this;
#ifndef NO_THREADS
lock = Mutex::create();
#endif
-
- _debug_parse_err_node=-1;
- _debug_parse_err_file="";
- _debug_call_stack_pos=0;
- int dmcs=GLOBAL_DEF("debug/script/max_call_stack",1024);
+ _debug_parse_err_node = -1;
+ _debug_parse_err_file = "";
+ _debug_call_stack_pos = 0;
+ int dmcs = GLOBAL_DEF("debug/script/max_call_stack", 1024);
if (ScriptDebugger::get_singleton()) {
//debugging enabled!
_debug_max_call_stack = dmcs;
- if (_debug_max_call_stack<1024)
- _debug_max_call_stack=1024;
- _call_stack = memnew_arr( CallLevel, _debug_max_call_stack+1 );
+ if (_debug_max_call_stack < 1024)
+ _debug_max_call_stack = 1024;
+ _call_stack = memnew_arr(CallLevel, _debug_max_call_stack + 1);
} else {
- _debug_max_call_stack=0;
- _call_stack=NULL;
+ _debug_max_call_stack = 0;
+ _call_stack = NULL;
}
-
}
VisualScriptLanguage::~VisualScriptLanguage() {
@@ -2864,8 +2647,8 @@ VisualScriptLanguage::~VisualScriptLanguage() {
if (lock)
memdelete(lock);
- if (_call_stack) {
+ if (_call_stack) {
memdelete_arr(_call_stack);
}
- singleton=NULL;
+ singleton = NULL;
}
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index ef73a89048..e3af3f4a1b 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -29,19 +29,19 @@
#ifndef VSCRIPT_H
#define VSCRIPT_H
-#include "script_language.h"
#include "os/thread.h"
+#include "script_language.h"
class VisualScriptInstance;
class VisualScriptNodeInstance;
class VisualScript;
class VisualScriptNode : public Resource {
- GDCLASS(VisualScriptNode,Resource)
+ GDCLASS(VisualScriptNode, Resource)
-friend class VisualScript;
+ friend class VisualScript;
- Set<VisualScript*> scripts_used;
+ Set<VisualScript *> scripts_used;
Array default_input_values;
bool breakpoint;
@@ -50,41 +50,40 @@ friend class VisualScript;
Array _get_default_input_values() const;
void validate_input_default_values();
-protected:
+protected:
void _notification(int p_what);
void ports_changed_notify();
static void _bind_methods();
-public:
+public:
Ref<VisualScript> get_visual_script() const;
- virtual int get_output_sequence_port_count() const=0;
- virtual bool has_input_sequence_port() const=0;
+ virtual int get_output_sequence_port_count() const = 0;
+ virtual bool has_input_sequence_port() const = 0;
- virtual String get_output_sequence_port_text(int p_port) const=0;
+ virtual String get_output_sequence_port_text(int p_port) const = 0;
virtual bool has_mixed_input_and_sequence_ports() const { return false; }
- virtual int get_input_value_port_count() const=0;
- virtual int get_output_value_port_count() const=0;
+ virtual int get_input_value_port_count() const = 0;
+ virtual int get_output_value_port_count() const = 0;
+ virtual PropertyInfo get_input_value_port_info(int p_idx) const = 0;
+ virtual PropertyInfo get_output_value_port_info(int p_idx) const = 0;
- virtual PropertyInfo get_input_value_port_info(int p_idx) const=0;
- virtual PropertyInfo get_output_value_port_info(int p_idx) const=0;
-
- void set_default_input_value(int p_port,const Variant& p_value);
+ void set_default_input_value(int p_port, const Variant &p_value);
Variant get_default_input_value(int p_port) const;
- virtual String get_caption() const=0;
- virtual String get_text() const=0;
- virtual String get_category() const=0;
+ virtual String get_caption() const = 0;
+ virtual String get_text() const = 0;
+ virtual String get_category() const = 0;
//used by editor, this is not really saved
void set_breakpoint(bool p_breakpoint);
bool is_breakpoint() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance)=0;
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0;
struct TypeGuess {
@@ -93,32 +92,32 @@ public:
StringName GDCLASS;
Ref<Script> script;
- TypeGuess() { type=Variant::NIL; ev_type=InputEvent::NONE; }
+ TypeGuess() {
+ type = Variant::NIL;
+ ev_type = InputEvent::NONE;
+ }
};
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptNode();
};
-
class VisualScriptNodeInstance {
-friend class VisualScriptInstance;
-friend class VisualScriptLanguage; //for debugger
-
+ friend class VisualScriptInstance;
+ friend class VisualScriptLanguage; //for debugger
enum { //input argument addressing
- INPUT_SHIFT=1<<24,
- INPUT_MASK=INPUT_SHIFT-1,
- INPUT_DEFAULT_VALUE_BIT=INPUT_SHIFT, // from unassigned input port, using default value (edited by user)
+ INPUT_SHIFT = 1 << 24,
+ INPUT_MASK = INPUT_SHIFT - 1,
+ INPUT_DEFAULT_VALUE_BIT = INPUT_SHIFT, // from unassigned input port, using default value (edited by user)
};
-
int id;
int sequence_index;
VisualScriptNodeInstance **sequence_outputs;
int sequence_output_count;
- Vector<VisualScriptNodeInstance*> dependencies;
+ Vector<VisualScriptNodeInstance *> dependencies;
int *input_ports;
int input_port_count;
int *output_ports;
@@ -129,7 +128,6 @@ friend class VisualScriptLanguage; //for debugger
VisualScriptNode *base;
public:
-
enum StartMode {
START_MODE_BEGIN_SEQUENCE,
START_MODE_CONTINUE_SEQUENCE,
@@ -137,44 +135,42 @@ public:
};
enum {
- STEP_SHIFT=1<<24,
- STEP_MASK=STEP_SHIFT-1,
- STEP_FLAG_PUSH_STACK_BIT=STEP_SHIFT, //push bit to stack
- STEP_FLAG_GO_BACK_BIT=STEP_SHIFT<<1, //go back to previous node
- STEP_NO_ADVANCE_BIT=STEP_SHIFT<<2, //do not advance past this node
- STEP_EXIT_FUNCTION_BIT=STEP_SHIFT<<3, //return from function
- STEP_YIELD_BIT=STEP_SHIFT<<4, //yield (will find VisualScriptFunctionState state in first working memory)
+ STEP_SHIFT = 1 << 24,
+ STEP_MASK = STEP_SHIFT - 1,
+ STEP_FLAG_PUSH_STACK_BIT = STEP_SHIFT, //push bit to stack
+ STEP_FLAG_GO_BACK_BIT = STEP_SHIFT << 1, //go back to previous node
+ STEP_NO_ADVANCE_BIT = STEP_SHIFT << 2, //do not advance past this node
+ STEP_EXIT_FUNCTION_BIT = STEP_SHIFT << 3, //return from function
+ STEP_YIELD_BIT = STEP_SHIFT << 4, //yield (will find VisualScriptFunctionState state in first working memory)
- FLOW_STACK_PUSHED_BIT=1<<30, //in flow stack, means bit was pushed (must go back here if end of sequence)
- FLOW_STACK_MASK=FLOW_STACK_PUSHED_BIT-1
+ FLOW_STACK_PUSHED_BIT = 1 << 30, //in flow stack, means bit was pushed (must go back here if end of sequence)
+ FLOW_STACK_MASK = FLOW_STACK_PUSHED_BIT - 1
};
- _FORCE_INLINE_ int get_input_port_count() const { return input_port_count; }
- _FORCE_INLINE_ int get_output_port_count() const { return output_port_count; }
- _FORCE_INLINE_ int get_sequence_output_count() const { return sequence_output_count; }
+ _FORCE_INLINE_ int get_input_port_count() const { return input_port_count; }
+ _FORCE_INLINE_ int get_output_port_count() const { return output_port_count; }
+ _FORCE_INLINE_ int get_sequence_output_count() const { return sequence_output_count; }
- _FORCE_INLINE_ int get_id() const { return id; }
+ _FORCE_INLINE_ int get_id() const { return id; }
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)=0; //do a step, return which sequence port to go out
+ 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) = 0; //do a step, return which sequence port to go out
- Ref<VisualScriptNode> get_base_node() { return Ref<VisualScriptNode>( base ); }
+ Ref<VisualScriptNode> get_base_node() { return Ref<VisualScriptNode>(base); }
VisualScriptNodeInstance();
virtual ~VisualScriptNodeInstance();
};
-
class VisualScript : public Script {
- GDCLASS( VisualScript, Script )
+ GDCLASS(VisualScript, Script)
RES_BASE_EXTENSION("vs");
public:
-
struct SequenceConnection {
union {
@@ -187,9 +183,9 @@ public:
uint64_t id;
};
- bool operator<(const SequenceConnection& p_connection) const {
+ bool operator<(const SequenceConnection &p_connection) const {
- return id<p_connection.id;
+ return id < p_connection.id;
}
};
@@ -206,15 +202,14 @@ public:
uint64_t id;
};
- bool operator<(const DataConnection& p_connection) const {
+ bool operator<(const DataConnection &p_connection) const {
- return id<p_connection.id;
+ return id < p_connection.id;
}
};
-
private:
-friend class VisualScriptInstance;
+ friend class VisualScriptInstance;
StringName base_type;
struct Argument {
@@ -228,7 +223,7 @@ friend class VisualScriptInstance;
Ref<VisualScriptNode> node;
};
- Map<int,NodeData> nodes;
+ Map<int, NodeData> nodes;
Set<SequenceConnection> sequence_connections;
@@ -238,9 +233,7 @@ friend class VisualScriptInstance;
Vector2 scroll;
-
- Function() { function_id=-1; }
-
+ Function() { function_id = -1; }
};
struct Variable {
@@ -249,109 +242,101 @@ friend class VisualScriptInstance;
bool _export;
};
+ Map<StringName, Function> functions;
+ Map<StringName, Variable> variables;
+ Map<StringName, Vector<Argument> > custom_signals;
-
- Map<StringName,Function> functions;
- Map<StringName,Variable> variables;
- Map<StringName,Vector<Argument> > custom_signals;
-
- Map<Object*,VisualScriptInstance*> instances;
+ Map<Object *, VisualScriptInstance *> instances;
#ifdef TOOLS_ENABLED
- Set<PlaceHolderScriptInstance*> placeholders;
+ Set<PlaceHolderScriptInstance *> placeholders;
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
void _update_placeholders();
#endif
- void _set_variable_info(const StringName& p_name,const Dictionary& p_info);
- Dictionary _get_variable_info(const StringName& p_name) const;
-
+ void _set_variable_info(const StringName &p_name, const Dictionary &p_info);
+ Dictionary _get_variable_info(const StringName &p_name) const;
- void _set_data(const Dictionary& p_data);
+ void _set_data(const Dictionary &p_data);
Dictionary _get_data() const;
protected:
-
void _node_ports_changed(int p_id);
static void _bind_methods();
-public:
-
- void add_function(const StringName& p_name);
- bool has_function(const StringName& p_name) const;
- void remove_function(const StringName& p_name);
- void rename_function(const StringName& p_name,const StringName& p_new_name);
- void set_function_scroll(const StringName& p_name, const Vector2& p_scroll);
- Vector2 get_function_scroll(const StringName& p_name) const;
+public:
+ void add_function(const StringName &p_name);
+ bool has_function(const StringName &p_name) const;
+ void remove_function(const StringName &p_name);
+ void rename_function(const StringName &p_name, const StringName &p_new_name);
+ void set_function_scroll(const StringName &p_name, const Vector2 &p_scroll);
+ Vector2 get_function_scroll(const StringName &p_name) const;
void get_function_list(List<StringName> *r_functions) const;
- int get_function_node_id(const StringName& p_name) const;
-
-
- void add_node(const StringName& p_func,int p_id,const Ref<VisualScriptNode>& p_node,const Point2& p_pos=Point2());
- void remove_node(const StringName& p_func,int p_id);
- bool has_node(const StringName& p_func,int p_id) const;
- Ref<VisualScriptNode> get_node(const StringName& p_func,int p_id) const;
- void set_node_pos(const StringName& p_func,int p_id,const Point2& p_pos);
- Point2 get_node_pos(const StringName& p_func,int p_id) const;
- void get_node_list(const StringName& p_func,List<int> *r_nodes) const;
-
- void sequence_connect(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node);
- void sequence_disconnect(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node);
- bool has_sequence_connection(const StringName& p_func,int p_from_node,int p_from_output,int p_to_node) const;
- void get_sequence_connection_list(const StringName& p_func,List<SequenceConnection> *r_connection) const;
-
- void data_connect(const StringName& p_func,int p_from_node,int p_from_port,int p_to_node,int p_to_port);
- 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;
-
- 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;
- void remove_variable(const StringName& p_name);
- void set_variable_default_value(const StringName& p_name,const Variant& p_value);
- Variant get_variable_default_value(const StringName& p_name) const;
- void set_variable_info(const StringName& p_name,const PropertyInfo& p_info);
- PropertyInfo get_variable_info(const StringName& p_name) const;
- void set_variable_export(const StringName& p_name,bool p_export);
- bool get_variable_export(const StringName& p_name) const;
+ int get_function_node_id(const StringName &p_name) const;
+
+ void add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos = Point2());
+ void remove_node(const StringName &p_func, int p_id);
+ bool has_node(const StringName &p_func, int p_id) const;
+ Ref<VisualScriptNode> get_node(const StringName &p_func, int p_id) const;
+ void set_node_pos(const StringName &p_func, int p_id, const Point2 &p_pos);
+ Point2 get_node_pos(const StringName &p_func, int p_id) const;
+ void get_node_list(const StringName &p_func, List<int> *r_nodes) const;
+
+ void sequence_connect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node);
+ void sequence_disconnect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node);
+ bool has_sequence_connection(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) const;
+ void get_sequence_connection_list(const StringName &p_func, List<SequenceConnection> *r_connection) const;
+
+ void data_connect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
+ 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;
+
+ 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;
+ void remove_variable(const StringName &p_name);
+ void set_variable_default_value(const StringName &p_name, const Variant &p_value);
+ Variant get_variable_default_value(const StringName &p_name) const;
+ void set_variable_info(const StringName &p_name, const PropertyInfo &p_info);
+ PropertyInfo get_variable_info(const StringName &p_name) const;
+ void set_variable_export(const StringName &p_name, bool p_export);
+ bool get_variable_export(const StringName &p_name) const;
void get_variable_list(List<StringName> *r_variables) const;
- void rename_variable(const StringName& p_name,const StringName& p_new_name);
-
-
- void add_custom_signal(const StringName& p_name);
- bool has_custom_signal(const StringName& p_name) const;
- void custom_signal_add_argument(const StringName& p_func,Variant::Type p_type,const String& p_name,int p_index=-1);
- void custom_signal_set_argument_type(const StringName& p_func,int p_argidx,Variant::Type p_type);
- Variant::Type custom_signal_get_argument_type(const StringName& p_func,int p_argidx) const;
- void custom_signal_set_argument_name(const StringName& p_func,int p_argidx,const String& p_name);
- String custom_signal_get_argument_name(const StringName& p_func,int p_argidx) const;
- void custom_signal_remove_argument(const StringName& p_func,int p_argidx);
- int custom_signal_get_argument_count(const StringName& p_func) const;
- void custom_signal_swap_argument(const StringName& p_func,int p_argidx,int p_with_argidx);
- void remove_custom_signal(const StringName& p_name);
- void rename_custom_signal(const StringName& p_name,const StringName& p_new_name);
+ void rename_variable(const StringName &p_name, const StringName &p_new_name);
+
+ void add_custom_signal(const StringName &p_name);
+ bool has_custom_signal(const StringName &p_name) const;
+ void custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index = -1);
+ void custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type);
+ Variant::Type custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const;
+ void custom_signal_set_argument_name(const StringName &p_func, int p_argidx, const String &p_name);
+ String custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const;
+ void custom_signal_remove_argument(const StringName &p_func, int p_argidx);
+ int custom_signal_get_argument_count(const StringName &p_func) const;
+ void custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx);
+ void remove_custom_signal(const StringName &p_name);
+ void rename_custom_signal(const StringName &p_name, const StringName &p_new_name);
void get_custom_signal_list(List<StringName> *r_custom_signals) const;
int get_available_id() const;
- void set_instance_base_type(const StringName& p_type);
+ void set_instance_base_type(const StringName &p_type);
virtual bool can_instance() const;
virtual Ref<Script> get_base_script() const;
virtual StringName get_instance_base_type() const;
- virtual ScriptInstance* instance_create(Object *p_this);
+ 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 void set_source_code(const String &p_code);
+ virtual Error reload(bool p_keep_state = false);
virtual bool is_tool() const;
@@ -359,14 +344,14 @@ public:
virtual ScriptLanguage *get_language() const;
- virtual bool has_script_signal(const StringName& p_signal) 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 bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
- virtual bool has_method(const StringName& p_method) const;
- virtual MethodInfo get_method_info(const StringName& p_method) const;
+ virtual bool has_method(const StringName &p_method) const;
+ virtual MethodInfo get_method_info(const StringName &p_method) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
@@ -378,13 +363,12 @@ public:
~VisualScript();
};
-
class VisualScriptInstance : public ScriptInstance {
Object *owner;
Ref<VisualScript> script;
- Map<StringName,Variant> variables; //using variable path, not script
- Map<int,VisualScriptNodeInstance*> instances;
+ Map<StringName, Variant> variables; //using variable path, not script
+ Map<int, VisualScriptNodeInstance *> instances;
struct Function {
int node;
@@ -398,50 +382,48 @@ class VisualScriptInstance : public ScriptInstance {
bool valid;
};
- Map<StringName,Function> functions;
+ Map<StringName, Function> functions;
Vector<Variant> default_values;
- int max_input_args,max_output_args;
+ int max_input_args, max_output_args;
StringName source;
- void _dependency_step(VisualScriptNodeInstance* node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Variant::CallError& r_error, String& error_str, VisualScriptNodeInstance **r_error_node);
- Variant _call_internal(const StringName& p_method, void* p_stack,int p_stack_size, VisualScriptNodeInstance* p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield,Variant::CallError &r_error);
-
+ void _dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Variant::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node);
+ Variant _call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Variant::CallError &r_error);
//Map<StringName,Function> functions;
-friend class VisualScriptFunctionState; //for yield
-friend class VisualScriptLanguage; //for debugger
+ friend class VisualScriptFunctionState; //for yield
+ friend class VisualScriptLanguage; //for debugger
public:
- virtual bool set(const StringName& p_name, const Variant& p_value);
- virtual bool get(const StringName& p_name, Variant &r_ret) const;
+ virtual bool set(const StringName &p_name, const Variant &p_value);
+ virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
- virtual Variant::Type get_property_type(const StringName& p_name,bool *r_is_valid=NULL) const;
+ virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
- virtual bool has_method(const StringName& p_method) const;
- virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
+ virtual 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);
- bool set_variable(const StringName& p_variable,const Variant& p_value) {
+ bool set_variable(const StringName &p_variable, const Variant &p_value) {
- Map<StringName,Variant>::Element *E=variables.find(p_variable);
+ Map<StringName, Variant>::Element *E = variables.find(p_variable);
if (!E)
return false;
- E->get()=p_value;
+ E->get() = p_value;
return true;
}
- bool get_variable(const StringName& p_variable,Variant* r_variable) const {
+ bool get_variable(const StringName &p_variable, Variant *r_variable) const {
- const Map<StringName,Variant>::Element *E=variables.find(p_variable);
+ const Map<StringName, Variant>::Element *E = variables.find(p_variable);
if (!E)
return false;
- *r_variable=E->get();
+ *r_variable = E->get();
return true;
-
}
virtual Ref<Script> get_script() const;
@@ -449,22 +431,21 @@ public:
_FORCE_INLINE_ VisualScript *get_script_ptr() { return script.ptr(); }
_FORCE_INLINE_ Object *get_owner_ptr() { return owner; }
- void create(const Ref<VisualScript>& p_script,Object *p_owner);
+ void create(const Ref<VisualScript> &p_script, Object *p_owner);
virtual ScriptLanguage *get_language();
- virtual RPCMode get_rpc_mode(const StringName& p_method) const;
- virtual RPCMode get_rset_mode(const StringName& p_variable) const;
+ virtual RPCMode get_rpc_mode(const StringName &p_method) const;
+ virtual RPCMode get_rset_mode(const StringName &p_variable) const;
VisualScriptInstance();
~VisualScriptInstance();
};
-
class VisualScriptFunctionState : public Reference {
- GDCLASS(VisualScriptFunctionState,Reference);
-friend class VisualScriptInstance;
+ GDCLASS(VisualScriptFunctionState, Reference);
+ friend class VisualScriptInstance;
ObjectID instance_id;
ObjectID script_id;
@@ -477,36 +458,34 @@ friend class VisualScriptInstance;
int flow_stack_pos;
int pass;
- Variant _signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
+ Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+
protected:
static void _bind_methods();
-public:
- void connect_to_signal(Object* p_obj,const String& p_signal,Array p_binds);
+public:
+ void connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds);
bool is_valid() const;
Variant resume(Array p_args);
VisualScriptFunctionState();
~VisualScriptFunctionState();
};
-
-typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String& p_type);
+typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String &p_type);
class VisualScriptLanguage : public ScriptLanguage {
- Map<String,VisualScriptNodeRegisterFunc> register_funcs;
+ Map<String, VisualScriptNodeRegisterFunc> register_funcs;
struct CallLevel {
- Variant *stack;
- Variant **work_mem;
- const StringName *function;
- VisualScriptInstance *instance;
- int *current_id;
-
+ Variant *stack;
+ Variant **work_mem;
+ const StringName *function;
+ VisualScriptInstance *instance;
+ int *current_id;
};
-
int _debug_parse_err_node;
String _debug_parse_err_file;
String _debug_error;
@@ -520,52 +499,52 @@ public:
StringName _step;
StringName _subcall;
- static VisualScriptLanguage* singleton;
+ static VisualScriptLanguage *singleton;
Mutex *lock;
- bool debug_break(const String& p_error,bool p_allow_continue=true);
- bool debug_break_parse(const String& p_file, int p_node,const String& p_error);
+ bool debug_break(const String &p_error, bool p_allow_continue = true);
+ bool debug_break_parse(const String &p_file, int p_node, const String &p_error);
- _FORCE_INLINE_ void enter_function(VisualScriptInstance *p_instance,const StringName* p_function, Variant *p_stack, Variant **p_work_mem,int *current_id) {
+ _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())
- return; //no support for other threads than main for now
+ 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)
- ScriptDebugger::get_singleton()->set_depth( ScriptDebugger::get_singleton()->get_depth() +1 );
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
+ ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1);
- if (_debug_call_stack_pos >= _debug_max_call_stack) {
- //stack overflow
- _debug_error="Stack Overflow (Stack Size: "+itos(_debug_max_call_stack)+")";
- ScriptDebugger::get_singleton()->debug(this);
- return;
- }
+ if (_debug_call_stack_pos >= _debug_max_call_stack) {
+ //stack overflow
+ _debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")";
+ ScriptDebugger::get_singleton()->debug(this);
+ return;
+ }
- _call_stack[_debug_call_stack_pos].stack=p_stack;
- _call_stack[_debug_call_stack_pos].instance=p_instance;
- _call_stack[_debug_call_stack_pos].function=p_function;
- _call_stack[_debug_call_stack_pos].work_mem=p_work_mem;
- _call_stack[_debug_call_stack_pos].current_id=current_id;
- _debug_call_stack_pos++;
+ _call_stack[_debug_call_stack_pos].stack = p_stack;
+ _call_stack[_debug_call_stack_pos].instance = p_instance;
+ _call_stack[_debug_call_stack_pos].function = p_function;
+ _call_stack[_debug_call_stack_pos].work_mem = p_work_mem;
+ _call_stack[_debug_call_stack_pos].current_id = current_id;
+ _debug_call_stack_pos++;
}
_FORCE_INLINE_ void exit_function() {
- if (Thread::get_main_ID()!=Thread::get_caller_ID())
- return; //no support for other threads than main for now
+ 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)
- ScriptDebugger::get_singleton()->set_depth( ScriptDebugger::get_singleton()->get_depth() -1 );
+ if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
+ ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1);
- if (_debug_call_stack_pos==0) {
+ if (_debug_call_stack_pos == 0) {
- _debug_error="Stack Underflow (Engine Bug)";
- ScriptDebugger::get_singleton()->debug(this);
- return;
- }
+ _debug_error = "Stack Underflow (Engine Bug)";
+ ScriptDebugger::get_singleton()->debug(this);
+ return;
+ }
- _debug_call_stack_pos--;
+ _debug_call_stack_pos--;
}
//////////////////////////////////////
@@ -576,22 +555,21 @@ public:
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
- virtual Error execute_file(const String& p_path) ;
+ virtual Error execute_file(const String &p_path);
virtual void finish();
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const;
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
- virtual Ref<Script> get_template(const String& p_class_name, const String& p_base_class_name) const;
- virtual bool validate(const String& p_script, int &r_line_error,int &r_col_error,String& r_test_error, const String& p_path="",List<String> *r_functions=NULL) const;
+ virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
+ virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
- virtual int find_function(const String& p_function,const String& p_code) const;
- virtual String make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const;
- virtual 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 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);
/* DEBUGGER FUNCTIONS */
@@ -600,45 +578,40 @@ public:
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
- virtual void debug_get_stack_level_locals(int p_level,List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual void debug_get_stack_level_members(int p_level,List<String> *p_members, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1);
- virtual String debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems=-1,int p_max_depth=-1);
-
+ virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
+ virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
virtual void reload_all_scripts();
- virtual void reload_tool_script(const Ref<Script>& p_script,bool p_soft_reload);
+ virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
/* LOADER FUNCTIONS */
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
- virtual void get_public_constants(List<Pair<String,Variant> > *p_constants) const;
+ 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);
+ 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);
- void add_register_func(const String& p_name,VisualScriptNodeRegisterFunc p_func);
- Ref<VisualScriptNode> create_node_from_name(const String& p_name);
+ void add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func);
+ Ref<VisualScriptNode> create_node_from_name(const String &p_name);
void get_registered_node_names(List<String> *r_names);
-
VisualScriptLanguage();
~VisualScriptLanguage();
-
};
//aid for registering
-template<class T>
-static Ref<VisualScriptNode> create_node_generic(const String& p_name) {
+template <class T>
+static Ref<VisualScriptNode> create_node_generic(const String &p_name) {
Ref<T> node;
node.instance();
return node;
}
-
-
#endif // VSCRIPT_H
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index e83cd3e614..378ca06f90 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -28,15 +28,15 @@
/*************************************************************************/
#include "visual_script_builtin_funcs.h"
-#include "math_funcs.h"
#include "class_db.h"
-#include "reference.h"
#include "func_ref.h"
+#include "io/marshalls.h"
+#include "math_funcs.h"
#include "os/os.h"
+#include "reference.h"
#include "variant_parser.h"
-#include "io/marshalls.h"
-const char* VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX]={
+const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX] = {
"sin",
"cos",
"tan",
@@ -96,10 +96,10 @@ const char* VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"color_named",
};
-VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String& p_string) {
+VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) {
- for(int i=0;i<FUNC_MAX;i++) {
- if (p_string==func_name[i])
+ for (int i = 0; i < FUNC_MAX; i++) {
+ if (p_string == func_name[i])
return BuiltinFunc(i);
}
@@ -108,19 +108,18 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(cons
String VisualScriptBuiltinFunc::get_func_name(BuiltinFunc p_func) {
- ERR_FAIL_INDEX_V(p_func,FUNC_MAX,String());
+ ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String());
return func_name[p_func];
}
-
int VisualScriptBuiltinFunc::get_output_sequence_port_count() const {
return has_input_sequence_port() ? 1 : 0;
}
-bool VisualScriptBuiltinFunc::has_input_sequence_port() const{
+bool VisualScriptBuiltinFunc::has_input_sequence_port() const {
- switch(func) {
+ switch (func) {
case MATH_RANDOMIZE:
case TEXT_PRINT:
@@ -129,15 +128,12 @@ bool VisualScriptBuiltinFunc::has_input_sequence_port() const{
return true;
default:
return false;
-
}
-
}
int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
-
- switch(p_func) {
+ switch (p_func) {
case MATH_RANDOMIZE:
case MATH_RAND:
@@ -200,19 +196,19 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_DECTIME:
case LOGIC_CLAMP:
return 3;
- case FUNC_MAX:{}
-
+ case FUNC_MAX: {
+ }
}
return 0;
}
-int VisualScriptBuiltinFunc::get_input_value_port_count() const{
+int VisualScriptBuiltinFunc::get_input_value_port_count() const {
return get_func_argument_count(func);
}
-int VisualScriptBuiltinFunc::get_output_value_port_count() const{
+int VisualScriptBuiltinFunc::get_output_value_port_count() const {
- switch(func) {
+ switch (func) {
case MATH_RANDOMIZE:
case TEXT_PRINT:
case TEXT_PRINTERR:
@@ -233,9 +229,9 @@ String VisualScriptBuiltinFunc::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const {
- switch(func) {
+ switch (func) {
case MATH_SIN:
case MATH_COS:
@@ -248,67 +244,67 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_ATAN:
case MATH_ATAN2:
case MATH_SQRT: {
- return PropertyInfo(Variant::REAL,"num");
+ return PropertyInfo(Variant::REAL, "num");
} break;
case MATH_FMOD:
case MATH_FPOSMOD: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"x");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "x");
else
- return PropertyInfo(Variant::REAL,"y");
+ return PropertyInfo(Variant::REAL, "y");
} break;
case MATH_FLOOR:
case MATH_CEIL:
case MATH_ROUND:
case MATH_ABS:
case MATH_SIGN: {
- return PropertyInfo(Variant::REAL,"num");
+ return PropertyInfo(Variant::REAL, "num");
} break;
case MATH_POW: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"x");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "x");
else
- return PropertyInfo(Variant::REAL,"y");
+ return PropertyInfo(Variant::REAL, "y");
} break;
case MATH_LOG:
case MATH_EXP:
case MATH_ISNAN:
case MATH_ISINF: {
- return PropertyInfo(Variant::REAL,"num");
+ return PropertyInfo(Variant::REAL, "num");
} break;
case MATH_EASE: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"s");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "s");
else
- return PropertyInfo(Variant::REAL,"curve");
+ return PropertyInfo(Variant::REAL, "curve");
} break;
case MATH_DECIMALS: {
- return PropertyInfo(Variant::REAL,"step");
+ return PropertyInfo(Variant::REAL, "step");
} break;
case MATH_STEPIFY: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"s");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "s");
else
- return PropertyInfo(Variant::REAL,"steps");
+ return PropertyInfo(Variant::REAL, "steps");
} break;
case MATH_LERP: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"from");
- else if (p_idx==1)
- return PropertyInfo(Variant::REAL,"to");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "from");
+ else if (p_idx == 1)
+ return PropertyInfo(Variant::REAL, "to");
else
- return PropertyInfo(Variant::REAL,"weight");
+ return PropertyInfo(Variant::REAL, "weight");
} break;
case MATH_DECTIME: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"value");
- else if (p_idx==1)
- return PropertyInfo(Variant::REAL,"amount");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "value");
+ else if (p_idx == 1)
+ return PropertyInfo(Variant::REAL, "amount");
else
- return PropertyInfo(Variant::REAL,"step");
+ return PropertyInfo(Variant::REAL, "step");
} break;
case MATH_RANDOMIZE: {
@@ -320,139 +316,140 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
} break;
case MATH_RANDOM: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"from");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "from");
else
- return PropertyInfo(Variant::REAL,"to");
+ return PropertyInfo(Variant::REAL, "to");
} break;
case MATH_SEED: {
- return PropertyInfo(Variant::INT,"seed");
+ return PropertyInfo(Variant::INT, "seed");
} break;
case MATH_RANDSEED: {
- return PropertyInfo(Variant::INT,"seed");
+ return PropertyInfo(Variant::INT, "seed");
} break;
case MATH_DEG2RAD: {
- return PropertyInfo(Variant::REAL,"deg");
+ return PropertyInfo(Variant::REAL, "deg");
} break;
case MATH_RAD2DEG: {
- return PropertyInfo(Variant::REAL,"rad");
+ return PropertyInfo(Variant::REAL, "rad");
} break;
case MATH_LINEAR2DB: {
- return PropertyInfo(Variant::REAL,"nrg");
+ return PropertyInfo(Variant::REAL, "nrg");
} break;
case MATH_DB2LINEAR: {
- return PropertyInfo(Variant::REAL,"db");
+ return PropertyInfo(Variant::REAL, "db");
} break;
case LOGIC_MAX: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"a");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "a");
else
- return PropertyInfo(Variant::REAL,"b");
+ return PropertyInfo(Variant::REAL, "b");
} break;
case LOGIC_MIN: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"a");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "a");
else
- return PropertyInfo(Variant::REAL,"b");
+ return PropertyInfo(Variant::REAL, "b");
} break;
case LOGIC_CLAMP: {
- if (p_idx==0)
- return PropertyInfo(Variant::REAL,"a");
- else if (p_idx==0) // FIXME: is it ok to test p_idx == 0 twice?
- return PropertyInfo(Variant::REAL,"min");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "a");
+ else if (p_idx == 0) // FIXME: is it ok to test p_idx == 0 twice?
+ return PropertyInfo(Variant::REAL, "min");
else
- return PropertyInfo(Variant::REAL,"max");
+ return PropertyInfo(Variant::REAL, "max");
} break;
case LOGIC_NEAREST_PO2: {
- return PropertyInfo(Variant::INT,"num");
+ return PropertyInfo(Variant::INT, "num");
} break;
case OBJ_WEAKREF: {
- return PropertyInfo(Variant::OBJECT,"source");
+ return PropertyInfo(Variant::OBJECT, "source");
} break;
case FUNC_FUNCREF: {
- if (p_idx==0)
- return PropertyInfo(Variant::OBJECT,"instance");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::OBJECT, "instance");
else
- return PropertyInfo(Variant::STRING,"funcname");
+ return PropertyInfo(Variant::STRING, "funcname");
} break;
case TYPE_CONVERT: {
- if (p_idx==0)
- return PropertyInfo(Variant::NIL,"what");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::NIL, "what");
else
- return PropertyInfo(Variant::STRING,"type");
+ return PropertyInfo(Variant::STRING, "type");
} break;
case TYPE_OF: {
- return PropertyInfo(Variant::NIL,"what");
+ return PropertyInfo(Variant::NIL, "what");
} break;
case TYPE_EXISTS: {
- return PropertyInfo(Variant::STRING,"type");
+ return PropertyInfo(Variant::STRING, "type");
} break;
case TEXT_CHAR: {
- return PropertyInfo(Variant::INT,"ascii");
+ return PropertyInfo(Variant::INT, "ascii");
} break;
case TEXT_STR: {
- return PropertyInfo(Variant::NIL,"value");
+ return PropertyInfo(Variant::NIL, "value");
} break;
case TEXT_PRINT: {
- return PropertyInfo(Variant::NIL,"value");
+ return PropertyInfo(Variant::NIL, "value");
} break;
case TEXT_PRINTERR: {
- return PropertyInfo(Variant::NIL,"value");
+ return PropertyInfo(Variant::NIL, "value");
} break;
case TEXT_PRINTRAW: {
- return PropertyInfo(Variant::NIL,"value");
+ return PropertyInfo(Variant::NIL, "value");
} break;
case VAR_TO_STR: {
- return PropertyInfo(Variant::NIL,"var");
+ return PropertyInfo(Variant::NIL, "var");
} break;
case STR_TO_VAR: {
- return PropertyInfo(Variant::STRING,"string");
+ return PropertyInfo(Variant::STRING, "string");
} break;
case VAR_TO_BYTES: {
- return PropertyInfo(Variant::NIL,"var");
+ return PropertyInfo(Variant::NIL, "var");
} break;
case BYTES_TO_VAR: {
- return PropertyInfo(Variant::POOL_BYTE_ARRAY,"bytes");
+ return PropertyInfo(Variant::POOL_BYTE_ARRAY, "bytes");
} break;
case COLORN: {
- if (p_idx==0)
- return PropertyInfo(Variant::STRING,"name");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::STRING, "name");
else
- return PropertyInfo(Variant::REAL,"alpha");
+ return PropertyInfo(Variant::REAL, "alpha");
} break;
- case FUNC_MAX:{}
+ case FUNC_MAX: {
+ }
}
return PropertyInfo();
}
-PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) const {
- Variant::Type t=Variant::NIL;
- switch(func) {
+ Variant::Type t = Variant::NIL;
+ switch (func) {
case MATH_SIN:
case MATH_COS:
@@ -469,36 +466,36 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_FPOSMOD:
case MATH_FLOOR:
case MATH_CEIL: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case MATH_ROUND: {
- t=Variant::INT;
+ t = Variant::INT;
} break;
case MATH_ABS: {
- t=Variant::NIL;
+ t = Variant::NIL;
} break;
case MATH_SIGN: {
- t=Variant::NIL;
+ t = Variant::NIL;
} break;
case MATH_POW:
case MATH_LOG:
case MATH_EXP: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case MATH_ISNAN:
case MATH_ISINF: {
- t=Variant::BOOL;
+ t = Variant::BOOL;
} break;
case MATH_EASE: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case MATH_DECIMALS: {
- t=Variant::INT;
+ t = Variant::INT;
} break;
case MATH_STEPIFY:
case MATH_LERP:
case MATH_DECTIME: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case MATH_RANDOMIZE: {
@@ -506,71 +503,67 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
} break;
case MATH_RAND: {
- t=Variant::INT;
+ t = Variant::INT;
} break;
case MATH_RANDF:
case MATH_RANDOM: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case MATH_SEED: {
} break;
case MATH_RANDSEED: {
- if (p_idx==0)
- return PropertyInfo(Variant::INT,"rnd");
+ if (p_idx == 0)
+ return PropertyInfo(Variant::INT, "rnd");
else
- return PropertyInfo(Variant::INT,"seed");
+ return PropertyInfo(Variant::INT, "seed");
} break;
case MATH_DEG2RAD:
case MATH_RAD2DEG:
case MATH_LINEAR2DB:
case MATH_DB2LINEAR: {
- t=Variant::REAL;
+ t = Variant::REAL;
} break;
case LOGIC_MAX:
case LOGIC_MIN:
case LOGIC_CLAMP: {
-
} break;
case LOGIC_NEAREST_PO2: {
- t=Variant::NIL;
+ t = Variant::NIL;
} break;
case OBJ_WEAKREF: {
- t=Variant::OBJECT;
+ t = Variant::OBJECT;
} break;
case FUNC_FUNCREF: {
- t=Variant::OBJECT;
+ t = Variant::OBJECT;
} break;
case TYPE_CONVERT: {
-
-
} break;
case TYPE_OF: {
- t=Variant::INT;
+ t = Variant::INT;
} break;
case TYPE_EXISTS: {
- t=Variant::BOOL;
+ t = Variant::BOOL;
} break;
case TEXT_CHAR:
case TEXT_STR: {
- t=Variant::STRING;
+ t = Variant::STRING;
} break;
case TEXT_PRINT: {
-
} break;
case TEXT_PRINTERR: {
@@ -579,26 +572,26 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
} break;
case VAR_TO_STR: {
- t=Variant::STRING;
+ t = Variant::STRING;
} break;
case STR_TO_VAR: {
} break;
case VAR_TO_BYTES: {
- t=Variant::POOL_BYTE_ARRAY;
+ t = Variant::POOL_BYTE_ARRAY;
} break;
case BYTES_TO_VAR: {
-
} break;
case COLORN: {
- t=Variant::COLOR;
+ t = Variant::COLOR;
} break;
- case FUNC_MAX:{}
+ case FUNC_MAX: {
+ }
}
- return PropertyInfo(t,"");
+ return PropertyInfo(t, "");
}
String VisualScriptBuiltinFunc::get_caption() const {
@@ -613,8 +606,8 @@ String VisualScriptBuiltinFunc::get_text() const {
void VisualScriptBuiltinFunc::set_func(BuiltinFunc p_which) {
- ERR_FAIL_INDEX(p_which,FUNC_MAX);
- func=p_which;
+ ERR_FAIL_INDEX(p_which, FUNC_MAX);
+ func = p_which;
_change_notify();
ports_changed_notify();
}
@@ -623,256 +616,252 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::get_func() {
return func;
}
-
-#define VALIDATE_ARG_NUM(m_arg) \
- if (!p_inputs[m_arg]->is_num()) {\
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\
- r_error.argument=m_arg;\
- r_error.expected=Variant::REAL;\
- return;\
+#define VALIDATE_ARG_NUM(m_arg) \
+ if (!p_inputs[m_arg]->is_num()) { \
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \
+ r_error.argument = m_arg; \
+ r_error.expected = Variant::REAL; \
+ return; \
}
+void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Variant::CallError &r_error, String &r_error_str) {
-void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inputs,Variant* r_return,Variant::CallError& r_error,String& r_error_str) {
-
- switch(p_func) {
+ switch (p_func) {
case VisualScriptBuiltinFunc::MATH_SIN: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::sin((double)*p_inputs[0]);
+ *r_return = Math::sin((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_COS: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::cos((double)*p_inputs[0]);
+ *r_return = Math::cos((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_TAN: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::tan((double)*p_inputs[0]);
+ *r_return = Math::tan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_SINH: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::sinh((double)*p_inputs[0]);
+ *r_return = Math::sinh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_COSH: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::cosh((double)*p_inputs[0]);
+ *r_return = Math::cosh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_TANH: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::tanh((double)*p_inputs[0]);
+ *r_return = Math::tanh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ASIN: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::asin((double)*p_inputs[0]);
+ *r_return = Math::asin((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ACOS: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::acos((double)*p_inputs[0]);
+ *r_return = Math::acos((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ATAN: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::atan((double)*p_inputs[0]);
+ *r_return = Math::atan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ATAN2: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::atan2((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_SQRT: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::sqrt((double)*p_inputs[0]);
+ *r_return = Math::sqrt((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_FMOD: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::fmod((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_FPOSMOD: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::fposmod((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_FLOOR: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::floor((double)*p_inputs[0]);
- } break;
+ *r_return = Math::floor((double)*p_inputs[0]);
+ } break;
case VisualScriptBuiltinFunc::MATH_CEIL: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::ceil((double)*p_inputs[0]);
+ *r_return = Math::ceil((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ROUND: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::round((double)*p_inputs[0]);
+ *r_return = Math::round((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ABS: {
- if (p_inputs[0]->get_type()==Variant::INT) {
+ if (p_inputs[0]->get_type() == Variant::INT) {
int64_t i = *p_inputs[0];
- *r_return=ABS(i);
- } else if (p_inputs[0]->get_type()==Variant::REAL) {
+ *r_return = ABS(i);
+ } else if (p_inputs[0]->get_type() == Variant::REAL) {
real_t r = *p_inputs[0];
- *r_return=Math::abs(r);
+ *r_return = Math::abs(r);
} else {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::REAL;
-
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::REAL;
}
} break;
case VisualScriptBuiltinFunc::MATH_SIGN: {
- if (p_inputs[0]->get_type()==Variant::INT) {
+ if (p_inputs[0]->get_type() == Variant::INT) {
- int64_t i = *p_inputs[0];
- *r_return= i < 0 ? -1 : ( i > 0 ? +1 : 0);
- } else if (p_inputs[0]->get_type()==Variant::REAL) {
-
- real_t r = *p_inputs[0];
- *r_return= r < 0.0 ? -1.0 : ( r > 0.0 ? +1.0 : 0.0);
- } else {
+ int64_t i = *p_inputs[0];
+ *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0);
+ } else if (p_inputs[0]->get_type() == Variant::REAL) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::REAL;
+ real_t r = *p_inputs[0];
+ *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0);
+ } else {
- }
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::REAL;
+ }
} break;
case VisualScriptBuiltinFunc::MATH_POW: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::pow((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_LOG: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::log((double)*p_inputs[0]);
+ *r_return = Math::log((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_EXP: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::exp((double)*p_inputs[0]);
+ *r_return = Math::exp((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ISNAN: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::is_nan((double)*p_inputs[0]);
+ *r_return = Math::is_nan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ISINF: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::is_inf((double)*p_inputs[0]);
+ *r_return = Math::is_inf((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_EASE: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::ease((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_DECIMALS: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::step_decimals((double)*p_inputs[0]);
+ *r_return = Math::step_decimals((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_STEPIFY: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::stepify((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_LERP: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- *r_return=Math::lerp((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]);
+ *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case VisualScriptBuiltinFunc::MATH_DECTIME: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
- *r_return=Math::dectime((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]);
+ *r_return = Math::dectime((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case VisualScriptBuiltinFunc::MATH_RANDOMIZE: {
Math::randomize();
} break;
case VisualScriptBuiltinFunc::MATH_RAND: {
- *r_return=Math::rand();
+ *r_return = Math::rand();
} break;
case VisualScriptBuiltinFunc::MATH_RANDF: {
- *r_return=Math::randf();
+ *r_return = Math::randf();
} break;
case VisualScriptBuiltinFunc::MATH_RANDOM: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return=Math::random((double)*p_inputs[0],(double)*p_inputs[1]);
+ *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_SEED: {
VALIDATE_ARG_NUM(0);
- uint64_t seed=*p_inputs[0];
+ uint64_t seed = *p_inputs[0];
Math::seed(seed);
} break;
case VisualScriptBuiltinFunc::MATH_RANDSEED: {
VALIDATE_ARG_NUM(0);
- uint64_t seed=*p_inputs[0];
+ uint64_t seed = *p_inputs[0];
int ret = Math::rand_from_seed(&seed);
Array reta;
reta.push_back(ret);
reta.push_back(seed);
- *r_return=reta;
+ *r_return = reta;
} break;
case VisualScriptBuiltinFunc::MATH_DEG2RAD: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::deg2rad((double)*p_inputs[0]);
+ *r_return = Math::deg2rad((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_RAD2DEG: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::rad2deg((double)*p_inputs[0]);
+ *r_return = Math::rad2deg((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_LINEAR2DB: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::linear2db((double)*p_inputs[0]);
+ *r_return = Math::linear2db((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_DB2LINEAR: {
VALIDATE_ARG_NUM(0);
- *r_return=Math::db2linear((double)*p_inputs[0]);
+ *r_return = Math::db2linear((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::LOGIC_MAX: {
- if (p_inputs[0]->get_type()==Variant::INT && p_inputs[1]->get_type()==Variant::INT) {
+ if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) {
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
- *r_return=MAX(a,b);
+ *r_return = MAX(a, b);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -880,17 +869,17 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
real_t a = *p_inputs[0];
real_t b = *p_inputs[1];
- *r_return=MAX(a,b);
+ *r_return = MAX(a, b);
}
} break;
case VisualScriptBuiltinFunc::LOGIC_MIN: {
- if (p_inputs[0]->get_type()==Variant::INT && p_inputs[1]->get_type()==Variant::INT) {
+ if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) {
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
- *r_return=MIN(a,b);
+ *r_return = MIN(a, b);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -898,17 +887,17 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
real_t a = *p_inputs[0];
real_t b = *p_inputs[1];
- *r_return=MIN(a,b);
+ *r_return = MIN(a, b);
}
} break;
case VisualScriptBuiltinFunc::LOGIC_CLAMP: {
- if (p_inputs[0]->get_type()==Variant::INT && p_inputs[1]->get_type()==Variant::INT && p_inputs[2]->get_type()==Variant::INT) {
+ if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) {
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
int64_t c = *p_inputs[2];
- *r_return=CLAMP(a,b,c);
+ *r_return = CLAMP(a, b, c);
} else {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -918,7 +907,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
real_t b = *p_inputs[1];
real_t c = *p_inputs[2];
- *r_return=CLAMP(a,b,c);
+ *r_return = CLAMP(a, b, c);
}
} break;
case VisualScriptBuiltinFunc::LOGIC_NEAREST_PO2: {
@@ -929,14 +918,13 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
} break;
case VisualScriptBuiltinFunc::OBJ_WEAKREF: {
- if (p_inputs[0]->get_type()!=Variant::OBJECT) {
+ if (p_inputs[0]->get_type() != Variant::OBJECT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
return;
-
}
if (p_inputs[0]->is_ref()) {
@@ -947,95 +935,87 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
return;
}
- Ref<WeakRef> wref = memnew( WeakRef );
+ Ref<WeakRef> wref = memnew(WeakRef);
wref->set_ref(r);
- *r_return=wref;
+ *r_return = wref;
} else {
Object *obj = *p_inputs[0];
if (!obj) {
return;
}
- Ref<WeakRef> wref = memnew( WeakRef );
+ Ref<WeakRef> wref = memnew(WeakRef);
wref->set_obj(obj);
- *r_return=wref;
+ *r_return = wref;
}
-
-
-
} break;
case VisualScriptBuiltinFunc::FUNC_FUNCREF: {
- if (p_inputs[0]->get_type()!=Variant::OBJECT) {
+ if (p_inputs[0]->get_type() != Variant::OBJECT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::OBJECT;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::OBJECT;
return;
-
}
- if (p_inputs[1]->get_type()!=Variant::STRING && p_inputs[1]->get_type()!=Variant::NODE_PATH) {
+ if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=1;
- r_error.expected=Variant::STRING;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 1;
+ r_error.expected = Variant::STRING;
return;
-
}
- Ref<FuncRef> fr = memnew( FuncRef);
+ Ref<FuncRef> fr = memnew(FuncRef);
fr->set_instance(*p_inputs[0]);
fr->set_function(*p_inputs[1]);
- *r_return=fr;
+ *r_return = fr;
} break;
case VisualScriptBuiltinFunc::TYPE_CONVERT: {
VALIDATE_ARG_NUM(1);
- int type=*p_inputs[1];
- if (type<0 || type>=Variant::VARIANT_MAX) {
+ int type = *p_inputs[1];
+ if (type < 0 || type >= Variant::VARIANT_MAX) {
- r_error_str=RTR("Invalid type argument to convert(), use TYPE_* constants.");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::INT;
+ r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::INT;
return;
} else {
-
- *r_return=Variant::construct(Variant::Type(type),p_inputs,1,r_error);
+ *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error);
}
} break;
case VisualScriptBuiltinFunc::TYPE_OF: {
-
*r_return = p_inputs[0]->get_type();
} break;
case VisualScriptBuiltinFunc::TYPE_EXISTS: {
-
*r_return = ClassDB::class_exists(*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::TEXT_CHAR: {
- CharType result[2] = {*p_inputs[0], 0};
-
- *r_return=String(result);
+ CharType result[2] = { *p_inputs[0], 0 };
+
+ *r_return = String(result);
} break;
case VisualScriptBuiltinFunc::TEXT_STR: {
String str = *p_inputs[0];
- *r_return=str;
+ *r_return = str;
} break;
case VisualScriptBuiltinFunc::TEXT_PRINT: {
@@ -1043,7 +1023,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
String str = *p_inputs[0];
print_line(str);
-
} break;
case VisualScriptBuiltinFunc::TEXT_PRINTERR: {
@@ -1051,98 +1030,93 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
String str = *p_inputs[0];
//str+="\n";
- OS::get_singleton()->printerr("%s\n",str.utf8().get_data());
-
+ OS::get_singleton()->printerr("%s\n", str.utf8().get_data());
} break;
case VisualScriptBuiltinFunc::TEXT_PRINTRAW: {
String str = *p_inputs[0];
//str+="\n";
- OS::get_singleton()->print("%s",str.utf8().get_data());
-
+ OS::get_singleton()->print("%s", str.utf8().get_data());
} break;
case VisualScriptBuiltinFunc::VAR_TO_STR: {
String vars;
- VariantWriter::write_to_string(*p_inputs[0],vars);
- *r_return=vars;
+ VariantWriter::write_to_string(*p_inputs[0], vars);
+ *r_return = vars;
} break;
case VisualScriptBuiltinFunc::STR_TO_VAR: {
- if (p_inputs[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
+ if (p_inputs[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
return;
}
VariantParser::StreamString ss;
- ss.s=*p_inputs[0];
+ ss.s = *p_inputs[0];
String errs;
int line;
- Error err = VariantParser::parse(&ss,*r_return,errs,line);
+ Error err = VariantParser::parse(&ss, *r_return, errs, line);
- if (err!=OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
- *r_return="Parse error at line "+itos(line)+": "+errs;
+ if (err != OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ *r_return = "Parse error at line " + itos(line) + ": " + errs;
return;
}
} break;
case VisualScriptBuiltinFunc::VAR_TO_BYTES: {
-
PoolByteArray barr;
int len;
- Error err = encode_variant(*p_inputs[0],NULL,len);
+ Error err = encode_variant(*p_inputs[0], NULL, len);
if (err) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::NIL;
- r_error_str="Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID).";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::NIL;
+ r_error_str = "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID).";
return;
}
barr.resize(len);
{
PoolByteArray::Write w = barr.write();
- encode_variant(*p_inputs[0],w.ptr(),len);
-
+ encode_variant(*p_inputs[0], w.ptr(), len);
}
- *r_return=barr;
+ *r_return = barr;
} break;
case VisualScriptBuiltinFunc::BYTES_TO_VAR: {
- if (p_inputs[0]->get_type()!=Variant::POOL_BYTE_ARRAY) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::POOL_BYTE_ARRAY;
+ if (p_inputs[0]->get_type() != Variant::POOL_BYTE_ARRAY) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::POOL_BYTE_ARRAY;
return;
}
- PoolByteArray varr=*p_inputs[0];
+ PoolByteArray varr = *p_inputs[0];
Variant ret;
{
- PoolByteArray::Read r=varr.read();
- Error err = decode_variant(ret,r.ptr(),varr.size(),NULL);
- if (err!=OK) {
- r_error_str=RTR("Not enough bytes for decoding bytes, or invalid format.");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::POOL_BYTE_ARRAY;
+ PoolByteArray::Read r = varr.read();
+ Error err = decode_variant(ret, r.ptr(), varr.size(), NULL);
+ if (err != OK) {
+ r_error_str = RTR("Not enough bytes for decoding bytes, or invalid format.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::POOL_BYTE_ARRAY;
return;
}
-
}
- *r_return=ret;
+ *r_return = ret;
} break;
case VisualScriptBuiltinFunc::COLORN: {
@@ -1150,72 +1124,65 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
VALIDATE_ARG_NUM(1);
Color color = Color::named(*p_inputs[0]);
- color.a=*p_inputs[1];
-
- *r_return=String(color);
+ color.a = *p_inputs[1];
+
+ *r_return = String(color);
} break;
default: {}
}
-
}
-
class VisualScriptNodeInstanceBuiltinFunc : public VisualScriptNodeInstance {
public:
-
VisualScriptBuiltinFunc *node;
VisualScriptInstance *instance;
VisualScriptBuiltinFunc::BuiltinFunc func;
-
//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; }
- 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) {
+ 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) {
- VisualScriptBuiltinFunc::exec_func(func,p_inputs,p_outputs[0],r_error,r_error_str);
+ VisualScriptBuiltinFunc::exec_func(func, p_inputs, p_outputs[0], r_error, r_error_str);
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptBuiltinFunc::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceBuiltinFunc * instance = memnew(VisualScriptNodeInstanceBuiltinFunc );
- instance->node=this;
- instance->instance=p_instance;
- instance->func=func;
+ VisualScriptNodeInstanceBuiltinFunc *instance = memnew(VisualScriptNodeInstanceBuiltinFunc);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->func = func;
return instance;
}
-
void VisualScriptBuiltinFunc::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_func","which"),&VisualScriptBuiltinFunc::set_func);
- ClassDB::bind_method(D_METHOD("get_func"),&VisualScriptBuiltinFunc::get_func);
+ ClassDB::bind_method(D_METHOD("set_func", "which"), &VisualScriptBuiltinFunc::set_func);
+ ClassDB::bind_method(D_METHOD("get_func"), &VisualScriptBuiltinFunc::get_func);
String cc;
- for(int i=0;i<FUNC_MAX;i++) {
+ for (int i = 0; i < FUNC_MAX; i++) {
- if (i>0)
- cc+=",";
- cc+=func_name[i];
+ if (i > 0)
+ cc += ",";
+ cc += func_name[i];
}
- ADD_PROPERTY(PropertyInfo(Variant::INT,"function",PROPERTY_HINT_ENUM,cc),"set_func","get_func");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, cc), "set_func", "get_func");
}
VisualScriptBuiltinFunc::VisualScriptBuiltinFunc() {
- func=MATH_SIN;
+ func = MATH_SIN;
}
-template<VisualScriptBuiltinFunc::BuiltinFunc func>
-static Ref<VisualScriptNode> create_builtin_func_node(const String& p_name) {
+template <VisualScriptBuiltinFunc::BuiltinFunc func>
+static Ref<VisualScriptNode> create_builtin_func_node(const String &p_name) {
Ref<VisualScriptBuiltinFunc> node;
node.instance();
@@ -1225,69 +1192,67 @@ static Ref<VisualScriptNode> create_builtin_func_node(const String& p_name) {
void register_visual_script_builtin_func_node() {
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/sin",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/cos",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COS>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/tan",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TAN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/sinh",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SINH>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/cosh",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COSH>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/tanh",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TANH>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/asin",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ASIN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/acos",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ACOS>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/atan",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ATAN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/atan2",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ATAN2>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/sqrt",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SQRT>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/fmod",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FMOD>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/fposmod",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FPOSMOD>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/floor",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FLOOR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/ceil",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CEIL>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/round",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ROUND>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/abs",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ABS>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/sign",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIGN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/pow",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POW>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/log",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LOG>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/exp",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_EXP>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/isnan",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ISNAN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/isinf",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ISINF>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/ease",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_EASE>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/decimals",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECIMALS>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/stepify",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_STEPIFY>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/lerp",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LERP>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/dectime",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECTIME>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/randomize",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOMIZE>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/rand",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAND>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/randf",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDF>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/random",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOM>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/seed",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SEED>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/randseed",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDSEED>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/deg2rad",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DEG2RAD>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear",create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/max",create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MAX>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/min",create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MIN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/clamp",create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_CLAMP>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/nearest_po2",create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_NEAREST_PO2>);
-
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/weakref",create_builtin_func_node<VisualScriptBuiltinFunc::OBJ_WEAKREF>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/funcref",create_builtin_func_node<VisualScriptBuiltinFunc::FUNC_FUNCREF>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/convert",create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_CONVERT>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/typeof",create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_OF>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/type_exists",create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_EXISTS>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/char",create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_CHAR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/str",create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_STR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/print",create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr",create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/printraw",create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTRAW>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2str",create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_STR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/str2var",create_builtin_func_node<VisualScriptBuiltinFunc::STR_TO_VAR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2bytes",create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_BYTES>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/bytes2var",create_builtin_func_node<VisualScriptBuiltinFunc::BYTES_TO_VAR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/color_named",create_builtin_func_node<VisualScriptBuiltinFunc::COLORN>);
-
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/sin", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/cos", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COS>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/tan", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TAN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/sinh", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SINH>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/cosh", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COSH>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/tanh", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TANH>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/asin", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ASIN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/acos", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ACOS>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/atan", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ATAN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/atan2", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ATAN2>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/sqrt", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SQRT>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/fmod", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FMOD>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/fposmod", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FPOSMOD>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/floor", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_FLOOR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/ceil", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CEIL>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/round", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ROUND>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/abs", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ABS>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/sign", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIGN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/pow", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POW>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/log", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LOG>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/exp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_EXP>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/isnan", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ISNAN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/isinf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_ISINF>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/ease", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_EASE>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/decimals", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECIMALS>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/stepify", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_STEPIFY>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LERP>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/dectime", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECTIME>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/randomize", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOMIZE>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/rand", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAND>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/randf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/random", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOM>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/seed", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SEED>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/randseed", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDSEED>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/deg2rad", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DEG2RAD>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/max", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MAX>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/min", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MIN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/clamp", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_CLAMP>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/nearest_po2", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_NEAREST_PO2>);
+
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/weakref", create_builtin_func_node<VisualScriptBuiltinFunc::OBJ_WEAKREF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/funcref", create_builtin_func_node<VisualScriptBuiltinFunc::FUNC_FUNCREF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/convert", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_CONVERT>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/typeof", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_OF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/type_exists", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_EXISTS>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/char", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_CHAR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/str", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_STR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/printraw", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTRAW>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2str", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_STR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/str2var", create_builtin_func_node<VisualScriptBuiltinFunc::STR_TO_VAR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2bytes", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_BYTES>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/bytes2var", create_builtin_func_node<VisualScriptBuiltinFunc::BYTES_TO_VAR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/color_named", create_builtin_func_node<VisualScriptBuiltinFunc::COLORN>);
}
diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h
index 75bea4b1b5..7246239513 100644
--- a/modules/visual_script/visual_script_builtin_funcs.h
+++ b/modules/visual_script/visual_script_builtin_funcs.h
@@ -31,12 +31,10 @@
#include "visual_script.h"
-
class VisualScriptBuiltinFunc : public VisualScriptNode {
- GDCLASS(VisualScriptBuiltinFunc,VisualScriptNode)
+ GDCLASS(VisualScriptBuiltinFunc, VisualScriptNode)
public:
-
enum BuiltinFunc {
MATH_SIN,
MATH_COS,
@@ -100,27 +98,25 @@ public:
static int get_func_argument_count(BuiltinFunc p_func);
static String get_func_name(BuiltinFunc p_func);
- static void exec_func(BuiltinFunc p_func, const Variant** p_inputs, Variant* r_return, Variant::CallError& r_error, String& r_error_str);
- static BuiltinFunc find_function(const String& p_string);
+ static void exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Variant::CallError &r_error, String &r_error_str);
+ static BuiltinFunc find_function(const String &p_string);
private:
- static const char* func_name[FUNC_MAX];
+ static const char *func_name[FUNC_MAX];
BuiltinFunc func;
+
protected:
static void _bind_methods();
-public:
+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;
@@ -131,15 +127,13 @@ public:
void set_func(BuiltinFunc p_which);
BuiltinFunc get_func();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptBuiltinFunc();
};
VARIANT_ENUM_CAST(VisualScriptBuiltinFunc::BuiltinFunc)
-
void register_visual_script_builtin_func_node();
-
#endif // VISUAL_SCRIPT_BUILTIN_FUNCS_H
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 7dd7059c31..5b1b496f72 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -29,29 +29,28 @@
#include "visual_script_editor.h"
#include "editor/editor_node.h"
-#include "visual_script_nodes.h"
-#include "visual_script_flow_control.h"
-#include "visual_script_func_nodes.h"
-#include "visual_script_expression.h"
-#include "os/input.h"
#include "editor/editor_resource_preview.h"
+#include "os/input.h"
#include "os/keyboard.h"
+#include "visual_script_expression.h"
+#include "visual_script_flow_control.h"
+#include "visual_script_func_nodes.h"
+#include "visual_script_nodes.h"
#ifdef TOOLS_ENABLED
class VisualScriptEditorSignalEdit : public Object {
- GDCLASS(VisualScriptEditorSignalEdit,Object)
+ GDCLASS(VisualScriptEditorSignalEdit, Object)
StringName sig;
+
public:
UndoRedo *undo_redo;
Ref<VisualScript> script;
-
protected:
-
static void _bind_methods() {
- ClassDB::bind_method("_sig_changed",&VisualScriptEditorSignalEdit::_sig_changed);
+ ClassDB::bind_method("_sig_changed", &VisualScriptEditorSignalEdit::_sig_changed);
}
void _sig_changed() {
@@ -59,149 +58,138 @@ protected:
_change_notify();
}
- bool _set(const StringName& p_name, const Variant& p_value) {
+ bool _set(const StringName &p_name, const Variant &p_value) {
- if (sig==StringName())
+ if (sig == StringName())
return false;
- if (p_name=="argument_count") {
+ if (p_name == "argument_count") {
- int new_argc=p_value;
+ int new_argc = p_value;
int argc = script->custom_signal_get_argument_count(sig);
- if (argc==new_argc)
+ if (argc == new_argc)
return true;
undo_redo->create_action("Change Signal Arguments");
-
-
if (new_argc < argc) {
- for(int i=new_argc;i<argc;i++) {
- undo_redo->add_do_method(script.ptr(),"custom_signal_remove_argument",sig,new_argc);
- undo_redo->add_undo_method(script.ptr(),"custom_signal_add_argument",sig,script->custom_signal_get_argument_name(sig,i),script->custom_signal_get_argument_type(sig,i),-1);
+ for (int i = new_argc; i < argc; i++) {
+ undo_redo->add_do_method(script.ptr(), "custom_signal_remove_argument", sig, new_argc);
+ undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1);
}
- } else if (new_argc>argc) {
+ } else if (new_argc > argc) {
- for(int i=argc;i<new_argc;i++) {
+ for (int i = argc; i < new_argc; i++) {
- undo_redo->add_do_method(script.ptr(),"custom_signal_add_argument",sig,Variant::NIL,"arg"+itos(i+1),-1);
- undo_redo->add_undo_method(script.ptr(),"custom_signal_remove_argument",sig,argc);
+ undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1);
+ undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc);
}
}
- undo_redo->add_do_method(this,"_sig_changed");
- undo_redo->add_undo_method(this,"_sig_changed");
+ undo_redo->add_do_method(this, "_sig_changed");
+ undo_redo->add_undo_method(this, "_sig_changed");
undo_redo->commit_action();
return true;
}
if (String(p_name).begins_with("argument/")) {
- int idx = String(p_name).get_slice("/",1).to_int()-1;
- ERR_FAIL_INDEX_V(idx,script->custom_signal_get_argument_count(sig),false);
- String what = String(p_name).get_slice("/",2);
- if (what=="type") {
+ int idx = String(p_name).get_slice("/", 1).to_int() - 1;
+ ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false);
+ String what = String(p_name).get_slice("/", 2);
+ if (what == "type") {
- int old_type = script->custom_signal_get_argument_type(sig,idx);
- int new_type=p_value;
+ int old_type = script->custom_signal_get_argument_type(sig, idx);
+ int new_type = p_value;
undo_redo->create_action("Change Argument Type");
- undo_redo->add_do_method(script.ptr(),"custom_signal_set_argument_type",sig,idx,new_type);
- undo_redo->add_undo_method(script.ptr(),"custom_signal_set_argument_type",sig,idx,old_type);
+ undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, new_type);
+ undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, old_type);
undo_redo->commit_action();
return true;
}
- if (what=="name") {
+ if (what == "name") {
- String old_name = script->custom_signal_get_argument_name(sig,idx);
- String new_name=p_value;
+ String old_name = script->custom_signal_get_argument_name(sig, idx);
+ String new_name = p_value;
undo_redo->create_action("Change Argument name");
- undo_redo->add_do_method(script.ptr(),"custom_signal_set_argument_name",sig,idx,new_name);
- undo_redo->add_undo_method(script.ptr(),"custom_signal_set_argument_name",sig,idx,old_name);
+ undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, new_name);
+ undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, old_name);
undo_redo->commit_action();
return true;
}
-
-
}
-
return false;
}
- bool _get(const StringName& p_name,Variant &r_ret) const {
+ bool _get(const StringName &p_name, Variant &r_ret) const {
- if (sig==StringName())
+ if (sig == StringName())
return false;
- if (p_name=="argument_count") {
+ if (p_name == "argument_count") {
r_ret = script->custom_signal_get_argument_count(sig);
return true;
}
if (String(p_name).begins_with("argument/")) {
- int idx = String(p_name).get_slice("/",1).to_int()-1;
- ERR_FAIL_INDEX_V(idx,script->custom_signal_get_argument_count(sig),false);
- String what = String(p_name).get_slice("/",2);
- if (what=="type") {
- r_ret = script->custom_signal_get_argument_type(sig,idx);
+ int idx = String(p_name).get_slice("/", 1).to_int() - 1;
+ ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false);
+ String what = String(p_name).get_slice("/", 2);
+ if (what == "type") {
+ r_ret = script->custom_signal_get_argument_type(sig, idx);
return true;
}
- if (what=="name") {
- r_ret = script->custom_signal_get_argument_name(sig,idx);
+ if (what == "name") {
+ r_ret = script->custom_signal_get_argument_name(sig, idx);
return true;
}
-
-
-
}
return false;
}
- void _get_property_list( List<PropertyInfo> *p_list) const {
+ void _get_property_list(List<PropertyInfo> *p_list) const {
- if (sig==StringName())
+ if (sig == StringName())
return;
- p_list->push_back(PropertyInfo(Variant::INT,"argument_count",PROPERTY_HINT_RANGE,"0,256"));
- String argt="Variant";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256"));
+ String argt = "Variant";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- for(int i=0;i<script->custom_signal_get_argument_count(sig);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"));
+ for (int i = 0; i < script->custom_signal_get_argument_count(sig); 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"));
}
}
public:
+ void edit(const StringName &p_sig) {
-
- void edit(const StringName& p_sig) {
-
- sig=p_sig;
+ sig = p_sig;
_change_notify();
}
- VisualScriptEditorSignalEdit() { undo_redo=NULL; }
+ VisualScriptEditorSignalEdit() { undo_redo = NULL; }
};
class VisualScriptEditorVariableEdit : public Object {
- GDCLASS(VisualScriptEditorVariableEdit,Object)
+ GDCLASS(VisualScriptEditorVariableEdit, Object)
StringName var;
+
public:
UndoRedo *undo_redo;
Ref<VisualScript> script;
-
protected:
-
static void _bind_methods() {
- ClassDB::bind_method("_var_changed",&VisualScriptEditorVariableEdit::_var_changed);
- ClassDB::bind_method("_var_value_changed",&VisualScriptEditorVariableEdit::_var_value_changed);
+ ClassDB::bind_method("_var_changed", &VisualScriptEditorVariableEdit::_var_changed);
+ ClassDB::bind_method("_var_value_changed", &VisualScriptEditorVariableEdit::_var_value_changed);
}
void _var_changed() {
@@ -213,138 +201,132 @@ protected:
_change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general
}
- bool _set(const StringName& p_name, const Variant& p_value) {
+ bool _set(const StringName &p_name, const Variant &p_value) {
- if (var==StringName())
+ if (var == StringName())
return false;
-
-
- if (String(p_name)=="value") {
+ if (String(p_name) == "value") {
undo_redo->create_action("Set Variable Default Value");
- Variant current=script->get_variable_default_value(var);
- undo_redo->add_do_method(script.ptr(),"set_variable_default_value",var,p_value);
- undo_redo->add_undo_method(script.ptr(),"set_variable_default_value",var,current);
- undo_redo->add_do_method(this,"_var_value_changed");
- undo_redo->add_undo_method(this,"_var_value_changed");
+ Variant current = script->get_variable_default_value(var);
+ undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, p_value);
+ undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, current);
+ undo_redo->add_do_method(this, "_var_value_changed");
+ undo_redo->add_undo_method(this, "_var_value_changed");
undo_redo->commit_action();
return true;
}
- Dictionary d = script->call("get_variable_info",var);
+ Dictionary d = script->call("get_variable_info", var);
- if (String(p_name)=="type") {
+ if (String(p_name) == "type") {
- Dictionary dc=d.copy();
- dc["type"]=p_value;
+ Dictionary dc = d.copy();
+ dc["type"] = p_value;
undo_redo->create_action("Set Variable Type");
- undo_redo->add_do_method(script.ptr(),"set_variable_info",var,dc);
- undo_redo->add_undo_method(script.ptr(),"set_variable_info",var,d);
- undo_redo->add_do_method(this,"_var_changed");
- undo_redo->add_undo_method(this,"_var_changed");
+ undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
+ undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
+ undo_redo->add_do_method(this, "_var_changed");
+ undo_redo->add_undo_method(this, "_var_changed");
undo_redo->commit_action();
return true;
}
- if (String(p_name)=="hint") {
+ if (String(p_name) == "hint") {
- Dictionary dc=d.copy();
- dc["hint"]=p_value;
+ Dictionary dc = d.copy();
+ dc["hint"] = p_value;
undo_redo->create_action("Set Variable Type");
- undo_redo->add_do_method(script.ptr(),"set_variable_info",var,dc);
- undo_redo->add_undo_method(script.ptr(),"set_variable_info",var,d);
- undo_redo->add_do_method(this,"_var_changed");
- undo_redo->add_undo_method(this,"_var_changed");
+ undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
+ undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
+ undo_redo->add_do_method(this, "_var_changed");
+ undo_redo->add_undo_method(this, "_var_changed");
undo_redo->commit_action();
return true;
}
- if (String(p_name)=="hint_string") {
+ if (String(p_name) == "hint_string") {
- Dictionary dc=d.copy();
- dc["hint_string"]=p_value;
+ Dictionary dc = d.copy();
+ dc["hint_string"] = p_value;
undo_redo->create_action("Set Variable Type");
- undo_redo->add_do_method(script.ptr(),"set_variable_info",var,dc);
- undo_redo->add_undo_method(script.ptr(),"set_variable_info",var,d);
- undo_redo->add_do_method(this,"_var_changed");
- undo_redo->add_undo_method(this,"_var_changed");
+ undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
+ undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
+ undo_redo->add_do_method(this, "_var_changed");
+ undo_redo->add_undo_method(this, "_var_changed");
undo_redo->commit_action();
return true;
}
- if (String(p_name)=="export") {
- script->set_variable_export(var,p_value);
+ if (String(p_name) == "export") {
+ script->set_variable_export(var, p_value);
return true;
}
-
return false;
}
- bool _get(const StringName& p_name,Variant &r_ret) const {
+ bool _get(const StringName &p_name, Variant &r_ret) const {
- if (var==StringName())
+ if (var == StringName())
return false;
- if (String(p_name)=="value") {
- r_ret=script->get_variable_default_value(var);
+ if (String(p_name) == "value") {
+ r_ret = script->get_variable_default_value(var);
return true;
}
PropertyInfo pinfo = script->get_variable_info(var);
- if (String(p_name)=="type") {
- r_ret=pinfo.type;
+ if (String(p_name) == "type") {
+ r_ret = pinfo.type;
return true;
}
- if (String(p_name)=="hint") {
- r_ret=pinfo.hint;
+ if (String(p_name) == "hint") {
+ r_ret = pinfo.hint;
return true;
}
- if (String(p_name)=="hint_string") {
- r_ret=pinfo.hint_string;
+ if (String(p_name) == "hint_string") {
+ r_ret = pinfo.hint_string;
return true;
}
- if (String(p_name)=="export") {
- r_ret=script->get_variable_export(var);
+ if (String(p_name) == "export") {
+ r_ret = script->get_variable_export(var);
return true;
}
return false;
}
- void _get_property_list( List<PropertyInfo> *p_list) const {
+ void _get_property_list(List<PropertyInfo> *p_list) const {
- if (var==StringName())
+ if (var == StringName())
return;
- String argt="Variant";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Variant";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- p_list->push_back(PropertyInfo(Variant::INT,"type",PROPERTY_HINT_ENUM,argt));
- p_list->push_back(PropertyInfo(script->get_variable_info(var).type,"value",script->get_variable_info(var).hint,script->get_variable_info(var).hint_string,PROPERTY_USAGE_DEFAULT));
- p_list->push_back(PropertyInfo(Variant::INT,"hint",PROPERTY_HINT_ENUM,"None,Range,ExpRange,Enum,ExpEasing,Length,SpriteFrame,KeyAccel,BitFlags,AllFlags,File,Dir,GlobalFile,GlobalDir,ResourceType,MultilineText"));
- p_list->push_back(PropertyInfo(Variant::STRING,"hint_string"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"export"));
-
+ p_list->push_back(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt));
+ p_list->push_back(PropertyInfo(script->get_variable_info(var).type, "value", script->get_variable_info(var).hint, script->get_variable_info(var).hint_string, PROPERTY_USAGE_DEFAULT));
+ p_list->push_back(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,ExpRange,Enum,ExpEasing,Length,SpriteFrame,KeyAccel,BitFlags,AllFlags,File,Dir,GlobalFile,GlobalDir,ResourceType,MultilineText"));
+ p_list->push_back(PropertyInfo(Variant::STRING, "hint_string"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "export"));
}
public:
+ void edit(const StringName &p_var) {
-
- void edit(const StringName& p_var) {
-
- var=p_var;
+ var = p_var;
_change_notify();
}
- VisualScriptEditorVariableEdit() { undo_redo=NULL; }
+ VisualScriptEditorVariableEdit() { undo_redo = NULL; }
};
static Color _color_from_type(Variant::Type p_type) {
Color color;
- switch(p_type) {
+ switch (p_type) {
case Variant::NIL: color = Color::html("69ecbd"); break;
case Variant::BOOL: color = Color::html("8da6f0"); break;
@@ -380,66 +362,60 @@ static Color _color_from_type(Variant::Type p_type) {
case Variant::POOL_COLOR_ARRAY: color = Color::html("e9ff97"); break;
default:
- color.set_hsv(p_type/float(Variant::VARIANT_MAX),0.7,0.7);
+ color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7);
}
return color;
}
-
-
void VisualScriptEditor::_update_graph_connections() {
graph->clear_connections();
List<VisualScript::SequenceConnection> sequence_conns;
- script->get_sequence_connection_list(edited_func,&sequence_conns);
+ script->get_sequence_connection_list(edited_func, &sequence_conns);
+ for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- for (List<VisualScript::SequenceConnection>::Element *E=sequence_conns.front();E;E=E->next()) {
-
- graph->connect_node(itos(E->get().from_node),E->get().from_output,itos(E->get().to_node),0);
+ graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0);
}
List<VisualScript::DataConnection> data_conns;
- script->get_data_connection_list(edited_func,&data_conns);
-
- for (List<VisualScript::DataConnection>::Element *E=data_conns.front();E;E=E->next()) {
+ script->get_data_connection_list(edited_func, &data_conns);
- VisualScript::DataConnection dc=E->get();
+ for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
+ VisualScript::DataConnection dc = E->get();
- Ref<VisualScriptNode> from_node = script->get_node(edited_func,E->get().from_node);
- Ref<VisualScriptNode> to_node = script->get_node(edited_func,E->get().to_node);
+ Ref<VisualScriptNode> from_node = script->get_node(edited_func, E->get().from_node);
+ Ref<VisualScriptNode> to_node = script->get_node(edited_func, E->get().to_node);
if (to_node->has_input_sequence_port()) {
dc.to_port++;
}
- dc.from_port+=from_node->get_output_sequence_port_count();
+ dc.from_port += from_node->get_output_sequence_port_count();
- graph->connect_node(itos(E->get().from_node),dc.from_port,itos(E->get().to_node),dc.to_port);
+ graph->connect_node(itos(E->get().from_node), dc.from_port, itos(E->get().to_node), dc.to_port);
}
-
}
-
void VisualScriptEditor::_update_graph(int p_only_id) {
if (updating_graph)
return;
- updating_graph=true;
+ updating_graph = true;
//byebye all nodes
- if (p_only_id>=0) {
+ if (p_only_id >= 0) {
if (graph->has_node(itos(p_only_id))) {
- Node* gid = graph->get_node(itos(p_only_id));
+ Node *gid = graph->get_node(itos(p_only_id));
if (gid)
memdelete(gid);
}
} else {
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
if (graph->get_child(i)->cast_to<GraphNode>()) {
memdelete(graph->get_child(i));
@@ -451,172 +427,160 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
if (!script->has_function(edited_func)) {
graph->hide();
select_func_text->show();
- updating_graph=false;
+ updating_graph = false;
return;
}
graph->show();
select_func_text->hide();
- Ref<Texture> type_icons[Variant::VARIANT_MAX]={
- Control::get_icon("MiniVariant","EditorIcons"),
- Control::get_icon("MiniBoolean","EditorIcons"),
- Control::get_icon("MiniInteger","EditorIcons"),
- Control::get_icon("MiniFloat","EditorIcons"),
- Control::get_icon("MiniString","EditorIcons"),
- Control::get_icon("MiniVector2","EditorIcons"),
- Control::get_icon("MiniRect2","EditorIcons"),
- Control::get_icon("MiniVector3","EditorIcons"),
- Control::get_icon("MiniTransform2D","EditorIcons"),
- Control::get_icon("MiniPlane","EditorIcons"),
- Control::get_icon("MiniQuat","EditorIcons"),
- Control::get_icon("MiniAabb","EditorIcons"),
- 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"),
- Control::get_icon("MiniIntArray","EditorIcons"),
- Control::get_icon("MiniFloatArray","EditorIcons"),
- Control::get_icon("MiniStringArray","EditorIcons"),
- Control::get_icon("MiniVector2Array","EditorIcons"),
- Control::get_icon("MiniVector3Array","EditorIcons"),
- Control::get_icon("MiniColorArray","EditorIcons")
+ Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
+ Control::get_icon("MiniVariant", "EditorIcons"),
+ Control::get_icon("MiniBoolean", "EditorIcons"),
+ Control::get_icon("MiniInteger", "EditorIcons"),
+ Control::get_icon("MiniFloat", "EditorIcons"),
+ Control::get_icon("MiniString", "EditorIcons"),
+ Control::get_icon("MiniVector2", "EditorIcons"),
+ Control::get_icon("MiniRect2", "EditorIcons"),
+ Control::get_icon("MiniVector3", "EditorIcons"),
+ Control::get_icon("MiniTransform2D", "EditorIcons"),
+ Control::get_icon("MiniPlane", "EditorIcons"),
+ Control::get_icon("MiniQuat", "EditorIcons"),
+ Control::get_icon("MiniAabb", "EditorIcons"),
+ 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"),
+ Control::get_icon("MiniIntArray", "EditorIcons"),
+ Control::get_icon("MiniFloatArray", "EditorIcons"),
+ Control::get_icon("MiniStringArray", "EditorIcons"),
+ Control::get_icon("MiniVector2Array", "EditorIcons"),
+ Control::get_icon("MiniVector3Array", "EditorIcons"),
+ Control::get_icon("MiniColorArray", "EditorIcons")
};
-
-
- Ref<Texture> seq_port = Control::get_icon("VisualShaderPort","EditorIcons");
+ Ref<Texture> seq_port = Control::get_icon("VisualShaderPort", "EditorIcons");
List<int> ids;
- script->get_node_list(edited_func,&ids);
- StringName editor_icons="EditorIcons";
+ script->get_node_list(edited_func, &ids);
+ StringName editor_icons = "EditorIcons";
- for(List<int>::Element *E=ids.front();E;E=E->next()) {
+ for (List<int>::Element *E = ids.front(); E; E = E->next()) {
- if (p_only_id>=0 && p_only_id!=E->get())
+ if (p_only_id >= 0 && p_only_id != E->get())
continue;
- Ref<VisualScriptNode> node = script->get_node(edited_func,E->get());
- Vector2 pos = script->get_node_pos(edited_func,E->get());
+ Ref<VisualScriptNode> node = script->get_node(edited_func, E->get());
+ Vector2 pos = script->get_node_pos(edited_func, E->get());
- GraphNode *gnode = memnew( GraphNode );
+ GraphNode *gnode = memnew(GraphNode);
gnode->set_title(node->get_caption());
- if (error_line==E->get()) {
+ if (error_line == E->get()) {
gnode->set_overlay(GraphNode::OVERLAY_POSITION);
} else if (node->is_breakpoint()) {
gnode->set_overlay(GraphNode::OVERLAY_BREAKPOINT);
}
- 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()));
+ 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()));
}
-
-
- gnode->set_meta("__vnode",node);
+ gnode->set_meta("__vnode", node);
gnode->set_name(itos(E->get()));
- gnode->connect("dragged",this,"_node_moved",varray(E->get()));
- gnode->connect("close_request",this,"_remove_node",varray(E->get()),CONNECT_DEFERRED);
+ gnode->connect("dragged", this, "_node_moved", varray(E->get()));
+ gnode->connect("close_request", this, "_remove_node", varray(E->get()), CONNECT_DEFERRED);
-
- if (E->get()!=script->get_function_node_id(edited_func)) {
+ if (E->get() != script->get_function_node_id(edited_func)) {
//function can't be erased
gnode->set_show_close_button(true);
}
-
if (node->cast_to<VisualScriptExpression>()) {
- LineEdit *line_edit = memnew( LineEdit );
+ LineEdit *line_edit = memnew(LineEdit);
line_edit->set_text(node->get_text());
line_edit->set_expand_to_text_length(true);
- line_edit->add_font_override("font",get_font("source","EditorFonts"));
+ line_edit->add_font_override("font", get_font("source", "EditorFonts"));
gnode->add_child(line_edit);
- line_edit->connect("text_changed",this,"_expression_text_changed",varray(E->get()));
+ line_edit->connect("text_changed", this, "_expression_text_changed", varray(E->get()));
} else {
- Label *text = memnew( Label );
+ Label *text = memnew(Label);
text->set_text(node->get_text());
gnode->add_child(text);
}
-
if (node->cast_to<VisualScriptComment>()) {
- Ref<VisualScriptComment> vsc=node;
+ Ref<VisualScriptComment> vsc = node;
gnode->set_comment(true);
gnode->set_resizeable(true);
- gnode->set_custom_minimum_size(vsc->get_size()*EDSCALE);
- gnode->connect("resize_request",this,"_comment_node_resized",varray(E->get()));
-
+ gnode->set_custom_minimum_size(vsc->get_size() * EDSCALE);
+ gnode->connect("resize_request", this, "_comment_node_resized", varray(E->get()));
}
+ int slot_idx = 0;
- int slot_idx=0;
-
- bool single_seq_output = node->get_output_sequence_port_count()==1 && node->get_output_sequence_port_text(0)==String();
- gnode->set_slot(0,node->has_input_sequence_port(),TYPE_SEQUENCE,Color(1,1,1,1),single_seq_output,TYPE_SEQUENCE,Color(1,1,1,1),seq_port,seq_port);
- gnode->set_offset(pos*EDSCALE);
+ bool single_seq_output = node->get_output_sequence_port_count() == 1 && node->get_output_sequence_port_text(0) == String();
+ gnode->set_slot(0, node->has_input_sequence_port(), TYPE_SEQUENCE, Color(1, 1, 1, 1), single_seq_output, TYPE_SEQUENCE, Color(1, 1, 1, 1), seq_port, seq_port);
+ gnode->set_offset(pos * EDSCALE);
slot_idx++;
-
- int mixed_seq_ports=0;
+ int mixed_seq_ports = 0;
if (!single_seq_output) {
if (node->has_mixed_input_and_sequence_ports()) {
- mixed_seq_ports=node->get_output_sequence_port_count();
+ mixed_seq_ports = node->get_output_sequence_port_count();
} else {
- for(int i=0;i<node->get_output_sequence_port_count();i++) {
+ for (int i = 0; i < node->get_output_sequence_port_count(); i++) {
- Label *text2 = memnew( Label );
+ Label *text2 = memnew(Label);
text2->set_text(node->get_output_sequence_port_text(i));
text2->set_align(Label::ALIGN_RIGHT);
gnode->add_child(text2);
- gnode->set_slot(slot_idx,false,0,Color(),true,TYPE_SEQUENCE,Color(1,1,1,1),seq_port,seq_port);
+ gnode->set_slot(slot_idx, false, 0, Color(), true, TYPE_SEQUENCE, Color(1, 1, 1, 1), seq_port, seq_port);
slot_idx++;
}
}
}
- for(int i=0;i<MAX(node->get_output_value_port_count(),MAX(mixed_seq_ports,node->get_input_value_port_count()));i++) {
+ for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) {
- bool left_ok=false;
- Variant::Type left_type=Variant::NIL;
+ bool left_ok = false;
+ Variant::Type left_type = Variant::NIL;
String left_name;
-
-
- if (i<node->get_input_value_port_count()) {
+ if (i < node->get_input_value_port_count()) {
PropertyInfo pi = node->get_input_value_port_info(i);
- left_ok=true;
- left_type=pi.type;
- left_name=pi.name;
+ left_ok = true;
+ left_type = pi.type;
+ left_name = pi.name;
}
- bool right_ok=false;
- Variant::Type right_type=Variant::NIL;
+ bool right_ok = false;
+ Variant::Type right_type = Variant::NIL;
String right_name;
- if (i>=mixed_seq_ports && i<node->get_output_value_port_count()+mixed_seq_ports) {
- PropertyInfo pi = node->get_output_value_port_info(i-mixed_seq_ports);
- right_ok=true;
- right_type=pi.type;
- right_name=pi.name;
+ if (i >= mixed_seq_ports && i < node->get_output_value_port_count() + mixed_seq_ports) {
+ PropertyInfo pi = node->get_output_value_port_info(i - mixed_seq_ports);
+ right_ok = true;
+ right_type = pi.type;
+ right_name = pi.name;
}
- HBoxContainer *hbc = memnew( HBoxContainer);
+ HBoxContainer *hbc = memnew(HBoxContainer);
if (left_ok) {
Ref<Texture> t;
- if (left_type>=0 && left_type<Variant::VARIANT_MAX) {
- t=type_icons[left_type];
+ if (left_type >= 0 && left_type < Variant::VARIANT_MAX) {
+ t = type_icons[left_type];
}
if (t.is_valid()) {
TextureRect *tf = memnew(TextureRect);
@@ -627,51 +591,51 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
hbc->add_child(memnew(Label(left_name)));
- if (left_type!=Variant::NIL && !script->is_input_value_port_connected(edited_func,E->get(),i)) {
+ if (left_type != Variant::NIL && !script->is_input_value_port_connected(edited_func, E->get(), i)) {
PropertyInfo pi = node->get_input_value_port_info(i);
- Button *button = memnew( Button );
+ Button *button = memnew(Button);
Variant value = node->get_default_input_value(i);
- if (value.get_type()!=left_type) {
+ if (value.get_type() != left_type) {
//different type? for now convert
//not the same, reconvert
Variant::CallError ce;
- const Variant *existingp=&value;
- value = Variant::construct(left_type,&existingp,1,ce,false);
+ const Variant *existingp = &value;
+ value = Variant::construct(left_type, &existingp, 1, ce, false);
}
- if (left_type==Variant::COLOR) {
- button->set_custom_minimum_size(Size2(30,0)*EDSCALE);
- button->connect("draw",this,"_draw_color_over_button",varray(button,value));
- } else if (left_type==Variant::OBJECT && Ref<Resource>(value).is_valid()) {
+ if (left_type == Variant::COLOR) {
+ button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
+ button->connect("draw", this, "_draw_color_over_button", varray(button, value));
+ } else if (left_type == Variant::OBJECT && Ref<Resource>(value).is_valid()) {
Ref<Resource> res = value;
Array arr;
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);
+ EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr);
- } else if (pi.type==Variant::INT && pi.hint==PROPERTY_HINT_ENUM){
+ } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) {
- button->set_text(pi.hint_string.get_slice(",",value));
+ button->set_text(pi.hint_string.get_slice(",", value));
} else {
button->set_text(value);
}
- button->connect("pressed",this,"_default_value_edited",varray(button,E->get(),i));
+ button->connect("pressed", this, "_default_value_edited", varray(button, E->get(), i));
hbc->add_child(button);
}
} else {
Control *c = memnew(Control);
- c->set_custom_minimum_size(Size2(10,0)*EDSCALE);
+ c->set_custom_minimum_size(Size2(10, 0) * EDSCALE);
hbc->add_child(c);
}
hbc->add_spacer();
- if (i<mixed_seq_ports) {
+ if (i < mixed_seq_ports) {
- Label *text2 = memnew( Label );
+ Label *text2 = memnew(Label);
text2->set_text(node->get_output_sequence_port_text(i));
text2->set_align(Label::ALIGN_RIGHT);
hbc->add_child(text2);
@@ -682,8 +646,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
hbc->add_child(memnew(Label(right_name)));
Ref<Texture> t;
- if (right_type>=0 && right_type<Variant::VARIANT_MAX) {
- t=type_icons[right_type];
+ if (right_type >= 0 && right_type < Variant::VARIANT_MAX) {
+ t = type_icons[right_type];
}
if (t.is_valid()) {
TextureRect *tf = memnew(TextureRect);
@@ -691,15 +655,14 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
hbc->add_child(tf);
}
-
}
gnode->add_child(hbc);
- if (i<mixed_seq_ports) {
- gnode->set_slot(slot_idx,left_ok,left_type,_color_from_type(left_type),true,TYPE_SEQUENCE,Color(1,1,1,1),Ref<Texture>(),seq_port);
+ if (i < mixed_seq_ports) {
+ gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type), true, TYPE_SEQUENCE, Color(1, 1, 1, 1), Ref<Texture>(), seq_port);
} else {
- gnode->set_slot(slot_idx,left_ok,left_type,_color_from_type(left_type),right_ok,right_type,_color_from_type(right_type));
+ gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type), right_ok, right_type, _color_from_type(right_type));
}
slot_idx++;
@@ -708,137 +671,134 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
graph->add_child(gnode);
if (gnode->is_comment()) {
- graph->move_child(gnode,0);
+ graph->move_child(gnode, 0);
}
}
_update_graph_connections();
- graph->call_deferred("set_scroll_ofs",script->get_function_scroll(edited_func)*EDSCALE); //may need to adapt a bit, let it do so
- updating_graph=false;
-
+ graph->call_deferred("set_scroll_ofs", script->get_function_scroll(edited_func) * EDSCALE); //may need to adapt a bit, let it do so
+ updating_graph = false;
}
void VisualScriptEditor::_update_members() {
-
- updating_members=true;
+ updating_members = true;
members->clear();
TreeItem *root = members->create_item();
TreeItem *functions = members->create_item(root);
- functions->set_selectable(0,false);
- functions->set_text(0,TTR("Functions:"));
- functions->add_button(0,Control::get_icon("Override","EditorIcons"),1);
- functions->add_button(0,Control::get_icon("Add","EditorIcons"),0);
- functions->set_custom_bg_color(0,Control::get_color("prop_section","Editor"));
+ functions->set_selectable(0, false);
+ functions->set_text(0, TTR("Functions:"));
+ functions->add_button(0, Control::get_icon("Override", "EditorIcons"), 1);
+ functions->add_button(0, Control::get_icon("Add", "EditorIcons"), 0);
+ functions->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
List<StringName> func_names;
script->get_function_list(&func_names);
- for (List<StringName>::Element *E=func_names.front();E;E=E->next()) {
- TreeItem *ti = members->create_item(functions) ;
- ti->set_text(0,E->get());
- ti->set_selectable(0,true);
- ti->set_editable(0,true);
+ for (List<StringName>::Element *E = func_names.front(); E; E = E->next()) {
+ TreeItem *ti = members->create_item(functions);
+ 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); function arguments are in the node now
- 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"));
- ti->set_custom_color(0,Color(1,1,1,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"));
+ ti->set_custom_color(0, Color(1, 1, 1, 1));
}
- if (selected==E->get())
+ if (selected == E->get())
ti->select(0);
}
TreeItem *variables = members->create_item(root);
- variables->set_selectable(0,false);
- variables->set_text(0,TTR("Variables:"));
- variables->add_button(0,Control::get_icon("Add","EditorIcons"));
- variables->set_custom_bg_color(0,Control::get_color("prop_section","Editor"));
-
- Ref<Texture> type_icons[Variant::VARIANT_MAX]={
- Control::get_icon("MiniVariant","EditorIcons"),
- Control::get_icon("MiniBoolean","EditorIcons"),
- Control::get_icon("MiniInteger","EditorIcons"),
- Control::get_icon("MiniFloat","EditorIcons"),
- Control::get_icon("MiniString","EditorIcons"),
- Control::get_icon("MiniVector2","EditorIcons"),
- Control::get_icon("MiniRect2","EditorIcons"),
- Control::get_icon("MiniVector3","EditorIcons"),
- Control::get_icon("MiniMatrix32","EditorIcons"),
- Control::get_icon("MiniPlane","EditorIcons"),
- Control::get_icon("MiniQuat","EditorIcons"),
- Control::get_icon("MiniAabb","EditorIcons"),
- 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"),
- Control::get_icon("MiniIntArray","EditorIcons"),
- Control::get_icon("MiniFloatArray","EditorIcons"),
- Control::get_icon("MiniStringArray","EditorIcons"),
- Control::get_icon("MiniVector2Array","EditorIcons"),
- Control::get_icon("MiniVector3Array","EditorIcons"),
- Control::get_icon("MiniColorArray","EditorIcons")
+ variables->set_selectable(0, false);
+ variables->set_text(0, TTR("Variables:"));
+ variables->add_button(0, Control::get_icon("Add", "EditorIcons"));
+ variables->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
+
+ Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
+ Control::get_icon("MiniVariant", "EditorIcons"),
+ Control::get_icon("MiniBoolean", "EditorIcons"),
+ Control::get_icon("MiniInteger", "EditorIcons"),
+ Control::get_icon("MiniFloat", "EditorIcons"),
+ Control::get_icon("MiniString", "EditorIcons"),
+ Control::get_icon("MiniVector2", "EditorIcons"),
+ Control::get_icon("MiniRect2", "EditorIcons"),
+ Control::get_icon("MiniVector3", "EditorIcons"),
+ Control::get_icon("MiniMatrix32", "EditorIcons"),
+ Control::get_icon("MiniPlane", "EditorIcons"),
+ Control::get_icon("MiniQuat", "EditorIcons"),
+ Control::get_icon("MiniAabb", "EditorIcons"),
+ 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"),
+ Control::get_icon("MiniIntArray", "EditorIcons"),
+ Control::get_icon("MiniFloatArray", "EditorIcons"),
+ Control::get_icon("MiniStringArray", "EditorIcons"),
+ Control::get_icon("MiniVector2Array", "EditorIcons"),
+ Control::get_icon("MiniVector3Array", "EditorIcons"),
+ Control::get_icon("MiniColorArray", "EditorIcons")
};
List<StringName> var_names;
script->get_variable_list(&var_names);
- for (List<StringName>::Element *E=var_names.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = var_names.front(); E; E = E->next()) {
TreeItem *ti = members->create_item(variables);
- ti->set_text(0,E->get());
+ ti->set_text(0, E->get());
Variant var = script->get_variable_default_value(E->get());
- ti->set_suffix(0,"="+String(var));
- ti->set_icon(0,type_icons[script->get_variable_info(E->get()).type]);
-
- 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->set_metadata(0,E->get());
- if (selected==E->get())
+ ti->set_suffix(0, "=" + String(var));
+ ti->set_icon(0, type_icons[script->get_variable_info(E->get()).type]);
+
+ 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->set_metadata(0, E->get());
+ if (selected == E->get())
ti->select(0);
}
TreeItem *_signals = members->create_item(root);
- _signals->set_selectable(0,false);
- _signals->set_text(0,TTR("Signals:"));
- _signals->add_button(0,Control::get_icon("Add","EditorIcons"));
- _signals->set_custom_bg_color(0,Control::get_color("prop_section","Editor"));
+ _signals->set_selectable(0, false);
+ _signals->set_text(0, TTR("Signals:"));
+ _signals->add_button(0, Control::get_icon("Add", "EditorIcons"));
+ _signals->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
List<StringName> signal_names;
script->get_custom_signal_list(&signal_names);
- for (List<StringName>::Element *E=signal_names.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = signal_names.front(); E; E = E->next()) {
TreeItem *ti = members->create_item(_signals);
- 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->set_metadata(0,E->get());
- if (selected==E->get())
+ 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->set_metadata(0, E->get());
+ if (selected == E->get())
ti->select(0);
}
- String base_type=script->get_instance_base_type();
- String icon_type=base_type;
- if (!Control::has_icon(base_type,"EditorIcons")) {
- icon_type="Object";
+ String base_type = script->get_instance_base_type();
+ String icon_type = base_type;
+ if (!Control::has_icon(base_type, "EditorIcons")) {
+ icon_type = "Object";
}
base_type_select->set_text(base_type);
- base_type_select->set_icon(Control::get_icon(icon_type,"EditorIcons"));
-
- updating_members=false;
+ base_type_select->set_icon(Control::get_icon(icon_type, "EditorIcons"));
+ updating_members = false;
}
void VisualScriptEditor::_member_selected() {
@@ -846,30 +806,24 @@ void VisualScriptEditor::_member_selected() {
if (updating_members)
return;
- TreeItem *ti=members->get_selected();
+ TreeItem *ti = members->get_selected();
ERR_FAIL_COND(!ti);
-
- selected=ti->get_metadata(0);
+ selected = ti->get_metadata(0);
//print_line("selected: "+String(selected));
+ if (ti->get_parent() == members->get_root()->get_children()) {
- if (ti->get_parent()==members->get_root()->get_children()) {
-
- if (edited_func!=selected) {
+ if (edited_func != selected) {
- revert_on_drag=edited_func;
- edited_func=selected;
+ revert_on_drag = edited_func;
+ edited_func = selected;
_update_members();
_update_graph();
}
return; //or crash because it will become invalid
-
}
-
-
-
}
void VisualScriptEditor::_member_edited() {
@@ -877,78 +831,75 @@ void VisualScriptEditor::_member_edited() {
if (updating_members)
return;
- TreeItem *ti=members->get_edited();
+ TreeItem *ti = members->get_edited();
ERR_FAIL_COND(!ti);
String name = ti->get_metadata(0);
String new_name = ti->get_text(0);
- if (name==new_name)
+ if (name == new_name)
return;
if (!new_name.is_valid_identifier()) {
- EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:")+" "+new_name);
- updating_members=true;
- ti->set_text(0,name);
- updating_members=false;
+ EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name);
+ updating_members = true;
+ ti->set_text(0, name);
+ updating_members = false;
return;
-
}
if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) {
- EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:")+" "+new_name);
- updating_members=true;
- ti->set_text(0,name);
- updating_members=false;
+ EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name);
+ updating_members = true;
+ ti->set_text(0, name);
+ updating_members = false;
return;
}
- TreeItem *root=members->get_root();
+ TreeItem *root = members->get_root();
- if (ti->get_parent()==root->get_children()) {
+ if (ti->get_parent() == root->get_children()) {
- if (edited_func==selected) {
- edited_func=new_name;
+ if (edited_func == selected) {
+ edited_func = new_name;
}
- selected=new_name;
-
+ selected = new_name;
_update_graph();
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);
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "rename_function", name, new_name);
+ undo_redo->add_undo_method(script.ptr(), "rename_function", new_name, name);
+ 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
-
}
- if (ti->get_parent()==root->get_children()->get_next()) {
+ if (ti->get_parent() == root->get_children()->get_next()) {
- selected=new_name;
+ selected = new_name;
undo_redo->create_action(TTR("Rename Variable"));
- undo_redo->add_do_method(script.ptr(),"rename_variable",name,new_name);
- undo_redo->add_undo_method(script.ptr(),"rename_variable",new_name,name);
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name);
+ undo_redo->add_undo_method(script.ptr(), "rename_variable", new_name, name);
+ 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
}
- if (ti->get_parent()==root->get_children()->get_next()->get_next()) {
+ if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
- selected=new_name;
+ selected = new_name;
undo_redo->create_action(TTR("Rename Signal"));
- undo_redo->add_do_method(script.ptr(),"rename_custom_signal",name,new_name);
- undo_redo->add_undo_method(script.ptr(),"rename_custom_signal",new_name,name);
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name);
+ undo_redo->add_undo_method(script.ptr(), "rename_custom_signal", new_name, name);
+ 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
@@ -961,137 +912,131 @@ void VisualScriptEditor::_override_pressed(int p_id) {
ERR_FAIL_COND(!virtuals_in_menu.has(p_id));
- VirtualInMenu vim=virtuals_in_menu[p_id];
+ VirtualInMenu vim = virtuals_in_menu[p_id];
String name = _validate_name(vim.name);
- selected=name;
- edited_func=selected;
+ selected = name;
+ edited_func = selected;
Ref<VisualScriptFunction> func_node;
func_node.instance();
func_node->set_name(vim.name);
undo_redo->create_action(TTR("Add Function"));
- undo_redo->add_do_method(script.ptr(),"add_function",name);
- for(int i=0;i<vim.args.size();i++) {
- func_node->add_argument(vim.args[i].first,vim.args[i].second);
+ undo_redo->add_do_method(script.ptr(), "add_function", name);
+ for (int i = 0; i < vim.args.size(); i++) {
+ func_node->add_argument(vim.args[i].first, vim.args[i].second);
}
-
- undo_redo->add_do_method(script.ptr(),"add_node",name,script->get_available_id(),func_node);
- if (vim.ret!=Variant::NIL || vim.ret_variant) {
+ undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node);
+ if (vim.ret != Variant::NIL || vim.ret_variant) {
Ref<VisualScriptReturn> ret_node;
ret_node.instance();
ret_node->set_return_type(vim.ret);
ret_node->set_enable_return_value(true);
ret_node->set_name(vim.name);
- undo_redo->add_do_method(script.ptr(),"add_node",name,script->get_available_id()+1,ret_node,Vector2(500,0));
-
+ undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id() + 1, ret_node, Vector2(500, 0));
}
- undo_redo->add_undo_method(script.ptr(),"remove_function",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->add_undo_method(script.ptr(), "remove_function", 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();
}
void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) {
- TreeItem *ti=p_item->cast_to<TreeItem>();
+ TreeItem *ti = p_item->cast_to<TreeItem>();
- TreeItem *root=members->get_root();
+ TreeItem *root = members->get_root();
- if (ti->get_parent()==root) {
+ if (ti->get_parent() == root) {
//main buttons
- if (ti==root->get_children()) {
+ if (ti == root->get_children()) {
//add function, this one uses menu
- if (p_button==1) {
+ if (p_button == 1) {
new_function_menu->clear();
- new_function_menu->set_size(Size2(0,0));
- int idx=0;
+ new_function_menu->set_size(Size2(0, 0));
+ int idx = 0;
virtuals_in_menu.clear();
List<MethodInfo> mi;
- ClassDB::get_method_list(script->get_instance_base_type(),&mi);
- for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
- MethodInfo mi=E->get();
- if (mi.flags&METHOD_FLAG_VIRTUAL) {
+ ClassDB::get_method_list(script->get_instance_base_type(), &mi);
+ for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) {
+ MethodInfo mi = E->get();
+ if (mi.flags & METHOD_FLAG_VIRTUAL) {
VirtualInMenu vim;
- vim.name=mi.name;
- vim.ret=mi.return_val.type;
- if (mi.return_val.name!=String())
- vim.ret_variant=true;
+ vim.name = mi.name;
+ vim.ret = mi.return_val.type;
+ if (mi.return_val.name != String())
+ vim.ret_variant = true;
else
- vim.ret_variant=false;
+ vim.ret_variant = false;
String desc;
- if (mi.return_val.type==Variant::NIL)
- desc="var";
+ if (mi.return_val.type == Variant::NIL)
+ desc = "var";
else
- desc=Variant::get_type_name(mi.return_val.type);
- desc+=" "+mi.name+" ( ";
-
+ desc = Variant::get_type_name(mi.return_val.type);
+ desc += " " + mi.name + " ( ";
- for(int i=0;i<mi.arguments.size();i++) {
+ for (int i = 0; i < mi.arguments.size(); i++) {
- if (i>0)
- desc+=", ";
+ if (i > 0)
+ desc += ", ";
- if (mi.arguments[i].type==Variant::NIL)
- desc+="var ";
+ if (mi.arguments[i].type == Variant::NIL)
+ desc += "var ";
else
- desc+=Variant::get_type_name(mi.arguments[i].type)+" ";
+ desc += Variant::get_type_name(mi.arguments[i].type) + " ";
- desc+=mi.arguments[i].name;
-
- Pair<Variant::Type,String> p;
- p.first=mi.arguments[i].type;
- p.second=mi.arguments[i].name;
- vim.args.push_back( p );
+ desc += mi.arguments[i].name;
+ Pair<Variant::Type, String> p;
+ p.first = mi.arguments[i].type;
+ p.second = mi.arguments[i].name;
+ vim.args.push_back(p);
}
- desc+=" )";
+ desc += " )";
- virtuals_in_menu[idx]=vim;
+ virtuals_in_menu[idx] = vim;
- new_function_menu->add_item(desc,idx);
+ new_function_menu->add_item(desc, idx);
idx++;
}
}
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_pos(members->get_global_pos() + pos.pos + Vector2(0, pos.size.y));
new_function_menu->popup();
return;
- } else if (p_button==0) {
-
+ } else if (p_button == 0) {
String name = _validate_name("new_function");
- selected=name;
- edited_func=selected;
+ selected = name;
+ edited_func = selected;
Ref<VisualScriptFunction> func_node;
func_node.instance();
func_node->set_name(name);
undo_redo->create_action(TTR("Add Function"));
- undo_redo->add_do_method(script.ptr(),"add_function",name);
- undo_redo->add_do_method(script.ptr(),"add_node",name,script->get_available_id(),func_node);
- undo_redo->add_undo_method(script.ptr(),"remove_function",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->add_do_method(script.ptr(), "add_function", name);
+ undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node);
+ undo_redo->add_undo_method(script.ptr(), "remove_function", 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();
@@ -1099,70 +1044,67 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
}
return; //or crash because it will become invalid
-
}
- if (ti==root->get_children()->get_next()) {
+ if (ti == root->get_children()->get_next()) {
//add variable
String name = _validate_name("new_variable");
- selected=name;
+ selected = name;
undo_redo->create_action(TTR("Add Variable"));
- undo_redo->add_do_method(script.ptr(),"add_variable",name);
- undo_redo->add_undo_method(script.ptr(),"remove_variable",name);
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "add_variable", name);
+ undo_redo->add_undo_method(script.ptr(), "remove_variable", name);
+ 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
-
}
- if (ti==root->get_children()->get_next()->get_next()) {
+ if (ti == root->get_children()->get_next()->get_next()) {
//add variable
String name = _validate_name("new_signal");
- selected=name;
+ selected = name;
undo_redo->create_action(TTR("Add Signal"));
- undo_redo->add_do_method(script.ptr(),"add_custom_signal",name);
- undo_redo->add_undo_method(script.ptr(),"remove_custom_signal",name);
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "add_custom_signal", name);
+ undo_redo->add_undo_method(script.ptr(), "remove_custom_signal", name);
+ 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 (ti->get_parent()==root->get_children()) {
+ if (ti->get_parent() == root->get_children()) {
//edit/remove function
String name = ti->get_metadata(0);
- if (p_button==1) {
+ 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);
+ 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()));
+ 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);
+ 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);
+ 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);
+ 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 (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);
}
/*
@@ -1170,98 +1112,89 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
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->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) {
-
+ } else if (p_button == 0) {
}
return; //or crash because it will become invalid
-
}
- if (ti->get_parent()==root->get_children()->get_next()) {
+ if (ti->get_parent() == root->get_children()->get_next()) {
//edit/remove variable
String name = ti->get_metadata(0);
- if (p_button==1) {
-
+ 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->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) {
+ } 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);
+ 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()) {
+ if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
//edit/remove variable
String name = ti->get_metadata(0);
- if (p_button==1) {
+ 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);
+ 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));
+ 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->add_do_method(this, "_update_members");
+ undo_redo->add_undo_method(this, "_update_members");
undo_redo->commit_action();
- } else if (p_button==0) {
+ } 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);
+ 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
-
}
-
-
}
}
-void VisualScriptEditor::_expression_text_changed(const String& p_text,int p_id) {
+void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) {
- Ref<VisualScriptExpression> vse = script->get_node(edited_func,p_id);
+ Ref<VisualScriptExpression> vse = script->get_node(edited_func, p_id);
if (!vse.is_valid())
return;
+ updating_graph = true;
- updating_graph=true;
-
- undo_redo->create_action(TTR("Change Expression"),UndoRedo::MERGE_ENDS);
- undo_redo->add_do_property(vse.ptr(),"expression",p_text);
- undo_redo->add_undo_property(vse.ptr(),"expression",vse->get("expression"));
- undo_redo->add_do_method(this,"_update_graph",p_id);
- undo_redo->add_undo_method(this,"_update_graph",p_id);
+ undo_redo->create_action(TTR("Change Expression"), UndoRedo::MERGE_ENDS);
+ undo_redo->add_do_property(vse.ptr(), "expression", p_text);
+ undo_redo->add_undo_property(vse.ptr(), "expression", vse->get("expression"));
+ undo_redo->add_do_method(this, "_update_graph", p_id);
+ undo_redo->add_undo_method(this, "_update_graph", p_id);
undo_redo->commit_action();
Node *node = graph->get_node(itos(p_id));
if (node->cast_to<Control>())
- node->cast_to<Control>()->set_size(Vector2(1,1)); //shrink if text is smaller
-
- updating_graph=false;
+ node->cast_to<Control>()->set_size(Vector2(1, 1)); //shrink if text is smaller
+ updating_graph = false;
}
void VisualScriptEditor::_available_node_doubleclicked() {
@@ -1272,27 +1205,27 @@ void VisualScriptEditor::_available_node_doubleclicked() {
return;
String which = item->get_metadata(0);
- if (which==String())
+ if (which == String())
return;
Vector2 ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
- while(true) {
- bool exists=false;
+ while (true) {
+ bool exists = false;
List<int> existing;
- script->get_node_list(edited_func,&existing);
- for (List<int>::Element *E=existing.front();E;E=E->next()) {
- Point2 pos = script->get_node_pos(edited_func,E->get());
- if (pos.distance_to(ofs)<15) {
- ofs+=Vector2(graph->get_snap(),graph->get_snap());
- exists=true;
+ script->get_node_list(edited_func, &existing);
+ for (List<int>::Element *E = existing.front(); E; E = E->next()) {
+ Point2 pos = script->get_node_pos(edited_func, E->get());
+ if (pos.distance_to(ofs) < 15) {
+ ofs += Vector2(graph->get_snap(), graph->get_snap());
+ exists = true;
break;
}
}
@@ -1300,26 +1233,23 @@ void VisualScriptEditor::_available_node_doubleclicked() {
if (exists)
continue;
break;
-
}
-
Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(which);
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
-
}
void VisualScriptEditor::_update_available_nodes() {
@@ -1328,63 +1258,61 @@ void VisualScriptEditor::_update_available_nodes() {
TreeItem *root = nodes->create_item();
- Map<String,TreeItem*> path_cache;
+ Map<String, TreeItem *> path_cache;
String filter = node_filter->get_text();
List<String> fnodes;
VisualScriptLanguage::singleton->get_registered_node_names(&fnodes);
- for (List<String>::Element *E=fnodes.front();E;E=E->next()) {
-
+ for (List<String>::Element *E = fnodes.front(); E; E = E->next()) {
Vector<String> path = E->get().split("/");
- if (filter!=String() && path.size() && path[path.size()-1].findn(filter)==-1)
+ if (filter != String() && path.size() && path[path.size() - 1].findn(filter) == -1)
continue;
String sp;
- TreeItem* parent=root;
+ TreeItem *parent = root;
- for(int i=0;i<path.size()-1;i++) {
+ for (int i = 0; i < path.size() - 1; i++) {
- if (i>0)
- sp+=",";
- sp+=path[i];
+ if (i > 0)
+ sp += ",";
+ sp += path[i];
if (!path_cache.has(sp)) {
- TreeItem* pathn = nodes->create_item(parent);
- pathn->set_selectable(0,false);
- pathn->set_text(0,path[i].capitalize());
- path_cache[sp]=pathn;
- parent=pathn;
- if (filter==String()) {
+ TreeItem *pathn = nodes->create_item(parent);
+ pathn->set_selectable(0, false);
+ pathn->set_text(0, path[i].capitalize());
+ path_cache[sp] = pathn;
+ parent = pathn;
+ if (filter == String()) {
pathn->set_collapsed(true); //should remember state
}
} else {
- parent=path_cache[sp];
+ parent = path_cache[sp];
}
}
TreeItem *item = nodes->create_item(parent);
- item->set_text(0,path[path.size()-1].capitalize());
- item->set_selectable(0,true);
- item->set_metadata(0,E->get());
+ item->set_text(0, path[path.size() - 1].capitalize());
+ item->set_selectable(0, true);
+ item->set_metadata(0, E->get());
}
-
}
-String VisualScriptEditor::_validate_name(const String& p_name) const {
+String VisualScriptEditor::_validate_name(const String &p_name) const {
- String valid=p_name;
+ String valid = p_name;
- int counter=1;
- while(true) {
+ int counter = 1;
+ while (true) {
bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid);
if (exists) {
counter++;
- valid=p_name+"_"+itos(counter);
+ valid = p_name + "_" + itos(counter);
continue;
}
@@ -1396,10 +1324,9 @@ String VisualScriptEditor::_validate_name(const String& p_name) const {
void VisualScriptEditor::_on_nodes_delete() {
-
List<int> to_erase;
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
if (gn->is_selected() && gn->is_close_button_visible()) {
@@ -1413,48 +1340,42 @@ void VisualScriptEditor::_on_nodes_delete() {
undo_redo->create_action("Remove VisualScript Nodes");
- for(List<int>::Element*F=to_erase.front();F;F=F->next()) {
-
-
- undo_redo->add_do_method(script.ptr(),"remove_node",edited_func,F->get());
- undo_redo->add_undo_method(script.ptr(),"add_node",edited_func,F->get(),script->get_node(edited_func,F->get()),script->get_node_pos(edited_func,F->get()));
+ for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
+ undo_redo->add_do_method(script.ptr(), "remove_node", edited_func, F->get());
+ undo_redo->add_undo_method(script.ptr(), "add_node", edited_func, F->get(), script->get_node(edited_func, F->get()), script->get_node_pos(edited_func, F->get()));
List<VisualScript::SequenceConnection> sequence_conns;
- script->get_sequence_connection_list(edited_func,&sequence_conns);
+ script->get_sequence_connection_list(edited_func, &sequence_conns);
+ for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- for (List<VisualScript::SequenceConnection>::Element *E=sequence_conns.front();E;E=E->next()) {
-
- if (E->get().from_node==F->get() || E->get().to_node==F->get()) {
- undo_redo->add_undo_method(script.ptr(),"sequence_connect",edited_func,E->get().from_node,E->get().from_output,E->get().to_node);
+ if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, E->get().from_node, E->get().from_output, E->get().to_node);
}
}
List<VisualScript::DataConnection> data_conns;
- script->get_data_connection_list(edited_func,&data_conns);
+ script->get_data_connection_list(edited_func, &data_conns);
- for (List<VisualScript::DataConnection>::Element *E=data_conns.front();E;E=E->next()) {
+ for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
- if (E->get().from_node==F->get() || E->get().to_node==F->get()) {
- undo_redo->add_undo_method(script.ptr(),"data_connect",edited_func,E->get().from_node,E->get().from_port,E->get().to_node,E->get().to_port);
+ if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
+ undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
}
}
-
}
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
}
-
void VisualScriptEditor::_on_nodes_duplicate() {
-
List<int> to_duplicate;
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
if (gn->is_selected() && gn->is_close_button_visible()) {
@@ -1467,64 +1388,60 @@ void VisualScriptEditor::_on_nodes_duplicate() {
return;
undo_redo->create_action("Duplicate VisualScript Nodes");
- int idc=script->get_available_id()+1;
+ int idc = script->get_available_id() + 1;
Set<int> to_select;
- for(List<int>::Element*F=to_duplicate.front();F;F=F->next()) {
+ for (List<int>::Element *F = to_duplicate.front(); F; F = F->next()) {
- Ref<VisualScriptNode> node = script->get_node(edited_func,F->get());
+ Ref<VisualScriptNode> node = script->get_node(edited_func, F->get());
Ref<VisualScriptNode> dupe = node->duplicate();
int new_id = idc++;
to_select.insert(new_id);
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,dupe,script->get_node_pos(edited_func,F->get())+Vector2(20,20));
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
-
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, dupe, script->get_node_pos(edited_func, F->get()) + Vector2(20, 20));
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
}
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
int id = gn->get_name().operator String().to_int();
gn->set_selected(to_select.has(id));
-
}
}
if (to_select.size()) {
- EditorNode::get_singleton()->push_item(script->get_node(edited_func,to_select.front()->get()).ptr());
+ EditorNode::get_singleton()->push_item(script->get_node(edited_func, to_select.front()->get()).ptr());
}
-
}
-void VisualScriptEditor::_input(const InputEvent& p_event) {
+void VisualScriptEditor::_input(const InputEvent &p_event) {
- if (p_event.type==InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) {
- revert_on_drag=String(); //so we can still drag functions
+ if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ revert_on_drag = String(); //so we can still drag functions
}
}
-Variant VisualScriptEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) {
+Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
-
- if (p_from==nodes) {
+ if (p_from == nodes) {
TreeItem *it = nodes->get_item_at_pos(p_point);
if (!it)
return Variant();
- String type=it->get_metadata(0);
- if (type==String())
+ String type = it->get_metadata(0);
+ if (type == String())
return Variant();
Dictionary dd;
- dd["type"]="visual_script_node_drag";
- dd["node_type"]=type;
+ dd["type"] = "visual_script_node_drag";
+ dd["node_type"] = type;
Label *label = memnew(Label);
label->set_text(it->get_text(0));
@@ -1532,49 +1449,42 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2& p_point,Control* p_fr
return dd;
}
- if (p_from==members) {
-
+ if (p_from == members) {
TreeItem *it = members->get_item_at_pos(p_point);
if (!it)
return Variant();
- String type=it->get_metadata(0);
+ String type = it->get_metadata(0);
- if (type==String())
+ if (type == String())
return Variant();
-
Dictionary dd;
- TreeItem *root=members->get_root();
+ TreeItem *root = members->get_root();
- if (it->get_parent()==root->get_children()) {
+ if (it->get_parent() == root->get_children()) {
- dd["type"]="visual_script_function_drag";
- dd["function"]=type;
- if (revert_on_drag!=String()) {
- edited_func=revert_on_drag; //revert so function does not change
- revert_on_drag=String();
+ dd["type"] = "visual_script_function_drag";
+ dd["function"] = type;
+ if (revert_on_drag != String()) {
+ edited_func = revert_on_drag; //revert so function does not change
+ revert_on_drag = String();
_update_graph();
}
- } else if (it->get_parent()==root->get_children()->get_next()) {
+ } else if (it->get_parent() == root->get_children()->get_next()) {
- dd["type"]="visual_script_variable_drag";
- dd["variable"]=type;
- } else if (it->get_parent()==root->get_children()->get_next()->get_next()) {
+ dd["type"] = "visual_script_variable_drag";
+ dd["variable"] = type;
+ } else if (it->get_parent() == root->get_children()->get_next()->get_next()) {
- dd["type"]="visual_script_signal_drag";
- dd["signal"]=type;
+ dd["type"] = "visual_script_signal_drag";
+ dd["signal"] = type;
} else {
return Variant();
}
-
-
-
-
-
Label *label = memnew(Label);
label->set_text(it->get_text(0));
set_drag_preview(label);
@@ -1583,78 +1493,69 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2& p_point,Control* p_fr
return Variant();
}
-bool VisualScriptEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{
-
- if (p_from==graph) {
+bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
+ if (p_from == graph) {
Dictionary d = p_data;
if (d.has("type") &&
- (
- String(d["type"])=="visual_script_node_drag" ||
- String(d["type"])=="visual_script_function_drag" ||
- String(d["type"])=="visual_script_variable_drag" ||
- String(d["type"])=="visual_script_signal_drag" ||
- String(d["type"])=="obj_property" ||
- String(d["type"])=="resource" ||
- String(d["type"])=="files" ||
- String(d["type"])=="nodes"
- ) ) {
-
+ (String(d["type"]) == "visual_script_node_drag" ||
+ String(d["type"]) == "visual_script_function_drag" ||
+ String(d["type"]) == "visual_script_variable_drag" ||
+ String(d["type"]) == "visual_script_signal_drag" ||
+ String(d["type"]) == "obj_property" ||
+ String(d["type"]) == "resource" ||
+ String(d["type"]) == "files" ||
+ String(d["type"]) == "nodes")) {
- if (String(d["type"])=="obj_property") {
+ if (String(d["type"]) == "obj_property") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature."));
#else
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature."));
#endif
- }
+ }
- if (String(d["type"])=="nodes") {
+ if (String(d["type"]) == "nodes") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node."));
#else
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node."));
#endif
- }
+ }
- if (String(d["type"])=="visual_script_variable_drag") {
+ if (String(d["type"]) == "visual_script_variable_drag") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter."));
#else
- const_cast<VisualScriptEditor*>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter."));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter."));
#endif
- }
-
- return true;
+ }
+ return true;
}
-
-
-
}
-
return false;
}
#ifdef TOOLS_ENABLED
-static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) {
+static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
return NULL;
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr==script)
+ if (scr.is_valid() && scr == script)
return p_current_node;
- for(int i=0;i<p_current_node->get_child_count();i++) {
- Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script);
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
if (n)
return n;
}
@@ -1664,43 +1565,40 @@ static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const R
#endif
+void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
-
-void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){
-
- if (p_from==graph) {
+ if (p_from == graph) {
Dictionary d = p_data;
- if (d.has("type") && String(d["type"])=="visual_script_node_drag") {
+ if (d.has("type") && String(d["type"]) == "visual_script_node_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
-
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(d["node_type"]);
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
}
- if (d.has("type") && String(d["type"])=="visual_script_variable_drag") {
+ if (d.has("type") && String(d["type"]) == "visual_script_variable_drag") {
#ifdef OSX_ENABLED
bool use_set = Input::get_singleton()->is_key_pressed(KEY_META);
@@ -1710,50 +1608,50 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Ref<VisualScriptNode> vnode;
if (use_set) {
Ref<VisualScriptVariableSet> vnodes;
vnodes.instance();
vnodes->set_variable(d["variable"]);
- vnode=vnodes;
+ vnode = vnodes;
} else {
Ref<VisualScriptVariableGet> vnodeg;
vnodeg.instance();
vnodeg->set_variable(d["variable"]);
- vnode=vnodeg;
+ vnode = vnodeg;
}
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
}
- if (d.has("type") && String(d["type"])=="visual_script_function_drag") {
+ if (d.has("type") && String(d["type"]) == "visual_script_function_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Ref<VisualScriptFunctionCall> vnode;
vnode.instance();
@@ -1762,33 +1660,31 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
- undo_redo->add_do_method(vnode.ptr(),"set_base_type",script->get_instance_base_type());
- undo_redo->add_do_method(vnode.ptr(),"set_function",d["function"]);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
+ undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type());
+ undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
-
}
-
- if (d.has("type") && String(d["type"])=="visual_script_signal_drag") {
+ if (d.has("type") && String(d["type"]) == "visual_script_signal_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Ref<VisualScriptEmitSignal> vnode;
vnode.instance();
@@ -1797,28 +1693,28 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
}
- if (d.has("type") && String(d["type"])=="resource") {
+ if (d.has("type") && String(d["type"]) == "resource") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Ref<VisualScriptPreload> prnode;
prnode.instance();
@@ -1827,28 +1723,28 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Preload Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,prnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- Node* node = graph->get_node(itos(new_id));
+ Node *node = graph->get_node(itos(new_id));
if (node) {
graph->set_selected(node);
_node_selected(node);
}
}
- if (d.has("type") && String(d["type"])=="files") {
+ if (d.has("type") && String(d["type"]) == "files") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
Array files = d["files"];
@@ -1858,7 +1754,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (files.size()) {
undo_redo->create_action(TTR("Add Preload Node"));
- for(int i=0;i<files.size();i++) {
+ for (int i = 0; i < files.size(); i++) {
Ref<Resource> res = ResourceLoader::load(files[i]);
if (!res.is_valid())
@@ -1868,22 +1764,21 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
prnode.instance();
prnode->set_preload(res);
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,prnode,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
new_ids.push_back(new_id);
new_id++;
- ofs+=Vector2(20,20)*EDSCALE;
+ ofs += Vector2(20, 20) * EDSCALE;
}
-
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
}
- for(List<int>::Element *E=new_ids.front();E;E=E->next()) {
+ for (List<int>::Element *E = new_ids.front(); E; E = E->next()) {
- Node* node = graph->get_node(itos(E->get()));
+ Node *node = graph->get_node(itos(E->get()));
if (node) {
graph->set_selected(node);
_node_selected(node);
@@ -1891,42 +1786,39 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
}
}
- if (d.has("type") && String(d["type"])=="nodes") {
-
- Node* sn = _find_script_node(get_tree()->get_edited_scene_root(),get_tree()->get_edited_scene_root(),script);
+ if (d.has("type") && String(d["type"]) == "nodes") {
+ Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
if (!sn) {
- EditorNode::get_singleton()->show_warning("Can't drop nodes because script '"+get_name()+"' is not used in this scene.");
+ EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene.");
return;
}
-
#ifdef OSX_ENABLED
bool use_node = Input::get_singleton()->is_key_pressed(KEY_META);
#else
bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
#endif
-
Array nodes = d["nodes"];
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
undo_redo->create_action(TTR("Add Node(s) From Tree"));
int base_id = script->get_available_id();
- if (nodes.size()>1) {
- use_node=true;
+ if (nodes.size() > 1) {
+ use_node = true;
}
- for(int i=0;i<nodes.size();i++) {
+ for (int i = 0; i < nodes.size(); i++) {
NodePath np = nodes[i];
Node *node = get_node(np);
@@ -1940,8 +1832,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Ref<VisualScriptSceneNode> scene_node;
scene_node.instance();
scene_node->set_node_path(sn->get_path_to(node));
- n=scene_node;
-
+ n = scene_node;
} else {
Ref<VisualScriptFunctionCall> call;
@@ -1949,38 +1840,33 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH);
call->set_base_path(sn->get_path_to(node));
call->set_base_type(node->get_class());
- n=call;
+ n = call;
method_select->select_method_from_instance(node);
- selecting_method_id=base_id;
-
+ selecting_method_id = base_id;
}
-
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,n,ofs);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, n, ofs);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
base_id++;
- ofs+=Vector2(25,25);
+ ofs += Vector2(25, 25);
}
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
-
-
}
- if (d.has("type") && String(d["type"])=="obj_property") {
-
- Node* sn = _find_script_node(get_tree()->get_edited_scene_root(),get_tree()->get_edited_scene_root(),script);
+ if (d.has("type") && String(d["type"]) == "obj_property") {
+ Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
- EditorNode::get_singleton()->show_warning("Can't drop properties because script '"+get_name()+"' is not used in this scene.\nDrop holding 'Shift' to just copy the signature.");
+ EditorNode::get_singleton()->show_warning("Can't drop properties because script '" + get_name() + "' is not used in this scene.\nDrop holding 'Shift' to just copy the signature.");
return;
}
- Object *obj=d["object"];
+ Object *obj = d["object"];
if (!obj)
return;
@@ -1990,10 +1876,10 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
#ifdef OSX_ENABLED
bool use_get = Input::get_singleton()->is_key_pressed(KEY_META);
#else
@@ -2002,7 +1888,6 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
-
if (use_get)
undo_redo->create_action(TTR("Add Getter Property"));
else
@@ -2022,7 +1907,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
pset->set_use_builtin_value(true);
pset->set_builtin_value(d["value"]);
}*/
- vnode=pset;
+ vnode = pset;
} else {
Ref<VisualScriptPropertyGet> pget;
@@ -2030,26 +1915,23 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE);
pget->set_base_type(obj->get_class());
- vnode=pget;
-
+ vnode = pget;
}
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,vnode,ofs);
- undo_redo->add_do_method(vnode.ptr(),"set_property",d["property"]);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs);
+ undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
if (!use_get) {
- undo_redo->add_do_method(vnode.ptr(),"set_default_input_value",0,d["value"]);
+ undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
}
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
} else {
-
-
if (use_get)
undo_redo->create_action(TTR("Add Getter Property"));
else
@@ -2063,74 +1945,63 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Ref<VisualScriptPropertySet> pset;
pset.instance();
- if (sn==node) {
+ if (sn == node) {
pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF);
} else {
pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH);
pset->set_base_path(sn->get_path_to(node));
}
- vnode=pset;
+ vnode = pset;
} else {
Ref<VisualScriptPropertyGet> pget;
pget.instance();
- if (sn==node) {
+ if (sn == node) {
pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF);
} else {
pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH);
pget->set_base_path(sn->get_path_to(node));
}
- vnode=pget;
-
+ vnode = pget;
}
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,vnode,ofs);
- undo_redo->add_do_method(vnode.ptr(),"set_property",d["property"]);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs);
+ undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
if (!use_get) {
- undo_redo->add_do_method(vnode.ptr(),"set_default_input_value",0,d["value"]);
+ undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
}
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
}
-
-
}
-
-
}
-
-
}
+void VisualScriptEditor::_selected_method(const String &p_method) {
-void VisualScriptEditor::_selected_method(const String& p_method) {
-
- Ref<VisualScriptFunctionCall> vsfc = script->get_node(edited_func,selecting_method_id);
+ Ref<VisualScriptFunctionCall> vsfc = script->get_node(edited_func, selecting_method_id);
if (!vsfc.is_valid())
return;
vsfc->set_function(p_method);
-
}
-void VisualScriptEditor::_draw_color_over_button(Object* obj,Color p_color) {
+void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) {
Button *button = obj->cast_to<Button>();
if (!button)
return;
- Ref<StyleBox> normal = get_stylebox("normal","Button" );
- button->draw_rect(Rect2(normal->get_offset(),button->get_size()-normal->get_minimum_size()),p_color);
-
+ Ref<StyleBox> normal = get_stylebox("normal", "Button");
+ button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
}
-void VisualScriptEditor::_button_resource_previewed(const String& p_path,const Ref<Texture>& p_preview,Variant p_ud) {
-
+void VisualScriptEditor::_button_resource_previewed(const String &p_path, const Ref<Texture> &p_preview, Variant p_ud) {
- Array ud=p_ud;
- ERR_FAIL_COND(ud.size()!=2);
+ Array ud = p_ud;
+ ERR_FAIL_COND(ud.size() != 2);
ObjectID id = ud[0];
Object *obj = ObjectDB::get_instance(id);
@@ -2147,73 +2018,63 @@ void VisualScriptEditor::_button_resource_previewed(const String& p_path,const R
b->set_icon(p_preview);
}
-
}
/////////////////////////
-
-
void VisualScriptEditor::apply_code() {
-
-
}
-Ref<Script> VisualScriptEditor::get_edited_script() const{
+Ref<Script> VisualScriptEditor::get_edited_script() const {
return script;
}
-Vector<String> VisualScriptEditor::get_functions(){
+Vector<String> VisualScriptEditor::get_functions() {
return Vector<String>();
}
-void VisualScriptEditor::set_edited_script(const Ref<Script>& p_script){
-
-
- script=p_script;
- signal_editor->script=p_script;
- signal_editor->undo_redo=undo_redo;
- variable_editor->script=p_script;
- variable_editor->undo_redo=undo_redo;
+void VisualScriptEditor::set_edited_script(const Ref<Script> &p_script) {
+ script = p_script;
+ signal_editor->script = p_script;
+ signal_editor->undo_redo = undo_redo;
+ variable_editor->script = p_script;
+ variable_editor->undo_redo = undo_redo;
- script->connect("node_ports_changed",this,"_node_ports_changed");
+ script->connect("node_ports_changed", this, "_node_ports_changed");
_update_members();
_update_available_nodes();
}
-void VisualScriptEditor::reload_text(){
-
-
+void VisualScriptEditor::reload_text() {
}
-String VisualScriptEditor::get_name(){
+String VisualScriptEditor::get_name() {
String name;
- if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
- name=script->get_path().get_file();
+ if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
+ name = script->get_path().get_file();
if (is_unsaved()) {
- name+="(*)";
+ name += "(*)";
}
- } else if (script->get_name()!="")
- name=script->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;
-
}
-Ref<Texture> VisualScriptEditor::get_icon(){
+Ref<Texture> VisualScriptEditor::get_icon() {
- return Control::get_icon("VisualScript","EditorIcons");
+ return Control::get_icon("VisualScript", "EditorIcons");
}
-bool VisualScriptEditor::is_unsaved(){
+bool VisualScriptEditor::is_unsaved() {
#ifdef TOOLS_ENABLED
return script->is_edited() || script->are_subnodes_edited();
@@ -2222,24 +2083,23 @@ bool VisualScriptEditor::is_unsaved(){
#endif
}
-Variant VisualScriptEditor::get_edit_state(){
+Variant VisualScriptEditor::get_edit_state() {
Dictionary d;
- d["function"]=edited_func;
- d["scroll"]=graph->get_scroll_ofs();
- d["zoom"]=graph->get_zoom();
- d["using_snap"]=graph->is_using_snap();
- d["snap"]=graph->get_snap();
+ d["function"] = edited_func;
+ d["scroll"] = graph->get_scroll_ofs();
+ d["zoom"] = graph->get_zoom();
+ d["using_snap"] = graph->is_using_snap();
+ d["snap"] = graph->get_snap();
return d;
}
-void VisualScriptEditor::set_edit_state(const Variant& p_state){
+void VisualScriptEditor::set_edit_state(const Variant &p_state) {
Dictionary d = p_state;
if (d.has("function")) {
- edited_func=p_state;
- selected=edited_func;
-
+ edited_func = p_state;
+ selected = edited_func;
}
_update_graph();
@@ -2257,10 +2117,8 @@ void VisualScriptEditor::set_edit_state(const Variant& p_state){
if (d.has("snap_enabled")) {
graph->set_use_snap(d["snap_enabled"]);
}
-
}
-
void VisualScriptEditor::_center_on_node(int p_id) {
Node *n = graph->get_node(itos(p_id));
@@ -2269,94 +2127,87 @@ void VisualScriptEditor::_center_on_node(int p_id) {
GraphNode *gn = n->cast_to<GraphNode>();
if (gn) {
gn->set_selected(true);
- Vector2 new_scroll = gn->get_offset() - graph->get_size()*0.5 + gn->get_size()*0.5;
- graph->set_scroll_ofs( new_scroll );
- script->set_function_scroll(edited_func,new_scroll/EDSCALE);
+ Vector2 new_scroll = gn->get_offset() - graph->get_size() * 0.5 + gn->get_size() * 0.5;
+ graph->set_scroll_ofs(new_scroll);
+ script->set_function_scroll(edited_func, new_scroll / EDSCALE);
script->set_edited(true); //so it's saved
-
}
}
-void VisualScriptEditor::goto_line(int p_line, bool p_with_error){
+void VisualScriptEditor::goto_line(int p_line, bool p_with_error) {
- p_line+=1; //add one because script lines begin from 0.
+ p_line += 1; //add one because script lines begin from 0.
if (p_with_error)
- error_line=p_line;
+ error_line = p_line;
List<StringName> functions;
script->get_function_list(&functions);
- for (List<StringName>::Element *E=functions.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
- if (script->has_node(E->get(),p_line)) {
+ if (script->has_node(E->get(), p_line)) {
- edited_func=E->get();
- selected=edited_func;
+ edited_func = E->get();
+ selected = edited_func;
_update_graph();
_update_members();
- call_deferred("_center_on_node",p_line); //editor might be just created and size might not exist yet
+ call_deferred("_center_on_node", p_line); //editor might be just created and size might not exist yet
return;
}
}
}
-void VisualScriptEditor::trim_trailing_whitespace(){
-
-
+void VisualScriptEditor::trim_trailing_whitespace() {
}
-void VisualScriptEditor::ensure_focus(){
+void VisualScriptEditor::ensure_focus() {
graph->grab_focus();
}
-void VisualScriptEditor::tag_saved_version(){
-
-
+void VisualScriptEditor::tag_saved_version() {
}
-void VisualScriptEditor::reload(bool p_soft){
-
-
+void VisualScriptEditor::reload(bool p_soft) {
}
-void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints){
+void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) {
List<StringName> functions;
script->get_function_list(&functions);
- for (List<StringName>::Element *E=functions.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
List<int> nodes;
- script->get_node_list(E->get(),&nodes);
- for (List<int>::Element *F=nodes.front();F;F=F->next()) {
+ script->get_node_list(E->get(), &nodes);
+ for (List<int>::Element *F = nodes.front(); F; F = F->next()) {
- Ref<VisualScriptNode> vsn = script->get_node(E->get(),F->get());
+ Ref<VisualScriptNode> vsn = script->get_node(E->get(), F->get());
if (vsn->is_breakpoint()) {
- p_breakpoints->push_back(F->get()-1); //subtract 1 because breakpoints in text start from zero
+ p_breakpoints->push_back(F->get() - 1); //subtract 1 because breakpoints in text start from zero
}
}
}
}
-bool VisualScriptEditor::goto_method(const String& p_method){
+bool VisualScriptEditor::goto_method(const String &p_method) {
if (!script->has_function(p_method))
return false;
- edited_func=p_method;
- selected=edited_func;
+ edited_func = p_method;
+ selected = edited_func;
_update_members();
_update_graph();
return true;
}
-void VisualScriptEditor::add_callback(const String& p_function,PoolStringArray p_args){
+void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray p_args) {
if (script->has_function(p_function)) {
- edited_func=p_function;
- selected=edited_func;
+ edited_func = p_function;
+ selected = edited_func;
_update_members();
_update_graph();
return;
@@ -2364,59 +2215,56 @@ void VisualScriptEditor::add_callback(const String& p_function,PoolStringArray p
Ref<VisualScriptFunction> func;
func.instance();
- for(int i=0;i<p_args.size();i++) {
+ for (int i = 0; i < p_args.size(); i++) {
String name = p_args[i];
- Variant::Type type=Variant::NIL;
+ Variant::Type type = Variant::NIL;
- if (name.find(":")!=-1) {
- String tt = name.get_slice(":",1);
- name=name.get_slice(":",0);
- for(int j=0;j<Variant::VARIANT_MAX;j++) {
+ if (name.find(":") != -1) {
+ String tt = name.get_slice(":", 1);
+ name = name.get_slice(":", 0);
+ for (int j = 0; j < Variant::VARIANT_MAX; j++) {
String tname = Variant::get_type_name(Variant::Type(j));
- if (tname==tt) {
- type=Variant::Type(j);
+ if (tname == tt) {
+ type = Variant::Type(j);
break;
}
}
}
- func->add_argument(type,name);
+ func->add_argument(type, name);
}
func->set_name(p_function);
script->add_function(p_function);
- script->add_node(p_function,script->get_available_id(),func);
+ script->add_node(p_function, script->get_available_id(), func);
- edited_func=p_function;
- selected=edited_func;
+ edited_func = p_function;
+ selected = edited_func;
_update_members();
_update_graph();
- graph->call_deferred("set_scroll_ofs",script->get_function_scroll(edited_func)); //for first time it might need to be later
+ graph->call_deferred("set_scroll_ofs", script->get_function_scroll(edited_func)); //for first time it might need to be later
//undo_redo->clear_history();
-
}
-void VisualScriptEditor::update_settings(){
+void VisualScriptEditor::update_settings() {
_update_graph();
}
void VisualScriptEditor::set_debugger_active(bool p_active) {
if (!p_active) {
- error_line=-1;
+ error_line = -1;
_update_graph(); //clear line break
}
}
-void VisualScriptEditor::set_tooltip_request_func(String p_method,Object* p_obj){
-
-
+void VisualScriptEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
}
-Control *VisualScriptEditor::get_edit_menu(){
+Control *VisualScriptEditor::get_edit_menu() {
return edit_menu;
}
@@ -2430,58 +2278,53 @@ void VisualScriptEditor::_change_base_type_callback() {
String bt = select_base_type->get_selected_type();
- ERR_FAIL_COND(bt==String());
+ ERR_FAIL_COND(bt == String());
undo_redo->create_action("Change Base Type");
- undo_redo->add_do_method(script.ptr(),"set_instance_base_type",bt);
- undo_redo->add_undo_method(script.ptr(),"set_instance_base_type",script->get_instance_base_type());
- undo_redo->add_do_method(this,"_update_members");
- undo_redo->add_undo_method(this,"_update_members");
+ undo_redo->add_do_method(script.ptr(), "set_instance_base_type", bt);
+ undo_redo->add_undo_method(script.ptr(), "set_instance_base_type", script->get_instance_base_type());
+ undo_redo->add_do_method(this, "_update_members");
+ undo_redo->add_undo_method(this, "_update_members");
undo_redo->commit_action();
-
}
-void VisualScriptEditor::_node_selected(Node* p_node) {
+void VisualScriptEditor::_node_selected(Node *p_node) {
Ref<VisualScriptNode> vnode = p_node->get_meta("__vnode");
if (vnode.is_null())
return;
- EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector
+ EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector
}
-static bool _get_out_slot(const Ref<VisualScriptNode>& p_node,int p_slot,int& r_real_slot,bool& r_sequence) {
+static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) {
- if (p_slot<p_node->get_output_sequence_port_count()) {
- r_sequence=true;
- r_real_slot=p_slot;
+ if (p_slot < p_node->get_output_sequence_port_count()) {
+ r_sequence = true;
+ r_real_slot = p_slot;
return true;
}
- r_real_slot=p_slot-p_node->get_output_sequence_port_count();
- r_sequence=false;
-
- return (r_real_slot<p_node->get_output_value_port_count());
+ r_real_slot = p_slot - p_node->get_output_sequence_port_count();
+ r_sequence = false;
+ return (r_real_slot < p_node->get_output_value_port_count());
}
-static bool _get_in_slot(const Ref<VisualScriptNode>& p_node,int p_slot,int& r_real_slot,bool& r_sequence) {
+static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) {
- if (p_slot==0 && p_node->has_input_sequence_port()) {
- r_sequence=true;
- r_real_slot=0;
+ if (p_slot == 0 && p_node->has_input_sequence_port()) {
+ r_sequence = true;
+ r_real_slot = 0;
return true;
}
+ r_real_slot = p_slot - (p_node->has_input_sequence_port() ? 1 : 0);
+ r_sequence = false;
- r_real_slot=p_slot-(p_node->has_input_sequence_port()?1:0);
- r_sequence=false;
-
- return r_real_slot<p_node->get_input_value_port_count();
-
+ return r_real_slot < p_node->get_input_value_port_count();
}
-
void VisualScriptEditor::_begin_node_move() {
undo_redo->create_action("Move Node(s)");
@@ -2492,164 +2335,151 @@ void VisualScriptEditor::_end_node_move() {
undo_redo->commit_action();
}
-void VisualScriptEditor::_move_node(String func,int p_id,const Vector2& p_to) {
-
+void VisualScriptEditor::_move_node(String func, int p_id, const Vector2 &p_to) {
-
- if (func==String(edited_func)) {
- Node* node = graph->get_node(itos(p_id));
+ if (func == String(edited_func)) {
+ Node *node = graph->get_node(itos(p_id));
if (node && node->cast_to<GraphNode>())
node->cast_to<GraphNode>()->set_offset(p_to);
}
- script->set_node_pos(edited_func,p_id,p_to/EDSCALE);
+ script->set_node_pos(edited_func, p_id, p_to / EDSCALE);
}
-void VisualScriptEditor::_node_moved(Vector2 p_from,Vector2 p_to, int p_id) {
+void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) {
- undo_redo->add_do_method(this,"_move_node",String(edited_func),p_id,p_to);
- undo_redo->add_undo_method(this,"_move_node",String(edited_func),p_id,p_from);
+ undo_redo->add_do_method(this, "_move_node", String(edited_func), p_id, p_to);
+ undo_redo->add_undo_method(this, "_move_node", String(edited_func), p_id, p_from);
}
void VisualScriptEditor::_remove_node(int p_id) {
-
undo_redo->create_action("Remove VisualScript Node");
- undo_redo->add_do_method(script.ptr(),"remove_node",edited_func,p_id);
- undo_redo->add_undo_method(script.ptr(),"add_node",edited_func,p_id,script->get_node(edited_func,p_id),script->get_node_pos(edited_func,p_id));
-
+ undo_redo->add_do_method(script.ptr(), "remove_node", edited_func, p_id);
+ undo_redo->add_undo_method(script.ptr(), "add_node", edited_func, p_id, script->get_node(edited_func, p_id), script->get_node_pos(edited_func, p_id));
List<VisualScript::SequenceConnection> sequence_conns;
- script->get_sequence_connection_list(edited_func,&sequence_conns);
-
+ script->get_sequence_connection_list(edited_func, &sequence_conns);
- for (List<VisualScript::SequenceConnection>::Element *E=sequence_conns.front();E;E=E->next()) {
+ for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- if (E->get().from_node==p_id || E->get().to_node==p_id) {
- undo_redo->add_undo_method(script.ptr(),"sequence_connect",edited_func,E->get().from_node,E->get().from_output,E->get().to_node);
+ if (E->get().from_node == p_id || E->get().to_node == p_id) {
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, E->get().from_node, E->get().from_output, E->get().to_node);
}
}
List<VisualScript::DataConnection> data_conns;
- script->get_data_connection_list(edited_func,&data_conns);
+ script->get_data_connection_list(edited_func, &data_conns);
- for (List<VisualScript::DataConnection>::Element *E=data_conns.front();E;E=E->next()) {
+ for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
- if (E->get().from_node==p_id || E->get().to_node==p_id) {
- undo_redo->add_undo_method(script.ptr(),"data_connect",edited_func,E->get().from_node,E->get().from_port,E->get().to_node,E->get().to_port);
+ if (E->get().from_node == p_id || E->get().to_node == p_id) {
+ undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
}
}
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
}
+void VisualScriptEditor::_node_ports_changed(const String &p_func, int p_id) {
-void VisualScriptEditor::_node_ports_changed(const String& p_func,int p_id) {
-
- if (p_func!=String(edited_func))
+ if (p_func != String(edited_func))
return;
_update_graph(p_id);
}
-void VisualScriptEditor::_graph_connected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot) {
+void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) {
- Ref<VisualScriptNode> from_node = script->get_node(edited_func,p_from.to_int());
+ Ref<VisualScriptNode> from_node = script->get_node(edited_func, p_from.to_int());
ERR_FAIL_COND(!from_node.is_valid());
bool from_seq;
int from_port;
- if (!_get_out_slot(from_node,p_from_slot,from_port,from_seq))
+ if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
return; //can't connect this, it' s invalid
- Ref<VisualScriptNode> to_node = script->get_node(edited_func,p_to.to_int());
+ Ref<VisualScriptNode> to_node = script->get_node(edited_func, p_to.to_int());
ERR_FAIL_COND(!to_node.is_valid());
bool to_seq;
int to_port;
- if (!_get_in_slot(to_node,p_to_slot,to_port,to_seq))
+ if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
return; //can't connect this, it' s invalid
-
- ERR_FAIL_COND(from_seq!=to_seq);
-
+ ERR_FAIL_COND(from_seq != to_seq);
undo_redo->create_action("Connect Nodes");
if (from_seq) {
- 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());
+ 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 {
- 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);
+ 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
- undo_redo->add_do_method(this,"_update_graph",p_from.to_int());
- undo_redo->add_do_method(this,"_update_graph",p_to.to_int());
- undo_redo->add_undo_method(this,"_update_graph",p_from.to_int());
- undo_redo->add_undo_method(this,"_update_graph",p_to.to_int());
+ undo_redo->add_do_method(this, "_update_graph", p_from.to_int());
+ undo_redo->add_do_method(this, "_update_graph", p_to.to_int());
+ undo_redo->add_undo_method(this, "_update_graph", p_from.to_int());
+ undo_redo->add_undo_method(this, "_update_graph", p_to.to_int());
}
- undo_redo->add_do_method(this,"_update_graph_connections");
- undo_redo->add_undo_method(this,"_update_graph_connections");
+ undo_redo->add_do_method(this, "_update_graph_connections");
+ undo_redo->add_undo_method(this, "_update_graph_connections");
undo_redo->commit_action();
-
}
-void VisualScriptEditor::_graph_disconnected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot){
+void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) {
- Ref<VisualScriptNode> from_node = script->get_node(edited_func,p_from.to_int());
+ Ref<VisualScriptNode> from_node = script->get_node(edited_func, p_from.to_int());
ERR_FAIL_COND(!from_node.is_valid());
bool from_seq;
int from_port;
- if (!_get_out_slot(from_node,p_from_slot,from_port,from_seq))
+ if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
return; //can't connect this, it' s invalid
- Ref<VisualScriptNode> to_node = script->get_node(edited_func,p_to.to_int());
+ Ref<VisualScriptNode> to_node = script->get_node(edited_func, p_to.to_int());
ERR_FAIL_COND(!to_node.is_valid());
bool to_seq;
int to_port;
- if (!_get_in_slot(to_node,p_to_slot,to_port,to_seq))
+ if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
return; //can't connect this, it' s invalid
-
- ERR_FAIL_COND(from_seq!=to_seq);
-
+ ERR_FAIL_COND(from_seq != to_seq);
undo_redo->create_action("Connect Nodes");
if (from_seq) {
- undo_redo->add_do_method(script.ptr(),"sequence_disconnect",edited_func,p_from.to_int(),from_port,p_to.to_int());
- undo_redo->add_undo_method(script.ptr(),"sequence_connect",edited_func,p_from.to_int(),from_port,p_to.to_int());
+ undo_redo->add_do_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int());
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int());
} else {
- undo_redo->add_do_method(script.ptr(),"data_disconnect",edited_func,p_from.to_int(),from_port,p_to.to_int(),to_port);
- undo_redo->add_undo_method(script.ptr(),"data_connect",edited_func,p_from.to_int(),from_port,p_to.to_int(),to_port);
+ undo_redo->add_do_method(script.ptr(), "data_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
+ undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
//update nodes in sgraph
- undo_redo->add_do_method(this,"_update_graph",p_from.to_int());
- undo_redo->add_do_method(this,"_update_graph",p_to.to_int());
- undo_redo->add_undo_method(this,"_update_graph",p_from.to_int());
- undo_redo->add_undo_method(this,"_update_graph",p_to.to_int());
+ undo_redo->add_do_method(this, "_update_graph", p_from.to_int());
+ undo_redo->add_do_method(this, "_update_graph", p_to.to_int());
+ undo_redo->add_undo_method(this, "_update_graph", p_from.to_int());
+ undo_redo->add_undo_method(this, "_update_graph", p_to.to_int());
}
- undo_redo->add_do_method(this,"_update_graph_connections");
- undo_redo->add_undo_method(this,"_update_graph_connections");
+ undo_redo->add_do_method(this, "_update_graph_connections");
+ undo_redo->add_undo_method(this, "_update_graph_connections");
undo_redo->commit_action();
}
+void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) {
-
-void VisualScriptEditor::_graph_connect_to_empty(const String& p_from,int p_from_slot,const Vector2& p_release_pos) {
-
- Node* node = graph->get_node(p_from);
+ Node *node = graph->get_node(p_from);
if (!node)
return;
@@ -2657,54 +2487,50 @@ void VisualScriptEditor::_graph_connect_to_empty(const String& p_from,int p_from
if (!gn)
return;
- Ref<VisualScriptNode> vsn = script->get_node(edited_func,p_from.to_int());
+ Ref<VisualScriptNode> vsn = script->get_node(edited_func, p_from.to_int());
if (!vsn.is_valid())
return;
- if (p_from_slot<vsn->get_output_sequence_port_count()) {
+ if (p_from_slot < vsn->get_output_sequence_port_count()) {
port_action_popup->clear();
- port_action_popup->add_item(TTR("Condition"),CREATE_COND);
- port_action_popup->add_item(TTR("Sequence"),CREATE_SEQUENCE);
- port_action_popup->add_item(TTR("Switch"),CREATE_SWITCH);
- port_action_popup->add_item(TTR("Iterator"),CREATE_ITERATOR);
- port_action_popup->add_item(TTR("While"),CREATE_WHILE);
- port_action_popup->add_item(TTR("Return"),CREATE_RETURN);
+ port_action_popup->add_item(TTR("Condition"), CREATE_COND);
+ port_action_popup->add_item(TTR("Sequence"), CREATE_SEQUENCE);
+ port_action_popup->add_item(TTR("Switch"), CREATE_SWITCH);
+ port_action_popup->add_item(TTR("Iterator"), CREATE_ITERATOR);
+ port_action_popup->add_item(TTR("While"), CREATE_WHILE);
+ port_action_popup->add_item(TTR("Return"), CREATE_RETURN);
- port_action_node=p_from.to_int();
- port_action_output=p_from_slot;
+ port_action_node = p_from.to_int();
+ port_action_output = p_from_slot;
} else {
port_action_popup->clear();
- port_action_popup->add_item(TTR("Call"),CREATE_CALL);
- port_action_popup->add_item(TTR("Get"),CREATE_GET);
- port_action_popup->add_item(TTR("Set"),CREATE_SET);
-
-
- port_action_output=p_from_slot-vsn->get_output_sequence_port_count();
- port_action_node=p_from.to_int();
-
+ port_action_popup->add_item(TTR("Call"), CREATE_CALL);
+ port_action_popup->add_item(TTR("Get"), CREATE_GET);
+ port_action_popup->add_item(TTR("Set"), CREATE_SET);
+ port_action_output = p_from_slot - vsn->get_output_sequence_port_count();
+ port_action_node = p_from.to_int();
}
- 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_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->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_node, int p_output, Set<int> &visited_nodes) {
VisualScriptNode::TypeGuess tg;
- tg.type=Variant::NIL;
+ tg.type = Variant::NIL;
if (visited_nodes.has(p_node))
return tg; //no loop
visited_nodes.insert(p_node);
- Ref<VisualScriptNode> node = script->get_node(edited_func,p_node);
+ Ref<VisualScriptNode> node = script->get_node(edited_func, p_node);
if (!node.is_valid()) {
@@ -2713,40 +2539,39 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node,i
Vector<VisualScriptNode::TypeGuess> in_guesses;
- for(int i=0;i<node->get_input_value_port_count();i++) {
+ for (int i = 0; i < node->get_input_value_port_count(); i++) {
PropertyInfo pi = node->get_input_value_port_info(i);
VisualScriptNode::TypeGuess g;
- g.type=pi.type;
+ g.type = pi.type;
- if (g.type==Variant::NIL || g.type==Variant::OBJECT) {
+ if (g.type == Variant::NIL || g.type == Variant::OBJECT) {
//any or object input, must further guess what this is
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_node, i, &from_node, &from_port)) {
- g = _guess_output_type(from_node,from_port,visited_nodes);
+ g = _guess_output_type(from_node, from_port, visited_nodes);
} else {
Variant defval = node->get_default_input_value(i);
- if (defval.get_type()==Variant::OBJECT) {
+ if (defval.get_type() == Variant::OBJECT) {
Object *obj = defval;
if (obj) {
- g.type=Variant::OBJECT;
- g.GDCLASS=obj->get_class();
- g.script=obj->get_script();
+ g.type = Variant::OBJECT;
+ g.GDCLASS = obj->get_class();
+ g.script = obj->get_script();
}
}
}
-
}
in_guesses.push_back(g);
}
- return node->guess_output_type(in_guesses.ptr(),p_output);
+ return node->guess_output_type(in_guesses.ptr(), p_output);
}
void VisualScriptEditor::_port_action_menu(int p_option) {
@@ -2754,29 +2579,29 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap,snap));
+ ofs = ofs.snapped(Vector2(snap, snap));
}
- ofs/=EDSCALE;
+ ofs /= EDSCALE;
- bool seq_connect=false;
+ bool seq_connect = false;
Ref<VisualScriptNode> vnode;
Set<int> vn;
- switch(p_option) {
+ switch (p_option) {
case CREATE_CALL: {
Ref<VisualScriptFunctionCall> n;
n.instance();
- vnode=n;
+ vnode = n;
- VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node,port_action_output,vn);
+ VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
- if (tg.type==Variant::OBJECT) {
+ if (tg.type == Variant::OBJECT) {
n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_INSTANCE);
- if (tg.GDCLASS!=StringName()) {
+ if (tg.GDCLASS != StringName()) {
n->set_base_type(tg.GDCLASS);
} else {
n->set_base_type("Object");
@@ -2789,29 +2614,25 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
new_connect_node_select->select_method_from_base_type(n->get_base_type());
}
-
} else {
n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
n->set_basic_type(tg.type);
new_connect_node_select->select_method_from_basic_type(tg.type);
}
-
-
} break;
case CREATE_SET: {
Ref<VisualScriptPropertySet> n;
n.instance();
- vnode=n;
-
+ vnode = n;
- VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node,port_action_output,vn);
+ VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
- if (tg.type==Variant::OBJECT) {
+ if (tg.type == Variant::OBJECT) {
n->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE);
- if (tg.GDCLASS!=StringName()) {
+ if (tg.GDCLASS != StringName()) {
n->set_base_type(tg.GDCLASS);
} else {
n->set_base_type("Object");
@@ -2824,25 +2645,24 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
new_connect_node_select->select_property_from_base_type(n->get_base_type());
}
-
} 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, tg.ev_type);
}
} break;
case CREATE_GET: {
Ref<VisualScriptPropertyGet> n;
n.instance();
- vnode=n;
+ vnode = n;
- VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node,port_action_output,vn);
+ VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
- if (tg.type==Variant::OBJECT) {
+ if (tg.type == Variant::OBJECT) {
n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE);
- if (tg.GDCLASS!=StringName()) {
+ if (tg.GDCLASS != StringName()) {
n->set_base_type(tg.GDCLASS);
} else {
n->set_base_type("Object");
@@ -2855,11 +2675,10 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
new_connect_node_select->select_property_from_base_type(n->get_base_type());
}
-
} 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, tg.ev_type);
}
} break;
@@ -2867,147 +2686,139 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
Ref<VisualScriptCondition> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
case CREATE_SEQUENCE: {
Ref<VisualScriptSequence> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
case CREATE_SWITCH: {
Ref<VisualScriptSwitch> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
case CREATE_ITERATOR: {
Ref<VisualScriptIterator> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
case CREATE_WHILE: {
Ref<VisualScriptWhile> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
case CREATE_RETURN: {
Ref<VisualScriptReturn> n;
n.instance();
- vnode=n;
- seq_connect=true;
+ vnode = n;
+ seq_connect = true;
} break;
-
}
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,vnode,ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
if (seq_connect) {
- undo_redo->add_do_method(script.ptr(),"sequence_connect",edited_func,port_action_node,port_action_output,new_id);
+ undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, port_action_node, port_action_output, new_id);
}
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
- undo_redo->add_do_method(this,"_update_graph",new_id);
- undo_redo->add_undo_method(this,"_update_graph",new_id);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
+ undo_redo->add_do_method(this, "_update_graph", new_id);
+ undo_redo->add_undo_method(this, "_update_graph", new_id);
undo_redo->commit_action();
- port_action_new_node=new_id;
-
+ port_action_new_node = new_id;
}
-void VisualScriptEditor::_selected_connect_node_method_or_setget(const String& p_text) {
+void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p_text) {
- Ref<VisualScriptNode> vsn = script->get_node(edited_func,port_action_new_node);
+ Ref<VisualScriptNode> vsn = script->get_node(edited_func, port_action_new_node);
if (vsn->cast_to<VisualScriptFunctionCall>()) {
Ref<VisualScriptFunctionCall> vsfc = vsn;
vsfc->set_function(p_text);
- script->data_connect(edited_func,port_action_node,port_action_output,port_action_new_node,0);
+ script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
}
if (vsn->cast_to<VisualScriptPropertySet>()) {
Ref<VisualScriptPropertySet> vsp = vsn;
vsp->set_property(p_text);
- script->data_connect(edited_func,port_action_node,port_action_output,port_action_new_node,0);
+ script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
}
if (vsn->cast_to<VisualScriptPropertyGet>()) {
Ref<VisualScriptPropertyGet> vsp = vsn;
vsp->set_property(p_text);
- script->data_connect(edited_func,port_action_node,port_action_output,port_action_new_node,0);
+ script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
}
_update_graph(port_action_new_node);
_update_graph_connections();
-
}
-
void VisualScriptEditor::_default_value_changed() {
-
- Ref<VisualScriptNode> vsn = script->get_node(edited_func,editing_id);
+ Ref<VisualScriptNode> vsn = script->get_node(edited_func, editing_id);
if (vsn.is_null())
return;
undo_redo->create_action("Change Input Value");
- undo_redo->add_do_method(vsn.ptr(),"set_default_input_value",editing_input,default_value_edit->get_variant());
- undo_redo->add_undo_method(vsn.ptr(),"set_default_input_value",editing_input,vsn->get_default_input_value(editing_input));
+ undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant());
+ undo_redo->add_undo_method(vsn.ptr(), "set_default_input_value", editing_input, vsn->get_default_input_value(editing_input));
- undo_redo->add_do_method(this,"_update_graph",editing_id);
- undo_redo->add_undo_method(this,"_update_graph",editing_id);
+ undo_redo->add_do_method(this, "_update_graph", editing_id);
+ undo_redo->add_undo_method(this, "_update_graph", editing_id);
undo_redo->commit_action();
-
}
-void VisualScriptEditor::_default_value_edited(Node * p_button,int p_id,int p_input_port) {
+void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_input_port) {
- Ref<VisualScriptNode> vsn = script->get_node(edited_func,p_id);
+ Ref<VisualScriptNode> vsn = script->get_node(edited_func, p_id);
if (vsn.is_null())
return;
PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port);
Variant existing = vsn->get_default_input_value(p_input_port);
- if (pinfo.type!=Variant::NIL && existing.get_type()!=pinfo.type) {
+ if (pinfo.type != Variant::NIL && existing.get_type() != pinfo.type) {
Variant::CallError ce;
- const Variant *existingp=&existing;
- existing = Variant::construct(pinfo.type,&existingp,1,ce,false);
-
+ const Variant *existingp = &existing;
+ 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_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)
+ 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_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)
default_value_edit->popup_centered_ratio();
else
default_value_edit->popup();
}
editing_id = p_id;
- editing_input=p_input_port;
-
+ editing_input = p_input_port;
}
-void VisualScriptEditor::_show_hint(const String& p_hint) {
+void VisualScriptEditor::_show_hint(const String &p_hint) {
hint_text->set_text(p_hint);
hint_text->show();
@@ -3019,38 +2830,38 @@ void VisualScriptEditor::_hide_timer() {
hint_text->hide();
}
-void VisualScriptEditor::_node_filter_changed(const String& p_text) {
+void VisualScriptEditor::_node_filter_changed(const String &p_text) {
_update_available_nodes();
}
-void VisualScriptEditor::_notification(int p_what) {
+void VisualScriptEditor::_notification(int p_what) {
- if (p_what==NOTIFICATION_READY) {
- node_filter_icon->set_texture(Control::get_icon("Zoom","EditorIcons"));
+ if (p_what == NOTIFICATION_READY) {
+ node_filter_icon->set_texture(Control::get_icon("Zoom", "EditorIcons"));
}
}
-void VisualScriptEditor::_graph_ofs_changed(const Vector2& p_ofs) {
+void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) {
if (updating_graph)
return;
- updating_graph=true;
+ updating_graph = true;
if (script->has_function(edited_func)) {
- script->set_function_scroll(edited_func,graph->get_scroll_ofs()/EDSCALE);
+ script->set_function_scroll(edited_func, graph->get_scroll_ofs() / EDSCALE);
script->set_edited(true);
}
- updating_graph=false;
+ updating_graph = false;
}
-void VisualScriptEditor::_comment_node_resized(const Vector2& p_new_size,int p_node) {
+void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_node) {
if (updating_graph)
return;
- Ref<VisualScriptComment> vsc = script->get_node(edited_func,p_node);
+ Ref<VisualScriptComment> vsc = script->get_node(edited_func, p_node);
if (vsc.is_null())
return;
@@ -3061,38 +2872,36 @@ void VisualScriptEditor::_comment_node_resized(const Vector2& p_new_size,int p_n
if (!gn)
return;
- updating_graph=true;
+ updating_graph = true;
graph->set_block_minimum_size_adjust(true); //faster resize
- undo_redo->create_action("Resize Comment",UndoRedo::MERGE_ENDS);
- undo_redo->add_do_method(vsc.ptr(),"set_size",p_new_size/EDSCALE);
- undo_redo->add_undo_method(vsc.ptr(),"set_size",vsc->get_size());
+ undo_redo->create_action("Resize Comment", UndoRedo::MERGE_ENDS);
+ undo_redo->add_do_method(vsc.ptr(), "set_size", p_new_size / EDSCALE);
+ undo_redo->add_undo_method(vsc.ptr(), "set_size", vsc->get_size());
undo_redo->commit_action();
gn->set_custom_minimum_size(p_new_size); //for this time since graph update is blocked
- gn->set_size(Size2(1,1));
+ gn->set_size(Size2(1, 1));
graph->set_block_minimum_size_adjust(false);
- updating_graph=false;
-
-
+ updating_graph = false;
}
void VisualScriptEditor::_menu_option(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case EDIT_DELETE_NODES: {
_on_nodes_delete();
} break;
case EDIT_TOGGLE_BREAKPOINT: {
List<String> reselect;
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
if (gn->is_selected()) {
int id = String(gn->get_name()).to_int();
- Ref<VisualScriptNode> vsn = script->get_node(edited_func,id);
+ Ref<VisualScriptNode> vsn = script->get_node(edited_func, id);
if (vsn.is_valid()) {
vsn->set_breakpoint(!vsn->is_breakpoint());
reselect.push_back(gn->get_name());
@@ -3103,7 +2912,7 @@ void VisualScriptEditor::_menu_option(int p_what) {
_update_graph();
- for(List<String>::Element *E=reselect.front();E;E=E->next()) {
+ for (List<String>::Element *E = reselect.front(); E; E = E->next()) {
GraphNode *gn = graph->get_node(E->get())->cast_to<GraphNode>();
gn->set_selected(true);
}
@@ -3124,22 +2933,21 @@ void VisualScriptEditor::_menu_option(int p_what) {
clipboard->data_connections.clear();
clipboard->sequence_connections.clear();
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
if (gn->is_selected()) {
int id = String(gn->get_name()).to_int();
- Ref<VisualScriptNode> node = script->get_node(edited_func,id);
+ Ref<VisualScriptNode> node = script->get_node(edited_func, id);
if (node->cast_to<VisualScriptFunction>()) {
EditorNode::get_singleton()->show_warning("Can't copy the function node.");
return;
}
if (node.is_valid()) {
- clipboard->nodes[id]=node->duplicate();
- clipboard->nodes_positions[id]=script->get_node_pos(edited_func,id);
+ clipboard->nodes[id] = node->duplicate();
+ clipboard->nodes_positions[id] = script->get_node_pos(edited_func, id);
}
-
}
}
}
@@ -3149,9 +2957,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
List<VisualScript::SequenceConnection> sequence_connections;
- script->get_sequence_connection_list(edited_func,&sequence_connections);
+ script->get_sequence_connection_list(edited_func, &sequence_connections);
- for (List<VisualScript::SequenceConnection>::Element *E=sequence_connections.front();E;E=E->next()) {
+ for (List<VisualScript::SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
@@ -3161,9 +2969,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
List<VisualScript::DataConnection> data_connections;
- script->get_data_connection_list(edited_func,&data_connections);
+ script->get_data_connection_list(edited_func, &data_connections);
- for (List<VisualScript::DataConnection>::Element *E=data_connections.front();E;E=E->next()) {
+ for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
@@ -3171,11 +2979,10 @@ void VisualScriptEditor::_menu_option(int p_what) {
}
}
- if (p_what==EDIT_CUT_NODES) {
+ if (p_what == EDIT_CUT_NODES) {
_on_nodes_delete(); // oh yeah, also delete on cut
}
-
} break;
case EDIT_PASTE_NODES: {
if (!script->has_function(edited_func))
@@ -3186,10 +2993,10 @@ void VisualScriptEditor::_menu_option(int p_what) {
break;
}
- Map<int,int> remap;
+ Map<int, int> remap;
undo_redo->create_action("Paste VisualScript Nodes");
- int idc=script->get_available_id()+1;
+ int idc = script->get_available_id() + 1;
Set<int> to_select;
@@ -3197,137 +3004,118 @@ void VisualScriptEditor::_menu_option(int p_what) {
{
List<int> nodes;
- script->get_node_list(edited_func,&nodes);
- for (List<int>::Element *E=nodes.front();E;E=E->next()) {
- Vector2 pos = script->get_node_pos(edited_func,E->get()).snapped(Vector2(2,2));
+ script->get_node_list(edited_func, &nodes);
+ for (List<int>::Element *E = nodes.front(); E; E = E->next()) {
+ Vector2 pos = script->get_node_pos(edited_func, E->get()).snapped(Vector2(2, 2));
existing_positions.insert(pos);
}
}
- for (Map<int,Ref<VisualScriptNode> >::Element *E=clipboard->nodes.front();E;E=E->next()) {
-
+ for (Map<int, Ref<VisualScriptNode> >::Element *E = clipboard->nodes.front(); E; E = E->next()) {
Ref<VisualScriptNode> node = E->get()->duplicate();
int new_id = idc++;
to_select.insert(new_id);
- remap[E->key()]=new_id;
+ remap[E->key()] = new_id;
Vector2 paste_pos = clipboard->nodes_positions[E->key()];
- while(existing_positions.has(paste_pos.snapped(Vector2(2,2)))) {
- paste_pos+=Vector2(20,20)*EDSCALE;
+ while (existing_positions.has(paste_pos.snapped(Vector2(2, 2)))) {
+ paste_pos += Vector2(20, 20) * EDSCALE;
}
-
- undo_redo->add_do_method(script.ptr(),"add_node",edited_func,new_id,node,paste_pos);
- undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,new_id);
-
+ undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, node, paste_pos);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
}
- for (Set<VisualScript::SequenceConnection>::Element *E=clipboard->sequence_connections.front();E;E=E->next()) {
-
-
- undo_redo->add_do_method(script.ptr(),"sequence_connect",edited_func,remap[E->get().from_node],E->get().from_output,remap[E->get().to_node]);
- undo_redo->add_undo_method(script.ptr(),"sequence_disconnect",edited_func,remap[E->get().from_node],E->get().from_output,remap[E->get().to_node]);
+ for (Set<VisualScript::SequenceConnection>::Element *E = clipboard->sequence_connections.front(); E; E = E->next()) {
+ undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
+ undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", edited_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
}
- for (Set<VisualScript::DataConnection>::Element *E=clipboard->data_connections.front();E;E=E->next()) {
-
-
- undo_redo->add_do_method(script.ptr(),"data_connect",edited_func,remap[E->get().from_node],E->get().from_port,remap[E->get().to_node],E->get().to_port);
- undo_redo->add_undo_method(script.ptr(),"data_disconnect",edited_func,remap[E->get().from_node],E->get().from_port,remap[E->get().to_node],E->get().to_port);
+ for (Set<VisualScript::DataConnection>::Element *E = clipboard->data_connections.front(); E; E = E->next()) {
+ undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
+ undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
}
- undo_redo->add_do_method(this,"_update_graph");
- undo_redo->add_undo_method(this,"_update_graph");
+ undo_redo->add_do_method(this, "_update_graph");
+ undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
- for(int i=0;i<graph->get_child_count();i++) {
+ for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>();
if (gn) {
int id = gn->get_name().operator String().to_int();
gn->set_selected(to_select.has(id));
-
}
}
} break;
-
-
}
}
void VisualScriptEditor::_bind_methods() {
- ClassDB::bind_method("_member_button",&VisualScriptEditor::_member_button);
- ClassDB::bind_method("_member_edited",&VisualScriptEditor::_member_edited);
- ClassDB::bind_method("_member_selected",&VisualScriptEditor::_member_selected);
- ClassDB::bind_method("_update_members",&VisualScriptEditor::_update_members);
- ClassDB::bind_method("_change_base_type",&VisualScriptEditor::_change_base_type);
- ClassDB::bind_method("_change_base_type_callback",&VisualScriptEditor::_change_base_type_callback);
- ClassDB::bind_method("_override_pressed",&VisualScriptEditor::_override_pressed);
- ClassDB::bind_method("_node_selected",&VisualScriptEditor::_node_selected);
- ClassDB::bind_method("_node_moved",&VisualScriptEditor::_node_moved);
- ClassDB::bind_method("_move_node",&VisualScriptEditor::_move_node);
- ClassDB::bind_method("_begin_node_move",&VisualScriptEditor::_begin_node_move);
- ClassDB::bind_method("_end_node_move",&VisualScriptEditor::_end_node_move);
- ClassDB::bind_method("_remove_node",&VisualScriptEditor::_remove_node);
- ClassDB::bind_method("_update_graph",&VisualScriptEditor::_update_graph,DEFVAL(-1));
- ClassDB::bind_method("_node_ports_changed",&VisualScriptEditor::_node_ports_changed);
- ClassDB::bind_method("_available_node_doubleclicked",&VisualScriptEditor::_available_node_doubleclicked);
- ClassDB::bind_method("_default_value_edited",&VisualScriptEditor::_default_value_edited);
- ClassDB::bind_method("_default_value_changed",&VisualScriptEditor::_default_value_changed);
- ClassDB::bind_method("_menu_option",&VisualScriptEditor::_menu_option);
- ClassDB::bind_method("_graph_ofs_changed",&VisualScriptEditor::_graph_ofs_changed);
- ClassDB::bind_method("_center_on_node",&VisualScriptEditor::_center_on_node);
- ClassDB::bind_method("_comment_node_resized",&VisualScriptEditor::_comment_node_resized);
- ClassDB::bind_method("_button_resource_previewed",&VisualScriptEditor::_button_resource_previewed);
- ClassDB::bind_method("_port_action_menu",&VisualScriptEditor::_port_action_menu);
- ClassDB::bind_method("_selected_connect_node_method_or_setget",&VisualScriptEditor::_selected_connect_node_method_or_setget);
- ClassDB::bind_method("_expression_text_changed",&VisualScriptEditor::_expression_text_changed);
-
-
-
-
- ClassDB::bind_method("get_drag_data_fw",&VisualScriptEditor::get_drag_data_fw);
- ClassDB::bind_method("can_drop_data_fw",&VisualScriptEditor::can_drop_data_fw);
- ClassDB::bind_method("drop_data_fw",&VisualScriptEditor::drop_data_fw);
-
- ClassDB::bind_method("_input",&VisualScriptEditor::_input);
- ClassDB::bind_method("_on_nodes_delete",&VisualScriptEditor::_on_nodes_delete);
- ClassDB::bind_method("_on_nodes_duplicate",&VisualScriptEditor::_on_nodes_duplicate);
-
- ClassDB::bind_method("_hide_timer",&VisualScriptEditor::_hide_timer);
-
- ClassDB::bind_method("_graph_connected",&VisualScriptEditor::_graph_connected);
- ClassDB::bind_method("_graph_disconnected",&VisualScriptEditor::_graph_disconnected);
- ClassDB::bind_method("_graph_connect_to_empty",&VisualScriptEditor::_graph_connect_to_empty);
-
- ClassDB::bind_method("_update_graph_connections",&VisualScriptEditor::_update_graph_connections);
- ClassDB::bind_method("_node_filter_changed",&VisualScriptEditor::_node_filter_changed);
-
- ClassDB::bind_method("_selected_method",&VisualScriptEditor::_selected_method);
- ClassDB::bind_method("_draw_color_over_button",&VisualScriptEditor::_draw_color_over_button);
-
-
-
-
+ ClassDB::bind_method("_member_button", &VisualScriptEditor::_member_button);
+ ClassDB::bind_method("_member_edited", &VisualScriptEditor::_member_edited);
+ ClassDB::bind_method("_member_selected", &VisualScriptEditor::_member_selected);
+ ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members);
+ ClassDB::bind_method("_change_base_type", &VisualScriptEditor::_change_base_type);
+ ClassDB::bind_method("_change_base_type_callback", &VisualScriptEditor::_change_base_type_callback);
+ ClassDB::bind_method("_override_pressed", &VisualScriptEditor::_override_pressed);
+ ClassDB::bind_method("_node_selected", &VisualScriptEditor::_node_selected);
+ ClassDB::bind_method("_node_moved", &VisualScriptEditor::_node_moved);
+ ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node);
+ ClassDB::bind_method("_begin_node_move", &VisualScriptEditor::_begin_node_move);
+ ClassDB::bind_method("_end_node_move", &VisualScriptEditor::_end_node_move);
+ ClassDB::bind_method("_remove_node", &VisualScriptEditor::_remove_node);
+ ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1));
+ ClassDB::bind_method("_node_ports_changed", &VisualScriptEditor::_node_ports_changed);
+ ClassDB::bind_method("_available_node_doubleclicked", &VisualScriptEditor::_available_node_doubleclicked);
+ ClassDB::bind_method("_default_value_edited", &VisualScriptEditor::_default_value_edited);
+ ClassDB::bind_method("_default_value_changed", &VisualScriptEditor::_default_value_changed);
+ ClassDB::bind_method("_menu_option", &VisualScriptEditor::_menu_option);
+ ClassDB::bind_method("_graph_ofs_changed", &VisualScriptEditor::_graph_ofs_changed);
+ ClassDB::bind_method("_center_on_node", &VisualScriptEditor::_center_on_node);
+ ClassDB::bind_method("_comment_node_resized", &VisualScriptEditor::_comment_node_resized);
+ ClassDB::bind_method("_button_resource_previewed", &VisualScriptEditor::_button_resource_previewed);
+ ClassDB::bind_method("_port_action_menu", &VisualScriptEditor::_port_action_menu);
+ ClassDB::bind_method("_selected_connect_node_method_or_setget", &VisualScriptEditor::_selected_connect_node_method_or_setget);
+ ClassDB::bind_method("_expression_text_changed", &VisualScriptEditor::_expression_text_changed);
+
+ ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw);
+ ClassDB::bind_method("can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw);
+ ClassDB::bind_method("drop_data_fw", &VisualScriptEditor::drop_data_fw);
+
+ ClassDB::bind_method("_input", &VisualScriptEditor::_input);
+ ClassDB::bind_method("_on_nodes_delete", &VisualScriptEditor::_on_nodes_delete);
+ ClassDB::bind_method("_on_nodes_duplicate", &VisualScriptEditor::_on_nodes_duplicate);
+
+ ClassDB::bind_method("_hide_timer", &VisualScriptEditor::_hide_timer);
+
+ ClassDB::bind_method("_graph_connected", &VisualScriptEditor::_graph_connected);
+ ClassDB::bind_method("_graph_disconnected", &VisualScriptEditor::_graph_disconnected);
+ ClassDB::bind_method("_graph_connect_to_empty", &VisualScriptEditor::_graph_connect_to_empty);
+
+ ClassDB::bind_method("_update_graph_connections", &VisualScriptEditor::_update_graph_connections);
+ ClassDB::bind_method("_node_filter_changed", &VisualScriptEditor::_node_filter_changed);
+
+ ClassDB::bind_method("_selected_method", &VisualScriptEditor::_selected_method);
+ ClassDB::bind_method("_draw_color_over_button", &VisualScriptEditor::_draw_color_over_button);
}
-
-
VisualScriptEditor::VisualScriptEditor() {
if (!clipboard) {
- clipboard = memnew( Clipboard );
+ clipboard = memnew(Clipboard);
}
- updating_graph=false;
+ updating_graph = false;
- edit_menu = memnew( MenuButton );
+ edit_menu = memnew(MenuButton);
edit_menu->set_text(TTR("Edit"));
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/delete_selected"), EDIT_DELETE_NODES);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/toggle_breakpoint"), EDIT_TOGGLE_BREAKPOINT);
@@ -3337,101 +3125,98 @@ VisualScriptEditor::VisualScriptEditor() {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/cut_nodes"), EDIT_CUT_NODES);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/paste_nodes"), EDIT_PASTE_NODES);
- edit_menu->get_popup()->connect("id_pressed",this,"_menu_option");
+ edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
- main_hsplit = memnew( HSplitContainer );
+ main_hsplit = memnew(HSplitContainer);
add_child(main_hsplit);
main_hsplit->set_area_as_parent_rect();
- left_vsplit = memnew( VSplitContainer );
+ left_vsplit = memnew(VSplitContainer);
main_hsplit->add_child(left_vsplit);
- VBoxContainer *left_vb = memnew( VBoxContainer );
+ 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);
- base_type_select->connect("pressed",this,"_change_base_type");
+ base_type_select = memnew(Button);
+ left_vb->add_margin_child(TTR("Base Type:"), base_type_select);
+ base_type_select->connect("pressed", this, "_change_base_type");
- members = memnew( Tree );
- left_vb->add_margin_child(TTR("Members:"),members,true);
+ members = memnew(Tree);
+ left_vb->add_margin_child(TTR("Members:"), members, true);
members->set_hide_root(true);
- members->connect("button_pressed",this,"_member_button");
- members->connect("item_edited",this,"_member_edited");
- members->connect("cell_selected",this,"_member_selected",varray(),CONNECT_DEFERRED);
+ members->connect("button_pressed", this, "_member_button");
+ members->connect("item_edited", this, "_member_edited");
+ members->connect("cell_selected", this, "_member_selected", varray(), CONNECT_DEFERRED);
members->set_single_select_cell_editing_only_when_already_selected(true);
members->set_hide_folding(true);
members->set_drag_forwarding(this);
-
- VBoxContainer *left_vb2 = memnew( VBoxContainer );
+ VBoxContainer *left_vb2 = memnew(VBoxContainer);
left_vsplit->add_child(left_vb2);
left_vb2->set_v_size_flags(SIZE_EXPAND_FILL);
-
- VBoxContainer *vbc_nodes = memnew( VBoxContainer );
- HBoxContainer *hbc_nodes = memnew( HBoxContainer );
- node_filter = memnew (LineEdit);
- node_filter->connect("text_changed",this,"_node_filter_changed");
+ VBoxContainer *vbc_nodes = memnew(VBoxContainer);
+ HBoxContainer *hbc_nodes = memnew(HBoxContainer);
+ node_filter = memnew(LineEdit);
+ 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 = 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 );
+ nodes = memnew(Tree);
vbc_nodes->add_child(nodes);
nodes->set_v_size_flags(SIZE_EXPAND_FILL);
- left_vb2->add_margin_child(TTR("Available Nodes:"),vbc_nodes,true);
+ left_vb2->add_margin_child(TTR("Available Nodes:"), vbc_nodes, true);
nodes->set_hide_root(true);
- nodes->connect("item_activated",this,"_available_node_doubleclicked");
+ nodes->connect("item_activated", this, "_available_node_doubleclicked");
nodes->set_drag_forwarding(this);
- graph = memnew( GraphEdit );
+ graph = memnew(GraphEdit);
main_hsplit->add_child(graph);
graph->set_h_size_flags(SIZE_EXPAND_FILL);
- graph->connect("node_selected",this,"_node_selected");
- graph->connect("_begin_node_move",this,"_begin_node_move");
- graph->connect("_end_node_move",this,"_end_node_move");
- graph->connect("delete_nodes_request",this,"_on_nodes_delete");
- graph->connect("duplicate_nodes_request",this,"_on_nodes_duplicate");
+ graph->connect("node_selected", this, "_node_selected");
+ graph->connect("_begin_node_move", this, "_begin_node_move");
+ graph->connect("_end_node_move", this, "_end_node_move");
+ graph->connect("delete_nodes_request", this, "_on_nodes_delete");
+ graph->connect("duplicate_nodes_request", this, "_on_nodes_duplicate");
graph->set_drag_forwarding(this);
graph->hide();
- graph->connect("scroll_offset_changed",this,"_graph_ofs_changed");
+ graph->connect("scroll_offset_changed", this, "_graph_ofs_changed");
- select_func_text = memnew( Label );
+ select_func_text = memnew(Label);
select_func_text->set_text(TTR("Select or create a function to edit graph"));
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);
-
- hint_text = memnew( Label );
- 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 = memnew(Label);
+ 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);
hint_text->set_valign(Label::VALIGN_CENTER);
graph->add_child(hint_text);
- hint_text_timer = memnew( Timer );
+ hint_text_timer = memnew(Timer);
hint_text_timer->set_wait_time(4);
- hint_text_timer->connect("timeout",this,"_hide_timer");
+ hint_text_timer->connect("timeout", this, "_hide_timer");
add_child(hint_text_timer);
//allowed casts (connections)
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- graph->add_valid_connection_type(Variant::NIL,i);
- graph->add_valid_connection_type(i,Variant::NIL);
- for(int j=0;j<Variant::VARIANT_MAX;j++) {
- if (Variant::can_convert(Variant::Type(i),Variant::Type(j))) {
- graph->add_valid_connection_type(i,j);
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ graph->add_valid_connection_type(Variant::NIL, i);
+ graph->add_valid_connection_type(i, Variant::NIL);
+ for (int j = 0; j < Variant::VARIANT_MAX; j++) {
+ if (Variant::can_convert(Variant::Type(i), Variant::Type(j))) {
+ graph->add_valid_connection_type(i, j);
}
}
@@ -3440,68 +3225,66 @@ VisualScriptEditor::VisualScriptEditor() {
graph->add_valid_left_disconnect_type(TYPE_SEQUENCE);
- graph->connect("connection_request",this,"_graph_connected");
- graph->connect("disconnection_request",this,"_graph_disconnected");
- graph->connect("connection_to_empty",this,"_graph_connect_to_empty");
+ graph->connect("connection_request", this, "_graph_connected");
+ graph->connect("disconnection_request", this, "_graph_disconnected");
+ graph->connect("connection_to_empty", this, "_graph_connect_to_empty");
- edit_signal_dialog = memnew( AcceptDialog );
+ edit_signal_dialog = memnew(AcceptDialog);
edit_signal_dialog->get_ok()->set_text(TTR("Close"));
add_child(edit_signal_dialog);
edit_signal_dialog->set_title(TTR("Edit Signal Arguments:"));
- signal_editor = memnew( VisualScriptEditorSignalEdit );
- edit_signal_edit = memnew( PropertyEditor );
+ signal_editor = memnew(VisualScriptEditorSignalEdit);
+ edit_signal_edit = memnew(PropertyEditor);
edit_signal_edit->hide_top_label();
edit_signal_dialog->add_child(edit_signal_edit);
edit_signal_edit->edit(signal_editor);
- edit_variable_dialog = memnew( AcceptDialog );
+ edit_variable_dialog = memnew(AcceptDialog);
edit_variable_dialog->get_ok()->set_text(TTR("Close"));
add_child(edit_variable_dialog);
edit_variable_dialog->set_title(TTR("Edit Variable:"));
- variable_editor = memnew( VisualScriptEditorVariableEdit );
- edit_variable_edit = memnew( PropertyEditor );
+ variable_editor = memnew(VisualScriptEditorVariableEdit);
+ edit_variable_edit = memnew(PropertyEditor);
edit_variable_edit->hide_top_label();
edit_variable_dialog->add_child(edit_variable_edit);
edit_variable_edit->edit(variable_editor);
- select_base_type=memnew(CreateDialog);
+ select_base_type = memnew(CreateDialog);
select_base_type->set_base_type("Object"); //anything goes
- select_base_type->connect("create",this,"_change_base_type_callback");
+ select_base_type->connect("create", this, "_change_base_type_callback");
select_base_type->get_ok()->set_text(TTR("Change"));
add_child(select_base_type);
undo_redo = EditorNode::get_singleton()->get_undo_redo();
- new_function_menu = memnew( PopupMenu );
- new_function_menu->connect("id_pressed",this,"_override_pressed");
+ new_function_menu = memnew(PopupMenu);
+ new_function_menu->connect("id_pressed", this, "_override_pressed");
add_child(new_function_menu);
- updating_members=false;
+ updating_members = false;
set_process_input(true); //for revert on drag
set_process_unhandled_input(true); //for revert on drag
- default_value_edit= memnew( CustomPropertyEditor);
+ default_value_edit = memnew(CustomPropertyEditor);
add_child(default_value_edit);
- default_value_edit->connect("variant_changed",this,"_default_value_changed");
+ default_value_edit->connect("variant_changed", this, "_default_value_changed");
- method_select = memnew( PropertySelector );
+ method_select = memnew(PropertySelector);
add_child(method_select);
- method_select->connect("selected",this,"_selected_method");
- error_line=-1;
+ method_select->connect("selected", this, "_selected_method");
+ error_line = -1;
- new_connect_node_select = memnew( PropertySelector );
+ new_connect_node_select = memnew(PropertySelector);
add_child(new_connect_node_select);
- new_connect_node_select->connect("selected",this,"_selected_connect_node_method_or_setget");
+ new_connect_node_select->connect("selected", this, "_selected_connect_node_method_or_setget");
- port_action_popup = memnew( PopupMenu );
+ port_action_popup = memnew(PopupMenu);
add_child(port_action_popup);
- port_action_popup->connect("id_pressed",this,"_port_action_menu");
-
-
+ port_action_popup->connect("id_pressed", this, "_port_action_menu");
}
VisualScriptEditor::~VisualScriptEditor() {
@@ -3511,17 +3294,16 @@ VisualScriptEditor::~VisualScriptEditor() {
memdelete(variable_editor);
}
-static ScriptEditorBase * create_editor(const Ref<Script>& p_script) {
+static ScriptEditorBase *create_editor(const Ref<Script> &p_script) {
if (p_script->cast_to<VisualScript>()) {
- return memnew( VisualScriptEditor );
+ return memnew(VisualScriptEditor);
}
return NULL;
}
-
-VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard=NULL;
+VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard = NULL;
void VisualScriptEditor::free_clipboard() {
if (clipboard)
@@ -3531,30 +3313,25 @@ void VisualScriptEditor::free_clipboard() {
static void register_editor_callback() {
ScriptEditor::register_create_script_editor_function(create_editor);
- 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_custom",Color(0.8,1.0,1.0));
- EditorSettings::get_singleton()->set("editors/visual_script/color_constants",Color(1.0,0.8,1.0));
-
+ 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_custom", Color(0.8, 1.0, 1.0));
+ EditorSettings::get_singleton()->set("editors/visual_script/color_constants", Color(1.0, 0.8, 1.0));
ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"));
ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
- ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD+KEY_F);
- ED_SHORTCUT("visual_script_editor/copy_nodes", TTR("Copy Nodes"), KEY_MASK_CMD+KEY_C);
- ED_SHORTCUT("visual_script_editor/cut_nodes", TTR("Cut Nodes"), KEY_MASK_CMD+KEY_X);
- ED_SHORTCUT("visual_script_editor/paste_nodes", TTR("Paste Nodes"), KEY_MASK_CMD+KEY_V);
-
+ ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD + KEY_F);
+ ED_SHORTCUT("visual_script_editor/copy_nodes", TTR("Copy Nodes"), KEY_MASK_CMD + KEY_C);
+ ED_SHORTCUT("visual_script_editor/cut_nodes", TTR("Cut Nodes"), KEY_MASK_CMD + KEY_X);
+ ED_SHORTCUT("visual_script_editor/paste_nodes", TTR("Paste Nodes"), KEY_MASK_CMD + KEY_V);
}
void VisualScriptEditor::register_editor() {
//too early to register stuff here, request a callback
EditorNode::add_plugin_init_callback(register_editor_callback);
-
-
-
}
#endif
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h
index cdaef8d0ce..5ece1c9e2c 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/visual_script_editor.h
@@ -29,26 +29,23 @@
#ifndef VISUALSCRIPT_EDITOR_H
#define VISUALSCRIPT_EDITOR_H
+#include "editor/create_dialog.h"
#include "editor/plugins/script_editor_plugin.h"
-#include "visual_script.h"
#include "editor/property_editor.h"
-#include "scene/gui/graph_edit.h"
-#include "editor/create_dialog.h"
#include "editor/property_selector.h"
+#include "scene/gui/graph_edit.h"
+#include "visual_script.h"
class VisualScriptEditorSignalEdit;
class VisualScriptEditorVariableEdit;
-
#ifdef TOOLS_ENABLED
-
class VisualScriptEditor : public ScriptEditorBase {
- GDCLASS(VisualScriptEditor,ScriptEditorBase)
+ GDCLASS(VisualScriptEditor, ScriptEditorBase)
enum {
- TYPE_SEQUENCE=1000,
- INDEX_BASE_SEQUENCE=1024
-
+ TYPE_SEQUENCE = 1000,
+ INDEX_BASE_SEQUENCE = 1024
};
@@ -115,7 +112,7 @@ class VisualScriptEditor : public ScriptEditorBase {
bool updating_graph;
- void _show_hint(const String& p_hint);
+ void _show_hint(const String &p_hint);
void _hide_timer();
CreateDialog *select_base_type;
@@ -124,18 +121,17 @@ class VisualScriptEditor : public ScriptEditorBase {
String name;
Variant::Type ret;
bool ret_variant;
- Vector< Pair<Variant::Type,String> > args;
+ Vector<Pair<Variant::Type, String> > args;
};
- Map<int,VirtualInMenu> virtuals_in_menu;
+ Map<int, VirtualInMenu> virtuals_in_menu;
PopupMenu *new_function_menu;
-
StringName edited_func;
void _update_graph_connections();
- void _update_graph(int p_only_id=-1);
+ void _update_graph(int p_only_id = -1);
bool updating_members;
@@ -143,12 +139,12 @@ class VisualScriptEditor : public ScriptEditorBase {
StringName selected;
- String _validate_name(const String& p_name) const;
+ String _validate_name(const String &p_name) const;
struct Clipboard {
- Map<int,Ref<VisualScriptNode> > nodes;
- Map<int,Vector2 > nodes_positions;
+ Map<int, Ref<VisualScriptNode> > nodes;
+ Map<int, Vector2> nodes_positions;
Set<VisualScript::SequenceConnection> sequence_connections;
Set<VisualScript::DataConnection> data_connections;
@@ -164,15 +160,14 @@ class VisualScriptEditor : public ScriptEditorBase {
Vector2 port_action_pos;
int port_action_new_node;
void _port_action_menu(int p_option);
- void _selected_connect_node_method_or_setget(const String& p_text);
-
+ void _selected_connect_node_method_or_setget(const String &p_text);
int error_line;
- void _node_selected(Node* p_node);
+ void _node_selected(Node *p_node);
void _center_on_node(int p_id);
- void _node_filter_changed(const String& p_text);
+ void _node_filter_changed(const String &p_text);
void _change_base_type_callback();
void _change_base_type();
void _member_selected();
@@ -181,82 +176,78 @@ class VisualScriptEditor : public ScriptEditorBase {
void _begin_node_move();
void _end_node_move();
- void _move_node(String func,int p_id,const Vector2& p_to);
+ void _move_node(String func, int p_id, const Vector2 &p_to);
- void _node_moved(Vector2 p_from,Vector2 p_to, int p_id);
+ void _node_moved(Vector2 p_from, Vector2 p_to, int p_id);
void _remove_node(int p_id);
- void _graph_connected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot);
- void _graph_disconnected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot);
- void _graph_connect_to_empty(const String& p_from,int p_from_slot,const Vector2& p_release_pos);
+ void _graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
+ void _graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
+ void _graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos);
- void _node_ports_changed(const String& p_func,int p_id);
+ void _node_ports_changed(const String &p_func, int p_id);
void _available_node_doubleclicked();
void _update_available_nodes();
void _member_button(Object *p_item, int p_column, int p_button);
- void _expression_text_changed(const String& p_text,int p_id);
-
+ void _expression_text_changed(const String &p_text, int p_id);
String revert_on_drag;
- void _input(const InputEvent& p_event);
+ void _input(const InputEvent &p_event);
void _on_nodes_delete();
void _on_nodes_duplicate();
- Variant get_drag_data_fw(const Point2& p_point,Control* p_from);
- bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const;
- void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from);
-
+ Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
+ bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
+ void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
int editing_id;
int editing_input;
void _default_value_changed();
- void _default_value_edited(Node * p_button,int p_id,int p_input_port);
+ void _default_value_edited(Node *p_button, int p_id, int p_input_port);
void _menu_option(int p_what);
- void _graph_ofs_changed(const Vector2& p_ofs);
- void _comment_node_resized(const Vector2& p_new_size,int p_node);
+ void _graph_ofs_changed(const Vector2 &p_ofs);
+ void _comment_node_resized(const Vector2 &p_new_size, int p_node);
int selecting_method_id;
- void _selected_method(const String& p_method);
+ void _selected_method(const String &p_method);
- void _draw_color_over_button(Object* obj,Color p_color);
- void _button_resource_previewed(const String& p_path,const Ref<Texture>& p_preview,Variant p_ud);
-
- VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node,int p_port_action_output,Set<int> &visited_nodes);
+ void _draw_color_over_button(Object *obj, Color p_color);
+ void _button_resource_previewed(const String &p_path, const Ref<Texture> &p_preview, Variant p_ud);
+ VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes);
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
virtual void apply_code();
virtual Ref<Script> get_edited_script() const;
virtual Vector<String> get_functions();
- virtual void set_edited_script(const Ref<Script>& p_script);
+ virtual void set_edited_script(const Ref<Script> &p_script);
virtual void reload_text();
virtual String get_name();
virtual Ref<Texture> get_icon();
virtual bool is_unsaved();
virtual Variant get_edit_state();
- virtual void set_edit_state(const Variant& p_state);
- virtual void goto_line(int p_line,bool p_with_error=false);
+ 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 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 bool goto_method(const String &p_method);
+ virtual void add_callback(const String &p_function, PoolStringArray p_args);
virtual void update_settings();
virtual void set_debugger_active(bool p_active);
- virtual void set_tooltip_request_func(String p_method,Object* p_obj);
+ virtual void set_tooltip_request_func(String p_method, Object *p_obj);
virtual Control *get_edit_menu();
virtual bool can_lose_focus_on_node_selection() { return false; }
diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp
index 3d15e696ef..741b422848 100644
--- a/modules/visual_script/visual_script_expression.cpp
+++ b/modules/visual_script/visual_script_expression.cpp
@@ -28,41 +28,40 @@
/*************************************************************************/
#include "visual_script_expression.h"
+bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_value) {
-bool VisualScriptExpression::_set(const StringName& p_name, const Variant& p_value) {
-
- if (String(p_name)=="expression") {
- expression=p_value;
- expression_dirty=true;
+ if (String(p_name) == "expression") {
+ expression = p_value;
+ expression_dirty = true;
ports_changed_notify();
return true;
}
- if (String(p_name)=="out_type") {
- output_type=Variant::Type(int(p_value));
- expression_dirty=true;
+ if (String(p_name) == "out_type") {
+ output_type = Variant::Type(int(p_value));
+ expression_dirty = true;
ports_changed_notify();
return true;
}
- if (String(p_name)=="sequenced") {
- sequenced=p_value;
+ if (String(p_name) == "sequenced") {
+ sequenced = p_value;
ports_changed_notify();
return true;
}
- if (String(p_name)=="input_count") {
+ if (String(p_name) == "input_count") {
- int from=inputs.size();
+ int from = inputs.size();
inputs.resize(int(p_value));
- for(int i=from;i<inputs.size();i++) {
- inputs[i].name=String::chr('a'+i);
- if (from==0) {
- inputs[i].type=output_type;
+ for (int i = from; i < inputs.size(); i++) {
+ inputs[i].name = String::chr('a' + i);
+ if (from == 0) {
+ inputs[i].type = output_type;
} else {
- inputs[i].type=inputs[from-1].type;
+ inputs[i].type = inputs[from - 1].type;
}
}
- expression_dirty=true;
+ expression_dirty = true;
ports_changed_notify();
_change_notify();
return true;
@@ -70,66 +69,64 @@ bool VisualScriptExpression::_set(const StringName& p_name, const Variant& p_val
if (String(p_name).begins_with("input/")) {
- int idx=String(p_name).get_slice("/",1).to_int();
- ERR_FAIL_INDEX_V(idx,inputs.size(),false);
+ int idx = String(p_name).get_slice("/", 1).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("/", 2);
- if (what=="type") {
+ if (what == "type") {
- inputs[idx].type=Variant::Type(int(p_value));
- } else if (what=="name") {
+ inputs[idx].type = Variant::Type(int(p_value));
+ } else if (what == "name") {
- inputs[idx].name=p_value;
+ inputs[idx].name = p_value;
} else {
return false;
}
- expression_dirty=true;
+ expression_dirty = true;
ports_changed_notify();
return true;
}
-
return false;
-
}
-bool VisualScriptExpression::_get(const StringName& p_name,Variant &r_ret) const {
+bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) const {
- if (String(p_name)=="expression") {
- r_ret=expression;
+ if (String(p_name) == "expression") {
+ r_ret = expression;
return true;
}
- if (String(p_name)=="out_type") {
- r_ret=output_type;
+ if (String(p_name) == "out_type") {
+ r_ret = output_type;
return true;
}
- if (String(p_name)=="sequenced") {
- r_ret=sequenced;
+ if (String(p_name) == "sequenced") {
+ r_ret = sequenced;
return true;
}
- if (String(p_name)=="input_count") {
- r_ret=inputs.size();
+ if (String(p_name) == "input_count") {
+ r_ret = inputs.size();
return true;
}
if (String(p_name).begins_with("input/")) {
- int idx=String(p_name).get_slice("/",1).to_int();
- ERR_FAIL_INDEX_V(idx,inputs.size(),false);
+ int idx = String(p_name).get_slice("/", 1).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("/", 2);
- if (what=="type") {
+ if (what == "type") {
- r_ret=inputs[idx].type;
- } else if (what=="name") {
+ r_ret = inputs[idx].type;
+ } else if (what == "name") {
- r_ret=inputs[idx].name;
+ r_ret = inputs[idx].name;
} else {
return false;
}
@@ -137,310 +134,296 @@ bool VisualScriptExpression::_get(const StringName& p_name,Variant &r_ret) const
return true;
}
-
return false;
}
-void VisualScriptExpression::_get_property_list( List<PropertyInfo> *p_list) const {
-
+void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) const {
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- p_list->push_back(PropertyInfo(Variant::STRING,"expression",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR));
- p_list->push_back(PropertyInfo(Variant::INT,"out_type",PROPERTY_HINT_ENUM,argt));
- p_list->push_back(PropertyInfo(Variant::INT,"input_count",PROPERTY_HINT_RANGE,"0,64,1"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"sequenced"));
+ p_list->push_back(PropertyInfo(Variant::STRING, "expression", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_list->push_back(PropertyInfo(Variant::INT, "out_type", PROPERTY_HINT_ENUM, argt));
+ p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,64,1"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced"));
- for(int i=0;i<inputs.size();i++) {
+ 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"));
}
}
int VisualScriptExpression::get_output_sequence_port_count() const {
- return sequenced?1:0;
+ return sequenced ? 1 : 0;
}
-bool VisualScriptExpression::has_input_sequence_port() const{
+bool VisualScriptExpression::has_input_sequence_port() const {
return sequenced;
}
-
-String VisualScriptExpression::get_output_sequence_port_text(int p_port) const{
+String VisualScriptExpression::get_output_sequence_port_text(int p_port) const {
return String();
}
-
-int VisualScriptExpression::get_input_value_port_count() const{
+int VisualScriptExpression::get_input_value_port_count() const {
return inputs.size();
-
}
-int VisualScriptExpression::get_output_value_port_count() const{
+int VisualScriptExpression::get_output_value_port_count() const {
return 1;
}
+PropertyInfo VisualScriptExpression::get_input_value_port_info(int p_idx) const {
-PropertyInfo VisualScriptExpression::get_input_value_port_info(int p_idx) const{
-
- return PropertyInfo(inputs[p_idx].type,inputs[p_idx].name);
+ return PropertyInfo(inputs[p_idx].type, inputs[p_idx].name);
}
-PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(output_type,"result");
+ return PropertyInfo(output_type, "result");
}
-String VisualScriptExpression::get_caption() const{
+String VisualScriptExpression::get_caption() const {
return "Expression";
}
-String VisualScriptExpression::get_text() const{
+String VisualScriptExpression::get_text() const {
return expression;
}
-
-Error VisualScriptExpression::_get_token(Token& r_token) {
+Error VisualScriptExpression::_get_token(Token &r_token) {
while (true) {
-#define GET_CHAR() (str_ofs>=expression.length()?0:expression[str_ofs++])
+#define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++])
CharType cchar = GET_CHAR();
- if (cchar==0) {
- r_token.type=TK_EOF;
+ if (cchar == 0) {
+ r_token.type = TK_EOF;
return OK;
}
-
- switch(cchar) {
+ switch (cchar) {
case 0: {
- r_token.type=TK_EOF;
+ r_token.type = TK_EOF;
return OK;
} break;
case '{': {
- r_token.type=TK_CURLY_BRACKET_OPEN;
+ r_token.type = TK_CURLY_BRACKET_OPEN;
return OK;
};
case '}': {
- r_token.type=TK_CURLY_BRACKET_CLOSE;
+ r_token.type = TK_CURLY_BRACKET_CLOSE;
return OK;
};
case '[': {
- r_token.type=TK_BRACKET_OPEN;
+ r_token.type = TK_BRACKET_OPEN;
return OK;
};
case ']': {
- r_token.type=TK_BRACKET_CLOSE;
+ r_token.type = TK_BRACKET_CLOSE;
return OK;
};
case '(': {
- r_token.type=TK_PARENTHESIS_OPEN;
+ r_token.type = TK_PARENTHESIS_OPEN;
return OK;
};
case ')': {
- r_token.type=TK_PARENTHESIS_CLOSE;
+ r_token.type = TK_PARENTHESIS_CLOSE;
return OK;
};
case ',': {
- r_token.type=TK_COMMA;
+ r_token.type = TK_COMMA;
return OK;
};
case ':': {
- r_token.type=TK_COLON;
+ r_token.type = TK_COLON;
return OK;
};
case '.': {
- r_token.type=TK_PERIOD;
+ r_token.type = TK_PERIOD;
return OK;
};
case '=': {
- cchar=GET_CHAR();
- if (cchar=='=') {
- r_token.type=TK_OP_EQUAL;
+ cchar = GET_CHAR();
+ if (cchar == '=') {
+ r_token.type = TK_OP_EQUAL;
} else {
_set_error("Expected '='");
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
return OK;
};
case '!': {
- if (expression[str_ofs]=='=') {
- r_token.type=TK_OP_NOT_EQUAL;
+ if (expression[str_ofs] == '=') {
+ r_token.type = TK_OP_NOT_EQUAL;
str_ofs++;
} else {
- r_token.type=TK_OP_NOT;
+ r_token.type = TK_OP_NOT;
}
return OK;
};
case '>': {
- if (expression[str_ofs]=='=') {
- r_token.type=TK_OP_GREATER_EQUAL;
+ if (expression[str_ofs] == '=') {
+ r_token.type = TK_OP_GREATER_EQUAL;
str_ofs++;
- } else if (expression[str_ofs]=='>') {
- r_token.type=TK_OP_SHIFT_RIGHT;
+ } else if (expression[str_ofs] == '>') {
+ r_token.type = TK_OP_SHIFT_RIGHT;
str_ofs++;
} else {
- r_token.type=TK_OP_GREATER;
+ r_token.type = TK_OP_GREATER;
}
return OK;
};
case '<': {
- if (expression[str_ofs]=='=') {
- r_token.type=TK_OP_LESS_EQUAL;
+ if (expression[str_ofs] == '=') {
+ r_token.type = TK_OP_LESS_EQUAL;
str_ofs++;
- } else if (expression[str_ofs]=='<') {
- r_token.type=TK_OP_SHIFT_LEFT;
+ } else if (expression[str_ofs] == '<') {
+ r_token.type = TK_OP_SHIFT_LEFT;
str_ofs++;
} else {
- r_token.type=TK_OP_LESS;
+ r_token.type = TK_OP_LESS;
}
return OK;
};
case '+': {
- r_token.type=TK_OP_ADD;
+ r_token.type = TK_OP_ADD;
return OK;
};
case '-': {
- r_token.type=TK_OP_SUB;
+ r_token.type = TK_OP_SUB;
return OK;
};
case '/': {
- r_token.type=TK_OP_DIV;
+ r_token.type = TK_OP_DIV;
return OK;
};
case '*': {
- r_token.type=TK_OP_MUL;
+ r_token.type = TK_OP_MUL;
return OK;
};
case '%': {
- r_token.type=TK_OP_MOD;
+ r_token.type = TK_OP_MOD;
return OK;
};
case '&': {
- if (expression[str_ofs]=='&') {
- r_token.type=TK_OP_AND;
+ if (expression[str_ofs] == '&') {
+ r_token.type = TK_OP_AND;
str_ofs++;
} else {
- r_token.type=TK_OP_BIT_AND;
+ r_token.type = TK_OP_BIT_AND;
}
return OK;
};
case '|': {
- if (expression[str_ofs]=='|') {
- r_token.type=TK_OP_OR;
+ if (expression[str_ofs] == '|') {
+ r_token.type = TK_OP_OR;
str_ofs++;
} else {
- r_token.type=TK_OP_BIT_OR;
+ r_token.type = TK_OP_BIT_OR;
}
return OK;
};
case '^': {
- r_token.type=TK_OP_BIT_XOR;
+ r_token.type = TK_OP_BIT_XOR;
return OK;
};
case '~': {
- r_token.type=TK_OP_BIT_INVERT;
+ r_token.type = TK_OP_BIT_INVERT;
return OK;
};
case '"': {
-
String str;
- while(true) {
+ while (true) {
- CharType ch=GET_CHAR();
+ CharType ch = GET_CHAR();
- if (ch==0) {
+ if (ch == 0) {
_set_error("Unterminated String");
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
- } else if (ch=='"') {
+ } else if (ch == '"') {
break;
- } else if (ch=='\\') {
+ } else if (ch == '\\') {
//escaped characters...
CharType next = GET_CHAR();
- if (next==0) {
+ if (next == 0) {
_set_error("Unterminated String");
- r_token.type=TK_ERROR;
- return ERR_PARSE_ERROR;
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
}
- CharType res=0;
+ CharType res = 0;
- switch(next) {
+ switch (next) {
- case 'b': res=8; break;
- case 't': res=9; break;
- case 'n': res=10; break;
- case 'f': res=12; break;
- case 'r': res=13; break;
+ case 'b': res = 8; break;
+ case 't': res = 9; break;
+ case 'n': res = 10; break;
+ case 'f': res = 12; break;
+ case 'r': res = 13; break;
case 'u': {
//hexnumbarh - oct is deprecated
-
- for(int j=0;j<4;j++) {
+ for (int j = 0; j < 4; j++) {
CharType c = GET_CHAR();
- if (c==0) {
+ if (c == 0) {
_set_error("Unterminated String");
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
- if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) {
+ if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
_set_error("Malformed hex constant in string");
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
CharType v;
- if (c>='0' && c<='9') {
- v=c-'0';
- } else if (c>='a' && c<='f') {
- v=c-'a';
- v+=10;
- } else if (c>='A' && c<='F') {
- v=c-'A';
- v+=10;
+ if (c >= '0' && c <= '9') {
+ v = c - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ v = c - 'a';
+ v += 10;
+ } else if (c >= 'A' && c <= 'F') {
+ v = c - 'A';
+ v += 10;
} else {
ERR_PRINT("BUG");
- v=0;
+ v = 0;
}
- res<<=4;
- res|=v;
-
-
+ res <<= 4;
+ res |= v;
}
-
-
} break;
//case '\"': res='\"'; break;
//case '\\': res='\\'; break;
@@ -452,408 +435,397 @@ Error VisualScriptExpression::_get_token(Token& r_token) {
} break;
}
- str+=res;
+ str += res;
} else {
- str+=ch;
+ str += ch;
}
}
- r_token.type=TK_CONSTANT;
- r_token.value=str;
+ r_token.type = TK_CONSTANT;
+ r_token.value = str;
return OK;
} break;
default: {
- if (cchar<=32) {
+ if (cchar <= 32) {
break;
}
- if (cchar=='-' || (cchar>='0' && cchar<='9')) {
+ if (cchar == '-' || (cchar >= '0' && cchar <= '9')) {
//a number
-
String num;
#define READING_SIGN 0
#define READING_INT 1
#define READING_DEC 2
#define READING_EXP 3
#define READING_DONE 4
- int reading=READING_INT;
-
- if (cchar=='-') {
- num+='-';
- cchar=GET_CHAR();
+ int reading = READING_INT;
+ if (cchar == '-') {
+ num += '-';
+ cchar = GET_CHAR();
}
-
-
CharType c = cchar;
- bool exp_sign=false;
- bool exp_beg=false;
- bool is_float=false;
+ bool exp_sign = false;
+ bool exp_beg = false;
+ bool is_float = false;
- while(true) {
+ while (true) {
- switch(reading) {
+ switch (reading) {
case READING_INT: {
- if (c>='0' && c<='9') {
+ if (c >= '0' && c <= '9') {
//pass
- } else if (c=='.') {
- reading=READING_DEC;
- is_float=true;
- } else if (c=='e') {
- reading=READING_EXP;
+ } else if (c == '.') {
+ reading = READING_DEC;
+ is_float = true;
+ } else if (c == 'e') {
+ reading = READING_EXP;
} else {
- reading=READING_DONE;
+ reading = READING_DONE;
}
- } break;
+ } break;
case READING_DEC: {
- if (c>='0' && c<='9') {
+ if (c >= '0' && c <= '9') {
- } else if (c=='e') {
- reading=READING_EXP;
+ } else if (c == 'e') {
+ reading = READING_EXP;
} else {
- reading=READING_DONE;
+ reading = READING_DONE;
}
- } break;
+ } break;
case READING_EXP: {
- if (c>='0' && c<='9') {
- exp_beg=true;
+ if (c >= '0' && c <= '9') {
+ exp_beg = true;
- } else if ((c=='-' || c=='+') && !exp_sign && !exp_beg) {
- if (c=='-')
- is_float=true;
- exp_sign=true;
+ } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
+ if (c == '-')
+ is_float = true;
+ exp_sign = true;
} else {
- reading=READING_DONE;
+ reading = READING_DONE;
}
- } break;
+ } break;
}
- if (reading==READING_DONE)
+ if (reading == READING_DONE)
break;
- num+=String::chr(c);
+ num += String::chr(c);
c = GET_CHAR();
-
-
}
str_ofs--;
- r_token.type=TK_CONSTANT;
+ r_token.type = TK_CONSTANT;
if (is_float)
- r_token.value=num.to_double();
+ r_token.value = num.to_double();
else
- r_token.value=num.to_int();
+ r_token.value = num.to_int();
return OK;
- } else if ((cchar>='A' && cchar<='Z') || (cchar>='a' && cchar<='z') || cchar=='_') {
+ } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
String id;
- bool first=true;
+ bool first = true;
- while((cchar>='A' && cchar<='Z') || (cchar>='a' && cchar<='z') || cchar=='_' || (!first && cchar>='0' && cchar<='9')) {
+ while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
- id+=String::chr(cchar);
- cchar=GET_CHAR();
- first=false;
+ id += String::chr(cchar);
+ cchar = GET_CHAR();
+ first = false;
}
str_ofs--; //go back one
- if (id=="in") {
- r_token.type=TK_OP_IN;
- } else if (id=="null") {
- r_token.type=TK_CONSTANT;
- r_token.value=Variant();
- } else if (id=="true") {
- r_token.type=TK_CONSTANT;
- r_token.value=true;
- } else if (id=="false") {
- r_token.type=TK_CONSTANT;
- r_token.value=false;
- } else if (id=="PI") {
- r_token.type=TK_CONSTANT;
- r_token.value=Math_PI;
+ if (id == "in") {
+ r_token.type = TK_OP_IN;
+ } else if (id == "null") {
+ r_token.type = TK_CONSTANT;
+ r_token.value = Variant();
+ } else if (id == "true") {
+ r_token.type = TK_CONSTANT;
+ r_token.value = true;
+ } else if (id == "false") {
+ r_token.type = TK_CONSTANT;
+ r_token.value = false;
+ } else if (id == "PI") {
+ r_token.type = TK_CONSTANT;
+ r_token.value = Math_PI;
} else if (id == "INF") {
r_token.type = TK_CONSTANT;
r_token.value = Math_INF;
} else if (id == "NAN") {
r_token.type = TK_CONSTANT;
r_token.value = Math_NAN;
- } else if (id=="not") {
- r_token.type=TK_OP_NOT;
- } else if (id=="or") {
- r_token.type=TK_OP_OR;
- } else if (id=="and") {
- r_token.type=TK_OP_AND;
- } else if (id=="self") {
- r_token.type=TK_SELF;
+ } else if (id == "not") {
+ r_token.type = TK_OP_NOT;
+ } else if (id == "or") {
+ r_token.type = TK_OP_OR;
+ } else if (id == "and") {
+ r_token.type = TK_OP_AND;
+ } else if (id == "self") {
+ r_token.type = TK_SELF;
} else {
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (id==Variant::get_type_name(Variant::Type(i))) {
- r_token.type=TK_BASIC_TYPE;
- r_token.value=i;
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (id == Variant::get_type_name(Variant::Type(i))) {
+ r_token.type = TK_BASIC_TYPE;
+ r_token.value = i;
return OK;
break;
}
}
VisualScriptBuiltinFunc::BuiltinFunc bifunc = VisualScriptBuiltinFunc::find_function(id);
- if (bifunc!=VisualScriptBuiltinFunc::FUNC_MAX) {
- r_token.type=TK_BUILTIN_FUNC;
- r_token.value=bifunc;
+ if (bifunc != VisualScriptBuiltinFunc::FUNC_MAX) {
+ r_token.type = TK_BUILTIN_FUNC;
+ r_token.value = bifunc;
return OK;
}
- r_token.type=TK_IDENTIFIER;
- r_token.value=id;
+ r_token.type = TK_IDENTIFIER;
+ r_token.value = id;
}
return OK;
} else {
_set_error("Unexpected character.");
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
}
}
}
- r_token.type=TK_ERROR;
+ r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
-const char* VisualScriptExpression::token_name[TK_MAX]={
-"CURLY BRACKET OPEN",
-"CURLY BRACKET CLOSE",
-"BRACKET OPEN",
-"BRACKET CLOSE",
-"PARENTHESIS OPEN",
-"PARENTHESIS CLOSE",
-"IDENTIFIER",
-"BUILTIN FUNC",
-"SELF",
-"CONSTANT",
-"BASIC TYPE",
-"COLON",
-"COMMA",
-"PERIOD",
-"OP IN",
-"OP EQUAL",
-"OP NOT EQUAL",
-"OP LESS",
-"OP LESS EQUAL",
-"OP GREATER",
-"OP GREATER EQUAL",
-"OP AND",
-"OP OR",
-"OP NOT",
-"OP ADD",
-"OP SUB",
-"OP MUL",
-"OP DIV",
-"OP MOD",
-"OP SHIFT LEFT",
-"OP SHIFT RIGHT",
-"OP BIT AND",
-"OP BIT OR",
-"OP BIT XOR",
-"OP BIT INVERT",
-"EOF",
-"ERROR"
+const char *VisualScriptExpression::token_name[TK_MAX] = {
+ "CURLY BRACKET OPEN",
+ "CURLY BRACKET CLOSE",
+ "BRACKET OPEN",
+ "BRACKET CLOSE",
+ "PARENTHESIS OPEN",
+ "PARENTHESIS CLOSE",
+ "IDENTIFIER",
+ "BUILTIN FUNC",
+ "SELF",
+ "CONSTANT",
+ "BASIC TYPE",
+ "COLON",
+ "COMMA",
+ "PERIOD",
+ "OP IN",
+ "OP EQUAL",
+ "OP NOT EQUAL",
+ "OP LESS",
+ "OP LESS EQUAL",
+ "OP GREATER",
+ "OP GREATER EQUAL",
+ "OP AND",
+ "OP OR",
+ "OP NOT",
+ "OP ADD",
+ "OP SUB",
+ "OP MUL",
+ "OP DIV",
+ "OP MOD",
+ "OP SHIFT LEFT",
+ "OP SHIFT RIGHT",
+ "OP BIT AND",
+ "OP BIT OR",
+ "OP BIT XOR",
+ "OP BIT INVERT",
+ "EOF",
+ "ERROR"
};
-VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
-
+VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
Vector<Expression> expression;
- while(true) {
+ while (true) {
//keep appending stuff to expression
- ENode*expr=NULL;
+ ENode *expr = NULL;
Token tk;
_get_token(tk);
if (error_set)
return NULL;
-
-
- switch(tk.type) {
+ switch (tk.type) {
case TK_CURLY_BRACKET_OPEN: {
//a dictionary
DictionaryNode *dn = alloc_node<DictionaryNode>();
+ while (true) {
- while(true) {
-
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_CURLY_BRACKET_CLOSE) {
+ if (tk.type == TK_CURLY_BRACKET_CLOSE) {
break;
}
- str_ofs=cofs; //revert
+ str_ofs = cofs; //revert
//parse an expression
- ENode* expr=_parse_expression();
+ ENode *expr = _parse_expression();
if (!expr)
return NULL;
dn->dict.push_back(expr);
_get_token(tk);
- if (tk.type!=TK_COLON) {
+ if (tk.type != TK_COLON) {
_set_error("Expected ':'");
return NULL;
}
- expr=_parse_expression();
+ expr = _parse_expression();
if (!expr)
return NULL;
dn->dict.push_back(expr);
- cofs=str_ofs;
+ cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_COMMA) {
+ if (tk.type == TK_COMMA) {
//all good
- } else if (tk.type==TK_CURLY_BRACKET_CLOSE) {
- str_ofs=cofs;
+ } else if (tk.type == TK_CURLY_BRACKET_CLOSE) {
+ str_ofs = cofs;
} else {
_set_error("Expected ',' or '}'");
}
}
- expr=dn;
+ expr = dn;
} break;
case TK_BRACKET_OPEN: {
//an array
ArrayNode *an = alloc_node<ArrayNode>();
+ while (true) {
- while(true) {
-
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_BRACKET_CLOSE) {
+ if (tk.type == TK_BRACKET_CLOSE) {
break;
}
- str_ofs=cofs; //revert
+ str_ofs = cofs; //revert
//parse an expression
- ENode* expr=_parse_expression();
+ ENode *expr = _parse_expression();
if (!expr)
return NULL;
an->array.push_back(expr);
- cofs=str_ofs;
+ cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_COMMA) {
+ if (tk.type == TK_COMMA) {
//all good
- } else if (tk.type==TK_BRACKET_CLOSE) {
- str_ofs=cofs;
+ } else if (tk.type == TK_BRACKET_CLOSE) {
+ str_ofs = cofs;
} else {
_set_error("Expected ',' or ']'");
}
}
- expr=an;
+ expr = an;
} break;
case TK_PARENTHESIS_OPEN: {
//a suexpression
- ENode* e=_parse_expression();
+ ENode *e = _parse_expression();
if (error_set)
return NULL;
_get_token(tk);
- if (tk.type!=TK_PARENTHESIS_CLOSE) {
+ if (tk.type != TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')'");
return NULL;
}
- expr=e;
+ expr = e;
} break;
case TK_IDENTIFIER: {
String what = tk.value;
- int index=-1;
- for(int i=0;i<inputs.size();i++) {
- if (what==inputs[i].name) {
- index=i;
+ int index = -1;
+ for (int i = 0; i < inputs.size(); i++) {
+ if (what == inputs[i].name) {
+ index = i;
break;
}
}
- if (index!=-1) {
+ if (index != -1) {
InputNode *input = alloc_node<InputNode>();
- input->index=index;
- expr=input;
+ input->index = index;
+ expr = input;
} else {
- _set_error("Invalid input identifier '"+what+"'. For script variables, use self (locals are for inputs)."+what);
+ _set_error("Invalid input identifier '" + what + "'. For script variables, use self (locals are for inputs)." + what);
return NULL;
}
} break;
case TK_SELF: {
SelfNode *self = alloc_node<SelfNode>();
- expr=self;
+ expr = self;
} break;
case TK_CONSTANT: {
ConstantNode *constant = alloc_node<ConstantNode>();
- constant->value=tk.value;
- expr=constant;
+ constant->value = tk.value;
+ expr = constant;
} break;
case TK_BASIC_TYPE: {
//constructor..
Variant::Type bt = Variant::Type(int(tk.value));
_get_token(tk);
- if (tk.type!=TK_PARENTHESIS_OPEN) {
+ if (tk.type != TK_PARENTHESIS_OPEN) {
_set_error("Expected '('");
return NULL;
}
ConstructorNode *constructor = alloc_node<ConstructorNode>();
- constructor->data_type=bt;
+ constructor->data_type = bt;
- while(true) {
+ while (true) {
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_PARENTHESIS_CLOSE) {
+ if (tk.type == TK_PARENTHESIS_CLOSE) {
break;
}
- str_ofs=cofs; //revert
+ str_ofs = cofs; //revert
//parse an expression
- ENode* expr=_parse_expression();
+ ENode *expr = _parse_expression();
if (!expr)
return NULL;
constructor->arguments.push_back(expr);
- cofs=str_ofs;
+ cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_COMMA) {
+ if (tk.type == TK_COMMA) {
//all good
- } else if (tk.type==TK_PARENTHESIS_CLOSE) {
- str_ofs=cofs;
+ } else if (tk.type == TK_PARENTHESIS_CLOSE) {
+ str_ofs = cofs;
} else {
_set_error("Expected ',' or ')'");
}
}
- expr=constructor;
+ expr = constructor;
} break;
case TK_BUILTIN_FUNC: {
@@ -861,35 +833,35 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
Variant::Type bt = Variant::Type(int(tk.value));
_get_token(tk);
- if (tk.type!=TK_PARENTHESIS_OPEN) {
+ if (tk.type != TK_PARENTHESIS_OPEN) {
_set_error("Expected '('");
return NULL;
}
BuiltinFuncNode *bifunc = alloc_node<BuiltinFuncNode>();
- bifunc->func=VisualScriptBuiltinFunc::BuiltinFunc(int(tk.value));
+ bifunc->func = VisualScriptBuiltinFunc::BuiltinFunc(int(tk.value));
- while(true) {
+ while (true) {
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_PARENTHESIS_CLOSE) {
+ if (tk.type == TK_PARENTHESIS_CLOSE) {
break;
}
- str_ofs=cofs; //revert
+ str_ofs = cofs; //revert
//parse an expression
- ENode* expr=_parse_expression();
+ ENode *expr = _parse_expression();
if (!expr)
return NULL;
bifunc->arguments.push_back(expr);
- cofs=str_ofs;
+ cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_COMMA) {
+ if (tk.type == TK_COMMA) {
//all good
- } else if (tk.type==TK_PARENTHESIS_CLOSE) {
- str_ofs=cofs;
+ } else if (tk.type == TK_PARENTHESIS_CLOSE) {
+ str_ofs = cofs;
} else {
_set_error("Expected ',' or ')'");
}
@@ -897,25 +869,25 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
int expected_args = VisualScriptBuiltinFunc::get_func_argument_count(bifunc->func);
if (bifunc->arguments.size() != expected_args) {
- _set_error("Builtin func '"+VisualScriptBuiltinFunc::get_func_name(bifunc->func)+"' expects "+itos(expected_args)+" arguments.");
+ _set_error("Builtin func '" + VisualScriptBuiltinFunc::get_func_name(bifunc->func) + "' expects " + itos(expected_args) + " arguments.");
}
- expr=bifunc;
+ expr = bifunc;
} break;
case TK_OP_SUB: {
Expression e;
- e.is_op=true;
- e.op=Variant::OP_NEGATE;
+ e.is_op = true;
+ e.op = Variant::OP_NEGATE;
expression.push_back(e);
continue;
} break;
case TK_OP_NOT: {
Expression e;
- e.is_op=true;
- e.op=Variant::OP_NOT;
+ e.is_op = true;
+ e.op = Variant::OP_NOT;
expression.push_back(e);
continue;
} break;
@@ -924,100 +896,98 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
_set_error("Expected expression.");
return NULL;
} break;
-
}
//before going to operators, must check indexing!
- while(true) {
- int cofs2=str_ofs;
+ while (true) {
+ int cofs2 = str_ofs;
_get_token(tk);
if (error_set)
return NULL;
- bool done=false;
+ bool done = false;
- switch(tk.type) {
+ switch (tk.type) {
case TK_BRACKET_OPEN: {
//value indexing
IndexNode *index = alloc_node<IndexNode>();
- index->base=expr;
+ index->base = expr;
- ENode* what=_parse_expression();
+ ENode *what = _parse_expression();
if (!what)
return NULL;
- index->index=what;
+ index->index = what;
_get_token(tk);
- if (tk.type!=TK_BRACKET_CLOSE) {
+ if (tk.type != TK_BRACKET_CLOSE) {
_set_error("Expected ']' at end of index.");
return NULL;
}
- expr=index;
+ expr = index;
} break;
case TK_PERIOD: {
//named indexing or function call
_get_token(tk);
- if (tk.type!=TK_IDENTIFIER) {
+ if (tk.type != TK_IDENTIFIER) {
_set_error("Expected identifier after '.'");
return NULL;
}
- StringName identifier=tk.value;
+ StringName identifier = tk.value;
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_PARENTHESIS_OPEN) {
+ if (tk.type == TK_PARENTHESIS_OPEN) {
//function call
CallNode *func_call = alloc_node<CallNode>();
- func_call->method=identifier;
- func_call->base=expr;
+ func_call->method = identifier;
+ func_call->base = expr;
- while(true) {
+ while (true) {
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_PARENTHESIS_CLOSE) {
+ if (tk.type == TK_PARENTHESIS_CLOSE) {
break;
}
- str_ofs=cofs; //revert
+ str_ofs = cofs; //revert
//parse an expression
- ENode* expr=_parse_expression();
+ ENode *expr = _parse_expression();
if (!expr)
return NULL;
func_call->arguments.push_back(expr);
- cofs=str_ofs;
+ cofs = str_ofs;
_get_token(tk);
- if (tk.type==TK_COMMA) {
+ if (tk.type == TK_COMMA) {
//all good
- } else if (tk.type==TK_PARENTHESIS_CLOSE) {
- str_ofs=cofs;
+ } else if (tk.type == TK_PARENTHESIS_CLOSE) {
+ str_ofs = cofs;
} else {
_set_error("Expected ',' or ')'");
}
}
- expr=func_call;
+ expr = func_call;
} else {
//named indexing
- str_ofs=cofs;
+ str_ofs = cofs;
NamedIndexNode *index = alloc_node<NamedIndexNode>();
- index->base=expr;
- index->name=identifier;
- expr=index;
-
+ index->base = expr;
+ index->name = identifier;
+ expr = index;
}
} break;
default: {
- str_ofs=cofs2;
- done=true;
+ str_ofs = cofs2;
+ done = true;
} break;
}
@@ -1028,74 +998,68 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
//push expression
{
Expression e;
- e.is_op=false;
- e.node=expr;
+ e.is_op = false;
+ e.node = expr;
expression.push_back(e);
}
//ok finally look for an operator
-
- int cofs=str_ofs;
+ int cofs = str_ofs;
_get_token(tk);
if (error_set)
return NULL;
-
Variant::Operator op = Variant::OP_MAX;
- switch(tk.type) {
- case TK_OP_IN: op=Variant::OP_IN; break;
- case TK_OP_EQUAL: op=Variant::OP_EQUAL; break;
- case TK_OP_NOT_EQUAL: op=Variant::OP_NOT_EQUAL; break;
- case TK_OP_LESS: op=Variant::OP_LESS; break;
- case TK_OP_LESS_EQUAL: op=Variant::OP_LESS_EQUAL; break;
- case TK_OP_GREATER: op=Variant::OP_GREATER; break;
- case TK_OP_GREATER_EQUAL: op=Variant::OP_GREATER_EQUAL; break;
- case TK_OP_AND: op=Variant::OP_AND; break;
- case TK_OP_OR: op=Variant::OP_OR; break;
- case TK_OP_NOT: op=Variant::OP_NOT; break;
- case TK_OP_ADD: op=Variant::OP_ADD; break;
- case TK_OP_SUB: op=Variant::OP_SUBSTRACT; break;
- case TK_OP_MUL: op=Variant::OP_MULTIPLY; break;
- case TK_OP_DIV: op=Variant::OP_DIVIDE; break;
- case TK_OP_MOD: op=Variant::OP_MODULE; break;
- case TK_OP_SHIFT_LEFT: op=Variant::OP_SHIFT_LEFT; break;
- case TK_OP_SHIFT_RIGHT: op=Variant::OP_SHIFT_RIGHT; break;
- case TK_OP_BIT_AND: op=Variant::OP_BIT_AND; break;
- case TK_OP_BIT_OR: op=Variant::OP_BIT_OR; break;
- case TK_OP_BIT_XOR: op=Variant::OP_BIT_XOR; break;
- case TK_OP_BIT_INVERT: op=Variant::OP_BIT_NEGATE; break;
+ switch (tk.type) {
+ case TK_OP_IN: op = Variant::OP_IN; break;
+ case TK_OP_EQUAL: op = Variant::OP_EQUAL; break;
+ case TK_OP_NOT_EQUAL: op = Variant::OP_NOT_EQUAL; break;
+ case TK_OP_LESS: op = Variant::OP_LESS; break;
+ case TK_OP_LESS_EQUAL: op = Variant::OP_LESS_EQUAL; break;
+ case TK_OP_GREATER: op = Variant::OP_GREATER; break;
+ case TK_OP_GREATER_EQUAL: op = Variant::OP_GREATER_EQUAL; break;
+ case TK_OP_AND: op = Variant::OP_AND; break;
+ case TK_OP_OR: op = Variant::OP_OR; break;
+ case TK_OP_NOT: op = Variant::OP_NOT; break;
+ case TK_OP_ADD: op = Variant::OP_ADD; break;
+ case TK_OP_SUB: op = Variant::OP_SUBSTRACT; break;
+ case TK_OP_MUL: op = Variant::OP_MULTIPLY; break;
+ case TK_OP_DIV: op = Variant::OP_DIVIDE; break;
+ case TK_OP_MOD: op = Variant::OP_MODULE; break;
+ case TK_OP_SHIFT_LEFT: op = Variant::OP_SHIFT_LEFT; break;
+ case TK_OP_SHIFT_RIGHT: op = Variant::OP_SHIFT_RIGHT; break;
+ case TK_OP_BIT_AND: op = Variant::OP_BIT_AND; break;
+ case TK_OP_BIT_OR: op = Variant::OP_BIT_OR; break;
+ case TK_OP_BIT_XOR: op = Variant::OP_BIT_XOR; break;
+ case TK_OP_BIT_INVERT: op = Variant::OP_BIT_NEGATE; break;
default: {};
}
- if (op==Variant::OP_MAX) { //stop appending stuff
- str_ofs=cofs;
+ if (op == Variant::OP_MAX) { //stop appending stuff
+ str_ofs = cofs;
break;
}
//push operator and go on
{
Expression e;
- e.is_op=true;
- e.op=op;
+ e.is_op = true;
+ e.op = op;
expression.push_back(e);
}
}
-
/* Reduce the set set of expressions and place them in an operator tree, respecting precedence */
+ while (expression.size() > 1) {
- while(expression.size()>1) {
-
- int next_op=-1;
- int min_priority=0xFFFFF;
- bool is_unary=false;
-
- for(int i=0;i<expression.size();i++) {
-
+ int next_op = -1;
+ int min_priority = 0xFFFFF;
+ bool is_unary = false;
+ for (int i = 0; i < expression.size(); i++) {
if (!expression[i].is_op) {
@@ -1104,77 +1068,80 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
int priority;
- bool unary=false;
-
- switch(expression[i].op) {
-
+ bool unary = false;
- case Variant::OP_BIT_NEGATE: priority=0; unary=true; break;
- case Variant::OP_NEGATE: priority=1; unary=true; break;
+ switch (expression[i].op) {
- case Variant::OP_MULTIPLY: priority=2; break;
- case Variant::OP_DIVIDE: priority=2; break;
- case Variant::OP_MODULE: priority=2; break;
+ case Variant::OP_BIT_NEGATE:
+ priority = 0;
+ unary = true;
+ break;
+ case Variant::OP_NEGATE:
+ priority = 1;
+ unary = true;
+ break;
- case Variant::OP_ADD: priority=3; break;
- case Variant::OP_SUBSTRACT: priority=3; break;
+ case Variant::OP_MULTIPLY: priority = 2; break;
+ case Variant::OP_DIVIDE: priority = 2; break;
+ case Variant::OP_MODULE: priority = 2; break;
- case Variant::OP_SHIFT_LEFT: priority=4; break;
- case Variant::OP_SHIFT_RIGHT: priority=4; break;
+ case Variant::OP_ADD: priority = 3; break;
+ case Variant::OP_SUBSTRACT: priority = 3; break;
- case Variant::OP_BIT_AND: priority=5; break;
- case Variant::OP_BIT_XOR: priority=6; break;
- case Variant::OP_BIT_OR: priority=7; break;
+ case Variant::OP_SHIFT_LEFT: priority = 4; break;
+ case Variant::OP_SHIFT_RIGHT: priority = 4; break;
- case Variant::OP_LESS: priority=8; break;
- case Variant::OP_LESS_EQUAL: priority=8; break;
- case Variant::OP_GREATER: priority=8; break;
- case Variant::OP_GREATER_EQUAL: priority=8; break;
+ case Variant::OP_BIT_AND: priority = 5; break;
+ case Variant::OP_BIT_XOR: priority = 6; break;
+ case Variant::OP_BIT_OR: priority = 7; break;
- case Variant::OP_EQUAL: priority=8; break;
- case Variant::OP_NOT_EQUAL: priority=8; break;
+ case Variant::OP_LESS: priority = 8; break;
+ case Variant::OP_LESS_EQUAL: priority = 8; break;
+ case Variant::OP_GREATER: priority = 8; break;
+ case Variant::OP_GREATER_EQUAL: priority = 8; break;
- case Variant::OP_IN: priority=10; break;
+ case Variant::OP_EQUAL: priority = 8; break;
+ case Variant::OP_NOT_EQUAL: priority = 8; break;
- case Variant::OP_NOT: priority=11; unary=true; break;
- case Variant::OP_AND: priority=12; break;
- case Variant::OP_OR: priority=13; break;
+ case Variant::OP_IN: priority = 10; break;
+ case Variant::OP_NOT:
+ priority = 11;
+ unary = true;
+ break;
+ case Variant::OP_AND: priority = 12; break;
+ case Variant::OP_OR: priority = 13; break;
default: {
- _set_error("Parser bug, invalid operator in expression: "+itos(expression[i].op));
+ _set_error("Parser bug, invalid operator in expression: " + itos(expression[i].op));
return NULL;
}
-
}
- if (priority<min_priority) {
+ if (priority < min_priority) {
// < is used for left to right (default)
// <= is used for right to left
- next_op=i;
- min_priority=priority;
- is_unary=unary;
+ next_op = i;
+ min_priority = priority;
+ is_unary = unary;
}
-
}
- if (next_op==-1) {
-
+ if (next_op == -1) {
_set_error("Yet another parser bug....");
- ERR_FAIL_COND_V(next_op==-1,NULL);
+ ERR_FAIL_COND_V(next_op == -1, NULL);
}
-
// OK! create operator..
if (is_unary) {
- int expr_pos=next_op;
- while(expression[expr_pos].is_op) {
+ int expr_pos = next_op;
+ while (expression[expr_pos].is_op) {
expr_pos++;
- if (expr_pos==expression.size()) {
+ if (expr_pos == expression.size()) {
//can happen..
_set_error("Unexpected end of expression..");
return NULL;
@@ -1182,35 +1149,34 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
}
//consecutively do unary opeators
- for(int i=expr_pos-1;i>=next_op;i--) {
+ for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=expression[i].op;
- op->nodes[0]=expression[i+1].node;
- op->nodes[1]=NULL;
- expression[i].is_op=false;
- expression[i].node=op;
- expression.remove(i+1);
+ op->op = expression[i].op;
+ op->nodes[0] = expression[i + 1].node;
+ op->nodes[1] = NULL;
+ expression[i].is_op = false;
+ expression[i].node = op;
+ expression.remove(i + 1);
}
-
} else {
- if (next_op <1 || next_op>=(expression.size()-1)) {
+ if (next_op < 1 || next_op >= (expression.size() - 1)) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
OperatorNode *op = alloc_node<OperatorNode>();
- op->op=expression[next_op].op;
+ op->op = expression[next_op].op;
- if (expression[next_op-1].is_op) {
+ if (expression[next_op - 1].is_op) {
_set_error("Parser bug..");
ERR_FAIL_V(NULL);
}
- if (expression[next_op+1].is_op) {
+ if (expression[next_op + 1].is_op) {
// this is not invalid and can really appear
// but it becomes invalid anyway because no binary op
// can be followed by an unary op in a valid combination,
@@ -1220,12 +1186,11 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
return NULL;
}
-
- op->nodes[0]=expression[next_op-1].node; //expression goes as left
- op->nodes[1]=expression[next_op+1].node; //next expression goes as right
+ op->nodes[0] = expression[next_op - 1].node; //expression goes as left
+ op->nodes[1] = expression[next_op + 1].node; //next expression goes as right
//replace all 3 nodes by this operator and make it an expression
- expression[next_op-1].node=op;
+ expression[next_op - 1].node = op;
expression.remove(next_op);
expression.remove(next_op);
}
@@ -1241,250 +1206,239 @@ bool VisualScriptExpression::_compile_expression() {
if (nodes) {
memdelete(nodes);
- nodes=NULL;
- root=NULL;
-
+ nodes = NULL;
+ root = NULL;
}
- error_str=String();
- error_set=false;
- str_ofs=0;
+ error_str = String();
+ error_set = false;
+ str_ofs = 0;
- root=_parse_expression();
+ root = _parse_expression();
if (error_set) {
- root=NULL;
+ root = NULL;
if (nodes) {
memdelete(nodes);
}
- nodes=NULL;
+ nodes = NULL;
return true;
}
- expression_dirty=false;
+ expression_dirty = false;
return false;
}
-
class VisualScriptNodeInstanceExpression : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
VisualScriptExpression *expression;
//virtual int get_working_memory_size() const { return 0; }
//execute by parsing the tree directly
- virtual bool _execute(const Variant** p_inputs,VisualScriptExpression::ENode *p_node,Variant& r_ret,String& r_error_str,Variant::CallError &ce) {
+ virtual bool _execute(const Variant **p_inputs, VisualScriptExpression::ENode *p_node, Variant &r_ret, String &r_error_str, Variant::CallError &ce) {
- switch(p_node->type) {
- case VisualScriptExpression::ENode::TYPE_INPUT: {
+ switch (p_node->type) {
+ case VisualScriptExpression::ENode::TYPE_INPUT: {
- const VisualScriptExpression::InputNode *in = static_cast<const VisualScriptExpression::InputNode*>(p_node);
- r_ret=*p_inputs[in->index];
+ const VisualScriptExpression::InputNode *in = static_cast<const VisualScriptExpression::InputNode *>(p_node);
+ r_ret = *p_inputs[in->index];
} break;
- case VisualScriptExpression::ENode::TYPE_CONSTANT: {
+ case VisualScriptExpression::ENode::TYPE_CONSTANT: {
- const VisualScriptExpression::ConstantNode *c = static_cast<const VisualScriptExpression::ConstantNode*>(p_node);
- r_ret=c->value;
+ const VisualScriptExpression::ConstantNode *c = static_cast<const VisualScriptExpression::ConstantNode *>(p_node);
+ r_ret = c->value;
} break;
- case VisualScriptExpression::ENode::TYPE_SELF: {
+ case VisualScriptExpression::ENode::TYPE_SELF: {
- r_ret=instance->get_owner_ptr();
+ r_ret = instance->get_owner_ptr();
} break;
- case VisualScriptExpression::ENode::TYPE_OPERATOR: {
+ case VisualScriptExpression::ENode::TYPE_OPERATOR: {
-
- const VisualScriptExpression::OperatorNode *op = static_cast<const VisualScriptExpression::OperatorNode*>(p_node);
+ const VisualScriptExpression::OperatorNode *op = static_cast<const VisualScriptExpression::OperatorNode *>(p_node);
Variant a;
- bool ret = _execute(p_inputs,op->nodes[0],a,r_error_str,ce);
+ bool ret = _execute(p_inputs, op->nodes[0], a, r_error_str, ce);
if (ret)
return true;
Variant b;
if (op->nodes[1]) {
- ret = _execute(p_inputs,op->nodes[1],b,r_error_str,ce);
+ ret = _execute(p_inputs, op->nodes[1], b, r_error_str, ce);
if (ret)
return true;
}
- bool valid=true;
- Variant::evaluate(op->op,a,b,r_ret,valid);
+ bool valid = true;
+ Variant::evaluate(op->op, a, b, r_ret, valid);
if (!valid) {
- r_error_str="Invalid operands to operator "+Variant::get_operator_name(op->op)+": "+Variant::get_type_name(a.get_type())+" and "+Variant::get_type_name(b.get_type())+".";
+ r_error_str = "Invalid operands to operator " + Variant::get_operator_name(op->op) + ": " + Variant::get_type_name(a.get_type()) + " and " + Variant::get_type_name(b.get_type()) + ".";
return true;
}
} break;
- case VisualScriptExpression::ENode::TYPE_INDEX: {
+ case VisualScriptExpression::ENode::TYPE_INDEX: {
- const VisualScriptExpression::IndexNode *index = static_cast<const VisualScriptExpression::IndexNode*>(p_node);
+ const VisualScriptExpression::IndexNode *index = static_cast<const VisualScriptExpression::IndexNode *>(p_node);
Variant base;
- bool ret = _execute(p_inputs,index->base,base,r_error_str,ce);
+ bool ret = _execute(p_inputs, index->base, base, r_error_str, ce);
if (ret)
return true;
Variant idx;
- ret = _execute(p_inputs,index->index,idx,r_error_str,ce);
+ ret = _execute(p_inputs, index->index, idx, r_error_str, ce);
if (ret)
return true;
bool valid;
- r_ret=base.get(idx,&valid);
+ r_ret = base.get(idx, &valid);
if (!valid) {
- r_error_str="Invalid index of type "+Variant::get_type_name(idx.get_type())+" for base of type "+Variant::get_type_name(base.get_type())+".";
+ r_error_str = "Invalid index of type " + Variant::get_type_name(idx.get_type()) + " for base of type " + Variant::get_type_name(base.get_type()) + ".";
return true;
}
-
-
} break;
- case VisualScriptExpression::ENode::TYPE_NAMED_INDEX: {
+ case VisualScriptExpression::ENode::TYPE_NAMED_INDEX: {
- const VisualScriptExpression::NamedIndexNode *index = static_cast<const VisualScriptExpression::NamedIndexNode*>(p_node);
+ const VisualScriptExpression::NamedIndexNode *index = static_cast<const VisualScriptExpression::NamedIndexNode *>(p_node);
Variant base;
- bool ret = _execute(p_inputs,index->base,base,r_error_str,ce);
+ bool ret = _execute(p_inputs, index->base, base, r_error_str, ce);
if (ret)
return true;
bool valid;
- r_ret=base.get_named(index->name,&valid);
+ r_ret = base.get_named(index->name, &valid);
if (!valid) {
- r_error_str="Invalid index '"+String(index->name)+"' for base of type "+Variant::get_type_name(base.get_type())+".";
+ r_error_str = "Invalid index '" + String(index->name) + "' for base of type " + Variant::get_type_name(base.get_type()) + ".";
return true;
}
} break;
- case VisualScriptExpression::ENode::TYPE_ARRAY: {
- const VisualScriptExpression::ArrayNode *array = static_cast<const VisualScriptExpression::ArrayNode*>(p_node);
+ case VisualScriptExpression::ENode::TYPE_ARRAY: {
+ const VisualScriptExpression::ArrayNode *array = static_cast<const VisualScriptExpression::ArrayNode *>(p_node);
Array arr;
arr.resize(array->array.size());
- for (int i=0;i<array->array.size();i++) {
+ for (int i = 0; i < array->array.size(); i++) {
Variant value;
- bool ret = _execute(p_inputs,array->array[i],value,r_error_str,ce);
+ bool ret = _execute(p_inputs, array->array[i], value, r_error_str, ce);
if (ret)
return true;
- arr[i]=value;
+ arr[i] = value;
}
- r_ret=arr;
+ r_ret = arr;
} break;
- case VisualScriptExpression::ENode::TYPE_DICTIONARY: {
- const VisualScriptExpression::DictionaryNode *dictionary = static_cast<const VisualScriptExpression::DictionaryNode*>(p_node);
+ case VisualScriptExpression::ENode::TYPE_DICTIONARY: {
+ const VisualScriptExpression::DictionaryNode *dictionary = static_cast<const VisualScriptExpression::DictionaryNode *>(p_node);
Dictionary d;
- for (int i=0;i<dictionary->dict.size();i+=2) {
+ for (int i = 0; i < dictionary->dict.size(); i += 2) {
Variant key;
- bool ret = _execute(p_inputs,dictionary->dict[i+0],key,r_error_str,ce);
+ bool ret = _execute(p_inputs, dictionary->dict[i + 0], key, r_error_str, ce);
if (ret)
return true;
Variant value;
- ret = _execute(p_inputs,dictionary->dict[i+1],value,r_error_str,ce);
+ ret = _execute(p_inputs, dictionary->dict[i + 1], value, r_error_str, ce);
if (ret)
return true;
- d[key]=value;
+ d[key] = value;
}
- r_ret=d;
+ r_ret = d;
} break;
- case VisualScriptExpression::ENode::TYPE_CONSTRUCTOR: {
+ case VisualScriptExpression::ENode::TYPE_CONSTRUCTOR: {
- const VisualScriptExpression::ConstructorNode *constructor = static_cast<const VisualScriptExpression::ConstructorNode*>(p_node);
+ const VisualScriptExpression::ConstructorNode *constructor = static_cast<const VisualScriptExpression::ConstructorNode *>(p_node);
Vector<Variant> arr;
- Vector<const Variant*> argp;
+ Vector<const Variant *> argp;
arr.resize(constructor->arguments.size());
argp.resize(constructor->arguments.size());
- for (int i=0;i<constructor->arguments.size();i++) {
+ for (int i = 0; i < constructor->arguments.size(); i++) {
Variant value;
- bool ret = _execute(p_inputs,constructor->arguments[i],value,r_error_str,ce);
+ bool ret = _execute(p_inputs, constructor->arguments[i], value, r_error_str, ce);
if (ret)
return true;
- arr[i]=value;
- argp[i]=&arr[i];
+ arr[i] = value;
+ argp[i] = &arr[i];
}
+ r_ret = Variant::construct(constructor->data_type, argp.ptr(), argp.size(), ce);
- r_ret=Variant::construct(constructor->data_type,argp.ptr(),argp.size(),ce);
-
- if (ce.error!=Variant::CallError::CALL_OK) {
- r_error_str="Invalid arguments to construct '"+Variant::get_type_name(constructor->data_type)+"'.";
+ if (ce.error != Variant::CallError::CALL_OK) {
+ r_error_str = "Invalid arguments to construct '" + Variant::get_type_name(constructor->data_type) + "'.";
return true;
}
-
} break;
- case VisualScriptExpression::ENode::TYPE_BUILTIN_FUNC: {
+ case VisualScriptExpression::ENode::TYPE_BUILTIN_FUNC: {
- const VisualScriptExpression::BuiltinFuncNode *bifunc = static_cast<const VisualScriptExpression::BuiltinFuncNode*>(p_node);
+ const VisualScriptExpression::BuiltinFuncNode *bifunc = static_cast<const VisualScriptExpression::BuiltinFuncNode *>(p_node);
Vector<Variant> arr;
- Vector<const Variant*> argp;
+ Vector<const Variant *> argp;
arr.resize(bifunc->arguments.size());
argp.resize(bifunc->arguments.size());
- for (int i=0;i<bifunc->arguments.size();i++) {
+ for (int i = 0; i < bifunc->arguments.size(); i++) {
Variant value;
- bool ret = _execute(p_inputs,bifunc->arguments[i],value,r_error_str,ce);
+ bool ret = _execute(p_inputs, bifunc->arguments[i], value, r_error_str, ce);
if (ret)
return true;
- arr[i]=value;
- argp[i]=&arr[i];
+ arr[i] = value;
+ argp[i] = &arr[i];
}
+ VisualScriptBuiltinFunc::exec_func(bifunc->func, argp.ptr(), &r_ret, ce, r_error_str);
- VisualScriptBuiltinFunc::exec_func(bifunc->func,argp.ptr(),&r_ret,ce,r_error_str);
-
- if (ce.error!=Variant::CallError::CALL_OK) {
- r_error_str="Builtin Call Failed. "+r_error_str;
+ if (ce.error != Variant::CallError::CALL_OK) {
+ r_error_str = "Builtin Call Failed. " + r_error_str;
return true;
}
} break;
- case VisualScriptExpression::ENode::TYPE_CALL: {
-
- const VisualScriptExpression::CallNode *call = static_cast<const VisualScriptExpression::CallNode*>(p_node);
+ case VisualScriptExpression::ENode::TYPE_CALL: {
+ const VisualScriptExpression::CallNode *call = static_cast<const VisualScriptExpression::CallNode *>(p_node);
Variant base;
- bool ret = _execute(p_inputs,call->base,base,r_error_str,ce);
+ bool ret = _execute(p_inputs, call->base, base, r_error_str, ce);
if (ret)
return true;
Vector<Variant> arr;
- Vector<const Variant*> argp;
+ Vector<const Variant *> argp;
arr.resize(call->arguments.size());
argp.resize(call->arguments.size());
- for (int i=0;i<call->arguments.size();i++) {
+ for (int i = 0; i < call->arguments.size(); i++) {
Variant value;
- bool ret = _execute(p_inputs,call->arguments[i],value,r_error_str,ce);
+ bool ret = _execute(p_inputs, call->arguments[i], value, r_error_str, ce);
if (ret)
return true;
- arr[i]=value;
- argp[i]=&arr[i];
+ arr[i] = value;
+ argp[i] = &arr[i];
}
+ r_ret = base.call(call->method, argp.ptr(), argp.size(), ce);
- r_ret=base.call(call->method,argp.ptr(),argp.size(),ce);
-
- if (ce.error!=Variant::CallError::CALL_OK) {
- r_error_str="On call to '"+String(call->method)+"':";
+ if (ce.error != Variant::CallError::CALL_OK) {
+ r_error_str = "On call to '" + String(call->method) + "':";
return true;
}
@@ -1493,53 +1447,47 @@ public:
return false;
}
- 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) {
+ 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) {
if (!expression->root || expression->error_set) {
- r_error_str=expression->error_str;
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = expression->error_str;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
-
- bool error = _execute(p_inputs,expression->root,*p_outputs[0],r_error_str,r_error);
- if (error && r_error.error==Variant::CallError::CALL_OK) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ bool error = _execute(p_inputs, expression->root, *p_outputs[0], r_error_str, r_error);
+ if (error && r_error.error == Variant::CallError::CALL_OK) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
}
#ifdef DEBUG_ENABLED
- if (!error && expression->output_type!=Variant::NIL && !Variant::can_convert_strict(p_outputs[0]->get_type(),expression->output_type)) {
-
- r_error_str+="Can't convert expression result from "+Variant::get_type_name(p_outputs[0]->get_type())+" to "+Variant::get_type_name(expression->output_type)+".";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ if (!error && expression->output_type != Variant::NIL && !Variant::can_convert_strict(p_outputs[0]->get_type(), expression->output_type)) {
+ r_error_str += "Can't convert expression result from " + Variant::get_type_name(p_outputs[0]->get_type()) + " to " + Variant::get_type_name(expression->output_type) + ".";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
}
#endif
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptExpression::instance(VisualScriptInstance* p_instance){
+VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance *p_instance) {
_compile_expression();
- VisualScriptNodeInstanceExpression *instance = memnew( VisualScriptNodeInstanceExpression );
- instance->instance=p_instance;
- instance->expression=this;
+ VisualScriptNodeInstanceExpression *instance = memnew(VisualScriptNodeInstanceExpression);
+ instance->instance = p_instance;
+ instance->expression = this;
return instance;
}
-
-VisualScriptExpression::VisualScriptExpression()
-{
- output_type=Variant::NIL;
- expression_dirty=true;
- error_set=true;
- root=NULL;
- nodes=NULL;
- sequenced=false;
+VisualScriptExpression::VisualScriptExpression() {
+ output_type = Variant::NIL;
+ expression_dirty = true;
+ error_set = true;
+ root = NULL;
+ nodes = NULL;
+ sequenced = false;
}
VisualScriptExpression::~VisualScriptExpression() {
@@ -1549,9 +1497,7 @@ VisualScriptExpression::~VisualScriptExpression() {
}
}
-
void register_visual_script_expression_node() {
- VisualScriptLanguage::singleton->add_register_func("operators/expression",create_node_generic<VisualScriptExpression>);
-
+ VisualScriptLanguage::singleton->add_register_func("operators/expression", create_node_generic<VisualScriptExpression>);
}
diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h
index 5bd960f60c..59a7d9fba0 100644
--- a/modules/visual_script/visual_script_expression.h
+++ b/modules/visual_script/visual_script_expression.h
@@ -34,15 +34,15 @@
class VisualScriptExpression : public VisualScriptNode {
- GDCLASS(VisualScriptExpression,VisualScriptNode)
-friend class VisualScriptNodeInstanceExpression;
+ GDCLASS(VisualScriptExpression, VisualScriptNode)
+ friend class VisualScriptNodeInstanceExpression;
struct Input {
Variant::Type type;
String name;
- Input() { type=Variant::NIL; }
+ Input() { type = Variant::NIL; }
};
Vector<Input> inputs;
@@ -97,28 +97,25 @@ friend class VisualScriptNodeInstanceExpression;
TK_MAX
};
- static const char* token_name[TK_MAX];
+ static const char *token_name[TK_MAX];
struct Token {
TokenType type;
Variant value;
};
-
- void _set_error(const String& p_err) {
+ void _set_error(const String &p_err) {
if (error_set)
return;
- error_str=p_err;
- error_set=true;
+ error_str = p_err;
+ error_set = true;
}
- Error _get_token(Token& r_token);
+ Error _get_token(Token &r_token);
String error_str;
bool error_set;
-
-
struct ENode {
enum Type {
@@ -139,8 +136,12 @@ friend class VisualScriptNodeInstanceExpression;
Type type;
- ENode() { next=NULL; }
- virtual ~ENode() { if (next) { memdelete(next); } }
+ ENode() { next = NULL; }
+ virtual ~ENode() {
+ if (next) {
+ memdelete(next);
+ }
+ }
};
struct Expression {
@@ -152,22 +153,21 @@ friend class VisualScriptNodeInstanceExpression;
};
};
- ENode* _parse_expression();
+ ENode *_parse_expression();
struct InputNode : public ENode {
int index;
InputNode() {
- type=TYPE_INPUT;
+ type = TYPE_INPUT;
}
};
-
struct ConstantNode : public ENode {
Variant value;
ConstantNode() {
- type=TYPE_CONSTANT;
+ type = TYPE_CONSTANT;
}
};
@@ -175,119 +175,104 @@ friend class VisualScriptNodeInstanceExpression;
Variant::Operator op;
- ENode* nodes[2];
+ ENode *nodes[2];
OperatorNode() {
- type=TYPE_OPERATOR;
+ type = TYPE_OPERATOR;
}
};
struct SelfNode : public ENode {
-
SelfNode() {
- type=TYPE_SELF;
+ type = TYPE_SELF;
}
};
struct IndexNode : public ENode {
- ENode*base;
- ENode*index;
+ ENode *base;
+ ENode *index;
IndexNode() {
- type=TYPE_INDEX;
+ type = TYPE_INDEX;
}
};
struct NamedIndexNode : public ENode {
- ENode*base;
+ ENode *base;
StringName name;
NamedIndexNode() {
- type=TYPE_NAMED_INDEX;
+ type = TYPE_NAMED_INDEX;
}
-
};
struct ConstructorNode : public ENode {
Variant::Type data_type;
- Vector<ENode*> arguments;
+ Vector<ENode *> arguments;
ConstructorNode() {
- type=TYPE_CONSTRUCTOR;
+ type = TYPE_CONSTRUCTOR;
}
};
struct CallNode : public ENode {
- ENode*base;
+ ENode *base;
StringName method;
- Vector<ENode*> arguments;
+ Vector<ENode *> arguments;
CallNode() {
- type=TYPE_CALL;
+ type = TYPE_CALL;
}
-
};
struct ArrayNode : public ENode {
- Vector<ENode*> array;
+ Vector<ENode *> array;
ArrayNode() {
- type=TYPE_ARRAY;
+ type = TYPE_ARRAY;
}
-
};
struct DictionaryNode : public ENode {
- Vector<ENode*> dict;
+ Vector<ENode *> dict;
DictionaryNode() {
- type=TYPE_DICTIONARY;
+ type = TYPE_DICTIONARY;
}
-
};
struct BuiltinFuncNode : public ENode {
VisualScriptBuiltinFunc::BuiltinFunc func;
- Vector<ENode*> arguments;
+ Vector<ENode *> arguments;
BuiltinFuncNode() {
- type=TYPE_BUILTIN_FUNC;
+ type = TYPE_BUILTIN_FUNC;
}
};
- template<class T>
- T* alloc_node() {
- T* node = memnew(T);
- node->next=nodes;
- nodes=node;
+ template <class T>
+ T *alloc_node() {
+ T *node = memnew(T);
+ node->next = nodes;
+ nodes = node;
return node;
}
ENode *root;
ENode *nodes;
-
-
-
-
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;
+ 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:
-
-
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;
@@ -295,14 +280,12 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "operators"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptExpression();
~VisualScriptExpression();
};
-
void register_visual_script_expression_node();
-
#endif // VISUALSCRIPTEXPRESSION_H
diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp
index 8aff96b70c..78847fb588 100644
--- a/modules/visual_script/visual_script_flow_control.cpp
+++ b/modules/visual_script/visual_script_flow_control.cpp
@@ -28,9 +28,8 @@
/*************************************************************************/
#include "visual_script_flow_control.h"
-#include "os/keyboard.h"
#include "global_config.h"
-
+#include "os/keyboard.h"
//////////////////////////////////////////
////////////////RETURN////////////////////
@@ -41,16 +40,16 @@ int VisualScriptReturn::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptReturn::has_input_sequence_port() const{
+bool VisualScriptReturn::has_input_sequence_port() const {
return true;
}
-int VisualScriptReturn::get_input_value_port_count() const{
+int VisualScriptReturn::get_input_value_port_count() const {
- return with_value?1:0;
+ return with_value ? 1 : 0;
}
-int VisualScriptReturn::get_output_value_port_count() const{
+int VisualScriptReturn::get_output_value_port_count() const {
return 0;
}
@@ -60,14 +59,14 @@ String VisualScriptReturn::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptReturn::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptReturn::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="result";
- pinfo.type=type;
+ pinfo.name = "result";
+ pinfo.type = type;
return pinfo;
}
-PropertyInfo VisualScriptReturn::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptReturn::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
@@ -83,23 +82,22 @@ String VisualScriptReturn::get_text() const {
void VisualScriptReturn::set_return_type(Variant::Type p_type) {
- if (type==p_type)
+ if (type == p_type)
return;
- type=p_type;
+ type = p_type;
ports_changed_notify();
-
}
-Variant::Type VisualScriptReturn::get_return_type() const{
+Variant::Type VisualScriptReturn::get_return_type() const {
return type;
}
void VisualScriptReturn::set_enable_return_value(bool p_enable) {
- if (with_value==p_enable)
+ if (with_value == p_enable)
return;
- with_value=p_enable;
+ with_value = p_enable;
ports_changed_notify();
}
@@ -110,24 +108,22 @@ bool VisualScriptReturn::is_return_value_enabled() const {
void VisualScriptReturn::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_return_type","type"),&VisualScriptReturn::set_return_type);
- ClassDB::bind_method(D_METHOD("get_return_type"),&VisualScriptReturn::get_return_type);
- ClassDB::bind_method(D_METHOD("set_enable_return_value","enable"),&VisualScriptReturn::set_enable_return_value);
- ClassDB::bind_method(D_METHOD("is_return_value_enabled"),&VisualScriptReturn::is_return_value_enabled);
+ ClassDB::bind_method(D_METHOD("set_return_type", "type"), &VisualScriptReturn::set_return_type);
+ ClassDB::bind_method(D_METHOD("get_return_type"), &VisualScriptReturn::get_return_type);
+ ClassDB::bind_method(D_METHOD("set_enable_return_value", "enable"), &VisualScriptReturn::set_enable_return_value);
+ ClassDB::bind_method(D_METHOD("is_return_value_enabled"), &VisualScriptReturn::is_return_value_enabled);
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ 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_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");
}
class VisualScriptNodeInstanceReturn : public VisualScriptNodeInstance {
public:
-
VisualScriptReturn *node;
VisualScriptInstance *instance;
bool with_value;
@@ -136,7 +132,7 @@ public:
//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; }
- 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) {
+ 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) {
if (with_value) {
*p_working_mem = *p_inputs[0];
@@ -146,27 +142,25 @@ public:
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptReturn::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceReturn * instance = memnew(VisualScriptNodeInstanceReturn );
- instance->node=this;
- instance->instance=p_instance;
- instance->with_value=with_value;
+ VisualScriptNodeInstanceReturn *instance = memnew(VisualScriptNodeInstanceReturn);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->with_value = with_value;
return instance;
}
VisualScriptReturn::VisualScriptReturn() {
- with_value=false;
- type=Variant::NIL;
+ with_value = false;
+ type = Variant::NIL;
}
-template<bool with_value>
-static Ref<VisualScriptNode> create_return_node(const String& p_name) {
+template <bool with_value>
+static Ref<VisualScriptNode> create_return_node(const String &p_name) {
Ref<VisualScriptReturn> node;
node.instance();
@@ -174,8 +168,6 @@ static Ref<VisualScriptNode> create_return_node(const String& p_name) {
return node;
}
-
-
//////////////////////////////////////////
////////////////CONDITION/////////////////
//////////////////////////////////////////
@@ -185,38 +177,38 @@ int VisualScriptCondition::get_output_sequence_port_count() const {
return 3;
}
-bool VisualScriptCondition::has_input_sequence_port() const{
+bool VisualScriptCondition::has_input_sequence_port() const {
return true;
}
-int VisualScriptCondition::get_input_value_port_count() const{
+int VisualScriptCondition::get_input_value_port_count() const {
return 1;
}
-int VisualScriptCondition::get_output_value_port_count() const{
+int VisualScriptCondition::get_output_value_port_count() const {
return 0;
}
String VisualScriptCondition::get_output_sequence_port_text(int p_port) const {
- if (p_port==0)
+ if (p_port == 0)
return "true";
- else if (p_port==1)
+ else if (p_port == 1)
return "false";
else
return "done";
}
-PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="cond";
- pinfo.type=Variant::BOOL;
+ pinfo.name = "cond";
+ pinfo.type = Variant::BOOL;
return pinfo;
}
-PropertyInfo VisualScriptCondition::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptCondition::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
@@ -230,16 +222,11 @@ String VisualScriptCondition::get_text() const {
return "if (cond) is: ";
}
-
void VisualScriptCondition::_bind_methods() {
-
-
-
}
class VisualScriptNodeInstanceCondition : public VisualScriptNodeInstance {
public:
-
VisualScriptCondition *node;
VisualScriptInstance *instance;
@@ -247,33 +234,28 @@ public:
//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; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_CONTINUE_SEQUENCE)
+ if (p_start_mode == START_MODE_CONTINUE_SEQUENCE)
return 2;
else if (p_inputs[0]->operator bool())
return 0 | STEP_FLAG_PUSH_STACK_BIT;
else
return 1 | STEP_FLAG_PUSH_STACK_BIT;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptCondition::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptCondition::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceCondition * instance = memnew(VisualScriptNodeInstanceCondition );
- instance->node=this;
- instance->instance=p_instance;
+ VisualScriptNodeInstanceCondition *instance = memnew(VisualScriptNodeInstanceCondition);
+ instance->node = this;
+ instance->instance = p_instance;
return instance;
}
VisualScriptCondition::VisualScriptCondition() {
-
}
-
-
//////////////////////////////////////////
////////////////WHILE/////////////////
//////////////////////////////////////////
@@ -283,36 +265,36 @@ int VisualScriptWhile::get_output_sequence_port_count() const {
return 2;
}
-bool VisualScriptWhile::has_input_sequence_port() const{
+bool VisualScriptWhile::has_input_sequence_port() const {
return true;
}
-int VisualScriptWhile::get_input_value_port_count() const{
+int VisualScriptWhile::get_input_value_port_count() const {
return 1;
}
-int VisualScriptWhile::get_output_value_port_count() const{
+int VisualScriptWhile::get_output_value_port_count() const {
return 0;
}
String VisualScriptWhile::get_output_sequence_port_text(int p_port) const {
- if (p_port==0)
+ if (p_port == 0)
return "repeat";
else
return "exit";
}
-PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="cond";
- pinfo.type=Variant::BOOL;
+ pinfo.name = "cond";
+ pinfo.type = Variant::BOOL;
return pinfo;
}
-PropertyInfo VisualScriptWhile::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptWhile::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
@@ -326,16 +308,11 @@ String VisualScriptWhile::get_text() const {
return "while (cond): ";
}
-
void VisualScriptWhile::_bind_methods() {
-
-
-
}
class VisualScriptNodeInstanceWhile : public VisualScriptNodeInstance {
public:
-
VisualScriptWhile *node;
VisualScriptInstance *instance;
@@ -343,32 +320,27 @@ public:
//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; }
- 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) {
+ 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 keep_going = p_inputs[0]->operator bool();
if (keep_going)
- return 0|STEP_FLAG_PUSH_STACK_BIT;
+ return 0 | STEP_FLAG_PUSH_STACK_BIT;
else
return 1;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptWhile::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptWhile::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceWhile * instance = memnew(VisualScriptNodeInstanceWhile );
- instance->node=this;
- instance->instance=p_instance;
+ VisualScriptNodeInstanceWhile *instance = memnew(VisualScriptNodeInstanceWhile);
+ instance->node = this;
+ instance->instance = p_instance;
return instance;
}
VisualScriptWhile::VisualScriptWhile() {
-
}
-
-
//////////////////////////////////////////
////////////////ITERATOR/////////////////
//////////////////////////////////////////
@@ -378,39 +350,39 @@ int VisualScriptIterator::get_output_sequence_port_count() const {
return 2;
}
-bool VisualScriptIterator::has_input_sequence_port() const{
+bool VisualScriptIterator::has_input_sequence_port() const {
return true;
}
-int VisualScriptIterator::get_input_value_port_count() const{
+int VisualScriptIterator::get_input_value_port_count() const {
return 1;
}
-int VisualScriptIterator::get_output_value_port_count() const{
+int VisualScriptIterator::get_output_value_port_count() const {
return 1;
}
String VisualScriptIterator::get_output_sequence_port_text(int p_port) const {
- if (p_port==0)
+ if (p_port == 0)
return "each";
else
return "exit";
}
-PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="input";
- pinfo.type=Variant::NIL;
+ pinfo.name = "input";
+ pinfo.type = Variant::NIL;
return pinfo;
}
-PropertyInfo VisualScriptIterator::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIterator::get_output_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="elem";
- pinfo.type=Variant::NIL;
+ pinfo.name = "elem";
+ pinfo.type = Variant::NIL;
return pinfo;
}
String VisualScriptIterator::get_caption() const {
@@ -423,16 +395,11 @@ String VisualScriptIterator::get_text() const {
return "for (elem) in (input): ";
}
-
void VisualScriptIterator::_bind_methods() {
-
-
-
}
class VisualScriptNodeInstanceIterator : public VisualScriptNodeInstance {
public:
-
VisualScriptIterator *node;
VisualScriptInstance *instance;
@@ -440,77 +407,68 @@ public:
//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; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_BEGIN_SEQUENCE) {
- p_working_mem[0]=*p_inputs[0];
+ if (p_start_mode == START_MODE_BEGIN_SEQUENCE) {
+ p_working_mem[0] = *p_inputs[0];
bool valid;
- bool can_iter = p_inputs[0]->iter_init(p_working_mem[1],valid);
+ bool can_iter = p_inputs[0]->iter_init(p_working_mem[1], valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Input type not iterable: ")+Variant::get_type_name(p_inputs[0]->get_type());
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Input type not iterable: ") + Variant::get_type_name(p_inputs[0]->get_type());
return 0;
}
if (!can_iter)
return 1; //nothing to iterate
-
- *p_outputs[0]=p_working_mem[0].iter_get( p_working_mem[1],valid);
+ *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Iterator became invalid");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Iterator became invalid");
return 0;
}
-
} else { //continue sequence
bool valid;
- bool can_iter = p_working_mem[0].iter_next(p_working_mem[1],valid);
+ bool can_iter = p_working_mem[0].iter_next(p_working_mem[1], valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Iterator became invalid: ")+Variant::get_type_name(p_inputs[0]->get_type());
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Iterator became invalid: ") + Variant::get_type_name(p_inputs[0]->get_type());
return 0;
}
if (!can_iter)
return 1; //nothing to iterate
-
- *p_outputs[0]=p_working_mem[0].iter_get( p_working_mem[1],valid);
+ *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Iterator became invalid");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Iterator became invalid");
return 0;
}
-
}
- return 0|STEP_FLAG_PUSH_STACK_BIT; //go around
+ return 0 | STEP_FLAG_PUSH_STACK_BIT; //go around
}
-
-
};
-VisualScriptNodeInstance* VisualScriptIterator::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptIterator::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceIterator * instance = memnew(VisualScriptNodeInstanceIterator );
- instance->node=this;
- instance->instance=p_instance;
+ VisualScriptNodeInstanceIterator *instance = memnew(VisualScriptNodeInstanceIterator);
+ instance->node = this;
+ instance->instance = p_instance;
return instance;
}
VisualScriptIterator::VisualScriptIterator() {
-
}
-
-
//////////////////////////////////////////
////////////////SEQUENCE/////////////////
//////////////////////////////////////////
@@ -520,30 +478,30 @@ int VisualScriptSequence::get_output_sequence_port_count() const {
return steps;
}
-bool VisualScriptSequence::has_input_sequence_port() const{
+bool VisualScriptSequence::has_input_sequence_port() const {
return true;
}
-int VisualScriptSequence::get_input_value_port_count() const{
+int VisualScriptSequence::get_input_value_port_count() const {
return 0;
}
-int VisualScriptSequence::get_output_value_port_count() const{
+int VisualScriptSequence::get_output_value_port_count() const {
return 1;
}
String VisualScriptSequence::get_output_sequence_port_text(int p_port) const {
- return itos(p_port+1);
+ return itos(p_port + 1);
}
-PropertyInfo VisualScriptSequence::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSequence::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptSequence::get_output_value_port_info(int p_idx) const{
- return PropertyInfo(Variant::INT,"current");
+PropertyInfo VisualScriptSequence::get_output_value_port_info(int p_idx) const {
+ return PropertyInfo(Variant::INT, "current");
}
String VisualScriptSequence::get_caption() const {
@@ -557,13 +515,12 @@ String VisualScriptSequence::get_text() const {
void VisualScriptSequence::set_steps(int p_steps) {
- ERR_FAIL_COND(p_steps<1);
- if (steps==p_steps)
+ ERR_FAIL_COND(p_steps < 1);
+ if (steps == p_steps)
return;
- steps=p_steps;
+ steps = p_steps;
ports_changed_notify();
-
}
int VisualScriptSequence::get_steps() const {
@@ -573,16 +530,14 @@ int VisualScriptSequence::get_steps() const {
void VisualScriptSequence::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_steps","steps"),&VisualScriptSequence::set_steps);
- ClassDB::bind_method(D_METHOD("get_steps"),&VisualScriptSequence::get_steps);
-
- ADD_PROPERTY(PropertyInfo(Variant::INT,"steps",PROPERTY_HINT_RANGE,"1,64,1"),"set_steps","get_steps");
+ ClassDB::bind_method(D_METHOD("set_steps", "steps"), &VisualScriptSequence::set_steps);
+ ClassDB::bind_method(D_METHOD("get_steps"), &VisualScriptSequence::get_steps);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "steps", PROPERTY_HINT_RANGE, "1,64,1"), "set_steps", "get_steps");
}
class VisualScriptNodeInstanceSequence : public VisualScriptNodeInstance {
public:
-
VisualScriptSequence *node;
VisualScriptInstance *instance;
int steps;
@@ -591,89 +546,83 @@ public:
//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; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_BEGIN_SEQUENCE) {
+ if (p_start_mode == START_MODE_BEGIN_SEQUENCE) {
- p_working_mem[0]=0;
+ p_working_mem[0] = 0;
}
int step = p_working_mem[0];
- *p_outputs[0]=step;
+ *p_outputs[0] = step;
- if (step+1==steps)
+ if (step + 1 == steps)
return step;
else {
- p_working_mem[0]=step+1;
- return step|STEP_FLAG_PUSH_STACK_BIT;
+ p_working_mem[0] = step + 1;
+ return step | STEP_FLAG_PUSH_STACK_BIT;
}
-
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSequence::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSequence * instance = memnew(VisualScriptNodeInstanceSequence );
- instance->node=this;
- instance->instance=p_instance;
- instance->steps=steps;
+ VisualScriptNodeInstanceSequence *instance = memnew(VisualScriptNodeInstanceSequence);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->steps = steps;
return instance;
}
VisualScriptSequence::VisualScriptSequence() {
- steps=1;
+ steps = 1;
}
-
//////////////////////////////////////////
////////////////EVENT TYPE FILTER///////////
//////////////////////////////////////////
int VisualScriptSwitch::get_output_sequence_port_count() const {
- return case_values.size()+1;
+ return case_values.size() + 1;
}
-bool VisualScriptSwitch::has_input_sequence_port() const{
+bool VisualScriptSwitch::has_input_sequence_port() const {
return true;
}
-int VisualScriptSwitch::get_input_value_port_count() const{
-
+int VisualScriptSwitch::get_input_value_port_count() const {
- return case_values.size()+1;
+ return case_values.size() + 1;
}
-int VisualScriptSwitch::get_output_value_port_count() const{
+int VisualScriptSwitch::get_output_value_port_count() const {
return 0;
}
String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const {
- if (p_port==case_values.size())
+ if (p_port == case_values.size())
return "done";
return String();
}
-PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const {
- if (p_idx<case_values.size()) {
- return PropertyInfo(case_values[p_idx].type," =");
+ if (p_idx < case_values.size()) {
+ return PropertyInfo(case_values[p_idx].type, " =");
} else
- return PropertyInfo(Variant::NIL,"input");
+ return PropertyInfo(Variant::NIL, "input");
}
-PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptSwitch::get_caption() const {
return "Switch";
@@ -684,47 +633,43 @@ String VisualScriptSwitch::get_text() const {
return "'input' is:";
}
-
class VisualScriptNodeInstanceSwitch : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
int case_count;
//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 false; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_CONTINUE_SEQUENCE) {
+ if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) {
return case_count; //exit
}
- for(int i=0;i<case_count;i++) {
+ for (int i = 0; i < case_count; i++) {
- if (*p_inputs[i]==*p_inputs[case_count]) {
- return i|STEP_FLAG_PUSH_STACK_BIT;
+ if (*p_inputs[i] == *p_inputs[case_count]) {
+ return i | STEP_FLAG_PUSH_STACK_BIT;
}
}
return case_count;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSwitch::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSwitch * instance = memnew(VisualScriptNodeInstanceSwitch );
- instance->instance=p_instance;
- instance->case_count=case_values.size();
+ VisualScriptNodeInstanceSwitch *instance = memnew(VisualScriptNodeInstanceSwitch);
+ instance->instance = p_instance;
+ instance->case_count = case_values.size();
return instance;
}
-bool VisualScriptSwitch::_set(const StringName& p_name, const Variant& p_value) {
+bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) {
- if (String(p_name)=="case_count") {
+ if (String(p_name) == "case_count") {
case_values.resize(p_value);
_change_notify();
ports_changed_notify();
@@ -733,10 +678,10 @@ bool VisualScriptSwitch::_set(const StringName& p_name, const Variant& p_value)
if (String(p_name).begins_with("case/")) {
- int idx = String(p_name).get_slice("/",1).to_int();
- ERR_FAIL_INDEX_V(idx,case_values.size(),false);
+ int idx = String(p_name).get_slice("/", 1).to_int();
+ ERR_FAIL_INDEX_V(idx, case_values.size(), false);
- case_values[idx].type=Variant::Type(int(p_value));
+ case_values[idx].type = Variant::Type(int(p_value));
_change_notify();
ports_changed_notify();
@@ -746,71 +691,63 @@ bool VisualScriptSwitch::_set(const StringName& p_name, const Variant& p_value)
return false;
}
-bool VisualScriptSwitch::_get(const StringName& p_name,Variant &r_ret) const {
+bool VisualScriptSwitch::_get(const StringName &p_name, Variant &r_ret) const {
- if (String(p_name)=="case_count") {
- r_ret=case_values.size();
+ if (String(p_name) == "case_count") {
+ r_ret = case_values.size();
return true;
}
if (String(p_name).begins_with("case/")) {
- int idx = String(p_name).get_slice("/",1).to_int();
- ERR_FAIL_INDEX_V(idx,case_values.size(),false);
+ int idx = String(p_name).get_slice("/", 1).to_int();
+ ERR_FAIL_INDEX_V(idx, case_values.size(), false);
- r_ret=case_values[idx].type;
+ r_ret = case_values[idx].type;
return true;
}
return false;
-
}
-void VisualScriptSwitch::_get_property_list( List<PropertyInfo> *p_list) const {
+void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back(PropertyInfo(Variant::INT,"case_count",PROPERTY_HINT_RANGE,"0,128"));
+ p_list->push_back(PropertyInfo(Variant::INT, "case_count", PROPERTY_HINT_RANGE, "0,128"));
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- for(int i=0;i<case_values.size();i++) {
- p_list->push_back(PropertyInfo(Variant::INT,"case/"+itos(i),PROPERTY_HINT_ENUM,argt));
+ for (int i = 0; i < case_values.size(); i++) {
+ p_list->push_back(PropertyInfo(Variant::INT, "case/" + itos(i), PROPERTY_HINT_ENUM, argt));
}
}
-
void VisualScriptSwitch::_bind_methods() {
-
-
}
VisualScriptSwitch::VisualScriptSwitch() {
-
-
}
//////////////////////////////////////////
////////////////EVENT ACTION FILTER///////////
//////////////////////////////////////////
-
int VisualScriptInputFilter::get_output_sequence_port_count() const {
return filters.size();
}
-bool VisualScriptInputFilter::has_input_sequence_port() const{
+bool VisualScriptInputFilter::has_input_sequence_port() const {
return true;
}
-int VisualScriptInputFilter::get_input_value_port_count() const{
-
+int VisualScriptInputFilter::get_input_value_port_count() const {
return 1;
}
-int VisualScriptInputFilter::get_output_value_port_count() const{
+int VisualScriptInputFilter::get_output_value_port_count() const {
return 1;
}
@@ -819,60 +756,60 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const
String text;
- switch(filters[p_port].type) {
+ switch (filters[p_port].type) {
case InputEvent::NONE: {
- text="None";
+ text = "None";
} break;
case InputEvent::KEY: {
InputEventKey k = filters[p_port].key;
- if (k.scancode==0 && k.unicode==0) {
- text="No Key";
+ if (k.scancode == 0 && k.unicode == 0) {
+ text = "No Key";
} else {
- if (k.scancode!=0) {
- text="KeyCode: "+keycode_get_string(k.scancode);
- } else if (k.unicode!=0) {
- text="Uniode: "+String::chr(k.unicode);
+ if (k.scancode != 0) {
+ text = "KeyCode: " + keycode_get_string(k.scancode);
+ } else if (k.unicode != 0) {
+ text = "Uniode: " + String::chr(k.unicode);
}
if (k.pressed)
- text+=", Pressed";
+ text += ", Pressed";
else
- text+=", Released";
+ text += ", Released";
if (k.echo)
- text+=", Echo";
+ text += ", Echo";
if (k.mod.alt)
- text="Alt+"+text;
+ text = "Alt+" + text;
if (k.mod.shift)
- text="Shift+"+text;
+ text = "Shift+" + text;
if (k.mod.control)
- text="Ctrl+"+text;
+ text = "Ctrl+" + text;
if (k.mod.meta)
- text="Meta+"+text;
+ text = "Meta+" + text;
}
} break;
case InputEvent::MOUSE_MOTION: {
InputEventMouseMotion mm = filters[p_port].mouse_motion;
- text="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)) {
- text=b.get_slice(",",i)+"+"+text;
+ for (int i = 0; i < 7; i++) {
+ if (mm.button_mask & (1 << i)) {
+ text = b.get_slice(",", i) + "+" + text;
}
}
if (mm.mod.alt)
- text="Alt+"+text;
+ text = "Alt+" + text;
if (mm.mod.shift)
- text="Shift+"+text;
+ text = "Shift+" + text;
if (mm.mod.control)
- text="Ctrl+"+text;
+ text = "Ctrl+" + text;
if (mm.mod.meta)
- text="Meta+"+text;
+ text = "Meta+" + text;
} break;
case InputEvent::MOUSE_BUTTON: {
@@ -880,106 +817,99 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const
String b = "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight";
- text=b.get_slice(",",mb.button_index)+" Mouse Button";
+ text = b.get_slice(",", mb.button_index) + " Mouse Button";
if (mb.pressed)
- text+=", Pressed";
+ text += ", Pressed";
else
- text+=", Released";
+ text += ", Released";
if (mb.doubleclick)
- text+=", DblClick";
+ text += ", DblClick";
if (mb.mod.alt)
- text="Alt+"+text;
+ text = "Alt+" + text;
if (mb.mod.shift)
- text="Shift+"+text;
+ text = "Shift+" + text;
if (mb.mod.control)
- text="Ctrl+"+text;
+ text = "Ctrl+" + text;
if (mb.mod.meta)
- text="Meta+"+text;
-
+ text = "Meta+" + text;
} break;
case InputEvent::JOYPAD_MOTION: {
InputEventJoypadMotion jm = filters[p_port].joy_motion;
- text="JoyMotion Axis "+itos(jm.axis>>1);
- if (jm.axis&1)
- text+=" > "+rtos(jm.axis_value);
+ text = "JoyMotion Axis " + itos(jm.axis >> 1);
+ if (jm.axis & 1)
+ text += " > " + rtos(jm.axis_value);
else
- text+=" < "+rtos(-jm.axis_value);
+ text += " < " + rtos(-jm.axis_value);
} break;
case InputEvent::JOYPAD_BUTTON: {
InputEventJoypadButton jb = filters[p_port].joy_button;
- text="JoyButton "+itos(jb.button_index);
+ text = "JoyButton " + itos(jb.button_index);
if (jb.pressed)
- text+=", Pressed";
+ text += ", Pressed";
else
- text+=", Released";
+ text += ", Released";
} break;
case InputEvent::SCREEN_TOUCH: {
InputEventScreenTouch sd = filters[p_port].screen_touch;
- text="Touch Finger "+itos(sd.index);
+ text = "Touch Finger " + itos(sd.index);
if (sd.pressed)
- text+=", Pressed";
+ text += ", Pressed";
else
- text+=", Released";
+ text += ", Released";
} break;
case InputEvent::SCREEN_DRAG: {
InputEventScreenDrag sd = filters[p_port].screen_drag;
- text="Drag Finger "+itos(sd.index);
+ text = "Drag Finger " + itos(sd.index);
} break;
case InputEvent::ACTION: {
-
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
- int index=1;
+ int index = 1;
- text="No Action";
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ text = "No Action";
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
-
- if (filters[p_port].action.action==index) {
- text="Action "+pi.name.substr(pi.name.find("/")+1,pi.name.length());
+ if (filters[p_port].action.action == index) {
+ text = "Action " + pi.name.substr(pi.name.find("/") + 1, pi.name.length());
break;
}
index++;
}
if (filters[p_port].action.pressed)
- text+=", Pressed";
+ text += ", Pressed";
else
- text+=", Released";
-
+ text += ", Released";
} break;
}
-
-
- return text+" - "+itos(p_port);
+ return text + " - " + itos(p_port);
}
-PropertyInfo VisualScriptInputFilter::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptInputFilter::get_input_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::INPUT_EVENT,"event");
+ return PropertyInfo(Variant::INPUT_EVENT, "event");
}
-PropertyInfo VisualScriptInputFilter::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptInputFilter::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::INPUT_EVENT,"");
+ return PropertyInfo(Variant::INPUT_EVENT, "");
}
-
String VisualScriptInputFilter::get_caption() const {
return "InputFilter";
@@ -990,94 +920,90 @@ String VisualScriptInputFilter::get_text() const {
return "";
}
+bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_value) {
-
-bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_value) {
-
- if (p_name=="filter_count") {
+ if (p_name == "filter_count") {
filters.resize(p_value);
_change_notify();
ports_changed_notify();
return true;
}
-
if (String(p_name).begins_with("filter_")) {
- int idx = String(p_name).replace_first("filters_","").get_slice("/",0).to_int();
-
- ERR_FAIL_INDEX_V(idx,filters.size(),false);
-
- 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;
+ int idx = String(p_name).replace_first("filters_", "").get_slice("/", 0).to_int();
+
+ ERR_FAIL_INDEX_V(idx, filters.size(), false);
+
+ 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;
}
_change_notify();
ports_changed_notify();
return true;
}
- if (what=="device") {
- filters[idx].device=p_value;
+ if (what == "device") {
+ filters[idx].device = p_value;
ports_changed_notify();
return true;
}
- switch(filters[idx].type) {
+ switch (filters[idx].type) {
case InputEvent::KEY: {
- if (what=="scancode") {
+ if (what == "scancode") {
String sc = p_value;
- if (sc==String()) {
- filters[idx].key.scancode=0;
+ if (sc == String()) {
+ filters[idx].key.scancode = 0;
} else {
- filters[idx].key.scancode=find_keycode(p_value);
+ filters[idx].key.scancode = find_keycode(p_value);
}
- } else if (what=="unicode") {
+ } else if (what == "unicode") {
String uc = p_value;
- if (uc==String()) {
- filters[idx].key.unicode=0;
+ if (uc == String()) {
+ filters[idx].key.unicode = 0;
} else {
- filters[idx].key.unicode=uc[0];
+ filters[idx].key.unicode = uc[0];
}
- } else if (what=="pressed") {
+ } else if (what == "pressed") {
- filters[idx].key.pressed=p_value;
- } else if (what=="echo") {
+ filters[idx].key.pressed = p_value;
+ } else if (what == "echo") {
- filters[idx].key.echo=p_value;
+ filters[idx].key.echo = p_value;
- } else if (what=="mod_alt") {
- filters[idx].key.mod.alt=p_value;
+ } else if (what == "mod_alt") {
+ filters[idx].key.mod.alt = p_value;
- } else if (what=="mod_shift") {
- filters[idx].key.mod.shift=p_value;
+ } else if (what == "mod_shift") {
+ filters[idx].key.mod.shift = p_value;
- } else if (what=="mod_ctrl") {
- filters[idx].key.mod.control=p_value;
+ } else if (what == "mod_ctrl") {
+ filters[idx].key.mod.control = p_value;
- } else if (what=="mod_meta") {
- filters[idx].key.mod.meta=p_value;
+ } else if (what == "mod_meta") {
+ filters[idx].key.mod.meta = p_value;
} else {
return false;
}
@@ -1087,21 +1013,20 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
} break;
case InputEvent::MOUSE_MOTION: {
+ if (what == "button_mask") {
+ filters[idx].mouse_motion.button_mask = p_value;
- if (what=="button_mask") {
- filters[idx].mouse_motion.button_mask=p_value;
-
- } else if (what=="mod_alt") {
- filters[idx].mouse_motion.mod.alt=p_value;
+ } else if (what == "mod_alt") {
+ filters[idx].mouse_motion.mod.alt = p_value;
- } else if (what=="mod_shift") {
- filters[idx].mouse_motion.mod.shift=p_value;
+ } else if (what == "mod_shift") {
+ filters[idx].mouse_motion.mod.shift = p_value;
- } else if (what=="mod_ctrl") {
- filters[idx].mouse_motion.mod.control=p_value;
+ } else if (what == "mod_ctrl") {
+ filters[idx].mouse_motion.mod.control = p_value;
- } else if (what=="mod_meta") {
- filters[idx].mouse_motion.mod.meta=p_value;
+ } else if (what == "mod_meta") {
+ filters[idx].mouse_motion.mod.meta = p_value;
} else {
return false;
}
@@ -1112,24 +1037,24 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
} break;
case InputEvent::MOUSE_BUTTON: {
- if (what=="button_index") {
- filters[idx].mouse_button.button_index=p_value;
- } else if (what=="pressed") {
- filters[idx].mouse_button.pressed=p_value;
- } else if (what=="doubleclicked") {
- filters[idx].mouse_button.doubleclick=p_value;
+ if (what == "button_index") {
+ filters[idx].mouse_button.button_index = p_value;
+ } else if (what == "pressed") {
+ filters[idx].mouse_button.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;
+ } else if (what == "mod_alt") {
+ filters[idx].mouse_button.mod.alt = p_value;
- } else if (what=="mod_shift") {
- filters[idx].mouse_button.mod.shift=p_value;
+ } else if (what == "mod_shift") {
+ filters[idx].mouse_button.mod.shift = p_value;
- } else if (what=="mod_ctrl") {
- filters[idx].mouse_button.mod.control=p_value;
+ } else if (what == "mod_ctrl") {
+ filters[idx].mouse_button.mod.control = p_value;
- } else if (what=="mod_meta") {
- filters[idx].mouse_button.mod.meta=p_value;
+ } else if (what == "mod_meta") {
+ filters[idx].mouse_button.mod.meta = p_value;
} else {
return false;
}
@@ -1139,26 +1064,25 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
} break;
case 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") {
- filters[idx].joy_motion.axis_value=p_value;
+ 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") {
+ filters[idx].joy_motion.axis_value = p_value;
} else {
return false;
}
ports_changed_notify();
return true;
-
} break;
case InputEvent::JOYPAD_BUTTON: {
- if (what=="button_index") {
- filters[idx].joy_button.button_index=p_value;
- } else if (what=="pressed") {
- filters[idx].joy_button.pressed=p_value;
+ if (what == "button_index") {
+ filters[idx].joy_button.button_index = p_value;
+ } else if (what == "pressed") {
+ filters[idx].joy_button.pressed = p_value;
} else {
return false;
}
@@ -1168,10 +1092,10 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
} break;
case 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;
+ if (what == "finger_index") {
+ filters[idx].screen_touch.index = p_value;
+ } else if (what == "pressed") {
+ filters[idx].screen_touch.pressed = p_value;
} else {
return false;
}
@@ -1179,8 +1103,8 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
return true;
} break;
case InputEvent::SCREEN_DRAG: {
- if (what=="finger_index") {
- filters[idx].screen_drag.index=p_value;
+ if (what == "finger_index") {
+ filters[idx].screen_drag.index = p_value;
} else {
return false;
}
@@ -1189,23 +1113,22 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
} break;
case InputEvent::ACTION: {
-
- if (what=="action_name") {
+ if (what == "action_name") {
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
- int index=1;
+ int index = 1;
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
- String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
- if (name==String(p_value)) {
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
+ if (name == String(p_value)) {
- filters[idx].action.action=index;
+ filters[idx].action.action = index;
ports_changed_notify();
return true;
}
@@ -1213,92 +1136,87 @@ bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_va
index++;
}
- filters[idx].action.action=0;
+ filters[idx].action.action = 0;
ports_changed_notify();
return false;
- } else if (what=="pressed") {
+ } else if (what == "pressed") {
- filters[idx].action.pressed=p_value;
+ filters[idx].action.pressed = p_value;
ports_changed_notify();
return true;
}
-
} break;
-
}
}
return false;
}
-bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) const{
+bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) const {
- if (p_name=="filter_count") {
- r_ret=filters.size();
+ if (p_name == "filter_count") {
+ r_ret = filters.size();
return true;
}
-
if (String(p_name).begins_with("filter_")) {
- int idx = String(p_name).replace_first("filters_","").get_slice("/",0).to_int();
-
- ERR_FAIL_INDEX_V(idx,filters.size(),false);
+ int idx = String(p_name).replace_first("filters_", "").get_slice("/", 0).to_int();
- String what = String(p_name).get_slice("/",1);
+ ERR_FAIL_INDEX_V(idx, filters.size(), false);
+ String what = String(p_name).get_slice("/", 1);
- if (what=="type") {
- r_ret=filters[idx].type;
+ if (what == "type") {
+ r_ret = filters[idx].type;
return true;
}
- if (what=="device") {
- r_ret=filters[idx].device;
+ if (what == "device") {
+ r_ret = filters[idx].device;
return true;
}
- switch(filters[idx].type) {
+ switch (filters[idx].type) {
case InputEvent::KEY: {
- if (what=="scancode") {
- if (filters[idx].key.scancode==0)
- r_ret=String();
+ if (what == "scancode") {
+ if (filters[idx].key.scancode == 0)
+ r_ret = String();
else {
- r_ret=keycode_get_string(filters[idx].key.scancode);
+ r_ret = keycode_get_string(filters[idx].key.scancode);
}
- } else if (what=="unicode") {
+ } else if (what == "unicode") {
-
- if (filters[idx].key.unicode==0) {
- r_ret=String();
+ if (filters[idx].key.unicode == 0) {
+ r_ret = String();
} else {
- CharType str[2]={ (CharType)filters[idx].key.unicode, 0};
- r_ret=String(str);
+ CharType str[2] = { (CharType)filters[idx].key.unicode, 0 };
+ r_ret = String(str);
}
- } else if (what=="pressed") {
+ } else if (what == "pressed") {
- r_ret=filters[idx].key.pressed;
- } else if (what=="echo") {
+ r_ret = filters[idx].key.pressed;
+ } else if (what == "echo") {
- r_ret=filters[idx].key.echo;
+ r_ret = filters[idx].key.echo;
- } else if (what=="mod_alt") {
- r_ret=filters[idx].key.mod.alt;
+ } else if (what == "mod_alt") {
+ r_ret = filters[idx].key.mod.alt;
- } else if (what=="mod_shift") {
- r_ret=filters[idx].key.mod.shift;
+ } else if (what == "mod_shift") {
+ r_ret = filters[idx].key.mod.shift;
- } else if (what=="mod_ctrl") {
- r_ret=filters[idx].key.mod.control;
+ } else if (what == "mod_ctrl") {
+ r_ret = filters[idx].key.mod.control;
- } else if (what=="mod_meta") {
- r_ret=filters[idx].key.mod.meta;
+ } else if (what == "mod_meta") {
+ r_ret = filters[idx].key.mod.meta;
} else {
return false;
}
@@ -1307,21 +1225,20 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons
} break;
case InputEvent::MOUSE_MOTION: {
+ if (what == "button_mask") {
+ r_ret = filters[idx].mouse_motion.button_mask;
- if (what=="button_mask") {
- r_ret=filters[idx].mouse_motion.button_mask;
-
- } else if (what=="mod_alt") {
- r_ret=filters[idx].mouse_motion.mod.alt;
+ } else if (what == "mod_alt") {
+ r_ret = filters[idx].mouse_motion.mod.alt;
- } else if (what=="mod_shift") {
- r_ret=filters[idx].mouse_motion.mod.shift;
+ } else if (what == "mod_shift") {
+ r_ret = filters[idx].mouse_motion.mod.shift;
- } else if (what=="mod_ctrl") {
- r_ret=filters[idx].mouse_motion.mod.control;
+ } else if (what == "mod_ctrl") {
+ r_ret = filters[idx].mouse_motion.mod.control;
- } else if (what=="mod_meta") {
- r_ret=filters[idx].mouse_motion.mod.meta;
+ } else if (what == "mod_meta") {
+ r_ret = filters[idx].mouse_motion.mod.meta;
} else {
return false;
}
@@ -1331,24 +1248,24 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons
} break;
case InputEvent::MOUSE_BUTTON: {
- if (what=="button_index") {
- r_ret=filters[idx].mouse_button.button_index;
- } else if (what=="pressed") {
- r_ret=filters[idx].mouse_button.pressed;
- } else if (what=="doubleclicked") {
- r_ret=filters[idx].mouse_button.doubleclick;
+ if (what == "button_index") {
+ r_ret = filters[idx].mouse_button.button_index;
+ } else if (what == "pressed") {
+ r_ret = filters[idx].mouse_button.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;
+ } else if (what == "mod_alt") {
+ r_ret = filters[idx].mouse_button.mod.alt;
- } else if (what=="mod_shift") {
- r_ret=filters[idx].mouse_button.mod.shift;
+ } else if (what == "mod_shift") {
+ r_ret = filters[idx].mouse_button.mod.shift;
- } else if (what=="mod_ctrl") {
- r_ret=filters[idx].mouse_button.mod.control;
+ } else if (what == "mod_ctrl") {
+ r_ret = filters[idx].mouse_button.mod.control;
- } else if (what=="mod_meta") {
- r_ret=filters[idx].mouse_button.mod.meta;
+ } else if (what == "mod_meta") {
+ r_ret = filters[idx].mouse_button.mod.meta;
} else {
return false;
}
@@ -1357,25 +1274,24 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons
} break;
case 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") {
- r_ret=filters[idx].joy_motion.axis_value;
+ 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") {
+ r_ret = filters[idx].joy_motion.axis_value;
} else {
return false;
}
return true;
-
} break;
case InputEvent::JOYPAD_BUTTON: {
- if (what=="button_index") {
- r_ret=filters[idx].joy_button.button_index;
- } else if (what=="pressed") {
- r_ret=filters[idx].joy_button.pressed;
+ if (what == "button_index") {
+ r_ret = filters[idx].joy_button.button_index;
+ } else if (what == "pressed") {
+ r_ret = filters[idx].joy_button.pressed;
} else {
return false;
}
@@ -1384,18 +1300,18 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons
} break;
case 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;
+ if (what == "finger_index") {
+ r_ret = filters[idx].screen_touch.index;
+ } else if (what == "pressed") {
+ r_ret = filters[idx].screen_touch.pressed;
} else {
return false;
}
return true;
} break;
case InputEvent::SCREEN_DRAG: {
- if (what=="finger_index") {
- r_ret=filters[idx].screen_drag.index;
+ if (what == "finger_index") {
+ r_ret = filters[idx].screen_drag.index;
} else {
return false;
}
@@ -1403,45 +1319,41 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons
} break;
case InputEvent::ACTION: {
-
- if (what=="action_name") {
+ if (what == "action_name") {
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
- int index=1;
+ int index = 1;
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
-
- if (filters[idx].action.action==index) {
- r_ret=pi.name.substr(pi.name.find("/")+1,pi.name.length());
+ if (filters[idx].action.action == index) {
+ r_ret = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
return true;
}
index++;
}
- r_ret="None"; //no index
+ r_ret = "None"; //no index
return false;
- } else if (what=="pressed") {
+ } else if (what == "pressed") {
- r_ret=filters[idx].action.pressed;
+ r_ret = filters[idx].action.pressed;
return true;
}
-
} break;
-
}
}
return false;
}
-static const char* event_type_names[InputEvent::TYPE_MAX]={
+static const char *event_type_names[InputEvent::TYPE_MAX] = {
"None",
"Key",
"MouseMotion",
@@ -1453,186 +1365,175 @@ static const char* event_type_names[InputEvent::TYPE_MAX]={
"Action"
};
-void VisualScriptInputFilter::_get_property_list( List<PropertyInfo> *p_list) const {
+void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back(PropertyInfo(Variant::INT,"filter_count",PROPERTY_HINT_RANGE,"0,64"));
+ 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++) {
- if (i>0)
- et+=",";
+ for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
+ if (i > 0)
+ et += ",";
- et+=event_type_names[i];
+ et += event_type_names[i];
}
String kc;
String actions;
+ for (int i = 0; i < filters.size(); i++) {
-
- for(int i=0;i<filters.size();i++) {
-
- String base = "filter_"+itos(i)+"/";
- p_list->push_back(PropertyInfo(Variant::INT,base+"type",PROPERTY_HINT_ENUM,et));
- p_list->push_back(PropertyInfo(Variant::INT,base+"device"));
- switch(filters[i].type) {
+ String base = "filter_" + itos(i) + "/";
+ p_list->push_back(PropertyInfo(Variant::INT, base + "type", PROPERTY_HINT_ENUM, et));
+ p_list->push_back(PropertyInfo(Variant::INT, base + "device"));
+ switch (filters[i].type) {
case InputEvent::NONE: {
} break;
case InputEvent::KEY: {
- if (kc==String()) {
+ if (kc == String()) {
int kcc = keycode_get_count();
- kc="None";
- for(int i=0;i<kcc;i++) {
- kc+=",";
- kc+=String(keycode_get_name_by_index(i));
+ kc = "None";
+ for (int i = 0; i < kcc; i++) {
+ kc += ",";
+ kc += String(keycode_get_name_by_index(i));
}
}
- p_list->push_back(PropertyInfo(Variant::STRING,base+"scancode",PROPERTY_HINT_ENUM,kc));
- p_list->push_back(PropertyInfo(Variant::STRING,base+"unicode"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"pressed"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"echo"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_alt"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_shift"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_ctrl"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_meta"));
-
+ p_list->push_back(PropertyInfo(Variant::STRING, base + "scancode", PROPERTY_HINT_ENUM, kc));
+ p_list->push_back(PropertyInfo(Variant::STRING, base + "unicode"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "echo"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_alt"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_shift"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_ctrl"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
case 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"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_ctrl"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_meta"));
+ 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"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_ctrl"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
case 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"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_alt"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_shift"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_ctrl"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"mod_meta"));
+ 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"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_alt"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_shift"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_ctrl"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
case 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::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"));
} break;
case InputEvent::JOYPAD_BUTTON: {
- p_list->push_back(PropertyInfo(Variant::INT,base+"button_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"pressed"));
+ p_list->push_back(PropertyInfo(Variant::INT, base + "button_index"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
} break;
case InputEvent::SCREEN_TOUCH: {
- p_list->push_back(PropertyInfo(Variant::INT,base+"finger_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"pressed"));
+ p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
} break;
case InputEvent::SCREEN_DRAG: {
- p_list->push_back(PropertyInfo(Variant::INT,base+"finger_index"));
+ p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index"));
} break;
case InputEvent::ACTION: {
+ if (actions == String()) {
-
- if (actions==String()) {
-
- actions="None";
+ actions = "None";
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
Vector<String> al;
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
- String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
-
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
al.push_back(name);
}
- for(int i=0;i<al.size();i++) {
- actions+=",";
- actions+=al[i];
+ for (int i = 0; i < al.size(); i++) {
+ actions += ",";
+ actions += al[i];
}
}
- p_list->push_back(PropertyInfo(Variant::STRING,base+"action_name",PROPERTY_HINT_ENUM,actions));
- p_list->push_back(PropertyInfo(Variant::BOOL,base+"pressed"));
+ p_list->push_back(PropertyInfo(Variant::STRING, base + "action_name", PROPERTY_HINT_ENUM, actions));
+ p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
} break;
-
}
}
}
class VisualScriptNodeInstanceInputFilter : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
Vector<InputEvent> filters;
//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 false; }
- 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) {
+ 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) {
- if (p_inputs[0]->get_type()!=Variant::INPUT_EVENT) {
- r_error_str="Input value not of type event";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ if (p_inputs[0]->get_type() != Variant::INPUT_EVENT) {
+ r_error_str = "Input value not of type event";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
InputEvent event = *p_inputs[0];
-
- for(int i=0;i<filters.size();i++) {
+ for (int i = 0; i < filters.size(); i++) {
const InputEvent &ie = filters[i];
- if (ie.type!=event.type)
+ if (ie.type != event.type)
continue;
- bool match=false;
+ bool match = false;
- switch(ie.type) {
+ switch (ie.type) {
case InputEvent::NONE: {
- match=true;
+ match = true;
} break;
case InputEvent::KEY: {
InputEventKey k = ie.key;
InputEventKey k2 = event.key;
- if (k.scancode==0 && k.unicode==0 && k2.scancode==0 && k2.unicode==0) {
- match=true;
+ if (k.scancode == 0 && k.unicode == 0 && k2.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.scancode != 0 && k.scancode == k2.scancode) || (k.unicode != 0 && k.unicode == k2.unicode)) {
//key valid
if (
- k.pressed==k2.pressed &&
- k.echo==k2.echo &&
- k.mod == k2.mod
- ) {
- match=true;
+ k.pressed == k2.pressed &&
+ k.echo == k2.echo &&
+ k.mod == k2.mod) {
+ match = true;
}
}
-
}
} break;
@@ -1640,10 +1541,9 @@ public:
InputEventMouseMotion mm = ie.mouse_motion;
InputEventMouseMotion mm2 = event.mouse_motion;
- if ( mm.button_mask==mm2.button_mask &&
- mm.mod==mm2.mod
- ) {
- match=true;
+ if (mm.button_mask == mm2.button_mask &&
+ mm.mod == mm2.mod) {
+ match = true;
}
} break;
@@ -1652,56 +1552,53 @@ public:
InputEventMouseButton mb = ie.mouse_button;
InputEventMouseButton mb2 = event.mouse_button;
- if ( mb.button_index==mb2.button_index &&
- mb.pressed==mb2.pressed &&
- mb.doubleclick==mb2.doubleclick &&
- mb.mod==mb2.mod) {
- match=true;
+ if (mb.button_index == mb2.button_index &&
+ mb.pressed == mb2.pressed &&
+ mb.doubleclick == mb2.doubleclick &&
+ mb.mod == mb2.mod) {
+ match = true;
}
-
} break;
case InputEvent::JOYPAD_MOTION: {
InputEventJoypadMotion jm = ie.joy_motion;
InputEventJoypadMotion jm2 = event.joy_motion;
- int axis = jm.axis>>1;
+ int axis = jm.axis >> 1;
- if (axis==jm2.axis) {
+ if (axis == jm2.axis) {
- if (jm.axis&1) {
+ if (jm.axis & 1) {
//greater
if (jm2.axis_value > jm.axis_value) {
- match=true;
+ match = true;
}
} else {
//less
if (jm2.axis_value < -jm.axis_value) {
- match=true;
+ match = true;
}
}
}
-
} break;
case InputEvent::JOYPAD_BUTTON: {
InputEventJoypadButton jb = ie.joy_button;
InputEventJoypadButton jb2 = event.joy_button;
- if ( jb.button_index==jb2.button_index &&
- jb.pressed == jb2.pressed
- ) {
- match=true;
+ if (jb.button_index == jb2.button_index &&
+ jb.pressed == jb2.pressed) {
+ match = true;
}
} break;
case InputEvent::SCREEN_TOUCH: {
InputEventScreenTouch st = ie.screen_touch;
InputEventScreenTouch st2 = event.screen_touch;
- if ( st.index==st2.index &&
- st.pressed==st2.pressed) {
- match=true;
+ if (st.index == st2.index &&
+ st.pressed == st2.pressed) {
+ match = true;
}
} break;
@@ -1709,8 +1606,8 @@ public:
InputEventScreenDrag sd = ie.screen_drag;
InputEventScreenDrag sd2 = event.screen_drag;
- if (sd.index==sd2.index) {
- match=true;
+ if (sd.index == sd2.index) {
+ match = true;
}
} break;
case InputEvent::ACTION: {
@@ -1718,88 +1615,72 @@ public:
InputEventAction ia = ie.action;
InputEventAction ia2 = event.action;
- if ( ia.action==ia2.action &&
- ia.pressed==ia2.pressed) {
- match=true;
+ if (ia.action == ia2.action &&
+ ia.pressed == ia2.pressed) {
+ match = true;
}
} break;
-
}
*p_outputs[0] = event;
if (match)
return i; //go through match output
-
}
return STEP_NO_ADVANCE_BIT; //none found, don't advance
-
-
}
-
-
};
+VisualScriptNodeInstance *VisualScriptInputFilter::instance(VisualScriptInstance *p_instance) {
-VisualScriptNodeInstance* VisualScriptInputFilter::instance(VisualScriptInstance* p_instance) {
-
- VisualScriptNodeInstanceInputFilter * instance = memnew(VisualScriptNodeInstanceInputFilter );
- instance->instance=p_instance;
- instance->filters=filters;
+ VisualScriptNodeInstanceInputFilter *instance = memnew(VisualScriptNodeInstanceInputFilter);
+ instance->instance = p_instance;
+ instance->filters = filters;
return instance;
}
-
-
-
VisualScriptInputFilter::VisualScriptInputFilter() {
-
-
}
-
//////////////////////////////////////////
////////////////TYPE CAST///////////
//////////////////////////////////////////
-
int VisualScriptTypeCast::get_output_sequence_port_count() const {
return 2;
}
-bool VisualScriptTypeCast::has_input_sequence_port() const{
+bool VisualScriptTypeCast::has_input_sequence_port() const {
return true;
}
-int VisualScriptTypeCast::get_input_value_port_count() const{
-
+int VisualScriptTypeCast::get_input_value_port_count() const {
return 1;
}
-int VisualScriptTypeCast::get_output_value_port_count() const{
+int VisualScriptTypeCast::get_output_value_port_count() const {
return 1;
}
String VisualScriptTypeCast::get_output_sequence_port_text(int p_port) const {
- return p_port==0 ? "yes" : "no";
+ return p_port == 0 ? "yes" : "no";
}
-PropertyInfo VisualScriptTypeCast::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptTypeCast::get_input_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"instance");
+ return PropertyInfo(Variant::OBJECT, "instance");
}
-PropertyInfo VisualScriptTypeCast::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptTypeCast::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"");
+ return PropertyInfo(Variant::OBJECT, "");
}
-
String VisualScriptTypeCast::get_caption() const {
return "TypeCast";
@@ -1807,47 +1688,44 @@ String VisualScriptTypeCast::get_caption() const {
String VisualScriptTypeCast::get_text() const {
- if (script!=String())
- return "Is "+script.get_file()+"?";
+ if (script != String())
+ return "Is " + script.get_file() + "?";
else
- return "Is "+base_type+"?";
+ return "Is " + base_type + "?";
}
-void VisualScriptTypeCast::set_base_type(const StringName& p_type) {
+void VisualScriptTypeCast::set_base_type(const StringName &p_type) {
- if (base_type==p_type)
+ if (base_type == p_type)
return;
- base_type=p_type;
+ base_type = p_type;
_change_notify();
ports_changed_notify();
}
-StringName VisualScriptTypeCast::get_base_type() const{
+StringName VisualScriptTypeCast::get_base_type() const {
return base_type;
}
-void VisualScriptTypeCast::set_base_script(const String& p_path){
+void VisualScriptTypeCast::set_base_script(const String &p_path) {
- if (script==p_path)
+ if (script == p_path)
return;
- script=p_path;
+ script = p_path;
_change_notify();
ports_changed_notify();
-
}
-String VisualScriptTypeCast::get_base_script() const{
+String VisualScriptTypeCast::get_base_script() const {
return script;
}
-
class VisualScriptNodeInstanceTypeCast : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
StringName base_type;
String script;
@@ -1855,19 +1733,19 @@ public:
//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 false; }
- 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) {
+ 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) {
Object *obj = *p_inputs[0];
- *p_outputs[0]=Variant();
+ *p_outputs[0] = Variant();
if (!obj) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Instance is null";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Instance is null";
return 0;
}
- if (script!=String()) {
+ if (script != String()) {
Ref<Script> obj_script = obj->get_script();
if (!obj_script.is_valid()) {
@@ -1880,90 +1758,79 @@ public:
}
Ref<Script> cast_script = Ref<Resource>(ResourceCache::get(script));
if (!cast_script.is_valid()) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Script path is not a script: "+script;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Script path is not a script: " + script;
return 1;
}
- while(obj_script.is_valid()) {
+ while (obj_script.is_valid()) {
- if (cast_script==obj_script) {
- *p_outputs[0]=*p_inputs[0]; //copy
+ if (cast_script == obj_script) {
+ *p_outputs[0] = *p_inputs[0]; //copy
return 0; // it is the script, yey
}
- obj_script=obj_script->get_base_script();
+ obj_script = obj_script->get_base_script();
}
return 1; //not found sorry
}
- if (ClassDB::is_parent_class(obj->get_class_name(),base_type)) {
- *p_outputs[0]=*p_inputs[0]; //copy
+ if (ClassDB::is_parent_class(obj->get_class_name(), base_type)) {
+ *p_outputs[0] = *p_inputs[0]; //copy
return 0;
} else
return 1;
-
}
-
-
};
-VisualScriptNodeInstance* VisualScriptTypeCast::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceTypeCast * instance = memnew(VisualScriptNodeInstanceTypeCast );
- instance->instance=p_instance;
- instance->base_type=base_type;
- instance->script=script;
+ VisualScriptNodeInstanceTypeCast *instance = memnew(VisualScriptNodeInstanceTypeCast);
+ instance->instance = p_instance;
+ instance->base_type = base_type;
+ instance->script = script;
return instance;
}
-
-
void VisualScriptTypeCast::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_base_type","type"),&VisualScriptTypeCast::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptTypeCast::get_base_type);
-
- ClassDB::bind_method(D_METHOD("set_base_script","path"),&VisualScriptTypeCast::set_base_script);
- ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptTypeCast::get_base_script);
+ ClassDB::bind_method(D_METHOD("set_base_type", "type"), &VisualScriptTypeCast::set_base_type);
+ ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptTypeCast::get_base_type);
+ ClassDB::bind_method(D_METHOD("set_base_script", "path"), &VisualScriptTypeCast::set_base_script);
+ ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptTypeCast::get_base_script);
List<String> script_extensions;
- for(int i=0;i>ScriptServer::get_language_count();i++) {
+ for (int i = 0; i > ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
}
String script_ext_hint;
- for (List<String>::Element *E=script_extensions.front();E;E=E->next()) {
- if (script_ext_hint!=String())
- script_ext_hint+=",";
- script_ext_hint+="*."+E->get();
+ for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
+ if (script_ext_hint != String())
+ script_ext_hint += ",";
+ 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, "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");
}
VisualScriptTypeCast::VisualScriptTypeCast() {
- base_type="Object";
+ base_type = "Object";
}
-
void register_visual_script_flow_control_nodes() {
- VisualScriptLanguage::singleton->add_register_func("flow_control/return",create_return_node<false>);
- VisualScriptLanguage::singleton->add_register_func("flow_control/return_with_value",create_return_node<true>);
- VisualScriptLanguage::singleton->add_register_func("flow_control/condition",create_node_generic<VisualScriptCondition>);
- VisualScriptLanguage::singleton->add_register_func("flow_control/while",create_node_generic<VisualScriptWhile>);
- 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/type_cast",create_node_generic<VisualScriptTypeCast>);
-
-
-
+ VisualScriptLanguage::singleton->add_register_func("flow_control/return", create_return_node<false>);
+ VisualScriptLanguage::singleton->add_register_func("flow_control/return_with_value", create_return_node<true>);
+ VisualScriptLanguage::singleton->add_register_func("flow_control/condition", create_node_generic<VisualScriptCondition>);
+ VisualScriptLanguage::singleton->add_register_func("flow_control/while", create_node_generic<VisualScriptWhile>);
+ 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/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 8406bb5a5b..1739f67b5b 100644
--- a/modules/visual_script/visual_script_flow_control.h
+++ b/modules/visual_script/visual_script_flow_control.h
@@ -33,27 +33,23 @@
class VisualScriptReturn : public VisualScriptNode {
- GDCLASS(VisualScriptReturn,VisualScriptNode)
-
+ GDCLASS(VisualScriptReturn, VisualScriptNode)
Variant::Type type;
bool with_value;
-protected:
+protected:
static void _bind_methods();
-public:
+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;
@@ -67,35 +63,27 @@ public:
void set_enable_return_value(bool p_enable);
bool is_return_value_enabled() const;
-
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptReturn();
};
-
class VisualScriptCondition : public VisualScriptNode {
- GDCLASS(VisualScriptCondition,VisualScriptNode)
-
-
+ GDCLASS(VisualScriptCondition, VisualScriptNode)
protected:
-
static void _bind_methods();
-public:
+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;
@@ -103,35 +91,27 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
-
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptCondition();
};
-
class VisualScriptWhile : public VisualScriptNode {
- GDCLASS(VisualScriptWhile,VisualScriptNode)
-
-
+ GDCLASS(VisualScriptWhile, VisualScriptNode)
protected:
-
static void _bind_methods();
-public:
+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;
@@ -139,36 +119,27 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
-
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptWhile();
};
-
-
class VisualScriptIterator : public VisualScriptNode {
- GDCLASS(VisualScriptIterator,VisualScriptNode)
-
-
+ GDCLASS(VisualScriptIterator, VisualScriptNode)
protected:
-
static void _bind_methods();
-public:
+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;
@@ -176,37 +147,29 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
-
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptIterator();
};
-
-
class VisualScriptSequence : public VisualScriptNode {
- GDCLASS(VisualScriptSequence,VisualScriptNode)
-
+ GDCLASS(VisualScriptSequence, VisualScriptNode)
int steps;
protected:
-
static void _bind_methods();
-public:
+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;
@@ -217,47 +180,41 @@ public:
void set_steps(int p_steps);
int get_steps() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptSequence();
};
-
-
-
class VisualScriptSwitch : public VisualScriptNode {
- GDCLASS(VisualScriptSwitch,VisualScriptNode)
+ GDCLASS(VisualScriptSwitch, VisualScriptNode)
struct Case {
Variant::Type type;
- Case() { type=Variant::NIL; }
+ Case() { type = Variant::NIL; }
};
Vector<Case> case_values;
-friend class VisualScriptNodeInstanceSwitch;
-protected:
+ friend class VisualScriptNodeInstanceSwitch;
- 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;
+protected:
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
-public:
+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 bool has_mixed_input_and_sequence_ports() const { return true; }
-
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;
@@ -265,40 +222,31 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptSwitch();
};
-
-
-
class VisualScriptInputFilter : public VisualScriptNode {
- GDCLASS(VisualScriptInputFilter,VisualScriptNode)
+ GDCLASS(VisualScriptInputFilter, VisualScriptNode)
Vector<InputEvent> filters;
-
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;
+ 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:
-
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;
@@ -306,40 +254,30 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptInputFilter();
};
-
-
-
-
class VisualScriptTypeCast : public VisualScriptNode {
- GDCLASS(VisualScriptTypeCast,VisualScriptNode)
-
+ GDCLASS(VisualScriptTypeCast, VisualScriptNode)
StringName base_type;
String script;
protected:
-
static void _bind_methods();
-public:
+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;
@@ -347,23 +285,17 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
- void set_base_type(const StringName& p_type);
+ void set_base_type(const StringName &p_type);
StringName get_base_type() const;
- void set_base_script(const String& p_path);
+ void set_base_script(const String &p_path);
String get_base_script() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptTypeCast();
};
-
-
-
void register_visual_script_flow_control_nodes();
-
-
#endif // VISUAL_SCRIPT_FLOW_CONTROL_H
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index c9ed49ee5c..3cd20050ce 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -28,12 +28,12 @@
/*************************************************************************/
#include "visual_script_func_nodes.h"
-#include "scene/main/scene_main_loop.h"
+#include "global_config.h"
+#include "io/resource_loader.h"
#include "os/os.h"
#include "scene/main/node.h"
+#include "scene/main/scene_main_loop.h"
#include "visual_script_nodes.h"
-#include "io/resource_loader.h"
-#include "global_config.h"
//////////////////////////////////////////
////////////////CALL//////////////////////
@@ -41,33 +41,33 @@
int VisualScriptFunctionCall::get_output_sequence_port_count() const {
- if (method_cache.flags&METHOD_FLAG_CONST || call_mode==CALL_MODE_BASIC_TYPE)
+ if (method_cache.flags & METHOD_FLAG_CONST || call_mode == CALL_MODE_BASIC_TYPE)
return 0;
else
return 1;
}
-bool VisualScriptFunctionCall::has_input_sequence_port() const{
+bool VisualScriptFunctionCall::has_input_sequence_port() const {
- if (method_cache.flags&METHOD_FLAG_CONST || call_mode==CALL_MODE_BASIC_TYPE)
+ if (method_cache.flags & METHOD_FLAG_CONST || call_mode == CALL_MODE_BASIC_TYPE)
return false;
else
return true;
}
#ifdef TOOLS_ENABLED
-static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) {
+static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
return NULL;
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr==script)
+ if (scr.is_valid() && scr == script)
return p_current_node;
- for(int i=0;i<p_current_node->get_child_count();i++) {
- Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script);
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
if (n)
return n;
}
@@ -83,7 +83,7 @@ Node *VisualScriptFunctionCall::_get_base_node() const {
if (!script.is_valid())
return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return NULL;
@@ -97,7 +97,7 @@ Node *VisualScriptFunctionCall::_get_base_node() const {
if (!edited_scene)
return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return NULL;
@@ -116,55 +116,51 @@ Node *VisualScriptFunctionCall::_get_base_node() const {
StringName VisualScriptFunctionCall::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
if (path)
return path->get_class();
-
}
return base_type;
}
+int VisualScriptFunctionCall::get_input_value_port_count() const {
-int VisualScriptFunctionCall::get_input_value_port_count() const{
-
- if (call_mode==CALL_MODE_BASIC_TYPE) {
-
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- Vector<StringName> names = Variant::get_method_argument_names(basic_type,function);
- return names.size() + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) + 1;
+ Vector<StringName> names = Variant::get_method_argument_names(basic_type, function);
+ return names.size() + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) + 1;
} else {
- MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
+ MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
if (mb) {
- return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) - use_default_args;
+ return mb->get_argument_count() + (call_mode == CALL_MODE_INSTANCE ? 1 : 0) + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) - use_default_args;
}
- return method_cache.arguments.size() + (call_mode==CALL_MODE_INSTANCE?1:0) + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) - use_default_args;
+ return method_cache.arguments.size() + (call_mode == CALL_MODE_INSTANCE ? 1 : 0) + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) - use_default_args;
}
-
}
-int VisualScriptFunctionCall::get_output_value_port_count() const{
+int VisualScriptFunctionCall::get_output_value_port_count() const {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- bool returns=false;
- Variant::get_method_return_type(basic_type,function,&returns);
- return returns?1:0;
+ bool returns = false;
+ Variant::get_method_return_type(basic_type, function, &returns);
+ return returns ? 1 : 0;
} else {
int ret;
- MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
+ MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
if (mb) {
ret = mb->has_return() ? 1 : 0;
} else
ret = 1; //it is assumed that script always returns something
- if (call_mode==CALL_MODE_INSTANCE) {
+ if (call_mode == CALL_MODE_INSTANCE) {
ret++;
}
@@ -177,46 +173,44 @@ String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const {
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
+ if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
+ if (p_idx == 0) {
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());
+ 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());
return pi;
} else {
p_idx--;
}
}
- if (rpc_call_mode>=RPC_RELIABLE_TO_ID) {
+ if (rpc_call_mode >= RPC_RELIABLE_TO_ID) {
- if (p_idx==0) {
- return PropertyInfo(Variant::INT,"peer_id");
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::INT, "peer_id");
} else {
p_idx--;
}
-
}
#ifdef DEBUG_METHODS_ENABLED
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
-
- Vector<StringName> names = Variant::get_method_argument_names(basic_type,function);
- Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type,function);
- return PropertyInfo(types[p_idx],names[p_idx]);
+ Vector<StringName> names = Variant::get_method_argument_names(basic_type, function);
+ Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function);
+ return PropertyInfo(types[p_idx], names[p_idx]);
} else {
- MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
+ MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
if (mb) {
return mb->get_argument_info(p_idx);
}
- if (p_idx>=0 && p_idx < method_cache.arguments.size()) {
+ if (p_idx >= 0 && p_idx < method_cache.arguments.size()) {
return method_cache.arguments[p_idx];
}
@@ -225,23 +219,20 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons
#else
return PropertyInfo();
#endif
-
}
-PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const{
-
+PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const {
#ifdef DEBUG_METHODS_ENABLED
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
-
- return PropertyInfo(Variant::get_method_return_type(basic_type,function),"");
+ return PropertyInfo(Variant::get_method_return_type(basic_type, function), "");
} else {
- if (call_mode==CALL_MODE_INSTANCE) {
- if (p_idx==0) {
- return PropertyInfo(Variant::OBJECT,"pass");
+ if (call_mode == CALL_MODE_INSTANCE) {
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::OBJECT, "pass");
} else {
p_idx--;
}
@@ -259,24 +250,21 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con
//}
- if (call_mode==CALL_MODE_INSTANCE) {
- ret.name="return";
+ if (call_mode == CALL_MODE_INSTANCE) {
+ ret.name = "return";
} else {
- ret.name="";
+ ret.name = "";
}
return ret;
-
-
}
#else
return PropertyInfo();
#endif
}
-
String VisualScriptFunctionCall::get_caption() const {
- static const char*cname[5]= {
+ static const char *cname[5] = {
"CallSelf",
"CallNode",
"CallInstance",
@@ -287,7 +275,7 @@ String VisualScriptFunctionCall::get_caption() const {
String caption = cname[call_mode];
if (rpc_call_mode) {
- caption+=" (RPC)";
+ caption += " (RPC)";
}
return caption;
@@ -295,57 +283,54 @@ String VisualScriptFunctionCall::get_caption() const {
String VisualScriptFunctionCall::get_text() const {
- if (call_mode==CALL_MODE_SELF)
- return " "+String(function)+"()";
- if (call_mode==CALL_MODE_SINGLETON)
- return String(singleton)+":"+String(function)+"()";
- else if (call_mode==CALL_MODE_BASIC_TYPE)
- return Variant::get_type_name(basic_type)+"."+String(function)+"()";
- else if (call_mode==CALL_MODE_NODE_PATH)
- return " ["+String(base_path.simplified())+"]."+String(function)+"()";
+ if (call_mode == CALL_MODE_SELF)
+ return " " + String(function) + "()";
+ if (call_mode == CALL_MODE_SINGLETON)
+ return String(singleton) + ":" + String(function) + "()";
+ else if (call_mode == CALL_MODE_BASIC_TYPE)
+ return Variant::get_type_name(basic_type) + "." + String(function) + "()";
+ else if (call_mode == CALL_MODE_NODE_PATH)
+ return " [" + String(base_path.simplified()) + "]." + String(function) + "()";
else
- return " "+base_type+"."+String(function)+"()";
-
+ return " " + base_type + "." + String(function) + "()";
}
-
void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
- if (basic_type==p_type)
+ if (basic_type == p_type)
return;
- basic_type=p_type;
-
+ basic_type = p_type;
_change_notify();
ports_changed_notify();
}
-Variant::Type VisualScriptFunctionCall::get_basic_type() const{
+Variant::Type VisualScriptFunctionCall::get_basic_type() const {
return basic_type;
}
-void VisualScriptFunctionCall::set_base_type(const StringName& p_type) {
+void VisualScriptFunctionCall::set_base_type(const StringName &p_type) {
- if (base_type==p_type)
+ if (base_type == p_type)
return;
- base_type=p_type;
+ base_type = p_type;
_change_notify();
ports_changed_notify();
}
-StringName VisualScriptFunctionCall::get_base_type() const{
+StringName VisualScriptFunctionCall::get_base_type() const {
return base_type;
}
-void VisualScriptFunctionCall::set_base_script(const String& p_path) {
+void VisualScriptFunctionCall::set_base_script(const String &p_path) {
- if (base_script==p_path)
+ if (base_script == p_path)
return;
- base_script=p_path;
+ base_script = p_path;
_change_notify();
ports_changed_notify();
}
@@ -355,15 +340,15 @@ String VisualScriptFunctionCall::get_base_script() const {
return base_script;
}
-void VisualScriptFunctionCall::set_singleton(const StringName& p_path) {
+void VisualScriptFunctionCall::set_singleton(const StringName &p_path) {
- if (singleton==p_path)
+ if (singleton == p_path)
return;
- singleton=p_path;
+ singleton = p_path;
Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton);
if (obj) {
- base_type=obj->get_class();
+ base_type = obj->get_class();
}
_change_notify();
@@ -375,40 +360,38 @@ StringName VisualScriptFunctionCall::get_singleton() const {
return singleton;
}
-
-
void VisualScriptFunctionCall::_update_method_cache() {
StringName type;
Ref<Script> script;
- if (call_mode==CALL_MODE_NODE_PATH) {
+ if (call_mode == CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
+ Node *node = _get_base_node();
if (node) {
- type=node->get_class();
- base_type=type; //cache, too
+ type = node->get_class();
+ base_type = type; //cache, too
script = node->get_script();
}
- } else if (call_mode==CALL_MODE_SELF) {
+ } else if (call_mode == CALL_MODE_SELF) {
if (get_visual_script().is_valid()) {
- type=get_visual_script()->get_instance_base_type();
- base_type=type; //cache, too
- script=get_visual_script();
+ type = get_visual_script()->get_instance_base_type();
+ base_type = type; //cache, too
+ script = get_visual_script();
}
- } else if (call_mode==CALL_MODE_SINGLETON) {
+ } else if (call_mode == CALL_MODE_SINGLETON) {
Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton);
if (obj) {
- type=obj->get_class();
- script=obj->get_script();
+ type = obj->get_class();
+ script = obj->get_script();
}
- } else if (call_mode==CALL_MODE_INSTANCE) {
+ } else if (call_mode == CALL_MODE_INSTANCE) {
- type=base_type;
- if (base_script!=String()) {
+ type = base_type;
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
@@ -417,20 +400,19 @@ void VisualScriptFunctionCall::_update_method_cache() {
if (ResourceCache::has(base_script)) {
- script = Ref<Resource>( ResourceCache::get(base_script) );
+ script = Ref<Resource>(ResourceCache::get(base_script));
} else {
return;
}
}
}
-
//print_line("BASE: "+String(type)+" FUNC: "+String(function));
- MethodBind *mb = ClassDB::get_method(type,function);
+ MethodBind *mb = ClassDB::get_method(type, function);
if (mb) {
- use_default_args=mb->get_default_argument_count();
+ use_default_args = mb->get_default_argument_count();
method_cache = MethodInfo();
- for(int i=0;i<mb->get_argument_count();i++) {
+ for (int i = 0; i < mb->get_argument_count(); i++) {
#ifdef DEBUG_METHODS_ENABLED
method_cache.arguments.push_back(mb->get_argument_info(i));
#else
@@ -439,7 +421,7 @@ void VisualScriptFunctionCall::_update_method_cache() {
}
if (mb->is_const()) {
- method_cache.flags|=METHOD_FLAG_CONST;
+ method_cache.flags |= METHOD_FLAG_CONST;
}
#ifdef DEBUG_METHODS_ENABLED
@@ -449,50 +431,47 @@ void VisualScriptFunctionCall::_update_method_cache() {
if (mb->is_vararg()) {
//for vararg just give it 10 arguments (should be enough for most use cases)
- for(int i=0;i<10;i++) {
- method_cache.arguments.push_back(PropertyInfo(Variant::NIL,"arg"+itos(i)));
+ for (int i = 0; i < 10; i++) {
+ method_cache.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i)));
use_default_args++;
}
}
} else if (script.is_valid() && script->has_method(function)) {
method_cache = script->get_method_info(function);
- use_default_args=method_cache.default_arguments.size();
+ use_default_args = method_cache.default_arguments.size();
}
}
-void VisualScriptFunctionCall::set_function(const StringName& p_type){
+void VisualScriptFunctionCall::set_function(const StringName &p_type) {
- if (function==p_type)
+ if (function == p_type)
return;
- function=p_type;
+ function = p_type;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- use_default_args = Variant::get_method_default_arguments(basic_type,function).size();
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
+ use_default_args = Variant::get_method_default_arguments(basic_type, function).size();
} else {
//update all caches
_update_method_cache();
-
}
-
_change_notify();
ports_changed_notify();
}
StringName VisualScriptFunctionCall::get_function() const {
-
return function;
}
-void VisualScriptFunctionCall::set_base_path(const NodePath& p_type) {
+void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) {
- if (base_path==p_type)
+ if (base_path == p_type)
return;
- base_path=p_type;
+ base_path = p_type;
_change_notify();
ports_changed_notify();
}
@@ -502,16 +481,14 @@ NodePath VisualScriptFunctionCall::get_base_path() const {
return base_path;
}
-
void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
+ if (call_mode == p_mode)
return;
- call_mode=p_mode;
+ call_mode = p_mode;
_change_notify();
ports_changed_notify();
-
}
VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const {
@@ -520,39 +497,35 @@ VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() con
void VisualScriptFunctionCall::set_use_default_args(int p_amount) {
- if (use_default_args==p_amount)
+ if (use_default_args == p_amount)
return;
- use_default_args=p_amount;
+ use_default_args = p_amount;
ports_changed_notify();
-
-
}
void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) {
- if (rpc_call_mode==p_mode)
+ if (rpc_call_mode == p_mode)
return;
- rpc_call_mode=p_mode;
+ rpc_call_mode = p_mode;
ports_changed_notify();
_change_notify();
}
-VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const{
+VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const {
return rpc_call_mode;
}
-
-int VisualScriptFunctionCall::get_use_default_args() const{
+int VisualScriptFunctionCall::get_use_default_args() const {
return use_default_args;
}
-
void VisualScriptFunctionCall::set_validate(bool p_amount) {
- validate=p_amount;
+ validate = p_amount;
}
bool VisualScriptFunctionCall::get_validate() const {
@@ -560,11 +533,9 @@ bool VisualScriptFunctionCall::get_validate() const {
return validate;
}
-
-void VisualScriptFunctionCall::_set_argument_cache(const Dictionary& p_cache) {
+void VisualScriptFunctionCall::_set_argument_cache(const Dictionary &p_cache) {
//so everything works in case all else fails
- method_cache=MethodInfo::from_dict(p_cache);
-
+ method_cache = MethodInfo::from_dict(p_cache);
}
Dictionary VisualScriptFunctionCall::_get_argument_cache() const {
@@ -572,84 +543,82 @@ Dictionary VisualScriptFunctionCall::_get_argument_cache() const {
return method_cache;
}
-void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const {
+void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const {
- if (property.name=="function/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
+ if (property.name == "function/base_type") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
- if (property.name=="function/base_script") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=0;
+ if (property.name == "function/base_script") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = 0;
}
}
- if (property.name=="function/basic_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE) {
- property.usage=0;
+ if (property.name == "function/basic_type") {
+ if (call_mode != CALL_MODE_BASIC_TYPE) {
+ property.usage = 0;
}
}
- if (property.name=="function/singleton") {
- if (call_mode!=CALL_MODE_SINGLETON) {
- property.usage=0;
+ if (property.name == "function/singleton") {
+ if (call_mode != CALL_MODE_SINGLETON) {
+ property.usage = 0;
} else {
List<GlobalConfig::Singleton> names;
GlobalConfig::get_singleton()->get_singletons(&names);
- property.hint=PROPERTY_HINT_ENUM;
+ property.hint = PROPERTY_HINT_ENUM;
String sl;
- for (List<GlobalConfig::Singleton>::Element *E=names.front();E;E=E->next()) {
- if (sl!=String())
- sl+=",";
- sl+=E->get().name;
+ for (List<GlobalConfig::Singleton>::Element *E = names.front(); E; E = E->next()) {
+ if (sl != String())
+ sl += ",";
+ sl += E->get().name;
}
- property.hint_string=sl;
-
+ property.hint_string = sl;
}
}
- if (property.name=="function/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
+ if (property.name == "function/node_path") {
+ if (call_mode != CALL_MODE_NODE_PATH) {
+ property.usage = 0;
} else {
Node *bnode = _get_base_node();
if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
+ property.hint_string = bnode->get_path(); //convert to loong string
} else {
-
}
}
}
- if (property.name=="function/function") {
+ if (property.name == "function/function") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_METHOD_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
+ property.hint = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE;
+ property.hint_string = Variant::get_type_name(basic_type);
- } 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());
- } else if (call_mode==CALL_MODE_SINGLETON) {
+ } 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());
+ } else if (call_mode == CALL_MODE_SINGLETON) {
Object *obj = GlobalConfig::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 = PROPERTY_HINT_METHOD_OF_INSTANCE;
+ property.hint_string = itos(obj->get_instance_ID());
} else {
- property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
- property.hint_string=base_type;//should be cached
+ property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
+ property.hint_string = base_type; //should be cached
}
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
- property.hint_string=base_type;
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
+ property.hint_string = base_type;
- if (base_script!=String()) {
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
@@ -657,143 +626,134 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const
if (ResourceCache::has(base_script)) {
- Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
if (script.is_valid()) {
- property.hint=PROPERTY_HINT_METHOD_OF_SCRIPT;
- property.hint_string=itos(script->get_instance_ID());
+ property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT;
+ property.hint_string = itos(script->get_instance_ID());
}
}
}
- } else if (call_mode==CALL_MODE_NODE_PATH) {
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
Node *node = _get_base_node();
if (node) {
- property.hint=PROPERTY_HINT_METHOD_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
+ property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE;
+ property.hint_string = itos(node->get_instance_ID());
} else {
- property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
- property.hint_string=get_base_type();
+ property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
+ property.hint_string = get_base_type();
}
-
}
-
}
- if (property.name=="function/use_default_args") {
+ if (property.name == "function/use_default_args") {
- property.hint=PROPERTY_HINT_RANGE;
+ property.hint = PROPERTY_HINT_RANGE;
- int mc=0;
+ int mc = 0;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- mc = Variant::get_method_default_arguments(basic_type,function).size();
+ mc = Variant::get_method_default_arguments(basic_type, function).size();
} else {
- MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
+ MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
if (mb) {
- mc=mb->get_default_argument_count();
+ mc = mb->get_default_argument_count();
}
}
- if (mc==0) {
- property.usage=0; //do not show
+ if (mc == 0) {
+ property.usage = 0; //do not show
} else {
- property.hint_string="0,"+itos(mc)+",1";
+ property.hint_string = "0," + itos(mc) + ",1";
}
}
- if (property.name=="rpc/call_mode") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- property.usage=0;
+ if (property.name == "rpc/call_mode") {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
+ property.usage = 0;
}
}
-
}
-
void VisualScriptFunctionCall::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptFunctionCall::get_base_type);
+ ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptFunctionCall::set_base_type);
+ ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptFunctionCall::get_base_type);
- ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptFunctionCall::set_base_script);
- ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptFunctionCall::get_base_script);
+ ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptFunctionCall::set_base_script);
+ ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptFunctionCall::get_base_script);
- ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type);
- ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type);
+ ClassDB::bind_method(D_METHOD("set_basic_type", "basic_type"), &VisualScriptFunctionCall::set_basic_type);
+ ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptFunctionCall::get_basic_type);
- ClassDB::bind_method(D_METHOD("set_singleton","singleton"),&VisualScriptFunctionCall::set_singleton);
- ClassDB::bind_method(D_METHOD("get_singleton"),&VisualScriptFunctionCall::get_singleton);
+ ClassDB::bind_method(D_METHOD("set_singleton", "singleton"), &VisualScriptFunctionCall::set_singleton);
+ ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptFunctionCall::get_singleton);
- ClassDB::bind_method(D_METHOD("set_function","function"),&VisualScriptFunctionCall::set_function);
- ClassDB::bind_method(D_METHOD("get_function"),&VisualScriptFunctionCall::get_function);
+ ClassDB::bind_method(D_METHOD("set_function", "function"), &VisualScriptFunctionCall::set_function);
+ ClassDB::bind_method(D_METHOD("get_function"), &VisualScriptFunctionCall::get_function);
- ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptFunctionCall::set_call_mode);
- ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptFunctionCall::get_call_mode);
+ ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptFunctionCall::set_call_mode);
+ ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptFunctionCall::get_call_mode);
- ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptFunctionCall::set_base_path);
- ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptFunctionCall::get_base_path);
+ ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptFunctionCall::set_base_path);
+ ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptFunctionCall::get_base_path);
- ClassDB::bind_method(D_METHOD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args);
- ClassDB::bind_method(D_METHOD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args);
+ ClassDB::bind_method(D_METHOD("set_use_default_args", "amount"), &VisualScriptFunctionCall::set_use_default_args);
+ ClassDB::bind_method(D_METHOD("get_use_default_args"), &VisualScriptFunctionCall::get_use_default_args);
- ClassDB::bind_method(D_METHOD("_set_argument_cache","argument_cache"),&VisualScriptFunctionCall::_set_argument_cache);
- ClassDB::bind_method(D_METHOD("_get_argument_cache"),&VisualScriptFunctionCall::_get_argument_cache);
+ ClassDB::bind_method(D_METHOD("_set_argument_cache", "argument_cache"), &VisualScriptFunctionCall::_set_argument_cache);
+ ClassDB::bind_method(D_METHOD("_get_argument_cache"), &VisualScriptFunctionCall::_get_argument_cache);
- ClassDB::bind_method(D_METHOD("set_rpc_call_mode","mode"),&VisualScriptFunctionCall::set_rpc_call_mode);
- ClassDB::bind_method(D_METHOD("get_rpc_call_mode"),&VisualScriptFunctionCall::get_rpc_call_mode);
+ ClassDB::bind_method(D_METHOD("set_rpc_call_mode", "mode"), &VisualScriptFunctionCall::set_rpc_call_mode);
+ ClassDB::bind_method(D_METHOD("get_rpc_call_mode"), &VisualScriptFunctionCall::get_rpc_call_mode);
- ClassDB::bind_method(D_METHOD("set_validate","enable"),&VisualScriptFunctionCall::set_validate);
- ClassDB::bind_method(D_METHOD("get_validate"),&VisualScriptFunctionCall::get_validate);
+ ClassDB::bind_method(D_METHOD("set_validate", "enable"), &VisualScriptFunctionCall::set_validate);
+ ClassDB::bind_method(D_METHOD("get_validate"), &VisualScriptFunctionCall::get_validate);
String bt;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (i>0)
- bt+=",";
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (i > 0)
+ bt += ",";
- bt+=Variant::get_type_name(Variant::Type(i));
+ bt += Variant::get_type_name(Variant::Type(i));
}
-
List<String> script_extensions;
- for(int i=0;i<ScriptServer::get_language_count();i++) {
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
}
String script_ext_hint;
- for (List<String>::Element *E=script_extensions.front();E;E=E->next()) {
- if (script_ext_hint!=String())
- script_ext_hint+=",";
- 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.
-
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
- BIND_CONSTANT( CALL_MODE_BASIC_TYPE );
+ for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
+ if (script_ext_hint != String())
+ script_ext_hint += ",";
+ 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.
+
+ BIND_CONSTANT(CALL_MODE_SELF);
+ BIND_CONSTANT(CALL_MODE_NODE_PATH);
+ BIND_CONSTANT(CALL_MODE_INSTANCE);
+ BIND_CONSTANT(CALL_MODE_BASIC_TYPE);
}
class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
public:
-
-
VisualScriptFunctionCall::CallMode call_mode;
NodePath node_path;
int input_args;
@@ -806,80 +766,76 @@ public:
VisualScriptFunctionCall *node;
VisualScriptInstance *instance;
-
-
//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_ bool call_rpc(Object* p_base,const Variant** p_args,int p_argcount) {
+ _FORCE_INLINE_ bool call_rpc(Object *p_base, const Variant **p_args, int p_argcount) {
if (!p_base)
return false;
- Node * node = p_base->cast_to<Node>();
+ Node *node = p_base->cast_to<Node>();
if (!node)
return false;
- int to_id=0;
- bool reliable=true;
+ int to_id = 0;
+ bool reliable = true;
- if (rpc_mode>=VisualScriptFunctionCall::RPC_RELIABLE_TO_ID) {
+ if (rpc_mode >= VisualScriptFunctionCall::RPC_RELIABLE_TO_ID) {
to_id = *p_args[0];
- p_args+=1;
- p_argcount-=1;
- if (rpc_mode==VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
- reliable=false;
+ p_args += 1;
+ p_argcount -= 1;
+ if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
+ reliable = false;
}
- } else if (rpc_mode==VisualScriptFunctionCall::RPC_UNRELIABLE) {
- reliable=false;
+ } else if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE) {
+ reliable = false;
}
- node->rpcp(to_id,!reliable,function,p_args,p_argcount);
+ node->rpcp(to_id, !reliable, function, p_args, p_argcount);
return true;
}
- 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) {
+ 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) {
+ switch (call_mode) {
case VisualScriptFunctionCall::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
+ Object *object = instance->get_owner_ptr();
if (rpc_mode) {
- call_rpc(object,p_inputs,input_args);
+ call_rpc(object, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = object->call(function,p_inputs,input_args,r_error);
+ *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
} else {
- object->call(function,p_inputs,input_args,r_error);
+ object->call(function, p_inputs, input_args, r_error);
}
} break;
case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Base object is not a Node!";
return 0;
}
- Node* another = node->get_node(node_path);
+ Node *another = node->get_node(node_path);
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Path does not lead Node!";
return 0;
}
if (rpc_mode) {
- call_rpc(node,p_inputs,input_args);
+ call_rpc(node, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = another->call(function,p_inputs,input_args,r_error);
+ *p_outputs[0] = another->call(function, p_inputs, input_args, r_error);
} else {
- another->call(function,p_inputs,input_args,r_error);
+ another->call(function, p_inputs, input_args, r_error);
}
} break;
@@ -891,98 +847,90 @@ public:
if (rpc_mode) {
Object *obj = v;
if (obj) {
- call_rpc(obj,p_inputs+1,input_args-1);
+ call_rpc(obj, p_inputs + 1, input_args - 1);
}
} else if (returns) {
- if (call_mode==VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
- *p_outputs[1] = v.call(function,p_inputs+1,input_args,r_error);
+ if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
+ *p_outputs[1] = v.call(function, p_inputs + 1, input_args, r_error);
} else {
- *p_outputs[0] = v.call(function,p_inputs+1,input_args,r_error);
+ *p_outputs[0] = v.call(function, p_inputs + 1, input_args, r_error);
}
} else {
- v.call(function,p_inputs+1,input_args,r_error);
+ v.call(function, p_inputs + 1, input_args, r_error);
}
- if (call_mode==VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
- *p_outputs[0]=*p_inputs[0];
+ if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
+ *p_outputs[0] = *p_inputs[0];
}
} break;
case VisualScriptFunctionCall::CALL_MODE_SINGLETON: {
- Object *object=GlobalConfig::get_singleton()->get_singleton_object(singleton);
+ Object *object = GlobalConfig::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)+"'";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid singleton name: '" + String(singleton) + "'";
return 0;
}
if (rpc_mode) {
- call_rpc(object,p_inputs,input_args);
+ call_rpc(object, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = object->call(function,p_inputs,input_args,r_error);
+ *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
} else {
- object->call(function,p_inputs,input_args,r_error);
+ object->call(function, p_inputs, input_args, r_error);
}
} break;
-
}
if (!validate) {
//ignore call errors if validation is disabled
- r_error.error=Variant::CallError::CALL_OK;
- r_error_str=String();
+ r_error.error = Variant::CallError::CALL_OK;
+ r_error_str = String();
}
return 0;
-
}
-
-
};
-VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VisualScriptInstance* p_instance) {
-
- VisualScriptNodeInstanceFunctionCall * instance = memnew(VisualScriptNodeInstanceFunctionCall );
- instance->node=this;
- instance->instance=p_instance;
- instance->singleton=singleton;
- instance->function=function;
- instance->call_mode=call_mode;
- instance->returns=get_output_value_port_count();
- instance->node_path=base_path;
- instance->input_args = get_input_value_port_count() - ( (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE) ? 1: 0 );
- instance->rpc_mode=rpc_call_mode;
- instance->validate=validate;
+VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) {
+
+ VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->singleton = singleton;
+ instance->function = function;
+ instance->call_mode = call_mode;
+ instance->returns = get_output_value_port_count();
+ instance->node_path = base_path;
+ instance->input_args = get_input_value_port_count() - ((call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0);
+ instance->rpc_mode = rpc_call_mode;
+ instance->validate = validate;
return instance;
}
+VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess *p_inputs, int p_output) const {
-VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess* p_inputs, int p_output) const {
-
- if (p_output==0 && call_mode==CALL_MODE_INSTANCE) {
+ if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) {
return p_inputs[0];
}
- return VisualScriptNode::guess_output_type(p_inputs,p_output);
-
+ return VisualScriptNode::guess_output_type(p_inputs, p_output);
}
VisualScriptFunctionCall::VisualScriptFunctionCall() {
- validate=true;
- call_mode=CALL_MODE_SELF;
- basic_type=Variant::NIL;
- use_default_args=0;
- base_type="Object";
- rpc_call_mode=RPC_DISABLED;
-
-
+ validate = true;
+ call_mode = CALL_MODE_SELF;
+ basic_type = Variant::NIL;
+ use_default_args = 0;
+ base_type = "Object";
+ rpc_call_mode = RPC_DISABLED;
}
-template<VisualScriptFunctionCall::CallMode cmode>
-static Ref<VisualScriptNode> create_function_call_node(const String& p_name) {
+template <VisualScriptFunctionCall::CallMode cmode>
+static Ref<VisualScriptNode> create_function_call_node(const String &p_name) {
Ref<VisualScriptFunctionCall> node;
node.instance();
@@ -990,12 +938,11 @@ static Ref<VisualScriptNode> create_function_call_node(const String& p_name) {
return node;
}
-
//////////////////////////////////////////
////////////////SET//////////////////////
//////////////////////////////////////////
-static const char* event_type_names[InputEvent::TYPE_MAX]={
+static const char *event_type_names[InputEvent::TYPE_MAX] = {
"None",
"Key",
"MouseMotion",
@@ -1007,15 +954,14 @@ static const char* event_type_names[InputEvent::TYPE_MAX]={
"Action"
};
-
int VisualScriptPropertySet::get_output_sequence_port_count() const {
- return call_mode!=CALL_MODE_BASIC_TYPE ? 1 : 0;
+ return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0;
}
-bool VisualScriptPropertySet::has_input_sequence_port() const{
+bool VisualScriptPropertySet::has_input_sequence_port() const {
- return call_mode!=CALL_MODE_BASIC_TYPE ? true : false;
+ return call_mode != CALL_MODE_BASIC_TYPE ? true : false;
}
Node *VisualScriptPropertySet::_get_base_node() const {
@@ -1025,7 +971,7 @@ Node *VisualScriptPropertySet::_get_base_node() const {
if (!script.is_valid())
return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return NULL;
@@ -1039,7 +985,7 @@ Node *VisualScriptPropertySet::_get_base_node() const {
if (!edited_scene)
return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return NULL;
@@ -1058,27 +1004,26 @@ Node *VisualScriptPropertySet::_get_base_node() const {
StringName VisualScriptPropertySet::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
if (path)
return path->get_class();
-
}
return base_type;
}
-int VisualScriptPropertySet::get_input_value_port_count() const{
+int VisualScriptPropertySet::get_input_value_port_count() const {
- int pc = (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?2:1;
+ int pc = (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 2 : 1;
return pc;
}
-int VisualScriptPropertySet::get_output_value_port_count() const{
+int VisualScriptPropertySet::get_output_value_port_count() const {
- return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE) ? 1 : 0;
+ return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0;
}
String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const {
@@ -1086,39 +1031,37 @@ String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const {
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
+ if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
+ if (p_idx == 0) {
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());
+ 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());
return pi;
} else {
p_idx--;
}
}
- PropertyInfo pinfo=type_cache;
- pinfo.name="value";
+ PropertyInfo pinfo = type_cache;
+ pinfo.name = "value";
return pinfo;
}
-PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const{
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- return PropertyInfo(basic_type,"out");
- } else if (call_mode==CALL_MODE_INSTANCE) {
- return PropertyInfo(Variant::OBJECT,"pass");
+PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
+ return PropertyInfo(basic_type, "out");
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ return PropertyInfo(Variant::OBJECT, "pass");
} else {
return PropertyInfo();
}
-
}
-
String VisualScriptPropertySet::get_caption() const {
- static const char*cname[4]= {
+ static const char *cname[4] = {
"SelfSet",
"NodeSet",
"InstanceSet",
@@ -1132,58 +1075,55 @@ String VisualScriptPropertySet::get_text() const {
String prop;
- if (call_mode==CALL_MODE_BASIC_TYPE)
- prop=Variant::get_type_name(basic_type)+"."+property;
- else if (call_mode==CALL_MODE_NODE_PATH)
- prop=String(base_path)+":"+property;
- else if (call_mode==CALL_MODE_SELF)
- prop=property;
- else if (call_mode==CALL_MODE_INSTANCE)
- prop=String(base_type)+":"+property;
+ if (call_mode == CALL_MODE_BASIC_TYPE)
+ prop = Variant::get_type_name(basic_type) + "." + property;
+ else if (call_mode == CALL_MODE_NODE_PATH)
+ prop = String(base_path) + ":" + property;
+ else if (call_mode == CALL_MODE_SELF)
+ prop = property;
+ else if (call_mode == CALL_MODE_INSTANCE)
+ prop = String(base_type) + ":" + property;
return prop;
-
}
void VisualScriptPropertySet::_update_base_type() {
//cache it because this information may not be available on load
- if (call_mode==CALL_MODE_NODE_PATH) {
+ if (call_mode == CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
+ Node *node = _get_base_node();
if (node) {
- base_type=node->get_class();
+ base_type = node->get_class();
}
- } else if (call_mode==CALL_MODE_SELF) {
+ } else if (call_mode == CALL_MODE_SELF) {
if (get_visual_script().is_valid()) {
- base_type=get_visual_script()->get_instance_base_type();
+ base_type = get_visual_script()->get_instance_base_type();
}
}
-
}
void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) {
- if (basic_type==p_type)
+ if (basic_type == p_type)
return;
- basic_type=p_type;
-
+ basic_type = p_type;
_change_notify();
_update_base_type();
ports_changed_notify();
}
-Variant::Type VisualScriptPropertySet::get_basic_type() const{
+Variant::Type VisualScriptPropertySet::get_basic_type() const {
return basic_type;
}
void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) {
- if (event_type==p_type)
+ if (event_type == p_type)
return;
- event_type=p_type;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ event_type = p_type;
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
_update_cache();
}
_change_notify();
@@ -1191,34 +1131,32 @@ void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) {
ports_changed_notify();
}
-InputEvent::Type VisualScriptPropertySet::get_event_type() const{
+InputEvent::Type VisualScriptPropertySet::get_event_type() const {
return event_type;
}
+void VisualScriptPropertySet::set_base_type(const StringName &p_type) {
-void VisualScriptPropertySet::set_base_type(const StringName& p_type) {
-
- if (base_type==p_type)
+ if (base_type == p_type)
return;
- base_type=p_type;
- _change_notify();
+ base_type = p_type;
+ _change_notify();
ports_changed_notify();
}
-StringName VisualScriptPropertySet::get_base_type() const{
+StringName VisualScriptPropertySet::get_base_type() const {
return base_type;
}
+void VisualScriptPropertySet::set_base_script(const String &p_path) {
-void VisualScriptPropertySet::set_base_script(const String& p_path) {
-
- if (base_script==p_path)
+ if (base_script == p_path)
return;
- base_script=p_path;
+ base_script = p_path;
_change_notify();
ports_changed_notify();
}
@@ -1228,10 +1166,8 @@ String VisualScriptPropertySet::get_base_script() const {
return base_script;
}
-
void VisualScriptPropertySet::_update_cache() {
-
if (!OS::get_singleton()->get_main_loop())
return;
if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>())
@@ -1240,57 +1176,56 @@ void VisualScriptPropertySet::_update_cache() {
if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise
return;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
//not super efficient..
Variant v;
- if (basic_type==Variant::INPUT_EVENT) {
+ if (basic_type == Variant::INPUT_EVENT) {
InputEvent ev;
- ev.type=event_type;
- v=ev;
+ ev.type = event_type;
+ v = ev;
} else {
Variant::CallError ce;
- v = Variant::construct(basic_type,NULL,0,ce);
+ v = Variant::construct(basic_type, NULL, 0, ce);
}
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name==property) {
+ if (E->get().name == property) {
- type_cache=E->get();
+ type_cache = E->get();
}
}
} else {
-
StringName type;
Ref<Script> script;
- Node *node=NULL;
+ Node *node = NULL;
- if (call_mode==CALL_MODE_NODE_PATH) {
+ if (call_mode == CALL_MODE_NODE_PATH) {
- node=_get_base_node();
+ node = _get_base_node();
if (node) {
- type=node->get_class();
- base_type=type; //cache, too
+ type = node->get_class();
+ base_type = type; //cache, too
script = node->get_script();
}
- } else if (call_mode==CALL_MODE_SELF) {
+ } else if (call_mode == CALL_MODE_SELF) {
if (get_visual_script().is_valid()) {
- type=get_visual_script()->get_instance_base_type();
- base_type=type; //cache, too
- script=get_visual_script();
+ type = get_visual_script()->get_instance_base_type();
+ base_type = type; //cache, too
+ script = get_visual_script();
}
- } else if (call_mode==CALL_MODE_INSTANCE) {
+ } else if (call_mode == CALL_MODE_INSTANCE) {
- type=base_type;
- if (base_script!=String()) {
+ type = base_type;
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
@@ -1299,7 +1234,7 @@ void VisualScriptPropertySet::_update_cache() {
if (ResourceCache::has(base_script)) {
- script = Ref<Resource>( ResourceCache::get(base_script) );
+ script = Ref<Resource>(ResourceCache::get(base_script));
} else {
return;
}
@@ -1308,12 +1243,11 @@ void VisualScriptPropertySet::_update_cache() {
List<PropertyInfo> pinfo;
-
if (node) {
node->get_property_list(&pinfo);
} else {
- ClassDB::get_property_list(type,&pinfo);
+ ClassDB::get_property_list(type, &pinfo);
}
if (script.is_valid()) {
@@ -1321,39 +1255,37 @@ void VisualScriptPropertySet::_update_cache() {
script->get_script_property_list(&pinfo);
}
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name==property) {
- type_cache=E->get();
+ if (E->get().name == property) {
+ type_cache = E->get();
return;
}
}
-
}
}
-void VisualScriptPropertySet::set_property(const StringName& p_type){
+void VisualScriptPropertySet::set_property(const StringName &p_type) {
- if (property==p_type)
+ if (property == p_type)
return;
- property=p_type;
+ property = p_type;
_update_cache();
- _change_notify();
+ _change_notify();
ports_changed_notify();
}
StringName VisualScriptPropertySet::get_property() const {
-
return property;
}
-void VisualScriptPropertySet::set_base_path(const NodePath& p_type) {
+void VisualScriptPropertySet::set_base_path(const NodePath &p_type) {
- if (base_path==p_type)
+ if (base_path == p_type)
return;
- base_path=p_type;
+ base_path = p_type;
_update_base_type();
_change_notify();
ports_changed_notify();
@@ -1364,28 +1296,23 @@ NodePath VisualScriptPropertySet::get_base_path() const {
return base_path;
}
-
void VisualScriptPropertySet::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
+ if (call_mode == p_mode)
return;
- call_mode=p_mode;
+ call_mode = p_mode;
_update_base_type();
_change_notify();
ports_changed_notify();
-
}
VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const {
return call_mode;
}
-
-
-
void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) {
- type_cache=PropertyInfo::from_dict(p_type);
+ type_cache = PropertyInfo::from_dict(p_type);
}
Dictionary VisualScriptPropertySet::_get_type_cache() const {
@@ -1393,61 +1320,60 @@ Dictionary VisualScriptPropertySet::_get_type_cache() const {
return type_cache;
}
-void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
+void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
- if (property.name=="property/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
+ if (property.name == "property/base_type") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
- if (property.name=="property/base_script") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=0;
+ if (property.name == "property/base_script") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = 0;
}
}
- if (property.name=="property/basic_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE) {
- property.usage=0;
+ if (property.name == "property/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/event_type") {
+ if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) {
+ property.usage = 0;
}
}
- if (property.name=="property/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
+ if (property.name == "property/node_path") {
+ if (call_mode != CALL_MODE_NODE_PATH) {
+ property.usage = 0;
} else {
Node *bnode = _get_base_node();
if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
+ property.hint_string = bnode->get_path(); //convert to loong string
} else {
-
}
}
}
- if (property.name=="property/property") {
+ if (property.name == "property/property") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
+ property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
+ property.hint_string = Variant::get_type_name(basic_type);
- } 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());
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=base_type;
+ } 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());
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
+ property.hint_string = base_type;
- if (base_script!=String()) {
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
@@ -1455,106 +1381,98 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
if (ResourceCache::has(base_script)) {
- Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
if (script.is_valid()) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT;
- property.hint_string=itos(script->get_instance_ID());
+ property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
+ property.hint_string = itos(script->get_instance_ID());
}
}
}
- } else if (call_mode==CALL_MODE_NODE_PATH) {
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
Node *node = _get_base_node();
if (node) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
+ property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE;
+ property.hint_string = itos(node->get_instance_ID());
} else {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=get_base_type();
+ property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
+ property.hint_string = get_base_type();
}
-
}
-
}
-
}
void VisualScriptPropertySet::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptPropertySet::get_base_type);
+ ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertySet::set_base_type);
+ ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertySet::get_base_type);
- ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptPropertySet::set_base_script);
- ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptPropertySet::get_base_script);
+ ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptPropertySet::set_base_script);
+ ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptPropertySet::get_base_script);
- ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type);
- ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptPropertySet::get_basic_type);
+ ClassDB::bind_method(D_METHOD("set_basic_type", "basic_type"), &VisualScriptPropertySet::set_basic_type);
+ ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptPropertySet::get_basic_type);
- 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_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_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);
-
- ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptPropertySet::set_call_mode);
- ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptPropertySet::get_call_mode);
-
- 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_property", "property"), &VisualScriptPropertySet::set_property);
+ ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertySet::get_property);
+ ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptPropertySet::set_call_mode);
+ ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptPropertySet::get_call_mode);
+ 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);
String bt;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (i>0)
- bt+=",";
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (i > 0)
+ bt += ",";
- bt+=Variant::get_type_name(Variant::Type(i));
+ bt += Variant::get_type_name(Variant::Type(i));
}
String et;
- for(int i=0;i<InputEvent::TYPE_MAX;i++) {
- if (i>0)
- et+=",";
+ for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
+ if (i > 0)
+ et += ",";
- et+=event_type_names[i];
+ et += event_type_names[i];
}
List<String> script_extensions;
- for(int i=0;i<ScriptServer::get_language_count();i++) {
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
}
String script_ext_hint;
- for (List<String>::Element *E=script_extensions.front();E;E=E->next()) {
- if (script_ext_hint!=String())
- script_ext_hint+=",";
- script_ext_hint+="*."+E->get();
+ for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
+ if (script_ext_hint != String())
+ script_ext_hint += ",";
+ 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");
-
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
+ 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");
+ BIND_CONSTANT(CALL_MODE_SELF);
+ BIND_CONSTANT(CALL_MODE_NODE_PATH);
+ BIND_CONSTANT(CALL_MODE_INSTANCE);
}
class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance {
public:
-
-
VisualScriptPropertySet::CallMode call_mode;
NodePath node_path;
StringName property;
@@ -1562,53 +1480,50 @@ public:
VisualScriptPropertySet *node;
VisualScriptInstance *instance;
-
-
//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; }
- 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) {
-
+ 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) {
+ switch (call_mode) {
case VisualScriptPropertySet::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
+ Object *object = instance->get_owner_ptr();
bool valid;
- object->set(property,*p_inputs[0],&valid);
+ object->set(property, *p_inputs[0], &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid set value '"+String(*p_inputs[0])+"' on property '"+String(property)+"' of type "+object->get_class();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid set value '" + String(*p_inputs[0]) + "' on property '" + String(property) + "' of type " + object->get_class();
}
} break;
case VisualScriptPropertySet::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Base object is not a Node!";
return 0;
}
- Node* another = node->get_node(node_path);
+ Node *another = node->get_node(node_path);
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Path does not lead Node!";
return 0;
}
bool valid;
- another->set(property,*p_inputs[0],&valid);
+ another->set(property, *p_inputs[0], &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid set value '"+String(*p_inputs[0])+"' on property '"+String(property)+"' of type "+another->get_class();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid set value '" + String(*p_inputs[0]) + "' on property '" + String(property) + "' of type " + another->get_class();
}
} break;
@@ -1619,58 +1534,50 @@ public:
bool valid;
- v.set(property,*p_inputs[1],&valid);
+ v.set(property, *p_inputs[1], &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid set value '"+String(*p_inputs[1])+"' ("+Variant::get_type_name(p_inputs[1]->get_type())+") on property '"+String(property)+"' of type "+Variant::get_type_name(v.get_type());
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid set value '" + String(*p_inputs[1]) + "' (" + Variant::get_type_name(p_inputs[1]->get_type()) + ") on property '" + String(property) + "' of type " + Variant::get_type_name(v.get_type());
}
- *p_outputs[0]=v;
+ *p_outputs[0] = v;
} break;
-
}
return 0;
-
}
-
-
};
-VisualScriptNodeInstance* VisualScriptPropertySet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstancePropertySet * instance = memnew(VisualScriptNodeInstancePropertySet );
- instance->node=this;
- instance->instance=p_instance;
- instance->property=property;
- instance->call_mode=call_mode;
- instance->node_path=base_path;
+ VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->property = property;
+ instance->call_mode = call_mode;
+ instance->node_path = base_path;
return instance;
}
+VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess *p_inputs, int p_output) const {
-
-VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess* p_inputs, int p_output) const {
-
- if (p_output==0 && call_mode==CALL_MODE_INSTANCE) {
+ if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) {
return p_inputs[0];
}
- return VisualScriptNode::guess_output_type(p_inputs,p_output);
-
+ return VisualScriptNode::guess_output_type(p_inputs, p_output);
}
VisualScriptPropertySet::VisualScriptPropertySet() {
- call_mode=CALL_MODE_SELF;
- base_type="Object";
- basic_type=Variant::NIL;
- event_type=InputEvent::NONE;
-
+ call_mode = CALL_MODE_SELF;
+ base_type = "Object";
+ basic_type = Variant::NIL;
+ event_type = InputEvent::NONE;
}
-template<VisualScriptPropertySet::CallMode cmode>
-static Ref<VisualScriptNode> create_property_set_node(const String& p_name) {
+template <VisualScriptPropertySet::CallMode cmode>
+static Ref<VisualScriptNode> create_property_set_node(const String &p_name) {
Ref<VisualScriptPropertySet> node;
node.instance();
@@ -1678,35 +1585,33 @@ static Ref<VisualScriptNode> create_property_set_node(const String& p_name) {
return node;
}
-
//////////////////////////////////////////
////////////////GET//////////////////////
//////////////////////////////////////////
int VisualScriptPropertyGet::get_output_sequence_port_count() const {
- return 0;// (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
+ return 0; // (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
}
-bool VisualScriptPropertyGet::has_input_sequence_port() const{
+bool VisualScriptPropertyGet::has_input_sequence_port() const {
- return false;//(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
+ return false; //(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
}
void VisualScriptPropertyGet::_update_base_type() {
//cache it because this information may not be available on load
- if (call_mode==CALL_MODE_NODE_PATH) {
+ if (call_mode == CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
+ Node *node = _get_base_node();
if (node) {
- base_type=node->get_class();
+ base_type = node->get_class();
}
- } else if (call_mode==CALL_MODE_SELF) {
+ } else if (call_mode == CALL_MODE_SELF) {
if (get_visual_script().is_valid()) {
- base_type=get_visual_script()->get_instance_base_type();
+ base_type = get_visual_script()->get_instance_base_type();
}
}
-
}
Node *VisualScriptPropertyGet::_get_base_node() const {
@@ -1715,7 +1620,7 @@ Node *VisualScriptPropertyGet::_get_base_node() const {
if (!script.is_valid())
return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return NULL;
@@ -1729,7 +1634,7 @@ Node *VisualScriptPropertyGet::_get_base_node() const {
if (!edited_scene)
return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return NULL;
@@ -1748,25 +1653,22 @@ Node *VisualScriptPropertyGet::_get_base_node() const {
StringName VisualScriptPropertyGet::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
if (path)
return path->get_class();
-
}
return base_type;
}
+int VisualScriptPropertyGet::get_input_value_port_count() const {
-int VisualScriptPropertyGet::get_input_value_port_count() const{
-
- return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0;
-
+ return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0;
}
-int VisualScriptPropertyGet::get_output_value_port_count() const{
+int VisualScriptPropertyGet::get_output_value_port_count() const {
return 1;
}
@@ -1776,31 +1678,29 @@ String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const {
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
+ if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
+ if (p_idx == 0) {
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());
+ 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());
return pi;
} else {
p_idx--;
}
}
return PropertyInfo();
-
}
-PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(type_cache,"value");
+ return PropertyInfo(type_cache, "value");
}
-
String VisualScriptPropertyGet::get_caption() const {
- static const char*cname[4]= {
+ static const char *cname[4] = {
"SelfGet",
"NodeGet",
"InstanceGet",
@@ -1814,39 +1714,39 @@ String VisualScriptPropertyGet::get_text() const {
String prop;
- if (call_mode==CALL_MODE_BASIC_TYPE)
- prop=Variant::get_type_name(basic_type)+"."+property;
- else if (call_mode==CALL_MODE_NODE_PATH)
- prop=String(base_path)+":"+property;
- else if (call_mode==CALL_MODE_SELF)
- prop=property;
- else if (call_mode==CALL_MODE_INSTANCE)
- prop=String(base_type)+":"+property;
+ if (call_mode == CALL_MODE_BASIC_TYPE)
+ prop = Variant::get_type_name(basic_type) + "." + property;
+ else if (call_mode == CALL_MODE_NODE_PATH)
+ prop = String(base_path) + ":" + property;
+ else if (call_mode == CALL_MODE_SELF)
+ prop = property;
+ else if (call_mode == CALL_MODE_INSTANCE)
+ prop = String(base_type) + ":" + property;
return prop;
}
-void VisualScriptPropertyGet::set_base_type(const StringName& p_type) {
+void VisualScriptPropertyGet::set_base_type(const StringName &p_type) {
- if (base_type==p_type)
+ if (base_type == p_type)
return;
- base_type=p_type;
+ base_type = p_type;
_change_notify();
ports_changed_notify();
}
-StringName VisualScriptPropertyGet::get_base_type() const{
+StringName VisualScriptPropertyGet::get_base_type() const {
return base_type;
}
-void VisualScriptPropertyGet::set_base_script(const String& p_path) {
+void VisualScriptPropertyGet::set_base_script(const String &p_path) {
- if (base_script==p_path)
+ if (base_script == p_path)
return;
- base_script=p_path;
+ base_script = p_path;
_change_notify();
ports_changed_notify();
}
@@ -1856,62 +1756,59 @@ String VisualScriptPropertyGet::get_base_script() const {
return base_script;
}
-
void VisualScriptPropertyGet::_update_cache() {
-
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
//not super efficient..
Variant v;
- if (basic_type==Variant::INPUT_EVENT) {
+ if (basic_type == Variant::INPUT_EVENT) {
InputEvent ev;
- ev.type=event_type;
- v=ev;
+ ev.type = event_type;
+ v = ev;
} else {
Variant::CallError ce;
- v = Variant::construct(basic_type,NULL,0,ce);
+ v = Variant::construct(basic_type, NULL, 0, ce);
}
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name==property) {
+ if (E->get().name == property) {
- type_cache=E->get().type;
+ type_cache = E->get().type;
return;
}
}
} else {
-
StringName type;
Ref<Script> script;
- Node *node=NULL;
+ Node *node = NULL;
- if (call_mode==CALL_MODE_NODE_PATH) {
+ if (call_mode == CALL_MODE_NODE_PATH) {
- node=_get_base_node();
+ node = _get_base_node();
if (node) {
- type=node->get_class();
- base_type=type; //cache, too
+ type = node->get_class();
+ base_type = type; //cache, too
script = node->get_script();
}
- } else if (call_mode==CALL_MODE_SELF) {
+ } else if (call_mode == CALL_MODE_SELF) {
if (get_visual_script().is_valid()) {
- type=get_visual_script()->get_instance_base_type();
- base_type=type; //cache, too
- script=get_visual_script();
+ type = get_visual_script()->get_instance_base_type();
+ base_type = type; //cache, too
+ script = get_visual_script();
}
- } else if (call_mode==CALL_MODE_INSTANCE) {
+ } else if (call_mode == CALL_MODE_INSTANCE) {
- type=base_type;
- if (base_script!=String()) {
+ type = base_type;
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
@@ -1920,53 +1817,51 @@ void VisualScriptPropertyGet::_update_cache() {
if (ResourceCache::has(base_script)) {
- script = Ref<Resource>( ResourceCache::get(base_script) );
+ script = Ref<Resource>(ResourceCache::get(base_script));
} else {
return;
}
}
}
-
- bool valid=false;
+ bool valid = false;
Variant::Type type_ret;
- type_ret=ClassDB::get_property_type(base_type,property,&valid);
+ type_ret = ClassDB::get_property_type(base_type, property, &valid);
if (valid) {
- type_cache=type_ret;
+ type_cache = type_ret;
return; //all dandy
}
if (node) {
- Variant prop = node->get(property,&valid);
+ Variant prop = node->get(property, &valid);
if (valid) {
- type_cache=prop.get_type();
+ type_cache = prop.get_type();
return; //all dandy again
}
}
if (script.is_valid()) {
- type_ret=script->get_static_property_type(property,&valid);
+ type_ret = script->get_static_property_type(property, &valid);
if (valid) {
- type_cache=type_ret;
+ type_cache = type_ret;
return; //all dandy
}
}
}
}
-void VisualScriptPropertyGet::set_property(const StringName& p_type){
+void VisualScriptPropertyGet::set_property(const StringName &p_type) {
- if (property==p_type)
+ if (property == p_type)
return;
- property=p_type;
-
+ property = p_type;
_update_cache();
_change_notify();
@@ -1974,16 +1869,15 @@ void VisualScriptPropertyGet::set_property(const StringName& p_type){
}
StringName VisualScriptPropertyGet::get_property() const {
-
return property;
}
-void VisualScriptPropertyGet::set_base_path(const NodePath& p_type) {
+void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) {
- if (base_path==p_type)
+ if (base_path == p_type)
return;
- base_path=p_type;
+ base_path = p_type;
_change_notify();
_update_base_type();
ports_changed_notify();
@@ -1994,48 +1888,42 @@ NodePath VisualScriptPropertyGet::get_base_path() const {
return base_path;
}
-
void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
+ if (call_mode == p_mode)
return;
- call_mode=p_mode;
+ call_mode = p_mode;
_change_notify();
_update_base_type();
ports_changed_notify();
-
}
VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const {
return call_mode;
}
-
-
void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) {
- if (basic_type==p_type)
+ if (basic_type == p_type)
return;
- basic_type=p_type;
-
+ basic_type = p_type;
_change_notify();
ports_changed_notify();
}
-Variant::Type VisualScriptPropertyGet::get_basic_type() const{
+Variant::Type VisualScriptPropertyGet::get_basic_type() const {
return basic_type;
}
-
void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) {
- if (event_type==p_type)
+ if (event_type == p_type)
return;
- event_type=p_type;
- if(call_mode==CALL_MODE_BASIC_TYPE) {
+ event_type = p_type;
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
_update_cache();
}
_change_notify();
@@ -2043,14 +1931,13 @@ void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) {
ports_changed_notify();
}
-InputEvent::Type VisualScriptPropertyGet::get_event_type() const{
+InputEvent::Type VisualScriptPropertyGet::get_event_type() const {
return event_type;
}
-
void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) {
- type_cache=p_type;
+ type_cache = p_type;
}
Variant::Type VisualScriptPropertyGet::_get_type_cache() const {
@@ -2058,61 +1945,59 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const {
return type_cache;
}
+void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
-void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="property/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
+ if (property.name == "property/base_type") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
- if (property.name=="property/base_script") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=0;
+ if (property.name == "property/base_script") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = 0;
}
}
- if (property.name=="property/basic_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE) {
- property.usage=0;
+ if (property.name == "property/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/event_type") {
+ if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) {
+ property.usage = 0;
}
}
- if (property.name=="property/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
+ if (property.name == "property/node_path") {
+ if (call_mode != CALL_MODE_NODE_PATH) {
+ property.usage = 0;
} else {
Node *bnode = _get_base_node();
if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
+ property.hint_string = bnode->get_path(); //convert to loong string
} else {
-
}
}
}
- if (property.name=="property/property") {
+ if (property.name == "property/property") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
+ property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
+ property.hint_string = Variant::get_type_name(basic_type);
- } 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());
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=base_type;
+ } 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());
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
+ property.hint_string = base_type;
- if (base_script!=String()) {
+ if (base_script != String()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
@@ -2120,103 +2005,97 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const {
if (ResourceCache::has(base_script)) {
- Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
if (script.is_valid()) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT;
- property.hint_string=itos(script->get_instance_ID());
+ property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
+ property.hint_string = itos(script->get_instance_ID());
}
}
}
- } else if (call_mode==CALL_MODE_NODE_PATH) {
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
Node *node = _get_base_node();
if (node) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
+ property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE;
+ property.hint_string = itos(node->get_instance_ID());
} else {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=get_base_type();
+ property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
+ property.hint_string = get_base_type();
}
-
}
-
}
-
}
void VisualScriptPropertyGet::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptPropertyGet::get_base_type);
-
- ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptPropertyGet::set_base_script);
- ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptPropertyGet::get_base_script);
+ ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertyGet::set_base_type);
+ ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertyGet::get_base_type);
- ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type);
- ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type);
+ ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptPropertyGet::set_base_script);
+ ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptPropertyGet::get_base_script);
- 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_basic_type", "basic_type"), &VisualScriptPropertyGet::set_basic_type);
+ ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptPropertyGet::get_basic_type);
- 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_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);
+ ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertyGet::set_property);
+ ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertyGet::get_property);
- ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptPropertyGet::set_call_mode);
- ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptPropertyGet::get_call_mode);
+ ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptPropertyGet::set_call_mode);
+ ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptPropertyGet::get_call_mode);
- 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_base_path", "base_path"), &VisualScriptPropertyGet::set_base_path);
+ ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptPropertyGet::get_base_path);
String bt;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (i>0)
- bt+=",";
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (i > 0)
+ bt += ",";
- bt+=Variant::get_type_name(Variant::Type(i));
+ bt += Variant::get_type_name(Variant::Type(i));
}
String et;
- for(int i=0;i<InputEvent::TYPE_MAX;i++) {
- if (i>0)
- et+=",";
+ for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
+ if (i > 0)
+ et += ",";
- et+=event_type_names[i];
+ et += event_type_names[i];
}
List<String> script_extensions;
- for(int i=0;i<ScriptServer::get_language_count();i++) {
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
}
String script_ext_hint;
- for (List<String>::Element *E=script_extensions.front();E;E=E->next()) {
- if (script_ext_hint!=String())
- script_ext_hint+=",";
- script_ext_hint+="."+E->get();
+ for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
+ if (script_ext_hint != String())
+ script_ext_hint += ",";
+ 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, "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");
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
+ BIND_CONSTANT(CALL_MODE_SELF);
+ BIND_CONSTANT(CALL_MODE_NODE_PATH);
+ BIND_CONSTANT(CALL_MODE_INSTANCE);
}
class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
public:
-
-
VisualScriptPropertyGet::CallMode call_mode;
NodePath node_path;
StringName property;
@@ -2224,51 +2103,47 @@ public:
VisualScriptPropertyGet *node;
VisualScriptInstance *instance;
+ 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) {
- 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) {
+ switch (call_mode) {
case VisualScriptPropertyGet::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
+ Object *object = instance->get_owner_ptr();
bool valid;
- *p_outputs[0] = object->get(property,&valid);
+ *p_outputs[0] = object->get(property, &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Invalid index property name.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Invalid index property name.");
return 0;
}
} break;
case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Base object is not a Node!");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Base object is not a Node!");
return 0;
}
- Node* another = node->get_node(node_path);
+ Node *another = node->get_node(node_path);
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Path does not lead Node!");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Path does not lead Node!");
return 0;
}
bool valid;
-
- *p_outputs[0] = another->get(property,&valid);
+ *p_outputs[0] = another->get(property, &valid);
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());
+ 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());
return 0;
}
@@ -2278,48 +2153,42 @@ public:
bool valid;
Variant v = *p_inputs[0];
- *p_outputs[0] = v.get(property,&valid);
+ *p_outputs[0] = v.get(property, &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Invalid index property name.");
-
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Invalid index property name.");
}
};
}
return 0;
}
-
-
-
-
};
-VisualScriptNodeInstance* VisualScriptPropertyGet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstancePropertyGet * instance = memnew(VisualScriptNodeInstancePropertyGet );
- instance->node=this;
- instance->instance=p_instance;
- instance->property=property;
- instance->call_mode=call_mode;
- instance->node_path=base_path;
+ VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->property = property;
+ instance->call_mode = call_mode;
+ instance->node_path = base_path;
return instance;
}
VisualScriptPropertyGet::VisualScriptPropertyGet() {
- call_mode=CALL_MODE_SELF;
- base_type="Object";
- basic_type=Variant::NIL;
- event_type=InputEvent::NONE;
- type_cache=Variant::NIL;
-
+ call_mode = CALL_MODE_SELF;
+ base_type = "Object";
+ basic_type = Variant::NIL;
+ event_type = InputEvent::NONE;
+ type_cache = Variant::NIL;
}
-template<VisualScriptPropertyGet::CallMode cmode>
-static Ref<VisualScriptNode> create_property_get_node(const String& p_name) {
+template <VisualScriptPropertyGet::CallMode cmode>
+static Ref<VisualScriptNode> create_property_get_node(const String &p_name) {
Ref<VisualScriptPropertyGet> node;
node.instance();
@@ -2327,7 +2196,6 @@ static Ref<VisualScriptNode> create_property_get_node(const String& p_name) {
return node;
}
-
//////////////////////////////////////////
////////////////EMIT//////////////////////
//////////////////////////////////////////
@@ -2337,13 +2205,12 @@ int VisualScriptEmitSignal::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptEmitSignal::has_input_sequence_port() const{
+bool VisualScriptEmitSignal::has_input_sequence_port() const {
return true;
}
-
-int VisualScriptEmitSignal::get_input_value_port_count() const{
+int VisualScriptEmitSignal::get_input_value_port_count() const {
Ref<VisualScript> vs = get_visual_script();
if (vs.is_valid()) {
@@ -2355,9 +2222,8 @@ int VisualScriptEmitSignal::get_input_value_port_count() const{
}
return 0;
-
}
-int VisualScriptEmitSignal::get_output_value_port_count() const{
+int VisualScriptEmitSignal::get_output_value_port_count() const {
return 0;
}
@@ -2366,7 +2232,7 @@ String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const {
Ref<VisualScript> vs = get_visual_script();
if (vs.is_valid()) {
@@ -2374,19 +2240,17 @@ PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const{
if (!vs->has_custom_signal(name))
return PropertyInfo();
- return PropertyInfo(vs->custom_signal_get_argument_type(name,p_idx),vs->custom_signal_get_argument_name(name,p_idx));
+ return PropertyInfo(vs->custom_signal_get_argument_type(name, p_idx), vs->custom_signal_get_argument_name(name, p_idx));
}
return PropertyInfo();
-
}
-PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptEmitSignal::get_caption() const {
return "EmitSignal";
@@ -2394,35 +2258,28 @@ String VisualScriptEmitSignal::get_caption() const {
String VisualScriptEmitSignal::get_text() const {
- return "emit "+String(name);
+ return "emit " + String(name);
}
+void VisualScriptEmitSignal::set_signal(const StringName &p_type) {
-
-void VisualScriptEmitSignal::set_signal(const StringName& p_type){
-
- if (name==p_type)
+ if (name == p_type)
return;
- name=p_type;
+ name = p_type;
_change_notify();
ports_changed_notify();
}
StringName VisualScriptEmitSignal::get_signal() const {
-
return name;
}
+void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const {
-void VisualScriptEmitSignal::_validate_property(PropertyInfo& property) const {
-
-
-
- if (property.name=="signal/signal") {
- property.hint=PROPERTY_HINT_ENUM;
-
+ if (property.name == "signal/signal") {
+ property.hint = PROPERTY_HINT_ENUM;
List<StringName> sigs;
@@ -2430,37 +2287,30 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo& property) const {
if (vs.is_valid()) {
vs->get_custom_signal_list(&sigs);
-
}
String ml;
- for (List<StringName>::Element *E=sigs.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) {
- if (ml!=String())
- ml+=",";
- ml+=E->get();
+ if (ml != String())
+ ml += ",";
+ ml += E->get();
}
- property.hint_string=ml;
+ property.hint_string = ml;
}
-
}
-
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");
-
+ 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");
}
class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance {
public:
-
VisualScriptEmitSignal *node;
VisualScriptInstance *instance;
int argcount;
@@ -2470,57 +2320,50 @@ public:
//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; }
- 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) {
-
+ 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) {
Object *obj = instance->get_owner_ptr();
- obj->emit_signal(name,p_inputs,argcount);
-
+ obj->emit_signal(name, p_inputs, argcount);
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptEmitSignal::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceEmitSignal * instance = memnew(VisualScriptNodeInstanceEmitSignal );
- instance->node=this;
- instance->instance=p_instance;
- instance->name=name;
- instance->argcount=get_input_value_port_count();
+ VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->name = name;
+ instance->argcount = get_input_value_port_count();
return instance;
}
VisualScriptEmitSignal::VisualScriptEmitSignal() {
}
-
-
-static Ref<VisualScriptNode> create_basic_type_call_node(const String& p_name) {
+static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) {
Vector<String> path = p_name.split("/");
- ERR_FAIL_COND_V(path.size()<4,Ref<VisualScriptNode>());
+ ERR_FAIL_COND_V(path.size() < 4, Ref<VisualScriptNode>());
String base_type = path[2];
String method = path[3];
Ref<VisualScriptFunctionCall> node;
node.instance();
- Variant::Type type=Variant::VARIANT_MAX;
+ Variant::Type type = Variant::VARIANT_MAX;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (Variant::get_type_name(Variant::Type(i))==base_type) {
- type=Variant::Type(i);
+ if (Variant::get_type_name(Variant::Type(i)) == base_type) {
+ type = Variant::Type(i);
break;
}
}
- ERR_FAIL_COND_V(type==Variant::VARIANT_MAX,Ref<VisualScriptNode>());
-
+ ERR_FAIL_COND_V(type == Variant::VARIANT_MAX, Ref<VisualScriptNode>());
node->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
node->set_basic_type(type);
@@ -2529,29 +2372,27 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String& p_name) {
return node;
}
-
void register_visual_script_func_nodes() {
- VisualScriptLanguage::singleton->add_register_func("functions/call",create_node_generic<VisualScriptFunctionCall>);
- VisualScriptLanguage::singleton->add_register_func("functions/set",create_node_generic<VisualScriptPropertySet>);
- VisualScriptLanguage::singleton->add_register_func("functions/get",create_node_generic<VisualScriptPropertyGet>);
+ VisualScriptLanguage::singleton->add_register_func("functions/call", create_node_generic<VisualScriptFunctionCall>);
+ VisualScriptLanguage::singleton->add_register_func("functions/set", create_node_generic<VisualScriptPropertySet>);
+ VisualScriptLanguage::singleton->add_register_func("functions/get", create_node_generic<VisualScriptPropertyGet>);
//VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>);
//VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>);
- VisualScriptLanguage::singleton->add_register_func("functions/emit_signal",create_node_generic<VisualScriptEmitSignal>);
-
+ VisualScriptLanguage::singleton->add_register_func("functions/emit_signal", create_node_generic<VisualScriptEmitSignal>);
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
Variant::Type t = Variant::Type(i);
String type_name = Variant::get_type_name(t);
Variant::CallError ce;
- Variant vt = Variant::construct(t,NULL,0,ce);
+ Variant vt = Variant::construct(t, NULL, 0, ce);
List<MethodInfo> ml;
vt.get_method_list(&ml);
- for (List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
- VisualScriptLanguage::singleton->add_register_func("functions/by_type/"+type_name+"/"+E->get().name,create_basic_type_call_node);
+ for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) {
+ VisualScriptLanguage::singleton->add_register_func("functions/by_type/" + type_name + "/" + E->get().name, create_basic_type_call_node);
}
}
}
diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h
index 7c1d4511cb..3f82edc5f0 100644
--- a/modules/visual_script/visual_script_func_nodes.h
+++ b/modules/visual_script/visual_script_func_nodes.h
@@ -31,10 +31,9 @@
#include "visual_script.h"
-
class VisualScriptFunctionCall : public VisualScriptNode {
- GDCLASS(VisualScriptFunctionCall,VisualScriptNode)
+ GDCLASS(VisualScriptFunctionCall, VisualScriptNode)
public:
enum CallMode {
CALL_MODE_SELF,
@@ -53,7 +52,6 @@ public:
};
private:
-
CallMode call_mode;
StringName base_type;
String base_script;
@@ -65,34 +63,29 @@ private:
StringName singleton;
bool validate;
-
Node *_get_base_node() const;
StringName _get_base_type() const;
MethodInfo method_cache;
void _update_method_cache();
- void _set_argument_cache(const Dictionary& p_args);
+ void _set_argument_cache(const Dictionary &p_args);
Dictionary _get_argument_cache() const;
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -103,22 +96,21 @@ public:
void set_basic_type(Variant::Type p_type);
Variant::Type get_basic_type() const;
- void set_base_type(const StringName& p_type);
+ void set_base_type(const StringName &p_type);
StringName get_base_type() const;
- void set_base_script(const String& p_path);
+ void set_base_script(const String &p_path);
String get_base_script() const;
- void set_singleton(const StringName& p_type);
+ void set_singleton(const StringName &p_type);
StringName get_singleton() const;
- void set_function(const StringName& p_type);
+ void set_function(const StringName &p_type);
StringName get_function() const;
- void set_base_path(const NodePath& p_type);
+ void set_base_path(const NodePath &p_type);
NodePath get_base_path() const;
-
void set_call_mode(CallMode p_mode);
CallMode get_call_mode() const;
@@ -131,21 +123,19 @@ public:
void set_rpc_call_mode(RPCCallMode p_mode);
RPCCallMode get_rpc_call_mode() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptFunctionCall();
};
-VARIANT_ENUM_CAST(VisualScriptFunctionCall::CallMode );
-VARIANT_ENUM_CAST(VisualScriptFunctionCall::RPCCallMode );
-
+VARIANT_ENUM_CAST(VisualScriptFunctionCall::CallMode);
+VARIANT_ENUM_CAST(VisualScriptFunctionCall::RPCCallMode);
class VisualScriptPropertySet : public VisualScriptNode {
- GDCLASS(VisualScriptPropertySet,VisualScriptNode)
+ GDCLASS(VisualScriptPropertySet, VisualScriptNode)
public:
enum CallMode {
CALL_MODE_SELF,
@@ -153,14 +143,13 @@ public:
CALL_MODE_INSTANCE,
CALL_MODE_BASIC_TYPE,
-
};
-private:
+private:
PropertyInfo type_cache;
CallMode call_mode;
- Variant::Type basic_type;
+ Variant::Type basic_type;
StringName base_type;
String base_script;
NodePath base_path;
@@ -174,28 +163,23 @@ private:
void _update_cache();
- void _set_type_cache(const Dictionary& p_type);
+ void _set_type_cache(const Dictionary &p_type);
Dictionary _get_type_cache() const;
-
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -203,10 +187,10 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "functions"; }
- void set_base_type(const StringName& p_type);
+ void set_base_type(const StringName &p_type);
StringName get_base_type() const;
- void set_base_script(const String& p_path);
+ void set_base_script(const String &p_path);
String get_base_script() const;
void set_basic_type(Variant::Type p_type);
@@ -215,28 +199,26 @@ public:
void set_event_type(InputEvent::Type p_type);
InputEvent::Type get_event_type() const;
- void set_property(const StringName& p_type);
+ void set_property(const StringName &p_type);
StringName get_property() const;
- void set_base_path(const NodePath& p_type);
+ void set_base_path(const NodePath &p_type);
NodePath get_base_path() const;
void set_call_mode(CallMode p_mode);
CallMode get_call_mode() const;
-
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptPropertySet();
};
-VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode );
-
+VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode);
class VisualScriptPropertyGet : public VisualScriptNode {
- GDCLASS(VisualScriptPropertyGet,VisualScriptNode)
+ GDCLASS(VisualScriptPropertyGet, VisualScriptNode)
public:
enum CallMode {
CALL_MODE_SELF,
@@ -245,8 +227,8 @@ public:
CALL_MODE_BASIC_TYPE,
};
-private:
+private:
Variant::Type type_cache;
CallMode call_mode;
@@ -267,23 +249,19 @@ private:
Variant::Type _get_type_cache() const;
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -291,10 +269,10 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "functions"; }
- void set_base_type(const StringName& p_type);
+ void set_base_type(const StringName &p_type);
StringName get_base_type() const;
- void set_base_script(const String& p_path);
+ void set_base_script(const String &p_path);
String get_base_script() const;
void set_basic_type(Variant::Type p_type);
@@ -303,55 +281,43 @@ public:
void set_event_type(InputEvent::Type p_type);
InputEvent::Type get_event_type() const;
- void set_property(const StringName& p_type);
+ void set_property(const StringName &p_type);
StringName get_property() const;
- void set_base_path(const NodePath& p_type);
+ void set_base_path(const NodePath &p_type);
NodePath get_base_path() const;
void set_call_mode(CallMode p_mode);
CallMode get_call_mode() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptPropertyGet();
};
-
-
-
-
-VARIANT_ENUM_CAST(VisualScriptPropertyGet::CallMode );
-
-
+VARIANT_ENUM_CAST(VisualScriptPropertyGet::CallMode);
class VisualScriptEmitSignal : public VisualScriptNode {
- GDCLASS(VisualScriptEmitSignal,VisualScriptNode)
+ GDCLASS(VisualScriptEmitSignal, VisualScriptNode)
private:
-
StringName name;
-
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -359,19 +325,14 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "functions"; }
- void set_signal(const StringName& p_type);
+ void set_signal(const StringName &p_type);
StringName get_signal() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
-
-
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptEmitSignal();
};
-
-
void register_visual_script_func_nodes();
#endif // VISUAL_SCRIPT_FUNC_NODES_H
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 824dfe88a9..68bd1e6d4c 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -28,157 +28,146 @@
/*************************************************************************/
#include "visual_script_nodes.h"
-#include "global_constants.h"
#include "global_config.h"
-#include "scene/main/scene_main_loop.h"
+#include "global_constants.h"
+#include "os/input.h"
#include "os/os.h"
#include "scene/main/node.h"
-#include "os/input.h"
+#include "scene/main/scene_main_loop.h"
//////////////////////////////////////////
////////////////FUNCTION//////////////////
//////////////////////////////////////////
+bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value) {
-bool VisualScriptFunction::_set(const StringName& p_name, const Variant& p_value) {
-
-
- if (p_name=="argument_count") {
+ if (p_name == "argument_count") {
- int new_argc=p_value;
+ int new_argc = p_value;
int argc = arguments.size();
- if (argc==new_argc)
+ if (argc == new_argc)
return true;
arguments.resize(new_argc);
- for(int i=argc;i<new_argc;i++) {
- arguments[i].name="arg"+itos(i+1);
- arguments[i].type=Variant::NIL;
+ for (int i = argc; i < new_argc; i++) {
+ arguments[i].name = "arg" + itos(i + 1);
+ arguments[i].type = Variant::NIL;
}
ports_changed_notify();
_change_notify();
return true;
}
if (String(p_name).begins_with("argument/")) {
- int idx = String(p_name).get_slice("/",1).to_int()-1;
- ERR_FAIL_INDEX_V(idx,arguments.size(),false);
- String what = String(p_name).get_slice("/",2);
- if (what=="type") {
+ int idx = String(p_name).get_slice("/", 1).to_int() - 1;
+ ERR_FAIL_INDEX_V(idx, arguments.size(), false);
+ String what = String(p_name).get_slice("/", 2);
+ if (what == "type") {
Variant::Type new_type = Variant::Type(int(p_value));
- arguments[idx].type=new_type;
+ arguments[idx].type = new_type;
ports_changed_notify();
return true;
}
- if (what=="name") {
+ if (what == "name") {
- arguments[idx].name=p_value;
+ arguments[idx].name = p_value;
ports_changed_notify();
return true;
}
-
-
}
- if (p_name=="stack/stackless") {
+ if (p_name == "stack/stackless") {
set_stack_less(p_value);
return true;
}
- if (p_name=="stack/size") {
- stack_size=p_value;
+ if (p_name == "stack/size") {
+ stack_size = p_value;
return true;
}
- if (p_name=="rpc/mode") {
- rpc_mode=ScriptInstance::RPCMode(int(p_value));
+ if (p_name == "rpc/mode") {
+ rpc_mode = ScriptInstance::RPCMode(int(p_value));
return true;
}
return false;
}
-bool VisualScriptFunction::_get(const StringName& p_name,Variant &r_ret) const {
+bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const {
-
- if (p_name=="argument_count") {
+ if (p_name == "argument_count") {
r_ret = arguments.size();
return true;
}
if (String(p_name).begins_with("argument/")) {
- int idx = String(p_name).get_slice("/",1).to_int()-1;
- ERR_FAIL_INDEX_V(idx,arguments.size(),false);
- String what = String(p_name).get_slice("/",2);
- if (what=="type") {
+ int idx = String(p_name).get_slice("/", 1).to_int() - 1;
+ ERR_FAIL_INDEX_V(idx, arguments.size(), false);
+ String what = String(p_name).get_slice("/", 2);
+ if (what == "type") {
r_ret = arguments[idx].type;
return true;
}
- if (what=="name") {
+ if (what == "name") {
r_ret = arguments[idx].name;
return true;
}
-
-
-
}
- if (p_name=="stack/stackless") {
- r_ret=stack_less;
+ if (p_name == "stack/stackless") {
+ r_ret = stack_less;
return true;
}
- if (p_name=="stack/size") {
- r_ret=stack_size;
+ if (p_name == "stack/size") {
+ r_ret = stack_size;
return true;
}
- if (p_name=="rpc/mode") {
- r_ret=rpc_mode;
+ if (p_name == "rpc/mode") {
+ r_ret = rpc_mode;
return true;
}
return false;
}
-void VisualScriptFunction::_get_property_list( List<PropertyInfo> *p_list) const {
-
+void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back(PropertyInfo(Variant::INT,"argument_count",PROPERTY_HINT_RANGE,"0,256"));
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256"));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- 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"));
+ 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"));
}
if (!stack_less) {
- p_list->push_back(PropertyInfo(Variant::INT,"stack/size",PROPERTY_HINT_RANGE,"1,100000"));
+ p_list->push_back(PropertyInfo(Variant::INT, "stack/size", PROPERTY_HINT_RANGE, "1,100000"));
}
- p_list->push_back(PropertyInfo(Variant::BOOL,"stack/stackless"));
- p_list->push_back(PropertyInfo(Variant::INT,"rpc/mode",PROPERTY_HINT_ENUM,"Disabled,Remote,Sync,Master,Slave"));
-
+ p_list->push_back(PropertyInfo(Variant::BOOL, "stack/stackless"));
+ p_list->push_back(PropertyInfo(Variant::INT, "rpc/mode", PROPERTY_HINT_ENUM, "Disabled,Remote,Sync,Master,Slave"));
}
-
int VisualScriptFunction::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptFunction::has_input_sequence_port() const{
+bool VisualScriptFunction::has_input_sequence_port() const {
return false;
}
-int VisualScriptFunction::get_input_value_port_count() const{
+int VisualScriptFunction::get_input_value_port_count() const {
return 0;
}
-int VisualScriptFunction::get_output_value_port_count() const{
+int VisualScriptFunction::get_output_value_port_count() const {
return arguments.size();
}
@@ -188,17 +177,17 @@ String VisualScriptFunction::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const {
ERR_FAIL_V(PropertyInfo());
return PropertyInfo();
}
-PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx,arguments.size(),PropertyInfo());
+ ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo());
PropertyInfo out;
- out.type=arguments[p_idx].type;
- out.name=arguments[p_idx].name;
+ out.type = arguments[p_idx].type;
+ out.name = arguments[p_idx].name;
return out;
}
@@ -212,53 +201,48 @@ String VisualScriptFunction::get_text() const {
return get_name(); //use name as function name I guess
}
-void VisualScriptFunction::add_argument(Variant::Type p_type,const String& p_name,int p_index){
+void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_name, int p_index) {
Argument arg;
- arg.name=p_name;
- arg.type=p_type;
- if (p_index>=0)
- arguments.insert(p_index,arg);
+ arg.name = p_name;
+ arg.type = p_type;
+ if (p_index >= 0)
+ arguments.insert(p_index, arg);
else
arguments.push_back(arg);
ports_changed_notify();
-
}
-void VisualScriptFunction::set_argument_type(int p_argidx,Variant::Type p_type){
+void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) {
- ERR_FAIL_INDEX(p_argidx,arguments.size());
+ ERR_FAIL_INDEX(p_argidx, arguments.size());
- arguments[p_argidx].type=p_type;
+ arguments[p_argidx].type = p_type;
ports_changed_notify();
}
Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const {
- ERR_FAIL_INDEX_V(p_argidx,arguments.size(),Variant::NIL);
+ ERR_FAIL_INDEX_V(p_argidx, arguments.size(), Variant::NIL);
return arguments[p_argidx].type;
-
}
-void VisualScriptFunction::set_argument_name(int p_argidx,const String& p_name) {
+void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) {
- ERR_FAIL_INDEX(p_argidx,arguments.size());
+ ERR_FAIL_INDEX(p_argidx, arguments.size());
- arguments[p_argidx].name=p_name;
+ arguments[p_argidx].name = p_name;
ports_changed_notify();
-
}
String VisualScriptFunction::get_argument_name(int p_argidx) const {
- ERR_FAIL_INDEX_V(p_argidx,arguments.size(),String());
+ ERR_FAIL_INDEX_V(p_argidx, arguments.size(), String());
return arguments[p_argidx].name;
-
}
void VisualScriptFunction::remove_argument(int p_argidx) {
- ERR_FAIL_INDEX(p_argidx,arguments.size());
+ ERR_FAIL_INDEX(p_argidx, arguments.size());
arguments.remove(p_argidx);
ports_changed_notify();
-
}
int VisualScriptFunction::get_argument_count() const {
@@ -266,68 +250,62 @@ int VisualScriptFunction::get_argument_count() const {
return arguments.size();
}
-
void VisualScriptFunction::set_rpc_mode(ScriptInstance::RPCMode p_mode) {
- rpc_mode=p_mode;
+ rpc_mode = p_mode;
}
ScriptInstance::RPCMode VisualScriptFunction::get_rpc_mode() const {
return rpc_mode;
}
-
class VisualScriptNodeInstanceFunction : public VisualScriptNodeInstance {
public:
-
VisualScriptFunction *node;
VisualScriptInstance *instance;
//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) {
+ 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) {
int ac = node->get_argument_count();
- for(int i=0;i<ac;i++) {
+ for (int i = 0; i < ac; i++) {
#ifdef DEBUG_ENABLED
Variant::Type expected = node->get_argument_type(i);
- if (expected!=Variant::NIL) {
- if (!Variant::can_convert_strict(p_inputs[i]->get_type(),expected)) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.expected=expected;
- r_error.argument=i;
+ if (expected != Variant::NIL) {
+ if (!Variant::can_convert_strict(p_inputs[i]->get_type(), expected)) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.expected = expected;
+ r_error.argument = i;
return 0;
}
}
#endif
- *p_outputs[i]=*p_inputs[i];
+ *p_outputs[i] = *p_inputs[i];
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptFunction::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceFunction * instance = memnew(VisualScriptNodeInstanceFunction );
- instance->node=this;
- instance->instance=p_instance;
+ VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction);
+ instance->node = this;
+ instance->instance = p_instance;
return instance;
}
VisualScriptFunction::VisualScriptFunction() {
- stack_size=256;
- stack_less=false;
- rpc_mode=ScriptInstance::RPC_MODE_DISABLED;
+ stack_size = 256;
+ stack_less = false;
+ rpc_mode = ScriptInstance::RPC_MODE_DISABLED;
}
-
void VisualScriptFunction::set_stack_less(bool p_enable) {
- stack_less=p_enable;
+ stack_less = p_enable;
_change_notify();
}
@@ -337,8 +315,8 @@ bool VisualScriptFunction::is_stack_less() const {
void VisualScriptFunction::set_stack_size(int p_size) {
- ERR_FAIL_COND(p_size <1 || p_size>100000);
- stack_size=p_size;
+ ERR_FAIL_COND(p_size < 1 || p_size > 100000);
+ stack_size = p_size;
}
int VisualScriptFunction::get_stack_size() const {
@@ -346,7 +324,6 @@ int VisualScriptFunction::get_stack_size() const {
return stack_size;
}
-
//////////////////////////////////////////
////////////////OPERATOR//////////////////
//////////////////////////////////////////
@@ -356,16 +333,16 @@ int VisualScriptOperator::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptOperator::has_input_sequence_port() const{
+bool VisualScriptOperator::has_input_sequence_port() const {
return false;
}
-int VisualScriptOperator::get_input_value_port_count() const{
+int VisualScriptOperator::get_input_value_port_count() const {
- return (op==Variant::OP_BIT_NEGATE || op==Variant::OP_NOT || op==Variant::OP_NEGATE || op==Variant::OP_POSITIVE) ? 1 : 2;
+ return (op == Variant::OP_BIT_NEGATE || op == Variant::OP_NOT || op == Variant::OP_NEGATE || op == Variant::OP_POSITIVE) ? 1 : 2;
}
-int VisualScriptOperator::get_output_value_port_count() const{
+int VisualScriptOperator::get_output_value_port_count() const {
return 1;
}
@@ -375,51 +352,51 @@ String VisualScriptOperator::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const {
- static const Variant::Type port_types[Variant::OP_MAX][2]={
- {Variant::NIL,Variant::NIL}, //OP_EQUAL,
- {Variant::NIL,Variant::NIL}, //OP_NOT_EQUAL,
- {Variant::NIL,Variant::NIL}, //OP_LESS,
- {Variant::NIL,Variant::NIL}, //OP_LESS_EQUAL,
- {Variant::NIL,Variant::NIL}, //OP_GREATER,
- {Variant::NIL,Variant::NIL}, //OP_GREATER_EQUAL,
+ static const Variant::Type port_types[Variant::OP_MAX][2] = {
+ { Variant::NIL, Variant::NIL }, //OP_EQUAL,
+ { Variant::NIL, Variant::NIL }, //OP_NOT_EQUAL,
+ { Variant::NIL, Variant::NIL }, //OP_LESS,
+ { Variant::NIL, Variant::NIL }, //OP_LESS_EQUAL,
+ { Variant::NIL, Variant::NIL }, //OP_GREATER,
+ { Variant::NIL, Variant::NIL }, //OP_GREATER_EQUAL,
//mathematic
- {Variant::NIL,Variant::NIL}, //OP_ADD,
- {Variant::NIL,Variant::NIL}, //OP_SUBSTRACT,
- {Variant::NIL,Variant::NIL}, //OP_MULTIPLY,
- {Variant::NIL,Variant::NIL}, //OP_DIVIDE,
- {Variant::NIL,Variant::NIL}, //OP_NEGATE,
- {Variant::NIL,Variant::NIL}, //OP_POSITIVE,
- {Variant::INT,Variant::INT}, //OP_MODULE,
- {Variant::STRING,Variant::STRING}, //OP_STRING_CONCAT,
+ { Variant::NIL, Variant::NIL }, //OP_ADD,
+ { Variant::NIL, Variant::NIL }, //OP_SUBSTRACT,
+ { Variant::NIL, Variant::NIL }, //OP_MULTIPLY,
+ { Variant::NIL, Variant::NIL }, //OP_DIVIDE,
+ { Variant::NIL, Variant::NIL }, //OP_NEGATE,
+ { Variant::NIL, Variant::NIL }, //OP_POSITIVE,
+ { Variant::INT, Variant::INT }, //OP_MODULE,
+ { Variant::STRING, Variant::STRING }, //OP_STRING_CONCAT,
//bitwise
- {Variant::INT,Variant::INT}, //OP_SHIFT_LEFT,
- {Variant::INT,Variant::INT}, //OP_SHIFT_RIGHT,
- {Variant::INT,Variant::INT}, //OP_BIT_AND,
- {Variant::INT,Variant::INT}, //OP_BIT_OR,
- {Variant::INT,Variant::INT}, //OP_BIT_XOR,
- {Variant::INT,Variant::INT}, //OP_BIT_NEGATE,
+ { Variant::INT, Variant::INT }, //OP_SHIFT_LEFT,
+ { Variant::INT, Variant::INT }, //OP_SHIFT_RIGHT,
+ { Variant::INT, Variant::INT }, //OP_BIT_AND,
+ { Variant::INT, Variant::INT }, //OP_BIT_OR,
+ { Variant::INT, Variant::INT }, //OP_BIT_XOR,
+ { Variant::INT, Variant::INT }, //OP_BIT_NEGATE,
//logic
- {Variant::BOOL,Variant::BOOL}, //OP_AND,
- {Variant::BOOL,Variant::BOOL}, //OP_OR,
- {Variant::BOOL,Variant::BOOL}, //OP_XOR,
- {Variant::BOOL,Variant::BOOL}, //OP_NOT,
+ { Variant::BOOL, Variant::BOOL }, //OP_AND,
+ { Variant::BOOL, Variant::BOOL }, //OP_OR,
+ { Variant::BOOL, Variant::BOOL }, //OP_XOR,
+ { Variant::BOOL, Variant::BOOL }, //OP_NOT,
//containment
- {Variant::NIL,Variant::NIL} //OP_IN,
+ { Variant::NIL, Variant::NIL } //OP_IN,
};
- ERR_FAIL_INDEX_V(p_idx,Variant::OP_MAX,PropertyInfo());
+ ERR_FAIL_INDEX_V(p_idx, Variant::OP_MAX, PropertyInfo());
PropertyInfo pinfo;
- pinfo.name=p_idx==0?"A":"B";
- pinfo.type=port_types[op][p_idx];
- if (pinfo.type==Variant::NIL)
- pinfo.type=typed;
+ pinfo.name = p_idx == 0 ? "A" : "B";
+ pinfo.type = port_types[op][p_idx];
+ if (pinfo.type == Variant::NIL)
+ pinfo.type = typed;
return pinfo;
}
-PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const{
- static const Variant::Type port_types[Variant::OP_MAX]={
+PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const {
+ static const Variant::Type port_types[Variant::OP_MAX] = {
//comparation
Variant::BOOL, //OP_EQUAL,
Variant::BOOL, //OP_NOT_EQUAL,
@@ -453,15 +430,14 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const{
};
PropertyInfo pinfo;
- pinfo.name="";
- pinfo.type=port_types[op];
- if (pinfo.type==Variant::NIL)
- pinfo.type=typed;
+ pinfo.name = "";
+ pinfo.type = port_types[op];
+ if (pinfo.type == Variant::NIL)
+ pinfo.type = typed;
return pinfo;
-
}
-static const char* op_names[]={
+static const char *op_names[] = {
//comparation
"Equal", //OP_EQUAL,
"NotEqual", //OP_NOT_EQUAL,
@@ -496,14 +472,12 @@ static const char* op_names[]={
String VisualScriptOperator::get_caption() const {
-
-
return op_names[op];
}
String VisualScriptOperator::get_text() const {
- static const wchar_t* op_names[]={
+ static const wchar_t *op_names[] = {
//comparation
L"A = B", //OP_EQUAL,
L"A \u2260 B", //OP_NOT_EQUAL,
@@ -539,24 +513,23 @@ String VisualScriptOperator::get_text() const {
void VisualScriptOperator::set_operator(Variant::Operator p_op) {
- if (op==p_op)
+ if (op == p_op)
return;
- op=p_op;
+ op = p_op;
ports_changed_notify();
-
}
-Variant::Operator VisualScriptOperator::get_operator() const{
+Variant::Operator VisualScriptOperator::get_operator() const {
return op;
}
void VisualScriptOperator::set_typed(Variant::Type p_op) {
- if (typed==p_op)
+ if (typed == p_op)
return;
- typed=p_op;
+ typed = p_op;
ports_changed_notify();
}
@@ -565,87 +538,80 @@ Variant::Type VisualScriptOperator::get_typed() const {
return typed;
}
-
void VisualScriptOperator::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator","op"),&VisualScriptOperator::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"),&VisualScriptOperator::get_operator);
+ ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualScriptOperator::set_operator);
+ ClassDB::bind_method(D_METHOD("get_operator"), &VisualScriptOperator::get_operator);
- ClassDB::bind_method(D_METHOD("set_typed","type"),&VisualScriptOperator::set_typed);
- ClassDB::bind_method(D_METHOD("get_typed"),&VisualScriptOperator::get_typed);
+ ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptOperator::set_typed);
+ ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptOperator::get_typed);
String types;
- for(int i=0;i<Variant::OP_MAX;i++) {
- if (i>0)
- types+=",";
- types+=op_names[i];
+ for (int i = 0; i < Variant::OP_MAX; i++) {
+ if (i > 0)
+ types += ",";
+ types += op_names[i];
}
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ 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,"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_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");
}
class VisualScriptNodeInstanceOperator : public VisualScriptNodeInstance {
public:
-
bool unary;
Variant::Operator op;
//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) {
+ 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 valid;
if (unary) {
- Variant::evaluate(op,*p_inputs[0],Variant(),*p_outputs[0],valid);
+ Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid);
} else {
- Variant::evaluate(op,*p_inputs[0],*p_inputs[1],*p_outputs[0],valid);
+ Variant::evaluate(op, *p_inputs[0], *p_inputs[1], *p_outputs[0], valid);
}
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- if (p_outputs[0]->get_type()==Variant::STRING) {
- r_error_str=*p_outputs[0];
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ if (p_outputs[0]->get_type() == Variant::STRING) {
+ r_error_str = *p_outputs[0];
} else {
if (unary)
- r_error_str=String(op_names[op])+RTR(": Invalid argument of type: ")+Variant::get_type_name(p_inputs[0]->get_type());
+ r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type());
else
- r_error_str=String(op_names[op])+RTR(": Invalid arguments: ")+"A: "+Variant::get_type_name(p_inputs[0]->get_type())+" B: "+Variant::get_type_name(p_inputs[1]->get_type());
+ r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type());
}
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptOperator::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceOperator * instance = memnew(VisualScriptNodeInstanceOperator );
- instance->unary=get_input_value_port_count()==1;
- instance->op=op;
+ VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator);
+ instance->unary = get_input_value_port_count() == 1;
+ instance->op = op;
return instance;
}
VisualScriptOperator::VisualScriptOperator() {
- op=Variant::OP_ADD;
- typed=Variant::NIL;
+ op = Variant::OP_ADD;
+ typed = Variant::NIL;
}
-
-
-template<Variant::Operator OP>
-static Ref<VisualScriptNode> create_op_node(const String& p_name) {
+template <Variant::Operator OP>
+static Ref<VisualScriptNode> create_op_node(const String &p_name) {
Ref<VisualScriptOperator> node;
node.instance();
@@ -662,16 +628,16 @@ int VisualScriptVariableGet::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptVariableGet::has_input_sequence_port() const{
+bool VisualScriptVariableGet::has_input_sequence_port() const {
return false;
}
-int VisualScriptVariableGet::get_input_value_port_count() const{
+int VisualScriptVariableGet::get_input_value_port_count() const {
return 0;
}
-int VisualScriptVariableGet::get_output_value_port_count() const{
+int VisualScriptVariableGet::get_output_value_port_count() const {
return 1;
}
@@ -681,25 +647,24 @@ String VisualScriptVariableGet::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="value";
+ pinfo.name = "value";
if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) {
PropertyInfo vinfo = get_visual_script()->get_variable_info(variable);
- pinfo.type=vinfo.type;
- pinfo.hint=vinfo.hint;
- pinfo.hint_string=vinfo.hint_string;
+ pinfo.type = vinfo.type;
+ pinfo.hint = vinfo.hint;
+ pinfo.hint_string = vinfo.hint_string;
}
return pinfo;
}
-
String VisualScriptVariableGet::get_caption() const {
return "Variable";
@@ -712,83 +677,73 @@ String VisualScriptVariableGet::get_text() const {
void VisualScriptVariableGet::set_variable(StringName p_variable) {
- if (variable==p_variable)
+ if (variable == p_variable)
return;
- variable=p_variable;
+ variable = p_variable;
ports_changed_notify();
-
}
-StringName VisualScriptVariableGet::get_variable() const{
+StringName VisualScriptVariableGet::get_variable() const {
return variable;
}
-void VisualScriptVariableGet::_validate_property(PropertyInfo& property) const {
+void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const {
- if (property.name=="variable/name" && get_visual_script().is_valid()) {
+ if (property.name == "variable/name" && get_visual_script().is_valid()) {
Ref<VisualScript> vs = get_visual_script();
List<StringName> vars;
vs->get_variable_list(&vars);
String vhint;
- for (List<StringName>::Element *E=vars.front();E;E=E->next()) {
- if (vhint!=String())
- vhint+=",";
+ for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
+ if (vhint != String())
+ vhint += ",";
- vhint+=E->get().operator String();
+ vhint += E->get().operator String();
}
- property.hint=PROPERTY_HINT_ENUM;
- property.hint_string=vhint;
+ property.hint = PROPERTY_HINT_ENUM;
+ property.hint_string = vhint;
}
}
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");
+ 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");
}
class VisualScriptNodeInstanceVariableGet : public VisualScriptNodeInstance {
public:
-
VisualScriptVariableGet *node;
VisualScriptInstance *instance;
StringName variable;
+ 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) {
- 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) {
-
- if (instance->get_variable(variable,p_outputs[0])==false) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("VariableGet not found in script: ")+"'"+String(variable)+"'";
+ if (instance->get_variable(variable, p_outputs[0]) == false) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("VariableGet not found in script: ") + "'" + String(variable) + "'";
return false;
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptVariableGet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceVariableGet * instance = memnew(VisualScriptNodeInstanceVariableGet );
- instance->node=this;
- instance->instance=p_instance;
- instance->variable=variable;
+ VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->variable = variable;
return instance;
}
VisualScriptVariableGet::VisualScriptVariableGet() {
-
-
}
-
//////////////////////////////////////////
////////////////VARIABLE SET//////////////////
//////////////////////////////////////////
@@ -798,16 +753,16 @@ int VisualScriptVariableSet::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptVariableSet::has_input_sequence_port() const{
+bool VisualScriptVariableSet::has_input_sequence_port() const {
return true;
}
-int VisualScriptVariableSet::get_input_value_port_count() const{
+int VisualScriptVariableSet::get_input_value_port_count() const {
return 1;
}
-int VisualScriptVariableSet::get_output_value_port_count() const{
+int VisualScriptVariableSet::get_output_value_port_count() const {
return 0;
}
@@ -817,25 +772,24 @@ String VisualScriptVariableSet::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="set";
+ pinfo.name = "set";
if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) {
PropertyInfo vinfo = get_visual_script()->get_variable_info(variable);
- pinfo.type=vinfo.type;
- pinfo.hint=vinfo.hint;
- pinfo.hint_string=vinfo.hint_string;
+ pinfo.type = vinfo.type;
+ pinfo.hint = vinfo.hint;
+ pinfo.hint_string = vinfo.hint_string;
}
return pinfo;
}
-PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptVariableSet::get_caption() const {
return "VariableSet";
@@ -848,87 +802,76 @@ String VisualScriptVariableSet::get_text() const {
void VisualScriptVariableSet::set_variable(StringName p_variable) {
- if (variable==p_variable)
+ if (variable == p_variable)
return;
- variable=p_variable;
+ variable = p_variable;
ports_changed_notify();
-
}
-StringName VisualScriptVariableSet::get_variable() const{
+StringName VisualScriptVariableSet::get_variable() const {
return variable;
}
-void VisualScriptVariableSet::_validate_property(PropertyInfo& property) const {
+void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const {
- if (property.name=="variable/name" && get_visual_script().is_valid()) {
+ if (property.name == "variable/name" && get_visual_script().is_valid()) {
Ref<VisualScript> vs = get_visual_script();
List<StringName> vars;
vs->get_variable_list(&vars);
String vhint;
- for (List<StringName>::Element *E=vars.front();E;E=E->next()) {
- if (vhint!=String())
- vhint+=",";
+ for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
+ if (vhint != String())
+ vhint += ",";
- vhint+=E->get().operator String();
+ vhint += E->get().operator String();
}
- property.hint=PROPERTY_HINT_ENUM;
- property.hint_string=vhint;
+ property.hint = PROPERTY_HINT_ENUM;
+ property.hint_string = vhint;
}
}
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");
+ 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");
}
class VisualScriptNodeInstanceVariableSet : public VisualScriptNodeInstance {
public:
-
VisualScriptVariableSet *node;
VisualScriptInstance *instance;
StringName variable;
//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) {
-
- if (instance->set_variable(variable,*p_inputs[0])==false) {
+ 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) {
+ if (instance->set_variable(variable, *p_inputs[0]) == false) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("VariableSet not found in script: ")+"'"+String(variable)+"'";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("VariableSet not found in script: ") + "'" + String(variable) + "'";
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptVariableSet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceVariableSet * instance = memnew(VisualScriptNodeInstanceVariableSet );
- instance->node=this;
- instance->instance=p_instance;
- instance->variable=variable;
+ VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->variable = variable;
return instance;
}
VisualScriptVariableSet::VisualScriptVariableSet() {
-
-
}
-
-
//////////////////////////////////////////
////////////////CONSTANT//////////////////
//////////////////////////////////////////
@@ -938,16 +881,16 @@ int VisualScriptConstant::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptConstant::has_input_sequence_port() const{
+bool VisualScriptConstant::has_input_sequence_port() const {
return false;
}
-int VisualScriptConstant::get_input_value_port_count() const{
+int VisualScriptConstant::get_input_value_port_count() const {
return 0;
}
-int VisualScriptConstant::get_output_value_port_count() const{
+int VisualScriptConstant::get_output_value_port_count() const {
return 1;
}
@@ -957,20 +900,19 @@ String VisualScriptConstant::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const {
PropertyInfo pinfo;
- pinfo.name="get";
- pinfo.type=type;
+ pinfo.name = "get";
+ pinfo.type = type;
return pinfo;
}
-
String VisualScriptConstant::get_caption() const {
return "Constant";
@@ -983,90 +925,82 @@ String VisualScriptConstant::get_text() const {
void VisualScriptConstant::set_constant_type(Variant::Type p_type) {
- if (type==p_type)
+ if (type == p_type)
return;
- type=p_type;
+ type = p_type;
ports_changed_notify();
Variant::CallError ce;
- value=Variant::construct(type,NULL,0,ce);
+ value = Variant::construct(type, NULL, 0, ce);
_change_notify();
-
}
-Variant::Type VisualScriptConstant::get_constant_type() const{
+Variant::Type VisualScriptConstant::get_constant_type() const {
return type;
}
-void VisualScriptConstant::set_constant_value(Variant p_value){
+void VisualScriptConstant::set_constant_value(Variant p_value) {
- if (value==p_value)
+ if (value == p_value)
return;
- value=p_value;
+ value = p_value;
ports_changed_notify();
}
-Variant VisualScriptConstant::get_constant_value() const{
+Variant VisualScriptConstant::get_constant_value() const {
return value;
}
-void VisualScriptConstant::_validate_property(PropertyInfo& property) const {
-
+void VisualScriptConstant::_validate_property(PropertyInfo &property) const {
- if (property.name=="constant/value") {
- property.type=type;
- if (type==Variant::NIL)
- property.usage=0; //do not save if nil
+ if (property.name == "constant/value") {
+ property.type = type;
+ if (type == Variant::NIL)
+ property.usage = 0; //do not save if nil
}
}
void VisualScriptConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant_type","type"),&VisualScriptConstant::set_constant_type);
- ClassDB::bind_method(D_METHOD("get_constant_type"),&VisualScriptConstant::get_constant_type);
+ ClassDB::bind_method(D_METHOD("set_constant_type", "type"), &VisualScriptConstant::set_constant_type);
+ ClassDB::bind_method(D_METHOD("get_constant_type"), &VisualScriptConstant::get_constant_type);
- ClassDB::bind_method(D_METHOD("set_constant_value","value"),&VisualScriptConstant::set_constant_value);
- ClassDB::bind_method(D_METHOD("get_constant_value"),&VisualScriptConstant::get_constant_value);
+ ClassDB::bind_method(D_METHOD("set_constant_value", "value"), &VisualScriptConstant::set_constant_value);
+ ClassDB::bind_method(D_METHOD("get_constant_value"), &VisualScriptConstant::get_constant_value);
- String argt="Null";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Null";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ 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, "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");
}
class VisualScriptNodeInstanceConstant : public VisualScriptNodeInstance {
public:
-
Variant constant;
//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) {
+ 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) {
- *p_outputs[0]=constant;
+ *p_outputs[0] = constant;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptConstant::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceConstant * instance = memnew(VisualScriptNodeInstanceConstant );
- instance->constant=value;
+ VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant);
+ instance->constant = value;
return instance;
}
VisualScriptConstant::VisualScriptConstant() {
- type=Variant::NIL;
-
+ type = Variant::NIL;
}
//////////////////////////////////////////
@@ -1078,16 +1012,16 @@ int VisualScriptPreload::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptPreload::has_input_sequence_port() const{
+bool VisualScriptPreload::has_input_sequence_port() const {
return false;
}
-int VisualScriptPreload::get_input_value_port_count() const{
+int VisualScriptPreload::get_input_value_port_count() const {
return 0;
}
-int VisualScriptPreload::get_output_value_port_count() const{
+int VisualScriptPreload::get_output_value_port_count() const {
return 1;
}
@@ -1097,23 +1031,22 @@ String VisualScriptPreload::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const {
- PropertyInfo pinfo=PropertyInfo(Variant::OBJECT,"res");
+ PropertyInfo pinfo = PropertyInfo(Variant::OBJECT, "res");
if (preload.is_valid()) {
- pinfo.hint=PROPERTY_HINT_RESOURCE_TYPE;
- pinfo.hint_string=preload->get_class();
+ pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pinfo.hint_string = preload->get_class();
}
return pinfo;
}
-
String VisualScriptPreload::get_caption() const {
return "Preload";
@@ -1124,7 +1057,7 @@ String VisualScriptPreload::get_text() const {
if (preload.is_valid()) {
if (preload->get_path().is_resource_file()) {
return preload->get_path();
- } else if (preload->get_name()!=String()) {
+ } else if (preload->get_name() != String()) {
return preload->get_name();
} else {
return preload->get_class();
@@ -1134,61 +1067,49 @@ String VisualScriptPreload::get_text() const {
}
}
+void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) {
-void VisualScriptPreload::set_preload(const Ref<Resource>& p_preload){
-
- if (preload==p_preload)
+ if (preload == p_preload)
return;
- preload=p_preload;
+ preload = p_preload;
ports_changed_notify();
}
-Ref<Resource> VisualScriptPreload::get_preload() const{
+Ref<Resource> VisualScriptPreload::get_preload() const {
return preload;
}
-
void VisualScriptPreload::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_preload", "resource"), &VisualScriptPreload::set_preload);
+ ClassDB::bind_method(D_METHOD("get_preload"), &VisualScriptPreload::get_preload);
- ClassDB::bind_method(D_METHOD("set_preload","resource"),&VisualScriptPreload::set_preload);
- ClassDB::bind_method(D_METHOD("get_preload"),&VisualScriptPreload::get_preload);
-
-
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"resource",PROPERTY_HINT_RESOURCE_TYPE,"Resource"),"set_preload","get_preload");
-
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), "set_preload", "get_preload");
}
class VisualScriptNodeInstancePreload : public VisualScriptNodeInstance {
public:
-
Ref<Resource> preload;
//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) {
+ 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) {
- *p_outputs[0]=preload;
+ *p_outputs[0] = preload;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptPreload::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstancePreload * instance = memnew(VisualScriptNodeInstancePreload );
- instance->preload=preload;
+ VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload);
+ instance->preload = preload;
return instance;
}
VisualScriptPreload::VisualScriptPreload() {
-
}
-
-
-
//////////////////////////////////////////
////////////////INDEX////////////////////
//////////////////////////////////////////
@@ -1198,16 +1119,16 @@ int VisualScriptIndexGet::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptIndexGet::has_input_sequence_port() const{
+bool VisualScriptIndexGet::has_input_sequence_port() const {
return false;
}
-int VisualScriptIndexGet::get_input_value_port_count() const{
+int VisualScriptIndexGet::get_input_value_port_count() const {
return 2;
}
-int VisualScriptIndexGet::get_output_value_port_count() const{
+int VisualScriptIndexGet::get_output_value_port_count() const {
return 1;
}
@@ -1217,22 +1138,20 @@ String VisualScriptIndexGet::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const {
- if (p_idx==0) {
- return PropertyInfo(Variant::NIL,"base");
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::NIL, "base");
} else {
- return PropertyInfo(Variant::NIL,"index");
-
+ return PropertyInfo(Variant::NIL, "index");
}
}
-PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptIndexGet::get_caption() const {
return "IndexGet";
@@ -1243,37 +1162,29 @@ String VisualScriptIndexGet::get_text() const {
return String("get");
}
-
class VisualScriptNodeInstanceIndexGet : 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) {
+ 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 valid;
- *p_outputs[0] = p_inputs[0]->get(*p_inputs[1],&valid);
+ *p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid get: "+p_inputs[0]->get_construct_string();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid get: " + p_inputs[0]->get_construct_string();
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptIndexGet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceIndexGet * instance = memnew(VisualScriptNodeInstanceIndexGet );
+ VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet);
return instance;
}
VisualScriptIndexGet::VisualScriptIndexGet() {
-
-
-
}
//////////////////////////////////////////
@@ -1285,16 +1196,16 @@ int VisualScriptIndexSet::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptIndexSet::has_input_sequence_port() const{
+bool VisualScriptIndexSet::has_input_sequence_port() const {
return true;
}
-int VisualScriptIndexSet::get_input_value_port_count() const{
+int VisualScriptIndexSet::get_input_value_port_count() const {
return 3;
}
-int VisualScriptIndexSet::get_output_value_port_count() const{
+int VisualScriptIndexSet::get_output_value_port_count() const {
return 0;
}
@@ -1304,25 +1215,23 @@ String VisualScriptIndexSet::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const {
- if (p_idx==0) {
- return PropertyInfo(Variant::NIL,"base");
- } else if (p_idx==1){
- return PropertyInfo(Variant::NIL,"index");
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::NIL, "base");
+ } else if (p_idx == 1) {
+ return PropertyInfo(Variant::NIL, "index");
} else {
- return PropertyInfo(Variant::NIL,"value");
-
+ return PropertyInfo(Variant::NIL, "value");
}
}
-PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptIndexSet::get_caption() const {
return "IndexSet";
@@ -1333,41 +1242,32 @@ String VisualScriptIndexSet::get_text() const {
return String("set");
}
-
class VisualScriptNodeInstanceIndexSet : 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) {
+ 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 valid;
- *p_outputs[0]=*p_inputs[0];
- p_outputs[0]->set(*p_inputs[1],*p_inputs[2],&valid);
+ *p_outputs[0] = *p_inputs[0];
+ p_outputs[0]->set(*p_inputs[1], *p_inputs[2], &valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid set: "+p_inputs[1]->get_construct_string();
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid set: " + p_inputs[1]->get_construct_string();
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptIndexSet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceIndexSet * instance = memnew(VisualScriptNodeInstanceIndexSet );
+ VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet);
return instance;
}
VisualScriptIndexSet::VisualScriptIndexSet() {
-
-
-
}
-
//////////////////////////////////////////
////////////////GLOBALCONSTANT///////////
//////////////////////////////////////////
@@ -1377,16 +1277,16 @@ int VisualScriptGlobalConstant::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptGlobalConstant::has_input_sequence_port() const{
+bool VisualScriptGlobalConstant::has_input_sequence_port() const {
return false;
}
-int VisualScriptGlobalConstant::get_input_value_port_count() const{
+int VisualScriptGlobalConstant::get_input_value_port_count() const {
return 0;
}
-int VisualScriptGlobalConstant::get_output_value_port_count() const{
+int VisualScriptGlobalConstant::get_output_value_port_count() const {
return 1;
}
@@ -1396,17 +1296,16 @@ String VisualScriptGlobalConstant::get_output_sequence_port_text(int p_port) con
return String();
}
-PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::REAL,"value");
+ return PropertyInfo(Variant::REAL, "value");
}
-
String VisualScriptGlobalConstant::get_caption() const {
return "GlobalConst";
@@ -1419,7 +1318,7 @@ String VisualScriptGlobalConstant::get_text() const {
void VisualScriptGlobalConstant::set_global_constant(int p_which) {
- index=p_which;
+ index = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1428,49 +1327,44 @@ int VisualScriptGlobalConstant::get_global_constant() {
return index;
}
-
class VisualScriptNodeInstanceGlobalConstant : public VisualScriptNodeInstance {
public:
-
int index;
//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) {
-
+ 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) {
*p_outputs[0] = GlobalConstants::get_global_constant_value(index);
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptGlobalConstant::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceGlobalConstant * instance = memnew(VisualScriptNodeInstanceGlobalConstant );
- instance->index=index;
+ VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant);
+ instance->index = index;
return instance;
}
void VisualScriptGlobalConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_global_constant","index"),&VisualScriptGlobalConstant::set_global_constant);
- ClassDB::bind_method(D_METHOD("get_global_constant"),&VisualScriptGlobalConstant::get_global_constant);
+ ClassDB::bind_method(D_METHOD("set_global_constant", "index"), &VisualScriptGlobalConstant::set_global_constant);
+ ClassDB::bind_method(D_METHOD("get_global_constant"), &VisualScriptGlobalConstant::get_global_constant);
String cc;
- for(int i=0;i<GlobalConstants::get_global_constant_count();i++) {
+ for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) {
- if (i>0)
- cc+=",";
- cc+=GlobalConstants::get_global_constant_name(i);
+ if (i > 0)
+ 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", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant");
}
VisualScriptGlobalConstant::VisualScriptGlobalConstant() {
- index=0;
+ index = 0;
}
//////////////////////////////////////////
@@ -1482,16 +1376,16 @@ int VisualScriptClassConstant::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptClassConstant::has_input_sequence_port() const{
+bool VisualScriptClassConstant::has_input_sequence_port() const {
return false;
}
-int VisualScriptClassConstant::get_input_value_port_count() const{
+int VisualScriptClassConstant::get_input_value_port_count() const {
return 0;
}
-int VisualScriptClassConstant::get_output_value_port_count() const{
+int VisualScriptClassConstant::get_output_value_port_count() const {
return 1;
}
@@ -1501,17 +1395,16 @@ String VisualScriptClassConstant::get_output_sequence_port_text(int p_port) cons
return String();
}
-PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::INT,"value");
+ return PropertyInfo(Variant::INT, "value");
}
-
String VisualScriptClassConstant::get_caption() const {
return "ClassConst";
@@ -1519,12 +1412,12 @@ String VisualScriptClassConstant::get_caption() const {
String VisualScriptClassConstant::get_text() const {
- return String(base_type)+"."+String(name);
+ return String(base_type) + "." + String(name);
}
-void VisualScriptClassConstant::set_class_constant(const StringName& p_which) {
+void VisualScriptClassConstant::set_class_constant(const StringName &p_which) {
- name=p_which;
+ name = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1533,10 +1426,9 @@ StringName VisualScriptClassConstant::get_class_constant() {
return name;
}
+void VisualScriptClassConstant::set_base_type(const StringName &p_which) {
-void VisualScriptClassConstant::set_base_type(const StringName& p_which) {
-
- base_type=p_which;
+ base_type = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1547,67 +1439,63 @@ StringName VisualScriptClassConstant::get_base_type() {
class VisualScriptNodeInstanceClassConstant : public VisualScriptNodeInstance {
public:
-
int value;
bool valid;
//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) {
+ 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) {
if (!valid) {
- r_error_str="Invalid constant name, pick a valid class constant.";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid constant name, pick a valid class constant.";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
}
*p_outputs[0] = value;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptClassConstant::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceClassConstant * instance = memnew(VisualScriptNodeInstanceClassConstant );
- instance->value=ClassDB::get_integer_constant(base_type,name,&instance->valid);
+ VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant);
+ instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid);
return instance;
}
-void VisualScriptClassConstant::_validate_property(PropertyInfo& property) const {
+void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const {
- if (property.name=="constant") {
+ if (property.name == "constant") {
List<String> constants;
- ClassDB::get_integer_constant_list(base_type,&constants,true);
+ ClassDB::get_integer_constant_list(base_type, &constants, true);
- property.hint_string="";
- for(List<String>::Element *E=constants.front();E;E=E->next()) {
- if (property.hint_string!=String()) {
- property.hint_string+=",";
+ property.hint_string = "";
+ for (List<String>::Element *E = constants.front(); E; E = E->next()) {
+ if (property.hint_string != String()) {
+ property.hint_string += ",";
}
- property.hint_string+=E->get();
+ property.hint_string += E->get();
}
}
}
void VisualScriptClassConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_class_constant","name"),&VisualScriptClassConstant::set_class_constant);
- ClassDB::bind_method(D_METHOD("get_class_constant"),&VisualScriptClassConstant::get_class_constant);
+ ClassDB::bind_method(D_METHOD("set_class_constant", "name"), &VisualScriptClassConstant::set_class_constant);
+ ClassDB::bind_method(D_METHOD("get_class_constant"), &VisualScriptClassConstant::get_class_constant);
- ClassDB::bind_method(D_METHOD("set_base_type","name"),&VisualScriptClassConstant::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptClassConstant::get_base_type);
+ ClassDB::bind_method(D_METHOD("set_base_type", "name"), &VisualScriptClassConstant::set_base_type);
+ 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, "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");
}
VisualScriptClassConstant::VisualScriptClassConstant() {
- base_type="Object";
+ base_type = "Object";
}
-
//////////////////////////////////////////
////////////////BASICTYPECONSTANT///////////
//////////////////////////////////////////
@@ -1617,16 +1505,16 @@ int VisualScriptBasicTypeConstant::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptBasicTypeConstant::has_input_sequence_port() const{
+bool VisualScriptBasicTypeConstant::has_input_sequence_port() const {
return false;
}
-int VisualScriptBasicTypeConstant::get_input_value_port_count() const{
+int VisualScriptBasicTypeConstant::get_input_value_port_count() const {
return 0;
}
-int VisualScriptBasicTypeConstant::get_output_value_port_count() const{
+int VisualScriptBasicTypeConstant::get_output_value_port_count() const {
return 1;
}
@@ -1636,17 +1524,16 @@ String VisualScriptBasicTypeConstant::get_output_sequence_port_text(int p_port)
return String();
}
-PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::INT,"value");
+ return PropertyInfo(Variant::INT, "value");
}
-
String VisualScriptBasicTypeConstant::get_caption() const {
return "BasicConst";
@@ -1654,12 +1541,12 @@ String VisualScriptBasicTypeConstant::get_caption() const {
String VisualScriptBasicTypeConstant::get_text() const {
- return Variant::get_type_name(type)+"."+String(name);
+ return Variant::get_type_name(type) + "." + String(name);
}
-void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName& p_which) {
+void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) {
- name=p_which;
+ name = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1668,10 +1555,9 @@ StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const {
return name;
}
-
void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) {
- type=p_which;
+ type = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1682,85 +1568,77 @@ Variant::Type VisualScriptBasicTypeConstant::get_basic_type() const {
class VisualScriptNodeInstanceBasicTypeConstant : public VisualScriptNodeInstance {
public:
-
int value;
bool valid;
//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) {
+ 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) {
if (!valid) {
- r_error_str="Invalid constant name, pick a valid basic type constant.";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Invalid constant name, pick a valid basic type constant.";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
}
*p_outputs[0] = value;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptBasicTypeConstant::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceBasicTypeConstant * instance = memnew(VisualScriptNodeInstanceBasicTypeConstant );
- instance->value=Variant::get_numeric_constant_value(type,name,&instance->valid);
+ VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant);
+ instance->value = Variant::get_numeric_constant_value(type, name, &instance->valid);
return instance;
}
-void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo& property) const {
+void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const {
- if (property.name=="constant") {
+ if (property.name == "constant") {
List<StringName> constants;
- Variant::get_numeric_constants_for_type(type,&constants);
+ Variant::get_numeric_constants_for_type(type, &constants);
- if (constants.size()==0) {
- property.usage=0;
+ if (constants.size() == 0) {
+ property.usage = 0;
return;
}
- property.hint_string="";
- for(List<StringName>::Element *E=constants.front();E;E=E->next()) {
- if (property.hint_string!=String()) {
- property.hint_string+=",";
+ property.hint_string = "";
+ for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
+ if (property.hint_string != String()) {
+ property.hint_string += ",";
}
- property.hint_string+=String(E->get());
+ property.hint_string += String(E->get());
}
-
}
}
void VisualScriptBasicTypeConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_basic_type","name"),&VisualScriptBasicTypeConstant::set_basic_type);
- ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptBasicTypeConstant::get_basic_type);
-
- ClassDB::bind_method(D_METHOD("set_basic_type_constant","name"),&VisualScriptBasicTypeConstant::set_basic_type_constant);
- ClassDB::bind_method(D_METHOD("get_basic_type_constant"),&VisualScriptBasicTypeConstant::get_basic_type_constant);
+ ClassDB::bind_method(D_METHOD("set_basic_type", "name"), &VisualScriptBasicTypeConstant::set_basic_type);
+ ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptBasicTypeConstant::get_basic_type);
+ ClassDB::bind_method(D_METHOD("set_basic_type_constant", "name"), &VisualScriptBasicTypeConstant::set_basic_type_constant);
+ ClassDB::bind_method(D_METHOD("get_basic_type_constant"), &VisualScriptBasicTypeConstant::get_basic_type_constant);
- String argt="Null";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Null";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ argt += "," + Variant::get_type_name(Variant::Type(i));
}
- 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::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");
}
VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() {
- type=Variant::NIL;
+ type = Variant::NIL;
}
-
-
//////////////////////////////////////////
////////////////MATHCONSTANT///////////
//////////////////////////////////////////
-
-const char* VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX]={
+const char *VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX] = {
"One",
"PI",
"PIx2",
@@ -1771,33 +1649,32 @@ const char* VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX]={
"NAN"
};
-double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={
+double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = {
1.0,
Math_PI,
- Math_PI*2,
- Math_PI*0.5,
+ Math_PI * 2,
+ Math_PI * 0.5,
2.71828182845904523536,
Math::sqrt(2.0),
Math_INF,
Math_NAN
};
-
int VisualScriptMathConstant::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptMathConstant::has_input_sequence_port() const{
+bool VisualScriptMathConstant::has_input_sequence_port() const {
return false;
}
-int VisualScriptMathConstant::get_input_value_port_count() const{
+int VisualScriptMathConstant::get_input_value_port_count() const {
return 0;
}
-int VisualScriptMathConstant::get_output_value_port_count() const{
+int VisualScriptMathConstant::get_output_value_port_count() const {
return 1;
}
@@ -1807,17 +1684,16 @@ String VisualScriptMathConstant::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::REAL,"value");
+ return PropertyInfo(Variant::REAL, "value");
}
-
String VisualScriptMathConstant::get_caption() const {
return "MathConst";
@@ -1830,7 +1706,7 @@ String VisualScriptMathConstant::get_text() const {
void VisualScriptMathConstant::set_math_constant(MathConstant p_which) {
- constant=p_which;
+ constant = p_which;
_change_notify();
ports_changed_notify();
}
@@ -1841,50 +1717,44 @@ VisualScriptMathConstant::MathConstant VisualScriptMathConstant::get_math_consta
class VisualScriptNodeInstanceMathConstant : public VisualScriptNodeInstance {
public:
-
float value;
//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) {
+ 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) {
- *p_outputs[0]=value;
+ *p_outputs[0] = value;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptMathConstant::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceMathConstant * instance = memnew(VisualScriptNodeInstanceMathConstant );
- instance->value=const_value[constant];
+ VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant);
+ instance->value = const_value[constant];
return instance;
}
-
void VisualScriptMathConstant::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_math_constant","which"),&VisualScriptMathConstant::set_math_constant);
- ClassDB::bind_method(D_METHOD("get_math_constant"),&VisualScriptMathConstant::get_math_constant);
+ ClassDB::bind_method(D_METHOD("set_math_constant", "which"), &VisualScriptMathConstant::set_math_constant);
+ ClassDB::bind_method(D_METHOD("get_math_constant"), &VisualScriptMathConstant::get_math_constant);
String cc;
- for(int i=0;i<MATH_CONSTANT_MAX;i++) {
+ for (int i = 0; i < MATH_CONSTANT_MAX; i++) {
- if (i>0)
- cc+=",";
- cc+=const_name[i];
+ if (i > 0)
+ 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", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant");
}
VisualScriptMathConstant::VisualScriptMathConstant() {
- constant=MATH_CONSTANT_ONE;
+ constant = MATH_CONSTANT_ONE;
}
-
-
//////////////////////////////////////////
////////////////GLOBALSINGLETON///////////
//////////////////////////////////////////
@@ -1894,16 +1764,16 @@ int VisualScriptEngineSingleton::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptEngineSingleton::has_input_sequence_port() const{
+bool VisualScriptEngineSingleton::has_input_sequence_port() const {
return false;
}
-int VisualScriptEngineSingleton::get_input_value_port_count() const{
+int VisualScriptEngineSingleton::get_input_value_port_count() const {
return 0;
}
-int VisualScriptEngineSingleton::get_output_value_port_count() const{
+int VisualScriptEngineSingleton::get_output_value_port_count() const {
return 1;
}
@@ -1913,17 +1783,16 @@ String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) co
return String();
}
-PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"instance");
+ return PropertyInfo(Variant::OBJECT, "instance");
}
-
String VisualScriptEngineSingleton::get_caption() const {
return "EngineSingleton";
@@ -1934,9 +1803,9 @@ String VisualScriptEngineSingleton::get_text() const {
return singleton;
}
-void VisualScriptEngineSingleton::set_singleton(const String& p_string) {
+void VisualScriptEngineSingleton::set_singleton(const String &p_string) {
- singleton=p_string;
+ singleton = p_string;
_change_notify();
ports_changed_notify();
@@ -1946,48 +1815,43 @@ String VisualScriptEngineSingleton::get_singleton() {
return singleton;
}
-
-
class VisualScriptNodeInstanceEngineSingleton : public VisualScriptNodeInstance {
public:
-
- Object* singleton;
+ Object *singleton;
//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) {
+ 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) {
- *p_outputs[0]=singleton;
+ *p_outputs[0] = singleton;
return 0;
}
-
};
-VisualScriptNodeInstance* VisualScriptEngineSingleton::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceEngineSingleton * instance = memnew(VisualScriptNodeInstanceEngineSingleton );
- instance->singleton=GlobalConfig::get_singleton()->get_singleton_object(singleton);
+ VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton);
+ instance->singleton = GlobalConfig::get_singleton()->get_singleton_object(singleton);
return instance;
}
-VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess* p_inputs, int p_output) const {
+VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const {
- Object *obj=GlobalConfig::get_singleton()->get_singleton_object(singleton);
+ Object *obj = GlobalConfig::get_singleton()->get_singleton_object(singleton);
TypeGuess tg;
- tg.type=Variant::OBJECT;
+ tg.type = Variant::OBJECT;
if (obj) {
- tg.GDCLASS=obj->get_class();
- tg.script=obj->get_script();
+ tg.GDCLASS = obj->get_class();
+ tg.script = obj->get_script();
}
return tg;
}
-
void VisualScriptEngineSingleton::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_singleton","name"),&VisualScriptEngineSingleton::set_singleton);
- ClassDB::bind_method(D_METHOD("get_singleton"),&VisualScriptEngineSingleton::get_singleton);
+ ClassDB::bind_method(D_METHOD("set_singleton", "name"), &VisualScriptEngineSingleton::set_singleton);
+ ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptEngineSingleton::get_singleton);
String cc;
@@ -1995,25 +1859,23 @@ void VisualScriptEngineSingleton::_bind_methods() {
GlobalConfig::get_singleton()->get_singletons(&singletons);
- for (List<GlobalConfig::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")
+ for (List<GlobalConfig::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
- if (cc!=String())
- cc+=",";
- cc+=E->get().name;
+ if (cc != String())
+ cc += ",";
+ cc += E->get().name;
}
- ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,cc),"set_singleton","get_singleton");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, cc), "set_singleton", "get_singleton");
}
VisualScriptEngineSingleton::VisualScriptEngineSingleton() {
- singleton=String();
+ singleton = String();
}
-
-
//////////////////////////////////////////
////////////////GETNODE///////////
//////////////////////////////////////////
@@ -2023,16 +1885,16 @@ int VisualScriptSceneNode::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptSceneNode::has_input_sequence_port() const{
+bool VisualScriptSceneNode::has_input_sequence_port() const {
return false;
}
-int VisualScriptSceneNode::get_input_value_port_count() const{
+int VisualScriptSceneNode::get_input_value_port_count() const {
return 0;
}
-int VisualScriptSceneNode::get_output_value_port_count() const{
+int VisualScriptSceneNode::get_output_value_port_count() const {
return 1;
}
@@ -2042,17 +1904,16 @@ String VisualScriptSceneNode::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"node");
+ return PropertyInfo(Variant::OBJECT, "node");
}
-
String VisualScriptSceneNode::get_caption() const {
return "SceneNode";
@@ -2063,9 +1924,9 @@ String VisualScriptSceneNode::get_text() const {
return path.simplified();
}
-void VisualScriptSceneNode::set_node_path(const NodePath& p_path) {
+void VisualScriptSceneNode::set_node_path(const NodePath &p_path) {
- path=p_path;
+ path = p_path;
_change_notify();
ports_changed_notify();
}
@@ -2074,68 +1935,59 @@ NodePath VisualScriptSceneNode::get_node_path() {
return path;
}
-
class VisualScriptNodeInstanceSceneNode : public VisualScriptNodeInstance {
public:
-
VisualScriptSceneNode *node;
VisualScriptInstance *instance;
NodePath path;
//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) {
+ 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) {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Base object is not a Node!";
return 0;
}
-
-
- Node* another = node->get_node(path);
+ Node *another = node->get_node(path);
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Path does not lead Node!";
return 0;
}
- *p_outputs[0]=another;
+ *p_outputs[0] = another;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSceneNode::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSceneNode * instance = memnew(VisualScriptNodeInstanceSceneNode );
- instance->node=this;
- instance->instance=p_instance;
- instance->path=path;
+ VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->path = path;
return instance;
}
-
-
-
#ifdef TOOLS_ENABLED
-static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) {
+static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
return NULL;
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr==script)
+ if (scr.is_valid() && scr == script)
return p_current_node;
- for(int i=0;i<p_current_node->get_child_count();i++) {
- Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script);
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
if (n)
return n;
}
@@ -2145,19 +1997,18 @@ static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const R
#endif
-VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess* p_inputs, int p_output) const {
-
+VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
VisualScriptSceneNode::TypeGuess tg;
- tg.type=Variant::OBJECT;
- tg.GDCLASS="Node";
+ tg.type = Variant::OBJECT;
+ tg.GDCLASS = "Node";
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
if (!script.is_valid())
return tg;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return tg;
@@ -2171,33 +2022,31 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu
if (!edited_scene)
return tg;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return tg;
- Node* another = script_node->get_node(path);
+ Node *another = script_node->get_node(path);
if (another) {
- tg.GDCLASS=another->get_class();
- tg.script=another->get_script();
+ tg.GDCLASS = another->get_class();
+ tg.script = another->get_script();
}
#endif
return tg;
-
}
-
-void VisualScriptSceneNode::_validate_property(PropertyInfo& property) const {
+void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const {
#ifdef TOOLS_ENABLED
- if (property.name=="node_path") {
+ if (property.name == "node_path") {
Ref<Script> script = get_visual_script();
if (!script.is_valid())
return;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return;
@@ -2211,30 +2060,29 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo& property) const {
if (!edited_scene)
return;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return;
- property.hint_string=script_node->get_path();
+ property.hint_string = script_node->get_path();
}
#endif
}
void VisualScriptSceneNode::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_node_path","path"),&VisualScriptSceneNode::set_node_path);
- ClassDB::bind_method(D_METHOD("get_node_path"),&VisualScriptSceneNode::get_node_path);
+ ClassDB::bind_method(D_METHOD("set_node_path", "path"), &VisualScriptSceneNode::set_node_path);
+ ClassDB::bind_method(D_METHOD("get_node_path"), &VisualScriptSceneNode::get_node_path);
- ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_node_path","get_node_path");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_node_path", "get_node_path");
}
VisualScriptSceneNode::VisualScriptSceneNode() {
- path=String(".");
+ path = String(".");
}
-
//////////////////////////////////////////
////////////////SceneTree///////////
//////////////////////////////////////////
@@ -2244,16 +2092,16 @@ int VisualScriptSceneTree::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptSceneTree::has_input_sequence_port() const{
+bool VisualScriptSceneTree::has_input_sequence_port() const {
return false;
}
-int VisualScriptSceneTree::get_input_value_port_count() const{
+int VisualScriptSceneTree::get_input_value_port_count() const {
return 0;
}
-int VisualScriptSceneTree::get_output_value_port_count() const{
+int VisualScriptSceneTree::get_output_value_port_count() const {
return 1;
}
@@ -2263,17 +2111,16 @@ String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"instance");
+ return PropertyInfo(Variant::OBJECT, "instance");
}
-
String VisualScriptSceneTree::get_caption() const {
return "SceneTree";
@@ -2284,68 +2131,60 @@ String VisualScriptSceneTree::get_text() const {
return "";
}
-
class VisualScriptNodeInstanceSceneTree : public VisualScriptNodeInstance {
public:
-
VisualScriptSceneTree *node;
VisualScriptInstance *instance;
//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) {
+ 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) {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Base object is not a Node!";
return 0;
}
- SceneTree* tree = node->get_tree();
+ SceneTree *tree = node->get_tree();
if (!tree) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Attempt to get SceneTree while node is not in the active tree.";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Attempt to get SceneTree while node is not in the active tree.";
return 0;
}
- *p_outputs[0]=tree;
+ *p_outputs[0] = tree;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSceneTree::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSceneTree * instance = memnew(VisualScriptNodeInstanceSceneTree );
- instance->node=this;
- instance->instance=p_instance;
+ VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree);
+ instance->node = this;
+ instance->instance = p_instance;
return instance;
}
-VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess* p_inputs, int p_output) const {
+VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const {
TypeGuess tg;
- tg.type=Variant::OBJECT;
- tg.GDCLASS="SceneTree";
+ tg.type = Variant::OBJECT;
+ tg.GDCLASS = "SceneTree";
return tg;
}
-void VisualScriptSceneTree::_validate_property(PropertyInfo& property) const {
-
+void VisualScriptSceneTree::_validate_property(PropertyInfo &property) const {
}
void VisualScriptSceneTree::_bind_methods() {
-
}
VisualScriptSceneTree::VisualScriptSceneTree() {
-
}
-
//////////////////////////////////////////
////////////////RESPATH///////////
//////////////////////////////////////////
@@ -2355,16 +2194,16 @@ int VisualScriptResourcePath::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptResourcePath::has_input_sequence_port() const{
+bool VisualScriptResourcePath::has_input_sequence_port() const {
return false;
}
-int VisualScriptResourcePath::get_input_value_port_count() const{
+int VisualScriptResourcePath::get_input_value_port_count() const {
return 0;
}
-int VisualScriptResourcePath::get_output_value_port_count() const{
+int VisualScriptResourcePath::get_output_value_port_count() const {
return 1;
}
@@ -2374,17 +2213,16 @@ String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::STRING,"path");
+ return PropertyInfo(Variant::STRING, "path");
}
-
String VisualScriptResourcePath::get_caption() const {
return "ResourcePath";
@@ -2395,9 +2233,9 @@ String VisualScriptResourcePath::get_text() const {
return path;
}
-void VisualScriptResourcePath::set_resource_path(const String& p_path) {
+void VisualScriptResourcePath::set_resource_path(const String &p_path) {
- path=p_path;
+ path = p_path;
_change_notify();
ports_changed_notify();
}
@@ -2406,47 +2244,39 @@ String VisualScriptResourcePath::get_resource_path() {
return path;
}
-
class VisualScriptNodeInstanceResourcePath : public VisualScriptNodeInstance {
public:
-
String path;
//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) {
+ 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) {
*p_outputs[0] = path;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptResourcePath::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceResourcePath * instance = memnew(VisualScriptNodeInstanceResourcePath );
- instance->path=path;
+ VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath);
+ instance->path = path;
return instance;
}
-
-
void VisualScriptResourcePath::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_resource_path","path"),&VisualScriptResourcePath::set_resource_path);
- ClassDB::bind_method(D_METHOD("get_resource_path"),&VisualScriptResourcePath::get_resource_path);
+ ClassDB::bind_method(D_METHOD("set_resource_path", "path"), &VisualScriptResourcePath::set_resource_path);
+ ClassDB::bind_method(D_METHOD("get_resource_path"), &VisualScriptResourcePath::get_resource_path);
- ADD_PROPERTY(PropertyInfo(Variant::STRING,"path",PROPERTY_HINT_FILE),"set_resource_path","get_resource_path");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), "set_resource_path", "get_resource_path");
}
VisualScriptResourcePath::VisualScriptResourcePath() {
- path="";
+ path = "";
}
-
-
//////////////////////////////////////////
////////////////SELF///////////
//////////////////////////////////////////
@@ -2456,16 +2286,16 @@ int VisualScriptSelf::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptSelf::has_input_sequence_port() const{
+bool VisualScriptSelf::has_input_sequence_port() const {
return false;
}
-int VisualScriptSelf::get_input_value_port_count() const{
+int VisualScriptSelf::get_input_value_port_count() const {
return 0;
}
-int VisualScriptSelf::get_output_value_port_count() const{
+int VisualScriptSelf::get_output_value_port_count() const {
return 1;
}
@@ -2475,17 +2305,16 @@ String VisualScriptSelf::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::OBJECT,"instance");
+ return PropertyInfo(Variant::OBJECT, "instance");
}
-
String VisualScriptSelf::get_caption() const {
return "Self";
@@ -2499,56 +2328,46 @@ String VisualScriptSelf::get_text() const {
return "";
}
-
class VisualScriptNodeInstanceSelf : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
//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) {
+ 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) {
*p_outputs[0] = instance->get_owner_ptr();
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSelf::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSelf * instance = memnew(VisualScriptNodeInstanceSelf );
- instance->instance=p_instance;
+ VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf);
+ instance->instance = p_instance;
return instance;
}
-VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess* p_inputs, int p_output) const {
+VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const {
VisualScriptSceneNode::TypeGuess tg;
- tg.type=Variant::OBJECT;
- tg.GDCLASS="Object";
+ tg.type = Variant::OBJECT;
+ tg.GDCLASS = "Object";
Ref<Script> script = get_visual_script();
if (!script.is_valid())
return tg;
- tg.GDCLASS=script->get_instance_base_type();
- tg.script=script;
+ tg.GDCLASS = script->get_instance_base_type();
+ tg.script = script;
return tg;
-
-
}
-
void VisualScriptSelf::_bind_methods() {
-
}
VisualScriptSelf::VisualScriptSelf() {
-
-
}
//////////////////////////////////////////
@@ -2563,7 +2382,7 @@ int VisualScriptCustomNode::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptCustomNode::has_input_sequence_port() const{
+bool VisualScriptCustomNode::has_input_sequence_port() const {
if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) {
return get_script_instance()->call("_has_input_sequence_port");
@@ -2571,14 +2390,14 @@ bool VisualScriptCustomNode::has_input_sequence_port() const{
return false;
}
-int VisualScriptCustomNode::get_input_value_port_count() const{
+int VisualScriptCustomNode::get_input_value_port_count() const {
if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) {
return get_script_instance()->call("_get_input_value_port_count");
}
return 0;
}
-int VisualScriptCustomNode::get_output_value_port_count() const{
+int VisualScriptCustomNode::get_output_value_port_count() const {
if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) {
return get_script_instance()->call("_get_output_value_port_count");
@@ -2589,37 +2408,36 @@ int VisualScriptCustomNode::get_output_value_port_count() const{
String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) {
- return get_script_instance()->call("_get_output_sequence_port_text",p_port);
+ return get_script_instance()->call("_get_output_sequence_port_text", p_port);
}
return String();
}
-PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const {
PropertyInfo info;
if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) {
- info.type=Variant::Type(int(get_script_instance()->call("_get_input_value_port_type",p_idx)));
+ info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx)));
}
if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_name")) {
- info.name=get_script_instance()->call("_get_input_value_port_name",p_idx);
+ info.name = get_script_instance()->call("_get_input_value_port_name", p_idx);
}
return info;
}
-PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const {
PropertyInfo info;
if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) {
- info.type=Variant::Type(int(get_script_instance()->call("_get_output_value_port_type",p_idx)));
+ info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx)));
}
if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_name")) {
- info.name=get_script_instance()->call("_get_output_value_port_name",p_idx);
+ info.name = get_script_instance()->call("_get_output_value_port_name", p_idx);
}
return info;
}
-
String VisualScriptCustomNode::get_caption() const {
if (get_script_instance() && get_script_instance()->has_method("_get_caption")) {
@@ -2646,21 +2464,20 @@ String VisualScriptCustomNode::get_category() const {
class VisualScriptNodeInstanceCustomNode : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
VisualScriptCustomNode *node;
int in_count;
int out_count;
int work_mem_size;
virtual int get_working_memory_size() const { return work_mem_size; }
- 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) {
+ 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) {
if (node->get_script_instance()) {
#ifdef DEBUG_ENABLED
if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) {
- r_error_str=RTR("Custom node has no _step() method, can't process graph.");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Custom node has no _step() method, can't process graph.");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
#endif
@@ -2670,111 +2487,102 @@ public:
in_values.resize(in_count);
- for(int i=0;i<in_count;i++) {
- in_values[i]=p_inputs[i];
+ for (int i = 0; i < in_count; i++) {
+ in_values[i] = p_inputs[i];
}
out_values.resize(in_count);
work_mem.resize(work_mem_size);
- for(int i=0;i<work_mem_size;i++) {
- work_mem[i]=p_working_mem[i];
+ for (int i = 0; i < work_mem_size; i++) {
+ work_mem[i] = p_working_mem[i];
}
int ret_out;
- Variant ret = node->get_script_instance()->call(VisualScriptLanguage::singleton->_step,in_values,out_values,p_start_mode,work_mem);
- if (ret.get_type()==Variant::STRING) {
- r_error_str=ret;
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ Variant ret = node->get_script_instance()->call(VisualScriptLanguage::singleton->_step, in_values, out_values, p_start_mode, work_mem);
+ if (ret.get_type() == Variant::STRING) {
+ r_error_str = ret;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
} else if (ret.is_num()) {
- ret_out=ret;
+ ret_out = ret;
} else {
- r_error_str=RTR("Invalid return value from _step(), must be integer (seq out), or string (error).");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = RTR("Invalid return value from _step(), must be integer (seq out), or string (error).");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
- for(int i=0;i<out_count;i++) {
- if (i<out_values.size()) {
- *p_outputs[i]=out_values[i];
+ for (int i = 0; i < out_count; i++) {
+ if (i < out_values.size()) {
+ *p_outputs[i] = out_values[i];
}
}
- for(int i=0;i<work_mem_size;i++) {
- if (i<work_mem.size()) {
- p_working_mem[i]=work_mem[i];
+ for (int i = 0; i < work_mem_size; i++) {
+ if (i < work_mem.size()) {
+ p_working_mem[i] = work_mem[i];
}
}
return ret_out;
-
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptCustomNode::instance(VisualScriptInstance* p_instance) {
-
- VisualScriptNodeInstanceCustomNode * instance = memnew(VisualScriptNodeInstanceCustomNode );
- instance->instance=p_instance;
- instance->in_count=get_input_value_port_count();
- instance->out_count=get_output_value_port_count();
+VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) {
+ VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode);
+ instance->instance = p_instance;
+ instance->in_count = get_input_value_port_count();
+ instance->out_count = get_output_value_port_count();
if (get_script_instance() && get_script_instance()->has_method("_get_working_memory_size")) {
instance->work_mem_size = get_script_instance()->call("_get_working_memory_size");
} else {
- instance->work_mem_size=0;
+ instance->work_mem_size = 0;
}
return instance;
}
-
-
void VisualScriptCustomNode::_bind_methods() {
- BIND_VMETHOD( MethodInfo(Variant::INT,"_get_output_sequence_port_count") );
- BIND_VMETHOD( MethodInfo(Variant::BOOL,"_has_input_sequence_port") );
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count"));
+ BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port"));
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_output_sequence_port_text",PropertyInfo(Variant::INT,"idx")) );
- BIND_VMETHOD( MethodInfo(Variant::INT,"_get_input_value_port_count") );
- BIND_VMETHOD( MethodInfo(Variant::INT,"_get_output_value_port_count") );
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_sequence_port_text", PropertyInfo(Variant::INT, "idx")));
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_count"));
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_count"));
- BIND_VMETHOD( MethodInfo(Variant::INT,"_get_input_value_port_type",PropertyInfo(Variant::INT,"idx")) );
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_input_value_port_name",PropertyInfo(Variant::INT,"idx")) );
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_type", PropertyInfo(Variant::INT, "idx")));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_name", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD( MethodInfo(Variant::INT,"_get_output_value_port_type",PropertyInfo(Variant::INT,"idx")) );
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_output_value_port_name",PropertyInfo(Variant::INT,"idx")) );
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_type", PropertyInfo(Variant::INT, "idx")));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_name", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_caption") );
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_text") );
- BIND_VMETHOD( MethodInfo(Variant::STRING,"_get_category") );
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_text"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category"));
- 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")) );
+ 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")));
- BIND_CONSTANT( START_MODE_BEGIN_SEQUENCE );
- BIND_CONSTANT( START_MODE_CONTINUE_SEQUENCE );
- BIND_CONSTANT( START_MODE_RESUME_YIELD );
-
- BIND_CONSTANT( STEP_PUSH_STACK_BIT );
- BIND_CONSTANT( STEP_GO_BACK_BIT );
- BIND_CONSTANT( STEP_NO_ADVANCE_BIT );
- BIND_CONSTANT( STEP_EXIT_FUNCTION_BIT );
- BIND_CONSTANT( STEP_YIELD_BIT );
+ BIND_CONSTANT(START_MODE_BEGIN_SEQUENCE);
+ BIND_CONSTANT(START_MODE_CONTINUE_SEQUENCE);
+ BIND_CONSTANT(START_MODE_RESUME_YIELD);
+ BIND_CONSTANT(STEP_PUSH_STACK_BIT);
+ BIND_CONSTANT(STEP_GO_BACK_BIT);
+ BIND_CONSTANT(STEP_NO_ADVANCE_BIT);
+ BIND_CONSTANT(STEP_EXIT_FUNCTION_BIT);
+ BIND_CONSTANT(STEP_YIELD_BIT);
}
VisualScriptCustomNode::VisualScriptCustomNode() {
-
-
}
//////////////////////////////////////////
@@ -2786,12 +2594,12 @@ int VisualScriptSubCall::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptSubCall::has_input_sequence_port() const{
+bool VisualScriptSubCall::has_input_sequence_port() const {
return true;
}
-int VisualScriptSubCall::get_input_value_port_count() const{
+int VisualScriptSubCall::get_input_value_port_count() const {
Ref<Script> script = get_script();
@@ -2803,7 +2611,7 @@ int VisualScriptSubCall::get_input_value_port_count() const{
return 0;
}
-int VisualScriptSubCall::get_output_value_port_count() const{
+int VisualScriptSubCall::get_output_value_port_count() const {
return 1;
}
@@ -2813,7 +2621,7 @@ String VisualScriptSubCall::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const {
Ref<Script> script = get_script();
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
@@ -2825,7 +2633,7 @@ PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const{
return PropertyInfo();
}
-PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const {
Ref<Script> script = get_script();
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
@@ -2835,18 +2643,16 @@ PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const{
return PropertyInfo();
}
-
String VisualScriptSubCall::get_caption() const {
return "SubCall";
}
-
String VisualScriptSubCall::get_text() const {
Ref<Script> script = get_script();
if (script.is_valid()) {
- if (script->get_name()!=String())
+ if (script->get_name() != String())
return script->get_name();
if (script->get_path().is_resource_file())
return script->get_path().get_file();
@@ -2862,53 +2668,45 @@ String VisualScriptSubCall::get_category() const {
class VisualScriptNodeInstanceSubCall : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
VisualScriptSubCall *subcall;
int input_args;
bool valid;
//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) {
+ 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) {
if (!valid) {
- r_error_str="Node requires a script with a _subcall(<args>) method to work.";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Node requires a script with a _subcall(<args>) method to work.";
+ 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_str);
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptSubCall::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceSubCall * instance = memnew(VisualScriptNodeInstanceSubCall );
- instance->instance=p_instance;
+ VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall);
+ instance->instance = p_instance;
Ref<Script> script = get_script();
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
- instance->valid=true;
- instance->input_args=get_input_value_port_count();
+ instance->valid = true;
+ instance->input_args = get_input_value_port_count();
} else {
- instance->valid=false;
+ instance->valid = false;
}
return instance;
}
-
-
void VisualScriptSubCall::_bind_methods() {
- BIND_VMETHOD( MethodInfo(Variant::NIL,"_subcall",PropertyInfo(Variant::NIL,"arguments:Variant")) );
-
+ BIND_VMETHOD(MethodInfo(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments:Variant")));
}
VisualScriptSubCall::VisualScriptSubCall() {
-
-
}
//////////////////////////////////////////
@@ -2920,15 +2718,15 @@ int VisualScriptComment::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptComment::has_input_sequence_port() const{
+bool VisualScriptComment::has_input_sequence_port() const {
return false;
}
-int VisualScriptComment::get_input_value_port_count() const{
+int VisualScriptComment::get_input_value_port_count() const {
return 0;
}
-int VisualScriptComment::get_output_value_port_count() const{
+int VisualScriptComment::get_output_value_port_count() const {
return 0;
}
@@ -2938,69 +2736,63 @@ String VisualScriptComment::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptComment::get_caption() const {
return title;
}
-
String VisualScriptComment::get_text() const {
return description;
}
-void VisualScriptComment::set_title(const String& p_title) {
-
+void VisualScriptComment::set_title(const String &p_title) {
- if (title==p_title)
+ if (title == p_title)
return;
- title=p_title;
+ title = p_title;
ports_changed_notify();
}
-String VisualScriptComment::get_title() const{
+String VisualScriptComment::get_title() const {
return title;
}
-void VisualScriptComment::set_description(const String& p_description){
+void VisualScriptComment::set_description(const String &p_description) {
- if (description==p_description)
+ if (description == p_description)
return;
- description=p_description;
+ description = p_description;
ports_changed_notify();
-
}
-String VisualScriptComment::get_description() const{
+String VisualScriptComment::get_description() const {
return description;
}
-void VisualScriptComment::set_size(const Size2& p_size){
+void VisualScriptComment::set_size(const Size2 &p_size) {
- if (size==p_size)
+ if (size == p_size)
return;
- size=p_size;
+ size = p_size;
ports_changed_notify();
-
}
-Size2 VisualScriptComment::get_size() const{
+Size2 VisualScriptComment::get_size() const {
return size;
}
-
String VisualScriptComment::get_category() const {
return "data";
@@ -3008,54 +2800,45 @@ String VisualScriptComment::get_category() const {
class VisualScriptNodeInstanceComment : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
//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) {
-
+ 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) {
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptComment::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceComment * instance = memnew(VisualScriptNodeInstanceComment );
- instance->instance=p_instance;
+ VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment);
+ instance->instance = p_instance;
return instance;
}
-
-
void VisualScriptComment::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_title", "title"), &VisualScriptComment::set_title);
+ ClassDB::bind_method(D_METHOD("get_title"), &VisualScriptComment::get_title);
- ClassDB::bind_method(D_METHOD("set_title","title"),&VisualScriptComment::set_title);
- ClassDB::bind_method(D_METHOD("get_title"),&VisualScriptComment::get_title);
+ ClassDB::bind_method(D_METHOD("set_description", "description"), &VisualScriptComment::set_description);
+ ClassDB::bind_method(D_METHOD("get_description"), &VisualScriptComment::get_description);
- ClassDB::bind_method(D_METHOD("set_description","description"),&VisualScriptComment::set_description);
- ClassDB::bind_method(D_METHOD("get_description"),&VisualScriptComment::get_description);
-
- ClassDB::bind_method(D_METHOD("set_size","size"),&VisualScriptComment::set_size);
- ClassDB::bind_method(D_METHOD("get_size"),&VisualScriptComment::get_size);
-
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),"set_title","get_title");
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"description",PROPERTY_HINT_MULTILINE_TEXT),"set_description","get_description");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"size"),"set_size","get_size");
+ ClassDB::bind_method(D_METHOD("set_size", "size"), &VisualScriptComment::set_size);
+ ClassDB::bind_method(D_METHOD("get_size"), &VisualScriptComment::get_size);
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "description", PROPERTY_HINT_MULTILINE_TEXT), "set_description", "get_description");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
}
VisualScriptComment::VisualScriptComment() {
- title="Comment";
- size=Size2(150,150);
+ title = "Comment";
+ size = Size2(150, 150);
}
-
//////////////////////////////////////////
////////////////Constructor///////////
//////////////////////////////////////////
@@ -3065,15 +2848,15 @@ int VisualScriptConstructor::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptConstructor::has_input_sequence_port() const{
+bool VisualScriptConstructor::has_input_sequence_port() const {
return false;
}
-int VisualScriptConstructor::get_input_value_port_count() const{
+int VisualScriptConstructor::get_input_value_port_count() const {
return constructor.arguments.size();
}
-int VisualScriptConstructor::get_output_value_port_count() const{
+int VisualScriptConstructor::get_output_value_port_count() const {
return 1;
}
@@ -3083,29 +2866,26 @@ String VisualScriptConstructor::get_output_sequence_port_text(int p_port) const
return "";
}
-PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const {
return constructor.arguments[p_idx];
}
-PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(type,"value");
+ return PropertyInfo(type, "value");
}
-
String VisualScriptConstructor::get_caption() const {
return "Construct";
}
-
String VisualScriptConstructor::get_text() const {
- return "new "+Variant::get_type_name(type)+"()";
+ return "new " + Variant::get_type_name(type) + "()";
}
-
String VisualScriptConstructor::get_category() const {
return "functions";
@@ -3113,10 +2893,10 @@ String VisualScriptConstructor::get_category() const {
void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) {
- if (type==p_type)
+ if (type == p_type)
return;
- type=p_type;
+ type = p_type;
ports_changed_notify();
}
@@ -3125,9 +2905,9 @@ Variant::Type VisualScriptConstructor::get_constructor_type() const {
return type;
}
-void VisualScriptConstructor::set_constructor(const Dictionary& p_info) {
+void VisualScriptConstructor::set_constructor(const Dictionary &p_info) {
- constructor=MethodInfo::from_dict(p_info);
+ constructor = MethodInfo::from_dict(p_info);
ports_changed_notify();
}
@@ -3136,65 +2916,57 @@ Dictionary VisualScriptConstructor::get_constructor() const {
return constructor;
}
-
class VisualScriptNodeInstanceConstructor : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
Variant::Type type;
int argcount;
//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) {
+ 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) {
Variant::CallError ce;
- *p_outputs[0]=Variant::construct(type,p_inputs,argcount,ce);
- if (ce.error!=Variant::CallError::CALL_OK) {
- r_error_str="Invalid arguments for constructor";
+ *p_outputs[0] = Variant::construct(type, p_inputs, argcount, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ r_error_str = "Invalid arguments for constructor";
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptConstructor::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceConstructor * instance = memnew(VisualScriptNodeInstanceConstructor );
- instance->instance=p_instance;
- instance->type=type;
- instance->argcount=constructor.arguments.size();
+ VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor);
+ instance->instance = p_instance;
+ instance->type = type;
+ instance->argcount = constructor.arguments.size();
return instance;
}
-
-
void VisualScriptConstructor::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constructor_type","type"),&VisualScriptConstructor::set_constructor_type);
- ClassDB::bind_method(D_METHOD("get_constructor_type"),&VisualScriptConstructor::get_constructor_type);
-
- ClassDB::bind_method(D_METHOD("set_constructor","constructor"),&VisualScriptConstructor::set_constructor);
- ClassDB::bind_method(D_METHOD("get_constructor"),&VisualScriptConstructor::get_constructor);
+ ClassDB::bind_method(D_METHOD("set_constructor_type", "type"), &VisualScriptConstructor::set_constructor_type);
+ ClassDB::bind_method(D_METHOD("get_constructor_type"), &VisualScriptConstructor::get_constructor_type);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"type",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_constructor_type","get_constructor_type");
- ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"constructor",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_constructor","get_constructor");
+ ClassDB::bind_method(D_METHOD("set_constructor", "constructor"), &VisualScriptConstructor::set_constructor);
+ ClassDB::bind_method(D_METHOD("get_constructor"), &VisualScriptConstructor::get_constructor);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_constructor_type", "get_constructor_type");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "constructor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_constructor", "get_constructor");
}
VisualScriptConstructor::VisualScriptConstructor() {
- type=Variant::NIL;
-
+ type = Variant::NIL;
}
-static Map<String,Pair<Variant::Type,MethodInfo> > constructor_map;
+static Map<String, Pair<Variant::Type, MethodInfo> > constructor_map;
-static Ref<VisualScriptNode> create_constructor_node(const String& p_name) {
+static Ref<VisualScriptNode> create_constructor_node(const String &p_name) {
- ERR_FAIL_COND_V(!constructor_map.has(p_name),Ref<VisualScriptNode>());
+ ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>());
Ref<VisualScriptConstructor> vsc;
vsc.instance();
@@ -3213,15 +2985,15 @@ int VisualScriptLocalVar::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptLocalVar::has_input_sequence_port() const{
+bool VisualScriptLocalVar::has_input_sequence_port() const {
return false;
}
-int VisualScriptLocalVar::get_input_value_port_count() const{
+int VisualScriptLocalVar::get_input_value_port_count() const {
return 0;
}
-int VisualScriptLocalVar::get_output_value_port_count() const{
+int VisualScriptLocalVar::get_output_value_port_count() const {
return 1;
}
@@ -3231,42 +3003,37 @@ String VisualScriptLocalVar::get_output_sequence_port_text(int p_port) const {
return "";
}
-PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(type,"get");
+ return PropertyInfo(type, "get");
}
-
String VisualScriptLocalVar::get_caption() const {
return "LocalVarGet";
}
-
String VisualScriptLocalVar::get_text() const {
return name;
}
-
String VisualScriptLocalVar::get_category() const {
return "data";
}
+void VisualScriptLocalVar::set_var_name(const StringName &p_name) {
-void VisualScriptLocalVar::set_var_name(const StringName& p_name) {
-
- if (name==p_name)
+ if (name == p_name)
return;
- name=p_name;
+ name = p_name;
ports_changed_notify();
-
}
StringName VisualScriptLocalVar::get_var_name() const {
@@ -3276,7 +3043,7 @@ StringName VisualScriptLocalVar::get_var_name() const {
void VisualScriptLocalVar::set_var_type(Variant::Type p_type) {
- type=p_type;
+ type = p_type;
ports_changed_notify();
}
@@ -3285,59 +3052,49 @@ Variant::Type VisualScriptLocalVar::get_var_type() const {
return type;
}
-
class VisualScriptNodeInstanceLocalVar : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
StringName name;
-
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) {
+ 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) {
- *p_outputs[0]=*p_working_mem;
+ *p_outputs[0] = *p_working_mem;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptLocalVar::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceLocalVar * instance = memnew(VisualScriptNodeInstanceLocalVar );
- instance->instance=p_instance;
- instance->name=name;
+ VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar);
+ instance->instance = p_instance;
+ instance->name = name;
return instance;
}
-
-
void VisualScriptLocalVar::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_var_name","name"),&VisualScriptLocalVar::set_var_name);
- ClassDB::bind_method(D_METHOD("get_var_name"),&VisualScriptLocalVar::get_var_name);
+ ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVar::set_var_name);
+ ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVar::get_var_name);
- ClassDB::bind_method(D_METHOD("set_var_type","type"),&VisualScriptLocalVar::set_var_type);
- ClassDB::bind_method(D_METHOD("get_var_type"),&VisualScriptLocalVar::get_var_type);
+ ClassDB::bind_method(D_METHOD("set_var_type", "type"), &VisualScriptLocalVar::set_var_type);
+ ClassDB::bind_method(D_METHOD("get_var_type"), &VisualScriptLocalVar::get_var_type);
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ 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, "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");
}
VisualScriptLocalVar::VisualScriptLocalVar() {
- name="new_local";
- type=Variant::NIL;
-
+ name = "new_local";
+ type = Variant::NIL;
}
//////////////////////////////////////////
@@ -3349,15 +3106,15 @@ int VisualScriptLocalVarSet::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptLocalVarSet::has_input_sequence_port() const{
+bool VisualScriptLocalVarSet::has_input_sequence_port() const {
return true;
}
-int VisualScriptLocalVarSet::get_input_value_port_count() const{
+int VisualScriptLocalVarSet::get_input_value_port_count() const {
return 1;
}
-int VisualScriptLocalVarSet::get_output_value_port_count() const{
+int VisualScriptLocalVarSet::get_output_value_port_count() const {
return 1;
}
@@ -3367,42 +3124,37 @@ String VisualScriptLocalVarSet::get_output_sequence_port_text(int p_port) const
return "";
}
-PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const {
- return PropertyInfo(type,"set");
+ return PropertyInfo(type, "set");
}
-PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(type,"get");
+ return PropertyInfo(type, "get");
}
-
String VisualScriptLocalVarSet::get_caption() const {
return "LocalVarSet";
}
-
String VisualScriptLocalVarSet::get_text() const {
return name;
}
-
String VisualScriptLocalVarSet::get_category() const {
return "data";
}
+void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) {
-void VisualScriptLocalVarSet::set_var_name(const StringName& p_name) {
-
- if (name==p_name)
+ if (name == p_name)
return;
- name=p_name;
+ name = p_name;
ports_changed_notify();
-
}
StringName VisualScriptLocalVarSet::get_var_name() const {
@@ -3412,7 +3164,7 @@ StringName VisualScriptLocalVarSet::get_var_name() const {
void VisualScriptLocalVarSet::set_var_type(Variant::Type p_type) {
- type=p_type;
+ type = p_type;
ports_changed_notify();
}
@@ -3421,63 +3173,52 @@ Variant::Type VisualScriptLocalVarSet::get_var_type() const {
return type;
}
-
class VisualScriptNodeInstanceLocalVarSet : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
StringName name;
-
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) {
+ 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) {
- *p_working_mem=*p_inputs[0];
- *p_outputs[0]=*p_working_mem;
+ *p_working_mem = *p_inputs[0];
+ *p_outputs[0] = *p_working_mem;
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptLocalVarSet::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceLocalVarSet * instance = memnew(VisualScriptNodeInstanceLocalVarSet );
- instance->instance=p_instance;
- instance->name=name;
+ VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet);
+ instance->instance = p_instance;
+ instance->name = name;
return instance;
}
-
-
void VisualScriptLocalVarSet::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_var_name","name"),&VisualScriptLocalVarSet::set_var_name);
- ClassDB::bind_method(D_METHOD("get_var_name"),&VisualScriptLocalVarSet::get_var_name);
+ ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVarSet::set_var_name);
+ ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVarSet::get_var_name);
- ClassDB::bind_method(D_METHOD("set_var_type","type"),&VisualScriptLocalVarSet::set_var_type);
- ClassDB::bind_method(D_METHOD("get_var_type"),&VisualScriptLocalVarSet::get_var_type);
+ ClassDB::bind_method(D_METHOD("set_var_type", "type"), &VisualScriptLocalVarSet::set_var_type);
+ ClassDB::bind_method(D_METHOD("get_var_type"), &VisualScriptLocalVarSet::get_var_type);
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ 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, "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");
}
VisualScriptLocalVarSet::VisualScriptLocalVarSet() {
- name="new_local";
- type=Variant::NIL;
-
+ name = "new_local";
+ type = Variant::NIL;
}
-
//////////////////////////////////////////
////////////////LocalVar///////////
//////////////////////////////////////////
@@ -3487,15 +3228,15 @@ int VisualScriptInputAction::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptInputAction::has_input_sequence_port() const{
+bool VisualScriptInputAction::has_input_sequence_port() const {
return false;
}
-int VisualScriptInputAction::get_input_value_port_count() const{
+int VisualScriptInputAction::get_input_value_port_count() const {
return 0;
}
-int VisualScriptInputAction::get_output_value_port_count() const{
+int VisualScriptInputAction::get_output_value_port_count() const {
return 1;
}
@@ -3505,58 +3246,52 @@ String VisualScriptInputAction::get_output_sequence_port_text(int p_port) const
return "";
}
-PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::BOOL,"pressed");
+ return PropertyInfo(Variant::BOOL, "pressed");
}
-
String VisualScriptInputAction::get_caption() const {
-
return "Action";
}
-
String VisualScriptInputAction::get_text() const {
- switch(mode) {
+ switch (mode) {
case MODE_PRESSED: {
return name;
} break;
case MODE_RELEASED: {
- return "not "+name;
+ return "not " + name;
} break;
case MODE_JUST_PRESSED: {
- return String(name)+" "+TTR("just pressed");
+ return String(name) + " " + TTR("just pressed");
} break;
case MODE_JUST_RELEASED: {
- return String(name)+" "+TTR("just released");
+ return String(name) + " " + TTR("just released");
} break;
}
return String();
}
-
String VisualScriptInputAction::get_category() const {
return "data";
}
+void VisualScriptInputAction::set_action_name(const StringName &p_name) {
-void VisualScriptInputAction::set_action_name(const StringName& p_name) {
-
- if (name==p_name)
+ if (name == p_name)
return;
- name=p_name;
+ name = p_name;
ports_changed_notify();
-
}
StringName VisualScriptInputAction::get_action_name() const {
@@ -3566,119 +3301,106 @@ StringName VisualScriptInputAction::get_action_name() const {
void VisualScriptInputAction::set_action_mode(Mode p_mode) {
- if (mode==p_mode)
+ if (mode == p_mode)
return;
- mode=p_mode;
+ mode = p_mode;
ports_changed_notify();
-
}
VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const {
return mode;
}
-
class VisualScriptNodeInstanceInputAction : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
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) {
+ 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) {
+ switch (mode) {
case VisualScriptInputAction::MODE_PRESSED: {
- *p_outputs[0]=Input::get_singleton()->is_action_pressed(action);
+ *p_outputs[0] = Input::get_singleton()->is_action_pressed(action);
} break;
case VisualScriptInputAction::MODE_RELEASED: {
- *p_outputs[0]=!Input::get_singleton()->is_action_pressed(action);
+ *p_outputs[0] = !Input::get_singleton()->is_action_pressed(action);
} break;
case VisualScriptInputAction::MODE_JUST_PRESSED: {
- *p_outputs[0]=Input::get_singleton()->is_action_just_pressed(action);
+ *p_outputs[0] = Input::get_singleton()->is_action_just_pressed(action);
} break;
- case VisualScriptInputAction:: MODE_JUST_RELEASED: {
- *p_outputs[0]=Input::get_singleton()->is_action_just_released(action);
+ case VisualScriptInputAction::MODE_JUST_RELEASED: {
+ *p_outputs[0] = Input::get_singleton()->is_action_just_released(action);
} break;
-
}
-
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptInputAction::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceInputAction * instance = memnew(VisualScriptNodeInstanceInputAction );
- instance->instance=p_instance;
- instance->action=name;
- instance->mode=mode;
+ VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction);
+ instance->instance = p_instance;
+ instance->action = name;
+ instance->mode = mode;
return instance;
}
-void VisualScriptInputAction::_validate_property(PropertyInfo& property) const {
+void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
+ if (property.name == "action") {
- if (property.name=="action") {
-
- property.hint=PROPERTY_HINT_ENUM;
+ property.hint = PROPERTY_HINT_ENUM;
String actions;
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
Vector<String> al;
- for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
- const PropertyInfo &pi=E->get();
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
- String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
-
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
al.push_back(name);
}
al.sort();
- for(int i=0;i<al.size();i++) {
- if (actions!=String())
- actions+=",";
- actions+=al[i];
+ for (int i = 0; i < al.size(); i++) {
+ if (actions != String())
+ actions += ",";
+ actions += al[i];
}
- property.hint_string=actions;
+ property.hint_string = actions;
}
}
-
void VisualScriptInputAction::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_action_name","name"),&VisualScriptInputAction::set_action_name);
- ClassDB::bind_method(D_METHOD("get_action_name"),&VisualScriptInputAction::get_action_name);
-
- ClassDB::bind_method(D_METHOD("set_action_mode","mode"),&VisualScriptInputAction::set_action_mode);
- ClassDB::bind_method(D_METHOD("get_action_mode"),&VisualScriptInputAction::get_action_mode);
+ ClassDB::bind_method(D_METHOD("set_action_name", "name"), &VisualScriptInputAction::set_action_name);
+ ClassDB::bind_method(D_METHOD("get_action_name"), &VisualScriptInputAction::get_action_name);
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),"set_action_name","get_action_name");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Pressed,Released,JustPressed,JustReleased"),"set_action_mode","get_action_mode");
+ ClassDB::bind_method(D_METHOD("set_action_mode", "mode"), &VisualScriptInputAction::set_action_mode);
+ ClassDB::bind_method(D_METHOD("get_action_mode"), &VisualScriptInputAction::get_action_mode);
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action_name", "get_action_name");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Pressed,Released,JustPressed,JustReleased"), "set_action_mode", "get_action_mode");
}
VisualScriptInputAction::VisualScriptInputAction() {
- name="";
- mode=MODE_PRESSED;
-
+ name = "";
+ mode = MODE_PRESSED;
}
//////////////////////////////////////////
@@ -3690,15 +3412,15 @@ int VisualScriptDeconstruct::get_output_sequence_port_count() const {
return 0;
}
-bool VisualScriptDeconstruct::has_input_sequence_port() const{
+bool VisualScriptDeconstruct::has_input_sequence_port() const {
return false;
}
-int VisualScriptDeconstruct::get_input_value_port_count() const{
+int VisualScriptDeconstruct::get_input_value_port_count() const {
return 1;
}
-int VisualScriptDeconstruct::get_output_value_port_count() const{
+int VisualScriptDeconstruct::get_output_value_port_count() const {
return elements.size();
}
@@ -3708,29 +3430,26 @@ String VisualScriptDeconstruct::get_output_sequence_port_text(int p_port) const
return "";
}
-PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const {
- return PropertyInfo(type,"value");
+ return PropertyInfo(type, "value");
}
-PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(elements[p_idx].type,elements[p_idx].name);
+ return PropertyInfo(elements[p_idx].type, elements[p_idx].name);
}
-
String VisualScriptDeconstruct::get_caption() const {
return "Deconstruct";
}
-
String VisualScriptDeconstruct::get_text() const {
- return "from "+Variant::get_type_name(type)+":";
+ return "from " + Variant::get_type_name(type) + ":";
}
-
String VisualScriptDeconstruct::get_category() const {
return "functions";
@@ -3740,33 +3459,33 @@ void VisualScriptDeconstruct::_update_elements() {
elements.clear();
Variant v;
- if (type==Variant::INPUT_EVENT) {
+ if (type == Variant::INPUT_EVENT) {
InputEvent ie;
- ie.type=input_type;
- v=ie;
+ ie.type = input_type;
+ v = ie;
} else {
Variant::CallError ce;
- v = Variant::construct(type,NULL,0,ce);
+ v = Variant::construct(type, NULL, 0, ce);
}
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
Element e;
- e.name=E->get().name;
- e.type=E->get().type;
+ e.name = E->get().name;
+ e.type = E->get().type;
elements.push_back(e);
}
}
void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) {
- if (type==p_type)
+ if (type == p_type)
return;
- type=p_type;
+ type = p_type;
_update_elements();
ports_changed_notify();
_change_notify(); //to make input appear/disappear
@@ -3779,10 +3498,10 @@ Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const {
void VisualScriptDeconstruct::set_deconstruct_input_type(InputEvent::Type p_input_type) {
- if (input_type==p_input_type)
+ if (input_type == p_input_type)
return;
- input_type=p_input_type;
+ input_type = p_input_type;
_update_elements();
ports_changed_notify();
}
@@ -3792,20 +3511,20 @@ InputEvent::Type VisualScriptDeconstruct::get_deconstruct_input_type() const {
return input_type;
}
-void VisualScriptDeconstruct::_set_elem_cache(const Array& p_elements) {
+void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) {
- ERR_FAIL_COND(p_elements.size()%2==1);
- elements.resize(p_elements.size()/2);
- for(int i=0;i<elements.size();i++) {
- elements[i].name=p_elements[i*2+0];
- elements[i].type=Variant::Type(int(p_elements[i*2+1]));
+ ERR_FAIL_COND(p_elements.size() % 2 == 1);
+ elements.resize(p_elements.size() / 2);
+ for (int i = 0; i < elements.size(); i++) {
+ elements[i].name = p_elements[i * 2 + 0];
+ elements[i].type = Variant::Type(int(p_elements[i * 2 + 1]));
}
}
Array VisualScriptDeconstruct::_get_elem_cache() const {
Array ret;
- for(int i=0;i<elements.size();i++) {
+ for (int i = 0; i < elements.size(); i++) {
ret.push_back(elements[i].name);
ret.push_back(elements[i].type);
}
@@ -3814,183 +3533,168 @@ Array VisualScriptDeconstruct::_get_elem_cache() const {
class VisualScriptNodeInstanceDeconstruct : public VisualScriptNodeInstance {
public:
-
- VisualScriptInstance* instance;
+ VisualScriptInstance *instance;
Vector<StringName> outputs;
//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) {
+ 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) {
- Variant in=*p_inputs[0];
+ Variant in = *p_inputs[0];
- for(int i=0;i<outputs.size();i++) {
+ for (int i = 0; i < outputs.size(); i++) {
bool valid;
- *p_outputs[i]=in.get(outputs[i],&valid);
+ *p_outputs[i] = in.get(outputs[i], &valid);
if (!valid) {
- r_error_str="Can't obtain element '"+String(outputs[i])+"' from "+Variant::get_type_name(in.get_type());
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Can't obtain element '" + String(outputs[i]) + "' from " + Variant::get_type_name(in.get_type());
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
-
}
return 0;
}
-
-
};
-VisualScriptNodeInstance* VisualScriptDeconstruct::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceDeconstruct * instance = memnew(VisualScriptNodeInstanceDeconstruct );
- instance->instance=p_instance;
+ VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct);
+ instance->instance = p_instance;
instance->outputs.resize(elements.size());
- for(int i=0;i<elements.size();i++) {
- instance->outputs[i]=elements[i].name;
+ for (int i = 0; i < elements.size(); i++) {
+ instance->outputs[i] = elements[i].name;
}
return instance;
}
+void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const {
-
-void VisualScriptDeconstruct::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="input_type") {
- if (type!=Variant::INPUT_EVENT) {
- property.usage=0;
+ if (property.name == "input_type") {
+ if (type != Variant::INPUT_EVENT) {
+ property.usage = 0;
}
}
}
-
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_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_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);
+ 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);
- String argt="Any";
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
- argt+=","+Variant::get_type_name(Variant::Type(i));
+ String argt = "Any";
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ 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");
+ 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;
-
+ type = Variant::NIL;
+ input_type = InputEvent::NONE;
}
-
void register_visual_script_nodes() {
- VisualScriptLanguage::singleton->add_register_func("data/set_variable",create_node_generic<VisualScriptVariableSet>);
- VisualScriptLanguage::singleton->add_register_func("data/get_variable",create_node_generic<VisualScriptVariableGet>);
- VisualScriptLanguage::singleton->add_register_func("data/engine_singleton",create_node_generic<VisualScriptEngineSingleton>);
- VisualScriptLanguage::singleton->add_register_func("data/scene_node",create_node_generic<VisualScriptSceneNode>);
- VisualScriptLanguage::singleton->add_register_func("data/scene_tree",create_node_generic<VisualScriptSceneTree>);
- VisualScriptLanguage::singleton->add_register_func("data/resource_path",create_node_generic<VisualScriptResourcePath>);
- VisualScriptLanguage::singleton->add_register_func("data/self",create_node_generic<VisualScriptSelf>);
- VisualScriptLanguage::singleton->add_register_func("data/comment",create_node_generic<VisualScriptComment>);
- VisualScriptLanguage::singleton->add_register_func("data/get_local_variable",create_node_generic<VisualScriptLocalVar>);
- VisualScriptLanguage::singleton->add_register_func("data/set_local_variable",create_node_generic<VisualScriptLocalVarSet>);
- 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("custom/custom_node",create_node_generic<VisualScriptCustomNode>);
- VisualScriptLanguage::singleton->add_register_func("custom/sub_call",create_node_generic<VisualScriptSubCall>);
-
- VisualScriptLanguage::singleton->add_register_func("index/get_index",create_node_generic<VisualScriptIndexGet>);
- VisualScriptLanguage::singleton->add_register_func("index/set_index",create_node_generic<VisualScriptIndexSet>);
-
-
- VisualScriptLanguage::singleton->add_register_func("operators/compare/equal",create_op_node<Variant::OP_EQUAL>);
- VisualScriptLanguage::singleton->add_register_func("operators/compare/not_equal",create_op_node<Variant::OP_NOT_EQUAL>);
- VisualScriptLanguage::singleton->add_register_func("operators/compare/less",create_op_node<Variant::OP_LESS>);
- VisualScriptLanguage::singleton->add_register_func("operators/compare/less_equal",create_op_node<Variant::OP_LESS_EQUAL>);
- VisualScriptLanguage::singleton->add_register_func("operators/compare/greater",create_op_node<Variant::OP_GREATER>);
- VisualScriptLanguage::singleton->add_register_func("operators/compare/greater_equal",create_op_node<Variant::OP_GREATER_EQUAL>);
+ VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic<VisualScriptVariableSet>);
+ VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic<VisualScriptVariableGet>);
+ VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic<VisualScriptEngineSingleton>);
+ VisualScriptLanguage::singleton->add_register_func("data/scene_node", create_node_generic<VisualScriptSceneNode>);
+ VisualScriptLanguage::singleton->add_register_func("data/scene_tree", create_node_generic<VisualScriptSceneTree>);
+ VisualScriptLanguage::singleton->add_register_func("data/resource_path", create_node_generic<VisualScriptResourcePath>);
+ VisualScriptLanguage::singleton->add_register_func("data/self", create_node_generic<VisualScriptSelf>);
+ VisualScriptLanguage::singleton->add_register_func("data/comment", create_node_generic<VisualScriptComment>);
+ VisualScriptLanguage::singleton->add_register_func("data/get_local_variable", create_node_generic<VisualScriptLocalVar>);
+ VisualScriptLanguage::singleton->add_register_func("data/set_local_variable", create_node_generic<VisualScriptLocalVarSet>);
+ 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("custom/custom_node", create_node_generic<VisualScriptCustomNode>);
+ VisualScriptLanguage::singleton->add_register_func("custom/sub_call", create_node_generic<VisualScriptSubCall>);
+
+ VisualScriptLanguage::singleton->add_register_func("index/get_index", create_node_generic<VisualScriptIndexGet>);
+ VisualScriptLanguage::singleton->add_register_func("index/set_index", create_node_generic<VisualScriptIndexSet>);
+
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/equal", create_op_node<Variant::OP_EQUAL>);
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/not_equal", create_op_node<Variant::OP_NOT_EQUAL>);
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/less", create_op_node<Variant::OP_LESS>);
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/less_equal", create_op_node<Variant::OP_LESS_EQUAL>);
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/greater", create_op_node<Variant::OP_GREATER>);
+ VisualScriptLanguage::singleton->add_register_func("operators/compare/greater_equal", create_op_node<Variant::OP_GREATER_EQUAL>);
//mathematic
- VisualScriptLanguage::singleton->add_register_func("operators/math/add",create_op_node<Variant::OP_ADD>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/subtract",create_op_node<Variant::OP_SUBSTRACT>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/multiply",create_op_node<Variant::OP_MULTIPLY>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/divide",create_op_node<Variant::OP_DIVIDE>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/negate",create_op_node<Variant::OP_NEGATE>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/positive",create_op_node<Variant::OP_POSITIVE>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/remainder",create_op_node<Variant::OP_MODULE>);
- VisualScriptLanguage::singleton->add_register_func("operators/math/string_concat",create_op_node<Variant::OP_STRING_CONCAT>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/add", create_op_node<Variant::OP_ADD>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/subtract", create_op_node<Variant::OP_SUBSTRACT>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/multiply", create_op_node<Variant::OP_MULTIPLY>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/divide", create_op_node<Variant::OP_DIVIDE>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/negate", create_op_node<Variant::OP_NEGATE>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/positive", create_op_node<Variant::OP_POSITIVE>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/remainder", create_op_node<Variant::OP_MODULE>);
+ VisualScriptLanguage::singleton->add_register_func("operators/math/string_concat", create_op_node<Variant::OP_STRING_CONCAT>);
//bitwise
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_left",create_op_node<Variant::OP_SHIFT_LEFT>);
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_right",create_op_node<Variant::OP_SHIFT_RIGHT>);
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_and",create_op_node<Variant::OP_BIT_AND>);
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_or",create_op_node<Variant::OP_BIT_OR>);
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_xor",create_op_node<Variant::OP_BIT_XOR>);
- VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_negate",create_op_node<Variant::OP_BIT_NEGATE>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_left", create_op_node<Variant::OP_SHIFT_LEFT>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_right", create_op_node<Variant::OP_SHIFT_RIGHT>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_and", create_op_node<Variant::OP_BIT_AND>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_or", create_op_node<Variant::OP_BIT_OR>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_xor", create_op_node<Variant::OP_BIT_XOR>);
+ VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_negate", create_op_node<Variant::OP_BIT_NEGATE>);
//logic
- VisualScriptLanguage::singleton->add_register_func("operators/logic/and",create_op_node<Variant::OP_AND>);
- VisualScriptLanguage::singleton->add_register_func("operators/logic/or",create_op_node<Variant::OP_OR>);
- 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/and", create_op_node<Variant::OP_AND>);
+ VisualScriptLanguage::singleton->add_register_func("operators/logic/or", create_op_node<Variant::OP_OR>);
+ 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("functions/deconstruct",create_node_generic<VisualScriptDeconstruct>);
+ VisualScriptLanguage::singleton->add_register_func("functions/deconstruct", create_node_generic<VisualScriptDeconstruct>);
- for(int i=1;i<Variant::VARIANT_MAX;i++) {
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
List<MethodInfo> constructors;
- Variant::get_constructor_list(Variant::Type(i),&constructors);
+ Variant::get_constructor_list(Variant::Type(i), &constructors);
- for(List<MethodInfo>::Element *E=constructors.front();E;E=E->next()) {
+ for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) {
- if (E->get().arguments.size()>0) {
+ if (E->get().arguments.size() > 0) {
-
- String name = "functions/constructors/"+Variant::get_type_name(Variant::Type(i))+" ( ";
- for(int j=0;j<E->get().arguments.size();j++) {
- if (j>0)
- name+=", ";
- if (E->get().arguments.size()==1)
- name+=Variant::get_type_name(E->get().arguments[j].type);
+ String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + " ( ";
+ for (int j = 0; j < E->get().arguments.size(); j++) {
+ if (j > 0)
+ name += ", ";
+ if (E->get().arguments.size() == 1)
+ name += Variant::get_type_name(E->get().arguments[j].type);
else
- name+=E->get().arguments[j].name;
+ name += E->get().arguments[j].name;
}
- name+=") ";
+ name += ") ";
- VisualScriptLanguage::singleton->add_register_func(name,create_constructor_node);
- Pair<Variant::Type,MethodInfo> pair;
- pair.first=Variant::Type(i);
- pair.second=E->get();
- constructor_map[name]=pair;
+ VisualScriptLanguage::singleton->add_register_func(name, create_constructor_node);
+ Pair<Variant::Type, MethodInfo> pair;
+ pair.first = Variant::Type(i);
+ pair.second = E->get();
+ constructor_map[name] = pair;
}
}
}
}
-
-
void unregister_visual_script_nodes() {
constructor_map.clear();
}
-
diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h
index 2e7fb0536c..b2fc115660 100644
--- a/modules/visual_script/visual_script_nodes.h
+++ b/modules/visual_script/visual_script_nodes.h
@@ -33,8 +33,7 @@
class VisualScriptFunction : public VisualScriptNode {
- GDCLASS(VisualScriptFunction,VisualScriptNode)
-
+ GDCLASS(VisualScriptFunction, VisualScriptNode)
struct Argument {
String name;
@@ -47,26 +46,20 @@ class VisualScriptFunction : public VisualScriptNode {
int stack_size;
ScriptInstance::RPCMode rpc_mode;
-
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;
+ 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:
-
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;
@@ -74,15 +67,14 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "flow_control"; }
- void add_argument(Variant::Type p_type,const String& p_name,int p_index=-1);
- void set_argument_type(int p_argidx,Variant::Type p_type);
+ void add_argument(Variant::Type p_type, const String &p_name, int p_index = -1);
+ void set_argument_type(int p_argidx, Variant::Type p_type);
Variant::Type get_argument_type(int p_argidx) const;
- void set_argument_name(int p_argidx,const String& p_name);
+ void set_argument_name(int p_argidx, const String &p_name);
String get_argument_name(int p_argidx) const;
void remove_argument(int p_argidx);
int get_argument_count() const;
-
void set_stack_less(bool p_enable);
bool is_stack_less() const;
@@ -92,35 +84,30 @@ public:
void set_rpc_mode(ScriptInstance::RPCMode p_mode);
ScriptInstance::RPCMode get_rpc_mode() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptFunction();
};
-
class VisualScriptOperator : public VisualScriptNode {
- GDCLASS(VisualScriptOperator,VisualScriptNode)
-
+ GDCLASS(VisualScriptOperator, VisualScriptNode)
Variant::Type typed;
Variant::Operator op;
-protected:
+protected:
static void _bind_methods();
-public:
+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;
@@ -134,35 +121,30 @@ public:
void set_typed(Variant::Type p_op);
Variant::Type get_typed() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptOperator();
};
-
class VisualScriptVariableGet : public VisualScriptNode {
- GDCLASS(VisualScriptVariableGet,VisualScriptNode)
-
+ GDCLASS(VisualScriptVariableGet, VisualScriptNode)
StringName variable;
-protected:
- virtual void _validate_property(PropertyInfo& property) const;
+protected:
+ virtual void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+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;
@@ -173,35 +155,30 @@ public:
void set_variable(StringName p_var);
StringName get_variable() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptVariableGet();
};
-
class VisualScriptVariableSet : public VisualScriptNode {
- GDCLASS(VisualScriptVariableSet,VisualScriptNode)
-
+ GDCLASS(VisualScriptVariableSet, VisualScriptNode)
StringName variable;
-protected:
- virtual void _validate_property(PropertyInfo& property) const;
+protected:
+ virtual void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+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;
@@ -212,36 +189,31 @@ public:
void set_variable(StringName p_var);
StringName get_variable() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptVariableSet();
};
-
class VisualScriptConstant : public VisualScriptNode {
- GDCLASS(VisualScriptConstant,VisualScriptNode)
-
+ GDCLASS(VisualScriptConstant, VisualScriptNode)
Variant::Type type;
Variant value;
+
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -255,36 +227,29 @@ public:
void set_constant_value(Variant p_value);
Variant get_constant_value() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptConstant();
};
-
-
class VisualScriptPreload : public VisualScriptNode {
- GDCLASS(VisualScriptPreload,VisualScriptNode)
-
+ GDCLASS(VisualScriptPreload, VisualScriptNode)
Ref<Resource> preload;
-protected:
+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;
@@ -292,32 +257,27 @@ 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_value);
Ref<Resource> get_preload() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptPreload();
};
class VisualScriptIndexGet : public VisualScriptNode {
- GDCLASS(VisualScriptIndexGet,VisualScriptNode)
-
+ GDCLASS(VisualScriptIndexGet, VisualScriptNode)
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;
@@ -325,30 +285,24 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "operators"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptIndexGet();
};
-
class VisualScriptIndexSet : public VisualScriptNode {
- GDCLASS(VisualScriptIndexSet,VisualScriptNode)
-
+ GDCLASS(VisualScriptIndexSet, VisualScriptNode)
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;
@@ -356,33 +310,28 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "operators"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptIndexSet();
};
-
-
class VisualScriptGlobalConstant : public VisualScriptNode {
- GDCLASS(VisualScriptGlobalConstant,VisualScriptNode)
+ GDCLASS(VisualScriptGlobalConstant, VisualScriptNode)
int index;
static void _bind_methods();
-public:
+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;
@@ -393,35 +342,31 @@ public:
void set_global_constant(int p_which);
int get_global_constant();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptGlobalConstant();
};
-
class VisualScriptClassConstant : public VisualScriptNode {
- GDCLASS(VisualScriptClassConstant,VisualScriptNode)
+ GDCLASS(VisualScriptClassConstant, VisualScriptNode)
StringName base_type;
StringName name;
+
protected:
static void _bind_methods();
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -429,40 +374,37 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "constants"; }
- void set_class_constant(const StringName& p_which);
+ void set_class_constant(const StringName &p_which);
StringName get_class_constant();
- void set_base_type(const StringName& p_which);
+ void set_base_type(const StringName &p_which);
StringName get_base_type();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptClassConstant();
};
class VisualScriptBasicTypeConstant : public VisualScriptNode {
- GDCLASS(VisualScriptBasicTypeConstant,VisualScriptNode)
+ GDCLASS(VisualScriptBasicTypeConstant, VisualScriptNode)
Variant::Type type;
StringName name;
+
protected:
static void _bind_methods();
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -470,24 +412,21 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "constants"; }
- void set_basic_type_constant(const StringName& p_which);
+ void set_basic_type_constant(const StringName &p_which);
StringName get_basic_type_constant() const;
void set_basic_type(Variant::Type p_which);
Variant::Type get_basic_type() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptBasicTypeConstant();
};
-
-
class VisualScriptMathConstant : public VisualScriptNode {
- GDCLASS(VisualScriptMathConstant,VisualScriptNode)
+ GDCLASS(VisualScriptMathConstant, VisualScriptNode)
public:
-
enum MathConstant {
MATH_CONSTANT_ONE,
MATH_CONSTANT_PI,
@@ -501,24 +440,22 @@ public:
};
private:
- static const char* const_name[MATH_CONSTANT_MAX];
+ static const char *const_name[MATH_CONSTANT_MAX];
static double const_value[MATH_CONSTANT_MAX];
MathConstant constant;
+
protected:
static void _bind_methods();
-public:
+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;
@@ -529,33 +466,30 @@ public:
void set_math_constant(MathConstant p_which);
MathConstant get_math_constant();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptMathConstant();
};
-VARIANT_ENUM_CAST( VisualScriptMathConstant::MathConstant )
+VARIANT_ENUM_CAST(VisualScriptMathConstant::MathConstant)
class VisualScriptEngineSingleton : public VisualScriptNode {
- GDCLASS(VisualScriptEngineSingleton,VisualScriptNode)
+ GDCLASS(VisualScriptEngineSingleton, VisualScriptNode)
String singleton;
static void _bind_methods();
-public:
+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;
@@ -566,38 +500,32 @@ public:
void set_singleton(const String &p_string);
String get_singleton();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptEngineSingleton();
};
-
-
-
class VisualScriptSceneNode : public VisualScriptNode {
- GDCLASS(VisualScriptSceneNode,VisualScriptNode)
+ GDCLASS(VisualScriptSceneNode, VisualScriptNode)
NodePath path;
+
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+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;
@@ -608,37 +536,30 @@ public:
void set_node_path(const NodePath &p_path);
NodePath get_node_path();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptSceneNode();
};
-
-
-
class VisualScriptSceneTree : public VisualScriptNode {
- GDCLASS(VisualScriptSceneTree,VisualScriptNode)
-
+ GDCLASS(VisualScriptSceneTree, VisualScriptNode)
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+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;
@@ -646,36 +567,31 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "data"; }
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptSceneTree();
};
-
-
class VisualScriptResourcePath : public VisualScriptNode {
- GDCLASS(VisualScriptResourcePath,VisualScriptNode)
+ GDCLASS(VisualScriptResourcePath, VisualScriptNode)
String path;
-protected:
+protected:
static void _bind_methods();
-public:
+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;
@@ -686,33 +602,27 @@ public:
void set_resource_path(const String &p_path);
String get_resource_path();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptResourcePath();
};
-
class VisualScriptSelf : public VisualScriptNode {
- GDCLASS(VisualScriptSelf,VisualScriptNode)
-
+ GDCLASS(VisualScriptSelf, VisualScriptNode)
protected:
-
static void _bind_methods();
-public:
+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;
@@ -720,25 +630,21 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "data"; }
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
-
- virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const;
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
VisualScriptSelf();
};
+class VisualScriptCustomNode : public VisualScriptNode {
-class VisualScriptCustomNode: public VisualScriptNode {
-
- GDCLASS(VisualScriptCustomNode,VisualScriptNode)
-
+ GDCLASS(VisualScriptCustomNode, VisualScriptNode)
protected:
-
static void _bind_methods();
-public:
+public:
enum StartMode { //replicated for step
START_MODE_BEGIN_SEQUENCE,
START_MODE_CONTINUE_SEQUENCE,
@@ -746,26 +652,23 @@ public:
};
enum { //replicated for step
- STEP_SHIFT=1<<24,
- STEP_MASK=STEP_SHIFT-1,
- STEP_PUSH_STACK_BIT=STEP_SHIFT, //push bit to stack
- STEP_GO_BACK_BIT=STEP_SHIFT<<1, //go back to previous node
- STEP_NO_ADVANCE_BIT=STEP_SHIFT<<2, //do not advance past this node
- STEP_EXIT_FUNCTION_BIT=STEP_SHIFT<<3, //return from function
- STEP_YIELD_BIT=STEP_SHIFT<<4, //yield (will find VisualScriptFunctionState state in first working memory)
+ STEP_SHIFT = 1 << 24,
+ STEP_MASK = STEP_SHIFT - 1,
+ STEP_PUSH_STACK_BIT = STEP_SHIFT, //push bit to stack
+ STEP_GO_BACK_BIT = STEP_SHIFT << 1, //go back to previous node
+ STEP_NO_ADVANCE_BIT = STEP_SHIFT << 2, //do not advance past this node
+ STEP_EXIT_FUNCTION_BIT = STEP_SHIFT << 3, //return from function
+ STEP_YIELD_BIT = STEP_SHIFT << 4, //yield (will find VisualScriptFunctionState state in first working memory)
};
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;
@@ -773,32 +676,27 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptCustomNode();
};
-class VisualScriptSubCall: public VisualScriptNode {
-
- GDCLASS(VisualScriptSubCall,VisualScriptNode)
+class VisualScriptSubCall : public VisualScriptNode {
+ GDCLASS(VisualScriptSubCall, VisualScriptNode)
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;
@@ -806,34 +704,31 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptSubCall();
};
-class VisualScriptComment: public VisualScriptNode {
-
- GDCLASS(VisualScriptComment,VisualScriptNode)
+class VisualScriptComment : public VisualScriptNode {
+ GDCLASS(VisualScriptComment, VisualScriptNode)
String title;
String description;
Size2 size;
-protected:
+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;
@@ -841,44 +736,39 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- void set_title(const String& p_title);
+ void set_title(const String &p_title);
String get_title() const;
- void set_description(const String& p_description);
+ void set_description(const String &p_description);
String get_description() const;
- void set_size(const Size2& p_size);
+ void set_size(const Size2 &p_size);
Size2 get_size() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptComment();
};
-class VisualScriptConstructor: public VisualScriptNode {
-
- GDCLASS(VisualScriptConstructor,VisualScriptNode)
+class VisualScriptConstructor : public VisualScriptNode {
+ GDCLASS(VisualScriptConstructor, VisualScriptNode)
Variant::Type type;
MethodInfo constructor;
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;
@@ -889,39 +779,33 @@ public:
void set_constructor_type(Variant::Type p_type);
Variant::Type get_constructor_type() const;
- void set_constructor(const Dictionary& p_info);
+ void set_constructor(const Dictionary &p_info);
Dictionary get_constructor() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptConstructor();
};
+class VisualScriptLocalVar : public VisualScriptNode {
-
-
-class VisualScriptLocalVar: public VisualScriptNode {
-
- GDCLASS(VisualScriptLocalVar,VisualScriptNode)
+ GDCLASS(VisualScriptLocalVar, VisualScriptNode)
StringName name;
Variant::Type type;
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;
@@ -929,39 +813,36 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- void set_var_name(const StringName& p_name);
+ void set_var_name(const StringName &p_name);
StringName get_var_name() const;
void set_var_type(Variant::Type p_type);
Variant::Type get_var_type() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptLocalVar();
};
-class VisualScriptLocalVarSet: public VisualScriptNode {
+class VisualScriptLocalVarSet : public VisualScriptNode {
- GDCLASS(VisualScriptLocalVarSet,VisualScriptNode)
+ GDCLASS(VisualScriptLocalVarSet, VisualScriptNode)
StringName name;
Variant::Type type;
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;
@@ -969,22 +850,20 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- void set_var_name(const StringName& p_name);
+ void set_var_name(const StringName &p_name);
StringName get_var_name() const;
void set_var_type(Variant::Type p_type);
Variant::Type get_var_type() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptLocalVarSet();
};
+class VisualScriptInputAction : public VisualScriptNode {
-
-class VisualScriptInputAction: public VisualScriptNode {
-
- GDCLASS(VisualScriptInputAction,VisualScriptNode)
+ GDCLASS(VisualScriptInputAction, VisualScriptNode)
public:
enum Mode {
MODE_PRESSED,
@@ -997,22 +876,19 @@ public:
Mode mode;
protected:
-
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -1020,57 +896,51 @@ public:
virtual String get_text() const;
virtual String get_category() const;
- void set_action_name(const StringName& p_name);
+ void set_action_name(const StringName &p_name);
StringName get_action_name() const;
void set_action_mode(Mode p_mode);
Mode get_action_mode() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptInputAction();
};
-VARIANT_ENUM_CAST( VisualScriptInputAction::Mode )
-
-class VisualScriptDeconstruct: public VisualScriptNode {
+VARIANT_ENUM_CAST(VisualScriptInputAction::Mode)
- GDCLASS(VisualScriptDeconstruct,VisualScriptNode)
+class VisualScriptDeconstruct : public VisualScriptNode {
+ GDCLASS(VisualScriptDeconstruct, VisualScriptNode)
struct Element {
StringName name;
Variant::Type type;
};
-
Vector<Element> elements;
void _update_elements();
Variant::Type type;
InputEvent::Type input_type;
- void _set_elem_cache(const Array& p_elements);
+ void _set_elem_cache(const Array &p_elements);
Array _get_elem_cache() const;
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -1084,12 +954,11 @@ public:
void set_deconstruct_input_type(InputEvent::Type p_input_type);
InputEvent::Type get_deconstruct_input_type() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptDeconstruct();
};
-
void register_visual_script_nodes();
void unregister_visual_script_nodes();
diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp
index 35335fd9bc..919ced74b9 100644
--- a/modules/visual_script/visual_script_yield_nodes.cpp
+++ b/modules/visual_script/visual_script_yield_nodes.cpp
@@ -28,9 +28,9 @@
/*************************************************************************/
#include "visual_script_yield_nodes.h"
-#include "scene/main/scene_main_loop.h"
#include "os/os.h"
#include "scene/main/node.h"
+#include "scene/main/scene_main_loop.h"
#include "visual_script_nodes.h"
//////////////////////////////////////////
@@ -42,16 +42,16 @@ int VisualScriptYield::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptYield::has_input_sequence_port() const{
+bool VisualScriptYield::has_input_sequence_port() const {
return true;
}
-int VisualScriptYield::get_input_value_port_count() const{
+int VisualScriptYield::get_input_value_port_count() const {
return 0;
}
-int VisualScriptYield::get_output_value_port_count() const{
+int VisualScriptYield::get_output_value_port_count() const {
return 0;
}
@@ -61,20 +61,19 @@ String VisualScriptYield::get_output_sequence_port_text(int p_port) const {
return String();
}
-PropertyInfo VisualScriptYield::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptYield::get_input_value_port_info(int p_idx) const {
return PropertyInfo();
}
-PropertyInfo VisualScriptYield::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptYield::get_output_value_port_info(int p_idx) const {
return PropertyInfo();
}
-
String VisualScriptYield::get_caption() const {
- return yield_mode==YIELD_RETURN?"Yield":"Wait";
+ return yield_mode == YIELD_RETURN ? "Yield" : "Wait";
}
String VisualScriptYield::get_text() const {
@@ -82,17 +81,15 @@ String VisualScriptYield::get_text() const {
switch (yield_mode) {
case YIELD_RETURN: return ""; break;
case YIELD_FRAME: return "Next Frame"; break;
- case YIELD_FIXED_FRAME: return "Next Fixed Frame"; break;
- case YIELD_WAIT: return rtos(wait_time)+" sec(s)"; break;
+ case YIELD_FIXED_FRAME: return "Next Fixed Frame"; break;
+ case YIELD_WAIT: return rtos(wait_time) + " sec(s)"; break;
}
return String();
}
-
class VisualScriptNodeInstanceYield : public VisualScriptNodeInstance {
public:
-
VisualScriptYield::YieldMode mode;
float wait_time;
@@ -100,18 +97,17 @@ public:
//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 false; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_RESUME_YIELD) {
+ if (p_start_mode == START_MODE_RESUME_YIELD) {
return 0; //resuming yield
} else {
//yield
-
SceneTree *tree = OS::get_singleton()->get_main_loop()->cast_to<SceneTree>();
if (!tree) {
- r_error_str="Main Loop is not SceneTree";
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Main Loop is not SceneTree";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
@@ -119,99 +115,92 @@ public:
state.instance();
int ret = STEP_YIELD_BIT;
- switch(mode) {
-
- case VisualScriptYield::YIELD_RETURN: ret=STEP_EXIT_FUNCTION_BIT; break; //return the yield
- case VisualScriptYield::YIELD_FRAME: state->connect_to_signal(tree,"idle_frame",Array()); break;
- case VisualScriptYield::YIELD_FIXED_FRAME: state->connect_to_signal(tree,"fixed_frame",Array()); break;
- case VisualScriptYield::YIELD_WAIT: state->connect_to_signal(tree->create_timer(wait_time).ptr(),"timeout",Array()); break;
-
+ switch (mode) {
+
+ case VisualScriptYield::YIELD_RETURN:
+ ret = STEP_EXIT_FUNCTION_BIT;
+ break; //return the yield
+ case VisualScriptYield::YIELD_FRAME: state->connect_to_signal(tree, "idle_frame", Array()); break;
+ case VisualScriptYield::YIELD_FIXED_FRAME: state->connect_to_signal(tree, "fixed_frame", Array()); break;
+ case VisualScriptYield::YIELD_WAIT: state->connect_to_signal(tree->create_timer(wait_time).ptr(), "timeout", Array()); break;
}
- *p_working_mem=state;
+ *p_working_mem = state;
return ret;
}
}
-
};
-VisualScriptNodeInstance* VisualScriptYield::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceYield * instance = memnew(VisualScriptNodeInstanceYield );
+ VisualScriptNodeInstanceYield *instance = memnew(VisualScriptNodeInstanceYield);
//instance->instance=p_instance;
- instance->mode=yield_mode;
- instance->wait_time=wait_time;
+ instance->mode = yield_mode;
+ instance->wait_time = wait_time;
return instance;
}
void VisualScriptYield::set_yield_mode(YieldMode p_mode) {
- if (yield_mode==p_mode)
+ if (yield_mode == p_mode)
return;
- yield_mode=p_mode;
+ yield_mode = p_mode;
ports_changed_notify();
_change_notify();
}
-VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode(){
+VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() {
return yield_mode;
}
void VisualScriptYield::set_wait_time(float p_time) {
- if (wait_time==p_time)
+ if (wait_time == p_time)
return;
- wait_time=p_time;
+ wait_time = p_time;
ports_changed_notify();
-
}
-float VisualScriptYield::get_wait_time(){
+float VisualScriptYield::get_wait_time() {
return wait_time;
}
+void VisualScriptYield::_validate_property(PropertyInfo &property) const {
-void VisualScriptYield::_validate_property(PropertyInfo& property) const {
-
-
- if (property.name=="wait_time") {
- if (yield_mode!=YIELD_WAIT) {
- property.usage=0;
+ if (property.name == "wait_time") {
+ if (yield_mode != YIELD_WAIT) {
+ property.usage = 0;
}
}
}
void VisualScriptYield::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_yield_mode","mode"),&VisualScriptYield::set_yield_mode);
- ClassDB::bind_method(D_METHOD("get_yield_mode"),&VisualScriptYield::get_yield_mode);
-
- ClassDB::bind_method(D_METHOD("set_wait_time","sec"),&VisualScriptYield::set_wait_time);
- ClassDB::bind_method(D_METHOD("get_wait_time"),&VisualScriptYield::get_wait_time);
+ ClassDB::bind_method(D_METHOD("set_yield_mode", "mode"), &VisualScriptYield::set_yield_mode);
+ ClassDB::bind_method(D_METHOD("get_yield_mode"), &VisualScriptYield::get_yield_mode);
- ADD_PROPERTY(PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Frame,FixedFrame,Time",PROPERTY_USAGE_NOEDITOR),"set_yield_mode","get_yield_mode");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"wait_time"),"set_wait_time","get_wait_time");
+ ClassDB::bind_method(D_METHOD("set_wait_time", "sec"), &VisualScriptYield::set_wait_time);
+ ClassDB::bind_method(D_METHOD("get_wait_time"), &VisualScriptYield::get_wait_time);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Frame,FixedFrame,Time", PROPERTY_USAGE_NOEDITOR), "set_yield_mode", "get_yield_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time"), "set_wait_time", "get_wait_time");
- BIND_CONSTANT( YIELD_FRAME );
- BIND_CONSTANT( YIELD_FIXED_FRAME );
- BIND_CONSTANT( YIELD_WAIT );
-
+ BIND_CONSTANT(YIELD_FRAME);
+ BIND_CONSTANT(YIELD_FIXED_FRAME);
+ BIND_CONSTANT(YIELD_WAIT);
}
VisualScriptYield::VisualScriptYield() {
- yield_mode=YIELD_FRAME;
- wait_time=1;
-
+ yield_mode = YIELD_FRAME;
+ wait_time = 1;
}
-
-template<VisualScriptYield::YieldMode MODE>
-static Ref<VisualScriptNode> create_yield_node(const String& p_name) {
+template <VisualScriptYield::YieldMode MODE>
+static Ref<VisualScriptNode> create_yield_node(const String &p_name) {
Ref<VisualScriptYield> node;
node.instance();
@@ -228,24 +217,24 @@ int VisualScriptYieldSignal::get_output_sequence_port_count() const {
return 1;
}
-bool VisualScriptYieldSignal::has_input_sequence_port() const{
+bool VisualScriptYieldSignal::has_input_sequence_port() const {
return true;
}
#ifdef TOOLS_ENABLED
-static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) {
+static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
return NULL;
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr==script)
+ if (scr.is_valid() && scr == script)
return p_current_node;
- for(int i=0;i<p_current_node->get_child_count();i++) {
- Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script);
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
if (n)
return n;
}
@@ -261,7 +250,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const {
if (!script.is_valid())
return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
+ MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (!main_loop)
return NULL;
@@ -275,7 +264,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const {
if (!edited_scene)
return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
+ Node *script_node = _find_script_node(edited_scene, edited_scene, script);
if (!script_node)
return NULL;
@@ -294,36 +283,32 @@ Node *VisualScriptYieldSignal::_get_base_node() const {
StringName VisualScriptYieldSignal::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
if (path)
return path->get_class();
-
}
return base_type;
}
-int VisualScriptYieldSignal::get_input_value_port_count() const{
+int VisualScriptYieldSignal::get_input_value_port_count() const {
- if (call_mode==CALL_MODE_INSTANCE)
+ if (call_mode == CALL_MODE_INSTANCE)
return 1;
else
return 0;
-
}
-int VisualScriptYieldSignal::get_output_value_port_count() const{
-
+int VisualScriptYieldSignal::get_output_value_port_count() const {
MethodInfo sr;
- if (!ClassDB::get_signal(_get_base_type(),signal,&sr))
+ if (!ClassDB::get_signal(_get_base_type(), signal, &sr))
return 0;
return sr.arguments.size();
-
}
String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const {
@@ -331,30 +316,27 @@ String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const
return String();
}
-PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const {
- if (call_mode==CALL_MODE_INSTANCE)
- return PropertyInfo(Variant::OBJECT,"instance");
+ if (call_mode == CALL_MODE_INSTANCE)
+ return PropertyInfo(Variant::OBJECT, "instance");
else
return PropertyInfo();
-
}
-PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const{
+PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const {
MethodInfo sr;
- if (!ClassDB::get_signal(_get_base_type(),signal,&sr))
+ if (!ClassDB::get_signal(_get_base_type(), signal, &sr))
return PropertyInfo(); //no signal
- ERR_FAIL_INDEX_V(p_idx,sr.arguments.size(),PropertyInfo());
+ ERR_FAIL_INDEX_V(p_idx, sr.arguments.size(), PropertyInfo());
return sr.arguments[p_idx];
-
}
-
String VisualScriptYieldSignal::get_caption() const {
- static const char*cname[3]= {
+ static const char *cname[3] = {
"WaitSignal",
"WaitNodeSignal",
"WaitInstanceSigna;",
@@ -365,52 +347,49 @@ String VisualScriptYieldSignal::get_caption() const {
String VisualScriptYieldSignal::get_text() const {
- if (call_mode==CALL_MODE_SELF)
- return " "+String(signal)+"()";
+ if (call_mode == CALL_MODE_SELF)
+ return " " + String(signal) + "()";
else
- return " "+_get_base_type()+"."+String(signal)+"()";
-
+ return " " + _get_base_type() + "." + String(signal) + "()";
}
+void VisualScriptYieldSignal::set_base_type(const StringName &p_type) {
-void VisualScriptYieldSignal::set_base_type(const StringName& p_type) {
-
- if (base_type==p_type)
+ if (base_type == p_type)
return;
- base_type=p_type;
+ base_type = p_type;
_change_notify();
ports_changed_notify();
}
-StringName VisualScriptYieldSignal::get_base_type() const{
+StringName VisualScriptYieldSignal::get_base_type() const {
return base_type;
}
-void VisualScriptYieldSignal::set_signal(const StringName& p_type){
+void VisualScriptYieldSignal::set_signal(const StringName &p_type) {
- if (signal==p_type)
+ if (signal == p_type)
return;
- signal=p_type;
+ signal = p_type;
_change_notify();
ports_changed_notify();
}
StringName VisualScriptYieldSignal::get_signal() const {
-
return signal;
}
-void VisualScriptYieldSignal::set_base_path(const NodePath& p_type) {
+void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) {
- if (base_path==p_type)
+ if (base_path == p_type)
return;
- base_path=p_type;
+ base_path = p_type;
_change_notify();
ports_changed_notify();
@@ -421,17 +400,15 @@ NodePath VisualScriptYieldSignal::get_base_path() const {
return base_path;
}
-
void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
+ if (call_mode == p_mode)
return;
- call_mode=p_mode;
+ call_mode = p_mode;
_change_notify();
ports_changed_notify();
-
}
VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const {
@@ -439,102 +416,89 @@ VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const
return call_mode;
}
+void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
-void VisualScriptYieldSignal::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="signal/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
+ if (property.name == "signal/base_type") {
+ if (call_mode != CALL_MODE_INSTANCE) {
+ property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
-
- if (property.name=="signal/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
+ if (property.name == "signal/node_path") {
+ if (call_mode != CALL_MODE_NODE_PATH) {
+ property.usage = 0;
} else {
Node *bnode = _get_base_node();
if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
+ property.hint_string = bnode->get_path(); //convert to loong string
} else {
-
}
}
}
- if (property.name=="signal/signal") {
- property.hint=PROPERTY_HINT_ENUM;
-
+ if (property.name == "signal/signal") {
+ property.hint = PROPERTY_HINT_ENUM;
List<MethodInfo> methods;
- ClassDB::get_signal_list(_get_base_type(),&methods);
+ ClassDB::get_signal_list(_get_base_type(), &methods);
List<String> mstring;
- for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().name.begins_with("_"))
continue;
- mstring.push_back(E->get().name.get_slice(":",0));
+ mstring.push_back(E->get().name.get_slice(":", 0));
}
mstring.sort();
String ml;
- for (List<String>::Element *E=mstring.front();E;E=E->next()) {
+ for (List<String>::Element *E = mstring.front(); E; E = E->next()) {
- if (ml!=String())
- ml+=",";
- ml+=E->get();
+ if (ml != String())
+ ml += ",";
+ ml += E->get();
}
- property.hint_string=ml;
+ property.hint_string = ml;
}
-
-
}
-
void VisualScriptYieldSignal::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptYieldSignal::set_base_type);
- ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptYieldSignal::get_base_type);
-
- ClassDB::bind_method(D_METHOD("set_signal","signal"),&VisualScriptYieldSignal::set_signal);
- ClassDB::bind_method(D_METHOD("get_signal"),&VisualScriptYieldSignal::get_signal);
+ ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptYieldSignal::set_base_type);
+ ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptYieldSignal::get_base_type);
- ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptYieldSignal::set_call_mode);
- ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptYieldSignal::get_call_mode);
-
- ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptYieldSignal::set_base_path);
- ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptYieldSignal::get_base_path);
+ ClassDB::bind_method(D_METHOD("set_signal", "signal"), &VisualScriptYieldSignal::set_signal);
+ ClassDB::bind_method(D_METHOD("get_signal"), &VisualScriptYieldSignal::get_signal);
+ ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptYieldSignal::set_call_mode);
+ ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptYieldSignal::get_call_mode);
+ ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptYieldSignal::set_base_path);
+ ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptYieldSignal::get_base_path);
String bt;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (i>0)
- bt+=",";
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ if (i > 0)
+ bt += ",";
- bt+=Variant::get_type_name(Variant::Type(i));
+ 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");
-
-
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
+ 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");
+ BIND_CONSTANT(CALL_MODE_SELF);
+ BIND_CONSTANT(CALL_MODE_NODE_PATH);
+ BIND_CONSTANT(CALL_MODE_INSTANCE);
}
class VisualScriptNodeInstanceYieldSignal : public VisualScriptNodeInstance {
public:
-
-
VisualScriptYieldSignal::CallMode call_mode;
NodePath node_path;
int output_args;
@@ -543,97 +507,88 @@ public:
VisualScriptYieldSignal *node;
VisualScriptInstance *instance;
-
-
virtual int get_working_memory_size() const { return 1; }
//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; }
- 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) {
+ 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) {
- if (p_start_mode==START_MODE_RESUME_YIELD) {
+ if (p_start_mode == START_MODE_RESUME_YIELD) {
return 0; //resuming yield
} else {
//yield
- Object * object;
+ Object *object;
- switch(call_mode) {
+ switch (call_mode) {
case VisualScriptYieldSignal::CALL_MODE_SELF: {
- object=instance->get_owner_ptr();
+ object = instance->get_owner_ptr();
} break;
case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = instance->get_owner_ptr()->cast_to<Node>();
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Base object is not a Node!";
return 0;
}
- Node* another = node->get_node(node_path);
+ Node *another = node->get_node(node_path);
if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Path does not lead Node!";
return 0;
}
- object=another;
+ object = another;
} break;
case VisualScriptYieldSignal::CALL_MODE_INSTANCE: {
object = *p_inputs[0];
if (!object) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Supplied instance input is null.";
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str = "Supplied instance input is null.";
return 0;
-
}
} break;
-
}
Ref<VisualScriptFunctionState> state;
state.instance();
- state->connect_to_signal(object,signal,Array());
+ state->connect_to_signal(object, signal, Array());
- *p_working_mem=state;
+ *p_working_mem = state;
return STEP_YIELD_BIT;
}
-
-
}
-
-
};
-VisualScriptNodeInstance* VisualScriptYieldSignal::instance(VisualScriptInstance* p_instance) {
+VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance *p_instance) {
- VisualScriptNodeInstanceYieldSignal * instance = memnew(VisualScriptNodeInstanceYieldSignal );
- instance->node=this;
- instance->instance=p_instance;
- instance->signal=signal;
- instance->call_mode=call_mode;
- instance->node_path=base_path;
+ VisualScriptNodeInstanceYieldSignal *instance = memnew(VisualScriptNodeInstanceYieldSignal);
+ instance->node = this;
+ instance->instance = p_instance;
+ instance->signal = signal;
+ instance->call_mode = call_mode;
+ instance->node_path = base_path;
instance->output_args = get_output_value_port_count();
return instance;
}
VisualScriptYieldSignal::VisualScriptYieldSignal() {
- call_mode=CALL_MODE_SELF;
- base_type="Object";
-
+ call_mode = CALL_MODE_SELF;
+ base_type = "Object";
}
-template<VisualScriptYieldSignal::CallMode cmode>
-static Ref<VisualScriptNode> create_yield_signal_node(const String& p_name) {
+template <VisualScriptYieldSignal::CallMode cmode>
+static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) {
Ref<VisualScriptYieldSignal> node;
node.instance();
@@ -643,12 +598,10 @@ static Ref<VisualScriptNode> create_yield_signal_node(const String& p_name) {
void register_visual_script_yield_nodes() {
- VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_frame",create_yield_node<VisualScriptYield::YIELD_FRAME>);
- VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_fixed_frame",create_yield_node<VisualScriptYield::YIELD_FIXED_FRAME>);
- VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_time",create_yield_node<VisualScriptYield::YIELD_WAIT>);
-
-
- VisualScriptLanguage::singleton->add_register_func("functions/yield",create_yield_node<VisualScriptYield::YIELD_RETURN>);
- VisualScriptLanguage::singleton->add_register_func("functions/yield_signal",create_node_generic<VisualScriptYieldSignal>);
+ VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_frame", create_yield_node<VisualScriptYield::YIELD_FRAME>);
+ VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_fixed_frame", create_yield_node<VisualScriptYield::YIELD_FIXED_FRAME>);
+ VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_time", create_yield_node<VisualScriptYield::YIELD_WAIT>);
+ VisualScriptLanguage::singleton->add_register_func("functions/yield", create_yield_node<VisualScriptYield::YIELD_RETURN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/yield_signal", create_node_generic<VisualScriptYieldSignal>);
}
diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h
index 80ac879aad..35f72cdfad 100644
--- a/modules/visual_script/visual_script_yield_nodes.h
+++ b/modules/visual_script/visual_script_yield_nodes.h
@@ -33,9 +33,8 @@
class VisualScriptYield : public VisualScriptNode {
- GDCLASS(VisualScriptYield,VisualScriptNode)
+ GDCLASS(VisualScriptYield, VisualScriptNode)
public:
-
enum YieldMode {
YIELD_RETURN,
YIELD_FRAME,
@@ -43,30 +42,25 @@ public:
YIELD_WAIT
};
-private:
+private:
YieldMode yield_mode;
float wait_time;
-
protected:
-
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
-public:
+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;
@@ -80,15 +74,15 @@ public:
void set_wait_time(float p_time);
float get_wait_time();
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptYield();
};
-VARIANT_ENUM_CAST( VisualScriptYield::YieldMode )
+VARIANT_ENUM_CAST(VisualScriptYield::YieldMode)
class VisualScriptYieldSignal : public VisualScriptNode {
- GDCLASS(VisualScriptYieldSignal,VisualScriptNode)
+ GDCLASS(VisualScriptYieldSignal, VisualScriptNode)
public:
enum CallMode {
CALL_MODE_SELF,
@@ -96,8 +90,8 @@ public:
CALL_MODE_INSTANCE,
};
-private:
+private:
CallMode call_mode;
StringName base_type;
NodePath base_path;
@@ -106,25 +100,20 @@ private:
Node *_get_base_node() const;
StringName _get_base_type() const;
-
protected:
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
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;
@@ -132,24 +121,24 @@ public:
virtual String get_text() const;
virtual String get_category() const { return "functions"; }
- void set_base_type(const StringName& p_type);
+ void set_base_type(const StringName &p_type);
StringName get_base_type() const;
- void set_signal(const StringName& p_type);
+ void set_signal(const StringName &p_type);
StringName get_signal() const;
- void set_base_path(const NodePath& p_type);
+ void set_base_path(const NodePath &p_type);
NodePath get_base_path() const;
void set_call_mode(CallMode p_mode);
CallMode get_call_mode() const;
- virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
+ virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptYieldSignal();
};
-VARIANT_ENUM_CAST(VisualScriptYieldSignal::CallMode );
+VARIANT_ENUM_CAST(VisualScriptYieldSignal::CallMode);
void register_visual_script_yield_nodes();
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp
index 98920954a4..88c8ecc0df 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp
@@ -28,60 +28,57 @@
/*************************************************************************/
#include "audio_stream_ogg_vorbis.h"
-
-
-size_t AudioStreamPlaybackOGGVorbis::_ov_read_func(void *p_dst,size_t p_data, size_t p_count, void *_f) {
+size_t AudioStreamPlaybackOGGVorbis::_ov_read_func(void *p_dst, size_t p_data, size_t p_count, void *_f) {
//printf("read to %p, %i bytes, %i nmemb, %p\n",p_dst,p_data,p_count,_f);
- FileAccess *fa=(FileAccess*)_f;
- size_t read_total = p_data*p_count;
+ FileAccess *fa = (FileAccess *)_f;
+ size_t read_total = p_data * p_count;
if (fa->eof_reached())
return 0;
- uint8_t *dst=(uint8_t*)p_dst;
+ uint8_t *dst = (uint8_t *)p_dst;
int read = fa->get_buffer(dst, read_total);
return read;
}
-int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f,ogg_int64_t offs, int whence) {
+int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f, ogg_int64_t offs, int whence) {
- //printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence);
+//printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence);
#ifdef SEEK_SET
//printf("seek set defined\n");
- FileAccess *fa=(FileAccess*)_f;
+ FileAccess *fa = (FileAccess *)_f;
- if (whence==SEEK_SET) {
+ if (whence == SEEK_SET) {
fa->seek(offs);
- } else if (whence==SEEK_CUR) {
+ } else if (whence == SEEK_CUR) {
- fa->seek(fa->get_pos()+offs);
- } else if (whence==SEEK_END) {
+ fa->seek(fa->get_pos() + offs);
+ } else if (whence == SEEK_END) {
fa->seek_end(offs);
} else {
ERR_PRINT("BUG, wtf was whence set to?\n");
}
- int ret=fa->eof_reached()?-1:0;
+ int ret = fa->eof_reached() ? -1 : 0;
//printf("returning %i\n",ret);
return ret;
#else
return -1; // no seeking
#endif
-
}
int AudioStreamPlaybackOGGVorbis::_ov_close_func(void *_f) {
//printf("close %p\n",_f);
if (!_f)
return 0;
- FileAccess *fa=(FileAccess*)_f;
+ FileAccess *fa = (FileAccess *)_f;
if (fa->is_open())
fa->close();
return 0;
@@ -90,40 +87,38 @@ long AudioStreamPlaybackOGGVorbis::_ov_tell_func(void *_f) {
//printf("close %p\n",_f);
- FileAccess *fa=(FileAccess*)_f;
+ FileAccess *fa = (FileAccess *)_f;
return fa->get_pos();
}
-
-
-int AudioStreamPlaybackOGGVorbis::mix(int16_t* p_bufer,int p_frames) {
+int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_bufer, int p_frames) {
if (!playing)
return 0;
- int total=p_frames;
+ int total = p_frames;
while (true) {
int todo = p_frames;
- if (todo==0 || todo<MIN_MIX) {
+ if (todo == 0 || todo < MIN_MIX) {
break;
}
- //printf("to mix %i - mix me %i bytes\n",to_mix,to_mix*stream_channels*sizeof(int16_t));
+//printf("to mix %i - mix me %i bytes\n",to_mix,to_mix*stream_channels*sizeof(int16_t));
- #ifdef BIG_ENDIAN_ENABLED
- long ret=ov_read(&vf,(char*)p_bufer,todo*stream_channels*sizeof(int16_t), 1, 2, 1, &current_section);
- #else
- long ret=ov_read(&vf,(char*)p_bufer,todo*stream_channels*sizeof(int16_t), 0, 2, 1, &current_section);
- #endif
+#ifdef BIG_ENDIAN_ENABLED
+ long ret = ov_read(&vf, (char *)p_bufer, todo * stream_channels * sizeof(int16_t), 1, 2, 1, &current_section);
+#else
+ long ret = ov_read(&vf, (char *)p_bufer, todo * stream_channels * sizeof(int16_t), 0, 2, 1, &current_section);
+#endif
- if (ret<0) {
+ if (ret < 0) {
playing = false;
- ERR_EXPLAIN("Error reading OGG Vorbis File: "+file);
- ERR_BREAK(ret<0);
- } else if (ret==0) { // end of song, reload?
+ ERR_EXPLAIN("Error reading OGG Vorbis File: " + file);
+ ERR_BREAK(ret < 0);
+ } else if (ret == 0) { // end of song, reload?
ov_clear(&vf);
@@ -131,65 +126,59 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t* p_bufer,int p_frames) {
if (!has_loop()) {
- playing=false;
- repeats=1;
+ playing = false;
+ repeats = 1;
break;
}
- f=FileAccess::open(file,FileAccess::READ);
+ f = FileAccess::open(file, FileAccess::READ);
- int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks);
- if (errv!=0) {
- playing=false;
+ int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
+ if (errv != 0) {
+ playing = false;
break; // :(
}
if (loop_restart_time) {
- bool ok = ov_time_seek(&vf,loop_restart_time)==0;
+ bool ok = ov_time_seek(&vf, loop_restart_time) == 0;
if (!ok) {
- playing=false;
+ playing = false;
//ERR_EXPLAIN("loop restart time rejected");
ERR_PRINT("loop restart time rejected")
}
- frames_mixed=stream_srate*loop_restart_time;
+ frames_mixed = stream_srate * loop_restart_time;
} else {
- frames_mixed=0;
+ frames_mixed = 0;
}
repeats++;
continue;
-
}
- ret/=stream_channels;
- ret/=sizeof(int16_t);
-
- frames_mixed+=ret;
+ ret /= stream_channels;
+ ret /= sizeof(int16_t);
- p_bufer+=ret*stream_channels;
- p_frames-=ret;
+ frames_mixed += ret;
+ p_bufer += ret * stream_channels;
+ p_frames -= ret;
}
- return total-p_frames;
-
+ return total - p_frames;
}
-
-
void AudioStreamPlaybackOGGVorbis::play(float p_from) {
if (playing)
stop();
- if (_load_stream()!=OK)
+ if (_load_stream() != OK)
return;
-
- frames_mixed=0;
- playing=true;
- if (p_from>0) {
+ frames_mixed = 0;
+ playing = true;
+ if (p_from > 0) {
seek_pos(p_from);
}
}
@@ -199,7 +188,7 @@ void AudioStreamPlaybackOGGVorbis::_close_file() {
if (f) {
memdelete(f);
- f=NULL;
+ f = NULL;
}
}
@@ -209,39 +198,35 @@ bool AudioStreamPlaybackOGGVorbis::is_playing() const {
void AudioStreamPlaybackOGGVorbis::stop() {
_clear_stream();
- playing=false;
+ playing = false;
//_clear();
}
-
-
float AudioStreamPlaybackOGGVorbis::get_pos() const {
int32_t frames = int32_t(frames_mixed);
if (frames < 0)
- frames=0;
+ frames = 0;
return double(frames) / stream_srate;
}
void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) {
-
-
if (!playing)
return;
- bool ok = ov_time_seek(&vf,p_time)==0;
+ bool ok = ov_time_seek(&vf, p_time) == 0;
ERR_FAIL_COND(!ok);
- frames_mixed=stream_srate*p_time;
+ frames_mixed = stream_srate * p_time;
}
-String AudioStreamPlaybackOGGVorbis::get_stream_name() const {
+String AudioStreamPlaybackOGGVorbis::get_stream_name() const {
return "";
}
void AudioStreamPlaybackOGGVorbis::set_loop(bool p_enable) {
- loops=p_enable;
+ loops = p_enable;
}
bool AudioStreamPlaybackOGGVorbis::has_loop() const {
@@ -253,99 +238,103 @@ int AudioStreamPlaybackOGGVorbis::get_loop_count() const {
return repeats;
}
+Error AudioStreamPlaybackOGGVorbis::set_file(const String &p_file) {
-Error AudioStreamPlaybackOGGVorbis::set_file(const String& p_file) {
-
- file=p_file;
- stream_valid=false;
+ file = p_file;
+ stream_valid = false;
Error err;
- f=FileAccess::open(file,FileAccess::READ,&err);
+ f = FileAccess::open(file, FileAccess::READ, &err);
if (err) {
- ERR_FAIL_COND_V( err, err );
+ ERR_FAIL_COND_V(err, err);
}
- int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks);
- switch(errv) {
+ int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
+ switch (errv) {
case OV_EREAD: { // - A read from media returned an error.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CANT_READ );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CANT_READ);
} break;
- case OV_EVERSION: // - Vorbis version mismatch.
+ case OV_EVERSION: // - Vorbis version mismatch.
case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_UNRECOGNIZED );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
} break;
case OV_EBADHEADER: { // - Invalid Vorbis bitstream header.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CORRUPT );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_BUG );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_BUG);
} break;
}
- const vorbis_info *vinfo=ov_info(&vf,-1);
- stream_channels=vinfo->channels;
- stream_srate=vinfo->rate;
- length = ov_time_total(&vf,-1);
+ const vorbis_info *vinfo = ov_info(&vf, -1);
+ stream_channels = vinfo->channels;
+ stream_srate = vinfo->rate;
+ length = ov_time_total(&vf, -1);
ov_clear(&vf);
memdelete(f);
- f=NULL;
- stream_valid=true;
-
+ f = NULL;
+ stream_valid = true;
return OK;
}
-Error AudioStreamPlaybackOGGVorbis::_load_stream() {
+Error AudioStreamPlaybackOGGVorbis::_load_stream() {
- ERR_FAIL_COND_V(!stream_valid,ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!stream_valid, ERR_UNCONFIGURED);
_clear_stream();
- if (file=="")
+ if (file == "")
return ERR_INVALID_DATA;
Error err;
- f=FileAccess::open(file,FileAccess::READ,&err);
+ f = FileAccess::open(file, FileAccess::READ, &err);
if (err) {
- ERR_FAIL_COND_V( err, err );
+ ERR_FAIL_COND_V(err, err);
}
- int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks);
- switch(errv) {
+ int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
+ switch (errv) {
case OV_EREAD: { // - A read from media returned an error.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CANT_READ );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CANT_READ);
} break;
- case OV_EVERSION: // - Vorbis version mismatch.
+ case OV_EVERSION: // - Vorbis version mismatch.
case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_UNRECOGNIZED );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
} break;
case OV_EBADHEADER: { // - Invalid Vorbis bitstream header.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_FILE_CORRUPT );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
- memdelete(f); f=NULL;
- ERR_FAIL_V( ERR_BUG );
+ memdelete(f);
+ f = NULL;
+ ERR_FAIL_V(ERR_BUG);
} break;
}
- repeats=0;
- stream_loaded=true;
-
+ repeats = 0;
+ stream_loaded = true;
return OK;
}
-
float AudioStreamPlaybackOGGVorbis::get_length() const {
if (!stream_loaded) {
- if (const_cast<AudioStreamPlaybackOGGVorbis*>(this)->_load_stream()!=OK)
+ if (const_cast<AudioStreamPlaybackOGGVorbis *>(this)->_load_stream() != OK)
return 0;
}
return length;
@@ -359,14 +348,14 @@ void AudioStreamPlaybackOGGVorbis::_clear_stream() {
ov_clear(&vf);
_close_file();
- stream_loaded=false;
+ stream_loaded = false;
//stream_channels=1;
- playing=false;
+ playing = false;
}
void AudioStreamPlaybackOGGVorbis::set_paused(bool p_paused) {
- paused=p_paused;
+ paused = p_paused;
}
bool AudioStreamPlaybackOGGVorbis::is_paused(bool p_paused) const {
@@ -374,39 +363,34 @@ bool AudioStreamPlaybackOGGVorbis::is_paused(bool p_paused) const {
return paused;
}
-
AudioStreamPlaybackOGGVorbis::AudioStreamPlaybackOGGVorbis() {
- loops=false;
- playing=false;
- _ov_callbacks.read_func=_ov_read_func;
- _ov_callbacks.seek_func=_ov_seek_func;
- _ov_callbacks.close_func=_ov_close_func;
- _ov_callbacks.tell_func=_ov_tell_func;
+ loops = false;
+ playing = false;
+ _ov_callbacks.read_func = _ov_read_func;
+ _ov_callbacks.seek_func = _ov_seek_func;
+ _ov_callbacks.close_func = _ov_close_func;
+ _ov_callbacks.tell_func = _ov_tell_func;
f = NULL;
- stream_loaded=false;
- stream_valid=false;
- repeats=0;
- paused=true;
- stream_channels=0;
- stream_srate=0;
- current_section=0;
- length=0;
- loop_restart_time=0;
+ stream_loaded = false;
+ stream_valid = false;
+ repeats = 0;
+ paused = true;
+ stream_channels = 0;
+ stream_srate = 0;
+ current_section = 0;
+ length = 0;
+ loop_restart_time = 0;
}
-
AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() {
_clear_stream();
-
}
-
-
-RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=OK;
+ *r_error = OK;
AudioStreamOGGVorbis *ogg_stream = memnew(AudioStreamOGGVorbis);
ogg_stream->set_file(p_path);
@@ -419,12 +403,11 @@ void ResourceFormatLoaderAudioStreamOGGVorbis::get_recognized_extensions(List<St
}
String ResourceFormatLoaderAudioStreamOGGVorbis::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="ogg")
+ if (p_path.get_extension().to_lower() == "ogg")
return "AudioStreamOGGVorbis";
return "";
}
-bool ResourceFormatLoaderAudioStreamOGGVorbis::handles_type(const String& p_type) const {
- return (p_type=="AudioStream" || p_type=="AudioStreamOGG" || p_type=="AudioStreamOGGVorbis");
+bool ResourceFormatLoaderAudioStreamOGGVorbis::handles_type(const String &p_type) const {
+ return (p_type == "AudioStream" || p_type == "AudioStreamOGG" || p_type == "AudioStreamOGGVorbis");
}
-
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h
index bc2bfa2ae6..a13e934f2a 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/vorbis/audio_stream_ogg_vorbis.h
@@ -38,18 +38,18 @@
class AudioStreamPlaybackOGGVorbis : public AudioStreamPlayback {
- GDCLASS(AudioStreamPlaybackOGGVorbis,AudioStreamPlayback);
+ GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlayback);
enum {
- MIN_MIX=1024
+ MIN_MIX = 1024
};
FileAccess *f;
ov_callbacks _ov_callbacks;
float length;
- static size_t _ov_read_func(void *p_dst,size_t p_data, size_t p_count, void *_f);
- static int _ov_seek_func(void *_f,ogg_int64_t offs, int whence);
+ static size_t _ov_read_func(void *p_dst, size_t p_data, size_t p_count, void *_f);
+ static int _ov_seek_func(void *_f, ogg_int64_t offs, int whence);
static int _ov_close_func(void *_f);
static long _ov_tell_func(void *_f);
@@ -63,7 +63,6 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlayback {
int stream_srate;
int current_section;
-
bool paused;
bool loops;
int repeats;
@@ -75,17 +74,14 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlayback {
bool stream_valid;
float loop_restart_time;
-
public:
+ Error set_file(const String &p_file);
-
- Error set_file(const String& p_file);
-
- virtual void play(float p_from=0);
+ virtual void play(float p_from = 0);
virtual void stop();
virtual bool is_playing() const;
- virtual void set_loop_restart_time(float p_time) { loop_restart_time=p_time; }
+ virtual void set_loop_restart_time(float p_time) { loop_restart_time = p_time; }
virtual void set_paused(bool p_paused);
virtual bool is_paused(bool p_paused) const;
@@ -106,37 +102,34 @@ public:
virtual int get_mix_rate() const { return stream_srate; }
virtual int get_minimum_buffer_size() const { return 0; }
- virtual int mix(int16_t* p_bufer,int p_frames);
+ virtual int mix(int16_t *p_bufer, int p_frames);
AudioStreamPlaybackOGGVorbis();
~AudioStreamPlaybackOGGVorbis();
};
-
class AudioStreamOGGVorbis : public AudioStream {
- GDCLASS(AudioStreamOGGVorbis,AudioStream);
+ GDCLASS(AudioStreamOGGVorbis, AudioStream);
String file;
-public:
+public:
Ref<AudioStreamPlayback> instance_playback() {
- Ref<AudioStreamPlaybackOGGVorbis> pb = memnew( AudioStreamPlaybackOGGVorbis );
+ Ref<AudioStreamPlaybackOGGVorbis> pb = memnew(AudioStreamPlaybackOGGVorbis);
pb->set_file(file);
return pb;
}
- void set_file(const String& p_file) { file=p_file; }
-
+ void set_file(const String &p_file) { file = p_file; }
};
class ResourceFormatLoaderAudioStreamOGGVorbis : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ 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 bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
-
#endif // AUDIO_STREAM_OGG_H
diff --git a/modules/vorbis/register_types.cpp b/modules/vorbis/register_types.cpp
index de929d9350..b405acd16b 100644
--- a/modules/vorbis/register_types.cpp
+++ b/modules/vorbis/register_types.cpp
@@ -34,12 +34,12 @@ static ResourceFormatLoaderAudioStreamOGGVorbis *vorbis_stream_loader = NULL;
void register_vorbis_types() {
- vorbis_stream_loader = memnew( ResourceFormatLoaderAudioStreamOGGVorbis );
+ vorbis_stream_loader = memnew(ResourceFormatLoaderAudioStreamOGGVorbis);
ResourceLoader::add_resource_format_loader(vorbis_stream_loader);
ClassDB::register_class<AudioStreamOGGVorbis>();
}
void unregister_vorbis_types() {
- memdelete( vorbis_stream_loader );
+ memdelete(vorbis_stream_loader);
}
diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp
index d4995ad798..8d6fbdfe75 100644
--- a/modules/webm/video_stream_webm.cpp
+++ b/modules/webm/video_stream_webm.cpp
@@ -28,14 +28,14 @@
/*************************************************************************/
#include "video_stream_webm.h"
-#include "VPXDecoder.hpp"
#include "OpusVorbisDecoder.hpp"
+#include "VPXDecoder.hpp"
-#include "mkvparser/mkvparser.h"
#include "../theora/yuv2rgb.h"
+#include "mkvparser/mkvparser.h"
-#include "os/file_access.h"
#include "global_config.h"
+#include "os/file_access.h"
#include <string.h>
@@ -85,22 +85,21 @@ private:
/**/
-VideoStreamPlaybackWebm::VideoStreamPlaybackWebm() :
- audio_track(0),
- webm(NULL),
- video(NULL),
- audio(NULL),
- video_frames(NULL), audio_frame(NULL),
- video_frames_pos(0), video_frames_capacity(0),
- num_decoded_samples(0), samples_offset(-1),
- mix_callback(NULL),
- mix_udata(NULL),
- playing(false), paused(false),
- delay_compensation(0.0),
- time(0.0), video_frame_delay(0.0), video_pos(0.0),
- texture(memnew(ImageTexture)),
- pcm(NULL)
-{}
+VideoStreamPlaybackWebm::VideoStreamPlaybackWebm()
+ : audio_track(0),
+ webm(NULL),
+ video(NULL),
+ audio(NULL),
+ video_frames(NULL), audio_frame(NULL),
+ video_frames_pos(0), video_frames_capacity(0),
+ num_decoded_samples(0), samples_offset(-1),
+ mix_callback(NULL),
+ mix_udata(NULL),
+ playing(false), paused(false),
+ delay_compensation(0.0),
+ time(0.0), video_frame_delay(0.0), video_pos(0.0),
+ texture(memnew(ImageTexture)),
+ pcm(NULL) {}
VideoStreamPlaybackWebm::~VideoStreamPlaybackWebm() {
delete_pointers();
@@ -299,22 +298,22 @@ void VideoStreamPlaybackWebm::update(float p_delta) {
if (image.chromaShiftW == 1 && image.chromaShiftH == 1) {
yuv420_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0);
-// libyuv::I420ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
+ // libyuv::I420ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
converted = true;
} else if (image.chromaShiftW == 1 && image.chromaShiftH == 0) {
yuv422_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0);
-// libyuv::I422ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
+ // libyuv::I422ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
converted = true;
} else if (image.chromaShiftW == 0 && image.chromaShiftH == 0) {
yuv444_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0);
-// libyuv::I444ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
+ // libyuv::I444ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
converted = true;
} else if (image.chromaShiftW == 2 && image.chromaShiftH == 0) {
-// libyuv::I411ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
-// converted = true;
+ // libyuv::I411ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h);
+ // converted = true;
}
if (converted)
@@ -361,8 +360,7 @@ int VideoStreamPlaybackWebm::get_mix_rate() const {
return 0;
}
-inline bool VideoStreamPlaybackWebm::has_enough_video_frames() const
-{
+inline bool VideoStreamPlaybackWebm::has_enough_video_frames() const {
if (video_frames_pos > 0) {
const double audio_delay = AudioServer::get_singleton()->get_output_delay();
@@ -423,9 +421,8 @@ String ResourceFormatLoaderVideoStreamWebm::get_resource_type(const String &p_pa
/**/
-VideoStreamWebm::VideoStreamWebm() :
- audio_track(0)
-{}
+VideoStreamWebm::VideoStreamWebm()
+ : audio_track(0) {}
Ref<VideoStreamPlayback> VideoStreamWebm::instance_playback() {
diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h
index cb4ef53f6d..2b62cf48b6 100644
--- a/modules/webm/video_stream_webm.h
+++ b/modules/webm/video_stream_webm.h
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "scene/resources/video_stream.h"
#include "io/resource_loader.h"
+#include "scene/resources/video_stream.h"
class WebMFrame;
class WebMDemuxer;
diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp
index 3508c6a663..829e77873a 100644
--- a/modules/webp/image_loader_webp.cpp
+++ b/modules/webp/image_loader_webp.cpp
@@ -29,59 +29,59 @@
#include "image_loader_webp.h"
#include "io/marshalls.h"
-#include "print_string.h"
#include "os/os.h"
+#include "print_string.h"
#include <stdlib.h>
#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 Image &p_image, float p_quality) {
- ERR_FAIL_COND_V(p_image.empty(),PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(p_image.empty(), PoolVector<uint8_t>());
- Image img=p_image;
+ Image img = p_image;
if (img.detect_alpha())
img.convert(Image::FORMAT_RGBA8);
else
img.convert(Image::FORMAT_RGB8);
- Size2 s(img.get_width(),img.get_height());
+ 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) {
+ uint8_t *dst_buff = NULL;
+ size_t dst_size = 0;
+ 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);
+ dst_size = WebPEncodeRGB(r.ptr(), s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
} else {
- dst_size = WebPEncodeRGBA(r.ptr(),s.width,s.height,4*s.width,CLAMP(p_quality*100.0,0,100.0),&dst_buff);
+ dst_size = WebPEncodeRGBA(r.ptr(), s.width, s.height, 4 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
}
- ERR_FAIL_COND_V(dst_size==0,PoolVector<uint8_t>());
+ ERR_FAIL_COND_V(dst_size == 0, PoolVector<uint8_t>());
PoolVector<uint8_t> dst;
- dst.resize(4+dst_size);
+ dst.resize(4 + dst_size);
PoolVector<uint8_t>::Write w = dst.write();
- w[0]='W';
- w[1]='E';
- w[2]='B';
- w[3]='P';
- copymem(&w[4],dst_buff,dst_size);
+ w[0] = 'W';
+ w[1] = 'E';
+ w[2] = 'B';
+ w[3] = 'P';
+ copymem(&w[4], dst_buff, dst_size);
free(dst_buff);
- w=PoolVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
return dst;
}
-static Image _webp_lossy_unpack(const PoolVector<uint8_t>& p_buffer) {
+static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) {
- int size = p_buffer.size()-4;
- ERR_FAIL_COND_V(size<=0,Image());
+ int size = p_buffer.size() - 4;
+ ERR_FAIL_COND_V(size <= 0, 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', Image());
WebPBitstreamFeatures features;
- if (WebPGetFeatures(&r[4],size,&features)!=VP8_STATUS_OK) {
+ if (WebPGetFeatures(&r[4], size, &features) != VP8_STATUS_OK) {
ERR_EXPLAIN("Error unpacking WEBP image:");
ERR_FAIL_V(Image());
}
@@ -91,31 +91,27 @@ static Image _webp_lossy_unpack(const PoolVector<uint8_t>& p_buffer) {
//print_line("alpha: "+itos(features.has_alpha));
PoolVector<uint8_t> dst_image;
- int datasize = features.width*features.height*(features.has_alpha?4:3);
+ int datasize = features.width * features.height * (features.has_alpha ? 4 : 3);
dst_image.resize(datasize);
PoolVector<uint8_t>::Write dst_w = dst_image.write();
- bool errdec=false;
- if (features.has_alpha) {
- errdec = WebPDecodeRGBAInto(&r[4],size,dst_w.ptr(),datasize,4*features.width)==NULL;
+ bool errdec = false;
+ if (features.has_alpha) {
+ errdec = WebPDecodeRGBAInto(&r[4], size, dst_w.ptr(), datasize, 4 * features.width) == NULL;
} else {
- errdec = WebPDecodeRGBInto(&r[4],size,dst_w.ptr(),datasize,3*features.width)==NULL;
-
+ errdec = WebPDecodeRGBInto(&r[4], size, dst_w.ptr(), datasize, 3 * features.width) == NULL;
}
//ERR_EXPLAIN("Error decoding webp! - "+p_file);
- ERR_FAIL_COND_V(errdec,Image());
+ ERR_FAIL_COND_V(errdec, 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);
-
+ return Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);
}
-
-Error ImageLoaderWEBP::load_image(Image *p_image,FileAccess *f) {
-
+Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) {
uint32_t size = f->get_len();
PoolVector<uint8_t> src_image;
@@ -124,60 +120,53 @@ Error ImageLoaderWEBP::load_image(Image *p_image,FileAccess *f) {
WebPBitstreamFeatures features;
PoolVector<uint8_t>::Write src_w = src_image.write();
- f->get_buffer(src_w.ptr(),size);
+ f->get_buffer(src_w.ptr(), size);
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_EOF);
- if (WebPGetFeatures(src_w.ptr(),size,&features)!=VP8_STATUS_OK) {
+ if (WebPGetFeatures(src_w.ptr(), size, &features) != VP8_STATUS_OK) {
f->close();
//ERR_EXPLAIN("Error decoding WEBP image: "+p_file);
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));
+ 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();
PoolVector<uint8_t> dst_image;
- int datasize = features.width*features.height*(features.has_alpha?4:3);
+ int datasize = features.width * features.height * (features.has_alpha ? 4 : 3);
dst_image.resize(datasize);
PoolVector<uint8_t>::Read src_r = src_image.read();
PoolVector<uint8_t>::Write dst_w = dst_image.write();
-
- bool errdec=false;
- if (features.has_alpha) {
- errdec = WebPDecodeRGBAInto(src_r.ptr(),size,dst_w.ptr(),datasize,4*features.width)==NULL;
+ bool errdec = false;
+ if (features.has_alpha) {
+ errdec = WebPDecodeRGBAInto(src_r.ptr(), size, dst_w.ptr(), datasize, 4 * features.width) == NULL;
} else {
- errdec = WebPDecodeRGBInto(src_r.ptr(),size,dst_w.ptr(),datasize,3*features.width)==NULL;
-
+ errdec = WebPDecodeRGBInto(src_r.ptr(), size, dst_w.ptr(), datasize, 3 * features.width) == NULL;
}
//ERR_EXPLAIN("Error decoding webp! - "+p_file);
- ERR_FAIL_COND_V(errdec,ERR_FILE_CORRUPT);
+ ERR_FAIL_COND_V(errdec, ERR_FILE_CORRUPT);
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 = Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);
return OK;
-
}
void ImageLoaderWEBP::get_recognized_extensions(List<String> *p_extensions) const {
-
+
p_extensions->push_back("webp");
}
-
ImageLoaderWEBP::ImageLoaderWEBP() {
- Image::lossy_packer=_webp_lossy_pack;
- Image::lossy_unpacker=_webp_lossy_unpack;
+ Image::lossy_packer = _webp_lossy_pack;
+ Image::lossy_unpacker = _webp_lossy_unpack;
}
-
-
diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h
index eb1b32ac95..ccf22bae13 100644
--- a/modules/webp/image_loader_webp.h
+++ b/modules/webp/image_loader_webp.h
@@ -36,14 +36,10 @@
*/
class ImageLoaderWEBP : public ImageFormatLoader {
-
public:
-
- virtual Error load_image(Image *p_image,FileAccess *f);
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual Error load_image(Image *p_image, FileAccess *f);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderWEBP();
};
-
-
#endif
diff --git a/modules/webp/register_types.cpp b/modules/webp/register_types.cpp
index 7a4e35dc4c..8a708aae6a 100644
--- a/modules/webp/register_types.cpp
+++ b/modules/webp/register_types.cpp
@@ -34,11 +34,11 @@ static ImageLoaderWEBP *image_loader_webp = NULL;
void register_webp_types() {
- image_loader_webp = memnew( ImageLoaderWEBP );
+ image_loader_webp = memnew(ImageLoaderWEBP);
ImageLoader::add_image_format_loader(image_loader_webp);
}
void unregister_webp_types() {
- memdelete( image_loader_webp );
+ memdelete(image_loader_webp);
}