[client] Merge chase camera and much of input

Handling of view angles is a little hacky at the moment, but this gets
the chase camera code and most of the common input code into one place,
which will make cleaning up the camera code much easier.
This commit is contained in:
Bill Currie 2022-02-22 15:23:09 +09:00
parent 2615953e17
commit deff95f490
23 changed files with 529 additions and 1127 deletions

View file

@ -25,13 +25,18 @@
*/
#ifndef __chase_h
#define __chase_h
#ifndef __client_chase_h
#define __client_chase_h
typedef struct chasestate_s {
struct model_s *worldmodel;
struct viewstate_s *viewstate;
} chasestate_t;
extern struct cvar_s *chase_active;
void Chase_Init_Cvars (void);
void Chase_Reset (void);
void Chase_Update (void);
void Chase_Update (chasestate_t *cs);
#endif // __chase_h
#endif // __client_chase_h

View file

@ -27,8 +27,46 @@
#ifndef __client_input_h_
#define __client_input_h_
void CL_Legacy_Init (void);
#include "QF/simd/vec4f.h"
#include "QF/input.h"
struct cbuf_s;
extern struct cvar_s *cl_upspeed;
extern struct cvar_s *cl_forwardspeed;
extern struct cvar_s *cl_backspeed;
extern struct cvar_s *cl_sidespeed;
extern struct cvar_s *cl_movespeedkey;
extern struct cvar_s *cl_yawspeed;
extern struct cvar_s *cl_pitchspeed;
extern struct cvar_s *cl_anglespeedkey;
#define FORWARD 0
#define SIDE 1
#define UP 2
typedef struct movestate_s {
vec4f_t move;
vec4f_t angles;
} movestate_t;
#define freelook (in_mlook.state & 1 || in_freelook->int_val)
void CL_OnFocusChange (void (*func) (int game));
void CL_Input_BuildMove (float frametime, movestate_t *state);
void CL_Input_Init (struct cbuf_s *cbuf);
void CL_Input_Init_Cvars (void);
void CL_Input_Activate (int in_game);
extern in_button_t in_left, in_right, in_forward, in_back;
extern in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
extern in_button_t in_use, in_jump, in_attack;
extern in_button_t in_up, in_down;
extern in_button_t in_strafe, in_klook, in_speed, in_mlook;
#endif // __client_input_h_

View file

@ -3,6 +3,7 @@ noinst_LTLIBRARIES += libs/client/libQFclient.la
libs_client_libQFclient_la_LDFLAGS= @STATIC@
libs_client_libQFclient_la_LIBADD= libs/gamecode/libQFgamecode.la libs/util/libQFutil.la
libs_client_libQFclient_la_SOURCES= \
libs/client/cl_chase.c \
libs/client/cl_effects.c \
libs/client/cl_entities.c \
libs/client/cl_input.c \

View file

@ -45,8 +45,9 @@
#include "world.h"
#include "nq/include/chase.h"
#include "nq/include/client.h"
#include "client/chase.h"
#include "client/input.h"
#include "client/view.h"
vec4f_t camera_origin = {0,0,0,1};
@ -83,22 +84,22 @@ Chase_Reset (void)
}
static inline void
TraceLine (vec3_t start, vec3_t end, vec3_t impact)
TraceLine (chasestate_t *cs, vec3_t start, vec3_t end, vec3_t impact)
{
trace_t trace;
memset (&trace, 0, sizeof (trace));
trace.fraction = 1;
MOD_TraceLine (cl.worldmodel->brush.hulls, 0, start, end, &trace);
MOD_TraceLine (cs->worldmodel->brush.hulls, 0, start, end, &trace);
VectorCopy (trace.endpos, impact);
}
void
Chase_Update (void)
Chase_Update (chasestate_t *cs)
{
float pitch, yaw, fwd;
usercmd_t cmd; // movement direction
vec4f_t move = {};
vec4f_t forward = {}, up = {}, right = {}, stop = {}, dir = {};
// lazy camera, look toward player entity
@ -106,7 +107,7 @@ Chase_Update (void)
if (chase_active->int_val == 2 || chase_active->int_val == 3) {
// control camera angles with key/mouse/joy-look
vec3_t d;
VectorSubtract (cl.viewstate.angles, player_angles, d);
VectorSubtract (cs->viewstate->angles, player_angles, d);
VectorAdd (camera_angles, d, camera_angles);
if (chase_active->int_val == 2) {
@ -148,7 +149,7 @@ Chase_Update (void)
camera_origin += 8 * forward;
//FIXME
TraceLine (&player_origin[0], &camera_origin[0], &stop[0]);
TraceLine (cs, &player_origin[0], &camera_origin[0], &stop[0]);
stop[3] = 1;
if (magnitude3f (stop)[0] != 0) {
camera_origin = stop - forward;
@ -160,7 +161,7 @@ Chase_Update (void)
if (chase_active->int_val == 2) {
if (dir[1] == 0 && dir[0] == 0) {
// look straight up or down
// camera_angles[YAW] = r_data->refdef->viewstate.angles[YAW];
// camera_angles[YAW] = r_data->refdef->viewstate->angles[YAW];
if (dir[2] > 0)
camera_angles[PITCH] = 90;
else
@ -188,53 +189,51 @@ Chase_Update (void)
// get basic movement from keyboard
memset (&cmd, 0, sizeof (cmd));
// VectorCopy (cl.viewstate.angles, cmd.angles);
// VectorCopy (cs->viewstate->angles, cmd.angles);
if (in_strafe.state & 1) {
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_right);
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_left);
}
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_moveright);
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
if (!(in_klook.state & 1)) {
cmd.forwardmove += cl_forwardspeed->value
move[FORWARD] += cl_forwardspeed->value
* IN_ButtonState (&in_forward);
cmd.forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
move[FORWARD] -= cl_backspeed->value * IN_ButtonState (&in_back);
}
if (in_speed.state & 1) {
cmd.forwardmove *= cl_movespeedkey->value;
cmd.sidemove *= cl_movespeedkey->value;
move *= cl_movespeedkey->value;
}
// mouse and joystick controllers add to movement
VectorSet (0, cl.viewstate.angles[1] - camera_angles[1], 0, dir);
VectorSet (0, cs->viewstate->angles[1] - camera_angles[1], 0, dir);
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
//forward *= viewdelta.position[2] * m_forward->value; FIXME
//right *= viewdelta.position[0] * m_side->value; FIXME
dir = forward + right;
cmd.forwardmove += dir[0];
cmd.sidemove -= dir[1];
move[FORWARD] += dir[0];
move[SIDE] -= dir[1];
VectorSet (0, camera_angles[1], 0, dir);
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
VectorScale (forward, cmd.forwardmove, forward);
VectorScale (right, cmd.sidemove, right);
VectorScale (forward, move[FORWARD], forward);
VectorScale (right, move[SIDE], right);
VectorAdd (forward, right, dir);
if (dir[1] || dir[0]) {
cl.viewstate.angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
if (cl.viewstate.angles[YAW] < 0) {
cl.viewstate.angles[YAW] += 360;
cs->viewstate->angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
if (cs->viewstate->angles[YAW] < 0) {
cs->viewstate->angles[YAW] += 360;
}
}
cl.viewstate.angles[PITCH] = 0;
cs->viewstate->angles[PITCH] = 0;
// remember the new angle to calculate the difference next frame
VectorCopy (cl.viewstate.angles, player_angles);
VectorCopy (cs->viewstate->angles, player_angles);
return;
}
@ -242,7 +241,7 @@ Chase_Update (void)
// regular camera, faces same direction as player
//FIXME
AngleVectors (cl.viewstate.angles, &forward[0], &right[0], &up[0]);
AngleVectors (cs->viewstate->angles, &forward[0], &right[0], &up[0]);
// calc exact destination
camera_origin = r_data->refdef->viewposition
@ -252,7 +251,7 @@ Chase_Update (void)
// check for walls between player and camera
//FIXME
TraceLine (&r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]);
TraceLine (cs, &r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]);
stop[3] = 1;
if (magnitude3f (stop)[0] != 0) {
camera_origin = stop + forward * 8;

View file

@ -39,15 +39,230 @@
#endif
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/input.h"
#include "QF/plist.h"
#include "QF/sys.h"
#include "QF/input/event.h"
#include "old_keys.h"
#include "client/input.h"
#include "client/view.h"
int cl_game_context;
int cl_demo_context;
static int cl_event_id;
static struct LISTENER_SET_TYPE(int) cl_on_focus_change
= LISTENER_SET_STATIC_INIT(4);
in_axis_t viewdelta_position_forward = {
.mode = ina_set,
.name = "move.forward",
.description = "Move forward (negative) or backward (positive)",
};
in_axis_t viewdelta_position_side = {
.mode = ina_set,
.name = "move.side",
.description = "Move right (positive) or left (negative)",
};
in_axis_t viewdelta_position_up = {
.mode = ina_set,
.name = "move.up",
.description = "Move up (positive) or down (negative)",
};
in_axis_t viewdelta_angles_pitch = {
.mode = ina_set,
.name = "move.pitch",
.description = "Pitch axis",
};
in_axis_t viewdelta_angles_yaw = {
.mode = ina_set,
.name = "move.yaw",
.description = "Yaw axis",
};
in_axis_t viewdelta_angles_roll = {
.mode = ina_set,
.name = "move.roll",
.description = "Roll axis",
};
in_button_t in_left = {
.name = "left",
.description = "When active the player is turning left"
};
in_button_t in_right = {
.name = "right",
.description = "When active the player is turning right"
};
in_button_t in_forward = {
.name = "forward",
.description = "When active the player is moving forward"
};
in_button_t in_back = {
.name = "back",
.description = "When active the player is moving backwards"
};
in_button_t in_lookup = {
.name = "lookup",
.description = "When active the player's view is looking up"
};
in_button_t in_lookdown = {
.name = "lookdown",
.description = "When active the player's view is looking down"
};
in_button_t in_moveleft = {
.name = "moveleft",
.description = "When active the player is strafing left"
};
in_button_t in_moveright = {
.name = "moveright",
.description = "When active the player is strafing right"
};
in_button_t in_use = {
.name = "use",
.description = "Left over command for opening doors and triggering"
" switches"
};
in_button_t in_jump = {
.name = "jump",
.description = "When active the player is jumping"
};
in_button_t in_attack = {
.name = "attack",
.description = "When active player is firing/using current weapon"
};
in_button_t in_up = {
.name = "moveup",
.description = "When active the player is swimming up in a liquid"
};
in_button_t in_down = {
.name = "movedown",
.description = "When active the player is swimming down in a liquid"
};
in_button_t in_strafe = {
.name = "strafe",
.description = "When active, +left and +right function like +moveleft and"
" +moveright"
};
in_button_t in_klook = {
.name = "klook",
.description = "When active, +forward and +back perform +lookup and"
" +lookdown"
};
in_button_t in_speed = {
.name = "speed",
.description = "When active the player is running"
};
in_button_t in_mlook = {
.name = "mlook",
.description = "When active moving the mouse or joystick forwards "
"and backwards performs +lookup and "
"+lookdown"
};
static in_axis_t *cl_in_axes[] = {
&viewdelta_position_forward,
&viewdelta_position_side,
&viewdelta_position_up,
&viewdelta_angles_pitch,
&viewdelta_angles_yaw,
&viewdelta_angles_roll,
0,
};
static in_button_t *cl_in_buttons[] = {
&in_left,
&in_right,
&in_forward,
&in_back,
&in_lookup,
&in_lookdown,
&in_moveleft,
&in_moveright,
&in_use,
&in_jump,
&in_attack,
&in_up,
&in_down,
&in_strafe,
&in_klook,
&in_speed,
&in_mlook,
0
};
cvar_t *cl_anglespeedkey;
cvar_t *cl_backspeed;
cvar_t *cl_forwardspeed;
cvar_t *cl_movespeedkey;
cvar_t *cl_pitchspeed;
cvar_t *cl_sidespeed;
cvar_t *cl_upspeed;
cvar_t *cl_yawspeed;
cvar_t *lookspring;
cvar_t *m_pitch;
cvar_t *m_yaw;
cvar_t *m_forward;
cvar_t *m_side;
static void
CL_AdjustAngles (float frametime, movestate_t *ms)
{
float down, up;
float pitchspeed, yawspeed;
vec4f_t delta = {};
pitchspeed = cl_pitchspeed->value;
yawspeed = cl_yawspeed->value;
if (in_speed.state & inb_down) {
pitchspeed *= cl_anglespeedkey->value;
yawspeed *= cl_anglespeedkey->value;
}
pitchspeed *= frametime;
yawspeed *= frametime;
if (!(in_strafe.state & inb_down)) {
delta[YAW] -= yawspeed * IN_ButtonState (&in_right);
delta[YAW] += yawspeed * IN_ButtonState (&in_left);
}
if (in_klook.state & inb_down) {
V_StopPitchDrift ();
delta[PITCH] -= pitchspeed * IN_ButtonState (&in_forward);
delta[PITCH] += pitchspeed * IN_ButtonState (&in_back);
}
up = IN_ButtonState (&in_lookup);
down = IN_ButtonState (&in_lookdown);
delta[PITCH] -= pitchspeed * up;
delta[PITCH] += pitchspeed * down;
delta[PITCH] -= IN_UpdateAxis (&viewdelta_angles_pitch) * m_pitch->value;
delta[YAW] -= IN_UpdateAxis (&viewdelta_angles_yaw) * m_yaw->value;
delta[ROLL] -= IN_UpdateAxis (&viewdelta_angles_roll) * m_pitch->value;
ms->angles += delta;
if (delta[PITCH]) {
V_StopPitchDrift ();
ms->angles[PITCH] = bound (-70, ms->angles[PITCH], 80);
}
if (delta[ROLL]) {
ms->angles[ROLL] = bound (-50, ms->angles[ROLL], 50);
}
if (delta[YAW]) {
ms->angles[YAW] = anglemod (ms->angles[YAW]);
}
}
static const char default_input_config[] = {
#include "libs/client/default_input.plc"
@ -114,7 +329,7 @@ cl_unbind_f (void)
Cmd_ExecuteString (cmd_buf->str, src_command);
}
void
static void
CL_Legacy_Init (void)
{
OK_Init ();
@ -123,3 +338,163 @@ CL_Legacy_Init (void)
// FIXME hashlinks
IN_LoadConfig (PL_GetPropertyList (default_input_config, 0));
}
void
CL_Input_BuildMove (float frametime, movestate_t *state)
{
if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring->int_val) {
V_StartPitchDrift ();
}
CL_AdjustAngles (frametime, state);
vec4f_t move = {};
if (in_strafe.state & inb_down) {
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_right);
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_left);
}
move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_moveright);
move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
move[UP] += cl_upspeed->value * IN_ButtonState (&in_up);
move[UP] -= cl_upspeed->value * IN_ButtonState (&in_down);
if (!(in_klook.state & inb_down)) {
move[FORWARD] += cl_forwardspeed->value * IN_ButtonState (&in_forward);
move[FORWARD] -= cl_backspeed->value * IN_ButtonState (&in_back);
}
// adjust for speed key
if (in_speed.state & inb_down) {
move *= cl_movespeedkey->value;
}
move[FORWARD] -= IN_UpdateAxis (&viewdelta_position_forward) * m_forward->value;
move[SIDE] += IN_UpdateAxis (&viewdelta_position_side) * m_side->value;
move[UP] -= IN_UpdateAxis (&viewdelta_position_up);
if (freelook)
V_StopPitchDrift ();
//if (cl.chase
// && (chase_active->int_val == 2 || chase_active->int_val == 3)) {
// /* adjust for chase camera angles
// * makes the player move relative to the chase camera frame rather
// * than the player's frame
// */
// vec3_t forward, right, up, f, r;
// vec3_t dir = {0, 0, 0};
// // need separate camera and player angles
// //FIXME dir[1] = r_data->refdef->viewangles[1] - cl.viewstate.angles[1];
// AngleVectors (dir, forward, right, up);
// VectorScale (forward, move[FORWARD], f);
// VectorScale (right, move[SIDE], r);
// move[FORWARD] = f[0] + r[0];
// move[SIDE] = f[1] + r[1];
//}
state->move = move;
}
static void
cl_on_focus_change_redirect (void *_func, const int *game)
{
void (*func) (int game) = _func;
func (*game);
}
void
CL_OnFocusChange (void (*func) (int game))
{
LISTENER_ADD (&cl_on_focus_change, cl_on_focus_change_redirect, func);
}
static int
cl_focus_event (const IE_event_t *ie_event)
{
int game = ie_event->type == ie_gain_focus;
LISTENER_INVOKE (&cl_on_focus_change, &game);
return 1;
}
static int
cl_key_event (const IE_event_t *ie_event)
{
if (ie_event->key.code == QFK_ESCAPE) {
Con_SetState (con_menu);
return 1;
}
return 0;
}
static int
cl_event_handler (const IE_event_t *ie_event, void *unused)
{
static int (*handlers[ie_event_count]) (const IE_event_t *ie_event) = {
[ie_key] = cl_key_event,
[ie_gain_focus] = cl_focus_event,
[ie_lose_focus] = cl_focus_event,
};
if (ie_event->type < 0 || ie_event->type >= ie_event_count
|| !handlers[ie_event->type]) {
return IN_Binding_HandleEvent (ie_event);
}
return handlers[ie_event->type] (ie_event);
}
void
CL_Input_Init (cbuf_t *cbuf)
{
cl_event_id = IE_Add_Handler (cl_event_handler, 0);
for (int i = 0; cl_in_axes[i]; i++) {
IN_RegisterAxis (cl_in_axes[i]);
}
for (int i = 0; cl_in_buttons[i]; i++) {
IN_RegisterButton (cl_in_buttons[i]);
}
cl_game_context = IMT_CreateContext ("key_game");
IMT_SetContextCbuf (cl_game_context, cbuf);
cl_demo_context = IMT_CreateContext ("key_demo");
IMT_SetContextCbuf (cl_demo_context, cbuf);
CL_Legacy_Init ();
}
void
CL_Input_Init_Cvars (void)
{
lookspring = Cvar_Get ("lookspring", "0", CVAR_ARCHIVE, NULL, "Snap view "
"to center when moving and no mlook/klook");
m_pitch = Cvar_Get ("m_pitch", "0.022", CVAR_ARCHIVE, NULL,
"mouse pitch (up/down) multipier");
m_yaw = Cvar_Get ("m_yaw", "0.022", CVAR_ARCHIVE, NULL,
"mouse yaw (left/right) multipiler");
m_forward = Cvar_Get ("m_forward", "1", CVAR_ARCHIVE, NULL,
"mouse forward/back speed");
m_side = Cvar_Get ("m_side", "0.8", CVAR_ARCHIVE, NULL,
"mouse strafe speed");
cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", CVAR_NONE, NULL,
"turn `run' speed multiplier");
cl_backspeed = Cvar_Get ("cl_backspeed", "200", CVAR_ARCHIVE, NULL,
"backward speed");
cl_forwardspeed = Cvar_Get ("cl_forwardspeed", "200", CVAR_ARCHIVE, NULL,
"forward speed");
cl_movespeedkey = Cvar_Get ("cl_movespeedkey", "2.0", CVAR_NONE, NULL,
"move `run' speed multiplier");
cl_pitchspeed = Cvar_Get ("cl_pitchspeed", "150", CVAR_NONE, NULL,
"look up/down speed");
cl_sidespeed = Cvar_Get ("cl_sidespeed", "350", CVAR_NONE, NULL,
"strafe speed");
cl_upspeed = Cvar_Get ("cl_upspeed", "200", CVAR_NONE, NULL,
"swim/fly up/down speed");
cl_yawspeed = Cvar_Get ("cl_yawspeed", "140", CVAR_NONE, NULL,
"turning speed");
}
void
CL_Input_Activate (int in_game)
{
IMT_SetContext (!in_game ? cl_demo_context : cl_game_context);
IE_Set_Focus (cl_event_id);
}

