From fbd76d6d683f1fb429e23d75e63824f3bec26aee Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 1 Sep 2020 18:07:37 +0300 Subject: [PATCH] client: fix build --- cl_dll/cdll_int.cpp | 2 +- cl_dll/entity.cpp | 4 +- cl_dll/getfont.h | 4 +- cl_dll/health.cpp | 2 +- cl_dll/hud.cpp | 6 +- cl_dll/hud_redraw.cpp | 7 +- cl_dll/hud_servers.cpp | 10 +- cl_dll/input_goldsource.cpp | 1628 +++++++++++++++++++++++++ cl_dll/input_mouse.cpp | 93 ++ cl_dll/input_mouse.h | 79 ++ cl_dll/input_xash3d.cpp | 293 +++++ cl_dll/{inputw32.cpp => inputw32.old} | 0 cl_dll/render/gl_aurora.cpp | 9 +- cl_dll/render/gl_backend.cpp | 3 +- cl_dll/render/gl_cubemaps.cpp | 6 +- cl_dll/render/gl_deferred.cpp | 6 +- cl_dll/render/gl_dlight.cpp | 5 +- cl_dll/render/gl_export.cpp | 15 +- cl_dll/render/gl_grass.cpp | 5 +- cl_dll/render/gl_shadows.cpp | 4 +- cl_dll/render/gl_sprite.cpp | 2 +- cl_dll/render/gl_studiodecal.h | 2 +- cl_dll/render/gl_studiodecal_new.cpp | 4 +- cl_dll/render/gl_world_new.cpp | 22 +- cl_dll/render/tri.cpp | 4 +- cl_dll/saytext.cpp | 5 +- cl_dll/status_icons.cpp | 5 +- cl_dll/util.cpp | 11 +- cl_dll/vgui_CustomObjects.cpp | 2 +- cl_dll/vgui_ScorePanel.cpp | 15 +- cl_dll/vgui_TeamFortressViewport.cpp | 11 +- cl_dll/vgui_TeamFortressViewport.h | 12 +- cl_dll/vgui_radio.cpp | 2 +- cl_dll/vgui_screenmsg.h | 6 +- cl_dll/vgui_tips.cpp | 3 - common/port.h | 9 + game_shared/mathlib.h | 17 +- game_shared/matrix.h | 2 +- game_shared/utlblockmemory.h | 5 +- game_shared/vgui_slider2.cpp | 2 +- game_shared/virtualfs.cpp | 33 + utils/vgui | 2 +- wscript | 2 +- 43 files changed, 2260 insertions(+), 99 deletions(-) create mode 100644 cl_dll/input_goldsource.cpp create mode 100644 cl_dll/input_mouse.cpp create mode 100644 cl_dll/input_mouse.h create mode 100644 cl_dll/input_xash3d.cpp rename cl_dll/{inputw32.cpp => inputw32.old} (100%) create mode 100644 game_shared/virtualfs.cpp diff --git a/cl_dll/cdll_int.cpp b/cl_dll/cdll_int.cpp index 762f6be..517aa9b 100644 --- a/cl_dll/cdll_int.cpp +++ b/cl_dll/cdll_int.cpp @@ -341,4 +341,4 @@ void DLLEXPORT HUD_ClipMoveToEntity( physent_t *pe, const float *start, float *m if( trace.ent != NULL && PM_GetPlayerMove( )) tr->ent = pe - PM_GetPlayerMove()->physents; else tr->ent = -1; -} \ No newline at end of file +} diff --git a/cl_dll/entity.cpp b/cl_dll/entity.cpp index f1ecfcf..4354d21 100644 --- a/cl_dll/entity.cpp +++ b/cl_dll/entity.cpp @@ -22,8 +22,6 @@ #include "gl_local.h" #include "gl_studio.h" -#define DLLEXPORT __declspec( dllexport ) - void Game_AddObjects( void ); extern vec3_t v_origin; @@ -934,4 +932,4 @@ Indices must start at 1, not zero. cl_entity_t DLLEXPORT *HUD_GetUserEntity( int index ) { return NULL; -} \ No newline at end of file +} diff --git a/cl_dll/getfont.h b/cl_dll/getfont.h index 474a6f1..640dc81 100644 --- a/cl_dll/getfont.h +++ b/cl_dll/getfont.h @@ -6,6 +6,6 @@ #ifndef _GETFONT_H #define _GETFONT_H -Font* FontFromMessage(const char* &ptext); +Font* FontFromMessage(const char* ptext); -#endif // _GETFONT_H \ No newline at end of file +#endif // _GETFONT_H diff --git a/cl_dll/health.cpp b/cl_dll/health.cpp index e46a669..0578d0e 100644 --- a/cl_dll/health.cpp +++ b/cl_dll/health.cpp @@ -427,7 +427,7 @@ int CHudHealth::DrawDamage(float flTime) // check for bits that should be expired - for ( i = 0; i < NUM_DMG_TYPES; i++ ) + for (int i = 0; i < NUM_DMG_TYPES; i++ ) { DAMAGE_IMAGE *pdmg = &m_dmg[i]; diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index ae0070b..883c3e3 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -36,7 +36,7 @@ #include "studio.h" #include "demo.h" #include "demo_api.h" -#include "vgui_scorepanel.h" +#include "vgui_ScorePanel.h" #include "gl_local.h" // buz #include "r_studioint.h" @@ -708,7 +708,7 @@ void CHud :: VidInit( void ) p = m_pSpriteList; int index = 0; - for ( j = 0; j < m_iSpriteCountAllRes; j++ ) + for ( int j = 0; j < m_iSpriteCountAllRes; j++ ) { if ( p->iRes == m_iRes ) { @@ -886,4 +886,4 @@ void CHud::AddHudElem(CHudBase *phudelem) float CHud::GetSensitivity( void ) { return m_flMouseSensitivity; -} \ No newline at end of file +} diff --git a/cl_dll/hud_redraw.cpp b/cl_dll/hud_redraw.cpp index 7b7bf7e..89256d2 100644 --- a/cl_dll/hud_redraw.cpp +++ b/cl_dll/hud_redraw.cpp @@ -158,7 +158,7 @@ int CHud :: Redraw( float flTime, int intermission ) m_fOldTime = m_flTime; // save time of previous redraw m_flTime = flTime; m_flTimeDelta = (double)m_flTime - m_fOldTime; - static m_flShotTime = 0; + static int m_flShotTime = 0; #if 0 // g-cont. disabled for users request @@ -359,7 +359,8 @@ int CHud :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int int CHud :: DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b ) { // find the end of the string - for ( char *szIt = szString; *szIt != 0; szIt++ ) + char *szIt; + for ( szIt = szString; *szIt != 0; szIt++ ) { // we should count the length? } @@ -518,4 +519,4 @@ void DrawBlurTest( float frametime ) { blurstate = false; } -} \ No newline at end of file +} diff --git a/cl_dll/hud_servers.cpp b/cl_dll/hud_servers.cpp index f5cb1c6..b516047 100644 --- a/cl_dll/hud_servers.cpp +++ b/cl_dll/hud_servers.cpp @@ -12,7 +12,11 @@ #include "hud_servers.h" #include "net_api.h" #include +#if XASH_WIN32 #include +#else +#include +#endif static int context_id; @@ -599,7 +603,7 @@ int CompareField( CHudServers::server_t *p1, CHudServers::server_t *p2, const ch return stricmp( sz1, sz2 ); } -int CALLBACK ServerListCompareFunc( CHudServers::server_t *p1, CHudServers::server_t *p2, const char *fieldname ) +int ServerListCompareFunc( CHudServers::server_t *p1, CHudServers::server_t *p2, const char *fieldname ) { if (!p1 || !p2) // No meaningful comparison return 0; @@ -750,7 +754,7 @@ int CHudServers::LoadMasterAddresses( int maxservers, int *count, netadr_t *padr char szMaster[ 256 ]; char szMasterFile[256]; char *pbuffer = NULL; - char *pstart = NULL ; + const char *pstart = NULL ; netadr_t adr; char szAdr[64]; int nPort; @@ -1227,4 +1231,4 @@ void ServerPlayers( int server ) { g_pServers->ServerPlayers( server ); } -} \ No newline at end of file +} diff --git a/cl_dll/input_goldsource.cpp b/cl_dll/input_goldsource.cpp new file mode 100644 index 0000000..be85ee3 --- /dev/null +++ b/cl_dll/input_goldsource.cpp @@ -0,0 +1,1628 @@ +//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +// in_win.c -- windows 95 mouse and joystick code +// 02/21/97 JCB Added extended DirectInput code to support external controllers. + +#include "input_mouse.h" + +#ifdef SUPPORT_GOLDSOURCE_INPUT + +#include "hud.h" +#include "cl_util.h" +#include "camera.h" +#include "kbutton.h" +#include "cvardef.h" +#include "const.h" +#include "camera.h" +#include "in_defs.h" +#include "keydefs.h" +#include "view.h" + +#ifndef _WIN32 +#define USE_SDL2 +#endif + +#ifdef USE_SDL2 +#define ARRAYSIZE(p) ( sizeof(p) /sizeof(p[0]) ) +#include +#include +#include +int (*pfnSDL_SetRelativeMouseMode)(SDL_bool); +Uint32 (*pfnSDL_GetRelativeMouseState)(int* x, int* y); +int (*pfnSDL_NumJoysticks)(void); +SDL_bool (*pfnSDL_IsGameController)(int); +SDL_GameController* (*pfnSDL_GameControllerOpen)(int); +Sint16 (*pfnSDL_GameControllerGetAxis)(SDL_GameController*, SDL_GameControllerAxis); +Uint8 (*pfnSDL_GameControllerGetButton)(SDL_GameController*, SDL_GameControllerButton); +void (*pfnSDL_JoystickUpdate)(void); +const char* (*pfnSDL_GameControllerName)(SDL_GameController*); + +int safe_pfnSDL_SetRelativeMouseMode(SDL_bool mode) +{ + if (pfnSDL_SetRelativeMouseMode) + return pfnSDL_SetRelativeMouseMode(mode); + return -1; +} +Uint32 safe_pfnSDL_GetRelativeMouseState(int* x, int* y) +{ + if (pfnSDL_GetRelativeMouseState) + return pfnSDL_GetRelativeMouseState(x, y); + return 0; +} +int safe_pfnSDL_NumJoysticks() +{ + if (pfnSDL_NumJoysticks) + return pfnSDL_NumJoysticks(); + return -1; +} +SDL_bool safe_pfnSDL_IsGameController(int joystick_index) +{ + if (pfnSDL_IsGameController) + return pfnSDL_IsGameController(joystick_index); + return SDL_FALSE; +} +SDL_GameController* safe_pfnSDL_GameControllerOpen(int joystick_index) +{ + if (pfnSDL_GameControllerOpen) + return pfnSDL_GameControllerOpen(joystick_index); + return NULL; +} +Sint16 safe_pfnSDL_GameControllerGetAxis(SDL_GameController* gamecontroller, SDL_GameControllerAxis axis) +{ + if (pfnSDL_GameControllerGetAxis) + return pfnSDL_GameControllerGetAxis(gamecontroller, axis); + return 0; +} +Uint8 safe_pfnSDL_GameControllerGetButton(SDL_GameController* gamecontroller, SDL_GameControllerButton button) +{ + if (pfnSDL_GameControllerGetButton) + return pfnSDL_GameControllerGetButton(gamecontroller, button); + return 0; +} +void safe_pfnSDL_JoystickUpdate() +{ + if (pfnSDL_JoystickUpdate) + pfnSDL_JoystickUpdate(); +} +const char* safe_pfnSDL_GameControllerName(SDL_GameController* gamecontroller) +{ + if (pfnSDL_GameControllerName) + return pfnSDL_GameControllerName(gamecontroller); + return NULL; +} + +struct SDLFunction +{ + void** ppfnFunc; + const char* name; +}; +static SDLFunction sdlFunctions[] = { + {(void**)&pfnSDL_SetRelativeMouseMode, "SDL_SetRelativeMouseMode"}, + {(void**)&pfnSDL_GetRelativeMouseState, "SDL_GetRelativeMouseState"}, + {(void**)&pfnSDL_NumJoysticks, "SDL_NumJoysticks"}, + {(void**)&pfnSDL_IsGameController, "SDL_IsGameController"}, + {(void**)&pfnSDL_GameControllerOpen, "SDL_GameControllerOpen"}, + {(void**)&pfnSDL_GameControllerGetAxis, "SDL_GameControllerGetAxis"}, + {(void**)&pfnSDL_GameControllerGetButton, "SDL_GameControllerGetButton"}, + {(void**)&pfnSDL_JoystickUpdate, "SDL_JoystickUpdate"}, + {(void**)&pfnSDL_GameControllerName, "SDL_GameControllerName"} +}; +#endif + +#ifdef _WIN32 +#include +#else +typedef unsigned int DWORD; +#endif + +#define MOUSE_BUTTON_COUNT 5 + +// use IN_SetVisibleMouse to set: +int iVisibleMouse = 0; + +extern cl_enginefunc_t gEngfuncs; + +extern int iMouseInUse; + +extern kbutton_t in_strafe; +extern kbutton_t in_mlook; +extern kbutton_t in_speed; +extern kbutton_t in_jlook; + +extern cvar_t *m_pitch; +extern cvar_t *m_yaw; +extern cvar_t *m_forward; +extern cvar_t *m_side; + +extern cvar_t *lookstrafe; +extern cvar_t *lookspring; +extern cvar_t *cl_pitchdown; +extern cvar_t *cl_pitchup; +extern cvar_t *cl_yawspeed; +extern cvar_t *cl_sidespeed; +extern cvar_t *cl_forwardspeed; +extern cvar_t *cl_pitchspeed; +extern cvar_t *cl_movespeedkey; + +#ifdef _WIN32 +static double s_flRawInputUpdateTime = 0.0f; +static bool m_bRawInput = false; +static bool m_bMouseThread = false; +bool isMouseRelative = false; +#endif + +#ifdef _WIN32 +#include "progdefs.h" +extern globalvars_t *gpGlobals; +#endif + +int CL_IsDead( void ); +extern Vector dead_viewangles; + +void V_StopPitchDrift( void ) +{ + +} + +// mouse variables +cvar_t *m_filter; +extern cvar_t *sensitivity; + +// Custom mouse acceleration (0 disable, 1 to enable, 2 enable with separate yaw/pitch rescale) +static cvar_t *m_customaccel; +//Formula: mousesensitivity = ( rawmousedelta^m_customaccel_exponent ) * m_customaccel_scale + sensitivity +// If mode is 2, then x and y sensitivity are scaled by m_pitch and m_yaw respectively. +// Custom mouse acceleration value. +static cvar_t *m_customaccel_scale; +//Max mouse move scale factor, 0 for no limit +static cvar_t *m_customaccel_max; +//Mouse move is raised to this power before being scaled by scale factor +static cvar_t *m_customaccel_exponent; + +#ifdef _WIN32 +// if threaded mouse is enabled then the time to sleep between polls +static cvar_t *m_mousethread_sleep; +#endif + +float mouse_x, mouse_y; + +static int restore_spi; +static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1}; +static int mouseactive = 0; +static int mouseparmsvalid; +static int mouseshowtoggle = 1; + +// joystick defines and variables +// where should defines be moved? +#define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick +#define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball +#define JOY_MAX_AXES 6 // X, Y, Z, R, U, V +#define JOY_AXIS_X 0 +#define JOY_AXIS_Y 1 +#define JOY_AXIS_Z 2 +#define JOY_AXIS_R 3 +#define JOY_AXIS_U 4 +#define JOY_AXIS_V 5 + +enum _ControlList +{ + AxisNada = 0, + AxisForward, + AxisLook, + AxisSide, + AxisTurn +}; + +#if !defined(USE_SDL2) && defined(_WIN32) +DWORD dwAxisFlags[JOY_MAX_AXES] = +{ + JOY_RETURNX, + JOY_RETURNY, + JOY_RETURNZ, + JOY_RETURNR, + JOY_RETURNU, + JOY_RETURNV +}; +#endif + +DWORD dwAxisMap[ JOY_MAX_AXES ]; +DWORD dwControlMap[ JOY_MAX_AXES ]; +#if defined(USE_SDL2) +int pdwRawValue[ JOY_MAX_AXES ]; +#elif defined(_WIN32) +PDWORD pdwRawValue[ JOY_MAX_AXES ]; +#endif +DWORD joy_oldbuttonstate, joy_oldpovstate; + +int joy_id; +DWORD joy_numbuttons; + +#ifdef USE_SDL2 +SDL_GameController *s_pJoystick = NULL; +#elif defined(_WIN32) +DWORD joy_flags; +static JOYINFOEX ji; +#endif + +// none of these cvars are saved over a session +// this means that advanced controller configuration needs to be executed +// each time. this avoids any problems with getting back to a default usage +// or when changing from one controller to another. this way at least something +// works. +extern cvar_t *in_joystick; +cvar_t *joy_name; +cvar_t *joy_advanced; +cvar_t *joy_advaxisx; +cvar_t *joy_advaxisy; +cvar_t *joy_advaxisz; +cvar_t *joy_advaxisr; +cvar_t *joy_advaxisu; +cvar_t *joy_advaxisv; +cvar_t *joy_forwardthreshold; +cvar_t *joy_sidethreshold; +cvar_t *joy_pitchthreshold; +cvar_t *joy_yawthreshold; +cvar_t *joy_forwardsensitivity; +cvar_t *joy_sidesensitivity; +cvar_t *joy_pitchsensitivity; +cvar_t *joy_yawsensitivity; +cvar_t *joy_wwhack1; +cvar_t *joy_wwhack2; + +int joy_avail, joy_advancedinit, joy_haspov; + +#ifdef _WIN32 +unsigned int s_hMouseThreadId = 0; +HANDLE s_hMouseThread = 0; +HANDLE s_hMouseQuitEvent = 0; +HANDLE s_hMouseThreadActiveLock = 0; +#endif + +/* +=========== +Force_CenterView_f +=========== +*/ +void Force_CenterView_f (void) +{ + vec3_t viewangles; + + if (!iMouseInUse) + { + gEngfuncs.GetViewAngles( (float *)viewangles ); + viewangles[PITCH] = 0; + gEngfuncs.SetViewAngles( (float *)viewangles ); + } +} + +#ifdef _WIN32 + +LONG mouseThreadActive = 0; +LONG mouseThreadCenterX = 0; +LONG mouseThreadCenterY = 0; +LONG mouseThreadDeltaX = 0; +LONG mouseThreadDeltaY = 0; +LONG mouseThreadSleep = 0; + +bool MouseThread_ActiveLock_Enter( void ) +{ + if(!m_bMouseThread) + return true; + + return WAIT_OBJECT_0 == WaitForSingleObject( s_hMouseThreadActiveLock, INFINITE); +} + +void MouseThread_ActiveLock_Exit( void ) +{ + if(!m_bMouseThread) + return; + + SetEvent( s_hMouseThreadActiveLock ); +} + +unsigned __stdcall MouseThread_Function( void * pArg ) +{ + while ( true ) + { + DWORD sleepVal = (DWORD)InterlockedExchangeAdd(&mouseThreadSleep, 0); + if(0 > sleepVal) sleepVal = 0; + else if(1000 < sleepVal) sleepVal = 1000; + if(WAIT_OBJECT_0 == WaitForSingleObject( s_hMouseQuitEvent, sleepVal)) + { + break; + } + + if( MouseThread_ActiveLock_Enter() ) + { + if ( InterlockedExchangeAdd(&mouseThreadActive, 0) ) + { + POINT mouse_pos; + POINT center_pos; + + center_pos.x = InterlockedExchangeAdd(&mouseThreadCenterX, 0); + center_pos.y = InterlockedExchangeAdd(&mouseThreadCenterY, 0); + GetCursorPos(&mouse_pos); + + mouse_pos.x -= center_pos.x; + mouse_pos.y -= center_pos.y; + + if(mouse_pos.x || mouse_pos.y) SetCursorPos( center_pos.x, center_pos.y ); + + InterlockedExchangeAdd(&mouseThreadDeltaX, mouse_pos.x); + InterlockedExchangeAdd(&mouseThreadDeltaY, mouse_pos.y); + } + + MouseThread_ActiveLock_Exit(); + } + } + + return 0; +} + +/// Updates mouseThreadActive using the global variables mouseactive, iVisibleMouse and m_bRawInput. Should be called after any of these is changed. +/// Has to be interlocked manually by programmer! Use MouseThread_ActiveLock_Enter and MouseThread_ActiveLock_Exit. +void UpdateMouseThreadActive(void) +{ + InterlockedExchange(&mouseThreadActive, mouseactive && !iVisibleMouse && !m_bRawInput); +} + +#endif + +void IN_SetMouseMode(bool enable) +{ + static bool currentMouseMode = false; + + if(enable == currentMouseMode) + return; + + if(enable) + { +#ifdef _WIN32 + if (mouseparmsvalid) + restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0); + + m_bRawInput = CVAR_GET_FLOAT( "m_rawinput" ) != 0; + if(m_bRawInput) + { +#ifdef USE_SDL2 + safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE); +#endif + isMouseRelative = true; + } +#else + safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE); +#endif + + currentMouseMode = true; + } + else + { +#ifdef _WIN32 + if(isMouseRelative) + { +#ifdef USE_SDL2 + safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE); +#endif + isMouseRelative = false; + } + + if (restore_spi) + SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); +#else + safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE); +#endif + + currentMouseMode = false; + } +} + +void IN_SetVisibleMouse(bool visible) +{ +#ifdef _WIN32 + bool lockEntered = MouseThread_ActiveLock_Enter(); +#endif + + iVisibleMouse = visible; + + IN_SetMouseMode(!visible); + +#ifdef _WIN32 + UpdateMouseThreadActive(); + if(lockEntered) MouseThread_ActiveLock_Exit(); +#endif +} + +void IN_ResetMouse( void ); + +/* +=========== +IN_ActivateMouse +=========== +*/ +void GoldSourceInput::IN_ActivateMouse (void) +{ + if (mouseinitialized) + { +#ifdef _WIN32 + bool lockEntered = MouseThread_ActiveLock_Enter(); +#endif + + IN_SetMouseMode(true); + + mouseactive = 1; + +#ifdef _WIN32 + UpdateMouseThreadActive(); + if(lockEntered) MouseThread_ActiveLock_Exit(); +#endif + + // now is a good time to reset mouse positon: + IN_ResetMouse(); + } +} + + +/* +=========== +IN_DeactivateMouse +=========== +*/ +void GoldSourceInput::IN_DeactivateMouse (void) +{ + if (mouseinitialized) + { +#ifdef _WIN32 + bool lockEntered = MouseThread_ActiveLock_Enter(); +#endif + + IN_SetMouseMode(false); + + mouseactive = 0; + +#ifdef _WIN32 + UpdateMouseThreadActive(); + if(lockEntered) MouseThread_ActiveLock_Exit(); +#endif + } +} + +/* +=========== +IN_StartupMouse +=========== +*/ +void GoldSourceInput::IN_StartupMouse (void) +{ + if ( gEngfuncs.CheckParm ("-nomouse", NULL ) ) + return; + + mouseinitialized = 1; +#ifdef _WIN32 + mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0); + + if (mouseparmsvalid) + { + if ( gEngfuncs.CheckParm ("-noforcemspd", NULL ) ) + newmouseparms[2] = originalmouseparms[2]; + + if ( gEngfuncs.CheckParm ("-noforcemaccel", NULL ) ) + { + newmouseparms[0] = originalmouseparms[0]; + newmouseparms[1] = originalmouseparms[1]; + } + + if ( gEngfuncs.CheckParm ("-noforcemparms", NULL ) ) + { + newmouseparms[0] = originalmouseparms[0]; + newmouseparms[1] = originalmouseparms[1]; + newmouseparms[2] = originalmouseparms[2]; + } + } +#endif + + mouse_buttons = MOUSE_BUTTON_COUNT; +} + +/* +=========== +IN_Shutdown +=========== +*/ +void GoldSourceInput::IN_Shutdown (void) +{ + IN_DeactivateMouse (); + +#ifdef _WIN32 + if ( s_hMouseQuitEvent ) + { + SetEvent( s_hMouseQuitEvent ); + } + + if ( s_hMouseThread ) + { + if(WAIT_OBJECT_0 != WaitForSingleObject( s_hMouseThread, 5000 )) + { + TerminateThread( s_hMouseThread, 0 ); + } + CloseHandle( s_hMouseThread ); + s_hMouseThread = (HANDLE)0; + } + + if ( s_hMouseQuitEvent ) + { + CloseHandle( s_hMouseQuitEvent ); + s_hMouseQuitEvent = (HANDLE)0; + } + + if( s_hMouseThreadActiveLock ) + { + CloseHandle( s_hMouseThreadActiveLock ); + s_hMouseThreadActiveLock = (HANDLE)0; + } +#endif + +#ifdef USE_SDL2 + for (int j=0; jvalue; + + // Using special accleration values + if ( m_customaccel->value != 0 ) + { + float raw_mouse_movement_distance = sqrt( mx * mx + my * my ); + float acceleration_scale = m_customaccel_scale->value; + float accelerated_sensitivity_max = m_customaccel_max->value; + float accelerated_sensitivity_exponent = m_customaccel_exponent->value; + float accelerated_sensitivity = ( (float)pow( raw_mouse_movement_distance, accelerated_sensitivity_exponent ) * acceleration_scale + mouse_senstivity ); + + if ( accelerated_sensitivity_max > 0.0001f && + accelerated_sensitivity > accelerated_sensitivity_max ) + { + accelerated_sensitivity = accelerated_sensitivity_max; + } + + *x *= accelerated_sensitivity; + *y *= accelerated_sensitivity; + + // Further re-scale by yaw and pitch magnitude if user requests alternate mode 2 + // This means that they will need to up their value for m_customaccel_scale greatly (>40x) since m_pitch/yaw default + // to 0.022 + if ( m_customaccel->value == 2 ) + { + *x *= m_yaw->value; + *y *= m_pitch->value; + } + } + else + { + // Just apply the default + *x *= mouse_senstivity; + *y *= mouse_senstivity; + } +} + +void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY) +{ + bool active = mouseactive && !iVisibleMouse; + int mx, my; + + if(active) + { + int deltaX, deltaY; +#ifdef _WIN32 + if ( !m_bRawInput ) + { + if ( m_bMouseThread ) + { + // update mouseThreadSleep: + InterlockedExchange(&mouseThreadSleep, (LONG)m_mousethread_sleep->value); + + bool lockEntered = MouseThread_ActiveLock_Enter(); + + current_pos.x = InterlockedExchange( &mouseThreadDeltaX, 0 ); + current_pos.y = InterlockedExchange( &mouseThreadDeltaY, 0 ); + + if(lockEntered) MouseThread_ActiveLock_Exit(); + } + else + { + GetCursorPos (¤t_pos); + } + } + else +#endif + { +#ifdef USE_SDL2 + safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY ); + current_pos.x = deltaX; + current_pos.y = deltaY; +#else + GetCursorPos (¤t_pos); + deltaX = current_pos.x - gEngfuncs.GetWindowCenterX(); + deltaY = current_pos.y - gEngfuncs.GetWindowCenterY(); +#endif + } + +#ifdef _WIN32 + if ( !m_bRawInput ) + { + if ( m_bMouseThread ) + { + mx = current_pos.x; + my = current_pos.y; + } + else + { + mx = current_pos.x - gEngfuncs.GetWindowCenterX() + mx_accum; + my = current_pos.y - gEngfuncs.GetWindowCenterY() + my_accum; + } + } + else +#endif + { + mx = deltaX + mx_accum; + my = deltaY + my_accum; + } + + mx_accum = 0; + my_accum = 0; + + // reset mouse position if required, so there is room to move: +#ifdef _WIN32 + // do not reset if mousethread would do it: + if ( m_bRawInput || !m_bMouseThread ) +#else + if(true) +#endif + IN_ResetMouse(); + +#ifdef _WIN32 + // update m_bRawInput occasionally: + if ( gpGlobals && gpGlobals->time - s_flRawInputUpdateTime > 1.0f ) + { + s_flRawInputUpdateTime = gpGlobals->time; + + bool lockEntered = MouseThread_ActiveLock_Enter(); + + m_bRawInput = CVAR_GET_FLOAT( "m_rawinput" ) != 0; + + if(m_bRawInput && !isMouseRelative) + { +#ifdef USE_SDL2 + safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE); +#endif + isMouseRelative = true; + } + else if(!m_bRawInput && isMouseRelative) + { +#ifdef USE_SDL2 + safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE); +#endif + isMouseRelative = false; + } + + UpdateMouseThreadActive(); + if(lockEntered) MouseThread_ActiveLock_Exit(); + } +#endif + } + else + { + mx = my = 0; + } + + if(pOutX) *pOutX = mx; + if(pOutY) *pOutY = my; +} + +/* +=========== +IN_MouseMove +=========== +*/ +void GoldSourceInput::IN_MouseMove ( float frametime, usercmd_t *cmd) +{ + int mx, my; + vec3_t viewangles; + + if( gHUD.m_iIntermission ) + return; // we can't move during intermission + + if( CL_IsDead() ) + { + viewangles = dead_viewangles; // HACKHACK: see below + } + else + { + gEngfuncs.GetViewAngles( viewangles ); + } + + if ( in_mlook.state & 1) + { + V_StopPitchDrift (); + } + + //jjb - this disbles normal mouse control if the user is trying to + // move the camera, or if the mouse cursor is visible or if we're in intermission + if ( !iMouseInUse && !gHUD.m_iIntermission && !iVisibleMouse ) + { + IN_GetMouseDelta( &mx, &my ); + + if (m_filter && m_filter->value) + { + mouse_x = (mx + old_mouse_x) * 0.5; + mouse_y = (my + old_mouse_y) * 0.5; + } + else + { + mouse_x = mx; + mouse_y = my; + } + + old_mouse_x = mx; + old_mouse_y = my; + + // Apply custom mouse scaling/acceleration + IN_ScaleMouse( &mouse_x, &mouse_y ); + + // add mouse X/Y movement to cmd + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) + cmd->sidemove += m_side->value * mouse_x; + else + viewangles[YAW] -= m_yaw->value * mouse_x; + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) + { + viewangles[PITCH] += m_pitch->value * mouse_y; + if (viewangles[PITCH] > cl_pitchdown->value) + viewangles[PITCH] = cl_pitchdown->value; + if (viewangles[PITCH] < -cl_pitchup->value) + viewangles[PITCH] = -cl_pitchup->value; + } + else + { + if ((in_strafe.state & 1) && gEngfuncs.IsNoClipping() ) + { + cmd->upmove -= m_forward->value * mouse_y; + } + else + { + cmd->forwardmove -= m_forward->value * mouse_y; + } + } + } + + // HACKHACK: change viewangles directly in viewcode, + // so viewangles when player is dead will not be changed on server + if( !CL_IsDead() ) + { + gEngfuncs.SetViewAngles( viewangles ); + } + + dead_viewangles = viewangles; // keep them actual +/* +//#define TRACE_TEST +#if defined( TRACE_TEST ) + { + int mx, my; + void V_Move( int mx, int my ); + IN_GetMousePos( &mx, &my ); + V_Move( mx, my ); + } +#endif +*/ +} + +/* +=========== +IN_Accumulate +=========== +*/ +void GoldSourceInput::IN_Accumulate (void) +{ + //only accumulate mouse if we are not moving the camera with the mouse + if ( !iMouseInUse && !iVisibleMouse) + { + if (mouseactive) + { +#ifdef _WIN32 + if ( !m_bRawInput ) + { + if ( !m_bMouseThread ) + { + GetCursorPos (¤t_pos); + + mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX(); + my_accum += current_pos.y - gEngfuncs.GetWindowCenterY(); + } + } + else +#endif + { +#ifdef USE_SDL2 + int deltaX, deltaY; + safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY ); + mx_accum += deltaX; + my_accum += deltaY; +#else + GetCursorPos (¤t_pos); + + mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX(); + my_accum += current_pos.y - gEngfuncs.GetWindowCenterY(); +#endif + } + + // force the mouse to the center, so there's room to move +#ifdef _WIN32 + // do not reset if mousethread would do it: + if ( m_bRawInput || !m_bMouseThread ) +#else + if(true) +#endif + IN_ResetMouse(); + + } + } + +} + +/* +=================== +IN_ClearStates +=================== +*/ +void GoldSourceInput::IN_ClearStates (void) +{ + if ( !mouseactive ) + return; + + mx_accum = 0; + my_accum = 0; + mouse_oldbuttonstate = 0; +} + +/* +=============== +IN_StartupJoystick +=============== +*/ +void IN_StartupJoystick (void) +{ + // abort startup if user requests no joystick + if ( gEngfuncs.CheckParm ("-nojoy", NULL ) ) + return; + + // assume no joystick + joy_avail = 0; +#ifdef USE_SDL2 + int nJoysticks = safe_pfnSDL_NumJoysticks(); + if ( nJoysticks > 0 ) + { + for ( int i = 0; i < nJoysticks; i++ ) + { + if ( safe_pfnSDL_IsGameController( i ) ) + { + s_pJoystick = safe_pfnSDL_GameControllerOpen( i ); + if ( s_pJoystick ) + { + //save the joystick's number of buttons and POV status + joy_numbuttons = SDL_CONTROLLER_BUTTON_MAX; + joy_haspov = 0; + + // old button and POV states default to no buttons pressed + joy_oldbuttonstate = joy_oldpovstate = 0; + + // mark the joystick as available and advanced initialization not completed + // this is needed as cvars are not available during initialization + gEngfuncs.Con_Printf ("joystick found\n\n", safe_pfnSDL_GameControllerName(s_pJoystick)); + joy_avail = 1; + joy_advancedinit = 0; + break; + } + } + } + } + else + { + gEngfuncs.Con_DPrintf ("joystick not found -- driver not present\n\n"); + } +#elif defined(_WIN32) + int numdevs; + JOYCAPS jc; + MMRESULT mmr; + // verify joystick driver is present + if ((numdevs = joyGetNumDevs ()) == 0) + { + gEngfuncs.Con_DPrintf ("joystick not found -- driver not present\n\n"); + return; + } + + // cycle through the joystick ids for the first valid one + for (joy_id=0 ; joy_idvalue == 0.0) + { + // default joystick initialization + // 2 axes only with joystick control + dwAxisMap[JOY_AXIS_X] = AxisTurn; + // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS; + dwAxisMap[JOY_AXIS_Y] = AxisForward; + // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS; + } + else + { + if ( strcmp ( joy_name->string, "joystick") != 0 ) + { + // notify user of advanced controller + gEngfuncs.Con_Printf ("\n%s configured\n\n", joy_name->string); + } + + // advanced initialization here + // data supplied by user via joy_axisn cvars + dwTemp = (DWORD) joy_advaxisx->value; + dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS; + dwTemp = (DWORD) joy_advaxisy->value; + dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS; + dwTemp = (DWORD) joy_advaxisz->value; + dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS; + dwTemp = (DWORD) joy_advaxisr->value; + dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS; + dwTemp = (DWORD) joy_advaxisu->value; + dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS; + dwTemp = (DWORD) joy_advaxisv->value; + dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f; + dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS; + } + +#if !defined(USE_SDL2) && defined(_WIN32) + // compute the axes to collect from DirectInput + joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV; + for (i = 0; i < JOY_MAX_AXES; i++) + { + if (dwAxisMap[i] != AxisNada) + { + joy_flags |= dwAxisFlags[i]; + } + } +#endif +} + + +/* +=========== +IN_Commands +=========== +*/ +void GoldSourceInput::IN_Commands (void) +{ + int i, key_index; + + if (!joy_avail) + { + return; + } + + DWORD buttonstate, povstate; + + // loop through the joystick buttons + // key a joystick event or auxillary event for higher number buttons for each state change +#ifdef USE_SDL2 + buttonstate = 0; + for ( i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++ ) + { + if ( safe_pfnSDL_GameControllerGetButton( s_pJoystick, (SDL_GameControllerButton)i ) ) + { + buttonstate |= 1<value != 0.0) + { + ji.dwUpos += 100; + } + return 1; + } + else + { + // read error occurred + // turning off the joystick seems too harsh for 1 read error,\ + // but what should be done? + // Con_Printf ("IN_ReadJoystick: no response\n"); + // joy_avail = 0; + return 0; + } +#else + return 0; +#endif +} + + +/* +=========== +IN_JoyMove +=========== +*/ +void IN_JoyMove ( float frametime, usercmd_t *cmd ) +{ + float speed, aspeed; + float fAxisValue, fTemp; + int i; + vec3_t viewangles; + + gEngfuncs.GetViewAngles( (float *)viewangles ); + + + // complete initialization if first time in + // this is needed as cvars are not available at initialization time + if( joy_advancedinit != 1 ) + { + Joy_AdvancedUpdate_f(); + joy_advancedinit = 1; + } + + // verify joystick is available and that the user wants to use it + if (!joy_avail || !in_joystick->value) + { + return; + } + + // collect the joystick data, if possible + if (IN_ReadJoystick () != 1) + { + return; + } + + if (in_speed.state & 1) + speed = cl_movespeedkey->value; + else + speed = 1; + + aspeed = speed * frametime; + + // loop through the axes + for (i = 0; i < JOY_MAX_AXES; i++) + { + // get the floating point zero-centered, potentially-inverted data for the current axis +#ifdef USE_SDL2 + fAxisValue = (float)pdwRawValue[i]; +#elif defined(_WIN32) + fAxisValue = (float) *pdwRawValue[i]; + fAxisValue -= 32768.0; +#endif + + if (joy_wwhack2->value != 0.0) + { + if (dwAxisMap[i] == AxisTurn) + { + // this is a special formula for the Logitech WingMan Warrior + // y=ax^b; where a = 300 and b = 1.3 + // also x values are in increments of 800 (so this is factored out) + // then bounds check result to level out excessively high spin rates + fTemp = 300.0 * pow(fabs(fAxisValue) / 800.0, 1.3); + if (fTemp > 14000.0) + fTemp = 14000.0; + // restore direction information + fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp; + } + } + + // convert range from -32768..32767 to -1..1 + fAxisValue /= 32768.0; + + switch (dwAxisMap[i]) + { + case AxisForward: + if ((joy_advanced->value == 0.0) && (in_jlook.state & 1)) + { + // user wants forward control to become look control + if (fabs(fAxisValue) > joy_pitchthreshold->value) + { + // if mouse invert is on, invert the joystick pitch value + // only absolute control support here (joy_advanced is 0) + if (m_pitch->value < 0.0) + { + viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity->value) * aspeed * cl_pitchspeed->value; + } + else + { + viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity->value) * aspeed * cl_pitchspeed->value; + } + V_StopPitchDrift(); + } + else + { + // no pitch movement + // disable pitch return-to-center unless requested by user + // *** this code can be removed when the lookspring bug is fixed + // *** the bug always has the lookspring feature on + if(lookspring->value == 0.0) + { + V_StopPitchDrift(); + } + } + } + else + { + // user wants forward control to be forward control + if (fabs(fAxisValue) > joy_forwardthreshold->value) + { + cmd->forwardmove += (fAxisValue * joy_forwardsensitivity->value) * speed * cl_forwardspeed->value; + } + } + break; + + case AxisSide: + if (fabs(fAxisValue) > joy_sidethreshold->value) + { + cmd->sidemove += (fAxisValue * joy_sidesensitivity->value) * speed * cl_sidespeed->value; + } + break; + + case AxisTurn: + if ((in_strafe.state & 1) || (lookstrafe->value && (in_jlook.state & 1))) + { + // user wants turn control to become side control + if (fabs(fAxisValue) > joy_sidethreshold->value) + { + cmd->sidemove -= (fAxisValue * joy_sidesensitivity->value) * speed * cl_sidespeed->value; + } + } + else + { + // user wants turn control to be turn control + if (fabs(fAxisValue) > joy_yawthreshold->value) + { + if(dwControlMap[i] == JOY_ABSOLUTE_AXIS) + { + viewangles[YAW] += (fAxisValue * joy_yawsensitivity->value) * aspeed * cl_yawspeed->value; + } + else + { + viewangles[YAW] += (fAxisValue * joy_yawsensitivity->value) * speed * 180.0; + } + + } + } + break; + + case AxisLook: + if (in_jlook.state & 1) + { + if (fabs(fAxisValue) > joy_pitchthreshold->value) + { + // pitch movement detected and pitch movement desired by user + if(dwControlMap[i] == JOY_ABSOLUTE_AXIS) + { + viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity->value) * aspeed * cl_pitchspeed->value; + } + else + { + viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity->value) * speed * 180.0; + } + V_StopPitchDrift(); + } + else + { + // no pitch movement + // disable pitch return-to-center unless requested by user + // *** this code can be removed when the lookspring bug is fixed + // *** the bug always has the lookspring feature on + if( lookspring->value == 0.0 ) + { + V_StopPitchDrift(); + } + } + } + break; + + default: + break; + } + } + + // bounds check pitch + if (viewangles[PITCH] > cl_pitchdown->value) + viewangles[PITCH] = cl_pitchdown->value; + if (viewangles[PITCH] < -cl_pitchup->value) + viewangles[PITCH] = -cl_pitchup->value; + + gEngfuncs.SetViewAngles( (float *)viewangles ); +} + +/* +=========== +IN_Move +=========== +*/ +void GoldSourceInput::IN_Move ( float frametime, usercmd_t *cmd) +{ + if ( !iMouseInUse && mouseactive ) + { + IN_MouseMove ( frametime, cmd); + } + + IN_JoyMove ( frametime, cmd); +} + +/* +=========== +IN_Init +=========== +*/ +void GoldSourceInput::IN_Init (void) +{ + m_filter = gEngfuncs.pfnRegisterVariable ( "m_filter","0", FCVAR_ARCHIVE ); + sensitivity = gEngfuncs.pfnRegisterVariable ( "sensitivity","3", FCVAR_ARCHIVE ); // user mouse sensitivity setting. + + in_joystick = gEngfuncs.pfnRegisterVariable ( "joystick","0", FCVAR_ARCHIVE ); + joy_name = gEngfuncs.pfnRegisterVariable ( "joyname", "joystick", 0 ); + joy_advanced = gEngfuncs.pfnRegisterVariable ( "joyadvanced", "0", 0 ); + joy_advaxisx = gEngfuncs.pfnRegisterVariable ( "joyadvaxisx", "0", 0 ); + joy_advaxisy = gEngfuncs.pfnRegisterVariable ( "joyadvaxisy", "0", 0 ); + joy_advaxisz = gEngfuncs.pfnRegisterVariable ( "joyadvaxisz", "0", 0 ); + joy_advaxisr = gEngfuncs.pfnRegisterVariable ( "joyadvaxisr", "0", 0 ); + joy_advaxisu = gEngfuncs.pfnRegisterVariable ( "joyadvaxisu", "0", 0 ); + joy_advaxisv = gEngfuncs.pfnRegisterVariable ( "joyadvaxisv", "0", 0 ); + joy_forwardthreshold = gEngfuncs.pfnRegisterVariable ( "joyforwardthreshold", "0.15", 0 ); + joy_sidethreshold = gEngfuncs.pfnRegisterVariable ( "joysidethreshold", "0.15", 0 ); + joy_pitchthreshold = gEngfuncs.pfnRegisterVariable ( "joypitchthreshold", "0.15", 0 ); + joy_yawthreshold = gEngfuncs.pfnRegisterVariable ( "joyyawthreshold", "0.15", 0 ); + joy_forwardsensitivity = gEngfuncs.pfnRegisterVariable ( "joyforwardsensitivity", "-1.0", 0 ); + joy_sidesensitivity = gEngfuncs.pfnRegisterVariable ( "joysidesensitivity", "-1.0", 0 ); + joy_pitchsensitivity = gEngfuncs.pfnRegisterVariable ( "joypitchsensitivity", "1.0", 0 ); + joy_yawsensitivity = gEngfuncs.pfnRegisterVariable ( "joyyawsensitivity", "-1.0", 0 ); + joy_wwhack1 = gEngfuncs.pfnRegisterVariable ( "joywwhack1", "0.0", 0 ); + joy_wwhack2 = gEngfuncs.pfnRegisterVariable ( "joywwhack2", "0.0", 0 ); + + m_customaccel = gEngfuncs.pfnRegisterVariable ( "m_customaccel", "0", FCVAR_ARCHIVE ); + m_customaccel_scale = gEngfuncs.pfnRegisterVariable ( "m_customaccel_scale", "0.04", FCVAR_ARCHIVE ); + m_customaccel_max = gEngfuncs.pfnRegisterVariable ( "m_customaccel_max", "0", FCVAR_ARCHIVE ); + m_customaccel_exponent = gEngfuncs.pfnRegisterVariable ( "m_customaccel_exponent", "1", FCVAR_ARCHIVE ); + +#ifdef _WIN32 + m_bRawInput = CVAR_GET_FLOAT( "m_rawinput" ) != 0; + m_bMouseThread = gEngfuncs.CheckParm ("-mousethread", NULL ) != NULL; + m_mousethread_sleep = gEngfuncs.pfnRegisterVariable ( "m_mousethread_sleep", "1", FCVAR_ARCHIVE ); // default to less than 1000 Hz + + m_bMouseThread = m_bMouseThread && NULL != m_mousethread_sleep; + + if (m_bMouseThread) + { + // init mouseThreadSleep: +#if 0 // _beginthreadex is not defined on VS 6? + InterlockedExchange(&mouseThreadSleep, (LONG)m_mousethread_sleep->value); + + s_hMouseQuitEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + s_hMouseThreadActiveLock = CreateEvent( NULL, FALSE, TRUE, NULL ); + if ( s_hMouseQuitEvent && s_hMouseThreadActiveLock) + { + s_hMouseThread = (HANDLE)_beginthreadex( NULL, 0, MouseThread_Function, NULL, 0, &s_hMouseThreadId ); + } + + m_bMouseThread = NULL != s_hMouseThread; +#else + m_bMouseThread = 0; +#endif + + // at this early stage this won't print anything: + // gEngfuncs.Con_DPrintf ("Mouse thread %s.\n", m_bMouseThread ? "initalized" : "failed to initalize"); + } +#endif + +#ifdef USE_SDL2 +#ifdef __APPLE__ +#define SDL2_FULL_LIBNAME "libsdl2-2.0.0.dylib" +#else +#define SDL2_FULL_LIBNAME "libSDL2-2.0.so.0" +#endif + sdl2Lib = dlopen(SDL2_FULL_LIBNAME, RTLD_NOW|RTLD_LOCAL); + if (sdl2Lib) { + for (int j=0; jIN_ClientMoveEvent(forwardmove, sidemove); +} + +extern "C" void DLLEXPORT IN_ClientLookEvent( float relyaw, float relpitch ) +{ + currentInput->IN_ClientLookEvent(relyaw, relpitch); +} + +void IN_Move( float frametime, usercmd_t *cmd ) +{ + currentInput->IN_Move(frametime, cmd); +} + +extern "C" void DLLEXPORT IN_MouseEvent( int mstate ) +{ + currentInput->IN_MouseEvent(mstate); +} + +extern "C" void DLLEXPORT IN_ClearStates( void ) +{ + currentInput->IN_ClearStates(); +} + +extern "C" void DLLEXPORT IN_ActivateMouse( void ) +{ + currentInput->IN_ActivateMouse(); +} + +extern "C" void DLLEXPORT IN_DeactivateMouse( void ) +{ + currentInput->IN_DeactivateMouse(); +} + +extern "C" void DLLEXPORT IN_Accumulate( void ) +{ + currentInput->IN_Accumulate(); +} + +/* +=========== +IN_ResetMouse +=========== +*/ +void IN_ResetMouse( void ) +{ + gEngfuncs.pfnSetMousePos( gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY() ); +} + +void IN_Commands( void ) +{ + currentInput->IN_Commands(); +} + +void IN_Shutdown( void ) +{ + currentInput->IN_Shutdown(); +} + +void IN_Init( void ) +{ +#ifdef SUPPORT_GOLDSOURCE_INPUT + if (IsXashFWGS()) { + gEngfuncs.Con_Printf( "FWGS Xash3D input is in use\n" ); + currentInput = &fwgsInput; + } else { + gEngfuncs.Con_Printf( "GoldSource input is in use\n" ); + currentInput = &goldSourceInput; + } +#else + currentInput = &fwgsInput; +#endif + currentInput->IN_Init(); +} diff --git a/cl_dll/input_mouse.h b/cl_dll/input_mouse.h new file mode 100644 index 0000000..c13b7fa --- /dev/null +++ b/cl_dll/input_mouse.h @@ -0,0 +1,79 @@ +#pragma once +#ifndef INPUT_MOUSE_H +#define INPUT_MOUSE_H +#include "cl_dll.h" +#include "usercmd.h" +#include "in_defs.h" + +class AbstractInput +{ +public: + virtual void IN_ClientMoveEvent( float forwardmove, float sidemove ) = 0; + virtual void IN_ClientLookEvent( float relyaw, float relpitch ) = 0; + virtual void IN_Move( float frametime, usercmd_t *cmd ) = 0; + virtual void IN_MouseEvent( int mstate ) = 0; + virtual void IN_ClearStates( void ) = 0; + virtual void IN_ActivateMouse( void ) = 0; + virtual void IN_DeactivateMouse( void ) = 0; + virtual void IN_Accumulate( void ) = 0; + virtual void IN_Commands( void ) = 0; + virtual void IN_Shutdown( void ) = 0; + virtual void IN_Init( void ) = 0; +}; + +class FWGSInput : public AbstractInput +{ +public: + virtual void IN_ClientMoveEvent( float forwardmove, float sidemove ); + virtual void IN_ClientLookEvent( float relyaw, float relpitch ); + virtual void IN_Move( float frametime, usercmd_t *cmd ); + virtual void IN_MouseEvent( int mstate ); + virtual void IN_ClearStates( void ); + virtual void IN_ActivateMouse( void ); + virtual void IN_DeactivateMouse( void ); + virtual void IN_Accumulate( void ); + virtual void IN_Commands( void ); + virtual void IN_Shutdown( void ); + virtual void IN_Init( void ); + +protected: + float ac_forwardmove; + float ac_sidemove; + int ac_movecount; + float rel_yaw; + float rel_pitch; +}; + +// No need for goldsource input support on the platforms that are not supported by GoldSource. +#if defined(GOLDSOURCE_SUPPORT) && (defined(_WIN32) || defined(__linux__) || defined(__APPLE__)) && (defined(__i386) || defined(_M_IX86)) +#define SUPPORT_GOLDSOURCE_INPUT +class GoldSourceInput : public AbstractInput +{ +public: + virtual void IN_ClientMoveEvent( float forwardmove, float sidemove ) {} + virtual void IN_ClientLookEvent( float relyaw, float relpitch ) {} + virtual void IN_Move( float frametime, usercmd_t *cmd ); + virtual void IN_MouseEvent( int mstate ); + virtual void IN_ClearStates( void ); + virtual void IN_ActivateMouse( void ); + virtual void IN_DeactivateMouse( void ); + virtual void IN_Accumulate( void ); + virtual void IN_Commands( void ); + virtual void IN_Shutdown( void ); + virtual void IN_Init( void ); + +protected: + void IN_GetMouseDelta( int *pOutX, int *pOutY); + void IN_MouseMove ( float frametime, usercmd_t *cmd); + void IN_StartupMouse (void); + + int mouse_buttons; + int mouse_oldbuttonstate; + POINT current_pos; + int old_mouse_x, old_mouse_y, mx_accum, my_accum; + int mouseinitialized; + void* sdl2Lib; +}; +#endif + +#endif diff --git a/cl_dll/input_xash3d.cpp b/cl_dll/input_xash3d.cpp new file mode 100644 index 0000000..3cb9d5b --- /dev/null +++ b/cl_dll/input_xash3d.cpp @@ -0,0 +1,293 @@ +#include "hud.h" +#include "usercmd.h" +#include "cvardef.h" +#include "kbutton.h" +#include "keydefs.h" +#include "input_mouse.h" +extern cvar_t *sensitivity; +extern cvar_t *in_joystick; + +extern kbutton_t in_strafe; +extern kbutton_t in_mlook; +extern kbutton_t in_speed; +extern kbutton_t in_jlook; +extern kbutton_t in_forward; +extern kbutton_t in_back; +extern kbutton_t in_moveleft; +extern kbutton_t in_moveright; + +extern cvar_t *m_pitch; +extern cvar_t *m_yaw; +extern cvar_t *m_forward; +extern cvar_t *m_side; +extern cvar_t *lookstrafe; +extern cvar_t *lookspring; +extern cvar_t *cl_pitchdown; +extern cvar_t *cl_pitchup; +extern cvar_t *cl_yawspeed; +extern cvar_t *cl_sidespeed; +extern cvar_t *cl_forwardspeed; +extern cvar_t *cl_pitchspeed; +extern cvar_t *cl_movespeedkey; +cvar_t *cl_laddermode; + + +#define F 1U<<0 // Forward +#define B 1U<<1 // Back +#define L 1U<<2 // Left +#define R 1U<<3 // Right +#define T 1U<<4 // Forward stop +#define S 1U<<5 // Side stop + +#define BUTTON_DOWN 1 +#define IMPULSE_DOWN 2 +#define IMPULSE_UP 4 + +int CL_IsDead( void ); +int g_iVisibleMouse = 0; +extern int iMouseInUse; +extern Vector dead_viewangles; + +void IN_ToggleButtons( float forwardmove, float sidemove ) +{ + static unsigned int moveflags = T | S; + + if( forwardmove ) + moveflags &= ~T; + else + { + //if( in_forward.state || in_back.state ) gEngfuncs.Con_Printf("Buttons pressed f%d b%d\n", in_forward.state, in_back.state); + if( !( moveflags & T ) ) + { + //IN_ForwardUp(); + //IN_BackUp(); + //gEngfuncs.Con_Printf("Reset forwardmove state f%d b%d\n", in_forward.state, in_back.state); + in_forward.state &= ~BUTTON_DOWN; + in_back.state &= ~BUTTON_DOWN; + moveflags |= T; + } + } + if( sidemove ) + moveflags &= ~S; + else + { + //gEngfuncs.Con_Printf("l%d r%d\n", in_moveleft.state, in_moveright.state); + //if( in_moveleft.state || in_moveright.state ) gEngfuncs.Con_Printf("Buttons pressed l%d r%d\n", in_moveleft.state, in_moveright.state); + if( !( moveflags & S ) ) + { + //IN_MoverightUp(); + //IN_MoveleftUp(); + //gEngfuncs.Con_Printf("Reset sidemove state f%d b%d\n", in_moveleft.state, in_moveright.state); + in_moveleft.state &= ~BUTTON_DOWN; + in_moveright.state &= ~BUTTON_DOWN; + moveflags |= S; + } + } + + if( forwardmove > 0.7f && !( moveflags & F ) ) + { + moveflags |= F; + in_forward.state |= BUTTON_DOWN; + } + if( forwardmove < 0.7f && ( moveflags & F ) ) + { + moveflags &= ~F; + in_forward.state &= ~BUTTON_DOWN; + } + if( forwardmove < -0.7f && !( moveflags & B ) ) + { + moveflags |= B; + in_back.state |= BUTTON_DOWN; + } + if( forwardmove > -0.7f && ( moveflags & B ) ) + { + moveflags &= ~B; + in_back.state &= ~BUTTON_DOWN; + } + if( sidemove > 0.9f && !( moveflags & R ) ) + { + moveflags |= R; + in_moveright.state |= BUTTON_DOWN; + } + if( sidemove < 0.9f && ( moveflags & R ) ) + { + moveflags &= ~R; + in_moveright.state &= ~BUTTON_DOWN; + } + if( sidemove < -0.9f && !( moveflags & L ) ) + { + moveflags |= L; + in_moveleft.state |= BUTTON_DOWN; + } + if( sidemove > -0.9f && ( moveflags & L ) ) + { + moveflags &= ~L; + in_moveleft.state &= ~BUTTON_DOWN; + } +} + +void FWGSInput::IN_ClientMoveEvent( float forwardmove, float sidemove ) +{ + //gEngfuncs.Con_Printf("IN_MoveEvent\n"); + + ac_forwardmove += forwardmove; + ac_sidemove += sidemove; + ac_movecount++; +} + +void FWGSInput::IN_ClientLookEvent( float relyaw, float relpitch ) +{ + rel_yaw += relyaw; + rel_pitch += relpitch; +} + +// Rotate camera and add move values to usercmd +void FWGSInput::IN_Move( float frametime, usercmd_t *cmd ) +{ + Vector viewangles; + bool fLadder = false; + + if( gHUD.m_iIntermission ) + return; // we can't move during intermission + + if( cl_laddermode->value != 2 ) + { + cl_entity_t *pplayer = gEngfuncs.GetLocalPlayer(); + if( pplayer ) + fLadder = pplayer->curstate.movetype == MOVETYPE_FLY; + } + //if(ac_forwardmove || ac_sidemove) + //gEngfuncs.Con_Printf("Move: %f %f %f %f\n", ac_forwardmove, ac_sidemove, rel_pitch, rel_yaw); +#if 0 + if( in_mlook.state & 1 ) + { + V_StopPitchDrift(); + } +#endif + if( CL_IsDead() ) + { + viewangles = dead_viewangles; // HACKHACK: see below + } + else + { + gEngfuncs.GetViewAngles( viewangles ); + } + if( gHUD.GetSensitivity() != 0 ) + { + rel_yaw *= gHUD.GetSensitivity(); + rel_pitch *= gHUD.GetSensitivity(); + } + else + { + rel_yaw *= sensitivity->value; + rel_pitch *= sensitivity->value; + } + viewangles[YAW] += rel_yaw; + if( fLadder ) + { + if( cl_laddermode->value == 1 ) + viewangles[YAW] -= ac_sidemove * 5; + ac_sidemove = 0; + } +#if 0 + if( gHUD.m_MOTD.m_bShow ) + gHUD.m_MOTD.scroll += rel_pitch; + else +#endif + viewangles[PITCH] += rel_pitch; + + if( viewangles[PITCH] > cl_pitchdown->value ) + viewangles[PITCH] = cl_pitchdown->value; + if( viewangles[PITCH] < -cl_pitchup->value ) + viewangles[PITCH] = -cl_pitchup->value; + + // HACKHACK: change viewangles directly in viewcode, + // so viewangles when player is dead will not be changed on server + if( !CL_IsDead() ) + { + gEngfuncs.SetViewAngles( viewangles ); + } + + dead_viewangles = viewangles; // keep them actual + if( ac_movecount ) + { + IN_ToggleButtons( ac_forwardmove / ac_movecount, ac_sidemove / ac_movecount ); + + if( ac_forwardmove ) + cmd->forwardmove = ac_forwardmove * cl_forwardspeed->value / ac_movecount; + if( ac_sidemove ) + cmd->sidemove = ac_sidemove * cl_sidespeed->value / ac_movecount; + if( ( in_speed.state & 1 ) && ( ac_sidemove || ac_forwardmove ) ) + { + cmd->forwardmove *= cl_movespeedkey->value; + cmd->sidemove *= cl_movespeedkey->value; + } + } + + ac_sidemove = ac_forwardmove = rel_pitch = rel_yaw = 0; + ac_movecount = 0; +} + +void FWGSInput::IN_MouseEvent( int mstate ) +{ + static int mouse_oldbuttonstate; + + if ( iMouseInUse || g_iVisibleMouse ) + return; + + // perform button actions + for( int i = 0; i < 5; i++ ) + { + if( ( mstate & ( 1 << i ) ) && !( mouse_oldbuttonstate & ( 1 << i ) ) ) + { + gEngfuncs.Key_Event( K_MOUSE1 + i, 1 ); + } + + if( !( mstate & ( 1 << i ) ) && ( mouse_oldbuttonstate & ( 1 << i ) ) ) + { + gEngfuncs.Key_Event( K_MOUSE1 + i, 0 ); + } + } + + mouse_oldbuttonstate = mstate; +} + +// Stubs + +void FWGSInput::IN_ClearStates( void ) +{ + //gEngfuncs.Con_Printf( "IN_ClearStates\n" ); +} + +void FWGSInput::IN_ActivateMouse( void ) +{ + //gEngfuncs.Con_Printf( "IN_ActivateMouse\n" ); +} + +void FWGSInput::IN_DeactivateMouse( void ) +{ + //gEngfuncs.Con_Printf( "IN_DeactivateMouse\n" ); +} + +void FWGSInput::IN_Accumulate( void ) +{ + //gEngfuncs.Con_Printf( "IN_Accumulate\n" ); +} + +void FWGSInput::IN_Commands( void ) +{ + //gEngfuncs.Con_Printf( "IN_Commands\n" ); +} + +void FWGSInput::IN_Shutdown( void ) +{ +} + +// Register cvars and reset data +void FWGSInput::IN_Init( void ) +{ + sensitivity = gEngfuncs.pfnRegisterVariable( "sensitivity", "3", FCVAR_ARCHIVE ); + in_joystick = gEngfuncs.pfnRegisterVariable( "joystick", "0", FCVAR_ARCHIVE ); + cl_laddermode = gEngfuncs.pfnRegisterVariable( "cl_laddermode", "2", FCVAR_ARCHIVE ); + ac_forwardmove = ac_sidemove = rel_yaw = rel_pitch = 0; +} diff --git a/cl_dll/inputw32.cpp b/cl_dll/inputw32.old similarity index 100% rename from cl_dll/inputw32.cpp rename to cl_dll/inputw32.old diff --git a/cl_dll/render/gl_aurora.cpp b/cl_dll/render/gl_aurora.cpp index e3a45b7..99822ee 100644 --- a/cl_dll/render/gl_aurora.cpp +++ b/cl_dll/render/gl_aurora.cpp @@ -929,7 +929,9 @@ void CParticleSystem :: DrawSystem( void ) { if( pParticle->m_fSize <= 0 || !ParticleIsVisible( pParticle )) continue; - DrawParticle( pParticle, GetVLeft(), GetVUp( )); + Vector vLeft = GetVLeft(); + Vector vUp = GetVUp(); + DrawParticle( pParticle, vLeft, vUp); } } @@ -1068,7 +1070,8 @@ void CParticleSystem :: DrawParticle( CParticle *part, const vec3_t &right, cons point[3] = origin + up * -fSinSize + right * fCosSize; ClearBounds( absmin, absmax ); - for( int i = 0; i < 4; i++ ) + int i; + for( i = 0; i < 4; i++ ) AddPointToBounds( point[i], absmin, absmax ); int iContents = CONTENTS_NONE; @@ -1168,4 +1171,4 @@ void CParticleSystem :: DrawParticle( CParticle *part, const vec3_t &right, cons RI->frame.trans_list.AddToTail( entry ); #endif } -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_backend.cpp b/cl_dll/render/gl_backend.cpp index 2122029..3aad8f8 100644 --- a/cl_dll/render/gl_backend.cpp +++ b/cl_dll/render/gl_backend.cpp @@ -13,6 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#include #include "hud.h" #include "cl_util.h" #include "const.h" @@ -1052,4 +1053,4 @@ void CompressNormalizedVector( char outVec[3], const Vector &inVec ) outVec[0] = FloatToChar( vNorm.x ); outVec[1] = FloatToChar( vNorm.y ); outVec[2] = FloatToChar( vNorm.z ); -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_cubemaps.cpp b/cl_dll/render/gl_cubemaps.cpp index 8ef8db4..041a9c5 100644 --- a/cl_dll/render/gl_cubemaps.cpp +++ b/cl_dll/render/gl_cubemaps.cpp @@ -211,13 +211,13 @@ void CL_BuildCubemaps_f( void ) { mcubemap_t *m = &world->defaultCubemap; FREE_TEXTURE( m->texture ); - m->valid = m->texture = false; + m->valid = ( m->texture = false ); for( int i = 0; i < world->num_cubemaps; i++ ) { mcubemap_t *m = &world->cubemaps[i]; FREE_TEXTURE( m->texture ); - m->valid = m->texture = false; + m->valid = ( m->texture = false ); } if( FBitSet( world->features, WORLD_HAS_SKYBOX )) @@ -225,4 +225,4 @@ void CL_BuildCubemaps_f( void ) world->rebuilding_cubemaps = CMREBUILD_CHECKING; world->loading_cubemaps = true; -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_deferred.cpp b/cl_dll/render/gl_deferred.cpp index 2951527..28a8d27 100644 --- a/cl_dll/render/gl_deferred.cpp +++ b/cl_dll/render/gl_deferred.cpp @@ -422,7 +422,7 @@ static void GL_DrawBilateralFilter( word hProgram, int pass ) case UT_COLORMAP: if( pass == BILATERAL_PASS0 ) u->SetValue( tr.fbo_light.GetTexture() ); - else if( pass = BILATERAL_PASS1 ) + else if( pass == BILATERAL_PASS1 ) u->SetValue( tr.fbo_filter.GetTexture() ); else u->SetValue( tr.defscene_fbo->colortarget[0] ); break; @@ -435,7 +435,7 @@ static void GL_DrawBilateralFilter( word hProgram, int pass ) case UT_SCREENSIZEINV: if( pass == BILATERAL_PASS0 ) u->SetValue( 1.0f / (float)glState.width, 0.0f ); - else if( pass = BILATERAL_PASS1 ) + else if( pass == BILATERAL_PASS1 ) u->SetValue( 0.0f, 1.0f / (float)glState.height ); else u->SetValue( 1.0f / (float)glState.width, 1.0f / (float)glState.height ); break; @@ -551,4 +551,4 @@ void GL_DrawDeferredPass( void ) GL_CleanupDrawState(); GL_BindFBO( FBO_MAIN ); GL_Setup3D(); -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_dlight.cpp b/cl_dll/render/gl_dlight.cpp index 20bb01d..e76b1fa 100644 --- a/cl_dll/render/gl_dlight.cpp +++ b/cl_dll/render/gl_dlight.cpp @@ -751,7 +751,7 @@ get_next_light: int ignored = -1; int light = 255; - for( i = 0; i < count; i++ ) + for( int i = 0; i < count; i++ ) { if( indexes[i][0] == -1.0f ) continue; @@ -768,6 +768,7 @@ get_next_light: if( ignored == -1 ) return; + int i; for( i = 0; i < (int)cv_deferred_maxlights->value && lights[i] != 255; i++ ); if( i < (int)cv_deferred_maxlights->value ) lights[i] = light; // nearest light for surf @@ -776,4 +777,4 @@ get_next_light: // if( count > (int)cv_deferred_maxlights->value && i == (int)cv_deferred_maxlights->value ) // Msg( "skipped light %i intensity %g, type %d\n", light, maxIllum, world->worldlights[light].emittype ); goto get_next_light; -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_export.cpp b/cl_dll/render/gl_export.cpp index dc67d61..e1b1470 100644 --- a/cl_dll/render/gl_export.cpp +++ b/cl_dll/render/gl_export.cpp @@ -13,8 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#define EXTERN - +#define APIENTRY_LINKAGE #include "hud.h" #include "cl_util.h" #include "gl_local.h" @@ -355,7 +354,7 @@ DebugCallback For ARB_debug_output ======================== */ -static void CALLBACK GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLuint severity, GLint length, const GLcharARB *message, GLvoid *userParam ) +static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLuint severity, GLint length, const GLcharARB *message, GLvoid *userParam ) { static char string[8192]; char *msg; @@ -502,10 +501,10 @@ static void GL_InitExtensions( void ) } // get our various GL strings - glConfig.vendor_string = pglGetString( GL_VENDOR ); - glConfig.renderer_string = pglGetString( GL_RENDERER ); - glConfig.version_string = pglGetString( GL_VERSION ); - glConfig.extensions_string = pglGetString( GL_EXTENSIONS ); + glConfig.vendor_string = (const char*)pglGetString( GL_VENDOR ); + glConfig.renderer_string = (const char*)pglGetString( GL_RENDERER ); + glConfig.version_string = (const char*)pglGetString( GL_VERSION ); + glConfig.extensions_string = (const char*)pglGetString( GL_EXTENSIONS ); if( Q_stristr( glConfig.renderer_string, "geforce" )) glConfig.hardware_type = GLHW_NVIDIA; @@ -1026,4 +1025,4 @@ void GL_Shutdown( void ) // now all extensions are disabled memset( glConfig.extension, 0, sizeof( glConfig.extension[0] ) * R_EXTCOUNT ); -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_grass.cpp b/cl_dll/render/gl_grass.cpp index 91e9741..50e79c5 100644 --- a/cl_dll/render/gl_grass.cpp +++ b/cl_dll/render/gl_grass.cpp @@ -1117,7 +1117,8 @@ find or add unique texture for grass */ byte R_GrassTextureForName( const char *name ) { - for( byte i = 0; i < GRASS_TEXTURES && grasstexs[i].name[0]; i++ ) + byte i; + for( i = 0; i < GRASS_TEXTURES && grasstexs[i].name[0]; i++ ) { if( !Q_stricmp( grasstexs[i].name, name )) return i; // found @@ -1772,4 +1773,4 @@ void R_GrassShutdown( void ) FREE_TEXTURE( grasstexs[i].gl_texturenum ); } -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_shadows.cpp b/cl_dll/render/gl_shadows.cpp index 783a49f..d0333ad 100644 --- a/cl_dll/render/gl_shadows.cpp +++ b/cl_dll/render/gl_shadows.cpp @@ -196,7 +196,7 @@ static int R_ComputeCropBounds( const matrix4x4 &lightViewProjection, Vector bou } // add studio models too - for( i = 0; i < prevRI->frame.solid_meshes.Count(); i++ ) + for( int i = 0; i < prevRI->frame.solid_meshes.Count(); i++ ) { if( !R_StudioGetBounds( &prevRI->frame.solid_meshes[i], worldBounds )) continue; @@ -657,4 +657,4 @@ void R_RenderShadowmaps( void ) GL_BindFBO( oldFBO ); GL_BindShader( NULL ); RI->currentlight = NULL; -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_sprite.cpp b/cl_dll/render/gl_sprite.cpp index c7cd874..e6595f2 100644 --- a/cl_dll/render/gl_sprite.cpp +++ b/cl_dll/render/gl_sprite.cpp @@ -593,4 +593,4 @@ mspriteframe_t *CSpriteModelRenderer :: GetSpriteFrame( const model_t *m_pSprite m_pCurrentEntity = NULL; return GetSpriteFrame( frame, 0.0f ); -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_studiodecal.h b/cl_dll/render/gl_studiodecal.h index 5db1775..b4099cb 100644 --- a/cl_dll/render/gl_studiodecal.h +++ b/cl_dll/render/gl_studiodecal.h @@ -56,4 +56,4 @@ typedef struct studiodecal_s shader_t forwardLightProj; } studiodecal_t; -#endif//GL_STUDIODECAL_H \ No newline at end of file +#endif//GL_STUDIODECAL_H diff --git a/cl_dll/render/gl_studiodecal_new.cpp b/cl_dll/render/gl_studiodecal_new.cpp index 508e784..8e2d98c 100644 --- a/cl_dll/render/gl_studiodecal_new.cpp +++ b/cl_dll/render/gl_studiodecal_new.cpp @@ -1137,7 +1137,7 @@ void CStudioModelRenderer :: AddDecalToModel( DecalBuildInfo_t& buildInfo ) float s = 1.0f / (float)ptexture->width; float t = 1.0f / (float)ptexture->height; - while( numVerts = *( ptricmds++ )) + while(( numVerts = *( ptricmds++ ))) { bool strip = ( numVerts < 0 ) ? false : true; int vertexState = 0; @@ -1778,4 +1778,4 @@ void CStudioModelRenderer :: DrawDecal( CSolidEntry *entry, GLenum cull_mode ) GL_DepthMask( GL_TRUE ); GL_Blend( GL_FALSE ); GL_Cull( GL_FRONT ); -} \ No newline at end of file +} diff --git a/cl_dll/render/gl_world_new.cpp b/cl_dll/render/gl_world_new.cpp index 878ea33..9151c77 100644 --- a/cl_dll/render/gl_world_new.cpp +++ b/cl_dll/render/gl_world_new.cpp @@ -146,7 +146,7 @@ check cubemap sides for valid */ static bool Mod_CheckCubemap( const char *name ) { - char *suf[6] = { "px", "nx", "py", "ny", "pz", "nz" }; + const char *suf[6] = { "px", "nx", "py", "ny", "pz", "nz" }; int valid_sides = 0; char sidename[64]; int iCompare; @@ -175,7 +175,7 @@ remove cubemap images from HDD */ static void Mod_DeleteCubemap( const char *name ) { - char *suf[6] = { "px", "nx", "py", "ny", "pz", "nz" }; + const char *suf[6] = { "px", "nx", "py", "ny", "pz", "nz" }; char sidename[64]; for( int i = 0; i < 6; i++ ) @@ -328,7 +328,7 @@ void GL_LoadAndRebuildCubemaps( int refParams ) // bind cubemaps onto world surfaces // so we don't need to search them again - for( i = 0; i < worldmodel->numsurfaces; i++ ) + for( int i = 0; i < worldmodel->numsurfaces; i++ ) { msurface_t *surf = &worldmodel->surfaces[i]; mextrasurf_t *es = surf->info; @@ -405,7 +405,7 @@ static void Mod_LoadCubemaps( const byte *base, const dlump_t *l ) cm->size = 4; } - for( i = 0; i < count; i++, in++, out++ ) + for( int i = 0; i < count; i++, in++, out++ ) { // build a cubemap name like enum Q_snprintf( out->name, sizeof( out->name ), "maps/env/%s/cube#%i", world->name, i ); @@ -965,12 +965,12 @@ Mod_SurfaceCompareBuild sort faces before lightmap building ================= */ -static int Mod_SurfaceCompareBuild( const unsigned short **a, const unsigned short **b ) +static int Mod_SurfaceCompareBuild( const unsigned short *a, const unsigned short *b ) { msurface_t *surf1, *surf2; - surf1 = &worldmodel->surfaces[(unsigned short)*a]; - surf2 = &worldmodel->surfaces[(unsigned short)*b]; + surf1 = &worldmodel->surfaces[*a]; + surf2 = &worldmodel->surfaces[*b]; if( FBitSet( surf1->flags, SURF_DRAWSKY ) && !FBitSet( surf2->flags, SURF_DRAWSKY )) return -1; @@ -1002,13 +1002,13 @@ Mod_SurfaceCompareInGame sort faces to reduce shader switches ================= */ -static int Mod_SurfaceCompareInGame( const unsigned short **a, const unsigned short **b ) +static int Mod_SurfaceCompareInGame( const unsigned short *a, const unsigned short *b ) { msurface_t *surf1, *surf2; mextrasurf_t *esrf1, *esrf2; - surf1 = &worldmodel->surfaces[(unsigned short)*a]; - surf2 = &worldmodel->surfaces[(unsigned short)*b]; + surf1 = &worldmodel->surfaces[*a]; + surf2 = &worldmodel->surfaces[*b]; esrf1 = surf1->info; esrf2 = surf2->info; @@ -4022,4 +4022,4 @@ void R_RenderShadowBrushList( void ) R_RenderShadowGrassOnList(); GL_CleanupDrawState(); -} \ No newline at end of file +} diff --git a/cl_dll/render/tri.cpp b/cl_dll/render/tri.cpp index 272dbff..ee9f81d 100644 --- a/cl_dll/render/tri.cpp +++ b/cl_dll/render/tri.cpp @@ -21,8 +21,6 @@ #include "com_model.h" #include "gl_local.h"// buz -#define DLLEXPORT __declspec( dllexport ) - extern "C" { void DLLEXPORT HUD_DrawNormalTriangles( void ); @@ -204,4 +202,4 @@ Render any triangles with transparent rendermode needs here */ void DLLEXPORT HUD_DrawTransparentTriangles( void ) { -} \ No newline at end of file +} diff --git a/cl_dll/saytext.cpp b/cl_dll/saytext.cpp index f502238..a0559bf 100644 --- a/cl_dll/saytext.cpp +++ b/cl_dll/saytext.cpp @@ -174,7 +174,8 @@ void CHudSayText :: SayTextPrint( const char *pszBuf, int iBufSize, int clientIn } // find an empty string slot - for ( int i = 0; i < MAX_LINES; i++ ) + int i; + for ( i = 0; i < MAX_LINES; i++ ) { if ( ! *g_szLineBuffer[i] ) break; @@ -318,4 +319,4 @@ void CHudSayText :: EnsureTextFitsInOneLineAndWrapIfHaveTo( int line ) } } } -} \ No newline at end of file +} diff --git a/cl_dll/status_icons.cpp b/cl_dll/status_icons.cpp index e184633..a113074 100644 --- a/cl_dll/status_icons.cpp +++ b/cl_dll/status_icons.cpp @@ -107,7 +107,8 @@ int CHudStatusIcons::MsgFunc_StatusIcon( const char *pszName, int iSize, void *p void CHudStatusIcons::EnableIcon( char *pszIconName, unsigned char red, unsigned char green, unsigned char blue ) { // check to see if the sprite is in the current list - for ( int i = 0; i < MAX_ICONSPRITES; i++ ) + int i; + for ( i = 0; i < MAX_ICONSPRITES; i++ ) { if ( !stricmp( m_IconList[i].szSpriteName, pszIconName ) ) break; @@ -155,7 +156,7 @@ void CHudStatusIcons::DisableIcon( char *pszIconName ) if ( !stricmp( m_IconList[i].szSpriteName, pszIconName ) ) { // clear the item from the list - memset( &m_IconList[i], 0, sizeof icon_sprite_t ); + memset( &m_IconList[i], 0, sizeof( icon_sprite_t )); return; } } diff --git a/cl_dll/util.cpp b/cl_dll/util.cpp index 6102d2b..e8f1c33 100644 --- a/cl_dll/util.cpp +++ b/cl_dll/util.cpp @@ -18,9 +18,10 @@ // implementation of class-less helper functions // -#include "STDIO.H" -#include "STDLIB.H" -#include "MATH.H" +#include +#include +#include +#include #include "hud.h" #include "cl_util.h" @@ -43,7 +44,7 @@ pfnAlertMessage ============= */ -void ALERT( ALERT_TYPE level, char *szFmt, ... ) +void ALERT( ALERT_TYPE level, const char *szFmt, ... ) { char buffer[2048]; // must support > 1k messages va_list args; @@ -1418,4 +1419,4 @@ color24 UnpackColor( float pack ) color.z = color.z - floor( color.z ); return color24( color.x * 256, color.y * 256, color.z * 256 ); -} \ No newline at end of file +} diff --git a/cl_dll/vgui_CustomObjects.cpp b/cl_dll/vgui_CustomObjects.cpp index 4e4f38a..34f1c6f 100644 --- a/cl_dll/vgui_CustomObjects.cpp +++ b/cl_dll/vgui_CustomObjects.cpp @@ -32,7 +32,7 @@ #include "vgui_int.h" #include "vgui_TeamFortressViewport.h" #include "vgui_ServerBrowser.h" -#include "../game_shared/vgui_LoadTGA.h" +#include "../game_shared/vgui_loadtga.h" // Arrow filenames char *sArrowFilenames[] = diff --git a/cl_dll/vgui_ScorePanel.cpp b/cl_dll/vgui_ScorePanel.cpp index 20bbeaf..e788c60 100644 --- a/cl_dll/vgui_ScorePanel.cpp +++ b/cl_dll/vgui_ScorePanel.cpp @@ -303,7 +303,8 @@ void ScorePanel::Update() void ScorePanel::SortTeams() { // clear out team scores - for ( int i = 1; i <= m_iNumTeams; i++ ) + int i; + for ( i = 1; i <= m_iNumTeams; i++ ) { if ( !g_TeamInfo[i].scores_overriden ) g_TeamInfo[i].frags = g_TeamInfo[i].deaths = 0; @@ -320,7 +321,8 @@ void ScorePanel::SortTeams() continue; // skip over players who are not in a team // find what team this player is in - for ( int j = 1; j <= m_iNumTeams; j++ ) + int j; + for ( j = 1; j <= m_iNumTeams; j++ ) { if ( !stricmp( g_PlayerExtraInfo[i].teamname, g_TeamInfo[j].name ) ) break; @@ -462,7 +464,8 @@ void ScorePanel::SortPlayers( int iTeam, char *team ) void ScorePanel::RebuildTeams() { // clear out player counts from teams - for ( int i = 1; i <= m_iNumTeams; i++ ) + int i; + for ( i = 1; i <= m_iNumTeams; i++ ) { g_TeamInfo[i].players = 0; } @@ -479,7 +482,8 @@ void ScorePanel::RebuildTeams() continue; // skip over players who are not in a team // is this player in an existing team? - for ( int j = 1; j <= m_iNumTeams; j++ ) + int j; + for ( j = 1; j <= m_iNumTeams; j++ ) { if ( g_TeamInfo[j].name[0] == '\0' ) break; @@ -541,7 +545,8 @@ void ScorePanel::FillGrid() bool bNextRowIsGap = false; - for(int row=0; row < NUM_ROWS; row++) + int row; + for(row=0; row < NUM_ROWS; row++) { CGrid *pGridRow = &m_PlayerGrids[row]; pGridRow->SetRowUnderline(0, false, 0, 0, 0, 0, 0); diff --git a/cl_dll/vgui_TeamFortressViewport.cpp b/cl_dll/vgui_TeamFortressViewport.cpp index 172d3d7..258b1d5 100644 --- a/cl_dll/vgui_TeamFortressViewport.cpp +++ b/cl_dll/vgui_TeamFortressViewport.cpp @@ -1070,11 +1070,11 @@ try pfile = gEngfuncs.COM_ParseFile(pfile, token); } } -catch( CException *e ) +catch( ... /* CException *e */ ) { - e; + /*e; //e->Delete(); - e = NULL; + e = NULL;*/ m_iInitialized = false; return newIndex; } @@ -2366,7 +2366,8 @@ int TeamFortressViewport::MsgFunc_TeamScore( const char *pszName, int iSize, voi char *TeamName = READ_STRING(); // find the team matching the name - for ( int i = 1; i <= m_pScoreBoard->m_iNumTeams; i++ ) + int i; + for ( i = 1; i <= m_pScoreBoard->m_iNumTeams; i++ ) { if ( !stricmp( TeamName, g_TeamInfo[i].name ) ) break; @@ -2545,4 +2546,4 @@ void VGuiAddPickupMessage( client_textmessage_t *msg ) gViewPort->AddPickupMessage( msg ); else gEngfuncs.Con_Printf("Pickup message error: Viewport is not constructed!\n"); -} \ No newline at end of file +} diff --git a/cl_dll/vgui_TeamFortressViewport.h b/cl_dll/vgui_TeamFortressViewport.h index cfd205e..3a49360 100644 --- a/cl_dll/vgui_TeamFortressViewport.h +++ b/cl_dll/vgui_TeamFortressViewport.h @@ -684,14 +684,14 @@ protected: char m_pszCommand[MAX_COMMAND_SIZE]; int m_iCloseVGUIMenu; public: - CMenuHandler_StringCommand( char *pszCommand ) + CMenuHandler_StringCommand( const char *pszCommand ) { strncpy( m_pszCommand, pszCommand, MAX_COMMAND_SIZE); m_pszCommand[MAX_COMMAND_SIZE-1] = '\0'; m_iCloseVGUIMenu = false; } - CMenuHandler_StringCommand( char *pszCommand, int iClose ) + CMenuHandler_StringCommand( const char *pszCommand, int iClose ) { strncpy( m_pszCommand, pszCommand, MAX_COMMAND_SIZE); m_pszCommand[MAX_COMMAND_SIZE-1] = '\0'; @@ -715,11 +715,11 @@ class CMenuHandler_StringCommandWatch : public CMenuHandler_StringCommand { private: public: - CMenuHandler_StringCommandWatch( char *pszCommand ) : CMenuHandler_StringCommand( pszCommand ) + CMenuHandler_StringCommandWatch( const char *pszCommand ) : CMenuHandler_StringCommand( pszCommand ) { } - CMenuHandler_StringCommandWatch( char *pszCommand, int iClose ) : CMenuHandler_StringCommand( pszCommand, iClose ) + CMenuHandler_StringCommandWatch( const char *pszCommand, int iClose ) : CMenuHandler_StringCommand( pszCommand, iClose ) { } @@ -745,11 +745,11 @@ class CMenuHandler_StringCommandClassSelect : public CMenuHandler_StringCommand { private: public: - CMenuHandler_StringCommandClassSelect( char *pszCommand ) : CMenuHandler_StringCommand( pszCommand ) + CMenuHandler_StringCommandClassSelect( const char *pszCommand ) : CMenuHandler_StringCommand( pszCommand ) { } - CMenuHandler_StringCommandClassSelect( char *pszCommand, int iClose ) : CMenuHandler_StringCommand( pszCommand, iClose ) + CMenuHandler_StringCommandClassSelect( const char *pszCommand, int iClose ) : CMenuHandler_StringCommand( pszCommand, iClose ) { } diff --git a/cl_dll/vgui_radio.cpp b/cl_dll/vgui_radio.cpp index 407e4e9..6fbf74c 100644 --- a/cl_dll/vgui_radio.cpp +++ b/cl_dll/vgui_radio.cpp @@ -50,7 +50,7 @@ void CRadioIcon::Initialize() CRadioIcon::CRadioIcon() : Panel(0, 0, 10, 10) { - if( m_pSpeakerBitmap = vgui_LoadTGANoInvertAlpha("gfx/vgui/speaker4.tga" ) ) + if(( m_pSpeakerBitmap = vgui_LoadTGANoInvertAlpha("gfx/vgui/speaker4.tga" ) )) m_pSpeakerBitmap->setColor( Color(255,255,255,1) ); else gEngfuncs.Con_Printf("Cannot load gfx/vgui/speaker4.tga!\n"); diff --git a/cl_dll/vgui_screenmsg.h b/cl_dll/vgui_screenmsg.h index e9349e1..2d91845 100644 --- a/cl_dll/vgui_screenmsg.h +++ b/cl_dll/vgui_screenmsg.h @@ -7,9 +7,7 @@ using namespace vgui; #include "vgui_shadowtext.h" - -Font* FontFromMessage(const char* &ptext); - +#include "getfont.h" class CScreenMessage : public ShadowTextPanel { @@ -170,4 +168,4 @@ protected: float m_delay; }; -#endif // _VGUIMSG_H \ No newline at end of file +#endif // _VGUIMSG_H diff --git a/cl_dll/vgui_tips.cpp b/cl_dll/vgui_tips.cpp index e07c7bb..96e1deb 100644 --- a/cl_dll/vgui_tips.cpp +++ b/cl_dll/vgui_tips.cpp @@ -30,9 +30,6 @@ void ShowTip( client_textmessage_t *tempMessage ) gEngfuncs.Con_Printf("Tips error: m_pTips or ViewPort is not constructed!\n"); } - -Font* FontFromMessage(const char* &ptext); - void CTips::Initialize() { setVisible(false); diff --git a/common/port.h b/common/port.h index b1af492..eb2a030 100644 --- a/common/port.h +++ b/common/port.h @@ -66,6 +66,7 @@ GNU General Public License for more details. #define FreeLibrary( x ) dlclose( x ) #define tell( a ) lseek(a, 0, SEEK_CUR) #define HAVE_DUP + #define _aligned_malloc( x, y ) aligned_alloc( y, x ) // man 3 posix_memalign #endif #if XASH_DOS4GW @@ -152,6 +153,14 @@ GNU General Public License for more details. #include #include +#if !defined MAX_PATH +#define MAX_PATH 4096 // 4k ought to be enough for anybody +#endif + +#if __cplusplus >= 2011L +#define COMPILE_TIME_ASSERT static_assert +#endif + #if defined XASH_SDL && !defined REF_DLL #include #endif diff --git a/game_shared/mathlib.h b/game_shared/mathlib.h index a224ce2..73563fa 100644 --- a/game_shared/mathlib.h +++ b/game_shared/mathlib.h @@ -96,6 +96,21 @@ void VectorAngles( const Vector &forward, Vector &angles ); void VectorAngles2( const Vector &forward, Vector &angles ); void MakeAxial( float normal[3] ); +// return the smallest power of two >= x. +// returns 0 if x == 0 or x > 0x80000000 (ie numbers that would be negative if x was signed) +// NOTE: the old code took an int, and if you pass in an int of 0x80000000 casted to a uint, +// you'll get 0x80000000, which is correct for uints, instead of 0, which was correct for ints +_forceinline uint SmallestPowerOfTwoGreaterOrEqual( uint x ) +{ + x -= 1; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x + 1; +} + // Remap a value in the range [A,B] to [C,D]. inline float RemapVal( float val, float A, float B, float C, float D) { @@ -263,4 +278,4 @@ float PackNormal( const Vector &normal ); extern float g_hullcolor[8][3]; extern int g_boxpnt[6][4]; -#endif//MATHLIB_H \ No newline at end of file +#endif//MATHLIB_H diff --git a/game_shared/matrix.h b/game_shared/matrix.h index 3da1b49..42e0ffc 100644 --- a/game_shared/matrix.h +++ b/game_shared/matrix.h @@ -1114,4 +1114,4 @@ public: Vector4D mat[4]; }; -#endif//MATRIX_H \ No newline at end of file +#endif//MATRIX_H diff --git a/game_shared/utlblockmemory.h b/game_shared/utlblockmemory.h index 965257f..0721334 100644 --- a/game_shared/utlblockmemory.h +++ b/game_shared/utlblockmemory.h @@ -244,7 +244,8 @@ void CUtlBlockMemory::ChangeSize( int nBlocks ) if ( !m_pMemory ) { - Error( "CUtlBlockMemory overflow!\n" ); + printf( "CUtlBlockMemory overflow!\n" ); + abort(); } // allocate new blocks if growing @@ -316,4 +317,4 @@ void CUtlBlockMemory::Purge( int numElements ) ChangeSize( nBlocks ); } -#endif // UTLBLOCKMEMORY_H \ No newline at end of file +#endif // UTLBLOCKMEMORY_H diff --git a/game_shared/vgui_slider2.cpp b/game_shared/vgui_slider2.cpp index 1b3381e..7dde524 100644 --- a/game_shared/vgui_slider2.cpp +++ b/game_shared/vgui_slider2.cpp @@ -433,4 +433,4 @@ void Slider2::setRangeWindowEnabled(bool state) void Slider2::setButtonOffset(int buttonOffset) { _buttonOffset=buttonOffset; -} \ No newline at end of file +} diff --git a/game_shared/virtualfs.cpp b/game_shared/virtualfs.cpp new file mode 100644 index 0000000..e57ee37 --- /dev/null +++ b/game_shared/virtualfs.cpp @@ -0,0 +1,33 @@ +//======================================================================= +// Copyright (C) XashXT Group 2014 +// virtualfs.h - Virtual FileSystem that writes into memory +//======================================================================= +#include "port.h" +#include +#include "mathlib.h" +#include "stringlib.h" +#include "virtualfs.h" + +size_t CVirtualFS :: Printf( const char *fmt, ... ) +{ + size_t result; + va_list args; + + va_start( args, fmt ); + result = VPrintf( fmt, args ); + va_end( args ); + + return result; +} + +size_t CVirtualFS :: IPrintf( const char *fmt, ... ) +{ + size_t result; + va_list args; + + va_start( args, fmt ); + result = IVPrintf( fmt, args ); + va_end( args ); + + return result; +} diff --git a/utils/vgui b/utils/vgui index f556626..9357307 160000 --- a/utils/vgui +++ b/utils/vgui @@ -1 +1 @@ -Subproject commit f5566261bda70bc5e0f2d277bfbadd2316c18bfb +Subproject commit 93573075afe885618ea15831e72d44bdacd65bfb diff --git a/wscript b/wscript index c515ac7..a697b2a 100644 --- a/wscript +++ b/wscript @@ -255,7 +255,7 @@ def configure(conf): pass else: conf.env.append_unique('DEFINES', ['stricmp=strcasecmp', 'strnicmp=strncasecmp', '_snprintf=snprintf', '_vsnprintf=vsnprintf', '_LINUX', 'LINUX']) - conf.env.append_unique('CXXFLAGS', ['-Wno-invalid-offsetof', '-fno-rtti', '-fno-exceptions']) + conf.env.append_unique('CXXFLAGS', ['-Wno-invalid-offsetof', '-fno-rtti']) # strip lib from pattern if conf.env.DEST_OS in ['linux', 'darwin']: