Mercurial > pygame
annotate src/time.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 165722bbba38 |
| children | 9fcb7abf3185 |
| rev | line source |
|---|---|
| 7 | 1 /* |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
2 pygame - Python Game Library |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
3 Copyright (C) 2000-2001 Pete Shinners |
| 7 | 4 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
| 7 | 9 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
13 Library General Public License for more details. |
| 7 | 14 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 7 | 18 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
19 Pete Shinners |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
20 pete@shinners.org |
| 7 | 21 */ |
| 22 | |
| 23 #include "pygame.h" | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
24 #include "pgcompat.h" |
| 1937 | 25 #include "doc/time_doc.h" |
| 7 | 26 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
27 #define WORST_CLOCK_ACCURACY 12 |
| 23 | 28 static SDL_TimerID event_timers[SDL_NUMEVENTS] = {NULL}; |
| 29 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
30 static Uint32 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
31 timer_callback (Uint32 interval, void* param) |
| 15 | 32 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
33 if (SDL_WasInit (SDL_INIT_VIDEO)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
34 { |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
35 SDL_Event event; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
36 memset (&event, 0, sizeof (event)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
37 event.type = (intptr_t) param; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
38 SDL_PushEvent (&event); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
39 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
40 return interval; |
| 15 | 41 } |
| 42 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
43 static int |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
44 accurate_delay (int ticks) |
| 277 | 45 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
46 int funcstart, delay; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
47 if (ticks <= 0) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
48 return 0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
49 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
50 if (!SDL_WasInit (SDL_INIT_TIMER)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
51 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
52 if (SDL_InitSubSystem (SDL_INIT_TIMER)) |
| 277 | 53 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
54 RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
55 return -1; |
| 277 | 56 } |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
57 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
58 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
59 funcstart = SDL_GetTicks (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
60 if (ticks >= WORST_CLOCK_ACCURACY) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
61 { |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
62 delay = (ticks - 2) - (ticks % WORST_CLOCK_ACCURACY); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
63 if (delay >= WORST_CLOCK_ACCURACY) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
64 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
65 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
66 SDL_Delay (delay); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
67 Py_END_ALLOW_THREADS; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
68 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
69 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
70 do |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
71 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
72 delay = ticks - (SDL_GetTicks () - funcstart); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
73 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
74 while (delay > 0); |
| 277 | 75 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
76 return SDL_GetTicks () - funcstart; |
| 277 | 77 } |
| 15 | 78 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
79 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
80 time_get_ticks (PyObject* self) |
| 7 | 81 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
82 if (!SDL_WasInit (SDL_INIT_TIMER)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
83 return PyInt_FromLong (0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
84 return PyInt_FromLong (SDL_GetTicks ()); |
| 7 | 85 } |
| 86 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
87 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
88 time_delay (PyObject* self, PyObject* arg) |
| 7 | 89 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
90 int ticks; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
91 PyObject* arg0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
92 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
93 /*for some reason PyArg_ParseTuple is puking on -1's! BLARG!*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
94 if (PyTuple_Size (arg) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
95 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
96 "delay requires one integer argument"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
97 arg0 = PyTuple_GET_ITEM (arg, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
98 if (!PyInt_Check (arg0)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
99 return RAISE (PyExc_TypeError, "delay requires one integer argument"); |
| 106 | 100 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
101 ticks = PyInt_AsLong (arg0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
102 if (ticks < 0) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
103 ticks = 0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
104 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
105 ticks = accurate_delay (ticks); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
106 if (ticks == -1) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
107 return NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
108 return PyInt_FromLong (ticks); |
| 277 | 109 } |
| 110 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
111 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
112 time_wait (PyObject* self, PyObject* arg) |
| 277 | 113 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
114 int ticks, start; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
115 PyObject* arg0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
116 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
117 /*for some reason PyArg_ParseTuple is puking on -1's! BLARG!*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
118 if (PyTuple_Size (arg) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
119 return RAISE (PyExc_ValueError, "delay requires one integer argument"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
120 arg0 = PyTuple_GET_ITEM (arg, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
121 if (!PyInt_Check (arg0)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
122 return RAISE (PyExc_TypeError, "delay requires one integer argument"); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
123 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
124 if (!SDL_WasInit (SDL_INIT_TIMER)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
125 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
126 if (SDL_InitSubSystem (SDL_INIT_TIMER)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
127 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
128 RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
129 return NULL; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
130 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
131 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
132 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
133 ticks = PyInt_AsLong (arg0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
134 if (ticks < 0) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
135 ticks = 0; |
| 277 | 136 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
137 start = SDL_GetTicks (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
138 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
139 SDL_Delay (ticks); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
140 Py_END_ALLOW_THREADS; |
| 277 | 141 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
142 return PyInt_FromLong (SDL_GetTicks () - start); |
| 15 | 143 } |
| 144 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
145 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
146 time_set_timer (PyObject* self, PyObject* arg) |
| 15 | 147 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
148 SDL_TimerID newtimer; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
149 int ticks = 0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
150 intptr_t event = SDL_NOEVENT; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
151 if (!PyArg_ParseTuple (arg, "ii", &event, &ticks)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
152 return NULL; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
153 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
154 if (event <= SDL_NOEVENT || event >= SDL_NUMEVENTS) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
155 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
156 "Event id must be between NOEVENT(0) and NUMEVENTS(32)"); |
| 23 | 157 |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
158 /*stop original timer*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
159 if (event_timers[event]) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
160 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
161 SDL_RemoveTimer (event_timers[event]); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
162 event_timers[event] = NULL; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
163 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
164 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
165 if (ticks <= 0) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
166 Py_RETURN_NONE; |
| 15 | 167 |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
168 /*just doublecheck that timer is initialized*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
169 if (!SDL_WasInit (SDL_INIT_TIMER)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
170 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
171 if (SDL_InitSubSystem (SDL_INIT_TIMER)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
172 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
173 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
174 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
175 newtimer = SDL_AddTimer (ticks, timer_callback, (void*) event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
176 if (!newtimer) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
177 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
178 event_timers[event] = newtimer; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
179 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
180 Py_RETURN_NONE; |
| 7 | 181 } |
| 182 | |
| 277 | 183 /*clock object interface*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
184 typedef struct |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
185 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
186 PyObject_HEAD |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
187 int last_tick; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
188 int fps_count, fps_tick; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
189 float fps; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
190 int timepassed, rawpassed; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
191 PyObject* rendered; |
| 277 | 192 } PyClockObject; |
| 193 | |
|
659
b0ba4d2579f0
Changed the behaviour of Clock.tick to use SDL_Delay instead of a busy loop. Added a tick_busy_loop which uses the old behaviour. This is more consistent with what people think Clock.tick() will do. That is not use up lots of cpu.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
194 // to be called by the other tick functions. |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
195 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
196 clock_tick_base(PyObject* self, PyObject* arg, int use_accurate_delay) |
| 277 | 197 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
198 PyClockObject* _clock = (PyClockObject*) self; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
199 float framerate = 0.0f; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
200 int nowtime; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
201 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
202 if (!PyArg_ParseTuple (arg, "|f", &framerate)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
203 return NULL; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
204 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
205 if (framerate) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
206 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
207 int delay, endtime = (int) ((1.0f / framerate) * 1000.0f); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
208 _clock->rawpassed = SDL_GetTicks () - _clock->last_tick; |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
209 delay = endtime - _clock->rawpassed; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
210 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
211 /*just doublecheck that timer is initialized*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
212 if (!SDL_WasInit (SDL_INIT_TIMER)) |
| 277 | 213 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
214 if (SDL_InitSubSystem (SDL_INIT_TIMER)) |
|
659
b0ba4d2579f0
Changed the behaviour of Clock.tick to use SDL_Delay instead of a busy loop. Added a tick_busy_loop which uses the old behaviour. This is more consistent with what people think Clock.tick() will do. That is not use up lots of cpu.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
215 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
216 RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
217 return NULL; |
|
659
b0ba4d2579f0
Changed the behaviour of Clock.tick to use SDL_Delay instead of a busy loop. Added a tick_busy_loop which uses the old behaviour. This is more consistent with what people think Clock.tick() will do. That is not use up lots of cpu.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
218 } |
| 277 | 219 } |
| 398 | 220 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
221 if (use_accurate_delay) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
222 delay = accurate_delay (delay); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
223 else |
| 277 | 224 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
225 // this uses sdls delay, which can be inaccurate. |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
226 if (delay < 0) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
227 delay = 0; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
228 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
229 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
230 SDL_Delay ((Uint32) delay); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
231 Py_END_ALLOW_THREADS; |
| 277 | 232 } |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
233 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
234 if (delay == -1) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
235 return NULL; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
236 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
237 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
238 nowtime = SDL_GetTicks (); |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
239 _clock->timepassed = nowtime - _clock->last_tick; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
240 _clock->fps_count += 1; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
241 _clock->last_tick = nowtime; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
242 if (!framerate) |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
243 _clock->rawpassed = _clock->timepassed; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
244 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
245 if (!_clock->fps_tick) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
246 { |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
247 _clock->fps_count = 0; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
248 _clock->fps_tick = nowtime; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
249 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
250 else if (_clock->fps_count >= 10) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
251 { |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
252 _clock->fps = _clock->fps_count / |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
253 ((nowtime - _clock->fps_tick) / 1000.0f); |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
254 _clock->fps_count = 0; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
255 _clock->fps_tick = nowtime; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
256 Py_XDECREF (_clock->rendered); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
257 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
258 return PyInt_FromLong (_clock->timepassed); |
|
659
b0ba4d2579f0
Changed the behaviour of Clock.tick to use SDL_Delay instead of a busy loop. Added a tick_busy_loop which uses the old behaviour. This is more consistent with what people think Clock.tick() will do. That is not use up lots of cpu.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
259 } |
|
b0ba4d2579f0
Changed the behaviour of Clock.tick to use SDL_Delay instead of a busy loop. Added a tick_busy_loop which uses the old behaviour. This is more consistent with what people think Clock.tick() will do. That is not use up lots of cpu.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
260 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
261 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
262 clock_tick (PyObject* self, PyObject* arg) |
| 277 | 263 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
264 return clock_tick_base (self, arg, 0); |
| 277 | 265 } |
| 266 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
267 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
268 clock_tick_busy_loop (PyObject* self, PyObject* arg) |
| 398 | 269 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
270 return clock_tick_base (self, arg, 1); |
| 398 | 271 } |
| 272 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
273 static PyObject* |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
274 clock_get_fps (PyObject* self, PyObject* args) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
275 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
276 PyClockObject* _clock = (PyClockObject*) self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
277 return PyFloat_FromDouble (_clock->fps); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
278 } |
| 277 | 279 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
280 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
281 clock_get_time (PyObject* self) |
| 277 | 282 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
283 PyClockObject* _clock = (PyClockObject*) self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
284 return PyInt_FromLong (_clock->timepassed); |
| 277 | 285 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
286 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
287 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
288 clock_get_rawtime (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
289 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
290 PyClockObject* _clock = (PyClockObject*) self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
291 return PyInt_FromLong (_clock->rawpassed); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
292 } |
| 277 | 293 |
| 294 /* clock object internals */ | |
| 295 | |
| 296 static struct PyMethodDef clock_methods[] = | |
| 297 { | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
298 { "tick", clock_tick, METH_VARARGS, DOC_CLOCKTICK }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
299 { "get_fps", (PyCFunction) clock_get_fps, METH_NOARGS, DOC_CLOCKGETFPS }, |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
300 { "get_time", (PyCFunction) clock_get_time, METH_NOARGS, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
301 DOC_CLOCKGETTIME }, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
302 { "get_rawtime", (PyCFunction) clock_get_rawtime, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
303 DOC_CLOCKGETRAWTIME }, |
|
1038
2fab82895a31
Fixed numerous doc comments. Removed wrong Rect.clip_ip() entry.
marcus
parents:
831
diff
changeset
|
304 { "tick_busy_loop", clock_tick_busy_loop, METH_VARARGS, |
| 1039 | 305 DOC_CLOCKTICKBUSYLOOP }, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
306 { NULL, NULL, 0, NULL} |
| 277 | 307 }; |
| 308 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
309 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
310 clock_dealloc (PyObject* self) |
| 277 | 311 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
312 PyClockObject* _clock = (PyClockObject*) self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
313 Py_XDECREF (_clock->rendered); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
314 PyObject_DEL (self); |
| 277 | 315 } |
| 316 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
317 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
318 clock_str (PyObject* self) |
| 277 | 319 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
320 char str[1024]; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
321 PyClockObject* _clock = (PyClockObject*) self; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
322 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
323 sprintf (str, "<Clock(fps=%.2f)>", (float) _clock->fps); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
324 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
325 return Text_FromUTF8 (str); |
| 277 | 326 } |
| 327 | |
| 328 static PyTypeObject PyClock_Type = | |
| 329 { | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
330 TYPE_HEAD (NULL, 0) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
331 "Clock", /* name */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
332 sizeof(PyClockObject), /* basic size */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
333 0, /* itemsize */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
334 clock_dealloc, /* dealloc */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
335 0, /* print */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
336 0, /* getattr */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
337 0, /* setattr */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
338 0, /* compare */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
339 clock_str, /* repr */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
340 0, /* as_number */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
341 0, /* as_sequence */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
342 0, /* as_mapping */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
343 (hashfunc)0, /* hash */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
344 (ternaryfunc)0, /* call */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
345 clock_str, /* str */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
346 0, /* tp_getattro */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
347 0, /* tp_setattro */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
348 0, /* tp_as_buffer */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
349 0, /* flags */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
350 DOC_PYGAMETIMECLOCK, /* Documentation string */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
351 0, /* tp_traverse */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
352 0, /* tp_clear */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
353 0, /* tp_richcompare */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
354 0, /* tp_weaklistoffset */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
355 0, /* tp_iter */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
356 0, /* tp_iternext */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
357 clock_methods, /* tp_methods */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
358 0, /* tp_members */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
359 0, /* tp_getset */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
360 0, /* tp_base */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
361 0, /* tp_dict */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
362 0, /* tp_descr_get */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
363 0, /* tp_descr_set */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
364 0, /* tp_dictoffset */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
365 0, /* tp_init */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
366 0, /* tp_alloc */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
367 0, /* tp_new */ |
| 277 | 368 }; |
| 369 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
370 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
371 ClockInit (PyObject* self) |
| 277 | 372 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
373 PyClockObject* _clock = PyObject_NEW (PyClockObject, &PyClock_Type); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
374 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
375 if (!_clock) { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
376 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
377 } |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
378 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
379 /*just doublecheck that timer is initialized*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
380 if (!SDL_WasInit (SDL_INIT_TIMER)) |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
381 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
382 if (SDL_InitSubSystem (SDL_INIT_TIMER)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
383 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
384 } |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
385 |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
386 _clock->fps_tick = 0; |
|
2224
165722bbba38
initialise timepassed and rawpassed to 0 in time.c
Rene Dudfield <renesd@gmail.com>
parents:
1937
diff
changeset
|
387 _clock->timepassed = 0; |
|
165722bbba38
initialise timepassed and rawpassed to 0 in time.c
Rene Dudfield <renesd@gmail.com>
parents:
1937
diff
changeset
|
388 _clock->rawpassed = 0; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
389 _clock->last_tick = SDL_GetTicks (); |
|
816
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
390 _clock->fps = 0.0f; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
391 _clock->fps_count = 0; |
|
612f754cf170
From Marcus: Fixes lots of warnings... mostly redeclarations.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
392 _clock->rendered = NULL; |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
393 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
394 return (PyObject*) _clock; |
| 277 | 395 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
396 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
397 static PyMethodDef _time_methods[] = |
| 7 | 398 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
399 { "get_ticks", (PyCFunction) time_get_ticks, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
400 DOC_PYGAMETIMEGETTICKS }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
401 { "delay", time_delay, METH_VARARGS, DOC_PYGAMETIMEDELAY }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
402 { "wait", time_wait, METH_VARARGS, DOC_PYGAMETIMEWAIT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
403 { "set_timer", time_set_timer, METH_VARARGS, DOC_PYGAMETIMESETTIMER }, |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
404 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
816
diff
changeset
|
405 { "Clock", (PyCFunction) ClockInit, METH_NOARGS, DOC_PYGAMETIMECLOCK }, |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
406 |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
407 { NULL, NULL, 0, NULL } |
| 7 | 408 }; |
| 409 | |
| 1584 | 410 #ifdef __SYMBIAN32__ |
| 411 PYGAME_EXPORT | |
| 412 void initpygame_time (void) | |
| 413 #else | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
414 MODINIT_DEFINE (time) |
| 1584 | 415 #endif |
| 7 | 416 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
417 PyObject *module; |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
418 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
419 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
420 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
421 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
422 "time", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
423 DOC_PYGAMETIME, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
424 -1, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
425 _time_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
426 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
427 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
428 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
429 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
430 /* need to import base module, just so SDL is happy. Do this first so if |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
431 the module is there is an error the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
432 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
433 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
434 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1584
diff
changeset
|
435 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
436 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
437 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1039
diff
changeset
|
438 /* type preparation */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
439 if (PyType_Ready (&PyClock_Type) < 0) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
440 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
441 } |
| 277 | 442 |
| 7 | 443 /* create the module */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
444 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
445 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
446 #else |
| 1584 | 447 module = Py_InitModule3 (MODPREFIX "time", _time_methods, DOC_PYGAMETIME); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
448 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
449 MODINIT_RETURN (module); |
| 7 | 450 } |
