void (* timerCallback)(void);
};
+//let's try +1... nope.
static Event eventList[EVENT_LIST_SIZE];
-static uint32 nextEvent;
+static uint32_t nextEvent;
void InitializeEventList(void)
{
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
eventList[i].valid = false;
}
//We just slap the next event into the list, no checking, no nada...
void SetCallbackTime(void (* callback)(void), double time)
{
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
{
if (!eventList[i].valid)
{
}
}
- WriteLog("SetCallbackTime() failed to find an empty slot in the list!\n");
+ WriteLog("TIMING: SetCallbackTime() failed to find an empty slot in the list!\n");
}
void RemoveCallback(void (* callback)(void))
{
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
{
if (eventList[i].valid && eventList[i].timerCallback == callback)
{
void AdjustCallbackTime(void (* callback)(void), double time)
{
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
{
if (eventList[i].valid && eventList[i].timerCallback == callback)
{
double GetTimeToNextEvent(void)
{
+ // Find the next event. Since the events are not necessarily in order of
+ // increasing time, we have to search through the list for the lowest one.
+
+//ALSO: There's a bug here--nextEvent is getting a bogus value/getting clobbered...
+// Seems like it's getting clobbered somewhere other than here...
double time = 0;
bool firstTime = true;
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
{
if (eventList[i].valid)
{
if (firstTime)
- time = eventList[i].eventTime, nextEvent = i, firstTime = false;
+ {
+ time = eventList[i].eventTime;
+ nextEvent = i;
+ firstTime = false;
+ }
else
{
if (eventList[i].eventTime < time)
- time = eventList[i].eventTime, nextEvent = i;
+ {
+ time = eventList[i].eventTime;
+ nextEvent = i;
+ }
}
}
}
+ if (time == 0)
+ WriteLog("TIMING: GetTimeToNextEvent() failed to find next event!\n");
+
+ if (nextEvent >= EVENT_LIST_SIZE)
+ WriteLog("TIMING: GetTimeToNextEvent() has bad nextEvent (=%u)!\n", nextEvent);
+
return time;
}
double elapsedTime = eventList[nextEvent].eventTime;
void (* event)(void) = eventList[nextEvent].timerCallback;
- for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+ for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
if (eventList[i].valid)
eventList[i].eventTime -= elapsedTime;