@@ -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 $@ | |||
@@ -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 | |||
@@ -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(); | |||
@@ -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 | |||
@@ -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() | |||
@@ -113,7 +113,7 @@ public: | |||
} | |||
/* Additional constructor if ptrdiff_t != int */ | |||
template<typename T2 = std::enable_if<!std::is_same<ptrdiff_t, int>::value, int>::type> | |||
template<typename T2 = int, typename T3 = typename std::enable_if<!std::is_same<ptrdiff_t, T2>::value, int>::type> | |||
inline arraynd(vec_t<T2, N> sizes, element_t e = element_t()) | |||
{ | |||
m_sizes = vec_t<ptrdiff_t, N>(sizes); | |||
@@ -152,7 +152,7 @@ public: | |||
/* If int != ptrdiff_t, access elements directly using an ivec2, | |||
* ivec3 etc. */ | |||
template<typename T2 = std::enable_if<!std::is_same<ptrdiff_t, int>::value, int>::type> | |||
template<typename T2 = int, typename T3 = typename std::enable_if<!std::is_same<ptrdiff_t, T2>::value, int>::type> | |||
inline element_t const & operator[](vec_t<T2, N> const &pos) const | |||
{ | |||
ptrdiff_t n = pos[N - 1]; | |||
@@ -161,7 +161,7 @@ public: | |||
return super::operator[](n); | |||
} | |||
template<typename T2 = std::enable_if<!std::is_same<ptrdiff_t, int>::value, int>::type> | |||
template<typename T2 = int, typename T3 = typename std::enable_if<!std::is_same<ptrdiff_t, T2>::value, int>::type> | |||
inline element_t & operator[](vec_t<T2, N> const &pos) | |||
{ | |||
return const_cast<element_t &>( | |||