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"
41 #define DEFAULT_LANGUAGE_CODE "en-us"
48 class SharedAssetManager;
51 class VirtualFileSystem;
57 std::runtime_error(
"An error occurred while running a background task") {}
61 unicode title =
_u(
"Simulant Application");
65 bool fullscreen =
true;
68 uint16_t target_frame_rate = 60;
71 uint16_t target_fixed_step_rate = 60;
74 bool enable_vsync =
false;
77 std::vector<Path> search_paths;
80 std::vector<unicode> arguments;
82 smlt::LogLevel log_level = smlt::LOG_LEVEL_INFO;
85 bool show_cursor =
false;
87 std::string source_language_code = DEFAULT_LANGUAGE_CODE;
90 uint32_t stage_node_pool_size = 64;
107 bool enable_virtual_screen =
false;
108 ScreenFormat virtual_screen_format = SCREEN_FORMAT_G1;
109 uint16_t virtual_screen_width = 48;
110 uint16_t virtual_screen_height = 32;
111 uint16_t virtual_screen_integer_scale = 1;
121 #ifdef SIMULANT_PROFILE
122 bool force_profiling =
true;
124 bool force_profiling =
false;
130 std::string force_renderer =
"";
131 std::string force_sound_driver =
"";
135 std::string log_file =
"";
139 bool additional_memory_logging =
true;
146 typedef std::shared_ptr<Loader> LoaderPtr;
147 typedef std::shared_ptr<LoaderType> LoaderTypePtr;
178 bool profiling_enabled()
const;
183 int32_t run(
int argc,
char* argv[]);
185 bool initialized()
const {
return initialized_; }
192 smlt::thread::ThreadID
thread_id()
const;
215 void start_coroutine(std::function<
void ()> func);
216 void update_coroutines();
217 void stop_all_coroutines();
228 LoaderPtr loader_for(
const Path &filename, LoaderHint hint=LOADER_HINT_NONE);
229 LoaderPtr loader_for(
const std::string& loader_name,
const Path& filename);
230 LoaderTypePtr loader_type(
const std::string& loader_name)
const;
232 void register_loader(LoaderTypePtr loader_type);
251 return active_language_;
261 auto it = active_translations_.find(source_text);
262 if(it == active_translations_.end()) {
269 void* platform_state() {
270 return platform_state_;
276 virtual std::shared_ptr<Window> instantiate_window();
279 void* platform_state_ =
nullptr;
280 friend void cr_run_main(std::function<
void ()> func);
281 std::function<void ()> cr_synced_function_;
283 void run_coroutines_and_late_update();
285 thread::ThreadID main_thread_id_;
286 bool has_shutdown_ =
false;
288 std::shared_ptr<Window> window_;
289 std::shared_ptr<SceneManager> scene_manager_;
290 std::shared_ptr<SharedAssetManager> asset_manager_;
291 std::shared_ptr<TimeKeeper> time_keeper_;
292 std::shared_ptr<StatsRecorder> stats_;
293 std::shared_ptr<VirtualFileSystem> vfs_;
294 std::shared_ptr<SoundDriver> sound_driver_;
295 std::shared_ptr<MaterialValuePool> pool_;
296 std::vector<LoaderTypePtr> loaders_;
298 bool initialized_ =
false;
299 bool is_running_ =
true;
301 float frame_counter_time_ = 0.0f;
302 int32_t frame_counter_frames_ = 0;
303 float frame_time_in_milliseconds_ = 0.0f;
305 void _call_fixed_update(
float dt) {
309 void _call_clean_up();
311 void _call_update(
float dt) {
315 void _call_late_update(
float dt) {
319 virtual bool init() = 0;
329 virtual bool pre_init() {
return true; }
331 virtual void fixed_update(
float dt) {
335 virtual void update(
float dt) {
339 virtual void late_update(
float dt) {
343 virtual void clean_up() {}
345 generic::DataCarrier data_carrier_;
349 bool construct_window(
const AppConfig& config);
353 void await_frame_time();
354 uint64_t last_frame_time_us_ = 0;
355 float requested_frame_time_ms_ = 0;
357 std::list<cort::CoroutineID> coroutines_;
358 void preload_default_font();
360 std::string active_language_ = DEFAULT_LANGUAGE_CODE;
361 std::map<unicode, unicode> active_translations_;
363 std::shared_ptr<Scene> overlay_scene_;
365 S_DEFINE_PROPERTY(window, &Application::window_);
366 S_DEFINE_PROPERTY(data, &Application::data_carrier_);
367 S_DEFINE_PROPERTY(scenes, &Application::scene_manager_);
368 S_DEFINE_PROPERTY(args, &Application::args_);
369 S_DEFINE_PROPERTY(config, &Application::config_);
370 S_DEFINE_PROPERTY(shared_assets, &Application::asset_manager_);
371 S_DEFINE_PROPERTY(time_keeper, &Application::time_keeper_);
372 S_DEFINE_PROPERTY(stats, &Application::stats_);
373 S_DEFINE_PROPERTY(vfs, &Application::vfs_);
374 S_DEFINE_PROPERTY(sound_driver, &Application::sound_driver_);
375 S_DEFINE_PROPERTY(material_value_pool, &Application::pool_);
388 std::vector<std::string> generate_potential_codes(
const std::string& language_code);
389 bool load_arb(std::shared_ptr<std::istream> stream, std::string* language_code =
nullptr);
390 bool load_arb_from_file(
const smlt::Path& filename);
397 void on_render_context_created();
399 void on_render_context_destroyed();
407 smlt::get_app()->translated_text((text))
409 #endif // APPLICATION_H