mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
facf7094f0
16 changed files with 162 additions and 98 deletions
|
@ -40,4 +40,9 @@ void VoxelScriptingInterface::queueVoxelDelete(float x, float y, float z, float
|
|||
VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0};
|
||||
|
||||
_voxelPacketSender.queueVoxelEditMessages(PACKET_TYPE_ERASE_VOXEL, 1, &deleteVoxelDetail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int VoxelScriptingInterface::packetsToSendCount() const {
|
||||
return _voxelPacketSender.packetsToSendCount();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ public slots:
|
|||
/// \param z the z-coordinate of the voxel (in VS space)
|
||||
/// \param scale the scale of the voxel (in VS space)
|
||||
void queueVoxelDelete(float x, float y, float z, float scale);
|
||||
|
||||
/// get the current number of pending, queued, but unsent packets
|
||||
int packetsToSendCount() const;
|
||||
|
||||
private:
|
||||
/// attached VoxelEditPacketSender that handles queuing and sending of packets to VS
|
||||
VoxelEditPacketSender _voxelPacketSender;
|
||||
|
|
|
@ -86,59 +86,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) {
|
|||
glm::vec3 p(_yourBodyPosition);
|
||||
p.y = 0.0005f;
|
||||
renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30);
|
||||
|
||||
// show if we are holding hands...
|
||||
if (_weAreHoldingHands) {
|
||||
renderBeamBetweenHands();
|
||||
|
||||
/*
|
||||
glPushMatrix();
|
||||
glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z);
|
||||
glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.020f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.025f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.030f, 10.0f, 10.0f);
|
||||
glPopMatrix();
|
||||
*/
|
||||
|
||||
/*
|
||||
glColor4f(0.9, 0.3, 0.3, 0.5);
|
||||
renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition);
|
||||
renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition);
|
||||
renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.1f, 20, cameraPosition);
|
||||
|
||||
renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition);
|
||||
renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition);
|
||||
renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.1f, 20, cameraPosition);
|
||||
*/
|
||||
}
|
||||
|
||||
//show that our hands are close enough to grasp..
|
||||
if (_handsCloseEnoughToGrasp) {
|
||||
glColor4f(0.9, 0.3, 0.3, 0.5);
|
||||
renderSphereOutline(_myHandPosition, 0.03f, 20, cameraPosition);
|
||||
renderSphereOutline(_yourHandPosition, 0.03f, 20, cameraPosition);
|
||||
}
|
||||
|
||||
// if your hand is grasping, show it...
|
||||
if (_yourHandState == HAND_STATE_GRASPING) {
|
||||
glPushMatrix();
|
||||
glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z);
|
||||
glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
// if my hand is grasping, show it...
|
||||
if (_myHandState == HAND_STATE_GRASPING) {
|
||||
glPushMatrix();
|
||||
glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z);
|
||||
glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f);
|
||||
glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,11 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
|||
|
||||
case PACKET_TYPE_VOXEL_QUERY:
|
||||
return 1;
|
||||
|
||||
case PACKET_TYPE_SET_VOXEL:
|
||||
case PACKET_TYPE_SET_VOXEL_DESTRUCTIVE:
|
||||
case PACKET_TYPE_ERASE_VOXEL:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
|
|
@ -39,8 +39,12 @@ void PacketSender::queuePacketForSending(sockaddr& address, unsigned char* packe
|
|||
}
|
||||
|
||||
bool PacketSender::process() {
|
||||
bool hasSlept = false;
|
||||
uint64_t USECS_PER_SECOND = 1000 * 1000;
|
||||
uint64_t USECS_SMALL_ADJUST = 2 * 1000; // approaximate 2ms
|
||||
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
||||
uint64_t INTERVAL_SLEEP_USECS = (SEND_INTERVAL_USECS > USECS_SMALL_ADJUST) ?
|
||||
SEND_INTERVAL_USECS - USECS_SMALL_ADJUST : SEND_INTERVAL_USECS;
|
||||
|
||||
// keep track of our process call times, so we have a reliable account of how often our caller calls us
|
||||
uint64_t now = usecTimestampNow();
|
||||
|
@ -50,9 +54,11 @@ bool PacketSender::process() {
|
|||
|
||||
if (_packets.size() == 0) {
|
||||
if (isThreaded()) {
|
||||
usleep(SEND_INTERVAL_USECS);
|
||||
usleep(INTERVAL_SLEEP_USECS);
|
||||
hasSlept = true;
|
||||
} else {
|
||||
return isStillRunning(); // in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us
|
||||
// in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us
|
||||
return isStillRunning();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +68,7 @@ bool PacketSender::process() {
|
|||
// if we're in non-threaded mode, then we actually need to determine how many packets to send per call to process
|
||||
// based on how often we get called... We do this by keeping a running average of our call times, and we determine
|
||||
// how many packets to send per call
|
||||
|
||||
if (!isThreaded()) {
|
||||
int averageCallTime;
|
||||
const int TRUST_AVERAGE_AFTER = AVERAGE_CALL_TIME_SAMPLES * 2;
|
||||
|
@ -89,8 +96,6 @@ bool PacketSender::process() {
|
|||
int packetsLeft = _packets.size();
|
||||
bool keepGoing = packetsLeft > 0;
|
||||
while (keepGoing) {
|
||||
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
||||
|
||||
lock();
|
||||
NetworkPacket& packet = _packets.front();
|
||||
NetworkPacket temporary = packet; // make a copy
|
||||
|
@ -117,14 +122,15 @@ bool PacketSender::process() {
|
|||
if (keepGoing) {
|
||||
now = usecTimestampNow();
|
||||
uint64_t elapsed = now - _lastSendTime;
|
||||
int usecToSleep = SEND_INTERVAL_USECS - elapsed;
|
||||
|
||||
int usecToSleep = INTERVAL_SLEEP_USECS - elapsed;
|
||||
|
||||
// we only sleep in non-threaded mode
|
||||
if (usecToSleep > 0) {
|
||||
if (usecToSleep > SEND_INTERVAL_USECS) {
|
||||
usecToSleep = SEND_INTERVAL_USECS;
|
||||
if (usecToSleep > INTERVAL_SLEEP_USECS) {
|
||||
usecToSleep = INTERVAL_SLEEP_USECS;
|
||||
}
|
||||
usleep(usecToSleep);
|
||||
hasSlept = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,8 +139,20 @@ bool PacketSender::process() {
|
|||
keepGoing = (packetsThisCall < packetsPerCall) && (packetsLeft > 0);
|
||||
}
|
||||
|
||||
// if threaded and we haven't slept? We want to sleep....
|
||||
if (isThreaded() && !hasSlept) {
|
||||
now = usecTimestampNow();
|
||||
uint64_t elapsed = now - _lastSendTime;
|
||||
int usecToSleep = INTERVAL_SLEEP_USECS - elapsed;
|
||||
if (usecToSleep > 0) {
|
||||
if (usecToSleep > INTERVAL_SLEEP_USECS) {
|
||||
usecToSleep = INTERVAL_SLEEP_USECS;
|
||||
}
|
||||
usleep(usecToSleep);
|
||||
}
|
||||
}
|
||||
|
||||
_lastSendTime = now;
|
||||
}
|
||||
|
||||
return isStillRunning(); // keep running till they terminate us
|
||||
return isStillRunning();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
#include "ReceivedPacketProcessor.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
ReceivedPacketProcessor::ReceivedPacketProcessor() {
|
||||
_dontSleep = false;
|
||||
}
|
||||
|
||||
void ReceivedPacketProcessor::queueReceivedPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength) {
|
||||
// Make sure our Node and NodeList knows we've heard from this node.
|
||||
Node* node = NodeList::getInstance()->nodeWithAddress(&address);
|
||||
|
@ -26,7 +30,10 @@ void ReceivedPacketProcessor::queueReceivedPacket(sockaddr& address, unsigned ch
|
|||
}
|
||||
|
||||
bool ReceivedPacketProcessor::process() {
|
||||
if (_packets.size() == 0) {
|
||||
|
||||
// If a derived class handles process sleeping, like the JurisdiciontListener, then it can set
|
||||
// this _dontSleep member and we will honor that request.
|
||||
if (_packets.size() == 0 && !_dontSleep) {
|
||||
const uint64_t RECEIVED_THREAD_SLEEP_INTERVAL = (1000 * 1000)/60; // check at 60fps
|
||||
usleep(RECEIVED_THREAD_SLEEP_INTERVAL);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
/// Generalized threaded processor for handling received inbound packets.
|
||||
class ReceivedPacketProcessor : public virtual GenericThread {
|
||||
public:
|
||||
ReceivedPacketProcessor();
|
||||
|
||||
/// Add packet from network receive thread to the processing queue.
|
||||
/// \param sockaddr& senderAddress the address of the sender
|
||||
|
@ -30,7 +31,7 @@ public:
|
|||
|
||||
/// How many received packets waiting are to be processed
|
||||
int packetsToProcessCount() const { return _packets.size(); }
|
||||
|
||||
|
||||
protected:
|
||||
/// Callback for processing of recieved packets. Implement this to process the incoming packets.
|
||||
/// \param sockaddr& senderAddress the address of the sender
|
||||
|
@ -42,6 +43,8 @@ protected:
|
|||
/// Implements generic processing behavior for this thread.
|
||||
virtual bool process();
|
||||
|
||||
bool _dontSleep;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<NetworkPacket> _packets;
|
||||
|
|
|
@ -250,10 +250,15 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
|||
|
||||
int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command);
|
||||
unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader];
|
||||
|
||||
*sequenceAt = sequence;
|
||||
unsigned char* copyAt = &messageBuffer[numBytesPacketHeader + sizeof(sequence)];
|
||||
int actualMessageSize = numBytesPacketHeader + sizeof(sequence);
|
||||
|
||||
// pack in timestamp
|
||||
uint64_t now = usecTimestampNow();
|
||||
uint64_t* timeAt = (uint64_t*)&messageBuffer[numBytesPacketHeader + sizeof(sequence)];
|
||||
*timeAt = now;
|
||||
|
||||
unsigned char* copyAt = &messageBuffer[numBytesPacketHeader + sizeof(sequence) + sizeof(now)];
|
||||
int actualMessageSize = numBytesPacketHeader + sizeof(sequence) + sizeof(now);
|
||||
|
||||
for (int i = 0; i < voxelCount && success; i++) {
|
||||
// get the coded voxel
|
||||
|
|
|
@ -71,6 +71,7 @@ VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assign
|
|||
_sendEnvironments = true;
|
||||
_sendMinimalEnvironment = false;
|
||||
_dumpVoxelsOnMove = false;
|
||||
_verboseDebug = false;
|
||||
_jurisdiction = NULL;
|
||||
_jurisdictionSender = NULL;
|
||||
_voxelServerPacketProcessor = NULL;
|
||||
|
@ -427,14 +428,14 @@ void VoxelServer::run() {
|
|||
|
||||
// should we send environments? Default is yes, but this command line suppresses sending
|
||||
const char* SEND_ENVIRONMENTS = "--sendEnvironments";
|
||||
bool dontSendEnvironments = !getCmdOption(_argc, _argv, SEND_ENVIRONMENTS);
|
||||
bool dontSendEnvironments = !cmdOptionExists(_argc, _argv, SEND_ENVIRONMENTS);
|
||||
if (dontSendEnvironments) {
|
||||
qDebug("Sending environments suppressed...\n");
|
||||
_sendEnvironments = false;
|
||||
} else {
|
||||
// should we send environments? Default is yes, but this command line suppresses sending
|
||||
const char* MINIMAL_ENVIRONMENT = "--minimalEnvironment";
|
||||
_sendMinimalEnvironment = getCmdOption(_argc, _argv, MINIMAL_ENVIRONMENT);
|
||||
_sendMinimalEnvironment = cmdOptionExists(_argc, _argv, MINIMAL_ENVIRONMENT);
|
||||
qDebug("Using Minimal Environment=%s\n", debug::valueOf(_sendMinimalEnvironment));
|
||||
}
|
||||
qDebug("Sending environments=%s\n", debug::valueOf(_sendEnvironments));
|
||||
|
@ -455,24 +456,28 @@ void VoxelServer::run() {
|
|||
srand((unsigned)time(0));
|
||||
|
||||
const char* DISPLAY_VOXEL_STATS = "--displayVoxelStats";
|
||||
_displayVoxelStats = getCmdOption(_argc, _argv, DISPLAY_VOXEL_STATS);
|
||||
_displayVoxelStats = cmdOptionExists(_argc, _argv, DISPLAY_VOXEL_STATS);
|
||||
qDebug("displayVoxelStats=%s\n", debug::valueOf(_displayVoxelStats));
|
||||
|
||||
const char* VERBOSE_DEBUG = "--verboseDebug";
|
||||
_verboseDebug = cmdOptionExists(_argc, _argv, VERBOSE_DEBUG);
|
||||
qDebug("verboseDebug=%s\n", debug::valueOf(_verboseDebug));
|
||||
|
||||
const char* DEBUG_VOXEL_SENDING = "--debugVoxelSending";
|
||||
_debugVoxelSending = getCmdOption(_argc, _argv, DEBUG_VOXEL_SENDING);
|
||||
_debugVoxelSending = cmdOptionExists(_argc, _argv, DEBUG_VOXEL_SENDING);
|
||||
qDebug("debugVoxelSending=%s\n", debug::valueOf(_debugVoxelSending));
|
||||
|
||||
const char* DEBUG_VOXEL_RECEIVING = "--debugVoxelReceiving";
|
||||
_debugVoxelReceiving = getCmdOption(_argc, _argv, DEBUG_VOXEL_RECEIVING);
|
||||
_debugVoxelReceiving = cmdOptionExists(_argc, _argv, DEBUG_VOXEL_RECEIVING);
|
||||
qDebug("debugVoxelReceiving=%s\n", debug::valueOf(_debugVoxelReceiving));
|
||||
|
||||
const char* WANT_ANIMATION_DEBUG = "--shouldShowAnimationDebug";
|
||||
_shouldShowAnimationDebug = getCmdOption(_argc, _argv, WANT_ANIMATION_DEBUG);
|
||||
_shouldShowAnimationDebug = cmdOptionExists(_argc, _argv, WANT_ANIMATION_DEBUG);
|
||||
qDebug("shouldShowAnimationDebug=%s\n", debug::valueOf(_shouldShowAnimationDebug));
|
||||
|
||||
// By default we will voxel persist, if you want to disable this, then pass in this parameter
|
||||
const char* NO_VOXEL_PERSIST = "--NoVoxelPersist";
|
||||
if (getCmdOption(_argc, _argv, NO_VOXEL_PERSIST)) {
|
||||
if (cmdOptionExists(_argc, _argv, NO_VOXEL_PERSIST)) {
|
||||
_wantVoxelPersist = false;
|
||||
}
|
||||
qDebug("wantVoxelPersist=%s\n", debug::valueOf(_wantVoxelPersist));
|
||||
|
@ -603,6 +608,34 @@ void VoxelServer::run() {
|
|||
|| packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE
|
||||
|| packetData[0] == PACKET_TYPE_ERASE_VOXEL
|
||||
|| packetData[0] == PACKET_TYPE_Z_COMMAND)) {
|
||||
|
||||
|
||||
const char* messageName;
|
||||
switch (packetData[0]) {
|
||||
case PACKET_TYPE_SET_VOXEL:
|
||||
messageName = "PACKET_TYPE_SET_VOXEL";
|
||||
break;
|
||||
case PACKET_TYPE_SET_VOXEL_DESTRUCTIVE:
|
||||
messageName = "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE";
|
||||
break;
|
||||
case PACKET_TYPE_ERASE_VOXEL:
|
||||
messageName = "PACKET_TYPE_ERASE_VOXEL";
|
||||
break;
|
||||
}
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
|
||||
if (packetData[0] != PACKET_TYPE_Z_COMMAND) {
|
||||
unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader)));
|
||||
uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence))));
|
||||
uint64_t arrivedAt = usecTimestampNow();
|
||||
uint64_t transitTime = arrivedAt - sentAt;
|
||||
if (wantShowAnimationDebug() || wantsDebugVoxelReceiving()) {
|
||||
printf("RECEIVE THREAD: got %s - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n",
|
||||
messageName,
|
||||
packetLength, sequence, transitTime);
|
||||
}
|
||||
}
|
||||
|
||||
_voxelServerPacketProcessor->queueReceivedPacket(senderAddress, packetData, packetLength);
|
||||
} else {
|
||||
// let processNodeData handle it.
|
||||
|
@ -611,7 +644,7 @@ void VoxelServer::run() {
|
|||
}
|
||||
}
|
||||
qDebug() << "VoxelServer::run()... AFTER loop...\n";
|
||||
|
||||
|
||||
// call NodeList::clear() so that all of our node specific objects, including our sending threads, are
|
||||
// properly shutdown and cleaned up.
|
||||
NodeList::getInstance()->clear();
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
bool wantsDebugVoxelSending() const { return _debugVoxelSending; }
|
||||
bool wantsDebugVoxelReceiving() const { return _debugVoxelReceiving; }
|
||||
bool wantsVerboseDebug() const { return _verboseDebug; }
|
||||
bool wantShowAnimationDebug() const { return _shouldShowAnimationDebug; }
|
||||
bool wantSendEnvironments() const { return _sendEnvironments; }
|
||||
bool wantDumpVoxelsOnMove() const { return _dumpVoxelsOnMove; }
|
||||
|
@ -76,6 +77,7 @@ private:
|
|||
bool _sendEnvironments;
|
||||
bool _sendMinimalEnvironment;
|
||||
bool _dumpVoxelsOnMove;
|
||||
bool _verboseDebug;
|
||||
JurisdictionMap* _jurisdiction;
|
||||
JurisdictionSender* _jurisdictionSender;
|
||||
VoxelServerPacketProcessor* _voxelServerPacketProcessor;
|
||||
|
|
|
@ -24,10 +24,10 @@ VoxelServerPacketProcessor::VoxelServerPacketProcessor(VoxelServer* myServer) :
|
|||
|
||||
void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
||||
|
||||
bool debugProcessPacket = _myServer->wantsDebugVoxelReceiving();
|
||||
bool debugProcessPacket = _myServer->wantsVerboseDebug();
|
||||
|
||||
if (debugProcessPacket) {
|
||||
printf("VoxelServerPacketProcessor::processPacket(() packetData=%p packetLength=%ld\n", packetData, packetLength);
|
||||
printf("VoxelServerPacketProcessor::processPacket() packetData=%p packetLength=%ld\n", packetData, packetLength);
|
||||
}
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
|
@ -40,25 +40,23 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned
|
|||
|
||||
_receivedPacketCount++;
|
||||
|
||||
unsigned short int itemNumber = (*((unsigned short int*)(packetData + numBytesPacketHeader)));
|
||||
if (_myServer->wantShowAnimationDebug()) {
|
||||
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
|
||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||
packetLength, itemNumber);
|
||||
}
|
||||
unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader)));
|
||||
uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence))));
|
||||
uint64_t arrivedAt = usecTimestampNow();
|
||||
uint64_t transitTime = arrivedAt - sentAt;
|
||||
|
||||
if (_myServer->wantsDebugVoxelReceiving()) {
|
||||
printf("got %s - %d command from client receivedBytes=%ld itemNumber=%d\n",
|
||||
if (_myServer->wantShowAnimationDebug() || _myServer->wantsDebugVoxelReceiving()) {
|
||||
printf("PROCESSING THREAD: got %s - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n",
|
||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||
_receivedPacketCount, packetLength, itemNumber);
|
||||
_receivedPacketCount, packetLength, sequence, transitTime);
|
||||
}
|
||||
int atByte = numBytesPacketHeader + sizeof(itemNumber);
|
||||
int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt);
|
||||
unsigned char* voxelData = (unsigned char*)&packetData[atByte];
|
||||
while (atByte < packetLength) {
|
||||
int maxSize = packetLength - atByte;
|
||||
|
||||
if (debugProcessPacket) {
|
||||
printf("VoxelServerPacketProcessor::processPacket(() %s packetData=%p packetLength=%ld voxelData=%p atByte=%d maxSize=%d\n",
|
||||
printf("VoxelServerPacketProcessor::processPacket() %s packetData=%p packetLength=%ld voxelData=%p atByte=%d maxSize=%d\n",
|
||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||
packetData, packetLength, voxelData, atByte, maxSize);
|
||||
}
|
||||
|
@ -100,7 +98,7 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned
|
|||
}
|
||||
|
||||
if (debugProcessPacket) {
|
||||
printf("VoxelServerPacketProcessor::processPacket(() DONE LOOPING FOR %s packetData=%p packetLength=%ld voxelData=%p atByte=%d\n",
|
||||
printf("VoxelServerPacketProcessor::processPacket() DONE LOOPING FOR %s packetData=%p packetLength=%ld voxelData=%p atByte=%d\n",
|
||||
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
|
||||
packetData, packetLength, voxelData, atByte);
|
||||
}
|
||||
|
@ -113,6 +111,18 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned
|
|||
|
||||
} else if (packetData[0] == PACKET_TYPE_ERASE_VOXEL) {
|
||||
|
||||
_receivedPacketCount++;
|
||||
|
||||
unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader)));
|
||||
uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence))));
|
||||
uint64_t arrivedAt = usecTimestampNow();
|
||||
uint64_t transitTime = arrivedAt - sentAt;
|
||||
|
||||
if (_myServer->wantShowAnimationDebug() || _myServer->wantsDebugVoxelReceiving()) {
|
||||
printf("PROCESSING THREAD: got PACKET_TYPE_ERASE_VOXEL - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n",
|
||||
_receivedPacketCount, packetLength, sequence, transitTime);
|
||||
}
|
||||
|
||||
// Send these bits off to the VoxelTree class to process them
|
||||
_myServer->getServerTree().lockForWrite();
|
||||
_myServer->getServerTree().processRemoveVoxelBitstream((unsigned char*)packetData, packetLength);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
JurisdictionListener::JurisdictionListener(PacketSenderNotify* notify) :
|
||||
PacketSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND)
|
||||
{
|
||||
ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
nodeList->addHook(this);
|
||||
}
|
||||
|
@ -53,8 +54,11 @@ bool JurisdictionListener::queueJurisdictionRequest() {
|
|||
}
|
||||
}
|
||||
|
||||
// set our packets per second to be the number of nodes
|
||||
setPacketsPerSecond(nodeCount);
|
||||
if (nodeCount > 0){
|
||||
setPacketsPerSecond(nodeCount);
|
||||
} else {
|
||||
setPacketsPerSecond(NO_SERVER_CHECK_RATE);
|
||||
}
|
||||
|
||||
// keep going if still running
|
||||
return isStillRunning();
|
||||
|
@ -84,5 +88,6 @@ bool JurisdictionListener::process() {
|
|||
// NOTE: This will sleep if there are no pending packets to process
|
||||
continueProcessing = ReceivedPacketProcessor::process();
|
||||
}
|
||||
|
||||
return continueProcessing;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
class JurisdictionListener : public NodeListHook, public PacketSender, public ReceivedPacketProcessor {
|
||||
public:
|
||||
static const int DEFAULT_PACKETS_PER_SECOND = 1;
|
||||
static const int NO_SERVER_CHECK_RATE = 60; // if no servers yet detected, keep checking at 60fps
|
||||
|
||||
JurisdictionListener(PacketSenderNotify* notify = NULL);
|
||||
~JurisdictionListener();
|
||||
|
@ -50,6 +51,5 @@ private:
|
|||
NodeToJurisdictionMap _jurisdictions;
|
||||
|
||||
bool queueJurisdictionRequest();
|
||||
|
||||
};
|
||||
#endif // __shared__JurisdictionListener__
|
||||
|
|
|
@ -32,7 +32,8 @@ VoxelEditPacketSender::VoxelEditPacketSender(PacketSenderNotify* notify) :
|
|||
_shouldSend(true),
|
||||
_maxPendingMessages(DEFAULT_MAX_PENDING_MESSAGES),
|
||||
_releaseQueuedMessagesPending(false),
|
||||
_voxelServerJurisdictions(NULL) {
|
||||
_voxelServerJurisdictions(NULL),
|
||||
_sequenceNumber(0) {
|
||||
}
|
||||
|
||||
VoxelEditPacketSender::~VoxelEditPacketSender() {
|
||||
|
@ -273,9 +274,19 @@ void VoxelEditPacketSender::releaseQueuedPacket(EditPacketBuffer& packetBuffer)
|
|||
|
||||
void VoxelEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type) {
|
||||
packetBuffer._currentSize = populateTypeAndVersion(&packetBuffer._currentBuffer[0], type);
|
||||
|
||||
// pack in sequence number
|
||||
unsigned short int* sequenceAt = (unsigned short int*)&packetBuffer._currentBuffer[packetBuffer._currentSize];
|
||||
*sequenceAt = 0;
|
||||
packetBuffer._currentSize += sizeof(unsigned short int); // set to command + sequence
|
||||
*sequenceAt = _sequenceNumber;
|
||||
packetBuffer._currentSize += sizeof(unsigned short int); // nudge past sequence
|
||||
_sequenceNumber++;
|
||||
|
||||
// pack in timestamp
|
||||
uint64_t now = usecTimestampNow();
|
||||
uint64_t* timeAt = (uint64_t*)&packetBuffer._currentBuffer[packetBuffer._currentSize];
|
||||
*timeAt = now;
|
||||
packetBuffer._currentSize += sizeof(uint64_t); // nudge past timestamp
|
||||
|
||||
packetBuffer._currentType = type;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,5 +105,7 @@ private:
|
|||
std::vector<EditPacketBuffer*> _preServerSingleMessagePackets; // these will go out as is
|
||||
|
||||
NodeToJurisdictionMap* _voxelServerJurisdictions;
|
||||
|
||||
unsigned short int _sequenceNumber;
|
||||
};
|
||||
#endif // __shared__VoxelEditPacketSender__
|
||||
|
|
|
@ -576,9 +576,15 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraD
|
|||
}
|
||||
}
|
||||
|
||||
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
||||
void VoxelTree::processRemoveVoxelBitstream(unsigned char* bitstream, int bufferSizeBytes) {
|
||||
//unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)]));
|
||||
int atByte = sizeof(short int) + numBytesForPacketHeader(bitstream);
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(bitstream);
|
||||
unsigned short int sequence = (*((unsigned short int*)(bitstream + numBytesPacketHeader)));
|
||||
uint64_t sentAt = (*((uint64_t*)(bitstream + numBytesPacketHeader + sizeof(sequence))));
|
||||
|
||||
int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt);
|
||||
|
||||
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
|
||||
while (atByte < bufferSizeBytes) {
|
||||
int maxSize = bufferSizeBytes - atByte;
|
||||
|
|
Loading…
Reference in a new issue