Skip to content

Commit

Permalink
Harddel Fix Pack #42 + Better Live Reftracking Support (#63877)
Browse files Browse the repository at this point in the history
* Hard Del Fixes, Ref Tracking Changes
  • Loading branch information
LemonInTheDark committed Jan 12, 2022
1 parent f3f7720 commit f8aad14
Show file tree
Hide file tree
Showing 109 changed files with 873 additions and 741 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/is_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#define isatom(A) (isloc(A))

#define isdatum(thing) (istype(thing, /datum))

#define isweakref(D) (istype(D, /datum/weakref))

//Turfs
Expand Down
11 changes: 9 additions & 2 deletions code/__HELPERS/_logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global"))
SEND_TEXT(world.log, text)
#endif

#ifdef REFERENCE_TRACKING
#if defined(REFERENCE_DOING_IT_LIVE)
#define log_reftracker(msg) log_harddel("## REF SEARCH [msg]")

/proc/log_harddel(text)
WRITE_LOG(GLOB.harddel_log, text)

#elif defined(REFERENCE_TRACKING) // Doing it locally
#define log_reftracker(msg) log_world("## REF SEARCH [msg]")
#else

#else //Not tracking at all
#define log_reftracker(msg)
#endif

Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/memory_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Adds a memory to a mob's mind if conditions are met, called wherever the memory takes place (memory for catching on fire in mob's fire code, for example)
* Argument:
* * memory_type: defined string in memory_defines.dm, shows the memories.json file which story parts to use (and generally what type it is)
* * extra_info: the contents of the story. You're gonna want at least the protagonist for who is the main character in the story
* * extra_info: the contents of the story. You're gonna want at least the protagonist for who is the main character in the story (Any non basic type will be converted to a string on insertion)
* * story_value: the quality of the memory, make easy or roundstart memories have a low value so they don't flood persistence
* * memory_flags: special specifications for skipping parts of the memory like moods for stories where showing moods doesn't make sense
* Returns the datum memory created, null otherwise.
Expand Down
10 changes: 10 additions & 0 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
#define TRACK_MAX_SHARE //Allows max share tracking, for use in the atmos debugging ui
#endif //ifdef TESTING

/// If this is uncommented, we set up the ref tracker to be used in a live environment
/// And to log events to [log_dir]/harddels.log
//#define REFERENCE_DOING_IT_LIVE
#ifdef REFERENCE_DOING_IT_LIVE
// compile the backend
#define REFERENCE_TRACKING
// actually look for refs
#define GC_FAILURE_HARD_LOOKUP
#endif // REFERENCE_DOING_IT_LIVE

//#define UNIT_TESTS //If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between

#ifndef PRELOAD_RSC //set to:
Expand Down
4 changes: 4 additions & 0 deletions code/_globalvars/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ GLOBAL_PROTECT(picture_logging_id)
GLOBAL_VAR(picture_logging_prefix)
GLOBAL_PROTECT(picture_logging_prefix)
/////
#ifdef REFERENCE_DOING_IT_LIVE
GLOBAL_LIST_EMPTY(harddel_log)
GLOBAL_PROTECT(harddel_log)
#endif
8 changes: 8 additions & 0 deletions code/_onclick/hud/fullscreen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@
icon_state = "flash"
alpha = 80

/atom/movable/screen/fullscreen/bluespace_sparkle
icon = 'icons/effects/effects.dmi'
screen_loc = "WEST,SOUTH to EAST,NORTH"
icon_state = "shieldsparkles"
layer = FLASH_LAYER
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
show_when_dead = TRUE

/atom/movable/screen/fullscreen/color_vision/green
color = "#00ff00"

