From 8ad02b58625535157824750ea151b96305603d44 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 15 Oct 2019 14:07:58 +0200 Subject: [PATCH] android: refresh the code so that most of the Android port compiles again. --- build/autotools/common.am | 3 ++- build/lol-build | 11 ++++++----- src/application/android-app.cpp | 19 ++++++++++--------- src/application/application.cpp | 3 ++- src/image/codec/android-image.cpp | 23 +++++++++++++---------- src/lol/math/arraynd.h | 6 +++--- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/build/autotools/common.am b/build/autotools/common.am index 77c8c97d..9ecc1ab0 100644 --- a/build/autotools/common.am +++ b/build/autotools/common.am @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# vi:syntax=python # # Define these variables from the beginning @@ -99,7 +101,6 @@ all-local-android: $(foreach p, $(PROGRAMS:%$(EXEEXT)=%), .$(p).androidstamp) cp "$(lol_srcdir)/build/android/icon.png" "$(d)/res/drawable/" $(MKDIR_P) "$(d)/libs/armeabi" $(LN_S) "$(abs_builddir)/$(p)$(EXEEXT)" "$(d)/libs/armeabi/lib$(p).so" - $(LN_S) "$${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so" "$(d)/libs/armeabi" android update project -t android-19 -n "$(p)" -p "$(d)" ant debug -f "$(d)/build.xml" touch $@ diff --git a/build/lol-build b/build/lol-build index 2f64dc27..51af5e90 100755 --- a/build/lol-build +++ b/build/lol-build @@ -223,11 +223,12 @@ configure() do_configure --host=armv7-apple-darwin10 CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" CC="$CC" CXX="$CXX" ;; android-arm) - CPPFLAGS="$CPPFLAGS -Wno-psabi -I$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport -I$ANDROID_NDK_ROOT/sources/android/native_app_glue -fpic -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" - CFLAGS="$CFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb" - CXXFLAGS="$CXXFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb -fno-rtti -fno-exceptions" - LOL_LIBS="$LOL_LIBS -L$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared -lm -fpic -XCClinker -shared -u ANativeActivity_onCreate" - PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure --host=arm-linux-androideabi ac_cv_exeext=.so CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" LOL_LIBS="$LOL_LIBS" + CPPFLAGS="$CPPFLAGS -I$ANDROID_NDK_ROOT/sources/android/native_app_glue -fpic -fomit-frame-pointer -fno-strict-aliasing" + CFLAGS="$CFLAGS" + CXXFLAGS="$CXXFLAGS" + LOL_LIBS="$LOL_LIBS -lm -fpic -XCClinker -shared -u ANativeActivity_onCreate" + HOST=armv7a-linux-androideabi27 + PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure --host="$HOST" CC="$HOST-clang" CXX="$HOST-clang++" ac_cv_exeext=.so CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" LOL_LIBS="$LOL_LIBS" # FIXME: is this needed? # ant debug # ant debug install diff --git a/src/application/android-app.cpp b/src/application/android-app.cpp index fef34574..58c237ee 100644 --- a/src/application/android-app.cpp +++ b/src/application/android-app.cpp @@ -92,7 +92,7 @@ private: void HandleCommand(int32_t cmd); int32_t HandleInput(AInputEvent* event); - vec2 m_prev_pos; + ivec2 m_prev_pos; EGLDisplay m_display; EGLSurface m_surface; @@ -160,7 +160,7 @@ void lol::AndroidAppData::DrawFrame() if (!m_display) return; - Ticker::tick_draw(); + ticker::tick_draw(); eglSwapBuffers(m_display, m_surface); } @@ -206,19 +206,20 @@ int32_t lol::AndroidAppData::HandleInput(AInputEvent* event) AMotionEvent_getY(event, 0)); pos *= m_wanted_resolution / Video::GetSize(); pos.y = m_wanted_resolution.y - 1 - pos.y; - mouse->internal_set_cursor(0, vec2(pos) / vec2(m_wanted_resolution), pos); + // FIXME: bring this back + //mouse->internal_set_cursor(0, vec2(pos) / vec2(m_wanted_resolution), pos); // Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick - mouse->internal_set_axis(0, (pos.x - m_prev_pos.x) / max_screen_size * 100.f); + mouse->internal_set_axis(input::axis::X, (pos.x - m_prev_pos.x) / max_screen_size * 100.f); // Unlike SDL, no need to negate Y axis - mouse->internal_set_axis(1, (pos.y - m_prev_pos.y) / max_screen_size * -100.f); + mouse->internal_set_axis(input::axis::Y, (pos.y - m_prev_pos.y) / max_screen_size * -100.f); m_prev_pos = pos; switch (AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK) { case AMOTION_EVENT_ACTION_DOWN: - mouse->internal_set_key(0, true); + mouse->internal_set_button(input::button::BTN_Left, true); break; case AMOTION_EVENT_ACTION_UP: - mouse->internal_set_key(0, false); + mouse->internal_set_button(input::button::BTN_Left, false); break; } return 1; @@ -341,7 +342,7 @@ lol::AndroidApp::AndroidApp(char const *title, ivec2 res, float fps) { /* Launch our ticker */ msg::debug("Java layer initialising ticker at %g fps", fps); - Ticker::Setup(fps); + ticker::setup(fps); m_data->m_wanted_resolution = res; } @@ -376,7 +377,7 @@ void lol::AndroidApp::Tick() /* Check if we are exiting */ if (m_data->m_native_app->destroyRequested != 0) - Ticker::Shutdown(); + ticker::Shutdown(); } m_data->DrawFrame(); diff --git a/src/application/application.cpp b/src/application/application.cpp index fa092b5f..44d31e02 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -73,7 +73,8 @@ class ApplicationDisplayData protected: #if __ANDROID__ - //NOT HANDLED YET + // TODO: implement this + null_display display; #elif __NX__ nx::app_display display; #elif LOL_USE_SDL diff --git a/src/image/codec/android-image.cpp b/src/image/codec/android-image.cpp index 798d1dbb..2ef3efc5 100644 --- a/src/image/codec/android-image.cpp +++ b/src/image/codec/android-image.cpp @@ -68,7 +68,7 @@ ResourceCodecData* AndroidImageCodec::Load(std::string const &path) #if !LOL_BUILD_RELEASE msg::error("JVM environment not found, cannot open image %s\n", path.c_str()); #endif - return false; + return nullptr; } jclass cls = env->GetObjectClass(g_activity->clazz); jmethodID mid; @@ -83,32 +83,34 @@ ResourceCodecData* AndroidImageCodec::Load(std::string const &path) #if !LOL_BUILD_RELEASE msg::error("could not load %s\n", path.c_str()); #endif - return false; + return nullptr; } env->NewGlobalRef(m_bmp); - /* Get image dimensions */ + // Get image dimensions mid = env->GetMethodID(cls, "getWidth", "(Landroid/graphics/Bitmap;)I"); - m_size.x = env->CallIntMethod(g_activity->clazz, mid, m_bmp); + int width = env->CallIntMethod(g_activity->clazz, mid, m_bmp); mid = env->GetMethodID(cls, "getHeight", "(Landroid/graphics/Bitmap;)I"); - m_size.y = env->CallIntMethod(g_activity->clazz, mid, m_bmp); + int height = env->CallIntMethod(g_activity->clazz, mid, m_bmp); + ivec2 size(width, height); + + auto data = new ResourceImageData(new image(size)); - /* Get pixels */ - m_array = env->NewIntArray(m_size.x * m_size.y); + // Get pixels + m_array = env->NewIntArray(size.x * size.y); env->NewGlobalRef(m_array); mid = env->GetMethodID(cls, "getPixels", "(Landroid/graphics/Bitmap;[I)V"); env->CallVoidMethod(g_activity->clazz, mid, m_bmp, m_array); m_pixels = env->GetIntArrayElements(m_array, 0); - for (int n = 0; n < m_size.x * m_size.y; n++) + for (int n = 0; n < size.x * size.y; n++) { uint32_t u = m_pixels[n]; u = (u & 0xff00ff00) | ((u & 0xff0000) >> 16) | ((u & 0xff) << 16); m_pixels[n] = u; } - m_format = PixelFormat::RGBA_8; - return new ResourceCodecData(); + return data; } bool AndroidImageCodec::Save(std::string const &path, ResourceCodecData* data) @@ -116,6 +118,7 @@ bool AndroidImageCodec::Save(std::string const &path, ResourceCodecData* data) UNUSED(path, data); /* TODO: unimplemented */ + return false; } bool AndroidImageCodec::Close() diff --git a/src/lol/math/arraynd.h b/src/lol/math/arraynd.h index 0541478c..4ce48ec8 100644 --- a/src/lol/math/arraynd.h +++ b/src/lol/math/arraynd.h @@ -113,7 +113,7 @@ public: } /* Additional constructor if ptrdiff_t != int */ - template::value, int>::type> + template::value, int>::type> inline arraynd(vec_t sizes, element_t e = element_t()) { m_sizes = vec_t(sizes); @@ -152,7 +152,7 @@ public: /* If int != ptrdiff_t, access elements directly using an ivec2, * ivec3 etc. */ - template::value, int>::type> + template::value, int>::type> inline element_t const & operator[](vec_t const &pos) const { ptrdiff_t n = pos[N - 1]; @@ -161,7 +161,7 @@ public: return super::operator[](n); } - template::value, int>::type> + template::value, int>::type> inline element_t & operator[](vec_t const &pos) { return const_cast(