diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/command_queue_mt.h | 2 | ||||
-rw-r--r-- | core/global_constants.cpp | 3 | ||||
-rw-r--r-- | core/globals.cpp | 6 | ||||
-rw-r--r-- | core/input_map.cpp | 58 | ||||
-rw-r--r-- | core/input_map.h | 1 | ||||
-rw-r--r-- | core/io/config_file.cpp | 8 | ||||
-rw-r--r-- | core/io/config_file.h | 2 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 10 | ||||
-rw-r--r-- | core/message_queue.cpp | 104 | ||||
-rw-r--r-- | core/message_queue.h | 7 | ||||
-rw-r--r-- | core/object.cpp | 120 | ||||
-rw-r--r-- | core/object.h | 1 | ||||
-rw-r--r-- | core/os/input_event.cpp | 1 | ||||
-rw-r--r-- | core/os/input_event.h | 3 | ||||
-rw-r--r-- | core/script_debugger_remote.cpp | 9 | ||||
-rw-r--r-- | core/script_language.h | 1 | ||||
-rw-r--r-- | core/ustring.cpp | 10 | ||||
-rw-r--r-- | core/ustring.h | 2 | ||||
-rw-r--r-- | core/variant.cpp | 40 | ||||
-rw-r--r-- | core/variant.h | 4 | ||||
-rw-r--r-- | core/variant_op.cpp | 4 | ||||
-rw-r--r-- | core/variant_parser.cpp | 22 |
22 files changed, 274 insertions, 144 deletions
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 84c3687b08..4fd33e3a55 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -983,7 +983,7 @@ public: void flush_all() { - ERR_FAIL_COND(sync); + //ERR_FAIL_COND(sync); lock(); while (true) { bool exit = !flush_one(); diff --git a/core/global_constants.cpp b/core/global_constants.cpp index f89ea00510..92e50a8b96 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -402,6 +402,9 @@ static _GlobalConstant _global_constants[]={ BIND_GLOBAL_CONSTANT( JOY_ANALOG_2_X ), BIND_GLOBAL_CONSTANT( JOY_ANALOG_2_Y ), + BIND_GLOBAL_CONSTANT( JOY_ANALOG_L2 ), + BIND_GLOBAL_CONSTANT( JOY_ANALOG_R2 ), + // error list diff --git a/core/globals.cpp b/core/globals.cpp index 17b139d1ad..1e60854f28 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -638,7 +638,9 @@ static Variant _decode_variant(const String& p_string) { InputEvent ie; ie.type=InputEvent::JOYSTICK_MOTION; ie.device=params[0].to_int(); - ie.joy_motion.axis=params[1].to_int(); + int axis = params[1].to_int();; + ie.joy_motion.axis=axis>>1; + ie.joy_motion.axis_value=axis&1?1:-1; return ie; } @@ -1029,7 +1031,7 @@ static String _encode_variant(const Variant& p_variant) { } break; case InputEvent::JOYSTICK_MOTION: { - return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis)+")"; + return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis * 2 + (ev.joy_motion.axis_value<0?0:1))+")"; } break; default: { diff --git a/core/input_map.cpp b/core/input_map.cpp index 6feec9af95..d4560a1e1b 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -204,6 +204,64 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac return _find_event(E->get().inputs,p_event)!=NULL; } +bool InputMap::event_is_joy_motion_action_pressed(const InputEvent& p_event) const { + + ERR_FAIL_COND_V(p_event.type!=InputEvent::JOYSTICK_MOTION,false); + bool pressed=false; + + //this could be optimized by having a separate list of joymotions? + + for (Map<StringName, Action>::Element *A=input_map.front();A;A=A->next()) { + + for (List<InputEvent>::Element *E=A->get().inputs.front();E;E=E->next()) { + + const InputEvent& e=E->get(); + if(e.type!=p_event.type) + continue; + if (e.type!=InputEvent::KEY && e.device!=p_event.device) + continue; + + switch(p_event.type) { + + case InputEvent::KEY: { + + if (e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod) + return e.key.pressed; + + } break; + case InputEvent::JOYSTICK_BUTTON: { + + if (e.joy_button.button_index==p_event.joy_button.button_index) { + return e.joy_button.pressed; + } + + } break; + case InputEvent::MOUSE_BUTTON: { + + if (e.mouse_button.button_index==p_event.mouse_button.button_index) { + return e.mouse_button.pressed; + } + + } break; + case InputEvent::JOYSTICK_MOTION: { + + if (e.joy_motion.axis==p_event.joy_motion.axis) { + if ( + (e.joy_motion.axis_value * p_event.joy_motion.axis_value >0) && //same axis + ABS(e.joy_motion.axis_value)>0.5 && ABS(p_event.joy_motion.axis_value)>0.5 ) + pressed=true; + } + + } break; + } + + } + } + + return pressed; + +} + void InputMap::load_from_globals() { input_map.clear();; diff --git a/core/input_map.h b/core/input_map.h index c803d5bf04..5cd1e41922 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -68,6 +68,7 @@ public: const List<InputEvent> *get_action_list(const StringName& p_action); bool event_is_action(const InputEvent& p_event, const StringName& p_action) const; + bool event_is_joy_motion_action_pressed(const InputEvent& p_event) const; void load_from_globals(); diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 03fdcf7c6c..f32d006cba 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -84,10 +84,10 @@ void ConfigFile::set_value(const String& p_section, const String& p_key, const V } } -Variant ConfigFile::get_value(const String& p_section, const String& p_key) const{ +Variant ConfigFile::get_value(const String& p_section, const String& p_key, Variant p_default) const { - ERR_FAIL_COND_V(!values.has(p_section),Variant()); - ERR_FAIL_COND_V(!values[p_section].has(p_key),Variant()); + ERR_FAIL_COND_V(!values.has(p_section),p_default); + ERR_FAIL_COND_V(!values[p_section].has(p_key),p_default); return values[p_section][p_key]; } @@ -199,7 +199,7 @@ Error ConfigFile::load(const String& p_path) { void ConfigFile::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_value","section","key","value"),&ConfigFile::set_value); - ObjectTypeDB::bind_method(_MD("get_value","section","key"),&ConfigFile::get_value); + ObjectTypeDB::bind_method(_MD("get_value","section","key","default"),&ConfigFile::get_value,DEFVAL(Variant())); ObjectTypeDB::bind_method(_MD("has_section","section"),&ConfigFile::has_section); ObjectTypeDB::bind_method(_MD("has_section_key","section","key"),&ConfigFile::has_section_key); diff --git a/core/io/config_file.h b/core/io/config_file.h index f12dcae497..4708fefeaa 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -46,7 +46,7 @@ protected: public: void set_value(const String& p_section, const String& p_key, const Variant& p_value); - Variant get_value(const String& p_section, const String& p_key) const; + Variant get_value(const String& p_section, const String& p_key, Variant p_default=Variant()) const; bool has_section(const String& p_section) const; bool has_section_key(const String& p_section,const String& p_key) const; diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 2f0c1a6512..20d9db3375 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -207,9 +207,15 @@ double Math::ceil(double p_x) { int Math::decimals(double p_step) { int max=4; + double llimit = Math::pow(0.1,max); + double ulimit = 1.0-llimit; int i=0; - while( (p_step - Math::floor(p_step)) != 0.0 && max) { - + while( max) { + + float d = absf(p_step) - Math::floor(absf(p_step)); + + if (d<llimit || d>ulimit) + break; p_step*=10.0; max--; i++; diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 8f2dd622ad..c69021f4f0 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "message_queue.h" #include "globals.h" - +#include "script_language.h" MessageQueue *MessageQueue::singleton=NULL; MessageQueue *MessageQueue::get_singleton() { @@ -36,26 +36,11 @@ MessageQueue *MessageQueue::get_singleton() { return singleton; } -Error MessageQueue::push_call(ObjectID p_id, const StringName& p_method, VARIANT_ARG_DECLARE) { +Error MessageQueue::push_call(ObjectID p_id,const StringName& p_method,const Variant** p_args,int p_argcount,bool p_show_error) { _THREAD_SAFE_METHOD_ - uint8_t room_needed=sizeof(Message); - int args=0; - if (p_arg5.get_type()!=Variant::NIL) - args=5; - else if (p_arg4.get_type()!=Variant::NIL) - args=4; - else if (p_arg3.get_type()!=Variant::NIL) - args=3; - else if (p_arg2.get_type()!=Variant::NIL) - args=2; - else if (p_arg1.get_type()!=Variant::NIL) - args=1; - else - args=0; - - room_needed+=sizeof(Variant)*args; + int room_needed=sizeof(Message)+sizeof(Variant)*p_argcount; if ((buffer_end+room_needed) >= buffer_size) { String type; @@ -65,53 +50,43 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName& p_method, VARIANT statistics(); } + ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY ); Message * msg = memnew_placement( &buffer[ buffer_end ], Message ); - msg->args=args; + msg->args=p_argcount; msg->instance_ID=p_id; msg->target=p_method; msg->type=TYPE_CALL; - buffer_end+=sizeof(Message); + if (p_show_error) + msg->type|=FLAG_SHOW_ERROR; + buffer_end+=sizeof(Message); - if (args>=1) { + for(int i=0;i<p_argcount;i++) { Variant * v = memnew_placement( &buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); - *v=p_arg1; - } - - if (args>=2) { + *v=*p_args[i]; - Variant * v = memnew_placement( &buffer[ buffer_end ], Variant ); - buffer_end+=sizeof(Variant); - *v=p_arg2; } - if (args>=3) { + return OK; +} - Variant * v = memnew_placement( &buffer[ buffer_end ], Variant ); - buffer_end+=sizeof(Variant); - *v=p_arg3; +Error MessageQueue::push_call(ObjectID p_id, const StringName& p_method, VARIANT_ARG_DECLARE) { - } + VARIANT_ARGPTRS; - if (args>=4) { + int argc=0; - Variant * v = memnew_placement( &buffer[ buffer_end ], Variant ); - buffer_end+=sizeof(Variant); - *v=p_arg4; + for(int i=0;i<VARIANT_ARG_MAX;i++) { + if (argptr[i]->get_type()==Variant::NIL) + break; + argc++; } - if (args>=5) { + return push_call(p_id,p_method,argptr,argc,false); - Variant * v = memnew_placement( &buffer[ buffer_end ], Variant ); - buffer_end+=sizeof(Variant); - *v=p_arg5; - } - - - return OK; } Error MessageQueue::push_set(ObjectID p_id, const StringName& p_prop, const Variant& p_value) { @@ -212,7 +187,7 @@ void MessageQueue::statistics() { if (target!=NULL) { - switch(message->type) { + switch(message->type&FLAG_MASK) { case TYPE_CALL: { @@ -251,7 +226,7 @@ void MessageQueue::statistics() { read_pos+=sizeof(Message); - if (message->type!=TYPE_NOTIFICATION) + if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION) read_pos+=sizeof(Variant)*message->args; } @@ -322,6 +297,26 @@ int MessageQueue::get_max_buffer_usage() const { return buffer_max_used; } + +void MessageQueue::_call_function(Object* p_target, const StringName& p_func, const Variant *p_args, int p_argcount,bool p_show_error) { + + const Variant **argptrs=NULL; + if (p_argcount) { + argptrs = (const Variant**)alloca(sizeof(Variant*)*p_argcount); + for(int i=0;i<p_argcount;i++) { + argptrs[i]=&p_args[i]; + } + } + + Variant::CallError ce; + p_target->call(p_func,argptrs,p_argcount,ce); + if (p_show_error && ce.error!=Variant::CallError::CALL_OK) { + + ERR_PRINTS("Error calling deferred method: "+Variant::get_call_error_text(p_target,p_func,argptrs,p_argcount,ce)); + + } +} + void MessageQueue::flush() { @@ -347,7 +342,7 @@ void MessageQueue::flush() { if (target!=NULL) { - switch(message->type) { + switch(message->type&FLAG_MASK) { case TYPE_CALL: { Variant *args= (Variant*)(message+1); @@ -355,12 +350,7 @@ void MessageQueue::flush() { // messages don't expect a return value - target->call( message->target, - (message->args>=1) ? args[0] : Variant(), - (message->args>=2) ? args[1] : Variant(), - (message->args>=3) ? args[2] : Variant(), - (message->args>=4) ? args[3] : Variant(), - (message->args>=5) ? args[4] : Variant() ); + _call_function(target,message->target,args,message->args,message->type&FLAG_SHOW_ERROR); for(int i=0;i<message->args;i++) { args[i].~Variant(); @@ -386,7 +376,7 @@ void MessageQueue::flush() { } uint32_t advance = sizeof(Message); - if (message->type!=TYPE_NOTIFICATION) + if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION) advance+=sizeof(Variant)*message->args; message->~Message(); @@ -423,14 +413,14 @@ MessageQueue::~MessageQueue() { Message *message = (Message*)&buffer[ read_pos ]; Variant *args= (Variant*)(message+1); int argc = message->args; - if (message->type!=TYPE_NOTIFICATION) { + if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION) { for (int i=0;i<argc;i++) args[i].~Variant(); } message->~Message(); read_pos+=sizeof(Message); - if (message->type!=TYPE_NOTIFICATION) + if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION) read_pos+=sizeof(Variant)*message->args; } diff --git a/core/message_queue.h b/core/message_queue.h index b6b74d2bd2..6a3ec79732 100644 --- a/core/message_queue.h +++ b/core/message_queue.h @@ -46,7 +46,10 @@ class MessageQueue { enum { TYPE_CALL, TYPE_NOTIFICATION, - TYPE_SET + TYPE_SET, + FLAG_SHOW_ERROR=1<<14, + FLAG_MASK=FLAG_SHOW_ERROR-1 + }; struct Message { @@ -65,12 +68,14 @@ class MessageQueue { uint32_t buffer_max_used; uint32_t buffer_size; + void _call_function(Object* p_target,const StringName& p_func,const Variant *p_args,int p_argcount,bool p_show_error); static MessageQueue *singleton; public: static MessageQueue *get_singleton(); + Error push_call(ObjectID p_id,const StringName& p_method,const Variant** p_args,int p_argcount,bool p_show_error=false); Error push_call(ObjectID p_id, const StringName& p_method, VARIANT_ARG_LIST); Error push_notification(ObjectID p_id, int p_notification); Error push_set(ObjectID p_id, const StringName& p_prop, const Variant& p_value); diff --git a/core/object.cpp b/core/object.cpp index ad9fdf73b9..c92fc35b24 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -512,17 +512,10 @@ Variant Object::_call_deferred_bind(const Variant** p_args, int p_argcount, Vari r_error.error=Variant::CallError::CALL_OK; - StringName signal = *p_args[0]; - - Variant v[VARIANT_ARG_MAX]; - - - for(int i=0;i<MIN(5,p_argcount-1);i++) { + StringName method = *p_args[0]; - v[i]=*p_args[i+1]; - } + MessageQueue::get_singleton()->push_call(get_instance_ID(),method,&p_args[1],p_argcount-1); - call_deferred(signal,v[0],v[1],v[2],v[3],v[4]); return Variant(); } @@ -839,6 +832,8 @@ void Object::call_multilevel(const StringName& p_name, VARIANT_ARG_DECLARE) { Variant Object::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) { + r_error.error=Variant::CallError::CALL_OK; + if (p_method==CoreStringNames::get_singleton()->_free) { //free must be here, before anything, always ready #ifdef DEBUG_ENABLED @@ -1130,21 +1125,22 @@ Variant Object::_emit_signal(const Variant** p_args, int p_argcount, Variant::Ca StringName signal = *p_args[0]; - Variant v[VARIANT_ARG_MAX]; - - for(int i=0;i<MIN(5,p_argcount-1);i++) { + const Variant**args=NULL; - v[i]=*p_args[i+1]; + int argc=p_argcount-1; + if (argc) { + args=&p_args[1]; } - emit_signal(signal,v[0],v[1],v[2],v[3],v[4]); + emit_signal(signal,args,argc); + return Variant(); -} +} -void Object::emit_signal(const StringName& p_name,VARIANT_ARG_DECLARE) { +void Object::emit_signal(const StringName& p_name,const Variant** p_args,int p_argcount) { if (_block_signals) return; //no emit, signals blocked @@ -1167,10 +1163,12 @@ void Object::emit_signal(const StringName& p_name,VARIANT_ARG_DECLARE) { OBJ_DEBUG_LOCK + Vector<const Variant*> bind_mem; + + for(int i=0;i<ssize;i++) { const Connection &c = slot_map.getv(i).conn; - VARIANT_ARGPTRS Object *target; #ifdef DEBUG_ENABLED @@ -1181,21 +1179,37 @@ void Object::emit_signal(const StringName& p_name,VARIANT_ARG_DECLARE) { #endif - int bind_count=c.binds.size(); - int bind=0; + const Variant **args=p_args; + int argc=p_argcount; - for(int i=0;bind < bind_count && i<VARIANT_ARG_MAX;i++) { + if (c.binds.size()) { + //handle binds + bind_mem.resize(p_argcount+c.binds.size()); - if (argptr[i]->get_type()==Variant::NIL) { - argptr[i]=&c.binds[bind]; - bind++; + for(int j=0;j<p_argcount;j++) { + bind_mem[j]=p_args[j]; + } + for(int j=0;j<c.binds.size();j++) { + bind_mem[p_argcount+j]=&c.binds[j]; } + + args=bind_mem.ptr(); + argc=bind_mem.size(); } if (c.flags&CONNECT_DEFERRED) { - MessageQueue::get_singleton()->push_call(target->get_instance_ID(),c.method,VARIANT_ARGPTRS_PASS); + MessageQueue::get_singleton()->push_call(target->get_instance_ID(),c.method,args,argc,true); } else { - target->call( c.method, VARIANT_ARGPTRS_PASS ); + Variant::CallError ce; + target->call( c.method, args, argc,ce ); + if (ce.error!=Variant::CallError::CALL_OK) { + + if (ce.error==Variant::CallError::CALL_ERROR_INVALID_METHOD && !ObjectTypeDB::type_exists( target->get_type_name() ) ) { + //most likely object is not initialized yet, do not throw error. + } else { + ERR_PRINTS("Error calling method from signal '"+String(p_name)+"': "+Variant::get_call_error_text(target,c.method,args,argc,ce)); + } + } } if (c.flags&CONNECT_ONESHOT) { @@ -1208,57 +1222,29 @@ void Object::emit_signal(const StringName& p_name,VARIANT_ARG_DECLARE) { } -#if 0 - - //old (deprecated and dangerous code) - s->lock++; - for( Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.front();E;E=E->next() ) { - - const Signal::Target& t = E->key(); - const Signal::Slot& s = E->get(); - const Connection &c = s.cE->get(); - VARIANT_ARGPTRS + while (!disconnect_data.empty()) { - int bind_count=c.binds.size(); - int bind=0; + const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get(); + disconnect(dd.signal,dd.target,dd.method); + disconnect_data.pop_front(); + } - for(int i=0;bind < bind_count && i<VARIANT_ARG_MAX;i++) { +} - if (argptr[i]->get_type()==Variant::NIL) { - argptr[i]=&c.binds[bind]; - bind++; - } - } +void Object::emit_signal(const StringName& p_name,VARIANT_ARG_DECLARE) { - if (c.flags&CONNECT_DEFERRED) { - MessageQueue::get_singleton()->push_call(t._id,t.method,VARIANT_ARGPTRS_PASS); - } else { - Object *obj = ObjectDB::get_instance(t._id); - ERR_CONTINUE(!obj); //yeah this should always be here - obj->call( t.method, VARIANT_ARGPTRS_PASS ); - } + VARIANT_ARGPTRS; - if (c.flags&CONNECT_ONESHOT) { - _ObjectSignalDisconnectData dd; - dd.signal=p_name; - dd.target=ObjectDB::get_instance(t._id); - dd.method=t.method; - disconnect_data.push_back(dd); - } + int argc=0; + for(int i=0;i<VARIANT_ARG_MAX;i++) { + if (argptr[i]->get_type()==Variant::NIL) + break; + argc++; } - - - s->lock--; -#endif - while (!disconnect_data.empty()) { - - const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get(); - disconnect(dd.signal,dd.target,dd.method); - disconnect_data.pop_front(); - } + emit_signal(p_name,argptr,argc); } diff --git a/core/object.h b/core/object.h index 38a91d7898..dcebf9b2a2 100644 --- a/core/object.h +++ b/core/object.h @@ -593,6 +593,7 @@ public: void add_user_signal(const MethodInfo& p_signal); void emit_signal(const StringName& p_name,VARIANT_ARG_LIST); + void emit_signal(const StringName& p_name, const Variant** p_args, int p_argcount); void get_signal_list(List<MethodInfo> *p_signals ) const; void get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const; void get_all_signal_connections(List<Connection> *p_connections) const; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 25b10a76d3..2f39567a7e 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -156,6 +156,7 @@ bool InputEvent::is_pressed() const { case MOUSE_BUTTON: return mouse_button.pressed; case JOYSTICK_BUTTON: return joy_button.pressed; case SCREEN_TOUCH: return screen_touch.pressed; + case JOYSTICK_MOTION: return InputMap::get_singleton()->event_is_joy_motion_action_pressed(*this); case ACTION: return action.pressed; default: {} } diff --git a/core/os/input_event.h b/core/os/input_event.h index 12980e2a15..b601adc875 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -143,6 +143,9 @@ enum { JOY_ANALOG_2_X = JOY_AXIS_4, JOY_ANALOG_2_Y = JOY_AXIS_5, + + JOY_ANALOG_L2 = JOY_AXIS_6, + JOY_ANALOG_R2 = JOY_AXIS_7, }; diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 299572fbff..b56ff4c0e1 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -30,7 +30,7 @@ #include "os/os.h" #include "io/ip.h" #include "globals.h" - +#include "os/input.h" void ScriptDebuggerRemote::_send_video_memory() { List<ResourceUsage> usage; @@ -135,6 +135,10 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) { packet_peer_stream->put_var(p_can_continue); packet_peer_stream->put_var(p_script->debug_get_error()); + Input::MouseMode mouse_mode=Input::get_singleton()->get_mouse_mode(); + if (mouse_mode!=Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + while(true) { @@ -296,6 +300,9 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) { packet_peer_stream->put_var("debug_exit"); packet_peer_stream->put_var(0); + if (mouse_mode!=Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(mouse_mode); + } diff --git a/core/script_language.h b/core/script_language.h index a179949c19..3138c88e8e 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -98,6 +98,7 @@ public: virtual bool has_script_signal(const StringName& p_signal) const=0; virtual void get_script_signal_list(List<MethodInfo> *r_signals) const=0; + virtual bool get_property_default_value(const StringName& p_property,Variant& r_value) const=0; virtual void update_exports() {} //editor tool diff --git a/core/ustring.cpp b/core/ustring.cpp index c93fb80ca8..21c0d78fdb 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1636,12 +1636,16 @@ int64_t String::to_int64() const { return integer*sign; } -int String::to_int(const char* p_str) { +int String::to_int(const char* p_str,int p_len) { int to=0; - while(p_str[to]!=0 && p_str[to]!='.') - to++; + if (p_len>=0) + to=p_len; + else { + while(p_str[to]!=0 && p_str[to]!='.') + to++; + } int integer=0; diff --git a/core/ustring.h b/core/ustring.h index 4c76b8e863..2b967d368a 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -144,7 +144,7 @@ public: int to_int() const; int64_t to_int64() const; - static int to_int(const char* p_str); + static int to_int(const char* p_str, int p_len=-1); static double to_double(const char* p_str); static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); diff --git a/core/variant.cpp b/core/variant.cpp index ab560e0d45..3bd8d80528 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -706,6 +706,17 @@ bool Variant::operator==(const Variant& p_variant) const { } +bool Variant::operator!=(const Variant& p_variant) const { + + if (type!=p_variant.type) //evaluation of operator== needs to be more strict + return true; + bool v; + Variant r; + evaluate(OP_NOT_EQUAL,*this,p_variant,r,v); + return r; + +} + bool Variant::operator<(const Variant& p_variant) const { if (type!=p_variant.type) //if types differ, then order by type first return type<p_variant.type; @@ -2981,3 +2992,32 @@ String Variant::get_construct_string() const { return vars; } + +String Variant::get_call_error_text(Object* p_base, const StringName& p_method,const Variant** p_argptrs,int p_argcount,const Variant::CallError &ce) { + + + String err_text; + + if (ce.error==Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) { + int errorarg=ce.argument; + err_text="Cannot convert argument "+itos(errorarg+1)+" from "+Variant::get_type_name(p_argptrs[errorarg]->get_type())+" to "+Variant::get_type_name(ce.expected)+"."; + } else if (ce.error==Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { + err_text="Expected "+itos(ce.argument)+" arguments."; + } else if (ce.error==Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { + err_text="Expected "+itos(ce.argument)+" arguments."; + } else if (ce.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) { + err_text="Method not found."; + } else if (ce.error==Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) { + err_text="Instance is null"; + } else if (ce.error==Variant::CallError::CALL_OK){ + return "Call OK"; + } + + String class_name = p_base->get_type(); + Ref<Script> script = p_base->get_script(); + if (script.is_valid() && script->get_path().is_resource_file()) { + + class_name+="("+script->get_path().get_file()+")"; + } + return "'"+class_name+"::"+String(p_method)+"': "+err_text; +} diff --git a/core/variant.h b/core/variant.h index 05bb5a7328..b58c781bdd 100644 --- a/core/variant.h +++ b/core/variant.h @@ -390,6 +390,9 @@ public: Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,CallError &r_error); Variant call(const StringName& p_method,const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant()); + + static String get_call_error_text(Object* p_base, const StringName& p_method,const Variant** p_argptrs,int p_argcount,const Variant::CallError &ce); + static Variant construct(const Variant::Type,const Variant** p_args,int p_argcount,CallError &r_error,bool p_strict=true); void get_method_list(List<MethodInfo> *p_list) const; @@ -411,6 +414,7 @@ public: //argsVariant call() bool operator==(const Variant& p_variant) const; + bool operator!=(const Variant& p_variant) const; bool operator<(const Variant& p_variant) const; uint32_t hash() const; diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 9218406e0f..204a00e1d5 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1003,7 +1003,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) return; } - *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length()); + *str = str->substr(0,idx)+chr+str->substr(idx+1,str->length()); valid=true; return; @@ -1364,7 +1364,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) valid=true; v->b=float(p_value)/255.0; return; - } else if (*str=="a8" ) { + } else if (*str=="a8" ) {\ valid=true; v->a=float(p_value)/255.0; return; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 3c8c43f5b3..9f2727d33d 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1072,8 +1072,24 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in ie.joy_motion.axis = token.value; get_token(p_stream,token,line,r_err_str); + + if (token.type!=TK_COMMA) { + r_err_str="Expected ',' after axis index"; + return ERR_PARSE_ERROR; + } + + get_token(p_stream,token,line,r_err_str); + if (token.type!=TK_NUMBER) { + r_err_str="Expected axis sign"; + return ERR_PARSE_ERROR; + } + + ie.joy_motion.axis_value = token.value; + + get_token(p_stream,token,line,r_err_str); + if (token.type!=TK_PARENTHESIS_CLOSE) { - r_err_str="Expected ')'"; + r_err_str="Expected ')' for jaxis"; return ERR_PARSE_ERROR; } @@ -1339,7 +1355,9 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in InputEvent ie; ie.type=InputEvent::JOYSTICK_MOTION; ie.device=params[0].to_int(); - ie.joy_motion.axis=params[1].to_int(); + int axis=params[1].to_int(); + ie.joy_motion.axis=axis>>1; + ie.joy_motion.axis_value=axis&1?1:-1; value= ie; |