From cf526872038c8f26a773732ae7b5b2c29a695d9d Mon Sep 17 00:00:00 2001 From: Jonathan De Wachter Date: Thu, 26 Jun 2014 05:15:25 +0200 Subject: [PATCH] [Android] onCreate nows waits for sf::Window to be created --- src/SFML/Main/MainAndroid.cpp | 24 +++---------------- src/SFML/Window/Android/WindowImplAndroid.cpp | 22 ++++++++--------- src/SFML/Window/Android/WindowImplAndroid.hpp | 2 ++ 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 83fe044ef..e98444b10 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -94,12 +94,6 @@ void* main(ActivityStates* states) // Initialize the thread before giving the hand initializeMain(states); - { - Lock lock(states->mutex); - - states->initialized = true; - } - sleep(seconds(0.5)); ::main(0, NULL); @@ -383,14 +377,6 @@ static void onLowMemory(ANativeActivity* activity) } -//////////////////////////////////////////////////////////// -int dummyProcessEvent(int fd, int events, void* data) -{ - // Do nothing - return 0; -} - - //////////////////////////////////////////////////////////// void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize) { @@ -408,14 +394,10 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ for (unsigned int i = 0; i < sf::Mouse::ButtonCount; i++) states->isButtonPressed[i] = false; - states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - // As the input queue will be created before the SFML window, we need to use - // this dummy function that will be replaced later by the first created - // SFML window - states->processEvent = dummyProcessEvent; - - if (savedState != NULL) { + if (savedState != NULL) + { states->savedState = malloc(savedStateSize); states->savedStateSize = savedStateSize; memcpy(states->savedState, savedState, savedStateSize); diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index da78bc7cb..bd22bf56c 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -46,22 +46,22 @@ namespace priv { //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(WindowHandle handle) +: m_size(0, 0) { } //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings) +: m_size(mode.width, mode.height) { ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); - // Replace our dummy process event function with the actual one - AInputQueue_detachLooper(states->inputQueue); - AInputQueue_attachLooper(states->inputQueue, states->looper, 1, processEvent, NULL); - - // Register the actual process event function so it can be set automatically later by the OS + // Register process event callback states->processEvent = processEvent; + + states->initialized = true; } @@ -98,6 +98,10 @@ void WindowImplAndroid::processEvents() if (tempEvent.type == Event::GainedFocus) { states->context->createSurface(states->window); + + m_size.x = ANativeWindow_getWidth(states->window); + m_size.y = ANativeWindow_getHeight(states->window); + states->updated = true; } else if (tempEvent.type == Event::LostFocus) @@ -129,13 +133,7 @@ void WindowImplAndroid::setPosition(const Vector2i& position) //////////////////////////////////////////////////////////// Vector2u WindowImplAndroid::getSize() const { - ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); - - int32_t width = ANativeWindow_getWidth(states->window); - int32_t height = ANativeWindow_getHeight(states->window); - - return Vector2u(static_cast(width), static_cast(height)); + return m_size; } diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index d1249a2ed..16a24538b 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -200,6 +200,8 @@ private: /// //////////////////////////////////////////////////////////// static int getUnicode(AInputEvent* event); + + Vector2u m_size; }; } // namespace priv