#include <application.hpp>
Definition at line 84 of file application.hpp.
Public Member Functions | |
application (const string &title, const int &argc, const char **argv) | |
Creates the global application object. | |
virtual | ~application () |
Virtual Functions | |
virtual void | cleanup () |
This function when the application ends. Do not call it yourself. | |
virtual bool | draw () |
This function is called for every frame. Do not call it yourself. If it returns false and the sim pointer is valid, the sim's draw function is called. | |
virtual bool | handle_event (const SDL_Event &e) |
Handles SDL events. | |
virtual void | init () |
This function is called by the constructor. Do not call it yourself. | |
virtual void | update () |
This function is called after every frame. Do not call it yourself. | |
Accessors | |
platform::display * | get_console () |
widget * | get_focus_widget () |
Return the widget with the current keyboard focus. | |
platform::budget * | get_global_budget () |
scenegraph::node * | get_global_scenery () |
void | get_mousedown_info (int &button, int &x, int &y) |
scenegraph::simulation * | get_simulation () |
string & | get_title () |
data::simple_stack< widget * > & | get_widgets () |
Game Lifecycle Functions | |
const gsgl::data::list < package * > & | get_loaded_packages () const |
void | load_and_run_simulation (const string &fname, gsgl::scenegraph::context *c) |
Loads and runs a simulation. This will set the top widget to be invisible. | |
void | load_package (const string &fname) |
Load a game package containing specifications for shared libraries, scenery, and vehicles. | |
void | load_scenery (platform::synchronized< string > &status_string) |
void | quit_application () |
Quits the application. Unloads and quits any simulation loaded. | |
void | run () |
void | unload_and_quit_simulation () |
Unloads and quits a simulation. This will set the top widget to be visible, so make sure that any extra widgets have been popped off the stack. | |
void | unload_scenery () |
Static Public Member Functions | |
static T * | global_instance () |
Static Public Attributes | |
System Configuration Variables | |
static data::config_variable < gsgl::string > | EVENT_MAP_PATH |
The program's event map. | |
static data::config_variable < gsgl::string > | PROGRAM_PATH |
The path that the program is running in. | |
static data::config_variable < gsgl::string > | SYS_DATA_PATH |
The directory of the system data. | |
static data::config_variable < gsgl::string > | USER_CONFIG_PATH |
The program's user config file. | |
static data::config_variable < gsgl::string > | USER_DATA_PATH |
The user's data directory. | |
Protected Types | |
enum | app_state { APP_NO_STATE = 0, APP_INITIALIZING, APP_UI_RUNNING, APP_SIM_LOADING, APP_SIM_RUNNING, APP_QUITTING, APP_DEAD } |
Protected Attributes | |
widget * | focus_widget |
platform::budget * | global_budget |
platform::display * | global_console |
scenegraph::context * | global_context |
scenegraph::event_map * | global_mapper |
scenegraph::node * | global_scenery |
scenegraph::simulation * | global_simulation |
data::list< package * > | loaded_packages |
platform::texture * | splash_screen |
app_state | state |
gsgl::string | title |
data::simple_stack< widget * > | widgets |
Private Member Functions | |
void | draw_budget (unsigned int ticks) |
void | draw_splash_screen () |
void | draw_ui (framework::widget *) |
bool | get_cmdline_dir (const int &argc, const char **argv, const int &pos, const gsgl::string &arg_key, gsgl::data::config_record &conf, const gsgl::string &conf_key) |
void | get_config_overrides (const int &argc, const char **argv) |
gsgl::string | get_program_dir (const gsgl::string &arg) |
gsgl::string | get_user_dir () |
bool | handle_ui_event (const SDL_Event &e, widget *w, int mouse_x, int mouse_y) |
bool | handle_ui_event (const SDL_Event &e, widget *w) |
scenegraph::node * | load_objects (const data::config_record &obj_config, platform::synchronized< string > &status_string) |
void | remove_viewpoint_nodes (scenegraph::node *) |
Private Attributes | |
data::list< gsgl::data_object * > | global_caches |
int | mouse_button_pressed |
int | mouse_button_x |
int | mouse_button_y |
enum app_state [protected] |
APP_NO_STATE | |
APP_INITIALIZING | |
APP_UI_RUNNING | |
APP_SIM_LOADING | |
APP_SIM_RUNNING | |
APP_QUITTING | |
APP_DEAD |
Definition at line 90 of file application.hpp.
application | ( | const string & | title, | |
const int & | argc, | |||
const char ** | argv | |||
) |
Creates the global application object.
This will also create the global application broker, event map and console objects. It will parse the command line to determine the correct system and user data directories.
Definition at line 98 of file application.cpp.
References list::append(), string::c_string(), font::create_global_font_cache(), material::create_global_material_cache(), model::create_global_model_cache(), texture::create_global_texture_cache(), display::DISPLAY_HEIGHT, display::DISPLAY_WIDTH, application::EVENT_MAP_PATH, file::exists(), config_record::get_children(), global_config::get_config(), application::get_config_overrides(), exception::get_message(), application::global_budget, application::global_caches, application::global_console, application::global_mapper, countable::is_empty(), application::load_package(), application::splash_screen, application::SYS_DATA_PATH, and gsgl::platform::TEXTURE_ENV_REPLACE.
~application | ( | ) | [virtual] |
Definition at line 171 of file application.cpp.
References list::clear(), application::focus_widget, application::global_budget, application::global_caches, application::global_console, application::global_context, application::global_mapper, application::global_scenery, application::global_simulation, iterable::iter(), application::splash_screen, and application::widgets.
void cleanup | ( | ) | [virtual] |
This function when the application ends. Do not call it yourself.
Implement this if cleanup is needed after the main loop terminates.
Definition at line 613 of file application.cpp.
Referenced by application::quit_application().
bool draw | ( | ) | [virtual] |
This function is called for every frame. Do not call it yourself. If it returns false and the sim pointer is valid, the sim's draw function is called.
Implement this to draw the simulation in a custom manner.
If this is not implemented or returns false, the sim will be updated and drawn automatically.
Definition at line 601 of file application.cpp.
Referenced by application::run().
void draw_budget | ( | unsigned int | ticks | ) | [private] |
Definition at line 485 of file application.cpp.
References font::calc_width(), display::draw_2d_text(), display::draw_text_start(), display::draw_text_stop(), string::format(), budget::get_data(), application::global_budget, application::global_console, and color::set().
Referenced by application::run().
void draw_splash_screen | ( | ) | [private] |
Definition at line 454 of file application.cpp.
References texture::bind(), CHECK_GL_ERRORS, display::draw_rectangle(), display::get_height(), display::get_width(), application::global_console, and application::splash_screen.
Referenced by application::run().
void draw_ui | ( | framework::widget * | w | ) | [private] |
Definition at line 557 of file application.cpp.
References assert, widget::draw(), widget::get_children(), widget::get_flags(), widget::get_x(), widget::get_y(), and widget::WIDGET_INVISIBLE.
Referenced by application::run().
bool get_cmdline_dir | ( | const int & | argc, | |
const char ** | argv, | |||
const int & | pos, | |||
const gsgl::string & | arg_key, | |||
gsgl::data::config_record & | conf, | |||
const gsgl::string & | conf_key | |||
) | [private] |
Definition at line 652 of file application.cpp.
References config_record::get_child(), directory::get_full_path(), config_record::get_text(), and string::w_string().
Referenced by application::get_config_overrides().
void get_config_overrides | ( | const int & | argc, | |
const char ** | argv | |||
) | [private] |
Definition at line 675 of file application.cpp.
References file::copy(), directory::create(), application::EVENT_MAP_PATH, file::exists(), directory::exists(), config_record::get_child(), application::get_cmdline_dir(), global_config::get_config(), config_record::get_name(), application::get_program_dir(), config_record::get_text(), application::get_user_dir(), config_variable::get_value(), countable::is_empty(), global_config::override_with(), global_config::save(), application::SYS_DATA_PATH, application::title, application::USER_CONFIG_PATH, application::USER_DATA_PATH, and string::w_string().
Referenced by application::application().
platform::display* get_console | ( | ) | [inline] |
widget* get_focus_widget | ( | ) | [inline] |
platform::budget* get_global_budget | ( | ) | [inline] |
Definition at line 147 of file application.hpp.
scenegraph::node* get_global_scenery | ( | ) | [inline] |
Definition at line 144 of file application.hpp.
const gsgl::data::list<package *>& get_loaded_packages | ( | ) | const [inline] |
Definition at line 160 of file application.hpp.
void get_mousedown_info | ( | int & | button, | |
int & | x, | |||
int & | y | |||
) |
Definition at line 945 of file application.cpp.
References application::mouse_button_pressed, application::mouse_button_x, and application::mouse_button_y.
string get_program_dir | ( | const gsgl::string & | arg | ) | [private] |
Definition at line 973 of file application.cpp.
References string::find_reverse(), directory::get_full_path(), and string::substring().
Referenced by application::get_config_overrides().
scenegraph::simulation* get_simulation | ( | ) | [inline] |
Definition at line 146 of file application.hpp.
string& get_title | ( | ) | [inline] |
string get_user_dir | ( | ) | [private] |
Definition at line 993 of file application.cpp.
References directory::get_full_path(), directory::SEPARATOR, and application::title.
Referenced by application::get_config_overrides().
data::simple_stack<widget *>& get_widgets | ( | ) | [inline] |
Definition at line 149 of file application.hpp.
static T* global_instance | ( | ) | [inline, static, inherited] |
Reimplemented in broker, global_register, logger, global_register< gsgl::data::broker_creator, gsgl::data::dictionary< gsgl::data::broker_creator *, gsgl::string > >, global_register< gsgl::data::log_target, gsgl::data::list< gsgl::data::log_target * > >, and global_register< gsgl::data::log_target >.
Definition at line 70 of file singleton.hpp.
Referenced by widget::button_down_here(), font::font(), tabbox::handle_event(), material::material(), model_part::model_part(), and texture::texture().
bool handle_event | ( | const SDL_Event & | e | ) | [virtual] |
Handles SDL events.
Implement this to handle SDL events other than through the default scene graph event handler.
Does not normally need to be reimplemented, as UI elements and scenegraph events will propagate by default.
If it returns true, the scene graph event handler will NOT be called. If it returns false, and the current simulation pointer is valid, then the event mapper will be called with the simulation's set event targets.
Definition at line 587 of file application.cpp.
Referenced by application::run().
bool handle_ui_event | ( | const SDL_Event & | e, | |
widget * | w, | |||
int | mouse_x, | |||
int | mouse_y | |||
) | [private] |
Definition at line 914 of file application.cpp.
References assert, widget::get_children(), widget::get_event_handler(), widget::get_flags(), widget::get_h(), widget::get_w(), widget::get_x(), widget::get_y(), widget::handle_event(), application::handle_ui_event(), widget::WIDGET_INACTIVE, and widget::WIDGET_INVISIBLE.
bool handle_ui_event | ( | const SDL_Event & | e, | |
widget * | w | |||
) | [private] |
Definition at line 899 of file application.cpp.
References assert, display::get_height(), application::global_console, application::mouse_button_pressed, application::mouse_button_x, application::mouse_button_y, and widget::x.
Referenced by application::handle_ui_event(), and application::run().
void init | ( | ) | [virtual] |
This function is called by the constructor. Do not call it yourself.
Implement this if initialization is needed prior to the main loop.
Reimplemented in periapsis_app.
Definition at line 594 of file application.cpp.
Referenced by application::run().
void load_and_run_simulation | ( | const string & | fname, | |
gsgl::scenegraph::context * | c | |||
) |
Loads and runs a simulation. This will set the top widget to be invisible.
Definition at line 216 of file application.cpp.
References application::APP_SIM_LOADING, application::APP_SIM_RUNNING, assert, application::global_console, application::global_context, application::global_scenery, application::global_simulation, simulation::init(), gsgl::log(), application::state, application::unload_and_quit_simulation(), widget::WIDGET_INVISIBLE, and application::widgets.
node * load_objects | ( | const data::config_record & | obj_config, | |
platform::synchronized< string > & | status_string | |||
) | [private] |
Definition at line 751 of file application.cpp.
References node::add_child(), assert, broker::create_object(), string::format(), config_record::get_children(), config_record::get_file(), file::get_full_path(), config_record::get_name(), broker::global_instance(), broker::has_object(), and string::w_string().
Referenced by application::load_scenery().
void load_package | ( | const string & | fname | ) |
Load a game package containing specifications for shared libraries, scenery, and vehicles.
Definition at line 204 of file application.cpp.
References application::loaded_packages, and string::w_string().
Referenced by application::application().
void load_scenery | ( | platform::synchronized< string > & | status_string | ) |
Definition at line 792 of file application.cpp.
References node::add_child(), list::append(), list::clear(), node::get_children(), config_record::get_children(), config_record::get_name(), application::global_scenery, countable::is_empty(), iterable::iter(), application::load_objects(), application::loaded_packages, list::size(), and string::w_string().
void quit_application | ( | ) |
Quits the application. Unloads and quits any simulation loaded.
This contains the main event loop of the application. It clears the screen, calls draw(), draws UI elements, and flips the buffers.
Definition at line 276 of file application.cpp.
References application::APP_QUITTING, application::cleanup(), application::global_simulation, application::state, and application::unload_and_quit_simulation().
Referenced by application::run().
void remove_viewpoint_nodes | ( | scenegraph::node * | n | ) | [private] |
Definition at line 620 of file application.cpp.
References list::append(), node::get_children(), and iterable::iter().
Referenced by application::unload_and_quit_simulation().
void run | ( | ) |
Definition at line 286 of file application.cpp.
References application::APP_DEAD, application::APP_INITIALIZING, application::APP_NO_STATE, application::APP_QUITTING, application::APP_SIM_RUNNING, application::APP_UI_RUNNING, CHECK_GL_ERRORS, simulation::draw(), application::draw(), application::draw_budget(), application::draw_splash_screen(), application::draw_ui(), simulation::get_context(), display::get_height(), display::get_width(), application::global_budget, application::global_console, application::global_mapper, application::global_simulation, event_map::handle_event(), application::handle_event(), application::handle_ui_event(), application::init(), simulation::is_running(), simulation::pre_draw(), application::quit_application(), context::render_flags, context::RENDER_UNLIT, context::RENDER_UNTEXTURED, context::RENDER_WIREFRAME, budget::reset(), application::splash_screen, application::state, application::unload_and_quit_simulation(), application::update(), simulation::update(), widget::WIDGET_INVISIBLE, and application::widgets.
Referenced by SDL_main().
void unload_and_quit_simulation | ( | ) |
Unloads and quits a simulation. This will set the top widget to be visible, so make sure that any extra widgets have been popped off the stack.
Definition at line 241 of file application.cpp.
References application::APP_UI_RUNNING, simulation::cleanup(), application::global_context, application::global_scenery, application::global_simulation, gsgl::log(), application::remove_viewpoint_nodes(), application::state, widget::WIDGET_INVISIBLE, and application::widgets.
Referenced by application::load_and_run_simulation(), application::quit_application(), and application::run().
void unload_scenery | ( | ) |
void update | ( | ) | [virtual] |
This function is called after every frame. Do not call it yourself.
Reimplemented in periapsis_app.
Definition at line 607 of file application.cpp.
Referenced by application::run().
config_variable< string > EVENT_MAP_PATH [static] |
The program's event map.
Definition at line 134 of file application.hpp.
Referenced by application::application(), and application::get_config_overrides().
widget* focus_widget [protected] |
platform::budget* global_budget [protected] |
Definition at line 121 of file application.hpp.
Referenced by application::application(), application::draw_budget(), application::run(), and application::~application().
data::list<gsgl::data_object *> global_caches [private] |
Definition at line 87 of file application.hpp.
Referenced by application::application(), and application::~application().
platform::display* global_console [protected] |
Definition at line 118 of file application.hpp.
Referenced by application::application(), application::draw_budget(), application::draw_splash_screen(), application::handle_ui_event(), application::load_and_run_simulation(), application::run(), and application::~application().
scenegraph::context* global_context [protected] |
Definition at line 114 of file application.hpp.
Referenced by application::load_and_run_simulation(), application::unload_and_quit_simulation(), and application::~application().
scenegraph::event_map* global_mapper [protected] |
Definition at line 119 of file application.hpp.
Referenced by application::application(), application::run(), and application::~application().
scenegraph::node* global_scenery [protected] |
Definition at line 115 of file application.hpp.
Referenced by application::load_and_run_simulation(), application::load_scenery(), application::unload_and_quit_simulation(), application::unload_scenery(), and application::~application().
scenegraph::simulation* global_simulation [protected] |
Definition at line 116 of file application.hpp.
Referenced by application::load_and_run_simulation(), application::quit_application(), application::run(), application::unload_and_quit_simulation(), and application::~application().
data::list<package *> loaded_packages [protected] |
Definition at line 106 of file application.hpp.
Referenced by application::load_package(), and application::load_scenery().
int mouse_button_pressed [private] |
Definition at line 201 of file application.hpp.
Referenced by application::get_mousedown_info(), and application::handle_ui_event().
int mouse_button_x [private] |
Definition at line 202 of file application.hpp.
Referenced by application::get_mousedown_info(), and application::handle_ui_event().
int mouse_button_y [private] |
Definition at line 202 of file application.hpp.
Referenced by application::get_mousedown_info(), and application::handle_ui_event().
config_variable< string > PROGRAM_PATH [static] |
The path that the program is running in.
Definition at line 131 of file application.hpp.
Referenced by package::package().
platform::texture* splash_screen [protected] |
Definition at line 107 of file application.hpp.
Referenced by application::application(), application::draw_splash_screen(), application::run(), and application::~application().
Definition at line 101 of file application.hpp.
Referenced by application::load_and_run_simulation(), application::quit_application(), application::run(), and application::unload_and_quit_simulation().
config_variable< string > SYS_DATA_PATH [static] |
The directory of the system data.
Definition at line 132 of file application.hpp.
Referenced by application::application(), application::get_config_overrides(), lithosphere_quadtree::lithosphere_quadtree(), and stellar_db::stellar_db().
gsgl::string title [protected] |
Definition at line 103 of file application.hpp.
Referenced by application::get_config_overrides(), and application::get_user_dir().
config_variable< string > USER_CONFIG_PATH [static] |
The program's user config file.
Definition at line 135 of file application.hpp.
Referenced by application::get_config_overrides().
config_variable< string > USER_DATA_PATH [static] |
The user's data directory.
Definition at line 133 of file application.hpp.
Referenced by application::get_config_overrides().
data::simple_stack<widget *> widgets [protected] |
Definition at line 110 of file application.hpp.
Referenced by periapsis_app::init(), application::load_and_run_simulation(), application::run(), application::unload_and_quit_simulation(), and application::~application().