Skip to content

Commit

Permalink
[SM64] Add depth arg and remove comma from existing cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Oct 8, 2024
1 parent 7cdb920 commit 4ce74fb
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions fast64_internal/sm64/sm64_geolayout_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def c_func_macro(self, base_cmd: str, *args: str):
all_args = list(args)
if self.hasDL:
all_args.append(self.get_dl_name())
return f'{self.get_c_func_macro(base_cmd)}({", ".join(all_args)}),'
return f'{self.get_c_func_macro(base_cmd)}({", ".join(all_args)})'


class TransformNode:
Expand Down Expand Up @@ -382,7 +382,7 @@ def to_c(self, depth):
if self.node is not None:
nodeC = self.node.to_c()
if nodeC is not None: # Should only be the case for DisplayListNode with no DL
data = depth * "\t" + self.node.to_c() + "\n"
data = depth * "\t" + f"{self.node.to_c(depth)},\n"
else:
data = ""
else:
Expand Down Expand Up @@ -464,9 +464,9 @@ def to_binary(self, segmentData):
command.extend(startAddress)
return command

def to_c(self):
def to_c(self, _depth = 0):
geo_name = self.geoRef or self.geolayout.name
return "GEO_BRANCH(" + ("1, " if self.storeReturn else "0, ") + geo_name + "),"
return "GEO_BRANCH(" + ("1, " if self.storeReturn else "0, ") + geo_name + ")"


class GeoLayoutBleed(BleedGraphics):
Expand Down Expand Up @@ -531,8 +531,8 @@ def to_binary(self, segmentData):
addFuncAddress(command, self.geo_func)
return command

def to_c(self):
return "GEO_ASM(" + str(self.func_param) + ", " + convert_addr_to_func(self.geo_func) + "),"
def to_c(self, _depth = 0):
return "GEO_ASM(" + str(self.func_param) + ", " + convert_addr_to_func(self.geo_func) + ")"


class HeldObjectNode:
Expand All @@ -551,7 +551,7 @@ def to_binary(self, segmentData):
addFuncAddress(command, self.geo_func)
return command

def to_c(self):
def to_c(self, _depth = 0):
return (
"GEO_HELD_OBJECT(0, "
+ str(convertFloatToShort(self.translate[0]))
Expand All @@ -561,7 +561,7 @@ def to_c(self):
+ str(convertFloatToShort(self.translate[2]))
+ ", "
+ convert_addr_to_func(self.geo_func)
+ "),"
+ ")"
)


Expand All @@ -576,8 +576,8 @@ def to_binary(self, segmentData):
command = bytearray([GEO_START, 0x00, 0x00, 0x00])
return command

def to_c(self):
return "GEO_NODE_START(),"
def to_c(self, _depth = 0):
return "GEO_NODE_START()"


class EndNode:
Expand All @@ -591,8 +591,8 @@ def to_binary(self, segmentData):
command = bytearray([GEO_END, 0x00, 0x00, 0x00])
return command

def to_c(self):
return "GEO_END(),"
def to_c(self, _depth = 0):
return "GEO_END()"


# Geolayout node hierarchy is first generated without material/draw layer
Expand All @@ -616,8 +616,8 @@ def to_binary(self, segmentData):
addFuncAddress(command, self.switchFunc)
return command

def to_c(self):
return "GEO_SWITCH_CASE(" + str(self.defaultCase) + ", " + convert_addr_to_func(self.switchFunc) + "),"
def to_c(self, _depth = 0):
return "GEO_SWITCH_CASE(" + str(self.defaultCase) + ", " + convert_addr_to_func(self.switchFunc) + ")"


