Add Android clang-tidy job

This commit is contained in:
Chris Thrasher 2023-07-27 17:07:56 -06:00
parent 66e7476872
commit b99a4e341e
13 changed files with 184 additions and 193 deletions

View File

@ -239,6 +239,7 @@ jobs:
- { name: Linux, os: ubuntu-22.04 }
- { name: Linux DRM, os: ubuntu-22.04, flags: -DSFML_USE_DRM=TRUE }
- { name: macOS, os: macos-12 }
- { name: Android, os: ubuntu-22.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_SYSTEM_NAME=Android -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$GITHUB_WORKSPACE/android-ndk-r23b -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_ANDROID_STL_TYPE=c++_shared -DCMAKE_ANDROID_API=26 }
steps:
- name: Checkout Code
@ -260,6 +261,12 @@ jobs:
brew install llvm || true
echo /usr/local/opt/llvm/bin >> $GITHUB_PATH
- name: Install Android Components
if: matrix.platform.name == 'Android'
run: |
wget -nv https://dl.google.com/android/repository/android-ndk-r23b-linux.zip -P $GITHUB_WORKSPACE
unzip -qq -d $GITHUB_WORKSPACE android-ndk-r23b-linux.zip
- name: Configure
shell: bash
run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_UNITY_BUILD=ON -DSFML_BUILD_EXAMPLES=TRUE -DSFML_BUILD_TEST_SUITE=TRUE ${{matrix.platform.flags}}

View File

@ -69,7 +69,7 @@ public:
using period = duration::period;
using time_point = std::chrono::time_point<SuspendAwareClock, duration>;
static constexpr bool is_steady = true;
static constexpr bool is_steady = true; // NOLINT(readability-identifier-naming)
static time_point now() noexcept;
};

View File

@ -974,9 +974,7 @@ Shader::Shader() = default;
////////////////////////////////////////////////////////////
Shader::~Shader()
{
}
Shader::~Shader() = default;
////////////////////////////////////////////////////////////

View File

@ -181,29 +181,29 @@ void goToFullscreenMode(ANativeActivity* activity)
// API Level 14
if (apiLevel >= 14)
{
jfieldID FieldSYSTEM_UI_FLAG_LOW_PROFILE = lJNIEnv->GetStaticFieldID(classView,
jfieldID fieldSystemUiFlagLowProfile = lJNIEnv->GetStaticFieldID(classView,
"SYSTEM_UI_FLAG_HIDE_NAVIGATION",
"I");
jint SYSTEM_UI_FLAG_LOW_PROFILE = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_LOW_PROFILE);
flags |= SYSTEM_UI_FLAG_LOW_PROFILE;
jint systemUiFlagLowProfile = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagLowProfile);
flags |= systemUiFlagLowProfile;
}
// API Level 16
if (apiLevel >= 16)
{
jfieldID FieldSYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
jint SYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_FULLSCREEN);
flags |= SYSTEM_UI_FLAG_FULLSCREEN;
jfieldID fieldSystemUiFlagFullscreen = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
jint systemUiFlagFullscreen = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagFullscreen);
flags |= systemUiFlagFullscreen;
}
// API Level 19
if (apiLevel >= 19)
{
jfieldID FieldSYSTEM_UI_FLAG_IMMERSIVE_STICKY = lJNIEnv->GetStaticFieldID(classView,
jfieldID fieldSystemUiFlagImmersiveSticky = lJNIEnv->GetStaticFieldID(classView,
"SYSTEM_UI_FLAG_IMMERSIVE_STICKY",
"I");
jint SYSTEM_UI_FLAG_IMMERSIVE_STICKY = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_IMMERSIVE_STICKY);
flags |= SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
jint systemUiFlagImmersiveSticky = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagImmersiveSticky);
flags |= systemUiFlagImmersiveSticky;
}
jmethodID methodsetSystemUiVisibility = lJNIEnv->GetMethodID(classView, "setSystemUiVisibility", "(I)V");
@ -490,17 +490,10 @@ static void onLowMemory(ANativeActivity* /* activity */)
JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, std::size_t savedStateSize)
{
// Create an activity states (will keep us in the know, about events we care)
auto* states = new sf::priv::ActivityStates;
auto* states = new sf::priv::ActivityStates();
// Initialize the states value
states->activity = nullptr;
states->window = nullptr;
states->looper = nullptr;
states->inputQueue = nullptr;
states->config = nullptr;
for (unsigned int i = 0; i < sf::Mouse::ButtonCount; ++i)
states->isButtonPressed[i] = false;
for (auto& isButtonPressed : states->isButtonPressed)
isButtonPressed = false;
gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);
states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

