T2DActivity.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 void android_InitDirList(const char* dir);
  44. extern void android_GetNextDir(const char* pdir, char *dir);
  45. extern void android_GetNextFile(const char* pdir, char *file);
  46. extern bool android_IsDir(const char* path);
  47. extern bool android_IsFile(const char* path);
  48. extern U32 android_GetFileSize(const char* pFilePath);
  49. extern bool android_DumpPath(const char* dir, Vector<Platform::FileInfo>& fileVector, U32 depth);
  50. extern bool android_DumpDirectories(const char *basePath, const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath);
  51. extern void toggleSplashScreen(bool show);
  52. /**
  53. * Our saved state data.
  54. */
  55. struct saved_state {
  56. float angle;
  57. int32_t x;
  58. int32_t y;
  59. };
  60. /**
  61. * Shared state for our app.
  62. */
  63. struct engine {
  64. struct android_app* app;
  65. ASensorManager* sensorManager;
  66. const ASensor* accelerometerSensor;
  67. ASensorEventQueue* sensorEventQueue;
  68. int animating;
  69. EGLDisplay display;
  70. EGLSurface surface;
  71. EGLContext context;
  72. int32_t width;
  73. int32_t height;
  74. struct saved_state state;
  75. };
  76. class T2DActivity {
  77. private:
  78. // The pixel dimensions of the backbuffer
  79. S32 backingWidth;
  80. S32 backingHeight;
  81. GLuint _vertexBuffer;
  82. GLuint _indexBuffer;
  83. GLuint _vertexArray;
  84. bool isLayedOut;
  85. char cacheDir[2048];
  86. bool accelerometerActive;
  87. public:
  88. T2DActivity() {
  89. accelerometerActive = false;
  90. }
  91. void enableAccelerometer(bool enable);
  92. bool isAccelerometerActive() {
  93. return accelerometerActive;
  94. }
  95. void loadCacheDir();
  96. char *getCacheDir() {
  97. return cacheDir;
  98. }
  99. void update();
  100. void finishShutdown();
  101. void finishGLSetup();
  102. void enumerateFonts();
  103. void dumpFontList();
  104. void getFontPath(const char* fontName, char* fontPath);
  105. };
  106. extern T2DActivity activity;
  107. #endif