Add angle override routine to cookcollision script

This commit is contained in:
Lucas S. Vieira 2025-01-17 01:11:35 -03:00
parent 0c39976abc
commit 54a783b8d5

View file

@ -66,7 +66,7 @@ def to_psx_angle(a):
return math.floor(rat * 4096) return math.floor(rat * 4096)
def get_height_mask(d: Direction, points): def get_height_mask(d: Direction, points, predef_angle):
# Perform iterative linecast. # Perform iterative linecast.
# Linecast checks for a point within a geometry starting at a height # Linecast checks for a point within a geometry starting at a height
# of 15 until 1 (inclusive). 0 means no collision at that height. # of 15 until 1 (inclusive). 0 means no collision at that height.
@ -101,6 +101,11 @@ def get_height_mask(d: Direction, points):
if not found: if not found:
heightmask.append(0) heightmask.append(0)
# When using a predefined angle, we don't need to perform any heavy
# angle calculations!
if predef_angle is not None:
return (heightmask, predef_angle)
# Build vector according to direction # Build vector according to direction
# and heightmask. # and heightmask.
# We have a somewhat naive approach here to determine angle: when we have # We have a somewhat naive approach here to determine angle: when we have
@ -146,11 +151,20 @@ def parse_masks(tiles):
res = [] res = []
for tile in tiles: for tile in tiles:
points = tile.get("points") points = tile.get("points")
predef = tile.get("predef", {})
id = tile.get("id") id = tile.get("id")
(floor, floor_angle) = get_height_mask(Direction.DOWN, points) (floor, floor_angle) = get_height_mask(
(ceil, ceil_angle) = get_height_mask(Direction.UP, points) Direction.DOWN, points, predef.get("floor_angle")
(rwall, rwall_angle) = get_height_mask(Direction.RIGHT, points) )
(lwall, lwall_angle) = get_height_mask(Direction.LEFT, points) (ceil, ceil_angle) = get_height_mask(
Direction.UP, points, predef.get("ceil_angle")
)
(rwall, rwall_angle) = get_height_mask(
Direction.RIGHT, points, predef.get("rwall_angle")
)
(lwall, lwall_angle) = get_height_mask(
Direction.LEFT, points, predef.get("lwall_angle")
)
res.append( res.append(
{ {
@ -171,6 +185,10 @@ def load_json(filename):
return json.load(fp) return json.load(fp)
def hex_to_int(s):
return int(s, 16)
def parse_json(j): def parse_json(j):
tiles = j.get("tiles") tiles = j.get("tiles")
res = [] res = []
@ -180,6 +198,15 @@ def parse_json(j):
objs = grp.get("objects") objs = grp.get("objects")
if objs: if objs:
o = objs[0] o = objs[0]
props = o.get("properties", [])
# Objects might have angle information encoded in them.
# In that case, take these premade angles.
# Name: angle_X value: ??
predef = {}
for prop in props:
has = True
predef[prop.get("name")] = hex_to_int(prop.get("value"))
id = tile.get("id") id = tile.get("id")
x = round(o.get("x"), 0) x = round(o.get("x"), 0)
y = round(o.get("y"), 0) y = round(o.get("y"), 0)
@ -199,6 +226,7 @@ def parse_json(j):
{ {
"id": id, "id": id,
"points": points, "points": points,
"predef": predef,
} }
) )
else: else:
@ -219,6 +247,7 @@ def parse_json(j):
{ {
"id": id, "id": id,
"points": points, "points": points,
"predef": predef,
} }
) )
# print(f"Number of collidable tiles: {len(res)}") # print(f"Number of collidable tiles: {len(res)}")