View file

@ -30,14 +30,15 @@
#include <stdio.h>
#include "QF/input.h"
#include "QF/mathlib.h"
#include "QF/model.h"
#include "QF/quakefs.h"
#include "QF/sound.h"
#include "QF/render.h"
#include "client/chase.h"
#include "client/entities.h"
#include "client/input.h"
#include "client/state.h"
#include "client/view.h"
@ -160,6 +161,8 @@ typedef struct client_state_s {
vec4f_t frameVelocity[2]; // Update by server, used for lean+bob
// (0 is newest)
viewstate_t viewstate;
movestate_t movestate;
chasestate_t chasestate;
// pitch drifting vars
float idealpitch;
@ -230,18 +233,6 @@ typedef struct client_state_s {
extern struct cvar_s *cl_name;
extern struct cvar_s *cl_color;
extern struct cvar_s *cl_upspeed;
extern struct cvar_s *cl_forwardspeed;
extern struct cvar_s *cl_backspeed;
extern struct cvar_s *cl_sidespeed;
extern struct cvar_s *cl_movespeedkey;
extern struct cvar_s *cl_yawspeed;
extern struct cvar_s *cl_pitchspeed;
extern struct cvar_s *cl_anglespeedkey;
extern struct cvar_s *cl_autofire;
extern struct cvar_s *cl_shownet;
@ -250,12 +241,6 @@ extern struct cvar_s *cl_nolerp;
extern struct cvar_s *hud_sbar;
extern struct cvar_s *cl_pitchdriftspeed;
extern struct cvar_s *lookspring;
extern struct cvar_s *m_pitch;
extern struct cvar_s *m_yaw;
extern struct cvar_s *m_forward;
extern struct cvar_s *m_side;
extern struct cvar_s *cl_name;
extern struct cvar_s *cl_writecfg;
@ -297,8 +282,8 @@ void CL_NextDemo (void);
// cl_input
void CL_Input_Init (struct cbuf_s *cbuf);
void CL_Input_Activate (void);
void CL_Init_Input (struct cbuf_s *cbuf);
void CL_Init_Input_Cvars (void);
void CL_SendCmd (void);
void CL_SendMove (usercmd_t *cmd);
@ -325,9 +310,6 @@ void CL_NewTranslation (int slot, struct skin_s *skin);
// view
void V_StartPitchDrift (void);
void V_StopPitchDrift (void);
void V_UpdatePalette (void);
void V_Register (void);
void V_ParseDamage (void);
@ -339,12 +321,6 @@ void CL_SignonReply (void);
void CL_RelinkEntities (void);
void CL_ClearEnts (void);
extern in_button_t in_left, in_right, in_forward, in_back;
extern in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
extern in_button_t in_use, in_jump, in_attack;
extern in_button_t in_up, in_down;
extern in_button_t in_strafe, in_klook, in_speed, in_mlook;
extern double realtime;
extern qboolean recording;

View file

@ -71,7 +71,7 @@ nq_server_LIBS= $(nq_server_LIBFILES) $(nq_common_LIBFILES) $(NET_LIBS)
nq_server_LIB_DEPS=$(nq_server_LIBFILES) $(nq_common_LIBFILES)
nq_source_libnq_client_a_SOURCES= \
nq/source/cl_chase.c nq/source/cl_cmd.c nq/source/cl_demo.c nq/source/cl_ents.c nq/source/cl_input.c nq/source/cl_main.c \
nq/source/cl_cmd.c nq/source/cl_demo.c nq/source/cl_ents.c nq/source/cl_input.c nq/source/cl_main.c \
nq/source/cl_screen.c nq/source/cl_parse.c nq/source/cl_view.c nq/source/sbar.c
nq_source_libnq_server_a_SOURCES= \

View file

@ -50,7 +50,8 @@
#include "client/effects.h"
#include "client/temp_entities.h"
#include "nq/include/chase.h"
#include "client/chase.h"
#include "nq/include/client.h"
#include "nq/include/host.h"
#include "nq/include/host.h"

View file

@ -50,151 +50,9 @@
#include "client/input.h"
#include "nq/include/chase.h"
#include "nq/include/client.h"
#include "nq/include/host.h"
int cl_game_context;
int cl_demo_context;
static int cl_event_id;
in_axis_t viewdelta_position_forward = {
.mode = ina_set,
.name = "move.forward",
.description = "Move forward (negative) or backward (positive)",
};
in_axis_t viewdelta_position_side = {
.mode = ina_set,
.name = "move.side",
.description = "Move right (positive) or left (negative)",
};
in_axis_t viewdelta_position_up = {
.mode = ina_set,
.name = "move.up",
.description = "Move up (positive) or down (negative)",
};
in_axis_t viewdelta_angles_pitch = {
.mode = ina_set,
.name = "move.pitch",
.description = "Pitch axis",
};
in_axis_t viewdelta_angles_yaw = {
.mode = ina_set,
.name = "move.yaw",
.description = "Yaw axis",
};
in_axis_t viewdelta_angles_roll = {
.mode = ina_set,
.name = "move.roll",
.description = "Roll axis",
};
in_button_t in_left = {
.name = "left",
.description = "When active the player is turning left"
};
in_button_t in_right = {
.name = "right",
.description = "When active the player is turning right"
};
in_button_t in_forward = {
.name = "forward",
.description = "When active the player is moving forward"
};
in_button_t in_back = {
.name = "back",
.description = "When active the player is moving backwards"
};
in_button_t in_lookup = {
.name = "lookup",
.description = "When active the player's view is looking up"
};
in_button_t in_lookdown = {
.name = "lookdown",
.description = "When active the player's view is looking down"
};
in_button_t in_moveleft = {
.name = "moveleft",
.description = "When active the player is strafing left"
};
in_button_t in_moveright = {
.name = "moveright",
.description = "When active the player is strafing right"
};
in_button_t in_use = {
.name = "use",
.description = "Left over command for opening doors and triggering"
" switches"
};
in_button_t in_jump = {
.name = "jump",
.description = "When active the player is jumping"
};
in_button_t in_attack = {
.name = "attack",
.description = "When active player is firing/using current weapon"
};
in_button_t in_up = {
.name = "moveup",
.description = "When active the player is swimming up in a liquid"
};
in_button_t in_down = {
.name = "movedown",
.description = "When active the player is swimming down in a liquid"
};
in_button_t in_strafe = {
.name = "strafe",
.description = "When active, +left and +right function like +moveleft and"
" +moveright"
};
in_button_t in_klook = {
.name = "klook",
.description = "When active, +forward and +back perform +lookup and"
" +lookdown"
};
in_button_t in_speed = {
.name = "speed",
.description = "When active the player is running"
};
in_button_t in_mlook = {
.name = "mlook",
.description = "When active moving the mouse or joystick forwards "
"and backwards performs +lookup and "
"+lookdown"
};
static in_axis_t *cl_in_axes[] = {
&viewdelta_position_forward,
&viewdelta_position_side,
&viewdelta_position_up,
&viewdelta_angles_pitch,
&viewdelta_angles_yaw,
&viewdelta_angles_roll,
0,
};
static in_button_t *cl_in_buttons[] = {
&in_left,
&in_right,
&in_forward,
&in_back,
&in_lookup,
&in_lookdown,
&in_moveleft,
&in_moveright,
&in_use,
&in_jump,
&in_attack,
&in_up,
&in_down,
&in_strafe,
&in_klook,
&in_speed,
&in_mlook,
0
};
int in_impulse;
void (*write_angles) (sizebuf_t *sb, const vec3_t angles);
@ -205,74 +63,6 @@ IN_Impulse (void *data)
in_impulse = atoi (Cmd_Argv (1));
}
cvar_t *cl_anglespeedkey;
cvar_t *cl_backspeed;
cvar_t *cl_forwardspeed;
cvar_t *cl_movespeedkey;
cvar_t *cl_pitchspeed;
cvar_t *cl_sidespeed;
cvar_t *cl_upspeed;
cvar_t *cl_yawspeed;
/*
CL_AdjustAngles
Moves the local angle positions
*/
static void
CL_AdjustAngles (void)
{
float down, up;
float pitchspeed, yawspeed;
pitchspeed = cl_pitchspeed->value;
yawspeed = cl_yawspeed->value;
if (in_speed.state & inb_down) {
pitchspeed *= cl_anglespeedkey->value;
yawspeed *= cl_anglespeedkey->value;
}
if ((cl.fpd & FPD_LIMIT_PITCH) && pitchspeed > FPD_MAXPITCH)
pitchspeed = FPD_MAXPITCH;
if ((cl.fpd & FPD_LIMIT_YAW) && yawspeed > FPD_MAXYAW)
yawspeed = FPD_MAXYAW;
pitchspeed *= host_frametime;
yawspeed *= host_frametime;
if (!(in_strafe.state & inb_down)) {
cl.viewstate.angles[YAW] -= yawspeed * IN_ButtonState (&in_right);
cl.viewstate.angles[YAW] += yawspeed * IN_ButtonState (&in_left);
cl.viewstate.angles[YAW] = anglemod (cl.viewstate.angles[YAW]);
}
if (in_klook.state & inb_down) {
V_StopPitchDrift ();
cl.viewstate.angles[PITCH] -= pitchspeed * IN_ButtonState (&in_forward);
cl.viewstate.angles[PITCH] += pitchspeed * IN_ButtonState (&in_back);
}
up = IN_ButtonState (&in_lookup);
down = IN_ButtonState (&in_lookdown);
cl.viewstate.angles[PITCH] -= pitchspeed * up;
cl.viewstate.angles[PITCH] += pitchspeed * down;
if (up || down)
V_StopPitchDrift ();
// FIXME: Need to clean up view angle limits
if (cl.viewstate.angles[PITCH] > 80)
cl.viewstate.angles[PITCH] = 80;
if (cl.viewstate.angles[PITCH] < -70)
cl.viewstate.angles[PITCH] = -70;
if (cl.viewstate.angles[ROLL] > 50)
cl.viewstate.angles[ROLL] = 50;
if (cl.viewstate.angles[ROLL] < -50)
cl.viewstate.angles[ROLL] = -50;
}
/*
CL_BaseMove
@ -281,75 +71,17 @@ CL_AdjustAngles (void)
void
CL_BaseMove (usercmd_t *cmd)
{
if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring->int_val) {
V_StartPitchDrift ();
}
if (cls.state != ca_active) {
return;
}
CL_AdjustAngles ();
VectorCopy (cl.viewstate.angles, cl.movestate.angles);//FIXME
CL_Input_BuildMove (host_frametime, &cl.movestate);
VectorCopy (cl.movestate.angles, cl.viewstate.angles);//FIXME
memset (cmd, 0, sizeof (*cmd));
if (in_strafe.state & inb_down) {
cmd->sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
}
cmd->sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
cmd->upmove += cl_upspeed->value * IN_ButtonState (&in_up);
cmd->upmove -= cl_upspeed->value * IN_ButtonState (&in_down);
if (!(in_klook.state & inb_down)) {
cmd->forwardmove += cl_forwardspeed->value * IN_ButtonState (&in_forward);
cmd->forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
}
// adjust for speed key
if (in_speed.state & inb_down) {
cmd->forwardmove *= cl_movespeedkey->value;
cmd->sidemove *= cl_movespeedkey->value;
cmd->upmove *= cl_movespeedkey->value;
}
if (freelook)
V_StopPitchDrift ();
// adjust for chase camera angles
/*FIXME:chase figure out just what this does and get it working
if (cl.chase
&& (chase_active->int_val == 2 || chase_active->int_val == 3)) {
vec3_t forward, right, up, f, r;
vec3_t dir = {0, 0, 0};
dir[1] = r_data->refdef->viewangles[1] - cl.viewstate.angles[1];
AngleVectors (dir, forward, right, up);
VectorScale (forward, cmd->forwardmove, f);
VectorScale (right, cmd->sidemove, r);
cmd->forwardmove = f[0] + r[0];
cmd->sidemove = f[1] + r[1];
VectorScale (forward, viewdelta.position[2], f);
VectorScale (right, viewdelta.position[0], r);
viewdelta.position[2] = f[0] + r[0];
viewdelta.position[0] = (f[1] + r[1]) * -1;
}
*/
cmd->forwardmove -= IN_UpdateAxis (&viewdelta_position_forward) * m_forward->value;
cmd->sidemove += IN_UpdateAxis (&viewdelta_position_side) * m_side->value;
cmd->upmove -= IN_UpdateAxis (&viewdelta_position_up);
cl.viewstate.angles[PITCH] -= IN_UpdateAxis (&viewdelta_angles_pitch) * m_pitch->value;
cl.viewstate.angles[YAW] -= IN_UpdateAxis (&viewdelta_angles_yaw) * m_yaw->value;
cl.viewstate.angles[ROLL] -= IN_UpdateAxis (&viewdelta_angles_roll) * m_pitch->value;
if (freelook && !(in_strafe.state & inb_down)) {
cl.viewstate.angles[PITCH]
= bound (-70, cl.viewstate.angles[PITCH], 80);
}
cmd->forwardmove = cl.movestate.move[FORWARD];
cmd->sidemove = cl.movestate.move[SIDE];
cmd->upmove = cl.movestate.move[UP];
}
@ -404,42 +136,16 @@ CL_SendMove (usercmd_t *cmd)
}
}
static int
cl_event_handler (const IE_event_t *ie_event, void *unused)
{
if (ie_event->type == ie_key) {
if (ie_event->key.code == QFK_ESCAPE) {
Con_SetState (con_menu);
return 1;
}
}
return IN_Binding_HandleEvent (ie_event);
}
void
CL_Input_Init (cbuf_t *cbuf)
CL_Init_Input (cbuf_t *cbuf)
{
cl_event_id = IE_Add_Handler (cl_event_handler, 0);
for (int i = 0; cl_in_axes[i]; i++) {
IN_RegisterAxis (cl_in_axes[i]);
}
for (int i = 0; cl_in_buttons[i]; i++) {
IN_RegisterButton (cl_in_buttons[i]);
}
cl_game_context = IMT_CreateContext ("key_game");
IMT_SetContextCbuf (cl_game_context, cbuf);
cl_demo_context = IMT_CreateContext ("key_demo");
IMT_SetContextCbuf (cl_demo_context, cbuf);
CL_Input_Init (cbuf);
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
"Call a game function or QuakeC function.");
CL_Legacy_Init ();
}
void
CL_Input_Activate (void)
CL_Init_Input_Cvars (void)
{
host_in_game = !cls.demoplayback;
IMT_SetContext (cls.demoplayback ? cl_demo_context : cl_game_context);
IE_Set_Focus (cl_event_id);
CL_Input_Init_Cvars ();
}

