Skip to content

Commit

Permalink
Fix thread signal issue under 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Shfty committed Dec 20, 2019
1 parent 3c112e1 commit aae28a6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions addons/qodot/src/nodes/qodot_map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func build_map(map_file: String) -> void:

if not queue_build_step(context, build_step):
print('Error: failed to queue build step.')
cleanup_thread_pool(context, thread_pool)
call_deferred('cleanup_thread_pool', context, thread_pool)
call_deferred("build_failed")
return

Expand All @@ -184,7 +184,7 @@ func build_map(map_file: String) -> void:
var job_duration = job_profiler.finish()
print_log("Done in " + String(job_duration * 0.001) + " seconds.\n")

cleanup_thread_pool(context, thread_pool)
call_deferred('cleanup_thread_pool', context, thread_pool)
call_deferred("finalize_build", context, build_steps)

func get_build_steps() -> Array:
Expand Down
7 changes: 3 additions & 4 deletions addons/qodot/src/util/qodot_thread_pool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func set_bucket_size(new_bucket_size):

# Interface
func add_thread():
free_threads.append(PoolThread.new())
var thread = PoolThread.new()
free_threads.append(thread)
thread.connect("jobs_finished", self, "finish_thread_jobs")

func remove_thread():
if(free_threads.size() > 0):
Expand All @@ -105,7 +107,6 @@ func start_thread_jobs():
while thread.job_bucket.size() < bucket_size && pending_jobs.size() > 0:
thread.job_bucket.append(pending_jobs.pop_front())

thread.connect("jobs_finished", self, "finish_thread_jobs")
thread.semaphore.post()
busy_threads.append(thread)

Expand All @@ -126,8 +127,6 @@ func finish_thread_jobs(thread, results):
for job_id in results:
job_results[job_id] = results[job_id]

thread.disconnect("jobs_finished", self, "finish_thread_jobs")

busy_threads.remove(busy_threads.find(thread))

if(free_threads.size() < max_threads):
Expand Down
41 changes: 30 additions & 11 deletions scenes/qodot_example/qodot_example.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=16 format=2]

[ext_resource path="res://scenes/qodot_example/qodot_example_environment.tres" type="Environment" id=1]
[ext_resource path="res://scenes/qodot_example/lightmaps/LightMap.png" type="Texture" id=2]
[ext_resource path="res://addons/qodot/src/nodes/qodot_map.gd" type="Script" id=3]
[ext_resource path="res://addons/qodot/src/nodes/qodot_spatial.gd" type="Script" id=4]
[ext_resource path="res://textures/base/checkerboard.png" type="Texture" id=5]
[ext_resource path="res://textures/base/uv_test_512.png" type="Texture" id=6]
[ext_resource path="res://textures/pbr/military-panel.tres" type="Material" id=7]
[ext_resource path="res://addons/qodot/src/build/pipeline/debug_pipeline.gd" type="Script" id=4]
[ext_resource path="res://addons/qodot/src/nodes/qodot_spatial.gd" type="Script" id=5]
[ext_resource path="res://textures/base/checkerboard.png" type="Texture" id=6]
[ext_resource path="res://textures/base/uv_test_512.png" type="Texture" id=7]
[ext_resource path="res://textures/pbr/military-panel.tres" type="Material" id=8]

[sub_resource type="BakedLightmapData" id=1]
bounds = AABB( -19.5469, -6.97813, -23.1791, 39.0938, 13.9563, 46.3582 )
Expand All @@ -19,10 +20,10 @@ user_data = [ NodePath("../QodotMap/Meshes/MaterialsMesh"), ExtResource( 2 ), -1
radius = 0.4

[sub_resource type="SpatialMaterial" id=3]
albedo_texture = ExtResource( 5 )
albedo_texture = ExtResource( 6 )

[sub_resource type="SpatialMaterial" id=4]
albedo_texture = ExtResource( 6 )
albedo_texture = ExtResource( 7 )

[sub_resource type="ArrayMesh" id=5]
lightmap_size_hint = Vector2( 104, 92 )
Expand Down Expand Up @@ -57,7 +58,7 @@ surfaces/2 = {
"blend_shape_data": [ ],
"format": 97599,
"index_count": 180,
"material": ExtResource( 7 ),
"material": ExtResource( 8 ),
"primitive": 4,
"skeleton_aabb": [ ],
"vertex_count": 126
Expand Down Expand Up @@ -190,14 +191,32 @@ far = 500.0

[node name="QodotMap" type="Spatial" parent="."]
script = ExtResource( 3 )
reload = false
print_to_log = true
map = "================================================================"
map_file = "res://scenes/qodot_example/qodot_example.map"
inverse_scale_factor = 16.0
build = "================================================================"
visual_build_type = 1
static_collision_build_type = 4
trigger_collision_build_type = 1
entity_spawn_build_type = 0
static_lighting_build_type = 1
use_custom_build_pipeline = false
custom_build_pipeline = ExtResource( 4 )
textures = "================================================================"
base_texture_path = "res://textures"
texture_extension = ".png"
texture_wads = [ ]
materials = "================================================================"
material_extension = ".tres"
default_material = null
threading = "================================================================"
max_build_threads = 4
build_bucket_size = 4

[node name="Meshes" type="Spatial" parent="QodotMap"]
script = ExtResource( 4 )
script = ExtResource( 5 )
__meta__ = {
"_edit_lock_": true
}
Expand All @@ -210,7 +229,7 @@ material/1 = null
material/2 = null

[node name="Collision" type="Spatial" parent="QodotMap"]
script = ExtResource( 4 )
script = ExtResource( 5 )
__meta__ = {
"_edit_lock_": true
}
Expand All @@ -224,7 +243,7 @@ __meta__ = {
shape = SubResource( 6 )

[node name="Triggers" type="Spatial" parent="QodotMap"]
script = ExtResource( 4 )
script = ExtResource( 5 )
__meta__ = {
"_edit_lock_": true
}
Expand Down

0 comments on commit aae28a6

Please sign in to comment.