#ifndef VSCRIPT_H #define VSCRIPT_H #include "script_language.h" #include "os/thread.h" class VisualScriptInstance; class VisualScriptNodeInstance; class VisualScript; class VisualScriptNode : public Resource { OBJ_TYPE(VisualScriptNode,Resource) friend class VisualScript; Set scripts_used; Array default_input_values; bool breakpoint; void _set_default_input_values(Array p_values); Array _get_default_input_values() const; void validate_input_default_values(); protected: virtual bool _use_builtin_script() const { return false; } void _notification(int p_what); void ports_changed_notify(); static void _bind_methods(); public: Ref get_visual_script() const; 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 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; 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; //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; struct TypeGuess { Variant::Type type; InputEvent::Type ev_type; StringName obj_type; String script_type; TypeGuess() { type=Variant::NIL; ev_type=InputEvent::NONE; } }; virtual TypeGuess guess_output_type(TypeGuess* p_inputs, int p_output) const; VisualScriptNode(); }; class VisualScriptNodeInstance { 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) }; int id; int sequence_index; VisualScriptNodeInstance **sequence_outputs; int sequence_output_count; Vector dependencies; int *input_ports; int input_port_count; int *output_ports; int output_port_count; int working_mem_idx; int pass_idx; VisualScriptNode *base; public: enum StartMode { START_MODE_BEGIN_SEQUENCE, START_MODE_CONTINUE_SEQUENCE, START_MODE_RESUME_YIELD }; 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) 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_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 Ref get_base_node() { return Ref( base ); } VisualScriptNodeInstance(); virtual ~VisualScriptNodeInstance(); }; class VisualScript : public Script { OBJ_TYPE( VisualScript, Script ) RES_BASE_EXTENSION("vs"); public: struct SequenceConnection { union { struct { uint64_t from_node : 24; uint64_t from_output : 16; uint64_t to_node : 24; }; uint64_t id; }; bool operator<(const SequenceConnection& p_connection) const { return id node; }; Map nodes; Set sequence_connections; Set data_connections; int function_id; Vector2 scroll; Function() { function_id=-1; } }; struct Variable { PropertyInfo info; Variant default_value; bool _export; }; Map functions; Map variables; Map script_variable_remap; Map > custom_signals; Map instances; #ifdef TOOLS_ENABLED Set 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_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; void get_function_list(List *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& 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 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 *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 *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 *r_connection) const; bool is_input_value_port_connected(const StringName& p_name,int p_node,int p_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 *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 get_custom_signal_list(List *r_custom_signals) const; int get_available_id() const; void set_instance_base_type(const StringName& p_type); virtual bool can_instance() const; virtual Ref