27 #include "arg_parser.h"
29 #include "utils/deprecated.h"
31 #include "utils/unicode.h"
32 #include "scenes/scene_manager.h"
33 #include "generic/property.h"
34 #include "generic/data_carrier.h"
35 #include "scenes/scene_manager.h"
40 #include "nodes/stage_node_pool.h"
43 #define DEFAULT_LANGUAGE_CODE "en-us"
50 class SharedAssetManager;
53 class VirtualFileSystem;
59 std::runtime_error(
"An error occurred while running a background task") {}
63 unicode title =
_u(
"Simulant Application");
67 bool fullscreen =
true;
70 uint16_t target_frame_rate = 60;
73 uint16_t target_fixed_step_rate = 60;
76 bool enable_vsync =
false;
79 std::vector<Path> search_paths;
82 std::vector<unicode> arguments;
84 smlt::LogLevel log_level = smlt::LOG_LEVEL_INFO;
87 bool show_cursor =
false;
89 std::string source_language_code = DEFAULT_LANGUAGE_CODE;
92 uint32_t stage_node_pool_size = 64;
109 bool enable_virtual_screen =
false;
110 ScreenFormat virtual_screen_format = SCREEN_FORMAT_G1;
111 uint16_t virtual_screen_width = 48;
112 uint16_t virtual_screen_height = 32;
113 uint16_t virtual_screen_integer_scale = 1;
123 #ifdef SIMULANT_PROFILE
124 bool force_profiling =
true;
126 bool force_profiling =
false;
132 std::string force_renderer =
"";
133 std::string force_sound_driver =
"";
137 std::string log_file =
"";
141 bool additional_memory_logging =
true;
148 typedef std::shared_ptr<Loader> LoaderPtr;
149 typedef std::shared_ptr<LoaderType> LoaderTypePtr;
182 int32_t run(
int argc,
char* argv[]);
184 bool initialized()
const {
return initialized_; }
191 smlt::thread::ThreadID
thread_id()
const;
202 uint32_t stage_node_pool_capacity_in_bytes()
const;
220 void start_coroutine(std::function<
void ()> func);
221 void update_coroutines();
222 void stop_all_coroutines();
233 LoaderPtr loader_for(
const Path &filename, LoaderHint hint=LOADER_HINT_NONE);
234 LoaderPtr loader_for(
const std::string& loader_name,
const Path& filename);
235 LoaderTypePtr loader_type(
const std::string& loader_name)
const;
237 void register_loader(LoaderTypePtr loader_type);
256 return active_language_;
266 auto it = active_translations_.find(source_text);
267 if(it == active_translations_.end()) {
278 friend void cr_run_main(std::function<
void ()> func);
279 std::function<void ()> cr_synced_function_;
281 void run_coroutines_and_late_update();
283 thread::ThreadID main_thread_id_;
284 bool has_shutdown_ =
false;
286 std::shared_ptr<Window> window_;
287 std::shared_ptr<SceneManager> scene_manager_;
288 std::shared_ptr<SharedAssetManager> asset_manager_;
289 std::shared_ptr<TimeKeeper> time_keeper_;
290 std::shared_ptr<StatsRecorder> stats_;
291 std::shared_ptr<VirtualFileSystem> vfs_;
292 std::shared_ptr<SoundDriver> sound_driver_;
294 std::vector<LoaderTypePtr> loaders_;
296 bool initialized_ =
false;
297 bool is_running_ =
true;
299 float frame_counter_time_ = 0.0f;
300 int32_t frame_counter_frames_ = 0;
301 float frame_time_in_milliseconds_ = 0.0f;
303 void _call_fixed_update(
float dt) {
307 void _call_clean_up();
309 void _call_update(
float dt) {
313 void _call_late_update(
float dt) {
317 virtual bool init() = 0;
327 virtual bool pre_init() {
return true; }
329 virtual void fixed_update(
float dt) {
333 virtual void update(
float dt) {
337 virtual void late_update(
float dt) {
341 virtual void clean_up() {}
343 generic::DataCarrier data_carrier_;
346 StageNodePool* node_pool_ =
nullptr;
348 void construct_window(
const AppConfig& config);
352 void await_frame_time();
353 uint64_t last_frame_time_us_ = 0;
354 float requested_frame_time_ms_ = 0;
356 std::list<cort::CoroutineID> coroutines_;
357 void preload_default_font();
359 std::string active_language_ = DEFAULT_LANGUAGE_CODE;
360 std::map<unicode, unicode> active_translations_;
362 S_DEFINE_PROPERTY(window, &Application::window_);
363 S_DEFINE_PROPERTY(data, &Application::data_carrier_);
364 S_DEFINE_PROPERTY(scenes, &Application::scene_manager_);
365 S_DEFINE_PROPERTY(args, &Application::args_);
366 S_DEFINE_PROPERTY(config, &Application::config_);
367 S_DEFINE_PROPERTY(stage_node_pool, &Application::node_pool_);
368 S_DEFINE_PROPERTY(shared_assets, &Application::asset_manager_);
369 S_DEFINE_PROPERTY(time_keeper, &Application::time_keeper_);
370 S_DEFINE_PROPERTY(stats, &Application::stats_);
371 S_DEFINE_PROPERTY(vfs, &Application::vfs_);
372 S_DEFINE_PROPERTY(sound_driver, &Application::sound_driver_);
374 friend Application* get_app();
375 static Application* global_app;
377 mutable thread::Mutex running_lock_;
379 std::vector<std::string> generate_potential_codes(
const std::string& language_code);
380 bool load_arb(std::shared_ptr<std::istream> stream, std::string* language_code =
nullptr);
381 bool load_arb_from_file(
const smlt::Path& filename);
384 Application* get_app();
389 smlt::get_app()->translated_text((text))
391 #endif // APPLICATION_H