00001 #ifndef GSGL_FRAMEWORK_APPLICATION_H
00002 #define GSGL_FRAMEWORK_APPLICATION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "framework/framework.hpp"
00038 #include "framework/package.hpp"
00039 #include "framework/widget.hpp"
00040
00041 #include "data/singleton.hpp"
00042 #include "data/list.hpp"
00043 #include "data/string.hpp"
00044 #include "data/config.hpp"
00045 #include "data/stack.hpp"
00046
00047
00048 union SDL_Event;
00049
00050 namespace gsgl
00051 {
00052
00053 namespace data
00054 {
00055 class log;
00056 class broker;
00057 }
00058
00059
00060 namespace platform
00061 {
00062 class budget;
00063 class display;
00064 class texture;
00065
00066 template <typename T>
00067 class synchronized;
00068 }
00069
00070
00071 namespace scenegraph
00072 {
00073 class event_map;
00074 class context;
00075 class simulation;
00076 class node;
00077 }
00078
00079
00080 namespace framework
00081 {
00082
00083
00084 class FRAMEWORK_API application
00085 : public framework_object, public gsgl::data::singleton<application>
00086 {
00087 data::list<gsgl::data_object *> global_caches;
00088
00089 protected:
00090 enum app_state
00091 {
00092 APP_NO_STATE = 0,
00093 APP_INITIALIZING,
00094 APP_UI_RUNNING,
00095 APP_SIM_LOADING,
00096 APP_SIM_RUNNING,
00097 APP_QUITTING,
00098 APP_DEAD
00099 };
00100
00101 app_state state;
00102
00103 gsgl::string title;
00104
00105
00106 data::list<package *> loaded_packages;
00107 platform::texture *splash_screen;
00108
00109
00110 data::simple_stack<widget *> widgets;
00111 widget *focus_widget;
00112
00113
00114 scenegraph::context *global_context;
00115 scenegraph::node *global_scenery;
00116 scenegraph::simulation *global_simulation;
00117
00118 platform::display *global_console;
00119 scenegraph::event_map *global_mapper;
00120
00121 platform::budget *global_budget;
00122
00123 public:
00124
00125 application(const string & title, const int & argc, const char **argv);
00126 virtual ~application();
00127
00128
00129
00130
00131 static data::config_variable<gsgl::string> PROGRAM_PATH;
00132 static data::config_variable<gsgl::string> SYS_DATA_PATH;
00133 static data::config_variable<gsgl::string> USER_DATA_PATH;
00134 static data::config_variable<gsgl::string> EVENT_MAP_PATH;
00135 static data::config_variable<gsgl::string> USER_CONFIG_PATH;
00136
00137
00138
00139
00140
00141
00142 string & get_title() { return title; }
00143
00144 scenegraph::node *get_global_scenery() { return global_scenery; }
00145 platform::display *get_console() { return global_console; }
00146 scenegraph::simulation *get_simulation() { return global_simulation; }
00147 platform::budget *get_global_budget() { return global_budget; }
00148
00149 data::simple_stack<widget *> & get_widgets() { return widgets; }
00150 widget *get_focus_widget() { return focus_widget; }
00151
00152 void get_mousedown_info(int & button, int & x, int & y);
00153
00154
00155
00156
00157
00158
00159 void load_package(const string & fname);
00160 const gsgl::data::list<package *> & get_loaded_packages() const { return loaded_packages; }
00161
00162 void load_scenery(platform::synchronized<string> & status_string);
00163 void unload_scenery();
00164
00165 void load_and_run_simulation(const string & fname, gsgl::scenegraph::context *c);
00166 void unload_and_quit_simulation();
00167 void quit_application();
00168
00169
00170 void run();
00171
00172
00173
00174
00175
00176
00177 virtual void init();
00178 virtual bool draw();
00179 virtual void update();
00180 virtual void cleanup();
00181
00182 virtual bool handle_event(const SDL_Event & e);
00183
00184
00185 private:
00186 void get_config_overrides(const int & argc, const char **argv);
00187 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);
00188 gsgl::string get_program_dir(const gsgl::string & arg);
00189 gsgl::string get_user_dir();
00190
00191
00192 scenegraph::node *load_objects(const data::config_record & obj_config, platform::synchronized<string> & status_string);
00193 void remove_viewpoint_nodes(scenegraph::node *);
00194
00195
00196 void draw_splash_screen();
00197 void draw_ui(framework::widget *);
00198 void draw_budget(unsigned int ticks);
00199
00200
00201 int mouse_button_pressed;
00202 int mouse_button_x, mouse_button_y;
00203
00204 bool handle_ui_event(const SDL_Event & e, widget *w);
00205 bool handle_ui_event(const SDL_Event & e, widget *w, int mouse_x, int mouse_y);
00206 };
00207
00208 }
00209
00210 }
00211
00212 #endif