Skip to content

Commit

Permalink
pos: Drop ATL *_or_none functions
Browse files Browse the repository at this point in the history
The rationale for this is that they didn't serve their intended purpose,
and somewhat misleading. They only called by interpolation, and in such
a way that the argument could never be None.

In 8.2 a special case was added to spline interpolation which used one
of these functions directly, however the additional None handling failed
to make the result any more usable. In order to address this in a more
useful way, and align with non-spline interpolation, None values will
now be treated as zero.
  • Loading branch information
mal committed Feb 13, 2024
1 parent 69cb6b8 commit 6a570b4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 59 deletions.
13 changes: 6 additions & 7 deletions renpy/atl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import renpy
from renpy.pyanalysis import Analysis, NOT_CONST, GLOBAL_CONST
from renpy.display.types import DualAngle, position, position_or_none
from renpy.display.types import DualAngle, position


def compiling(loc):
Expand Down Expand Up @@ -106,11 +106,10 @@ def interpolate(t, a, b, typ):
if a is None:
a = 0

if typ in (position_or_none, position):
if typ is position:
if renpy.config.mixed_position:
a = position(a)
b = position(b)
return a + t * (b - a)
else:
typ = type(b)

Expand All @@ -128,8 +127,8 @@ def interpolate_spline(t, spline, typ):
if spline[0] is None:
return spline[-1]

if renpy.config.mixed_position and typ in (position_or_none, position):
spline = [position_or_none(i) for i in spline]
if typ is position and renpy.config.mixed_position:
spline = [i if i is None else position(i) for i in spline]

lenspline = len(spline)

Expand Down Expand Up @@ -1443,7 +1442,7 @@ def execute(self, trans, st, state, events):

if radii is not None:
startradius, endradius = radii
trans.state.radius = interpolate(complete, startradius, endradius, position_or_none)
trans.state.radius = interpolate(complete, startradius, endradius, position)

if anchorangles is not None:
startangle, endangle = anchorangles[:2]
Expand All @@ -1453,7 +1452,7 @@ def execute(self, trans, st, state, events):

if anchorradii is not None:
startradius, endradius = anchorradii
trans.state.anchorradius = interpolate(complete, startradius, endradius, position_or_none)
trans.state.anchorradius = interpolate(complete, startradius, endradius, position)



Expand Down
2 changes: 1 addition & 1 deletion renpy/display/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __init__(self, start, end):

def __call__(self, t, sizes=(None, None, None, None)):

return renpy.atl.interpolate(t, tuple(self.start), tuple(self.end), renpy.display.types.position_or_none)
return renpy.atl.interpolate(t, tuple(self.start), tuple(self.end), renpy.display.types.position)


