Exemple #1
0
static void snd_callback(void *userdata, Uint8 * stream, int len)
{
	static int lasttime;
	static float lastfreq;
	int i;

	swsndupdate();

	// lasttime stores the time offset from the last call
	// we save the time so that the multiple time slices
	// all fit together smoothly

	// if we have changed frequency since last time, we need
	// to adjust lasttime to the new frequency

	lasttime *= (int)(lastfreq / current_freq);

	for (i = 0; i < len; ++i) {
		if (speaker_on) {
			stream[i] =
			    127 * (int)square_wave(current_freq *
					      (i + lasttime));
		} else {
			stream[i] = 0;
		}
	}

	lasttime += len;
	lastfreq = current_freq;
}
Exemple #2
0
int swgetc()
{
	int i;

	while(!(i = Vid_GetKey())) {

		// sdh 15/11/2001: dont thrash the processor while 
		// waiting for a key press

		Timer_Sleep(100);

		swsndupdate();
		if (ctlbreak())
			break;
	}

	return i;
}
Exemple #3
0
int swmain(int argc, char *argv[])
{
	int nexttic;

	nobjects = (OBJECTS *) malloc(100 * sizeof(OBJECTS));

	swinit(argc, argv);
	setjmp(envrestart);

	// sdh 28/10/2001: playmode is called from here now
	// makes for a more coherent progression through the setup process

	if (!playmode)
		getgamemode();
	swinitlevel();

	nexttic = Timer_GetMS();
        skip_time = 0;

	for (;;) {
                int nowtime;

		/* generate a new move command periodically
		 * and send to other players if neccessary */

                nowtime = Timer_GetMS();

		if (nowtime > nexttic
		 && latest_player_time[player] - countmove < MAX_NET_LAG) {

			new_move();

                        /* Be accurate (exact amount between tics);
                         * However, if a large spike occurs between tics,
                         * catch up immediately.
                         */

                        if (nowtime - nexttic > 1000)
                                nexttic = nowtime + (1000/FPS);
                        else
			        nexttic += (1000 / FPS);

                        // wait a bit longer to compensate for lag

                        nexttic += skip_time;
                        skip_time = 0;
		}

		asynupdate();
		swsndupdate();

		/* if we have all the tic commands we need, we can move */

		if (can_move()) {
                        calculate_lag();
			//dump_cmds();
			swmove();
			swdisp();
			swcollsn();
			swsound();
		}

		// sdh 15/11/2001: dont thrash the 
		// processor while waiting
		Timer_Sleep(10);
	}

	return 0;
}