فهرست منبع

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 "pvector.h"
 
+ConfigVariableInt PhysicsManager::_random_seed
+("physics_manager_random_seed", 139);
+
 ////////////////////////////////////////////////////////////////////
 //     Function : PhysicsManager
 //       Access : Public
@@ -44,6 +47,20 @@ 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
 //       Access : Public

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

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