def Pan(startpos, endpos, time, child=None, repeat=False, bounce=False,
Expand Down
67 changes: 34 additions & 33 deletions renpy/display/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import renpy
from renpy.display.layout import Container
from renpy.display.accelerator import RenderTransform
from renpy.display.types import DualAngle, absolute, any_object, bool_or_none, float_or_none, matrix, mesh, position, position_or_none
from renpy.display.types import DualAngle, absolute, any_object, matrix, mesh, position


class Camera(renpy.object.Object):
"""
Expand Down Expand Up @@ -1210,22 +1211,22 @@ def add_gl_property(name):
add_property("additive", float, 0.0)
add_property("alpha", float, 1.0)
add_property("blend", any_object, None)
add_property("blur", float_or_none, None)
add_property("corner1", (position_or_none, position_or_none), None)
add_property("corner2", (position_or_none, position_or_none), None)
add_property("crop", (position_or_none, position_or_none, position_or_none, position_or_none), None)
add_property("crop_relative", bool_or_none, None)
add_property("blur", float, None)
add_property("corner1", (position, position), None)
add_property("corner2", (position, position), None)
add_property("crop", (position, position, position, position), None)
add_property("crop_relative", bool, None)
add_property("debug", any_object, None)
add_property("delay", float, 0)
add_property("events", bool, True)
add_property("fit", str, None)
add_property("matrixanchor", (position_or_none, position_or_none), None)
add_property("matrixanchor", (position, position), None)
add_property("matrixcolor", matrix, None)
add_property("matrixtransform", matrix, None)
add_property("maxsize", (int, int), None)
add_property("mesh", mesh, False, diff=None)
add_property("mesh_pad", any_object, None)
add_property("nearest", bool_or_none, None)
add_property("nearest", bool, None)
add_property("perspective", any_object, None)
add_property("rotate", float, None)
add_property("rotate_pad", bool, True)
Expand All @@ -1240,23 +1241,23 @@ def add_gl_property(name):
add_property("transform_anchor", bool, False)
add_property("zoom", float, 1.0)

add_property("xanchoraround", position_or_none, 0.5)
add_property("xanchor", position_or_none, None, diff=4)
add_property("xaround", position_or_none, 0.0)
add_property("xanchoraround", position, 0.5)
add_property("xanchor", position, None, diff=4)
add_property("xaround", position, 0.0)
add_property("xoffset", absolute, 0.0)
add_property("xpan", float_or_none, None)
add_property("xpos", position_or_none, None, diff=4)
add_property("xsize", position_or_none, None)
add_property("xpan", float, None)
add_property("xpos", position, None, diff=4)
add_property("xsize", position, None)
add_property("xtile", int, 1)
add_property("xzoom", float, 1.0)

add_property("yanchoraround", position_or_none, 0.5)
add_property("yanchor", position_or_none, None, diff=4)
add_property("yaround", position_or_none, 0.0)
add_property("yanchoraround", position, 0.5)
add_property("yanchor", position, None, diff=4)
add_property("yaround", position, 0.0)
add_property("yoffset", absolute, 0.0)
add_property("ypan", float_or_none, None)
add_property("ypos", position_or_none, None, diff=4)
add_property("ysize", position_or_none, None)
add_property("ypan", float, None)
add_property("ypos", position, None, diff=4)
add_property("ysize", position, None)
add_property("ytile", int, 1)
add_property("yzoom", float, 1.0)

Expand All @@ -1275,23 +1276,23 @@ def add_gl_property(name):

ALIASES = {
"alignaround" : (float, float),
"align" : (position_or_none, position_or_none), # documented as (float, float)
"anchor" : (position_or_none, position_or_none),
"align" : (position, position), # documented as (float, float)
"anchor" : (position, position),
"anchorangle" : DualAngle.from_any,
"anchoraround" : (position_or_none, position_or_none),
"anchorradius" : position_or_none,
"anchoraround" : (position, position),
"anchorradius" : position,
"angle" : float,
"around" : (position_or_none, position_or_none),
"around" : (position, position),
"offset" : (absolute, absolute),
"pos" : (position_or_none, position_or_none),
"radius" : position_or_none,
"pos" : (position, position),
"radius" : position,
"size" : (int, int),
"xalign" : position_or_none, # documented as float,
"xcenter" : position_or_none,
"xycenter" : (position_or_none, position_or_none),
"xysize" : (position_or_none, position_or_none),
"yalign" : position_or_none, # documented as float
"ycenter" : position_or_none,
"xalign" : position, # documented as float,
"xcenter" : position,
"xycenter" : (position, position),
"xysize" : (position, position),
"yalign" : position, # documented as float
"ycenter" : position,
}

renpy.atl.PROPERTIES.update(ALIASES)
Expand Down
18 changes: 0 additions & 18 deletions renpy/display/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,6 @@ def any_object(x):
return x


def bool_or_none(x):
if x is None:
return x
return bool(x)


def float_or_none(x):
if x is None:
return x
return float(x)


def matrix(x):
if x is None:
return None
Expand All @@ -305,9 +293,3 @@ def mesh(x):
return x

return bool(x)


def position_or_none(x):
if x is None:
return None
return position(x)

0 comments on commit 6a570b4

Please sign in to comment.