View file

@ -55,7 +55,7 @@
#include "client/particles.h"
#include "client/temp_entities.h"
#include "nq/include/chase.h"
#include "client/chase.h"
#include "nq/include/cl_skin.h"
#include "nq/include/client.h"
#include "nq/include/host.h"
@ -81,13 +81,6 @@ cvar_t *cl_cshift_contents;
cvar_t *cl_cshift_damage;
cvar_t *cl_cshift_powerup;
cvar_t *lookspring;
cvar_t *m_pitch;
cvar_t *m_yaw;
cvar_t *m_forward;
cvar_t *m_side;
cvar_t *hud_fps;
cvar_t *hud_time;
@ -174,6 +167,7 @@ CL_InitCvars (void)
S_Init_Cvars ();
CL_Demo_Init ();
CL_Init_Input_Cvars ();
Chase_Init_Cvars ();
V_Init_Cvars ();
@ -188,38 +182,12 @@ CL_InitCvars (void)
cl_name = Cvar_Get ("_cl_name", "player", CVAR_ARCHIVE, NULL,
"Player name");
cl_color = Cvar_Get ("_cl_color", "0", CVAR_ARCHIVE, NULL, "Player color");
cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", CVAR_NONE, NULL,
"turn `run' speed multiplier");
cl_backspeed = Cvar_Get ("cl_backspeed", "200", CVAR_ARCHIVE, NULL,
"backward speed");
cl_forwardspeed = Cvar_Get ("cl_forwardspeed", "200", CVAR_ARCHIVE, NULL,
"forward speed");
cl_movespeedkey = Cvar_Get ("cl_movespeedkey", "2.0", CVAR_NONE, NULL,
"move `run' speed multiplier");
cl_pitchspeed = Cvar_Get ("cl_pitchspeed", "150", CVAR_NONE, NULL,
"look up/down speed");
cl_sidespeed = Cvar_Get ("cl_sidespeed", "350", CVAR_NONE, NULL,
"strafe speed");
cl_upspeed = Cvar_Get ("cl_upspeed", "200", CVAR_NONE, NULL,
"swim/fly up/down speed");
cl_yawspeed = Cvar_Get ("cl_yawspeed", "140", CVAR_NONE, NULL,
"turning speed");
cl_writecfg = Cvar_Get ("cl_writecfg", "1", CVAR_NONE, NULL,
"write config files?");
cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_NONE, NULL,
"show network packets. 0=off, 1=basic, 2=verbose");
cl_nolerp = Cvar_Get ("cl_nolerp", "0", CVAR_NONE, NULL,
"linear motion interpolation");
lookspring = Cvar_Get ("lookspring", "0", CVAR_ARCHIVE, NULL, "Snap view "
"to center when moving and no mlook/klook");
m_pitch = Cvar_Get ("m_pitch", "0.022", CVAR_ARCHIVE, NULL,
"mouse pitch (up/down) multipier");
m_yaw = Cvar_Get ("m_yaw", "0.022", CVAR_ARCHIVE, NULL,
"mouse yaw (left/right) multipiler");
m_forward = Cvar_Get ("m_forward", "1", CVAR_ARCHIVE, NULL,
"mouse forward/back speed");
m_side = Cvar_Get ("m_side", "0.8", CVAR_ARCHIVE, NULL,
"mouse strafe speed");
hud_fps = Cvar_Get ("hud_fps", "0", CVAR_ARCHIVE, NULL,
"display realtime frames per second");
Cvar_MakeAlias ("show_fps", hud_fps);
@ -564,7 +532,7 @@ CL_SetState (cactive_t state)
host_in_game = 0;
Con_SetState (state == ca_active ? con_inactive : con_fullscreen);
if (state != old_state && state == ca_active) {
CL_Input_Activate ();
CL_Input_Activate (host_in_game = !cls.demoplayback);
}
}
@ -603,7 +571,7 @@ CL_Init (cbuf_t *cbuf)
Sbar_Init ();
CL_Input_Init (cbuf);
CL_Init_Input (cbuf);
CL_Particles_Init ();
CL_TEnts_Init ();
CL_ClearState ();

