Merge branch 'master' of https://github.com/worklist/hifi into 19461

This commit is contained in:
Stojce Slavkovski 2013-12-17 22:11:29 +01:00
commit 3e1c857a2e
14 changed files with 154 additions and 93 deletions

View file

@ -3484,13 +3484,13 @@ void Application::displayStats() {
// iterate all the current voxel stats, and list their sending modes, and total voxel counts
std::stringstream sendingMode("");
sendingMode << "Voxel Sending Mode: [";
sendingMode << "Octree Sending Mode: [";
int serverCount = 0;
int movingServerCount = 0;
unsigned long totalNodes = 0;
unsigned long totalInternal = 0;
unsigned long totalLeaves = 0;
for(NodeToVoxelSceneStatsIterator i = _voxelServerSceneStats.begin(); i != _voxelServerSceneStats.end(); i++) {
for(NodeToVoxelSceneStatsIterator i = _octreeServerSceneStats.begin(); i != _octreeServerSceneStats.end(); i++) {
//const QUuid& uuid = i->first;
VoxelSceneStats& stats = i->second;
serverCount++;
@ -4138,7 +4138,7 @@ void Application::domainChanged(QString domain) {
// reset our node to stats and node to jurisdiction maps... since these must be changing...
_voxelServerJurisdictions.clear();
_voxelServerSceneStats.clear();
_octreeServerSceneStats.clear();
_particleServerJurisdictions.clear();
}
@ -4173,8 +4173,8 @@ void Application::nodeKilled(Node* node) {
// also clean up scene stats for that server
_voxelSceneStatsLock.lockForWrite();
if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) {
_voxelServerSceneStats.erase(nodeUUID);
if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) {
_octreeServerSceneStats.erase(nodeUUID);
}
_voxelSceneStatsLock.unlock();
@ -4204,8 +4204,8 @@ void Application::nodeKilled(Node* node) {
// also clean up scene stats for that server
_voxelSceneStatsLock.lockForWrite();
if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) {
_voxelServerSceneStats.erase(nodeUUID);
if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) {
_octreeServerSceneStats.erase(nodeUUID);
}
_voxelSceneStatsLock.unlock();
@ -4232,8 +4232,8 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m
// now that we know the node ID, let's add these stats to the stats for that node...
_voxelSceneStatsLock.lockForWrite();
if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) {
VoxelSceneStats& stats = _voxelServerSceneStats[nodeUUID];
if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) {
VoxelSceneStats& stats = _octreeServerSceneStats[nodeUUID];
stats.trackIncomingOctreePacket(messageData, messageLength, wasStatsPacket);
}
_voxelSceneStatsLock.unlock();
@ -4256,10 +4256,10 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen
// now that we know the node ID, let's add these stats to the stats for that node...
_voxelSceneStatsLock.lockForWrite();
if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) {
_voxelServerSceneStats[nodeUUID].unpackFromMessage(messageData, messageLength);
if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) {
_octreeServerSceneStats[nodeUUID].unpackFromMessage(messageData, messageLength);
} else {
_voxelServerSceneStats[nodeUUID] = temp;
_octreeServerSceneStats[nodeUUID] = temp;
}
_voxelSceneStatsLock.unlock();

View file

@ -157,7 +157,7 @@ public:
QSettings* getSettings() { return _settings; }
Swatch* getSwatch() { return &_swatch; }
QMainWindow* getWindow() { return _window; }
NodeToVoxelSceneStats* getVoxelSceneStats() { return &_voxelServerSceneStats; }
NodeToVoxelSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
void lockVoxelSceneStats() { _voxelSceneStatsLock.lockForRead(); }
void unlockVoxelSceneStats() { _voxelSceneStatsLock.unlock(); }
@ -199,6 +199,7 @@ public:
glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); }
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; }
void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination);
/// set a voxel which is to be rendered with a highlight
@ -493,7 +494,7 @@ private:
NodeToJurisdictionMap _voxelServerJurisdictions;
NodeToJurisdictionMap _particleServerJurisdictions;
NodeToVoxelSceneStats _voxelServerSceneStats;
NodeToVoxelSceneStats _octreeServerSceneStats;
QReadWriteLock _voxelSceneStatsLock;
std::vector<VoxelFade> _voxelFades;

View file

