Ticket #3010: timer.diff

File timer.diff, 1.9 KB (added by eriktorbjorn, 17 years ago)

Patch against current SVN

  • backends/timer/default/default-timer.cpp

     
    2929struct TimerSlot {
    3030        Common::TimerManager::TimerProc callback;
    3131        void *refCon;
    32         int32 interval;
    33         int32 nextFireTime;
     32        uint32 interval;        // microseconds
     33        uint32 nextFireTime;    // milliseconds
     34        uint32 microsecs;
    3435       
    3536        TimerSlot *next;
    3637};
     
    3940        // The head points to a fake anchor TimerSlot; this common
    4041        // trick allows us to get rid of many special cases.
    4142       
    42         const int32 nextFireTime = newSlot->nextFireTime;
     43        const uint32 nextFireTime = newSlot->nextFireTime;
    4344        TimerSlot *slot = head;
    4445        newSlot->next = 0;
    4546
     
    8081void DefaultTimerManager::handler() {
    8182        Common::StackLock lock(_mutex);
    8283
    83         const int32 curTime = g_system->getMillis() * 1000;
     84        const uint32 curTime = g_system->getMillis();
    8485       
    8586        // Repeat as long as there is a TimerSlot that is scheduled to fire.
    8687        TimerSlot *slot = _head->next;
     
    9293                // queue. Has to be done before the timer callback is invoked, in case
    9394                // the callback wants to remove itself.
    9495                assert(slot->interval > 0);
    95                 slot->nextFireTime += slot->interval;
     96                slot->nextFireTime += (slot->interval / 1000);
     97                slot->microsecs += (slot->interval % 1000);
     98                if (slot->microsecs > 1000) {
     99                        slot->nextFireTime++;
     100                        slot->microsecs -= 1000;
     101                }
    96102                insertPrioQueue(_head, slot);
    97103
    98104                // Invoke the timer callback
     
    108114        assert(interval > 0);
    109115        Common::StackLock lock(_mutex);
    110116       
    111        
    112117        TimerSlot *slot = new TimerSlot;
    113118        slot->callback = callback;
    114119        slot->refCon = refCon;
    115120        slot->interval = interval;
    116         slot->nextFireTime = g_system->getMillis() * 1000 + interval;
     121        slot->nextFireTime = g_system->getMillis() + interval / 1000;
     122        slot->microsecs = interval % 1000;
    117123        slot->next = 0;
    118124       
    119125        insertPrioQueue(_head, slot);