| 1200 | } |
| 1201 | |
| 1202 | void Input::parse_input_event(const Ref<InputEvent> &p_event) { |
| 1203 | _THREAD_SAFE_METHOD_ |
| 1204 | |
| 1205 | ERR_FAIL_COND(p_event.is_null()); |
| 1206 | |
| 1207 | #ifdef DEBUG_ENABLED |
| 1208 | uint64_t curr_frame = Engine::get_singleton()->get_process_frames(); |
| 1209 | if (curr_frame != last_parsed_frame) { |
| 1210 | frame_parsed_events.clear(); |
| 1211 | last_parsed_frame = curr_frame; |
| 1212 | frame_parsed_events.insert(p_event); |
| 1213 | } else if (frame_parsed_events.has(p_event)) { |
| 1214 | // It would be technically safe to send the same event in cases such as: |
| 1215 | // - After an explicit flush. |
| 1216 | // - In platforms using buffering when agile flushing is enabled, after one of the mid-frame flushes. |
| 1217 | // - If platform doesn't use buffering and event accumulation is disabled. |
| 1218 | // - If platform doesn't use buffering and the event type is not accumulable. |
| 1219 | // However, it wouldn't be reasonable to ask users to remember the full ruleset and be aware at all times |
| 1220 | // of the possibilities of the target platform, project settings and engine internals, which may change |
| 1221 | // without prior notice. |
| 1222 | // Therefore, the guideline is, "don't send the same event object more than once per frame". |
| 1223 | WARN_PRINT_ONCE( |
| 1224 | "An input event object is being parsed more than once in the same frame, which is unsafe.\n" |
| 1225 | "If you are generating events in a script, you have to instantiate a new event instead of sending the same one more than once, unless the original one was sent on an earlier frame.\n" |
| 1226 | "You can call duplicate() on the event to get a new instance with identical values."); |
| 1227 | } else { |
| 1228 | frame_parsed_events.insert(p_event); |
| 1229 | } |
| 1230 | #endif |
| 1231 | |
| 1232 | if (use_accumulated_input) { |
| 1233 | if (buffered_events.is_empty() || !buffered_events.back()->get()->accumulate(p_event)) { |
| 1234 | buffered_events.push_back(p_event); |
| 1235 | } |
| 1236 | } else if (agile_input_event_flushing) { |
| 1237 | buffered_events.push_back(p_event); |
| 1238 | } else { |
| 1239 | _parse_input_event_impl(p_event, false); |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | #ifdef DEBUG_ENABLED |
| 1244 | void Input::flush_frame_parsed_events() { |
no test coverage detected