@ -1066,7 +1066,7 @@ void Menu::bandwidthDetailsClosed() {
void Menu::voxelStatsDetails() {
if (!_voxelStatsDialog) {
_voxelStatsDialog = new VoxelStatsDialog(Application::getInstance()->getGLWidget(),
Application::getInstance()->getVoxelSceneStats());
Application::getInstance()->getOcteeSceneStats());
connect(_voxelStatsDialog, SIGNAL(closed()), SLOT(voxelStatsDetailsClosed()));
_voxelStatsDialog->show();
}

View file

@ -26,9 +26,12 @@ const int TOY_BALL_HAND = 1;
const float TOY_BALL_RADIUS = 0.05f;
const float TOY_BALL_DAMPING = 0.99f;
const glm::vec3 NO_VELOCITY = glm::vec3(0,0,0);
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-1,0);
const glm::vec3 NO_GRAVITY = glm::vec3(0,0,0);
const float NO_DAMPING = 0.f;
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-0.5,0);
const QString TOY_BALL_UPDATE_SCRIPT("");
const float PALM_COLLISION_RADIUS = 0.03f;
const float CATCH_RADIUS = 0.2f;
const xColor TOY_BALL_ON_SERVER_COLOR[] =
{
{ 255, 0, 0 },
@ -80,21 +83,15 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
bool grabButtonPressed = (palm.getControllerButtons() & BUTTON_FWD);
bool ballAlreadyInHand = _toyBallInHand[handID];
glm::vec3 targetPosition = palm.getPosition() / (float)TREE_SCALE;
float targetRadius = (TOY_BALL_RADIUS * 4.0f) / (float)TREE_SCALE;
glm::vec3 targetPosition = (ballFromHand ? palm.getPosition() : fingerTipPosition) / (float)TREE_SCALE;
float targetRadius = CATCH_RADIUS / (float)TREE_SCALE;
const Particle* closestParticle = Application::getInstance()->getParticles()
->getTree()->findClosestParticle(targetPosition, targetRadius);
//printf("simulateToyBall() handID:%d grabButtonPressed:%s ballAlreadyInHand:%s\n",
// handID, debug::valueOf(grabButtonPressed), debug::valueOf(ballAlreadyInHand));
if (closestParticle) {
//printf("potentially caught... handID:%d particle ID:%d grabButtonPressed:%s ballAlreadyInHand:%s\n",
// handID, closestParticle->getID(), debug::valueOf(grabButtonPressed), debug::valueOf(ballAlreadyInHand));
// If I don't currently have a ball in my hand, then I can catch this closest particle
if (!ballAlreadyInHand && grabButtonPressed) {
//printf("caught... handID:%d particle ID:%d\n", handID, closestParticle->getID());
ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID());
glm::vec3 newPosition = targetPosition;
glm::vec3 newVelocity = NO_VELOCITY;
@ -107,8 +104,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
closestParticle->getRadius(),
closestParticle->getXColor(),
newVelocity,
closestParticle->getGravity(),
closestParticle->getDamping(),
NO_GRAVITY,
NO_DAMPING,
IN_HAND, // we just grabbed it!
closestParticle->getUpdateScript());
@ -461,20 +458,23 @@ void Hand::render( bool isMine) {
_renderAlpha = 1.0;
if (Menu::getInstance()->isOptionChecked(MenuOption::CollisionProxies)) {
for (int i = 0; i < getNumPalms(); i++) {
PalmData& palm = getPalms()[i];
if (!palm.isActive()) {
continue;
if (Menu::getInstance()->isOptionChecked(MenuOption::CollisionProxies)) {
for (int i = 0; i < getNumPalms(); i++) {
PalmData& palm = getPalms()[i];
if (!palm.isActive()) {
continue;
}
glm::vec3 position = palm.getPosition();
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
glColor3f(0.0f, 1.0f, 0.0f);
glutSolidSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10);
glPopMatrix();
}
glm::vec3 position = palm.getPosition();
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
glColor3f(0.0f, 1.0f, 0.0f);
glutSolidSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10);
glPopMatrix();
}
}
if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayLeapHands)) {
renderLeapHands();
@ -503,10 +503,11 @@ void Hand::render( bool isMine) {
void Hand::renderLeapHands() {
const float alpha = 1.0f;
const float TARGET_ALPHA = 0.5f;
//const glm::vec3 handColor = _ballColor;
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
bool ballFromHand = Menu::getInstance()->isOptionChecked(MenuOption::BallFromHand);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
@ -517,26 +518,25 @@ void Hand::renderLeapHands() {
if (!palm.isActive()) {
continue;
}
glm::vec3 targetPosition = palm.getPosition();
float targetRadius = (TOY_BALL_RADIUS * 4.0f);
glm::vec3 targetPosition = ballFromHand ? palm.getPosition() : palm.getTipPosition();
glPushMatrix();
const Particle* closestParticle = Application::getInstance()->getParticles()
->getTree()->findClosestParticle(targetPosition / (float)TREE_SCALE,
targetRadius / (float)TREE_SCALE);
CATCH_RADIUS / (float)TREE_SCALE);
// If we are hitting a particle then draw the target green, otherwise yellow
if (closestParticle) {
glColor4f(0,1,0, alpha);
glColor4f(0,1,0, TARGET_ALPHA);
} else {
glColor4f(1,1,0, alpha);
glColor4f(1,1,0, TARGET_ALPHA);
}
glTranslatef(targetPosition.x, targetPosition.y, targetPosition.z);
glutWireSphere(targetRadius, 20.0f, 20.0f);
glutWireSphere(CATCH_RADIUS, 10.f, 10.f);
const float collisionRadius = 0.05f;
glColor4f(0.5f,0.5f,0.5f, alpha);
glutWireSphere(collisionRadius, 20.0f, 20.0f);
glutWireSphere(collisionRadius, 10.f, 10.f);
glPopMatrix();
}
}

View file

@ -107,8 +107,8 @@ void SixenseManager::update(float deltaTime) {
const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR;
finger.setRawTipPosition(position + rotation * FINGER_VECTOR);
// temporary for toy ball - store first finger tip velocity
glm::vec3 oldTipPosition = palm->getTipPosition();
// Store the one fingertip in the palm structure so we can track velocity
glm::vec3 oldTipPosition = palm->getTipRawPosition();
palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime / 1000.f);
palm->setTipPosition(newTipPosition);

View file

@ -170,7 +170,7 @@ void VoxelStatsDialog::paintEvent(QPaintEvent* event) {
unsigned long totalLeaves = 0;
Application::getInstance()->lockVoxelSceneStats();
NodeToVoxelSceneStats* sceneStats = Application::getInstance()->getVoxelSceneStats();
NodeToVoxelSceneStats* sceneStats = Application::getInstance()->getOcteeSceneStats();
for(NodeToVoxelSceneStatsIterator i = sceneStats->begin(); i != sceneStats->end(); i++) {
//const QUuid& uuid = i->first;
VoxelSceneStats& stats = i->second;
@ -215,26 +215,42 @@ void VoxelStatsDialog::paintEvent(QPaintEvent* event) {
"Leaves: " << serversLeavesString.toLocal8Bit().constData() << "";
label->setText(statsValue.str().c_str());
showAllVoxelServers();
showAllOctreeServers();
this->QDialog::paintEvent(event);
}
void VoxelStatsDialog::showAllOctreeServers() {
int serverCount = 0;
void VoxelStatsDialog::showAllVoxelServers() {
showOctreeServersOfType(serverCount, NODE_TYPE_VOXEL_SERVER, "Voxel",
Application::getInstance()->getVoxelServerJurisdictions());
showOctreeServersOfType(serverCount, NODE_TYPE_PARTICLE_SERVER, "Particle",
Application::getInstance()->getParticleServerJurisdictions());
if (_voxelServerLabelsCount > serverCount) {
for (int i = serverCount; i < _voxelServerLabelsCount; i++) {
int serverLabel = _voxelServerLables[i];
RemoveStatItem(serverLabel);
_voxelServerLables[i] = 0;
}
_voxelServerLabelsCount = serverCount;
}
}
void VoxelStatsDialog::showOctreeServersOfType(int& serverCount, NODE_TYPE serverType, const char* serverTypeName,
NodeToJurisdictionMap& serverJurisdictions) {
QLocale locale(QLocale::English);
int serverNumber = 0;
int serverCount = 0;
NodeList* nodeList = NodeList::getInstance();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
// only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
serverNumber++;
if (node->getType() == serverType) {
serverCount++;
if (serverCount > _voxelServerLabelsCount) {
char label[128] = { 0 };
sprintf(label, "Voxel Server %d",serverCount);
sprintf(label, "%s Server %d", serverTypeName, serverCount);
int thisServerRow = _voxelServerLables[serverCount-1] = AddStatItem(label);
_labels[thisServerRow]->setTextFormat(Qt::RichText);
_labels[thisServerRow]->setTextInteractionFlags(Qt::TextBrowserInteraction);
@ -254,14 +270,12 @@ void VoxelStatsDialog::showAllVoxelServers() {
QUuid nodeUUID = node->getUUID();
NodeToJurisdictionMap& voxelServerJurisdictions = Application::getInstance()->getVoxelServerJurisdictions();
// lookup our nodeUUID in the jurisdiction map, if it's missing then we're
// missing at least one jurisdiction
if (voxelServerJurisdictions.find(nodeUUID) == voxelServerJurisdictions.end()) {
if (serverJurisdictions.find(nodeUUID) == serverJurisdictions.end()) {
serverDetails << " unknown jurisdiction ";
} else {
const JurisdictionMap& map = voxelServerJurisdictions[nodeUUID];
const JurisdictionMap& map = serverJurisdictions[nodeUUID];
unsigned char* rootCode = map.getRootOctalCode();
@ -285,13 +299,13 @@ void VoxelStatsDialog::showAllVoxelServers() {
} // jurisdiction
// now lookup stats details for this server...
if (_extraServerDetails[serverNumber-1] != LESS) {
if (_extraServerDetails[serverCount-1] != LESS) {
Application::getInstance()->lockVoxelSceneStats();
NodeToVoxelSceneStats* sceneStats = Application::getInstance()->getVoxelSceneStats();
NodeToVoxelSceneStats* sceneStats = Application::getInstance()->getOcteeSceneStats();
if (sceneStats->find(nodeUUID) != sceneStats->end()) {
VoxelSceneStats& stats = sceneStats->at(nodeUUID);
switch (_extraServerDetails[serverNumber-1]) {
switch (_extraServerDetails[serverCount-1]) {
case MOST: {
extraDetails << "<br/>" ;
@ -345,12 +359,12 @@ void VoxelStatsDialog::showAllVoxelServers() {
" Wasted Bytes: " << incomingWastedBytesString.toLocal8Bit().constData();
serverDetails << extraDetails.str();
if (_extraServerDetails[serverNumber-1] == MORE) {
linkDetails << " " << " [<a href='most-" << serverNumber << "'>most...</a>]";
linkDetails << " " << " [<a href='less-" << serverNumber << "'>less...</a>]";
if (_extraServerDetails[serverCount-1] == MORE) {
linkDetails << " " << " [<a href='most-" << serverCount << "'>most...</a>]";
linkDetails << " " << " [<a href='less-" << serverCount << "'>less...</a>]";
} else {
linkDetails << " " << " [<a href='more-" << serverNumber << "'>less...</a>]";
linkDetails << " " << " [<a href='less-" << serverNumber << "'>least...</a>]";
linkDetails << " " << " [<a href='more-" << serverCount << "'>less...</a>]";
linkDetails << " " << " [<a href='less-" << serverCount << "'>least...</a>]";
}
} break;
@ -361,22 +375,13 @@ void VoxelStatsDialog::showAllVoxelServers() {
}
Application::getInstance()->unlockVoxelSceneStats();
} else {
linkDetails << " " << " [<a href='more-" << serverNumber << "'>more...</a>]";
linkDetails << " " << " [<a href='most-" << serverNumber << "'>most...</a>]";
linkDetails << " " << " [<a href='more-" << serverCount << "'>more...</a>]";
linkDetails << " " << " [<a href='most-" << serverCount << "'>most...</a>]";
}
serverDetails << linkDetails.str();
_labels[_voxelServerLables[serverCount - 1]]->setText(serverDetails.str().c_str());
} // is VOXEL_SERVER
} // Node Loop
if (_voxelServerLabelsCount > serverCount) {
for (int i = serverCount; i < _voxelServerLabelsCount; i++) {
int serverLabel = _voxelServerLables[i];
RemoveStatItem(serverLabel);
_voxelServerLables[i] = 0;
}
_voxelServerLabelsCount = serverCount;
}
}
void VoxelStatsDialog::reject() {

View file

@ -42,7 +42,10 @@ protected:
int AddStatItem(const char* caption, unsigned colorRGBA = DEFAULT_COLOR);
void RemoveStatItem(int item);
void showAllVoxelServers();
void showAllOctreeServers();
void showOctreeServersOfType(int& serverNumber, NODE_TYPE serverType,
const char* serverTypeName, NodeToJurisdictionMap& serverJurisdictions);
private:

View file

@ -158,7 +158,9 @@ public:
void addToPosition(const glm::vec3& delta);
void setTipPosition(const glm::vec3& position) { _tipPosition = position; }
const glm::vec3 getTipPosition() const { return _tipPosition; }
const glm::vec3 getTipPosition() const { return _owningHandData->leapPositionToWorldPosition(_tipPosition); }
const glm::vec3 getTipRawPosition() const { return _tipPosition; }
const glm::vec3& getTipVelocity() const { return _tipVelocity; }
void setTipVelocity(const glm::vec3& velocity) { _tipVelocity = velocity; }

View file

@ -43,6 +43,7 @@ void Particle::init(glm::vec3 position, float radius, rgbColor color, glm::vec3
_id = id;
}
_lastUpdated = usecTimestampNow();
_lastEdited = _lastUpdated;
_position = position;
_radius = radius;
@ -67,6 +68,9 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const {
if (success) {
success = packetData->appendValue(getLastUpdated());
}
if (success) {
success = packetData->appendValue(getLastEdited());
}
if (success) {
success = packetData->appendValue(getRadius());
}
@ -99,7 +103,7 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const {
}
int Particle::expectedBytes() {
int expectedBytes = sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(float) +
int expectedBytes = sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(float) +
sizeof(glm::vec3) + sizeof(rgbColor) + sizeof(glm::vec3) +
sizeof(glm::vec3) + sizeof(float) + sizeof(bool);
return expectedBytes;
@ -125,6 +129,11 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
dataAt += sizeof(_lastUpdated);
bytesRead += sizeof(_lastUpdated);
// _lastEdited
memcpy(&_lastEdited, dataAt, sizeof(_lastEdited));
dataAt += sizeof(_lastEdited);
bytesRead += sizeof(_lastEdited);
// radius
memcpy(&_radius, dataAt, sizeof(_radius));
dataAt += sizeof(_radius);
@ -219,6 +228,11 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
memcpy(&newParticle._lastUpdated, dataAt, sizeof(newParticle._lastUpdated));
dataAt += sizeof(newParticle._lastUpdated);
processedBytes += sizeof(newParticle._lastUpdated);
// lastEdited
memcpy(&newParticle._lastEdited, dataAt, sizeof(newParticle._lastEdited));
dataAt += sizeof(newParticle._lastEdited);
processedBytes += sizeof(newParticle._lastEdited);
// radius
memcpy(&newParticle._radius, dataAt, sizeof(newParticle._radius));
@ -279,6 +293,7 @@ void Particle::debugDump() const {
printf("Particle id :%u\n", _id);
printf(" created:%llu\n", _created);
printf(" last updated:%llu\n", _lastUpdated);
printf(" last edited:%llu\n", _lastEdited);
printf(" position:%f,%f,%f\n", _position.x, _position.y, _position.z);
printf(" velocity:%f,%f,%f\n", _velocity.x, _velocity.y, _velocity.z);
printf(" gravity:%f,%f,%f\n", _gravity.x, _gravity.y, _gravity.z);
@ -337,6 +352,11 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count,
copyAt += sizeof(details[i].lastUpdated);
sizeOut += sizeof(details[i].lastUpdated);
// lastEdited
memcpy(copyAt, &details[i].lastEdited, sizeof(details[i].lastEdited));
copyAt += sizeof(details[i].lastEdited);
sizeOut += sizeof(details[i].lastEdited);
// radius
memcpy(copyAt, &details[i].radius, sizeof(details[i].radius));
copyAt += sizeof(details[i].radius);

View file

@ -26,6 +26,7 @@ class ParticleDetail {
public:
uint32_t id;
uint64_t lastUpdated;
uint64_t lastEdited;
glm::vec3 position;
float radius;
rgbColor color;
@ -70,6 +71,7 @@ public:
uint64_t getCreated() const { return _created; }
uint64_t getLifetime() const { return usecTimestampNow() - _created; }
uint64_t getLastUpdated() const { return _lastUpdated; }
uint64_t getLastEdited() const { return _lastEdited; }
uint32_t getID() const { return _id; }
bool getShouldDie() const { return _shouldDie; }
QString getUpdateScript() const { return _updateScript; }
@ -92,7 +94,7 @@ public:
void setUpdateScript(QString updateScript) { _updateScript = updateScript; }
void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; }
void setCreated(uint64_t created) { _created = created; }
bool appendParticleData(OctreePacketData* packetData) const;
int readParticleDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
static int expectedBytes();
@ -116,6 +118,7 @@ protected:
glm::vec3 _velocity;
uint64_t _lastUpdated;
uint64_t _created;
uint64_t _lastEdited;
uint32_t _id;
static uint32_t _nextID;
bool _shouldDie;

View file

@ -44,7 +44,8 @@ void ParticleEditHandle::createParticle(glm::vec3 position, float radius, xColor
glm::vec3 gravity, float damping, bool inHand, QString updateScript) {
// setup a ParticleDetail struct with the data
ParticleDetail addParticleDetail = { NEW_PARTICLE, usecTimestampNow(),
uint64_t now = usecTimestampNow();
ParticleDetail addParticleDetail = { NEW_PARTICLE, now, now,
position, radius, {color.red, color.green, color.blue },
velocity, gravity, damping, inHand, updateScript, _creatorTokenID };
@ -69,7 +70,8 @@ bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor
}
// setup a ParticleDetail struct with the data
ParticleDetail newParticleDetail = { _id, usecTimestampNow(),
uint64_t now = usecTimestampNow();
ParticleDetail newParticleDetail = { _id, now, now,
position, radius, {color.red, color.green, color.blue },
velocity, gravity, damping, inHand, updateScript, _creatorTokenID };

View file

@ -22,7 +22,8 @@ unsigned int ParticleScriptingInterface::queueParticleAdd(glm::vec3 position, fl
_nextCreatorTokenID++;
// setup a ParticleDetail struct with the data
ParticleDetail addParticleDetail = { NEW_PARTICLE, usecTimestampNow(),
uint64_t now = usecTimestampNow();
ParticleDetail addParticleDetail = { NEW_PARTICLE, now, now,
position, radius, {color.red, color.green, color.blue }, velocity,
gravity, damping, inHand, updateScript, creatorTokenID };

View file

@ -115,15 +115,39 @@ bool ParticleTreeElement::containsParticle(const Particle& particle) const {
}
bool ParticleTreeElement::updateParticle(const Particle& particle) {
bool wantDebug = false;
uint16_t numberOfParticles = _particles.size();
for (uint16_t i = 0; i < numberOfParticles; i++) {
if (_particles[i].getID() == particle.getID()) {
uint64_t actuallyCreated = particle.getCreated();
if (!particle.isNewlyCreated()) {
actuallyCreated = _particles[i].getCreated();
int difference = _particles[i].getLastUpdated() - particle.getLastUpdated();
bool changedOnServer = _particles[i].getLastEdited() < particle.getLastEdited();
bool localOlder = _particles[i].getLastUpdated() < particle.getLastUpdated();
if (changedOnServer || localOlder) {
if (wantDebug) {
printf("local particle [id:%d] %s and %s than server particle by %d, particle.isNewlyCreated()=%s\n",
particle.getID(), (changedOnServer ? "CHANGED" : "same"),
(localOlder ? "OLDER" : "NEWER"),
difference, debug::valueOf(particle.isNewlyCreated()) );
}
uint64_t actuallyCreated = particle.getCreated();
if (!particle.isNewlyCreated()) {
actuallyCreated = _particles[i].getCreated();
}
_particles[i] = particle;
_particles[i].setCreated(actuallyCreated);
} else {
if (wantDebug) {
printf(">>> NO CHANGE <<< -- local particle [id:%d] %s and %s than server particle by %d, "
"particle.isNewlyCreated()=%s\n",
particle.getID(), (changedOnServer ? "CHANGED" : "same"),
(localOlder ? "OLDER" : "NEWER"),
difference, debug::valueOf(particle.isNewlyCreated()) );
}
}
_particles[i] = particle;
_particles[i].setCreated(actuallyCreated);
return true;
}
}

View file

@ -54,7 +54,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
return 2;
case PACKET_TYPE_PARTICLE_DATA:
return 2;
return 3;
default:
return 0;