source: trunk/src/platform/android/androidapp.cpp @ 1684

Last change on this file since 1684 was 1684, checked in by sam, 10 years ago

build: switch the Android native build rules to autoconf; still a bit rough
but we can now create shared objects for each project; only the testsuite
is not building properly because of issues with STLport, and EglApp is
deactivated because AndroidApp should have precedence.

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#if defined __ANDROID__
16
17#include <jni.h>
18#include <android/log.h>
19
20#include "core.h"
21#include "loldebug.h"
22#include "androidapp.h"
23
24using namespace lol;
25
26/* One of these wrappers will be overridden by the user's version */
27void lol_android_main(void) __attribute__((weak));
28void lol_android_main(void) {}
29void lol_android_main(int argc, char **argv) __attribute__((weak));
30void lol_android_main(int argc, char **argv) {}
31void lol_android_main(int argc, char **argv, char **envp) __attribute__((weak));
32void lol_android_main(int argc, char **argv, char **envp) {}
33
34namespace lol
35{
36JavaVM *g_vm;
37jobject g_activity;
38Thread *g_main_thread;
39
40AndroidApp::AndroidApp(char const *title, ivec2 res, float fps) :
41    data(0)
42{
43}
44
45void AndroidApp::ShowPointer(bool show)
46{
47}
48
49void AndroidApp::Run()
50{
51    while (!Ticker::Finished())
52    {
53        /* Tick the renderer, show the frame and clamp to desired framerate. */
54        Ticker::TickDraw();
55    }
56}
57
58void *AndroidApp::MainRun(void *data)
59{
60    int argc = 1;
61    char *argv[] = { "", NULL };
62    char *env[] = { NULL };
63
64    /* Call the user's main() function. One of these will work. */
65    lol_android_main();
66    lol_android_main(argc, argv);
67    lol_android_main(argc, argv, env);
68
69    return NULL;
70}
71
72AndroidApp::~AndroidApp()
73{
74}
75
76};
77
78extern "C" jint
79JNI_OnLoad(JavaVM* vm, void* reserved)
80{
81    g_vm = vm;
82    return JNI_VERSION_1_4;
83}
84
85extern "C" void
86Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
87{
88    env->NewGlobalRef(thiz); /* FIXME: never released! */
89    g_activity = thiz;
90}
91
92extern "C" void
93Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
94{
95    Log::Info("initialising renderer");
96    Ticker::Setup(30.0f);
97    Video::Setup(ivec2(320, 200));
98
99    g_main_thread = new Thread(lol::AndroidApp::MainRun, NULL);;
100}
101
102extern "C" void
103Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
104                                                jint w, jint h)
105{
106    Log::Info("resizing to %i x %i", w, h);
107    Video::Setup(ivec2(w, h));
108}
109
110extern "C" void
111Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
112{
113    /* FIXME: clean up */
114    delete g_main_thread;
115}
116
117extern "C" void
118Java_org_zoy_LolEngine_LolView_nativePause(JNIEnv* env)
119{
120    /* TODO: unimplemented */
121}
122
123extern "C" void
124Java_org_zoy_LolEngine_LolView_nativeDown(JNIEnv* env)
125{
126    Input::SetMouseButton(0);
127}
128
129extern "C" void
130Java_org_zoy_LolEngine_LolView_nativeUp(JNIEnv* env)
131{
132    Input::UnsetMouseButton(0);
133}
134
135extern "C" void
136Java_org_zoy_LolEngine_LolView_nativeMove(JNIEnv* env, jobject thiz,
137                                          jint x, jint y)
138{
139    ivec2 pos = ivec2(0, 479) + ivec2(x * 640, -y * 480) / Video::GetSize();
140    Input::SetMousePos(pos);
141}
142
143/* Call to render the next GL frame */
144extern "C" void
145Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
146{
147    Ticker::TickDraw();
148}
149
150#endif /* __ANDROID__ */
151
Note: See TracBrowser for help on using the repository browser.