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

Last change on this file since 865 was 865, checked in by sam, 9 years ago

core: move platform-specific code to specific directories.

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