From 0c66efa48d40b0a9d4eb248fd1f4ec82c30cd010 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 20 Jul 2019 19:23:34 +0100 Subject: [PATCH] Several Changes.. - HUD positioning - still needs a bit of tweaking - Crowbar whoosing sounds now working - Flashlight on X button - Change weapon selection using right stick up/down, press fire to select chosen weapon --- .../jni/src/Lambda1VR/L1VR_SurfaceView.c | 102 ++++++++++-------- .../jni/src/hlsdk-xash3d/cl_dll/ammo.cpp | 10 +- .../hlsdk-xash3d/cl_dll/ammo_secondary.cpp | 2 +- .../src/hlsdk-xash3d/cl_dll/ammohistory.cpp | 12 +-- .../jni/src/hlsdk-xash3d/cl_dll/battery.cpp | 4 +- .../src/hlsdk-xash3d/cl_dll/status_icons.cpp | 4 +- .../jni/src/hlsdk-xash3d/cl_dll/vr_helper.cpp | 7 +- .../jni/src/hlsdk-xash3d/dlls/crowbar.cpp | 4 +- 8 files changed, 81 insertions(+), 64 deletions(-) diff --git a/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c b/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c index 4206471..b458330 100644 --- a/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c +++ b/Projects/Android/jni/src/Lambda1VR/L1VR_SurfaceView.c @@ -1148,6 +1148,11 @@ static inline sendButtonActionSimple(const char* action) Cbuf_AddText( command ); } +static inline between(float min, float val, float max) +{ + return (min < val) && (val < max); +} + static void ovrApp_HandleInput( ovrApp * app ) { //The amount of yaw changed by controller @@ -1312,11 +1317,19 @@ static void ovrApp_HandleInput( ovrApp * app ) flashlightangles[YAW] += (cl.refdef.cl_viewangles[YAW] - hmdorientation[YAW]); controllerYawHeading = -cl.refdef.cl_viewangles[YAW] + flashlightangles[YAW]; + //flashlight on/off + if (((leftTrackedRemoteState_new.Buttons & ovrButton_X) != + (leftTrackedRemoteState_old.Buttons & ovrButton_X)) && + (leftTrackedRemoteState_old.Buttons & ovrButton_X)) { + sendButtonActionSimple("impulse 100"); + } + //Run - handleTrackedControllerButton(offHandTrackedRemoteState, - offHandTrackedRemoteStateOld, + handleTrackedControllerButton(&leftTrackedRemoteState_new, + &leftTrackedRemoteState_old, ovrButton_GripTrigger, K_SHIFT); - } + + } //Right-hand specific stuff { @@ -1347,23 +1360,21 @@ static void ovrApp_HandleInput( ovrApp * app ) if (dominantGripPushed && (GetTimeInMilliSeconds() - dominantGripPushTime) > vr_reloadtimeoutms->integer) { //Fire Secondary - handleTrackedControllerButton(&rightTrackedRemoteState_new, - &rightTrackedRemoteState_old, - ovrButton_Trigger, K_MOUSE2); + if ((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) != + (rightTrackedRemoteState_old.Buttons & ovrButton_Trigger)) { + + sendButtonAction("+attack2", (rightTrackedRemoteState_new.Buttons & ovrButton_Trigger)); + } } else { //Fire Primary - handleTrackedControllerButton(&rightTrackedRemoteState_new, - &rightTrackedRemoteState_old, - ovrButton_Trigger, K_MOUSE1); + if ((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) != + (rightTrackedRemoteState_old.Buttons & ovrButton_Trigger)) { + + sendButtonAction("+attack", (rightTrackedRemoteState_new.Buttons & ovrButton_Trigger)); + } } } else { - //flashlight on/off - if ((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) && - ((rightTrackedRemoteState_new.Buttons & ovrButton_Trigger) != - (rightTrackedRemoteState_old.Buttons & ovrButton_Trigger))) { - - sendButtonActionSimple("impulse 100"); - } + //Unused for now } //Duck with A @@ -1372,6 +1383,27 @@ static void ovrApp_HandleInput( ovrApp * app ) sendButtonAction("+duck", (rightTrackedRemoteState_new.Buttons & ovrButton_A)); } + + //Weapon Chooser + static bool weaponSwitched = false; + if (between(-0.15f, rightTrackedRemoteState_new.Joystick.x, 0.15f) && + (between(0.7f, rightTrackedRemoteState_new.Joystick.y, 1.0f) || + between(-1.0f, rightTrackedRemoteState_new.Joystick.y, -0.7f))) + { + if (!weaponSwitched) { + if (between(0.7f, rightTrackedRemoteState_new.Joystick.y, 1.0f)) + { + sendButtonActionSimple("invnext"); + } + else + { + sendButtonActionSimple("invprev"); + } + weaponSwitched = true; + } + } else { + weaponSwitched = false; + } } //Left-hand specific stuff @@ -1400,25 +1432,23 @@ static void ovrApp_HandleInput( ovrApp * app ) remote_movementForward); if (!r_lefthand->integer) { - //flashlight on/off - if ((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) && - ((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) != - (leftTrackedRemoteState_old.Buttons & ovrButton_Trigger))) { - - sendButtonActionSimple("impulse 100"); - } + //Unused for now } else { if (dominantGripPushed && (GetTimeInMilliSeconds() - dominantGripPushTime) > vr_reloadtimeoutms->integer) { //Fire Secondary - handleTrackedControllerButton(&leftTrackedRemoteState_new, - &leftTrackedRemoteState_old, - ovrButton_Trigger, K_MOUSE2); + if ((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) != + (leftTrackedRemoteState_old.Buttons & ovrButton_Trigger)) { + + sendButtonAction("+attack2", (leftTrackedRemoteState_new.Buttons & ovrButton_Trigger)); + } } else { //Fire Primary - handleTrackedControllerButton(&leftTrackedRemoteState_new, - &leftTrackedRemoteState_old, - ovrButton_Trigger, K_MOUSE1); + if ((leftTrackedRemoteState_new.Buttons & ovrButton_Trigger) != + (leftTrackedRemoteState_old.Buttons & ovrButton_Trigger)) { + + sendButtonAction("+attack", (leftTrackedRemoteState_new.Buttons & ovrButton_Trigger)); + } } } @@ -1462,20 +1492,6 @@ static void ovrApp_HandleInput( ovrApp * app ) { decreaseSnap = true; } - - //Next Weapon - if (((leftTrackedRemoteState_new.Buttons & ovrButton_X) != - (leftTrackedRemoteState_old.Buttons & ovrButton_X)) && - (leftTrackedRemoteState_old.Buttons & ovrButton_X)){ - sendButtonActionSimple("invnext"); - } - - //Prev Weapon - if (((leftTrackedRemoteState_new.Buttons & ovrButton_Y) != - (leftTrackedRemoteState_old.Buttons & ovrButton_Y)) && - (leftTrackedRemoteState_old.Buttons & ovrButton_Y)){ - sendButtonActionSimple("invprev"); - } } } diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo.cpp index c1cd925..4f0cc01 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo.cpp @@ -871,7 +871,7 @@ int CHudAmmo::Draw( float flTime ) ScaleColors( r, g, b, a ); // Does this weapon have a clip? - y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2 - (ScreenHeight * 0.3f); + y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2 - (ScreenHeight / 3); // Does weapon have any ammo at all? if( m_pWeapon->iAmmoType > 0 ) @@ -1014,8 +1014,8 @@ int CHudAmmo::DrawWList( float flTime ) else iActiveSlot = gpActiveSel->iSlot; - x = 10; //!!! - y = 10; //!!! + x = ScreenWidth / 3; + y = ScreenHeight / 3; // Ensure that there are available choices in the active slot if( iActiveSlot > 0 ) @@ -1060,12 +1060,12 @@ int CHudAmmo::DrawWList( float flTime ) } a = 128; //!!! - x = 10; + x = ScreenWidth / 3; // Draw all of the buckets for( i = 0; i < MAX_WEAPON_SLOTS; i++ ) { - y = giBucketHeight + 10; + y = (ScreenHeight / 3) + giBucketHeight + 10; // If this is the active slot, draw the bigger pictures, // otherwise just draw boxes diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo_secondary.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo_secondary.cpp index f626113..fba03f2 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo_secondary.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammo_secondary.cpp @@ -68,7 +68,7 @@ int CHudAmmoSecondary::Draw( float flTime ) AmmoWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left; - y = (ScreenHeight * 0.3f) - ( gHUD.m_iFontHeight * 4 ); // this is one font height higher than the weapon ammo values + y = (ScreenHeight / 3) - ( gHUD.m_iFontHeight * 4 ); // this is one font height higher than the weapon ammo values x = (ScreenWidth * 0.65f) - AmmoWidth; if( m_HUD_ammoicon ) diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammohistory.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammohistory.cpp index 4b1e674..b01b319 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammohistory.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/ammohistory.cpp @@ -130,8 +130,8 @@ int HistoryResource::DrawAmmoHistory( float flTime ) ScaleColors( r, g, b, min( scale, 255 ) ); // Draw the pic - int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); - int xpos = ScreenWidth - 24; + int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)) - (ScreenHeight / 3); + int xpos = (ScreenWidth / 4) - 24; if( spr && *spr ) // weapon isn't loaded yet so just don't draw the pic { // the dll has to make sure it has sent info the weapons you need @@ -160,8 +160,8 @@ int HistoryResource::DrawAmmoHistory( float flTime ) float scale = ( rgAmmoHistory[i].DisplayTime - flTime ) * 80; ScaleColors( r, g, b, min( scale, 255 ) ); - int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) ); - int xpos = ScreenWidth - ( weap->rcInactive.right - weap->rcInactive.left ); + int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) ) - (ScreenHeight / 3); + int xpos = (ScreenWidth / 4) - ( weap->rcInactive.right - weap->rcInactive.left ); SPR_Set( weap->hInactive, r, g, b ); SPR_DrawAdditive( 0, xpos, ypos, &weap->rcInactive ); } @@ -178,8 +178,8 @@ int HistoryResource::DrawAmmoHistory( float flTime ) float scale = ( rgAmmoHistory[i].DisplayTime - flTime ) * 80; ScaleColors( r, g, b, min( scale, 255 ) ); - int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) ); - int xpos = ScreenWidth - ( rect.right - rect.left ) - 10; + int ypos = ScreenHeight - ( AMMO_PICKUP_PICK_HEIGHT + ( AMMO_PICKUP_GAP * i ) ) - (ScreenHeight / 3); + int xpos = (ScreenWidth / 4) - ( rect.right - rect.left ) - 10; SPR_Set( gHUD.GetSprite( rgAmmoHistory[i].iId ), r, g, b ); SPR_DrawAdditive( 0, xpos, ypos, &rect ); diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/battery.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/battery.cpp index 2f26057..9da8f08 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/battery.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/battery.cpp @@ -108,8 +108,8 @@ int CHudBattery::Draw( float flTime ) int iOffset = ( m_prc1->bottom - m_prc1->top ) / 6; - y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; - x = ScreenWidth / 5; + y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2 - (ScreenHeight / 3); + x = ScreenWidth / 4; // make sure we have the right sprite handles if( !m_hSprite1 ) diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/status_icons.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/status_icons.cpp index 4b2d972..6d01292 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/status_icons.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/status_icons.cpp @@ -56,8 +56,8 @@ int CHudStatusIcons::Draw( float flTime ) if( gEngfuncs.IsSpectateOnly() ) return 1; // find starting position to draw from, along right-hand side of screen - int x = 5; - int y = ScreenHeight / 2; + int x = ScreenWidth / 3; + int y = ScreenHeight / 3; // loop through icon list, and draw any valid icons drawing up from the middle of screen for( int i = 0; i < MAX_ICONSPRITES; i++ ) diff --git a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/vr_helper.cpp b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/vr_helper.cpp index b3fd5a6..1e80696 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/vr_helper.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/cl_dll/vr_helper.cpp @@ -151,9 +151,10 @@ void VRHelper::UpdateGunPosition(struct ref_params_s* pparams) Vector originInRelativeHLSpace(-originInVRSpace.z * vr_worldscale->value, -originInVRSpace.x * vr_worldscale->value, originInVRSpace.y * vr_worldscale->value); cl_entity_t *localPlayer = gEngfuncs.GetLocalPlayer(); - Vector clientGroundPosition = localPlayer->curstate.origin; - clientGroundPosition.z -= localPlayer->curstate.mins.z; - Vector originInHLSpace = clientGroundPosition + originInRelativeHLSpace; + Vector clientPosition = pparams->vieworg; + //Vector clientPositionInRelativeHLSpace(clientPosition.x * vr_worldscale->value, clientPosition.y * vr_worldscale->value, , clientPosition.z * vr_worldscale->value); + + Vector originInHLSpace = clientPosition + originInRelativeHLSpace; VectorCopy(originInHLSpace, viewent->origin); VectorCopy(originInHLSpace, viewent->curstate.origin); diff --git a/Projects/Android/jni/src/hlsdk-xash3d/dlls/crowbar.cpp b/Projects/Android/jni/src/hlsdk-xash3d/dlls/crowbar.cpp index a6d1775..14f3b60 100644 --- a/Projects/Android/jni/src/hlsdk-xash3d/dlls/crowbar.cpp +++ b/Projects/Android/jni/src/hlsdk-xash3d/dlls/crowbar.cpp @@ -160,10 +160,10 @@ void CCrowbar::ItemPostFrame() if (!playedWooshSound) { // prevent w-w-woo-woosh stutters when player waves crowbar around frantically - if (UTIL_WeaponTimeBase() > lastWooshSoundTime + 0.5f) + if (gpGlobals->time > lastWooshSoundTime + 0.5f) { EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, "weapons/cbar_miss1.wav", 1, ATTN_NORM, 0, 98 + RANDOM_LONG(0, 3)); - lastWooshSoundTime = UTIL_WeaponTimeBase(); + lastWooshSoundTime = gpGlobals->time; } playedWooshSound = true; }