00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PANDAFRAMEWORK_H
00016 #define PANDAFRAMEWORK_H
00017
00018 #include "pandabase.h"
00019
00020 #include "windowFramework.h"
00021
00022 #include "nodePath.h"
00023 #include "eventHandler.h"
00024 #include "graphicsPipe.h"
00025 #include "graphicsEngine.h"
00026 #include "graphicsWindow.h"
00027 #include "recorderController.h"
00028 #include "pointerTo.h"
00029 #include "asyncTaskManager.h"
00030 #include "genericAsyncTask.h"
00031
00032 #include "pvector.h"
00033
00034
00035
00036
00037
00038
00039
00040 class EXPCL_FRAMEWORK PandaFramework {
00041 public:
00042 PandaFramework();
00043 virtual ~PandaFramework();
00044
00045 void open_framework(int &argc, char **&argv);
00046 void close_framework();
00047
00048 GraphicsPipe *get_default_pipe();
00049 INLINE GraphicsEngine *get_graphics_engine();
00050 INLINE const NodePath &get_data_root() const;
00051 INLINE EventHandler &get_event_handler();
00052 INLINE AsyncTaskManager &get_task_mgr();
00053 NodePath get_mouse(GraphicsOutput *window);
00054 void remove_mouse(const GraphicsOutput *window);
00055
00056 void define_key(const string &event_name,
00057 const string &description,
00058 EventHandler::EventCallbackFunction *function,
00059 void *data);
00060
00061 INLINE void set_window_title(const string &title);
00062 virtual void get_default_window_props(WindowProperties &props);
00063
00064 WindowFramework *open_window();
00065 WindowFramework *open_window(GraphicsPipe *pipe,
00066 GraphicsStateGuardian *gsg = NULL);
00067 WindowFramework *open_window(const WindowProperties &props, int flags,
00068 GraphicsPipe *pipe = NULL,
00069 GraphicsStateGuardian *gsg = NULL);
00070
00071 INLINE int get_num_windows() const;
00072 INLINE WindowFramework *get_window(int n) const;
00073 int find_window(const GraphicsOutput *win) const;
00074 int find_window(const WindowFramework *wf) const;
00075 void close_window(int n);
00076 INLINE void close_window(WindowFramework *wf);
00077 void close_all_windows();
00078 bool all_windows_closed() const;
00079
00080 NodePath &get_models();
00081
00082 void report_frame_rate(ostream &out) const;
00083 void reset_frame_rate();
00084
00085 void set_wireframe(bool enable);
00086 void set_texture(bool enable);
00087 void set_two_sided(bool enable);
00088 void set_lighting(bool enable);
00089 void set_perpixel(bool enable);
00090 void set_background_type(WindowFramework::BackgroundType type);
00091
00092 INLINE bool get_wireframe() const;
00093 INLINE bool get_texture() const;
00094 INLINE bool get_two_sided() const;
00095 INLINE bool get_lighting() const;
00096 INLINE bool get_perpixel() const;
00097 INLINE WindowFramework::BackgroundType get_background_type() const;
00098
00099 static int hide_collision_solids(NodePath node);
00100 static int show_collision_solids(NodePath node);
00101
00102 void set_highlight(const NodePath &node);
00103 void clear_highlight();
00104 INLINE bool has_highlight() const;
00105 INLINE const NodePath &get_highlight() const;
00106
00107 INLINE RecorderController *get_recorder() const;
00108 INLINE void set_recorder(RecorderController *recorder);
00109
00110 void enable_default_keys();
00111
00112 virtual bool do_frame(Thread *current_thread);
00113 void main_loop();
00114
00115 INLINE void set_exit_flag();
00116 INLINE void clear_exit_flag();
00117
00118 public:
00119 static LoaderOptions _loader_options;
00120
00121 protected:
00122 virtual PT(WindowFramework) make_window_framework();
00123 virtual void make_default_pipe();
00124 virtual void do_enable_default_keys();
00125 bool clear_text();
00126
00127 public:
00128 static void event_esc(const Event *, void *data);
00129 static void event_f(const Event *, void *data);
00130 static void event_w(const Event *, void *data);
00131 static void event_t(const Event *, void *data);
00132 static void event_b(const Event *, void *data);
00133 static void event_i(const Event *, void *data);
00134 static void event_l(const Event *, void *data);
00135 static void event_p(const Event *, void *data);
00136 static void event_c(const Event *, void *data);
00137 static void event_a(const Event *, void *data);
00138 static void event_C(const Event *, void *data);
00139 static void event_B(const Event *, void *data);
00140 static void event_L(const Event *, void *data);
00141 static void event_A(const Event *, void *data);
00142 static void event_h(const Event *, void *data);
00143 static void event_arrow_up(const Event *, void *data);
00144 static void event_arrow_down(const Event *, void *data);
00145 static void event_arrow_left(const Event *, void *data);
00146 static void event_arrow_right(const Event *, void *data);
00147 static void event_S(const Event *, void *data);
00148 static void event_f9(const Event *, void *data);
00149 static void event_comma(const Event *, void *data);
00150 static void event_question(const Event * event, void *data);
00151 static void event_window_event(const Event *, void *data);
00152
00153
00154 static AsyncTask::DoneStatus task_data_loop(GenericAsyncTask *task, void *data);
00155 static AsyncTask::DoneStatus task_event(GenericAsyncTask *task, void *data);
00156 static AsyncTask::DoneStatus task_clear_screenshot_text(GenericAsyncTask *task, void *data);
00157 static AsyncTask::DoneStatus task_igloop(GenericAsyncTask *task, void *data);
00158 static AsyncTask::DoneStatus task_record_frame(GenericAsyncTask *task, void *data);
00159 static AsyncTask::DoneStatus task_play_frame(GenericAsyncTask *task, void *data);
00160
00161 static AsyncTask::DoneStatus task_clear_text(GenericAsyncTask *task, void *data);
00162 static AsyncTask::DoneStatus task_garbage_collect(GenericAsyncTask *task, void *data);
00163
00164 private:
00165 bool _is_open;
00166 bool _made_default_pipe;
00167
00168 string _window_title;
00169
00170 PT(GraphicsPipe) _default_pipe;
00171 PT(GraphicsEngine) _engine;
00172
00173 NodePath _data_root;
00174 EventHandler &_event_handler;
00175 AsyncTaskManager &_task_mgr;
00176
00177 typedef pvector< PT(WindowFramework) > Windows;
00178 Windows _windows;
00179
00180 typedef pmap< const GraphicsOutput *, NodePath > Mouses;
00181 Mouses _mouses;
00182
00183 NodePath _models;
00184
00185
00186 double _start_time;
00187 int _frame_count;
00188
00189 bool _wireframe_enabled;
00190 bool _texture_enabled;
00191 bool _two_sided_enabled;
00192 bool _lighting_enabled;
00193 bool _perpixel_enabled;
00194 WindowFramework::BackgroundType _background_type;
00195
00196 NodePath _highlight;
00197 NodePath _highlight_wireframe;
00198
00199 bool _default_keys_enabled;
00200
00201 bool _exit_flag;
00202
00203 class KeyDefinition {
00204 public:
00205 string _event_name;
00206 string _description;
00207 };
00208 typedef pvector<KeyDefinition> KeyDefinitions;
00209 KeyDefinitions _key_definitions;
00210
00211 NodePath _help_text;
00212 NodePath _screenshot_text;
00213
00214 PT(RecorderController) _recorder;
00215
00216 friend class WindowFramework;
00217 };
00218
00219 #include "pandaFramework.I"
00220
00221 #endif