Allows for deferred initialization after round start

This commit is contained in:
Crazylemon64
2016-07-02 23:25:21 -07:00
parent f2b48c7c67
commit 2a56c57bcf
4 changed files with 100 additions and 84 deletions
+6 -1
View File
@@ -20,10 +20,15 @@
var/auto_init = 1
// TODO: Make this less deliciously fragile and world-affecting
// This is used in the map loader to defer initialization once all entities
// are placed, so that pipes and window spawners correctly function
// when plunked down mid-game
var/defer_auto_init = 0
/atom/movable/New()
. = ..()
areaMaster = get_area_master(src)
if(auto_init && ticker && ticker.current_state == GAME_STATE_PLAYING)
if(!defer_auto_init && auto_init && ticker && ticker.current_state == GAME_STATE_PLAYING)
initialize()
/atom/movable/Destroy()
@@ -6,7 +6,7 @@
var/useGrille = 1
var/windowtospawn = /obj/structure/window/basic
/obj/effect/spawner/window/New()
/obj/effect/spawner/window/initialize()
spawn(0)
for(var/obj/structure/grille/G in get_turf(src)) qdel(G) //just in case mappers don't know what they are doing
@@ -30,7 +30,8 @@
spawn(10)
qdel(src)
/obj/effect/spawner/window/reinforced
name = "reinforced window spawner"
icon_state = "rwindow_spawner"
windowtospawn = /obj/structure/window/reinforced
windowtospawn = /obj/structure/window/reinforced
+89 -81
View File
@@ -44,96 +44,104 @@ var/global/dmm_suite/preloader/_preloader = new
var/dmm_suite/loaded_map/LM = new
dmmRegex.next = 1
while(dmmRegex.Find(tfile, dmmRegex.next))
// It is *VERY* important that this is reset to 0 when we are done here
// Otherwise lots of things will fall apart like a milkless lich
defer_auto_init = 1
try
dmmRegex.next = 1
while(dmmRegex.Find(tfile, dmmRegex.next))
// "aa" = (/type{vars=blah})
if(dmmRegex.group[1]) // Model
var/key = dmmRegex.group[1]
if(grid_models[key]) // Duplicate model keys are ignored in DMMs
continue
if(key_len != length(key))
if(!key_len)
key_len = length(key)
else
throw EXCEPTION("Inconsistant key length in DMM")
if(!measureOnly)
grid_models[key] = dmmRegex.group[2]
// (1,1,1) = {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
else if(dmmRegex.group[3]) // Coords
if(!key_len)
throw EXCEPTION("Coords before model definition in DMM")
var/xcrdStart = text2num(dmmRegex.group[3]) + x_offset - 1
//position of the currently processed square
var/xcrd
var/ycrd = text2num(dmmRegex.group[4]) + y_offset - 1
var/zcrd = text2num(dmmRegex.group[5]) + z_offset - 1
if(zcrd > world.maxz)
if(cropMap)
// "aa" = (/type{vars=blah})
if(dmmRegex.group[1]) // Model
var/key = dmmRegex.group[1]
if(grid_models[key]) // Duplicate model keys are ignored in DMMs
continue
else
world.maxz = zcrd //create a new z_level if needed
bounds[MAP_MINX] = min(bounds[MAP_MINX], xcrdStart)
bounds[MAP_MINZ] = min(bounds[MAP_MINZ], zcrd)
bounds[MAP_MAXZ] = max(bounds[MAP_MAXZ], zcrd)
var/list/gridLines = splittext(dmmRegex.group[6], "\n")
var/leadingBlanks = 0
while(leadingBlanks < gridLines.len && gridLines[++leadingBlanks] == "")
if(leadingBlanks > 1)
gridLines.Cut(1, leadingBlanks) // Remove all leading blank lines.
if(!gridLines.len) // Skip it if only blank lines exist.
continue
if(gridLines.len && gridLines[gridLines.len] == "")
gridLines.Cut(gridLines.len) // Remove only one blank line at the end.
bounds[MAP_MINY] = min(bounds[MAP_MINY], ycrd)
ycrd += gridLines.len - 1 // Start at the top and work down
if(!cropMap && ycrd > world.maxy)
if(key_len != length(key))
if(!key_len)
key_len = length(key)
else
throw EXCEPTION("Inconsistant key length in DMM")
if(!measureOnly)
world.maxy = ycrd // Expand Y here. X is expanded in the loop below
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], ycrd)
else
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], min(ycrd, world.maxy))
grid_models[key] = dmmRegex.group[2]
var/maxx = xcrdStart
if(measureOnly)
for(var/line in gridLines)
maxx = max(maxx, xcrdStart + length(line) / key_len - 1)
else
for(var/line in gridLines)
if(ycrd <= world.maxy && ycrd >= 1)
xcrd = xcrdStart
for(var/tpos = 1 to length(line) - key_len + 1 step key_len)
if(xcrd > world.maxx)
if(cropMap)
break
else
world.maxx = xcrd
// (1,1,1) = {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
else if(dmmRegex.group[3]) // Coords
if(!key_len)
throw EXCEPTION("Coords before model definition in DMM")
if(xcrd >= 1)
var/model_key = copytext(line, tpos, tpos + key_len)
if(!grid_models[model_key])
throw EXCEPTION("Undefined model key in DMM.")
parse_grid(grid_models[model_key], xcrd, ycrd, zcrd, LM)
CHECK_TICK
var/xcrdStart = text2num(dmmRegex.group[3]) + x_offset - 1
//position of the currently processed square
var/xcrd
var/ycrd = text2num(dmmRegex.group[4]) + y_offset - 1
var/zcrd = text2num(dmmRegex.group[5]) + z_offset - 1
maxx = max(maxx, xcrd)
++xcrd
--ycrd
if(zcrd > world.maxz)
if(cropMap)
continue
else
world.maxz = zcrd //create a new z_level if needed
bounds[MAP_MAXX] = max(bounds[MAP_MAXX], cropMap ? min(maxx, world.maxx) : maxx)
bounds[MAP_MINX] = min(bounds[MAP_MINX], xcrdStart)
bounds[MAP_MINZ] = min(bounds[MAP_MINZ], zcrd)
bounds[MAP_MAXZ] = max(bounds[MAP_MAXZ], zcrd)
CHECK_TICK
var/list/gridLines = splittext(dmmRegex.group[6], "\n")
var/leadingBlanks = 0
while(leadingBlanks < gridLines.len && gridLines[++leadingBlanks] == "")
if(leadingBlanks > 1)
gridLines.Cut(1, leadingBlanks) // Remove all leading blank lines.
if(!gridLines.len) // Skip it if only blank lines exist.
continue
if(gridLines.len && gridLines[gridLines.len] == "")
gridLines.Cut(gridLines.len) // Remove only one blank line at the end.
bounds[MAP_MINY] = min(bounds[MAP_MINY], ycrd)
ycrd += gridLines.len - 1 // Start at the top and work down
if(!cropMap && ycrd > world.maxy)
if(!measureOnly)
world.maxy = ycrd // Expand Y here. X is expanded in the loop below
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], ycrd)
else
bounds[MAP_MAXY] = max(bounds[MAP_MAXY], min(ycrd, world.maxy))
var/maxx = xcrdStart
if(measureOnly)
for(var/line in gridLines)
maxx = max(maxx, xcrdStart + length(line) / key_len - 1)
else
for(var/line in gridLines)
if(ycrd <= world.maxy && ycrd >= 1)
xcrd = xcrdStart
for(var/tpos = 1 to length(line) - key_len + 1 step key_len)
if(xcrd > world.maxx)
if(cropMap)
break
else
world.maxx = xcrd
if(xcrd >= 1)
var/model_key = copytext(line, tpos, tpos + key_len)
if(!grid_models[model_key])
throw EXCEPTION("Undefined model key in DMM.")
parse_grid(grid_models[model_key], xcrd, ycrd, zcrd, LM)
CHECK_TICK
maxx = max(maxx, xcrd)
++xcrd
--ycrd
bounds[MAP_MAXX] = max(bounds[MAP_MAXX], cropMap ? min(maxx, world.maxx) : maxx)
CHECK_TICK
catch(var/exception/e)
// Can't let this stay 1 or the world falls apart
defer_auto_init = 0
throw e
defer_auto_init = 0
qdel(LM)
if(bounds[MAP_MINX] == 1.#INF) // Shouldn't need to check every item
log_startup_progress("Min x: bounds[MAP_MINX]")
+2
View File
@@ -11,6 +11,8 @@ var/global/list/potentialRandomZlevels = generateMapList(filename = "config/away
T.lighting_build_overlays()
for(var/obj/structure/cable/PC in T)
makepowernet_for(PC)
for(var/atom/movable/AM in T)
AM.initialize()
for(var/turf/T in smoothTurfs)
if(T.smooth)
smooth_icon(T)