Skip to content

Commit

Permalink
updates rustg, patches potential memory issue, leaper + fire changes,…
Browse files Browse the repository at this point in the history
… ai safety
  • Loading branch information
BurgerLUA committed Jan 19, 2024
1 parent 55c6001 commit 7274280
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 68 deletions.
104 changes: 68 additions & 36 deletions code/__defines/_rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@
#define RUST_G (__rust_g || __detect_rust_g())
#endif

// Handle 515 call() -> call_ext() changes
#if DM_VERSION >= 515
#define RUSTG_CALL call_ext
#else
#define RUSTG_CALL call
#endif

/// Gets the version of rust_g
/proc/rustg_get_version() return call_ext(RUST_G, "get_version")()
/proc/rustg_get_version() return RUSTG_CALL(RUST_G, "get_version")()


/**
Expand All @@ -51,7 +58,7 @@
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace(key, patterns, replacements) call_ext(RUST_G, "setup_acreplace")(key, json_encode(patterns), json_encode(replacements))
#define rustg_setup_acreplace(key, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(patterns), json_encode(replacements))

/**
* Sets up the Aho-Corasick automaton using supplied options.
Expand All @@ -63,7 +70,7 @@
* * patterns - A non-associative list of strings to search for
* * replacements - Default replacements for this automaton, used with rustg_acreplace
*/
#define rustg_setup_acreplace_with_options(key, options, patterns, replacements) call_ext(RUST_G, "setup_acreplace")(key, json_encode(options), json_encode(patterns), json_encode(replacements))
#define rustg_setup_acreplace_with_options(key, options, patterns, replacements) RUSTG_CALL(RUST_G, "setup_acreplace")(key, json_encode(options), json_encode(patterns), json_encode(replacements))

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
Expand All @@ -72,7 +79,7 @@
* * key - The key for the automaton
* * text - Text to run replacements on
*/
#define rustg_acreplace(key, text) call_ext(RUST_G, "acreplace")(key, text)
#define rustg_acreplace(key, text) RUSTG_CALL(RUST_G, "acreplace")(key, text)

/**
* Run the specified replacement engine with the provided haystack text to replace, returning replaced text.
Expand All @@ -82,7 +89,7 @@
* * text - Text to run replacements on
* * replacements - Replacements for this call. Must be the same length as the set-up patterns
*/
#define rustg_acreplace_with_replacements(key, text, replacements) call_ext(RUST_G, "acreplace_with_replacements")(key, text, json_encode(replacements))
#define rustg_acreplace_with_replacements(key, text, replacements) RUSTG_CALL(RUST_G, "acreplace_with_replacements")(key, text, json_encode(replacements))

/**
* This proc generates a cellular automata noise grid which can be used in procedural generation methods.
Expand All @@ -98,70 +105,95 @@
* * height: The height of the grid.
*/
#define rustg_cnoise_generate(percentage, smoothing_iterations, birth_limit, death_limit, width, height) \
call_ext(RUST_G, "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)

#define rustg_dmi_strip_metadata(fname) call_ext(RUST_G, "dmi_strip_metadata")(fname)
#define rustg_dmi_create_png(path, width, height, data) call_ext(RUST_G, "dmi_create_png")(path, width, height, data)
#define rustg_dmi_resize_png(path, width, height, resizetype) call_ext(RUST_G, "dmi_resize_png")(path, width, height, resizetype)
#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)
/**
* input: must be a path, not an /icon; you have to do your own handling if it is one, as icon objects can't be directly passed to rustg.
*
* 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) call_ext(RUST_G, "file_read")(fname)
#define rustg_file_exists(fname) call_ext(RUST_G, "file_exists")(fname)
#define rustg_file_write(text, fname) call_ext(RUST_G, "file_write")(text, fname)
#define rustg_file_append(text, fname) call_ext(RUST_G, "file_append")(text, fname)
#define rustg_file_get_line_count(fname) text2num(call_ext(RUST_G, "file_get_line_count")(fname))
#define rustg_file_seek_line(fname, line) call_ext(RUST_G, "file_seek_line")(fname, "[line]")
#define rustg_file_read(fname) RUSTG_CALL(RUST_G, "file_read")(fname)
#define rustg_file_exists(fname) (RUSTG_CALL(RUST_G, "file_exists")(fname) == "true")
#define rustg_file_write(text, fname) RUSTG_CALL(RUST_G, "file_write")(text, fname)
#define rustg_file_append(text, fname) RUSTG_CALL(RUST_G, "file_append")(text, fname)
#define rustg_file_get_line_count(fname) text2num(RUSTG_CALL(RUST_G, "file_get_line_count")(fname))
#define rustg_file_seek_line(fname, line) RUSTG_CALL(RUST_G, "file_seek_line")(fname, "[line]")

#ifdef RUSTG_OVERRIDE_BUILTINS
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#endif

#define rustg_git_revparse(rev) call_ext(RUST_G, "rg_git_revparse")(rev)
#define rustg_git_commit_date(rev) call_ext(RUST_G, "rg_git_commit_date")(rev)
/// Returns the git hash of the given revision, ex. "HEAD".
#define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)

/**
* Returns the date of the given revision in the format YYYY-MM-DD.
* Returns null if the revision is invalid.
*/
#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev)

#define RUSTG_HTTP_METHOD_GET "get"
#define RUSTG_HTTP_METHOD_PUT "put"
#define RUSTG_HTTP_METHOD_DELETE "delete"
#define RUSTG_HTTP_METHOD_PATCH "patch"
#define RUSTG_HTTP_METHOD_HEAD "head"
#define RUSTG_HTTP_METHOD_POST "post"
#define rustg_http_request_blocking(method, url, body, headers, options) call_ext(RUST_G, "http_request_blocking")(method, url, body, headers, options)
#define rustg_http_request_async(method, url, body, headers, options) call_ext(RUST_G, "http_request_async")(method, url, body, headers, options)
#define rustg_http_check_request(req_id) call_ext(RUST_G, "http_check_request")(req_id)
#define rustg_http_request_blocking(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_blocking")(method, url, body, headers, options)
#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_JOB_NO_RESULTS_YET "NO RESULTS YET"
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB"
#define RUSTG_JOB_ERROR "JOB PANICKED"

#define rustg_json_is_valid(text) (call_ext(RUST_G, "json_is_valid")(text) == "true")
#define rustg_json_is_valid(text) (RUSTG_CALL(RUST_G, "json_is_valid")(text) == "true")

#define rustg_log_write(fname, text, format) RUSTG_CALL(RUST_G, "log_write")(fname, text, format)
/proc/rustg_log_close_all() return RUSTG_CALL(RUST_G, "log_close_all")()

#define rustg_log_write(fname, text, format) call_ext(RUST_G, "log_write")(fname, text, format)
/proc/rustg_log_close_all() return call_ext(RUST_G, "log_close_all")()
#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)

#define rustg_noise_get_at_coordinates(seed, x, y) call_ext(RUST_G, "noise_get_at_coordinates")(seed, x, y)
#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)
#define rustg_sql_connected(handle) RUSTG_CALL(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) RUSTG_CALL(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) RUSTG_CALL(RUST_G, "sql_check_query")("[job_id]")

#define rustg_sql_connect_pool(options) call_ext(RUST_G, "sql_connect_pool")(options)
#define rustg_sql_query_async(handle, query, params) call_ext(RUST_G, "sql_query_async")(handle, query, params)
#define rustg_sql_query_blocking(handle, query, params) call_ext(RUST_G, "sql_query_blocking")(handle, query, params)
#define rustg_sql_connected(handle) call_ext(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) call_ext(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) call_ext(RUST_G, "sql_check_query")("[job_id]")
#define rustg_time_microseconds(id) text2num(RUSTG_CALL(RUST_G, "time_microseconds")(id))
#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)

#define rustg_time_microseconds(id) text2num(call_ext(RUST_G, "time_microseconds")(id))
#define rustg_time_milliseconds(id) text2num(call_ext(RUST_G, "time_milliseconds")(id))
#define rustg_time_reset(id) call_ext(RUST_G, "time_reset")(id)
/// Returns the timestamp as a string
/proc/rustg_unix_timestamp()
return RUSTG_CALL(RUST_G, "unix_timestamp")()

#define rustg_raw_read_toml_file(path) json_decode(call_ext(RUST_G, "toml_file_to_json")(path) || "null")
#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)
var/list/output = rustg_raw_read_toml_file(path)
if (output["success"])
return json_decode(output["content"])
else
CRASH(output["content"])

#define rustg_raw_toml_encode(value) json_decode(RUSTG_CALL(RUST_G, "toml_encode")(json_encode(value)))

/proc/rustg_toml_encode(value)
var/list/output = rustg_raw_toml_encode(value)
if (output["success"])
return output["content"]
else
CRASH(output["content"])

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

#ifdef RUSTG_OVERRIDE_BUILTINS
#define url_encode(text) rustg_url_encode(text)
Expand Down
56 changes: 28 additions & 28 deletions code/__defines/qdel.dm
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
var/global/list/qdel_refs_to_type = list()

#define qdel(object) \
if (!object) { \
log_error("Tried to qdel null object! in [__FILE__]:[__LINE__]"); \
} \
else if (object.qdeleting) { \
if (!object.qdel_warning) { \
var/warning_message = "[object.get_debug_name()] was queued for delete more than once! in [__FILE__]:[__LINE__], Original: [object.qdeleting]."; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
object.qdel_warning = TRUE; \
} \
else { \
var/datum/_qdel_stored_object = object; \
_qdel_stored_object.qdeleting = "[__FILE__]:[__LINE__]"; \
HOOK_CALL_ADV("Destroy",_qdel_stored_object,null); \
qdel_refs_to_type["\ref[_qdel_stored_object]"] = _qdel_stored_object.type; \
if(!_qdel_stored_object.PreDestroy()) { \
var/warning_message = "[_qdel_stored_object.get_debug_name()] did not have a proper PreDestroy() call! in [__FILE__]:[__LINE__]"; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
if(!_qdel_stored_object.Destroy()) { \
var/warning_message = "[_qdel_stored_object.get_debug_name()] did not have a proper Destroy() call! in [__FILE__]:[__LINE__]"; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
_qdel_stored_object.PostDestroy(); \
#define qdel(object) \
if (!object) { \
log_error("Tried to qdel null object! in [__FILE__]:[__LINE__]"); \
} \
else if (object.qdeleting) { \
if (!object.qdel_warning) { \
var/warning_message = "[object.get_debug_name()] was queued for delete more than once! in [__FILE__]:[__LINE__], Original: [object.qdeleting]."; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
object.qdel_warning = TRUE; \
} \
else { \
var/datum/_qdel_stored_object = object; \
_qdel_stored_object.qdeleting = "[__FILE__]:[__LINE__]"; \
HOOK_CALL_ADV("Destroy",_qdel_stored_object,null); \
if(CONFIG("TRACK_GARBAGE",null)) {qdel_refs_to_type["\ref[_qdel_stored_object]"] = _qdel_stored_object.type}; \
if(!_qdel_stored_object.PreDestroy()) { \
var/warning_message = "[_qdel_stored_object.get_debug_name()] did not have a proper PreDestroy() call! in [__FILE__]:[__LINE__]"; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
if(!_qdel_stored_object.Destroy()) { \
var/warning_message = "[_qdel_stored_object.get_debug_name()] did not have a proper Destroy() call! in [__FILE__]:[__LINE__]"; \
log_error(warning_message); \
rustg_log_write(GARBAGE_LOGS_PATH,warning_message,"true"); \
} \
_qdel_stored_object.PostDestroy(); \
}

#define qdel_in(object,time) CALLBACK_GLOBAL("\ref[object]_qdel_in",time,/datum/proc/delete)
6 changes: 5 additions & 1 deletion code/_core/client/verbs/debug.dm
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,12 @@ var/global/static/list/destroy_everything_whitelist = list(
set category = "Debug"
set name = "Print Garbage Collection"

if(!CONFIG("TRACK_GARBAGE",null))
src.to_chat("Garbage tracking has been disabled in config. Enable it in config to allow this.")
return TRUE

if(!length(qdel_refs_to_type))
src.to_chat("Nothing has been found in the garbage collection system. Yay!")
src.to_chat("Nothing has been found in the garbage collection system. Perhaps you are using this too early.")
return TRUE

var/final_text = ""
Expand Down
7 changes: 7 additions & 0 deletions code/_core/datum/ai/ai_life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

/ai/proc/on_life(var/tick_rate=1)

//Safeties.
if(objective_attack && !objective_attack.z)
set_objective(null)

if(objective_move && !objective_move.z)
set_move_objective(null)

if(owner.is_busy())
return FALSE

Expand Down
4 changes: 2 additions & 2 deletions code/_core/mob/living/simple/leaper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
flick("shoot",src)

var/list/exploding_turfs = list()
var/turfs_to_check = 20
var/blood_to_explode = 8
var/turfs_to_check = 10
var/blood_to_explode = 5

while(blood_to_explode > 0 && turfs_to_check > 0)
turfs_to_check--
Expand Down
3 changes: 2 additions & 1 deletion code/_core/obj/fire_process.dm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
return FALSE

//Don't spread if we're too far from the "source"
if(get_dist(src,initial_turf) > VIEW_RANGE*2)
if(get_dist(src,initial_turf) > VIEW_RANGE)
momentum = 0x0
return FALSE

var/turf/current_turf = loc
Expand Down
1 change: 1 addition & 0 deletions code/_core/world/_world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var/global/world_state = STATE_STARTING
return TRUE

/world/Reboot(reason)
rustg_log_close_all()
TgsReboot()
. = ..()

Expand Down
Binary file modified librust_g.so
Binary file not shown.
Binary file modified rust_g.dll
Binary file not shown.

0 comments on commit 7274280

Please sign in to comment.