Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the maploader with TG's version #19008

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions aurorastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "code\__DEFINES\lighting.dm"
#include "code\__DEFINES\logging.dm"
#include "code\__DEFINES\machinery.dm"
#include "code\__DEFINES\maps.dm"
#include "code\__DEFINES\materials.dm"
#include "code\__DEFINES\math_physics.dm"
#include "code\__DEFINES\maths.dm"
Expand Down Expand Up @@ -242,6 +243,7 @@
#include "code\_globalvars\edible.dm"
#include "code\_globalvars\logging.dm"
#include "code\_globalvars\tgui.dm"
#include "code\_globalvars\lists\mapping.dm"
#include "code\_onclick\adjacent.dm"
#include "code\_onclick\ai.dm"
#include "code\_onclick\click.dm"
Expand Down Expand Up @@ -2371,12 +2373,11 @@
#include "code\modules\lock\lock.dm"
#include "code\modules\lock\lock_construct.dm"
#include "code\modules\makeshift\makeshift_reagents.dm"
#include "code\modules\maps\dmm_suite.dm"
#include "code\modules\mapping\preloader.dm"
#include "code\modules\mapping\reader.dm"
#include "code\modules\maps\helper_landmarks.dm"
#include "code\modules\maps\map_template.dm"
#include "code\modules\maps\reader.dm"
#include "code\modules\maps\ruins.dm"
#include "code\modules\maps\swapmaps.dm"
#include "code\modules\maps\planet_types\asteroid.dm"
#include "code\modules\maps\planet_types\barren.dm"
#include "code\modules\maps\planet_types\crystal.dm"
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@

#define ADMIN_JMP(src) "(<a href='?_src_=holder;adminplayerobservecoodjump=1;X=[src.x];Y=[src.y];Z=[src.z]'>JMP</a>)"
#define COORD(src) "[src ? src.Admin_Coordinates_Readable() : "nonexistent location"]"
#define AREACOORD(src) "[src ? src.Admin_Coordinates_Readable(TRUE) : "nonexistent location"]"
2 changes: 2 additions & 0 deletions code/__DEFINES/maps.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// A map key that corresponds to being one exclusively for Space.
#define SPACE_KEY "space"
2 changes: 2 additions & 0 deletions code/__DEFINES/turfs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
DEFINES
################################*/

#define CHANGETURF_DEFER_CHANGE (1<<0)

#define TURF_REMOVE_CROWBAR BITFLAG(1)
#define TURF_REMOVE_SCREWDRIVER BITFLAG(2)
#define TURF_REMOVE_SHOVEL BITFLAG(3)
Expand Down
17 changes: 15 additions & 2 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@
LAZYINITLIST(lazy_list[key]); \
lazy_list[key] |= value;

///Ensures the length of a list is at least I, prefilling it with V if needed. if V is a proc call, it is repeated for each new index so that list() can just make a new list for each item.
#define LISTASSERTLEN(L, I, V...) \
if (length(L) < I) { \
var/_OLD_LENGTH = length(L); \
L.len = I; \
/* Convert the optional argument to a if check */ \
for (var/_USELESS_VAR in list(V)) { \
for (var/_INDEX_TO_ASSIGN_TO in _OLD_LENGTH+1 to I) { \
L[_INDEX_TO_ASSIGN_TO] = V; \
} \
} \
}

#define reverseList(L) reverse_range(L.Copy())

/*
Aurora Snowflake
*/
Expand All @@ -117,8 +132,6 @@
/proc/list_clear_nulls(list/list_to_clear)
return (list_to_clear.RemoveAll(null) > 0)

#define reverseList(L) reverse_range(L.Copy())

/// Passed into BINARY_INSERT to compare keys
#define COMPARE_KEY __BIN_LIST[__BIN_MID]
/// Passed into BINARY_INSERT to compare values
Expand Down
18 changes: 18 additions & 0 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@
return copytext_char(text, 1, i + 1)
return ""