Expand Down
3 changes: 3 additions & 0 deletions code/controllers/subsystem/air.dm
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@ GLOBAL_LIST_EMPTY(colored_images)
/datum/controller/subsystem/air/proc/start_processing_machine(obj/machinery/machine)
if(machine.atmos_processing)
return
if(QDELETED(machine))
stack_trace("We tried to add a garbage collecting machine to SSair. Don't")
return
machine.atmos_processing = TRUE
atmos_machinery += machine

Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/garbage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ SUBSYSTEM_DEF(garbage)
#ifdef REFERENCE_TRACKING
if (QDEL_HINT_FINDREFERENCE) //qdel will, if REFERENCE_TRACKING is enabled, display all references to this object, then queue the object for deletion.
SSgarbage.Queue(D)
D.find_references()
D.find_references() //This breaks ci. Consider it insurance against somehow pring reftracking on accident
if (QDEL_HINT_IFFAIL_FINDREFERENCE) //qdel will, if REFERENCE_TRACKING is enabled and the object fails to collect, display all references to this object.
SSgarbage.Queue(D)
SSgarbage.reference_find_on_fail["\ref[D]"] = TRUE
Expand Down
3 changes: 2 additions & 1 deletion code/controllers/subsystem/parallax.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ SUBSYSTEM_DEF(parallax)
if(!istype(movable_eye))
continue

for (movable_eye; isloc(movable_eye.loc) && !isturf(movable_eye.loc); movable_eye = movable_eye.loc);
while(isloc(movable_eye.loc) && !isturf(movable_eye.loc))
movable_eye = movable_eye.loc
//get the last movable holding the mobs eye

if(movable_eye == processing_client.movingmob)
Expand Down
21 changes: 14 additions & 7 deletions code/datums/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

/datum/action/proc/link_to(Target)
target = Target
RegisterSignal(Target, COMSIG_ATOM_UPDATED_ICON, .proc/OnUpdatedIcon)
RegisterSignal(target, COMSIG_ATOM_UPDATED_ICON, .proc/OnUpdatedIcon)
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/clear_ref, override = TRUE)

/datum/action/Destroy()
if(owner)
Expand All @@ -49,7 +50,7 @@
return
Remove(owner)
owner = M
RegisterSignal(owner, COMSIG_PARENT_QDELETING, .proc/owner_deleted)
RegisterSignal(owner, COMSIG_PARENT_QDELETING, .proc/clear_ref, override = TRUE)

//button id generation
var/counter = 0
Expand All @@ -75,9 +76,12 @@
else
Remove(owner)

/datum/action/proc/owner_deleted(datum/source)
/datum/action/proc/clear_ref(datum/ref)
SIGNAL_HANDLER
Remove(owner)
if(ref == owner)
Remove(owner)
if(ref == target)
qdel(src)

/datum/action/proc/Remove(mob/M)
for(var/datum/weakref/reference as anything in sharers)
Expand All @@ -93,10 +97,13 @@
M.update_action_buttons()
if(owner)
UnregisterSignal(owner, COMSIG_PARENT_QDELETING)
if(target == owner)
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/clear_ref)
owner = null
button.moved = FALSE //so the button appears in its normal position when given to another owner.
button.locked = FALSE
button.id = null
if(button)
button.moved = FALSE //so the button appears in its normal position when given to another owner.
button.locked = FALSE
button.id = null

/datum/action/proc/Trigger()
if(!IsAvailable())
Expand Down
17 changes: 10 additions & 7 deletions code/datums/ai/_item_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
///Max attemps to make
var/max_attempts = 3


/datum/ai_behavior/item_move_close_and_attack/setup(datum/ai_controller/controller, target_key, throw_count_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]

var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/item_move_close_and_attack/perform(delta_time, datum/ai_controller/controller, target_key, throw_count_key)
. = ..()
var/obj/item/item_pawn = controller.pawn
var/atom/throw_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()

item_pawn.visible_message(span_warning("[item_pawn] hurls towards [throw_target]!"))
item_pawn.throw_at(throw_target, rand(4,5), 9)
Expand All @@ -48,12 +48,15 @@
controller.blackboard -= target_key
controller.blackboard[throw_count_key] = 0

/datum/ai_behavior/item_move_close_and_attack/haunted
/datum/ai_behavior/item_move_close_and_attack/ghostly
attack_sound = 'sound/items/haunted/ghostitemattack.ogg'
max_attempts = 4

