mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:38:02 +02:00
use packet version helpers for PACKET_TYPE_SET_VOXEL commands
This commit is contained in:
parent
b816761a74
commit
374fffb151
2 changed files with 33 additions and 23 deletions
|
@ -1312,7 +1312,8 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) {
|
||||||
// if we have room don't have room in the buffer, then send the previously generated message first
|
// if we have room don't have room in the buffer, then send the previously generated message first
|
||||||
if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
||||||
controlledBroadcastToNodes(args->messageBuffer, args->bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
controlledBroadcastToNodes(args->messageBuffer, args->bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
||||||
args->bufferInUse = sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // reset
|
args->bufferInUse = numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_SET_VOXEL_DESTRUCTIVE)
|
||||||
|
+ sizeof(unsigned short int); // reset
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy this node's code color details into our buffer.
|
// copy this node's code color details into our buffer.
|
||||||
|
@ -1375,10 +1376,12 @@ void Application::importVoxels() {
|
||||||
// the server as an set voxel message, this will also rebase the voxels to the new location
|
// the server as an set voxel message, this will also rebase the voxels to the new location
|
||||||
unsigned char* calculatedOctCode = NULL;
|
unsigned char* calculatedOctCode = NULL;
|
||||||
SendVoxelsOperationArgs args;
|
SendVoxelsOperationArgs args;
|
||||||
args.messageBuffer[0] = PACKET_TYPE_SET_VOXEL_DESTRUCTIVE;
|
|
||||||
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE)];
|
int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
|
||||||
|
|
||||||
|
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
|
||||||
*sequenceAt = 0;
|
*sequenceAt = 0;
|
||||||
args.bufferInUse = sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // set to command + sequence
|
args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
|
||||||
|
|
||||||
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
|
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
|
||||||
// voxel size/position details.
|
// voxel size/position details.
|
||||||
|
@ -1391,7 +1394,7 @@ void Application::importVoxels() {
|
||||||
importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
|
importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
|
||||||
|
|
||||||
// If we have voxels left in the packet, then send the packet
|
// If we have voxels left in the packet, then send the packet
|
||||||
if (args.bufferInUse > (sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) {
|
if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
|
||||||
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1426,10 +1429,12 @@ void Application::pasteVoxels() {
|
||||||
// Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to
|
// Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to
|
||||||
// the server as an set voxel message, this will also rebase the voxels to the new location
|
// the server as an set voxel message, this will also rebase the voxels to the new location
|
||||||
SendVoxelsOperationArgs args;
|
SendVoxelsOperationArgs args;
|
||||||
args.messageBuffer[0] = PACKET_TYPE_SET_VOXEL_DESTRUCTIVE;
|
|
||||||
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE)];
|
int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
|
||||||
|
|
||||||
|
unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
|
||||||
*sequenceAt = 0;
|
*sequenceAt = 0;
|
||||||
args.bufferInUse = sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // set to command + sequence
|
args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
|
||||||
|
|
||||||
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
|
// we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
|
||||||
// voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a
|
// voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a
|
||||||
|
@ -1443,7 +1448,7 @@ void Application::pasteVoxels() {
|
||||||
_clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args);
|
_clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args);
|
||||||
|
|
||||||
// If we have voxels left in the packet, then send the packet
|
// If we have voxels left in the packet, then send the packet
|
||||||
if (args.bufferInUse > (sizeof(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) {
|
if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
|
||||||
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,17 +11,20 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "Syssocket.h"
|
#include "Syssocket.h"
|
||||||
#endif
|
#endif
|
||||||
#include "Log.h"
|
|
||||||
#include "SharedUtil.h"
|
|
||||||
#include "OctalCode.h"
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
#include "OctalCode.h"
|
||||||
|
#include "PacketHeaders.h"
|
||||||
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
long long usecTimestamp(timeval *time) {
|
long long usecTimestamp(timeval *time) {
|
||||||
return (time->tv_sec * 1000000 + time->tv_usec);
|
return (time->tv_sec * 1000000 + time->tv_usec);
|
||||||
}
|
}
|
||||||
|
@ -209,13 +212,14 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
|
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
|
||||||
int actualMessageSize = 3;
|
int actualMessageSize = 3;
|
||||||
unsigned char* messageBuffer = new unsigned char[messageSize];
|
unsigned char* messageBuffer = new unsigned char[messageSize];
|
||||||
unsigned short int* sequenceAt = (unsigned short int*)&messageBuffer[1];
|
|
||||||
|
|
||||||
messageBuffer[0]=command;
|
int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command);
|
||||||
*sequenceAt=sequence;
|
unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader];
|
||||||
unsigned char* copyAt = &messageBuffer[3];
|
|
||||||
|
|
||||||
for (int i=0;i<voxelCount && success;i++) {
|
*sequenceAt = sequence;
|
||||||
|
unsigned char* copyAt = &messageBuffer[numBytesPacketHeader + sizeof(sequence)];
|
||||||
|
|
||||||
|
for (int i = 0; i < voxelCount && success; i++) {
|
||||||
// get the coded voxel
|
// get the coded voxel
|
||||||
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
||||||
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
||||||
|
@ -224,12 +228,12 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
|
|
||||||
// make sure we have room to copy this voxel
|
// make sure we have room to copy this voxel
|
||||||
if (actualMessageSize+lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
if (actualMessageSize+lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
||||||
success=false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
// add it to our message
|
// add it to our message
|
||||||
memcpy(copyAt,voxelData,lengthOfVoxelData);
|
memcpy(copyAt, voxelData, lengthOfVoxelData);
|
||||||
copyAt+=lengthOfVoxelData;
|
copyAt += lengthOfVoxelData;
|
||||||
actualMessageSize+=lengthOfVoxelData;
|
actualMessageSize += lengthOfVoxelData;
|
||||||
}
|
}
|
||||||
// cleanup
|
// cleanup
|
||||||
delete[] voxelData;
|
delete[] voxelData;
|
||||||
|
@ -238,9 +242,10 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
if (success) {
|
if (success) {
|
||||||
// finally, copy the result to the output
|
// finally, copy the result to the output
|
||||||
bufferOut = new unsigned char[actualMessageSize];
|
bufferOut = new unsigned char[actualMessageSize];
|
||||||
sizeOut=actualMessageSize;
|
sizeOut = actualMessageSize;
|
||||||
memcpy(bufferOut,messageBuffer,actualMessageSize);
|
memcpy(bufferOut, messageBuffer, actualMessageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] messageBuffer; // clean up our temporary buffer
|
delete[] messageBuffer; // clean up our temporary buffer
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue