3#include <Covellite/App/Application.hpp>
4#include <Covellite/Events.hpp>
5#include <Covellite/App/Events.hpp>
7using AppInfo_t = ::alicorn::system::platform::AppInfo;
9using namespace covellite::app;
14 inline static void Error(
const char * _Format, ...)
17 va_start(Args, _Format);
18 (void)__android_log_print(ANDROID_LOG_ERROR,
"Covellite++", _Format, Args);
22 inline static void Info(
const char * _Format, ...)
25 va_start(Args, _Format);
26 (void)__android_log_print(ANDROID_LOG_INFO,
"Covellite++", _Format, Args);
35Application::Application(
const Run_t & _Run) :
38 auto & App = AppInfo_t::Get<android_app>();
41 App.onAppCmd = [](
android_app * _pApp, int32_t _Message)
43 if (_pApp ==
nullptr || _pApp->userData ==
nullptr)
return;
46 auto & Events = *(
reinterpret_cast<Application *
>(_pApp->userData));
48 Events.m_Events[_Message]();
51 App.onInputEvent = [](
android_app * _pApp, AInputEvent * _pEvent) -> int32_t
53 if (_pApp ==
nullptr || _pApp->userData ==
nullptr)
return 0;
56 auto & Events = *(
reinterpret_cast<Application *
>(_pApp->userData));
58 const auto EventType = AInputEvent_getType(_pEvent);
59 const auto ActionType = AMotionEvent_getAction(_pEvent);
61 const auto IsSuccess = Events.m_Events[(EventType << 8) | ActionType](_pEvent);
62 return (IsSuccess) ? 1 : 0;
65 m_Events[(int32_t)APP_CMD_INIT_WINDOW]
66 .Connect([=]() { m_Events[events::Application.Start](); });
67 m_Events[(int32_t)APP_CMD_STOP]
68 .Connect([=]() { m_Events[events::Application.Exit](); });
69 m_Events[(int32_t)APP_CMD_TERM_WINDOW]
77 while(!m_Windows.empty()) m_Windows.pop();
79 m_Events[events::Application.Exit]
80 .Connect([=]() { ANativeActivity_finish(App.activity); });
91 auto & DestroyRequested = AppInfo_t::Get<android_app>().destroyRequested;
95 while (DestroyRequested == 0)
112 m_Events[events::Application.Update]();
118 m_Events[(int32_t)APP_CMD_LOST_FOCUS]
119 .Connect([=]() { m_IsFocused =
false; });
120 m_Events[(int32_t)APP_CMD_GAINED_FOCUS]
121 .Connect([=]() { m_IsFocused =
true; });
132 auto & DestroyRequested = AppInfo_t::Get<android_app>().destroyRequested;
134 Logcat::Info(
"Application::Run(): event based circle started.");
136 while (DestroyRequested == 0)
139 m_Events[events::Application.Update]();
145 Application::~Application(
void)
noexcept
147 auto & App = AppInfo_t::Get<android_app>();
149 App.onAppCmd =
nullptr;
150 App.onInputEvent =
nullptr;
151 App.userData =
nullptr;
169 Logcat::Info(
"Application::Main(): start program.");
173 auto * pApp =
reinterpret_cast<android_app *
>(_pParams);
175 Logcat::Info(
"Application::Main(): init.");
188 Logcat::Info(
"Application::Main(): create app object.");
190 const auto pApplication = _fnCreateApp();
192 Logcat::Info(
"Application::Main(): run program.");
196 catch (const ::std::exception & _Ex)
198 Logcat::Error(
"Application::Main(): error [%s].", _Ex.what());
202 Logcat::Error(
"Application::Main(): error [unknown].");
205 Logcat::Info(
"Application::Main(): finish program.");
237 const auto Result = ALooper_pollAll((_IsWaitMessage) ? -1 : 0,
238 nullptr,
nullptr, (
void **)&pSource);
239 if (Result < 0 || pSource ==
nullptr)
return false;
241 pSource->process(&AppInfo_t::Get<android_app>(), pSource);
Definition android_native_app_glue.h:90
Definition android_native_app_glue.h:111
Класс входит в проект Covellite.App Базовый класс приложения для Android.
Definition Application.hpp:51
Application(const Run_t &)
Инициализирующий конструктор класса.
Definition Application.android.cpp:35
static void Main(void *) noexcept
Функция точки входа в программу.
Definition Application.inl:58
VIRTUAL_MOCK bool PostCommand(bool)
Функция вызова сигнала произошедшего события..
Definition Application.android.cpp:233
::std::string GetCommandLine(void) const
Функция получения параметров командной строки, которые были переданы программе ее при запуске.
Definition Application.android.cpp:212
Непрерывная отрисовка экрана (режим работы игры).
Definition Application.hpp:57
Definition Application.hpp:58