Skip to content

Commit 4cc7391

Browse files
committed
perf: stop resetting mouse to center each frame
this is actually quite expensive on Windows. 5% of the frame can be used up by this over time due to weird process initialization, calling into WoW64, etc. this may have regressions. i tried testing as much as possible but vgui is a strange beast.
1 parent 8e7309e commit 4cc7391

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

src/engine/sys_mainwind.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ void CGame::AppActivate( bool fActive )
301301
ClearIOStates();
302302

303303
UpdateMaterialSystemConfig();
304+
305+
// Once we return, let VGUI know it needs to relock.
306+
vgui::surface()->UnlockCursor();
304307
}
305308
else
306309
{

src/game/client/in_mouse.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ void CInput::ActivateMouse (void)
138138
}
139139
m_fMouseActive = true;
140140

141-
ResetMouse();
142141
#if !defined( PLATFORM_WINDOWS )
142+
ResetMouse();
143143
int dx, dy;
144144
engine->GetMouseDelta( dx, dy, true );
145145
#endif
@@ -174,9 +174,10 @@ void CInput::DeactivateMouse (void)
174174
}
175175
m_fMouseActive = false;
176176
vgui::surface()->SetCursor( vgui::dc_arrow );
177-
#if !defined( PLATFORM_WINDOWS )
178177
// now put the mouse back in the middle of the screen
179178
ResetMouse();
179+
#ifdef PLATFORM_WINDOWS
180+
::ClipCursor(NULL);
180181
#endif
181182

182183
// Clear accumulated error, too
@@ -686,8 +687,10 @@ void CInput::MouseMove( CUserCmd *cmd )
686687
// Add mouse X/Y movement to cmd
687688
ApplyMouse( viewangles, cmd, mouse_x, mouse_y );
688689

690+
#if !defined( PLATFORM_WINDOWS )
689691
// Re-center the mouse.
690692
ResetMouse();
693+
#endif
691694
}
692695

693696
// Store out the new viewangles.

src/game/client/tf/vgui/tf_matchmaking_dashboard.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ void CTFMatchmakingPopup::OnTick()
314314
m_bActive = false;
315315
OnExit();
316316
}
317-
}
318317

319-
SetMouseInputEnabled( ShouldBeActve() );
320-
SetKeyBoardInputEnabled( false ); // Never
318+
SetMouseInputEnabled( bShouldBeActive );
319+
SetKeyBoardInputEnabled( false ); // Never
320+
}
321321
}
322322

323323

src/vguimatsurface/MatSystemSurface.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,8 @@ void CMatSystemSurface::CalculateMouseVisible()
41084108
int c = surface()->GetPopupCount();
41094109

41104110
VPANEL modalSubTree = input()->GetModalSubTree();
4111+
VPanel* p = nullptr;
4112+
41114113
if ( modalSubTree )
41124114
{
41134115
for (i = 0 ; i < c ; i++ )
@@ -4118,7 +4120,7 @@ void CMatSystemSurface::CalculateMouseVisible()
41184120
continue;
41194121

41204122
bool isVisible=pop->IsVisible();
4121-
VPanel *p= pop->GetParent();
4123+
p= pop->GetParent();
41224124

41234125
while (p && isVisible)
41244126
{
@@ -4148,7 +4150,7 @@ void CMatSystemSurface::CalculateMouseVisible()
41484150
VPanel *pop = (VPanel *)surface()->GetPopup(i) ;
41494151

41504152
bool isVisible=pop->IsVisible();
4151-
VPanel *p= pop->GetParent();
4153+
p= pop->GetParent();
41524154

41534155
while (p && isVisible)
41544156
{
@@ -4185,6 +4187,27 @@ void CMatSystemSurface::CalculateMouseVisible()
41854187
}
41864188
else
41874189
{
4190+
#ifdef PLATFORM_WINDOWS
4191+
if (!IsCursorLocked() && p)
4192+
{
4193+
VPanel* contextPanel = p;
4194+
while (contextPanel->GetParent() && !contextPanel->Plat())
4195+
{
4196+
contextPanel = contextPanel->GetParent();
4197+
}
4198+
int absThis[4];
4199+
contextPanel->GetAbsPos(absThis[0], absThis[1]);
4200+
contextPanel->GetSize(absThis[2], absThis[3]);
4201+
absThis[2] += absThis[0];
4202+
absThis[3] += absThis[1];
4203+
RECT rect;
4204+
rect.left = absThis[0];
4205+
rect.top = absThis[1];
4206+
rect.right = absThis[2];
4207+
rect.bottom = absThis[3];
4208+
::ClipCursor(&rect);
4209+
}
4210+
#endif
41884211
SetCursor(vgui::dc_none);
41894212
LockCursor();
41904213
}

0 commit comments

Comments
 (0)