//Returns a string with reserved characters and spaces after the first and last letters removed
//Like trim(), but very slightly faster. worth it for niche usecases
/proc/trim_reduced(text)
var/starting_coord = 1
var/text_len = length(text)
for (var/i in 1 to text_len)
if (text2ascii(text, i) > 32)
starting_coord = i
break

for (var/i = text_len, i >= starting_coord, i--)
if (text2ascii(text, i) > 32)
return copytext(text, starting_coord, i + 1)

if(starting_coord > 1)
return copytext(text, starting_coord)
return ""

//Returns a string with reserved characters and spaces before the first word and after the last word removed.
/proc/trim(text)
return trim_left(trim_right(text))
Expand Down
2 changes: 2 additions & 0 deletions code/_globalvars/lists/mapping.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// List of all the maps that have been cached for /proc/load_map
GLOBAL_LIST_EMPTY(cached_maps)
11 changes: 5 additions & 6 deletions code/controllers/subsystems/initialization/atlas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ SUBSYSTEM_DEF(atlas)
to_world("<span class='warning'>WARNING: Suspected pre-compiled map: things may break horribly!</span>")
log_subsystem_atlas("-- WARNING: Suspected pre-compiled map! --")

maploader = new

var/datum/map/M
for (var/type in subtypesof(/datum/map))
M = new type
Expand Down Expand Up @@ -186,8 +184,6 @@ SUBSYSTEM_DEF(atlas)
if (!maps_loaded)
world.map_panic("No maps loaded!")

QDEL_NULL(maploader)

InitializeSectors()

var/chosen_sector
Expand Down Expand Up @@ -225,7 +221,7 @@ SUBSYSTEM_DEF(atlas)
var/mfile
var/first_dmm = TRUE
var/time
for (var/i in 1 to files.len)
for (var/i in 1 to length(files))
mfile = files[i]
if (!mapregex.Find(mfile))
continue
Expand All @@ -241,7 +237,10 @@ SUBSYSTEM_DEF(atlas)
first_dmm = FALSE
log_subsystem_atlas("Overwriting first Z.")

if (!maploader.load_map(file(mfile), 0, 0, target_z, no_changeturf = TRUE))
if(!target_z)
world.incrementMaxZ()

if (!load_map(file(mfile), 1, 1, target_z ? target_z : world.maxz, no_changeturf = TRUE, new_z = TRUE))
log_subsystem_atlas("Failed to load '[mfile]'!")
else
log_subsystem_atlas("Loaded level in [(world.time - time)/10] seconds.")
Expand Down
10 changes: 2 additions & 8 deletions code/controllers/subsystems/initialization/map_finalization.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SUBSYSTEM_DEF(finalize)
flags = SS_NO_FIRE | SS_NO_DISPLAY
init_order = INIT_ORDER_MAPFINALIZE

var/dmm_suite/maploader
var/datum/away_mission/selected_mission

/datum/controller/subsystem/finalize/Initialize(timeofday)
Expand Down Expand Up @@ -45,7 +44,6 @@ SUBSYSTEM_DEF(finalize)
sortTim(GLOB.all_areas, GLOBAL_PROC_REF(cmp_name_asc))

/datum/controller/subsystem/finalize/proc/load_space_ruin()
maploader = new

if(!selected_mission)
log_subsystem_mapfinalization("Not loading away mission, because no mission has been selected.")
Expand All @@ -56,22 +54,20 @@ SUBSYSTEM_DEF(finalize)
var/time = world.time
LOG_DEBUG("Attempting to load [mfile]")

