Mercurial > touhou
annotate pytouhou/ui/window.pyx @ 654:ec7e888e88f3
Up to instruction 34 validated.
author | Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com> |
---|---|
date | Thu, 08 Aug 2019 16:42:25 +0200 |
parents | 80687f258001 |
children |
rev | line source |
---|---|
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
15 cimport cython |
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
16 |
635
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
17 cimport pytouhou.lib.sdl as sdl |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
18 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
20 cdef class Clock: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
21 def __init__(self, long fps=-1): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 self._target_fps = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 self._ref_tick = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 self._ref_frame = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 self._fps_tick = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 self._fps_frame = 0 |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
27 self.fps = 0 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 self.set_target_fps(fps) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
31 cdef void set_target_fps(self, long fps) nogil: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 self._target_fps = fps |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 self._ref_tick = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 self._fps_tick = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
37 @cython.cdivision(True) |
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
38 cdef bint tick(self) nogil except True: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 current = sdl.get_ticks() |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 if not self._ref_tick: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 self._ref_tick = current |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 self._ref_frame = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 |
452
1f5156093785
By default, only enable fps limiting if vsync doesn't do the job.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
45 if self._fps_frame >= (self._target_fps if self._target_fps > 0 else 60): |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
46 self.fps = self._fps_frame * 1000. / (current - self._fps_tick) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 self._fps_tick = current |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 self._fps_frame = 0 |
452
1f5156093785
By default, only enable fps limiting if vsync doesn't do the job.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
49 # If we are relying on vsync, but vsync doesn't work or is higher |
1f5156093785
By default, only enable fps limiting if vsync doesn't do the job.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
50 # than 60 fps, limit ourselves to 60 fps. |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
51 if self._target_fps < 0 and self.fps > 64.: |
452
1f5156093785
By default, only enable fps limiting if vsync doesn't do the job.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
52 self._target_fps = 60 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 self._ref_frame += 1 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 self._fps_frame += 1 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 target_tick = self._ref_tick |
496
104c737ce8b3
Test target FPS for natural instead of non-zero.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
491
diff
changeset
|
58 if self._target_fps > 0: |
491
2276229282fd
Fix gcc’s warnings with -Wall -Wextra.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
469
diff
changeset
|
59 target_tick += <unsigned long>(self._ref_frame * 1000 / self._target_fps) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 if current <= target_tick: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 sdl.delay(target_tick - current) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 else: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 self._ref_tick = current |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 self._ref_frame = 0 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
69 cdef class Runner: |
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
70 cdef bint start(self) except True: |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
71 pass |
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
72 |
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
73 cdef bint finish(self) except True: |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
74 pass |
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
75 |
606
3c2f96f1d715
Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
596
diff
changeset
|
76 cpdef bint update(self, bint render) except -1: |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
77 return False |
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
78 |
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
79 |
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
80 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
81 cdef class Window: |
596
ab131d04987d
Fix a regression introduced in the previous commit when the interface has a different resolution than 640×480 and framebuffer_blit is enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
594
diff
changeset
|
82 def __init__(self, backend, int width=640, int height=480, long fps_limit=-1, frameskip=1): |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
552
diff
changeset
|
83 if backend is not None: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
552
diff
changeset
|
84 self.win = backend.create_window( |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
552
diff
changeset
|
85 'PyTouhou', |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
552
diff
changeset
|
86 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, |
596
ab131d04987d
Fix a regression introduced in the previous commit when the interface has a different resolution than 640×480 and framebuffer_blit is enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
594
diff
changeset
|
87 width, height, |
589
0768122da817
Add a frameskip option, and use swap interval to implement it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
88 frameskip) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 |
552
aad758aef26d
Don’t store framerate limit in the Window while it already is in the Clock.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
533
diff
changeset
|
90 self.clock = Clock(fps_limit) |
589
0768122da817
Add a frameskip option, and use swap interval to implement it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
91 self.frame = 0 |
0768122da817
Add a frameskip option, and use swap interval to implement it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
92 self.frameskip = frameskip |
596
ab131d04987d
Fix a regression introduced in the previous commit when the interface has a different resolution than 640×480 and framebuffer_blit is enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
594
diff
changeset
|
93 self.width = width |
ab131d04987d
Fix a regression introduced in the previous commit when the interface has a different resolution than 640×480 and framebuffer_blit is enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
594
diff
changeset
|
94 self.height = height |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
97 cdef void set_size(self, int width, int height) nogil: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 self.win.set_window_size(width, height) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
101 cpdef set_runner(self, Runner runner=None): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 self.runner = runner |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
103 if runner is not None: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
104 runner.start() |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
107 cpdef run(self): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 try: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 while self.run_frame(): |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 pass |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 finally: |
588
7a82c4b52b16
Prevent a traceback when we call Window.run without a runner set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
578
diff
changeset
|
112 if self.runner is not None: |
7a82c4b52b16
Prevent a traceback when we call Window.run without a runner set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
578
diff
changeset
|
113 self.runner.finish() |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 |
594
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
116 @cython.cdivision(True) |
606
3c2f96f1d715
Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
596
diff
changeset
|
117 cdef bint run_frame(self) except -1: |
594
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
118 cdef bint render = (self.win is not None and |
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
119 (self.frameskip <= 1 or not self.frame % self.frameskip)) |
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
120 |
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
121 running = False |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
122 if self.runner is not None: |
594
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
123 running = self.runner.update(render) |
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
124 if render: |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
552
diff
changeset
|
125 self.win.present() |
594
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
126 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 self.clock.tick() |
589
0768122da817
Add a frameskip option, and use swap interval to implement it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
128 self.frame += 1 |
594
12756994a92c
Make frameskip actually skip the rendering part, not just the buffer swap.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
589
diff
changeset
|
129 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 return running |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
460
diff
changeset
|
133 cdef double get_fps(self) nogil: |
533
de778a80820a
Optimise Clock a bit more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
134 return self.clock.fps |
635
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
135 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
136 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
137 cdef list get_events(self): |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
138 return self.win.get_events() |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
139 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
140 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
141 cdef int get_keystate(self) nogil: |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
142 return self.win.get_keystate() |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
143 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
144 |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
145 cdef void toggle_fullscreen(self) nogil: |
80687f258001
Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
146 self.win.toggle_fullscreen() |