Added virtual _execute to threadPoolJob.

This commit is contained in:
Relintai 2023-06-05 09:05:16 +02:00
parent 645045f97c
commit 9a2a39923a
2 changed files with 12 additions and 4 deletions

View File

@ -107,18 +107,18 @@ bool ThreadPoolJob::should_do(const bool just_check) {
return true; return true;
} }
bool ThreadPoolJob::should_return() { bool ThreadPoolJob::should_return() {
if (_cancelled) if (_cancelled) {
return true; return true;
}
if (_max_allocated_time < 0.00001) if (_max_allocated_time < 0.00001) {
return false; return false;
}
return get_current_execution_time() >= _max_allocated_time; return get_current_execution_time() >= _max_allocated_time;
} }
void ThreadPoolJob::execute() { void ThreadPoolJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
_current_run_stage = 0; _current_run_stage = 0;
_start_time = OS::get_singleton()->get_system_time_msecs(); _start_time = OS::get_singleton()->get_system_time_msecs();
@ -126,6 +126,12 @@ void ThreadPoolJob::execute() {
call("_execute"); call("_execute");
} }
void ThreadPoolJob::_execute() {
set_complete(true);
ERR_FAIL_MSG(get_class() + " ThreadPoolJob::_execute is not overridden!");
}
ThreadPoolJob::ThreadPoolJob() { ThreadPoolJob::ThreadPoolJob() {
_complete = true; _complete = true;
_cancelled = false; _cancelled = false;
@ -181,6 +187,7 @@ void ThreadPoolJob::_bind_methods() {
BIND_VMETHOD(MethodInfo("_execute")); BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &ThreadPoolJob::execute); ClassDB::bind_method(D_METHOD("execute"), &ThreadPoolJob::execute);
ClassDB::bind_method(D_METHOD("_execute"), &ThreadPoolJob::_execute);
ADD_SIGNAL(MethodInfo("completed")); ADD_SIGNAL(MethodInfo("completed"));
} }

View File

@ -63,6 +63,7 @@ public:
bool should_return(); bool should_return();
void execute(); void execute();
virtual void _execute();
ThreadPoolJob(); ThreadPoolJob();
~ThreadPoolJob(); ~ThreadPoolJob();