Gotta go fast (#23609)

* Jukebox playlist cache 40% faster

* Cached minimaps

* add the txt to .gitignore
This commit is contained in:
DamianX
2021-09-12 01:23:12 +02:00
committed by GitHub
parent 2df22e1743
commit aeb1ab8b4d
4 changed files with 98 additions and 139 deletions

View File

@@ -81,12 +81,26 @@ var/const/ALLOW_CENTCOMM = FALSE
/proc/generateMiniMaps()
set category = "Debug"
set name = "Generate minimaps"
//spawn // NO
var/last_git_hash_path = "data/last_git_commit_hash.txt"
var/last_git_hash = trim(file2text(last_git_hash_path))
var/current_git_hash = trim(return_revision())
var/delete_cache = !last_git_hash || !current_git_hash || last_git_hash != current_git_hash
if(delete_cache)
testing("MINIMAP: Deleting outdated cached minimaps")
else
testing("MINIMAP: Will attempt to use cached minimaps")
for (var/z = 1 to world.maxz)
if(z == CENTCOMM_Z && !ALLOW_CENTCOMM)
continue
if(delete_cache)
fdel("[getMinimapFile(z)].png")
generateMiniMap(z)
testing(fdel(last_git_hash_path))
text2file(current_git_hash, last_git_hash_path)
testing("MINIMAP: All minimaps have been generated.")
minimapinit = 1
// some idiot put HTML asset sending here. In a spawn. After a long wait for minimap generation.
@@ -115,9 +129,6 @@ var/const/ALLOW_CENTCOMM = FALSE
/proc/generateMiniMap(z, x1 = 1, y1 = 1, x2 = world.maxx, y2 = world.maxy)
var/result_path = "[getMinimapFile(z)].png"
var/hash_path = "[getMinimapFile(z)].md5"
var/hash = ""
var/temp
var/obj/obj
#ifdef MINIMAP_DEBUG
@@ -125,145 +136,102 @@ var/const/ALLOW_CENTCOMM = FALSE
var/savefile/F = new/savefile(tiledata_path)
#endif
// Note for future developer: If you have tiles on the map with random or dynamic icons this hash check will fail
// every time. You'll have to modify this code to generate a unique hash for your object.
// Don't forget to modify the minimap generation code to use a default icon (or skip generation altogether).
for(var/i = x1 to x2)
for(var/r = y1 to y2)
var/turf/tile = locate(i, r, z)
if (istype(tile.loc, /area/asteroid) || istype(tile.loc, /area/mine/unexplored) || istype(tile, /turf/unsimulated/mineral) || (isspace(tile.loc) && istype(tile, /turf/unsimulated/floor/asteroid)))
temp = "/area/asteroid"
else if (istype(tile.loc, /area/mine) && istype(tile, /turf/unsimulated/floor/asteroid))
temp = "/area/mine/explored"
else if (tile.loc.type == /area/start || (tile.type == get_base_turf(z) && !(locate(/obj/structure/lattice) in tile)) || istype(tile, /turf/space/transit))
temp = "/turf/space"
if (locate(/obj/structure/catwalk) in tile)
else
else if (tile.type == get_base_turf(z))
if (locate(/obj/structure/catwalk) in tile)
temp = "/obj/structure/lattice/catwalk"
else
temp = "/obj/structure/lattice"
else if (tile.type == /turf/simulated/floor/plating && (locate(/obj/structure/shuttle/window) in tile))
temp = "/obj/structure/window/shuttle"
else
temp = "[tile.icon][tile.icon_state][tile.dir]"
obj = locate(/obj/structure/transit_tube) in tile
if (obj)
temp = "[temp]/obj/structure/transit_tube[obj.icon_state][obj.dir]"
#ifdef MINIMAP_DEBUG
if (F["/[tile.y]/[tile.x]"] && F["/[tile.y]/[tile.x]"] != temp)
CRASH("Mismatch: [tile.type] at [tile.x],[tile.y],[tile.z] ([tile.icon], [tile.icon_state], [tile.dir])")
else
F["/[tile.y]/[tile.x]"] << temp
#endif
hash = md5("[hash][temp]")
if (fexists(result_path))
if (!fexists(hash_path) || trim(file2text(hash_path)) != hash)
fdel(result_path)
fdel(hash_path)
testing("Found cached minimap for level [z]")
return
ASSERT(x1 > 0)
ASSERT(y1 > 0)
ASSERT(x2 <= world.maxx)
ASSERT(y2 <= world.maxy)
if (!fexists(result_path))
ASSERT(x1 > 0)
ASSERT(y1 > 0)
ASSERT(x2 <= world.maxx)
ASSERT(y2 <= world.maxy)
var/icon/map_icon = new/icon('html/mapbase2000.png')
var/icon/map_icon = new/icon('html/mapbase2000.png')
// map_icon is fine and contains only 1 direction at this point.
// map_icon is fine and contains only 1 direction at this point.
ASSERT(map_icon.Width() == MAX_ICON_DIMENSION && map_icon.Height() == MAX_ICON_DIMENSION)
ASSERT(map_icon.Width() == MAX_ICON_DIMENSION && map_icon.Height() == MAX_ICON_DIMENSION)
testing("MINIMAP: Generating minimap for z-level [z].")
testing("MINIMAP: Generating minimap for z-level [z].")
var/i = 0
var/icon/turf_icon
var/icon/obj_icon
var/old_icon
var/old_icon_state
var/old_dir
var/new_icon
var/new_icon_state
var/new_dir
var/i = 0
var/icon/turf_icon
var/icon/obj_icon
var/old_icon
var/old_icon_state
var/old_dir
var/new_icon
var/new_icon_state
var/new_dir
for(var/s = x1 to x2)
for(var/r = y1 to y2)
var/turf/tile = locate(s, r, z)
if (tile.turf_flags & NO_MINIMAP)
continue
for(var/s = x1 to x2)
for(var/r = y1 to y2)
var/turf/tile = locate(s, r, z)
if (tile.turf_flags & NO_MINIMAP)
continue
if (tile.loc.type != /area/start && (tile.type != get_base_turf(z)|| (locate(/obj/structure/lattice) in tile) || (locate(/obj/structure/transit_tube) in tile)) && !istype(tile, /turf/space/transit) && !istype(tile.loc, /area/vault))
if (istype(tile.loc, /area/asteroid) || istype(tile.loc, /area/mine/unexplored) || istype(tile, /turf/unsimulated/mineral) || (isspace(tile.loc) && istype(tile, /turf/unsimulated/floor/asteroid)))
new_icon = 'icons/turf/walls.dmi'
new_icon_state = "rock"
new_dir = 2
else if (istype(tile.loc, /area/mine) && istype(tile, /turf/unsimulated/floor/asteroid))
new_icon = 'icons/turf/floors.dmi'
new_icon_state = "asteroid"
new_dir = 2
else if (tile.type == get_base_turf(z))
obj = locate(/obj/structure/lattice) in tile
if (tile.loc.type != /area/start && (tile.type != get_base_turf(z)|| (locate(/obj/structure/lattice) in tile) || (locate(/obj/structure/transit_tube) in tile)) && !istype(tile, /turf/space/transit) && !istype(tile.loc, /area/vault))
if (istype(tile.loc, /area/asteroid) || istype(tile.loc, /area/mine/unexplored) || istype(tile, /turf/unsimulated/mineral) || (isspace(tile.loc) && istype(tile, /turf/unsimulated/floor/asteroid)))
new_icon = 'icons/turf/walls.dmi'
new_icon_state = "rock"
new_dir = 2
else if (istype(tile.loc, /area/mine) && istype(tile, /turf/unsimulated/floor/asteroid))
new_icon = 'icons/turf/floors.dmi'
new_icon_state = "asteroid"
new_dir = 2
else if (tile.type == get_base_turf(z))
obj = locate(/obj/structure/lattice) in tile
if (!obj)
obj = locate(/obj/structure/transit_tube) in tile
ASSERT(obj != null)
if (obj)
new_icon = obj.icon
new_dir = obj.dir
new_icon_state = obj.icon_state
else if (tile.type == /turf/simulated/floor/plating && (locate(/obj/structure/shuttle/window) in tile))
new_icon = 'icons/obj/structures.dmi'
new_dir = 2
new_icon_state = "swindow"
else
new_icon = tile.icon
new_icon_state = tile.icon_state
new_dir = tile.dir
if (new_icon != old_icon || new_icon_state != old_icon_state || new_dir != old_dir)
old_icon = new_icon
old_icon_state = new_icon_state
old_dir = new_dir
turf_icon = new/icon(new_icon, new_icon_state, new_dir, 1, 0)
turf_icon.Scale(ICON_SIZE, ICON_SIZE)
if (tile.type != get_base_turf(z) || (locate(/obj/structure/lattice) in tile))
if (!obj)
obj = locate(/obj/structure/transit_tube) in tile
if (obj)
obj_icon = new/icon(obj.icon, obj.icon_state, obj.dir, 1, 0)
obj_icon.Scale(ICON_SIZE, ICON_SIZE)
turf_icon.Blend(obj_icon, ICON_OVERLAY)
ASSERT(obj != null)
map_icon.Blend(turf_icon, ICON_OVERLAY, ((tile.x - 1) * ICON_SIZE), ((tile.y - 1) * ICON_SIZE))
if ((++i) % 512 == 0)
sleep(1) // deliberate delay to avoid lag spikes
//if ((i % 1024) == 0)
//testing("MINIMAP: Generated [s*(y2-y1+1)+r] of [(y2-y1+1)*(x2-x1+1)] tiles.")
if (obj)
new_icon = obj.icon
new_dir = obj.dir
new_icon_state = obj.icon_state
else if (tile.type == /turf/simulated/floor/plating && (locate(/obj/structure/shuttle/window) in tile))
new_icon = 'icons/obj/structures.dmi'
new_dir = 2
new_icon_state = "swindow"
else
sleep(-1) // avoid sleeping if possible: prioritize pending procs
new_icon = tile.icon
new_icon_state = tile.icon_state
new_dir = tile.dir
//testing("MINIMAP: Generated [(y2-y1+1)*(x2-x1+1)] of [(y2-y1+1)*(x2-x1+1)] tiles. Processed [i] tiles")
if (new_icon != old_icon || new_icon_state != old_icon_state || new_dir != old_dir)
old_icon = new_icon
old_icon_state = new_icon_state
old_dir = new_dir
// BYOND BUG: map_icon now contains 4 directions? Create a new icon with only a single state.
var/icon/result_icon = new/icon()
turf_icon = new/icon(new_icon, new_icon_state, new_dir, 1, 0)
turf_icon.Scale(ICON_SIZE, ICON_SIZE)
result_icon.Insert(map_icon, "", SOUTH, 1, 0)
if (tile.type != get_base_turf(z) || (locate(/obj/structure/lattice) in tile))
obj = locate(/obj/structure/transit_tube) in tile
fcopy(result_icon, result_path)
text2file(hash, hash_path)
if (obj)
obj_icon = new/icon(obj.icon, obj.icon_state, obj.dir, 1, 0)
obj_icon.Scale(ICON_SIZE, ICON_SIZE)
turf_icon.Blend(obj_icon, ICON_OVERLAY)
map_icon.Blend(turf_icon, ICON_OVERLAY, ((tile.x - 1) * ICON_SIZE), ((tile.y - 1) * ICON_SIZE))
if ((++i) % 512 == 0)
sleep(1) // deliberate delay to avoid lag spikes
//if ((i % 1024) == 0)
//testing("MINIMAP: Generated [s*(y2-y1+1)+r] of [(y2-y1+1)*(x2-x1+1)] tiles.")
else
sleep(-1) // avoid sleeping if possible: prioritize pending procs
//testing("MINIMAP: Generated [(y2-y1+1)*(x2-x1+1)] of [(y2-y1+1)*(x2-x1+1)] tiles. Processed [i] tiles")
// BYOND BUG: map_icon now contains 4 directions? Create a new icon with only a single state.
var/icon/result_icon = new/icon()
result_icon.Insert(map_icon, "", SOUTH, 1, 0)
fcopy(result_icon, result_path)
#ifdef MINIMAP_DEBUG
#undef MINIMAP_DEBUG