anchor.diff:  	. = _load_impl(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
   	Master.StopLoadingMap()
   
  -
   #define MAPLOADING_CHECK_TICK \
   	if(TICK_CHECK) { \
   		SSatoms.map_loader_stop(); \
   		stoplag(); \
   		SSatoms.map_loader_begin(); \
   	}
  +
   // Do not call except via load() above.
   /datum/parsed_map/proc/_load_impl(x_offset = 1, y_offset = 1, z_offset = world.maxz + 1, cropMap = FALSE, no_changeturf = FALSE, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY, placeOnTop = FALSE, new_z = FALSE)
   	PRIVATE_PROC(TRUE)
  +	// Tell ss atoms that we're doing maploading
  +	// We'll have to account for this in the following tick_checks so it doesn't overflow
  +	SSatoms.map_loader_begin()
  +
  +	// Loading used to be done in this proc
  +	// We make the assumption that if the inner procs runtime, we WANT to do cleanup on them, but we should stil tell our parents we failed
  +	// Since well, we did
  +	var/sucessful = FALSE
  +	switch(map_format)
  +		if(MAP_TGM)
  +			sucessful = _tgm_load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
  +		else
  +			sucessful = _dmm_load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
  +
  +	// And we are done lads, call it off
  +	SSatoms.map_loader_stop()
  +
  +	if(new_z)
  +		for(var/z_index in bounds[MAP_MINZ] to bounds[MAP_MAXZ])
  +			SSmapping.build_area_turfs(z_index)
  +
  +	if(!no_changeturf)
  +		for(var/turf/T as anything in block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])))
  +			//we do this after we load everything in. if we don't, we'll have weird atmos bugs regarding atmos adjacent turfs
  +			T.AfterChange(CHANGETURF_IGNORE_AIR)
  +
  +	if(expanded_x || expanded_y)
  +		SEND_GLOBAL_SIGNAL(COMSIG_GLOB_EXPANDED_WORLD_BOUNDS, expanded_x, expanded_y)
  +
  +	#ifdef TESTING
  +	if(turfsSkipped)
  +		testing("Skipped loading [turfsSkipped] default turfs")
  +	#endif
  +
  +	return sucessful
  +
  +// Wanna clear something up about maps, talking in 255x255 here
  +// In the tgm format, each gridset contains 255 lines, each line representing one tile, with 255 total gridsets
  +// In the dmm format, each gridset contains 255 lines, each line representing one row of tiles, containing 255 * line length characters, with one gridset per z
  +// You can think of dmm as storing maps in rows, whereas tgm stores them in columns
  +/datum/parsed_map/proc/_tgm_load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
  +	// setup
  +	var/list/modelCache = build_cache(no_changeturf)
  +	var/space_key = modelCache[SPACE_KEY]
  +	var/list/bounds
  +	src.bounds = bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
  +
  +	// Building y coordinate ranges
  +	var/y_relative_to_absolute = y_offset - 1
  +	var/x_relative_to_absolute = x_offset - 1
  +
  +	// Ok so like. something important
  +	// We talk in "relative" coords here, so the coordinate system of the map datum
  +	// This is so we can do offsets, but it is NOT the same as positions in game
  +	// That's why there's some uses of - y_relative_to_absolute here, to turn absolute positions into relative ones
  +	// TGM maps process in columns, so the starting y will always be the max size
  +	// We know y starts at 1
  +	var/datum/grid_set/first_column = gridSets[1]
  +	var/relative_y = first_column.ycrd
  +	var/highest_y = relative_y + y_relative_to_absolute
  +
  +	if(!cropMap && highest_y > world.maxy)
  +		world.maxy = highest_y // Expand Y here. X is expanded later on
  +		expanded_y = TRUE
  +
  +	// Skip Y coords that are above the smallest of the three params
  +	// So maxy and y_upper get to act as thresholds, and relative_y can play
  +	var/y_skip_above = min(world.maxy - y_relative_to_absolute, y_upper, relative_y)
  +	// How many lines to skip because they'd be above the y cuttoff line
  +	var/y_starting_skip = relative_y - y_skip_above
  +	highest_y += y_starting_skip
  +
  +
  +	// Y is the LOWEST it will ever be here, so we can easily set a threshold for how low to go
  +	var/line_count = length(first_column.gridLines)
  +	var/lowest_y = relative_y - (line_count - 1) // -1 because we decrement at the end of the loop, not the start
  +	var/y_ending_skip = max(max(y_lower, 1 - y_relative_to_absolute) - lowest_y, 0)
  +
  +	// X setup
  +	var/x_delta_with = x_upper
  +	if(cropMap)
  +		// Take our smaller crop threshold yes?
  +		x_delta_with = min(x_delta_with, world.maxx)
  +
  +	// We're gonna skip all the entries above the upper x, or maxx if cropMap is set
  +	// The last column is guarenteed to have the highest x value we;ll encounter
  +	// Even if z scales, this still works
  +	var/datum/grid_set/last_column = gridSets[length(gridSets)]
  +	var/final_x = last_column.xcrd + x_relative_to_absolute
  +
  +	if(final_x > x_delta_with)
  +		// If our relative x is greater then X upper, well then we've gotta limit our expansion
  +		var/delta = max(final_x - x_delta_with, 0)
  +		final_x -= delta
  +	if(final_x > world.maxx && !cropMap)
  +		world.maxx = final_x
  +		expanded_x = TRUE
  +
  +	var/lowest_x = max(x_lower, 1 - x_relative_to_absolute)
  +
  +	// We make the assumption that the last block of turfs will have the highest embedded z in it
  +	var/highest_z = last_column.zcrd + z_offset - 1 // Lets not just make a new z level each time we increment maxz
  +	var/z_threshold = world.maxz
  +	if(highest_z > z_threshold && cropMap)
  +		for(var/i in z_threshold + 1 to highest_z) //create a new z_level if needed
  +			world.incrementMaxZ()
  +		if(!no_changeturf)
  +			WARNING("Z-level expansion occurred without no_changeturf set, this may cause problems when /turf/AfterChange is called")
  +
  +	for(var/datum/grid_set/gset as anything in gridSets)
  +		var/true_xcrd = gset.xcrd + x_relative_to_absolute
  +
  +		// any cutoff of x means we just shouldn't iterate this gridset
  +		if(final_x < true_xcrd || lowest_x > gset.xcrd)
  +			continue
  +
  +		var/zcrd = gset.zcrd + z_offset - 1
  +		// If we're using changeturf, we disable it if we load into a z level we JUST created
  +		var/no_afterchange = no_changeturf || zcrd > z_threshold
  +
  +		// We're gonna track the first and last pairs of coords we find
  +		// Since x is always incremented in steps of 1, we only need to deal in y
  +		// The first x is guarenteed to be the lowest, the first y the highest, and vis versa
  +		// This is faster then doing mins and maxes inside the hot loop below
  +		var/first_found = FALSE
  +		var/first_y = 0
  +		var/last_y = 0
  +
  +		var/ycrd = highest_y
  +		// Everything following this line is VERY hot.
  +		for(var/i in 1 + y_starting_skip to line_count - y_ending_skip)
  +			if(gset.gridLines[i] == space_key && no_afterchange)
  +				#ifdef TESTING
  +				++turfsSkipped
  +				#endif
  +				ycrd--
  +				MAPLOADING_CHECK_TICK
  +				continue
  +
  +			var/list/cache = modelCache[gset.gridLines[i]]
  +			if(!cache)
  +				SSatoms.map_loader_stop()
  +				CRASH("Undefined model key in DMM: [gset.gridLines[i]]")
  +			build_coordinate(cache, locate(true_xcrd, ycrd, zcrd), no_afterchange, placeOnTop, new_z)
  +
  +			// only bother with bounds that actually exist
  +			if(!first_found)
  +				first_found = TRUE
  +				first_y = ycrd
  +			last_y = ycrd
  +			ycrd--
  +			MAPLOADING_CHECK_TICK
  +
  +		// The x coord never changes, so not tracking first x is safe
  +		// If no ycrd is found, we assume this row is totally empty and just continue on
  +		if(first_found)
  +			bounds[MAP_MINX] = min(bounds[MAP_MINX], true_xcrd)
  +			bounds[MAP_MINY] = min(bounds[MAP_MINY], last_y)
  +			bounds[MAP_MINZ] = min(bounds[MAP_MINZ], zcrd)
  +			bounds[MAP_MAXX] = max(bounds[MAP_MAXX], true_xcrd)
  +			bounds[MAP_MAXY] = max(bounds[MAP_MAXY], first_y)
  +			bounds[MAP_MAXZ] = max(bounds[MAP_MAXZ], zcrd)
  +	return TRUE
  +
  +/// Stanrdard loading, not used in production
  +/// Doesn't take advantage of any tgm optimizations, which makes it slower but also more general
  +/// Use this if for some reason your map format is messy
  +/datum/parsed_map/proc/_dmm_load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
  +	// setup
   	var/list/modelCache = build_cache(no_changeturf)
   	var/space_key = modelCache[SPACE_KEY]
   	var/list/bounds
   	var/key_len = src.key_len
   	src.bounds = bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
   
  -	// Tell ss atoms that we're doing maploading
  -	// We'll have to account for this in the following tick_checks so it doesn't overflow
  -	SSatoms.map_loader_begin()
  -
  -	//used for sending the maxx and maxy expanded global signals at the end of this proc
  -	var/has_expanded_world_maxx = FALSE
  -	var/has_expanded_world_maxy = FALSE
   	var/y_relative_to_absolute = y_offset - 1
   	var/x_relative_to_absolute = x_offset - 1
  +	var/line_len = src.line_len
   	for(var/datum/grid_set/gset as anything in gridSets)
   		var/relative_x = gset.xcrd
   		var/relative_y = gset.ycrd
  
