Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
BraXi committed Sep 16, 2024
1 parent 6392e5d commit 3ace916
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 58 deletions.
5 changes: 3 additions & 2 deletions src/engine/client/cl_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void Con_Print (char *txt)
}
}


#if 0 // unused
/*
==============
Con_CenteredPrint
Expand All @@ -428,6 +428,7 @@ void Con_CenteredPrint (char *text)
strcat (buffer, "\n");
Con_Print (buffer);
}
#endif

/*
==============================================================================
Expand Down Expand Up @@ -555,7 +556,7 @@ void Con_DrawNotify (void)
if (cls.state != CS_ACTIVE)
return;

v = viddef.height - ((viddef.height / 5));
v = viddef.height - ((viddef.height / 4));
for (i= con.current-NUM_CON_TIMES+1 ; i<=con.current ; i++)
{
if (i < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/engine/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See the attached GNU General Public License v2 for more details.

#include "client.h"

cvar_t *freelook;
cvar_t *cl_freelook;

cvar_t *rcon_client_password;
cvar_t *rcon_address;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ void CL_InitLocal (void)
cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", 0, NULL);

cl_run = Cvar_Get ("cl_run", "0", CVAR_ARCHIVE, NULL);
freelook = Cvar_Get( "freelook", "1", CVAR_ARCHIVE, NULL);
cl_freelook = Cvar_Get( "cl_freelook", "1", CVAR_ARCHIVE, NULL);
lookspring = Cvar_Get ("lookspring", "0", CVAR_ARCHIVE, NULL);
lookstrafe = Cvar_Get ("lookstrafe", "0", CVAR_ARCHIVE, NULL);
sensitivity = Cvar_Get ("sensitivity", "3", CVAR_ARCHIVE, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ extern cvar_t *m_yaw;
extern cvar_t *m_forward;
extern cvar_t *m_side;

extern cvar_t *freelook;
extern cvar_t *cl_freelook;

extern cvar_t *cl_paused;
extern cvar_t *cl_timedemo;
Expand Down
17 changes: 11 additions & 6 deletions src/engine/client/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ Copyright (C) 1997-2001 Id Software, Inc.
See the attached GNU General Public License v2 for more details.
*/

//
// console
//
// cl_console.h

#ifndef _PRAGMA_CL_CONSOLE_H_
#define _PRAGMA_CL_CONSOLE_H_

#pragma once

#define NUM_CON_TIMES 8
#define CON_TEXTSIZE 32768

#define CON_TEXTSIZE 32768
typedef struct
{
qboolean initialized;
Expand All @@ -37,14 +40,16 @@ typedef struct
// for transparent notify lines
} console_t;

extern console_t con;
extern console_t con;

void Con_CheckResize (void);
void Con_Init (void);
void Con_DrawConsole (float frac);
void Con_Print (char *txt);
void Con_CenteredPrint (char *text);
//void Con_CenteredPrint (char *text);
void Con_Clear_f (void);
void Con_DrawNotify (void);
void Con_ClearNotify (void);
void Con_ToggleConsole_f (void);

#endif /*_PRAGMA_CL_CONSOLE_H_*/
5 changes: 5 additions & 0 deletions src/engine/client/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ See the attached GNU General Public License v2 for more details.

// input.h -- external (non-keyboard) input devices

#ifndef _PRAGMA_INPUT_H_
#define _PRAGMA_INPUT_H_

void IN_Init (void);

void IN_Shutdown (void);
Expand All @@ -23,3 +26,5 @@ void IN_Move (usercmd_t *cmd);
// add additional movement on top of the keyboard move cmd

void IN_Activate (qboolean active);

#endif /*_PRAGMA_INPUT_H_*/
118 changes: 71 additions & 47 deletions src/engine/client/input_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,36 @@ cvar_t *m_filter;

qboolean mlooking;

