| 114 | |
| 115 | |
| 116 | void PlatformAndroid::onAppCmd(struct android_app* app, int32_t cmd) |
| 117 | { |
| 118 | DBG("On APP cmd called"); |
| 119 | |
| 120 | struct EGL_Window* window = (struct EGL_Window*)app->userData; |
| 121 | switch (cmd) { |
| 122 | case APP_CMD_SAVE_STATE: |
| 123 | // The system has asked us to save our current state. Do so. |
| 124 | //window->m_pAppHandle->savedState = malloc(sizeof(saved_state)); |
| 125 | //*((struct saved_state*)window->m_pAppHandle->savedState) = engine->state; |
| 126 | //window->m_pAppHandle->savedStateSize = sizeof(saved_state); |
| 127 | break; |
| 128 | |
| 129 | case APP_CMD_INIT_WINDOW: |
| 130 | // Command from main thread: a new ANativeWindow is ready for use. Upon |
| 131 | // receiving this command, android_app->window will contain the new window |
| 132 | // surface. |
| 133 | if (m_Window == NULL) |
| 134 | { |
| 135 | DBG("Setting window"); |
| 136 | m_Window = m_App->window; |
| 137 | bgfx::androidSetWindow(m_Window); |
| 138 | m_HasFocus = true; |
| 139 | |
| 140 | int32_t width = ANativeWindow_getWidth(m_Window); |
| 141 | int32_t height = ANativeWindow_getHeight(m_Window); |
| 142 | |
| 143 | windowSizeEvent(width, height); |
| 144 | |
| 145 | m_Thread = std::thread( |
| 146 | [this](){ |
| 147 | using namespace std::chrono_literals; |
| 148 | |
| 149 | std::promise<int32_t> returnValue; |
| 150 | mainLoop(std::move(returnValue), NUMARGS, const_cast<char**>(ARGS)); |
| 151 | while(true) |
| 152 | { |
| 153 | if(m_HasFocus) |
| 154 | { |
| 155 | update(); |
| 156 | }else |
| 157 | { |
| 158 | std::this_thread::sleep_for(1s); |
| 159 | } |
| 160 | } |
| 161 | }); |
| 162 | } |
| 163 | break; |
| 164 | |
| 165 | case APP_CMD_TERM_WINDOW: |
| 166 | // The window is being hidden or closed, clean it up. |
| 167 | //engine_term_display(window); |
| 168 | setQuit(true); |
| 169 | break; |
| 170 | |
| 171 | case APP_CMD_GAINED_FOCUS: |
| 172 | m_HasFocus = true; |
| 173 | break; |