/* =============== IN_StartupJoystick =============== */ void IN_StartupJoystick (void) { int numdevs; JOYCAPS jc; MMRESULT mmr; // assume no joystick joy_avail = 0; // abort startup if user requests no joystick if ( gEngfuncs.CheckParm ("-nojoy", NULL ) ) return; // 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_id<numdevs ; joy_id++) { memset (&ji, 0, sizeof(ji)); ji.dwSize = sizeof(ji); ji.dwFlags = JOY_RETURNCENTERED; if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR) break; } // abort startup if we didn't find a valid joystick if (mmr != JOYERR_NOERROR) { gEngfuncs.Con_DPrintf ("joystick not found -- no valid joysticks (%x)\n\n", mmr); return; } // get the capabilities of the selected joystick // abort startup if command fails memset (&jc, 0, sizeof(jc)); if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR) { gEngfuncs.Con_DPrintf ("joystick not found -- invalid joystick capabilities (%x)\n\n", mmr); return; } // save the joystick's number of buttons and POV status joy_numbuttons = jc.wNumButtons; joy_haspov = jc.wCaps & JOYCAPS_HASPOV; // 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", mmr); joy_avail = 1; joy_advancedinit = 0; }
/* =========== IN_ResetMouse FIXME: Call through to engine? =========== */ void IN_ResetMouse( void ) { // no work to do in SDL #ifdef _WIN32 // reset only if mouse is active and not in visible mode: if(mouseactive && !iVisibleMouse) { if ( !m_bRawInput && gEngfuncs.GetWindowCenterX && gEngfuncs.GetWindowCenterY ) { bool lockEntered = MouseThread_ActiveLock_Enter(); int centerX = gEngfuncs.GetWindowCenterX(); int centerY = gEngfuncs.GetWindowCenterY(); SetCursorPos ( centerX, centerY ); InterlockedExchange( &mouseThreadCenterX, centerX ); InterlockedExchange( &mouseThreadCenterY, centerY ); InterlockedExchange( &mouseThreadDeltaX, 0 ); InterlockedExchange( &mouseThreadDeltaY, 0 ); if(lockEntered) MouseThread_ActiveLock_Exit(); } } #endif }
void CAM_ToThirdPerson(void) { vec3_t viewangles; #if !defined( DEBUG ) if ( gEngfuncs.GetMaxClients() > 1 ) { // no thirdperson in multiplayer. return; } #endif gEngfuncs.GetViewAngles( (float *)viewangles ); if( !cam_thirdperson ) { cam_thirdperson = 1; cam_ofs[ YAW ] = viewangles[ YAW ]; cam_ofs[ PITCH ] = viewangles[ PITCH ]; cam_ofs[ 2 ] = CAM_MIN_DIST; } gEngfuncs.Cvar_SetValue( "cam_command", 0 ); }
/* ============ KeyDown ============ */ void KeyDown (kbutton_t *b) { int k; char *c; c = gEngfuncs.Cmd_Argv(1); if (c[0]) k = atoi(c); else k = -1; // typed manually at the console for continuous down if (k == b->down[0] || k == b->down[1]) return; // repeating key if (!b->down[0]) b->down[0] = k; else if (!b->down[1]) b->down[1] = k; else { gEngfuncs.Con_DPrintf ("Three keys down for a button '%c' '%c' '%c'!\n", b->down[0], b->down[1], c); return; } if (b->state & 1) return; // still down b->state |= 1 + 2; // down + impulse down }
/* =========== IN_MouseEvent =========== */ void DLLEXPORT IN_MouseEvent (int mstate) { int i; if ( iMouseInUse || g_iVisibleMouse ) return; // perform button actions for (i=0 ; i<mouse_buttons ; 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; }
/* =========== IN_Accumulate =========== */ void CL_DLLEXPORT IN_Accumulate(void) { //only accumulate mouse if we are not moving the camera with the mouse if(!iMouseInUse && !g_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 { int deltaX, deltaY; SDL_GetRelativeMouseState(&deltaX, &deltaY); mx_accum += deltaX; my_accum += deltaY; } // force the mouse to the center, so there's room to move IN_ResetMouse(); } } }
/* =========== IN_StartupMouse =========== */ void IN_StartupMouse (void) { if ( gEngfuncs.CheckParm ("-nomouse", NULL ) ) return; mouseinitialized = 1; 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]; } } mouse_buttons = MOUSE_BUTTON_COUNT; }
void DLLEXPORT HUD_Frame( double time ) { #ifdef USE_VGUI_FOR_GOLDSOURCE_SUPPORT if (!gViewPort) gEngfuncs.VGui_ViewportPaintBackground(HUD_GetRect()); #else gEngfuncs.VGui_ViewportPaintBackground(HUD_GetRect()); #endif }
/* ================= HUD_GetRect VGui stub ================= */ int *HUD_GetRect( void ) { static int extent[4]; extent[0] = gEngfuncs.GetWindowCenterX() - ScreenWidth / 2; extent[1] = gEngfuncs.GetWindowCenterY() - ScreenHeight / 2; extent[2] = gEngfuncs.GetWindowCenterX() + ScreenWidth / 2; extent[3] = gEngfuncs.GetWindowCenterY() + ScreenHeight / 2; return extent; }
/* =========== Force_CenterView_f =========== */ void Force_CenterView_f (void) { vec3_t viewangles; if (!iMouseInUse) { gEngfuncs.GetViewAngles( (float *)viewangles ); viewangles[PITCH] = 0; gEngfuncs.SetViewAngles( (float *)viewangles ); } }
void CL_LoadParticleMan( void ) { char szPDir[512]; if ( gEngfuncs.COM_ExpandFilename( PARTICLEMAN_DLLNAME, szPDir, sizeof( szPDir ) ) == FALSE ) { g_pParticleMan = NULL; g_hParticleManModule = NULL; return; } g_hParticleManModule = Sys_LoadModule( szPDir ); CreateInterfaceFn particleManFactory = Sys_GetFactory( g_hParticleManModule ); if ( particleManFactory == NULL ) { g_pParticleMan = NULL; g_hParticleManModule = NULL; return; } g_pParticleMan = (IParticleMan *)particleManFactory( PARTICLEMAN_INTERFACE, NULL); if ( g_pParticleMan ) { g_pParticleMan->SetUp( &gEngfuncs ); // Add custom particle classes here BEFORE calling anything else or you will die. g_pParticleMan->AddCustomParticleClassSize ( sizeof ( CBaseParticle ) ); } }
void DLLEXPORT HUD_Init( void ) { InitInput(); gHUD.Init(); gEngfuncs.pfnHookUserMsg( "Bhopcap", __MsgFunc_Bhopcap ); }
void TeamFortressViewport::paintBackground() { // int wide, tall; // getParent()->getSize( wide, tall ); // setSize( wide, tall ); gEngfuncs.VGui_ViewportPaintBackground(HUD_GetRect()); }
int CL_DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion ) { gEngfuncs = *pEnginefuncs; RecClInitialize(pEnginefuncs, iVersion); if (iVersion != CLDLL_INTERFACE_VERSION) return 0; memcpy(&gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t)); EV_HookEvents(); // get tracker interface, if any char szDir[512]; if (!gEngfuncs.COM_ExpandFilename("Bin/TrackerUI.dll", szDir, sizeof(szDir))) { g_pTrackerUser = NULL; g_hTrackerModule = NULL; return 1; } g_hTrackerModule = Sys_LoadModule(szDir); CreateInterfaceFn trackerFactory = Sys_GetFactory(g_hTrackerModule); if (!trackerFactory) { g_pTrackerUser = NULL; g_hTrackerModule = NULL; return 1; } g_pTrackerUser = (ITrackerUser *)trackerFactory(TRACKERUSER_INTERFACE_VERSION, NULL); return 1; }
void CAM_ClearStates( void ) { vec3_t viewangles; gEngfuncs.GetViewAngles( (float *)viewangles ); cam_pitchup.state = 0; cam_pitchdown.state = 0; cam_yawleft.state = 0; cam_yawright.state = 0; cam_in.state = 0; cam_out.state = 0; cam_thirdperson = 0; cam_command->value = 0; cam_mousemove=0; cam_snapto->value = 0; cam_distancemove = 0; cam_ofs[ 0 ] = 0.0; cam_ofs[ 1 ] = 0.0; cam_ofs[ 2 ] = CAM_MIN_DIST; cam_idealpitch->value = viewangles[ PITCH ]; cam_idealyaw->value = viewangles[ YAW ]; cam_idealdist->value = CAM_MIN_DIST; }
/* ============ KeyUp ============ */ void KeyUp (kbutton_t *b) { int k; char *c; c = gEngfuncs.Cmd_Argv(1); if (c[0]) k = atoi(c); else { // typed manually at the console, assume for unsticking, so clear all b->down[0] = b->down[1] = 0; b->state = 4; // impulse up return; } if (b->down[0] == k) b->down[0] = 0; else if (b->down[1] == k) b->down[1] = 0; else return; // key up without coresponding down (menu pass through) if (b->down[0] || b->down[1]) { //Con_Printf ("Keys down for button: '%c' '%c' '%c' (%d,%d,%d)!\n", b->down[0], b->down[1], c, b->down[0], b->down[1], c); return; // some other key is still holding it down } if (!(b->state & 1)) return; // still up (this should not happen) b->state &= ~1; // now up b->state |= 4; // impulse up }
void CAM_ToThirdPerson(void) { vec3_t viewangles; gEngfuncs.GetViewAngles( (float *)viewangles ); if( !cam_thirdperson ) { cam_thirdperson = 1; cam_ofs[ YAW ] = viewangles[ YAW ]; cam_ofs[ PITCH ] = viewangles[ PITCH ]; cam_ofs[ 2 ] = CAM_MIN_DIST; } gEngfuncs.Cvar_SetValue( "cam_command", 0 ); }
void CL_DLLEXPORT HUD_Frame( double time ) { gEngfuncs.VGui_ViewportPaintBackground(HUD_GetRect()); ServersThink( time ); GetClientVoiceMgr()->Frame(time); }
/* =========== IN_ResetMouse FIXME: Call through to engine? =========== */ void IN_ResetMouse(void) { // no work to do in SDL #ifdef _WIN32 if(!m_bRawInput && mouseactive && gEngfuncs.GetWindowCenterX && gEngfuncs.GetWindowCenterY) { SetCursorPos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY()); ThreadInterlockedExchange(&old_mouse_pos.x, gEngfuncs.GetWindowCenterX()); ThreadInterlockedExchange(&old_mouse_pos.y, gEngfuncs.GetWindowCenterY()); } if(gpGlobals && gpGlobals->time - s_flRawInputUpdateTime > 1.0f) { s_flRawInputUpdateTime = gpGlobals->time; m_bRawInput = CVAR_GET_FLOAT("m_rawinput") != 0; } #endif }
/* =========== IN_Accumulate =========== */ void DLLEXPORT IN_Accumulate (void) { //only accumulate mouse if we are not moving the camera with the mouse if ( !iMouseInUse && !g_iVisibleMouse ) { if (mouseactive) { GetCursorPos (¤t_pos); mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX(); my_accum += current_pos.y - gEngfuncs.GetWindowCenterY(); // force the mouse to the center, so there's room to move IN_ResetMouse(); } } }
int EXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion ) { gEngfuncs = *pEnginefuncs; //!!! mwh UNDONE We need to think about our versioning strategy. Do we want to try to be compatible // with previous versions, especially when we're only 'bonus' functionality? Should it be the engine // that decides if the DLL is compliant? if (iVersion != CLDLL_INTERFACE_VERSION) return 0; memcpy(&gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t)); EV_HookEvents(); // Determine which filesystem to use. #if defined ( _WIN32 ) char *szFsModule = "filesystem_stdio.dll"; #elif defined(OSX) char *szFsModule = "filesystem_stdio.dylib"; #elif defined(LINUX) char *szFsModule = "filesystem_stdio.so"; #else #error #endif char szFSDir[MAX_PATH]; szFSDir[0] = 0; if ( gEngfuncs.COM_ExpandFilename( szFsModule, szFSDir, sizeof( szFSDir ) ) == FALSE ) { return false; } // Get filesystem interface. g_pFileSystemModule = Sys_LoadModule( szFSDir ); assert( g_pFileSystemModule ); if( !g_pFileSystemModule ) { return false; } CreateInterfaceFn fileSystemFactory = Sys_GetFactory( g_pFileSystemModule ); if( !fileSystemFactory ) { return false; } g_pFileSystem = ( IFileSystem * )fileSystemFactory( FILESYSTEM_INTERFACE_VERSION, NULL ); assert( g_pFileSystem ); if( !g_pFileSystem ) { return false; } return 1; }
/* =========== Joy_AdvancedUpdate_f =========== */ void Joy_AdvancedUpdate_f (void) { // called once by IN_ReadJoystick and by user whenever an update is needed // cvars are now available int i; DWORD dwTemp; // initialize all the maps for (i = 0; i < JOY_MAX_AXES; i++) { dwAxisMap[i] = AxisNada; dwControlMap[i] = JOY_ABSOLUTE_AXIS; pdwRawValue[i] = RawValuePointer(i); } if( joy_advanced->value == 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; } }
/* =============== 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; int nJoysticks = SDL_NumJoysticks(); if ( nJoysticks > 0 ) { for ( int i = 0; i < nJoysticks; i++ ) { if ( SDL_IsGameController( i ) ) { s_pJoystick = SDL_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", SDL_GameControllerName(s_pJoystick)); joy_avail = 1; joy_advancedinit = 0; break; } } } } else { gEngfuncs.Con_DPrintf ("joystick not found -- driver not present\n\n"); } }
int HUD_Redraw(float time, int intermission) { static int count = 0; if (count < 10) { gEngfuncs.Con_Printf("F**k World!!!!! (hit:%d)\n", count + 1); count++; } return gExportfuncs.HUD_Redraw(time, intermission); }
void CAM_ToThirdPerson(void) { //Only allow cam_command if we are running a debug version of the client.dll #ifndef _DEBUG return; #endif vec3_t viewangles; gEngfuncs.GetViewAngles( (float *)viewangles ); if( !cam_thirdperson ) { cam_thirdperson = 1; cam_ofs[ YAW ] = viewangles[ YAW ]; cam_ofs[ PITCH ] = viewangles[ PITCH ]; cam_ofs[ 2 ] = CAM_MIN_DIST; } gEngfuncs.Cvar_SetValue( "cam_command", 0 ); }
bool HUD_MessageBox( const char *msg ) { gEngfuncs.Con_Printf( msg ); // just in case if( IsXashFWGS() ) { gMobileEngfuncs->pfnSys_Warn( msg ); return true; } // TODO: Load SDL2 and call ShowSimpleMessageBox return false; }
int DLLEXPORT HUD_VidInit( void ) { gHUD.VidInit(); #ifdef USE_VGUI_FOR_GOLDSOURCE_SUPPORT vgui::Panel* root=(vgui::Panel*)gEngfuncs.VGui_GetPanel(); if (root) { gEngfuncs.Con_Printf( "Root VGUI panel exists\n" ); root->setBgColor(128,128,0,0); if (gViewPort != NULL) { gViewPort->Initialize(); } else { gViewPort = new TeamFortressViewport(0,0,root->getWide(),root->getTall()); gViewPort->setParent(root); } } else { gEngfuncs.Con_Printf( "Root VGUI panel does not exist\n" ); } #endif return 1; }
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COPYDATA: { COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT*)lParam; char command[128]; strcpy(command, (char *)pCopyData->lpData); command[pCopyData->cbData] = 0; gEngfuncs.pfnClientCmd(command); return 1; } } return CallWindowProc(g_MainWndProc, hWnd, message, wParam, lParam); }
int CL_DLLEXPORT CL_IsThirdPerson( void ) { RecClCL_IsThirdPerson(); return (cam_thirdperson ? 1 : 0) || (g_iUser1 && (g_iUser2 == gEngfuncs.GetLocalPlayer()->index) ); }
void CAM_Init( void ) { gEngfuncs.pfnAddCommand( "+campitchup", CAM_PitchUpDown ); gEngfuncs.pfnAddCommand( "-campitchup", CAM_PitchUpUp ); gEngfuncs.pfnAddCommand( "+campitchdown", CAM_PitchDownDown ); gEngfuncs.pfnAddCommand( "-campitchdown", CAM_PitchDownUp ); gEngfuncs.pfnAddCommand( "+camyawleft", CAM_YawLeftDown ); gEngfuncs.pfnAddCommand( "-camyawleft", CAM_YawLeftUp ); gEngfuncs.pfnAddCommand( "+camyawright", CAM_YawRightDown ); gEngfuncs.pfnAddCommand( "-camyawright", CAM_YawRightUp ); gEngfuncs.pfnAddCommand( "+camin", CAM_InDown ); gEngfuncs.pfnAddCommand( "-camin", CAM_InUp ); gEngfuncs.pfnAddCommand( "+camout", CAM_OutDown ); gEngfuncs.pfnAddCommand( "-camout", CAM_OutUp ); gEngfuncs.pfnAddCommand( "thirdperson", CAM_ToThirdPerson ); gEngfuncs.pfnAddCommand( "firstperson", CAM_ToFirstPerson ); gEngfuncs.pfnAddCommand( "+cammousemove",CAM_StartMouseMove); gEngfuncs.pfnAddCommand( "-cammousemove",CAM_EndMouseMove); gEngfuncs.pfnAddCommand( "+camdistance", CAM_StartDistance ); gEngfuncs.pfnAddCommand( "-camdistance", CAM_EndDistance ); gEngfuncs.pfnAddCommand( "snapto", CAM_ToggleSnapto ); #ifdef DEBUG gEngfuncs.pfnAddCommand( "camtoggle", CAM_Toggle ); #endif cam_command = gEngfuncs.pfnRegisterVariable ( "cam_command", "0", 0 ); // tells camera to go to thirdperson cam_snapto = gEngfuncs.pfnRegisterVariable ( "cam_snapto", "0", 0 ); // snap to thirdperson view cam_idealyaw = gEngfuncs.pfnRegisterVariable ( "cam_idealyaw", "90", 0 ); // thirdperson yaw cam_idealpitch = gEngfuncs.pfnRegisterVariable ( "cam_idealpitch", "0", 0 ); // thirperson pitch cam_idealdist = gEngfuncs.pfnRegisterVariable ( "cam_idealdist", "64", 0 ); // thirdperson distance cam_contain = gEngfuncs.pfnRegisterVariable ( "cam_contain", "0", 0 ); // contain camera to world c_maxpitch = gEngfuncs.pfnRegisterVariable ( "c_maxpitch", "90.0", 0 ); c_minpitch = gEngfuncs.pfnRegisterVariable ( "c_minpitch", "0.0", 0 ); c_maxyaw = gEngfuncs.pfnRegisterVariable ( "c_maxyaw", "135.0", 0 ); c_minyaw = gEngfuncs.pfnRegisterVariable ( "c_minyaw", "-135.0", 0 ); c_maxdistance = gEngfuncs.pfnRegisterVariable ( "c_maxdistance", "200.0", 0 ); c_mindistance = gEngfuncs.pfnRegisterVariable ( "c_mindistance", "30.0", 0 ); }