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

Last change on this file since 1219 was 1219, checked in by sam, 8 years ago

android: slightly update Android project for newer SDK versions.

  • Property svn:keywords set to Id
File size: 2.5 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 "loldebug.h"
20#include "androidapp.h"
21
22using namespace lol;
23
24/* Monsterz-specific */
25#include "interface.h"
26
27namespace lol
28{
29JavaVM *g_vm;
30jobject g_activity;
31
32AndroidApp::AndroidApp(char const *title, ivec2 res, float fps) :
33    data(0)
34{
35}
36
37void AndroidApp::ShowPointer(bool show)
38{
39}
40
41void AndroidApp::Run()
42{
43    while (!Ticker::Finished())
44    {
45        /* Tick the renderer, show the frame and clamp to desired framerate. */
46        Ticker::TickDraw();
47    }
48}
49
50AndroidApp::~AndroidApp()
51{
52}
53
54};
55
56extern "C" jint
57JNI_OnLoad(JavaVM* vm, void* reserved)
58{
59    g_vm = vm;
60    return JNI_VERSION_1_4;
61}
62
63extern "C" void
64Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
65{
66    env->NewGlobalRef(thiz); /* FIXME: never released! */
67    g_activity = thiz;
68}
69
70extern "C" void
71Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
72{
73    Log::Info("initialising renderer");
74    Ticker::Setup(30.0f);
75    Video::Setup(ivec2(320, 200));
76
77    new Interface();
78    new DebugFps(20, 20);
79}
80
81extern "C" void
82Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
83                                                jint w, jint h)
84{
85    Log::Info("resizing to %i x %i", w, h);
86    Video::Setup(ivec2(w, h));
87}
88
89extern "C" void
90Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
91{
92    /* FIXME: clean up */
93}
94
95extern "C" void
96Java_org_zoy_LolEngine_LolView_nativePause(JNIEnv* env)
97{
98    /* TODO: unimplemented */
99}
100
101extern "C" void
102Java_org_zoy_LolEngine_LolView_nativeDown(JNIEnv* env)
103{
104    Input::SetMouseButton(0);
105}
106
107extern "C" void
108Java_org_zoy_LolEngine_LolView_nativeUp(JNIEnv* env)
109{
110    Input::UnsetMouseButton(0);
111}
112
113extern "C" void
114Java_org_zoy_LolEngine_LolView_nativeMove(JNIEnv* env, jobject thiz,
115                                          jint x, jint y)
116{
117    ivec2 pos = ivec2(0, 479) + ivec2(x * 640, -y * 480) / Video::GetSize();
118    Input::SetMousePos(pos);
119}
120
121/* Call to render the next GL frame */
122extern "C" void
123Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
124{
125    Ticker::TickDraw();
126}
127
Note: See TracBrowser for help on using the repository browser.