shithub: candycrisis

ref: 6e467c170e62f4a5fe7c9ea677cecb540c043a0d
dir: /src/gameticks.cpp/

View raw version
// gameticks.c

#include <SDL_timer.h>
#include "gameticks.h"

MTicks baseTickCount, freezeTickCount;
int freezeLevel;

MTicks MTickCount()
{
	return (unsigned int ) ((float)SDL_GetTicks() * 0.06f);
}

void InitGameTickCount( void )
{
	baseTickCount = freezeTickCount = 0;
	freezeLevel = 0;
}

void FreezeGameTickCount( void )
{
	if( freezeLevel	== 0 ) 
    {
        freezeTickCount = MTickCount( );
    }
	freezeLevel--;
}

void UnfreezeGameTickCount( void )
{
	freezeLevel++;
	if( freezeLevel >= 0 )
	{
		freezeLevel = 0;
		baseTickCount += MTickCount( ) - freezeTickCount;
	}
}

unsigned int  GameTickCount( void )
{
	if( freezeLevel < 0 )
		return freezeTickCount - baseTickCount;

	return MTickCount( ) - baseTickCount;
}