mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:07:07 +02:00
add updateFoo() methods that accumulate flags
about properties that have changed
This commit is contained in:
parent
c2adc6256e
commit
a183248f38
2 changed files with 137 additions and 8 deletions
|
@ -90,6 +90,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
||||||
_lastEditedFromRemoteInRemoteTime = 0;
|
_lastEditedFromRemoteInRemoteTime = 0;
|
||||||
_lastUpdated = 0;
|
_lastUpdated = 0;
|
||||||
_created = 0;
|
_created = 0;
|
||||||
|
_updateFlags = 0;
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
_simulationState = EntityItem::Static;
|
_simulationState = EntityItem::Static;
|
||||||
|
@ -102,6 +103,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
||||||
_lastEditedFromRemoteInRemoteTime = 0;
|
_lastEditedFromRemoteInRemoteTime = 0;
|
||||||
_lastUpdated = 0;
|
_lastUpdated = 0;
|
||||||
_created = properties.getCreated();
|
_created = properties.getCreated();
|
||||||
|
_updateFlags = 0;
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
setProperties(properties, true); // force copy
|
setProperties(properties, true); // force copy
|
||||||
|
@ -731,11 +733,6 @@ bool EntityItem::lifetimeHasExpired() const {
|
||||||
return isMortal() && (getAge() > getLifetime());
|
return isMortal() && (getAge() > getLifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EntityItem::copyChangedProperties(const EntityItem& other) {
|
|
||||||
*this = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemProperties EntityItem::getProperties() const {
|
EntityItemProperties EntityItem::getProperties() const {
|
||||||
EntityItemProperties properties;
|
EntityItemProperties properties;
|
||||||
properties._id = getID();
|
properties._id = getID();
|
||||||
|
@ -947,4 +944,104 @@ void EntityItem::recalculateCollisionShape() {
|
||||||
_collisionShape.setScale(entityAACube.getScale());
|
_collisionShape.setScale(entityAACube.getScale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityItem::updatePosition(const glm::vec3& value) {
|
||||||
|
if (_position != value) {
|
||||||
|
_position = value;
|
||||||
|
recalculateCollisionShape();
|
||||||
|
_updateFlags |= UPDATE_POSITION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updatePositionInMeters(const glm::vec3& value) {
|
||||||
|
glm::vec3 position = glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f);
|
||||||
|
if (_position != position) {
|
||||||
|
_position = position;
|
||||||
|
recalculateCollisionShape();
|
||||||
|
_updateFlags |= UPDATE_POSITION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateDimensions(const glm::vec3& value) {
|
||||||
|
if (_dimensions != value) {
|
||||||
|
_dimensions = value;
|
||||||
|
recalculateCollisionShape();
|
||||||
|
_updateFlags |= UPDATE_SHAPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateDimensionsInMeters(const glm::vec3& value) {
|
||||||
|
glm::vec3 dimensions = value / (float) TREE_SCALE;
|
||||||
|
if (_dimensions != dimensions) {
|
||||||
|
_dimensions = dimensions;
|
||||||
|
recalculateCollisionShape();
|
||||||
|
_updateFlags |= UPDATE_SHAPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateRotation(const glm::quat& rotation) {
|
||||||
|
if (_rotation != rotation) {
|
||||||
|
_rotation = rotation;
|
||||||
|
recalculateCollisionShape();
|
||||||
|
_updateFlags |= UPDATE_POSITION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateMass(float value) {
|
||||||
|
if (_mass != value) {
|
||||||
|
_mass = value;
|
||||||
|
_updateFlags |= UPDATE_MASS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateVelocity(const glm::vec3& value) {
|
||||||
|
if (_velocity != value) {
|
||||||
|
_velocity = value;
|
||||||
|
_updateFlags |= UPDATE_VELOCITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateVelocityInMeters(const glm::vec3& value) {
|
||||||
|
glm::vec3 velocity = value / (float) TREE_SCALE;
|
||||||
|
if (_velocity != velocity) {
|
||||||
|
_velocity = velocity;
|
||||||
|
_updateFlags |= UPDATE_VELOCITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateGravity(const glm::vec3& value) {
|
||||||
|
if (_gravity != value) {
|
||||||
|
_gravity = value;
|
||||||
|
_updateFlags |= UPDATE_VELOCITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateGravityInMeters(const glm::vec3& value) {
|
||||||
|
glm::vec3 gravity = value / (float) TREE_SCALE;
|
||||||
|
if (_gravity != gravity) {
|
||||||
|
_gravity = gravity;
|
||||||
|
_updateFlags |= UPDATE_VELOCITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateAngularVelocity(const glm::vec3& value) {
|
||||||
|
if (_angularVelocity != value) {
|
||||||
|
_angularVelocity = value;
|
||||||
|
_updateFlags |= UPDATE_VELOCITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateIgnoreForCollisions(bool value) {
|
||||||
|
if (_ignoreForCollisions != value) {
|
||||||
|
_ignoreForCollisions = value;
|
||||||
|
_updateFlags |= UPDATE_COLLISION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItem::updateCollisionsWillMove(bool value) {
|
||||||
|
if (_collisionsWillMove != value) {
|
||||||
|
_collisionsWillMove = value;
|
||||||
|
_updateFlags |= UPDATE_COLLISION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,14 @@ class EntityTreeElementExtraEncodeData;
|
||||||
#define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0;
|
#define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0;
|
||||||
#define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() { };
|
#define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() { };
|
||||||
|
|
||||||
|
enum EntityUpdateFlags {
|
||||||
|
UPDATE_POSITION = 0x0001,
|
||||||
|
UPDATE_VELOCITY = 0x0002,
|
||||||
|
UPDATE_MASS = 0x0004,
|
||||||
|
UPDATE_COLLISION = 0x0008,
|
||||||
|
UPDATE_SHAPE = 0x0010,
|
||||||
|
//UPDATE_APPEARANCE = 0x8000,
|
||||||
|
};
|
||||||
|
|
||||||
/// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available
|
/// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available
|
||||||
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
||||||
|
@ -125,9 +133,6 @@ public:
|
||||||
|
|
||||||
virtual void debugDump() const;
|
virtual void debugDump() const;
|
||||||
|
|
||||||
// similar to assignment/copy, but it handles keeping lifetime accurate
|
|
||||||
void copyChangedProperties(const EntityItem& other);
|
|
||||||
|
|
||||||
// attributes applicable to all entity types
|
// attributes applicable to all entity types
|
||||||
EntityTypes::EntityType getType() const { return _type; }
|
EntityTypes::EntityType getType() const { return _type; }
|
||||||
const glm::vec3& getPosition() const { return _position; } /// get position in domain scale units (0.0 - 1.0)
|
const glm::vec3& getPosition() const { return _position; } /// get position in domain scale units (0.0 - 1.0)
|
||||||
|
@ -266,6 +271,29 @@ public:
|
||||||
virtual const Shape& getCollisionShapeInMeters() const { return _collisionShape; }
|
virtual const Shape& getCollisionShapeInMeters() const { return _collisionShape; }
|
||||||
virtual bool contains(const glm::vec3& point) const { return getAABox().contains(point); }
|
virtual bool contains(const glm::vec3& point) const { return getAABox().contains(point); }
|
||||||
|
|
||||||
|
// updateFoo() methods to be used when changes need to be accumulated in the _updateFlags
|
||||||
|
void updatePosition(const glm::vec3& value);
|
||||||
|
void updatePositionInMeters(const glm::vec3& value);
|
||||||
|
void updateDimensions(const glm::vec3& value);
|
||||||
|
void updateDimensionsInMeters(const glm::vec3& value);
|
||||||
|
void updateRotation(const glm::quat& rotation);
|
||||||
|
void updateMass(float value);
|
||||||
|
void updateVelocity(const glm::vec3& value);
|
||||||
|
void updateVelocityInMeters(const glm::vec3& value);
|
||||||
|
void updateGravity(const glm::vec3& value);
|
||||||
|
void updateGravityInMeters(const glm::vec3& value);
|
||||||
|
void updateAngularVelocity(const glm::vec3& value);
|
||||||
|
void updateIgnoreForCollisions(bool value);
|
||||||
|
void updateCollisionsWillMove(bool value);
|
||||||
|
|
||||||
|
void setUpdateFlags(uint32_t mask) { _updateFlags |= mask; }
|
||||||
|
void clearUpdateFlags(uint32_t mask) { _updateFlags &= ~mask; }
|
||||||
|
|
||||||
|
#ifdef USE_BULLET_PHYSICS
|
||||||
|
EntityMotionState* getMotionState() const { return _motionState; }
|
||||||
|
virtual EntityMotionState* createMotionState() { return NULL; }
|
||||||
|
void destroyMotionState();
|
||||||
|
#endif // USE_BULLET_PHYSICS
|
||||||
SimulationState getSimulationState() const { return _simulationState; }
|
SimulationState getSimulationState() const { return _simulationState; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -314,6 +342,10 @@ protected:
|
||||||
|
|
||||||
AACubeShape _collisionShape;
|
AACubeShape _collisionShape;
|
||||||
SimulationState _simulationState; // only set by EntityTree
|
SimulationState _simulationState; // only set by EntityTree
|
||||||
|
|
||||||
|
// UpdateFlags are set whenever a property changes that requires the change to be communicated to other
|
||||||
|
// data structures. It is the responsibility of the EntityTree to relay changes entity and clear flags.
|
||||||
|
uint32_t _updateFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue