-
Notifications
You must be signed in to change notification settings - Fork 360
Closed
Labels
performanceSpeed / OptimizationsSpeed / Optimizations
Milestone
Description
This might just be about reverting #2021
The vector sprite perf testing showed 2.x cost. We should quickly review the cost of the sprite scale changes before we release.
Lines 263 to 339 in fa6e938
| @property | |
| def scale(self) -> Vec2: | |
| """Get or set the x & y scale of the sprite as a pair of values. | |
| You may set it to either a single value or a pair of values: | |
| .. list-table:: | |
| :header-rows: 0 | |
| * - Single value | |
| - ``sprite.scale = 2.0`` | |
| * - Tuple or :py:class:`~pyglet,math.Vec2` | |
| - ``sprite.scale = (1.0, 3.0)`` | |
| The two-channel version is useful for making health bars and | |
| other indicators. | |
| .. note:: Returns a :py:class:`pyglet.math.Vec2` for | |
| compatibility. | |
| Arcade versions lower than 3,0 used one or both of the following | |
| for scale: | |
| * A single :py:class:`float` on versions <= 2.6 | |
| * A ``scale_xy`` property and exposing only the x component | |
| on some intermediate dev releases | |
| Although scale is internally stored as a :py:class:`tuple`, we | |
| return a :py:class:`pyglet.math.Vec2` to allow the in-place | |
| operators to work in addition to setting values directly: | |
| * Old-style (``sprite.scale *= 2.0``) | |
| * New-style (``sprite.scale *= 2.0, 2.0``) | |
| .. note:: Negative scale values are supported. | |
| This applies to both single-axis and dual-axis. | |
| Negatives will flip & mirror the sprite, but the | |
| with will use :py:func:`abs` to report total width | |
| and height instead of negatives. | |
| """ | |
| return Vec2(*self._scale) | |
| @scale.setter | |
| def scale(self, new_scale: Point2 | AsFloat): | |
| if isinstance(new_scale, (float, int)): | |
| scale_x = new_scale | |
| scale_y = new_scale | |
| else: # Treat it as some sort of iterable or sequence | |
| # Don't abstract this. Keep it here since it's a hot code path | |
| try: | |
| scale_x, scale_y = new_scale # type / length implicit check | |
| except ValueError: | |
| raise ValueError( | |
| "scale must be a tuple-like object which unpacks to exactly 2 coordinates" | |
| ) | |
| except TypeError: | |
| raise TypeError( | |
| "scale must be a tuple-like object which unpacks to exactly 2 coordinates" | |
| ) | |
| new_scale = scale_x, scale_y | |
| if new_scale == self._scale: | |
| return | |
| self._hit_box.scale = new_scale | |
| tex_width, tex_height = self._texture.size | |
| self._scale = new_scale | |
| self._width = tex_width * scale_x | |
| self._height = tex_height * scale_y | |
| self.update_spatial_hash() | |
| for sprite_list in self.sprite_lists: | |
| sprite_list._update_size(self) |
We might just have to revert these changes for now and bake them into the new experimental sprites.
See : #2184
Metadata
Metadata
Assignees
Labels
performanceSpeed / OptimizationsSpeed / Optimizations