106 lines
2.2 KiB

  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <jni.h>
  14. #include <android/log.h>
  15. #include "core.h"
  16. #include "lolgl.h"
  17. #include "loldebug.h"
  18. using namespace lol;
  19. #include "interface.h"
  20. namespace lol
  21. {
  22. JavaVM *g_vm;
  23. jobject g_activity;
  24. };
  25. extern "C" jint
  26. JNI_OnLoad(JavaVM* vm, void* reserved)
  27. {
  28. g_vm = vm;
  29. return JNI_VERSION_1_4;
  30. }
  31. extern "C" void
  32. Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
  33. {
  34. env->NewGlobalRef(thiz); /* FIXME: never released! */
  35. g_activity = thiz;
  36. }
  37. extern "C" void
  38. Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
  39. {
  40. Log::Info("initialising renderer");
  41. Ticker::Setup(30.0f);
  42. Video::Setup(ivec2(320, 200));
  43. new Interface();
  44. new DebugFps(20, 20);
  45. }
  46. extern "C" void
  47. Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
  48. jint w, jint h)
  49. {
  50. Log::Info("resizing to %i x %i", w, h);
  51. Video::Setup(ivec2(w, h));
  52. }
  53. extern "C" void
  54. Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
  55. {
  56. /* FIXME: clean up */
  57. }
  58. extern "C" void
  59. Java_org_zoy_LolEngine_LolView_nativePause(JNIEnv* env)
  60. {
  61. /* TODO: unimplemented */
  62. }
  63. extern "C" void
  64. Java_org_zoy_LolEngine_LolView_nativeDown(JNIEnv* env)
  65. {
  66. Input::SetMouseButton(0);
  67. }
  68. extern "C" void
  69. Java_org_zoy_LolEngine_LolView_nativeUp(JNIEnv* env)
  70. {
  71. Input::UnsetMouseButton(0);
  72. }
  73. extern "C" void
  74. Java_org_zoy_LolEngine_LolView_nativeMove(JNIEnv* env, jobject thiz,
  75. jint x, jint y)
  76. {
  77. ivec2 pos = ivec2(0, 479) + ivec2(x * 640, -y * 480) / Video::GetSize();
  78. Input::SetMousePos(pos);
  79. }
  80. /* Call to render the next GL frame */
  81. extern "C" void
  82. Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
  83. {
  84. Ticker::ClampFps();
  85. Ticker::TickGame();
  86. Ticker::TickDraw();
  87. }