View File

@ -62,7 +62,7 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
// Get the value of meta-data named "sfml.app.lib_name"
jclass classBundle = lJNIEnv->FindClass("android/os/Bundle");
jmethodID methodGetString = lJNIEnv->GetMethodID(classBundle, "getString", "(Ljava/lang/String;)Ljava/lang/String;");
jstring valueString = static_cast<jstring>(lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName));
auto* valueString = static_cast<jstring>(lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName));
// No meta-data "sfml.app.lib_name" was found so we abort and inform the user
if (valueString == nullptr)
@ -72,7 +72,7 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
}
// Convert the application name to a C++ string and return it
const std::size_t applicationNameLength = static_cast<std::size_t>(lJNIEnv->GetStringUTFLength(valueString));
const auto applicationNameLength = static_cast<std::size_t>(lJNIEnv->GetStringUTFLength(valueString));
const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, nullptr);
if (applicationNameLength >= 256)
@ -88,35 +88,35 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
return name;
}
void* loadLibrary(const char* libraryName, JNIEnv* lJNIEnv, jobject& ObjectActivityInfo)
void* loadLibrary(const char* libraryName, JNIEnv* lJNIEnv, jobject& objectActivityInfo)
{
// Find out the absolute path of the library
jclass ClassActivityInfo = lJNIEnv->FindClass("android/content/pm/ActivityInfo");
jfieldID FieldApplicationInfo = lJNIEnv->GetFieldID(ClassActivityInfo,
jclass classActivityInfo = lJNIEnv->FindClass("android/content/pm/ActivityInfo");
jfieldID fieldApplicationInfo = lJNIEnv->GetFieldID(classActivityInfo,
"applicationInfo",
"Landroid/content/pm/ApplicationInfo;");
jobject ObjectApplicationInfo = lJNIEnv->GetObjectField(ObjectActivityInfo, FieldApplicationInfo);
jobject objectApplicationInfo = lJNIEnv->GetObjectField(objectActivityInfo, fieldApplicationInfo);
jclass ClassApplicationInfo = lJNIEnv->FindClass("android/content/pm/ApplicationInfo");
jfieldID FieldNativeLibraryDir = lJNIEnv->GetFieldID(ClassApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;");
jclass classApplicationInfo = lJNIEnv->FindClass("android/content/pm/ApplicationInfo");
jfieldID fieldNativeLibraryDir = lJNIEnv->GetFieldID(classApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;");
jobject ObjectDirPath = lJNIEnv->GetObjectField(ObjectApplicationInfo, FieldNativeLibraryDir);
jobject objectDirPath = lJNIEnv->GetObjectField(objectApplicationInfo, fieldNativeLibraryDir);
jclass ClassSystem = lJNIEnv->FindClass("java/lang/System");
jmethodID StaticMethodMapLibraryName = lJNIEnv->GetStaticMethodID(ClassSystem,
jclass classSystem = lJNIEnv->FindClass("java/lang/System");
jmethodID staticMethodMapLibraryName = lJNIEnv->GetStaticMethodID(classSystem,
"mapLibraryName",
"(Ljava/lang/String;)Ljava/lang/String;");
jstring LibNameObject = lJNIEnv->NewStringUTF(libraryName);
jobject ObjectName = lJNIEnv->CallStaticObjectMethod(ClassSystem, StaticMethodMapLibraryName, LibNameObject);
jstring libNameObject = lJNIEnv->NewStringUTF(libraryName);
jobject objectName = lJNIEnv->CallStaticObjectMethod(classSystem, staticMethodMapLibraryName, libNameObject);
jclass ClassFile = lJNIEnv->FindClass("java/io/File");
jmethodID FileConstructor = lJNIEnv->GetMethodID(ClassFile, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
jobject ObjectFile = lJNIEnv->NewObject(ClassFile, FileConstructor, ObjectDirPath, ObjectName);
jclass classFile = lJNIEnv->FindClass("java/io/File");
jmethodID fileConstructor = lJNIEnv->GetMethodID(classFile, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
jobject objectFile = lJNIEnv->NewObject(classFile, fileConstructor, objectDirPath, objectName);
// Get the library absolute path and convert it
jmethodID MethodGetPath = lJNIEnv->GetMethodID(ClassFile, "getPath", "()Ljava/lang/String;");
jstring javaLibraryPath = static_cast<jstring>(lJNIEnv->CallObjectMethod(ObjectFile, MethodGetPath));
jmethodID methodGetPath = lJNIEnv->GetMethodID(classFile, "getPath", "()Ljava/lang/String;");
auto* javaLibraryPath = static_cast<jstring>(lJNIEnv->CallObjectMethod(objectFile, methodGetPath));
const char* libraryPath = lJNIEnv->GetStringUTFChars(javaLibraryPath, nullptr);
// Manually load the library
@ -152,74 +152,70 @@ JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedSt
JNIEnv* lJNIEnv = activity->env;
// Retrieve the NativeActivity
jobject ObjectNativeActivity = activity->clazz;
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);
jobject objectNativeActivity = activity->clazz;
jclass classNativeActivity = lJNIEnv->GetObjectClass(objectNativeActivity);
// Retrieve the ActivityInfo
jmethodID MethodGetPackageManager = lJNIEnv->GetMethodID(ClassNativeActivity,
jmethodID methodGetPackageManager = lJNIEnv->GetMethodID(classNativeActivity,
"getPackageManager",
"()Landroid/content/pm/PackageManager;");
jobject ObjectPackageManager = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetPackageManager);
jobject objectPackageManager = lJNIEnv->CallObjectMethod(objectNativeActivity, methodGetPackageManager);
jmethodID MethodGetIndent = lJNIEnv->GetMethodID(ClassNativeActivity, "getIntent", "()Landroid/content/Intent;");
jobject ObjectIntent = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetIndent);
jmethodID methodGetIndent = lJNIEnv->GetMethodID(classNativeActivity, "getIntent", "()Landroid/content/Intent;");
jobject objectIntent = lJNIEnv->CallObjectMethod(objectNativeActivity, methodGetIndent);
jclass ClassIntent = lJNIEnv->FindClass("android/content/Intent");
jmethodID MethodGetComponent = lJNIEnv->GetMethodID(ClassIntent,
jclass classIntent = lJNIEnv->FindClass("android/content/Intent");
jmethodID methodGetComponent = lJNIEnv->GetMethodID(classIntent,
"getComponent",
"()Landroid/content/ComponentName;");
jobject ObjectComponentName = lJNIEnv->CallObjectMethod(ObjectIntent, MethodGetComponent);
jobject objectComponentName = lJNIEnv->CallObjectMethod(objectIntent, methodGetComponent);
jclass ClassPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager");
jclass classPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager");
jfieldID FieldGET_META_DATA = lJNIEnv->GetStaticFieldID(ClassPackageManager, "GET_META_DATA", "I");
jint GET_META_DATA = lJNIEnv->GetStaticIntField(ClassPackageManager, FieldGET_META_DATA);
jfieldID fieldGetMetaData = lJNIEnv->GetStaticFieldID(classPackageManager, "GET_META_DATA", "I");
jint getMetaData = lJNIEnv->GetStaticIntField(classPackageManager, fieldGetMetaData);
jmethodID MethodGetActivityInfo = lJNIEnv->GetMethodID(ClassPackageManager,
jmethodID methodGetActivityInfo = lJNIEnv->GetMethodID(classPackageManager,
"getActivityInfo",
"(Landroid/content/ComponentName;I)Landroid/content/pm/"
"ActivityInfo;");
jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager,
MethodGetActivityInfo,
ObjectComponentName,
GET_META_DATA);
jobject objectActivityInfo = lJNIEnv->CallObjectMethod(objectPackageManager, methodGetActivityInfo, objectComponentName, getMetaData);
// Load our libraries in reverse order
#if defined(STL_LIBRARY)
#define _SFML_QS(s) _SFML_S(s)
#define _SFML_S(s) #s
loadLibrary(_SFML_QS(STL_LIBRARY), lJNIEnv, ObjectActivityInfo);
#undef _SFML_S
#undef _SFML_QS
#define SFML_QS(s) SFML_S(s)
#define SFML_S(s) #s
loadLibrary(SFML_QS(STL_LIBRARY), lJNIEnv, objectActivityInfo);
#undef SFML_S
#undef SFML_QS
#endif
loadLibrary("openal", lJNIEnv, ObjectActivityInfo);
loadLibrary("openal", lJNIEnv, objectActivityInfo);
#if !defined(SFML_DEBUG)
loadLibrary("sfml-system", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-window", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-graphics", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-audio", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-network", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-system", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-window", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-graphics", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-audio", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-network", lJNIEnv, objectActivityInfo);
#else
loadLibrary("sfml-system-d", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-window-d", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-graphics-d", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-audio-d", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-network-d", lJNIEnv, ObjectActivityInfo);
loadLibrary("sfml-system-d", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-window-d", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-graphics-d", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-audio-d", lJNIEnv, objectActivityInfo);
loadLibrary("sfml-network-d", lJNIEnv, objectActivityInfo);
#endif
void* handle = loadLibrary(getLibraryName(lJNIEnv, ObjectActivityInfo), lJNIEnv, ObjectActivityInfo);
void* handle = loadLibrary(getLibraryName(lJNIEnv, objectActivityInfo), lJNIEnv, objectActivityInfo);
// Call the original ANativeActivity_onCreate function
activityOnCreatePointer ANativeActivity_onCreate = reinterpret_cast<activityOnCreatePointer>(
dlsym(handle, "ANativeActivity_onCreate"));
auto nativeActivityOnCreate = reinterpret_cast<activityOnCreatePointer>(dlsym(handle, "ANativeActivity_onCreate"));
if (!ANativeActivity_onCreate)
if (!nativeActivityOnCreate)
{
LOGE("sfml-activity: Undefined symbol ANativeActivity_onCreate");
std::exit(1);
}
ANativeActivity_onCreate(activity, savedState, savedStateSize);
nativeActivityOnCreate(activity, savedState, savedStateSize);
}

View File

@ -35,10 +35,7 @@
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-error", __VA_ARGS__))
LogcatStream::LogcatStream() : std::streambuf()
{
// Nothing to do
}
LogcatStream::LogcatStream() = default;
std::streambuf::int_type LogcatStream::overflow(std::streambuf::int_type c)
{

View File

@ -54,12 +54,12 @@ namespace sf::priv
{
struct ActivityStates
{
ANativeActivity* activity;
ANativeWindow* window;
ANativeActivity* activity{};
ANativeWindow* window{};
ALooper* looper;
AInputQueue* inputQueue;
AConfiguration* config;
ALooper* looper{};
AInputQueue* inputQueue{};
AConfiguration* config{};
EGLDisplay display;
EglContext* context;

View File

@ -95,58 +95,58 @@ void InputImpl::setVirtualKeyboardVisible(bool visible)
// Retrieves NativeActivity
jobject lNativeActivity = states.activity->clazz;
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
jclass classNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
// Retrieves Context.INPUT_METHOD_SERVICE
jclass ClassContext = lJNIEnv->FindClass("android/content/Context");
jfieldID FieldINPUT_METHOD_SERVICE = lJNIEnv->GetStaticFieldID(ClassContext,
jclass classContext = lJNIEnv->FindClass("android/content/Context");
jfieldID fieldInputMethodService = lJNIEnv->GetStaticFieldID(classContext,
"INPUT_METHOD_SERVICE",
"Ljava/lang/String;");
jobject INPUT_METHOD_SERVICE = lJNIEnv->GetStaticObjectField(ClassContext, FieldINPUT_METHOD_SERVICE);
lJNIEnv->DeleteLocalRef(ClassContext);
jobject inputMethodService = lJNIEnv->GetStaticObjectField(classContext, fieldInputMethodService);
lJNIEnv->DeleteLocalRef(classContext);
// Runs getSystemService(Context.INPUT_METHOD_SERVICE)
jclass ClassInputMethodManager = lJNIEnv->FindClass("android/view/inputmethod/InputMethodManager");
jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(ClassNativeActivity,
jclass classInputMethodManager = lJNIEnv->FindClass("android/view/inputmethod/InputMethodManager");
jmethodID methodGetSystemService = lJNIEnv->GetMethodID(classNativeActivity,
"getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;");
jobject lInputMethodManager = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetSystemService, INPUT_METHOD_SERVICE);
lJNIEnv->DeleteLocalRef(INPUT_METHOD_SERVICE);
jobject lInputMethodManager = lJNIEnv->CallObjectMethod(lNativeActivity, methodGetSystemService, inputMethodService);
lJNIEnv->DeleteLocalRef(inputMethodService);
// Runs getWindow().getDecorView()
jmethodID MethodGetWindow = lJNIEnv->GetMethodID(ClassNativeActivity, "getWindow", "()Landroid/view/Window;");
jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetWindow);
jclass ClassWindow = lJNIEnv->FindClass("android/view/Window");
jmethodID MethodGetDecorView = lJNIEnv->GetMethodID(ClassWindow, "getDecorView", "()Landroid/view/View;");
jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow, MethodGetDecorView);
jmethodID methodGetWindow = lJNIEnv->GetMethodID(classNativeActivity, "getWindow", "()Landroid/view/Window;");
jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity, methodGetWindow);
jclass classWindow = lJNIEnv->FindClass("android/view/Window");
jmethodID methodGetDecorView = lJNIEnv->GetMethodID(classWindow, "getDecorView", "()Landroid/view/View;");
jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow, methodGetDecorView);
lJNIEnv->DeleteLocalRef(lWindow);
lJNIEnv->DeleteLocalRef(ClassWindow);
lJNIEnv->DeleteLocalRef(classWindow);
if (visible)
{
// Runs lInputMethodManager.showSoftInput(...)
jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager,
jmethodID methodShowSoftInput = lJNIEnv->GetMethodID(classInputMethodManager,
"showSoftInput",
"(Landroid/view/View;I)Z");
lJNIEnv->CallBooleanMethod(lInputMethodManager, MethodShowSoftInput, lDecorView, lFlags);
lJNIEnv->CallBooleanMethod(lInputMethodManager, methodShowSoftInput, lDecorView, lFlags);
}
else
{
// Runs lWindow.getViewToken()
jclass ClassView = lJNIEnv->FindClass("android/view/View");
jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(ClassView, "getWindowToken", "()Landroid/os/IBinder;");
jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView, MethodGetWindowToken);
lJNIEnv->DeleteLocalRef(ClassView);
jclass classView = lJNIEnv->FindClass("android/view/View");
jmethodID methodGetWindowToken = lJNIEnv->GetMethodID(classView, "getWindowToken", "()Landroid/os/IBinder;");
jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView, methodGetWindowToken);
lJNIEnv->DeleteLocalRef(classView);
// lInputMethodManager.hideSoftInput(...)
jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager,
jmethodID methodHideSoftInput = lJNIEnv->GetMethodID(classInputMethodManager,
"hideSoftInputFromWindow",
"(Landroid/os/IBinder;I)Z");
lJNIEnv->CallBooleanMethod(lInputMethodManager, MethodHideSoftInput, lBinder, lFlags);
lJNIEnv->CallBooleanMethod(lInputMethodManager, methodHideSoftInput, lBinder, lFlags);
lJNIEnv->DeleteLocalRef(lBinder);
}
lJNIEnv->DeleteLocalRef(ClassNativeActivity);
lJNIEnv->DeleteLocalRef(ClassInputMethodManager);
lJNIEnv->DeleteLocalRef(classNativeActivity);
lJNIEnv->DeleteLocalRef(classInputMethodManager);
lJNIEnv->DeleteLocalRef(lDecorView);
// Finished with the JVM

View File

@ -82,7 +82,7 @@ bool SensorImpl::isAvailable(Sensor::Type sensor)
{
const ASensor* available = getDefaultSensor(sensor);
return available ? true : false;
return available != nullptr;
}
@ -117,7 +117,7 @@ void SensorImpl::close()
////////////////////////////////////////////////////////////
Vector3f SensorImpl::update()
Vector3f SensorImpl::update() const
{
// Update our sensor data list
ALooper_pollAll(0, nullptr, nullptr, nullptr);

View File

@ -85,7 +85,7 @@ public:
/// \return Sensor value
///
////////////////////////////////////////////////////////////
[[nodiscard]] Vector3f update();
[[nodiscard]] Vector3f update() const;
////////////////////////////////////////////////////////////
/// \brief Enable or disable the sensor

View File

@ -257,37 +257,37 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
AInputEvent* _event = nullptr;
AInputEvent* inputEvent = nullptr;
if (AInputQueue_getEvent(states.inputQueue, &_event) >= 0)
if (AInputQueue_getEvent(states.inputQueue, &inputEvent) >= 0)
{
if (AInputQueue_preDispatchEvent(states.inputQueue, _event))
if (AInputQueue_preDispatchEvent(states.inputQueue, inputEvent))
return 1;
int handled = 0;
std::int32_t type = AInputEvent_getType(_event);
std::int32_t type = AInputEvent_getType(inputEvent);
if (type == AINPUT_EVENT_TYPE_KEY)
{
std::int32_t action = AKeyEvent_getAction(_event);
std::int32_t key = AKeyEvent_getKeyCode(_event);
std::int32_t action = AKeyEvent_getAction(inputEvent);
std::int32_t key = AKeyEvent_getKeyCode(inputEvent);
if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) &&
key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN)
{
handled = processKeyEvent(_event, states);
handled = processKeyEvent(inputEvent, states);
}
}
else if (type == AINPUT_EVENT_TYPE_MOTION)
{
std::int32_t action = AMotionEvent_getAction(_event);
std::int32_t action = AMotionEvent_getAction(inputEvent);
switch (action & AMOTION_EVENT_ACTION_MASK)
{
case AMOTION_EVENT_ACTION_SCROLL:
{
handled = processScrollEvent(_event, states);
handled = processScrollEvent(inputEvent, states);
break;
}
@ -295,7 +295,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
// case AMOTION_EVENT_ACTION_HOVER_MOVE:
case AMOTION_EVENT_ACTION_MOVE:
{
handled = processMotionEvent(_event, states);
handled = processMotionEvent(inputEvent, states);
break;
}
@ -303,7 +303,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
case AMOTION_EVENT_ACTION_POINTER_DOWN:
case AMOTION_EVENT_ACTION_DOWN:
{
handled = processPointerEvent(true, _event, states);
handled = processPointerEvent(true, inputEvent, states);
break;
}
@ -311,13 +311,13 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
case AMOTION_EVENT_ACTION_UP:
case AMOTION_EVENT_ACTION_CANCEL:
{
handled = processPointerEvent(false, _event, states);
handled = processPointerEvent(false, inputEvent, states);
break;
}
}
}
AInputQueue_finishEvent(states.inputQueue, _event, handled);
AInputQueue_finishEvent(states.inputQueue, inputEvent, handled);
}
return 1;
@ -325,7 +325,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
////////////////////////////////////////////////////////////
int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& states)
int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityStates& states)
{
// Prepare the Java virtual machine
jint lResult;
@ -347,29 +347,29 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& s
}
// Retrieve everything we need to create this MotionEvent in Java
std::int64_t downTime = AMotionEvent_getDownTime(_event);
std::int64_t eventTime = AMotionEvent_getEventTime(_event);
std::int32_t action = AMotionEvent_getAction(_event);
float x = AMotionEvent_getX(_event, 0);
float y = AMotionEvent_getY(_event, 0);
float pressure = AMotionEvent_getPressure(_event, 0);
float size = AMotionEvent_getSize(_event, 0);
std::int32_t metaState = AMotionEvent_getMetaState(_event);
float xPrecision = AMotionEvent_getXPrecision(_event);
float yPrecision = AMotionEvent_getYPrecision(_event);
std::int32_t deviceId = AInputEvent_getDeviceId(_event);
std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(_event);
std::int64_t downTime = AMotionEvent_getDownTime(inputEvent);
std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent);
std::int32_t action = AMotionEvent_getAction(inputEvent);
float x = AMotionEvent_getX(inputEvent, 0);
float y = AMotionEvent_getY(inputEvent, 0);
float pressure = AMotionEvent_getPressure(inputEvent, 0);
float size = AMotionEvent_getSize(inputEvent, 0);
std::int32_t metaState = AMotionEvent_getMetaState(inputEvent);
float xPrecision = AMotionEvent_getXPrecision(inputEvent);
float yPrecision = AMotionEvent_getYPrecision(inputEvent);
std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent);
std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent);
// Create the MotionEvent object in Java through its static constructor obtain()
jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent");
jmethodID StaticMethodObtain = lJNIEnv->GetStaticMethodID(ClassMotionEvent,
jclass classMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent");
jmethodID staticMethodObtain = lJNIEnv->GetStaticMethodID(classMotionEvent,
"obtain",
"(JJIFFFFIFFII)Landroid/view/MotionEvent;");
// Note: C standard compatibility, varargs
// automatically promote floats to doubles
// even though the function signature declares float
jobject ObjectMotionEvent = lJNIEnv->CallStaticObjectMethod(ClassMotionEvent,
StaticMethodObtain,
jobject objectMotionEvent = lJNIEnv->CallStaticObjectMethod(classMotionEvent,
staticMethodObtain,
downTime,
eventTime,
action,
@ -384,19 +384,19 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& s
edgeFlags);
// Call its getAxisValue() method to get the delta value of our wheel move event
jmethodID MethodGetAxisValue = lJNIEnv->GetMethodID(ClassMotionEvent, "getAxisValue", "(I)F");
jfloat delta = lJNIEnv->CallFloatMethod(ObjectMotionEvent, MethodGetAxisValue, 0x00000001);
jmethodID methodGetAxisValue = lJNIEnv->GetMethodID(classMotionEvent, "getAxisValue", "(I)F");
jfloat delta = lJNIEnv->CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001);
lJNIEnv->DeleteLocalRef(ClassMotionEvent);
lJNIEnv->DeleteLocalRef(ObjectMotionEvent);
lJNIEnv->DeleteLocalRef(classMotionEvent);
lJNIEnv->DeleteLocalRef(objectMotionEvent);
// Create and send our mouse wheel event
Event event;
event.type = Event::MouseWheelScrolled;
event.mouseWheelScroll.wheel = Mouse::VerticalWheel;
event.mouseWheelScroll.delta = static_cast<float>(delta);
event.mouseWheelScroll.x = static_cast<int>(AMotionEvent_getX(_event, 0));
event.mouseWheelScroll.y = static_cast<int>(AMotionEvent_getY(_event, 0));
event.mouseWheelScroll.x = static_cast<int>(AMotionEvent_getX(inputEvent, 0));
event.mouseWheelScroll.y = static_cast<int>(AMotionEvent_getY(inputEvent, 0));
forwardEvent(event);
@ -408,12 +408,12 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& s
////////////////////////////////////////////////////////////
int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* states */)
int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates& /* states */)
{
std::int32_t action = AKeyEvent_getAction(_event);
std::int32_t action = AKeyEvent_getAction(inputEvent);
std::int32_t key = AKeyEvent_getKeyCode(_event);
std::int32_t metakey = AKeyEvent_getMetaState(_event);
std::int32_t key = AKeyEvent_getKeyCode(inputEvent);
std::int32_t metakey = AKeyEvent_getMetaState(inputEvent);
Event event;
event.key.code = androidKeyToSF(key);
@ -431,7 +431,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s
event.type = Event::KeyReleased;
forwardEvent(event);
if (std::uint32_t unicode = static_cast<std::uint32_t>(getUnicode(_event)))
if (auto unicode = static_cast<std::uint32_t>(getUnicode(inputEvent)))
{
event.type = Event::TextEntered;
event.text.unicode = static_cast<std::uint32_t>(unicode);
@ -454,12 +454,12 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s
// https://code.google.com/p/android/issues/detail?id=33998
return 0;
}
else if (std::uint32_t unicode = static_cast<std::uint32_t>(getUnicode(_event))) // This is a repeated sequence
else if (auto unicode = static_cast<std::uint32_t>(getUnicode(inputEvent))) // This is a repeated sequence
{
event.type = Event::TextEntered;
event.text.unicode = static_cast<std::uint32_t>(unicode);
std::int32_t repeats = AKeyEvent_getRepeatCount(_event);
std::int32_t repeats = AKeyEvent_getRepeatCount(inputEvent);
for (std::int32_t i = 0; i < repeats; ++i)
forwardEvent(event);
return 1;
@ -471,9 +471,9 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s
////////////////////////////////////////////////////////////
int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& states)
int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityStates& states)
{
std::int32_t device = AInputEvent_getSource(_event);
std::int32_t device = AInputEvent_getSource(inputEvent);
Event event;
@ -482,14 +482,14 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s
else if (static_cast<std::uint32_t>(device) & AINPUT_SOURCE_TOUCHSCREEN)
event.type = Event::TouchMoved;
std::size_t pointerCount = AMotionEvent_getPointerCount(_event);
std::size_t pointerCount = AMotionEvent_getPointerCount(inputEvent);
for (std::size_t p = 0; p < pointerCount; ++p)
{
std::int32_t id = AMotionEvent_getPointerId(_event, p);
std::int32_t id = AMotionEvent_getPointerId(inputEvent, p);
int x = static_cast<int>(AMotionEvent_getX(_event, p));
int y = static_cast<int>(AMotionEvent_getY(_event, p));
int x = static_cast<int>(AMotionEvent_getX(inputEvent, p));
int y = static_cast<int>(AMotionEvent_getY(inputEvent, p));
if (device == AINPUT_SOURCE_MOUSE)
{
@ -517,16 +517,16 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s
////////////////////////////////////////////////////////////
int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, ActivityStates& states)
int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* inputEvent, ActivityStates& states)
{
std::int32_t device = AInputEvent_getSource(_event);
std::int32_t action = AMotionEvent_getAction(_event);
std::int32_t device = AInputEvent_getSource(inputEvent);
std::int32_t action = AMotionEvent_getAction(inputEvent);
std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
std::int32_t id = AMotionEvent_getPointerId(_event, index);
std::int32_t id = AMotionEvent_getPointerId(inputEvent, index);
int x = static_cast<int>(AMotionEvent_getX(_event, index));
int y = static_cast<int>(AMotionEvent_getY(_event, index));
int x = static_cast<int>(AMotionEvent_getX(inputEvent, index));
int y = static_cast<int>(AMotionEvent_getY(inputEvent, index));
Event event;
@ -740,10 +740,10 @@ int WindowImplAndroid::getUnicode(AInputEvent* event)
jint source = AInputEvent_getSource(event);
// Construct a KeyEvent object from the event data
jclass ClassKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent");
jmethodID KeyEventConstructor = lJNIEnv->GetMethodID(ClassKeyEvent, "<init>", "(JJIIIIIIII)V");
jobject ObjectKeyEvent = lJNIEnv->NewObject(ClassKeyEvent,
KeyEventConstructor,
jclass classKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent");
jmethodID keyEventConstructor = lJNIEnv->GetMethodID(classKeyEvent, "<init>", "(JJIIIIIIII)V");
jobject objectKeyEvent = lJNIEnv->NewObject(classKeyEvent,
keyEventConstructor,
downTime,
eventTime,
action,
@ -756,11 +756,11 @@ int WindowImplAndroid::getUnicode(AInputEvent* event)
source);
// Call its getUnicodeChar() method to get the Unicode value
jmethodID MethodGetUnicode = lJNIEnv->GetMethodID(ClassKeyEvent, "getUnicodeChar", "(I)I");
int unicode = lJNIEnv->CallIntMethod(ObjectKeyEvent, MethodGetUnicode, metaState);
jmethodID methodGetUnicode = lJNIEnv->GetMethodID(classKeyEvent, "getUnicodeChar", "(I)I");
int unicode = lJNIEnv->CallIntMethod(objectKeyEvent, methodGetUnicode, metaState);
lJNIEnv->DeleteLocalRef(ClassKeyEvent);
lJNIEnv->DeleteLocalRef(ObjectKeyEvent);
lJNIEnv->DeleteLocalRef(classKeyEvent);
lJNIEnv->DeleteLocalRef(objectKeyEvent);
// Detach this thread from the JVM
lJavaVM->DetachCurrentThread();

View File

@ -68,7 +68,7 @@ public:
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~WindowImplAndroid();
~WindowImplAndroid() override;
////////////////////////////////////////////////////////////
/// \brief Get the OS-specific handle of the window
@ -225,9 +225,9 @@ private:
////////////////////////////////////////////////////////////
static int processEvent(int fd, int events, void* data);
static int processScrollEvent(AInputEvent* _event, ActivityStates& states);
static int processKeyEvent(AInputEvent* _event, ActivityStates& states);
static int processMotionEvent(AInputEvent* _event, ActivityStates& states);
static int processScrollEvent(AInputEvent* inputEvent, ActivityStates& states);
static int processKeyEvent(AInputEvent* inputEvent, ActivityStates& states);
static int processMotionEvent(AInputEvent* inputEvent, ActivityStates& states);
static int processPointerEvent(bool isDown, AInputEvent* event, ActivityStates& states);
////////////////////////////////////////////////////////////

View File

@ -124,11 +124,11 @@ EglContext::EglContext(EglContext* shared)
m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings());
updateSettings();
// Note: The EGL specs say that attrib_list can be a null pointer when passed to eglCreatePbufferSurface,
// Note: The EGL specs say that attribList can be a null pointer when passed to eglCreatePbufferSurface,
// but this is resulting in a segfault. Bug in Android?
EGLint attrib_list[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
EGLint attribList[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
eglCheck(m_surface = eglCreatePbufferSurface(m_display, m_config, attrib_list));
eglCheck(m_surface = eglCreatePbufferSurface(m_display, m_config, attribList));
// Create EGL context
createContext(shared);