if (!maploader.load_map(file(mfile), 0, 0, no_changeturf = TRUE))
if (!load_map(file(mfile), 1, 1, no_changeturf = TRUE))
log_subsystem_mapfinalization_error("Failed to load '[mfile]'!")
log_mapping("Failed to load '[mfile]'!")
admin_notice(SPAN_DANGER("Failed to load '[mfile]'!"), R_DEBUG)
else
log_subsystem_mapfinalization("Loaded away mission on z [world.maxz] in [(world.time - time)/10] seconds.")
admin_notice(SPAN_DANGER("Loaded away mission on z [world.maxz] in [(world.time - time)/10] seconds."), R_DEBUG)
SSatlas.current_map.restricted_levels.Add(world.maxz)
QDEL_NULL(maploader)

/datum/controller/subsystem/finalize/proc/place_dungeon_spawns()
var/map_directory = "maps/dungeon_spawns/"
var/list/files = flist(map_directory)
var/start_time = world.time
var/dungeons_placed = 0
var/dmm_suite/maploader = new

var/dungeon_chance = GLOB.config.dungeon_chance

Expand All @@ -96,7 +92,7 @@ SUBSYSTEM_DEF(finalize)

if(isfile(map_file)) //Sanity
log_subsystem_mapfinalization("Loading dungeon '[chosen_dungeon]' at coordinates [spawn_location.x], [spawn_location.y], [spawn_location.z].")
maploader.load_map(map_file,spawn_location.x,spawn_location.y,spawn_location.z)
load_map(map_file,spawn_location.x,spawn_location.y,spawn_location.z)
dungeons_placed += 1
else
log_subsystem_mapfinalization_error("ERROR: Something weird happened with the file: [chosen_dungeon].")
Expand All @@ -107,8 +103,6 @@ SUBSYSTEM_DEF(finalize)

log_subsystem_mapfinalization("Loaded [dungeons_placed] asteroid dungeons in [(world.time - start_time)/10] seconds.")

qdel(maploader)

/datum/controller/subsystem/finalize/proc/generate_contact_report()
if(!selected_mission)
return
Expand Down
4 changes: 2 additions & 2 deletions code/game/atom/atoms_initializing_EXPENSIVE.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
*/
/atom/New(loc, ...)
// For the DMM Suite.
if(GLOB.use_preloader && (src.type == GLOB._preloader_path))//in case the instanciated atom is creating other atoms in New()
GLOB._preloader.load(src)
if(GLOB.use_preloader && src.type == GLOB._preloader_path)//in case the instanciated atom is creating other atoms in New()
world.preloader_load(src)

//. = ..() //uncomment if you are dumb enough to add a /datum/New() proc

Expand Down
45 changes: 45 additions & 0 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,51 @@ var/list/world_api_rate_limit = list()
return TRUE


/**
* Handles incresing the world's maxx var and intializing the new turfs and assigning them to the global area.
* If map_load_z_cutoff is passed in, it will only load turfs up to that z level, inclusive.
* This is because maploading will handle the turfs it loads itself.
*/
/world/proc/increase_max_x(new_maxx, map_load_z_cutoff = maxz)
if(new_maxx <= maxx)
return
//var/old_max = world.maxx
maxx = new_maxx
if(!map_load_z_cutoff)
return
//var/area/global_area = GLOB.areas_by_type[world.area] // We're guaranteed to be touching the global area, so we'll just do this
//LISTASSERTLEN(global_area.turfs_by_zlevel, map_load_z_cutoff, list())
// for (var/zlevel in 1 to map_load_z_cutoff)
// var/list/to_add = block(
// locate(old_max + 1, 1, zlevel),
// locate(maxx, maxy, zlevel))
//
// global_area.turfs_by_zlevel[zlevel] += to_add

/world/proc/increase_max_y(new_maxy, map_load_z_cutoff = maxz)
if(new_maxy <= maxy)
return
//var/old_maxy = maxy
maxy = new_maxy
if(!map_load_z_cutoff)
return
//var/area/global_area = GLOB.areas_by_type[world.area] // We're guarenteed to be touching the global area, so we'll just do this
//LISTASSERTLEN(global_area.turfs_by_zlevel, map_load_z_cutoff, list())
// for (var/zlevel in 1 to map_load_z_cutoff)
// var/list/to_add = block(
// locate(1, old_maxy + 1, 1),
// locate(maxx, maxy, map_load_z_cutoff))
// global_area.turfs_by_zlevel[zlevel] += to_add

