@@ -9,7 +9,7 @@ anything.
9
9
Arcade uses OpenGL. It is very fast at drawing sprites and off-loads functions such as rotation
10
10
and transparency to the graphics card.
11
11
12
- Here are some comparisons between Arcade 2.6 and Pygame 2.0.1 :
12
+ Here are some comparisons between Arcade 2.6 and Pygame 2.2.0 ce :
13
13
14
14
.. list-table :: Library Information
15
15
:widths: 33 33 33
@@ -76,7 +76,7 @@ Here are some comparisons between Arcade 2.6 and Pygame 2.0.1:
76
76
- Yes
77
77
* - Batch drawing
78
78
- Via GPU
79
- - Via Surface [#f5 ]_
79
+ - Via Surface [#f3 ]_
80
80
* - Default Hitbox
81
81
- .. image:: images/hitbox_simple.png
82
82
:width: 30%
@@ -109,66 +109,94 @@ Here are some comparisons between Arcade 2.6 and Pygame 2.0.1:
109
109
- `Yes <resources.html >`__
110
110
- No
111
111
112
- .. list-table :: Performance Comparison [#f6]_
113
- :widths: 33 33 33
114
- :header-rows: 1
115
-
116
- * - Feature
117
- - Arcade
118
- - Pygame
119
- * - Draw 50,000 stationary sprites
120
- - 0.001 seconds
121
- - 0.425 seconds
122
- * - Move 5,000 sprites
123
- - 0.010 seconds
124
- - 0.003 seconds
125
- * - # sprites program can move + draw
126
- before FPS drops below 55
127
- - 8500
128
- - 2000
129
- * - Collision detection 50,000 sprites
130
- - | 0.044 seconds no spatial hashing [#f3 ]_
131
- | 0.005 seconds with spatial hashing
132
- - 0.004 seconds [#f4 ]_
133
- * - Draw 5,000 plain rectangles [#f7 ]_
134
- - 0.081 seconds
135
- - 0.008 seconds
136
- * - Draw 5,000 rotated rectangles [#f8 ]_
137
- - 0.081 seconds
138
- - 0.029 seconds
139
-
140
- .. figure :: images/fps_comparison2.svg
141
-
142
- FPS comparison of programs drawing **stationary ** sprites.
143
-
144
- .. figure :: images/fps_comparison1.svg
145
-
146
- FPS comparison of programs drawing **moving ** sprites.
147
-
148
112
.. [#f1 ] To support rotation and/or scaling, PyGame programs must write the image to a surface, transform the surface,
149
113
then create a sprite out of the surface. This takes a lot of CPU. Arcade off-loads all these operations to the
150
114
graphics card.
151
115
.. [#f2 ] When creating a sprite from an image, Pygame will load the image from the disk every time. The user must
152
116
cache the image with their own code for better performance. Arcade does this automatically.
153
- .. [#f5 ] A programmer can achieve a similar result by drawing to a surface, then drawing the surface to the screen.
154
- .. [#f6 ] Performance tests done on an Intel Core i7-9700F with GeForce GTX 980 Ti. Source code for tests available at
155
- https://github.com/pythonarcade/performance_tests and more detailed results at
156
- https://craven-performance-testing.s3-us-west-2.amazonaws.com/index.html
157
- .. [#f3 ] Polygon hit box, rotation allowed
158
- .. [#f4 ] Rectangular hit box, no rotation allowed
159
- .. [#f7 ] Why is Arcade so slow here? With PyGame, most of the drawing is done on the **CPU ** side. Bitmaps
160
- are created and manipulated by the CPU. It is pretty fast. With Arcade, most of the drawing happens
161
- on the **GPU ** side. Sprites and drawings are batched together, and we just tell the GPU what we want
162
- to change. Or better yet, we write a "shader" program that runs completely on the GPU.
163
- This is *incredibly * fast. But
164
- if instead a CPU program runs commands to draw individual GPU items one-by-one, both sets
165
- of processors wait for a synchronous communication.
166
- That is horribly slow. Drawing individual rects and bits like
167
- PyGame does, won't work well at all on Arcade. Use sprites, shaders, or batch-drawing to
168
- get fast performance.
169
- .. [#f8 ] Scaling and rotation must be done by the programmer drawing to a surface, transforming the surface,
170
- then blit'ing the surface to the screen. Arcade uses the GPU for these operations and needs no
171
- additional code or performance hits.
117
+ .. [#f3 ] A programmer can achieve a similar result by drawing to a surface, then drawing the surface to the screen.
118
+
119
+
120
+ Performance Comparison
121
+ ----------------------
122
+
123
+ These performance tests were done on an Intel Core i7-9700F with GeForce GTX 980 Ti. Source code for tests available at:
124
+
125
+ * https://craven-performance-testing.s3-us-west-2.amazonaws.com/index.html
126
+ * https://github.com/pythonarcade/performance_tests
127
+
128
+ Sprite Drawing
129
+ ^^^^^^^^^^^^^^
130
+
131
+ How fast can the graphics libraries draw sprites that don't move?
132
+ This graph shows the Frames Per Second (FPS) the computer can maintain vs. the number of sprites being drawn
133
+ each frame:
134
+
135
+ .. image :: images/fps_comparison_stationary_sprites.svg
136
+
137
+ Why is Arcade so fast?
138
+ Arcade loads the sprites to the GPU and can redraw stationary sprites with almost no CPU effort. This allows
139
+ it to scale drawing of stationary sprites to even 1 million plus, and still keep 60 FPS.
140
+
141
+ While Pygame's speed may drop off fast, there's still a few thousand sprites that can be drawn on the screen
142
+ before FPS drops off. For many games that's plenty.
143
+ Also, for sprites that don't move, Pygame programs can draw the sprites to a 'surface' at the start of a game.
144
+ A program can then use that surface to the screen in one operation.
145
+
146
+ How fast can we draw moving sprites?
147
+ Moving sprites are more challenging to draw, as we can't simply use what we did in the prior frame.
148
+
149
+ .. image :: images/fps_comparison_moving_sprites.svg
150
+
151
+ Arcade only updates the changed location of the sprite, keeping the dimensions and image on the GPU
152
+ allowing it to still have fast updates.
153
+
154
+ Arcade also has two sprite classes available. The full-featured :py:class: `arcade.Sprite ` class
155
+ and the smaller and faster :py:class: `arcade.BasicSprite ` class. If you don't need collision detection
156
+ or physics support, the ``BasicSprite `` class works great.
157
+
158
+ Collision Processing
159
+ ^^^^^^^^^^^^^^^^^^^^
160
+
161
+ Another time-critical component in games is the time it takes to figure out if sprites collide:
162
+
163
+ .. image :: images/fps_comparison_stationary_collision.svg
164
+
165
+ Normally collision detection is an O(N) operation. That is, if are checking to see if a sprite collides with
166
+ any of 1,000 other sprites, we have 1,000 checks to do. If there are a lot of sprites, this takes time.
167
+
168
+ Arcade has two ways to speed this up.
169
+
170
+ 1. Spatial Hashing. If we know those 1,000 sprites aren't going to move at all (or very much) we can set up a
171
+ grid. We figure out what grid locaiton the player is in. Then we only check the player against whichever
172
+ of the 1,000 sprites are in the same grid location. This works great for tiled maps where the platforms, ramps,
173
+ etc. don't move.
174
+ 2. Off-load to the GPU. As there are 1,000s of processors on your graphics card, we can calculate collisions there.
175
+ However it takes time to set up the GPU. This is only faster if we have more than 1500 or so sprites to check.
176
+
177
+ Arcade has multiple modes that allow you to select these collision options.
178
+
179
+ Shapes
180
+ ^^^^^^
181
+
182
+ Aside from sprites, how fast can a library draw various graphical shapes? Rectangle, circles, arcs, and more?
183
+
184
+ This next benchmark looks at drawing rectangles. Important things to keep in mind:
185
+
186
+ * Pygame uses memory bliting which is crazy fast and why it comes out in first-place. This doesn't work as well
187
+ if you are drawing anything but unrotated rectangles.
188
+ * Arcade's shapes are easy, but crazy-slow.
189
+ Thankfully you can use Pyglet shapes in the same program as Arcade.
190
+ For anything more than a dozen or so shapes, a program should do that.
191
+ * Arcade has a Sprite class for solid-color rectangles. If you needed rectangles the `SpriteSolidColor `
192
+ would be a high performance option not shown here.
193
+
194
+ .. image :: images/fps_comparison_unrotated_rects.svg
195
+
196
+ What if a shape needs to be rotated? Pyglet can offload this to the GPU and this allows it to perform
197
+ faster than Pygame that relies on the CPU.
198
+
199
+ .. image :: images/fps_comparison_rotated_rects.svg
172
200
173
201
.. _MIT License : https://github.com/pythonarcade/arcade/blob/development/license.rst
174
202
.. _LGPL : https://github.com/pygame/pygame/blob/main/docs/LGPL.txt
0 commit comments