⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oldd_net.c

📁 制作游戏 魔法师传奇 源代码设计 MOFASHICHUANQI 经典老游戏
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	else
	{
		skiptics -= newtics;
		newtics = 0;
	}
	
		
	netbuffer->player = consoleplayer;
	if (doomcom->drone)
		netbuffer->player |= PL_DRONE;
	
//
// drone packets
//
	if (doomcom->drone)
	{
		I_StartTic ();
		D_ProcessEvents ();
		goto sendit;
	}
	
//
// build new ticcmds for console player
//
	gameticdiv = (gametic+doomcom->ticdup-1)/doomcom->ticdup;
	for (i=0 ; i<newtics ; i++)
	{
		I_StartTic ();
		D_ProcessEvents ();
		if (maketic - gameticdiv >= BACKUPTICS/2 /* /doomcom->ticdup */- 1)
		{
			newtics = i;
			break;          // can't hold any more
		}
//printf ("mk:%i ",maketic);
		G_BuildTiccmd (&localcmds[maketic%BACKUPTICS]);
		maketic++;
	}

//
// send the packet to the other nodes
//
sendit:
	for (i=0 ; i<doomcom->numnodes ; i++)
		if (nodeingame[i])
		{
			if (doomcom->drone)
			{
				netbuffer->starttic = realstart = maketic + BACKUPTICS/2;
				netbuffer->numtics = 0;
			}
			else
			{
				netbuffer->starttic = realstart = resendto[i];
				netbuffer->numtics = maketic - realstart;
				resendto[i] = maketic - doomcom->extratics;
			}
	
			if (netbuffer->numtics > BACKUPTICS)
				I_Error ("NetUpdate: netbuffer->numtics > BACKUPTICS");

			for (j=0 ; j< netbuffer->numtics ; j++)
				netbuffer->cmds[j] = 
					localcmds[(realstart+j)%BACKUPTICS];
					
			if (remoteresend[i])
			{
				netbuffer->retransmitfrom = nettics[i]/doomcom->ticdup;
				HSendPacket (i, NCMD_RETRANSMIT);
			}
			else
			{
				netbuffer->retransmitfrom = 0;
				HSendPacket (i, 0);
			}
		}

//
// listen for other packets
//		
listen:

	GetPackets ();
}


/*
=====================
=
= CheckAbort
=
=====================
*/

void CheckAbort (void)
{
	event_t *ev;
	
	I_WaitVBL(2);
	
	I_StartTic ();
	for ( ; eventtail != eventhead 
	; eventtail = (++eventtail)&(MAXEVENTS-1) )
	{
		ev = &events[eventtail];
		if (ev->type == ev_keydown && ev->data1 == KEY_ESCAPE)
			I_Error ("Network game synchronization aborted.");
	}
}

/*
=====================
=
= D_ArbitrateNetStart
=
=====================
*/

void D_ArbitrateNetStart (void)
{
	int		i;
	boolean	gotinfo[MAXNETNODES];
	
	autostart = true;
	memset (gotinfo,0,sizeof(gotinfo));
	
	if (doomcom->consoleplayer)
	{	// listen for setup info from key player
		printf ("listening for network start info...\n");
		while (1)
		{
			CheckAbort ();
			if (!HGetPacket ())
				continue;
			if (netbuffer->checksum & NCMD_SETUP)
			{
				if (netbuffer->player != VERSION)
					I_Error ("Different DOOM versions cannot play a net game!");
				startskill = netbuffer->retransmitfrom & 15;
				deathmatch = (netbuffer->retransmitfrom & 0x80) > 0;
				nomonsters = (netbuffer->retransmitfrom & 0x40) > 0;
				respawnparm = (netbuffer->retransmitfrom & 0x20) > 0;
				startmap = netbuffer->starttic & 15;
				startepisode = netbuffer->starttic >> 4;
				return;
			}
		}
	}
	else
	{	// key player, send the setup info
		printf ("sending network start info...\n");
		do
		{
			CheckAbort ();
			for (i=0 ; i<doomcom->numnodes ; i++)
			{
				netbuffer->retransmitfrom = startskill;
				if (deathmatch)
					netbuffer->retransmitfrom |= 0x80;
				if (nomonsters)
					netbuffer->retransmitfrom |= 0x40;
				if (respawnparm)
					netbuffer->retransmitfrom |= 0x20;
				netbuffer->starttic = startepisode * 16 + startmap;
				netbuffer->player = VERSION;
				netbuffer->numtics = 0;
				HSendPacket (i, NCMD_SETUP);
			}
	
			while (HGetPacket ())
			{
				gotinfo[netbuffer->player&0x7f] = true;
			}

			for (i=1 ; i<doomcom->numnodes ; i++)
				if (!gotinfo[i])
					break;
		} while (i < doomcom->numnodes);
	}
}

/*
===================
=
= D_CheckNetGame
=
= Works out player numbers among the net participants
===================
*/

