Skip to content

Commit

Permalink
[Repo Settings] Only set if different
Browse files Browse the repository at this point in the history
Fixes lag at start up from draw layers being set unnecessarily.
Some clean up that I already did in Fast-64#461
  • Loading branch information
Lilaa3 committed Oct 1, 2024
1 parent 7cdb920 commit 6256680
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 53 deletions.
15 changes: 14 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down
19 changes: 7 additions & 12 deletions fast64_internal/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", {}))

Expand All @@ -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()

Expand Down
11 changes: 6 additions & 5 deletions fast64_internal/sm64/settings/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
36 changes: 27 additions & 9 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down
31 changes: 5 additions & 26 deletions fast64_internal/sm64/settings/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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


Expand All @@ -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)
9 changes: 9 additions & 0 deletions fast64_internal/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

0 comments on commit 6256680

Please sign in to comment.