device.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "types.h"
  7. #include "config.h"
  8. #include "linear_allocator.h"
  9. #include "world_types.h"
  10. #include "resource_types.h"
  11. #include "lua_types.h"
  12. #include "filesystem_types.h"
  13. #include "container_types.h"
  14. #include "input_types.h"
  15. #include "device_options.h"
  16. namespace crown
  17. {
  18. /// @defgroup Device Device
  19. /// This is the place where to look for accessing all of
  20. /// the engine subsystems and related stuff.
  21. ///
  22. /// @ingroup Device
  23. struct Device
  24. {
  25. Device(DeviceOptions& opts);
  26. void init();
  27. /// Shutdowns the engine freeing all the allocated resources.
  28. void shutdown();
  29. /// Returns a string identifying what platform the engine is running on.
  30. const char* platform() const { return CROWN_PLATFORM_NAME; }
  31. /// Returns a string identifying what architecture the engine is running on.
  32. const char* architecture() const { return CROWN_ARCH_NAME; }
  33. /// Returns a string identifying the engine version.
  34. const char* version() const { return CROWN_VERSION_MAJOR "." CROWN_VERSION_MINOR "." CROWN_VERSION_MICRO; }
  35. /// Returns wheter the engine is running (i.e. it is advancing
  36. /// the simulation).
  37. bool is_running() const;
  38. /// Return the number of frames rendered.
  39. uint64_t frame_count() const;
  40. /// Returns the time in seconds needed to render the last frame.
  41. float last_delta_time() const;
  42. /// Returns the time in seconds since the the application started.
  43. double time_since_start() const;
  44. /// Quits the application.
  45. void quit();
  46. /// Pauses the engine.
  47. void pause();
  48. /// Unpauses the engine.
  49. void unpause();
  50. void update_resolution(uint16_t width, uint16_t height);
  51. /// Returns the main window resolution.
  52. void resolution(uint16_t& width, uint16_t& height);
  53. /// Updates all the subsystems.
  54. void update();
  55. /// Renders the given @a world from the point of view of @a camera.
  56. void render_world(World& world, Camera* camera);
  57. /// Creates a new world.
  58. World* create_world();
  59. /// Destroys the world @a w.
  60. void destroy_world(World& w);
  61. /// Returns the resource package @a id.
  62. ResourcePackage* create_resource_package(StringId64 id);
  63. /// Destroy a previously created resource @a package.
  64. /// @note
  65. /// To unload the resources loaded by the package, you have to call
  66. /// ResourcePackage::unload() first.
  67. void destroy_resource_package(ResourcePackage& package);
  68. /// Reloads the resource @a type @a name.
  69. void reload(StringId64 type, StringId64 name);
  70. /// Returns the resource manager.
  71. ResourceManager* resource_manager();
  72. /// Returns the lua environment.
  73. LuaEnvironment* lua_environment();
  74. /// Returns the input manager.
  75. InputManager* input_manager();
  76. private:
  77. void read_config();
  78. private:
  79. // Used to allocate all subsystems
  80. LinearAllocator _allocator;
  81. uint16_t _width;
  82. uint16_t _height;
  83. bool _is_init;
  84. bool _is_running;
  85. bool _is_paused;
  86. uint64_t _frame_count;
  87. int64_t _last_time;
  88. int64_t _current_time;
  89. float _last_delta_time;
  90. double _time_since_start;
  91. DeviceOptions& _device_options;
  92. Filesystem* _bundle_filesystem;
  93. StringId64 _boot_package_id;
  94. StringId64 _boot_script_id;
  95. ResourcePackage* _boot_package;
  96. LuaEnvironment* _lua_environment;
  97. ResourceManager* _resource_manager;
  98. InputManager* _input_manager;
  99. Array<World*> _worlds;
  100. private:
  101. // Disable copying
  102. Device(const Device&);
  103. Device& operator=(const Device&);
  104. };
  105. namespace device_globals
  106. {
  107. void init(DeviceOptions& opts);
  108. void shutdown();
  109. } // namespace device_globals
  110. Device* device();
  111. } // namespace crown