Unicode codepoint input
This commit is contained in:
parent
232494cc46
commit
8ec2da45a2
|
@ -42,7 +42,6 @@ NativeEngine::NativeEngine(struct android_app *app)
|
|||
|
||||
AndroidAssetManager::create(m_app->activity->assetManager);
|
||||
|
||||
|
||||
// INTEGRATION
|
||||
// Hier kannst du Initialisierungscode aufrufen.
|
||||
// Beachte das Renderer noch _nicht_ gültig ist.
|
||||
|
@ -84,8 +83,7 @@ void NativeEngine::gameLoop()
|
|||
struct android_poll_source* source;
|
||||
|
||||
// Poll commands
|
||||
while ((ALooper_pollAll(isAnimating() ? 0 : -1, nullptr,
|
||||
&events, reinterpret_cast<void**>(&source))) >= 0) {
|
||||
while ((ALooper_pollAll(isAnimating() ? 0 : -1, nullptr, &events, reinterpret_cast<void**>(&source))) >= 0) {
|
||||
if (source)
|
||||
source->process(source->app, source);
|
||||
if (m_app->destroyRequested)
|
||||
|
@ -169,9 +167,7 @@ void NativeEngine::gameLoop()
|
|||
}
|
||||
else {
|
||||
// Swipe
|
||||
ALOGI("Swipe from %f %f to %f %f",
|
||||
m_last_down.x, m_last_down.y,
|
||||
x, y);
|
||||
ALOGI("Swipe from %f %f to %f %f", m_last_down.x, m_last_down.y, x, y);
|
||||
input_events[input_event_count].kind = TouchInputEventKind::EndSwipe;
|
||||
input_events[input_event_count].start = {m_last_down.x, m_last_down.y};
|
||||
input_events[input_event_count].end = {x, y};
|
||||
|
@ -197,26 +193,21 @@ void NativeEngine::gameLoop()
|
|||
// INTEGRATION Rufe hier deine "gameloop"/"update" funktion auf, die als Parameter
|
||||
// den GameState, input_events und input_event_count und die Displaygröße bekommen sollte:
|
||||
//
|
||||
// kUpdate(&m_state, input_events, input_event_count, m_display_width, m_display_height)
|
||||
// kUpdate(&m_state, input_events, input_event_count,
|
||||
// nullptr, 0,
|
||||
// m_display_width, m_display_height)
|
||||
//
|
||||
// (Für Kompatibilität zu Windows sollte die funktion auch tastatur input akzeptieren,
|
||||
// den es unter Android aber momentan nicht gibt.)
|
||||
//
|
||||
// Die Funktion könnte folgende Definition haben:
|
||||
// void kUpdate(GameState* state,
|
||||
// const TouchInputEvent* touch_events,
|
||||
// unsigned int touch_event_count,
|
||||
// unsigned int* pressed_codepoints,
|
||||
// unsigned int codepoint_count,
|
||||
// float display_width,
|
||||
// float display_height)
|
||||
|
||||
/*static bool erster_aufruf = true;
|
||||
if (erster_aufruf){
|
||||
computeWindowWidthHeight(m_display_width, m_display_height);
|
||||
initKrimiDinner();
|
||||
erster_aufruf = false;
|
||||
}
|
||||
|
||||
krimiDinnerLoop(&m_state, input_events, input_event_count,
|
||||
m_display_width, m_display_height);*/
|
||||
|
||||
// ENDE INTEGRATION
|
||||
|
||||
// BEISPIELCODE
|
||||
|
@ -250,7 +241,6 @@ bool NativeEngine::isAnimating() const
|
|||
return m_has_window && m_has_focus && m_is_visible;
|
||||
}
|
||||
|
||||
|
||||
void NativeEngine::handleAppCmd(int32_t cmd)
|
||||
{
|
||||
ALOGV("NativeEngine: Handling command %d.", cmd);
|
||||
|
@ -277,8 +267,7 @@ void NativeEngine::handleAppCmd(int32_t cmd)
|
|||
m_has_focus = g_app_state.has_focus;
|
||||
}
|
||||
}
|
||||
ALOGV("HandleCommand(%d): hasWindow = %d, hasFocus = %d", cmd,
|
||||
m_has_window ? 1 : 0, m_has_focus ? 1 : 0);
|
||||
ALOGV("HandleCommand(%d): hasWindow = %d, hasFocus = %d", cmd, m_has_window ? 1 : 0, m_has_focus ? 1 : 0);
|
||||
break;
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
ALOGV("NativeEngine: APP_CMD_TERM_WINDOW");
|
||||
|
@ -311,7 +300,12 @@ void NativeEngine::handleAppCmd(int32_t cmd)
|
|||
break;
|
||||
}
|
||||
ALOGV("NativeEngine STATUS: F%d, V%d, W%d, EGL: D %p, S %p, CTX %p, CFG %p",
|
||||
m_has_focus, m_is_visible, m_has_window, m_egl_display, m_egl_surface, m_egl_context,
|
||||
m_has_focus,
|
||||
m_is_visible,
|
||||
m_has_window,
|
||||
m_egl_display,
|
||||
m_egl_surface,
|
||||
m_egl_context,
|
||||
m_egl_config);
|
||||
}
|
||||
|
||||
|
@ -346,7 +340,9 @@ bool NativeEngine::prepareToRender()
|
|||
}
|
||||
|
||||
ALOGI("NativeEngine: binding surface and context (display %p, surface %p, context %p)",
|
||||
m_egl_display, m_egl_surface, m_egl_context);
|
||||
m_egl_display,
|
||||
m_egl_surface,
|
||||
m_egl_context);
|
||||
|
||||
if (eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, m_egl_context) == EGL_FALSE) {
|
||||
ALOGE("NativeEngine: eglMakeCurrent failed, EGL error: %d", eglGetError());
|
||||
|
@ -396,12 +392,18 @@ bool NativeEngine::initSurface()
|
|||
|
||||
EGLint num_configs;
|
||||
const EGLint attribs[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_ES3_BIT,
|
||||
EGL_SURFACE_TYPE,
|
||||
EGL_WINDOW_BIT,
|
||||
EGL_BLUE_SIZE,
|
||||
8,
|
||||
EGL_GREEN_SIZE,
|
||||
8,
|
||||
EGL_RED_SIZE,
|
||||
8,
|
||||
EGL_DEPTH_SIZE,
|
||||
16,
|
||||
EGL_NONE,
|
||||
};
|
||||
eglChooseConfig(m_egl_display, attribs, &m_egl_config, 1, &num_configs);
|
||||
|
@ -429,10 +431,7 @@ bool NativeEngine::initContext()
|
|||
ALOGI("NativeEngine: initializing context");
|
||||
assert(m_egl_display != EGL_NO_DISPLAY);
|
||||
|
||||
EGLint attrib_list[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLint attrib_list[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
||||
|
||||
if (m_egl_context != EGL_NO_CONTEXT)
|
||||
return true;
|
||||
|
|
|
@ -6,16 +6,34 @@
|
|||
#include "Win32AssetManager.h"
|
||||
#include "TouchInput.h"
|
||||
#include "Position.h"
|
||||
#include "GameState.h"
|
||||
|
||||
#undef APIENTRY
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
struct CodePointsArray
|
||||
{
|
||||
unsigned int* cps; // codepoints
|
||||
unsigned int count;
|
||||
unsigned int cap;
|
||||
};
|
||||
|
||||
static void errorCallback(int error, const char* desc)
|
||||
{
|
||||
MessageBoxA(NULL, desc, "Error", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
|
||||
static void charCallback(GLFWwindow* window, unsigned int cp)
|
||||
{
|
||||
CodePointsArray* cp_array = reinterpret_cast<CodePointsArray*>(glfwGetWindowUserPointer(window));
|
||||
assert(cp_array != nullptr);
|
||||
if (cp_array->count < cp_array->cap)
|
||||
cp_array->cps[cp_array->count++] = cp;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
glfwSetErrorCallback(errorCallback);
|
||||
|
@ -24,6 +42,12 @@ int main()
|
|||
return 1;
|
||||
}
|
||||
|
||||
unsigned int pressed_codepoints[100];
|
||||
CodePointsArray cp_array;
|
||||
cp_array.cps = pressed_codepoints;
|
||||
cp_array.cap = 100;
|
||||
cp_array.count = 0;
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
|
@ -32,6 +56,9 @@ int main()
|
|||
glfwTerminate();
|
||||
return 1;
|
||||
}
|
||||
glfwSetWindowUserPointer(window, &cp_array);
|
||||
glfwSetCharCallback(window, charCallback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
int ret = gladLoadGLES2Loader((GLADloadproc)glfwGetProcAddress);
|
||||
if (!ret) {
|
||||
|
@ -41,6 +68,8 @@ int main()
|
|||
return 1;
|
||||
}
|
||||
|
||||
GameState state = {};
|
||||
|
||||
const char* asset_dir = "app\\src\\main\\assets";
|
||||
Win32AssetManager::create(asset_dir);
|
||||
|
||||
|
@ -53,35 +82,51 @@ int main()
|
|||
|
||||
glfwSwapInterval(1);
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
/* Reset the pressed codepoints array,
|
||||
* because glfwPollEvents() will call our characterCallback
|
||||
*/
|
||||
cp_array.count = 0;
|
||||
|
||||
glfwPollEvents();
|
||||
|
||||
/* Gather keyboard input */
|
||||
|
||||
/* Gather mouse input */
|
||||
TouchInputEvent touch_event = {};
|
||||
TouchInputEvent input_events[1] = {};
|
||||
int input_event_count = 0;
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
|
||||
double x, y;
|
||||
glfwGetCursorPos(window, &x, &y);
|
||||
touch_event.kind = TouchInputEventKind::Tap;
|
||||
touch_event.start = {static_cast<float>(x), static_cast<float>(y)};
|
||||
touch_event.end = touch_event.start;
|
||||
input_events[0].kind = TouchInputEventKind::Tap;
|
||||
input_events[0].start = {static_cast<float>(x), static_cast<float>(y)};
|
||||
input_events[0].end = input_events[0].start;
|
||||
input_event_count = 1;
|
||||
}
|
||||
|
||||
if (cp_array.count > 0) {
|
||||
printf("CP: %u\n", cp_array.cps[0]);
|
||||
}
|
||||
|
||||
int w, h;
|
||||
glfwGetFramebufferSize(window, &w, &h);
|
||||
|
||||
float display_width = static_cast<float>(w);
|
||||
float display_height = static_cast<float>(h);
|
||||
|
||||
// INTEGRATION Rufe hier deine "gameloop"/"update" funktion auf, die als Parameter
|
||||
// den GameState, input_events und input_event_count und die Displaygröße bekommen sollte:
|
||||
//
|
||||
// kUpdate(&m_state, input_events, input_event_count, m_display_width, m_display_height)
|
||||
// kUpdate(&state, input_events, input_event_count,
|
||||
// cp_array.cps, cp_array.count,
|
||||
// display_width, display_height)
|
||||
//
|
||||
//
|
||||
// Die Funktion könnte folgende Definition haben:
|
||||
// void kUpdate(GameState* state,
|
||||
// const TouchInputEvent* touch_events,
|
||||
// unsigned int touch_event_count,
|
||||
// unsigned int* pressed_codepoints,
|
||||
// unsigned int codepoint_count,
|
||||
// float display_width,
|
||||
// float display_height)
|
||||
// ENDE INTEGRATION
|
||||
|
@ -96,7 +141,7 @@ int main()
|
|||
d *= -1.f;
|
||||
|
||||
if (input_event_count > 0) {
|
||||
smiley_pos = touch_event.end;
|
||||
smiley_pos = input_events[0].end;
|
||||
smiley_pos.x -= 250;
|
||||
smiley_pos.y -= 250;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user