Panda3D
 All Classes Functions Variables Enumerations
pandaFramework.h
1 // Filename: pandaFramework.h
2 // Created by: drose (02Apr02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PANDAFRAMEWORK_H
16 #define PANDAFRAMEWORK_H
17 
18 #include "pandabase.h"
19 #include "config_framework.h"
20 
21 #include "windowFramework.h"
22 
23 #include "nodePath.h"
24 #include "eventHandler.h"
25 #include "graphicsPipe.h"
26 #include "graphicsEngine.h"
27 #include "graphicsWindow.h"
28 #include "recorderController.h"
29 #include "pointerTo.h"
30 #include "asyncTaskManager.h"
31 #include "genericAsyncTask.h"
32 
33 #include "pvector.h"
34 
35 ////////////////////////////////////////////////////////////////////
36 // Class : PandaFramework
37 // Description : This class serves to provide a high-level framework
38 // for basic applications that use Panda in simple ways
39 // (like opening a window to view models, etc.).
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_FRAMEWORK PandaFramework {
42 public:
44  virtual ~PandaFramework();
45 
46  void open_framework(int &argc, char **&argv);
47  void close_framework();
48 
49  GraphicsPipe *get_default_pipe();
50  INLINE GraphicsEngine *get_graphics_engine();
51  INLINE const NodePath &get_data_root() const;
52  INLINE EventHandler &get_event_handler();
53  INLINE AsyncTaskManager &get_task_mgr();
54  NodePath get_mouse(GraphicsOutput *window);
55  void remove_mouse(const GraphicsOutput *window);
56 
57  void define_key(const string &event_name,
58  const string &description,
59  EventHandler::EventCallbackFunction *function,
60  void *data);
61 
62  INLINE void set_window_title(const string &title);
63  virtual void get_default_window_props(WindowProperties &props);
64 
65  WindowFramework *open_window();
66  WindowFramework *open_window(GraphicsPipe *pipe,
67  GraphicsStateGuardian *gsg = NULL);
68  WindowFramework *open_window(const WindowProperties &props, int flags,
69  GraphicsPipe *pipe = NULL,
70  GraphicsStateGuardian *gsg = NULL);
71 
72  INLINE int get_num_windows() const;
73  INLINE WindowFramework *get_window(int n) const;
74  int find_window(const GraphicsOutput *win) const;
75  int find_window(const WindowFramework *wf) const;
76  void close_window(int n);
77  INLINE void close_window(WindowFramework *wf);
78  void close_all_windows();
79  bool all_windows_closed() const;
80 
81  NodePath &get_models();
82 
83  void report_frame_rate(ostream &out) const;
84  void reset_frame_rate();
85 
86  void set_wireframe(bool enable);
87  void set_texture(bool enable);
88  void set_two_sided(bool enable);
89  void set_lighting(bool enable);
90  void set_perpixel(bool enable);
91  void set_background_type(WindowFramework::BackgroundType type);
92 
93  INLINE bool get_wireframe() const;
94  INLINE bool get_texture() const;
95  INLINE bool get_two_sided() const;
96  INLINE bool get_lighting() const;
97  INLINE bool get_perpixel() const;
98  INLINE WindowFramework::BackgroundType get_background_type() const;
99 
100  static int hide_collision_solids(NodePath node);
101  static int show_collision_solids(NodePath node);
102 
103  void set_highlight(const NodePath &node);
104  void clear_highlight();
105  INLINE bool has_highlight() const;
106  INLINE const NodePath &get_highlight() const;
107 
108  INLINE RecorderController *get_recorder() const;
109  INLINE void set_recorder(RecorderController *recorder);
110 
111  void enable_default_keys();
112 
113  virtual bool do_frame(Thread *current_thread);
114  void main_loop();
115 
116  INLINE void set_exit_flag();
117  INLINE void clear_exit_flag();
118 
119 public:
120  static LoaderOptions _loader_options;
121 
122 protected:
123  virtual PT(WindowFramework) make_window_framework();
124  virtual void make_default_pipe();
125  virtual void do_enable_default_keys();
126  bool clear_text();
127 
128 public:
129  static void event_esc(const Event *, void *data);
130  static void event_f(const Event *, void *data);
131  static void event_w(const Event *, void *data);
132  static void event_t(const Event *, void *data);
133  static void event_b(const Event *, void *data);
134  static void event_i(const Event *, void *data);
135  static void event_l(const Event *, void *data);
136  static void event_p(const Event *, void *data);
137  static void event_c(const Event *, void *data);
138  static void event_a(const Event *, void *data);
139  static void event_C(const Event *, void *data);
140  static void event_B(const Event *, void *data);
141  static void event_L(const Event *, void *data);
142  static void event_A(const Event *, void *data);
143  static void event_h(const Event *, void *data);
144  static void event_arrow_up(const Event *, void *data);
145  static void event_arrow_down(const Event *, void *data);
146  static void event_arrow_left(const Event *, void *data);
147  static void event_arrow_right(const Event *, void *data);
148  static void event_S(const Event *, void *data);
149  static void event_f9(const Event *, void *data);
150  static void event_comma(const Event *, void *data);
151  static void event_question(const Event * event, void *data);
152  static void event_window_event(const Event *, void *data);
153 
154 
155  static AsyncTask::DoneStatus task_data_loop(GenericAsyncTask *task, void *data);
156  static AsyncTask::DoneStatus task_event(GenericAsyncTask *task, void *data);
157  static AsyncTask::DoneStatus task_clear_screenshot_text(GenericAsyncTask *task, void *data);
158  static AsyncTask::DoneStatus task_igloop(GenericAsyncTask *task, void *data);
159  static AsyncTask::DoneStatus task_record_frame(GenericAsyncTask *task, void *data);
160  static AsyncTask::DoneStatus task_play_frame(GenericAsyncTask *task, void *data);
161 
162  static AsyncTask::DoneStatus task_clear_text(GenericAsyncTask *task, void *data);
163  static AsyncTask::DoneStatus task_garbage_collect(GenericAsyncTask *task, void *data);
164 
165 private:
166  bool _is_open;
167  bool _made_default_pipe;
168 
169  string _window_title;
170 
171  PT(GraphicsPipe) _default_pipe;
172  PT(GraphicsEngine) _engine;
173 
174  NodePath _data_root;
175  EventHandler &_event_handler;
176  AsyncTaskManager &_task_mgr;
177 
179  Windows _windows;
180 
182  Mouses _mouses;
183 
184  NodePath _models;
185 
186  // For counting frame rate.
187  double _start_time;
188  int _frame_count;
189 
190  bool _wireframe_enabled;
191  bool _texture_enabled;
192  bool _two_sided_enabled;
193  bool _lighting_enabled;
194  bool _perpixel_enabled;
195  WindowFramework::BackgroundType _background_type;
196 
197  NodePath _highlight;
198  NodePath _highlight_wireframe;
199 
200  bool _default_keys_enabled;
201 
202  bool _exit_flag;
203 
204  class KeyDefinition {
205  public:
206  string _event_name;
207  string _description;
208  };
210  KeyDefinitions _key_definitions;
211 
212  NodePath _help_text;
213  NodePath _screenshot_text;
214 
215  PT(RecorderController) _recorder;
216 
217  friend class WindowFramework;
218 };
219 
220 #include "pandaFramework.I"
221 
222 #endif
A class to monitor events from the C++ side of things.
Definition: eventHandler.h:41
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
This encapsulates the data that is normally associated with a single window, or with a single display...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
Associates a generic C-style function pointer with an AsyncTask object.
This is a base class for the various different classes that represent the result of a frame of render...
A thread; that is, a lightweight process.
Definition: thread.h:51
A named event, possibly with parameters.
Definition: event.h:36
Encapsulates all the communication with a particular instance of a given rendering backend...
This object manages the process of recording the user's runtime inputs to a bam file so that the sess...
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
This class is the main interface to controlling the render process.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165