void IN_MLookDown (void) { mlooking = true; }
void IN_MLookUp (void) {
mlooking = false;
if (!freelook->value && lookspring->value)
IN_CenterView ();
void IN_MLookDown (void)
{
mlooking = true;
}

int mouse_buttons;
int mouse_oldbuttonstate;
POINT current_pos;
int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;

int old_x, old_y;
void IN_MLookUp (void)
{
mlooking = false;
if (!cl_freelook->value && lookspring->value)
IN_CenterView ();
}

static int mouse_buttons;
static int mouse_oldbuttonstate;
static int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
static POINT current_pos;

qboolean mouseactive; // false when not focus app

qboolean restore_spi;
qboolean mouseinitialized;
int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
qboolean mouseparmsvalid;
static int originalmouseparms[3];
static int newmouseparms[3] = { 0, 0, 1 };;

int window_center_x, window_center_y;
RECT window_rect;
static qboolean bMouseActive; // false when not focus app
static qboolean bRestoreMouseSPI;
static qboolean bMouseInitialized;
static qboolean bMouseParamsValid;

static int window_center_x, window_center_y;
static int window_center_x_old, window_center_y_old;
static RECT window_rect;


/*
Expand All @@ -69,27 +76,33 @@ Called when the window gains focus or changes in some way
*/
void IN_ActivateMouse (void)
{
int width, height;
int width, height;

if (!mouseinitialized)
if (!bMouseInitialized)
{
return;
}

if (!in_mouse->value)
{
mouseactive = false;
bMouseActive = false;
return;
}
if (mouseactive)

if (bMouseActive)
{
return;
}

mouseactive = true;
bMouseActive = true;

if (mouseparmsvalid)
restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
if (bMouseParamsValid)
bRestoreMouseSPI = SystemParametersInfo(SPI_SETMOUSE, 0, newmouseparms, 0);

width = GetSystemMetrics (SM_CXSCREEN);
height = GetSystemMetrics (SM_CYSCREEN);
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);

GetWindowRect ( cl_hwnd, &window_rect);
GetWindowRect(cl_hwnd, &window_rect);
if (window_rect.left < 0)
window_rect.left = 0;
if (window_rect.top < 0)
Expand All @@ -104,8 +117,8 @@ void IN_ActivateMouse (void)

SetCursorPos (window_center_x, window_center_y);

old_x = window_center_x;
old_y = window_center_y;
window_center_x_old = window_center_x;
window_center_y_old = window_center_y;

SetCapture ( cl_hwnd );
ClipCursor (&window_rect);
Expand All @@ -123,18 +136,27 @@ Called when the window loses focus
*/
void IN_DeactivateMouse (void)
{
if (!mouseinitialized)
if (!bMouseInitialized)
{
return;
if (!mouseactive)
}

if (!bMouseActive)
{
return;
}

if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
if (bRestoreMouseSPI)
{
SystemParametersInfo(SPI_SETMOUSE, 0, originalmouseparms, 0);
}

mouseactive = false;
bMouseActive = false;

ClipCursor (NULL);
ReleaseCapture ();

// evil..
while (ShowCursor (TRUE) < 0)
;
}
Expand All @@ -154,8 +176,8 @@ void IN_StartupMouse (void)
if ( !cv->value )
return;

mouseinitialized = true;
mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
bMouseInitialized = true;
bMouseParamsValid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
mouse_buttons = 3;
}

Expand All @@ -164,24 +186,22 @@ void IN_StartupMouse (void)
IN_MouseEvent
===========
*/
void IN_MouseEvent (int mstate)
void IN_MouseEvent(int mstate)
{
int i;

if (!mouseinitialized)
if (!bMouseInitialized)
return;

// perform button actions
for (i=0 ; i<mouse_buttons ; i++)
for (i = 0 ; i < mouse_buttons; i++)
{
if ( (mstate & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
if ( (mstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, true, sys_msg_time);
}

if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
if ( !(mstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, false, sys_msg_time);
}
Expand All @@ -200,12 +220,16 @@ void IN_MouseMove (usercmd_t *cmd)
{
int mx, my;

if (!mouseactive)
if (!bMouseActive)
{
return;
}

// find mouse movement
if (!GetCursorPos (&current_pos))
{
return;
}

mx = current_pos.x - window_center_x;
my = current_pos.y - window_center_y;
Expand Down Expand Up @@ -238,7 +262,7 @@ void IN_MouseMove (usercmd_t *cmd)
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;

if ( (mlooking || freelook->value) && !(in_strafe.state & 1))
if ( (mlooking || cl_freelook->value) && !(in_strafe.state & 1))
{
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
}
Expand Down Expand Up @@ -309,7 +333,7 @@ between a deactivate and an activate.
void IN_Activate (qboolean active)
{
in_appactive = active;
mouseactive = !active; // force a new window check or turn off
bMouseActive = !active; // force a new window check or turn off
}


Expand All @@ -322,7 +346,7 @@ Called every frame, even if not generating commands
*/
void IN_Frame (void)
{
if (!mouseinitialized)
if (!bMouseInitialized)
return;

if (!in_mouse || !in_appactive)
Expand Down

0 comments on commit 3ace916

Please sign in to comment.