diff --git a/citadel.dme b/citadel.dme index b7e0dc06561..7a965a5fca8 100644 --- a/citadel.dme +++ b/citadel.dme @@ -338,6 +338,7 @@ #include "code\__HELPERS\icons\download.dm" #include "code\__HELPERS\icons\flatten.dm" #include "code\__HELPERS\icons\hologram.dm" +#include "code\__HELPERS\icons\metadata.dm" #include "code\__HELPERS\lists\_string_lists.dm" #include "code\__HELPERS\lists\asset_sorted.dm" #include "code\__HELPERS\lists\associations.dm" diff --git a/code/__DEFINES/rust_g.dm b/code/__DEFINES/rust_g.dm index fed30f30472..2d506e79965 100644 --- a/code/__DEFINES/rust_g.dm +++ b/code/__DEFINES/rust_g.dm @@ -107,9 +107,28 @@ #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) +/// output: json_encode'd list. json_decode to get a flat list with icon states in the order they're in inside the .dmi +#define rustg_dmi_icon_states(fname) RUSTG_CALL(RUST_G, "dmi_icon_states")(fname) #define rustg_file_read(fname) RUSTG_CALL(RUST_G, "file_read")(fname) #define rustg_file_exists(fname) RUSTG_CALL(RUST_G, "file_exists")(fname) @@ -126,6 +145,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" @@ -147,6 +182,86 @@ #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} + * 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) + +/** + * Connects to a given redis server. + * + * Arguments: + * * addr - The address of the server, for example "redis://127.0.0.1/" + */ +#define rustg_redis_connect_rq(addr) RUSTG_CALL(RUST_G, "redis_connect_rq")(addr) +/** + * Disconnects from a previously connected redis server + */ +/proc/rustg_redis_disconnect_rq() return RUSTG_CALL(RUST_G, "redis_disconnect_rq")() +/** + * https://redis.io/commands/lpush/ + * + * Arguments + * * key (string) - The key to use + * * elements (list) - The elements to push, use a list even if there's only one element. + */ +#define rustg_redis_lpush(key, elements) RUSTG_CALL(RUST_G, "redis_lpush")(key, json_encode(elements)) +/** + * https://redis.io/commands/lrange/ + * + * Arguments + * * key (string) - The key to use + * * start (string) - The zero-based index to start retrieving at + * * stop (string) - The zero-based index to stop retrieving at (inclusive) + */ +#define rustg_redis_lrange(key, start, stop) RUSTG_CALL(RUST_G, "redis_lrange")(key, start, stop) +/** + * https://redis.io/commands/lpop/ + * + * Arguments + * * key (string) - The key to use + * * count (string|null) - The amount to pop off the list, pass null to omit (thus just 1) + * + * Note: `count` was added in Redis version 6.2.0 + */ +#define rustg_redis_lpop(key, count) RUSTG_CALL(RUST_G, "redis_lpop")(key, count) + #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) @@ -158,8 +273,9 @@ #define rustg_time_milliseconds(id) text2num(RUSTG_CALL(RUST_G, "time_milliseconds")(id)) #define rustg_time_reset(id) RUSTG_CALL(RUST_G, "time_reset")(id) +/// Returns the timestamp as a string /proc/rustg_unix_timestamp() - return text2num(RUSTG_CALL(RUST_G, "unix_timestamp")()) + return RUSTG_CALL(RUST_G, "unix_timestamp")() #define rustg_raw_read_toml_file(path) json_decode(RUSTG_CALL(RUST_G, "toml_file_to_json")(path) || "null") @@ -179,6 +295,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) @@ -186,3 +305,21 @@ #define url_encode(text) rustg_url_encode(text) #define url_decode(text) rustg_url_decode(text) #endif + +/** + * 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) + + diff --git a/code/__HELPERS/icons/metadata.dm b/code/__HELPERS/icons/metadata.dm new file mode 100644 index 00000000000..0cf5ddcefbd --- /dev/null +++ b/code/__HELPERS/icons/metadata.dm @@ -0,0 +1,21 @@ +/** + * icon_states() but faster and better, basically + */ +/proc/fast_icon_states(what) + if(isicon(what) || isfile(what)) + // uh oh + // gotta fcopy + if(!fcopy(what, "data/tmp/rustg_icon_states.dmi")) + . = list() + CRASH("failed to fcopy a passed in icon/file to scratch destination for rustg invoke") + // invoke + . = rustg_dmi_icon_states("data/tmp/rustg_icon_states.dmi") + if(!fdel("data/tmp/rustg_icon_states.dmi")) + CRASH("failed to fdel temporary scratch file") + else if(istext(what)) + // can invoke directly + . = rustg_dmi_icon_states(what) + if(!length(.)) + . = list() + CRASH("failed to run icon states; please check the input / source.") + . = json_decode(.) diff --git a/code/modules/mob/inventory/slot_meta.dm b/code/modules/mob/inventory/slot_meta.dm index db881f99a3d..22bd8f4a04e 100644 --- a/code/modules/mob/inventory/slot_meta.dm +++ b/code/modules/mob/inventory/slot_meta.dm @@ -182,7 +182,7 @@ GLOBAL_LIST_EMPTY(inventory_slot_type_cache) render_default_icons -= bodytype_str continue var/icon/I = render_default_icons[bodytype_str] - render_state_cache[bodytype_str] = icon_states(I) + render_state_cache[bodytype_str] = fast_icon_states(I) // turn into hash for(var/state in render_state_cache[bodytype_str]) render_state_cache[bodytype_str][state] = TRUE @@ -299,7 +299,7 @@ GLOBAL_LIST_EMPTY(inventory_slot_type_cache) render_rolldown_icons -= bodytype_str continue var/icon/I = render_rolldown_icons[bodytype_str] - render_rolldown_states[bodytype_str] = icon_states(I) + render_rolldown_states[bodytype_str] = fast_icon_states(I) // turn into hash for(var/state in render_rolldown_states[bodytype_str]) render_rolldown_states[bodytype_str][state] = TRUE @@ -311,7 +311,7 @@ GLOBAL_LIST_EMPTY(inventory_slot_type_cache) render_rollsleeve_icons -= bodytype_str continue var/icon/I = render_rollsleeve_icons[bodytype_str] - render_rollsleeve_states[bodytype_str] = icon_states(I) + render_rollsleeve_states[bodytype_str] = fast_icon_states(I) // turn into hash for(var/state in render_rollsleeve_states[bodytype_str]) render_rollsleeve_states[bodytype_str][state] = TRUE diff --git a/rust_g.dll b/rust_g.dll index be19f57946d..f3287ce98aa 100644 Binary files a/rust_g.dll and b/rust_g.dll differ