mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 14:59:14 +02:00
change signature of parseData to use unsigned char*, include packet header always
This commit is contained in:
parent
288a259ac1
commit
5c091a51a6
16 changed files with 40 additions and 41 deletions
|
@ -309,7 +309,7 @@ int main(int argc, const char * argv[])
|
||||||
agentList->increaseAgentId();
|
agentList->increaseAgentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes);
|
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
|
||||||
} else {
|
} else {
|
||||||
memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024);
|
memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024);
|
||||||
agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024);
|
agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024);
|
||||||
|
|
|
@ -77,7 +77,7 @@ int main(int argc, char* argv[])
|
||||||
switch (packetData[0]) {
|
switch (packetData[0]) {
|
||||||
case PACKET_HEADER_HEAD_DATA:
|
case PACKET_HEADER_HEAD_DATA:
|
||||||
// this is positional data from an agent
|
// this is positional data from an agent
|
||||||
agentList->updateAgentWithData(agentAddress, (void *)(packetData + 1), receivedBytes);
|
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
|
||||||
|
|
||||||
currentBufferPosition = broadcastPacket + 1;
|
currentBufferPosition = broadcastPacket + 1;
|
||||||
agentIndex = 0;
|
agentIndex = 0;
|
||||||
|
|
|
@ -1174,7 +1174,7 @@ void Head::SetNewHeadTarget(float pitch, float yaw) {
|
||||||
YawTarget = yaw;
|
YawTarget = yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::processTransmitterData(char *packetData, int numBytes) {
|
void Head::processTransmitterData(unsigned char *packetData, int numBytes) {
|
||||||
// Read a packet from a transmitter app, process the data
|
// Read a packet from a transmitter app, process the data
|
||||||
float accX, accY, accZ,
|
float accX, accY, accZ,
|
||||||
graX, graY, graZ,
|
graX, graY, graZ,
|
||||||
|
|
|
@ -139,7 +139,7 @@ class Head : public AvatarData {
|
||||||
|
|
||||||
void renderBody();
|
void renderBody();
|
||||||
void renderHead( int faceToFace, int isMine );
|
void renderHead( int faceToFace, int isMine );
|
||||||
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
|
void renderOrientataionDirections( glm::vec3 position, Orientation orientation, float size );
|
||||||
|
|
||||||
void simulate(float);
|
void simulate(float);
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class Head : public AvatarData {
|
||||||
// Related to getting transmitter UDP data used to animate the avatar hand
|
// Related to getting transmitter UDP data used to animate the avatar hand
|
||||||
//
|
//
|
||||||
|
|
||||||
void processTransmitterData(char * packetData, int numBytes);
|
void processTransmitterData(unsigned char * packetData, int numBytes);
|
||||||
float getTransmitterHz() { return transmitterHz; };
|
float getTransmitterHz() { return transmitterHz; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -112,33 +112,33 @@ long int VoxelSystem::getVoxelsBytesReadRunningAverage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VoxelSystem::parseData(void *data, int size) {
|
void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
unsigned char command = *(unsigned char*)data;
|
unsigned char command = *sourceBuffer;
|
||||||
unsigned char *voxelData = (unsigned char *) data + 1;
|
unsigned char *voxelData = sourceBuffer + 1;
|
||||||
|
|
||||||
switch(command) {
|
switch(command) {
|
||||||
case PACKET_HEADER_VOXEL_DATA:
|
case PACKET_HEADER_VOXEL_DATA:
|
||||||
// ask the VoxelTree to read the bitstream into the tree
|
// ask the VoxelTree to read the bitstream into the tree
|
||||||
tree->readBitstreamToTree(voxelData, size - 1);
|
tree->readBitstreamToTree(voxelData, numBytes - 1);
|
||||||
break;
|
break;
|
||||||
case PACKET_HEADER_ERASE_VOXEL:
|
case PACKET_HEADER_ERASE_VOXEL:
|
||||||
// ask the tree to read the "remove" bitstream
|
// ask the tree to read the "remove" bitstream
|
||||||
tree->processRemoveVoxelBitstream((unsigned char*)data,size);
|
tree->processRemoveVoxelBitstream(sourceBuffer, numBytes);
|
||||||
break;
|
break;
|
||||||
case PACKET_HEADER_Z_COMMAND:
|
case PACKET_HEADER_Z_COMMAND:
|
||||||
|
|
||||||
// the Z command is a special command that allows the sender to send high level semantic
|
// the Z command is a special command that allows the sender to send high level semantic
|
||||||
// requests, like erase all, or add sphere scene, different receivers may handle these
|
// requests, like erase all, or add sphere scene, different receivers may handle these
|
||||||
// messages differently
|
// messages differently
|
||||||
char* packetData =(char*)data;
|
char* packetData = (char *)sourceBuffer;
|
||||||
char* command = &packetData[1]; // start of the command
|
char* command = &packetData[1]; // start of the command
|
||||||
int commandLength = strlen(command); // commands are null terminated strings
|
int commandLength = strlen(command); // commands are null terminated strings
|
||||||
int totalLength = 1+commandLength+1;
|
int totalLength = 1+commandLength+1;
|
||||||
|
|
||||||
printf("got Z message len(%d)= %s\n",size,command);
|
printf("got Z message len(%d)= %s\n", numBytes, command);
|
||||||
|
|
||||||
while (totalLength <= size) {
|
while (totalLength <= numBytes) {
|
||||||
if (0==strcmp(command,(char*)"erase all")) {
|
if (0==strcmp(command,(char*)"erase all")) {
|
||||||
printf("got Z message == erase all\n");
|
printf("got Z message == erase all\n");
|
||||||
tree->eraseAllVoxels();
|
tree->eraseAllVoxels();
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
VoxelSystem();
|
VoxelSystem();
|
||||||
~VoxelSystem();
|
~VoxelSystem();
|
||||||
|
|
||||||
void parseData(void *data, int size);
|
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
VoxelSystem* clone() const;
|
VoxelSystem* clone() const;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
|
@ -1260,7 +1260,7 @@ void *networkReceive(void *args)
|
||||||
{
|
{
|
||||||
sockaddr senderAddress;
|
sockaddr senderAddress;
|
||||||
ssize_t bytesReceived;
|
ssize_t bytesReceived;
|
||||||
char *incomingPacket = new char[MAX_PACKET_SIZE];
|
unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
while (!stopNetworkReceiveThread) {
|
while (!stopNetworkReceiveThread) {
|
||||||
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
|
|
|
@ -60,16 +60,17 @@ int AvatarData::getBroadcastData(char* destinationBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// called on the other agents - assigns it to my views of the others
|
// called on the other agents - assigns it to my views of the others
|
||||||
void AvatarData::parseData(void *sourceBuffer, int numBytes) {
|
void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
char* bufferPointer = (char*) sourceBuffer ;
|
// increment to push past the packet header
|
||||||
|
sourceBuffer++;
|
||||||
|
|
||||||
memcpy(&_bodyPosition, bufferPointer, sizeof(float) * 3);
|
memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3);
|
||||||
bufferPointer += sizeof(float) * 3;
|
sourceBuffer += sizeof(float) * 3;
|
||||||
|
|
||||||
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyYaw);
|
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw);
|
||||||
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyPitch);
|
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch);
|
||||||
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyRoll);
|
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 AvatarData::getBodyPosition() {
|
glm::vec3 AvatarData::getBodyPosition() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
void setBodyPosition(glm::vec3 bodyPosition);
|
void setBodyPosition(glm::vec3 bodyPosition);
|
||||||
|
|
||||||
int getBroadcastData(char* destinationBuffer);
|
int getBroadcastData(char* destinationBuffer);
|
||||||
void parseData(void *sourceBuffer, int numBytes);
|
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
|
|
||||||
float getBodyYaw();
|
float getBodyYaw();
|
||||||
void setBodyYaw(float bodyYaw);
|
void setBodyYaw(float bodyYaw);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
class AgentData {
|
class AgentData {
|
||||||
public:
|
public:
|
||||||
virtual ~AgentData() = 0;
|
virtual ~AgentData() = 0;
|
||||||
virtual void parseData(void * data, int size) = 0;
|
virtual void parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
||||||
virtual AgentData* clone() const = 0;
|
virtual AgentData* clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent) {
|
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) {
|
||||||
// find the avatar mixer in our agent list and update the lastRecvTime from it
|
// find the avatar mixer in our agent list and update the lastRecvTime from it
|
||||||
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
|
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
|
||||||
delete[] packetHolder;
|
delete[] packetHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes) {
|
void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
|
||||||
// find the agent by the sockaddr
|
// find the agent by the sockaddr
|
||||||
int agentIndex = indexOfMatchingAgent(senderAddress);
|
int agentIndex = indexOfMatchingAgent(senderAddress);
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::updateAgentWithData(Agent *agent, void *packetData, int dataBytes) {
|
void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
|
||||||
agent->setLastRecvTimeUsecs(usecTimestampNow());
|
agent->setLastRecvTimeUsecs(usecTimestampNow());
|
||||||
|
|
||||||
if (agent->getLinkedData() == NULL) {
|
if (agent->getLinkedData() == NULL) {
|
||||||
|
|
|
@ -49,11 +49,11 @@ public:
|
||||||
|
|
||||||
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
|
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
|
||||||
|
|
||||||
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||||
void processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent);
|
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
|
||||||
|
|
||||||
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||||
void updateAgentWithData(Agent *agent, void *packetData, int dataBytes);
|
void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
|
||||||
|
|
||||||
void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
|
void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
|
||||||
char getOwnerType();
|
char getOwnerType();
|
||||||
|
|
|
@ -105,12 +105,10 @@ void AudioRingBuffer::setBearing(float newBearing) {
|
||||||
bearing = newBearing;
|
bearing = newBearing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioRingBuffer::parseData(void *data, int size) {
|
void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
unsigned char *audioDataStart = (unsigned char *) data;
|
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
|
||||||
|
|
||||||
if (size > (bufferLengthSamples * sizeof(int16_t))) {
|
|
||||||
|
|
||||||
unsigned char *dataPtr = audioDataStart + 1;
|
unsigned char *dataPtr = sourceBuffer + 1;
|
||||||
|
|
||||||
for (int p = 0; p < 3; p ++) {
|
for (int p = 0; p < 3; p ++) {
|
||||||
memcpy(&position[p], dataPtr, sizeof(float));
|
memcpy(&position[p], dataPtr, sizeof(float));
|
||||||
|
@ -123,7 +121,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
|
||||||
memcpy(&bearing, dataPtr, sizeof(float));
|
memcpy(&bearing, dataPtr, sizeof(float));
|
||||||
dataPtr += sizeof(float);
|
dataPtr += sizeof(float);
|
||||||
|
|
||||||
audioDataStart = dataPtr;
|
sourceBuffer = dataPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endOfLastWrite == NULL) {
|
if (endOfLastWrite == NULL) {
|
||||||
|
@ -134,7 +132,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
|
||||||
started = false;
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(endOfLastWrite, audioDataStart, bufferLengthSamples * sizeof(int16_t));
|
memcpy(endOfLastWrite, sourceBuffer, bufferLengthSamples * sizeof(int16_t));
|
||||||
|
|
||||||
endOfLastWrite += bufferLengthSamples;
|
endOfLastWrite += bufferLengthSamples;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class AudioRingBuffer : public AgentData {
|
||||||
~AudioRingBuffer();
|
~AudioRingBuffer();
|
||||||
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
||||||
|
|
||||||
void parseData(void *data, int size);
|
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
AudioRingBuffer* clone() const;
|
AudioRingBuffer* clone() const;
|
||||||
|
|
||||||
int16_t* getNextOutput();
|
int16_t* getNextOutput();
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
~VoxelAgentData();
|
~VoxelAgentData();
|
||||||
VoxelAgentData(const VoxelAgentData &otherAgentData);
|
VoxelAgentData(const VoxelAgentData &otherAgentData);
|
||||||
|
|
||||||
void parseData(void *data, int size);
|
void parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
VoxelAgentData* clone() const;
|
VoxelAgentData* clone() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ int main(int argc, const char * argv[])
|
||||||
agentList->increaseAgentId();
|
agentList->increaseAgentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
agentList->updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes);
|
agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue