示例#1
0
文件: game.c 项目: HerbFargus/xrick
/*
 * Main loop
 */
void
game_run(void)
{
  U32 tm, tmx;

	loaddata(); /* load cached data */

	game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD;
	tm = sys_gettime();
	game_state = XRICK;

	/* main loop */
	while (game_state != EXIT) {

		/* timer */
		tmx = tm; tm = sys_gettime(); tmx = tm - tmx;
		if (tmx < game_period) sys_sleep(game_period - tmx);

		/* video */
		/*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/
		sysvid_update(game_rects);
		draw_STATUSRECT.next = NULL;  /* FIXME freerects should handle this */

		/* sound */
		/*snd_mix();*/

		/* events */
		if (game_waitevt)
			sysevt_wait();  /* wait for an event */
		else
			sysevt_poll();  /* process events (non-blocking) */

		/* frame */
		frame();
	}

	freedata(); /* free cached data */
}
示例#2
0
文件: game.c 项目: uli/xrick-spmp8000
/*
 * Main loop
 */
void
game_run(void)
{
  U32 tm;
#if 0
  U32 tmx;
#endif

	loaddata(); /* load cached data */

	game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD;
	tm = sys_gettime();
	game_state = XRICK;

	/* main loop */
	while (game_state != EXIT) {

#if 0
		/* This code doesn't make any sense to me at all. It waits
		   until the desired amount of time has passed and then
		   takes the time at which it started waiting (which is
		   not synchronous with anything) as the reference point
		   for the next frame. This sort of works if your system
		   takes very little time to compute the frame, but fails
		   horribly otherwise, e.g. if you use blocking I/O
		   (sound, vblank). */
		tmx = tm; tm = sys_gettime(); tmx = tm - tmx;
		if (tmx < game_period) sys_sleep(game_period - tmx);
#endif

		/* video */
		/*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/
		sysvid_update(game_rects);
		draw_STATUSRECT.next = NULL;  /* FIXME freerects should handle this */

		/* timer */
		/* Reset the timing if it's way out of line, such as when
		   the game thread has been paused. */
		if (sys_gettime() - tm > game_period * 10)
			tm = sys_gettime() - game_period / 2;
		/* Update sound while waiting. */
		do {
			syssnd_callback();
		} while (sys_gettime() - tm < game_period / 2);
		/* Use the time at which the frame should have been complete as
		   reference for the next frame. This makes it possible to
		   "catch up" if a frame has taken longer for some reason. */
		tm = tm + game_period / 2;

		/* sound */
		/*snd_mix();*/

		/* events */
		if (game_waitevt)
			sysevt_wait();  /* wait for an event */
		else
			sysevt_poll();  /* process events (non-blocking) */

		/* frame */
		frame();
	}

	freedata(); /* free cached data */
}