mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
parent
1d418afe86
commit
f8db8a3faa
1308 changed files with 147754 additions and 174357 deletions
|
|
@ -29,95 +29,90 @@
|
|||
#include "message_queue.h"
|
||||
#include "globals.h"
|
||||
#include "script_language.h"
|
||||
MessageQueue *MessageQueue::singleton=NULL;
|
||||
MessageQueue *MessageQueue::singleton = NULL;
|
||||
|
||||
MessageQueue *MessageQueue::get_singleton() {
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
Error MessageQueue::push_call(ObjectID p_id,const StringName& p_method,const Variant** p_args,int p_argcount,bool p_show_error) {
|
||||
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_
|
||||
|
||||
int room_needed=sizeof(Message)+sizeof(Variant)*p_argcount;
|
||||
int room_needed = sizeof(Message) + sizeof(Variant) * p_argcount;
|
||||
|
||||
if ((buffer_end+room_needed) >= buffer_size) {
|
||||
if ((buffer_end + room_needed) >= buffer_size) {
|
||||
String type;
|
||||
if (ObjectDB::get_instance(p_id))
|
||||
type=ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed method: "+type+":"+p_method+" target ID: "+itos(p_id));
|
||||
type = ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed method: " + type + ":" + p_method + " target ID: " + itos(p_id));
|
||||
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=p_argcount;
|
||||
msg->instance_ID=p_id;
|
||||
msg->target=p_method;
|
||||
msg->type=TYPE_CALL;
|
||||
ERR_FAIL_COND_V((buffer_end + room_needed) >= buffer_size, ERR_OUT_OF_MEMORY);
|
||||
Message *msg = memnew_placement(&buffer[buffer_end], Message);
|
||||
msg->args = p_argcount;
|
||||
msg->instance_ID = p_id;
|
||||
msg->target = p_method;
|
||||
msg->type = TYPE_CALL;
|
||||
if (p_show_error)
|
||||
msg->type|=FLAG_SHOW_ERROR;
|
||||
msg->type |= FLAG_SHOW_ERROR;
|
||||
|
||||
buffer_end+=sizeof(Message);
|
||||
buffer_end += sizeof(Message);
|
||||
|
||||
for(int i=0;i<p_argcount;i++) {
|
||||
|
||||
Variant * v = memnew_placement( &buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=*p_args[i];
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
|
||||
Variant *v = memnew_placement(&buffer[buffer_end], Variant);
|
||||
buffer_end += sizeof(Variant);
|
||||
*v = *p_args[i];
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
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, VARIANT_ARG_DECLARE) {
|
||||
|
||||
VARIANT_ARGPTRS;
|
||||
|
||||
int argc=0;
|
||||
int argc = 0;
|
||||
|
||||
for(int i=0;i<VARIANT_ARG_MAX;i++) {
|
||||
if (argptr[i]->get_type()==Variant::NIL)
|
||||
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
|
||||
if (argptr[i]->get_type() == Variant::NIL)
|
||||
break;
|
||||
argc++;
|
||||
}
|
||||
|
||||
return push_call(p_id,p_method,argptr,argc,false);
|
||||
|
||||
return push_call(p_id, p_method, argptr, argc, false);
|
||||
}
|
||||
|
||||
Error MessageQueue::push_set(ObjectID p_id, const StringName& p_prop, const Variant& p_value) {
|
||||
Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
uint8_t room_needed=sizeof(Message)+sizeof(Variant);
|
||||
uint8_t room_needed = sizeof(Message) + sizeof(Variant);
|
||||
|
||||
if ((buffer_end+room_needed) >= buffer_size) {
|
||||
if ((buffer_end + room_needed) >= buffer_size) {
|
||||
String type;
|
||||
if (ObjectDB::get_instance(p_id))
|
||||
type=ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed set: "+type+":"+p_prop+" target ID: "+itos(p_id));
|
||||
type = ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed set: " + type + ":" + p_prop + " target ID: " + itos(p_id));
|
||||
statistics();
|
||||
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY );
|
||||
ERR_FAIL_COND_V((buffer_end + room_needed) >= buffer_size, ERR_OUT_OF_MEMORY);
|
||||
|
||||
Message * msg = memnew_placement( &buffer[ buffer_end ], Message );
|
||||
msg->args=1;
|
||||
msg->instance_ID=p_id;
|
||||
msg->target=p_prop;
|
||||
msg->type=TYPE_SET;
|
||||
Message *msg = memnew_placement(&buffer[buffer_end], Message);
|
||||
msg->args = 1;
|
||||
msg->instance_ID = p_id;
|
||||
msg->target = p_prop;
|
||||
msg->type = TYPE_SET;
|
||||
|
||||
buffer_end+=sizeof(Message);
|
||||
|
||||
Variant * v = memnew_placement( &buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_value;
|
||||
buffer_end += sizeof(Message);
|
||||
|
||||
Variant *v = memnew_placement(&buffer[buffer_end], Variant);
|
||||
buffer_end += sizeof(Variant);
|
||||
*v = p_value;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
@ -126,73 +121,66 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
|
|||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
ERR_FAIL_COND_V(p_notification<0, ERR_INVALID_PARAMETER );
|
||||
ERR_FAIL_COND_V(p_notification < 0, ERR_INVALID_PARAMETER);
|
||||
|
||||
uint8_t room_needed=sizeof(Message);
|
||||
uint8_t room_needed = sizeof(Message);
|
||||
|
||||
if ((buffer_end+room_needed) >= buffer_size) {
|
||||
if ((buffer_end + room_needed) >= buffer_size) {
|
||||
String type;
|
||||
if (ObjectDB::get_instance(p_id))
|
||||
type=ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed notification: "+itos(p_notification)+" target ID: "+itos(p_id));
|
||||
type = ObjectDB::get_instance(p_id)->get_type();
|
||||
print_line("failed notification: " + itos(p_notification) + " target ID: " + itos(p_id));
|
||||
statistics();
|
||||
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V((buffer_end + room_needed) >= buffer_size, ERR_OUT_OF_MEMORY);
|
||||
Message *msg = memnew_placement(&buffer[buffer_end], Message);
|
||||
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY );
|
||||
Message * msg = memnew_placement( &buffer[ buffer_end ], Message );
|
||||
|
||||
msg->type=TYPE_NOTIFICATION;
|
||||
msg->instance_ID=p_id;
|
||||
msg->type = TYPE_NOTIFICATION;
|
||||
msg->instance_ID = p_id;
|
||||
//msg->target;
|
||||
msg->notification=p_notification;
|
||||
|
||||
buffer_end+=sizeof(Message);
|
||||
msg->notification = p_notification;
|
||||
|
||||
buffer_end += sizeof(Message);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error MessageQueue::push_call(Object *p_object, const StringName& p_method, VARIANT_ARG_DECLARE) {
|
||||
Error MessageQueue::push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) {
|
||||
|
||||
return push_call(p_object->get_instance_ID(),p_method,VARIANT_ARG_PASS);
|
||||
return push_call(p_object->get_instance_ID(), p_method, VARIANT_ARG_PASS);
|
||||
}
|
||||
|
||||
Error MessageQueue::push_notification(Object *p_object, int p_notification) {
|
||||
|
||||
return push_notification(p_object->get_instance_ID(),p_notification);
|
||||
return push_notification(p_object->get_instance_ID(), p_notification);
|
||||
}
|
||||
Error MessageQueue::push_set(Object *p_object, const StringName& p_prop, const Variant& p_value) {
|
||||
Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const Variant &p_value) {
|
||||
|
||||
return push_set(p_object->get_instance_ID(),p_prop,p_value);
|
||||
return push_set(p_object->get_instance_ID(), p_prop, p_value);
|
||||
}
|
||||
|
||||
|
||||
void MessageQueue::statistics() {
|
||||
|
||||
Map<StringName,int> set_count;
|
||||
Map<int,int> notify_count;
|
||||
Map<StringName,int> call_count;
|
||||
int null_count=0;
|
||||
Map<StringName, int> set_count;
|
||||
Map<int, int> notify_count;
|
||||
Map<StringName, int> call_count;
|
||||
int null_count = 0;
|
||||
|
||||
uint32_t read_pos=0;
|
||||
while (read_pos < buffer_end ) {
|
||||
Message *message = (Message*)&buffer[ read_pos ];
|
||||
uint32_t read_pos = 0;
|
||||
while (read_pos < buffer_end) {
|
||||
Message *message = (Message *)&buffer[read_pos];
|
||||
|
||||
Object *target = ObjectDB::get_instance(message->instance_ID);
|
||||
|
||||
if (target!=NULL) {
|
||||
if (target != NULL) {
|
||||
|
||||
|
||||
switch(message->type&FLAG_MASK) {
|
||||
switch (message->type & FLAG_MASK) {
|
||||
|
||||
case TYPE_CALL: {
|
||||
|
||||
if (!call_count.has(message->target))
|
||||
call_count[message->target]=0;
|
||||
call_count[message->target] = 0;
|
||||
|
||||
call_count[message->target]++;
|
||||
|
||||
|
|
@ -200,7 +188,7 @@ void MessageQueue::statistics() {
|
|||
case TYPE_NOTIFICATION: {
|
||||
|
||||
if (!notify_count.has(message->notification))
|
||||
notify_count[message->notification]=0;
|
||||
notify_count[message->notification] = 0;
|
||||
|
||||
notify_count[message->notification]++;
|
||||
|
||||
|
|
@ -208,12 +196,11 @@ void MessageQueue::statistics() {
|
|||
case TYPE_SET: {
|
||||
|
||||
if (!set_count.has(message->target))
|
||||
set_count[message->target]=0;
|
||||
set_count[message->target] = 0;
|
||||
|
||||
set_count[message->target]++;
|
||||
|
||||
} break;
|
||||
|
||||
}
|
||||
|
||||
//object was deleted
|
||||
|
|
@ -224,31 +211,28 @@ void MessageQueue::statistics() {
|
|||
null_count++;
|
||||
}
|
||||
|
||||
|
||||
read_pos+=sizeof(Message);
|
||||
if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION)
|
||||
read_pos+=sizeof(Variant)*message->args;
|
||||
read_pos += sizeof(Message);
|
||||
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
|
||||
read_pos += sizeof(Variant) * message->args;
|
||||
}
|
||||
|
||||
print_line("TOTAL BYTES: " + itos(buffer_end));
|
||||
print_line("NULL count: " + itos(null_count));
|
||||
|
||||
print_line("TOTAL BYTES: "+itos(buffer_end));
|
||||
print_line("NULL count: "+itos(null_count));
|
||||
for (Map<StringName, int>::Element *E = set_count.front(); E; E = E->next()) {
|
||||
|
||||
for(Map<StringName,int>::Element *E=set_count.front();E;E=E->next()) {
|
||||
|
||||
print_line("SET "+E->key()+": "+itos(E->get()));
|
||||
print_line("SET " + E->key() + ": " + itos(E->get()));
|
||||
}
|
||||
|
||||
for(Map<StringName,int>::Element *E=call_count.front();E;E=E->next()) {
|
||||
for (Map<StringName, int>::Element *E = call_count.front(); E; E = E->next()) {
|
||||
|
||||
print_line("CALL "+E->key()+": "+itos(E->get()));
|
||||
print_line("CALL " + E->key() + ": " + itos(E->get()));
|
||||
}
|
||||
|
||||
for(Map<int,int>::Element *E=notify_count.front();E;E=E->next()) {
|
||||
for (Map<int, int>::Element *E = notify_count.front(); E; E = E->next()) {
|
||||
|
||||
print_line("NOTIFY "+itos(E->key())+": "+itos(E->get()));
|
||||
print_line("NOTIFY " + itos(E->key()) + ": " + itos(E->get()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MessageQueue::print() {
|
||||
|
|
@ -297,62 +281,58 @@ 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) {
|
||||
|
||||
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;
|
||||
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];
|
||||
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));
|
||||
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() {
|
||||
|
||||
|
||||
if (buffer_end > buffer_max_used) {
|
||||
buffer_max_used=buffer_end;
|
||||
buffer_max_used = buffer_end;
|
||||
//statistics();
|
||||
}
|
||||
|
||||
uint32_t read_pos=0;
|
||||
uint32_t read_pos = 0;
|
||||
|
||||
//using reverse locking strategy
|
||||
_THREAD_SAFE_LOCK_
|
||||
|
||||
while (read_pos<buffer_end) {
|
||||
while (read_pos < buffer_end) {
|
||||
|
||||
_THREAD_SAFE_UNLOCK_
|
||||
|
||||
//lock on each interation, so a call can re-add itself to the message queue
|
||||
|
||||
Message *message = (Message*)&buffer[ read_pos ];
|
||||
Message *message = (Message *)&buffer[read_pos];
|
||||
|
||||
Object *target = ObjectDB::get_instance(message->instance_ID);
|
||||
|
||||
if (target!=NULL) {
|
||||
if (target != NULL) {
|
||||
|
||||
switch(message->type&FLAG_MASK) {
|
||||
switch (message->type & FLAG_MASK) {
|
||||
case TYPE_CALL: {
|
||||
|
||||
Variant *args= (Variant*)(message+1);
|
||||
Variant *args = (Variant *)(message + 1);
|
||||
|
||||
// messages don't expect a return value
|
||||
|
||||
_call_function(target, message->target, args, message->args, message->type & FLAG_SHOW_ERROR);
|
||||
|
||||
_call_function(target,message->target,args,message->args,message->type&FLAG_SHOW_ERROR);
|
||||
|
||||
for(int i=0;i<message->args;i++) {
|
||||
for (int i = 0; i < message->args; i++) {
|
||||
args[i].~Variant();
|
||||
}
|
||||
|
||||
|
|
@ -365,65 +345,60 @@ void MessageQueue::flush() {
|
|||
} break;
|
||||
case TYPE_SET: {
|
||||
|
||||
Variant *arg= (Variant*)(message+1);
|
||||
Variant *arg = (Variant *)(message + 1);
|
||||
// messages don't expect a return value
|
||||
target->set(message->target,*arg);
|
||||
target->set(message->target, *arg);
|
||||
|
||||
arg->~Variant();
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32_t advance = sizeof(Message);
|
||||
if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION)
|
||||
advance+=sizeof(Variant)*message->args;
|
||||
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
|
||||
advance += sizeof(Variant) * message->args;
|
||||
message->~Message();
|
||||
|
||||
_THREAD_SAFE_LOCK_
|
||||
read_pos+=advance;
|
||||
|
||||
read_pos += advance;
|
||||
}
|
||||
|
||||
|
||||
buffer_end=0; // reset buffer
|
||||
buffer_end = 0; // reset buffer
|
||||
_THREAD_SAFE_UNLOCK_
|
||||
|
||||
}
|
||||
|
||||
MessageQueue::MessageQueue() {
|
||||
|
||||
ERR_FAIL_COND(singleton!=NULL);
|
||||
singleton=this;
|
||||
ERR_FAIL_COND(singleton != NULL);
|
||||
singleton = this;
|
||||
|
||||
buffer_end=0;
|
||||
buffer_max_used=0;
|
||||
buffer_size=GLOBAL_DEF( "core/message_queue_size_kb", DEFAULT_QUEUE_SIZE_KB );
|
||||
buffer_size*=1024;
|
||||
buffer = memnew_arr( uint8_t, buffer_size );
|
||||
buffer_end = 0;
|
||||
buffer_max_used = 0;
|
||||
buffer_size = GLOBAL_DEF("core/message_queue_size_kb", DEFAULT_QUEUE_SIZE_KB);
|
||||
buffer_size *= 1024;
|
||||
buffer = memnew_arr(uint8_t, buffer_size);
|
||||
}
|
||||
|
||||
|
||||
MessageQueue::~MessageQueue() {
|
||||
|
||||
uint32_t read_pos=0;
|
||||
uint32_t read_pos = 0;
|
||||
|
||||
while (read_pos < buffer_end ) {
|
||||
while (read_pos < buffer_end) {
|
||||
|
||||
Message *message = (Message*)&buffer[ read_pos ];
|
||||
Variant *args= (Variant*)(message+1);
|
||||
Message *message = (Message *)&buffer[read_pos];
|
||||
Variant *args = (Variant *)(message + 1);
|
||||
int argc = message->args;
|
||||
if ((message->type&FLAG_MASK)!=TYPE_NOTIFICATION) {
|
||||
for (int i=0;i<argc;i++)
|
||||
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&FLAG_MASK)!=TYPE_NOTIFICATION)
|
||||
read_pos+=sizeof(Variant)*message->args;
|
||||
read_pos += sizeof(Message);
|
||||
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
|
||||
read_pos += sizeof(Variant) * message->args;
|
||||
}
|
||||
|
||||
singleton=NULL;
|
||||
memdelete_arr( buffer );
|
||||
singleton = NULL;
|
||||
memdelete_arr(buffer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue