History

use smart pointers for entity simulations

Seth Alves committed 10 years ago

Commit a0771f81 parent b234d9423 files · +74 −58Browse files

Showing the changes to interface/src/Application.cpp (1 of 23 files). Show all

Unified · Split

interface/src/Application.cpp+12−11
@@ -509,6 +509,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 508 unmodified lines
509 _sessionRunTimer(startupTimer),509 _sessionRunTimer(startupTimer),
510 _previousSessionCrashed(setupEssentials(argc, argv)),510 _previousSessionCrashed(setupEssentials(argc, argv)),
511 _undoStackScriptingInterface(&_undoStack),511 _undoStackScriptingInterface(&_undoStack),
512 _entitySimulation(new PhysicalEntitySimulation()),
512 _physicsEngine(new PhysicsEngine(Vectors::ZERO)),513 _physicsEngine(new PhysicsEngine(Vectors::ZERO)),
513 _entityClipboardRenderer(false, this, this),514 _entityClipboardRenderer(false, this, this),
514 _entityClipboard(new EntityTree()),515 _entityClipboard(new EntityTree()),
@@ -2995,13 +2996,13 @@ void Application::init() { · 2480 unmodified lines
2995 _physicsEngine->init();2996 _physicsEngine->init();
2996 2997
2997 EntityTreePointer tree = getEntities()->getTree();2998 EntityTreePointer tree = getEntities()->getTree();
2998 _entitySimulation.init(tree, _physicsEngine, &_entityEditSender);2999 _entitySimulation->init(tree, _physicsEngine, &_entityEditSender);
2999 tree->setSimulation(&_entitySimulation);3000 tree->setSimulation(_entitySimulation);
3000 3001
3001 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();3002 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
3002 3003
3003 // connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts3004 // connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts
3004 connect(&_entitySimulation, &EntitySimulation::entityCollisionWithEntity,3005 connect(_entitySimulation.get(), &EntitySimulation::entityCollisionWithEntity,
3005 getEntities(), &EntityTreeRenderer::entityCollisionWithEntity);3006 getEntities(), &EntityTreeRenderer::entityCollisionWithEntity);
3006 3007
3007 // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing3008 // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing
@@ -3404,22 +3405,22 @@ void Application::update(float deltaTime) { · 396 unmodified lines
3404 3405
3405 PerformanceTimer perfTimer("updateStates)");3406 PerformanceTimer perfTimer("updateStates)");
3406 static VectorOfMotionStates motionStates;3407 static VectorOfMotionStates motionStates;
3407 _entitySimulation.getObjectsToRemoveFromPhysics(motionStates);3408 _entitySimulation->getObjectsToRemoveFromPhysics(motionStates);
3408 _physicsEngine->removeObjects(motionStates);3409 _physicsEngine->removeObjects(motionStates);
3409 _entitySimulation.deleteObjectsRemovedFromPhysics();3410 _entitySimulation->deleteObjectsRemovedFromPhysics();
3410 3411
3411 getEntities()->getTree()->withReadLock([&] {3412 getEntities()->getTree()->withReadLock([&] {
3412 _entitySimulation.getObjectsToAddToPhysics(motionStates);3413 _entitySimulation->getObjectsToAddToPhysics(motionStates);
3413 _physicsEngine->addObjects(motionStates);3414 _physicsEngine->addObjects(motionStates);
3414 3415
3415 });3416 });
3416 getEntities()->getTree()->withReadLock([&] {3417 getEntities()->getTree()->withReadLock([&] {
3417 _entitySimulation.getObjectsToChange(motionStates);3418 _entitySimulation->getObjectsToChange(motionStates);
3418 VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);3419 VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);
3419 _entitySimulation.setObjectsToChange(stillNeedChange);3420 _entitySimulation->setObjectsToChange(stillNeedChange);
3420 });3421 });
3421 3422
3422 _entitySimulation.applyActionChanges();3423 _entitySimulation->applyActionChanges();
3423 3424
3424 avatarManager->getObjectsToRemoveFromPhysics(motionStates);3425 avatarManager->getObjectsToRemoveFromPhysics(motionStates);
3425 _physicsEngine->removeObjects(motionStates);3426 _physicsEngine->removeObjects(motionStates);
@@ -3447,7 +3448,7 @@ void Application::update(float deltaTime) { · 21 unmodified lines
3447 getEntities()->getTree()->withWriteLock([&] {3448 getEntities()->getTree()->withWriteLock([&] {
3448 PerformanceTimer perfTimer("handleOutgoingChanges");3449 PerformanceTimer perfTimer("handleOutgoingChanges");
3449 const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();3450 const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();
3450 _entitySimulation.handleOutgoingChanges(outgoingChanges);3451 _entitySimulation->handleOutgoingChanges(outgoingChanges);
3451 avatarManager->handleOutgoingChanges(outgoingChanges);3452 avatarManager->handleOutgoingChanges(outgoingChanges);
3452 });3453 });
3453 3454
@@ -3460,7 +3461,7 @@ void Application::update(float deltaTime) { · 6 unmodified lines
3460 PerformanceTimer perfTimer("entities");3461 PerformanceTimer perfTimer("entities");
3461 // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk3462 // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk
3462 // deadlock.)3463 // deadlock.)
3463 _entitySimulation.handleCollisionEvents(collisionEvents);3464 _entitySimulation->handleCollisionEvents(collisionEvents);
3464 3465
3465 // NOTE: the getEntities()->update() call below will wait for lock3466 // NOTE: the getEntities()->update() call below will wait for lock
3466 // and will simulate entity motion (the EntityTree has been given an EntitySimulation).3467 // and will simulate entity motion (the EntityTree has been given an EntitySimulation).