3
3
import gc
4
4
import io
5
5
import math
6
+ import os
6
7
7
8
import pymunk
8
9
10
+ try :
11
+ import pygame
12
+
13
+ import pymunk .pygame_util
14
+
15
+ pymunk .pygame_util .positive_y_is_up = True
16
+ except :
17
+ pass
9
18
"""
10
19
Benchmarks
11
20
@@ -232,9 +241,6 @@ def __init__(self, size):
232
241
self .space .add (b , c )
233
242
234
243
235
- import random
236
-
237
-
238
244
class Multifixture (Benchmark ):
239
245
steps = 500
240
246
default_size = 100
@@ -244,7 +250,6 @@ class Multifixture(Benchmark):
244
250
245
251
def __init__ (self , size ):
246
252
super ().__init__ ()
247
- random .seed (1 )
248
253
s1 = pymunk .Segment (self .space .static_body , (- 35 , 0 ), (35 , 0 ), 1 )
249
254
s2 = pymunk .Segment (self .space .static_body , (- 36 , 50 ), (- 36 , 0 ), 1 )
250
255
s3 = pymunk .Segment (self .space .static_body , (36 , 50 ), (36 , 0 ), 1 )
@@ -526,6 +531,20 @@ def __init__(self, size):
526
531
self .space .add (b , c )
527
532
528
533
534
+ class Stacking :
535
+
536
+ def __init__ (self ):
537
+ self .space = pymunk .Space ()
538
+
539
+ s = pymunk .Segment (self .space .static_body , (0 , 500 ), (500 , 500 ), 5 )
540
+
541
+ def update (self , dt ):
542
+ pass
543
+
544
+ def draw (self ):
545
+ pass
546
+
547
+
529
548
benchmarks = [
530
549
FallingSquares ,
531
550
FallingCircles ,
@@ -615,6 +634,18 @@ def run(bench_cls, size, interactive):
615
634
sim .update (1 / fps )
616
635
steps += 1
617
636
637
+ if not interactive and False : # temp disabled until end state is nice to look at.
638
+ try :
639
+ os .environ ["SDL_VIDEODRIVER" ] = "dummy"
640
+ surface = pygame .Surface ((600 , 600 ))
641
+ draw_options = pymunk .pygame_util .DrawOptions (surface )
642
+ draw_options .flags = draw_options .DRAW_SHAPES
643
+ surface .fill (pygame .Color ("white" ))
644
+ sim .draw (draw_options )
645
+ pygame .image .save (surface , f"{ bench_cls .__name__ } _{ size } .png" )
646
+ except Exception as e :
647
+ print ("Could not save screenshot" , e )
648
+
618
649
time_s = timeit .default_timer () - start_time
619
650
return {"benchmark" : bench_cls .__name__ , "size" : size , "time" : time_s }
620
651
@@ -629,7 +660,7 @@ def run(bench_cls, size, interactive):
629
660
choices = benchmark_names ,
630
661
nargs = "*" ,
631
662
help = "Run these benchmarks" ,
632
- default = benchmark_names [ 0 : 1 ] ,
663
+ default = benchmark_names ,
633
664
)
634
665
parser .add_argument (
635
666
"-s" ,
@@ -650,12 +681,6 @@ def run(bench_cls, size, interactive):
650
681
writer = csv .DictWriter (csv_output , fieldnames = ["benchmark" , "size" , "time" ])
651
682
writer .writeheader ()
652
683
for name in args .benchmarks :
653
- if args .interactive :
654
- import pygame
655
-
656
- import pymunk .pygame_util
657
-
658
- pymunk .pygame_util .positive_y_is_up = True
659
684
660
685
bench_cls = [bench for bench in benchmarks if bench .__name__ == name ][0 ]
661
686
@@ -679,17 +704,3 @@ def run(bench_cls, size, interactive):
679
704
print ("DONE!" )
680
705
print ("Full Result:" )
681
706
print (csv_output .getvalue ())
682
-
683
-
684
- class Stacking :
685
-
686
- def __init__ (self ):
687
- self .space = pymunk .Space ()
688
-
689
- s = pymunk .Segment (self .space .static_body , (0 , 500 ), (500 , 500 ), 5 )
690
-
691
- def update (self , dt ):
692
- pass
693
-
694
- def draw (self ):
695
- pass
0 commit comments