void SdlManager::SdlController::RunHapticLeftRight(float left, float right) { CriticalCode criticalCode(criticalSection); if(!haptic) return; hapticEffect.leftright.length = SDL_HAPTIC_INFINITY; hapticEffect.leftright.large_magnitude = uint16_t(left * 0xffff); hapticEffect.leftright.small_magnitude = uint16_t(right * 0xffff); if(hapticEffectIndex >= 0 && hapticEffect.type == SDL_HAPTIC_LEFTRIGHT) { SDL_HapticStopEffect(haptic, hapticEffectIndex); SDL_HapticUpdateEffect(haptic, hapticEffectIndex, &hapticEffect); } else { if(hapticEffectIndex >= 0) { SDL_HapticStopEffect(haptic, hapticEffectIndex); SDL_HapticDestroyEffect(haptic, hapticEffectIndex); } hapticEffect.type = SDL_HAPTIC_LEFTRIGHT; hapticEffectIndex = SDL_HapticNewEffect(haptic, &hapticEffect); } SDL_HapticRunEffect(haptic, hapticEffectIndex, 1); }
bool Joystick::UpdateOutput() { #ifdef USE_SDL_HAPTIC std::list<EffectIDState>::iterator i = m_state_out.begin(), e = m_state_out.end(); for ( ; i != e; ++i) { if (i->changed) // if SetState was called on this output { if (-1 == i->id) // effect isn't currently uploaded { if (i->effect.type) // if outputstate is >0 this would be true if ((i->id = SDL_HapticNewEffect( m_haptic, &i->effect )) > -1) // upload the effect SDL_HapticRunEffect(m_haptic, i->id, 1); // run the effect } else // effect is already uploaded { if (i->effect.type) // if ouputstate >0 SDL_HapticUpdateEffect(m_haptic, i->id, &i->effect); // update the effect else { SDL_HapticStopEffect(m_haptic, i->id); // else, stop and remove the effect SDL_HapticDestroyEffect(m_haptic, i->id); i->id = -1; // mark it as not uploaded } } i->changed = false; } } #endif return true; }
JNIEXPORT jint JNICALL Java_at_wisch_joystick_FFJoystick_stopEffectNative (JNIEnv *env, jclass, jint hapticDeviceIndex, jint effectIndex){ int num = SDL_HapticStopEffect(ffjoysticks[hapticDeviceIndex], effectIndex); if (num < 0) { throwException(env, SDL_GetError()); return -25; } return 0; }
bool SdlRumbleEffect::stop() { if (isActive()) { return (SDL_HapticStopEffect(mHaptic, mId) == 0); } return false; }
void SdlManager::SdlController::StopHaptic() { CriticalCode criticalCode(criticalSection); if(hapticEffectIndex >= 0) { SDL_HapticStopEffect(haptic, hapticEffectIndex); } }
bool Joystick::setVibration() { bool success = true; if (SDL_WasInit(SDL_INIT_HAPTIC) && haptic && SDL_HapticIndex(haptic) != -1) success = (SDL_HapticStopEffect(haptic, vibration.id) == 0); if (success) vibration.left = vibration.right = 0.0f; return success; }
/* * Stops the simple rumble on a haptic device. */ int SDL_HapticRumbleStop(SDL_Haptic * haptic) { if (!ValidHaptic(haptic)) { return -1; } if (haptic->rumble_id < 0) { return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); } return SDL_HapticStopEffect(haptic, haptic->rumble_id); }
void Joystick::HapticEffect::Update() { if (m_id == -1 && m_effect.type > 0) { m_id = SDL_HapticNewEffect(m_haptic, &m_effect); if (m_id > -1) SDL_HapticRunEffect(m_haptic, m_id, 1); } else if (m_id > -1 && m_effect.type == 0) { SDL_HapticStopEffect(m_haptic, m_id); SDL_HapticDestroyEffect(m_haptic, m_id); m_id = -1; } else if (m_id > -1) { SDL_HapticUpdateEffect(m_haptic, m_id, &m_effect); } }
bool SDL2FFBDevice::stopEffect(const int idx) { std::shared_ptr<SDL2FFBEffect> sdlEff; CHECK_EFFECT_IDX(idx); if (m_effects[idx] == nullptr) return true; if (m_effects[idx]->status() != FFBEffect::FFBEffectStatus::PLAYING) return true; sdlEff = std::static_pointer_cast<SDL2FFBEffect>(m_effects[idx]); if (SDL_HapticStopEffect(c_haptic, sdlEff->internalIdx()) < 0) { QMessageBox::critical(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to stop the effect:\n%1").arg(SDL_GetError())); return false; } sdlEff->setStatus(FFBEffect::FFBEffectStatus::UPLOADED); return true; }
/** * @brief Runs a rumble effect. * * @brief Current modifier being added. */ static void spfx_hapticRumble( double mod ) { #if SDL_VERSION_ATLEAST(1,3,0) SDL_HapticEffect *efx; double len, mag; if (haptic_rumble >= 0) { /* Not time to update yet. */ if ((haptic_lastUpdate > 0.) || shake_off || (mod > SHAKE_MAX/3.)) return; /* Stop the effect if it was playing. */ SDL_HapticStopEffect( haptic, haptic_rumble ); /* Get length and magnitude. */ len = 1000. * shake_rad / SHAKE_DECAY; mag = 32767. * (shake_rad / SHAKE_MAX); /* Update the effect. */ efx = &haptic_rumbleEffect; efx->periodic.magnitude = (uint32_t)mag;; efx->periodic.length = (uint32_t)len; efx->periodic.fade_length = MIN( efx->periodic.length, 1000 ); if (SDL_HapticUpdateEffect( haptic, haptic_rumble, &haptic_rumbleEffect ) < 0) { WARN("Failed to update haptic effect: %s.", SDL_GetError()); return; } /* Run the new effect. */ SDL_HapticRunEffect( haptic, haptic_rumble, 1 ); /* Set timer again. */ haptic_lastUpdate = HAPTIC_UPDATE_INTERVAL; } #else /* SDL_VERSION_ATLEAST(1,3,0) */ (void) mod; #endif /* SDL_VERSION_ATLEAST(1,3,0) */ }
void SdlManager::SdlController::Close() { CriticalCode criticalCode(criticalSection); if(hapticEffectIndex >= 0) { SDL_HapticStopEffect(haptic, hapticEffectIndex); SDL_HapticDestroyEffect(haptic, hapticEffectIndex); hapticEffectIndex = -1; } if(haptic) { SDL_HapticClose(haptic); haptic = nullptr; } if(controller) { SDL_GameControllerClose(controller); controller = nullptr; } }
bool Joystick::UpdateOutput() { #ifdef USE_SDL_HAPTIC for (auto &i : m_state_out) { if (i.changed) // if SetState was called on this output { if (-1 == i.id) // effect isn't currently uploaded { if (i.effect.type) // if outputstate is >0 this would be true { if ((i.id = SDL_HapticNewEffect(m_haptic, &i.effect)) > -1) // upload the effect { SDL_HapticRunEffect(m_haptic, i.id, 1); // run the effect } } } else // effect is already uploaded { if (i.effect.type) // if ouputstate >0 { SDL_HapticUpdateEffect(m_haptic, i.id, &i.effect); // update the effect } else { SDL_HapticStopEffect(m_haptic, i.id); // else, stop and remove the effect SDL_HapticDestroyEffect(m_haptic, i.id); i.id = -1; // mark it as not uploaded } } i.changed = false; } } #endif return true; }
void Application::OnEvent(SDL_Event* Event) { if(Event->type == SDL_QUIT) { Running = false; } if(Event->type == SDL_JOYAXISMOTION) { if(Event->jaxis.axis == 0) { if(Event->jaxis.value > 5000 || Event->jaxis.value < -5000) { astate->xcont = (double) Event->jaxis.value / 32767.0; } else { astate->xcont = 0; } } if(Event->jaxis.axis == 3) { astate->targetx = (double) Event->jaxis.value / 32767.0; } if(Event->jaxis.axis == 4) { astate->targety = -(double) Event->jaxis.value / 32767.0; } } if(Event->type == SDL_KEYDOWN) { if(Event->key.keysym.sym == SDLK_LEFT) { astate->xcont--; } if(Event->key.keysym.sym == SDLK_RIGHT) { astate->xcont++; } if(astate->xcont > 0) { astate->xcont = 1; } else if (astate->xcont < 0) { astate->xcont = -1; } if(Event->key.keysym.sym == SDLK_ESCAPE) { Running = false; } } if(Event->type == SDL_KEYUP) { if(Event->key.keysym.sym == SDLK_LEFT) { astate->xcont++; } if(Event->key.keysym.sym == SDLK_RIGHT) { astate->xcont--; } if(astate->xcont > 0) { astate->xcont = 1; } else if (astate->xcont < 0) { astate->xcont = -1; } } // ref for below: // jbutton.button 0 = A // jbutton.button 1 = B // jbutton.button 2 = X // jbutton.button 3 = Y // jbutton.button 4 = left bump // jbutton.button 5 = right bump if (Event->type == SDL_JOYBUTTONDOWN) { if (Event->jbutton.button == 4 || Event->jbutton.button == 5) { astate->pushing = true; if (haptic != NULL) { SDL_HapticRunEffect(haptic, effect_id, SDL_HAPTIC_INFINITY); } } else if (Event->jbutton.button == 3) { entities.push_back(Bullet::Create(&Level::p_level->world, graphics, Player::player->x + (astate->xcont >= 0 ? Player::player->width/1.2 : -Player::player->width/1.2), Player::player->y, astate->xcont >= 0 ? 100:-100,0)); printf("player at %g %g\n",(Player::player->x),(Player::player->y)); // (Player::player->x)*10, // (Player::player->y)*10,4,0)); if (astate->xcont >= 0.0) { Player::player->shoot_right = true; } else { Player::player->shoot_left = true; } } /// \todo Get these controls unconnected else if (Event->jbutton.button == 2) { if (astate->xcont >= 0.0) { Player::player->swing_right = true; } else { Player::player->swing_left = true; } } } if (Event->type == SDL_JOYBUTTONUP) { if (Event->jbutton.button == 4 || Event->jbutton.button == 5) { astate->pushing = false; if (haptic != NULL) { SDL_HapticStopEffect(haptic, effect_id); } } } }