From: Markus R. <rol...@us...> - 2007-03-31 13:28:54
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1411 Modified Files: mainframe.cpp mainframe.h Log Message: - added a second timer to update the FpsController periodically while the simulation is paused - added member mLastFPSUpdate that hold the simulation time of the last static FPS controller update - start the FPS timer when the simulation pauses Index: mainframe.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** mainframe.h 15 Mar 2007 07:26:24 -0000 1.8 --- mainframe.h 31 Mar 2007 13:28:50 -0000 1.9 *************** *** 104,107 **** --- 104,108 ---- void OnLogTimer(wxTimerEvent& event); + void OnFPSTimer(wxTimerEvent& event); /** appends the accumulated log buffer to the log window pane */ *************** *** 159,162 **** --- 160,168 ---- protected: wxTimer mTimer; + + //! simulation time of the last static FPS controller update + float mLastFPSUpdate; + wxTimer mFPSTimer; + wxToolBar* mToolBar; SparkTree mSparkTree; Index: mainframe.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** mainframe.cpp 15 Mar 2007 07:26:24 -0000 1.9 --- mainframe.cpp 31 Mar 2007 13:28:50 -0000 1.10 *************** *** 43,49 **** --- 43,53 ---- #include <oxygen/simulationserver/simulationserver.h> #include <oxygen/sceneserver/sceneserver.h> + #include <oxygen/sceneserver/fpscontroller.h> #include <kerosin/inputserver/inputcontrol.h> #include "simspark.h" + #define TI_LOG 1 + #define TI_FPS 2 + BEGIN_EVENT_TABLE(mainframe, wxFrame) EVT_MENU(wxID_EXIT, mainframe::OnExit) *************** *** 72,76 **** EVT_MENU(ID_HELP_ABOUT, mainframe::OnHelpAbout) ! EVT_TIMER(1, mainframe::OnLogTimer) EVT_TREE_ITEM_EXPANDING(1, mainframe::OnTreeItemExpanding) --- 76,81 ---- EVT_MENU(ID_HELP_ABOUT, mainframe::OnHelpAbout) ! EVT_TIMER(TI_LOG, mainframe::OnLogTimer) ! EVT_TIMER(TI_FPS, mainframe::OnFPSTimer) EVT_TREE_ITEM_EXPANDING(1, mainframe::OnTreeItemExpanding) *************** *** 87,91 **** mainframe::mainframe(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style): wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE), ! mTimer(this,1) { mToolBar = 0; --- 92,96 ---- mainframe::mainframe(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style): wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE), ! mTimer(this,TI_LOG), mFPSTimer(this,TI_FPS) { mToolBar = 0; *************** *** 334,337 **** --- 339,390 ---- } + void mainframe::OnFPSTimer(wxTimerEvent& event) + { + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + + if ( + (spark.get() == 0) || + (spark->GetSimState() != S_PAUSED) + ) + { + return; + } + + shared_ptr<InputControl> inputCtr = spark->GetInputControl(); + if (inputCtr.get() == 0) + { + return; + } + + inputCtr->StartCycle(); + + shared_ptr<FPSController> fps = inputCtr->GetFPSController(); + if ( + (fps.get() == 0) || + (! fps->NeedStaticUpdate()) + ) + { + // currently no update need, check again after full interval + mFPSTimer.Start(FPS_UPDATE_INTERVAL); + return; + } + + shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); + if (sim.get() == 0) + { + return; + } + + float now = sim->GetTime(); + fps->UpdateStatic(std::max<float>(0, now - mLastFPSUpdate)); + mLastFPSUpdate = now; + + wxClientDC dc(this); + mCanvas->Render(dc); + + // recheck and update as soon as posssible + mFPSTimer.Start(1); + } + void mainframe::UpdateLogWindow() { *************** *** 414,418 **** if (inputCtr.get() != 0) { ! inputCtr->SetFPSController("/usr/scene/camera/physics/controller"); inputCtr->SetAdvanceTime(false); } --- 467,471 ---- if (inputCtr.get() != 0) { ! inputCtr->SetFPSController(MAINFRAME_FPS_CONTROLLER.c_str()); inputCtr->SetAdvanceTime(false); } *************** *** 421,424 **** --- 474,479 ---- sim->Init(0,0); sim->SetAutoTimeMode(false); + + mLastFPSUpdate = 0.0; } *************** *** 426,433 **** --- 481,492 ---- { sim->Done(); + + mLastFPSUpdate = sim->GetTime(); + mFPSTimer.Start(FPS_UPDATE_INTERVAL); } void mainframe::StartSimulation() { + mFPSTimer.Stop(); shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); if ( |