From e3d04fd2483a0d1f501d71ddb3a4ff62e7dec9f7 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 13 Jan 2002 20:31:26 +0000 Subject: [PATCH] more multi-window support --- direct/src/gui/DirectWaitBar.py | 2 +- direct/src/showbase/ShowBase.py | 13 ++++++++- direct/src/showbase/showBase.cxx | 45 ++++++-------------------------- direct/src/showbase/showBase.h | 1 + 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/direct/src/gui/DirectWaitBar.py b/direct/src/gui/DirectWaitBar.py index 0ed3e96579..93c20120f2 100644 --- a/direct/src/gui/DirectWaitBar.py +++ b/direct/src/gui/DirectWaitBar.py @@ -77,7 +77,7 @@ class DirectWaitBar(DirectFrame): def update(self, value): self['value'] = value # finally update the window - base.win.update() + base.win.renderAndUpdate() def finish(self): # Fill the bar in N frames diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 320f410220..6a46e9d687 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -75,6 +75,8 @@ class ShowBase: # stores a CollisionTraverser pointer here, we'll traverse it # in the igloop task. self.cTrav = 0 + # Ditto for an AppTraverser. + self.appTrav = 0 # base.win is the main, or only window; base.winList is a list of # *all* windows. Similarly with base.pipeList and base.camList. @@ -513,10 +515,19 @@ class ShowBase: # CollisionTraverser set. if self.cTrav: self.cTrav.traverse(self.render) + if self.appTrav: + self.appTrav.traverse(self.render.getTopNode()) + # Finally, render the frame. for win in self.winList: - win.update() + win.renderAndUpdate() + + # The clock needs to be ticked once per frame. globalClock.tick() + + # Lerp stuff needs this event, and it must be generated in + # C++, not in Python. + throwNewFrame() return Task.cont def restart(self): diff --git a/direct/src/showbase/showBase.cxx b/direct/src/showbase/showBase.cxx index 14e1c27593..f7bc5be59d 100644 --- a/direct/src/showbase/showBase.cxx +++ b/direct/src/showbase/showBase.cxx @@ -60,38 +60,6 @@ get_particle_path() { std::string chan_config = "single"; std::string window_title = "Panda3D"; -void render_frame(GraphicsPipe *pipe) { - int num_windows = pipe->get_num_windows(); - for (int w = 0; w < num_windows; w++) { - GraphicsWindow *win = pipe->get_window(w); - win->get_gsg()->render_frame(); - } - // clock tick moved to igloop in ShowBase.py because - // clock must tick while app is iconified and draw - // callback is not being called by panda gsg - - // ClockObject::get_global_clock()->tick(); - throw_event("NewFrame"); -} - -class WindowCallback : public GraphicsWindow::Callback { -public: - WindowCallback(GraphicsPipe *pipe, Node *render_top) : - _pipe(pipe), - _render_top(render_top), - _app_traverser(RenderRelation::get_class_type()) { } - virtual ~WindowCallback() { } - - virtual void draw(bool) { - _app_traverser.traverse(_render_top); - render_frame(_pipe); - } - - PT(GraphicsPipe) _pipe; - PT(Node) _render_top; - AppTraverser _app_traverser; -}; - PT(GraphicsPipe) make_graphics_pipe() { PT(GraphicsPipe) main_pipe; @@ -142,14 +110,17 @@ ChanConfig make_graphics_window(GraphicsPipe *pipe, NodeRelation *render_arc) { main_win = chan_config.get_win(); assert(main_win != (GraphicsWindow*)0L); - WindowCallback *wcb = new WindowCallback(pipe, render_top); - - // Set draw callback. Currently there is no reason to use the idle callback. - main_win->set_draw_callback(wcb); - return chan_config; } +// Throw the "NewFrame" event in the C++ world. Some of the lerp code +// depends on receiving this. +void +throw_new_frame() { + throw_event("NewFrame"); +} + + // Create a scene graph, associated with the indicated window, that // can contain 2-d geometry and will be rendered on top of the // existing 3-d window. Returns the top node of the scene graph. diff --git a/direct/src/showbase/showBase.h b/direct/src/showbase/showBase.h index bbc5d83f01..6817f08d1b 100644 --- a/direct/src/showbase/showBase.h +++ b/direct/src/showbase/showBase.h @@ -47,6 +47,7 @@ EXPCL_DIRECT ChanConfig make_graphics_window(GraphicsPipe *pipe, NodeRelation *render_arc); +EXPCL_DIRECT void throw_new_frame(); EXPCL_DIRECT NodePath setup_panda_2d(GraphicsWindow *win, const string &name); EXPCL_DIRECT void add_render_layer(GraphicsWindow *win, Node *render_top, Camera *camera);