Couple of changes

- Updated bHaptics aars to v1.15
- Added support for looping sound effects that trigger haptics
This commit is contained in:
Simon 2021-03-10 21:48:41 +00:00
parent 1bac1246c3
commit 6082f9ebc8
19 changed files with 172 additions and 110 deletions

View file

@ -955,20 +955,26 @@ void Doom3Quest_Vibrate(int channel, float low, float high)
vibration_channel_intensity[channel][1] = high;
}
void jni_haptic_event(const char* event, int position, int intensity, float angle, float yHeight);
void jni_haptic_event(const char* event, int position, int flags, int intensity, float angle, float yHeight);
void jni_haptic_stopevent(const char* event);
void jni_haptic_stopall();
void jni_haptic_beginframe();
void jni_haptic_endframe();
void jni_haptic_enable();
void jni_haptic_disable();
void Doom3Quest_HapticEvent(const char* event, int position, int intensity, float angle, float yHeight )
void Doom3Quest_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight )
{
jni_haptic_event(event, position, intensity, angle, yHeight);
jni_haptic_event(event, position, flags, intensity, angle, yHeight);
}
void Doom3Quest_HapticStopAll()
void Doom3Quest_HapticBeginFrame()
{
jni_haptic_stopall();
jni_haptic_beginframe();
}
void Doom3Quest_HapticEndFrame()
{
jni_haptic_endframe();
}
void Doom3Quest_HapticStopEvent(const char* event)
@ -1730,6 +1736,8 @@ void Doom3Quest_processHaptics() {//Handle haptics
else
vrapi_SetHapticVibrationSimple(gAppState.Ovr, controllerIDs[1 - h], 0.0f);
}
Doom3Quest_HapticBeginFrame();
}
void showLoadingIcon()
@ -1912,6 +1920,8 @@ void Doom3Quest_submitFrame()
gAppState.RenderThreadFrameIndex++;
SDL_UnlockMutex(gAppState.RenderThreadFrameIndex_Mutex);
}
Doom3Quest_HapticEndFrame();
}
@ -1950,7 +1960,8 @@ Activity lifecycle
jmethodID android_shutdown;
jmethodID android_haptic_event;
jmethodID android_haptic_stopevent;
jmethodID android_haptic_stopall;
jmethodID android_haptic_beginframe;
jmethodID android_haptic_endframe;
jmethodID android_haptic_enable;
jmethodID android_haptic_disable;
static JavaVM *jVM;
@ -1968,9 +1979,8 @@ void jni_shutdown()
return (*env)->CallVoidMethod(env, jniCallbackObj, android_shutdown);
}
void jni_haptic_event(const char* event, int position, int intensity, float angle, float yHeight)
void jni_haptic_event(const char* event, int position, int flags, int intensity, float angle, float yHeight)
{
ALOGV("Calling: jni_haptic_event");
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
@ -1980,7 +1990,7 @@ void jni_haptic_event(const char* event, int position, int intensity, float angl
jstring StringArg1 = (*env)->NewStringUTF(env, event);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_event, StringArg1, position, intensity, angle, yHeight);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_event, StringArg1, position, flags, intensity, angle, yHeight);
}
void jni_haptic_stopevent(const char* event)
@ -1998,9 +2008,8 @@ void jni_haptic_stopevent(const char* event)
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_stopevent, StringArg1);
}
void jni_haptic_stopall()
void jni_haptic_beginframe()
{
ALOGV("Calling: jni_haptic_stopall");
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
@ -2008,7 +2017,19 @@ void jni_haptic_stopall()
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_stopall);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_beginframe);
}
void jni_haptic_endframe()
{
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_endframe);
}
void jni_haptic_enable()
@ -2110,9 +2131,10 @@ JNIEXPORT void JNICALL Java_com_drbeef_doom3quest_GLES3JNILib_onStart( JNIEnv *
jclass callbackClass = (*env)->GetObjectClass(env, jniCallbackObj);
android_shutdown = (*env)->GetMethodID(env,callbackClass,"shutdown","()V");
android_haptic_event = (*env)->GetMethodID(env, callbackClass, "haptic_event", "(Ljava/lang/String;IIFF)V");
android_haptic_event = (*env)->GetMethodID(env, callbackClass, "haptic_event", "(Ljava/lang/String;IIIFF)V");
android_haptic_stopevent = (*env)->GetMethodID(env, callbackClass, "haptic_stopevent", "(Ljava/lang/String;)V");
android_haptic_stopall = (*env)->GetMethodID(env, callbackClass, "haptic_stopall", "()V");
android_haptic_beginframe = (*env)->GetMethodID(env, callbackClass, "haptic_beginframe", "()V");
android_haptic_endframe = (*env)->GetMethodID(env, callbackClass, "haptic_endframe", "()V");
android_haptic_enable = (*env)->GetMethodID(env, callbackClass, "haptic_enable", "()V");
android_haptic_disable = (*env)->GetMethodID(env, callbackClass, "haptic_disable", "()V");

View file

@ -61,7 +61,7 @@ extern bool inGameGuiActive;
extern bool objectiveSystemActive;
extern bool inCinematic;
void Doom3Quest_HapticEvent(const char* event, int position, int intensity, float angle, float yHeight );
void Doom3Quest_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
@ -285,11 +285,11 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame
if (velocityTriggeredAttack)
{
if (controlscheme == 0) {
Doom3Quest_HapticEvent("punch_right", 0, 100, 0,
Doom3Quest_HapticEvent("punch_right", 0, 0, 100, 0,
0);
}
else{
Doom3Quest_HapticEvent("punch_left", 0, 100, 0,
Doom3Quest_HapticEvent("punch_left", 0, 0, 100, 0,
0);
}
}
@ -325,11 +325,11 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame
if (velocityTriggeredAttack)
{
if (controlscheme == 1) {
Doom3Quest_HapticEvent("punch_right", 0, 100, 0,
Doom3Quest_HapticEvent("punch_right", 0, 0, 100, 0,
0);
}
else{
Doom3Quest_HapticEvent("punch_left", 0, 100, 0,
Doom3Quest_HapticEvent("punch_left", 0, 0, 100, 0,
0);
}
}

View file

@ -171,8 +171,7 @@ public:
virtual int GetFrameNumber();
virtual void Vibrate(int channel, float low, float high );
virtual void HapticEvent(const char* event, int position, int intensity, float angle, float yHeight );
virtual void HapticStopAll();
virtual void HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
virtual void HapticStopEvent(const char* event);
virtual void HapticEnable();
virtual void HapticDisable();
@ -2276,8 +2275,7 @@ void idCommonLocal::InitSIMD( void ) {
extern "C" void Doom3Quest_FrameSetup(int controlscheme, int switch_sticks, int refresh);
extern "C" void Doom3Quest_Vibrate(int channel, float low, float high );
extern "C" void Doom3Quest_HapticEvent(const char* event, int position, int intensity, float angle, float yHeight );
extern "C" void Doom3Quest_HapticStopAll();
extern "C" void Doom3Quest_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
extern "C" void Doom3Quest_HapticStopEvent(const char* event);
extern "C" void Doom3Quest_HapticEnable();
extern "C" void Doom3Quest_HapticDisable();
@ -2287,14 +2285,9 @@ void idCommonLocal::Vibrate(int channel, float low, float high)
Doom3Quest_Vibrate(channel, low, high);
}
void idCommonLocal::HapticEvent(const char* event, int position, int intensity, float angle, float yHeight )
void idCommonLocal::HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight )
{
Doom3Quest_HapticEvent(event, position, intensity, angle, yHeight);
}
void idCommonLocal::HapticStopAll( )
{
Doom3Quest_HapticStopAll();
Doom3Quest_HapticEvent(event, position, flags, intensity, angle, yHeight);
}
void idCommonLocal::HapticStopEvent(const char* event)

View file

@ -220,8 +220,7 @@ public:
//Haptic Feedback
virtual void Vibrate(int channel, float low, float high ) = 0;
virtual void HapticEvent(const char* event, int position, int intensity, float angle, float yHeight ) = 0;
virtual void HapticStopAll() = 0;
virtual void HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight ) = 0;
virtual void HapticStopEvent(const char* event) = 0;
virtual void HapticEnable() = 0;
virtual void HapticDisable() = 0;

View file

@ -1627,8 +1627,10 @@ bool idEntity::StartSoundShader( const idSoundShader *shader, const s_channelTyp
idVec3 entityOrigin = GetPhysics()->GetOrigin(0);
float distance = (playerOrigin - entityOrigin).Length();
if (distance <= 200.0F) {
bool repeat = (shader->GetParms()->soundShaderFlags & SSF_LOOPING) != 0;
//Pass sound on in case it can trigger a haptic event (like doors)
common->HapticEvent(shader->GetName(), 0, (int)(200.0f - distance), 0, 0);
common->HapticEvent(shader->GetName(), 0, repeat ? 1 : 0, (int)(200.0f - distance), 0, 0);
}
}

View file

@ -989,7 +989,7 @@ bool idInventory::Give( idPlayer *owner, const idDict &spawnArgs, const char *st
armor = maxarmor;
}
common->HapticEvent("pickup_shield", 0, amount * 5, 0, 0);
common->HapticEvent("pickup_shield", 0, 0, amount * 5, 0, 0);
nextArmorDepleteTime = 0;
armorPulse = true;
@ -1000,7 +1000,7 @@ bool idInventory::Give( idPlayer *owner, const idDict &spawnArgs, const char *st
// set, don't add. not going over the clip size limit.
clip[ i ] = atoi( value );
common->HapticEvent("pickup_ammo", 0, 100, 0, 0);
common->HapticEvent("pickup_ammo", 0, 0, 100, 0, 0);
}
} else if ( !idStr::Icmp( statname, "berserk" ) ) {
GivePowerUp( owner, BERSERK, SEC2MS( atof( value ) ) );
@ -1047,7 +1047,7 @@ bool idInventory::Give( idPlayer *owner, const idDict &spawnArgs, const char *st
if ( ( weapons & ( 1 << i ) ) == 0 || ( duplicateWeapons & ( 1 << i ) ) == 0 || gameLocal.isMultiplayer ) {
tookWeapon = true;
common->HapticEvent("pickup_weapon", 0, 100, 0, 0);
common->HapticEvent("pickup_weapon", 0, 0, 100, 0, 0);
if ( owner->GetUserInfo()->GetBool( "ui_autoSwitch" ) && idealWeapon ) {
assert( !gameLocal.isClient );
@ -4646,7 +4646,7 @@ bool idPlayer::GiveItem( idItem *item ) {
if (gave)
{
common->HapticEvent("pickup_weapon", 0, 100, 0, 0);
common->HapticEvent("pickup_weapon", 0, 0, 100, 0, 0);
}
}
@ -5089,7 +5089,7 @@ void idPlayer::GiveSecurity( const char *security ) {
hud->HandleNamedEvent( "securityPickup" );
}
common->HapticEvent("pda_alarm", 0, 100, 0, 0);
common->HapticEvent("pda_alarm", 0, 0, 100, 0, 0);
}
/*
@ -5110,7 +5110,7 @@ void idPlayer::GiveEmail( const char *emailName ) {
hud->HandleNamedEvent( "emailPickup" );
}
common->HapticEvent("pda_alarm", 0, 100, 0, 0);
common->HapticEvent("pda_alarm", 0, 0, 100, 0, 0);
}
@ -5571,7 +5571,7 @@ void idPlayerHand::NextBestWeapon()
debugPrint();
}
common->HapticEvent("weapon_switch", 0, 100, 0, 0);
common->HapticEvent("weapon_switch", 0, 0, 100, 0, 0);
}
/*
@ -5747,7 +5747,7 @@ void idPlayerHand::NextWeapon( int dir )
if( vr_debugHands.GetBool() )
common->Printf( "Changing weapon\n" );
common->HapticEvent("weapon_switch", 0, 100, 0, 0);
common->HapticEvent("weapon_switch", 0, 0, 100, 0, 0);
}
if( vr_debugHands.GetBool() )
{
@ -6007,7 +6007,7 @@ void idPlayerHand::SelectWeapon( int num, bool force, bool specific )
idealWeapon = num;
owner->UpdateHudWeapon( whichHand );
common->HapticEvent("weapon_switch", 0, 100, 0, 0);
common->HapticEvent("weapon_switch", 0, 0, 100, 0, 0);
}
common->Printf( "After SelectWeapon(%d):\n", idealWeapon);
@ -7502,7 +7502,7 @@ bool idPlayer::HandleSingleGuiCommand( idEntity *entityGui, idLexer *src ) {
{
//Ass health increases, play the effect higher up the body
float yHeight = -0.5f + ((float)(health+amt) / 100.0f);
common->HapticEvent("healstation", 0, 100, 0, yHeight);
common->HapticEvent("healstation", 0, 0, 100, 0, yHeight);
}
health += amt;
if ( health > 100 ) {
@ -8216,7 +8216,7 @@ void idPlayer::UpdateFocus( void ) {
//Rumble the controller to let player know they scored a touch.
hands[fingerHand].SetControllerShake( 0.1f, 12, 0.8f, 12 );
common->HapticEvent("pda_touch", 0, 100, 0, 0);
common->HapticEvent("pda_touch", 0, 0, 100, 0, 0);
focusTime = gameLocal.time + FOCUS_GUI_TIME;
break;
@ -8430,7 +8430,7 @@ bool idPlayer::UpdateFocusPDA()
hands[fingerHand].SetControllerShake( 0.1f, 12, 0.8f, 12 );
hands[pdahand].SetControllerShake( 0.1f, 12, 0.8f, 12 );
common->HapticEvent("pda_touch", 0, 100, 0, 0);
common->HapticEvent("pda_touch", 0, 0, 100, 0, 0);
}
commonVr->scanningPDA = false;
return true;
@ -9876,7 +9876,7 @@ void idPlayer::TogglePDA( int hand ) {
hud->HandleNamedEvent( "pdaPickupHide" );
hud->HandleNamedEvent( "videoPickupHide" );
common->HapticEvent("pda_open", 0, 100, 0, 0);
common->HapticEvent("pda_open", 0, 0, 100, 0, 0);
} else {
inventory.selPDA = objectiveSystem->State().GetInt( "listPDA_sel_0" );
inventory.selVideo = objectiveSystem->State().GetInt( "listPDAVideo_sel_0" );
@ -9884,7 +9884,7 @@ void idPlayer::TogglePDA( int hand ) {
inventory.selEMail = objectiveSystem->State().GetInt( "listPDAEmail_sel_0" );
objectiveSystem->Activate( false, gameLocal.time );
common->HapticEvent("pda_close", 0, 100, 0, 0);
common->HapticEvent("pda_close", 0, 0, 100, 0, 0);
}
//objectiveSystemOpen ^= 1;
objectiveSystemOpen = !objectiveSystemOpen;
@ -11797,7 +11797,7 @@ void idPlayer::Think( void ) {
if (health > 0 && health < 40)
{
//heartbeat is a special case that uses intensity for a different purpose
common->HapticEvent("heartbeat", 0, health, 0, 0);
common->HapticEvent("heartbeat", 0, 0, health, 0, 0);
}
//UpdateFlashlightHolster();
@ -12511,7 +12511,7 @@ void idPlayer::Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &di
if (inventory.armor == 0)
{
if ( IsType( idPlayer::Type ) ) {
common->HapticEvent("shield_break", 0, 100, 0, 0);
common->HapticEvent("shield_break", 0, 0, 100, 0, 0);
}
}
@ -12525,7 +12525,7 @@ void idPlayer::Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &di
StartSound( "snd_burn", SND_CHANNEL_BODY3, 0, false, NULL );
if ( IsType( idPlayer::Type ) ) {
common->HapticEvent("fire", 0, damage * 4, 0, 0);
common->HapticEvent("fire", 0, 0, damage * 4, 0, 0);
}
} else if ( damageDef->dict.GetBool( "no_air" ) ) {
@ -12629,10 +12629,10 @@ void idPlayer::Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &di
//Indicate head damage if appropriate
if ( location >= 0 && location < damageGroups.Size() &&
strstr( damageGroups[location].c_str(), "head" ) ) {
common->HapticEvent(damageDefName, 3, damage * 4, 0, 0);
common->HapticEvent(damageDefName, 3, 0, damage * 4, 0, 0);
}
common->HapticEvent(damageDefName, 0, damage * 4, damageYaw, yHeight);
common->HapticEvent(damageDefName, 0, 0, damage * 4, damageYaw, yHeight);
}
lastDamageDef = damageDef->Index();

View file

@ -431,7 +431,7 @@ void idPlayerView::CalculateShake() {
player->hands[HAND_LEFT].SetControllerShake( highMag, highDuration, lowMag, lowDuration );
//generic rumbling - keep it low
common->HapticEvent("rumble", 0, 30.0f * idMath::ClampFloat(0.1, 1.0, shakeVolume*2.0f + 0.1f), highDuration, 0);
common->HapticEvent("rumble", 0, 0, 30.0f * idMath::ClampFloat(0.1, 1.0, shakeVolume*2.0f + 0.1f), highDuration, 0);
}
}

View file

@ -1939,7 +1939,7 @@ void idWeapon::Reload( void ) {
WEAPON_RELOAD = true;
}
common->HapticEvent("weapon_reload", vr_weaponHand.GetInteger() ? 1 : 2, 100, 0,0);
common->HapticEvent("weapon_reload", vr_weaponHand.GetInteger() ? 1 : 2, 0, 100, 0,0);
}
/*
@ -2088,19 +2088,19 @@ void idWeapon::BeginAttack( void ) {
currentWeapon = IdentifyWeapon();
if (currentWeapon == WEAPON_HANDGRENADE)
{
common->HapticEvent("handgrenade_init", position, 100, 0, 0);
common->HapticEvent("handgrenade_init", position, 0, 100, 0, 0);
}
if (currentWeapon == WEAPON_CHAINGUN)
{
common->HapticEvent("chaingun_init", position, 100, 0, 0);
common->HapticEvent("chaingun_init", position, 0, 100, 0, 0);
}
if (currentWeapon == WEAPON_BFG)
{
common->HapticEvent("bfg_init", position, 100, 0, 0);
common->HapticEvent("bfg_init", position, 0, 100, 0, 0);
}
if (currentWeapon == WEAPON_HANDGRENADE)
{
common->HapticEvent("grenade_init", position, 100, 0, 0);
common->HapticEvent("grenade_init", position, 0, 100, 0, 0);
}
}
@ -4039,35 +4039,35 @@ void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float
if (currentWeap == WEAPON_PISTOL)
{
common->HapticEvent("pistol_fire", position, 100, 0, 0);
common->HapticEvent("pistol_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_SHOTGUN)
{
common->HapticEvent("shotgun_fire", position, 100, 0, 0);
common->HapticEvent("shotgun_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_PLASMAGUN)
{
common->HapticEvent("plasmagun_fire", position, 100, 0, 0);
common->HapticEvent("plasmagun_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_HANDGRENADE)
{
common->HapticEvent("handgrenade_fire", position, 100, 0, 0);
common->HapticEvent("handgrenade_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_MACHINEGUN)
{
common->HapticEvent("machinegun_fire", position, 100, 0, 0);
common->HapticEvent("machinegun_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_CHAINGUN)
{
common->HapticEvent("chaingun_fire", position, 100, 0, 0);
common->HapticEvent("chaingun_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_BFG)
{
common->HapticEvent("bfg_fire", position, 100, 0, 0);
common->HapticEvent("bfg_fire", position, 0, 100, 0, 0);
}
if (currentWeap == WEAPON_ROCKETLAUNCHER)
{
common->HapticEvent("rocket_fire", position, 100, 0, 0);
common->HapticEvent("rocket_fire", position, 0, 100, 0, 0);
}
}

View file

@ -151,6 +151,7 @@ idSoundChannel::idSoundChannel
*/
idSoundChannel::idSoundChannel( void ) {
decoder = NULL;
soundShader = NULL;
Clear();
}
@ -209,9 +210,16 @@ void idSoundChannel::Start( void ) {
idSoundChannel::Stop
===================
*/
extern "C" void Doom3Quest_HapticStopEvent(const char* event);
void idSoundChannel::Stop( void ) {
triggerState = false;
stopped = true;
if (soundShader != NULL)
{
Doom3Quest_HapticStopEvent(soundShader->GetName());
}
if ( decoder != NULL ) {
idSampleDecoder::Free( decoder );
decoder = NULL;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -53,15 +53,9 @@ import static android.system.Os.setenv;
}
/*
position is used for weapon based haptics:
0 - Will play on both arms if tactosy tact files present for both
1 - Will play on left arm only if tactosy tact files present for left
2 - Will play on right arm only if tactosy tact files present for right
*/
public void haptic_event(String event, int position, int intensity, float angle, float yHeight) {
public void haptic_event(String event, int position, int flags, int intensity, float angle, float yHeight) {
bHaptics.playHaptic(event, position, intensity, angle, yHeight);
bHaptics.playHaptic(event, position, flags, intensity, angle, yHeight);
}
public void haptic_stopevent(String event) {
@ -69,8 +63,12 @@ import static android.system.Os.setenv;
bHaptics.stopHaptic(event);
}
public void haptic_stopall() {
bHaptics.stopAll();
public void haptic_beginframe() {
bHaptics.beginFrame();
}
public void haptic_endframe() {
bHaptics.endFrame();
}
public void haptic_enable() {

View file

@ -12,7 +12,6 @@ import com.bhaptics.bhapticsmanger.BhapticsModule;
import com.bhaptics.bhapticsmanger.HapticPlayer;
import com.bhaptics.commons.PermissionUtils;
import com.bhaptics.commons.model.BhapticsDevice;
import com.bhaptics.commons.model.ConnectionStatus;
import com.bhaptics.commons.model.DotPoint;
import com.bhaptics.commons.model.PositionType;
@ -27,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.Vector;
@ -35,16 +35,18 @@ public class bHaptics {
public static class Haptic
{
Haptic(PositionType type, String key, String altKey, float intensity, float duration) {
Haptic(PositionType type, String key, String altKey, String group, float intensity, float duration) {
this.type = type;
this.key = key;
this.altKey = altKey;
this.group = group;
this.intensity = intensity;
this.duration = duration;
}
public final String key;
public final String altKey;
public final String group;
public final float intensity;
public final float duration;
public final PositionType type;
@ -55,7 +57,6 @@ public class bHaptics {
private static Random rand = new Random();
private static boolean hasPairedDevice = false;
private static boolean hasConnectedHeadDevice = false;
private static boolean enabled = false;
private static boolean requestingPermission = false;
@ -67,6 +68,8 @@ public class bHaptics {
private static Map<String, Vector<Haptic>> eventToEffectKeyMap = new HashMap<>();
private static Map<String, Haptic> repeatingHaptics = new HashMap<>();
public static void initialise()
{
if (initialised)
@ -203,7 +206,8 @@ public class bHaptics {
String hapticKey = key + "_" + type.name();
player.registerProject(hapticKey, content);
Haptic haptic = new Haptic(type, hapticKey, group, intensity, duration);
UUID uuid = UUID.randomUUID();
Haptic haptic = new Haptic(type, hapticKey, uuid.toString(), group, intensity, duration);
Vector<Haptic> haptics;
if (!eventToEffectKeyMap.containsKey(key))
@ -284,7 +288,45 @@ public class bHaptics {
enabled = false;
}
public static void playHaptic(String event, int position, float intensity, float angle, float yHeight)
public static void beginFrame()
{
if (enabled && hasPairedDevice) {
repeatingHaptics.forEach((key, haptic) -> {
//If a repeating haptic isn't playing, start it again
if (!player.isPlaying(haptic.altKey)) {
player.submitRegistered(haptic.key, haptic.altKey, 100, 1.0f, 0, 0);
}
});
}
else
{
repeatingHaptics.clear();
}
}
public static void endFrame() {}
/*
position values:
0 - Will play on both arms if tactosy tact files present for both
1 - Will play on left arm only if tactosy tact files present for left
2 - Will play on right arm only if tactosy tact files present for right
3 - Will play on head only (if present)
flag values:
0 - No flags set
1 - Indicate this is a looping effect that should play repeatedly until stopped
intensity:
0 - 100
angle:
0 - 360
yHeight:
-0.5 - 0.5
*/
public static void playHaptic(String event, int position, int flags, float intensity, float angle, float yHeight)
{
if (enabled && hasPairedDevice) {
String key = getHapticEventKey(event);
@ -294,8 +336,7 @@ public class bHaptics {
//Special rumble effect that changes intensity per frame
if (key.compareTo("rumble") == 0)
{
//Allow all other haptics to take precedence, only rumble if no other haptics is playing
if (!player.isAnythingPlaying()) {
{
float highDuration = angle;
List<DotPoint> vector = new Vector<>();
@ -313,21 +354,22 @@ public class bHaptics {
}
else if (eventToEffectKeyMap.containsKey(key)) {
Vector<Haptic> haptics = eventToEffectKeyMap.get(key);
//Don't allow a haptic to interrupt itself if it is already playing
if (player.isPlaying(haptics.get(0).altKey)) {
return;
}
for (Haptic haptic : haptics) {
//Don't allow a haptic to interrupt itself if it is already playing
if (player.isPlaying(haptics.get(0).altKey)) {
return;
}
//The following groups play at full intensity
if (haptic.altKey.compareTo("environment") == 0) {
if (haptic.group.compareTo("environment") == 0) {
intensity = 100;
}
if (position > 0)
{
BhapticsManager manager = BhapticsModule.getBhapticsManager();
//If playing left position and haptic type is right, don;t play that one
if (position == 1 && haptic.type == PositionType.ForearmR)
{
@ -340,8 +382,9 @@ public class bHaptics {
continue;
}
if (position == 3 &&
(haptic.type != PositionType.Head || !hasConnectedHeadDevice))
(haptic.type != PositionType.Head || !manager.isDeviceConnected(BhapticsManager.DeviceType.Head)))
{
continue;
}
@ -357,7 +400,7 @@ public class bHaptics {
float duration = haptic.duration;
//Special hack for heartbeat
if (haptic.altKey.compareTo("health") == 0)
if (haptic.group.compareTo("health") == 0)
{
//The worse condition we are in, the faster the heart beats!
float health = intensity;
@ -365,7 +408,14 @@ public class bHaptics {
flIntensity = 1.0f;
}
player.submitRegistered(haptic.key, haptic.altKey, flIntensity, duration, angle, yHeight);
//If this is a repeating event, then add to the set to play in begin frame
if (flags == 1)
{
repeatingHaptics.put(key, haptic);
}
else {
player.submitRegistered(haptic.key, haptic.altKey, flIntensity, duration, angle, yHeight);
}
}
}
}
@ -423,20 +473,17 @@ public class bHaptics {
return key;
}
public static void stopAll() {
if (hasPairedDevice) {
player.turnOffAll();
}
}
public static void stopHaptic(String event) {
if (hasPairedDevice) {
if (enabled && hasPairedDevice) {
String key = getHapticEventKey(event);
if (repeatingHaptics.containsKey(key))
{
player.turnOff(key);
repeatingHaptics.remove(key);
}
}
}
@ -478,14 +525,7 @@ public class bHaptics {
manager.addBhapticsManageCallback(new BhapticsManagerCallback() {
@Override
public void onDeviceUpdate(List<BhapticsDevice> list) {
for (BhapticsDevice device : deviceList) {
if (device.isPaired() &&
device.getPosition() == PositionType.Head &&
device.getConnectionStatus() == ConnectionStatus.Connected) {
hasConnectedHeadDevice = true;
break;
}
}
}
@Override