Haptics!! Yeah!

- haptics for damage / weapons / hitting sh*t with the crowbar
- when you pull the pin on the grenade
- and when you grab the crowbar from your "backpack"
- the geiger counter will also haptic blip the flashlight as well as the audible beep
This commit is contained in:
Simon committed 2019-10-10 18:08:45 +01:00
1 parent e179ff1077
commit ff8d710aed
16 files changed
+77 -65

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.lambda1vr"
android:versionCode="10"
android:versionName="1.1.2" android:installLocation="auto" >
android:versionName="1.2.0" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>
@@ -1327,6 +1327,33 @@ void Android_MessageBox(const char *title, const char *text)
ALOGE("%s %s", title, text);
}
/*
========================
Android_Vibrate
========================
*/
//0 = left, 1 = right
float vibration_channel_duration[2] = {0.0f, 0.0f};
float vibration_channel_intensity[2] = {0.0f, 0.0f};
extern convar_t *vibration_enable;
void Android_Vibrate( float duration, int channel, float intensity )
{
if( !vibration_enable->integer )
return;
if (vibration_channel_duration[channel] > 0.0f)
return;
if (vibration_channel_duration[channel] == -1.0f && duration != 0.0f)
return;
vibration_channel_duration[channel] = duration;
vibration_channel_intensity[channel] = intensity;
}
void initialize_gl4es();
void VR_Init()
@@ -1532,6 +1559,31 @@ void * AppThreadFunction( void * parm )
vrapi_SubmitFrame2( appState.Ovr, &frameDesc );
}
//Handle haptics
static float lastFrameTime = 0.0f;
float timestamp = (float)(GetTimeInMilliSeconds());
float frametime = timestamp - lastFrameTime;
lastFrameTime = timestamp;
for (int i = 0; i < 2; ++i) {
if (vibration_channel_duration[i] > 0.0f ||
vibration_channel_duration[i] == -1.0f) {
vrapi_SetHapticVibrationSimple(appState.Ovr, controllerIDs[i],
vibration_channel_intensity[i]);
if (vibration_channel_duration[i] != -1.0f) {
vibration_channel_duration[i] -= frametime;
if (vibration_channel_duration[i] < 0.0f) {
vibration_channel_duration[i] = 0.0f;
vibration_channel_intensity[i] = 0.0f;
}
}
} else {
vrapi_SetHapticVibrationSimple(appState.Ovr, controllerIDs[i], 0.0f);
}
}
if (runStatus == -1) {
#ifndef NDEBUG
if (appState.FrameIndex > 10800)
@@ -64,4 +64,4 @@ void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
void QuatToYawPitchRoll(ovrQuatf q, float pitchAdjust, vec3_t out);
bool useScreenLayer();
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
void Android_Vibrate( float duration, int channel, float intensity );
@@ -12,6 +12,8 @@ ovrInputStateTrackedRemote rightTrackedRemoteState_old;
ovrInputStateTrackedRemote rightTrackedRemoteState_new;
ovrTracking rightRemoteTracking_new;
ovrDeviceID controllerIDs[2];
float remote_movementSideways;
float remote_movementForward;
float positional_movementSideways;
@@ -135,9 +135,11 @@ void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The
if (remoteCapabilities.ControllerCapabilities & ovrControllerCaps_RightHand) {
rightTrackedRemoteState_new = trackedRemoteState;
rightRemoteTracking_new = remoteTracking;
controllerIDs[1] = cap.DeviceID;
} else{
leftTrackedRemoteState_new = trackedRemoteState;
leftRemoteTracking_new = remoteTracking;
controllerIDs[0] = cap.DeviceID;
}
}
}
@@ -197,6 +197,7 @@ void HandleInput_Left( ovrMobile * Ovr, double displayTime )
if (dominantGripPushed) {
//Initiate crowbar from backpack mode
sendButtonActionSimple("weapon_crowbar");
Android_Vibrate(80, 0, 0.8); // vibrate to let user know they switched
grabMeleeWeapon = 1;
}
}
@@ -194,6 +194,7 @@ void HandleInput_Right(ovrMobile * Ovr, double displayTime )
if (dominantGripPushed) {
//Initiate crowbar from backpack mode
sendButtonActionSimple("weapon_crowbar");
Android_Vibrate(80, 1, 0.8); // vibrate to let user know they switched
grabMeleeWeapon = 1;
}
}
@@ -28,37 +28,27 @@ GNU General Public License for more details.
mobile_engfuncs_t *gMobileEngfuncs;
convar_t *vibration_length;
convar_t *vibration_enable;
static void pfnVibrate( float life, char flags )
static void pfnVibrate( float duration, int channel, float intensity )
{
if( !vibration_enable->integer )
return;
if( life < 0.0f )
{
MsgDev( D_WARN, "Negative vibrate time: %f\n", life );
return;
}
//MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags );
// here goes platform-specific backends
#ifdef __ANDROID__
Android_Vibrate( life * vibration_length->value, flags );
Android_Vibrate( duration, channel, intensity );
#endif
}
static void Vibrate_f()
{
if( Cmd_Argc() != 2 )
if( Cmd_Argc() != 4 )
{
Msg( "Usage: vibrate <time>\n" );
Msg( "Usage: vibrate <time> <channel> <intensity>\n" );
return;
}
pfnVibrate( Q_atof( Cmd_Argv(1) ), VIBRATE_NORMAL );
pfnVibrate( Q_atof( Cmd_Argv(1) ), Q_atoi( Cmd_Argv(2) ), Q_atof( Cmd_Argv(3) ));
}
static void pfnEnableTextInput( int enable )
@@ -140,7 +130,6 @@ void Mobile_Init( void )
}
Cmd_AddCommand( "vibrate", (xcommand_t)Vibrate_f, "Vibrate for specified time");
vibration_length = Cvar_Get( "vibration_length", "1.0", CVAR_ARCHIVE, "Vibration length");
vibration_enable = Cvar_Get( "vibration_enable", "1", CVAR_ARCHIVE, "Enable vibration");
}
@@ -139,7 +139,7 @@ Q_buildcommit will identify this build as release or "notset"
*/
const char *Q_buildcommit( void )
{
return "Lambda1VR-v1.1.2";
return "Lambda1VR-v1.2.0";
}
/*
@@ -1332,7 +1332,7 @@ int EXPORT Host_Main( int argc, const char **argv, const char *progname, int bCh
Cmd_AddCommand ( "net_error", Net_Error_f, "send network bad message from random place");
}
host_cheats = Cvar_Get( "sv_cheats", "1", CVAR_LATCH, "allow usage of cheat commands and variables" );
host_cheats = Cvar_Get( "sv_cheats", "0", CVAR_LATCH, "allow usage of cheat commands and variables" );
host_maxfps = Cvar_Get( "fps_max", "72", CVAR_ARCHIVE, "host fps upper limit" );
host_sleeptime = Cvar_Get( "sleeptime", "1", CVAR_ARCHIVE, "higher value means lower accuracy" );
host_framerate = Cvar_Get( "host_framerate", "0", 0, "locks frame timing to this value in seconds" );
@@ -44,7 +44,7 @@ typedef struct mobile_engfuncs_s
// vibration control
// life -- time to vibrate in ms
void (*pfnVibrate)( float life, char flags );
void (*pfnVibrate)( float duration, int channel, float intensity );
// enable text input
void (*pfnEnableTextInput)( int enable );
@@ -19,7 +19,7 @@ GNU General Public License for more details.
//
// mobility interface implementation
//
void Android_Vibrate( float life, char flags );
void Android_Vibrate( float duration, int channel, float intensity );
void *Android_GetNativeObject( const char *obj );
void Android_ShellExecute( const char *path, const char *parms );
@@ -944,19 +944,6 @@ void Android_EnableTextInput( qboolean enable, qboolean force )
}
}
/*
========================
Android_Vibrate
========================
*/
void Android_Vibrate( float life, char flags )
{
return;
if( life )
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.vibrate, (int)life );
}
/*
========================
Android_GetNativeObject
@@ -39,7 +39,6 @@ private:
void _Init() override;
void _VidInit() override;
void GetConfig();
void VibrateChanged();
void SaveAndPopMenu() override;
void LerpingCvarWrite();
@@ -69,30 +68,12 @@ void CMenuAudio::GetConfig( void )
soundVolume.LinkCvar( "volume" );
musicVolume.LinkCvar( "MP3Volume" );
suitVolume.LinkCvar( "suitvolume" );
vibration.LinkCvar( "vibration_length" );
lerping.LinkCvar( "s_lerping", CMenuEditable::CVAR_VALUE );
noDSP.LinkCvar( "dsp_off" );
muteFocusLost.LinkCvar( "snd_mute_losefocus" );
vibrationEnable.LinkCvar( "vibration_enable" );
reverseChannels.LinkCvar( "s_reverse_channels" );
if( !vibrationEnable.bChecked )
vibration.SetGrayed( true );
oldVibrate = vibration.GetCurrentValue();
}
void CMenuAudio::VibrateChanged()
{
float newVibrate = vibration.GetCurrentValue();
if( oldVibrate != newVibrate )
{
char cmd[64];
snprintf( cmd, 64, "vibrate %f", newVibrate );
EngFuncs::ClientCmd( FALSE, cmd );
vibration.WriteCvar();
oldVibrate = newVibrate;
}
}
/*
@@ -166,11 +147,6 @@ void CMenuAudio::_Init( void )
vibrationEnable.onChanged.pExtra = &vibration.iFlags;
vibrationEnable.SetCoord( 700, 470 );
vibration.SetNameAndStatus( "Vibration", "Default vibration length" );
vibration.Setup( 0.0f, 5.0f, 0.05f );
vibration.onChanged = VoidCb( &CMenuAudio::VibrateChanged );
vibration.SetCoord( 700, 570 );
reverseChannels.SetNameAndStatus( "Reverse audio channels", "Use it when you can't swap your headphones' speakers" );
reverseChannels.onChanged = CMenuEditable::WriteCvarCb;
reverseChannels.SetCoord( 320, 620 );
@@ -67,11 +67,13 @@ void CMenuOptions::_Init( void )
AddButton( "Video", "Change screen size, video mode and gamma",
PC_VIDEO, UI_Video_Menu, QMF_NOTIFY );
// Cheats
AddButton( "No Clip", "No Clip", PC_CONSOLE, UI_NoClip_Btn, QMF_NOTIFY );
AddButton( "God", "God", PC_CONSOLE, UI_God_Btn, QMF_NOTIFY );
AddButton( "Give Suit", "Give Suit", PC_CONSOLE, UI_GiveSuit_Btn, QMF_NOTIFY );
AddButton( "Give Crowbar", "Give Crowbar", PC_CONSOLE, UI_GiveCrowbar_Btn, QMF_NOTIFY );
// Cheats - Only add these if sv_cheats is enabled
if (EngFuncs::GetCvarFloat("sv_cheats") != 0.0f) {
AddButton("No Clip", "No Clip", PC_CONSOLE, UI_NoClip_Btn, QMF_NOTIFY);
AddButton("God", "God", PC_CONSOLE, UI_God_Btn, QMF_NOTIFY);
AddButton("Give Suit", "Give Suit", PC_CONSOLE, UI_GiveSuit_Btn, QMF_NOTIFY);
AddButton("Give Crowbar", "Give Crowbar", PC_CONSOLE, UI_GiveCrowbar_Btn, QMF_NOTIFY);
}
#ifndef VR
AddButton( "Touch", "Change touch settings and buttons",