mirror of https://github.com/buggins/dlangui.git
refactoring
This commit is contained in:
parent
e633218cb5
commit
1ac9601f47
|
@ -93,17 +93,21 @@ class AndroidPlatform : Platform {
|
||||||
protected AndroidWindow[] _windows;
|
protected AndroidWindow[] _windows;
|
||||||
protected AndroidWindow _activeWindow;
|
protected AndroidWindow _activeWindow;
|
||||||
engine _engine;
|
engine _engine;
|
||||||
|
|
||||||
|
|
||||||
protected android_app* _appstate;
|
protected android_app* _appstate;
|
||||||
|
protected EGLDisplay _display;
|
||||||
|
protected EGLSurface _surface;
|
||||||
|
protected EGLContext _context;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
|
||||||
|
|
||||||
this(android_app* state) {
|
this(android_app* state) {
|
||||||
_appstate = state;
|
_appstate = state;
|
||||||
memset(&_engine, 0, engine.sizeof);
|
memset(&_engine, 0, engine.sizeof);
|
||||||
state.userData = cast(void*)this;
|
state.userData = cast(void*)this;
|
||||||
state.onAppCmd = &engine_handle_cmd;
|
state.onAppCmd = &engine_handle_cmd;
|
||||||
state.onInputEvent = &engine_handle_input;
|
state.onInputEvent = &engine_handle_input;
|
||||||
_engine.app = state;
|
|
||||||
|
|
||||||
// Prepare to monitor accelerometer
|
// Prepare to monitor accelerometer
|
||||||
_engine.sensorManager = ASensorManager_getInstance();
|
_engine.sensorManager = ASensorManager_getInstance();
|
||||||
_engine.accelerometerSensor = ASensorManager_getDefaultSensor(_engine.sensorManager,
|
_engine.accelerometerSensor = ASensorManager_getDefaultSensor(_engine.sensorManager,
|
||||||
|
@ -162,9 +166,9 @@ class AndroidPlatform : Platform {
|
||||||
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
|
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
|
||||||
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
|
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
|
||||||
|
|
||||||
ANativeWindow_setBuffersGeometry(_engine.app.window, 0, 0, format);
|
ANativeWindow_setBuffersGeometry(_appstate.window, 0, 0, format);
|
||||||
|
|
||||||
surface = eglCreateWindowSurface(display, config, _engine.app.window, null);
|
surface = eglCreateWindowSurface(display, config, _appstate.window, null);
|
||||||
context = eglCreateContext(display, config, null, null);
|
context = eglCreateContext(display, config, null, null);
|
||||||
|
|
||||||
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
|
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
|
||||||
|
@ -175,11 +179,11 @@ class AndroidPlatform : Platform {
|
||||||
eglQuerySurface(display, surface, EGL_WIDTH, &w);
|
eglQuerySurface(display, surface, EGL_WIDTH, &w);
|
||||||
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
|
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
|
||||||
|
|
||||||
_engine.display = display;
|
_display = display;
|
||||||
_engine.context = context;
|
_context = context;
|
||||||
_engine.surface = surface;
|
_surface = surface;
|
||||||
_engine.width = w;
|
_width = w;
|
||||||
_engine.height = h;
|
_height = h;
|
||||||
_engine.state.angle = 0;
|
_engine.state.angle = 0;
|
||||||
|
|
||||||
// Initialize GL state.
|
// Initialize GL state.
|
||||||
|
@ -195,37 +199,37 @@ class AndroidPlatform : Platform {
|
||||||
* Just the current frame in the display.
|
* Just the current frame in the display.
|
||||||
*/
|
*/
|
||||||
void engine_draw_frame() {
|
void engine_draw_frame() {
|
||||||
if (_engine.display == null) {
|
if (_display == null) {
|
||||||
// No display.
|
// No display.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just fill the screen with a color.
|
// Just fill the screen with a color.
|
||||||
glClearColor(_engine.state.x/_engine.width, _engine.state.angle,
|
glClearColor(_engine.state.x/_width, _engine.state.angle,
|
||||||
_engine.state.y/_engine.height, 1);
|
_engine.state.y/_height, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
eglSwapBuffers(_engine.display, _engine.surface);
|
eglSwapBuffers(_display, _surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tear down the EGL context currently associated with the display.
|
* Tear down the EGL context currently associated with the display.
|
||||||
*/
|
*/
|
||||||
void engine_term_display() {
|
void engine_term_display() {
|
||||||
if (_engine.display != EGL_NO_DISPLAY) {
|
if (_display != EGL_NO_DISPLAY) {
|
||||||
eglMakeCurrent(_engine.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
if (_engine.context != EGL_NO_CONTEXT) {
|
if (_context != EGL_NO_CONTEXT) {
|
||||||
eglDestroyContext(_engine.display, _engine.context);
|
eglDestroyContext(_display, _context);
|
||||||
}
|
}
|
||||||
if (_engine.surface != EGL_NO_SURFACE) {
|
if (_surface != EGL_NO_SURFACE) {
|
||||||
eglDestroySurface(_engine.display, _engine.surface);
|
eglDestroySurface(_display, _surface);
|
||||||
}
|
}
|
||||||
eglTerminate(_engine.display);
|
eglTerminate(_display);
|
||||||
}
|
}
|
||||||
_engine.animating = 0;
|
_engine.animating = 0;
|
||||||
_engine.display = EGL_NO_DISPLAY;
|
_display = EGL_NO_DISPLAY;
|
||||||
_engine.context = EGL_NO_CONTEXT;
|
_context = EGL_NO_CONTEXT;
|
||||||
_engine.surface = EGL_NO_SURFACE;
|
_surface = EGL_NO_SURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,13 +252,13 @@ class AndroidPlatform : Platform {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case APP_CMD_SAVE_STATE:
|
case APP_CMD_SAVE_STATE:
|
||||||
// The system has asked us to save our current state. Do so.
|
// The system has asked us to save our current state. Do so.
|
||||||
_engine.app.savedState = malloc(saved_state.sizeof);
|
_appstate.savedState = malloc(saved_state.sizeof);
|
||||||
*(cast(saved_state*)_engine.app.savedState) = _engine.state;
|
*(cast(saved_state*)_appstate.savedState) = _engine.state;
|
||||||
_engine.app.savedStateSize = saved_state.sizeof;
|
_appstate.savedStateSize = saved_state.sizeof;
|
||||||
break;
|
break;
|
||||||
case APP_CMD_INIT_WINDOW:
|
case APP_CMD_INIT_WINDOW:
|
||||||
// The window is being shown, get it ready.
|
// The window is being shown, get it ready.
|
||||||
if (_engine.app.window != null) {
|
if (_appstate.window != null) {
|
||||||
engine_init_display();
|
engine_init_display();
|
||||||
engine_draw_frame();
|
engine_draw_frame();
|
||||||
}
|
}
|
||||||
|
@ -416,18 +420,18 @@ struct saved_state {
|
||||||
* Shared state for our app.
|
* Shared state for our app.
|
||||||
*/
|
*/
|
||||||
struct engine {
|
struct engine {
|
||||||
android_app* app;
|
//android_app* app;
|
||||||
|
|
||||||
ASensorManager* sensorManager;
|
ASensorManager* sensorManager;
|
||||||
const(ASensor)* accelerometerSensor;
|
const(ASensor)* accelerometerSensor;
|
||||||
ASensorEventQueue* sensorEventQueue;
|
ASensorEventQueue* sensorEventQueue;
|
||||||
|
|
||||||
int animating;
|
int animating;
|
||||||
EGLDisplay display;
|
//EGLDisplay display;
|
||||||
EGLSurface surface;
|
//EGLSurface surface;
|
||||||
EGLContext context;
|
//EGLContext context;
|
||||||
int width;
|
//int width;
|
||||||
int height;
|
//int height;
|
||||||
saved_state state;
|
saved_state state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue