From: <a-...@us...> - 2010-02-10 03:50:47
|
Revision: 162 http://simspark.svn.sourceforge.net/simspark/?rev=162&view=rev Author: a-held Date: 2010-02-10 03:50:40 +0000 (Wed, 10 Feb 2010) Log Message: ----------- Fetch PhysicsServer from SceneGraph instead of using a GetInstance method Modified Paths: -------------- branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.cpp branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.cpp branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.h Modified: branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.cpp 2010-02-09 05:23:09 UTC (rev 161) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.cpp 2010-02-10 03:50:40 UTC (rev 162) @@ -22,34 +22,32 @@ #include <oxygen/physicsserver/physicsserver.h> #include <oxygen/physicsserver/int/physicsserverint.h> #include <oxygen/physicsserver/impfactory.h> +#include <oxygen/physicsserver/rigidbody.h> #include <oxygen/physicsserver/world.h> #include <oxygen/physicsserver/space.h> #include <oxygen/sceneserver/scene.h> +#include <oxygen/sceneserver/transform.h> +#include <zeitgeist/logserver/logserver.h> #include <iostream> using namespace oxygen; using namespace boost; +using namespace std; shared_ptr<PhysicsServerInt> PhysicsServer::mPhysicsServerImp; -shared_ptr<PhysicsServer> PhysicsServer::mInstance; PhysicsServer::PhysicsServer() : Leaf() { mPhysicsServerImp = ImpFactory::GetInstance()->GetPhysicsServerImp(); } -shared_ptr<PhysicsServer> PhysicsServer::GetInstance(){ - if (mInstance.get() == 0) - mInstance = shared_ptr<PhysicsServer>(new PhysicsServer()); - return mInstance; -} - void PhysicsServer::ResetCache(){ mActiveSpace.reset(); mActiveWorld.reset(); } -void PhysicsServer::UpdateCache(shared_ptr<Scene> activeScene){ +void PhysicsServer::UpdateCache(shared_ptr<Scene> activeScene) +{ if (mActiveSpace.get() == 0) { // cache the space reference @@ -72,9 +70,24 @@ } } -void PhysicsServer::StepSimulation(float deltaTime){ +void PhysicsServer::StepSimulation(float deltaTime) +{ if (mActiveWorld.get() != 0) { mActiveWorld->Step(deltaTime); } } + +void PhysicsServer::SetUpBox(shared_ptr<RigidBody> body, string name) +{ + if (body.get() != 0) + { + body->SetName(name); + } +} + +void PhysicsServer::ConfirmExistence() +{ + GetLog()->Normal() << + "(PhysicsServer) I print, therefore I am\n"; +} Modified: branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h =================================================================== --- branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h 2010-02-09 05:23:09 UTC (rev 161) +++ branches/multiphys/spark/lib/oxygen/physicsserver/physicsserver.h 2010-02-10 03:50:40 UTC (rev 162) @@ -26,11 +26,13 @@ #include <zeitgeist/leaf.h> #include <oxygen/oxygen_defines.h> #include <boost/shared_ptr.hpp> +#include <string> namespace oxygen { class PhysicsServerInt; class Scene; +class RigidBody; class World; class Space; @@ -43,9 +45,6 @@ PhysicsServer(); virtual ~PhysicsServer(){}; - /** Returns the instance of the PhysicsServer. */ - static boost::shared_ptr<PhysicsServer> GetInstance(); - /** Resets the active space and active world */ void ResetCache(); @@ -58,9 +57,13 @@ /** Advance the simulation by \param deltatime */ void StepSimulation(float deltaTime); + /** Creates a new Box and adds it to the SceneGraph */ + void SetUpBox(boost::shared_ptr<RigidBody> body, std::string name); + + /** Used for debugging */ + void ConfirmExistence(); + private: - static boost::shared_ptr<PhysicsServer> mInstance; - static boost::shared_ptr<PhysicsServerInt> mPhysicsServerImp; /** cached reference to the Space node below the active scene */ Modified: branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.cpp =================================================================== --- branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.cpp 2010-02-09 05:23:09 UTC (rev 161) +++ branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.cpp 2010-02-10 03:50:40 UTC (rev 162) @@ -41,13 +41,34 @@ int SceneServer::mTransformMark = 0; SceneServer::SceneServer() : Node() -{ +{ } SceneServer::~SceneServer() { } +void SceneServer::OnLink() +{ + shared_ptr<CoreContext> context = GetCore()->CreateContext(); + + mPhysicsServer = shared_static_cast<PhysicsServer> + (context->Get("/sys/server/physics")); + + if (mPhysicsServer.get() == 0) + { + GetLog()->Error() << + "(SceneServer) ERROR: PhysicsServer not found at /sys/server/physics\n"; + } + else + { + GetLog()->Normal() << + "(SceneServer) Found PhysicsServer\n"; + + mPhysicsServer->ConfirmExistence(); + } +} + bool SceneServer::CreateScene(const std::string &location) { shared_ptr<CoreContext> context = GetCore()->CreateContext(); @@ -69,7 +90,7 @@ void SceneServer::ResetCache() { - PhysicsServer::GetInstance()->ResetCache(); + mPhysicsServer->ResetCache(); } void SceneServer::UpdateCache() @@ -80,14 +101,7 @@ return; } - /*shared_ptr<PhysicsServer> phServer = shared_static_cast<PhysicsServer> - (GetChildOfClass("oxygen/PhysicsServer")); - - if (phServer.get() == 0){ - GetLog()->Error() << "(SceneServer) No PhysicsServer found!"; - }*/ - - PhysicsServer::GetInstance()->UpdateCache(mActiveScene.get()); + mPhysicsServer->UpdateCache(mActiveScene.get()); } void SceneServer::OnUnlink() @@ -154,10 +168,10 @@ mActiveScene->PrePhysicsUpdate(deltaTime); // determine collisions - PhysicsServer::GetInstance()->DoCollisions(); + mPhysicsServer->DoCollisions(); // do physics - PhysicsServer::GetInstance()->StepSimulation(deltaTime); + mPhysicsServer->StepSimulation(deltaTime); mActiveScene->PostPhysicsUpdate(); mActiveScene->UpdateHierarchy(); @@ -183,10 +197,10 @@ { boost::recursive_mutex::scoped_lock lock(mMutex); // determine collisions - PhysicsServer::GetInstance()->DoCollisions(); + mPhysicsServer->DoCollisions(); // do physics - PhysicsServer::GetInstance()->StepSimulation(deltaTime); + mPhysicsServer->StepSimulation(deltaTime); } void SceneServer::PostPhysicsUpdate() @@ -376,5 +390,3 @@ return true; } - - Modified: branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.h =================================================================== --- branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.h 2010-02-09 05:23:09 UTC (rev 161) +++ branches/multiphys/spark/lib/oxygen/sceneserver/sceneserver.h 2010-02-10 03:50:40 UTC (rev 162) @@ -49,6 +49,7 @@ class Scene; class BaseNode; class Transform; +class PhysicsServer; /** The scene server manages displayable subtrees within the object hierarchy. Each subtree begins with a Scene node. The scene server knows @@ -107,6 +108,9 @@ /** resets all cached references */ void ResetCache(); + + /** Retrieves the PhysicsServer from the SceneGraph */ + virtual void OnLink(); /** resets all cached references */ virtual void OnUnlink(); @@ -122,6 +126,10 @@ */ void RemoveTransformPaths(boost::shared_ptr<zeitgeist::Leaf> root); + /** Pointer to the instance of the physicsserver */ + //causes crash at runtime if declared + boost::shared_ptr<PhysicsServer> mPhysicsServer; + private: /** the current active scene */ CachedPath<Scene> mActiveScene; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |