-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Optimize CitraPerGame config updates to O(1) file I/O #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,65 +9,48 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ;--- Helpers --------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetRes(f) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| SetRes(cfg, f) { | ||||||||||||||||||||||||||||||||||
| ; Replace resolution_factor with value f (supports 1-10) | ||||||||||||||||||||||||||||||||||
| cfg := RegExReplace(cfg, "m)^resolution_factor=([2-9]|10|1)$", "resolution_factor=" f) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetFilter(name, isDefaultTrue) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetFilter(cfg, name, isDefaultTrue) { | ||||||||||||||||||||||||||||||||||
| if (name = "none") | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "texture_filter_name=xBRZ freescale", "texture_filter_name=none") | ||||||||||||||||||||||||||||||||||
| else if (name = "xBRZ freescale") | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "texture_filter_name=none", "texture_filter_name=xBRZ freescale") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "texture_filter_name\default=" (isDefaultTrue ? "false" : "true"), "texture_filter_name\default=" (isDefaultTrue ? "true" : "false")) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetShader(name, wantDefaultFalse) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetShader(cfg, name, wantDefaultFalse) { | ||||||||||||||||||||||||||||||||||
| if (name = "none (builtin)") | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "pp_shader_name=Bump_Mapping_AA_optimize", "pp_shader_name=none (builtin)") | ||||||||||||||||||||||||||||||||||
| else if (name = "Bump_Mapping_AA_optimize") | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "pp_shader_name=none (builtin)", "pp_shader_name=Bump_Mapping_AA_optimize") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "pp_shader_name\default=" (wantDefaultFalse ? "true" : "false"), "pp_shader_name\default=" (wantDefaultFalse ? "false" : "true")) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetPreload(on) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetPreload(cfg, on) { | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "preload_textures\default=" (on ? "true" : "false"), "preload_textures\default=" (on ? "false" : "true")) | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "preload_textures=" (on ? "false" : "false"), "preload_textures=" (on ? "true" : "false")) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetClock(pct) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetClock(cfg, pct) { | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "cpu_clock_percentage=125", "cpu_clock_percentage=" pct) | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "cpu_clock_percentage=25", "cpu_clock_percentage=" pct) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetLayout(opt) { | ||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
| cfg := LoadConfig(CitraConfigFile) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SetLayout(cfg, opt) { | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "layout_option=2", "layout_option=" opt) | ||||||||||||||||||||||||||||||||||
| cfg := StrReplace(cfg, "layout_option=0", "layout_option=" opt) | ||||||||||||||||||||||||||||||||||
| SaveConfig(cfg, CitraConfigFile) | ||||||||||||||||||||||||||||||||||
| return cfg | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| NormKey(k) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -114,51 +97,56 @@ else if (game = "mario_luigi_bis") | |||||||||||||||||||||||||||||||||
| else if (game = "mario_luigi_bowsers_inside_story") | ||||||||||||||||||||||||||||||||||
| game := "mario_luigi_bowser_s_inside_story" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| global CitraConfigFile | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| global CitraConfigFile |
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg := LoadConfig(CitraConfigFile) happens before verifying that game matches a supported key (the invalid-key path calls ShowHelp() later). If an unsupported key is passed, this extra file read is unnecessary; consider moving the load/save work inside the recognized-game branches (or after validating the key).
| global CitraConfigFile | |
| global CitraConfigFile | |
| ; Validate game key before loading config to avoid unnecessary file I/O | |
| if !(game = "default" | |
| || game = "3d_land" | |
| || game = "hd_texture_pack" | |
| || game = "luigi_s_mansion_2" | |
| || game = "mario_kart_7" | |
| || game = "mario_luigi_bowser_s_inside_story" | |
| || game = "mario_luigi" | |
| || game = "no_preloading" | |
| || game = "nsmb2") { | |
| ShowHelp() | |
| } |
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value of SaveConfig(cfg, CitraConfigFile) is ignored, but SaveConfig() can fail and returns false (and shows an error MsgBox). As written, the script will still show "Applied config" even if the save failed. Consider checking the return value and exiting with a non-zero code when saving fails.
| SaveConfig(cfg, CitraConfigFile) | |
| if !SaveConfig(cfg, CitraConfigFile) { | |
| ExitApp 1 | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetPreload()cannot reliably turn preloading off: the secondStrReplacealways searches forpreload_textures=false(because(on ? "false" : "false")is always "false"), so whenonis false and the config currently containspreload_textures=true, it will not be changed back tofalse. Update the replacement logic to handle both current states (e.g., replace the opposite of the desired value, or use a regex to setpreload_textures=to the requested boolean).