瀏覽代碼

Added ability to set random seed to assist in synchronizing physics and particles across cluster rendering machines

Mark Mine 21 年之前
父節點
當前提交
7d2b8904e0
共有 2 個文件被更改,包括 21 次插入0 次删除
  1. 17 0
      panda/src/physics/physicsManager.cxx
  2. 4 0
      panda/src/physics/physicsManager.h

+ 17 - 0
panda/src/physics/physicsManager.cxx

@@ -22,6 +22,9 @@
 #include <algorithm>
 #include <algorithm>
 #include "pvector.h"
 #include "pvector.h"
 
 
+ConfigVariableInt PhysicsManager::_random_seed
+("physics_manager_random_seed", 139);
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function : PhysicsManager
 //     Function : PhysicsManager
 //       Access : Public
 //       Access : Public
@@ -44,6 +47,20 @@ PhysicsManager::
 ~PhysicsManager() {
 ~PhysicsManager() {
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function : InitRandomSeed
+//       Access : Public
+//  Description : One-time config function, sets up the random seed
+//                used by the physics and particle systems.
+//                For synchronizing across distributed computers
+////////////////////////////////////////////////////////////////////
+void PhysicsManager::
+init_random_seed(void) {
+  // Use the random seed specified by the physics_manager_random_seed
+  // Config Variable
+  srand(_random_seed);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function : remove_linear_force
 //     Function : remove_linear_force
 //       Access : Public
 //       Access : Public

+ 4 - 0
panda/src/physics/physicsManager.h

@@ -32,6 +32,8 @@
 #include "plist.h"
 #include "plist.h"
 #include "pvector.h"
 #include "pvector.h"
 
 
+#include "configVariableInt.h"
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : PhysicsManager
 //       Class : PhysicsManager
 // Description : Physics don't get much higher-level than this.
 // Description : Physics don't get much higher-level than this.
@@ -74,6 +76,7 @@ PUBLISHED:
   void remove_linear_force(LinearForce *f);
   void remove_linear_force(LinearForce *f);
   void remove_angular_force(AngularForce *f);
   void remove_angular_force(AngularForce *f);
   void do_physics(float dt);
   void do_physics(float dt);
+  void init_random_seed();
   
   
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
   virtual void write_physicals(ostream &out, unsigned int indent=0) const;
   virtual void write_physicals(ostream &out, unsigned int indent=0) const;
@@ -85,6 +88,7 @@ PUBLISHED:
 
 
 public:
 public:
   friend class Physical;
   friend class Physical;
+  static ConfigVariableInt _random_seed;
 
 
 private:
 private:
   float _viscosity;
   float _viscosity;