inputsystem: fix UB in touch events callback, make touch more responsive

This commit is contained in:
nillerusr
2023-08-17 14:31:43 +03:00
parent 02a3c641a6
commit 4f10928299
8 changed files with 58 additions and 49 deletions

View File

@@ -729,7 +729,7 @@ public:
void PrecacheMaterial( const char *pMaterialName );
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar );
virtual void IN_TouchEvent( uint data, uint data2, uint data3, uint data4 );
virtual void IN_TouchEvent( int type, int fingerId, int x, int y );
private:
void UncacheAllMaterials( );
@@ -2637,24 +2637,20 @@ CSteamID GetSteamIDForPlayerIndex( int iPlayerIndex )
#endif
void CHLClient::IN_TouchEvent( uint data, uint data2, uint data3, uint data4 )
void CHLClient::IN_TouchEvent( int type, int fingerId, int x, int y )
{
if( enginevgui->IsGameUIVisible() )
return;
touch_event_t ev;
ev.type = data & 0xFFFF;
ev.fingerid = (data >> 16) & 0xFFFF;
ev.x = (double)((data2 >> 16) & 0xFFFF) / 0xFFFF;
ev.y = (double)(data2 & 0xFFFF) / 0xFFFF;
ev.type = type;
ev.fingerid = fingerId;
memcpy( &ev.x, &x, sizeof(ev.x) );
memcpy( &ev.y, &y, sizeof(ev.y) );
union{uint i;float f;} ifconv;
ifconv.i = data3;
ev.dx = ifconv.f;
ifconv.i = data4;
ev.dy = ifconv.f;
if( type == IE_FingerMotion )
inputsystem->GetTouchAccumulators( fingerId, ev.dx, ev.dy );
gTouch.ProcessEvent( &ev );
}