Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into preparations-for-an…
Browse files Browse the repository at this point in the history
…imation-rework
  • Loading branch information
Lilaa3 committed Sep 3, 2024
2 parents 8203db3 + 2e5dd87 commit 81db750
Show file tree
Hide file tree
Showing 37 changed files with 509 additions and 234 deletions.
22 changes: 14 additions & 8 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from dataclasses import dataclass, field

from ..utility import create_or_get_world
from .f3d_gbi import (
GfxTag,
GfxListTag,
Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(self):
self.build_default_othermodes()

def build_default_geo(self):
defaults = bpy.context.scene.world.rdp_defaults
defaults = create_or_get_world(bpy.context.scene).rdp_defaults

setGeo = SPSetGeometryMode([])
clearGeo = SPClearGeometryMode([])
Expand Down Expand Up @@ -91,7 +92,7 @@ def place_in_flaglist(flag: bool, enum: str, set_list: SPSetGeometryMode, clear_
self.default_clear_geo = clearGeo

def build_default_othermodes(self):
defaults = bpy.context.scene.world.rdp_defaults
defaults = create_or_get_world(bpy.context.scene).rdp_defaults

othermode_H = SPSetOtherMode("G_SETOTHERMODE_H", 4, 20 - self.is_f3d_old, [])
# if the render mode is set, it will be consider non-default a priori
Expand Down Expand Up @@ -225,9 +226,8 @@ def bleed_textures(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state:
for j, cmd in enumerate(cur_fmat.texture_DL.commands):
if not cmd:
continue # some cmds are None from previous step
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state):
if cmd in last_mat.texture_DL.commands:
commands_bled.commands[j] = None
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state, last_mat.texture_DL.commands) is True:
commands_bled.commands[j] = None
# remove Nones from list
while None in commands_bled.commands:
commands_bled.commands.remove(None)
Expand Down Expand Up @@ -479,9 +479,15 @@ def bleed_SPSetOtherMode(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: in
else:
return cmd == self.default_othermode_L

# bleed if there are no tags to scroll and cmd was in last list
def bleed_DPSetTileSize(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: int, last_cmd_list: GfxList = None):
return cmd.tags != GfxTag.TileScroll0 and cmd.tags != GfxTag.TileScroll1 and cmd in last_cmd_list
# Don´t bleed if the cmd is used for scrolling or if the last cmd's tags are not the same (those are not hashed)
def bleed_DPSetTileSize(self, _cmd_list: GfxList, cmd: GbiMacro, _bleed_state: int, last_cmd_list: GfxList = None):
if cmd.tags == GfxTag.TileScroll0 or cmd.tags == GfxTag.TileScroll1:
return False
if cmd in last_cmd_list:
last_size_cmd = last_cmd_list[last_cmd_list.index(cmd)]
if last_size_cmd.tags == cmd.tags:
return True
return False

# At most, only one sync is needed after drawing tris. The f3d writer should
# already have placed the appropriate sync type required. If a second sync is
Expand Down
76 changes: 49 additions & 27 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from typing import Sequence, Union, Tuple
from dataclasses import dataclass, fields
from dataclasses import dataclass, fields, field
import bpy, os, enum, copy
from ..utility import *

Expand Down Expand Up @@ -72,15 +72,26 @@ class GfxMatWriteMethod(enum.Enum):
"F3DEX3": (56, 56),
}

drawLayerRenderMode = {
0: ("G_RM_ZB_OPA_SURF", "G_RM_NOOP2"),
1: ("G_RM_AA_ZB_OPA_SURF", "G_RM_NOOP2"),
2: ("G_RM_AA_ZB_OPA_DECAL", "G_RM_NOOP2"),
3: ("G_RM_AA_ZB_OPA_INTER", "G_RM_NOOP2"),
4: ("G_RM_AA_ZB_TEX_EDGE", "G_RM_NOOP2"),
5: ("G_RM_AA_ZB_XLU_SURF", "G_RM_NOOP2"),
6: ("G_RM_AA_ZB_XLU_DECAL", "G_RM_NOOP2"),
7: ("G_RM_AA_ZB_XLU_INTER", "G_RM_NOOP2"),
sm64_default_draw_layers = {
"0": ("G_RM_ZB_OPA_SURF", "G_RM_NOOP2"),
"1": ("G_RM_AA_ZB_OPA_SURF", "G_RM_NOOP2"),
"2": ("G_RM_AA_ZB_OPA_DECAL", "G_RM_NOOP2"),
"3": ("G_RM_AA_ZB_OPA_INTER", "G_RM_NOOP2"),
"4": ("G_RM_AA_ZB_TEX_EDGE", "G_RM_NOOP2"),
"5": ("G_RM_AA_ZB_XLU_SURF", "G_RM_NOOP2"),
"6": ("G_RM_AA_ZB_XLU_DECAL", "G_RM_NOOP2"),
"7": ("G_RM_AA_ZB_XLU_INTER", "G_RM_NOOP2"),
}

oot_default_draw_layers = {
"Opaque": ("G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"),
"Transparent": ("G_RM_AA_ZB_XLU_SURF", "G_RM_AA_ZB_XLU_SURF2"),
"Overlay": ("G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"),
}

default_draw_layers = {
"SM64": sm64_default_draw_layers,
"OOT": oot_default_draw_layers,
}

CCMUXDict = {
Expand Down Expand Up @@ -3238,18 +3249,18 @@ def spc(x):


# A palette is just a RGBA16 texture with width = 1.
@dataclass
class FImage:
def __init__(self, name, fmt, bitSize, width, height, filename):
self.name = name
self.fmt = fmt
self.bitSize = bitSize
self.width = width
self.height = height
self.startAddress = 0
self.data = bytearray(0)
self.filename = filename
self.converted = False
self.isLargeTexture = False
name: str
fmt: str
bitSize: str
width: int
height: int
filename: str
data: bytearray = field(init=False, compare=False, default_factory=bytearray)
startAddress: int = field(init=False, compare=False, default=0)
isLargeTexture: bool = field(init=False, compare=False, default=False)
converted: bool = field(init=False, compare=False, default=False)

def size(self):
return len(self.data)
Expand Down Expand Up @@ -3812,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 @@ -4025,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 @@ -4211,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 @@ -4315,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 @@ -4818,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 @@ -4841,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
Loading

0 comments on commit 81db750

Please sign in to comment.