-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial cleanup of arcade.types #2065
Merged
eruvanos
merged 31 commits into
pythonarcade:development
from
pushfoo:arcade_type_module_cleanup
Apr 23, 2024
Merged
Initial cleanup of arcade.types #2065
eruvanos
merged 31 commits into
pythonarcade:development
from
pushfoo:arcade_type_module_cleanup
Apr 23, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Remove unused TypeVar import * Move BufferProtocol conditional import to the top * Make backport-related imports conditional instead of universal
* Remove Vec2 and Vec3 from the unions since pyglet's Vec tpyes are now tuples * Remove Vec2 and Vec3 imports from arcade.math
* Add subscriptable PathOr alias * Remove Optional from PathOrTexture * Wrap usages of PathOrTexture in Optional * Add bytes to PathLike Union alias * Clean up imports in some PathOrTexture-using files * Move the if TYPE_CHECKING import of Texture closer to the usage
Praying to the merging gods we can get this in ASAP. Super important. Also, glorious write up, push. |
7 tasks
* Add back Vector alias * Rename it to Velocity in arcade.types * Change imports in particles + annotations in particles to account for this
…m just getting it to build.
This was referenced Apr 18, 2024
DragonMoffon
approved these changes
Apr 20, 2024
eruvanos
pushed a commit
that referenced
this pull request
Apr 23, 2024
* Replace old bloated color validation with Color's from_iterable + normalize * Improve readability & fail speed in draw_commands * Move validation & unpacking ctx members to locals to top of functions * Use Color's from_iterable + normalize * Use named variables for goal buffer sizes to make buffer expansion clearer * Add comments and attempt to make math more readable * Finish dedupe of logic / name shortening in draw_lines * Skip tuple redundant tuple conversion since array.array accepts appropriate iterables * Don't re-divide when we already know the size * Explain safety // 8 * Separate steps better in draw_points * Copy to ctypes array earlier * Skip tuple conversion for array.array since it takes generators * Attempt to make draw_polygon_outline's current logic more readable * Sequence.extend doesn't exist, so annotate local variable as List[Point]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
TL;DR: Spring cleaning to make 3.0-critical fixes easier
arcade.types
a folder moduleColor
and related toarcade.types.color
NamedPoint
Vec2
once non-advertised API issues are resolvedIPoint
in favor of clearerSize2D[int]
arcade.types.Vector
toVelocity
arcade.math
:Vec*
fromV_2D
andV_3D
aliases sincepyglet.math.Vec*
types are now tuplesarcade.types.AsFloat
in a few places, such asarcade.,math.lerp
Why?
TL;DR: Multiple 3.0-mandatory issues need good rectangle abstraction(s)
Rect
into our rectangle abstractionarcade.types
moduleThe 3.0 issues which need good rectangles
The following 3.0-mandatory issues would all be massively helped along by sharing rectangle handling code to avoid bugs:
1. Cameras
Due to lack of good rectangle abstractions, cameras individually compute and expose both raw and scaled values by:
value[0]
)*Data
classes.As a result of this, we have:
.
accesses due to individual recalculation of valuesFor example, if we want to check what's in the player's view, scaled projection boundaries currently waste 4 function calls and repeated
.
accesses recalculating the values:arcade/arcade/camera/camera_2d.py
Lines 364 to 469 in d625a01
Instead, we should be recalculating the scaled rectangle bounds once relative to the projection centerpoint and returning it. For bound checking, we'll:
left <= x <= right and bottom <= y <= top
)2. The 3.0-mandatory create_text_sprite rework
I've paused work on #1410 since I don't want to buggily rewrite bounds checking and scaling code.
3. (Not actually 3.0) Screenshots
To complete #2039 to satisfaction, we'll want region handling. Rectangles can do that.
Just how nasty is our type situation?
Rectangles are very nasty
First, we have at least 4 different ways of using / defining "rectangle" data. We won't fix this in this PR, but we'll clear room for it.
Two of the rectangle definitions are very bad:
Rect
type alias insidearcade.types
:LBWH
in the commentsLRBT
elsewherearcade.math.rand_in_rect
takesbottom_left: Point, width: float, height: float
We also have two good ones:
The LBWH
Rect
inside the GUI__contains__
as point bound-checking toolSeparate left, right, bottom, top arguments to functions in
draw_commands
The rest is cluttered
This PR tries to clean up some of the various redundant or one-off definitions cluttering
arcade.types
. It also movesColor
and related defs into their own submodule.Future work / PRs
3.0 Critical Work
Rect
type which computes not just axis bound values (LRBT), but also width and heightProtocol
with propertiestyping.NamedTuple
for base classes due to these being fastest for named access according to the pyglet team's testsRect
into the decided reusable componentarcade.particles
:arcade.types.Velcocity
As time allows
utils