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
509509 _sessionRunTimer(startupTimer),
510510 _previousSessionCrashed(setupEssentials(argc, argv)),
511511 _undoStackScriptingInterface(&_undoStack),
512+ _entitySimulation(new PhysicalEntitySimulation()),
512513 _physicsEngine(new PhysicsEngine(Vectors::ZERO)),
513514 _entityClipboardRenderer(false, this, this),
514515 _entityClipboard(new EntityTree()),
@@ -2995,13 +2996,13 @@ void Application::init() { · 2480 unmodified lines
29952996 _physicsEngine->init();
29962997
29972998 EntityTreePointer tree = getEntities()->getTree();
2998− _entitySimulation.init(tree, _physicsEngine, &_entityEditSender);
2999− tree->setSimulation(&_entitySimulation);
2999+ _entitySimulation->init(tree, _physicsEngine, &_entityEditSender);
3000+ tree->setSimulation(_entitySimulation);
30003001
30013002 auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
30023003
30033004 // 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,
30053006 getEntities(), &EntityTreeRenderer::entityCollisionWithEntity);
30063007
30073008 // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing
@@ -3404,22 +3405,22 @@ void Application::update(float deltaTime) { · 396 unmodified lines
34043405
34053406 PerformanceTimer perfTimer("updateStates)");
34063407 static VectorOfMotionStates motionStates;
3407− _entitySimulation.getObjectsToRemoveFromPhysics(motionStates);
3408+ _entitySimulation->getObjectsToRemoveFromPhysics(motionStates);
34083409 _physicsEngine->removeObjects(motionStates);
3409− _entitySimulation.deleteObjectsRemovedFromPhysics();
3410+ _entitySimulation->deleteObjectsRemovedFromPhysics();
34103411
34113412 getEntities()->getTree()->withReadLock([&] {
3412− _entitySimulation.getObjectsToAddToPhysics(motionStates);
3413+ _entitySimulation->getObjectsToAddToPhysics(motionStates);
34133414 _physicsEngine->addObjects(motionStates);
34143415
34153416 });
34163417 getEntities()->getTree()->withReadLock([&] {
3417− _entitySimulation.getObjectsToChange(motionStates);
3418+ _entitySimulation->getObjectsToChange(motionStates);
34183419 VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);
3419− _entitySimulation.setObjectsToChange(stillNeedChange);
3420+ _entitySimulation->setObjectsToChange(stillNeedChange);
34203421 });
34213422
3422− _entitySimulation.applyActionChanges();
3423+ _entitySimulation->applyActionChanges();
34233424
34243425 avatarManager->getObjectsToRemoveFromPhysics(motionStates);
34253426 _physicsEngine->removeObjects(motionStates);
@@ -3447,7 +3448,7 @@ void Application::update(float deltaTime) { · 21 unmodified lines
34473448 getEntities()->getTree()->withWriteLock([&] {
34483449 PerformanceTimer perfTimer("handleOutgoingChanges");
34493450 const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();
3450− _entitySimulation.handleOutgoingChanges(outgoingChanges);
3451+ _entitySimulation->handleOutgoingChanges(outgoingChanges);
34513452 avatarManager->handleOutgoingChanges(outgoingChanges);
34523453 });
34533454
@@ -3460,7 +3461,7 @@ void Application::update(float deltaTime) { · 6 unmodified lines
34603461 PerformanceTimer perfTimer("entities");
34613462 // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk
34623463 // deadlock.)
3463− _entitySimulation.handleCollisionEvents(collisionEvents);
3464+ _entitySimulation->handleCollisionEvents(collisionEvents);
34643465
34653466 // NOTE: the getEntities()->update() call below will wait for lock
34663467 // and will simulate entity motion (the EntityTree has been given an EntitySimulation).