예제 #1
0
/*
=================
CL_CreateNewCommands

Create a new usercmd_t structure for this frame
=================
*/
void CL_CreateNewCommands( void ) {
	//usercmd_t	*cmd;
	int			cmdNum;

	// no need to create usercmds until we have a gamestate
	if ( cls.state < CA_PRIMED ) {
		return;
	}

	frame_msec = com_frameTime - old_com_frameTime;

	// if running over 1000fps, act as if each frame is 1ms
	// prevents divisions by zero
	if ( frame_msec < 1 ) {
		frame_msec = 1;
	}

	// if running less than 5fps, truncate the extra time to prevent
	// unexpected moves after a hitch
	if ( frame_msec > 200 ) {
		frame_msec = 200;
	}
	old_com_frameTime = com_frameTime;


	// generate a command for this frame
	cl.cmdNumber++;
	cmdNum = cl.cmdNumber & CMD_MASK;
	cl.cmds[cmdNum] = CL_CreateCmd ();
	//cmd = &cl.cmds[cmdNum];
}
예제 #2
0
/*
=================
CL_CreateNewCommands

Create a new usercmd_t structure for this frame
=================
*/
void CL_CreateNewCommands(void)
{
	int cmdNum;

	// no need to create usercmds until we have a gamestate
	if (cls.state < CA_PRIMED)
	{
		return;
	}

	frame_msec = com_frameTime - old_com_frameTime;

	// force at least 1 msec frametime to avoid CL_KeyState returning
	// bogus values resulting in #IND cl.viewangles[]
	if (frame_msec < 1)
	{
		frame_msec = 1;
	}

	// if running less than 5fps, truncate the extra time to prevent
	// unexpected moves after a hitch
	if (frame_msec > 200)
	{
		frame_msec = 200;
	}
	old_com_frameTime = com_frameTime;

	// generate a command for this frame
	cl.cmdNumber++;
	cmdNum          = cl.cmdNumber & CMD_MASK;
	cl.cmds[cmdNum] = CL_CreateCmd();
}
예제 #3
0
/*
=================
CL_CreateNewCommands

Create a new usercmd_t structure for this frame
=================
*/
void
CL_CreateNewCommands(void)
{
  int cmdNum;

  // no need to create usercmds until we have a gamestate
  if (clc.state < CA_PRIMED)
  {
    return;
  }

  frame_msec = com_frameTime - old_com_frameTime;

  // if running less than 5fps, truncate the extra time to prevent
  // unexpected moves after a hitch
  if (frame_msec > 200)
  {
    frame_msec = 200;
  }
  old_com_frameTime = com_frameTime;


  // generate a command for this frame
  cl.cmdNumber++;
  cmdNum = cl.cmdNumber & CMD_MASK;
  cl.cmds[cmdNum] = CL_CreateCmd();
}
예제 #4
0
파일: cl_main.c 프로젝트: Reedych/xash3d
/*
=================
CL_SendCmd

Called every frame to builds and sends a command packet to the server.
=================
*/
void CL_SendCmd( void )
{
	// we create commands even if a demo is playing,
	CL_CreateCmd();
	// clc_move, userinfo etc
	CL_WritePacket();

	// make sure what menu and CL_WritePacket catch changes
	userinfo->modified = false;
}
예제 #5
0
파일: cl_input.c 프로젝트: Razish/QtZ
// Create a new usercmd_t structure for this frame
void CL_CreateNewCommands( void ) {
	// no need to create usercmds until we have a gamestate
	if ( clc.state < CA_PRIMED )
		return;

	frame_msec = com_frameTime - old_com_frameTime;
	old_com_frameTime = com_frameTime;

		 if ( frame_msec > 200 )	frame_msec = 200;
	else if ( frame_msec < 1 )		frame_msec = 1;

	cl.cmds[++cl.cmdNumber & CMD_MASK] = CL_CreateCmd();
}
예제 #6
0
/*
=================
CL_SendCmd
=================
*/
void CL_SendCmd (void)
{
	sizebuf_t	buf;
	byte		data[128];
	int			i;
	usercmd_t	*cmd, *oldcmd;
	usercmd_t	nullcmd;
	int			checksumIndex;

	// clear buffer
	memset (&buf, 0, sizeof(buf));

	// build a command even if not connected

	// save this command off for prediction
	i = cls.netchan.outgoing_sequence & (CMD_BACKUP-1);
	cmd = &cl.cmds[i];
	cl.cmd_time[i] = cls.realtime;	// for netgraph ping calculation

	*cmd = CL_CreateCmd ();

	cl.cmd = *cmd;

	if (cls.state == ca_disconnected || cls.state == ca_connecting)
		return;

	if (cls.state == ca_connected)
	{
		if (cls.netchan.message.cursize	|| curtime - cls.netchan.last_sent > 1000 )
			Netchan_Transmit (&cls.netchan, 0, buf.data);	
		return;
	}

	// send a userinfo update if needed
	if (userinfo_modified)
	{
		CL_FixUpGender();
		userinfo_modified = false;
		MSG_WriteByte (&cls.netchan.message, clc_userinfo);
		MSG_WriteString (&cls.netchan.message, Cvar_Userinfo() );
	}

	SZ_Init (&buf, data, sizeof(data));

	// Knightmare- removed this, put ESC-only substitute in keys.c
	/*if (cmd->buttons && cl.cinematictime > 0 && !cl.attractloop 
		&& cls.realtime - cl.cinematictime > 1000)
	{	// skip the rest of the cinematic
		SCR_FinishCinematic ();
	}*/

	// begin a client move command
	MSG_WriteByte (&buf, clc_move);

	// save the position for a checksum byte
	checksumIndex = buf.cursize;
	MSG_WriteByte (&buf, 0);

	// let the server know what the last frame we
	// got was, so the next message can be delta compressed
	if (cl_nodelta->value || !cl.frame.valid || cls.demowaiting)
		MSG_WriteLong (&buf, -1);	// no compression
	else
		MSG_WriteLong (&buf, cl.frame.serverframe);

	// send this and the previous cmds in the message, so
	// if the last packet was dropped, it can be recovered
	i = (cls.netchan.outgoing_sequence-2) & (CMD_BACKUP-1);
	cmd = &cl.cmds[i];
	memset (&nullcmd, 0, sizeof(nullcmd));
	MSG_WriteDeltaUsercmd (&buf, &nullcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence-1) & (CMD_BACKUP-1);
	cmd = &cl.cmds[i];
	MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence) & (CMD_BACKUP-1);
	cmd = &cl.cmds[i];
	MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);

	// calculate a checksum over the move commands
	buf.data[checksumIndex] = COM_BlockSequenceCRCByte(
		buf.data + checksumIndex + 1, buf.cursize - checksumIndex - 1,
		cls.netchan.outgoing_sequence);

	//
	// deliver the message
	//
	Netchan_Transmit (&cls.netchan, buf.cursize, buf.data);	
}
예제 #7
0
void
CL_SendCmd(void)
{
	sizebuf_t buf;
	byte data[128];
	int i;
	usercmd_t *cmd, *oldcmd;
	usercmd_t nullcmd;
	int checksumIndex;

	/* build a command even if not connected */

	/* save this command off for prediction */
	i = cls.netchan.outgoing_sequence & (CMD_BACKUP - 1);
	cmd = &cl.cmds[i];
	cl.cmd_time[i] = cls.realtime; /* for netgraph ping calculation */

	*cmd = CL_CreateCmd();

	cl.cmd = *cmd;

	if ((cls.state == ca_disconnected) || (cls.state == ca_connecting))
	{
		return;
	}

	if (cls.state == ca_connected)
	{
		if (cls.netchan.message.cursize ||
			(curtime - cls.netchan.last_sent > 100))
		{
			Netchan_Transmit(&cls.netchan, 0, buf.data);
		}

		return;
	}

	/* send a userinfo update if needed */
	if (userinfo_modified)
	{
		CL_FixUpGender();
		userinfo_modified = false;
		MSG_WriteByte(&cls.netchan.message, clc_userinfo);
		MSG_WriteString(&cls.netchan.message, Cvar_Userinfo());
	}

	SZ_Init(&buf, data, sizeof(data));

	if (cmd->buttons && (cl.cinematictime > 0) && !cl.attractloop &&
		(cls.realtime - cl.cinematictime > 1000))
	{
		/* skip the rest of the cinematic */
		SCR_FinishCinematic();
	}

	/* begin a client move command */
	MSG_WriteByte(&buf, clc_move);

	/* save the position for a checksum byte */
	checksumIndex = buf.cursize;
	MSG_WriteByte(&buf, 0);

	/* let the server know what the last frame we
	   got was, so the next message can be delta
	   compressed */
	if (cl_nodelta->value || !cl.frame.valid || cls.demowaiting)
	{
		MSG_WriteLong(&buf, -1); /* no compression */
	}
	else
	{
		MSG_WriteLong(&buf, cl.frame.serverframe);
	}

	/* send this and the previous cmds in the message, so
	   if the last packet was dropped, it can be recovered */
	i = (cls.netchan.outgoing_sequence - 2) & (CMD_BACKUP - 1);
	cmd = &cl.cmds[i];
	memset(&nullcmd, 0, sizeof(nullcmd));
	MSG_WriteDeltaUsercmd(&buf, &nullcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence - 1) & (CMD_BACKUP - 1);
	cmd = &cl.cmds[i];
	MSG_WriteDeltaUsercmd(&buf, oldcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence) & (CMD_BACKUP - 1);
	cmd = &cl.cmds[i];
	MSG_WriteDeltaUsercmd(&buf, oldcmd, cmd);

	/* calculate a checksum over the move commands */
	buf.data[checksumIndex] = COM_BlockSequenceCRCByte(
			buf.data + checksumIndex + 1, buf.cursize - checksumIndex - 1,
			cls.netchan.outgoing_sequence);

	/* deliver the message */
	Netchan_Transmit(&cls.netchan, buf.cursize, buf.data);
}
예제 #8
0
void CLQW_SendCmd() {
	if ( cls.state == CA_DISCONNECTED ) {
		return;
	}
	if ( clc.demoplaying ) {
		return;	// sendcmds come from the demo

	}
	// save this command off for prediction
	int i = clc.netchan.outgoingSequence & UPDATE_MASK_QW;
	qwusercmd_t* cmd = &cl.qw_frames[ i ].cmd;
	cl.qw_frames[ i ].senttime = cls.realtime * 0.001;
	cl.qw_frames[ i ].receivedtime = -1;		// we haven't gotten a reply yet

	int seq_hash = clc.netchan.outgoingSequence;

	// get basic movement from keyboard
	Com_Memset( cmd, 0, sizeof ( *cmd ) );

	in_usercmd_t inCmd = CL_CreateCmd();

	cmd->forwardmove = inCmd.forwardmove;
	cmd->sidemove = inCmd.sidemove;
	cmd->upmove = inCmd.upmove;
	cmd->buttons = inCmd.buttons;
	cmd->impulse = inCmd.impulse;
	cmd->msec = inCmd.msec;
	VectorCopy( inCmd.fAngles, cmd->angles );

	//
	// allways dump the first two message, because it may contain leftover inputs
	// from the last level
	//
	if ( ++cl.qh_movemessages <= 2 ) {
		return;
	}

	// send this and the previous cmds in the message, so
	// if the last packet was dropped, it can be recovered
	QMsg buf;
	byte data[ 128 ];
	buf.InitOOB( data, 128 );

	buf.WriteByte( q1clc_move );

	// save the position for a checksum byte
	int checksumIndex = buf.cursize;
	buf.WriteByte( 0 );

	// write our lossage percentage
	int lost = CLQW_CalcNet();
	buf.WriteByte( ( byte )lost );

	i = ( clc.netchan.outgoingSequence - 2 ) & UPDATE_MASK_QW;
	cmd = &cl.qw_frames[ i ].cmd;
	qwusercmd_t nullcmd = {};
	MSGQW_WriteDeltaUsercmd( &buf, &nullcmd, cmd );
	qwusercmd_t* oldcmd = cmd;

	i = ( clc.netchan.outgoingSequence - 1 ) & UPDATE_MASK_QW;
	cmd = &cl.qw_frames[ i ].cmd;
	MSGQW_WriteDeltaUsercmd( &buf, oldcmd, cmd );
	oldcmd = cmd;

	i = ( clc.netchan.outgoingSequence ) & UPDATE_MASK_QW;
	cmd = &cl.qw_frames[ i ].cmd;
	MSGQW_WriteDeltaUsercmd( &buf, oldcmd, cmd );

	// calculate a checksum over the move commands
	buf._data[ checksumIndex ] = COMQW_BlockSequenceCRCByte(
		buf._data + checksumIndex + 1, buf.cursize - checksumIndex - 1,
		seq_hash );

	// request delta compression of entities
	if ( clc.netchan.outgoingSequence - cl.qh_validsequence >= UPDATE_BACKUP_QW - 1 ) {
		cl.qh_validsequence = 0;
	}

	if ( cl.qh_validsequence && !cl_nodelta->value && cls.state == CA_ACTIVE &&
		 !clc.demorecording ) {
		cl.qw_frames[ clc.netchan.outgoingSequence & UPDATE_MASK_QW ].delta_sequence = cl.qh_validsequence;
		buf.WriteByte( qwclc_delta );
		buf.WriteByte( cl.qh_validsequence & 255 );
	} else {
		cl.qw_frames[ clc.netchan.outgoingSequence & UPDATE_MASK_QW ].delta_sequence = -1;
	}

	if ( clc.demorecording ) {
		CLQW_WriteDemoCmd( cmd );
	}

	//
	// deliver the message
	//
	Netchan_Transmit( &clc.netchan, buf.cursize, buf._data );
}