Panda3D
Loading...
Searching...
No Matches
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 */
38class EXPCL_FRAMEWORK PandaFramework {
39public:
40 PandaFramework();
41 virtual ~PandaFramework();
42
43 void open_framework();
44 void open_framework(int &argc, char **&argv);
45 void close_framework();
46
49 INLINE const NodePath &get_data_root() const;
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
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
117public:
118 static LoaderOptions _loader_options;
119
120protected:
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
126public:
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
163private:
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 };
207 typedef pvector<KeyDefinition> KeyDefinitions;
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.
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
A class to monitor events from the C++ side of things.
A named event, possibly with parameters.
Definition event.h:33
Associates a generic C-style function pointer with an AsyncTask object.
This class is the main interface to controlling the render process.
This is a base class for the various different classes that represent the result of a frame of render...
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
Specifies parameters that may be passed to the loader.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
static int hide_collision_solids(NodePath node)
Hides any collision solids, or occluders, which are visible in the indicated scene graph.
bool get_perpixel() const
Returns the current state of the perpixel flag.
RecorderController * get_recorder() const
Returns the RecorderController that has been associated with the PandaFramework, if any,...
static void event_window_event(const Event *, void *data)
Default handler for window events: window resized or closed, etc.
void set_background_type(WindowFramework::BackgroundType type)
Sets the background type of all windows.
void close_window(int n)
Closes the nth window and removes it from the list.
void remove_mouse(const GraphicsOutput *window)
Removes the mouse that may have been created by an earlier call to get_mouse().
static AsyncTask::DoneStatus task_event(GenericAsyncTask *task, void *data)
Called once per frame to process the pending events.
const NodePath & get_data_root() const
Returns the root of the data graph.
int find_window(const GraphicsOutput *win) const
Returns the index of the first WindowFramework object found that references the indicated GraphicsOut...
bool get_texture() const
Returns the current state of the texture flag.
void clear_highlight()
Unhighlights the currently highlighted node, if any.
void set_recorder(RecorderController *recorder)
Assigns a RecorderController with the PandaFramework.
static void event_S(const Event *, void *data)
Default handler for shift-S key: activate stats.
void set_two_sided(bool enable)
Sets the two_sided state on all windows.
static void event_arrow_left(const Event *, void *data)
Default handler for up arrow key: in highlight mode, move the highlight to the node's nearest sibling...
static AsyncTask::DoneStatus task_record_frame(GenericAsyncTask *task, void *data)
Called once per frame to ask the recorder to record the user input data, if enabled.
GraphicsPipe * get_default_pipe()
Returns the default pipe.
void clear_exit_flag()
Resets the exit flag after it has previously been set.
static void event_arrow_right(const Event *, void *data)
Default handler for up arrow key: in highlight mode, move the highlight to the node's nearest sibling...
static void event_t(const Event *, void *data)
Default handler for t key: toggle texture.
WindowFramework * open_window()
Opens a window on the default graphics pipe.
static int show_collision_solids(NodePath node)
Shows any collision solids, or occluders, which are directly hidden in the indicated scene graph.
static void event_B(const Event *, void *data)
Default handler for shift-B key: describe the bounding volume of the currently selected object,...
void enable_default_keys()
Sets callbacks on the event handler to handle all of the normal viewer keys, like t to toggle texture...
static AsyncTask::DoneStatus task_data_loop(GenericAsyncTask *task, void *data)
Called once per frame to process the data graph (which handles user input via the mouse and keyboard,...
static void event_arrow_up(const Event *, void *data)
Default handler for up arrow key: in highlight mode, move the highlight to the node's parent.
static void event_L(const Event *, void *data)
Default handler for shift-L key: list the contents of the scene graph, or the highlighted node.
WindowFramework::BackgroundType get_background_type() const
Returns the current background type setting.
static AsyncTask::DoneStatus task_play_frame(GenericAsyncTask *task, void *data)
Called once per frame to ask the recorder to play back the user input data, if enabled.
void open_framework()
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
static void event_A(const Event *, void *data)
Default handler for shift-A key: analyze the contents of the scene graph, or the highlighted node.
void reset_frame_rate()
Resets the frame rate computation.
void set_exit_flag()
Sets the flag that indicates it is time for the application to exit.
static void event_f(const Event *, void *data)
Default handler for f key: report and reset frame rate.
const NodePath & get_highlight() const
Returns the currently highlighted node, if any, or an empty NodePath if no node is highlighted.
void report_frame_rate(std::ostream &out) const
Reports the currently measured average frame rate to the indicated ostream.
static AsyncTask::DoneStatus task_clear_text(GenericAsyncTask *task, void *data)
Called once to remove the screenshot text from onscreen.
void set_window_title(const std::string &title)
Specifies the title that is set for all subsequently created windows.
static void event_i(const Event *, void *data)
Default handler for i key: invert one-sided faces.
static void event_a(const Event *, void *data)
Default handler for a key: toggle the animation controls.
int get_num_windows() const
Returns the number of windows that are currently open.
WindowFramework * get_window(int n) const
Returns the nth window currently open.
static void event_esc(const Event *, void *data)
Default handler for ESC or q key: close the current window (and exit the application if that was the ...
void define_key(const std::string &event_name, const std::string &description, EventHandler::EventCallbackFunction *function, void *data)
Sets up a handler for the indicated key.
void set_wireframe(bool enable)
Sets the wireframe state on all windows.
static void event_f9(const Event *, void *data)
Default handler for f9 key: take screenshot.
GraphicsEngine * get_graphics_engine()
Returns the GraphicsEngine that is used to render all the windows in the framework.
static void event_question(const Event *event, void *data)
Default handler for ?
static void event_C(const Event *, void *data)
Default handler for shift-C key: toggle the showing of collision solids.
NodePath & get_models()
Returns the root of the scene graph normally reserved for parenting models and such.
void main_loop()
Called to yield control to the panda framework.
bool all_windows_closed() const
Returns true if all of the opened windows have been closed by the user, false otherwise.
static void event_h(const Event *, void *data)
Default handler for h key: toggle highlight mode.
virtual void get_default_window_props(WindowProperties &props)
Fills in the indicated window properties structure according to the normal window properties for this...
void set_texture(bool enable)
Sets the texture state on all windows.
static void event_comma(const Event *, void *data)
Default handler for comma key: rotate background color.
bool get_wireframe() const
Returns the current state of the wireframe flag.
void close_all_windows()
Closes all currently open windows and empties the list of windows.
static void event_w(const Event *, void *data)
Default handler for w key: toggle wireframe.
bool get_two_sided() const
Returns the current state of the two_sided flag.
static void event_p(const Event *, void *data)
Default handler for p key: toggle per-pixel lighting.
static void event_l(const Event *, void *data)
Default handler for l key: toggle lighting.
void set_lighting(bool enable)
Sets the lighting state on all windows.
static void event_b(const Event *, void *data)
Default handler for b key: toggle backface (two-sided rendering).
void set_perpixel(bool enable)
Sets the perpixel state on all windows.
NodePath get_mouse(GraphicsOutput *window)
Returns a NodePath to the MouseAndKeyboard associated with the indicated GraphicsWindow object.
void set_highlight(const NodePath &node)
Sets the indicated node (normally a node within the get_models() tree) up as the highlighted node.
EventHandler & get_event_handler()
Returns the EventHandler object that serves events in the framework.
static void event_arrow_down(const Event *, void *data)
Default handler for up arrow key: in highlight mode, move the highlight to the node's first child.
static void event_c(const Event *, void *data)
Default handler for c key: center the trackball over the scene, or over the highlighted part of the s...
static AsyncTask::DoneStatus task_garbage_collect(GenericAsyncTask *task, void *data)
This task is created automatically if garbage_collect_states is true.
void close_framework()
Should be called at the end of an application to close Panda.
AsyncTaskManager & get_task_mgr()
Returns the Task Manager object that manages tasks in the framework.
virtual bool do_frame(Thread *current_thread)
Renders one frame and performs all associated processing.
static AsyncTask::DoneStatus task_igloop(GenericAsyncTask *task, void *data)
Called once per frame to render the scene.
bool get_lighting() const
Returns the current state of the lighting flag.
bool has_highlight() const
Returns true if any node is highlighted, false otherwise.
This object manages the process of recording the user's runtime inputs to a bam file so that the sess...
A thread; that is, a lightweight process.
Definition thread.h:46
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.