Device.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #define MAX_SUBSYSTEMS_HEAP 1024 * 1024
  30. namespace crown
  31. {
  32. class Filesystem;
  33. class ResourceManager;
  34. class OsWindow;
  35. class Bundle;
  36. class Renderer;
  37. class DebugRenderer;
  38. class InputManager;
  39. class Keyboard;
  40. class Mouse;
  41. class Touch;
  42. class Accelerometer;
  43. class LuaEnvironment;
  44. class ConsoleServer;
  45. class BundleCompiler;
  46. /// The Engine.
  47. /// It is the place where to look for accessing all of
  48. /// the engine subsystems and related stuff.
  49. class CE_EXPORT Device
  50. {
  51. public:
  52. Device();
  53. ~Device();
  54. /// Initializes the engine allowing to pass command line
  55. /// parameters to configure some parameters.
  56. bool init(int argc, char** argv);
  57. /// Shutdowns the engine freeing all the allocated resources
  58. void shutdown();
  59. /// Returns wheter the engine is running (i.e. it is actually
  60. /// doing work).
  61. bool is_running() const;
  62. /// Returns whether the engine is correctly initialized
  63. bool is_init() const;
  64. /// Return the number of frames rendered from the first
  65. /// call to Device::start()
  66. uint64_t frame_count() const;
  67. /// Returns the time in milliseconds needed to render
  68. /// the last frame
  69. float last_delta_time() const;
  70. /// Forces the engine to actually start doing work.
  71. void start();
  72. /// Forces the engine to stop all the work it is doing
  73. /// and normally terminates the program.
  74. void stop();
  75. /// Updates all the subsystems
  76. void frame();
  77. void compile(const char* bundle_dir, const char* source_dir, const char* resource);
  78. void reload(ResourceId name);
  79. Filesystem* filesystem();
  80. ResourceManager* resource_manager();
  81. InputManager* input_manager();
  82. LuaEnvironment* lua_environment();
  83. OsWindow* window();
  84. Renderer* renderer();
  85. DebugRenderer* debug_renderer();
  86. Keyboard* keyboard();
  87. Mouse* mouse();
  88. Touch* touch();
  89. Accelerometer* accelerometer();
  90. ConsoleServer* console_server();
  91. private:
  92. void parse_command_line(int argc, char** argv);
  93. void check_preferred_settings();
  94. void read_engine_settings();
  95. void print_help_message();
  96. private:
  97. // Used to allocate all subsystems
  98. uint8_t m_subsystems_heap[MAX_SUBSYSTEMS_HEAP];
  99. LinearAllocator m_allocator;
  100. // Preferred settings from command line
  101. int32_t m_preferred_window_width;
  102. int32_t m_preferred_window_height;
  103. int32_t m_preferred_window_fullscreen;
  104. uint32_t m_parent_window_handle;
  105. char m_source_dir[MAX_PATH_LENGTH];
  106. char m_bundle_dir[MAX_PATH_LENGTH];
  107. int32_t m_compile;
  108. int32_t m_continue;
  109. int32_t m_quit_after_init;
  110. bool m_is_init : 1;
  111. bool m_is_running : 1;
  112. uint64_t m_frame_count;
  113. uint64_t m_last_time;
  114. uint64_t m_current_time;
  115. float m_last_delta_time;
  116. // Public subsystems
  117. Filesystem* m_filesystem;
  118. OsWindow* m_window;
  119. InputManager* m_input_manager;
  120. LuaEnvironment* m_lua_environment;
  121. Renderer* m_renderer;
  122. DebugRenderer* m_debug_renderer;
  123. // Private subsystems
  124. BundleCompiler* m_bundle_compiler;
  125. ResourceManager* m_resource_manager;
  126. Bundle* m_resource_bundle;
  127. // Debug subsystems
  128. ConsoleServer* m_console_server;
  129. private:
  130. // Disable copying
  131. Device(const Device&);
  132. Device& operator=(const Device&);
  133. };
  134. CE_EXPORT Device* device();
  135. } // namespace crown