class TranslateRotateNode(BaseDisplayListNode):
Expand Down Expand Up @@ -688,7 +688,7 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
if self.fieldLayout == 0:
return self.c_func_macro(
"GEO_TRANSLATE_ROTATE",
Expand Down Expand Up @@ -755,7 +755,7 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
return self.c_func_macro(
"GEO_TRANSLATE_NODE",
getDrawLayerName(self.drawLayer),
Expand Down Expand Up @@ -798,7 +798,7 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
return self.c_func_macro(
"GEO_ROTATION_NODE",
getDrawLayerName(self.drawLayer),
Expand Down Expand Up @@ -840,7 +840,7 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
return self.c_func_macro(
"GEO_BILLBOARD_WITH_PARAMS",
getDrawLayerName(self.drawLayer),
Expand Down Expand Up @@ -875,11 +875,11 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
if not self.hasDL:
return None
args = [getDrawLayerName(self.drawLayer), self.get_dl_name()]
return f"GEO_DISPLAY_LIST({join_c_args(args)}),"
return f"GEO_DISPLAY_LIST({join_c_args(args)})"


class ShadowNode:
Expand All @@ -899,9 +899,9 @@ def to_binary(self, segmentData):
command.extend(self.shadowScale.to_bytes(2, "big"))
return command

def to_c(self):
def to_c(self, _depth = 0):
return (
"GEO_SHADOW(" + str(self.shadowType) + ", " + str(self.shadowSolidity) + ", " + str(self.shadowScale) + "),"
"GEO_SHADOW(" + str(self.shadowType) + ", " + str(self.shadowSolidity) + ", " + str(self.shadowScale) + ")"
)


Expand Down Expand Up @@ -933,7 +933,7 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
return self.c_func_macro(
"GEO_SCALE", getDrawLayerName(self.drawLayer), str(int(round(self.scaleValue * 0x10000)))
)
Expand All @@ -952,12 +952,12 @@ def to_binary(self, segmentData):
command.extend(convertFloatToShort(self.cullingRadius).to_bytes(2, "big"))
return command

def to_c(self):
def to_c(self, _depth = 0):
cullingRadius = convertFloatToShort(self.cullingRadius)
# if abs(cullingRadius) > 2**15 - 1:
# raise PluginError("A render area node has a culling radius that does not fit an s16.\n Radius is " +\
# str(cullingRadius) + ' when converted to SM64 units.')
return "GEO_CULLING_RADIUS(" + str(convertFloatToShort(self.cullingRadius)) + "),"
return "GEO_CULLING_RADIUS(" + str(convertFloatToShort(self.cullingRadius)) + ")"


class RenderRangeNode:
Expand All @@ -975,13 +975,13 @@ def to_binary(self, segmentData):
command.extend(convertFloatToShort(self.maxDist).to_bytes(2, "big"))
return command

def to_c(self):
def to_c(self, _depth = 0):
minDist = convertFloatToShort(self.minDist)
maxDist = convertFloatToShort(self.maxDist)
# if (abs(minDist) > 2**15 - 1) or (abs(maxDist) > 2**15 - 1):
# raise PluginError("A render range (LOD) node has a range that does not fit an s16.\n Range is " +\
# str(minDist) + ', ' + str(maxDist) + ' when converted to SM64 units.')
return "GEO_RENDER_RANGE(" + str(minDist) + ", " + str(maxDist) + "),"
return "GEO_RENDER_RANGE(" + str(minDist) + ", " + str(maxDist) + ")"


class DisplayListWithOffsetNode(BaseDisplayListNode):
Expand Down Expand Up @@ -1012,15 +1012,15 @@ def to_binary(self, segmentData):
command.extend(bytearray([0x00] * 4))
return command

def to_c(self):
def to_c(self, _depth = 0):
args = [
getDrawLayerName(self.drawLayer),
str(convertFloatToShort(self.translate[0])),
str(convertFloatToShort(self.translate[1])),
str(convertFloatToShort(self.translate[2])),
self.get_dl_name(), # This node requires 'NULL' if there is no DL
]
return f"GEO_ANIMATED_PART({join_c_args(args)}),"
return f"GEO_ANIMATED_PART({join_c_args(args)})"


class ScreenAreaNode:
Expand All @@ -1046,10 +1046,10 @@ def to_binary(self, segmentData):
command.extend(dimensions[1].to_bytes(2, "big", signed=True))
return command

def to_c(self):
def to_c(self, _depth = 0):
if self.useDefaults:
return (
"GEO_NODE_SCREEN_AREA(10, " + "SCREEN_WIDTH/2, SCREEN_HEIGHT/2, " + "SCREEN_WIDTH/2, SCREEN_HEIGHT/2),"
"GEO_NODE_SCREEN_AREA(10, " + "SCREEN_WIDTH/2, SCREEN_HEIGHT/2, " + "SCREEN_WIDTH/2, SCREEN_HEIGHT/2)"
)
else:
return (
Expand All @@ -1063,7 +1063,7 @@ def to_c(self):
+ str(self.dimensions[0])
+ ", "
+ str(self.dimensions[1])
+ "),"
+ ")"
)


Expand All @@ -1081,8 +1081,8 @@ def to_binary(self, segmentData):
command.extend(bytearray(pack(">f", self.scale)))
return command

def to_c(self):
return "GEO_NODE_ORTHO(" + format(self.scale, ".4f") + "),"
def to_c(self, _depth = 0):
return "GEO_NODE_ORTHO(" + format(self.scale, ".4f") + ")"


class FrustumNode:
Expand All @@ -1106,9 +1106,9 @@ def to_binary(self, segmentData):
command.extend(bytes.fromhex("8029AA3C"))
return command

def to_c(self):
def to_c(self, _depth = 0):
if not self.useFunc:
return "GEO_CAMERA_FRUSTUM(" + format(self.fov, ".4f") + ", " + str(self.near) + ", " + str(self.far) + "),"
return "GEO_CAMERA_FRUSTUM(" + format(self.fov, ".4f") + ", " + str(self.near) + ", " + str(self.far) + ")"
else:
return (
"GEO_CAMERA_FRUSTUM_WITH_FUNC("
Expand All @@ -1117,7 +1117,7 @@ def to_c(self):
+ str(self.near)
+ ", "
+ str(self.far)
+ ", geo_camera_fov),"
+ ", geo_camera_fov)"
)


Expand All @@ -1133,8 +1133,8 @@ def to_binary(self, segmentData):
command = bytearray([GEO_SET_Z_BUF, 0x01 if self.enable else 0x00, 0x00, 0x00])
return command

def to_c(self):
return "GEO_ZBUFFER(" + ("1" if self.enable else "0") + "),"
def to_c(self, _depth = 0):
return "GEO_ZBUFFER(" + ("1" if self.enable else "0") + ")"


class CameraNode:
Expand All @@ -1160,7 +1160,7 @@ def to_binary(self, segmentData):
addFuncAddress(command, self.geo_func)
return command

def to_c(self):
def to_c(self, _depth = 0):
return (
"GEO_CAMERA("
+ str(self.camType)
Expand All @@ -1178,7 +1178,7 @@ def to_c(self):
+ str(self.lookAt[2])
+ ", "
+ convert_addr_to_func(self.geo_func)
+ "),"
+ ")"
)


Expand All @@ -1194,8 +1194,8 @@ def to_binary(self, segmentData):
command = bytearray([GEO_SETUP_OBJ_RENDER, 0x00, 0x00, 0x00])
return command

def to_c(self):
return "GEO_RENDER_OBJ(),"
def to_c(self, _depth = 0):
return "GEO_RENDER_OBJ()"


class BackgroundNode:
Expand All @@ -1217,11 +1217,11 @@ def to_binary(self, segmentData):
addFuncAddress(command, self.geo_func)
return command

def to_c(self):
def to_c(self, _depth = 0):
if self.isColor:
return "GEO_BACKGROUND_COLOR(0x" + format(self.backgroundValue, "04x").upper() + "),"
return "GEO_BACKGROUND_COLOR(0x" + format(self.backgroundValue, "04x").upper() + ")"
else:
return "GEO_BACKGROUND(" + str(self.backgroundValue) + ", " + convert_addr_to_func(self.geo_func) + "),"
return "GEO_BACKGROUND(" + str(self.backgroundValue) + ", " + convert_addr_to_func(self.geo_func) + ")"


class CustomNode:
Expand All @@ -1236,8 +1236,8 @@ def size(self):
def to_binary(self, segmentData):
raise PluginError("Custom Geo Nodes are not supported for binary exports.")

def to_c(self):
return f"{self.command}({self.args}),"
def to_c(self, _depth = 0):
return f"{self.command}({self.args})"


class CustomAnimatedNode(BaseDisplayListNode):
Expand All @@ -1262,7 +1262,7 @@ def get_ptr_offsets(self):
def to_binary(self, segmentData):
raise PluginError("Custom Geo Nodes are not supported for binary exports.")

def to_c(self):
def to_c(self, _depth = 0):
args = [
getDrawLayerName(self.drawLayer),
str(convertFloatToShort(self.translate[0])),
Expand All @@ -1271,7 +1271,7 @@ def to_c(self):
*(str(radians_to_s16(r)) for r in self.rotate.to_euler("XYZ")),
self.get_dl_name(), # This node requires 'NULL' if there is no DL
]
return f"{self.command}({join_c_args(args)}),"
return f"{self.command}({join_c_args(args)})"


nodeGroupClasses = [
Expand Down

0 comments on commit 4ce74fb

Please sign in to comment.