Skip to content

Commit

Permalink
pulse optimisation (#7624)
Browse files Browse the repository at this point in the history
# About the pull request

<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

turns out the var checked by like only three things didn't need to be
updated every life tick, who knew! thanks baycoders

# Explain why it's good for the game
removes a proc called on every carbon from life.dm

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>

Put screenshots and videos here with an empty line between the
screenshots and the `<details>` tags.

</details>


# Changelog
:cl:
code: slightly optimised how pulse is checked by checking it when
required rather than every lifetick
/:cl:

---------

Co-authored-by: Stan_Albatross <[email protected]>
Co-authored-by: harryob <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent 48a3d9e commit 2bb8409
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion code/__DEFINES/objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#define PULSE_SLOW 1 //<60 bpm
#define PULSE_NORM 2 //60-90 bpm
#define PULSE_FAST 3 //90-120 bpm
#define PULSE_2FAST 4 //>120 bpm
#define PULSE_FASTER 4 //>120 bpm
#define PULSE_THREADY 5 //occurs during hypovolemic shock

//proc/get_pulse methods
Expand Down
22 changes: 0 additions & 22 deletions code/modules/mob/living/carbon/carbon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -430,28 +430,6 @@

observer.client.add_to_screen(action.button)

//generates realistic-ish pulse output based on preset levels
/mob/living/carbon/proc/get_pulse(method) //method 0 is for hands, 1 is for machines, more accurate
var/temp = 0 //see setup.dm:694
switch(src.pulse)
if(PULSE_NONE)
return "0"
if(PULSE_SLOW)
temp = rand(40, 60)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_NORM)
temp = rand(60, 90)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_FAST)
temp = rand(90, 120)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_2FAST)
temp = rand(120, 160)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_THREADY)
return method ? ">250" : "extremely weak and fast, patient's artery feels like a thread"
// output for machines^ ^^^^^^^output for people^^^^^^^^^

/mob/living/carbon/verb/mob_sleep()
set name = "Sleep"
set category = "IC"
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/carbon/human/examine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
user.visible_message("<b>[user]</b> checks [src]'s pulse.", "You check [src]'s pulse.", null, 4)
spawn(15)
if(user && src && distance <= 1)
get_pulse(GETPULSE_HAND) // to update it
if(pulse == PULSE_NONE || status_flags & FAKEDEATH)
to_chat(user, SPAN_DEADSAY("[t_He] has no pulse[client ? "" : " and [t_his] soul has departed"]..."))
else
Expand Down
35 changes: 35 additions & 0 deletions code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1765,3 +1765,38 @@

return .

/// generates realistic-ish pulse output based on preset levels.
/// method == GETPULSE_HAND is for hands, GETPULSE_TOOL is for machines, more accurate
/mob/living/carbon/human/proc/get_pulse(method)
var/temp = 0 //see setup.dm:694

if(species && species.flags & NO_BLOOD)
pulse = PULSE_NONE //No blood, no pulse.

else if(stat == DEAD || status_flags & FAKEDEATH)
pulse = PULSE_NONE //That's it, you're dead, nothing can influence your pulse

else if(floor(blood_volume) <= BLOOD_VOLUME_BAD) //How much blood do we have
pulse = PULSE_THREADY //not enough :(

else
pulse = PULSE_NORM

switch(pulse)
if(PULSE_NONE)
return "0"
if(PULSE_SLOW)
temp = rand(40, 60)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_NORM)
temp = rand(60, 90)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_FAST)
temp = rand(90, 120)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_FASTER)
temp = rand(120, 160)
return num2text(method ? temp : temp + rand(-10, 10))
if(PULSE_THREADY)
return method ? ">250" : "extremely weak and fast, patient's artery feels like a thread"
// output for machines^ ^^^^^^^output for people^^^^^^^^^
2 changes: 0 additions & 2 deletions code/modules/mob/living/carbon/human/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@

handle_regular_hud_updates()

pulse = handle_pulse()

if(!client && !mind && species)
species.handle_npc(src)

Expand Down
14 changes: 0 additions & 14 deletions code/modules/mob/living/carbon/human/life/handle_pulse.dm

This file was deleted.

3 changes: 2 additions & 1 deletion code/modules/mob/living/living_healthscan.dm
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ GLOBAL_LIST_INIT(known_implants, subtypesof(/obj/item/implant))
else
dat += "\tBlood Level normal: [blood_percent]% [blood_volume]cl. Type: [blood_type]\n"
// Show pulse
dat += "\tPulse: <span class='[H.pulse == PULSE_THREADY || H.pulse == PULSE_NONE ? INTERFACE_RED : ""]'>[H.get_pulse(GETPULSE_TOOL)] bpm.</span>\n"
var/target_pulse = H.get_pulse(GETPULSE_TOOL)
dat += "\tPulse: <span class='[H.pulse == PULSE_THREADY || H.pulse == PULSE_NONE ? INTERFACE_RED : ""]'>[target_pulse] bpm.</span>\n"
if((H.stat == DEAD && !H.client))
unrevivable = 1
if(!unrevivable)
Expand Down
1 change: 0 additions & 1 deletion colonialmarines.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,6 @@
#include "code\modules\mob\living\carbon\human\life\handle_fire.dm"
#include "code\modules\mob\living\carbon\human\life\handle_grabbed.dm"
#include "code\modules\mob\living\carbon\human\life\handle_organs.dm"
#include "code\modules\mob\living\carbon\human\life\handle_pulse.dm"
#include "code\modules\mob\living\carbon\human\life\handle_regular_hud_updates.dm"
#include "code\modules\mob\living\carbon\human\life\handle_regular_status_updates.dm"
#include "code\modules\mob\living\carbon\human\life\handle_stasis_bag.dm"
Expand Down

0 comments on commit 2bb8409

Please sign in to comment.