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