11#!/usr/bin/env python
22"""
33 Stress test designed to test tdl under harsh conditions
4-
4+
55 Note that one of the slower parts is converting colors over ctypes so you
66 can get a bit of speed avoiding the fgcolor and bgcolor parameters.
77 Another thing slowing things down are mass calls to ctypes functions.
@@ -27,23 +27,23 @@ class StopWatch:
2727 def __init__ (self ):
2828 self .enterTime = None
2929 self .snapshots = []
30-
30+
3131 def __enter__ (self ):
3232 self .enterTime = time .clock ()
33-
33+
3434 def __exit__ (self , * exc ):
3535 self .snapshots .append (time .clock () - self .enterTime )
3636 if len (self .snapshots ) > self .MAXSNAPSHOTS :
3737 self .snapshots .pop (0 )
38-
38+
3939 def getMeanTime (self ):
4040 if not self .snapshots :
4141 return 0
4242 return sum (self .snapshots ) / len (self .snapshots )
43-
43+
4444
4545class TestApp (tdl .event .App ):
46-
46+
4747 def __init__ (self , console ):
4848 self .console = console
4949 self .writer = self .console
@@ -53,22 +53,22 @@ def __init__(self, console):
5353 self .cells = list (itertools .product (range (self .width ), range (self .height )))
5454 self .tick = 0
5555 self .init ()
56-
56+
5757 def init (self ):
5858 pass
59-
59+
6060 def ev_MOUSEDOWN (self , event ):
6161 self .suspend ()
62-
62+
6363 def update (self , deltaTime ):
6464 self .updateTest (deltaTime )
6565 self .tick += 1
6666 #if self.tick % 50 == 0:
6767 tdl .setTitle ('%s: %i FPS' % (self .__class__ .__name__ , tdl .getFPS ()))
6868 tdl .flush ()
69-
70- class FullDrawCharTest (TestApp ):
71-
69+
70+ class FullDrawCharTest (TestApp ):
71+
7272 def updateTest (self , deltaTime ):
7373 # getrandbits is around 5x faster than using randint
7474 bgcolors = [(random .getrandbits (7 ), random .getrandbits (7 ), random .getrandbits (7 )) for _ in range (self .total )]
@@ -77,26 +77,26 @@ def updateTest(self, deltaTime):
7777 for (x ,y ), bgcolor , char in zip (self .cells , bgcolors , char ):
7878 self .console .draw_char (x , y , char , fgcolor , bgcolor )
7979
80- class PreCompiledColorTest (TestApp ):
80+ class PreCompiledColorTest (TestApp ):
8181 """
8282 This test was to see if the cast to the ctypes Color object was a big
8383 impact on performance, turns out there's no hit with this class.
8484 """
85-
85+
8686 def init (self ):
8787 self .bgcolors = [tdl ._Color (random .getrandbits (7 ),
8888 random .getrandbits (7 ),
8989 random .getrandbits (7 ))
9090 for _ in range (256 )]
9191 self .fgcolor = tdl ._Color (255 , 255 , 255 )
92-
92+
9393 def updateTest (self , deltaTime ):
9494 # getrandbits is around 5x faster than using randint
9595 char = [random .getrandbits (8 ) for _ in range (self .total )]
9696 for (x ,y ), char in zip (self .cells , char ):
9797 self .console .draw_char (x , y , char ,
9898 self .fgcolor , random .choice (self .bgcolors ))
99-
99+
100100
101101class CharOnlyTest (TestApp ):
102102
@@ -114,17 +114,17 @@ def updateTest(self, deltaTime):
114114 for (x ,y ), char in zip (self .cells , char ):
115115 self .writer .move (x , y )
116116 self .writer .print_str (chr (char ))
117-
118- class ColorOnlyTest (TestApp ):
119-
117+
118+ class ColorOnlyTest (TestApp ):
119+
120120 def updateTest (self , deltaTime ):
121121 # getrandbits is around 5x faster than using randint
122122 bgcolors = [(random .getrandbits (6 ), random .getrandbits (6 ), random .getrandbits (6 )) for _ in range (self .total )]
123123 for (x ,y ), bgcolor in zip (self .cells , bgcolors ):
124124 self .console .draw_char (x , y , None , None , bgcolor )
125125
126- class GetCharTest (TestApp ):
127-
126+ class GetCharTest (TestApp ):
127+
128128 def updateTest (self , deltaTime ):
129129 for (x ,y ) in self .cells :
130130 self .console .get_char (x , y )
@@ -134,23 +134,23 @@ class SingleRectTest(TestApp):
134134 def updateTest (self , deltaTime ):
135135 bgcolor = (random .getrandbits (6 ), random .getrandbits (6 ), random .getrandbits (6 ))
136136 self .console .draw_rect (0 , 0 , None , None , ' ' , (255 , 255 , 255 ), bgcolor )
137-
137+
138138class DrawStrTest (TestApp ):
139139
140140 def updateTest (self , deltaTime ):
141141 for y in range (self .height ):
142142 bgcolor = (random .getrandbits (6 ), random .getrandbits (6 ), random .getrandbits (6 ))
143143 string = [random .getrandbits (8 ) for x in range (self .width )]
144144 self .console .draw_str (0 , y , string , (255 , 255 , 255 ), bgcolor )
145-
145+
146146class BlitScrollTest (TestApp ):
147147 def updateTest (self , deltaTime ):
148148 self .console .scroll (0 , 1 )
149149 for x in range (self .width ):
150150 bgcolor = (random .getrandbits (6 ), random .getrandbits (6 ), random .getrandbits (6 ))
151151 ch = random .getrandbits (8 )
152152 self .console .draw_char (x , 0 , ch , bg = bgcolor )
153-
153+
154154# match libtcod sample screen
155155WIDTH = 46
156156HEIGHT = 20
@@ -174,4 +174,4 @@ def main():
174174 # stats.reverse_order()
175175 # stats.print_stats()
176176 # os.remove('profile.prof')
177-
177+
0 commit comments