109 строки
2.3 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. jobject g_ctx;
  23. JNIEnv *g_env;
  24. };
  25. extern "C" jint
  26. JNI_OnLoad(JavaVM* vm, void* reserved)
  27. {
  28. return JNI_VERSION_1_4;
  29. }
  30. extern "C" void
  31. Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
  32. {
  33. env->NewGlobalRef(thiz); /* FIXME: never released! */
  34. g_ctx = thiz;
  35. }
  36. extern "C" void
  37. Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
  38. {
  39. /* We cannot use JNI_OnLoad for this because we're in a different
  40. * thread now. */
  41. g_env = env;
  42. Log::Info("initialising renderer");
  43. Ticker::Setup(30.0f);
  44. Video::Setup(vec2i(320, 200));
  45. new Interface();
  46. new DebugFps(20, 20);
  47. }
  48. extern "C" void
  49. Java_org_zoy_LolEngine_LolRenderer_nativeResize(JNIEnv* env, jobject thiz,
  50. jint w, jint h)
  51. {
  52. Log::Info("resizing to %i x %i", w, h);
  53. Video::Setup(vec2i(w, h));
  54. }
  55. extern "C" void
  56. Java_org_zoy_LolEngine_LolRenderer_nativeDone(JNIEnv* env)
  57. {
  58. /* FIXME: clean up */
  59. }
  60. extern "C" void
  61. Java_org_zoy_LolEngine_LolView_nativePause(JNIEnv* env)
  62. {
  63. /* TODO: unimplemented */
  64. }
  65. extern "C" void
  66. Java_org_zoy_LolEngine_LolView_nativeDown(JNIEnv* env)
  67. {
  68. Input::SetMouseButton(0);
  69. }
  70. extern "C" void
  71. Java_org_zoy_LolEngine_LolView_nativeUp(JNIEnv* env)
  72. {
  73. Input::UnsetMouseButton(0);
  74. }
  75. extern "C" void
  76. Java_org_zoy_LolEngine_LolView_nativeMove(JNIEnv* env, jobject thiz,
  77. jint x, jint y)
  78. {
  79. vec2i pos = vec2i(0, 479) + vec2i(x * 640, -y * 480) / Video::GetSize();
  80. Input::SetMousePos(pos);
  81. }
  82. /* Call to render the next GL frame */
  83. extern "C" void
  84. Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
  85. {
  86. Ticker::ClampFps();
  87. Ticker::TickGame();
  88. Ticker::TickDraw();
  89. }