Yep, I changed gpGlobals to NOT be a pointer, and I no longer get a runtime error. But I found out that my timer system doesn't work, what it's supposed to do is:
- Every class based from CBase(entities) has a member called m_fNextThinkTime, and whenever gpGlobals.curtime >= m_fThinkTime of that class, that class's Think( ) function is called. But I have a bug in the code and that function doesn't ever get called, I tested it using this code:
void CBaseEntity::Think( )
{
dbPositionObject( m_nModelID, m_vOrigin.x + 0.3, m_vOrigin.y, m_vOrigin.z );
SetNextThink( gpGlobals.curtime + 2.0 );
}
gpGlobals.curtime is measured in milliseconds, which I think is 0.001f in code, is this right?
gpGlobals.curtime is updated by gpGlobals.timer, here is the code for it:
timer.h:
#ifndef TIMER_H
#define TIMER_H
#include <ctime>
class CTimer {
clock_t counter;
public:
CTimer(): counter(0) {}
bool elasped(clock_t ms)
{
clock_t tick = std::clock();
if(tick - counter >= ms)
{
counter = tick;
return true;
}
return false;
}
};
#endif //TIMER_H
And here is where it's updated:
void CEntityController::Loop( )
{
if( gpGlobals.timer.elasped( 0.001 ) )
gpGlobals.curtime += 0.001;
ThinkEntities( );
}
Loop get's called every frame.
I set up a breakpoint and it seems that at 7 seconds(approx.), gpGlobals.curtime == 0.49999711, this is wierd because it should be 7.00, or atleast, that's what I want it to do.
I don't really know how to find the cause of this bug so any help would(and has been!) really appreciated.