Skip to content

Commit 351af0b

Browse files
authored
random backend updates (#7061)
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request title ## Changelog :cl: fix: world_topic status host is correct now code: updated progressbar code: updated stack trace code: updated callback code: updated weakref code: updated topic request, now supports returning json format code: datum browser doesnt hold atom owner directly code: updated stat tracking (debugging, not player stat) admin: updated del-all verbs admin: allow f12 browser inspect (516 only) /:cl: <!-- Both :cl:'s are required for the changelog to work! You can put your name to the right of the first :cl: if you want to overwrite your GitHub username as author ingame. --> <!-- You can use multiple of the same prefix (they're only used for the icon ingame) and delete the unneeded ones. Despite some of the tags, changelogs should generally represent how a player might be affected by the changes rather than a summary of the PR's contents. -->
1 parent 38cca1c commit 351af0b

35 files changed

+994
-404
lines changed

citadel.dme

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "code\__DEFINES\ability.dm"
3434
#include "code\__DEFINES\access.dm"
3535
#include "code\__DEFINES\actionspeed_modification.dm"
36+
#include "code\__DEFINES\admin_verb.dm"
3637
#include "code\__DEFINES\appearance.dm"
3738
#include "code\__DEFINES\assert.dm"
3839
#include "code\__DEFINES\automata.dm"
@@ -56,6 +57,7 @@
5657
#include "code\__DEFINES\holidays.dm"
5758
#include "code\__DEFINES\holomap.dm"
5859
#include "code\__DEFINES\holospheres.dm"
60+
#include "code\__DEFINES\html_assistant.dm"
5961
#include "code\__DEFINES\icon_smoothing.dm"
6062
#include "code\__DEFINES\ingredients.dm"
6163
#include "code\__DEFINES\instruments.dm"
@@ -93,6 +95,7 @@
9395
#include "code\__DEFINES\spaceman_dmm.dm"
9496
#include "code\__DEFINES\spans.dm"
9597
#include "code\__DEFINES\spells.dm"
98+
#include "code\__DEFINES\stack_trace.dm"
9699
#include "code\__DEFINES\stat_tracking.dm"
97100
#include "code\__DEFINES\statpanel.dm"
98101
#include "code\__DEFINES\supply.dm"
@@ -411,6 +414,7 @@
411414
#include "code\__HELPERS\shell.dm"
412415
#include "code\__HELPERS\spatial_info.dm"
413416
#include "code\__HELPERS\stack_trace.dm"
417+
#include "code\__HELPERS\stat_tracking.dm"
414418
#include "code\__HELPERS\stoplag.dm"
415419
#include "code\__HELPERS\storage.dm"
416420
#include "code\__HELPERS\text.dm"

code/__DEFINES/_core.dm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
/proc/___rethrow_exception(exception/E)
77
throw E
88

9-
/// Gives us the stack trace from CRASH() without ending the current proc.
10-
/// Unlike STACK_TRACE, this will:
11-
/// * call a new proc so the originating trace isn't from the original file anymore
12-
/// * put the stack trace in stack trace storage
13-
#define stack_trace(message) _stack_trace(message, __FILE__, __LINE__)
14-
159
/// get variable if not null or
1610
#define VALUE_OR_DEFAULT(VAL, DEFAULT) (isnull(VAL)? (DEFAULT) : (VAL))
1711

code/__DEFINES/_lists.dm

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,28 @@
2525
#define LAZYLEN(L) length(L)
2626
///Sets a list to null
2727
#define LAZYNULL(L) L = null
28-
/// Null-safe L.Cut()
28+
///Adds to the item K the value V, if the list is null it will initialize it
29+
#define LAZYADDASSOC(L, K, V) if(!L) { L = list(); } L[K] += V;
30+
///This is used to add onto lazy assoc list when the value you're adding is a /list/. This one has extra safety over lazyaddassoc because the value could be null (and thus cant be used to += objects)
31+
#define LAZYADDASSOCLIST(L, K, V) if(!L) { L = list(); } L[K] += list(V);
32+
///Removes the value V from the item K, if the item K is empty will remove it from the list, if the list is empty will set the list to null
33+
#define LAZYREMOVEASSOC(L, K, V) if(L) { if(L[K]) { L[K] -= V; if(!length(L[K])) L -= K; } if(!length(L)) L = null; }
34+
///Accesses an associative list, returns null if nothing is found
35+
#define LAZYACCESSASSOC(L, I, K) L ? L[I] ? L[I][K] ? L[I][K] : null : null : null
36+
//These methods don't null the list
37+
///Use LAZYLISTDUPLICATE instead if you want it to null with no entries
38+
#define LAZYCOPY(L) (L ? L.Copy() : list() )
39+
/// Consider LAZYNULL instead
2940
#define LAZYCLEARLIST(L) if(L) L.Cut()
30-
/// Null-safe L.Copy()
31-
#define LAZYCOPY(L) (L? L.Copy() : null)
32-
/// Reads L or an empty list if L is not a list. Note: Does NOT assign, L may be an expression.
41+
///Returns the list if it's actually a valid list, otherwise will initialize it
3342
#define SANITIZE_LIST(L) ( islist(L) ? L : list() )
3443
#define SANITIZE_TO_LIST(L) ( islist(L) ? L : list(L) )
44+
/// Performs an insertion on the given lazy list with the given key and value. If the value already exists, a new one will not be made.
45+
#define LAZYORASSOCLIST(lazy_list, key, value) \
46+
LAZYINITLIST(lazy_list); \
47+
LAZYINITLIST(lazy_list[key]); \
48+
lazy_list[key] |= value;
49+
3550
#define reverseList(L) reverseRange(L.Copy())
3651

3752
#define SAFEPICK(L) (length(L)? pick(L) : null)

code/__DEFINES/admin_verb.dm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This port is currently half-assed, we do not include the entire avd stuff
2+
3+
/// Use this to mark your verb as not having a description. Should ONLY be used if you are also hiding the verb!
4+
#define ADMIN_VERB_NO_DESCRIPTION ""
5+
/// Used to verbs you do not want to show up in the master verb panel.
6+
#define ADMIN_CATEGORY_HIDDEN null
7+
8+
// Admin verb categories
9+
#define ADMIN_CATEGORY_MAIN "Admin"
10+
#define ADMIN_CATEGORY_EVENTS "Admin.Events"
11+
#define ADMIN_CATEGORY_FUN "Admin.Fun"
12+
#define ADMIN_CATEGORY_GAME "Admin.Game"
13+
#define ADMIN_CATEGORY_SHUTTLE "Admin.Shuttle"
14+
15+
// Special categories that are separated
16+
#define ADMIN_CATEGORY_DEBUG "Debug"
17+
#define ADMIN_CATEGORY_SERVER "Server"
18+
#define ADMIN_CATEGORY_OBJECT "Object"
19+
#define ADMIN_CATEGORY_MAPPING "Mapping"
20+
#define ADMIN_CATEGORY_PROFILE "Profile"
21+
#define ADMIN_CATEGORY_IPINTEL "Admin.IPIntel"
22+
23+
// Visibility flags
24+
#define ADMIN_VERB_VISIBLITY_FLAG_MAPPING_DEBUG "Map-Debug"

code/__DEFINES/html_assistant.dm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define HTML_SKELETON_INTERNAL(head, body) \
2+
"<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><meta http-equiv='X-UA-Compatible' content='IE=edge'>[head]</head><body>[body]</body></html>"
3+
4+
#define HTML_SKELETON_TITLE(title, body) HTML_SKELETON_INTERNAL("<title>[title]</title>", body)
5+
#define HTML_SKELETON(body) HTML_SKELETON_INTERNAL("", body)

code/__DEFINES/stack_trace.dm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// gives us the stack trace from CRASH() without ending the current proc.
2+
#define stack_trace(message) _stack_trace(message, __FILE__, __LINE__)
3+
4+
#define WORKAROUND_IDENTIFIER "%//%"

code/__DEFINES/stat_tracking.dm

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,67 @@
1-
//
2-
// Defines used for advanced performance profiling of subsystems.
3-
// Currently used only by SSoverlays (2018-02-24 ~Leshana)
4-
//
51
#define STAT_ENTRY_TIME 1
62
#define STAT_ENTRY_COUNT 2
73
#define STAT_ENTRY_LENGTH 2
84

5+
96
#define STAT_START_STOPWATCH var/STAT_STOP_WATCH = TICK_USAGE
107
#define STAT_STOP_STOPWATCH var/STAT_TIME = TICK_USAGE_TO_MS(STAT_STOP_WATCH)
118
#define STAT_LOG_ENTRY(entrylist, entryname) \
129
var/list/STAT_ENTRY = entrylist[entryname] || (entrylist[entryname] = new /list(STAT_ENTRY_LENGTH));\
1310
STAT_ENTRY[STAT_ENTRY_TIME] += STAT_TIME;\
14-
var/STAT_INCR_AMOUNT = min(1, 2**round((STAT_ENTRY[STAT_ENTRY_COUNT] || 0)/SHORT_REAL_LIMIT));\
15-
if (STAT_INCR_AMOUNT == 1 || prob(100/STAT_INCR_AMOUNT)) {\
16-
STAT_ENTRY[STAT_ENTRY_COUNT] += STAT_INCR_AMOUNT;\
17-
};\
11+
STAT_ENTRY[STAT_ENTRY_COUNT] += 1;
12+
13+
// Cost tracking macros, to be used in one proc. If you're using this raw you'll want to use global lists
14+
// If you don't you'll need another way of reading it
15+
#define INIT_COST(costs, counting) \
16+
var/list/_costs = costs; \
17+
var/list/_counting = counting; \
18+
var/_usage = TICK_USAGE;
19+
20+
// STATIC cost tracking macro. Uses static lists instead of the normal global ones
21+
// Good for debug stuff, and for running before globals init
22+
#define INIT_COST_STATIC(...) \
23+
var/static/list/hidden_static_list_for_fun1 = list(); \
24+
var/static/list/hidden_static_list_for_fun2 = list(); \
25+
INIT_COST(hidden_static_list_for_fun1, hidden_static_list_for_fun2)
26+
27+
// Cost tracking macro for global lists, prevents erroring if GLOB has not yet been initialized
28+
#define INIT_COST_GLOBAL(costs, counting) \
29+
INIT_COST_STATIC() \
30+
if(GLOB){\
31+
costs = hidden_static_list_for_fun1; \
32+
counting = hidden_static_list_for_fun2 ; \
33+
} \
34+
_usage = TICK_USAGE;
35+
36+
37+
#define SET_COST(category) \
38+
do { \
39+
var/_cost = TICK_USAGE; \
40+
_costs[category] += TICK_DELTA_TO_MS(_cost - _usage);\
41+
_counting[category] += 1; \
42+
} while(FALSE); \
43+
_usage = TICK_USAGE;
44+
45+
#define SET_COST_LINE(...) SET_COST("[__LINE__]")
46+
47+
/// A quick helper for running the code as a statement and profiling its cost.
48+
/// For example, `SET_COST_STMT(var/x = do_work())`
49+
#define SET_COST_STMT(code...) ##code; SET_COST("[__LINE__] - [#code]")
50+
51+
#define EXPORT_STATS_TO_JSON_LATER(filename, costs, counts) EXPORT_STATS_TO_FILE_LATER(filename, costs, counts, stat_tracking_export_to_json_later)
52+
#define EXPORT_STATS_TO_CSV_LATER(filename, costs, counts) EXPORT_STATS_TO_FILE_LATER(filename, costs, counts, stat_tracking_export_to_csv_later)
53+
54+
#define EXPORT_STATS_TO_FILE_LATER(filename, costs, counts, proc) \
55+
do { \
56+
var/static/last_export = 0; \
57+
/* Need to always run if we haven't yet, since this code can be placed ANYWHERE */ \
58+
if (world.time - last_export > 1.1 SECONDS || (last_export == 0)) { \
59+
last_export = world.time; \
60+
/* spawn() is used here because this is often used to track init times, where timers act oddly. */ \
61+
/* I was making timers and even after init times were complete, the timers didn't run :shrug: */ \
62+
spawn (1 SECONDS) { \
63+
##proc(filename, costs, counts); \
64+
} \
65+
} \
66+
} while (FALSE); \
67+
_usage = TICK_USAGE;

code/__DEFINES/vv.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,5 @@
153153

154154
// /obj/item/card/id
155155
#define VV_HK_ID_MOD "id_mod"
156+
157+
#define VV_HK_WEAKREF_RESOLVE "weakref_resolve"

code/__HELPERS/do_after.dm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
. = TRUE
2020
while (world.time < endtime)
2121
stoplag(1)
22-
if (progress)
22+
if (progress && !QDELETED(progbar))
2323
progbar.update(world.time - starttime)
2424
if(!user || !target)
2525
. = FALSE
@@ -52,7 +52,7 @@
5252
break
5353

5454
if(!QDELETED(progbar))
55-
qdel(progbar)
55+
progbar.end_progress()
5656

5757
STOP_INTERACTING_WITH(user, target, INTERACTING_FOR_DO_AFTER)
5858

@@ -71,7 +71,7 @@
7171
* * progress_instance - override progressbar instance
7272
*/
7373
/proc/do_after(mob/user, delay, atom/target, flags, mobility_flags = MOBILITY_CAN_USE, max_distance, datum/callback/additional_checks, atom/progress_anchor, datum/progressbar/progress_instance)
74-
if(isnull(user))
74+
if(isnull(user) || QDELETED(user))
7575
return FALSE
7676
if(!delay)
7777
return \
@@ -111,7 +111,8 @@
111111
while(world.time < (start_time + delay))
112112
stoplag(1)
113113

114-
progress?.update((world.time - start_time) * delay_factor)
114+
if (progress && !QDELETED(progress))
115+
progress.update((world.time - start_time) * delay_factor)
115116

116117
// check if deleted
117118
if(QDELETED(user))
@@ -172,7 +173,7 @@
172173

173174
//* end
174175
if(!QDELETED(progress))
175-
qdel(progress)
176+
progress.end_progress()
176177

177178
if(!isnull(target))
178179
STOP_INTERACTING_WITH(user, target, INTERACTING_FOR_DO_AFTER)

code/__HELPERS/game.dm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,23 @@
567567

568568
return hear
569569

570+
///Get active players who are playing in the round
571+
/proc/get_active_player_count(alive_check = FALSE, afk_check = FALSE, human_check = FALSE)
572+
var/active_players = 0
573+
for(var/mob/player_mob as anything in GLOB.player_list)
574+
if(!player_mob?.client)
575+
continue
576+
if(alive_check && player_mob.stat == DEAD)
577+
continue
578+
if(afk_check && player_mob.client.is_afk())
579+
continue
580+
if(human_check && !ishuman(player_mob))
581+
continue
582+
if(isnewplayer(player_mob)) // exclude people in the lobby
583+
continue
584+
if(isobserver(player_mob)) // Ghosts are fine if they were playing once (didn't start as observers)
585+
// var/mob/dead/observer/ghost_player = player_mob
586+
// if(ghost_player.started_as_observer) // Exclude people who started as observers
587+
continue
588+
active_players++
589+
return active_players

0 commit comments

Comments
 (0)