[Android] onCreate nows waits for sf::Window to be created

This commit is contained in:
Jonathan De Wachter 2014-06-26 05:15:25 +02:00
parent fb81ddfdcb
commit cf52687203
3 changed files with 15 additions and 33 deletions

View File

@ -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)
{
@ -410,12 +396,8 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
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);

View File

@ -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<unsigned int>(width), static_cast<unsigned int>(height));
return m_size;
}

View File

@ -200,6 +200,8 @@ private:
///
////////////////////////////////////////////////////////////
static int getUnicode(AInputEvent* event);
Vector2u m_size;
};
} // namespace priv