Skip to content

Commit

Permalink
faster initial texture caching, head icons update
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 28, 2024
1 parent bb1ed2a commit aa8a4fc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
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.44"
var major_minor = "0.45"
var patch = "0000"
var full = ""
var unearth_map_format_version:float = 1.05
Expand Down
42 changes: 27 additions & 15 deletions Scenes/CurrentTextures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ onready var oColumnEditorVoxelView = Nodelist.list["oColumnEditorVoxelView"]
onready var oMapProperties = Nodelist.list["oMapProperties"]

const IMAGE_FORMAT = Image.FORMAT_RGB8
const textureWidth = 256
const textureHeight = 2176

enum {
LOADING_NOT_STARTED
LOADING_IN_PROGRESS
Expand All @@ -45,6 +44,7 @@ func _notification(what: int):
yield(get_tree(),'idle_frame')
oMapProperties._on_MapProperties_visibility_changed() # Refresh list of styles if it's visible


func _on_ReloadTextureMapsButton_pressed():
if texturesLoadedState != LOADING_IN_PROGRESS: # Don't do anything if it's already doing something
oMessage.quick("Reloading tilesets")
Expand Down Expand Up @@ -96,6 +96,7 @@ func start():
if oDataSlab.get_cell(0,0) != -1:
set_current_texture_pack()


func scan_dk_data_directory():
var path = oGame.DK_DATA_DIRECTORY
var dictionary = {}
Expand All @@ -121,25 +122,33 @@ func convert_tmapa_to_image(tmapaDatPath):
var file = File.new()
if file.open(tmapaDatPath, File.READ) == OK:
CODETIME_START = OS.get_ticks_msec()
var imageSize = file.get_len() # (Width * Height)

var img = Image.new()
img.create(textureWidth, textureHeight, false, IMAGE_FORMAT)
file.seek(0)
img.lock()
for y in textureHeight:
for x in textureWidth:
var paletteIndex = file.get_8()
img.set_pixel(x,y,paletteData[paletteIndex])
img.unlock()

print('Converted tmapa*.dat to image in: '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
var texturePalIndices = file.get_buffer(imageSize)
file.close()

var data = PoolByteArray()
data.resize(256 * 2176 * 3)
data.fill(0) # Any space that goes beyond the size of tmapb will be set to black

var idx = 0
for i in (imageSize):
var color = paletteData[texturePalIndices[i]]
data[idx] = color.r8
data[idx + 1] = color.g8
data[idx + 2] = color.b8
idx += 3

var img = Image.new()
img.create_from_data(256, 2176, false, IMAGE_FORMAT, data)

print("Converted " + str(tmapaDatPath.get_file()) + " to image in: " + str(OS.get_ticks_msec() - CODETIME_START) + "ms")
return img
else:
print("Failed to open file.")
return null


func save_image_as_png(img, inputPath):
var fileName = inputPath.get_file().get_basename().to_lower() + ".png"

Expand All @@ -166,20 +175,22 @@ func load_cache_filename(path):
imgA.load(cachePathtmapa)
var imgB = Image.new()
imgB.load(cachePathtmapb)
load_image_into_cache(imgA,imgB, tmapaNumber)
load_image_into_cache(imgA, imgB, tmapaNumber)
#print('Loaded cache file: ' + cachePath)
return OK
else:
print('Cache file not found: ' + cachePathtmapa)
cachedTextures.clear()
return FAILED

func load_image_into_cache(imgA, imgB,tmapaNumber):

func load_image_into_cache(imgA, imgB, tmapaNumber):
tmapaNumber = int(tmapaNumber)
while cachedTextures.size() <= tmapaNumber: # Fill all array positions, in case a tmapa00#.dat file inbetween is deleted
cachedTextures.append([null, null])
cachedTextures[tmapaNumber] = convert_img_to_two_texture_arrays(imgA,imgB)


# SLICE COUNT being too high is the reason TextureArray doesn't work on old PC. (NOT IMAGE SIZE, NOT MIPMAPS EITHER)
# RES files might actually take longer to generate a TextureArray from than PNG, not sure.
func convert_img_to_two_texture_arrays(imgA,imgB):
Expand Down Expand Up @@ -220,6 +231,7 @@ func convert_img_to_two_texture_arrays(imgA,imgB):

return twoTextureArrays


func set_current_texture_pack():
var value = oDataLevelStyle.data

Expand Down
2 changes: 1 addition & 1 deletion Scenes/Guidelines.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func _draw():
var size2 = M.ySize if i == 0 else M.xSize

var center = floor(size1 * 0.5)
var offset = 0.5 if size1 % 2 == 1 else 0
var offset = 0.5 if size1 % 2 == 1 else 0.0
var thickness = 0.15

var start = Vector2(center + offset - thickness, 0)
Expand Down
2 changes: 2 additions & 0 deletions Scenes/OpenMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ onready var oThingDetails = Nodelist.list["oThingDetails"]
onready var oInspector = Nodelist.list["oInspector"]
onready var oGuidelines = Nodelist.list["oGuidelines"]
onready var oResizeCurrentMapSize = Nodelist.list["oResizeCurrentMapSize"]
onready var oOwnerSelection = Nodelist.list["oOwnerSelection"]

var TOTAL_TIME_TO_OPEN_MAP

Expand Down Expand Up @@ -246,6 +247,7 @@ func continue_load(map):

func continue_load_openmap(map):
oEditor.mapHasBeenEdited = false
oOwnerSelection.update_ownership_head_icons()
oPickSlabWindow.add_slabs()
oDynamicMapTree.highlight_current_map()
oCurrentMap.set_path_and_title(map)
Expand Down
39 changes: 27 additions & 12 deletions Scenes/OwnerSelection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@ onready var oOwnershipGridContainer = Nodelist.list["oOwnershipGridContainer"]
onready var oMirrorOptions = Nodelist.list["oMirrorOptions"]
onready var oCollectibleLabel = Nodelist.list["oCollectibleLabel"]
onready var oCurrentFormat = Nodelist.list["oCurrentFormat"]

#onready var oEditor = Nodelist.list["oEditor"]
onready var gridItemScene = preload("res://Scenes/GenericGridItem.tscn")
#onready var $GridContainer = $VBoxContainer/ScrollContainer/GridContainer
onready var oSelectedRect = $Control/SelectedRect
onready var oCenteredLabel = $Control/CenteredLabel
#export var grid_item_size : Vector2
#export var grid_window_scale : float setget update_scale
#

var ownership_available = true

func _ready():

func update_ownership_head_icons():
for i in oOwnershipGridContainer.get_children():
i.free()

var iconSize
var owner_order
if oCurrentFormat.selected == 0: # Classic format
owner_order = [0,1,2,3,4,5]
oOwnershipGridContainer.columns = 6
iconSize = Vector2(42, 42)
else:
owner_order = [0,1,2,3,6,7,8,4,5]

oOwnershipGridContainer.columns = 5
iconSize = Vector2(51, 51)

oOwnershipGridContainer.visible = false
oOwnershipGridContainer.visible = true

for i in owner_order:
var id = gridItemScene.instance()

Expand All @@ -42,19 +48,21 @@ func _ready():
7: id.texture_normal = preload("res://edited_images/plyrsym_32/symbol_player_black_std.png")
8: id.texture_normal = preload("res://edited_images/plyrsym_32/symbol_player_orange_std.png")
setText = Constants.ownershipNames[i]

add_child_to_grid(id, setText)
add_child_to_grid(id, setText, iconSize)

set_selection(oSelection.paintOwnership) # Default initial selection

func add_child_to_grid(id, set_text):

func add_child_to_grid(id, set_text, icon_size):
oOwnershipGridContainer.add_child(id)
set_text = set_text.replace(" ","\n") # Use "New lines" wherever there was a space.
id.set_meta("grid_item_text", set_text)
id.connect("mouse_entered", self, "_on_hovered_over_item", [id])
id.connect("mouse_exited", self, "_on_hovered_none")
id.connect("pressed",self,"pressed",[id])
id.rect_min_size = Vector2(42, 42)
id.rect_min_size = icon_size


func pressed(id):
var setValue = id.get_meta("grid_value")
Expand All @@ -66,9 +74,11 @@ func pressed(id):
set_selection(setValue)
oOnlyOwnership.select_appropriate_button()


func _process(delta): # It's necessary to use _process to update selection, because ScrollContainer won't fire a signal while you're scrolling.
update_selection()


func update_selection():
if oSelectedRect == null: return
if is_instance_valid(oSelectedRect.boundToItem) == false: return
Expand All @@ -82,14 +92,17 @@ func update_selection():
oSelectedRect.rect_global_position = oSelectedRect.boundToItem.rect_global_position
oSelectedRect.rect_size = oSelectedRect.boundToItem.rect_size


func _on_hovered_none():
oCenteredLabel.get_node("Label").text = ""


func _on_hovered_over_item(id):
var offset = Vector2(id.rect_size.x * 0.5, id.rect_size.y * 0.5)
oCenteredLabel.rect_global_position = id.rect_global_position + offset
oCenteredLabel.get_node("Label").text = id.get_meta("grid_item_text")


func set_selection(value):
oSelectedRect.visible = false

Expand All @@ -102,6 +115,7 @@ func set_selection(value):
if id.get_meta("grid_value") == value:
oSelectedRect.boundToItem = id


func collectible_ownership_mode(collMode):
if collMode == true:
oCollectibleLabel.visible = true
Expand All @@ -111,6 +125,7 @@ func collectible_ownership_mode(collMode):
oUseSlabOwnerCheckBox.visible = true
update_ownership_available()


func update_ownership_available():
ownership_available = true
oOwnershipGridContainer.modulate.a = 1.00
Expand Down
3 changes: 2 additions & 1 deletion Scenes/Properties.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ onready var oOptionsOptionButton = Nodelist.list["oOptionsOptionButton"]
onready var oEnsignPositionX = Nodelist.list["oEnsignPositionX"]
onready var oEnsignPositionY = Nodelist.list["oEnsignPositionY"]
onready var oMapCoordinatesWindow = Nodelist.list["oMapCoordinatesWindow"]

onready var oOwnerSelection = Nodelist.list["oOwnerSelection"]
onready var oHBoxPlayers = Nodelist.list["oHBoxPlayers"]
onready var oHBoxSpeech = Nodelist.list["oHBoxSpeech"]
onready var oHBoxEnsignPosition = Nodelist.list["oHBoxEnsignPosition"]
Expand Down Expand Up @@ -112,6 +112,7 @@ func set_format_selection(setFormat):
# When you change format, the object settings that are available also change
oPlacingSettings.update_placing_tab()
oInspector.deselect()
oOwnerSelection.update_ownership_head_icons()

func refresh_dungeon_style_options():
oDungeonStyleList.clear()
Expand Down

0 comments on commit aa8a4fc

Please sign in to comment.