extern	int			viewangleoffset;

void D_CheckNetGame (void)
{
	int             i;
	
	for (i=0 ; i<MAXNETNODES ; i++)
	{
		nodeingame[i] = false;
       	nettics[i] = 0;
		remoteresend[i] = false;	// set when local needs tics
		resendto[i] = 0;			// which tic to start sending
	}
	
// I_InitNetwork sets doomcom and netgame
	I_InitNetwork ();
	if (doomcom->id != DOOMCOM_ID)
		I_Error ("Doomcom buffer invalid!");
	netbuffer = &doomcom->data;
	consoleplayer = displayplayer = doomcom->consoleplayer;
	if (netgame)
		D_ArbitrateNetStart ();
printf ("startskill %i  deathmatch: %i  startmap: %i  startepisode: %i\n", startskill, deathmatch, startmap, startepisode);
	
// read values out of doomcom
	ticdup = doomcom->ticdup;
					
	for (i=0 ; i<doomcom->numplayers ; i++)
		playeringame[i] = true;
	for (i=0 ; i<doomcom->numnodes ; i++)
		nodeingame[i] = true;
	
printf ("player %i of %i (%i nodes)\n", consoleplayer+1, doomcom->numplayers, doomcom->numnodes);

}

/*
==================
=
= D_QuitNetGame
=
= Called before quitting to leave a net game without hanging the
= other players
=
==================
*/

void D_QuitNetGame (void)
{
	int             i, j;
	
	if (debugfile)
		fclose (debugfile);
		
	if (!netgame || !usergame || consoleplayer == -1)
		return;
	
// send a bunch of packets for security
	netbuffer->player = consoleplayer;
	if (doomcom->drone)
		netbuffer->player |= PL_DRONE;
	netbuffer->numtics = 0;
	for (i=0 ; i<4 ; i++)
	{
		for (j=1 ; j<doomcom->numnodes ; j++)
			if (nodeingame[j])
				HSendPacket (j, NCMD_EXIT);
		I_WaitVBL (1);
	}
}



/*
===============
=
= TryRunTics
=
===============
*/

int	frametics[4], frameon;
int	frameskip[4];
int		oldnettics;
extern	boolean	advancedemo;

void TryRunTics (void)
{
	int             i;
	int             lowtic, nextlowest;
	int             entertic;
	int	static		oldentertics;
	int				realtics, availabletics;
	int				counts;
	int				numplaying;

//
// get real tics
//			
	entertic = I_GetTime ();
	realtics = entertic - oldentertics;
	oldentertics = entertic;

//
// get available tics
//
	NetUpdate ();
	
	lowtic = nextlowest = MAXINT;
	numplaying = 0;
	for (i=0 ; i<doomcom->numnodes ; i++)
		if (nodeingame[i])
		{
			numplaying++;
			if (nettics[i] < lowtic)
			{
				nextlowest = lowtic;
				lowtic = nettics[i];
			}
			else if (nettics[i] < nextlowest)
				nextlowest = nettics[i]; 
		}
	availabletics = lowtic - gametic;
	

//
// decide how many tics to run
//
	if (realtics < availabletics-1)
		counts = realtics+1;
	else if (realtics < availabletics)
		counts = realtics;
	else
		counts = availabletics;
	if (counts < 1)
		counts = 1;
		
	frameon++;
	
if (debugfile)
	fprintf (debugfile,"=======real: %i  avail: %i  game: %i\n",realtics, availabletics,counts);

//=============================================================================
//
//	ideally nettics[0] should be 1 - 3 tics above lowtic
//	if we are consistantly slower, speed up time
//	drones should never hold up the other players
//
	for (i=0 ; i<MAXPLAYERS ; i++)
		if (playeringame[i])
			break;
	if (consoleplayer == i)
	{	// the key player does not adapt
	}
	else
	{
		if (nettics[0] <= nettics[nodeforplayer[i]])
		{
			gametime--;
//			printf ("-");
		}
		frameskip[frameon&3] = (oldnettics > nettics[nodeforplayer[i]]);
		oldnettics = nettics[0];
		if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3])
		{
			skiptics = 1;
//			printf ("+");
		}
	}
//=============================================================================

//
// wait for new tics if needed
//
	while (lowtic < gametic + counts)	
	{

		NetUpdate ();   
		lowtic = MAXINT;
		
		for (i=0 ; i<doomcom->numnodes ; i++)
			if (nodeingame[i] && nettics[i] < lowtic)
				lowtic = nettics[i];

		if (lowtic < gametic)
			I_Error ("TryRunTics: lowtic < gametic");
			
		// don't stay in here forever -- give the menu a chance to work
		if (I_GetTime () - entertic >= 20)
			return;
	}
			

//
// run the tics
//	
	while (counts--)
	{
		G_Ticker ();
		NetUpdate ();					// check for new console commands
		gametic++;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -