// // System time handlers // // by James L. Hammons // (C) 2005 Underground Software // // JLH = James L. Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ // JLH 01/04/2006 Cosmetic changes (like this one ;-) // // STILL TO DO: // // - Handling for an event that occurs NOW // #include "timing.h" #include "log.h" #define EVENT_LIST_SIZE 512 // NOTE ABOUT TIMING SYSTEM DATA STRUCTURES: // A queue won't work for this system because we can't guarantee that an event will go // in with a time that is later than the ones already queued up. So we just use a simple // list. // Although if we used an insertion sort we could, but it wouldn't work for adjusting // times... struct Event { bool valid; double eventTime; void (* timerCallback)(void); }; //let's try +1... nope. static Event eventList[EVENT_LIST_SIZE]; static uint32_t nextEvent; void InitializeEventList(void) { for(uint32_t i=0; i= EVENT_LIST_SIZE) WriteLog("TIMING: GetTimeToNextEvent() has bad nextEvent (=%u)!\n", nextEvent); return time; } void HandleNextEvent(void) { double elapsedTime = eventList[nextEvent].eventTime; void (* event)(void) = eventList[nextEvent].timerCallback; for(uint32_t i=0; i