diff options
Diffstat (limited to 'core/event_queue.cpp')
-rw-r--r-- | core/event_queue.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/core/event_queue.cpp b/core/event_queue.cpp index 088e80b266..53638c5431 100644 --- a/core/event_queue.cpp +++ b/core/event_queue.cpp @@ -43,118 +43,118 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method, args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; - + room_needed+=sizeof(Variant)*args; - + ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY ); Event * ev = memnew_placement( &event_buffer[ buffer_end ], Event ); ev->args=args; ev->instance_ID=p_instance_ID; ev->method=p_method; - + buffer_end+=sizeof(Event); - + if (args>=1) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg1; } if (args>=2) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg2; } if (args>=3) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg3; - + } if (args>=4) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg4; } if (args>=5) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg5; } - + if (buffer_max_used>buffer_end); buffer_max_used=buffer_end; - + return OK; } void EventQueue::flush_events() { uint32_t read_pos=0; - + while (read_pos < buffer_end ) { - + Event *event = (Event*)&event_buffer[ read_pos ]; Variant *args= (Variant*)(event+1); Object *obj = ObjectDB::get_instance(event->instance_ID); - - if (obj) { + + if (obj) { // events don't expect a return value - obj->call( event->method, + obj->call( event->method, (event->args>=1) ? args[0] : Variant(), (event->args>=2) ? args[1] : Variant(), (event->args>=3) ? args[2] : Variant(), (event->args>=4) ? args[3] : Variant(), (event->args>=5) ? args[4] : Variant() ); } - + if (event->args>=1) args[0].~Variant(); if (event->args>=2) args[1].~Variant(); if (event->args>=3) args[2].~Variant(); if (event->args>=4) args[3].~Variant(); if (event->args>=5) args[4].~Variant(); event->~Event(); - + read_pos+=sizeof(Event)+sizeof(Variant)*event->args; } - + buffer_end=0; // reset buffer } EventQueue::EventQueue(uint32_t p_buffer_size) { - + buffer_end=0; buffer_max_used=0; buffer_size=p_buffer_size; event_buffer = memnew_arr( uint8_t, buffer_size ); - + } EventQueue::~EventQueue() { uint32_t read_pos=0; - + while (read_pos < buffer_end ) { - + Event *event = (Event*)&event_buffer[ read_pos ]; Variant *args= (Variant*)(event+1); for (int i=0;i<event->args;i++) args[i].~Variant(); event->~Event(); - + read_pos+=sizeof(Event)+sizeof(Variant)*event->args; } - + memdelete_arr(event_buffer); event_buffer=NULL; } |