From 446eb90af57971ad2c0cc09a725b0e530fac2960 Mon Sep 17 00:00:00 2001 From: Lila Date: Sun, 15 Sep 2024 18:43:53 +0100 Subject: [PATCH] it took all my collective brain cells to if bleed_state != self.bleed_start: --- fast64_internal/f3d/f3d_bleed.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fast64_internal/f3d/f3d_bleed.py b/fast64_internal/f3d/f3d_bleed.py index c063854d8..4f85dd10d 100644 --- a/fast64_internal/f3d/f3d_bleed.py +++ b/fast64_internal/f3d/f3d_bleed.py @@ -262,8 +262,9 @@ def bleed_mat(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int): commands_bled.commands = copy.copy(gfx.commands) # copy the commands also last_cmd_list = last_mat.mat_only_DL.commands - revert_geo_cmd = next((cmd for cmd in last_mat.revert.commands if type(cmd) == SPGeometryMode), None) + # handle write diff, save pre bleed cmds geo_cmd = next((cmd for cmd in commands_bled.commands if type(cmd) == SPGeometryMode), None) + othermode_cmds = [cmd for cmd in commands_bled.commands if isinstance(cmd, SPSetOtherModeSub)] for j, cmd in enumerate(gfx.commands): if self.bleed_individual_cmd(commands_bled, cmd, bleed_state, last_cmd_list): @@ -272,13 +273,20 @@ def bleed_mat(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int): while None in commands_bled.commands: commands_bled.commands.remove(None) + # handle write diff + revert_geo_cmd = next((cmd for cmd in last_mat.revert.commands if type(cmd) == SPGeometryMode), None) geo_cmd_bleeded = geo_cmd is not None and geo_cmd not in commands_bled.commands - # if there was a geo command, and it wasnt bleeded, add revert + # if there was a geo command, and it wasnt bleeded, add revert's modes to it if not geo_cmd_bleeded and geo_cmd and revert_geo_cmd: geo_cmd.extend(revert_geo_cmd.clearFlagList, revert_geo_cmd.setFlagList) - # if there was no geo command but there was a revert, add the revert + # if there was no geo command but there was a revert, add the revert command elif geo_cmd is None and revert_geo_cmd: commands_bled.commands.insert(0, revert_geo_cmd) + + for revert_cmd in [cmd for cmd in last_mat.revert.commands if isinstance(cmd, SPSetOtherModeSub)]: + othermode_cmd = next((cmd for cmd in othermode_cmds if type(cmd) == type(revert_cmd)), None) + if othermode_cmd is None: # if there is no equivelent cmd, it must be using the revert + commands_bled.commands.insert(0, revert_cmd) else: commands_bled = self.bleed_cmd_list(cur_fmat.mat_only_DL, bleed_state) # some syncs may become redundant after bleeding @@ -484,6 +492,11 @@ def bleed_individual_cmd(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: in if not last_cmd_list: return self.bleed_self_conflict + if isinstance(cmd, SPSetOtherModeSub): + if bleed_state != self.bleed_start: + return cmd in last_cmd_list + else: + return cmd.mode == self.default_othermode_dict[type(cmd)] # apply specific logic to these cmds, see functions below, otherwise default behavior is to bleed if cmd is in the last list bleed_func = getattr(self, (f"bleed_{type(cmd).__name__}"), None) if bleed_func: @@ -582,7 +595,6 @@ def add_reset_cmd(self, cmd: GbiMacro, reset_cmd_dict: dict[GbiMacro]): reset_cmd_dict[SPGeometryMode] = SPGeometryMode([], []) reset_cmd_dict[SPGeometryMode].extend(cmd.clearFlagList, cmd.setFlagList) elif isinstance(cmd, SPSetOtherModeSub): - cmd_type = type(cmd) l: SPSetOtherMode = reset_cmd_dict.get("G_SETOTHERMODE_L") h: SPSetOtherMode = reset_cmd_dict.get("G_SETOTHERMODE_H") if l or h: # should never be reached, but if we reach it we are prepared @@ -596,7 +608,7 @@ def add_reset_cmd(self, cmd: GbiMacro, reset_cmd_dict: dict[GbiMacro]): l.flagList.remove(existing_mode) l.flagList.append(cmd.mode) else: - reset_cmd_dict[cmd_type] = cmd + reset_cmd_dict[type(cmd)] = cmd # separate other mode H and othermode L if type(cmd) == SPSetOtherMode: