~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to src/time.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "pygame.h"
 
24
#include "pgcompat.h"
24
25
#include "pygamedocs.h"
25
26
 
26
27
#define WORST_CLOCK_ACCURACY 12
270
271
}
271
272
 
272
273
static PyObject*
273
 
clock_get_fps (PyObject* self)
 
274
clock_get_fps (PyObject* self, PyObject* args)
274
275
{
275
276
    PyClockObject* _clock = (PyClockObject*) self;
276
277
    return PyFloat_FromDouble (_clock->fps);
296
297
{
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,
 
301
      DOC_CLOCKGETTIME },
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);        
313
315
}
314
316
 
315
 
static PyObject*
316
 
clock_getattr (PyObject *self, char *name)
317
 
{
318
 
    return Py_FindMethod (clock_methods, self, name);
319
 
}
320
 
 
321
317
PyObject*
322
318
clock_str (PyObject* self)
323
319
{
326
322
    
327
323
    sprintf (str, "<Clock(fps=%.2f)>", (float) _clock->fps);
328
324
    
329
 
    return PyString_FromString (str);
 
325
    return Text_FromUTF8 (str);
330
326
}
331
327
 
332
328
static PyTypeObject PyClock_Type =
333
329
{
334
 
    PyObject_HEAD_INIT(NULL)
335
 
    0,                          /*size*/
336
 
    "Clock",                    /*name*/
337
 
    sizeof(PyClockObject),          /*basic size*/
338
 
    0,                          /*itemsize*/
339
 
    clock_dealloc,                      /*dealloc*/
340
 
    0,                          /*print*/
341
 
    clock_getattr,                      /*getattr*/
342
 
    NULL,                               /*setattr*/
343
 
    NULL,                               /*compare*/
344
 
    clock_str,                  /*repr*/
345
 
    NULL,                               /*as_number*/
346
 
    NULL,                               /*as_sequence*/
347
 
    NULL,                               /*as_mapping*/
348
 
    (hashfunc)NULL,             /*hash*/
349
 
    (ternaryfunc)NULL,          /*call*/
350
 
    clock_str,                  /*str*/
351
 
    /* Space for future expansion */
352
 
    0L,0L,0L,0L,
353
 
    DOC_PYGAMETIMECLOCK /* Documentation string */
 
330
    TYPE_HEAD (NULL, 0)
 
331
    "Clock",                    /* name */
 
332
    sizeof(PyClockObject),      /* basic size */
 
333
    0,                          /* itemsize */
 
334
    clock_dealloc,              /* dealloc */
 
335
    0,                          /* print */
 
336
    0,                          /* getattr */
 
337
    0,                          /* setattr */
 
338
    0,                          /* compare */
 
339
    clock_str,                  /* repr */
 
340
    0,                          /* as_number */
 
341
    0,                          /* as_sequence */
 
342
    0,                          /* as_mapping */
 
343
    (hashfunc)0,                /* hash */
 
344
    (ternaryfunc)0,             /* call */
 
345
    clock_str,                  /* str */
 
346
    0,                          /* tp_getattro */
 
347
    0,                          /* tp_setattro */
 
348
    0,                          /* tp_as_buffer */
 
349
    0,                          /* flags */
 
350
    DOC_PYGAMETIMECLOCK,        /* Documentation string */
 
351
    0,                          /* tp_traverse */
 
352
    0,                          /* tp_clear */
 
353
    0,                          /* tp_richcompare */
 
354
    0,                          /* tp_weaklistoffset */
 
355
    0,                          /* tp_iter */
 
356
    0,                          /* tp_iternext */
 
357
    clock_methods,              /* tp_methods */
 
358
    0,                          /* tp_members */
 
359
    0,                          /* tp_getset */
 
360
    0,                          /* tp_base */
 
361
    0,                          /* tp_dict */
 
362
    0,                          /* tp_descr_get */
 
363
    0,                          /* tp_descr_set */
 
364
    0,                          /* tp_dictoffset */
 
365
    0,                          /* tp_init */
 
366
    0,                          /* tp_alloc */
 
367
    0,                          /* tp_new */
354
368
};
355
369
 
356
370
PyObject*
357
371
ClockInit (PyObject* self)
358
372
{
359
 
    PyClockObject* _clock;
360
 
    
361
 
    _clock = PyObject_NEW (PyClockObject, &PyClock_Type);
362
 
    if (!_clock)
 
373
    PyClockObject* _clock = PyObject_NEW (PyClockObject, &PyClock_Type);
 
374
 
 
375
    if (!_clock) {
363
376
        return NULL;
 
377
    }
364
378
    
365
379
    /*just doublecheck that timer is initialized*/
366
380
    if (!SDL_WasInit (SDL_INIT_TIMER))
378
392
    return (PyObject*) _clock;
379
393
}
380
394
 
381
 
static PyMethodDef time_builtins[] =
 
395
static PyMethodDef _time_methods[] =
382
396
{
383
397
    { "get_ticks", (PyCFunction) time_get_ticks, METH_NOARGS,
384
398
      DOC_PYGAMETIMEGETTICKS },
391
405
    { NULL, NULL, 0, NULL }
392
406
};
393
407
 
 
408
#ifdef __SYMBIAN32__
394
409
PYGAME_EXPORT
395
 
void inittime (void)
 
410
void initpygame_time (void)
 
411
#else
 
412
MODINIT_DEFINE (time)
 
413
#endif    
396
414
{
397
415
    PyObject *module;
398
416
    
399
 
    PyType_Init (PyClock_Type);
 
417
#if PY3
 
418
    static struct PyModuleDef _module = {
 
419
        PyModuleDef_HEAD_INIT,
 
420
        "time",
 
421
        DOC_PYGAMETIME,
 
422
        -1,
 
423
        _time_methods,
 
424
        NULL, NULL, NULL, NULL
 
425
    };
 
426
#endif
 
427
 
 
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.
 
430
    */
 
431
    import_pygame_base ();
 
432
    if (PyErr_Occurred ()) {
 
433
        MODINIT_ERROR;
 
434
    }
 
435
 
 
436
    /* type preparation */
 
437
    if (PyType_Ready (&PyClock_Type) < 0) {
 
438
        MODINIT_ERROR;
 
439
    }
400
440
    
401
441
    /* create the module */
402
 
    module = Py_InitModule3 ("time", time_builtins, DOC_PYGAMETIME);
403
 
    
404
 
    /*need to import base module, just so SDL is happy*/
405
 
    import_pygame_base ();
 
442
#if PY3
 
443
    module = PyModule_Create (&_module);
 
444
#else
 
445
    module = Py_InitModule3 (MODPREFIX "time", _time_methods, DOC_PYGAMETIME);
 
446
#endif
 
447
    MODINIT_RETURN (module);
406
448
}