Fixes a bug involving a map template resetting the map loader's

progress
This commit is contained in:
Crazylemon64
2016-07-06 22:51:48 -07:00
parent 2ca2397e69
commit 1745c71474
13 changed files with 111 additions and 48 deletions
+20 -9
View File
@@ -9,30 +9,41 @@
var/template_name = null
var/datum/map_template/template = null
var/centered = 1
var/loaded = 0
var/delay_init = 0
/obj/effect/landmark/map_loader/New(loc, tname)
/obj/effect/landmark/map_loader/New(turf/loc, tname)
..()
if(tname)
template_name = tname
if(template_name)
template = map_templates[template_name]
/obj/effect/landmark/map_loader/initialize()
..()
if(template)
load(template)
/obj/effect/landmark/map_loader/proc/load(datum/map_template/t)
spawn(1)
if(!t)
return
t.load(get_turf(src), centered = centered)
t.loaded++
qdel(src)
if(!t)
return
if(loaded)
return
loaded = 1
var/turf/pos = get_turf(src)
// Hop to nullspace so we don't get re-initialized by the map we're loading
loc = null
t.load(pos, centered = centered, delay_init = delay_init)
t.loaded++
qdel(src)
/obj/effect/landmark/map_loader/random
var/template_list = ""
/obj/effect/landmark/map_loader/random/New()
/obj/effect/landmark/map_loader/random/initialize()
..()
if(template_list)
template_name = safepick(splittext(template_list, ";"))
template = map_templates[template_name]
load(template)
load(template)
+31 -8
View File
@@ -8,6 +8,9 @@ var/global/use_preloader = FALSE
var/global/dmm_suite/preloader/_preloader = new
/dmm_suite
// These regexes are global - meaning that starting the maploader again mid-load will
// reset progress - which means we need to track our index per-map, or we'll
// eternally recurse
// /"([a-zA-Z]+)" = \(((?:.|\n)*?)\)\n(?!\t)|\((\d+),(\d+),(\d+)\) = \{"([a-zA-Z\n]*)"\}/g
var/static/regex/dmmRegex = new/regex({""(\[a-zA-Z]+)" = \\(((?:.|\n)*?)\\)\n(?!\t)|\\((\\d+),(\\d+),(\\d+)\\) = \\{"(\[a-zA-Z\n]*)"\\}"}, "g")
// /^[\s\n]+"?|"?[\s\n]+$|^"|"$/g
@@ -35,7 +38,9 @@ var/global/dmm_suite/preloader/_preloader = new
*/
/dmm_suite/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, delay_init as num)
var/tfile = dmm_file//the map file we're creating
var/fname = "Lambda"
if(isfile(tfile))
fname = "[tfile]"
tfile = file2text(tfile)
if(!x_offset)
@@ -49,14 +54,19 @@ var/global/dmm_suite/preloader/_preloader = new
var/list/grid_models = list()
var/key_len = 0
var/dmm_suite/loaded_map/LM = new
if(measureOnly)
delay_init = 0
// This try-catch is used as a budget "Finally" clause, as the dirt count
// needs to be reset
var/watch = start_watch()
log_debug("[measureOnly ? "Measuring" : "Loading"] map: [fname]")
try
dmmRegex.next = 1
while(dmmRegex.Find(tfile, dmmRegex.next))
LM.index = 1
while(dmmRegex.Find(tfile, LM.index))
LM.index = dmmRegex.next
// "aa" = (/type{vars=blah})
if(dmmRegex.group[1]) // Model
@@ -136,8 +146,10 @@ var/global/dmm_suite/preloader/_preloader = new
if(xcrd >= 1)
var/model_key = copytext(line, tpos, tpos + key_len)
if(!grid_models[model_key])
throw EXCEPTION("Undefined model key in DMM.")
throw EXCEPTION("Undefined model key in DMM: [model_key]. Map file: [fname].")
parse_grid(grid_models[model_key], xcrd, ycrd, zcrd, LM)
// After this call, it is NOT safe to reference `dmmRegex` without another call to
// "Find" - we might've hit a map loader here and changed its state
CHECK_TICK
maxx = max(maxx, xcrd)
@@ -148,14 +160,17 @@ var/global/dmm_suite/preloader/_preloader = new
CHECK_TICK
catch(var/exception/e)
_preloader.reset()
if(delay_init)
for(var/i in LM.touched_z_levels)
zlevels.remove_dirt(i)
throw e
if(delay_init)
_preloader.reset()
for(var/i in LM.touched_z_levels)
zlevels.remove_dirt(i)
log_debug("Loaded map in [stop_watch(watch)]s.")
qdel(LM)
if(bounds[MAP_MINX] == 1.#INF) // Shouldn't need to check every item
log_debug("Min x: bounds[MAP_MINX]")
@@ -166,10 +181,11 @@ var/global/dmm_suite/preloader/_preloader = new
log_debug("Max z: bounds[MAP_MAXZ]")
return null
else
for(var/t in block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])))
var/turf/T = t
//we do this after we load everything in. if we don't; we'll have weird atmos bugs regarding atmos adjacent turfs
T.AfterChange(1,but_its_not_the_saaaaaame = TRUE) // are you happy now
if(!measureOnly)
for(var/t in block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])))
var/turf/T = t
//we do this after we load everything in. if we don't; we'll have weird atmos bugs regarding atmos adjacent turfs
T.AfterChange(1,keep_cabling = TRUE)
return bounds
/**
@@ -204,7 +220,6 @@ var/global/dmm_suite/preloader/_preloader = new
members = cached[1]
members_attributes = cached[2]
else
/////////////////////////////////////////////////////////
//Constructing members and corresponding variables lists
////////////////////////////////////////////////////////
@@ -418,6 +433,7 @@ var/global/dmm_suite/preloader/_preloader = new
//Preloader datum
//////////////////
// This ain't re-entrant, but we had this before the maploader update
/dmm_suite/preloader
parent_type = /datum
var/list/attributes
@@ -437,6 +453,12 @@ var/global/dmm_suite/preloader/_preloader = new
what.vars[attribute] = value
use_preloader = FALSE
// If the map loader fails, make this safe
/dmm_suite/preloader/proc/reset()
use_preloader = FALSE
attributes = list()
target_path = null
// A datum for use within the context of loading a single map,
// so that one can have separate "unpowered" areas for ruins or whatever,
// yet have a single area type for use of mapping, instead of creating
@@ -445,6 +467,7 @@ var/global/dmm_suite/preloader/_preloader = new
parent_type = /datum
var/list/touched_z_levels = list()
var/list/area_list = list()
var/index = 1 // To store the state of the regex
/dmm_suite/loaded_map/proc/area_path_to_real_area(area/A)
if(!ispath(A, /area))
@@ -54,9 +54,8 @@
name = "space hotel pamphlet"
info = "<h3>Welcome to Deep Space Hotel 419!</h3>Thank you for choosing our hotel. Simply hand your credit or debit card to the concierge and get your room key! To check out, hand your credit card back.<small><h4>Conditions:</h4><ul><li>The hotel is not responsible for any losses due to time or space anomalies.<li>The hotel is not responsible for events that occur outside of the hotel station, including, but not limited to, events that occur inside of dimensional pockets.<li>The hotel is not responsible for overcharging your account.<li>The hotel is not responsible for missing persons.<li>The hotel is not responsible for mind-altering effects due to drugs, magic, demons, or space worms.</ul></small>"
/obj/effect/landmark/map_loader/hotel_room/New()
/obj/effect/landmark/map_loader/hotel_room/initialize()
..()
// load and randomly assign rooms
var/global/list/south_room_templates = list()
var/global/list/north_room_templates = list()
@@ -65,17 +64,18 @@
if(!loaded)
loaded = 1
for(var/map in flist(path))
var/datum/map_template/T = new(path = "[path][map]", rename = "[map]")
if(copytext(map, 1, 3) == "n_")
north_room_templates += T
else if(copytext(map, 1, 3) == "s_")
south_room_templates += T
else
// omnidirectional rooms are randomly assigned
if(prob(50))
if(cmptext(copytext(map, length(map) - 3), ".dmm"))
var/datum/map_template/T = new(path = "[path][map]", rename = "[map]")
if(copytext(map, 1, 3) == "n_")
north_room_templates += T
else
else if(copytext(map, 1, 3) == "s_")
south_room_templates += T
else
// omnidirectional rooms are randomly assigned
if(prob(50))
north_room_templates += T
else
south_room_templates += T
var/datum/map_template/M = safepick(dir == NORTH ? north_room_templates : south_room_templates)
if(M)
@@ -309,4 +309,4 @@
S.retal_target = target
S.retal = 1
#undef CHECKOUT_TIME
#undef CHECKOUT_TIME
+32
View File
@@ -31,6 +31,9 @@ var/global/list/potentialRandomZlevels = generateMapList(filename = "config/away
var/atom/A = R
if(A.smooth)
smooth_icon(A)
if(istype(T, /turf/simulated/mineral)) // For the listening post, among other maps
var/turf/simulated/mineral/MT = T
MT.add_edges()
log_debug("\tTook [stop_watch(subtimer)]s")
log_debug("Initializing pipenets")
@@ -70,6 +73,35 @@ var/global/list/potentialRandomZlevels = generateMapList(filename = "config/away
log_startup_progress(" No away missions found.")
return
/proc/createALLZlevels()
if(awaydestinations.len) //crude, but it saves another var!
return
if(potentialRandomZlevels && potentialRandomZlevels.len)
var/watch = start_watch()
log_startup_progress("Loading away missions...")
for(var/map in potentialRandomZlevels)
var/file = file(map)
if(isfile(file))
log_startup_progress("Loading away mission: [map]")
maploader.load_map(file)
late_setup_level(block(locate(1, 1, world.maxz), locate(world.maxx, world.maxy, world.maxz)))
log_to_dd(" Away mission loaded: [map]")
//map_transition_config.Add(AWAY_MISSION_LIST)
for(var/obj/effect/landmark/L in landmarks_list)
if (L.name != "awaystart")
continue
awaydestinations.Add(L)
log_startup_progress(" Away mission loaded in [stop_watch(watch)]s.")
watch = start_watch()
else
log_startup_progress(" No away missions found.")
return
/proc/generateMapList(filename)
var/list/potentialMaps = list()
+2 -1
View File
@@ -9,6 +9,7 @@
invisibility = INVISIBILITY_LIGHTING
color = "#000000"
icon_state = "light1"
auto_init = 0 // doesn't need special init
var/lum_r
var/lum_g
@@ -104,4 +105,4 @@
if(istype(T))
T.lighting_overlay = null
return ..()
return ..()
@@ -7,8 +7,9 @@ var/global/datum/zlev_manager/zlevels = new
// Populate our z level list
/datum/zlev_manager/proc/initialize()
for(var/i = 1, i < world.maxz, i++)
z_list.Add(new /datum/zlevel(i))
z_list.len = world.maxz
for(var/i = 1, i <= world.maxz, i++)
z_list[i] = new /datum/zlevel(i)
// For when you need the z-level to be at a certain point
@@ -23,7 +24,8 @@ var/global/datum/zlev_manager/zlevels = new
/datum/zlev_manager/proc/add_new_zlevel()
world.maxz++
var/our_z = world.maxz
z_list.Add(new /datum/zlevel(our_z))
z_list.len++
z_list[our_z] = new /datum/zlevel(our_z)
return our_z
/datum/zlev_manager/proc/cut_levels_downto(new_maxz)
@@ -37,7 +39,7 @@ var/global/datum/zlev_manager/zlevels = new
/datum/zlev_manager/proc/kill_topmost_zlevel()
var/our_z = world.maxz
qdel(z_list[our_z])
z_list.Remove(our_z)
z_list.len--
world.maxz--
/*