T2DActivity.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef T2DACTIVITY_H
  23. #define T2DACTIVITY_H
  24. #include "platformAndroid/AndroidGL2ES.h"
  25. #include "graphics/DynamicTexture.h"
  26. #include <errno.h>
  27. #include <EGL/egl.h>
  28. //#include <android/sensor.h>
  29. #include <android/log.h>
  30. #include <android_native_app_glue.h>
  31. #include <android/asset_manager.h>
  32. #include <android/sensor.h>
  33. #include <android/configuration.h>
  34. #include <sstream>
  35. #include <list>
  36. #include <unistd.h>
  37. #include <time.h>
  38. extern void adprintf(const char* fmt,...);
  39. extern int _AndroidGetScreenWidth();
  40. extern int _AndroidGetScreenHeight();
  41. extern S32 _AndroidGameGetOrientation();
  42. extern char* _AndroidLoadFile(const char* fileName, U32 *size);
  43. extern char* _AndroidLoadInternalFile(const char* fileName, U32 *size);
  44. extern void android_InitDirList(const char* dir);
  45. extern void android_GetNextDir(const char* pdir, char *dir);
  46. extern void android_GetNextFile(const char* pdir, char *file);
  47. extern bool android_IsDir(const char* path);
  48. extern bool android_IsFile(const char* path);
  49. extern U32 android_GetFileSize(const char* pFilePath);
  50. extern bool android_DumpPath(const char* dir, Vector<Platform::FileInfo>& fileVector, U32 depth);
  51. extern bool android_DumpDirectories(const char *basePath, const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath);
  52. extern void toggleSplashScreen(bool show);
  53. /**
  54. * Our saved state data.
  55. */
  56. struct saved_state {
  57. float angle;
  58. int32_t x;
  59. int32_t y;
  60. };
  61. /**
  62. * Shared state for our app.
  63. */
  64. struct engine {
  65. struct android_app* app;
  66. ASensorManager* sensorManager;
  67. const ASensor* accelerometerSensor;
  68. ASensorEventQueue* sensorEventQueue;
  69. int animating;
  70. EGLDisplay display;
  71. EGLSurface surface;
  72. EGLContext context;
  73. int32_t width;
  74. int32_t height;
  75. struct saved_state state;
  76. };
  77. class T2DActivity {
  78. private:
  79. // The pixel dimensions of the backbuffer
  80. S32 backingWidth;
  81. S32 backingHeight;
  82. GLuint _vertexBuffer;
  83. GLuint _indexBuffer;
  84. GLuint _vertexArray;
  85. bool isLayedOut;
  86. char cacheDir[2048];
  87. char internalDir[2048];
  88. bool accelerometerActive;
  89. public:
  90. T2DActivity() {
  91. accelerometerActive = false;
  92. }
  93. void enableAccelerometer(bool enable);
  94. bool isAccelerometerActive() {
  95. return accelerometerActive;
  96. }
  97. void loadCacheDir();
  98. char *getCacheDir() {
  99. return cacheDir;
  100. }
  101. void loadInternalDir();
  102. char *getInternalDir() {
  103. return internalDir;
  104. }
  105. void update();
  106. void finishShutdown();
  107. void finishGLSetup();
  108. void enumerateFonts();
  109. void dumpFontList();
  110. void getFontPath(const char* fontName, char* fontPath);
  111. };
  112. extern T2DActivity activity;
  113. #endif