mirror of
https://github.com/overte-org/overte.git
synced 2025-04-30 10:22:46 +02:00
incoming changes is now QSet<ObjectMotionState*>
This commit is contained in:
parent
11f1ad1d7f
commit
cc0e82b97f
2 changed files with 29 additions and 42 deletions
|
@ -8,7 +8,7 @@
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
// TODO: make _incomingEntityChanges to be list of MotionState*'s.
|
// TODO DONE: make _incomingChanges to be list of MotionState*'s.
|
||||||
// TODO: make MotionState able to clear incoming flags
|
// TODO: make MotionState able to clear incoming flags
|
||||||
// TODO: make MotionState::setWorldTransform() put itself on _incomingChanges list
|
// TODO: make MotionState::setWorldTransform() put itself on _incomingChanges list
|
||||||
// TODO: give PhysicsEngine instance an _entityPacketSender
|
// TODO: give PhysicsEngine instance an _entityPacketSender
|
||||||
|
@ -38,8 +38,6 @@ PhysicsEngine::~PhysicsEngine() {
|
||||||
|
|
||||||
// begin EntitySimulation overrides
|
// begin EntitySimulation overrides
|
||||||
void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
|
void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
|
||||||
// relay outgoing changes: from physics engine to EntityItem's
|
|
||||||
|
|
||||||
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPhysics.begin();
|
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPhysics.begin();
|
||||||
uint32_t frame = getFrameCount();
|
uint32_t frame = getFrameCount();
|
||||||
float subStepRemainder = getSubStepRemainder();
|
float subStepRemainder = getSubStepRemainder();
|
||||||
|
@ -84,7 +82,12 @@ void PhysicsEngine::removeEntityInternal(EntityItem* entity) {
|
||||||
|
|
||||||
void PhysicsEngine::entityChangedInternal(EntityItem* entity) {
|
void PhysicsEngine::entityChangedInternal(EntityItem* entity) {
|
||||||
// queue incoming changes: from external sources (script, EntityServer, etc) to physics engine
|
// queue incoming changes: from external sources (script, EntityServer, etc) to physics engine
|
||||||
_incomingEntityChanges.insert(entity);
|
assert(entity);
|
||||||
|
void* physicsInfo = entity->getPhysicsInfo();
|
||||||
|
if (physicsInfo) {
|
||||||
|
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
|
||||||
|
_incomingChanges.insert(motionState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::clearEntitiesInternal() {
|
void PhysicsEngine::clearEntitiesInternal() {
|
||||||
|
@ -94,29 +97,34 @@ void PhysicsEngine::clearEntitiesInternal() {
|
||||||
removeObject(*stateItr);
|
removeObject(*stateItr);
|
||||||
}
|
}
|
||||||
_entityMotionStates.clear();
|
_entityMotionStates.clear();
|
||||||
_incomingEntityChanges.clear();
|
_incomingChanges.clear();
|
||||||
}
|
}
|
||||||
// end EntitySimulation overrides
|
// end EntitySimulation overrides
|
||||||
|
|
||||||
void PhysicsEngine::relayIncomingChangesToSimulation() {
|
void PhysicsEngine::relayIncomingChangesToSimulation() {
|
||||||
// process incoming changes
|
// process incoming changes
|
||||||
QSet<EntityItem*>::iterator itemItr = _incomingEntityChanges.begin();
|
QSet<ObjectMotionState*>::iterator stateItr = _incomingChanges.begin();
|
||||||
while (itemItr != _incomingEntityChanges.end()) {
|
while (stateItr != _incomingChanges.end()) {
|
||||||
EntityItem* entity = *itemItr;
|
ObjectMotionState* motionState = *stateItr;
|
||||||
void* physicsInfo = entity->getPhysicsInfo();
|
motionState->clearConflictingDirtyFlags();
|
||||||
if (physicsInfo) {
|
uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS;
|
||||||
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
|
|
||||||
uint32_t flags = entity->getDirtyFlags();
|
btRigidBody* body = motionState->_body;
|
||||||
if (flags & DIRTY_PHYSICS_FLAGS) {
|
if (body) {
|
||||||
updateObject(motionState, flags);
|
if (flags & HARD_DIRTY_PHYSICS_FLAGS) {
|
||||||
// this incoming change will override any outgoing changes to the same parameters
|
// a HARD update requires the body be pulled out of physics engine, changed, then reinserted
|
||||||
motionState->clearOutgoingDirtyFlags(flags);
|
// but it also handles all EASY changes
|
||||||
|
updateObjectHard(body, motionState, flags);
|
||||||
|
} else if (flags) {
|
||||||
|
// an EASY update does NOT require that the body be pulled out of physics engine
|
||||||
|
updateObjectEasy(body, motionState, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity->clearDirtyFlags();
|
|
||||||
++itemItr;
|
motionState->clearIncomingDirtyFlags(flags);
|
||||||
|
++stateItr;
|
||||||
}
|
}
|
||||||
_incomingEntityChanges.clear();
|
_incomingChanges.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
|
@ -295,22 +303,6 @@ bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsEngine::updateObject(ObjectMotionState* motionState, uint32_t flags) {
|
|
||||||
btRigidBody* body = motionState->_body;
|
|
||||||
if (!body) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & HARD_DIRTY_PHYSICS_FLAGS) {
|
|
||||||
// a hard update requires the body be pulled out of physics engine, changed, then reinserted
|
|
||||||
updateObjectHard(body, motionState, flags);
|
|
||||||
} else if (flags & EASY_DIRTY_PHYSICS_FLAGS) {
|
|
||||||
// an easy update does not require that the body be pulled out of physics engine
|
|
||||||
updateObjectEasy(body, motionState, flags);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags) {
|
void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags) {
|
||||||
MotionType newType = motionState->computeMotionType();
|
MotionType newType = motionState->computeMotionType();
|
||||||
|
|
|
@ -73,11 +73,6 @@ public:
|
||||||
/// \return true if Object removed
|
/// \return true if Object removed
|
||||||
bool removeObject(ObjectMotionState* motionState);
|
bool removeObject(ObjectMotionState* motionState);
|
||||||
|
|
||||||
/// \param motionState pointer to Object's MotionState
|
|
||||||
/// \param flags set of bits indicating what categories of properties need to be updated
|
|
||||||
/// \return true if entity updated
|
|
||||||
bool updateObject(ObjectMotionState* motionState, uint32_t flags);
|
|
||||||
|
|
||||||
/// process queue of changed from external sources
|
/// process queue of changed from external sources
|
||||||
void relayIncomingChangesToSimulation();
|
void relayIncomingChangesToSimulation();
|
||||||
|
|
||||||
|
@ -111,7 +106,7 @@ private:
|
||||||
|
|
||||||
// EntitySimulation stuff
|
// EntitySimulation stuff
|
||||||
QSet<EntityMotionState*> _entityMotionStates; // all entities that we track
|
QSet<EntityMotionState*> _entityMotionStates; // all entities that we track
|
||||||
QSet<EntityItem*> _incomingEntityChanges; // entities with pending physics changes by script or packet
|
QSet<ObjectMotionState*> _incomingChanges; // entities with pending physics changes by script or packet
|
||||||
QSet<ObjectMotionState*> _outgoingPhysics; // MotionStates with pending transform changes from physics simulation
|
QSet<ObjectMotionState*> _outgoingPhysics; // MotionStates with pending transform changes from physics simulation
|
||||||
|
|
||||||
EntityEditPacketSender* _entityPacketSender;
|
EntityEditPacketSender* _entityPacketSender;
|
||||||
|
|
Loading…
Reference in a new issue