/world/proc/incrementMaxZ()
world.maxz++
// SSmobs.MaxZChanged()
// SSidlenpcpool.MaxZChanged()

//This doesn't belong here... But we do not have the Z-level manager TG does, so it will do, for now
//btw, the content of the signal is also different than what TG expects
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_Z, world.maxz)

/world/proc/change_fps(new_value = 20)
if(new_value <= 0)
CRASH("change_fps() called with [new_value] new_value.")
Expand Down
15 changes: 15 additions & 0 deletions code/modules/admin/verbs/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,22 @@ var/intercom_range_display_status = 0
new/obj/effect/debugging/camera_range(C.loc)
feedback_add_details("admin_verb","mCRD") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!

#ifdef TESTING
GLOBAL_LIST_EMPTY(dirty_vars)

/client/proc/see_dirty_varedits()
set category = "Mapping"
set name = "Dirty Varedits"

var/list/dat = list()
dat += "<h3>Abandon all hope ye who enter here</h3><br><br>"
for(var/thing in GLOB.dirty_vars)
dat += "[thing]<br>"
CHECK_TICK
var/datum/browser/popup = new(usr, "dirty_vars", "Dirty Varedits", 900, 750)
popup.set_content(dat.Join())
popup.open()
#endif

/client/proc/sec_camera_report()
set category = "Mapping"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/awaymissions/zlevel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
potentialRandomZlevels.Add(name)


var/static/dmm_suite/loader = new
if(potentialRandomZlevels.len)
admin_notice("<span class='danger'>Loading away mission...</span>", R_DEBUG)

var/map = pick(potentialRandomZlevels)
var/file = file(map)
if(isfile(file))
loader.load_map(file)
load_map(file)
LOG_DEBUG("away mission loaded: [map]")

for(var/obj/effect/landmark/L in GLOB.landmarks_list)
Expand Down
41 changes: 41 additions & 0 deletions code/modules/mapping/preloader.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// global datum that will preload variables on atoms instanciation
GLOBAL_VAR_INIT(use_preloader, FALSE)
GLOBAL_LIST_INIT(_preloader_attributes, null)
GLOBAL_LIST_INIT(_preloader_path, null)

/// Preloader datum
/datum/map_preloader
var/list/attributes
var/target_path

/world/proc/preloader_setup(list/the_attributes, path)
if(the_attributes.len)
GLOB.use_preloader = TRUE
GLOB._preloader_attributes = the_attributes
GLOB._preloader_path = path

/world/proc/preloader_load(atom/what)
GLOB.use_preloader = FALSE
var/list/attributes = GLOB._preloader_attributes
for(var/attribute in attributes)
var/value = attributes[attribute]
if(islist(value))
value = deep_copy_list(value)
#ifdef TESTING
if(what.vars[attribute] == value)
var/message = "<font color=green>[what.type]</font> at [AREACOORD(what)] - <b>VAR:</b> <font color=red>[attribute] = [isnull(value) ? "null" : (isnum(value) ? value : "\"[value]\"")]</font>"
log_mapping("DIRTY VAR: [message]")
GLOB.dirty_vars += message
#endif
what.vars[attribute] = value

/// Template noop (no operation) is used to skip a turf or area when the template is loaded this allows for template transparency
/// ex. if a ship has gaps in it's design, you would use template_noop to fill these in so that when the ship moves z-level, any
/// tiles these gaps land on will not be deleted and replaced with the ships (empty) tiles
/area/template_noop
name = "Area Passthrough"

/// See above explanation
/turf/template_noop
name = "Turf Passthrough"
icon_state = "noop"
Loading
Loading