View file

@ -40,7 +40,8 @@
#include "compat.h"
#include "nq/include/chase.h"
#include "client/chase.h"
#include "nq/include/client.h"
#include "nq/include/host.h"
@ -696,7 +697,7 @@ V_CalcRefdef (void)
}
if (cl.chase && chase_active->int_val) {
Chase_Update ();
Chase_Update (&cl.chasestate);
}
}

View file

@ -58,7 +58,8 @@
#include "buildnum.h"
#include "compat.h"
#include "nq/include/chase.h"
#include "client/chase.h"
#include "nq/include/host.h"
#include "nq/include/server.h"
#include "nq/include/sv_progs.h"

View file

@ -1,37 +0,0 @@
/*
chase.h
@description@
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifndef __chase_h
#define __chase_h
extern struct cvar_s *chase_active;
void Chase_Init_Cvars (void);
void Chase_Reset (void);
void Chase_Update (void);
#endif // __chase_h

View file

@ -28,15 +28,12 @@
#ifndef _CL_INPUT_H
#define _CL_INPUT_H
#include "QF/input.h"
#include "qw/protocol.h"
void CL_OnFocusChange (void (*func) (int game));
struct cbuf_s;
void CL_Input_Activate (void);
void CL_Input_Init (void);
void CL_Input_Init_Cvars (void);
void CL_Init_Input (struct cbuf_s *cbuf);
void CL_Init_Input_Cvars (void);
void CL_ClearStates (void);
void CL_SendCmd (void);
void CL_SendMove (usercmd_t *cmd);
@ -49,11 +46,6 @@ int CL_ReadFromServer (void);
void CL_WriteToServer (usercmd_t *cmd);
void CL_BaseMove (usercmd_t *cmd);
extern in_button_t in_left, in_right, in_forward, in_back;
extern in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
extern in_button_t in_use, in_jump, in_attack;
extern in_button_t in_up, in_down;
extern in_button_t in_strafe, in_klook, in_speed, in_mlook;
extern int in_impulse;
#endif

View file

@ -36,7 +36,9 @@
#include "QF/plugin/vid_render.h"
#include "QF/scene/entity.h"
#include "client/chase.h"
#include "client/entities.h"
#include "client/input.h"
#include "client/state.h"
#include "client/view.h"
@ -198,6 +200,8 @@ typedef struct client_state_s {
// the client maintains its own idea of view angles, which are sent to the
// server each frame. And reset only at level change and teleport times
viewstate_t viewstate;
movestate_t movestate;
chasestate_t chasestate;
// pitch drifting vars
float idealpitch;
float pitchvel;
@ -275,18 +279,6 @@ extern struct cvar_s *cl_netgraph_height;
extern struct cvar_s *cl_netgraph_alpha;
extern struct cvar_s *cl_netgraph_box;
extern struct cvar_s *cl_upspeed;
extern struct cvar_s *cl_forwardspeed;
extern struct cvar_s *cl_backspeed;
extern struct cvar_s *cl_sidespeed;
extern struct cvar_s *cl_movespeedkey;
extern struct cvar_s *cl_yawspeed;
extern struct cvar_s *cl_pitchspeed;
extern struct cvar_s *cl_anglespeedkey;
extern struct cvar_s *cl_draw_locs;
extern struct cvar_s *cl_shownet;
extern struct cvar_s *hud_sbar;
@ -294,12 +286,6 @@ extern struct cvar_s *hud_sbar_separator;
extern struct cvar_s *hud_swap;
extern struct cvar_s *cl_pitchdriftspeed;
extern struct cvar_s *lookspring;
extern struct cvar_s *m_pitch;
extern struct cvar_s *m_yaw;
extern struct cvar_s *m_forward;
extern struct cvar_s *m_side;
extern struct cvar_s *cl_name;

View file

@ -103,7 +103,7 @@ qw_client_libs= qw/source/libqw_client.a qw/source/libqw_common.a \
libs/client/libQFclient.la
qw_source_libqw_client_a_SOURCES= \
qw/source/cl_cam.c qw/source/cl_chase.c qw/source/cl_chat.c qw/source/cl_cmd.c qw/source/cl_cvar.c qw/source/cl_demo.c \
qw/source/cl_cam.c qw/source/cl_chat.c qw/source/cl_cmd.c qw/source/cl_cvar.c qw/source/cl_demo.c \
qw/source/cl_entparse.c qw/source/cl_ents.c qw/source/cl_http.c qw/source/cl_input.c qw/source/cl_main.c qw/source/cl_ngraph.c \
qw/source/cl_parse.c qw/source/cl_pred.c qw/source/cl_rss.c qw/source/cl_screen.c qw/source/cl_skin.c qw/source/cl_slist.c \
qw/source/cl_view.c \

View file

@ -48,7 +48,6 @@
#include "compat.h"
#include "sbar.h"
#include "qw/include/chase.h"
#include "qw/include/cl_cam.h"
#include "qw/include/cl_input.h"
#include "qw/include/client.h"

View file

@ -1,262 +0,0 @@
/*
cl_chase.c
chase camera support
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/cvar.h"
#include "QF/keys.h"
#include "QF/input.h"
#include "QF/mathlib.h"
#include "QF/plugin/vid_render.h"
#include "QF/simd/vec4f.h"
#include "qw/include/chase.h"
#include "qw/include/cl_input.h"
#include "qw/include/client.h"
#include "world.h"
vec4f_t camera_origin = {0,0,0,1};
vec4f_t player_origin = {0,0,0,1};
vec4f_t player_angles = {0,0,0,1};
vec3_t camera_angles = {0,0,0};
vec3_t chase_angles;
vec3_t chase_dest;
vec3_t chase_dest_angles;
vec3_t chase_pos;
cvar_t *chase_back;
cvar_t *chase_up;
cvar_t *chase_right;
cvar_t *chase_active;
void
Chase_Init_Cvars (void)
{
chase_back = Cvar_Get ("chase_back", "100", CVAR_NONE, NULL, "None");
chase_up = Cvar_Get ("chase_up", "16", CVAR_NONE, NULL, "None");
chase_right = Cvar_Get ("chase_right", "0", CVAR_NONE, NULL, "None");
chase_active = Cvar_Get ("chase_active", "0", CVAR_NONE, NULL, "None");
}
void
Chase_Reset (void)
{
// for respawning and teleporting
// start position 12 units behind head
}
static inline void
TraceLine (vec3_t start, vec3_t end, vec3_t impact)
{
trace_t trace;
memset (&trace, 0, sizeof (trace));
trace.fraction = 1;
MOD_TraceLine (cl.worldmodel->brush.hulls, 0, start, end, &trace);
VectorCopy (trace.endpos, impact);
}
void
Chase_Update (void)
{
float pitch, yaw, fwd;
usercmd_t cmd; // movement direction
vec4f_t forward = {}, up = {}, right = {}, stop = {}, dir = {};
// lazy camera, look toward player entity
if (chase_active->int_val == 2 || chase_active->int_val == 3) {
// control camera angles with key/mouse/joy-look
vec3_t d;
VectorSubtract (cl.viewstate.angles, player_angles, d);
VectorAdd (camera_angles, d, camera_angles);
if (chase_active->int_val == 2) {
if (camera_angles[PITCH] < -60)
camera_angles[PITCH] = -60;
if (camera_angles[PITCH] > 60)
camera_angles[PITCH] = 60;
}
// move camera, it's not enough to just change the angles because
// the angles are automatically changed to look toward the player
if (chase_active->int_val == 3) {
player_origin = r_data->refdef->viewposition;
}
AngleVectors (camera_angles, &forward[0], &right[0], &up[0]);
camera_origin = player_origin - chase_back->value * forward;
if (chase_active->int_val == 2) {
player_origin = r_data->refdef->viewposition;
// don't let camera get too low
if (camera_origin[2] < player_origin[2] + chase_up->value) {
camera_origin[2] = player_origin[2] + chase_up->value;
}
}
// don't let camera get too far from player
dir = camera_origin - player_origin;
forward = normalf (dir);
if (magnitudef (dir)[0] > chase_back->value) {
camera_origin = player_origin + forward * chase_back->value;
}
// check for walls between player and camera
camera_origin += 8 * forward;
//FIXME
TraceLine (&player_origin[0], &camera_origin[0], &stop[0]);
stop[3] = 1;
if (magnitude3f (stop)[0] != 0) {
camera_origin = stop - forward;
}
dir = camera_origin - r_data->refdef->viewposition;
forward = normalf (dir);
if (chase_active->int_val == 2) {
if (dir[1] == 0 && dir[0] == 0) {
// look straight up or down
// camera_angles[YAW] = r_data->refdef->viewstate.angles[YAW];
if (dir[2] > 0)
camera_angles[PITCH] = 90;
else
camera_angles[PITCH] = 270;
} else {
yaw = (atan2 (dir[1], dir[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
if (yaw < 180)
yaw += 180;
else
yaw -= 180;
camera_angles[YAW] = yaw;
fwd = sqrt (dir[0] * dir[0] + dir[1] * dir[1]);
pitch = (atan2 (dir[2], fwd) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
camera_angles[PITCH] = pitch;
}
}
AngleQuat (camera_angles, &r_data->refdef->viewrotation[0]);//FIXME rotate camera
r_data->refdef->viewposition = camera_origin; // move camera
// get basic movement from keyboard
memset (&cmd, 0, sizeof (cmd));
// VectorCopy (cl.viewstate.angles, cmd.angles);
if (in_strafe.state & 1) {
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
}
cmd.sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
cmd.sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
if (!(in_klook.state & 1)) {
cmd.forwardmove += cl_forwardspeed->value
* IN_ButtonState (&in_forward);
cmd.forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
}
if (in_speed.state & 1) {
cmd.forwardmove *= cl_movespeedkey->value;
cmd.sidemove *= cl_movespeedkey->value;
}
// mouse and joystick controllers add to movement
VectorSet (0, cl.viewstate.angles[1] - camera_angles[1], 0, dir);
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
//forward *= viewdelta.position[2] * m_forward->value; FIXME
//right *= viewdelta.position[0] * m_side->value; FIXME
dir = forward + right;
cmd.forwardmove += dir[0];
cmd.sidemove -= dir[1];
VectorSet (0, camera_angles[1], 0, dir);
AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME
VectorScale (forward, cmd.forwardmove, forward);
VectorScale (right, cmd.sidemove, right);
VectorAdd (forward, right, dir);
if (dir[1] || dir[0]) {
cl.viewstate.angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI);
if (cl.viewstate.angles[YAW] < 0) {
cl.viewstate.angles[YAW] += 360;
}
}
cl.viewstate.angles[PITCH] = 0;
// remember the new angle to calculate the difference next frame
VectorCopy (cl.viewstate.angles, player_angles);
return;
}
// regular camera, faces same direction as player
//FIXME
AngleVectors (cl.viewstate.angles, &forward[0], &right[0], &up[0]);
// calc exact destination
camera_origin = r_data->refdef->viewposition
- forward * chase_back->value - right * chase_right->value;
// chase_up is world up
camera_origin[2] += chase_up->value;
// check for walls between player and camera
//FIXME
TraceLine (&r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]);
stop[3] = 1;
if (magnitude3f (stop)[0] != 0) {
camera_origin = stop + forward * 8;
}
r_data->refdef->viewposition = camera_origin;
}

View file

@ -44,9 +44,10 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "client/input.h"
#include "qw/include/client.h"
#include "qw/include/cl_chat.h"
#include "qw/include/cl_input.h"
llist_t *ignore_list, *dead_ignore_list;

View file

@ -55,7 +55,6 @@
#include "qw/msg_ucmd.h"
#include "qw/pmove.h"
#include "qw/include/chase.h"
#include "qw/include/cl_cam.h"
#include "qw/include/cl_ents.h"
#include "qw/include/cl_main.h"

View file

@ -56,7 +56,6 @@
#include "qw/msg_ucmd.h"
#include "qw/include/chase.h"
#include "qw/include/cl_cam.h"
#include "qw/include/cl_demo.h"
#include "qw/include/cl_input.h"
@ -64,153 +63,10 @@
#include "qw/include/client.h"
#include "qw/include/host.h"
int cl_game_context;
int cl_demo_context;
static int cl_event_id;
static struct LISTENER_SET_TYPE(int) cl_on_focus_change
= LISTENER_SET_STATIC_INIT(4);
cvar_t *cl_nodelta;
cvar_t *cl_maxnetfps;
cvar_t *cl_spamimpulse;
in_axis_t viewdelta_position_forward = {
.mode = ina_set,
.name = "move.forward",
.description = "Move forward (negative) or backward (positive)",
};
in_axis_t viewdelta_position_side = {
.mode = ina_set,
.name = "move.side",
.description = "Move right (positive) or left (negative)",
};
in_axis_t viewdelta_position_up = {
.mode = ina_set,
.name = "move.up",
.description = "Move up (positive) or down (negative)",
};
in_axis_t viewdelta_angles_pitch = {
.mode = ina_set,
.name = "move.pitch",
.description = "Pitch axis",
};
in_axis_t viewdelta_angles_yaw = {
.mode = ina_set,
.name = "move.yaw",
.description = "Yaw axis",
};
in_axis_t viewdelta_angles_roll = {
.mode = ina_set,
.name = "move.roll",
.description = "Roll axis",
};
in_button_t in_left = {
.name = "left",
.description = "When active the player is turning left"
};
in_button_t in_right = {
.name = "right",
.description = "When active the player is turning right"
};
in_button_t in_forward = {
.name = "forward",
.description = "When active the player is moving forward"
};
in_button_t in_back = {
.name = "back",
.description = "When active the player is moving backwards"
};
in_button_t in_lookup = {
.name = "lookup",
.description = "When active the player's view is looking up"
};
in_button_t in_lookdown = {
.name = "lookdown",
.description = "When active the player's view is looking down"
};
in_button_t in_moveleft = {
.name = "moveleft",
.description = "When active the player is strafing left"
};
in_button_t in_moveright = {
.name = "moveright",
.description = "When active the player is strafing right"
};
in_button_t in_use = {
.name = "use",
.description = "Left over command for opening doors and triggering"
" switches"
};
in_button_t in_jump = {
.name = "jump",
.description = "When active the player is jumping"
};
in_button_t in_attack = {
.name = "attack",
.description = "When active player is firing/using current weapon"
};
in_button_t in_up = {
.name = "moveup",
.description = "When active the player is swimming up in a liquid"
};
in_button_t in_down = {
.name = "movedown",
.description = "When active the player is swimming down in a liquid"
};
in_button_t in_strafe = {
.name = "strafe",
.description = "When active, +left and +right function like +moveleft and"
" +moveright"
};
in_button_t in_klook = {
.name = "klook",
.description = "When active, +forward and +back perform +lookup and"
" +lookdown"
};
in_button_t in_speed = {
.name = "speed",
.description = "When active the player is running"
};
in_button_t in_mlook = {
.name = "mlook",
.description = "When active moving the mouse or joystick forwards "
"and backwards performs +lookup and "
"+lookdown"
};
static in_axis_t *cl_in_axes[] = {
&viewdelta_position_forward,
&viewdelta_position_side,
&viewdelta_position_up,
&viewdelta_angles_pitch,
&viewdelta_angles_yaw,
&viewdelta_angles_roll,
0,
};
static in_button_t *cl_in_buttons[] = {
&in_left,
&in_right,
&in_forward,
&in_back,
&in_lookup,
&in_lookdown,
&in_moveleft,
&in_moveright,
&in_use,
&in_jump,
&in_attack,
&in_up,
&in_down,
&in_strafe,
&in_klook,
&in_speed,
&in_mlook,
0
};
int in_impulse;
static void
@ -223,74 +79,6 @@ IN_Impulse (void *data)
Team_BestWeaponImpulse (); // HACK HACK HACK
}
cvar_t *cl_anglespeedkey;
cvar_t *cl_backspeed;
cvar_t *cl_forwardspeed;
cvar_t *cl_movespeedkey;
cvar_t *cl_pitchspeed;
cvar_t *cl_sidespeed;
cvar_t *cl_upspeed;
cvar_t *cl_yawspeed;
/*
CL_AdjustAngles
Moves the local angle positions
*/
static void
CL_AdjustAngles (void)
{
float down, up;
float pitchspeed, yawspeed;
pitchspeed = cl_pitchspeed->value;
yawspeed = cl_yawspeed->value;
if (in_speed.state & inb_down) {
pitchspeed *= cl_anglespeedkey->value;
yawspeed *= cl_anglespeedkey->value;
}
if ((cl.fpd & FPD_LIMIT_PITCH) && pitchspeed > FPD_MAXPITCH)
pitchspeed = FPD_MAXPITCH;
if ((cl.fpd & FPD_LIMIT_YAW) && yawspeed > FPD_MAXYAW)
yawspeed = FPD_MAXYAW;
pitchspeed *= host_frametime;
yawspeed *= host_frametime;
if (!(in_strafe.state & inb_down)) {
cl.viewstate.angles[YAW] -= yawspeed * IN_ButtonState (&in_right);
cl.viewstate.angles[YAW] += yawspeed * IN_ButtonState (&in_left);
cl.viewstate.angles[YAW] = anglemod (cl.viewstate.angles[YAW]);
}
if (in_klook.state & inb_down) {
V_StopPitchDrift ();
cl.viewstate.angles[PITCH] -= pitchspeed * IN_ButtonState (&in_forward);
cl.viewstate.angles[PITCH] += pitchspeed * IN_ButtonState (&in_back);
}
up = IN_ButtonState (&in_lookup);
down = IN_ButtonState (&in_lookdown);
cl.viewstate.angles[PITCH] -= pitchspeed * up;
cl.viewstate.angles[PITCH] += pitchspeed * down;
if (up || down)
V_StopPitchDrift ();
// FIXME: Need to clean up view angle limits
if (cl.viewstate.angles[PITCH] > 80)
cl.viewstate.angles[PITCH] = 80;
if (cl.viewstate.angles[PITCH] < -70)
cl.viewstate.angles[PITCH] = -70;
if (cl.viewstate.angles[ROLL] > 50)
cl.viewstate.angles[ROLL] = 50;
if (cl.viewstate.angles[ROLL] < -50)
cl.viewstate.angles[ROLL] = -50;
}
/*
CL_BaseMove
@ -299,76 +87,18 @@ CL_AdjustAngles (void)
void
CL_BaseMove (usercmd_t *cmd)
{
if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring->int_val) {
V_StartPitchDrift ();
}
if (cls.state != ca_active) {
return;
}
CL_AdjustAngles ();
VectorCopy (cl.viewstate.angles, cl.movestate.angles);//FIXME
CL_Input_BuildMove (host_frametime, &cl.movestate);
VectorCopy (cl.movestate.angles, cl.viewstate.angles);//FIXME
memset (cmd, 0, sizeof (*cmd));
VectorCopy (cl.viewstate.angles, cmd->angles);
if (in_strafe.state & inb_down) {
cmd->sidemove += cl_sidespeed->value * IN_ButtonState (&in_right);
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_left);
}
cmd->sidemove += cl_sidespeed->value * IN_ButtonState (&in_moveright);
cmd->sidemove -= cl_sidespeed->value * IN_ButtonState (&in_moveleft);
cmd->upmove += cl_upspeed->value * IN_ButtonState (&in_up);
cmd->upmove -= cl_upspeed->value * IN_ButtonState (&in_down);
if (!(in_klook.state & inb_down)) {
cmd->forwardmove += cl_forwardspeed->value * IN_ButtonState (&in_forward);
cmd->forwardmove -= cl_backspeed->value * IN_ButtonState (&in_back);
}
// adjust for speed key
if (in_speed.state & inb_down) {
cmd->forwardmove *= cl_movespeedkey->value;
cmd->sidemove *= cl_movespeedkey->value;
cmd->upmove *= cl_movespeedkey->value;
}
if (freelook)
V_StopPitchDrift ();
// adjust for chase camera angles
/*FIXME:chase figure out just what this does and get it working
if (cl.chase
&& (chase_active->int_val == 2 || chase_active->int_val == 3)) {
vec3_t forward, right, up, f, r;
vec3_t dir = {0, 0, 0};
dir[1] = r_data->refdef->viewangles[1] - cl.viewstate.angles[1];
AngleVectors (dir, forward, right, up);
VectorScale (forward, cmd->forwardmove, f);
VectorScale (right, cmd->sidemove, r);
cmd->forwardmove = f[0] + r[0];
cmd->sidemove = f[1] + r[1];
VectorScale (forward, viewdelta.position[2], f);
VectorScale (right, viewdelta.position[0], r);
viewdelta.position[2] = f[0] + r[0];
viewdelta.position[0] = (f[1] + r[1]) * -1;
}
*/
cmd->forwardmove -= IN_UpdateAxis (&viewdelta_position_forward) * m_forward->value;
cmd->sidemove += IN_UpdateAxis (&viewdelta_position_side) * m_side->value;
cmd->upmove -= IN_UpdateAxis (&viewdelta_position_up);
cl.viewstate.angles[PITCH] -= IN_UpdateAxis (&viewdelta_angles_pitch) * m_pitch->value;
cl.viewstate.angles[YAW] -= IN_UpdateAxis (&viewdelta_angles_yaw) * m_yaw->value;
cl.viewstate.angles[ROLL] -= IN_UpdateAxis (&viewdelta_angles_roll) * m_pitch->value;
if (freelook && !(in_strafe.state & inb_down)) {
cl.viewstate.angles[PITCH]
= bound (-70, cl.viewstate.angles[PITCH], 80);
}
cmd->forwardmove = cl.movestate.move[FORWARD];
cmd->sidemove = cl.movestate.move[SIDE];
cmd->upmove = cl.movestate.move[UP];
VectorCopy (cl.movestate.angles, cmd->angles);
}
static int
@ -564,82 +294,18 @@ CL_SendCmd (void)
Netchan_Transmit (&cls.netchan, buf.cursize, buf.data);
}
static int
cl_key_event (const IE_event_t *ie_event)
{
if (ie_event->key.code == QFK_ESCAPE) {
Con_SetState (con_menu);
return 1;
}
return 0;
}
static void
cl_on_focus_change_redirect (void *_func, const int *game)
{
void (*func) (int game) = _func;
func (*game);
}
void
CL_OnFocusChange (void (*func) (int game))
CL_Init_Input (cbuf_t *cbuf)
{
LISTENER_ADD (&cl_on_focus_change, cl_on_focus_change_redirect, func);
}
static int
cl_focus_event (const IE_event_t *ie_event)
{
int game = ie_event->type == ie_gain_focus;
LISTENER_INVOKE (&cl_on_focus_change, &game);
return 1;
}
static int
cl_event_handler (const IE_event_t *ie_event, void *unused)
{
static int (*handlers[ie_event_count]) (const IE_event_t *ie_event) = {
[ie_key] = cl_key_event,
[ie_gain_focus] = cl_focus_event,
[ie_lose_focus] = cl_focus_event,
};
if (ie_event->type < 0 || ie_event->type >= ie_event_count
|| !handlers[ie_event->type]) {
return IN_Binding_HandleEvent (ie_event);
}
return handlers[ie_event->type] (ie_event);
}
void
CL_Input_Init (void)
{
cl_event_id = IE_Add_Handler (cl_event_handler, 0);
for (int i = 0; cl_in_axes[i]; i++) {
IN_RegisterAxis (cl_in_axes[i]);
}
for (int i = 0; cl_in_buttons[i]; i++) {
IN_RegisterButton (cl_in_buttons[i]);
}
cl_game_context = IMT_CreateContext ("key_game");
IMT_SetContextCbuf (cl_game_context, cl_cbuf);
cl_demo_context = IMT_CreateContext ("key_demo");
IMT_SetContextCbuf (cl_demo_context, cl_cbuf);
CL_Input_Init (cbuf);
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
"Call a game function or QuakeC function.");
CL_Legacy_Init ();
}
void
CL_Input_Activate (void)
{
IMT_SetContext (cls.demoplayback ? cl_demo_context : cl_game_context);
IE_Set_Focus (cl_event_id);
}
void
CL_Input_Init_Cvars (void)
CL_Init_Input_Cvars (void)
{
CL_Input_Init_Cvars ();
cl_nodelta = Cvar_Get ("cl_nodelta", "0", CVAR_NONE, NULL,
"Disable player delta compression. Set to 1 if you "
"have a poor ISP and get many U_REMOVE warnings.");

View file

@ -158,13 +158,6 @@ cvar_t *cl_cshift_powerup;
cvar_t *cl_model_crcs;
cvar_t *lookspring;
cvar_t *m_pitch;
cvar_t *m_yaw;
cvar_t *m_forward;
cvar_t *m_side;
cvar_t *cl_predict_players;
cvar_t *cl_solid_players;
@ -1172,7 +1165,7 @@ CL_SetState (cactive_t state)
}
Con_SetState (state == ca_active ? con_inactive : con_fullscreen);
if (state != old_state && state == ca_active) {
CL_Input_Activate ();
CL_Input_Activate (!cls.demoplayback);
}
}
@ -1211,7 +1204,7 @@ CL_Init (void)
Sbar_Init ();
CL_Input_Init ();
CL_Init_Input (cl_cbuf);
CL_Ents_Init ();
CL_Particles_Init ();
CL_TEnts_Init ();
@ -1312,6 +1305,23 @@ cl_cmd_pkt_adr_f (cvar_t *var)
memset (&cl_cmd_packet_address, 0, sizeof (cl_cmd_packet_address));
}
static void
cl_pitchspeed_f (cvar_t *var)
{
if ((cl.fpd & FPD_LIMIT_PITCH) && var->value > FPD_MAXPITCH) {
var->value = FPD_MAXPITCH;
}
}
static void
cl_yawspeed_f (cvar_t *var)
{
if ((cl.fpd & FPD_LIMIT_YAW) && var->value > FPD_MAXYAW) {
var->value = FPD_MAXYAW;
}
}
static void
CL_Init_Cvars (void)
{
@ -1321,7 +1331,7 @@ CL_Init_Cvars (void)
S_Init_Cvars ();
CL_Cam_Init_Cvars ();
CL_Input_Init_Cvars ();
CL_Init_Input_Cvars ();
CL_Prediction_Init_Cvars ();
CL_NetGraph_Init_Cvars ();
Game_Init_Cvars ();
@ -1329,6 +1339,9 @@ CL_Init_Cvars (void)
Team_Init_Cvars ();
V_Init_Cvars ();
cl_pitchspeed->callback = cl_pitchspeed_f;
cl_yawspeed->callback = cl_yawspeed_f;
cls.userinfo = Info_ParseString ("", MAX_INFO_STRING, 0);
cl_model_crcs = Cvar_Get ("cl_model_crcs", "1", CVAR_ARCHIVE, NULL,
@ -1358,24 +1371,8 @@ CL_Init_Cvars (void)
"Shift view colors on damage");
cl_cshift_powerup = Cvar_Get ("cl_cshift_powerup", "1", CVAR_ARCHIVE, NULL,
"Shift view colors for powerups");
cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", CVAR_NONE, NULL,
"turn `run' speed multiplier");
cl_backspeed = Cvar_Get ("cl_backspeed", "200", CVAR_ARCHIVE, NULL,
"backward speed");
cl_fb_players = Cvar_Get ("cl_fb_players", "0", CVAR_ARCHIVE, NULL, "fullbrightness of player models. "
"server must allow (via fbskins serverinfo).");
cl_forwardspeed = Cvar_Get ("cl_forwardspeed", "200", CVAR_ARCHIVE, NULL,
"forward speed");
cl_movespeedkey = Cvar_Get ("cl_movespeedkey", "2.0", CVAR_NONE, NULL,
"move `run' speed multiplier");
cl_pitchspeed = Cvar_Get ("cl_pitchspeed", "150", CVAR_NONE, NULL,
"look up/down speed");
cl_sidespeed = Cvar_Get ("cl_sidespeed", "350", CVAR_NONE, NULL,
"strafe speed");
cl_upspeed = Cvar_Get ("cl_upspeed", "200", CVAR_NONE, NULL,
"swim/fly up/down speed");
cl_yawspeed = Cvar_Get ("cl_yawspeed", "140", CVAR_NONE, NULL,
"turning speed");
cl_writecfg = Cvar_Get ("cl_writecfg", "1", CVAR_NONE, NULL,
"write config files?");
cl_draw_locs = Cvar_Get ("cl_draw_locs", "0", CVAR_NONE, NULL,
@ -1388,16 +1385,6 @@ CL_Init_Cvars (void)
"connection timeout (since last packet received)");
host_speeds = Cvar_Get ("host_speeds", "0", CVAR_NONE, NULL,
"display host processing times");
lookspring = Cvar_Get ("lookspring", "0", CVAR_ARCHIVE, NULL, "Snap view "
"to center when moving and no mlook/klook");
m_forward = Cvar_Get ("m_forward", "1", CVAR_ARCHIVE, NULL,
"mouse forward/back speed");
m_pitch = Cvar_Get ("m_pitch", "0.022", CVAR_ARCHIVE, NULL,
"mouse pitch (up/down) multipier");
m_side = Cvar_Get ("m_side", "0.8", CVAR_ARCHIVE, NULL,
"mouse strafe speed");
m_yaw = Cvar_Get ("m_yaw", "0.022", CVAR_ARCHIVE, NULL,
"mouse yaw (left/right) multiplier");
rcon_password = Cvar_Get ("rcon_password", "", CVAR_NONE, NULL,
"remote control password");
rcon_address = Cvar_Get ("rcon_address", "", CVAR_NONE, NULL, "server IP "

View file

@ -39,7 +39,7 @@
#include "qw/bothdefs.h"
#include "qw/include/chase.h"
#include "client/chase.h"
#include "qw/include/cl_cam.h"
#include "qw/include/cl_ents.h"
#include "qw/include/cl_main.h"
@ -701,7 +701,7 @@ V_CalcRefdef (void)
}
if (cl.chase && chase_active->int_val) {
Chase_Update ();
Chase_Update (&cl.chasestate);
}
}