Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Merged
111 changes: 98 additions & 13 deletions code/__DEFINES/rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@
#define rustg_cnoise_generate(percentage, smoothing_iterations, birth_limit, death_limit, width, height) \
RUSTG_CALL(RUST_G, "cnoise_generate")(percentage, smoothing_iterations, birth_limit, death_limit, width, height)

/**
* This proc generates a grid of perlin-like noise
*
* Returns a single string that goes row by row, with values of 1 representing an turned on cell, and a value of 0 representing a turned off cell.
*
* Arguments:
* * seed: seed for the function
* * accuracy: how close this is to the original perlin noise, as accuracy approaches infinity, the noise becomes more and more perlin-like
* * stamp_size: Size of a singular stamp used by the algorithm, think of this as the same stuff as frequency in perlin noise
* * world_size: size of the returned grid.
* * lower_range: lower bound of values selected for. (inclusive)
* * upper_range: upper bound of values selected for. (exclusive)
*/
#define rustg_dbp_generate(seed, accuracy, stamp_size, world_size, lower_range, upper_range) \
RUSTG_CALL(RUST_G, "dbp_generate")(seed, accuracy, stamp_size, world_size, lower_range, upper_range)


#define rustg_dmi_strip_metadata(fname) RUSTG_CALL(RUST_G, "dmi_strip_metadata")(fname)
#define rustg_dmi_create_png(path, width, height, data) RUSTG_CALL(RUST_G, "dmi_create_png")(path, width, height, data)
#define rustg_dmi_resize_png(path, width, height, resizetype) RUSTG_CALL(RUST_G, "dmi_resize_png")(path, width, height, resizetype)
Expand All @@ -126,6 +143,22 @@
#define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)
#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev)

#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, fname)
#define rustg_hash_generate_totp(seed) RUSTG_CALL(RUST_G, "generate_totp")(seed)
#define rustg_hash_generate_totp_tolerance(seed, tolerance) RUSTG_CALL(RUST_G, "generate_totp_tolerance")(seed, tolerance)

#define RUSTG_HASH_MD5 "md5"
#define RUSTG_HASH_SHA1 "sha1"
#define RUSTG_HASH_SHA256 "sha256"
#define RUSTG_HASH_SHA512 "sha512"
#define RUSTG_HASH_XXH64 "xxh64"
#define RUSTG_HASH_BASE64 "base64"

#ifdef RUSTG_OVERRIDE_BUILTINS
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif

#define RUSTG_HTTP_METHOD_GET "get"
#define RUSTG_HTTP_METHOD_PUT "put"
#define RUSTG_HTTP_METHOD_DELETE "delete"
Expand All @@ -136,6 +169,9 @@
#define rustg_http_request_async(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_async")(method, url, body, headers, options)
#define rustg_http_check_request(req_id) RUSTG_CALL(RUST_G, "http_check_request")(req_id)

#define rustg_influxdb2_publish(data, endpoint, token) RUSTG_CALL(RUST_G, "influxdb2_publish")(data, endpoint, token)
#define rustg_influxdb2_publish_profile(data, endpoint, token, round_id) RUSTG_CALL(RUST_G, "influxdb2_publish_profile")(data, endpoint, token, round_id)

#define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET"
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB"
#define RUSTG_JOB_ERROR "JOB PANICKED"
Expand All @@ -147,6 +183,47 @@

#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)

/**
* Register a list of nodes into a rust library. This list of nodes must have been serialized in a json.
* Node {// Index of this node in the list of nodes
* unique_id: usize,
* // Position of the node in byond
* x: usize,
* y: usize,
* z: usize,
* // Indexes of nodes connected to this one
* connected_nodes_id: Vec<usize>}
* It is important that the node with the unique_id 0 is the first in the json, unique_id 1 right after that, etc.
* It is also important that all unique ids follow. {0, 1, 2, 4} is not a correct list and the registering will fail
* Nodes should not link across z levels.
* A node cannot link twice to the same node and shouldn't link itself either
*/
#define rustg_register_nodes_astar(json) RUSTG_CALL(RUST_G, "register_nodes_astar")(json)

/**
* Add a new node to the static list of nodes. Same rule as registering_nodes applies.
* This node unique_id must be equal to the current length of the static list of nodes
*/
#define rustg_add_node_astar(json) RUSTG_CALL(RUST_G, "add_node_astar")(json)

/**²
* Remove every link to the node with unique_id. Replace that node by null
*/
#define rustg_remove_node_astart(unique_id) RUSTG_CALL(RUST_G, "remove_node_astar")(unique_id)

/**
* Compute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance
*/
#define rustg_generate_path_astar(start_node_id, goal_node_id) RUSTG_CALL(RUST_G, "generate_path_astar")(start_node_id, goal_node_id)

#define RUSTG_REDIS_ERROR_CHANNEL "RUSTG_REDIS_ERROR_CHANNEL"

#define rustg_redis_connect(addr) RUSTG_CALL(RUST_G, "redis_connect")(addr)
/proc/rustg_redis_disconnect() return RUSTG_CALL(RUST_G, "redis_disconnect")()
#define rustg_redis_subscribe(channel) RUSTG_CALL(RUST_G, "redis_subscribe")(channel)
/proc/rustg_redis_get_messages() return RUSTG_CALL(RUST_G, "redis_get_messages")()
#define rustg_redis_publish(channel, message) RUSTG_CALL(RUST_G, "redis_publish")(channel, message)

#define rustg_sql_connect_pool(options) RUSTG_CALL(RUST_G, "sql_connect_pool")(options)
#define rustg_sql_query_async(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_async")(handle, query, params)
#define rustg_sql_query_blocking(handle, query, params) RUSTG_CALL(RUST_G, "sql_query_blocking")(handle, query, params)
Expand All @@ -161,6 +238,9 @@
/proc/rustg_unix_timestamp()
return text2num(RUSTG_CALL(RUST_G, "unix_timestamp")())

/proc/rustg_unix_timestamp_int()
return RUSTG_CALL(RUST_G, "unix_timestamp_int")()

#define rustg_raw_read_toml_file(path) json_decode(RUSTG_CALL(RUST_G, "toml_file_to_json")(path) || "null")

/proc/rustg_read_toml_file(path)
Expand All @@ -179,6 +259,9 @@
else
CRASH(output["content"])

#define rustg_unzip_download_async(url, unzip_directory) RUSTG_CALL(RUST_G, "unzip_download_async")(url, unzip_directory)
#define rustg_unzip_check(job_id) RUSTG_CALL(RUST_G, "unzip_check")("[job_id]")

#define rustg_url_encode(text) RUSTG_CALL(RUST_G, "url_encode")("[text]")
#define rustg_url_decode(text) RUSTG_CALL(RUST_G, "url_decode")(text)

Expand All @@ -187,18 +270,20 @@
#define url_decode(text) rustg_url_decode(text)
#endif

#define rustg_hash_string(algorithm, text) RUSTG_CALL(RUST_G, "hash_string")(algorithm, text)
#define rustg_hash_file(algorithm, fname) RUSTG_CALL(RUST_G, "hash_file")(algorithm, fname)
#define rustg_hash_generate_totp(seed) RUSTG_CALL(RUST_G, "generate_totp")(seed)
#define rustg_hash_generate_totp_tolerance(seed, tolerance) RUSTG_CALL(RUST_G, "generate_totp_tolerance")(seed, tolerance)
/**
* This proc generates a noise grid using worley noise algorithm
*
* Returns a single string that goes row by row, with values of 1 representing an alive cell, and a value of 0 representing a dead cell.
*
* Arguments:
* * region_size: The size of regions
* * threshold: the value that determines wether a cell is dead or alive
* * node_per_region_chance: chance of a node existiing in a region
* * size: size of the returned grid
* * node_min: minimum amount of nodes in a region (after the node_per_region_chance is applied)
* * node_max: maximum amount of nodes in a region
*/
#define rustg_worley_generate(region_size, threshold, node_per_region_chance, size, node_min, node_max) \
RUSTG_CALL(RUST_G, "worley_generate")(region_size, threshold, node_per_region_chance, size, node_min, node_max)

#define RUSTG_HASH_MD5 "md5"
#define RUSTG_HASH_SHA1 "sha1"
#define RUSTG_HASH_SHA256 "sha256"
#define RUSTG_HASH_SHA512 "sha512"
#define RUSTG_HASH_XXH64 "xxh64"
#define RUSTG_HASH_BASE64 "base64"

#ifdef RUSTG_OVERRIDE_BUILTINS
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif
9 changes: 8 additions & 1 deletion code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,14 @@
/datum/config_entry/string/vpn_lookup_key // Key for VPN lookup API
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN

/datum/config_entry/flag/auto_profile
/datum/config_entry/string/metrics_api
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN
/datum/config_entry/string/metrics_token
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN
/datum/config_entry/string/metrics_api_profile
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN
/datum/config_entry/string/metrics_token_profile
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN

/datum/config_entry/flag/disable_gc_failure_hard_deletes

Expand Down
14 changes: 14 additions & 0 deletions code/controllers/subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,17 @@
if (NAMEOF(src, queued_priority)) //editing this breaks things.
return FALSE
. = ..()

