From 7d2b8904e01b2fcfe7314c0b7207202308b981bc Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Sat, 26 Feb 2005 00:22:47 +0000 Subject: [PATCH] Added ability to set random seed to assist in synchronizing physics and particles across cluster rendering machines --- panda/src/physics/physicsManager.cxx | 17 +++++++++++++++++ panda/src/physics/physicsManager.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/panda/src/physics/physicsManager.cxx b/panda/src/physics/physicsManager.cxx index 12d74793d8..03a5c54caf 100644 --- a/panda/src/physics/physicsManager.cxx +++ b/panda/src/physics/physicsManager.cxx @@ -22,6 +22,9 @@ #include #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 diff --git a/panda/src/physics/physicsManager.h b/panda/src/physics/physicsManager.h index c4ae7ca334..8c067cb8e5 100644 --- a/panda/src/physics/physicsManager.h +++ b/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;