Skip to content

Commit

Permalink
Removed column graphics multi-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 30, 2024
1 parent 3860517 commit fe23420
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Autoload/Cube.gd
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func get_cubescfg_modified_time():
# read_cubes_cfg()
# # Refresh the display of anything that handles cubes
#
# oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.SINGLE_THREADED)
# oOverheadGraphics.update_full_overhead_map()
# oPickSlabWindow.add_slabs()
# oColumnEditor._on_ColumnEditor_visibility_changed()
# oSlabsetWindow._on_SlabsetWindow_visibility_changed()
Expand Down
2 changes: 1 addition & 1 deletion Autoload/Version.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node

var major_minor = "0.48"
var major_minor = "0.49"
var patch = "0000"
var full = ""
var unearth_map_format_version:float = 1.05
Expand Down
2 changes: 0 additions & 2 deletions Scenes/CfgLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func start(mapPath):
var file_exists = File.new()

for i in files_to_load.size():
var CODETIME_START = OS.get_ticks_msec()
var file_name = files_to_load[i]

var combined_cfg = {}
Expand Down Expand Up @@ -109,7 +108,6 @@ func load_objects_data(cfg): # 10ms
var newEditorTab
var newGenre


if Things.DATA_OBJECT.has(id) == true:
newName = objSection.get("Name", Things.DATA_OBJECT[id][Things.NAME_ID])

Expand Down
3 changes: 0 additions & 3 deletions Scenes/MapBrowser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ func _on_MapBrowser_visibility_changed():


func toggle_map_preview(togglePreview):
if togglePreview == false and oMapBrowser.visible == true:
yield(oOverheadGraphics, "graphics_thread_completed")

oQuickMapPreview.visible = togglePreview

# Toggle to false if currently selecting the opened map
Expand Down
6 changes: 1 addition & 5 deletions Scenes/OpenMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func continue_load(map):
oOverheadOwnership.start()
oScriptHelpers.start()

oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.MULTI_THREADED)
oOverheadGraphics.update_full_overhead_map()

oDataClm.count_filled_clm_entries()

Expand All @@ -203,14 +203,10 @@ func continue_load(map):

oMenu.add_recent(map)




# Update for Undo

oDisplaySlxNumbers.update()


if oColumnEditor.visible == true:
oColumnEditor.visible = false
Utils.popup_centered(oColumnEditor)
Expand Down
56 changes: 3 additions & 53 deletions Scenes/OverheadGraphics.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ onready var oUndoStates = Nodelist.list["oUndoStates"]
onready var oQuickMapPreviewDisplay = Nodelist.list["oQuickMapPreviewDisplay"]
onready var oMessage = Nodelist.list["oMessage"]


signal graphics_thread_completed

var thread_currently_processing = false

var overheadImgData = Image.new()
var overheadTexData = ImageTexture.new()

Expand All @@ -26,16 +21,7 @@ var mutex = Mutex.new()
var job_queue = []
var pixel_data = PoolByteArray()

enum {
SINGLE_THREADED,
MULTI_THREADED,
}

func _ready():
thread.start(self, "multi_threaded")


func update_full_overhead_map(threadType):
func update_full_overhead_map():
var CODETIME_START = OS.get_ticks_msec()

if arrayOfColorRects.empty() == true:
Expand All @@ -48,14 +34,8 @@ func update_full_overhead_map(threadType):
for xSlab in range(0, M.xSize):
shapePositionArray.append(Vector2(xSlab,ySlab))

match threadType:
SINGLE_THREADED:
if thread_currently_processing == false:
overhead2d_update_rect_single_threaded(shapePositionArray)
MULTI_THREADED:
mutex.lock()
job_queue.append(shapePositionArray.duplicate(true)) # This duplicate somehow fixes a crash, or maybe just helps improve a race condition
mutex.unlock()
overhead2d_update_rect_single_threaded(shapePositionArray)

print('Overhead graphics done in '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')


Expand All @@ -66,36 +46,6 @@ func overhead2d_update_rect_single_threaded(shapePositionArray):
overheadImgData.create_from_data(M.xSize * 3, M.ySize * 3, false, Image.FORMAT_RGB8, pixel_data)
overheadTexData.create_from_image(overheadImgData, 0)


func multi_threaded():
while true:
if job_queue.size() == 0:
continue
thread_currently_processing = true
print("graphics multi_threaded start")

mutex.lock()
var shapePositionArray = job_queue.pop_front()
mutex.unlock()

var newPixelData = PoolByteArray()
print("graphics multi_threaded 1")
var resulting_pixel_data = generate_pixel_data(newPixelData, shapePositionArray)
print("graphics multi_threaded 2")
call_deferred("thread_done", resulting_pixel_data)
print("graphics multi_threaded end")


func thread_done(resulting_pixel_data):
if resulting_pixel_data != null:
pixel_data = resulting_pixel_data
overheadImgData.create_from_data(M.xSize * 3, M.ySize * 3, false, Image.FORMAT_RGB8, pixel_data)
overheadTexData.create_from_image(overheadImgData, 0)
else:
oMessage.quick("thread crashed")

thread_currently_processing = false
emit_signal("graphics_thread_completed")

func generate_pixel_data(pixData, shapePositionArray):
print("generate_pixel_data START")
Expand Down
2 changes: 1 addition & 1 deletion Scenes/ResizeCurrentMapSize.gd
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func _on_ResizeApplyButton_pressed():

update_editor_appearance()

oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.SINGLE_THREADED)
oOverheadGraphics.update_full_overhead_map()

# I need to update every slab on the map, it's bugged otherwise, it clears a diagonal streak of objects for some reason.

Expand Down
3 changes: 2 additions & 1 deletion Scenes/UndoStates.gd
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ func perform_undo():
print('perform_undo: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')

var IDLE_FRAME_CODETIME_START = OS.get_ticks_msec()
yield(get_tree(), 'idle_frame')

print('Idle frame (after undo): ' + str(OS.get_ticks_msec() - IDLE_FRAME_CODETIME_START) + 'ms')

performing_undo = false


Expand Down

0 comments on commit fe23420

Please sign in to comment.