#ifndef KRIMI_DINNER_ENGINE_NATIVEENGINE_H
#define KRIMI_DINNER_ENGINE_NATIVEENGINE_H

/// @file NativeEngine.h
/// @brief Android game activity code

#include "Position.h"
#include "StringRepository.h"
#include "GameState.h"

#include <game-activity/native_app_glue/android_native_app_glue.h>
#include <EGL/egl.h>


/// @brief Interface to the android game activity
class NativeEngine {
public:
    NativeEngine(struct android_app* app);
    ~NativeEngine();

    /// Main loop
    void gameLoop();

    /// Handles app commands
    void handleAppCmd(int32_t event);

private:
    bool isAnimating() const;

    JNIEnv* getJniEnv();

    bool prepareToRender();
    void renderFrame();

    bool initDisplay();
    void killDisplay();
    bool initSurface();
    void killSurface();
    bool initContext();
    void killContext();

    bool initGLObjects();
    void killGLObjects();

    struct android_app* m_app;

    bool m_has_window;
    bool m_has_focus;
    bool m_is_visible;

    GameState m_state;

    EGLDisplay m_egl_display;
    EGLSurface m_egl_surface;
    EGLContext m_egl_context;
    EGLConfig m_egl_config;

    float m_display_width;
    float m_display_height;

    StringHandle m_smiley;
    Position m_smiley_pos;

    Position m_last_down;
    bool m_in_motion;

    JNIEnv* m_jni_env;
};


#endif