mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 12:00:11 +02:00
First cut at new ParticleEditPacketSender class
This commit is contained in:
parent
c067f8ad11
commit
426c89b639
4 changed files with 162 additions and 0 deletions
|
@ -105,6 +105,14 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
|
|||
Particle newParticle; // id and lastUpdated will get set here...
|
||||
unsigned char* dataAt = data;
|
||||
processedBytes = 0;
|
||||
|
||||
// the first part of the data is our octcode...
|
||||
int octets = numberOfThreeBitSectionsInCode(data);
|
||||
int lengthOfOctcode = bytesRequiredForCodeLength(octets);
|
||||
|
||||
// we don't actually do anything with this octcode...
|
||||
dataAt += lengthOfOctcode;
|
||||
processedBytes += lengthOfOctcode;
|
||||
|
||||
// radius
|
||||
memcpy(&newParticle._radius, dataAt, sizeof(newParticle._radius));
|
||||
|
@ -129,3 +137,57 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
|
|||
return newParticle;
|
||||
}
|
||||
|
||||
|
||||
bool Particle::encodeParticleAddMessageDetails(PACKET_TYPE command, int count, const ParticleDetail* details,
|
||||
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
|
||||
|
||||
bool success = true; // assume the best
|
||||
unsigned char* copyAt = bufferOut;
|
||||
sizeOut = 0;
|
||||
|
||||
for (int i = 0; i < count && success; i++) {
|
||||
// get the coded voxel
|
||||
unsigned char* octcode = pointToOctalCode(details[i].position.x, details[i].position.y, details[i].position.z, details[i].radius);
|
||||
|
||||
int octets = numberOfThreeBitSectionsInCode(octcode);
|
||||
int lengthOfOctcode = bytesRequiredForCodeLength(octets);
|
||||
int lenfthOfEditData = lengthOfOctcode + expectedBytes();
|
||||
|
||||
// make sure we have room to copy this voxel
|
||||
if (sizeOut + lenfthOfEditData > sizeIn) {
|
||||
success = false;
|
||||
} else {
|
||||
// add it to our message
|
||||
memcpy(copyAt, octcode, lengthOfOctcode);
|
||||
copyAt += lengthOfOctcode;
|
||||
sizeOut += lengthOfOctcode;
|
||||
|
||||
// Now add our edit content details...
|
||||
|
||||
// radius
|
||||
memcpy(copyAt, &details[i].radius, sizeof(details[i].radius));
|
||||
copyAt += sizeof(details[i].radius);
|
||||
sizeOut += sizeof(details[i].radius);
|
||||
|
||||
// position
|
||||
memcpy(copyAt, &details[i].position, sizeof(details[i].position));
|
||||
copyAt += sizeof(details[i].position);
|
||||
sizeOut += sizeof(details[i].position);
|
||||
|
||||
// color
|
||||
memcpy(copyAt, details[i].color, sizeof(details[i].color));
|
||||
copyAt += sizeof(details[i].color);
|
||||
sizeOut += sizeof(details[i].color);
|
||||
|
||||
// velocity
|
||||
memcpy(copyAt, &details[i].velocity, sizeof(details[i].velocity));
|
||||
copyAt += sizeof(details[i].velocity);
|
||||
sizeOut += sizeof(details[i].velocity);
|
||||
}
|
||||
// cleanup
|
||||
delete[] octcode;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,14 @@
|
|||
#include <SharedUtil.h>
|
||||
#include <OctreePacketData.h>
|
||||
|
||||
class ParticleDetail {
|
||||
public:
|
||||
glm::vec3 position;
|
||||
float radius;
|
||||
rgbColor color;
|
||||
glm::vec3 velocity;
|
||||
};
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
Particle();
|
||||
|
@ -37,6 +45,9 @@ public:
|
|||
bool appendParticleData(OctreePacketData* packetData) const;
|
||||
int readParticleDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
|
||||
static int expectedBytes();
|
||||
|
||||
static bool encodeParticleAddMessageDetails(PACKET_TYPE command, int count, const ParticleDetail* details,
|
||||
unsigned char* bufferOut, int sizeIn, int& sizeOut);
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
rgbColor _color;
|
||||
|
|
55
libraries/particles/src/ParticleEditPacketSender.cpp
Normal file
55
libraries/particles/src/ParticleEditPacketSender.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// ParticleEditPacketSender.cpp
|
||||
// interface
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
// Threaded or non-threaded voxel packet Sender for the Application
|
||||
//
|
||||
|
||||
#include <assert.h>
|
||||
#include <PerfStat.h>
|
||||
#include <OctalCode.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include "ParticleEditPacketSender.h"
|
||||
#include "Particle.h"
|
||||
|
||||
|
||||
void ParticleEditPacketSender::sendAddParticleMessage(PACKET_TYPE type, const ParticleDetail& detail) {
|
||||
// allows app to disable sending if for example voxels have been disabled
|
||||
if (!_shouldSend) {
|
||||
return; // bail early
|
||||
}
|
||||
|
||||
static unsigned char bufferOut[MAX_PACKET_SIZE];
|
||||
int sizeOut = 0;
|
||||
|
||||
// This encodes the voxel edit message into a buffer...
|
||||
if (Particle::encodeParticleAddMessageDetails(type, 1, &detail, &bufferOut[0], _maxPacketSize, sizeOut)){
|
||||
// If we don't have voxel jurisdictions, then we will simply queue up these packets and wait till we have
|
||||
// jurisdictions for processing
|
||||
if (!serversExist()) {
|
||||
queuePendingPacketToNodes(type, bufferOut, sizeOut);
|
||||
} else {
|
||||
queuePacketToNodes(bufferOut, sizeOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEditPacketSender::queueParticleAddMessages(PACKET_TYPE type, int numberOfDetails, ParticleDetail* details) {
|
||||
if (!_shouldSend) {
|
||||
return; // bail early
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfDetails; i++) {
|
||||
// use MAX_PACKET_SIZE since it's static and guarenteed to be larger than _maxPacketSize
|
||||
static unsigned char bufferOut[MAX_PACKET_SIZE];
|
||||
int sizeOut = 0;
|
||||
|
||||
if (Particle::encodeParticleAddMessageDetails(type, 1, &details[i], &bufferOut[0], _maxPacketSize, sizeOut)) {
|
||||
queueOctreeEditMessage(type, bufferOut, sizeOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
libraries/particles/src/ParticleEditPacketSender.h
Normal file
34
libraries/particles/src/ParticleEditPacketSender.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// ParticleEditPacketSender.h
|
||||
// shared
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
// Voxel Packet Sender
|
||||
//
|
||||
|
||||
#ifndef __shared__ParticleEditPacketSender__
|
||||
#define __shared__ParticleEditPacketSender__
|
||||
|
||||
#include <OctreeEditPacketSender.h>
|
||||
#include "Particle.h"
|
||||
|
||||
/// Utility for processing, packing, queueing and sending of outbound edit voxel messages.
|
||||
class ParticleEditPacketSender : public virtual OctreeEditPacketSender {
|
||||
public:
|
||||
ParticleEditPacketSender(PacketSenderNotify* notify = NULL) : OctreeEditPacketSender(notify) { }
|
||||
~ParticleEditPacketSender() { }
|
||||
|
||||
/// Send particle add message immediately
|
||||
void sendAddParticleMessage(PACKET_TYPE type, const ParticleDetail& detail);
|
||||
|
||||
/// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines
|
||||
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
|
||||
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
|
||||
void queueParticleAddMessages(PACKET_TYPE type, int numberOfDetails, ParticleDetail* details);
|
||||
|
||||
// My server type is the voxel server
|
||||
virtual unsigned char getMyNodeType() const { return NODE_TYPE_PARTICLE_SERVER; }
|
||||
};
|
||||
#endif // __shared__ParticleEditPacketSender__
|
Loading…
Reference in a new issue