mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into movables
This commit is contained in:
commit
7af3843bed
19 changed files with 169 additions and 241 deletions
|
@ -776,25 +776,8 @@ void AudioMixer::run() {
|
||||||
// if the stream should be muted, send mute packet
|
// if the stream should be muted, send mute packet
|
||||||
if (nodeData->getAvatarAudioStream()
|
if (nodeData->getAvatarAudioStream()
|
||||||
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
||||||
static const int TIME_BETWEEN_MUTES = 5; // in secs
|
QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeNoisyMute);
|
||||||
if (usecTimestampNow() - nodeData->getAvatarAudioStream()->getLastMuted() >
|
nodeList->writeDatagram(packet, node);
|
||||||
TIME_BETWEEN_MUTES * USECS_PER_SECOND) {
|
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
|
||||||
int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float);
|
|
||||||
|
|
||||||
// Fake data to force mute
|
|
||||||
glm::vec3 position = nodeData->getAvatarAudioStream()->getPosition();
|
|
||||||
float radius = 1.0f;
|
|
||||||
|
|
||||||
char* packet = (char*)malloc(packetSize);
|
|
||||||
populatePacketHeader(packet, PacketTypeMuteEnvironment);
|
|
||||||
memcpy(packet + headerSize, &position, sizeof(glm::vec3));
|
|
||||||
memcpy(packet + headerSize + sizeof(glm::vec3), &radius, sizeof(float));
|
|
||||||
|
|
||||||
nodeList->writeDatagram(packet, packetSize, node);
|
|
||||||
nodeData->getAvatarAudioStream()->setLastMutedNow();
|
|
||||||
free(packet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
#include "AvatarAudioStream.h"
|
#include "AvatarAudioStream.h"
|
||||||
|
|
||||||
AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings) :
|
AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings) :
|
||||||
PositionalAudioStream(PositionalAudioStream::Microphone, isStereo, settings),
|
PositionalAudioStream(PositionalAudioStream::Microphone, isStereo, settings)
|
||||||
_lastMuted(usecTimestampNow())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,12 @@ class AvatarAudioStream : public PositionalAudioStream {
|
||||||
public:
|
public:
|
||||||
AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings);
|
AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings);
|
||||||
|
|
||||||
qint64 getLastMuted() const { return _lastMuted; }
|
|
||||||
void setLastMutedNow() { _lastMuted = usecTimestampNow(); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disallow copying of AvatarAudioStream objects
|
// disallow copying of AvatarAudioStream objects
|
||||||
AvatarAudioStream(const AvatarAudioStream&);
|
AvatarAudioStream(const AvatarAudioStream&);
|
||||||
AvatarAudioStream& operator= (const AvatarAudioStream&);
|
AvatarAudioStream& operator= (const AvatarAudioStream&);
|
||||||
|
|
||||||
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
||||||
|
|
||||||
qint64 _lastMuted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarAudioStream_h
|
#endif // hifi_AvatarAudioStream_h
|
||||||
|
|
|
@ -99,6 +99,7 @@ Audio::Audio(QObject* parent) :
|
||||||
_muted(false),
|
_muted(false),
|
||||||
_reverb(false),
|
_reverb(false),
|
||||||
_reverbOptions(&_scriptReverbOptions),
|
_reverbOptions(&_scriptReverbOptions),
|
||||||
|
_gverbLocal(NULL),
|
||||||
_gverb(NULL),
|
_gverb(NULL),
|
||||||
_iconColor(1.0f),
|
_iconColor(1.0f),
|
||||||
_iconPulseTimeReference(usecTimestampNow()),
|
_iconPulseTimeReference(usecTimestampNow()),
|
||||||
|
@ -504,12 +505,23 @@ bool Audio::switchOutputToAudioDevice(const QString& outputDeviceName) {
|
||||||
|
|
||||||
void Audio::initGverb() {
|
void Audio::initGverb() {
|
||||||
// Initialize a new gverb instance
|
// Initialize a new gverb instance
|
||||||
|
_gverbLocal = gverb_new(_outputFormat.sampleRate(), _reverbOptions->getMaxRoomSize(), _reverbOptions->getRoomSize(),
|
||||||
|
_reverbOptions->getReverbTime(), _reverbOptions->getDamping(), _reverbOptions->getSpread(),
|
||||||
|
_reverbOptions->getInputBandwidth(), _reverbOptions->getEarlyLevel(),
|
||||||
|
_reverbOptions->getTailLevel());
|
||||||
_gverb = gverb_new(_outputFormat.sampleRate(), _reverbOptions->getMaxRoomSize(), _reverbOptions->getRoomSize(),
|
_gverb = gverb_new(_outputFormat.sampleRate(), _reverbOptions->getMaxRoomSize(), _reverbOptions->getRoomSize(),
|
||||||
_reverbOptions->getReverbTime(), _reverbOptions->getDamping(), _reverbOptions->getSpread(),
|
_reverbOptions->getReverbTime(), _reverbOptions->getDamping(), _reverbOptions->getSpread(),
|
||||||
_reverbOptions->getInputBandwidth(), _reverbOptions->getEarlyLevel(),
|
_reverbOptions->getInputBandwidth(), _reverbOptions->getEarlyLevel(),
|
||||||
_reverbOptions->getTailLevel());
|
_reverbOptions->getTailLevel());
|
||||||
|
|
||||||
// Configure the instance (these functions are not super well named - they actually set several internal variables)
|
// Configure the instance (these functions are not super well named - they actually set several internal variables)
|
||||||
|
gverb_set_roomsize(_gverbLocal, _reverbOptions->getRoomSize());
|
||||||
|
gverb_set_revtime(_gverbLocal, _reverbOptions->getReverbTime());
|
||||||
|
gverb_set_damping(_gverbLocal, _reverbOptions->getDamping());
|
||||||
|
gverb_set_inputbandwidth(_gverbLocal, _reverbOptions->getInputBandwidth());
|
||||||
|
gverb_set_earlylevel(_gverbLocal, DB_CO(_reverbOptions->getEarlyLevel()));
|
||||||
|
gverb_set_taillevel(_gverbLocal, DB_CO(_reverbOptions->getTailLevel()));
|
||||||
|
|
||||||
gverb_set_roomsize(_gverb, _reverbOptions->getRoomSize());
|
gverb_set_roomsize(_gverb, _reverbOptions->getRoomSize());
|
||||||
gverb_set_revtime(_gverb, _reverbOptions->getReverbTime());
|
gverb_set_revtime(_gverb, _reverbOptions->getReverbTime());
|
||||||
gverb_set_damping(_gverb, _reverbOptions->getDamping());
|
gverb_set_damping(_gverb, _reverbOptions->getDamping());
|
||||||
|
@ -565,25 +577,27 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioFormat) {
|
void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) {
|
||||||
float wetFraction = DB_CO(_reverbOptions->getWetLevel());
|
float wetFraction = DB_CO(_reverbOptions->getWetLevel());
|
||||||
float dryFraction = 1.0f - wetFraction;
|
float dryFraction = (noEcho) ? 0.0f : (1.0f - wetFraction);
|
||||||
|
|
||||||
float lValue,rValue;
|
float lValue,rValue;
|
||||||
for (int sample = 0; sample < numSamples; sample += audioFormat.channelCount()) {
|
for (int sample = 0; sample < numSamples; sample += audioFormat.channelCount()) {
|
||||||
// Run GVerb
|
// Run GVerb
|
||||||
float value = (float)samplesData[sample];
|
float value = (float)samplesData[sample];
|
||||||
gverb_do(_gverb, value, &lValue, &rValue);
|
gverb_do(gverb, value, &lValue, &rValue);
|
||||||
|
|
||||||
// Mix, accounting for clipping, the left and right channels. Ignore the rest.
|
// Mix, accounting for clipping, the left and right channels. Ignore the rest.
|
||||||
for (int j = sample; j < sample + audioFormat.channelCount(); j++) {
|
for (int j = sample; j < sample + audioFormat.channelCount(); j++) {
|
||||||
if (j == sample) {
|
if (j == sample) {
|
||||||
// left channel
|
// left channel
|
||||||
int lResult = glm::clamp((int)(samplesData[j] * dryFraction + lValue * wetFraction), MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
int lResult = glm::clamp((int)(samplesData[j] * dryFraction + lValue * wetFraction),
|
||||||
|
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
||||||
samplesData[j] = (int16_t)lResult;
|
samplesData[j] = (int16_t)lResult;
|
||||||
} else if (j == (sample + 1)) {
|
} else if (j == (sample + 1)) {
|
||||||
// right channel
|
// right channel
|
||||||
int rResult = glm::clamp((int)(samplesData[j] * dryFraction + rValue * wetFraction), MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
int rResult = glm::clamp((int)(samplesData[j] * dryFraction + rValue * wetFraction),
|
||||||
|
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
||||||
samplesData[j] = (int16_t)rResult;
|
samplesData[j] = (int16_t)rResult;
|
||||||
} else {
|
} else {
|
||||||
// ignore channels above 2
|
// ignore channels above 2
|
||||||
|
@ -622,23 +636,10 @@ void Audio::handleLocalEchoAndReverb(QByteArray& inputByteArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasLocalReverb) {
|
if (hasLocalReverb) {
|
||||||
QByteArray loopbackCopy;
|
|
||||||
if (!hasEcho) {
|
|
||||||
loopbackCopy = loopBackByteArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data());
|
int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data());
|
||||||
int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t);
|
int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t);
|
||||||
updateGverbOptions();
|
updateGverbOptions();
|
||||||
addReverb(loopbackSamples, numLoopbackSamples, _outputFormat);
|
addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat, !hasEcho);
|
||||||
|
|
||||||
if (!hasEcho) {
|
|
||||||
int16_t* loopbackCopySamples = reinterpret_cast<int16_t*>(loopbackCopy.data());
|
|
||||||
for (int i = 0; i < numLoopbackSamples; ++i) {
|
|
||||||
loopbackSamples[i] = glm::clamp((int)loopbackSamples[i] - loopbackCopySamples[i],
|
|
||||||
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_loopbackOutputDevice) {
|
if (_loopbackOutputDevice) {
|
||||||
|
@ -1029,7 +1030,7 @@ void Audio::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& ou
|
||||||
|
|
||||||
if(_reverb || _receivedAudioStream.hasReverb()) {
|
if(_reverb || _receivedAudioStream.hasReverb()) {
|
||||||
updateGverbOptions();
|
updateGverbOptions();
|
||||||
addReverb((int16_t*)outputBuffer.data(), numDeviceOutputSamples, _outputFormat);
|
addReverb(_gverb, (int16_t*)outputBuffer.data(), numDeviceOutputSamples, _outputFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,6 +248,7 @@ private:
|
||||||
AudioEffectOptions _scriptReverbOptions;
|
AudioEffectOptions _scriptReverbOptions;
|
||||||
AudioEffectOptions _zoneReverbOptions;
|
AudioEffectOptions _zoneReverbOptions;
|
||||||
AudioEffectOptions* _reverbOptions;
|
AudioEffectOptions* _reverbOptions;
|
||||||
|
ty_gverb* _gverbLocal;
|
||||||
ty_gverb* _gverb;
|
ty_gverb* _gverb;
|
||||||
GLuint _micTextureId;
|
GLuint _micTextureId;
|
||||||
GLuint _muteTextureId;
|
GLuint _muteTextureId;
|
||||||
|
@ -269,7 +270,7 @@ private:
|
||||||
// Adds Reverb
|
// Adds Reverb
|
||||||
void initGverb();
|
void initGverb();
|
||||||
void updateGverbOptions();
|
void updateGverbOptions();
|
||||||
void addReverb(int16_t* samples, int numSamples, QAudioFormat& format);
|
void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false);
|
||||||
|
|
||||||
void handleLocalEchoAndReverb(QByteArray& inputByteArray);
|
void handleLocalEchoAndReverb(QByteArray& inputByteArray);
|
||||||
|
|
||||||
|
|
|
@ -141,17 +141,29 @@ void DatagramProcessor::processDatagrams() {
|
||||||
AccountManager::getInstance().checkAndSignalForAccessToken();
|
AccountManager::getInstance().checkAndSignalForAccessToken();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PacketTypeNoisyMute:
|
||||||
case PacketTypeMuteEnvironment: {
|
case PacketTypeMuteEnvironment: {
|
||||||
glm::vec3 position;
|
bool mute = !Application::getInstance()->getAudio()->getMuted();
|
||||||
float radius;
|
|
||||||
|
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
if (incomingType == PacketTypeMuteEnvironment) {
|
||||||
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
glm::vec3 position;
|
||||||
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
float radius, distance;
|
||||||
|
|
||||||
|
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
||||||
|
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
||||||
|
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
||||||
|
distance = glm::distance(Application::getInstance()->getAvatar()->getPosition(), position);
|
||||||
|
|
||||||
|
mute = mute && (distance < radius);
|
||||||
|
}
|
||||||
|
|
||||||
if (glm::distance(Application::getInstance()->getAvatar()->getPosition(), position) < radius
|
if (mute) {
|
||||||
&& !Application::getInstance()->getAudio()->getMuted()) {
|
|
||||||
Application::getInstance()->getAudio()->toggleMute();
|
Application::getInstance()->getAudio()->toggleMute();
|
||||||
|
if (incomingType == PacketTypeMuteEnvironment) {
|
||||||
|
AudioScriptingInterface::getInstance().environmentMuted();
|
||||||
|
} else {
|
||||||
|
AudioScriptingInterface::getInstance().mutedByMixer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,8 +246,7 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderableModelEntityItem::needsSimulation() const {
|
bool RenderableModelEntityItem::needsSimulation() const {
|
||||||
SimulationState simulationState = getSimulationState();
|
return _needsInitialSimulation || getSimulationState() == EntityItem::Moving;
|
||||||
return _needsInitialSimulation || simulationState == Moving || simulationState == Changing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
||||||
|
|
|
@ -37,6 +37,10 @@ public slots:
|
||||||
|
|
||||||
void injectorStopped();
|
void injectorStopped();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mutedByMixer();
|
||||||
|
void environmentMuted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AudioScriptingInterface();
|
AudioScriptingInterface();
|
||||||
QList< QPointer<AudioInjector> > _activeInjectors;
|
QList< QPointer<AudioInjector> > _activeInjectors;
|
||||||
|
|
|
@ -94,4 +94,4 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst
|
||||||
bool successPropertyFits = true;
|
bool successPropertyFits = true;
|
||||||
|
|
||||||
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
|
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
||||||
_created = 0;
|
_created = 0;
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
|
_simulationState = EntityItem::Static;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) {
|
EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) {
|
||||||
|
@ -104,6 +105,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
setProperties(properties, true); // force copy
|
setProperties(properties, true); // force copy
|
||||||
|
_simulationState = EntityItem::Static;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
||||||
|
@ -404,7 +406,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
qDebug() << " fromSameServerEdit=" << fromSameServerEdit;
|
qDebug() << " fromSameServerEdit=" << fromSameServerEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ignoreServerPacket = false; // assume we're use this server packet
|
bool ignoreServerPacket = false; // assume we'll use this server packet
|
||||||
|
|
||||||
// If this packet is from the same server edit as the last packet we accepted from the server
|
// If this packet is from the same server edit as the last packet we accepted from the server
|
||||||
// we probably want to use it.
|
// we probably want to use it.
|
||||||
|
@ -715,13 +717,10 @@ void EntityItem::update(const quint64& updateTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItem::SimulationState EntityItem::getSimulationState() const {
|
EntityItem::SimulationState EntityItem::computeSimulationState() const {
|
||||||
if (hasVelocity() || (hasGravity() && !isRestingOnSurface())) {
|
if (hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity()) {
|
||||||
return EntityItem::Moving;
|
return EntityItem::Moving;
|
||||||
}
|
}
|
||||||
if (hasAngularVelocity()) {
|
|
||||||
return EntityItem::Changing;
|
|
||||||
}
|
|
||||||
if (isMortal()) {
|
if (isMortal()) {
|
||||||
return EntityItem::Mortal;
|
return EntityItem::Mortal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "EntityItemProperties.h"
|
#include "EntityItemProperties.h"
|
||||||
#include "EntityTypes.h"
|
#include "EntityTypes.h"
|
||||||
|
|
||||||
|
class EntityTree;
|
||||||
class EntityTreeElement;
|
class EntityTreeElement;
|
||||||
class EntityTreeElementExtraEncodeData;
|
class EntityTreeElementExtraEncodeData;
|
||||||
|
|
||||||
|
@ -59,10 +60,10 @@ public:
|
||||||
// methods for getting/setting all properties of an entity
|
// methods for getting/setting all properties of an entity
|
||||||
virtual EntityItemProperties getProperties() const;
|
virtual EntityItemProperties getProperties() const;
|
||||||
|
|
||||||
/// returns true is something changed
|
/// returns true if something changed
|
||||||
virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false);
|
virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false);
|
||||||
|
|
||||||
/// override this in your derived class if you'd like to be informed when something about the state of the entity
|
/// Override this in your derived class if you'd like to be informed when something about the state of the entity
|
||||||
/// has changed. This will be called with properties change or when new data is loaded from a stream
|
/// has changed. This will be called with properties change or when new data is loaded from a stream
|
||||||
virtual void somethingChangedNotification() { }
|
virtual void somethingChangedNotification() { }
|
||||||
|
|
||||||
|
@ -115,11 +116,13 @@ public:
|
||||||
typedef enum SimulationState_t {
|
typedef enum SimulationState_t {
|
||||||
Static,
|
Static,
|
||||||
Mortal,
|
Mortal,
|
||||||
Changing,
|
|
||||||
Moving
|
Moving
|
||||||
} SimulationState;
|
} SimulationState;
|
||||||
|
|
||||||
virtual SimulationState getSimulationState() const;
|
// computes the SimulationState that the entity SHOULD be in.
|
||||||
|
// Use getSimulationState() to find the state under which it is currently categorized.
|
||||||
|
virtual SimulationState computeSimulationState() const;
|
||||||
|
|
||||||
virtual void debugDump() const;
|
virtual void debugDump() const;
|
||||||
|
|
||||||
// similar to assignment/copy, but it handles keeping lifetime accurate
|
// similar to assignment/copy, but it handles keeping lifetime accurate
|
||||||
|
@ -262,8 +265,13 @@ public:
|
||||||
void applyHardCollision(const CollisionInfo& collisionInfo);
|
void applyHardCollision(const CollisionInfo& collisionInfo);
|
||||||
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); }
|
||||||
|
|
||||||
|
SimulationState getSimulationState() const { return _simulationState; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
friend class EntityTree;
|
||||||
|
void setSimulationState(SimulationState state) { _simulationState = state; }
|
||||||
|
|
||||||
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
||||||
virtual void recalculateCollisionShape();
|
virtual void recalculateCollisionShape();
|
||||||
|
|
||||||
|
@ -305,6 +313,7 @@ protected:
|
||||||
void setRadius(float value);
|
void setRadius(float value);
|
||||||
|
|
||||||
AACubeShape _collisionShape;
|
AACubeShape _collisionShape;
|
||||||
|
SimulationState _simulationState; // only set by EntityTree
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
|
||||||
_entityToElementMap.clear();
|
_entityToElementMap.clear();
|
||||||
Octree::eraseAllOctreeElements(createNewRoot);
|
Octree::eraseAllOctreeElements(createNewRoot);
|
||||||
_movingEntities.clear();
|
_movingEntities.clear();
|
||||||
_changingEntities.clear();
|
|
||||||
_mortalEntities.clear();
|
_mortalEntities.clear();
|
||||||
|
_changedEntities.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityTree::handlesEditPacketType(PacketType packetType) const {
|
bool EntityTree::handlesEditPacketType(PacketType packetType) const {
|
||||||
|
@ -80,7 +80,7 @@ void EntityTree::addEntityItem(EntityItem* entityItem) {
|
||||||
EntityItemID entityID = entityItem->getEntityItemID();
|
EntityItemID entityID = entityItem->getEntityItemID();
|
||||||
EntityTreeElement* containingElement = getContainingElement(entityID);
|
EntityTreeElement* containingElement = getContainingElement(entityID);
|
||||||
if (containingElement) {
|
if (containingElement) {
|
||||||
qDebug() << "UNEXPECTED!!!! don't call addEntityItem() on existing entity items. entityID=" << entityID;
|
qDebug() << "UNEXPECTED!!!! don't call addEntityItem() on existing EntityItems. entityID=" << entityID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void EntityTree::addEntityItem(EntityItem* entityItem) {
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
|
|
||||||
// check to see if we need to simulate this entity..
|
// check to see if we need to simulate this entity..
|
||||||
changeEntityState(entityItem, EntityItem::Static, entityItem->getSimulationState());
|
updateEntityState(entityItem);
|
||||||
|
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
}
|
}
|
||||||
|
@ -123,15 +123,13 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check to see if we need to simulate this entity...
|
// check to see if we need to simulate this entity...
|
||||||
EntityItem::SimulationState oldState = existingEntity->getSimulationState();
|
|
||||||
QString entityScriptBefore = existingEntity->getScript();
|
QString entityScriptBefore = existingEntity->getScript();
|
||||||
|
|
||||||
UpdateEntityOperator theOperator(this, containingElement, existingEntity, properties);
|
UpdateEntityOperator theOperator(this, containingElement, existingEntity, properties);
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
|
||||||
EntityItem::SimulationState newState = existingEntity->getSimulationState();
|
updateEntityState(existingEntity);
|
||||||
changeEntityState(existingEntity, oldState, newState);
|
|
||||||
|
|
||||||
QString entityScriptAfter = existingEntity->getScript();
|
QString entityScriptAfter = existingEntity->getScript();
|
||||||
if (entityScriptBefore != entityScriptAfter) {
|
if (entityScriptBefore != entityScriptAfter) {
|
||||||
|
@ -229,10 +227,6 @@ void EntityTree::removeEntityFromSimulationLists(const EntityItemID& entityID) {
|
||||||
// make sure to remove it from any of our simulation lists
|
// make sure to remove it from any of our simulation lists
|
||||||
EntityItem::SimulationState theState = theEntity->getSimulationState();
|
EntityItem::SimulationState theState = theEntity->getSimulationState();
|
||||||
switch (theState) {
|
switch (theState) {
|
||||||
case EntityItem::Changing:
|
|
||||||
_changingEntities.removeAll(theEntity);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EntityItem::Moving:
|
case EntityItem::Moving:
|
||||||
_movingEntities.removeAll(theEntity);
|
_movingEntities.removeAll(theEntity);
|
||||||
break;
|
break;
|
||||||
|
@ -244,6 +238,7 @@ void EntityTree::removeEntityFromSimulationLists(const EntityItemID& entityID) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
_changedEntities.remove(theEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,7 +513,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
|
||||||
// search for the entity by EntityItemID
|
// search for the entity by EntityItemID
|
||||||
EntityItem* existingEntity = findEntityByEntityItemID(entityItemID);
|
EntityItem* existingEntity = findEntityByEntityItemID(entityItemID);
|
||||||
|
|
||||||
// if the entityItem exists, then update it
|
// if the EntityItem exists, then update it
|
||||||
if (existingEntity) {
|
if (existingEntity) {
|
||||||
updateEntity(entityItemID, properties);
|
updateEntity(entityItemID, properties);
|
||||||
existingEntity->markAsChangedOnServer();
|
existingEntity->markAsChangedOnServer();
|
||||||
|
@ -580,15 +575,42 @@ void EntityTree::releaseSceneEncodeData(OctreeElementExtraEncodeData* extraEncod
|
||||||
extraEncodeData->clear();
|
extraEncodeData->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::changeEntityState(EntityItem* const entity,
|
void EntityTree::updateEntityState(EntityItem* entity) {
|
||||||
EntityItem::SimulationState oldState, EntityItem::SimulationState newState) {
|
EntityItem::SimulationState oldState = entity->getSimulationState();
|
||||||
|
EntityItem::SimulationState newState = entity->computeSimulationState();
|
||||||
|
if (newState != oldState) {
|
||||||
|
switch (oldState) {
|
||||||
|
case EntityItem::Moving:
|
||||||
|
_movingEntities.removeAll(entity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EntityItem::Mortal:
|
||||||
|
_mortalEntities.removeAll(entity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (newState) {
|
||||||
|
case EntityItem::Moving:
|
||||||
|
_movingEntities.push_back(entity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EntityItem::Mortal:
|
||||||
|
_mortalEntities.push_back(entity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
entity->setSimulationState(newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: can we short circuit this if the state isn't changing?
|
void EntityTree::clearEntityState(EntityItem* entity) {
|
||||||
|
EntityItem::SimulationState oldState = entity->getSimulationState();
|
||||||
switch (oldState) {
|
switch (oldState) {
|
||||||
case EntityItem::Changing:
|
|
||||||
_changingEntities.removeAll(entity);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EntityItem::Moving:
|
case EntityItem::Moving:
|
||||||
_movingEntities.removeAll(entity);
|
_movingEntities.removeAll(entity);
|
||||||
break;
|
break;
|
||||||
|
@ -600,24 +622,11 @@ void EntityTree::changeEntityState(EntityItem* const entity,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
entity->setSimulationState(EntityItem::Static);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTree::entityChanged(EntityItem* entity) {
|
||||||
switch (newState) {
|
_changedEntities.insert(entity);
|
||||||
case EntityItem::Changing:
|
|
||||||
_changingEntities.push_back(entity);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EntityItem::Moving:
|
|
||||||
_movingEntities.push_back(entity);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EntityItem::Mortal:
|
|
||||||
_mortalEntities.push_back(entity);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::update() {
|
void EntityTree::update() {
|
||||||
|
@ -633,7 +642,7 @@ void EntityTree::update() {
|
||||||
lockForWrite();
|
lockForWrite();
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
QSet<EntityItemID> entitiesToDelete;
|
QSet<EntityItemID> entitiesToDelete;
|
||||||
updateChangingEntities(now, entitiesToDelete);
|
updateChangedEntities(now, entitiesToDelete);
|
||||||
updateMovingEntities(now, entitiesToDelete);
|
updateMovingEntities(now, entitiesToDelete);
|
||||||
updateMortalEntities(now, entitiesToDelete);
|
updateMortalEntities(now, entitiesToDelete);
|
||||||
|
|
||||||
|
@ -643,55 +652,25 @@ void EntityTree::update() {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::updateChangingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
void EntityTree::updateChangedEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
||||||
QSet<EntityItem*> entitiesBecomingStatic;
|
|
||||||
QSet<EntityItem*> entitiesBecomingMortal;
|
|
||||||
QSet<EntityItem*> entitiesBecomingMoving;
|
|
||||||
|
|
||||||
// TODO: switch these to iterators so we can remove items that get deleted
|
// TODO: switch these to iterators so we can remove items that get deleted
|
||||||
for (int i = 0; i < _changingEntities.size(); i++) {
|
foreach (EntityItem* thisEntity, _changedEntities) {
|
||||||
EntityItem* thisEntity = _changingEntities[i];
|
// check to see if the lifetime has expired, for immortal entities this is always false
|
||||||
thisEntity->update(now);
|
|
||||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
qDebug() << "Lifetime has expired for thisEntity:" << thisEntity->getEntityItemID();
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
entitiesBecomingStatic << thisEntity;
|
clearEntityState(thisEntity);
|
||||||
} else {
|
} else {
|
||||||
// check to see if this entity is no longer moving
|
updateEntityState(thisEntity);
|
||||||
EntityItem::SimulationState newState = thisEntity->getSimulationState();
|
|
||||||
|
|
||||||
if (newState == EntityItem::Static) {
|
|
||||||
entitiesBecomingStatic << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Mortal) {
|
|
||||||
entitiesBecomingMortal << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Moving) {
|
|
||||||
entitiesBecomingMoving << thisEntity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_changedEntities.clear();
|
||||||
// change state for any entities that were changing but are now either static, mortal, or moving
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingStatic) {
|
|
||||||
changeEntityState(entity, EntityItem::Changing, EntityItem::Static);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingMortal) {
|
|
||||||
changeEntityState(entity, EntityItem::Changing, EntityItem::Mortal);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingMoving) {
|
|
||||||
changeEntityState(entity, EntityItem::Changing, EntityItem::Moving);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
||||||
PerformanceTimer perfTimer("updateMovingEntities");
|
PerformanceTimer perfTimer("updateMovingEntities");
|
||||||
if (_movingEntities.size() > 0) {
|
if (_movingEntities.size() > 0) {
|
||||||
MovingEntitiesOperator moveOperator(this);
|
MovingEntitiesOperator moveOperator(this);
|
||||||
|
|
||||||
QSet<EntityItem*> entitiesBecomingStatic;
|
|
||||||
QSet<EntityItem*> entitiesBecomingMortal;
|
|
||||||
QSet<EntityItem*> entitiesBecomingChanging;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("_movingEntities");
|
PerformanceTimer perfTimer("_movingEntities");
|
||||||
|
|
||||||
|
@ -703,7 +682,7 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
entitiesBecomingStatic << thisEntity;
|
clearEntityState(thisEntity);
|
||||||
} else {
|
} else {
|
||||||
AACube oldCube = thisEntity->getMaximumAACube();
|
AACube oldCube = thisEntity->getMaximumAACube();
|
||||||
thisEntity->update(now);
|
thisEntity->update(now);
|
||||||
|
@ -714,19 +693,10 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
if (!domainBounds.touches(newCube)) {
|
if (!domainBounds.touches(newCube)) {
|
||||||
qDebug() << "Entity " << thisEntity->getEntityItemID() << " moved out of domain bounds.";
|
qDebug() << "Entity " << thisEntity->getEntityItemID() << " moved out of domain bounds.";
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
entitiesBecomingStatic << thisEntity;
|
clearEntityState(thisEntity);
|
||||||
} else {
|
} else {
|
||||||
moveOperator.addEntityToMoveList(thisEntity, oldCube, newCube);
|
moveOperator.addEntityToMoveList(thisEntity, oldCube, newCube);
|
||||||
|
updateEntityState(thisEntity);
|
||||||
// check to see if this entity is no longer moving
|
|
||||||
EntityItem::SimulationState newState = thisEntity->getSimulationState();
|
|
||||||
if (newState == EntityItem::Changing) {
|
|
||||||
entitiesBecomingChanging << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Mortal) {
|
|
||||||
entitiesBecomingMortal << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Static) {
|
|
||||||
entitiesBecomingStatic << thisEntity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -735,25 +705,10 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
PerformanceTimer perfTimer("recurseTreeWithOperator");
|
PerformanceTimer perfTimer("recurseTreeWithOperator");
|
||||||
recurseTreeWithOperator(&moveOperator);
|
recurseTreeWithOperator(&moveOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// change state for any entities that were moving but are now either static, mortal, or changing
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingStatic) {
|
|
||||||
changeEntityState(entity, EntityItem::Moving, EntityItem::Static);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingMortal) {
|
|
||||||
changeEntityState(entity, EntityItem::Moving, EntityItem::Mortal);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingChanging) {
|
|
||||||
changeEntityState(entity, EntityItem::Moving, EntityItem::Changing);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
void EntityTree::updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
||||||
QSet<EntityItem*> entitiesBecomingStatic;
|
|
||||||
QSet<EntityItem*> entitiesBecomingChanging;
|
|
||||||
QSet<EntityItem*> entitiesBecomingMoving;
|
|
||||||
|
|
||||||
// TODO: switch these to iterators so we can remove items that get deleted
|
// TODO: switch these to iterators so we can remove items that get deleted
|
||||||
for (int i = 0; i < _mortalEntities.size(); i++) {
|
for (int i = 0; i < _mortalEntities.size(); i++) {
|
||||||
EntityItem* thisEntity = _mortalEntities[i];
|
EntityItem* thisEntity = _mortalEntities[i];
|
||||||
|
@ -762,31 +717,12 @@ void EntityTree::updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
entitiesBecomingStatic << thisEntity;
|
clearEntityState(thisEntity);
|
||||||
} else {
|
} else {
|
||||||
// check to see if this entity is no longer moving
|
// check to see if this entity is no longer moving
|
||||||
EntityItem::SimulationState newState = thisEntity->getSimulationState();
|
updateEntityState(thisEntity);
|
||||||
|
|
||||||
if (newState == EntityItem::Static) {
|
|
||||||
entitiesBecomingStatic << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Changing) {
|
|
||||||
entitiesBecomingChanging << thisEntity;
|
|
||||||
} else if (newState == EntityItem::Moving) {
|
|
||||||
entitiesBecomingMoving << thisEntity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// change state for any entities that were mortal but are now either static, changing, or moving
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingStatic) {
|
|
||||||
changeEntityState(entity, EntityItem::Mortal, EntityItem::Static);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingChanging) {
|
|
||||||
changeEntityState(entity, EntityItem::Mortal, EntityItem::Changing);
|
|
||||||
}
|
|
||||||
foreach(EntityItem* entity, entitiesBecomingMoving) {
|
|
||||||
changeEntityState(entity, EntityItem::Mortal, EntityItem::Moving);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#ifndef hifi_EntityTree_h
|
#ifndef hifi_EntityTree_h
|
||||||
#define hifi_EntityTree_h
|
#define hifi_EntityTree_h
|
||||||
|
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
#include <Octree.h>
|
#include <Octree.h>
|
||||||
#include "EntityTreeElement.h"
|
#include "EntityTreeElement.h"
|
||||||
|
|
||||||
|
@ -135,8 +137,10 @@ public:
|
||||||
|
|
||||||
void sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z);
|
void sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z);
|
||||||
|
|
||||||
void changeEntityState(EntityItem* const entity,
|
void updateEntityState(EntityItem* entity);
|
||||||
EntityItem::SimulationState oldState, EntityItem::SimulationState newState);
|
void clearEntityState(EntityItem* entity);
|
||||||
|
|
||||||
|
void entityChanged(EntityItem* entity);
|
||||||
|
|
||||||
void trackDeletedEntity(const EntityItemID& entityID);
|
void trackDeletedEntity(const EntityItemID& entityID);
|
||||||
|
|
||||||
|
@ -153,7 +157,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void updateChangingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
void updateChangedEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
||||||
void updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
void updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
||||||
void updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
void updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete);
|
||||||
|
|
||||||
|
@ -173,9 +177,10 @@ private:
|
||||||
|
|
||||||
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
|
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
|
||||||
|
|
||||||
QList<EntityItem*> _movingEntities; // entities that are moving as part of update
|
QList<EntityItem*> _movingEntities; // entities that need to be updated
|
||||||
QList<EntityItem*> _changingEntities; // entities that are changing (like animating), but not moving
|
QList<EntityItem*> _mortalEntities; // entities that need to be checked for expiry
|
||||||
QList<EntityItem*> _mortalEntities; // entities that are mortal (have lifetime), but not moving or changing
|
|
||||||
|
QSet<EntityItem*> _changedEntities; // entities that have changed in the last frame
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityTree_h
|
#endif // hifi_EntityTree_h
|
||||||
|
|
|
@ -737,14 +737,10 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
||||||
QString entityScriptBefore = entityItem->getScript();
|
QString entityScriptBefore = entityItem->getScript();
|
||||||
bool bestFitBefore = bestFitEntityBounds(entityItem);
|
bool bestFitBefore = bestFitEntityBounds(entityItem);
|
||||||
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
|
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
|
||||||
EntityItem::SimulationState oldState = entityItem->getSimulationState();
|
|
||||||
|
|
||||||
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
|
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
|
||||||
|
// TODO: Andrew to only set changed if something has actually changed
|
||||||
EntityItem::SimulationState newState = entityItem->getSimulationState();
|
_myTree->entityChanged(entityItem);
|
||||||
if (oldState != newState) {
|
|
||||||
_myTree->changeEntityState(entityItem, oldState, newState);
|
|
||||||
}
|
|
||||||
bool bestFitAfter = bestFitEntityBounds(entityItem);
|
bool bestFitAfter = bestFitEntityBounds(entityItem);
|
||||||
|
|
||||||
if (bestFitBefore != bestFitAfter) {
|
if (bestFitBefore != bestFitAfter) {
|
||||||
|
@ -771,9 +767,8 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
||||||
addEntityItem(entityItem); // add this new entity to this elements entities
|
addEntityItem(entityItem); // add this new entity to this elements entities
|
||||||
entityItemID = entityItem->getEntityItemID();
|
entityItemID = entityItem->getEntityItemID();
|
||||||
_myTree->setContainingElement(entityItemID, this);
|
_myTree->setContainingElement(entityItemID, this);
|
||||||
|
_myTree->updateEntityState(entityItem);
|
||||||
_myTree->emitAddingEntity(entityItemID); // we just added an entity
|
_myTree->emitAddingEntity(entityItemID); // we just added an entity
|
||||||
EntityItem::SimulationState newState = entityItem->getSimulationState();
|
|
||||||
_myTree->changeEntityState(entityItem, EntityItem::Static, newState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move the buffer forward to read more entities
|
// Move the buffer forward to read more entities
|
||||||
|
|
|
@ -371,15 +371,15 @@ bool ModelEntityItem::isAnimatingSomething() const {
|
||||||
!getAnimationURL().isEmpty();
|
!getAnimationURL().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItem::SimulationState ModelEntityItem::getSimulationState() const {
|
EntityItem::SimulationState ModelEntityItem::computeSimulationState() const {
|
||||||
EntityItem::SimulationState baseClassState = EntityItem::getSimulationState();
|
EntityItem::SimulationState baseClassState = EntityItem::computeSimulationState();
|
||||||
|
|
||||||
// if the base class is static, then consider our animation state, and upgrade to changing if
|
// if the base class is static, then consider our animation state, and upgrade to changing if
|
||||||
// we are animating. If the base class has a higher simulation state than static, then
|
// we are animating. If the base class has a higher simulation state than static, then
|
||||||
// use the base class state.
|
// use the base class state.
|
||||||
if (baseClassState == EntityItem::Static) {
|
if (baseClassState == EntityItem::Static) {
|
||||||
if (isAnimatingSomething()) {
|
if (isAnimatingSomething()) {
|
||||||
return EntityItem::Changing;
|
return EntityItem::Moving;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baseClassState;
|
return baseClassState;
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
|
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
|
||||||
|
|
||||||
virtual void update(const quint64& now);
|
virtual void update(const quint64& now);
|
||||||
virtual SimulationState getSimulationState() const;
|
virtual SimulationState computeSimulationState() const;
|
||||||
virtual void debugDump() const;
|
virtual void debugDump() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ enum PacketType {
|
||||||
UNUSED_2,
|
UNUSED_2,
|
||||||
UNUSED_3,
|
UNUSED_3,
|
||||||
UNUSED_4,
|
UNUSED_4,
|
||||||
UNUSED_5,
|
PacketTypeNoisyMute,
|
||||||
PacketTypeMetavoxelData,
|
PacketTypeMetavoxelData,
|
||||||
PacketTypeAvatarIdentity,
|
PacketTypeAvatarIdentity,
|
||||||
PacketTypeAvatarBillboard,
|
PacketTypeAvatarBillboard,
|
||||||
|
|
|
@ -289,36 +289,26 @@ int Octree::readElementData(OctreeElement* destinationElement, const unsigned ch
|
||||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||||
// check the colors mask to see if we have a child to color in
|
// check the colors mask to see if we have a child to color in
|
||||||
if (oneAtBit(colorInPacketMask, i)) {
|
if (oneAtBit(colorInPacketMask, i)) {
|
||||||
// create the child if it doesn't exist
|
// addChildAtIndex() should actually be called getOrAddChildAtIndex().
|
||||||
if (!destinationElement->getChildAtIndex(i)) {
|
// When it adds the child it automatically sets the detinationElement dirty.
|
||||||
destinationElement->addChildAtIndex(i);
|
OctreeElement* childElementAt = destinationElement->addChildAtIndex(i);
|
||||||
if (destinationElement->isDirty()) {
|
|
||||||
_isDirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OctreeElement* childElementAt = destinationElement->getChildAtIndex(i);
|
int childElementDataRead = childElementAt->readElementDataFromBuffer(nodeData + bytesRead, bytesLeftToRead, args);
|
||||||
bool nodeIsDirty = false;
|
childElementAt->setSourceUUID(args.sourceUUID);
|
||||||
if (childElementAt) {
|
|
||||||
|
bytesRead += childElementDataRead;
|
||||||
|
bytesLeftToRead -= childElementDataRead;
|
||||||
|
|
||||||
int childElementDataRead = childElementAt->readElementDataFromBuffer(nodeData + bytesRead, bytesLeftToRead, args);
|
// It's possible that we already had this version of element data, in which case the unpacking of the data
|
||||||
childElementAt->setSourceUUID(args.sourceUUID);
|
// wouldn't flag childElementAt as dirty, so we manually flag it here... if the element is to be rendered.
|
||||||
|
if (childElementAt->getShouldRender() && !childElementAt->isRendered()) {
|
||||||
bytesRead += childElementDataRead;
|
childElementAt->setDirtyBit(); // force dirty!
|
||||||
bytesLeftToRead -= childElementDataRead;
|
|
||||||
|
|
||||||
// if we had a local version of the element already, it's possible that we have it already but
|
|
||||||
// with the same color data, so this won't count as a change. To address this we check the following
|
|
||||||
if (!childElementAt->isDirty() && childElementAt->getShouldRender() && !childElementAt->isRendered()) {
|
|
||||||
childElementAt->setDirtyBit(); // force dirty!
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeIsDirty = childElementAt->isDirty();
|
|
||||||
}
|
|
||||||
if (nodeIsDirty) {
|
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (destinationElement->isDirty()) {
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char childrenInTreeMask = ALL_CHILDREN_ASSUMED_TO_EXIST;
|
unsigned char childrenInTreeMask = ALL_CHILDREN_ASSUMED_TO_EXIST;
|
||||||
|
|
|
@ -92,7 +92,7 @@ public:
|
||||||
PropertyFlags operator<<(Enum flag) const;
|
PropertyFlags operator<<(Enum flag) const;
|
||||||
|
|
||||||
// NOTE: due to the nature of the compact storage of these property flags, and the fact that the upper bound of the
|
// NOTE: due to the nature of the compact storage of these property flags, and the fact that the upper bound of the
|
||||||
// enum is not know, these operators will only perform their bitwise operations on the set of properties that have
|
// enum is not known, these operators will only perform their bitwise operations on the set of properties that have
|
||||||
// been previously set
|
// been previously set
|
||||||
PropertyFlags& operator^=(const PropertyFlags& other);
|
PropertyFlags& operator^=(const PropertyFlags& other);
|
||||||
PropertyFlags& operator^=(Enum flag);
|
PropertyFlags& operator^=(Enum flag);
|
||||||
|
@ -106,7 +106,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void shinkIfNeeded();
|
void shrinkIfNeeded();
|
||||||
|
|
||||||
QBitArray _flags;
|
QBitArray _flags;
|
||||||
int _maxFlag;
|
int _maxFlag;
|
||||||
|
@ -142,7 +142,7 @@ template<typename Enum> inline void PropertyFlags<Enum>::setHasProperty(Enum fla
|
||||||
_flags.setBit(flag, value);
|
_flags.setBit(flag, value);
|
||||||
|
|
||||||
if (flag == _maxFlag && !value) {
|
if (flag == _maxFlag && !value) {
|
||||||
shinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,27 +274,27 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
|
||||||
|
|
||||||
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(const PropertyFlags& other) {
|
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(const PropertyFlags& other) {
|
||||||
_flags &= other._flags;
|
_flags &= other._flags;
|
||||||
shinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(Enum flag) {
|
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(Enum flag) {
|
||||||
PropertyFlags other(flag);
|
PropertyFlags other(flag);
|
||||||
_flags &= other._flags;
|
_flags &= other._flags;
|
||||||
shinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(const PropertyFlags& other) {
|
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(const PropertyFlags& other) {
|
||||||
_flags ^= other._flags;
|
_flags ^= other._flags;
|
||||||
shinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(Enum flag) {
|
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(Enum flag) {
|
||||||
PropertyFlags other(flag);
|
PropertyFlags other(flag);
|
||||||
_flags ^= other._flags;
|
_flags ^= other._flags;
|
||||||
shinkIfNeeded();
|
shrinkIfNeeded();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Enum> inline void PropertyFlags<Enum>::shinkIfNeeded() {
|
template<typename Enum> inline void PropertyFlags<Enum>::shrinkIfNeeded() {
|
||||||
int maxFlagWas = _maxFlag;
|
int maxFlagWas = _maxFlag;
|
||||||
while (_maxFlag >= 0) {
|
while (_maxFlag >= 0) {
|
||||||
if (_flags.testBit(_maxFlag)) {
|
if (_flags.testBit(_maxFlag)) {
|
||||||
|
|
Loading…
Reference in a new issue