android 表面,扩展,实例都创建成功
This commit is contained in:
+20
-10
@@ -3,14 +3,21 @@
|
||||
#include <game-activity/native_app_glue/android_native_app_glue.h>
|
||||
#include <game-activity/GameActivity.h>
|
||||
#include "AndroidOut.h"
|
||||
#include "Application.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
using namespace std;
|
||||
extern "C" {
|
||||
|
||||
android_app* g_android_app = nullptr;
|
||||
Application* g_Application = nullptr;
|
||||
|
||||
void handle_cmd(android_app *pApp, int32_t cmd) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
aout << "APP_CMD_INIT_WINDOW" << std::endl;
|
||||
g_Application->initVulkan();
|
||||
break;
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
aout << "APP_CMD_TERM_WINDOW" << std::endl;
|
||||
@@ -20,26 +27,24 @@ void handle_cmd(android_app *pApp, int32_t cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
android_app* g_android_app = nullptr;
|
||||
|
||||
void android_main(struct android_app *pApp) {
|
||||
aout << "Welcome to android_main" << std::endl;
|
||||
|
||||
g_android_app = pApp;
|
||||
Application application;
|
||||
g_Application = &application;
|
||||
pApp->onAppCmd = handle_cmd;
|
||||
|
||||
android_app_set_motion_event_filter(pApp, nullptr);
|
||||
|
||||
// This sets up a typical game/event loop. It will run until the app is destroyed.
|
||||
do {
|
||||
auto ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||
// Process all pending events before running game logic.
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
// 0 is non-blocking.
|
||||
int timeout = 0;
|
||||
int events;
|
||||
android_poll_source *pSource;
|
||||
int result = ALooper_pollOnce(timeout, nullptr, &events,
|
||||
reinterpret_cast<void**>(&pSource));
|
||||
int result = ALooper_pollOnce(timeout, nullptr, &events, reinterpret_cast<void**>(&pSource));
|
||||
switch (result) {
|
||||
case ALOOPER_POLL_TIMEOUT:
|
||||
[[clang::fallthrough]];
|
||||
@@ -58,8 +63,13 @@ void android_main(struct android_app *pApp) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(application.isInited())
|
||||
{
|
||||
application.drawFrame();
|
||||
}
|
||||
auto end_ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||
this_thread::sleep_for(chrono::milliseconds((end_ms-ms)));
|
||||
} while (!pApp->destroyRequested);
|
||||
application.cleanup();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user