| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- /*
- Copyright (c) 2013 Daniele Bartolini, Michele Rossi
- Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
- #pragma once
- #include "Types.h"
- #include "Config.h"
- #include "OS.h"
- #include "LinearAllocator.h"
- #include "Resource.h"
- #define MAX_SUBSYSTEMS_HEAP 1024 * 1024
- namespace crown
- {
- class Filesystem;
- class ResourceManager;
- class OsWindow;
- class Bundle;
- class Renderer;
- class DebugRenderer;
- class InputManager;
- class Keyboard;
- class Mouse;
- class Touch;
- class Accelerometer;
- class LuaEnvironment;
- class ConsoleServer;
- class BundleCompiler;
- class ResourcePackage;
- /// The Engine.
- /// It is the place where to look for accessing all of
- /// the engine subsystems and related stuff.
- class CE_EXPORT Device
- {
- public:
- Device();
- ~Device();
- /// Initializes the engine allowing to pass command line
- /// parameters to configure some parameters.
- bool init(int argc, char** argv);
- /// Shutdowns the engine freeing all the allocated resources
- void shutdown();
- /// Returns wheter the engine is running (i.e. it is actually
- /// doing work).
- bool is_running() const;
- /// Returns whether the engine is correctly initialized
- bool is_init() const;
- /// Returns wheter the engine is paused
- bool is_paused() const;
- /// Return the number of frames rendered from the first
- /// call to Device::start()
- uint64_t frame_count() const;
- /// Returns the time in milliseconds needed to render
- /// the last frame
- float last_delta_time() const;
- /// Forces the engine to actually start doing work.
- void start();
- /// Forces the engine to stop all the work it is doing
- /// and normally terminates the program.
- void stop();
- /// Pauses the engine
- void pause();
- /// Unpauses the engine
- void unpause();
- /// Updates all the subsystems
- void frame();
- /// Returns the resource package with the given @a package_name name.
- ResourcePackage* create_resource_package(const char* name);
- /// Destroy a previously created resource @a package.
- /// @note
- /// To unload the resources loaded by the package, you have to call
- /// ResourcePackage::unload() first.
- void destroy_resource_package(ResourcePackage* package);
- void compile(const char* bundle_dir, const char* source_dir, const char* resource);
- void reload(ResourceId name);
- Filesystem* filesystem();
- ResourceManager* resource_manager();
- InputManager* input_manager();
- LuaEnvironment* lua_environment();
- OsWindow* window();
- Renderer* renderer();
- DebugRenderer* debug_renderer();
- Keyboard* keyboard();
- Mouse* mouse();
- Touch* touch();
- Accelerometer* accelerometer();
- ConsoleServer* console_server();
- inline void init_renderer() { m_renderer_init_request = true; }
- private:
- void init();
- void parse_command_line(int argc, char** argv);
- void check_preferred_settings();
- void read_engine_settings();
- void print_help_message();
- private:
- // Used to allocate all subsystems
- uint8_t m_subsystems_heap[MAX_SUBSYSTEMS_HEAP];
- LinearAllocator m_allocator;
- // Preferred settings
- int32_t m_preferred_window_width;
- int32_t m_preferred_window_height;
- int32_t m_preferred_window_fullscreen;
- uint32_t m_parent_window_handle;
- char m_source_dir[MAX_PATH_LENGTH];
- char m_bundle_dir[MAX_PATH_LENGTH];
- char m_boot_file[MAX_PATH_LENGTH];
- int32_t m_compile;
- int32_t m_continue;
- int32_t m_quit_after_init;
- bool m_is_init : 1;
- bool m_is_running : 1;
- bool m_is_paused : 1;
- bool m_is_really_paused :1;
- uint64_t m_frame_count;
- uint64_t m_last_time;
- uint64_t m_current_time;
- float m_last_delta_time;
- // Public subsystems
- Filesystem* m_filesystem;
- OsWindow* m_window;
- InputManager* m_input_manager;
- LuaEnvironment* m_lua_environment;
- Renderer* m_renderer;
- DebugRenderer* m_debug_renderer;
- // Private subsystems
- BundleCompiler* m_bundle_compiler;
- ResourceManager* m_resource_manager;
- Bundle* m_resource_bundle;
- // Debug subsystems
- ConsoleServer* m_console_server;
- bool m_renderer_init_request;
- private:
- // Disable copying
- Device(const Device&);
- Device& operator=(const Device&);
- friend class MainThread;
- };
- CE_EXPORT Device* device();
- } // namespace crown
|