Device.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "Config.h"
  26. #include "OS.h"
  27. #include "LinearAllocator.h"
  28. #include "Resource.h"
  29. #include "DiskMountPoint.h"
  30. #ifdef ANDROID
  31. #include "AndroidMountPoint.h"
  32. #endif
  33. #define MAX_SUBSYSTEMS_HEAP 1024 * 1024
  34. namespace crown
  35. {
  36. class Filesystem;
  37. class ResourceManager;
  38. class OsWindow;
  39. class Bundle;
  40. class Renderer;
  41. class DebugRenderer;
  42. class InputManager;
  43. class Keyboard;
  44. class Mouse;
  45. class Touch;
  46. class Accelerometer;
  47. class LuaEnvironment;
  48. class ConsoleServer;
  49. /// The Engine.
  50. /// It is the place where to look for accessing all of
  51. /// the engine subsystems and related stuff.
  52. class CE_EXPORT Device
  53. {
  54. public:
  55. Device();
  56. ~Device();
  57. /// Initializes the engine allowing to pass command line
  58. /// parameters to configure some parameters.
  59. bool init(int argc, char** argv);
  60. /// Shutdowns the engine freeing all the allocated resources
  61. void shutdown();
  62. /// Returns wheter the engine is running (i.e. it is actually
  63. /// doing work).
  64. bool is_running() const;
  65. /// Returns whether the engine is correctly initialized
  66. bool is_init() const;
  67. /// Return the number of frames rendered from the first
  68. /// call to Device::start()
  69. uint64_t frame_count() const;
  70. /// Returns the time in milliseconds needed to render
  71. /// the last frame
  72. float last_delta_time() const;
  73. /// Forces the engine to actually start doing work.
  74. void start();
  75. /// Forces the engine to stop all the work it is doing
  76. /// and normally terminates the program.
  77. void stop();
  78. /// Updates all the subsystems
  79. void frame();
  80. void reload(ResourceId name);
  81. Filesystem* filesystem();
  82. ResourceManager* resource_manager();
  83. InputManager* input_manager();
  84. LuaEnvironment* lua_environment();
  85. OsWindow* window();
  86. Renderer* renderer();
  87. DebugRenderer* debug_renderer();
  88. Keyboard* keyboard();
  89. Mouse* mouse();
  90. Touch* touch();
  91. Accelerometer* accelerometer();
  92. ConsoleServer* console_server();
  93. private:
  94. void create_filesystem();
  95. void create_resource_manager();
  96. void create_input_manager();
  97. void create_lua_environment();
  98. void create_window();
  99. void create_renderer();
  100. void create_debug_renderer();
  101. void create_console_server();
  102. void parse_command_line(int argc, char** argv);
  103. void check_preferred_settings();
  104. void read_engine_settings();
  105. void print_help_message();
  106. private:
  107. // Used to allocate all subsystems
  108. uint8_t m_subsystems_heap[MAX_SUBSYSTEMS_HEAP];
  109. LinearAllocator m_allocator;
  110. // Preferred settings from command line
  111. int32_t m_preferred_window_width;
  112. int32_t m_preferred_window_height;
  113. int32_t m_preferred_window_fullscreen;
  114. uint32_t m_parent_window_handle;
  115. int32_t m_preferred_mode;
  116. char m_root_path[MAX_PATH_LENGTH];
  117. char m_dest_path[MAX_PATH_LENGTH];
  118. char m_resource_path[MAX_PATH_LENGTH];
  119. int32_t m_compile;
  120. int32_t m_quit_after_init;
  121. bool m_is_init : 1;
  122. bool m_is_running : 1;
  123. uint64_t m_frame_count;
  124. uint64_t m_last_time;
  125. uint64_t m_current_time;
  126. float m_last_delta_time;
  127. // Public subsystems
  128. Filesystem* m_filesystem;
  129. OsWindow* m_window;
  130. InputManager* m_input_manager;
  131. LuaEnvironment* m_lua_environment;
  132. Renderer* m_renderer;
  133. DebugRenderer* m_debug_renderer;
  134. // Private subsystems
  135. ResourceManager* m_resource_manager;
  136. Bundle* m_resource_bundle;
  137. // Debug subsystems
  138. ConsoleServer* m_console_server;
  139. #ifdef ANDROID
  140. AndroidMountPoint m_root_mountpoint;
  141. #else
  142. DiskMountPoint m_root_mountpoint;
  143. #endif
  144. private:
  145. enum
  146. {
  147. MODE_RELEASE,
  148. MODE_DEVELOPMENT
  149. };
  150. // Disable copying
  151. Device(const Device&);
  152. Device& operator=(const Device&);
  153. };
  154. CE_EXPORT Device* device();
  155. } // namespace crown