/datum/controller/subsystem/proc/get_metrics()
SHOULD_CALL_PARENT(TRUE)
. = list()
.["@measurement"] = "subsystem"
.["@tags"] = list("subsystem" = type)
.["$cost"] = cost
.["$tick_usage"] = tick_usage
.["$tick_overrun"] = tick_overrun
.["$last_fire"] = last_fire
.["$next_fire"] = next_fire
.["$tick_allocation_avg"] = tick_allocation_avg
.["$times_fired"] = times_fired
.["$postponed_fires"] = postponed_fires
3 changes: 3 additions & 0 deletions code/controllers/subsystem/acid.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ SUBSYSTEM_DEF(acid)
msg = "P:[length(processing)]"
return ..()

/datum/controller/subsystem/acid/get_metrics()
. = ..()
.["processing"] = length(processing)

/datum/controller/subsystem/acid/fire(resumed = 0)
if (!resumed)
Expand Down
4 changes: 4 additions & 0 deletions code/controllers/subsystem/adjacent_air.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ SUBSYSTEM_DEF(adjacent_air)
#endif
return ..()

/datum/controller/subsystem/adjacent_air/get_metrics()
. = ..()
.["queued"] = length(queue)

/datum/controller/subsystem/adjacent_air/Initialize()
while(length(queue))
fire(mc_check = FALSE)
Expand Down
17 changes: 17 additions & 0 deletions code/controllers/subsystem/air.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ SUBSYSTEM_DEF(air)
msg += "AT/MS:[round((cost ? active_turfs.len/cost : 0),0.1)]"
return ..()

/datum/controller/subsystem/air/get_metrics()
. = ..()
.["cost_equalize"] = cost_equalize
.["cost_turfs"] = cost_turfs
.["cost_groups"] = cost_groups
.["cost_highpressure"] = cost_highpressure
.["cost_hotspots"] = cost_hotspots
.["cost_superconductivity"] = cost_superconductivity
.["cost_pipenets"] = cost_pipenets
.["cost_rebuilds"] = cost_rebuilds
.["cost_atmos_machinery"] = cost_atmos_machinery
.["active_turfs"] = active_turfs.len
.["excited_gruops"] = get_amt_excited_groups()
.["hotspts"] = hotspots.len
.["networks"] = networks.len
.["high_pressure_delta"] = high_pressure_delta.len
.["active_super_conductivity"] = active_super_conductivity.len

/datum/controller/subsystem/air/Initialize(timeofday)
extools_update_ssair()
Expand Down
11 changes: 11 additions & 0 deletions code/controllers/subsystem/area_contents.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ SUBSYSTEM_DEF(area_contents)
msg = "A:[length(currentrun)] MR:[length(marked_for_clearing)] TC:[total_to_clear] CF:[total_clearing_from]"
return ..()

/datum/controller/subsystem/area_contents/get_metrics()
. = ..()
var/total_clearing_from = 0
var/total_to_clear = 0
for(var/area/to_clear as anything in marked_for_clearing)
total_to_clear += length(to_clear.turfs_to_uncontain)
total_clearing_from += length(to_clear.contained_turfs)
.["areas"] = length(currentrun)
.["marked_for_clearing"] = length(marked_for_clearing)
.["total_to_clear"] = total_to_clear
.["total_clearing_from"] = total_clearing_from

/datum/controller/subsystem/area_contents/fire(resumed)
if(!resumed)
Expand Down
4 changes: 4 additions & 0 deletions code/controllers/subsystem/asset_loading.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ SUBSYSTEM_DEF(asset_loading)

return ..()

/datum/controller/subsystem/asset_loading/get_metrics()
. = ..()
.["queued"] = length(generate_queue)

/datum/controller/subsystem/asset_loading/fire(resumed)
while(length(generate_queue))
var/datum/asset/to_load = generate_queue[generate_queue.len]
Expand Down
5 changes: 5 additions & 0 deletions code/controllers/subsystem/augury.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ SUBSYSTEM_DEF(augury)
msg = "W:[watchers.len]|D:[length(doombringers)]"
return ..()

/datum/controller/subsystem/augury/get_metrics()
. = ..()
.["watchers"] = watchers.len
.["doombringers"] = length(doombringers)

/datum/controller/subsystem/augury/proc/register_doom(atom/A, severity)
doombringers[A] = severity
RegisterSignal(A, COMSIG_PARENT_QDELETING, PROC_REF(unregister_doom))
Expand Down
7 changes: 7 additions & 0 deletions code/controllers/subsystem/demo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ SUBSYSTEM_DEF(demo)
msg += "}"
return ..(msg)

/datum/controller/subsystem/demo/get_metrics()
. = ..()
.["remaining_turfs"] = marked_turfs.len
.["remaining_new"] = marked_new.len
.["remaining_updated"] = marked_dirty.len
.["remaining_deleted"] = del_list.len

