first pass at removing timestamps from particles removed _lastUpdated/getLastUpdated()

This commit is contained in:
ZappoMan 2013-12-18 16:59:36 -08:00
parent 6b0d7c30f0
commit 1badc8dc5d
7 changed files with 30 additions and 35 deletions

View file

@ -656,6 +656,16 @@ void OctreeServer::run() {
_persistThread->initialize(true);
}
}
// Debug option to demonstrate that the server's local time does not
// need to be in sync with any other network node. This forces clock
// skew for the individual server node
const char* TIME_ADJUST = "--usecTimestampNowAdjust";
const char* timeAdjustOption = getCmdOption(_argc, _argv, TIME_ADJUST);
if (timeAdjustOption) {
::usecTimestampNowAdjust = atoi(timeAdjustOption);
qDebug("timeAdjustOption=%s usecTimestampNowAdjust=%d\n", timeAdjustOption, ::usecTimestampNowAdjust);
}
// Check to see if the user passed in a command line option for setting packet send rate
const char* PACKETS_PER_SECOND = "--packetsPerSecond";

View file

@ -42,8 +42,9 @@ void Particle::init(glm::vec3 position, float radius, rgbColor color, glm::vec3
} else {
_id = id;
}
_lastUpdated = usecTimestampNow();
_lastEdited = _lastUpdated;
uint64_t now = usecTimestampNow();
_lastEdited = now;
_lastSimulated = now;
_position = position;
_radius = radius;
@ -65,9 +66,6 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const {
if (success) {
success = packetData->appendValue(getCreated());
}
if (success) {
success = packetData->appendValue(getLastUpdated());
}
if (success) {
success = packetData->appendValue(getLastEdited());
}
@ -124,11 +122,6 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
dataAt += sizeof(_created);
bytesRead += sizeof(_created);
// lastupdated
memcpy(&_lastUpdated, dataAt, sizeof(_lastUpdated));
dataAt += sizeof(_lastUpdated);
bytesRead += sizeof(_lastUpdated);
// _lastEdited
memcpy(&_lastEdited, dataAt, sizeof(_lastEdited));
dataAt += sizeof(_lastEdited);
@ -186,7 +179,7 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
Particle Particle::fromEditPacket(unsigned char* data, int length, int& processedBytes) {
Particle newParticle; // id and lastUpdated will get set here...
Particle newParticle; // id and _lastSimulated will get set here...
unsigned char* dataAt = data;
processedBytes = 0;
@ -224,11 +217,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
dataAt += sizeof(newParticle._created);
processedBytes += sizeof(newParticle._created);
// lastUpdated
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);
@ -292,7 +280,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
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);
@ -347,11 +334,6 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count,
copyAt += sizeof(created);
sizeOut += sizeof(created);
// lastUpdated
memcpy(copyAt, &details[i].lastUpdated, sizeof(details[i].lastUpdated));
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);
@ -405,7 +387,6 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count,
if (wantDebugging) {
printf("encodeParticleEditMessageDetails()....\n");
printf("Particle id :%u\n", details[i].id);
printf(" last updated:%llu\n", details[i].lastUpdated);
printf(" nextID:%u\n", _nextID);
}
}
@ -419,7 +400,7 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count,
void Particle::update() {
uint64_t now = usecTimestampNow();
uint64_t elapsed = now - _lastUpdated;
uint64_t elapsed = now - _lastSimulated;
uint64_t USECS_PER_SECOND = 1000 * 1000;
float timeElapsed = (float)((float)elapsed/(float)USECS_PER_SECOND);
@ -454,7 +435,7 @@ void Particle::update() {
//printf("applying damping to Particle timeElapsed=%f\n",timeElapsed);
}
_lastUpdated = now;
_lastSimulated = now;
}
void Particle::runScript() {

View file

@ -25,7 +25,6 @@ const uint32_t UNKNOWN_TOKEN = 0xFFFFFFFF;
class ParticleDetail {
public:
uint32_t id;
uint64_t lastUpdated;
uint64_t lastEdited;
glm::vec3 position;
float radius;
@ -70,7 +69,6 @@ public:
float getDamping() const { return _damping; }
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; }
@ -116,7 +114,6 @@ protected:
rgbColor _color;
float _radius;
glm::vec3 _velocity;
uint64_t _lastUpdated;
uint64_t _created;
uint64_t _lastEdited;
uint32_t _id;
@ -129,6 +126,9 @@ protected:
uint32_t _creatorTokenID;
bool _newlyCreated;
uint64_t _lastSimulated;
};
class ParticleScriptObject : public QObject {

View file

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

View file

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

View file

@ -119,18 +119,20 @@ bool ParticleTreeElement::updateParticle(const Particle& particle) {
uint16_t numberOfParticles = _particles.size();
for (uint16_t i = 0; i < numberOfParticles; i++) {
if (_particles[i].getID() == particle.getID()) {
int difference = _particles[i].getLastUpdated() - particle.getLastUpdated();
//int difference = _particles[i].getLastUpdated() - particle.getLastUpdated();
//bool localOlder = _particles[i].getLastUpdated() < particle.getLastUpdated();
bool changedOnServer = _particles[i].getLastEdited() < particle.getLastEdited();
bool localOlder = _particles[i].getLastUpdated() < particle.getLastUpdated();
if (changedOnServer || localOlder) {
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();
@ -141,11 +143,13 @@ bool ParticleTreeElement::updateParticle(const Particle& 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()) );
**/
}
}
return true;

View file

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