Skip to content

Commit

Permalink
[F3D] Fix issues in the GBI macros (#419)
Browse files Browse the repository at this point in the history
* [F3D] Fix issues in the GBI macros

* black format

* Use getattr default over hasattr

* Same change for SPSetOtherMode
  • Loading branch information
Lilaa3 authored Aug 20, 2024
1 parent ee4cde1 commit 9e8e0fe
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3823,6 +3823,9 @@ def to_binary(self, f3d, segments):
self.point
).to_binary(f3d, segments)

def size(self, f3d):
return GFX_SIZE * 2


@dataclass(unsafe_hash=True)
class SPFresnelScale(GbiMacro):
Expand Down Expand Up @@ -4036,6 +4039,9 @@ def to_c(self, static=True):
header = "gsSPLightColor(" if static else "gSPLightColor(glistp++, "
return header + f"{self.n}, 0x" + format(self.color_to_int(), "08X") + ")"

def size(self, _f3d):
return GFX_SIZE * 2


@dataclass(unsafe_hash=True)
class SPSetLights(GbiMacro):
Expand Down Expand Up @@ -4222,7 +4228,7 @@ class SPPerspNormalize(GbiMacro):

def to_binary(self, f3d, segments):
if f3d.F3DEX_GBI_3:
return gsMoveHalfwd(f3d.G_MW_FX, G_MWO_PERSPNORM, (self.s), f3d)
return gsMoveHalfwd(f3d.G_MW_FX, f3d.G_MWO_PERSPNORM, (self.s), f3d)
else:
return gsMoveWd(f3d.G_MW_PERSPNORM, 0, (self.s), f3d)

Expand Down Expand Up @@ -4326,9 +4332,9 @@ class SPSetOtherMode(GbiMacro):
def to_binary(self, f3d, segments):
data = 0
for flag in self.flagList:
data |= getattr(f3d, flag) if hasattr(f3d, str(flag)) else flag
cmd = getattr(f3d, self.cmd) if hasattr(f3d, str(self.cmd)) else self.cmd
sft = getattr(f3d, self.sft) if hasattr(f3d, str(self.sft)) else self.sft
data |= getattr(f3d, str(flag), flag)
cmd = getattr(f3d, str(self.cmd), self.cmd)
sft = getattr(f3d, str(self.sft), self.sft)
return gsSPSetOtherMode(cmd, sft, self.length, data, f3d)


Expand Down Expand Up @@ -4829,7 +4835,12 @@ class DPSetOtherMode(GbiMacro):
mode1: list

def to_binary(self, f3d, segments):
words = _SHIFTL(f3d.G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(self.mode0, 0, 24), self.mode1
mode0 = mode1 = 0
for mode in self.mode0:
mode0 |= getattr(f3d, str(mode), mode)
for mode in self.mode1:
mode1 |= getattr(f3d, str(mode), mode)
words = _SHIFTL(f3d.G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(mode0, 0, 24), mode1
return words[0].to_bytes(4, "big") + words[1].to_bytes(4, "big")


Expand All @@ -4852,7 +4863,7 @@ def to_binary(self, f3d, segments):
return gsDPLoadTileGeneric(f3d.G_SETTILESIZE, self.tile, self.uls, self.ult, self.lrs, self.lrt)

def is_LOADTILE(self, f3d):
return self.t == f3d.G_TX_LOADTILE
return self.tile == f3d.G_TX_LOADTILE


@dataclass(unsafe_hash=True)
Expand Down

0 comments on commit 9e8e0fe

Please sign in to comment.