mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Haptics implementation are on all simulators but
Ion::Haptics::isEnabled is per platform.
This commit is contained in:
committed by
EmilieNumworks
parent
0c0510599d
commit
17fd1aea29
@@ -1,11 +1,12 @@
|
||||
ion_src += $(addprefix ion/src/simulator/android/src/cpp/, \
|
||||
images.cpp \
|
||||
haptics.cpp \
|
||||
haptics_enabled.cpp \
|
||||
)
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/callback.cpp \
|
||||
dummy/language.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ion_src += ion/src/shared/collect_registers.cpp
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "../../../shared/haptics.h"
|
||||
#include <jni.h>
|
||||
#include <SDL.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
static SDL_Haptic * sSDLHaptic = nullptr;
|
||||
|
||||
void init() {
|
||||
if (SDL_Init(SDL_INIT_HAPTIC) == 0) {
|
||||
sSDLHaptic = SDL_HapticOpen(0);
|
||||
if (sSDLHaptic) {
|
||||
if (SDL_HapticRumbleInit(sSDLHaptic) != 0) {
|
||||
sSDLHaptic = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
if (sSDLHaptic) {
|
||||
SDL_HapticClose(sSDLHaptic);
|
||||
}
|
||||
}
|
||||
|
||||
void perform() {
|
||||
// Retrieve system setting: is haptic feedback enabled?
|
||||
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
|
||||
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class,"hapticFeedbackIsEnabled", "()Z");
|
||||
|
||||
bool feedbackEnabled = env->CallObjectMethod(activity, j_methodId);
|
||||
|
||||
if (feedbackEnabled && sSDLHaptic) {
|
||||
SDL_HapticRumblePlay(sSDLHaptic, 1.0, 40);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
ion/src/simulator/android/src/cpp/haptics_enabled.cpp
Normal file
20
ion/src/simulator/android/src/cpp/haptics_enabled.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../../../shared/haptics.h"
|
||||
#include <jni.h>
|
||||
#include <SDL.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
bool isEnabled() {
|
||||
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
|
||||
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
|
||||
jmethodID j_methodId = env->GetMethodID(j_class,"hapticFeedbackIsEnabled", "()Z");
|
||||
|
||||
return env->CallObjectMethod(activity, j_methodId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ ion_src += $(addprefix ion/src/simulator/ios/, \
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
apple/language.m \
|
||||
dummy/callback.cpp \
|
||||
dummy/haptics.cpp \
|
||||
dummy/haptics_enabled.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ion_src += ion/src/shared/collect_registers.cpp
|
||||
|
||||
@@ -15,9 +15,10 @@ ion_src += $(addprefix ion/src/simulator/linux/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/callback.cpp \
|
||||
dummy/haptics.cpp \
|
||||
dummy/haptics_enabled.cpp \
|
||||
collect_registers_x86_64.s \
|
||||
collect_registers.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
|
||||
@@ -5,9 +5,10 @@ ion_src += $(addprefix ion/src/simulator/macos/, \
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
apple/language.m \
|
||||
dummy/callback.cpp \
|
||||
dummy/haptics.cpp \
|
||||
dummy/haptics_enabled.cpp \
|
||||
collect_registers_x86_64.s \
|
||||
collect_registers.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ifeq ($(EPSILON_TELEMETRY),1)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "../haptics.h"
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
}
|
||||
|
||||
void perform() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
15
ion/src/simulator/shared/dummy/haptics_enabled.cpp
Normal file
15
ion/src/simulator/shared/dummy/haptics_enabled.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../haptics.h"
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
bool isEnabled() {
|
||||
/* Dummy default to false as failsafe.
|
||||
* Avoid to get haptics feedback that are not desactivable. */
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace Ion {
|
||||
namespace Events {
|
||||
|
||||
void didPressNewKey() {
|
||||
Simulator::Haptics::perform();
|
||||
Simulator::Haptics::rumble();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
ion/src/simulator/shared/haptics.cpp
Normal file
35
ion/src/simulator/shared/haptics.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "haptics.h"
|
||||
#include <SDL.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
static SDL_Haptic * sSDLHaptic = nullptr;
|
||||
|
||||
void init() {
|
||||
if (SDL_Init(SDL_INIT_HAPTIC) == 0) {
|
||||
sSDLHaptic = SDL_HapticOpen(0);
|
||||
if (sSDLHaptic) {
|
||||
if (SDL_HapticRumbleInit(sSDLHaptic) != 0) {
|
||||
sSDLHaptic = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
if (sSDLHaptic) {
|
||||
SDL_HapticClose(sSDLHaptic);
|
||||
}
|
||||
}
|
||||
|
||||
void rumble() {
|
||||
if (isEnabled() && sSDLHaptic) {
|
||||
SDL_HapticRumblePlay(sSDLHaptic, 1.0, 40);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ namespace Simulator {
|
||||
namespace Haptics {
|
||||
|
||||
void init();
|
||||
void perform();
|
||||
bool isEnabled();
|
||||
void rumble();
|
||||
void shutdown();
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ ion_src += $(addprefix ion/src/simulator/web/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/language.cpp \
|
||||
dummy/haptics.cpp \
|
||||
dummy/haptics_enabled.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ion_src += ion/src/shared/collect_registers.cpp
|
||||
|
||||
@@ -6,7 +6,8 @@ ion_src += $(addprefix ion/src/simulator/windows/, \
|
||||
|
||||
ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/callback.cpp \
|
||||
dummy/haptics.cpp \
|
||||
dummy/haptics_enabled.cpp \
|
||||
haptics.cpp \
|
||||
)
|
||||
|
||||
ion_src += ion/src/shared/collect_registers.cpp
|
||||
|
||||
Reference in New Issue
Block a user