/datum/ai_behavior/item_move_close_and_attack/haunted/finish_action(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/atom/throw_target = controller.blackboard[target_key]
/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted

/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted/finish_action(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()
var/list/hauntee_list = controller.blackboard[BB_TO_HAUNT_LIST]
hauntee_list[throw_target]--
return ..()
10 changes: 4 additions & 6 deletions code/datums/ai/cursed/cursed_behaviors.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed

/datum/ai_behavior/item_move_close_and_attack/cursed
attack_sound = 'sound/items/haunted/ghostitemattack.ogg'
max_attempts = 4

/datum/ai_behavior/item_move_close_and_attack/cursed/reset_blackboard(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/atom/throw_target = controller.blackboard[target_key]
/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed/reset_blackboard(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()
//dropping our target from the blackboard if they are no longer a valid target after the attack behavior
if(get_dist(throw_target, controller.pawn) > CURSED_VIEW_RANGE)
controller.blackboard[target_key] = null
5 changes: 3 additions & 2 deletions code/datums/ai/cursed/cursed_subtrees.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
var/obj/item/item_pawn = controller.pawn

//make sure we have a target
var/mob/living/carbon/curse_target = controller.blackboard[BB_CURSE_TARGET]
var/datum/weakref/target_ref = controller.blackboard[BB_CURSE_TARGET]
var/mob/living/carbon/curse_target = target_ref?.resolve()
if(!curse_target)
controller.queue_behavior(/datum/ai_behavior/find_and_set, BB_CURSE_TARGET, /mob/living/carbon, CURSED_VIEW_RANGE)
return
Expand All @@ -11,4 +12,4 @@
controller.blackboard[BB_CURSE_TARGET] = null
return
controller.current_movement_target = curse_target
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/cursed)
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed)
30 changes: 19 additions & 11 deletions code/datums/ai/generic/generic_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,22 @@
pawn.activate_hand(pawn.get_active_hand())
finish_action(controller, TRUE)

/// Use the currently held item, or unarmed, on an object in the world
/// Use the currently held item, or unarmed, on a weakref to an object in the world
/datum/ai_behavior/use_on_object
required_distance = 1
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT

/datum/ai_behavior/use_on_object/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/use_on_object/perform(delta_time, datum/ai_controller/controller, target_key)
. = ..()
var/mob/living/pawn = controller.pawn
var/obj/item/held_item = pawn.get_item_by_slot(pawn.get_active_hand())
var/atom/target = controller.blackboard[BB_MONKEY_CURRENT_PRESS_TARGET]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/target = target_ref?.resolve()

if(!target || !pawn.CanReach(target))
finish_action(controller, FALSE)
Expand All @@ -113,13 +115,15 @@

/datum/ai_behavior/give/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/give/perform(delta_time, datum/ai_controller/controller, target_key)
. = ..()
var/mob/living/pawn = controller.pawn
var/obj/item/held_item = pawn.get_item_by_slot(pawn.get_active_hand())
var/atom/target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/target = target_ref?.resolve()

if(!target || !pawn.CanReach(target) || !isliving(target))
finish_action(controller, FALSE)
Expand Down Expand Up @@ -151,12 +155,14 @@

/datum/ai_behavior/consume/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/consume/perform(delta_time, datum/ai_controller/controller, target_key, hunger_timer_key)
. = ..()
var/mob/living/living_pawn = controller.pawn
var/obj/item/target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/obj/item/target = target_ref.resolve()

if(!(target in living_pawn.held_items))
if(!living_pawn.put_in_hand_check(target))
Expand Down Expand Up @@ -187,7 +193,7 @@
. = ..()
var/find_this_thing = search_tactic(controller, locate_path, search_range)
if(find_this_thing)
controller.blackboard[set_key] = find_this_thing
controller.blackboard[set_key] = WEAKREF(find_this_thing)
finish_action(controller, TRUE)
else
finish_action(controller, FALSE)
Expand Down Expand Up @@ -341,7 +347,8 @@
/datum/ai_behavior/setup_instrument/perform(delta_time, datum/ai_controller/controller, song_instrument_key, song_lines_key)
. = ..()

var/obj/item/instrument/song_instrument = controller.blackboard[song_instrument_key]
var/datum/weakref/instrument_ref = controller.blackboard[song_instrument_key]
var/obj/item/instrument/song_instrument = instrument_ref.resolve()
var/datum/song/song = song_instrument.song
var/song_lines = controller.blackboard[song_lines_key]

Expand All @@ -357,7 +364,8 @@
/datum/ai_behavior/play_instrument/perform(delta_time, datum/ai_controller/controller, song_instrument_key)
. = ..()

var/obj/item/instrument/song_instrument = controller.blackboard[song_instrument_key]
var/datum/weakref/instrument_ref = controller.blackboard[song_instrument_key]
var/obj/item/instrument/song_instrument = instrument_ref.resolve()
var/datum/song/song = song_instrument.song

song.start_playing(controller.pawn)
Expand All @@ -377,5 +385,5 @@
possible_targets += thing
if(!possible_targets.len)
finish_action(controller, FALSE)
controller.blackboard[target_key] = pick(possible_targets)
controller.blackboard[target_key] = WEAKREF(pick(possible_targets))
finish_action(controller, TRUE)
10 changes: 6 additions & 4 deletions code/datums/ai/generic/generic_subtrees.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* * BB_SONG_LINES - not set by this subtree, is the song loaded into the song datum.
*/
/datum/ai_planning_subtree/generic_play_instrument/SelectBehaviors(datum/ai_controller/controller, delta_time)
if(!controller.blackboard[BB_SONG_INSTRUMENT])
var/datum/weakref/player_ref = controller.blackboard[BB_SONG_INSTRUMENT]
var/obj/item/instrument/song_player = player_ref?.resolve()

if(!song_player)
controller.queue_behavior(/datum/ai_behavior/find_and_set/in_hands, BB_SONG_INSTRUMENT, /obj/item/instrument)
return //we can't play a song since we do not have an instrument

var/obj/item/instrument/song_player = controller.blackboard[BB_SONG_INSTRUMENT]

var/list/parsed_song_lines = splittext(controller.blackboard[BB_SONG_LINES], "\n")
popleft(parsed_song_lines) //remove BPM as it is parsed out
if(!compare_list(song_player.song.lines, parsed_song_lines) || !song_player.song.repeat)
Expand Down Expand Up @@ -53,7 +54,8 @@
if(world.time < controller.blackboard[BB_NEXT_HUNGRY])
return

if(!controller.blackboard[BB_FOOD_TARGET])
var/datum/weakref/food_ref = controller.blackboard[BB_FOOD_TARGET]
if(!food_ref?.resolve())
controller.queue_behavior(/datum/ai_behavior/find_and_set/edible, BB_FOOD_TARGET, /obj/item, 2)
return

Expand Down
8 changes: 4 additions & 4 deletions code/datums/ai/hauntium/hauntium_subtrees.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

var/list/to_haunt_list = controller.blackboard[BB_TO_HAUNT_LIST]

for(var/i in to_haunt_list)
if(to_haunt_list[i] <= 0)
for(var/mob/living/potential_target as anything in to_haunt_list)
if(to_haunt_list[potential_target] <= 0)
to_haunt_list -= potential_target
continue
var/mob/living/potential_target = i
if(get_dist(potential_target, item_pawn) <= 7)
controller.blackboard[BB_HAUNT_TARGET] = potential_target
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/haunted, BB_HAUNT_TARGET, BB_HAUNTED_THROW_ATTEMPT_COUNT)
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted, BB_HAUNT_TARGET, BB_HAUNTED_THROW_ATTEMPT_COUNT)
return SUBTREE_RETURN_FINISH_PLANNING

0 comments on commit f8aad14

Please sign in to comment.