Ein Versuch cl_input zu modernisieren

This commit is contained in:
Yamagi Burmeister 2009-03-01 21:06:44 +00:00
parent e548206c18
commit 5a86784a95

View file

@ -198,13 +198,6 @@ float CL_KeyState (kbutton_t *key)
key->downtime = sys_frame_time; key->downtime = sys_frame_time;
} }
#if 0
if (msec)
{
Com_Printf ("%i ", msec);
}
#endif
val = (float)msec / frame_msec; val = (float)msec / frame_msec;
if (val < 0) if (val < 0)
val = 0; val = 0;
@ -231,82 +224,70 @@ cvar_t *cl_run;
cvar_t *cl_anglespeedkey; cvar_t *cl_anglespeedkey;
/*
================
CL_AdjustAngles
Moves the local angle positions
================
*/
void CL_AdjustAngles (void)
{
float speed;
float up, down;
if (in_speed.state & 1)
speed = cls.frametime * cl_anglespeedkey->value;
else
speed = cls.frametime;
if (!(in_strafe.state & 1))
{
cl.viewangles[YAW] -= speed*cl_yawspeed->value*CL_KeyState (&in_right);
cl.viewangles[YAW] += speed*cl_yawspeed->value*CL_KeyState (&in_left);
}
if (in_klook.state & 1)
{
cl.viewangles[PITCH] -= speed*cl_pitchspeed->value * CL_KeyState (&in_forward);
cl.viewangles[PITCH] += speed*cl_pitchspeed->value * CL_KeyState (&in_back);
}
up = CL_KeyState (&in_lookup);
down = CL_KeyState(&in_lookdown);
cl.viewangles[PITCH] -= speed*cl_pitchspeed->value * up;
cl.viewangles[PITCH] += speed*cl_pitchspeed->value * down;
}
/* /*
================ ================
CL_BaseMove CL_BaseMove
Send the intended movement message to the server Applies keyboard input to usercmd
================ ================
*/ */
void CL_BaseMove (usercmd_t *cmd) void CL_BaseMove (usercmd_t *cmd)
{ {
CL_AdjustAngles (); int i;
float tspeed;
float mspeed;
memset (cmd, 0, sizeof(*cmd)); //adjust for turning speed
if (in_speed.state & 1)
tspeed = cls.frametime * cl_anglespeedkey->value;
else
tspeed = cls.frametime;
VectorCopy (cl.viewangles, cmd->angles); //adjust for running speed
if (in_strafe.state & 1)
{
cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_right);
cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_left);
}
cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_moveright);
cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_moveleft);
cmd->upmove += cl_upspeed->value * CL_KeyState (&in_up);
cmd->upmove -= cl_upspeed->value * CL_KeyState (&in_down);
if (! (in_klook.state & 1) )
{
cmd->forwardmove += cl_forwardspeed->value * CL_KeyState (&in_forward);
cmd->forwardmove -= cl_forwardspeed->value * CL_KeyState (&in_back);
}
//
// adjust for speed key / running
//
if ( (in_speed.state & 1) ^ (int)(cl_run->value) ) if ( (in_speed.state & 1) ^ (int)(cl_run->value) )
{ mspeed = 2;
cmd->forwardmove *= 2; else
cmd->sidemove *= 2; mspeed = 1;
cmd->upmove *= 2;
//handle left/right on keyboard
i = cls.netchan.outgoing_sequence & (CMD_BACKUP-1);
cmd = &cl.cmds[i];
cl.cmd_time[i] = cls.realtime; // for netgraph ping calculation
if (in_strafe.state & 1)
{ // keyboard strafe
cmd->sidemove += mspeed * cl_sidespeed->value * CL_KeyState (&in_right);
cmd->sidemove -= mspeed * cl_sidespeed->value * CL_KeyState (&in_left);
}
else
{ // keyboard turn
cl.viewangles[YAW] -= tspeed*cl_yawspeed->value*CL_KeyState (&in_right);
cl.viewangles[YAW] += tspeed*cl_yawspeed->value*CL_KeyState (&in_left);
} }
//handle foward/back on keyboard
if (in_klook.state & 1)
{ // keyboard look
cl.viewangles[PITCH] -= tspeed*cl_pitchspeed->value * CL_KeyState (&in_forward);
cl.viewangles[PITCH] += tspeed*cl_pitchspeed->value * CL_KeyState (&in_back);
}
else
{ // keyboard move front/back
cmd->forwardmove += mspeed * cl_forwardspeed->value * CL_KeyState (&in_forward);
cmd->forwardmove -= mspeed * cl_forwardspeed->value * CL_KeyState (&in_back);
}
// keyboard look up/down
cl.viewangles[PITCH] -= tspeed*cl_pitchspeed->value * CL_KeyState(&in_lookup);
cl.viewangles[PITCH] += tspeed*cl_pitchspeed->value * CL_KeyState(&in_lookdown);
// keyboard strafe left/right
cmd->sidemove += mspeed * cl_sidespeed->value * CL_KeyState (&in_moveright);
cmd->sidemove -= mspeed * cl_sidespeed->value * CL_KeyState (&in_moveleft);
// keyboard jump/crouch
cmd->upmove += mspeed * cl_upspeed->value * CL_KeyState (&in_up);
cmd->upmove -= mspeed * cl_upspeed->value * CL_KeyState (&in_down);
} }
void CL_ClampPitch (void) void CL_ClampPitch (void)
@ -328,23 +309,61 @@ void CL_ClampPitch (void)
cl.viewangles[PITCH] = -89 - pitch; cl.viewangles[PITCH] = -89 - pitch;
} }
/* // CL_InitCmd
============== inline void CL_InitCmd (void)
CL_FinishMove
==============
*/
void CL_FinishMove (usercmd_t *cmd)
{ {
int ms; usercmd_t *cmd = &cl.cmds[ cls.netchan.outgoing_sequence & (CMD_BACKUP-1) ];
int i;
// // init the current cmd buffer
// figure button bits memset(cmd, 0, sizeof(struct usercmd_s) );
// }
// CL_RefreshCmd
void CL_RefreshCmd (void)
{
int i, ms;
usercmd_t *cmd = &cl.cmds[ cls.netchan.outgoing_sequence & (CMD_BACKUP-1) ];
//get delta for this sample.
frame_msec = sys_frame_time - old_sys_frame_time;
// bounds checking
if (frame_msec < 1)
return;
if (frame_msec > 1000)
frame_msec = 500;
// get basic movement from keyboard
CL_BaseMove (cmd);
// allow mice or other external controllers to add to the move
IN_Move (cmd);
// update cmd viewangles for CL_PredictMove
CL_ClampPitch ();
for (i=0 ; i<3 ; i++)
cmd->angles[i] = ANGLE2SHORT(cl.viewangles[i]);
// update cmd->msec for CL_PredictMove
ms = cls.frametime * 1000;
if (ms > 250)
ms = 100;
cmd->msec = ms;
//update counter
old_sys_frame_time = sys_frame_time;
}
// CL_FinalizeCmd
void CL_FinalizeCmd (void)
{
usercmd_t *cmd = &cl.cmds[ cls.netchan.outgoing_sequence & (CMD_BACKUP-1) ];
//set any button hits that occured since last frame
if ( in_attack.state & 3 ) if ( in_attack.state & 3 )
cmd->buttons |= BUTTON_ATTACK; cmd->buttons |= BUTTON_ATTACK;
in_attack.state &= ~2; in_attack.state &= ~2;
if (in_use.state & 3) if (in_use.state & 3)
cmd->buttons |= BUTTON_USE; cmd->buttons |= BUTTON_USE;
in_use.state &= ~2; in_use.state &= ~2;
@ -352,53 +371,13 @@ void CL_FinishMove (usercmd_t *cmd)
if (anykeydown && cls.key_dest == key_game) if (anykeydown && cls.key_dest == key_game)
cmd->buttons |= BUTTON_ANY; cmd->buttons |= BUTTON_ANY;
// send milliseconds of time to apply the move
ms = cls.frametime * 1000;
if (ms > 250)
ms = 100; // time was unreasonable
cmd->msec = ms;
CL_ClampPitch ();
for (i=0 ; i<3 ; i++)
cmd->angles[i] = ANGLE2SHORT(cl.viewangles[i]);
cmd->impulse = in_impulse; cmd->impulse = in_impulse;
in_impulse = 0; in_impulse = 0;
// send the ambient light level at the player's current position // set the ambient light level at the player's current position
cmd->lightlevel = (byte)cl_lightlevel->value; cmd->lightlevel = (byte)cl_lightlevel->value;
} }
/*
=================
CL_CreateCmd
=================
*/
usercmd_t CL_CreateCmd (void)
{
usercmd_t cmd;
frame_msec = sys_frame_time - old_sys_frame_time;
if (frame_msec < 1)
frame_msec = 1;
if (frame_msec > 200)
frame_msec = 200;
// get basic movement from keyboard
CL_BaseMove (&cmd);
// allow mice or other external controllers to add to the move
IN_Move (&cmd);
CL_FinishMove (&cmd);
old_sys_frame_time = sys_frame_time;
//cmd.impulse = cls.framecount;
return cmd;
}
void IN_CenterView (void) void IN_CenterView (void)
{ {
@ -449,8 +428,6 @@ void CL_InitInput (void)
cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0); cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0);
} }
/* /*
================= =================
CL_SendCmd CL_SendCmd
@ -465,27 +442,29 @@ void CL_SendCmd (void)
usercmd_t nullcmd; usercmd_t nullcmd;
int checksumIndex; 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) if (cls.state == ca_disconnected || cls.state == ca_connecting)
return; return;
if ( cls.state == ca_connected) if ( cls.state == ca_connected)
{ {
if (cls.netchan.message.cursize || curtime - cls.netchan.last_sent > 1000 ) if (cls.netchan.message.cursize || curtime - cls.netchan.last_sent > 1000 ) {
memset (&buf, 0, sizeof(buf));
Com_DPrintf ("connected: flushing netchan (len=%d, %s)\n", cls.netchan.message.cursize, cls.netchan.message.data);
Netchan_Transmit (&cls.netchan, 0, buf.data); Netchan_Transmit (&cls.netchan, 0, buf.data);
}
return; return;
} }
i = cls.netchan.outgoing_sequence & (CMD_BACKUP-1);
cmd = &cl.cmds[i];
cl.cmd_time[i] = cls.realtime; // for netgraph ping calculation
//jec - prepare the pending user command for sending.
CL_FinalizeCmd();
cl.cmd = *cmd;
// send a userinfo update if needed
// send a userinfo update if needed // send a userinfo update if needed
if (userinfo_modified) if (userinfo_modified)
{ {
@ -503,7 +482,6 @@ void CL_SendCmd (void)
SCR_FinishCinematic (); SCR_FinishCinematic ();
} }
// begin a client move command
MSG_WriteByte (&buf, clc_move); MSG_WriteByte (&buf, clc_move);
// save the position for a checksum byte // save the position for a checksum byte
@ -512,6 +490,9 @@ void CL_SendCmd (void)
// let the server know what the last frame we // let the server know what the last frame we
// got was, so the next message can be delta compressed // got was, so the next message can be delta compressed
//r1: after a vid_restart memory locations of models changes! all existing ents
//need to be re-sent so the client updates its model to the new memory location.
if (cl_nodelta->value || !cl.frame.valid || cls.demowaiting) if (cl_nodelta->value || !cl.frame.valid || cls.demowaiting)
MSG_WriteLong (&buf, -1); // no compression MSG_WriteLong (&buf, -1); // no compression
else else
@ -543,6 +524,7 @@ void CL_SendCmd (void)
// deliver the message // deliver the message
// //
Netchan_Transmit (&cls.netchan, buf.cursize, buf.data); Netchan_Transmit (&cls.netchan, buf.cursize, buf.data);
CL_InitCmd(); //jec - init the next usercmd buffer.
} }