mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 21:56:14 +02:00
first pass at removing timestamps from particles removed _lastUpdated/getLastUpdated()
This commit is contained in:
parent
6b0d7c30f0
commit
1badc8dc5d
7 changed files with 30 additions and 35 deletions
|
@ -657,6 +657,16 @@ void OctreeServer::run() {
|
|||
}
|
||||
}
|
||||
|
||||
// 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";
|
||||
const char* packetsPerSecond = getCmdOption(_argc, _argv, PACKETS_PER_SECOND);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -54,7 +54,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
|||
return 2;
|
||||
|
||||
case PACKET_TYPE_PARTICLE_DATA:
|
||||
return 3;
|
||||
return 4;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue