WTS/game/scripts/utility/devtools.rpy
LoafyLemon e1766d767e Bug fixes
* Fixed animation list for dolls
* Attempt at fixing Android 11 Texture Leak
2022-06-21 20:12:26 +01:00

165 lines
6.2 KiB
Plaintext

init python:
if renpy.android:
class Android11TextureLeakFix(NoRollback):
def __init__(self, limit=100):
self.statements = 0
self.limit = limit
def __call__(self, name):
if renpy.is_init_phase():
return
self.statements += 1
if self.statements > self.limit:
self.statements = 0
# Big thanks to Andykl (https://github.com/Andykl)
# for finding the issue and inventing this workaround.
# https://github.com/renpy/renpy/issues/3643
cache = renpy.display.im.cache
cache_size = cache.get_total_size()
cache_limit = cache.cache_limit * 0.95
if cache_size >= cache_limit:
if config.developer:
print("Cache limit reached, purging cache... ({}/{})\n{}".format(cache_size, cache_limit, renpy.get_filename_line()))
cache.clear()
if renpy.game.interface is not None:
if config.developer:
print("Statements limit reached, cleaning textures... ({})\n{}".format(self.limit, renpy.get_filename_line()))
renpy.game.interface.full_redraw = True
renpy.game.interface.restart_interaction = True
if renpy.display.draw is not None:
renpy.display.draw.kill_textures()
renpy.display.render.free_memory()
config.statement_callbacks.append(Android11TextureLeakFix())
init python early:
if renpy.version_tuple < (7,5,0,22061501):
raise RuntimeWarning("Your Ren'Py launcher is outdated, the current minimal requirement is 7.5.0.22061501+\nPlease perform an update and try launching the game again.")
from renpy.uguu import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION
def get_gpu_info():
try:
info = "\n".join([glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION)])
except:
info = "ERR: Unknown or incompatible driver."
return info
def get_renderer():
return "DirectX" if preferences.renderer == "angle2" else "OpenGL"
init python:
config.missing_image_callback = missing_image_func
if config.developer:
renpy.arguments.register_command("whitespace", save_whitespace)
else:
config.missing_label_callback = missing_label_func
config.return_not_found_label = "missing_return"
init -1 python:
def missing_image_func(path):
global systemerror
systemerror = ["Missing image", path]
file, ext = os.path.splitext(path)
if renpy.loadable(file + ".png"):
return Image(file + ".png")
if config.developer:
raise IOError("Missing image: {}".format(path))
return Image("images/blank.webp")
def missing_label_func(name):
global systemerror
systemerror = ["Missing label", name]
return "missing_label"
def TBA_message(msg="Currently unavailable, check in later versions of the game."):
renpy.show_screen("blktone")
renpy.with_statement(d3)
renpy.say(nar, msg)
renpy.hide_screen("blktone")
renpy.with_statement(d3)
return
def save_whitespace(refresh=False):
"""
Generates a whitespace information file.
"""
global whitespace_dict
ap = renpy.arguments.ArgumentParser("Generates a whitespace information file.", require_command=False)
ap.add_argument("--refresh", action="store_true", help="Recalculate for all images.")
args = ap.parse_args()
if args.refresh or refresh:
whitespace_dict = {}
path = os.path.normpath(config.gamedir)
images = []
for root, dirs, files in os.walk(path):
for file in fnmatch.filter(files, "*.webp"):
img = os.path.join(root, file).replace("\\", "/").split("/game/")[1]
images.append(img)
c = len(images)
for i, img in enumerate(images):
# stdout causes issues on Windows
# sys.stdout.write("\rCalculating whitespace... {:3.0f}%".format(i / float(c - 1) * 100.0))
# sys.stdout.flush()
crop_whitespace(img)
file = os.path.normpath(config.gamedir + "/images.whitespace")
with open(file, "w") as f:
for img, box in sorted(whitespace_dict.iteritems()):
f.write(u"{}:{},{},{},{}\n".format(img, *box))
print "\rCalculating whitespace... Done!"
return False
label missing_label():
$ renpy.choice_for_skipping()
$ err_msg1 = systemerror[0]
$ err_msg2 = systemerror[1]
"{color=#7a0000}System{/color}" "Uh-oh. Looks like you've encountered a bug. Don't worry, we will try to return you back to the office after displaying the error message, your save file won't be affected."
"{color=#7a0000}System{/color}" "{color=#7a0000}Error:{/color} [err_msg1] '{color=#7a0000}[err_msg2]{/color}'\n\n\n{size=-4}You can report this bug on our {a=https://discord.gg/7PD57yt}discord{/a}.{/size}"
$ active_girl = None
$ systemerror = [None, None]
jump main_room
label missing_return():
$ renpy.choice_for_skipping()
"{color=#7a0000}System{/color}" "Uh-oh. Looks like you've encountered a bug. Don't worry, we will try to return you back to the office after displaying the error message, your save file won't be affected."
"{color=#7a0000}System{/color}" "{color=#7a0000}Error:{/color} Point of no return.\n\n\n{size=-4}You can report this bug on our {a=https://discord.gg/7PD57yt}discord{/a}.{/size}"
$ active_girl = None
jump main_room
screen placeholder():
tag cg
zorder 16 # above dolls
add Placeholder("bg")
add Placeholder("girl")
init 2000 python hide:
def set_screen_layer(layer, *screens):
for scr_name in screens:
for _, scr in renpy.display.screen.get_all_screen_variants(scr_name):
scr.layer = layer
set_screen_layer("interface", "_performance", "_image_load_log")