positive.code: 			continue
  
  		.[model_key] = list(members, members_attributes)
  
  /datum/parsed_map/proc/build_coordinate(list/model, turf/crds, no_changeturf as num, placeOnTop as num, new_z)
  	// If we don't have a turf, nothing we will do next will actually acomplish anything, so just go back
  
negative.code: 
  	// raw strings used to represent regexes more accurately
  	// '' used to avoid confusing syntax highlighting
  	var/static/regex/dmm_regex = new(@'"([a-zA-Z]+)" = (?:\(\n|\()((?:.|\n)*?)\)\n(?!\t)|\((\d+),(\d+),(\d+)\) = \{"([a-zA-Z\n]*)"\}', "g")
  	/// Matches key formats in TMG (IE: newline after the \()
  	var/static/regex/matches_tgm = new(@'^"[A-z]*"[\s]*=[\s]*\([\s]*\n', "m")
  	/// Pulls out key value pairs for TGM
  	var/static/regex/var_edits_tgm = new(@'^\t([A-z]*) = (.*?);?$')
  	/// Pulls out model paths for DMM
  	var/static/regex/model_path = new(@'(\/[^\{]*?(?:\{.*?\})?)(?:,|$)', "g")
  
  	#ifdef TESTING
  	var/turfsSkipped = 0
  