MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / push_callablep

Method push_callablep

core/object/message_queue.cpp:94–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94Error CallQueue::push_callablep(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) {
95 uint32_t room_needed = sizeof(Message) + sizeof(Variant) * p_argcount;
96
97 ERR_FAIL_COND_V_MSG(room_needed > uint32_t(PAGE_SIZE_BYTES), ERR_INVALID_PARAMETER, "Message is too large to fit on a page (" + itos(PAGE_SIZE_BYTES) + " bytes), consider passing less arguments.");
98
99 LOCK_MUTEX;
100
101 _ensure_first_page();
102
103 if ((page_bytes[pages_used - 1] + room_needed) > uint32_t(PAGE_SIZE_BYTES)) {
104 if (pages_used == max_pages) {
105 fprintf(stderr, "Failed method: %s. Message queue out of memory. %s\n", String(p_callable).utf8().get_data(), error_text.utf8().get_data());
106 statistics();
107 UNLOCK_MUTEX;
108 return ERR_OUT_OF_MEMORY;
109 }
110 _add_page();
111 }
112
113 Page *page = pages[pages_used - 1];
114
115 uint8_t *buffer_end = &page->data[page_bytes[pages_used - 1]];
116
117 Message *msg = memnew_placement(buffer_end, Message);
118 msg->args = p_argcount;
119 msg->callable = p_callable;
120 msg->type = TYPE_CALL;
121 if (p_show_error) {
122 msg->type |= FLAG_SHOW_ERROR;
123 }
124 // Support callables of static methods.
125 if (p_callable.get_object_id().is_null() && p_callable.is_valid()) {
126 msg->type |= FLAG_NULL_IS_OK;
127 }
128
129 buffer_end += sizeof(Message);
130
131 for (int i = 0; i < p_argcount; i++) {
132 Variant *v = memnew_placement(buffer_end, Variant);
133 buffer_end += sizeof(Variant);
134 *v = *p_args[i];
135 }
136
137 page_bytes[pages_used - 1] += room_needed;
138
139 UNLOCK_MUTEX;
140
141 return OK;
142}
143
144Error CallQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) {
145 LOCK_MUTEX;

Callers 2

call_deferredpMethod · 0.80
emit_signalpMethod · 0.80

Calls 7

itosFunction · 0.85
StringClass · 0.50
get_dataMethod · 0.45
utf8Method · 0.45
is_nullMethod · 0.45
get_object_idMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected