Handling state
This commit is contained in:
parent
dd8fbe4c2f
commit
b8a0ab5468
|
@ -1,5 +1,10 @@
|
||||||
# Krimi Dinner Engine
|
# Krimi Dinner Engine
|
||||||
|
|
||||||
Source code für die Krimi Dinner Engine.
|
Source code für die Krimi Dinner Engine.
|
||||||
In app/src/main/cpp/NativeEngine.cpp sind Kommentare (beginnend mit INTEGRATION), die erklären, wie
|
|
||||||
das Spiel integriert werden kann.
|
In
|
||||||
|
[app/src/main/cpp/NativeEngine.cpp](app/src/main/cpp/NativeEngine.cpp),
|
||||||
|
[app/src/main/cpp/CMakeLists.txt](app/src/main/cpp/CMakeLists.txt)
|
||||||
|
und [app/src/main/cpp/GameState.h](app/src/main/cpp/GameState.h)
|
||||||
|
sind Kommentare
|
||||||
|
(beginnend mit INTEGRATION), die Hinweise geben, wie das Spiel integriert werden kann.
|
|
@ -1,14 +1,11 @@
|
||||||
cmake_minimum_required(VERSION 3.18.1)
|
cmake_minimum_required(VERSION 3.18.1)
|
||||||
project("kde")
|
project("kde")
|
||||||
|
|
||||||
find_library(log-lib log )
|
find_library(log-lib log)
|
||||||
find_package(game-activity REQUIRED CONFIG)
|
find_package(game-activity REQUIRED CONFIG)
|
||||||
find_package(games-frame-pacing REQUIRED CONFIG)
|
find_package(games-frame-pacing REQUIRED CONFIG)
|
||||||
|
|
||||||
add_library(kde SHARED
|
add_library(kde SHARED
|
||||||
kde.cpp
|
|
||||||
NativeEngine.cpp
|
|
||||||
NativeEngine.h
|
|
||||||
Renderer.cpp
|
Renderer.cpp
|
||||||
Renderer.h
|
Renderer.h
|
||||||
Texture.cpp
|
Texture.cpp
|
||||||
|
@ -18,10 +15,19 @@ add_library(kde SHARED
|
||||||
StringRepository.h
|
StringRepository.h
|
||||||
StringRepository.cpp
|
StringRepository.cpp
|
||||||
Hash.h
|
Hash.h
|
||||||
Hash.cpp)
|
Hash.cpp
|
||||||
target_link_libraries(kde ${log-lib}
|
GameState.h)
|
||||||
EGL
|
|
||||||
GLESv3
|
if (ANDROID)
|
||||||
android
|
message(STATUS "Building for Android")
|
||||||
game-activity::game-activity
|
target_sources(kde PUBLIC
|
||||||
games-frame-pacing::swappy_static)
|
kde.cpp
|
||||||
|
NativeEngine.cpp
|
||||||
|
NativeEngine.h)
|
||||||
|
target_link_libraries(kde ${log-lib}
|
||||||
|
EGL
|
||||||
|
GLESv3
|
||||||
|
android
|
||||||
|
game-activity::game-activity
|
||||||
|
games-frame-pacing::swappy_static)
|
||||||
|
endif()
|
13
app/src/main/cpp/GameState.h
Normal file
13
app/src/main/cpp/GameState.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_GAMESTATE_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_GAMESTATE_H
|
||||||
|
|
||||||
|
/// @brief State that is saved between app resumes
|
||||||
|
struct GameState
|
||||||
|
{
|
||||||
|
bool has_focus;
|
||||||
|
|
||||||
|
// INTEGRATION Füge deinen State hier hinzu
|
||||||
|
int foo;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,7 +13,7 @@
|
||||||
#include <swappy/swappyGL.h>
|
#include <swappy/swappyGL.h>
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
|
|
||||||
static NativeEngineState g_app_state = { false };
|
static GameState g_app_state = { false };
|
||||||
|
|
||||||
static void _handle_cmd_proxy(struct android_app* app, int32_t cmd)
|
static void _handle_cmd_proxy(struct android_app* app, int32_t cmd)
|
||||||
{
|
{
|
||||||
|
@ -160,14 +160,14 @@ void NativeEngine::gameLoop()
|
||||||
|
|
||||||
if (isAnimating() && Renderer::ptr) {
|
if (isAnimating() && Renderer::ptr) {
|
||||||
// INTEGRATION Rufe hier deine "gameloop"/"update" funktion auf, die als Parameter
|
// INTEGRATION Rufe hier deine "gameloop"/"update" funktion auf, die als Parameter
|
||||||
// input_events und input_event_count bekommen sollte.
|
// den GameState, input_events und input_event_count und die Displaygröße bekommen sollte:
|
||||||
// Außerdem stehen m_display_width und m_display_height zur Verfügung:
|
|
||||||
//
|
//
|
||||||
// kUpdate(input_events, input_event_count, m_display_width, m_display_height)
|
// kUpdate(&m_state, input_events, input_event_count, m_display_width, m_display_height)
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Die Funktion könnte folgende Definition haben:
|
// Die Funktion könnte folgende Definition haben:
|
||||||
// void kUpdate(const TouchInputEvent* touch_events,
|
// void kUpdate(GameState* state,
|
||||||
|
// const TouchInputEvent* touch_events,
|
||||||
// unsigned int touch_event_count,
|
// unsigned int touch_event_count,
|
||||||
// float display_width,
|
// float display_width,
|
||||||
// float display_height)
|
// float display_height)
|
||||||
|
@ -210,6 +210,11 @@ void NativeEngine::handleAppCmd(int32_t cmd)
|
||||||
ALOGV("NativeEngine: Handling command %d.", cmd);
|
ALOGV("NativeEngine: Handling command %d.", cmd);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case APP_CMD_SAVE_STATE:
|
case APP_CMD_SAVE_STATE:
|
||||||
|
ALOGV("NativeEngine:: APP_CMD_SAVE_STATE");
|
||||||
|
m_state.has_focus = m_has_focus;
|
||||||
|
m_app->savedState = malloc(sizeof(m_state));
|
||||||
|
*reinterpret_cast<GameState*>(m_app->savedState) = m_state;
|
||||||
|
m_app->savedStateSize = sizeof(m_state);
|
||||||
break;
|
break;
|
||||||
case APP_CMD_INIT_WINDOW:
|
case APP_CMD_INIT_WINDOW:
|
||||||
ALOGV("NativeEngine:: APP_CMD_INIT_WINDOW");
|
ALOGV("NativeEngine:: APP_CMD_INIT_WINDOW");
|
||||||
|
@ -217,7 +222,7 @@ void NativeEngine::handleAppCmd(int32_t cmd)
|
||||||
m_has_window = true;
|
m_has_window = true;
|
||||||
SwappyGL_setWindow(m_app->window);
|
SwappyGL_setWindow(m_app->window);
|
||||||
if (m_app->savedStateSize == sizeof(m_state) && m_app->savedState) {
|
if (m_app->savedStateSize == sizeof(m_state) && m_app->savedState) {
|
||||||
m_state = *reinterpret_cast<NativeEngineState*>(m_app->savedState);
|
m_state = *reinterpret_cast<GameState*>(m_app->savedState);
|
||||||
m_has_focus = m_state.has_focus;
|
m_has_focus = m_state.has_focus;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -252,6 +257,9 @@ void NativeEngine::handleAppCmd(int32_t cmd)
|
||||||
ALOGV("NativeEngine: APP_CMD_STOP");
|
ALOGV("NativeEngine: APP_CMD_STOP");
|
||||||
m_is_visible = false;
|
m_is_visible = false;
|
||||||
break;
|
break;
|
||||||
|
case APP_CMD_RESUME:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_RESUME");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ALOGW("Unhandled command.");
|
ALOGW("Unhandled command.");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -6,15 +6,11 @@
|
||||||
|
|
||||||
#include "Position.h"
|
#include "Position.h"
|
||||||
#include "StringRepository.h"
|
#include "StringRepository.h"
|
||||||
|
#include "GameState.h"
|
||||||
|
|
||||||
#include <game-activity/native_app_glue/android_native_app_glue.h>
|
#include <game-activity/native_app_glue/android_native_app_glue.h>
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
|
|
||||||
/// @brief State that is saved between app resumes
|
|
||||||
struct NativeEngineState
|
|
||||||
{
|
|
||||||
bool has_focus;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief Interface to the android game activity
|
/// @brief Interface to the android game activity
|
||||||
class NativeEngine {
|
class NativeEngine {
|
||||||
|
@ -52,7 +48,7 @@ private:
|
||||||
bool m_has_focus;
|
bool m_has_focus;
|
||||||
bool m_is_visible;
|
bool m_is_visible;
|
||||||
|
|
||||||
NativeEngineState m_state;
|
GameState m_state;
|
||||||
|
|
||||||
EGLDisplay m_egl_display;
|
EGLDisplay m_egl_display;
|
||||||
EGLSurface m_egl_surface;
|
EGLSurface m_egl_surface;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user