26 #include "arg_parser.h"
28 #include "utils/deprecated.h"
30 #include "utils/unicode.h"
31 #include "scenes/scene_manager.h"
32 #include "generic/property.h"
33 #include "generic/data_carrier.h"
34 #include "scenes/scene_manager.h"
39 #include "nodes/stage_node_pool.h"
42 #define DEFAULT_LANGUAGE_CODE "en-us"
49 class SharedAssetManager;
52 class VirtualFileSystem;
58 std::runtime_error(
"An error occurred while running a background task") {}
62 unicode title =
_u(
"Simulant Application");
66 bool fullscreen =
true;
69 uint16_t target_frame_rate = 60;
72 uint16_t target_fixed_step_rate = 60;
75 bool enable_vsync =
false;
78 std::vector<Path> search_paths;
81 std::vector<unicode> arguments;
83 smlt::LogLevel log_level = smlt::LOG_LEVEL_WARN;
86 bool show_cursor =
false;
88 std::string source_language_code = DEFAULT_LANGUAGE_CODE;
91 uint32_t stage_node_pool_size = 64;
99 "/cd/simulant/fonts/Orbitron",
100 "/cd/assets/simulant/fonts/Orbitron"
101 "/pc/simulant/fonts/Orbitron",
102 "/pc/assets/simulant/fonts/Orbitron"
104 "simulant/fonts/Orbitron",
105 "assets/simulant/fonts/Orbitron"
118 bool enable_virtual_screen =
false;
119 ScreenFormat virtual_screen_format = SCREEN_FORMAT_G1;
120 uint16_t virtual_screen_width = 48;
121 uint16_t virtual_screen_height = 32;
122 uint16_t virtual_screen_integer_scale = 1;
132 #ifdef SIMULANT_PROFILE
133 bool force_profiling =
true;
135 bool force_profiling =
false;
141 std::string force_renderer =
"";
142 std::string force_sound_driver =
"";
146 std::string log_file =
"";
153 typedef std::shared_ptr<Loader> LoaderPtr;
154 typedef std::shared_ptr<LoaderType> LoaderTypePtr;
187 int32_t run(
int argc,
char* argv[]);
189 bool initialized()
const {
return initialized_; }
196 smlt::thread::ThreadID
thread_id()
const;
207 uint32_t stage_node_pool_capacity_in_bytes()
const;
225 void start_coroutine(std::function<
void ()> func);
226 void update_coroutines();
227 void stop_all_coroutines();
238 LoaderPtr loader_for(
const Path &filename, LoaderHint hint=LOADER_HINT_NONE);
239 LoaderPtr loader_for(
const std::string& loader_name,
const Path& filename);
240 LoaderTypePtr loader_type(
const std::string& loader_name)
const;
242 void register_loader(LoaderTypePtr loader_type);
253 return active_language_;
263 auto it = active_translations_.find(source_text);
264 if(it == active_translations_.end()) {
275 friend void cr_run_main(std::function<
void ()> func);
276 std::function<void ()> cr_synced_function_;
278 void run_coroutines_and_late_update();
280 thread::ThreadID main_thread_id_;
281 bool has_shutdown_ =
false;
283 std::shared_ptr<Window> window_;
284 std::shared_ptr<SceneManager> scene_manager_;
285 std::shared_ptr<SharedAssetManager> asset_manager_;
286 std::shared_ptr<TimeKeeper> time_keeper_;
287 std::shared_ptr<StatsRecorder> stats_;
288 std::shared_ptr<VirtualFileSystem> vfs_;
289 std::shared_ptr<SoundDriver> sound_driver_;
291 std::vector<LoaderTypePtr> loaders_;
293 bool initialized_ =
false;
294 bool is_running_ =
true;
296 float frame_counter_time_ = 0.0f;
297 int32_t frame_counter_frames_ = 0;
298 float frame_time_in_milliseconds_ = 0.0f;
300 void _call_fixed_update(
float dt) {
304 void _call_clean_up() {
308 void _call_update(
float dt) {
312 void _call_late_update(
float dt) {
316 virtual bool init() = 0;
317 virtual void fixed_update(
float dt) {
321 virtual void update(
float dt) {
325 virtual void late_update(
float dt) {
329 virtual void clean_up() {}
331 generic::DataCarrier data_carrier_;
334 StageNodePool* node_pool_ =
nullptr;
336 void construct_window(
const AppConfig& config);
340 void await_frame_time();
341 uint64_t last_frame_time_us_ = 0;
342 float requested_frame_time_ms_ = 0;
344 std::list<cort::CoroutineID> coroutines_;
345 void preload_default_font();
347 std::string active_language_ = DEFAULT_LANGUAGE_CODE;
348 std::map<unicode, unicode> active_translations_;
350 S_DEFINE_PROPERTY(window, &Application::window_);
351 S_DEFINE_PROPERTY(data, &Application::data_carrier_);
352 S_DEFINE_PROPERTY(scenes, &Application::scene_manager_);
353 S_DEFINE_PROPERTY(args, &Application::args_);
354 S_DEFINE_PROPERTY(config, &Application::config_);
355 S_DEFINE_PROPERTY(stage_node_pool, &Application::node_pool_);
356 S_DEFINE_PROPERTY(shared_assets, &Application::asset_manager_);
357 S_DEFINE_PROPERTY(time_keeper, &Application::time_keeper_);
358 S_DEFINE_PROPERTY(stats, &Application::stats_);
359 S_DEFINE_PROPERTY(vfs, &Application::vfs_);
360 S_DEFINE_PROPERTY(sound_driver, &Application::sound_driver_);
362 friend Application* get_app();
363 static Application* global_app;
365 mutable thread::Mutex running_lock_;
367 std::vector<std::string> generate_potential_codes(
const std::string& language_code);
368 bool load_arb_file(
const smlt::Path& filename);
371 Application* get_app();
376 smlt::get_app()->translated_text((text))
378 #endif // APPLICATION_H