Example #1
0
/*!
* Start a one shot timer 
* @param me Pointer to the timer
* @param act none-zero to active the timer
* @param callback Pointer to the callback function, which will be called if the timer expired
* @param data_p Pointer to user defined data, which is useful by user when implementing callback function
* @param ticks Timer alarm in ticks
*/
void TimerFireIn(Timer *me, int act, void *callback, unsigned char *data_p, unsigned int ticks)
{
	if (act)
	{
		/* Remove in case Timer is already added */
		TimerRemove(me);
		TimerAdd(me, act, callback, data_p, ticks);
	}
}
Example #2
0
/*!
* Start a periodic timer 
* @param me Pointer to the timer
* @param act none-zero to active the timer
* @param callback Pointer to the callback function, which will be called if the timer expired
* @param data_p Pointer to user defined data, which is useful by user when implementing callback function
* @param ticks Timer alarm in ticks
*/
void TimerFireEvery(Timer *me, int act, void *callback, unsigned char *data_p, unsigned int ticks)
{
	/* This is not used in current code.  In order to trigger a callback periodically 
	the user will need to rearm the timer within the callback.  */
	if (act)
	{
		TimerRemove(me);
		TimerAdd(me, act, callback, data_p, ticks);
	}
}
Example #3
0
int GroundAdd(double fromX, double fromY, double toX, double toY, int traits, int invisible)
{
	int i = 0;
	double lower;
	if (groundsEnd == MAX_GROUNDLEN) {
		ErrorPrintf(L"GroundError: Resource used up.");
		return -1;
	}
	grounds[groundsEnd].leftId = grounds[groundsEnd].rightId = -1;
	for (i = 0; i < groundsEnd; ++i) {
		if (grounds[i].fromX < toX && fromX < grounds[i].toX)
			return 1;
		else if (grounds[i].fromX == toX) {
			grounds[i].leftId = groundsEnd;
			grounds[groundsEnd].rightId = i;
		}
		else if (grounds[i].toX == fromX) {
			grounds[i].rightId = groundsEnd;
			grounds[groundsEnd].leftId = i;
		}
	}
	grounds[groundsEnd].fromX = fromX;
	grounds[groundsEnd].fromY = fromY;
	grounds[groundsEnd].toX = toX;
	grounds[groundsEnd].toY = toY;
	grounds[groundsEnd].traits = traits;
	grounds[groundsEnd].invisible = invisible;
	if (groundsMostId[0] == -1 || fromX < grounds[groundsMostId[0]].fromX)
		groundsMostId[0] = groundsEnd;
	if (groundsMostId[1] == -1 || toX > grounds[groundsMostId[1]].toX)
		groundsMostId[1] = groundsEnd;
	if (fromY > toY) lower = fromY;
	else lower = toY;
	if (groundsLowestID == -1 || grounds[groundsLowestID].fromY < lower && grounds[groundsLowestID].toY < lower)
		groundsLowestID = groundsEnd;
	grounds[groundsEnd].color = 0.0;
	grounds[groundsEnd].hasTimer = 0;
	if (!grounds[groundsEnd].invisible && gameState == STARTED) {
		grounds[groundsEnd].hasTimer = 1;
		TimerAdd(GroundVisibleTimer, groundsEnd, 20);
	}
	else if(!grounds[groundsEnd].invisible)
		grounds[groundsEnd].color = 1.0;
	grounds[groundsEnd].points.points[0][0] = fromX;	grounds[groundsEnd].points.points[0][1] = fromY + 0.5;
	grounds[groundsEnd].points.points[1][0] = fromX;	grounds[groundsEnd].points.points[1][1] = fromY;
	grounds[groundsEnd].points.points[2][0] = toX;		grounds[groundsEnd].points.points[2][1] = toY;
	grounds[groundsEnd].points.points[3][0] = toX;		grounds[groundsEnd].points.points[3][1] = toY + 0.5;
	grounds[groundsEnd].points.n = 4;
	grounds[groundsEnd].points.velocity[0] = 0.0;		grounds[groundsEnd].points.velocity[1] = 0.0;
	grounds[groundsEnd].points.usev = 1;
	DrawerAdd(GroundDrawer, groundsEnd, 6);
	CollisionAdd(GroundCollision, groundsEnd, ID_GROUND, &groundCollisionTypes, GroundCollisionNotifier);
	++groundsEnd;
	return groundsEnd;
}
Example #4
0
static void GroundVisibleTimer(int id, int ms)
{
	if (gameState != STARTED || id < 0) return;
	grounds[id].color += STEP_GROUNDVISIBLE;
	if (grounds[id].color >= 1.0) {
		grounds[id].color = 1.0;
		grounds[id].hasTimer = 0;
	}
	else
		TimerAdd(GroundVisibleTimer, id, ms + 20);
}
Example #5
0
int ErrorPrintf(wchar_t *format, ...)
{
	int ret;
	va_list args;
	va_start(args, format);
	ret = vswprintf(errorBuffer, format, args);
	va_end(args);
	TimerUpdateID(ErrorTimer, ErrorTimerUpdateID);
	TimerAdd(ErrorTimer, 0, ERROR_TIME);
	return ret;
}
Example #6
0
void StartmenuStart()
{
	static int first = 1;
	nowpos = (double)selected * itemSize.cy;
	nowvelocity = 0.0;
	if (first) {
		darking = 0;
		menuState = READY;
		first = 0;
	}
	else {
		darking = MAXDARKING;
		menuState = START;
	}
	TimerAdd(StartmenuTimer, 0, 20);
}
Example #7
0
static void GroundCollisionNotifier(int id, int othertype, int otherid, double n[2], double depth, int usev)
{
	if (othertype == ID_PLAYER) {
		if (grounds[id].invisible && grounds[id].hasTimer == 0) {
			grounds[id].invisible = 0;
			grounds[id].hasTimer = 1;
			TimerAdd(GroundVisibleTimer, id, 20);
		}
		switch (grounds[id].traits)
		{
		case GROUND_DIE:
			PlayerMinusLife(0.2 * PLAYERLIFE_MAX);
			break;
		default:
			break;
		}
	}
}
Example #8
0
static void StartmenuTimer(int id, int ms)
{
	TCHAR filename[MAX_PATH];
	double distance;
	if (gameState != NOTSTARTED || gamefilesEnd == 0) return;
	if (menuState == END) {
		if (darking >= MAXDARKING)
			EngineStart(STARTED);
		else
			++darking;
	}
	else if (menuState == START) {
		if (darking == 0)
			menuState = READY;
		else
			--darking;
	}
	else if (!commandLineFocus && KeyboardIsDown[VK_ESCAPE])
		EngineStop();
	else if (!commandLineFocus && KeyboardIsDown[VK_SPACE] || KeyboardIsDown[VK_RETURN] || KeyboardIsDown[VK_RIGHT]) {
		wcscpy(filename, GAMEFILE_DIR);
		wcscat(filename, gamefiles[selected]);
		wcscat(filename, GAMEFILE_EXTENSION);
		LoaderLoad(filename);
		menuState = END;
	}
	else {
		selected = (selected + KeyboardGetNum[VK_DOWN] - KeyboardGetNum[VK_UP]
			+ 3 * KeyboardGetNum[VK_PRIOR] - 3 * KeyboardGetNum[VK_NEXT] + 5 * gamefilesEnd) % gamefilesEnd;
		if (!commandLineFocus && KeyboardIsDown[VK_HOME]) selected = 0;
		else if (!commandLineFocus && KeyboardIsDown[VK_END]) selected = gamefilesEnd - 1;
		distance = (double)selected * itemSize.cy - nowpos;
		nowvelocity += factor1 * distance - factor2 * nowvelocity;
		nowpos += nowvelocity;
	}
	TimerAdd(StartmenuTimer, id, ms + 20);
}
Example #9
0
BaseTimeVal& BaseTimeVal::operator+=(const BaseTimeVal& other) {
  if (this != &other) {
    TimerAdd(m_tv, other.m_tv, &m_tv);
  }
  return *this;
}