/datum/controller/subsystem/demo/proc/mark_turf(turf/T)
if(!can_fire)
return
Expand Down
4 changes: 4 additions & 0 deletions code/controllers/subsystem/disease.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ SUBSYSTEM_DEF(disease)
msg = "P:[length(active_diseases)]"
return ..()

/datum/controller/subsystem/disease/get_metrics()
. = ..()
.["active_diseases"] = length(active_diseases)

/datum/controller/subsystem/disease/proc/get_disease_name(id)
var/datum/disease/advance/A = archive_diseases[id]
if(A.name)
Expand Down
18 changes: 18 additions & 0 deletions code/controllers/subsystem/explosions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ SUBSYSTEM_DEF(explosions)
msg += "} "
return ..()

/datum/controller/subsystem/explosions/get_metrics()
. = ..()
.["cost_lowturf"] = cost_lowturf
.["cost_medturf"] = cost_medturf
.["cost_highturf"] = cost_highturf
.["cost_flameturf"] = cost_flameturf
.["cost_low_mov_atom"] = cost_low_mov_atom
.["cost_med_mov_atom"] = cost_med_mov_atom
.["cost_high_mov_atom"] = cost_high_mov_atom
.["cost_throwturf"] = cost_throwturf
.["lowturfs"] = lowturf.len
.["medturfs"] = medturf.len
.["highturfs"] = highturf.len
.["flameturfs"] = flameturf.len
.["low_mov_atom"] = low_mov_atom.len
.["med_mov_atom"] = med_mov_atom.len
.["high_mov_atom"] = high_mov_atom.len
.["throwturf"] = throwturf.len

/datum/controller/subsystem/explosions/proc/is_exploding()
return (lowturf.len || medturf.len || highturf.len || flameturf.len || throwturf.len || low_mov_atom.len || med_mov_atom.len || high_mov_atom.len)
Expand Down
3 changes: 3 additions & 0 deletions code/controllers/subsystem/fire_burning.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SUBSYSTEM_DEF(fire_burning)
msg = "P:[length(processing)]"
return ..()

/datum/controller/subsystem/fire_burning/get_metrics()
. = ..()
.["queued"] = length(processing)

/datum/controller/subsystem/fire_burning/fire(resumed = 0)
if (!resumed)
Expand Down
11 changes: 11 additions & 0 deletions code/controllers/subsystem/garbage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ SUBSYSTEM_DEF(garbage)
msg += "|F:[fail_counts.Join(",")]"
return ..()

/datum/controller/subsystem/garbage/get_metrics()
. = ..()
for(var/i in 1 to GC_QUEUE_COUNT)
.["queue_items_[i]"] = length(queues[i])
.["queue_passed_[i]"] = pass_counts[i]
.["queue_failed_[i]"] = fail_counts[i]
.["delslasttick"] = delslasttick
.["gcedlasttick"] = gcedlasttick
.["totaldels"] = totaldels
.["totalgcs"] = totalgcs

/datum/controller/subsystem/garbage/Shutdown()
//Adds the del() log to the qdel log file
var/list/dellog = list()
Expand Down
5 changes: 5 additions & 0 deletions code/controllers/subsystem/idlenpcpool.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ SUBSYSTEM_DEF(idlenpcpool)
msg = "IdleNPCS:[length(idlelist)]|Z:[length(zlist)]"
return ..()

/datum/controller/subsystem/idlenpcpool/get_metrics()
. = ..()
.["idle_npcs"] = length(GLOB.simple_animals[AI_IDLE])
.["z_zombies"] = length(GLOB.simple_animals[AI_Z_OFF])

/datum/controller/subsystem/idlenpcpool/proc/MaxZChanged()
if (!islist(idle_mobs_by_zlevel))
idle_mobs_by_zlevel = new /list(world.maxz,0)
Expand Down
5 changes: 5 additions & 0 deletions code/controllers/subsystem/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ SUBSYSTEM_DEF(lighting)
msg = "L:[length(sources_queue)]|C:[length(corners_queue)]|O:[length(objects_queue)]"
return ..()

/datum/controller/subsystem/lighting/get_metrics()
. = ..()
.["queue_sources"] = length(sources_queue)
.["queue_corners"] = length(corners_queue)
.["queue_objects"] = length(objects_queue)

/datum/controller/subsystem/lighting/Initialize(timeofday)
if(!initialized)
Expand Down
4 changes: 4 additions & 0 deletions code/controllers/subsystem/machines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ SUBSYSTEM_DEF(machines)
msg = "M:[length(processing)]|PN:[length(powernets)]"
return ..()

/datum/controller/subsystem/machines/get_metrics()
. = ..()
.["machines"] = length(processing)
.["powernets"] = length(powernets)

/datum/controller/subsystem/machines/fire(resumed = 0)
if (!resumed)
Expand Down
Loading