Skip to content

Commit

Permalink
it took all my collective brain cells to if bleed_state != self.bleed…
Browse files Browse the repository at this point in the history
…_start:
  • Loading branch information
Lilaa3 committed Sep 15, 2024
1 parent c5e5dd8 commit 446eb90
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 446eb90

Please sign in to comment.