Moved ThreadPool to core. Also it can change it's thread count now when it has time for it.

This commit is contained in:
Relintai 2022-09-10 04:16:50 +02:00
parent d10db3fddd
commit 27316923d3
49 changed files with 153 additions and 1407 deletions

View File

@ -41,6 +41,7 @@ bool ThreadPool::get_use_threads() const {
}
void ThreadPool::set_use_threads(const bool value) {
_use_threads = value;
_dirty = true;
}
int ThreadPool::get_thread_count() const {
@ -48,6 +49,7 @@ int ThreadPool::get_thread_count() const {
}
void ThreadPool::set_thread_count(const bool value) {
_thread_count = value;
_dirty = true;
}
int ThreadPool::get_thread_fallback_count() const {
@ -55,6 +57,7 @@ int ThreadPool::get_thread_fallback_count() const {
}
void ThreadPool::set_thread_fallback_count(const bool value) {
_thread_fallback_count = value;
_dirty = true;
}
float ThreadPool::get_max_work_per_frame_percent() const {
@ -62,6 +65,7 @@ float ThreadPool::get_max_work_per_frame_percent() const {
}
void ThreadPool::set_max_work_per_frame_percent(const bool value) {
_max_work_per_frame_percent = value;
_dirty = true;
}
float ThreadPool::get_max_time_per_frame() const {
@ -69,6 +73,42 @@ float ThreadPool::get_max_time_per_frame() const {
}
void ThreadPool::set_max_time_per_frame(const bool value) {
_max_time_per_frame = value;
_dirty = true;
}
bool ThreadPool::is_working() const {
_THREAD_SAFE_LOCK_
if (_queue.size() > 0) {
_THREAD_SAFE_UNLOCK_
return true;
}
for (int i = 0; i < _threads.size(); ++i) {
if (_threads[i]->job.is_valid()) {
_THREAD_SAFE_UNLOCK_
return true;
}
}
_THREAD_SAFE_UNLOCK_
return false;
}
bool ThreadPool::is_working_no_lock() const {
if (_queue.size() > 0) {
return true;
}
for (int i = 0; i < _threads.size(); ++i) {
if (_threads[i]->job.is_valid()) {
return true;
}
}
return false;
}
bool ThreadPool::has_job(const Ref<ThreadPoolJob> &job) {
@ -189,11 +229,15 @@ void ThreadPool::_worker_thread_func(void *user_data) {
}
}
void ThreadPool::register_update() {
SceneTree::get_singleton()->connect("idle_frame", this, "update");
}
void ThreadPool::update() {
if (_dirty) {
apply_settings();
}
if (_use_threads) {
return;
}
if (_queue.size() == 0) {
return;
}
@ -219,9 +263,7 @@ void ThreadPool::update() {
}
}
ThreadPool::ThreadPool() {
_instance = this;
void ThreadPool::register_core_settings() {
_use_threads = GLOBAL_DEF("thread_pool/use_threads", true);
_thread_count = GLOBAL_DEF("thread_pool/thread_count", -1);
_thread_fallback_count = GLOBAL_DEF("thread_pool/thread_fallback_count", 4);
@ -251,7 +293,43 @@ ThreadPool::ThreadPool() {
if (_thread_count <= 0) {
_thread_count = _thread_fallback_count;
}
}
_dirty = true;
apply_settings();
}
void ThreadPool::apply_settings() {
if (!_dirty) {
return;
}
_THREAD_SAFE_LOCK_
if (is_working_no_lock()) {
_THREAD_SAFE_UNLOCK_
return;
}
_dirty = false;
for (int i = 0; i < _threads.size(); ++i) {
ThreadPoolContext *context = _threads[i];
CRASH_COND(context->job.is_valid());
context->running = false;
context->semaphore->post();
context->thread->wait_to_finish();
memdelete(context->thread);
memdelete(context->semaphore);
memdelete(context);
}
_threads.resize(0);
if (_use_threads) {
_threads.resize(_thread_count);
for (int i = 0; i < _threads.size(); ++i) {
@ -265,9 +343,14 @@ ThreadPool::ThreadPool() {
_threads.write[i] = context;
}
} else {
call_deferred("register_update");
}
_THREAD_SAFE_UNLOCK_
}
ThreadPool::ThreadPool() {
_instance = this;
_dirty = false;
}
ThreadPool::~ThreadPool() {
@ -315,12 +398,14 @@ void ThreadPool::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_max_time_per_frame", "value"), &ThreadPool::set_max_time_per_frame);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_time_per_frame"), "set_max_time_per_frame", "get_max_time_per_frame");
ClassDB::bind_method(D_METHOD("is_working"), &ThreadPool::is_working);
ClassDB::bind_method(D_METHOD("is_working_no_lock"), &ThreadPool::is_working_no_lock);
ClassDB::bind_method(D_METHOD("has_job", "job"), &ThreadPool::has_job);
ClassDB::bind_method(D_METHOD("add_job", "job"), &ThreadPool::add_job);
ClassDB::bind_method(D_METHOD("cancel_job", "job"), &ThreadPool::cancel_job);
ClassDB::bind_method(D_METHOD("cancel_job_wait", "job"), &ThreadPool::cancel_job_wait);
ClassDB::bind_method(D_METHOD("register_update"), &ThreadPool::register_update);
ClassDB::bind_method(D_METHOD("update"), &ThreadPool::update);
}

View File

@ -25,9 +25,9 @@ SOFTWARE.
*/
#include "core/object/object.h"
#include "core/containers/vector.h"
#include "core/containers/list.h"
#include "core/containers/vector.h"
#include "core/object/object.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
@ -72,6 +72,9 @@ public:
float get_max_time_per_frame() const;
void set_max_time_per_frame(const bool value);
bool is_working() const;
bool is_working_no_lock() const;
bool has_job(const Ref<ThreadPoolJob> &job);
void add_job(const Ref<ThreadPoolJob> &job);
@ -81,9 +84,12 @@ public:
void _thread_finished(ThreadPoolContext *context);
static void _worker_thread_func(void *user_data);
void register_update();
void update();
void register_core_settings();
void apply_settings();
ThreadPool();
~ThreadPool();
@ -93,6 +99,7 @@ protected:
private:
static ThreadPool *_instance;
bool _dirty;
bool _use_threads;
int _thread_count;
int _thread_fallback_count;

View File

@ -31,14 +31,14 @@
#include "register_core_types.h"
#include "core/bind/core_bind.h"
#include "core/object/class_db.h"
#include "core/string/compressed_translation.h"
#include "core/config/engine.h"
#include "core/config/project_settings.h"
#include "core/containers/packed_data_container.h"
#include "core/core_string_names.h"
#include "core/crypto/aes_context.h"
#include "core/crypto/crypto.h"
#include "core/crypto/hashing_context.h"
#include "core/config/engine.h"
#include "core/object/func_ref.h"
#include "core/input/input.h"
#include "core/input/input_map.h"
#include "core/io/config_file.h"
#include "core/io/dtls_server.h"
@ -65,13 +65,17 @@
#include "core/math/geometry.h"
#include "core/math/random_number_generator.h"
#include "core/math/triangle_mesh.h"
#include "core/input/input.h"
#include "core/object/class_db.h"
#include "core/object/func_ref.h"
#include "core/object/undo_redo.h"
#include "core/os/main_loop.h"
#include "core/os/time.h"
#include "core/containers/packed_data_container.h"
#include "core/config/project_settings.h"
#include "core/string/compressed_translation.h"
#include "core/string/translation.h"
#include "core/object/undo_redo.h"
#include "core/os/thread_pool.h"
#include "core/os/thread_pool_execute_job.h"
#include "core/os/thread_pool_job.h"
#include "core/bind/logger_bind.h"
#include "core/log/logger_backend.h"
@ -92,6 +96,7 @@ static _ClassDB *_classdb = nullptr;
static _Marshalls *_marshalls = nullptr;
static _JSON *_json = nullptr;
static _PLogger *_plogger = nullptr;
static ThreadPool *thread_pool = NULL;
static IP *ip = nullptr;
@ -232,6 +237,8 @@ void register_core_types() {
_marshalls = memnew(_Marshalls);
_json = memnew(_JSON);
_plogger = memnew(_PLogger);
thread_pool = memnew(ThreadPool);
}
void register_core_settings() {
@ -243,6 +250,8 @@ void register_core_settings() {
GLOBAL_DEF("network/ssl/certificates", "");
ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt"));
ThreadPool::get_singleton()->register_core_settings();
}
void register_core_singletons() {
@ -262,6 +271,9 @@ void register_core_singletons() {
ClassDB::register_class<Expression>();
ClassDB::register_class<Time>();
ClassDB::register_class<_PLogger>();
ClassDB::register_class<ThreadPoolJob>();
ClassDB::register_class<ThreadPoolExecuteJob>();
ClassDB::register_class<ThreadPool>();
Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton()));
@ -278,6 +290,7 @@ void register_core_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("PLogger", _PLogger::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ThreadPool", ThreadPool::get_singleton()));
}
void unregister_core_types() {
@ -291,6 +304,7 @@ void unregister_core_types() {
memdelete(_plogger);
memdelete(_geometry);
memdelete(thread_pool);
ResourceLoader::remove_resource_format_loader(resource_format_image);
resource_format_image.unref();

View File

@ -15,8 +15,7 @@ repo, should you want to. It contains all my modules.
# Optional Dependencies
[Mesh Data Resource](https://github.com/Relintai/mesh_data_resource): Support for merged meshes, even in gles2.\
[Texture Packer](https://github.com/Relintai/texture_packer): Prop Instance will use this to merge textures.\
[Thread Pool](https://github.com/Relintai/thread_pool): Prop Instance will use this for multithreaded generation.
[Texture Packer](https://github.com/Relintai/texture_packer): Prop Instance will use this to merge textures.
# PropData

View File

@ -15,8 +15,7 @@ repo, should you want to. It contains all my modules.
# Optional Dependencies
[Mesh Data Resource](https://github.com/Relintai/mesh_data_resource): Support for merged meshes, even in gles2.\
[Texture Packer](https://github.com/Relintai/texture_packer): Prop2D Instance will use this to merge textures.\
[Thread Pool](https://github.com/Relintai/thread_pool): Prop2D Instance will use this for multithreaded generation.
[Texture Packer](https://github.com/Relintai/texture_packer): Prop2D Instance will use this to merge textures.
# Prop2DData

View File

@ -22,7 +22,6 @@ You can grab pre-built binaries (even editor + export templates) from the [Broke
## Optional Dependencies
`https://github.com/Relintai/thread_pool`: Threaded chunk generation. Without this terraman is single threaded! \
`https://github.com/Relintai/texture_packer`: You get access to [TerraLibraryMerger](#voxellibrarymerger) and [TerraLibraryMergerPCM](#voxellibrarymergerpcm). \
`https://github.com/Relintai/mesh_data_resource`: You get access to a bunch of properties, and methods that can manipulate meshes.\
`https://github.com/Relintai/props`: You get access to a bunch of properties, and methods that can manipulate, and use props.\
@ -107,8 +106,7 @@ They also provide a way to easily modularize mesh and lod generation.
Base class for jobs.
If the [thread pool](https://github.com/Relintai/thread_pool) module is present, this is inherited from `ThreadPoolJob`,
else it implements the same api as `ThreadPoolJob`, but it's not going to use threading.
This is inherited from `ThreadPoolJob`.
A job has a reference to it's owner chunk.

View File

@ -173,7 +173,7 @@ You can look at the world implementations for more examples: [TerraWorldBlocky](
Stores terrain data, prop data. And mesh data (TerraChunkDefault), and the mesh generation jobs.
When it starts building meshes it will start submitting jobs to thread_pool (if present) one by one.
When it starts building meshes it will start submitting jobs to thread_pool one by one.
#### TerraMesher

View File

@ -19,7 +19,6 @@ If compile breaks, and I don't notice please report.
## Optional Dependencies
`https://github.com/Relintai/thread_pool`: Threaded chunk generation. Without this Voxelman is single threaded! \
`https://github.com/Relintai/texture_packer`: You get access to [VoxelLibraryMerger](#voxellibrarymerger) and [VoxelLibraryMergerPCM](#voxellibrarymergerpcm). \
`https://github.com/Relintai/mesh_data_resource`: You get access to a bunch of properties, and methods that can manipulate meshes.\
`https://github.com/Relintai/props`: You get access to a bunch of properties, and methods that can manipulate, and use props.\
@ -179,7 +178,7 @@ You can look at the world implementations for more examples: [VoxelWorldBlocky](
Stores terrain data, prop data. And mesh data (VoxelChunkDefault), and the mesh generation jobs.
When it starts building meshes it will start submitting jobs to thread_pool (if present) one by one.
When it starts building meshes it will start submitting jobs to thread_pool one by one.
#### VoxelMesher

View File

@ -3,8 +3,8 @@
#include "mm_node.h"
#include "mm_node_universal_property.h"
#include "modules/thread_pool/thread_pool.h"
#include "modules/thread_pool/thread_pool_job.h"
#include "core/os/thread_pool.h"
#include "core/os/thread_pool_job.h"
Vector2 MMMaterial::get_image_size() {
return image_size;

View File

@ -21,10 +21,6 @@ if os.path.isdir('../terraman'):
if os.path.isdir('../mesh_utils'):
module_env.Append(CPPDEFINES=['MESH_UTILS_PRESENT'])
if os.path.isdir('../thread_pool'):
module_env.Append(CPPDEFINES=['THREAD_POOL_PRESENT'])
sources = [
"register_types.cpp",

View File

@ -50,16 +50,6 @@ void PropTextureJob::_execute() {
}
PropTextureJob::PropTextureJob() {
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
PropTextureJob::~PropTextureJob() {
@ -73,102 +63,4 @@ void PropTextureJob::_bind_methods() {
#endif
ClassDB::bind_method(D_METHOD("_execute"), &PropTextureJob::_execute);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &PropTextureJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &PropTextureJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &PropTextureJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &PropTextureJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &PropTextureJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &PropTextureJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &PropTextureJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &PropTextureJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &PropTextureJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &PropTextureJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &PropTextureJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &PropTextureJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool PropTextureJob::get_complete() const {
return _complete;
}
void PropTextureJob::set_complete(const bool value) {
_complete = value;
}
bool PropTextureJob::get_cancelled() const {
return _cancelled;
}
void PropTextureJob::set_cancelled(const bool value) {
_cancelled = value;
}
float PropTextureJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void PropTextureJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int PropTextureJob::get_start_time() const {
return _start_time;
}
void PropTextureJob::set_start_time(const int value) {
_start_time = value;
}
int PropTextureJob::get_current_run_stage() const {
return _current_run_stage;
}
void PropTextureJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int PropTextureJob::get_stage() const {
return _stage;
}
void PropTextureJob::set_stage(const int value) {
_stage = value;
}
void PropTextureJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float PropTextureJob::get_current_execution_time() {
return 0;
}
bool PropTextureJob::should_do(const bool just_check) {
return true;
}
bool PropTextureJob::should_return() {
if (_cancelled)
return true;
return false;
}
void PropTextureJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,9 +24,7 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool_job.h"
#endif
#include "core/os/thread_pool_job.h"
#include "core/object/reference.h"
@ -34,13 +32,8 @@ SOFTWARE.
class TexturePacker;
#endif
#if THREAD_POOL_PRESENT
class PropTextureJob : public ThreadPoolJob {
GDCLASS(PropTextureJob, ThreadPoolJob);
#else
class PropTextureJob : public Reference {
GDCLASS(PropTextureJob, Reference);
#endif
public:
#if TEXTURE_PACKER_PRESENT
@ -59,46 +52,6 @@ protected:
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> _merger;
#endif
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
#endif

View File

@ -130,17 +130,6 @@ PropInstanceJob::PropInstanceJob() {
_build_phase_type = BUILD_PHASE_TYPE_NORMAL;
_build_done = true;
_phase = 0;
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
PropInstanceJob::~PropInstanceJob() {
@ -181,102 +170,5 @@ void PropInstanceJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("_execute_phase"), &PropInstanceJob::_execute_phase);
ClassDB::bind_method(D_METHOD("prop_instance_exit_tree"), &PropInstanceJob::prop_instance_exit_tree);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &PropInstanceJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &PropInstanceJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &PropInstanceJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &PropInstanceJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &PropInstanceJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &PropInstanceJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &PropInstanceJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &PropInstanceJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &PropInstanceJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &PropInstanceJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &PropInstanceJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &PropInstanceJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool PropInstanceJob::get_complete() const {
return _complete;
}
void PropInstanceJob::set_complete(const bool value) {
_complete = value;
}
bool PropInstanceJob::get_cancelled() const {
return _cancelled;
}
void PropInstanceJob::set_cancelled(const bool value) {
_cancelled = value;
}
float PropInstanceJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void PropInstanceJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int PropInstanceJob::get_start_time() const {
return _start_time;
}
void PropInstanceJob::set_start_time(const int value) {
_start_time = value;
}
int PropInstanceJob::get_current_run_stage() const {
return _current_run_stage;
}
void PropInstanceJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int PropInstanceJob::get_stage() const {
return _stage;
}
void PropInstanceJob::set_stage(const int value) {
_stage = value;
}
void PropInstanceJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float PropInstanceJob::get_current_execution_time() {
return 0;
}
bool PropInstanceJob::should_do(const bool just_check) {
return true;
}
bool PropInstanceJob::should_return() {
if (_cancelled)
return true;
return false;
}
void PropInstanceJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,23 +24,13 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../thread_pool/thread_pool_job.h"
#else
#include "core/object/reference.h"
#endif
#include "core/os/thread_pool_job.h"
class PropData;
class PropInstance;
#if THREAD_POOL_PRESENT
class PropInstanceJob : public ThreadPoolJob {
GDCLASS(PropInstanceJob, ThreadPoolJob);
#else
class PropInstanceJob : public Reference {
GDCLASS(PropInstanceJob, Reference);
#endif
public:
static const String BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE;
@ -93,46 +83,6 @@ protected:
bool _in_tree;
Ref<PropData> _prop;
PropInstance *_instance;
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
VARIANT_ENUM_CAST(PropInstanceJob::ActiveBuildPhaseType);

View File

@ -39,9 +39,7 @@
#include "./singleton/prop_cache.h"
#endif
#if THREAD_POOL_PRESENT
#include "../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
#include "./props/prop_data_tiled_wall.h"
@ -556,11 +554,7 @@ void PropInstanceMerger::_build() {
Don't submit here, as it starts in physics process mode
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
_job->execute();
#endif
*/
}
@ -803,11 +797,7 @@ void PropInstanceMerger::_notification(int p_what) {
_job->physics_process(get_physics_process_delta_time());
if (_job->get_build_phase_type() == PropInstanceJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
job->execute();
#endif
}
}
}
@ -824,11 +814,7 @@ void PropInstanceMerger::_notification(int p_what) {
_job->process(get_process_delta_time());
if (_job->get_build_phase_type() == PropInstanceJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
job->execute();
#endif
}
}
} else {

View File

@ -30,9 +30,7 @@ SOFTWARE.
#include "../jobs/prop_texture_job.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
#include "../material_cache/prop_material_cache.h"
#include "../tiled_wall/tiled_wall_data.h"

View File

@ -21,10 +21,6 @@ if os.path.isdir('../terraman_2d'):
if os.path.isdir('../mesh_utils'):
module_env.Append(CPPDEFINES=['MESH_UTILS_PRESENT'])
if os.path.isdir('../thread_pool'):
module_env.Append(CPPDEFINES=['THREAD_POOL_PRESENT'])
sources = [
"register_types.cpp",

View File

@ -50,16 +50,6 @@ void Prop2DTextureJob::_execute() {
}
Prop2DTextureJob::Prop2DTextureJob() {
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
Prop2DTextureJob::~Prop2DTextureJob() {
@ -73,102 +63,4 @@ void Prop2DTextureJob::_bind_methods() {
#endif
ClassDB::bind_method(D_METHOD("_execute"), &Prop2DTextureJob::_execute);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &Prop2DTextureJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &Prop2DTextureJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &Prop2DTextureJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &Prop2DTextureJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &Prop2DTextureJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &Prop2DTextureJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &Prop2DTextureJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &Prop2DTextureJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &Prop2DTextureJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &Prop2DTextureJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &Prop2DTextureJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &Prop2DTextureJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool Prop2DTextureJob::get_complete() const {
return _complete;
}
void Prop2DTextureJob::set_complete(const bool value) {
_complete = value;
}
bool Prop2DTextureJob::get_cancelled() const {
return _cancelled;
}
void Prop2DTextureJob::set_cancelled(const bool value) {
_cancelled = value;
}
float Prop2DTextureJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void Prop2DTextureJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int Prop2DTextureJob::get_start_time() const {
return _start_time;
}
void Prop2DTextureJob::set_start_time(const int value) {
_start_time = value;
}
int Prop2DTextureJob::get_current_run_stage() const {
return _current_run_stage;
}
void Prop2DTextureJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int Prop2DTextureJob::get_stage() const {
return _stage;
}
void Prop2DTextureJob::set_stage(const int value) {
_stage = value;
}
void Prop2DTextureJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float Prop2DTextureJob::get_current_execution_time() {
return 0;
}
bool Prop2DTextureJob::should_do(const bool just_check) {
return true;
}
bool Prop2DTextureJob::should_return() {
if (_cancelled)
return true;
return false;
}
void Prop2DTextureJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,9 +24,7 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool_job.h"
#endif
#include "core/os/thread_pool_job.h"
#include "core/object/reference.h"
@ -34,13 +32,8 @@ SOFTWARE.
class TexturePacker;
#endif
#if THREAD_POOL_PRESENT
class Prop2DTextureJob : public ThreadPoolJob {
GDCLASS(Prop2DTextureJob, ThreadPoolJob);
#else
class Prop2DTextureJob : public Reference {
GDCLASS(Prop2DTextureJob, Reference);
#endif
public:
#if TEXTURE_PACKER_PRESENT
@ -59,46 +52,6 @@ protected:
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> _merger;
#endif
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
#endif

View File

@ -130,17 +130,6 @@ Prop2DInstanceJob::Prop2DInstanceJob() {
_build_phase_type = BUILD_PHASE_TYPE_NORMAL;
_build_done = true;
_phase = 0;
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
Prop2DInstanceJob::~Prop2DInstanceJob() {
@ -181,102 +170,4 @@ void Prop2DInstanceJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("_execute_phase"), &Prop2DInstanceJob::_execute_phase);
ClassDB::bind_method(D_METHOD("prop_instance_exit_tree"), &Prop2DInstanceJob::prop_instance_exit_tree);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &Prop2DInstanceJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &Prop2DInstanceJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &Prop2DInstanceJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &Prop2DInstanceJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &Prop2DInstanceJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &Prop2DInstanceJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &Prop2DInstanceJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &Prop2DInstanceJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &Prop2DInstanceJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &Prop2DInstanceJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &Prop2DInstanceJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &Prop2DInstanceJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool Prop2DInstanceJob::get_complete() const {
return _complete;
}
void Prop2DInstanceJob::set_complete(const bool value) {
_complete = value;
}
bool Prop2DInstanceJob::get_cancelled() const {
return _cancelled;
}
void Prop2DInstanceJob::set_cancelled(const bool value) {
_cancelled = value;
}
float Prop2DInstanceJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void Prop2DInstanceJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int Prop2DInstanceJob::get_start_time() const {
return _start_time;
}
void Prop2DInstanceJob::set_start_time(const int value) {
_start_time = value;
}
int Prop2DInstanceJob::get_current_run_stage() const {
return _current_run_stage;
}
void Prop2DInstanceJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int Prop2DInstanceJob::get_stage() const {
return _stage;
}
void Prop2DInstanceJob::set_stage(const int value) {
_stage = value;
}
void Prop2DInstanceJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float Prop2DInstanceJob::get_current_execution_time() {
return 0;
}
bool Prop2DInstanceJob::should_do(const bool just_check) {
return true;
}
bool Prop2DInstanceJob::should_return() {
if (_cancelled)
return true;
return false;
}
void Prop2DInstanceJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -23,25 +23,14 @@ SOFTWARE.
*/
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../thread_pool/thread_pool_job.h"
#else
#include "core/os/thread_pool_job.h"
#include "core/object/reference.h"
#endif
class Prop2DData;
class Prop2DInstance;
#if THREAD_POOL_PRESENT
class Prop2DInstanceJob : public ThreadPoolJob {
GDCLASS(Prop2DInstanceJob, ThreadPoolJob);
#else
class Prop2DInstanceJob : public Reference {
GDCLASS(Prop2DInstanceJob, Reference);
#endif
public:
static const String BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE;
@ -95,46 +84,6 @@ protected:
bool _in_tree;
Ref<Prop2DData> _prop;
Prop2DInstance *_instance;
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
VARIANT_ENUM_CAST(Prop2DInstanceJob::ActiveBuildPhaseType);

View File

@ -36,9 +36,7 @@
#include "./singleton/prop_2d_cache.h"
#endif
#if THREAD_POOL_PRESENT
#include "../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
#include "./props/prop_2d_data_tiled_wall_2d.h"
@ -353,11 +351,7 @@ void Prop2DInstanceMerger::_build() {
Don't submit here, as it starts in physics process mode
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
_job->execute();
#endif
*/
}
@ -564,11 +558,7 @@ void Prop2DInstanceMerger::_notification(int p_what) {
_job->physics_process(get_physics_process_delta_time());
if (_job->get_build_phase_type() == Prop2DInstanceJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
job->execute();
#endif
}
}
}
@ -585,11 +575,7 @@ void Prop2DInstanceMerger::_notification(int p_what) {
_job->process(get_process_delta_time());
if (_job->get_build_phase_type() == Prop2DInstanceJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(_job);
#else
job->execute();
#endif
}
}
}

View File

@ -30,9 +30,7 @@ SOFTWARE.
#include "../jobs/prop_2d_texture_job.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
#include "../material_cache/prop_2d_material_cache.h"
#include "../tiled_wall/tiled_wall_2d_data.h"

View File

@ -9,9 +9,6 @@ if os.path.isdir('../texture_packer'):
module_env.Append(CPPDEFINES=['TEXTURE_PACKER_PRESENT'])
has_texture_packer = True
if os.path.isdir('../thread_pool'):
module_env.Append(CPPDEFINES=['THREAD_POOL_PRESENT'])
if os.path.isdir('../mesh_data_resource'):
module_env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])

View File

@ -60,7 +60,7 @@ void TerrainJob::set_build_done(const bool val) {
void TerrainJob::next_job() {
ERR_FAIL_COND(!_chunk.is_valid());
_chunk->job_next();
set_build_done(true);
}
@ -295,17 +295,6 @@ TerrainJob::TerrainJob() {
_build_phase_type = BUILD_PHASE_TYPE_NORMAL;
_build_done = true;
_phase = 0;
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
TerrainJob::~TerrainJob() {
@ -347,102 +336,4 @@ void TerrainJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_random_ao", "seed", "octaves", "period", "persistence", "scale_factor"), &TerrainJob::generate_random_ao, DEFVAL(4), DEFVAL(30), DEFVAL(0.3), DEFVAL(0.6));
ClassDB::bind_method(D_METHOD("chunk_exit_tree"), &TerrainJob::chunk_exit_tree);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &TerrainJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &TerrainJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &TerrainJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &TerrainJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &TerrainJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &TerrainJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &TerrainJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &TerrainJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &TerrainJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &TerrainJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &TerrainJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &TerrainJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool TerrainJob::get_complete() const {
return _complete;
}
void TerrainJob::set_complete(const bool value) {
_complete = value;
}
bool TerrainJob::get_cancelled() const {
return _cancelled;
}
void TerrainJob::set_cancelled(const bool value) {
_cancelled = value;
}
float TerrainJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void TerrainJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int TerrainJob::get_start_time() const {
return _start_time;
}
void TerrainJob::set_start_time(const int value) {
_start_time = value;
}
int TerrainJob::get_current_run_stage() const {
return _current_run_stage;
}
void TerrainJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int TerrainJob::get_stage() const {
return _stage;
}
void TerrainJob::set_stage(const int value) {
_stage = value;
}
void TerrainJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float TerrainJob::get_current_execution_time() {
return 0;
}
bool TerrainJob::should_do(const bool just_check) {
return true;
}
bool TerrainJob::should_return() {
if (_cancelled)
return true;
return false;
}
void TerrainJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,23 +24,14 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../../../thread_pool/thread_pool_job.h"
#else
#include "core/object/reference.h"
#endif
#include "core/os/thread_pool_job.h"
#include "../../defines.h"
class TerrainChunk;
#if THREAD_POOL_PRESENT
class TerrainJob : public ThreadPoolJob {
GDCLASS(TerrainJob, ThreadPoolJob);
#else
class TerrainJob : public Reference {
GDCLASS(TerrainJob, Reference);
#endif
public:
static const String BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE;
@ -95,46 +86,6 @@ protected:
int _phase;
bool _in_tree;
Ref<TerrainChunk> _chunk;
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
VARIANT_ENUM_CAST(TerrainJob::ActiveBuildPhaseType);

View File

@ -33,9 +33,7 @@ SOFTWARE.
#include "servers/physics_server.h"
#include "terrain_structure.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
_FORCE_INLINE_ bool TerrainChunk::get_process() const {
return _is_processing;
@ -302,11 +300,7 @@ void TerrainChunk::job_next() {
j->set_complete(false);
if (j->get_build_phase_type() == TerrainJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(j);
#else
j->execute();
#endif
}
}
Ref<TerrainJob> TerrainChunk::job_get_current() {
@ -682,7 +676,6 @@ void TerrainChunk::cancel_build() {
_abort_build = true;
#if THREAD_POOL_PRESENT
if (_is_generating) {
Ref<TerrainJob> job = job_get_current();
@ -690,7 +683,6 @@ void TerrainChunk::cancel_build() {
ThreadPool::get_singleton()->cancel_job(job);
}
}
#endif
}
void TerrainChunk::bake_lights() {
@ -1038,7 +1030,6 @@ Vector3 TerrainChunk::to_global(Vector3 p_local) const {
}
bool TerrainChunk::is_safe_to_delete() {
#if THREAD_POOL_PRESENT
if (!_is_generating) {
return true;
}
@ -1050,9 +1041,6 @@ bool TerrainChunk::is_safe_to_delete() {
}
return !ThreadPool::get_singleton()->has_job(job);
#else
return true;
#endif
}
TerrainChunk::TerrainChunk() {
@ -1179,11 +1167,7 @@ void TerrainChunk::_generation_process(const float delta) {
job->process(delta);
if (job->get_build_phase_type() == TerrainJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}
@ -1208,11 +1192,7 @@ void TerrainChunk::_generation_physics_process(const float delta) {
job->physics_process(delta);
if (job->get_build_phase_type() == TerrainJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}

View File

@ -9,9 +9,6 @@ if os.path.isdir('../texture_packer'):
module_env.Append(CPPDEFINES=['TEXTURE_PACKER_PRESENT'])
has_texture_packer = True
if os.path.isdir('../thread_pool'):
module_env.Append(CPPDEFINES=['THREAD_POOL_PRESENT'])
if os.path.isdir('../mesh_data_resource'):
module_env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])

View File

@ -271,17 +271,6 @@ Terrain2DJob::Terrain2DJob() {
_build_phase_type = BUILD_PHASE_TYPE_NORMAL;
_build_done = true;
_phase = 0;
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
Terrain2DJob::~Terrain2DJob() {
@ -323,102 +312,4 @@ void Terrain2DJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_random_ao", "seed", "octaves", "period", "persistence", "scale_factor"), &Terrain2DJob::generate_random_ao, DEFVAL(4), DEFVAL(30), DEFVAL(0.3), DEFVAL(0.6));
ClassDB::bind_method(D_METHOD("chunk_exit_tree"), &Terrain2DJob::chunk_exit_tree);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &Terrain2DJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &Terrain2DJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &Terrain2DJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &Terrain2DJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &Terrain2DJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &Terrain2DJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &Terrain2DJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &Terrain2DJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &Terrain2DJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &Terrain2DJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &Terrain2DJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &Terrain2DJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool Terrain2DJob::get_complete() const {
return _complete;
}
void Terrain2DJob::set_complete(const bool value) {
_complete = value;
}
bool Terrain2DJob::get_cancelled() const {
return _cancelled;
}
void Terrain2DJob::set_cancelled(const bool value) {
_cancelled = value;
}
float Terrain2DJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void Terrain2DJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int Terrain2DJob::get_start_time() const {
return _start_time;
}
void Terrain2DJob::set_start_time(const int value) {
_start_time = value;
}
int Terrain2DJob::get_current_run_stage() const {
return _current_run_stage;
}
void Terrain2DJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int Terrain2DJob::get_stage() const {
return _stage;
}
void Terrain2DJob::set_stage(const int value) {
_stage = value;
}
void Terrain2DJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float Terrain2DJob::get_current_execution_time() {
return 0;
}
bool Terrain2DJob::should_do(const bool just_check) {
return true;
}
bool Terrain2DJob::should_return() {
if (_cancelled)
return true;
return false;
}
void Terrain2DJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,23 +24,14 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../../../thread_pool/thread_pool_job.h"
#else
#include "core/object/reference.h"
#endif
#include "core/os/thread_pool_job.h"
#include "../../defines.h"
class Terrain2DChunk;
#if THREAD_POOL_PRESENT
class Terrain2DJob : public ThreadPoolJob {
GDCLASS(Terrain2DJob, ThreadPoolJob);
#else
class Terrain2DJob : public Reference {
GDCLASS(Terrain2DJob, Reference);
#endif
public:
static const String BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE;
@ -95,46 +86,6 @@ protected:
int _phase;
bool _in_tree;
Ref<Terrain2DChunk> _chunk;
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
VARIANT_ENUM_CAST(Terrain2DJob::ActiveBuildPhaseType);

View File

@ -32,9 +32,7 @@ SOFTWARE.
#include "jobs/terrain_2d_job.h"
#include "terrain_2d_structure.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
_FORCE_INLINE_ bool Terrain2DChunk::get_process() const {
return _is_processing;
@ -338,11 +336,7 @@ void Terrain2DChunk::job_next() {
j->set_complete(false);
if (j->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(j);
#else
j->execute();
#endif
}
}
Ref<Terrain2DJob> Terrain2DChunk::job_get_current() {
@ -718,7 +712,6 @@ void Terrain2DChunk::cancel_build() {
_abort_build = true;
#if THREAD_POOL_PRESENT
if (_is_generating) {
Ref<Terrain2DJob> job = job_get_current();
@ -726,7 +719,6 @@ void Terrain2DChunk::cancel_build() {
ThreadPool::get_singleton()->cancel_job(job);
}
}
#endif
}
void Terrain2DChunk::bake_lights() {
@ -1091,7 +1083,6 @@ Vector2 Terrain2DChunk::to_global(Vector2 p_local) const {
}
bool Terrain2DChunk::is_safe_to_delete() {
#if THREAD_POOL_PRESENT
if (!_is_generating) {
return true;
}
@ -1103,9 +1094,6 @@ bool Terrain2DChunk::is_safe_to_delete() {
}
return !ThreadPool::get_singleton()->has_job(job);
#else
return true;
#endif
}
void Terrain2DChunk::setup_canvas_items_size(const int amount) {
@ -1263,11 +1251,7 @@ void Terrain2DChunk::_generation_process(const float delta) {
job->process(delta);
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}
@ -1292,11 +1276,7 @@ void Terrain2DChunk::_generation_physics_process(const float delta) {
job->physics_process(delta);
if (job->get_build_phase_type() == Terrain2DJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}

View File

@ -1,8 +0,0 @@
.import
*.d
*.o
*.meta
*.obj
*.pyc
*.bc
*.os

View File

@ -1,19 +0,0 @@
Copyright (c) 2020-2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,27 +0,0 @@
import os
Import('env')
module_env = env.Clone()
sources = [
"register_types.cpp",
"thread_pool.cpp",
"thread_pool_job.cpp",
"thread_pool_execute_job.cpp",
]
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
# Shared lib compilation
module_env.Append(CCFLAGS=['-fPIC'])
module_env['LIBS'] = []
shared_lib = module_env.SharedLibrary(target='#bin/thread_pool', source=sources)
shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0]
env.Append(LIBS=[shared_lib_shim])
env.Append(LIBPATH=['#bin'])
else:
# Static compilation
module_env.add_source_files(env.modules_sources, sources)

View File

@ -1,19 +0,0 @@
def can_build(env, platform):
return True
def configure(env):
pass
def get_doc_classes():
return [
"ThreadPool",
"ThreadPoolJob",
"ThreadPoolExecuteJob",
]
def get_doc_path():
return "doc_classes"

View File

@ -1,48 +0,0 @@
#include "register_types.h"
/*
Copyright (c) 2020-2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "core/config/engine.h"
#include "thread_pool.h"
#include "thread_pool_execute_job.h"
#include "thread_pool_job.h"
static ThreadPool *thread_pool = NULL;
void register_thread_pool_types() {
ClassDB::register_class<ThreadPoolJob>();
ClassDB::register_class<ThreadPoolExecuteJob>();
thread_pool = memnew(ThreadPool);
ClassDB::register_class<ThreadPool>();
Engine::get_singleton()->add_singleton(Engine::Singleton("ThreadPool", ThreadPool::get_singleton()));
}
void unregister_thread_pool_types() {
if (thread_pool) {
memdelete(thread_pool);
}
}

View File

@ -1,31 +0,0 @@
#ifndef THREAD_POOL_REGISTER_TYPES_H
#define THREAD_POOL_REGISTER_TYPES_H
/*
Copyright (c) 2020-2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
void register_thread_pool_types();
void unregister_thread_pool_types();
#endif

View File

@ -9,9 +9,6 @@ if os.path.isdir('../texture_packer'):
module_env.Append(CPPDEFINES=['TEXTURE_PACKER_PRESENT'])
has_texture_packer = True
if os.path.isdir('../thread_pool'):
module_env.Append(CPPDEFINES=['THREAD_POOL_PRESENT'])
if os.path.isdir('../mesh_data_resource'):
module_env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])

View File

@ -60,7 +60,7 @@ void VoxelJob::set_build_done(const bool val) {
void VoxelJob::next_job() {
ERR_FAIL_COND(!_chunk.is_valid());
_chunk->job_next();
set_build_done(true);
}
@ -308,17 +308,6 @@ VoxelJob::VoxelJob() {
_build_phase_type = BUILD_PHASE_TYPE_NORMAL;
_build_done = true;
_phase = 0;
#if !THREAD_POOL_PRESENT
_complete = true;
_cancelled = false;
_max_allocated_time = 0;
_start_time = 0;
_current_run_stage = 0;
_stage = 0;
#endif
}
VoxelJob::~VoxelJob() {
@ -360,103 +349,4 @@ void VoxelJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_random_ao", "seed", "octaves", "period", "persistence", "scale_factor"), &VoxelJob::generate_random_ao, DEFVAL(4), DEFVAL(30), DEFVAL(0.3), DEFVAL(0.6));
ClassDB::bind_method(D_METHOD("chunk_exit_tree"), &VoxelJob::chunk_exit_tree);
#if !THREAD_POOL_PRESENT
ClassDB::bind_method(D_METHOD("get_complete"), &VoxelJob::get_complete);
ClassDB::bind_method(D_METHOD("set_complete", "value"), &VoxelJob::set_complete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "complete"), "set_complete", "get_complete");
ClassDB::bind_method(D_METHOD("get_start_time"), &VoxelJob::get_start_time);
ClassDB::bind_method(D_METHOD("set_start_time", "value"), &VoxelJob::set_start_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "start_time"), "set_start_time", "get_start_time");
ClassDB::bind_method(D_METHOD("get_current_run_stage"), &VoxelJob::get_current_run_stage);
ClassDB::bind_method(D_METHOD("set_current_run_stage", "value"), &VoxelJob::set_current_run_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_run_stage"), "set_current_run_stage", "get_current_run_stage");
ClassDB::bind_method(D_METHOD("get_stage"), &VoxelJob::get_stage);
ClassDB::bind_method(D_METHOD("set_stage", "value"), &VoxelJob::set_stage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "stage"), "set_stage", "get_stage");
ClassDB::bind_method(D_METHOD("get_current_execution_time"), &VoxelJob::get_current_execution_time);
ClassDB::bind_method(D_METHOD("should_do", "just_check"), &VoxelJob::should_do, DEFVAL(false));
ClassDB::bind_method(D_METHOD("should_return"), &VoxelJob::should_return);
BIND_VMETHOD(MethodInfo("_execute"));
ClassDB::bind_method(D_METHOD("execute"), &VoxelJob::execute);
ADD_SIGNAL(MethodInfo("completed"));
#endif
}
#if !THREAD_POOL_PRESENT
bool VoxelJob::get_complete() const {
return _complete;
}
void VoxelJob::set_complete(const bool value) {
_complete = value;
}
bool VoxelJob::get_cancelled() const {
return _cancelled;
}
void VoxelJob::set_cancelled(const bool value) {
_cancelled = value;
}
float VoxelJob::get_max_allocated_time() const {
return _max_allocated_time;
}
void VoxelJob::set_max_allocated_time(const float value) {
_max_allocated_time = value;
}
int VoxelJob::get_start_time() const {
return _start_time;
}
void VoxelJob::set_start_time(const int value) {
_start_time = value;
}
int VoxelJob::get_current_run_stage() const {
return _current_run_stage;
}
void VoxelJob::set_current_run_stage(const int value) {
_current_run_stage = value;
}
int VoxelJob::get_stage() const {
return _stage;
}
void VoxelJob::set_stage(const int value) {
_stage = value;
}
void VoxelJob::reset_stages() {
_current_run_stage = 0;
_stage = 0;
}
float VoxelJob::get_current_execution_time() {
return 0;
}
bool VoxelJob::should_do(const bool just_check) {
return true;
}
bool VoxelJob::should_return() {
if (_cancelled)
return true;
return false;
}
void VoxelJob::execute() {
ERR_FAIL_COND(!has_method("_execute"));
call("_execute");
}
#endif

View File

@ -24,23 +24,14 @@ SOFTWARE.
#include "scene/resources/texture.h"
#if THREAD_POOL_PRESENT
#include "../../../thread_pool/thread_pool_job.h"
#else
#include "core/object/reference.h"
#endif
#include "core/os/thread_pool_job.h"
#include "../../defines.h"
class VoxelChunk;
#if THREAD_POOL_PRESENT
class VoxelJob : public ThreadPoolJob {
GDCLASS(VoxelJob, ThreadPoolJob);
#else
class VoxelJob : public Reference {
GDCLASS(VoxelJob, Reference);
#endif
public:
static const String BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE;
@ -95,46 +86,6 @@ protected:
int _phase;
bool _in_tree;
Ref<VoxelChunk> _chunk;
public:
#if !THREAD_POOL_PRESENT
bool get_complete() const;
void set_complete(const bool value);
bool get_cancelled() const;
void set_cancelled(const bool value);
float get_max_allocated_time() const;
void set_max_allocated_time(const float value);
int get_start_time() const;
void set_start_time(const int value);
int get_current_run_stage() const;
void set_current_run_stage(const int value);
int get_stage() const;
void set_stage(const int value);
void reset_stages();
float get_current_execution_time();
bool should_do(const bool just_check = false);
bool should_return();
void execute();
private:
bool _complete;
bool _cancelled;
float _max_allocated_time;
uint64_t _start_time;
int _current_run_stage;
int _stage;
#endif
};
VARIANT_ENUM_CAST(VoxelJob::ActiveBuildPhaseType);

View File

@ -32,9 +32,7 @@ SOFTWARE.
#include "servers/physics_server.h"
#include "voxel_structure.h"
#if THREAD_POOL_PRESENT
#include "../../thread_pool/thread_pool.h"
#endif
#include "core/os/thread_pool.h"
_FORCE_INLINE_ bool VoxelChunk::get_is_build_threaded() const {
return _is_build_threaded;
@ -308,11 +306,7 @@ void VoxelChunk::job_next() {
j->set_complete(false);
if (j->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(j);
#else
j->execute();
#endif
}
}
Ref<VoxelJob> VoxelChunk::job_get_current() {
@ -1157,11 +1151,7 @@ void VoxelChunk::_generation_process(const float delta) {
job->process(delta);
if (job->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}
@ -1182,11 +1172,7 @@ void VoxelChunk::_generation_physics_process(const float delta) {
job->physics_process(delta);
if (job->get_build_phase_type() == VoxelJob::BUILD_PHASE_TYPE_NORMAL) {
#if THREAD_POOL_PRESENT
ThreadPool::get_singleton()->add_job(job);
#else
job->execute();
#endif
}
}
}

View File

@ -36,6 +36,7 @@
#include "core/os/dir_access.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/os/thread_pool.h"
#include "core/string/print_string.h"
#include "core/config/project_settings.h"
#include "main/input_default.h"
@ -610,6 +611,8 @@ bool SceneTree::idle(float p_time) {
if (multiplayer_poll) {
multiplayer->poll();
}
ThreadPool::get_singleton()->update();
emit_signal("idle_frame");