source: trunk/src/androidapp.cpp @ 836

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

android: implement JNI_OnLoad and use Log::Info instead of the native
Android functions.

  • Property svn:keywords set to Id
File size: 2.3 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#include <jni.h>
16#include <android/log.h>
17
18#include "core.h"
19#include "lolgl.h"
20#include "loldebug.h"
21
22using namespace lol;
23
24#include "interface.h"
25
26namespace lol
27{
28jobject g_ctx;
29JNIEnv *g_env;
30};
31
32extern "C" jint
33JNI_OnLoad(JavaVM* vm, void* reserved)
34{
35    return JNI_VERSION_1_4;
36}
37
38extern "C" void
39Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
40{
41    env->NewGlobalRef(thiz); /* FIXME: never released! */
42    g_ctx = thiz;
43}
44
45extern "C" void
46Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
47{
48    /* We cannot use JNI_OnLoad for this because we're in a different
49     * thread now. */
50    g_env = env;
51
52    Log::Info("initialising renderer");
53    Ticker::Setup(30.0f);
54    Video::Setup(vec2i(320, 200));
55
56    new Interface();
57    new DebugFps(20, 20);
58}
59
60extern "C" void
61Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
62                                                jint w, jint h)
63{
64    Log::Info("resizing to %i x %i", w, h);
65    Video::Setup(vec2i(w, h));
66}
67
68extern "C" void
69Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
70{
71    /* FIXME: clean up */
72}
73
74extern "C" void
75Java_org_zoy_LolEngine_LolView_nativePause(JNIEnv* env)
76{
77    /* TODO: unimplemented */
78}
79
80extern "C" void
81Java_org_zoy_LolEngine_LolView_nativeDown(JNIEnv* env)
82{
83    Input::SetMouseButton(0);
84}
85
86extern "C" void
87Java_org_zoy_LolEngine_LolView_nativeUp(JNIEnv* env)
88{
89    Input::UnsetMouseButton(0);
90}
91
92extern "C" void
93Java_org_zoy_LolEngine_LolView_nativeMove(JNIEnv* env, jobject thiz,
94                                          jint x, jint y)
95{
96    vec2i pos = vec2i(0, 479) + vec2i(x * 640, -y * 480) / Video::GetSize();
97    Input::SetMousePos(pos);
98}
99
100/* Call to render the next GL frame */
101extern "C" void
102Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
103{
104    Ticker::ClampFps();
105    Ticker::TickGame();
106    Ticker::TickDraw();
107}
108
Note: See TracBrowser for help on using the repository browser.