Files
Bubberstation/code/game/pooling/atom_pool.dm
MrStonedOne bd6d51a0b5 Massive MC and subsystem rewrite
MC:
	No longer tracks a subsystem's cpu usage. This was basically worthless and took up space on the stat panel
	Can calculate wait down to a tenth of a decisecond to make it fps/world.ticklag agnostic
	Now allows subsystems to have a dynamic wait, that is based on a ratio of how long that subsystem has been taking to process(cost). (This system allows for upper and lower bounds, and an changeable cost delta for each subsystem)
	MC can now be told to init a zlevel

All Subsystems:
	Stats panel now allows child subsystems to pass it a message to add to its stats entry. All subsystems have been moved over to this system - This should cut down on subsystems having to copy and paste the stats proc in order to add to it
	All subsystems now properlly handle being given a zlevel in their init proc

Subsystem changes:
	Air:
		Added air to the dynamic wait subsystem. upper bound: 50, lower bound: 5, cost delta: 3 times process cost
		Air now fires 4 times faster when it can do so without lagging things up
		Pipenet has been merged into air
		Atmos machinery now processes with process_atmos(), ticked by air, not machinery.
		Hotspots (the fire object) are now object pooled
	Pipenet:
		Deleted, added to air
	Machinery:
		Moved all atmos calcualtions in all objects's process() to process_atmos().
	Lighting:
		Added Lighting to the dynamic wait subsystem. upper bound: 20, lower bound: 5, cost delta: 3 times process cost
	Ticker:
		Fixed ticker not updating the lobby panel when game start delayed
		Fixed the game start timer updating rapidly from queued fires when game start delay is removed
	Garbage/qdel:
		qdel will now limit its process time to 2ds a fire.
		qdel can now be given hints as a return to Destroy() as to what should be done with the object.
		the options are:
			queue: (default) this is the normal behavior.
			letmelive: old default to non-null/zero. does nothing with the object
			iwillgc: functionally the same as above, mainly to let people working with objects know that the object will not be queued for GC checking
			harddel: this will queue the object to be deleted without storing a soft reference, mainly to save locate() processing time.
			harddel_now: this will del() the object. To allow for a clean removal of every del() not in qdel
		All objects have been updated to the new system, harddel and iwillgc was not added to any new objects.
		Fixed some objects not GCing because they didn't properlly clear references in Destory()
		Fixed some objects getting qdel'ed preventing other objects from getting GCed because they did not null their reference to that object.
2015-04-29 02:00:25 -07:00

112 lines
2.3 KiB
Plaintext

/*
/tg/station13 /atom/movable Pool:
---------------------------------
By RemieRichards
Creation/Deletion is laggy, so let's reduce reuse and recycle!
Locked to /atom/movable and it's subtypes due to Loc being a const var on /atom
but being read&write on /movable due to how they... move.
Usage:
To get a object, just called PoolOrNew(type, list of args to pass to New)
To put a object back in the pool, call place in pool.
This will call destroy on the object, set its loc to null,
and reset all of its vars to their default
You can override your object's destroy to return QDEL_HINT_PLACEINPOOL
to ensure its always placed in this pool (this will only be acted on if qdel calls destroy, and destroy will not get called twice)
*/
var/global/list/GlobalPool = list()
//You'll be using this proc 90% of the time.
//It grabs a type from the pool if it can
//And if it can't, it creates one
//The pool is flexible and will expand to fit
//The new created atom when it eventually
//Goes into the pool
//Second argument can be a new location
//Or a list of arguments
//Either way it gets passed to new
/proc/PoolOrNew(var/get_type,var/second_arg)
if(!get_type)
return
var/atom/movable/AM
AM = GetFromPool(get_type,second_arg)
if(!AM)
if(ispath(get_type))
if(islist(second_arg))
AM = new get_type (arglist(second_arg))
else
AM = new get_type (second_arg)
if(AM)
return AM
/proc/GetFromPool(var/get_type,var/second_arg)
if(!get_type)
return 0
if(isnull(GlobalPool[get_type]))
return 0
if(length(GlobalPool[get_type]) == 0)
return 0
var/atom/movable/AM = pick_n_take(GlobalPool[get_type])
if(AM)
AM.ResetVars()
if(islist(second_arg))
AM.loc = second_arg[1]
AM.New(arglist(second_arg))
else
AM.loc = second_arg
AM.New(second_arg)
return AM
return 0
/proc/PlaceInPool(var/atom/movable/AM, destroy = 1)
if(!istype(AM))
return
if(AM in GlobalPool[AM.type])
return
if(!GlobalPool[AM.type])
GlobalPool[AM.type] = list()
GlobalPool[AM.type] |= AM
if (destroy)
AM.Destroy()
AM.ResetVars()
/atom/movable/proc/ResetVars()
var/list/excluded = list("animate_movement", "loc", "locs", "parent_type", "vars", "verbs", "type")
for(var/V in vars)
if(V in excluded)
continue
vars[V] = initial(vars[V])
vars["loc"] = null