From: Markus R. <rol...@us...> - 2007-02-15 21:08:08
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv26874 Modified Files: Tag: WIN32 mainframe.cpp mainframe.h simspark.cpp simspark.h sparkglcanvas.cpp sparkglcanvas.h Added Files: Tag: WIN32 constants.h Log Message: - added the ability to open simulations at runtime --- NEW FILE: constants.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: constants.h,v 1.1.2.1 2007/02/15 21:08:00 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef RSGEDIT_CONSTANTS_H #define RSGEDIT_CONSTANTS_H enum ESimState { S_PAUSED, S_RUNNING }; #endif // RSGEDIT_CONSTANTS_H Index: mainframe.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.h,v retrieving revision 1.7.2.2 retrieving revision 1.7.2.3 diff -C2 -d -r1.7.2.2 -r1.7.2.3 *** mainframe.h 15 Feb 2007 10:57:27 -0000 1.7.2.2 --- mainframe.h 15 Feb 2007 21:07:59 -0000 1.7.2.3 *************** *** 25,28 **** --- 25,29 ---- #include <wx/wx.h> #include <wx/image.h> + #include "constants.h" #include "sparktree.h" #include "propertylist.h" *************** *** 33,36 **** --- 34,42 ---- class SparkGLCanvas; + namespace oxygen + { + class SimulationServer; + } + // begin wxGlade: ::dependencies #include <wx/splitter.h> *************** *** 46,49 **** --- 52,57 ---- #define ID_VIEW_TOOLBAR (wxID_HIGHEST+22) + #define ID_FILE_OPEN (wxID_HIGHEST+23) + class mainframe: public wxFrame { public: *************** *** 67,70 **** --- 75,90 ---- void PauseSimulation(); + /** pause and reset the running simulation */ + void ResetSimulation(); + + /** go through one simulation cycle with the given time step */ + void AdvanceSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim, float tDeltaSec); + + /** prepare to start the simulation */ + void InitSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim); + + /** shut down the simulation */ + void DoneSimulation(boost::shared_ptr<oxygen::SimulationServer>& sim); + void OnUpdateStartSimulation(wxUpdateUIEvent& event); void OnStartSimulation(wxCommandEvent& event); *************** *** 79,82 **** --- 99,105 ---- void OnUpdateViewLog(wxUpdateUIEvent& event); + void OnFileOpen(wxCommandEvent& event); + void OnUpdateFileOpen(wxUpdateUIEvent& event); + void OnExit(wxCommandEvent& event); void OnClose( wxCloseEvent& event ); *************** *** 86,93 **** /** appends the accumulated log buffer to the log window pane */ void UpdateLogWindow(); ! /** returns true iff its safe to close this frame now */ bool CanClose(); void InitTreeNodeProperties(); --- 109,119 ---- /** appends the accumulated log buffer to the log window pane */ void UpdateLogWindow(); ! /** returns true iff its safe to close this frame now */ bool CanClose(); + /** returns the current simulation state */ + ESimState GetSimState() const; + void InitTreeNodeProperties(); Index: sparkglcanvas.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkglcanvas.cpp,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -C2 -d -r1.4.2.1 -r1.4.2.2 *** sparkglcanvas.cpp 10 Feb 2007 19:01:54 -0000 1.4.2.1 --- sparkglcanvas.cpp 15 Feb 2007 21:07:59 -0000 1.4.2.2 *************** *** 69,72 **** --- 69,77 ---- } + void SparkGLCanvas::Reset() + { + mInit = false; + } + void SparkGLCanvas::Render(wxDC& dc) { *************** *** 251,255 **** if ( (spark.get() == 0) || ! (spark->GetSimState() != SimSpark::S_RUNNING) ) { --- 256,260 ---- if ( (spark.get() == 0) || ! (spark->GetSimState() != S_RUNNING) ) { Index: simspark.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/simspark.cpp,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** simspark.cpp 9 Jan 2006 11:28:24 -0000 1.4 --- simspark.cpp 15 Feb 2007 21:07:59 -0000 1.4.2.1 *************** *** 21,24 **** --- 21,25 ---- #include <zeitgeist/scriptserver/scriptserver.h> #include <zeitgeist/logserver/logserver.h> + #include <oxygen/sceneserver/scene.h> #include <oxygen/simulationserver/simulationserver.h> *************** *** 26,29 **** --- 27,31 ---- using namespace boost; using namespace zeitgeist; + using namespace oxygen; using namespace spark; *************** *** 53,56 **** --- 55,70 ---- } + void SimSpark::ResetSimulation() + { + // recreat scene along with world and space nodes + GetScriptServer()->Eval("sparkResetScene()"); + + // recreate a default empty scene with a camera node + GetScriptServer()->Eval("rsgeditResetScene()"); + + // update stale references + GetScriptServer()->UpdateCachedAllNodes(); + } + void SimSpark::PrintHelp() { *************** *** 66,70 **** } ! SimSpark::ESimState SimSpark::GetSimState() const { return mState; --- 80,84 ---- } ! ESimState SimSpark::GetSimState() const { return mState; Index: mainframe.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.cpp,v retrieving revision 1.8.2.2 retrieving revision 1.8.2.3 diff -C2 -d -r1.8.2.2 -r1.8.2.3 *** mainframe.cpp 15 Feb 2007 10:57:26 -0000 1.8.2.2 --- mainframe.cpp 15 Feb 2007 21:07:59 -0000 1.8.2.3 *************** *** 24,29 **** --- 24,32 ---- #include "propertyframe.h" + #include <wx/filedlg.h> + #include <rsgedit/res/xpm_play.xpm> #include <rsgedit/res/xpm_pause.xpm> + #include <rsgedit/res/xpm_open.xpm> //! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro *************** *** 31,34 **** --- 34,38 ---- #include <zeitgeist/logserver/logserver.h> + #include <zeitgeist/scriptserver/scriptserver.h> #include <oxygen/simulationserver/simulationserver.h> #include <oxygen/sceneserver/sceneserver.h> *************** *** 52,55 **** --- 56,62 ---- EVT_UPDATE_UI(ID_VIEW_TREE, mainframe::OnUpdateViewTree) + EVT_MENU(ID_FILE_OPEN, mainframe::OnFileOpen) + EVT_UPDATE_UI(ID_FILE_OPEN, mainframe::OnUpdateFileOpen) + EVT_TIMER(1, mainframe::OnLogTimer) *************** *** 93,96 **** --- 100,104 ---- SetMenuBar(MainFrame_menubar); wxMenu* wxglade_tmp_menu_1 = new wxMenu(); + wxglade_tmp_menu_1->Append(ID_FILE_OPEN, wxT("&Open"), wxT(""), wxITEM_NORMAL); wxglade_tmp_menu_1->Append(wxID_EXIT, wxT("&Exit"), wxT(""), wxITEM_NORMAL); MainFrame_menubar->Append(wxglade_tmp_menu_1, wxT("&File")); *************** *** 116,119 **** --- 124,129 ---- mToolBar = CreateToolBar( wxTB_FLAT|wxTB_HORIZONTAL, wxID_ANY ); + mToolBar->AddTool(ID_FILE_OPEN, wxT("Open"), wxBitmap(xpm_open)); + mToolBar->AddSeparator(); mToolBar->AddTool(ID_SIM_START, wxT("Start"), wxBitmap(xpm_play)); mToolBar->AddTool(ID_SIM_PAUSE, wxT("Pause"), wxBitmap(xpm_pause)); *************** *** 228,231 **** --- 238,253 ---- } + ESimState mainframe::GetSimState() const + { + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if (spark.get() == 0) + { + assert(false); + return S_PAUSED; + } + + return spark->GetSimState(); + } + bool mainframe::CanClose() { *************** *** 233,237 **** if ( (spark.get() != 0) && ! (spark->GetSimState() == SimSpark::S_RUNNING) ) { --- 255,259 ---- if ( (spark.get() != 0) && ! (spark->GetSimState() == S_RUNNING) ) { *************** *** 242,245 **** --- 264,268 ---- } + void mainframe::OnClose( wxCloseEvent& event ) { *************** *** 261,271 **** void mainframe::OnUpdateStartSimulation(wxUpdateUIEvent& event) { ! shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! bool enable = ( ! (spark.get() != 0) && ! (spark->GetSimState() == SimSpark::S_PAUSED) ! ); ! ! event.Enable(enable); } --- 284,288 ---- void mainframe::OnUpdateStartSimulation(wxUpdateUIEvent& event) { ! event.Enable(GetSimState() == S_PAUSED); } *************** *** 277,287 **** void mainframe::OnUpdatePauseSimulation(wxUpdateUIEvent& event) { ! shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! bool enable = ( ! (spark.get() != 0) && ! (spark->GetSimState() == SimSpark::S_RUNNING) ! ); ! ! event.Enable(enable); } --- 294,298 ---- void mainframe::OnUpdatePauseSimulation(wxUpdateUIEvent& event) { ! event.Enable(GetSimState() == S_RUNNING); } *************** *** 315,319 **** if ( (spark.get() == 0) || ! (spark->GetSimState() != SimSpark::S_RUNNING) ) { --- 326,330 ---- if ( (spark.get() == 0) || ! (spark->GetSimState() != S_RUNNING) ) { *************** *** 331,352 **** } ! void mainframe::StartSimulation() { shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); if ( (spark.get() == 0) || ! (spark->GetSimState() != SimSpark::S_PAUSED) ) { return; } ! shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); ! if (sim.get() == 0) ! { ! return; ! } ! spark->SetSimState(SimSpark::S_RUNNING); // tell the inputControl node the loaction of our camera --- 342,385 ---- } ! void mainframe::ResetSimulation() { + PauseSimulation(); shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if ( (spark.get() == 0) || ! (spark->GetSimState() != S_PAUSED) ) { + assert(false); return; } ! spark->ResetSimulation(); ! mCanvas->Reset(); ! spark->GetLog()->Normal() << "(RsgEdit) resetting simulation\n"; ! } ! void mainframe::AdvanceSimulation(shared_ptr<SimulationServer>& sim, float tDeltaSec) ! { ! // go through the next simulation cycle ! sim->AdvanceTime(tDeltaSec); ! sim->Cycle(); ! ! // refresh the display ! RefreshProperties(); ! ! wxClientDC dc(this); ! mCanvas->Render(dc); ! } ! ! void mainframe::InitSimulation(shared_ptr<SimulationServer>& sim) ! { ! shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! if (spark.get() == 0) ! { ! assert(false); ! return; ! } // tell the inputControl node the loaction of our camera *************** *** 361,364 **** --- 394,424 ---- sim->Init(0,0); sim->SetAutoTimeMode(false); + } + + void mainframe::DoneSimulation(shared_ptr<SimulationServer>& sim) + { + sim->Done(); + } + + void mainframe::StartSimulation() + { + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if ( + (spark.get() == 0) || + (spark->GetSimState() != S_PAUSED) + ) + { + return; + } + + shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); + if (sim.get() == 0) + { + return; + } + + spark->SetSimState(S_RUNNING); + + InitSimulation(sim); spark->GetLog()->Normal() << "(RsgEdit) starting simulation\n"; *************** *** 374,386 **** tLast = tNow; ! // go through the next simulation cycle ! sim->AdvanceTime(tDeltaSec); ! sim->Cycle(); ! ! // refresh the display ! RefreshProperties(); ! ! wxClientDC dc(this); ! mCanvas->Render(dc); // pump the wxWidgets message loop --- 434,438 ---- tLast = tNow; ! AdvanceSimulation(sim, tDeltaSec); // pump the wxWidgets message loop *************** *** 388,393 **** } ! sim->Done(); ! spark->SetSimState(SimSpark::S_PAUSED); spark->GetLog()->Normal() << "(RsgEdit) simulation paused\n"; --- 440,446 ---- } ! DoneSimulation(sim); ! ! spark->SetSimState(S_PAUSED); spark->GetLog()->Normal() << "(RsgEdit) simulation paused\n"; *************** *** 486,487 **** --- 539,585 ---- } } + + void mainframe::OnUpdateFileOpen(wxUpdateUIEvent& event) + { + event.Enable(GetSimState() == S_PAUSED); + } + + void mainframe::OnFileOpen(wxCommandEvent& event) + { + wxString message = "Choose a ruby script to run"; + wxString default_path = "./rsg"; + wxString default_filename = ""; + wxString default_extension = ""; + wxString wildcard = "ruby scripts (*.rb)|*.rb"; + + wxString filename = wxFileSelector(message, default_path, default_filename, default_extension, wildcard); + if (filename.empty() ) + { + return; + } + + ResetSimulation(); + mSparkTree.Init(mCtrTree); + InitTreeNodeProperties(); + + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if (spark.get() == 0) + { + assert(false); + return; + } + + spark->GetScriptServer()->Run(filename.c_str()); + spark->GetLog()->Normal() << "(RsgEdit) reading " << filename << "\n"; + + shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); + if (sim.get() == 0) + { + assert(false); + return; + } + + InitSimulation(sim); + AdvanceSimulation(sim, 0.01f); + DoneSimulation(sim); + } Index: sparkglcanvas.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkglcanvas.h,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -C2 -d -r1.3.2.1 -r1.3.2.2 *** sparkglcanvas.h 10 Feb 2007 19:01:54 -0000 1.3.2.1 --- sparkglcanvas.h 15 Feb 2007 21:07:59 -0000 1.3.2.2 *************** *** 64,67 **** --- 64,68 ---- void Render(wxDC& dc); + void Reset(); protected: Index: simspark.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/simspark.h,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** simspark.h 8 Jan 2006 15:37:37 -0000 1.3 --- simspark.h 15 Feb 2007 21:07:59 -0000 1.3.2.1 *************** *** 23,26 **** --- 23,27 ---- #include <spark/spark.h> #include <wx/string.h> + #include "constants.h" #include <sstream> *************** *** 28,38 **** { public: - enum ESimState - { - S_PAUSED, - S_RUNNING - }; - - public: SimSpark(const std::string& relPathPrefix); --- 29,32 ---- *************** *** 52,55 **** --- 46,52 ---- ESimState GetSimState() const; + /** resets the simulation, i.e. empties the scene */ + void ResetSimulation(); + /** set the current simulationm state */ void SetSimState(ESimState state); |