Files
Yogstation/code/datums/datum.dm
Chubbygummibear 0fda5cfc6a Icon smoothing, and Rendering overhaul, and Camera fix, and mapmerge.py fix, and Multi-z, and THE PLANE CUBE (#21221)
* why no work

angy

* weird errors

shit sucks

* fixved it

I can spell good

* fix?

POSSIBLY

* nope

wasnt this

* no more immutable

thhanks koffee

* ok

ok

* removes all the pref stuff

""removes""

* remove this

idiot

* this goes bye

 bye

* these go too

genius

* bye

bye

* better night vision

* tries to fix camera

maybe

* ok fuck it we ball

we ball

* ok lets go back

go back go back go back

* WORK

DAMNIT

* ha

fuc kyou

* this

maybe

* this doesnt work :(

* maybe fix

maybe

* fucks everything

why do i do this

* test update

test

* Revert "tries to fix camera"

This reverts commit 2d14fbae66.

* reverts everything I just did

peko pain

* bye

bitch

* oh yeah add this

I guess

* Fucks up the camera net + chunk

why

* test maybe revert

* Revert "test maybe revert"

This reverts commit 98c5ef1b93.

* Revert "Fucks up the camera net + chunk"

This reverts commit 0e421ebf5f.

* this isnt going well

uh oh

* Attempts to rework out security camera

and probably more

* Revert "this isnt going well"

This reverts commit 1d8ceac867.

* Revert "Revert "this isnt going well""

This reverts commit e26fb61415.

* ok

ok

* Revert "ok"

This reverts commit 7e7a7f8372.

* Revert "Merge remote-tracking branch 'upstream/master' into NahI'dPortit"

This reverts commit 01094731c1, reversing
changes made to c0cf69ebf1.

* this doesn't need to be redefined

I guess

* no we need this

totally

* a familiar pain

* 515 is L

* yeah

yeah

* ok god

fine

* bye bye basemap :(

doesnt work on runtime station

* Fixes AI statis not working

god im good

* remove this

oh god

* Revert "Revert "Merge remote-tracking branch 'upstream/master' into NahI'dPortit""

This reverts commit b3fb3ba0db.

* proves to god I exist

and im pissed

* yog exclusive feature (tm)

plane master

* bring this back from previous push

* updates vendor emissives

as well as firealarms

* Updates barsign

and fucks everything up

* Fixes barsigns breaks all lights and updates barsigns to be machines and not structures

We will address this in a later patch

* not sure who changed that

oh well

* yeah

this got moved

* this needs updating

yeah

* turns off the carbon monoxide alarm

duh

* FIXES IT YES

thank you biome

* turns this off too

yeah

* Can't compile yet but ports a ton of shit

* L

* the game opens ig

* extra shit

* fixes

* signals and smooth queue

* look ma im going horribly out of scope

* fixes chasms

* this fixed nothing

* ???

* more barsigns

for later

* forgive me cowboy. also fuck diagonals

* oops

we need this apparently

* fuck it we ball

* Update _lists.dm

* Update icon_smoothing.dm

* it now works kinda

* Update atom_initializing_EXPENSIVE.dm

* lighting don't work

* we have light

* sort turfs better

* big fucking reorganize

* like everything except templates

* boy i sure hope nothing bad happens to these bar templates

* we're back

* no runtimes baby

* no errors

* shuttles are almost fixed i think

* Revert "shuttles are almost fixed i think"

This reverts commit 046058827c.

* Revert "Merge remote-tracking branch 'upstream/master' into icon_smoothing"

This reverts commit 863e1b776d, reversing
changes made to 884623e600.

* Revert "no errors"

This reverts commit 884623e600.

* too far back i think

* midround smoothing runtimes fixed i think

* comment cleanup

* should fix the component runtimes

* Revert "Revert "Merge remote-tracking branch 'upstream/master' into icon_smoothing""

This reverts commit a8ff8d63aa.

* NO RUNTIMES AND ICEMETA WORKS LET'S GOOOOOO

* please stay fixed icemeta

* organizing render dms

* woops this too in the reorganizing

* cryo fixed

* nah, i'd win

* parallax isn't my problem

* pls don't break icemeta

* runtime station gets a cam console

* well it compiles

* maybe fix the map

* woops

* man i hate maps

* was that it?

* PLEASE

* missing focus tests

* maybe that was it

* maybe

* let's take the batteries out of the carbon monoxide detector

* fuck osha

* i hate vending machines

* that's not a computer

* slot machine fix

* PLEASE

* that wasn't supposed to be there

* fuck it i can't fix everything at once

* BLUESPACE LOCKER?

* literally why

* hhh

* does this fix chasms?

* that should fix bad index

* please?

* turf_flags for reservations

* haha oops

* yolo (kill me)

* fix wood walls and other walls

* fix stairs

* that might have fixed shittles

* baseturfs are good now i think

* should fix plasma windows

* decals fixed

* please fix changelog

* shuttle lighting still fucky

* lighting is stinky slow and doesn't finish updating by the time the server starts guh

* lighting seemingly works

* slipping works

* shuttle sounds, slips, and windoors fixed

* why am i here

* fuck the changelog

* of course someone touched smoothing as i'm almost done

* we good?

* updating ai_eye and rename

* z updates and more ai cam updates

* ice fixed

* weather and ice fix

* clockies can see and other clean up catches

* windows fixed

* cowbot forgive me i'm trying to update flashlights to tg because there's no light on lower multi-z z's like ice meta bottom floor

* movable lighting works on multi-z

* gps fix

* item stacking from drag works

* falsewall fix

* job panel fixed

* AI HANDLED

* woops that comment should be gone

* i hate ai i hate ai

* brass glass visible again

* vents on top of tiles now

* sigdrobe sprite back

* centcomm portals work

* portals and see openspace mapping icons fixed

* icemeta my behated

* kill

* is that it

* lighting cutoff is old hat

* angery overlay

* not super necessary

* also extra but whatever

* ticker but thicker

* job fix i hope

* this isn't needed anymore

* latejoin fix?

* laserpointer, pipecrawl, and some consoles fixed

* i hate fixing bugs as they're made

* we're not ready for that

* redef cleanup

* gps arrows, gun flashlights, shuttle console placement, multi-z pulling fixed

* goofy ah gun code

* this was a good idea and necessary

* should fix caltrop component

* does this please the linter

* linter please accept this async function

* THERE

* take the batteries out

* make it stop

* cowbot stopped me from letting ghosts dab

* recycler loc fix

* fix border firedoors not blocking movement

* should fix screen fade out and fade in on round start and end

* darker command tile trim and fixed bronze wall sprites

* fuck you linter

* railings actually stop you from leaving

* probably fixes gibtonite overlay when struck

* armaments dispenser and clockwork catwalk

* turbine fix probably

* pointing at inhand items should be fixed

* fix overwatch app

* should hopefully fix cable rotation on shuttle move

* flashlights have better directionality logic

* hopefully fixes shuttle atmos on move

* grilles fixed

* hopefully this fixes shuttle buttons, airolocks, and other machinery not working after moving

* ice meta mining area finally not freezing

* fix lightbulb icons not updating

* lava mask and lighting dots

* we actually have this

* fuck glowshrooms GC

* fix light fixture interactions and icon updates

* hopefully catches all the updates

* lava lighting good to go

* seclite was missing inhands

* smoothing in replays

* light updates accurate in replays

* biome's multi-z requests

---------

Co-authored-by: cowbot92 <75333826+cowbot92@users.noreply.github.com>
Co-authored-by: Molti <gamingjoelouis@gmail.com>
Co-authored-by: Ringalong <53777086+JohnFulpWillard@users.noreply.github.com>
2024-02-18 13:16:55 -06:00

381 lines
12 KiB
Plaintext

/**
* The absolute base class for everything
*
* A datum instantiated has no physical world prescence, use an atom if you want something
* that actually lives in the world
*
* Be very mindful about adding variables to this class, they are inherited by every single
* thing in the entire game, and so you can easily cause memory usage to rise a lot with careless
* use of variables at this level
*/
/datum
/**
* Tick count time when this object was destroyed.
*
* If this is non zero then the object has been garbage collected and is awaiting either
* a hard del by the GC subsystme, or to be autocollected (if it has no references)
*/
var/gc_destroyed
/// Active timers with this datum as the target
var/list/_active_timers
/// Status traits attached to this datum. associative list of the form: list(trait name (string) = list(source1, source2, source3,...))
var/list/_status_traits
/**
* Components attached to this datum
*
* Lazy associated list in the structure of `type -> component/list of components`
*/
var/list/_datum_components
/**
* Any datum registered to receive signals from this datum is in this list
*
* Lazy associated list in the structure of `signal -> registree/list of registrees`
*/
var/list/_listen_lookup
/// Lazy associated list in the structure of `target -> list(signal -> proctype)` that are run when the datum receives that signal
var/list/list/_signal_procs
/// Datum level flags
var/datum_flags = NONE
/// A cached version of our \ref
/// The brunt of \ref costs are in creating entries in the string tree (a tree of immutable strings)
/// This avoids doing that more then once per datum by ensuring ref strings always have a reference to them after they're first pulled
var/cached_ref
/// A weak reference to another datum
var/datum/weakref/weak_reference
/*
* Lazy associative list of currently active cooldowns.
*
* cooldowns [ COOLDOWN_INDEX ] = add_timer()
* add_timer() returns the truthy value of -1 when not stoppable, and else a truthy numeric index
*/
var/list/cooldowns
/// List for handling persistent filters.
var/list/filter_data
#ifdef TESTING
var/running_find_references
var/last_find_references = 0
#endif
#ifdef DATUMVAR_DEBUGGING_MODE
var/list/cached_vars
#endif
/**
* Called when a href for this datum is clicked
*
* Sends a COMSIG_TOPIC signal
*/
/datum/Topic(href, href_list[])
..()
SEND_SIGNAL(src, COMSIG_TOPIC, usr, href_list)
/**
* Default implementation of clean-up code.
*
* This should be overridden to remove all references pointing to the object being destroyed, if
* you do override it, make sure to call the parent and return it's return value by default
*
* Return an appropriate QDEL_HINT to modify handling of your deletion;
* in most cases this is QDEL_HINT_QUEUE.
*
* The base case is responsible for doing the following
* * Erasing timers pointing to this datum
* * Erasing compenents on this datum
* * Notifying datums listening to signals from this datum that we are going away
*
* Returns QDEL_HINT_QUEUE
*/
/datum/proc/Destroy(force=FALSE, ...)
SHOULD_CALL_PARENT(TRUE)
tag = null
datum_flags &= ~DF_USE_TAG //In case something tries to REF us
weak_reference = null //ensure prompt GCing of weakref.
if(_active_timers)
var/list/timers = _active_timers
_active_timers = null
for(var/datum/timedevent/timer as anything in timers)
if (timer.spent && !(timer.flags & TIMER_DELETE_ME))
continue
qdel(timer)
//BEGIN: ECS SHIT
var/list/dc = _datum_components
if(dc)
for(var/component_key in dc)
var/component_or_list = dc[component_key]
if(islist(component_or_list))
for(var/datum/component/component as anything in component_or_list)
qdel(component, FALSE, TRUE)
else
var/datum/component/C = component_or_list
qdel(C, FALSE, TRUE)
dc.Cut()
clear_signal_refs()
return QDEL_HINT_QUEUE
///Only override this if you know what you're doing. You do not know what you're doing
///This is a threat
/datum/proc/clear_signal_refs()
var/list/lookup = _listen_lookup
if(lookup)
for(var/sig in lookup)
var/list/comps = lookup[sig]
if(length(comps))
for(var/datum/component/comp as anything in comps)
comp.UnregisterSignal(src, sig)
else
var/datum/component/comp = comps
comp.UnregisterSignal(src, sig)
_listen_lookup = lookup = null
for(var/target in _signal_procs)
UnregisterSignal(target, _signal_procs[target])
#ifdef DATUMVAR_DEBUGGING_MODE
/datum/proc/save_vars()
cached_vars = list()
for(var/i in vars)
if(i == "cached_vars")
continue
cached_vars[i] = vars[i]
/datum/proc/check_changed_vars()
. = list()
for(var/i in vars)
if(i == "cached_vars")
continue
if(cached_vars[i] != vars[i])
.[i] = list(cached_vars[i], vars[i])
/datum/proc/txt_changed_vars()
var/list/l = check_changed_vars()
var/t = "[src]([REF(src)]) changed vars:"
for(var/i in l)
t += "\"[i]\" \[[l[i][1]]\] --> \[[l[i][2]]\] "
t += "."
/datum/proc/to_chat_check_changed_vars(target = world)
to_chat(target, txt_changed_vars())
#endif
///Return a LIST for serialize_datum to encode! Not the actual json!
/datum/proc/serialize_list(list/options)
CRASH("Attempted to serialize datum [src] of type [type] without serialize_list being implemented!")
///Accepts a LIST from deserialize_datum. Should return src or another datum.
/datum/proc/deserialize_list(json, list/options)
CRASH("Attempted to deserialize datum [src] of type [type] without deserialize_list being implemented!")
///Serializes into JSON. Does not encode type.
/datum/proc/serialize_json(list/options)
. = serialize_list(options)
if(!islist(.))
. = null
else
. = json_encode(.)
///Deserializes from JSON. Does not parse type.
/datum/proc/deserialize_json(list/input, list/options)
var/list/jsonlist = json_decode(input)
. = deserialize_list(jsonlist)
if(!istype(., /datum))
. = null
///Convert a datum into a json blob
/proc/json_serialize_datum(datum/D, list/options)
if(!istype(D))
return
var/list/jsonlist = D.serialize_list(options)
if(islist(jsonlist))
jsonlist["DATUM_TYPE"] = D.type
return json_encode(jsonlist)
/// Convert a list of json to datum
/proc/json_deserialize_datum(list/jsonlist, list/options, target_type, strict_target_type = FALSE)
if(!islist(jsonlist))
if(!istext(jsonlist))
CRASH("Invalid JSON")
jsonlist = json_decode(jsonlist)
if(!islist(jsonlist))
CRASH("Invalid JSON")
if(!jsonlist["DATUM_TYPE"])
return
if(!ispath(jsonlist["DATUM_TYPE"]))
if(!istext(jsonlist["DATUM_TYPE"]))
return
jsonlist["DATUM_TYPE"] = text2path(jsonlist["DATUM_TYPE"])
if(!ispath(jsonlist["DATUM_TYPE"]))
return
if(target_type)
if(!ispath(target_type))
return
if(strict_target_type)
if(target_type != jsonlist["DATUM_TYPE"])
return
else if(!ispath(jsonlist["DATUM_TYPE"], target_type))
return
var/typeofdatum = jsonlist["DATUM_TYPE"] //BYOND won't directly read if this is just put in the line below, and will instead runtime because it thinks you're trying to make a new list?
var/datum/D = new typeofdatum
var/datum/returned = D.deserialize_list(jsonlist, options)
if(!istype(returned, /datum))
qdel(D)
else
return returned
/**
* Callback called by a timer to end an associative-list-indexed cooldown.
*
* Arguments:
* * source - datum storing the cooldown
* * index - string index storing the cooldown on the cooldowns associative list
*
* This sends a signal reporting the cooldown end.
*/
/proc/end_cooldown(datum/source, index)
if(QDELETED(source))
return
SEND_SIGNAL(source, COMSIG_CD_STOP(index))
TIMER_COOLDOWN_END(source, index)
/**
* Proc used by stoppable timers to end a cooldown before the time has ran out.
*
* Arguments:
* * source - datum storing the cooldown
* * index - string index storing the cooldown on the cooldowns associative list
*
* This sends a signal reporting the cooldown end, passing the time left as an argument.
*/
/proc/reset_cooldown(datum/source, index)
if(QDELETED(source))
return
SEND_SIGNAL(source, COMSIG_CD_RESET(index), S_TIMER_COOLDOWN_TIMELEFT(source, index))
TIMER_COOLDOWN_END(source, index)
/** Add a filter to the datum.
* This is on datum level, despite being most commonly / primarily used on atoms, so that filters can be applied to images / mutable appearances.
* Can also be used to assert a filter's existence. I.E. update a filter regardless if it exists or not.
*
* Arguments:
* * name - Filter name
* * priority - Priority used when sorting the filter.
* * params - Parameters of the filter.
*/
/datum/proc/add_filter(name, priority, list/params)
LAZYINITLIST(filter_data)
var/list/copied_parameters = params.Copy()
copied_parameters["priority"] = priority
filter_data[name] = copied_parameters
update_filters()
/// Reapplies all the filters.
/datum/proc/update_filters()
ASSERT(isatom(src) || istype(src, /image))
var/atom/atom_cast = src // filters only work with images or atoms.
atom_cast.filters = null
filter_data = sortTim(filter_data, GLOBAL_PROC_REF(cmp_filter_data_priority), TRUE)
for(var/filter_raw in filter_data)
var/list/data = filter_data[filter_raw]
var/list/arguments = data.Copy()
arguments -= "priority"
atom_cast.filters += filter(arglist(arguments))
UNSETEMPTY(filter_data)
/obj/item/update_filters()
. = ..()
update_item_action_buttons()
/** Update a filter's parameter to the new one. If the filter doesnt exist we won't do anything.
*
* Arguments:
* * name - Filter name
* * new_params - New parameters of the filter
* * overwrite - TRUE means we replace the parameter list completely. FALSE means we only replace the things on new_params.
*/
/datum/proc/modify_filter(name, list/new_params, overwrite = FALSE)
var/filter = get_filter(name)
if(!filter)
return
if(overwrite)
filter_data[name] = new_params
else
for(var/thing in new_params)
filter_data[name][thing] = new_params[thing]
update_filters()
/** Update a filter's parameter and animate this change. If the filter doesnt exist we won't do anything.
* Basically a [datum/proc/modify_filter] call but with animations. Unmodified filter parameters are kept.
*
* Arguments:
* * name - Filter name
* * new_params - New parameters of the filter
* * time - time arg of the BYOND animate() proc.
* * easing - easing arg of the BYOND animate() proc.
* * loop - loop arg of the BYOND animate() proc.
*/
/datum/proc/transition_filter(name, list/new_params, time, easing, loop)
var/filter = get_filter(name)
if(!filter)
return
// This can get injected by the filter procs, we want to support them so bye byeeeee
new_params -= "type"
animate(filter, new_params, time = time, easing = easing, loop = loop)
modify_filter(name, new_params)
/// Updates the priority of the passed filter key
/datum/proc/change_filter_priority(name, new_priority)
if(!filter_data || !filter_data[name])
return
filter_data[name]["priority"] = new_priority
update_filters()
/// Returns the filter associated with the passed key
/datum/proc/get_filter(name)
ASSERT(isatom(src) || istype(src, /image))
if(filter_data && filter_data[name])
var/atom/atom_cast = src // filters only work with images or atoms.
return atom_cast.filters[filter_data.Find(name)]
/// Returns the indice in filters of the given filter name.
/// If it is not found, returns null.
/datum/proc/get_filter_index(name)
return filter_data?.Find(name)
/// Removes the passed filter, or multiple filters, if supplied with a list.
/datum/proc/remove_filter(name_or_names)
if(!filter_data)
return
var/list/names = islist(name_or_names) ? name_or_names : list(name_or_names)
for(var/name in names)
if(filter_data[name])
filter_data -= name
update_filters()
/datum/proc/clear_filters()
ASSERT(isatom(src) || istype(src, /image))
var/atom/atom_cast = src // filters only work with images or atoms.
filter_data = null
atom_cast.filters = null
/// Return text from this proc to provide extra context to hard deletes that happen to it
/// Optional, you should use this for cases where replication is difficult and extra context is required
/// Can be called more then once per object, use harddel_deets_dumped to avoid duplicate calls (I am so sorry)
/datum/proc/dump_harddel_info()
return