From 62566803f76d83d96dabe01da940e00b9b19753c Mon Sep 17 00:00:00 2001 From: Lila Date: Tue, 1 Oct 2024 08:49:03 +0100 Subject: [PATCH] [Repo Settings] Only set if different Fixes lag at start up from draw layers being set unnecessarily. Some clean up that I already did in #461 --- __init__.py | 15 +++++++- fast64_internal/repo_settings.py | 19 ++++------ fast64_internal/sm64/settings/panels.py | 11 +++--- fast64_internal/sm64/settings/properties.py | 36 ++++++++++++++----- .../sm64/settings/repo_settings.py | 31 +++------------- fast64_internal/utility.py | 9 +++++ 6 files changed, 68 insertions(+), 53 deletions(-) diff --git a/__init__.py b/__init__.py index d3e5c548c..5ab654ba6 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ from . import addon_updater_ops -from .fast64_internal.utility import prop_split, multilineLabel, draw_and_check_tab +from .fast64_internal.utility import prop_split, multilineLabel, prop_group_to_json, set_prop_if_in_data from .fast64_internal.repo_settings import ( draw_repo_settings, @@ -213,6 +213,19 @@ class Fast64Settings_Properties(bpy.types.PropertyGroup): internal_game_update_ver: bpy.props.IntProperty(default=0) + def to_repo_settings(self): + data = {} + data["autoLoad"] = self.auto_repo_load_settings + data["autoPickTextureFormat"] = self.auto_pick_texture_format + if self.auto_pick_texture_format: + data["preferRGBAOverCI"] = self.prefer_rgba_over_ci + return data + + def from_repo_settings(self, data: dict): + set_prop_if_in_data(self, "auto_repo_load_settings", data, "autoLoad") + set_prop_if_in_data(self, "auto_pick_texture_format", data, "autoPickTextureFormat") + set_prop_if_in_data(self, "prefer_rgba_over_ci", data, "preferRGBAOverCI") + class Fast64_Properties(bpy.types.PropertyGroup): """ diff --git a/fast64_internal/repo_settings.py b/fast64_internal/repo_settings.py index 04418e821..e0af49b6f 100644 --- a/fast64_internal/repo_settings.py +++ b/fast64_internal/repo_settings.py @@ -6,7 +6,7 @@ from bpy.props import StringProperty from bpy.path import abspath -from .utility import filepath_checks, prop_split, filepath_ui_warnings, draw_and_check_tab +from .utility import filepath_checks, prop_split, filepath_ui_warnings, draw_and_check_tab, set_prop_if_in_data from .operators import OperatorBase from .f3d.f3d_material import draw_rdp_world_defaults from .sm64.settings.repo_settings import load_sm64_repo_settings, save_sm64_repo_settings @@ -71,13 +71,10 @@ def load_repo_settings(scene: Scene, path: os.PathLike, skip_if_no_auto_load=Fal ) fast64_settings = scene.fast64.settings - fast64_settings.auto_repo_load_settings = data.get("autoLoad", fast64_settings.auto_repo_load_settings) - fast64_settings.auto_pick_texture_format = data.get( - "autoPickTextureFormat", fast64_settings.auto_pick_texture_format - ) - fast64_settings.prefer_rgba_over_ci = data.get("preferRGBAOverCI", fast64_settings.prefer_rgba_over_ci) - scene.f3d_type = data.get("microcode", scene.f3d_type) - scene.saveTextures = data.get("saveTextures", scene.saveTextures) + fast64_settings.from_repo_settings(data) + set_prop_if_in_data(scene, "f3d_type", data, "microcode") + set_prop_if_in_data(scene, "saveTextures", data, "saveTextures") + rdp_defaults: RDPSettings = scene.world.rdp_defaults rdp_defaults.from_dict(data.get("rdpDefaults", {})) @@ -90,12 +87,10 @@ def save_repo_settings(scene: Scene, path: os.PathLike): data = {} data["version"] = CUR_VERSION - data["autoLoad"] = fast64_settings.auto_repo_load_settings + data.update(fast64_settings.to_repo_settings()) data["microcode"] = scene.f3d_type data["saveTextures"] = scene.saveTextures - data["autoPickTextureFormat"] = fast64_settings.auto_pick_texture_format - if fast64_settings.auto_pick_texture_format: - data["preferRGBAOverCI"] = fast64_settings.prefer_rgba_over_ci + rdp_defaults: RDPSettings = scene.world.rdp_defaults data["rdpDefaults"] = rdp_defaults.to_dict() diff --git a/fast64_internal/sm64/settings/panels.py b/fast64_internal/sm64/settings/panels.py index 97fe73040..ba82351a7 100644 --- a/fast64_internal/sm64/settings/panels.py +++ b/fast64_internal/sm64/settings/panels.py @@ -2,8 +2,7 @@ from bpy.types import Context from ...panels import SM64_Panel - -from .repo_settings import draw_repo_settings +from ...utility import draw_and_check_tab class SM64_GeneralSettingsPanel(SM64_Panel): @@ -18,10 +17,12 @@ def draw(self, context: Context): if sm64_props.export_type == "C": # If the repo settings tab is open, we pass show_repo_settings as False # because we want to draw those specfic properties in the repo settings box - draw_repo_settings(scene, col.box()) - col.separator() + box = col.box().column() + if draw_and_check_tab(box, sm64_props, "sm64_repo_settings_tab", icon="PROPERTIES"): + sm64_props.draw_repo_settings(box) + col.separator() - sm64_props.draw_props(col, not sm64_props.sm64_repo_settings_tab) + sm64_props.draw_props(col, not sm64_props.sm64_repo_settings_tab or sm64_props.binary_export) else: sm64_props.draw_props(col, True) diff --git a/fast64_internal/sm64/settings/properties.py b/fast64_internal/sm64/settings/properties.py index 471ad617d..a5744ad36 100644 --- a/fast64_internal/sm64/settings/properties.py +++ b/fast64_internal/sm64/settings/properties.py @@ -6,7 +6,7 @@ from bpy.utils import register_class, unregister_class from ...render_settings import on_update_render_settings -from ...utility import directory_path_checks, directory_ui_warnings, prop_split, upgrade_old_prop +from ...utility import directory_path_checks, directory_ui_warnings, prop_split, set_prop_if_in_data, upgrade_old_prop from ..sm64_constants import defaultExtendSegment4 from ..sm64_objects import SM64_CombinedObjectProperties from ..sm64_utility import export_rom_ui_warnings, import_rom_ui_warnings @@ -133,6 +133,29 @@ def upgrade_changed_props(): upgrade_old_prop(combined_props, new, scene, old) sm64_props.version = SM64_Properties.cur_version + def to_repo_settings(self): + data = {} + data["refresh_version"] = self.refresh_version + data["compression_format"] = self.compression_format + data["force_extended_ram"] = self.force_extended_ram + data["matstack_fix"] = self.matstack_fix + return data + + def from_repo_settings(self, data: dict): + set_prop_if_in_data(self, "refresh_version", data, "refresh_version") + set_prop_if_in_data(self, "compression_format", data, "compression_format") + set_prop_if_in_data(self, "force_extended_ram", data, "force_extended_ram") + set_prop_if_in_data(self, "matstack_fix", data, "matstack_fix") + + def draw_repo_settings(self, layout: UILayout): + col = layout.column() + if not self.binary_export: + col.prop(self, "disable_scroll") + prop_split(col, self, "compression_format", "Compression Format") + prop_split(col, self, "refresh_version", "Refresh (Function Map)") + col.prop(self, "force_extended_ram") + col.prop(self, "matstack_fix") + def draw_props(self, layout: UILayout, show_repo_settings: bool = True): col = layout.column() @@ -152,14 +175,9 @@ def draw_props(self, layout: UILayout, show_repo_settings: bool = True): directory_ui_warnings(col, abspath(self.decomp_path)) col.separator() - if not self.binary_export: - col.prop(self, "disable_scroll") - if show_repo_settings: - prop_split(col, self, "compression_format", "Compression Format") - prop_split(col, self, "refresh_version", "Refresh (Function Map)") - col.prop(self, "force_extended_ram") - col.prop(self, "matstack_fix") - col.separator() + if show_repo_settings: + self.draw_repo_settings(col) + col.separator() col.prop(self, "show_importing_menus") if self.show_importing_menus: diff --git a/fast64_internal/sm64/settings/repo_settings.py b/fast64_internal/sm64/settings/repo_settings.py index f74b7eb3d..a32df8621 100644 --- a/fast64_internal/sm64/settings/repo_settings.py +++ b/fast64_internal/sm64/settings/repo_settings.py @@ -2,7 +2,7 @@ from bpy.types import Scene, UILayout -from ...utility import draw_and_check_tab, prop_split +from ...utility import draw_and_check_tab, prop_split, set_prop_if_in_data def save_sm64_repo_settings(scene: Scene): @@ -18,11 +18,7 @@ def save_sm64_repo_settings(scene: Scene): } sm64_props = scene.fast64.sm64 - data["refresh_version"] = sm64_props.refresh_version - data["compression_format"] = sm64_props.compression_format - data["force_extended_ram"] = sm64_props.force_extended_ram - data["matstack_fix"] = sm64_props.matstack_fix - + data.update(sm64_props.to_repo_settings()) return data @@ -33,26 +29,9 @@ def load_sm64_repo_settings(scene: Scene, data: dict[str, Any]): for layer in range(8): draw_layer = draw_layers.get(str(layer), {}) if "cycle_1" in draw_layer: - setattr(world, f"draw_layer_{layer}_cycle_1", draw_layer["cycle_1"]) + set_prop_if_in_data(world, f"draw_layer_{layer}_cycle_1", draw_layer, "cycle_1") if "cycle_2" in draw_layer: - setattr(world, f"draw_layer_{layer}_cycle_2", draw_layer["cycle_2"]) - - sm64_props = scene.fast64.sm64 - sm64_props.refresh_version = data.get("refresh_version", sm64_props.refresh_version) - sm64_props.compression_format = data.get("compression_format", sm64_props.compression_format) - sm64_props.force_extended_ram = data.get("force_extended_ram", sm64_props.force_extended_ram) - sm64_props.matstack_fix = data.get("matstack_fix", sm64_props.matstack_fix) + set_prop_if_in_data(world, f"draw_layer_{layer}_cycle_2", draw_layer, "cycle_2") - -def draw_repo_settings(scene: Scene, layout: UILayout): - col = layout.column() sm64_props = scene.fast64.sm64 - if not draw_and_check_tab(col, sm64_props, "sm64_repo_settings_tab", icon="PROPERTIES"): - return - - prop_split(col, sm64_props, "compression_format", "Compression Format") - prop_split(col, sm64_props, "refresh_version", "Refresh (Function Map)") - col.prop(sm64_props, "force_extended_ram") - col.prop(sm64_props, "matstack_fix") - - col.label(text="See Fast64 repo settings for general settings", icon="INFO") + sm64_props.from_repo_settings(data) diff --git a/fast64_internal/utility.py b/fast64_internal/utility.py index 14f6aea59..aef4ee729 100644 --- a/fast64_internal/utility.py +++ b/fast64_internal/utility.py @@ -1896,3 +1896,12 @@ def create_or_get_world(scene: Scene) -> World: WORLD_WARNING_COUNT = 0 print(f'No world in this file, creating world named "Fast64".') return bpy.data.worlds.new("Fast64") + + +def set_if_different(owner: object, prop: str, value): + if getattr(owner, prop) != value: + setattr(owner, prop, value) + + +def set_prop_if_in_data(owner: object, prop_name: str, data: dict, data_name: str): + set_if_different(owner, prop_name, data.get(data_name, getattr(owner, prop_name)))