Merge pull request #7512 from Menshin/maploader_instanciation_fix

Maploader instantiation fixes
This commit is contained in:
Mloc
2014-12-24 21:55:13 +00:00

View File

@@ -2,6 +2,9 @@
//SS13 Optimized Map loader //SS13 Optimized Map loader
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
//global datum that will preload variables on atoms instanciation
var/global/dmm_suite/preloader/_preloader = null
/** /**
* Construct the model map and control the loading process * Construct the model map and control the loading process
@@ -163,7 +166,7 @@
//first instance the /area and remove it from the members list //first instance the /area and remove it from the members list
index = members.len index = members.len
var/atom/instance var/atom/instance
var/dmm_suite/preloader/_preloader = new(members_attributes[index])//preloader for assigning set variables on atom creation _preloader = new(members_attributes[index])//preloader for assigning set variables on atom creation
instance = locate(members[index]) instance = locate(members[index])
instance.contents.Add(locate(xcrd,ycrd,zcrd)) instance.contents.Add(locate(xcrd,ycrd,zcrd))
@@ -191,34 +194,6 @@
T = UT T = UT
index++ index++
//Replace the previous part of the code with this if it's unsafe to assume tiles have ALWAYS an /area AND a /turf
/*while(members.len > 0)
var/length = members.len
var/member = members[length]
if(ispath(member,/area))
var/atom/instance
var/dmm_suite/preloader/_preloader = new(members_attributes[length])
instance = locate(member)
instance.contents.Add(locate(xcrd,ycrd,zcrd))
if(_preloader && instance)
_preloader.load(instance)
members.Remove(member)
continue
else if(ispath(member,/turf))
instance_atom(member,members_attributes[length],xcrd,ycrd,zcrd)
members.Remove(member)
continue
else
break
*/
//finally instance all remainings objects/mobs //finally instance all remainings objects/mobs
for(index=1,index < first_turf_index,index++) for(index=1,index < first_turf_index,index++)
instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd) instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd)
@@ -230,11 +205,11 @@
//Instance an atom at (x,y,z) and gives it the variables in attributes //Instance an atom at (x,y,z) and gives it the variables in attributes
/dmm_suite/proc/instance_atom(var/path,var/list/attributes, var/x, var/y, var/z) /dmm_suite/proc/instance_atom(var/path,var/list/attributes, var/x, var/y, var/z)
var/atom/instance var/atom/instance
var/dmm_suite/preloader/_preloader = new(attributes) _preloader = new(attributes, path)
instance = new path (locate(x,y,z), _preloader)//first preloader pass instance = new path (locate(x,y,z))//first preloader pass
if(_preloader && instance)//second preloader pass, as some variables may have been reset/changed by New() if(_preloader && instance)//second preloader pass, for those atoms that don't ..() in New()
_preloader.load(instance) _preloader.load(instance)
return instance return instance
@@ -242,9 +217,9 @@
//text trimming (both directions) helper proc //text trimming (both directions) helper proc
//optionally removes quotes before and after the text (for variable name) //optionally removes quotes before and after the text (for variable name)
/dmm_suite/proc/trim_text(var/what as text,var/trim_quotes=0) /dmm_suite/proc/trim_text(var/what as text,var/trim_quotes=0)
while(length(what) && (findtext(what," ",1,2)))// || findtext(what,quote,1,2))) while(length(what) && (findtext(what," ",1,2)))
what=copytext(what,2,0) what=copytext(what,2,0)
while(length(what) && (findtext(what," ",length(what),0)))// || findtext(what,quote,length(what),0))) while(length(what) && (findtext(what," ",length(what),0)))
what=copytext(what,1,length(what)) what=copytext(what,1,length(what))
if(trim_quotes) if(trim_quotes)
while(length(what) && (findtext(what,quote,1,2))) while(length(what) && (findtext(what,quote,1,2)))
@@ -298,14 +273,18 @@
else if(isnum(text2num(trim_right))) else if(isnum(text2num(trim_right)))
trim_right = text2num(trim_right) trim_right = text2num(trim_right)
//Check for file //Check for null
else if(copytext(trim_right,1,2) == "'") else if(trim_right == "null")
trim_right = file(copytext(trim_right,2,length(trim_right))) trim_right = null
//Check for list //Check for list
else if(copytext(trim_right,1,5) == "list") else if(copytext(trim_right,1,5) == "list")
trim_right = text2list(copytext(trim_right,6,length(trim_right))) trim_right = text2list(copytext(trim_right,6,length(trim_right)))
//Check for file
else if(copytext(trim_right,1,2) == "'")
trim_right = file(copytext(trim_right,2,length(trim_right)))
to_return[trim_left] = trim_right to_return[trim_left] = trim_right
else//simple var else//simple var
@@ -323,10 +302,11 @@
placed.opacity = 1 placed.opacity = 1
placed.underlays += turfs_underlays placed.underlays += turfs_underlays
//atom creation method that preloads variables before creation //atom creation method that preloads variables at creation
/atom/New(atom/loc, dmm_suite/preloader/_dmm_preloader) /atom/New()
if(istype(_dmm_preloader, /dmm_suite/preloader)) if(_preloader && (src.type == _preloader.target_path))//in case the instanciated atom is creating other atoms in New()
_dmm_preloader.load(src) _preloader.load(src)
. = ..() . = ..()
////////////////// //////////////////
@@ -336,12 +316,15 @@
/dmm_suite/preloader /dmm_suite/preloader
parent_type = /datum parent_type = /datum
var/list/attributes var/list/attributes
var/target_path
/dmm_suite/preloader/New(list/the_attributes) /dmm_suite/preloader/New(var/list/the_attributes, var/path)
.=..() .=..()
if(!the_attributes.len) if(!the_attributes.len)
Del() Del()
return
attributes = the_attributes attributes = the_attributes
target_path = path
/dmm_suite/preloader/proc/load(atom/what) /dmm_suite/preloader/proc/load(atom/what)
for(var/attribute in attributes) for(var/attribute in attributes)