清理cpp 内容, 只保留主文件。CMakeLists.txt 采用根目录的。

This commit is contained in:
xsl
2025-10-16 14:31:24 +08:00
parent 19932029fb
commit 550f8bb868
13 changed files with 35 additions and 1101 deletions
+4 -57
View File
@@ -2,72 +2,30 @@
#include <game-activity/native_app_glue/android_native_app_glue.h>
#include <game-activity/GameActivity.h>
#include "AndroidOut.h"
#include "Renderer.h"
extern "C" {
/*!
* Handles commands sent to this Android application
* @param pApp the app the commands are coming from
* @param cmd the command to handle
*/
void handle_cmd(android_app *pApp, int32_t cmd) {
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// A new window is created, associate a renderer with it. You may replace this with a
// "game" class if that suits your needs. Remember to change all instances of userData
// if you change the class here as a reinterpret_cast is dangerous this in the
// android_main function and the APP_CMD_TERM_WINDOW handler case.
pApp->userData = new Renderer(pApp);
aout << "APP_CMD_INIT_WINDOW" << std::endl;
break;
case APP_CMD_TERM_WINDOW:
// The window is being destroyed. Use this to clean up your userData to avoid leaking
// resources.
//
// We have to check if userData is assigned just in case this comes in really quickly
if (pApp->userData) {
//
auto *pRenderer = reinterpret_cast<Renderer *>(pApp->userData);
pApp->userData = nullptr;
delete pRenderer;
}
aout << "APP_CMD_TERM_WINDOW" << std::endl;
break;
default:
break;
}
}
/*!
* Enable the motion events you want to handle; not handled events are
* passed back to OS for further processing. For this example case,
* only pointer and joystick devices are enabled.
*
* @param motionEvent the newly arrived GameActivityMotionEvent.
* @return true if the event is from a pointer or joystick device,
* false for all other input devices.
*/
bool motion_event_filter_func(const GameActivityMotionEvent *motionEvent) {
auto sourceClass = motionEvent->source & AINPUT_SOURCE_CLASS_MASK;
return (sourceClass == AINPUT_SOURCE_CLASS_POINTER ||
sourceClass == AINPUT_SOURCE_CLASS_JOYSTICK);
}
/*!
* This the main entry point for a native activity
*/
void android_main(struct android_app *pApp) {
// Can be removed, useful to ensure your code is running
aout << "Welcome to android_main" << std::endl;
// Register an event handler for Android events
pApp->onAppCmd = handle_cmd;
// Set input event filters (set it to NULL if the app wants to process all inputs).
// Note that for key inputs, this example uses the default default_key_filter()
// implemented in android_native_app_glue.c.
android_app_set_motion_event_filter(pApp, motion_event_filter_func);
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 {
@@ -99,18 +57,7 @@ void android_main(struct android_app *pApp) {
}
}
// Check if any user data is associated. This is assigned in handle_cmd
if (pApp->userData) {
// We know that our user data is a Renderer, so reinterpret cast it. If you change your
// user data remember to change it here
auto *pRenderer = reinterpret_cast<Renderer *>(pApp->userData);
// Process game input
pRenderer->handleInput();
// Render a frame
pRenderer->render();
}
} while (!pApp->destroyRequested);
}
}