Skip to content

Commit

Permalink
Add Byond Tracy support, fix a bug (#454)
Browse files Browse the repository at this point in the history
* Add defines for byond-tracy support (#70931)

Adds `USE_BYOND_TRACY`, which automatically loads a given
prof.dll/libprof.so using https://github.com/mafemergency/byond-tracy/.

Not intended for use in production, and we do not ship a copy of
byond-tracy. It is extremely easy to compile yourself, but if you're
someone interesting enough to play around with this then let me know and
I can just give you a build.

I'm going to be using this for init profiling.

* optimize and fix

* fix damage

---------

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
  • Loading branch information
Kapu1178 and Mothblocks authored Aug 2, 2023
1 parent 42da20e commit 7eb40c6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ Temporary Items
/tools/LinuxOneShot/TGS_Instances
/tools/LinuxOneShot/TGS_Logs

# byond-tracy, we intentionally do not ship this and do not want to maintain it
prof.dll
libprof.so

# JavaScript tools
**/node_modules

Expand Down
3 changes: 3 additions & 0 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
///NEVER run this on live, it's for simulating highpop only
// #define VERB_STRESS_TEST

// If this is uncommented, will attempt to load and initialize prof.dll/libprof.so.
// We do not ship byond-tracy. Build it yourself here: https://github.com/mafemergency/byond-tracy/
// #define USE_BYOND_TRACY

///Uncomment this to force all verbs to run into overtime all of the time
///Essentially negating the reserve 2%
Expand Down
20 changes: 20 additions & 0 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ GLOBAL_VAR(restart_counter)
* All atoms in both compiled and uncompiled maps are initialized()
*/
/world/New()
#ifdef USE_BYOND_TRACY
#warn USE_BYOND_TRACY is enabled
init_byond_tracy()
#endif

log_world("World loaded at [time_stamp()]!")

Expand Down Expand Up @@ -372,6 +376,22 @@ GLOBAL_VAR(restart_counter)
/world/proc/on_tickrate_change()
SStimer?.reset_buckets()

/world/proc/init_byond_tracy()
var/library

switch (system_type)
if (MS_WINDOWS)
library = "prof.dll"
if (UNIX)
library = "libprof.so"
else
CRASH("Unsupported platform: [system_type]")

var/init_result = call(library, "init")()
if (init_result != "0")
CRASH("Error initializing byond-tracy: [init_result]")


/world/Profile(command, type, format)
if((command & PROFILE_STOP) || !global.config?.loaded || !CONFIG_GET(flag/forbid_all_profiling))
. = ..()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@
LAZYCLEARLIST(cached_tentacle_turfs)
last_location = loc
tentacle_recheck_cooldown = world.time + initial(tentacle_recheck_cooldown)
for(var/turf/open/T in orange(4, loc))
var/list/nearby_turfs = RANGE_TURFS(4, loc)
nearby_turfs -= get_turf(src)
for(var/turf/open/T in nearby_turfs)
LAZYADD(cached_tentacle_turfs, T)
for(var/t in cached_tentacle_turfs)
if(isopenturf(t))
Expand Down
10 changes: 2 additions & 8 deletions code/modules/surgery/bodyparts/_bodyparts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,9 @@
//Applies brute and burn damage to the organ. Returns 1 if the damage-icon states changed at all.
//Damage will not exceed max_damage using this proc
//Cannot apply negative damage
/obj/item/bodypart/proc/receive_damage(brute = 0, burn = 0, stamina = 0, blocked = 0, updating_health = TRUE, required_status = null, sharpness = NONE, breaks_bones = TRUE)
/obj/item/bodypart/proc/receive_damage(brute = 0, burn = 0, blocked = 0, updating_health = TRUE, required_status = null, sharpness = NONE, breaks_bones = TRUE)
SHOULD_CALL_PARENT(TRUE)
var/hit_percent = (100-blocked)/100
if(stamina)
stack_trace("Bodypart took stamina damage!")
if((!brute && !burn) || hit_percent <= 0)
return FALSE
if(owner && (owner.status_flags & GODMODE))
Expand Down Expand Up @@ -581,11 +579,8 @@

if(can_inflict <= 0)
return FALSE
if(brute)
set_brute_dam(brute_dam + brute)
if(burn)
set_burn_dam(burn_dam + burn)

update_damage()
if(owner)
update_disabled()
if(updating_health)
Expand Down Expand Up @@ -655,7 +650,6 @@

//update damage counts
for(var/datum/wound/W as anything in wounds)

if(W.damage <= 0)
qdel(W)
continue
Expand Down

0 comments on commit 7eb40c6

Please sign in to comment.