8 #include <android/sensor.h>
11 #include <android/window.h>
23 ASensorManager* sensorManager;
24 const ASensor* accelerometerSensor;
25 ASensorEventQueue* sensorEventQueue;
29 Play_State(
const Play_State &);
30 Play_State operator=(
const Play_State &);
37 static Saved_State &
get() {
38 static Saved_State ss;
114 const float w2 = w / 2.0f;
115 const float h2 = 300.0f;
117 for(
int i = 0;
i != 4; ++
i) {
118 const float x =
i & 1 ? w2 : 0.0f;
119 const float y =
i / 2 ? h2 : 0.0f;
128 quad.lend_Material(&mat);
137 const int x =
int(Saved_State::get().position.x) & 0xFFFFFFFE;
138 const int y =
int(Saved_State::get().position.y) & 0xFFFFFFFE;
139 const float tx = 0.05f *
w;
140 const float ty = 0.05f * 600.0f;
141 const float w10 = w / 10.0f;
149 Material mat(ss ?
"sson" :
"ssoff");
150 quad.lend_Material(&mat);
156 get_Fonts()[
"system_36_x600"].render_text(
"Hello world!\nThis is\nthe event\nmankind\nhas been\nwaiting for.",
Point2f(),
Color(1.0
f, 1.0
f, 0.0
f, 1.0
f));
167 return new Play_State;
234 Joysticks::completely_destroy();
248 switch (AInputEvent_getType(event)) {
249 case AINPUT_EVENT_TYPE_KEY:
250 switch(AKeyEvent_getKeyCode(event)) {
252 if(AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN)
255 ZENI_LOGI(
"<audio>Hello World, ...</audio>");
264 case AKEYCODE_SEARCH:
272 case AINPUT_EVENT_TYPE_MOTION:
273 Play_State::Saved_State::get().position.x = AMotionEvent_getX(event, 0);
274 Play_State::Saved_State::get().position.y = AMotionEvent_getY(event, 0);
275 Play_State::Saved_State::get().velocity.x = 0.0f;
276 Play_State::Saved_State::get().velocity.y = 0.0f;
294 struct engine* engine = (
struct engine*)app->
userData;
299 if (engine->app->window !=
NULL) {
307 if(engine->accelerometerSensor) {
308 ASensorEventQueue_enableSensor(engine->sensorEventQueue,
309 engine->accelerometerSensor);
311 ASensorEventQueue_setEventRate(engine->sensorEventQueue,
312 engine->accelerometerSensor,
321 if(engine->accelerometerSensor) {
322 ASensorEventQueue_disableSensor(engine->sensorEventQueue,
323 engine->accelerometerSensor);
336 engine->app->savedStateSize =
sizeof(Play_State::Saved_State);
337 engine->app->savedState =
malloc(engine->app->savedStateSize);
338 *
reinterpret_cast<Play_State::Saved_State *
>(engine->app->savedState) = Play_State::Saved_State::get();
362 while((ident=ALooper_pollAll(0,
NULL, &events, (
void**)&source)) >= 0) {
364 source->
process(state, source);
371 Core::preinit(state);
373 struct engine engine;
378 memset(&engine, 0,
sizeof(engine));
385 engine.sensorManager = ASensorManager_getInstance();
386 engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
387 ASENSOR_TYPE_ACCELEROMETER);
388 engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
394 Play_State::Saved_State &saved_state = Play_State::Saved_State::get();
397 saved_state = *
reinterpret_cast<Play_State::Saved_State *
>(state->
savedState);
412 while((ident=ALooper_pollAll(block,
NULL, &events, (
void**)&source)) >= 0)
415 if (source !=
NULL) {
416 source->
process(state, source);
421 if (engine.accelerometerSensor !=
NULL) {
423 while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
426 saved_state.acceleration.x =
event.acceleration.x;
427 saved_state.acceleration.y =
event.acceleration.y;
428 saved_state.acceleration.z =
event.acceleration.z;
442 saved_state.velocity.x -= saved_state.acceleration.x;
443 saved_state.velocity.y += saved_state.acceleration.y;
448 const float v = saved_state.velocity.magnitude();
450 const float mu0 = 1.5f;
451 const float mu = 0.5f;
452 const float mu_actual = v < 0.001f ? mu0 : mu;
453 const float n = mu_actual * saved_state.acceleration.z;
458 const float fraction = 1.0f - n /
v;
459 saved_state.velocity *= fraction;
462 saved_state.position += saved_state.velocity;
464 if(saved_state.position.x < 0.0f) {
465 saved_state.position.x = 0.0f;
466 saved_state.velocity.x =
std::max(0.0
f, saved_state.velocity.x);
468 else if(saved_state.position.x + w10 >=
get_Window().get_width()) {
470 saved_state.velocity.x =
std::min(0.0
f, saved_state.velocity.x);
472 if(saved_state.position.y < 0.0f) {
473 saved_state.position.y = 0.0f;
474 saved_state.velocity.y =
std::max(0.0
f, saved_state.velocity.y);
476 else if(saved_state.position.y + h10 >=
get_Window().get_height()) {
478 saved_state.velocity.y =
std::min(0.0
f, saved_state.velocity.y);
void prerender()
Called in main, calls the function by the same name in the current Gamestate.
static const int & get_width()
Get the size of the window.
unsigned long give(const String &name, TYPE *const &type, const bool &keep, const String &filename="")
Add an entry (which it will later delete)
The Video Rendering Singleton.
Sound_Source_Pool & get_Sound_Source_Pool()
Get access to the singleton.
static const bool & is_enabled()
Determine whether the use of rendering is desired.
static void render(const Vertex_Buffer_Macrorenderer ¯orenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
An Abstraction of a Material.
static void engine_handle_cmd(struct android_app *app, int32_t cmd)
GLfloat GLfloat GLfloat GLfloat v3
An Abstraction of a Quadrilateral.
void(* onAppCmd)(struct android_app *app, int32_t cmd)
Game & get_Game()
Get access to the singleton.
static int engine_init_display(struct engine *engine)
virtual void on_key(const SDL_KeyboardEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
static void completely_destroy()
virtual bool begin_prerender()=0
Must be called before begin_render.
#define GL_PERSPECTIVE_CORRECTION_HINT
void update()
Redistribute hardware Sound_Sources according to the Replacement_Policy. Newer Sound_Sources are impl...
#define GL_COLOR_BUFFER_BIT
void android_main(struct android_app *state)
Keyboard button event structure (event.key.*)
A Featureful 3-Space Vector Class.
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
static void set_enabled(const bool &enabled)
Enable/Disable the use of rendering; This will not close the rendering window once it is open...
void set_screen_saver(const bool &enabled)
Enable/Disable the screen saver.
class Bootstrap g_bootstrap
virtual void render(const Renderable &renderable)=0
Render a Renderable.
bool is_screen_saver_enabled()
Check to see if the screen saver is enabled.
static void engine_draw_frame(struct engine *)
Gamestate_Zero_Initializer * g_gzi
void render()
Called in main, calls the function by the same name in the current Gamestate.
void(* process)(struct android_app *app, struct android_poll_source *source)
Textures & get_Textures()
Get access to the singleton.
Window & get_Window()
Get access to the singleton.
EGLSurface EGLint EGLint y
An Abstraction of a Vertex in 2-space, textured.
virtual bool begin_render()=0
Must be called before all rendering functions; Returns true if rendering can proceed.
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
void ZENI_LOGI(const Zeni::String &str)
static int32_t engine_handle_input(struct android_app *app, AInputEvent *event)
static const int & get_height()
Get the height of the window.
The base class for all gamestates.
Core & get_Core()
Get access to the singleton.
int32_t(* onInputEvent)(struct android_app *app, AInputEvent *event)
static void engine_term_display(struct engine *engine)
GLint GLint GLint GLint GLint w
virtual void end_render()=0
Must be called after all rendering functions.
Fonts & get_Fonts()
Get access to the singleton.
Video & get_Video()
Get access to the singleton.
void set_sprite_frame(const String &sprite, const int &frame_number)
A 2D Point represented with floats.
GLsizei GLsizei GLchar * source
The Window Management Singleton.
GLfloat GLfloat GLfloat v2
void play_sound(const String &sound_name, const float &pitch, const float &gain, const Point3f &position, const Vector3f &velocity)
A 2D Point represented with integers.