273
clock_get_fps (PyObject* self)
274
clock_get_fps (PyObject* self, PyObject* args)
275
276
PyClockObject* _clock = (PyClockObject*) self;
276
277
return PyFloat_FromDouble (_clock->fps);
297
298
{ "tick", clock_tick, METH_VARARGS, DOC_CLOCKTICK },
298
299
{ "get_fps", (PyCFunction) clock_get_fps, METH_NOARGS, DOC_CLOCKGETFPS },
299
{ "get_time", (PyCFunction) clock_get_time, METH_NOARGS, DOC_CLOCKGETTIME },
300
{ "get_time", (PyCFunction) clock_get_time, METH_NOARGS,
300
302
{ "get_rawtime", (PyCFunction) clock_get_rawtime, METH_NOARGS,
301
303
DOC_CLOCKGETRAWTIME },
302
304
{ "tick_busy_loop", clock_tick_busy_loop, METH_VARARGS,
312
314
PyObject_DEL (self);
316
clock_getattr (PyObject *self, char *name)
318
return Py_FindMethod (clock_methods, self, name);
322
318
clock_str (PyObject* self)
327
323
sprintf (str, "<Clock(fps=%.2f)>", (float) _clock->fps);
329
return PyString_FromString (str);
325
return Text_FromUTF8 (str);
332
328
static PyTypeObject PyClock_Type =
334
PyObject_HEAD_INIT(NULL)
337
sizeof(PyClockObject), /*basic size*/
339
clock_dealloc, /*dealloc*/
341
clock_getattr, /*getattr*/
346
NULL, /*as_sequence*/
348
(hashfunc)NULL, /*hash*/
349
(ternaryfunc)NULL, /*call*/
351
/* Space for future expansion */
353
DOC_PYGAMETIMECLOCK /* Documentation string */
332
sizeof(PyClockObject), /* basic size */
334
clock_dealloc, /* dealloc */
339
clock_str, /* repr */
343
(hashfunc)0, /* hash */
344
(ternaryfunc)0, /* call */
348
0, /* tp_as_buffer */
350
DOC_PYGAMETIMECLOCK, /* Documentation string */
353
0, /* tp_richcompare */
354
0, /* tp_weaklistoffset */
357
clock_methods, /* tp_methods */
362
0, /* tp_descr_get */
363
0, /* tp_descr_set */
364
0, /* tp_dictoffset */
357
371
ClockInit (PyObject* self)
359
PyClockObject* _clock;
361
_clock = PyObject_NEW (PyClockObject, &PyClock_Type);
373
PyClockObject* _clock = PyObject_NEW (PyClockObject, &PyClock_Type);
365
379
/*just doublecheck that timer is initialized*/
366
380
if (!SDL_WasInit (SDL_INIT_TIMER))
378
392
return (PyObject*) _clock;
381
static PyMethodDef time_builtins[] =
395
static PyMethodDef _time_methods[] =
383
397
{ "get_ticks", (PyCFunction) time_get_ticks, METH_NOARGS,
384
398
DOC_PYGAMETIMEGETTICKS },
391
405
{ NULL, NULL, 0, NULL }
410
void initpygame_time (void)
412
MODINIT_DEFINE (time)
397
415
PyObject *module;
399
PyType_Init (PyClock_Type);
418
static struct PyModuleDef _module = {
419
PyModuleDef_HEAD_INIT,
424
NULL, NULL, NULL, NULL
428
/* need to import base module, just so SDL is happy. Do this first so if
429
the module is there is an error the module is not loaded.
431
import_pygame_base ();
432
if (PyErr_Occurred ()) {
436
/* type preparation */
437
if (PyType_Ready (&PyClock_Type) < 0) {
401
441
/* create the module */
402
module = Py_InitModule3 ("time", time_builtins, DOC_PYGAMETIME);
404
/*need to import base module, just so SDL is happy*/
405
import_pygame_base ();
443
module = PyModule_Create (&_module);
445
module = Py_InitModule3 (MODPREFIX "time", _time_methods, DOC_PYGAMETIME);
447
MODINIT_RETURN (module);