mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 06:16:24 +02:00
Merge pull request #111 from birarda/avatar-from-mixer
return int of bytes read from parseData, removing AvatarData const, fix socketMatch NULL socket crash
This commit is contained in:
commit
19e7e73b5d
11 changed files with 47 additions and 37 deletions
|
@ -114,7 +114,7 @@ float VoxelSystem::getVoxelsBytesReadPerSecondAverage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
unsigned char command = *sourceBuffer;
|
unsigned char command = *sourceBuffer;
|
||||||
unsigned char *voxelData = sourceBuffer + 1;
|
unsigned char *voxelData = sourceBuffer + 1;
|
||||||
|
@ -154,6 +154,7 @@ void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupNewVoxelsForDrawing();
|
setupNewVoxelsForDrawing();
|
||||||
|
return numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::setupNewVoxelsForDrawing() {
|
void VoxelSystem::setupNewVoxelsForDrawing() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
VoxelSystem();
|
VoxelSystem();
|
||||||
~VoxelSystem();
|
~VoxelSystem();
|
||||||
|
|
||||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
int parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
VoxelSystem* clone() const;
|
VoxelSystem* clone() const;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
|
@ -1456,8 +1456,7 @@ void *networkReceive(void *args)
|
||||||
case PACKET_HEADER_BULK_AVATAR_DATA:
|
case PACKET_HEADER_BULK_AVATAR_DATA:
|
||||||
AgentList::getInstance()->processBulkAgentData(&senderAddress,
|
AgentList::getInstance()->processBulkAgentData(&senderAddress,
|
||||||
incomingPacket,
|
incomingPacket,
|
||||||
bytesReceived,
|
bytesReceived);
|
||||||
BYTES_PER_AVATAR);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
|
|
|
@ -95,7 +95,9 @@ int AvatarData::getBroadcastData(unsigned 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(unsigned char* sourceBuffer, int numBytes) {
|
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
unsigned char* startPosition = sourceBuffer;
|
||||||
|
|
||||||
// increment to push past the packet header
|
// increment to push past the packet header
|
||||||
sourceBuffer++;
|
sourceBuffer++;
|
||||||
|
|
||||||
|
@ -126,6 +128,8 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
sourceBuffer += sizeof(_cameraNearClip);
|
sourceBuffer += sizeof(_cameraNearClip);
|
||||||
memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip));
|
memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip));
|
||||||
sourceBuffer += sizeof(_cameraFarClip);
|
sourceBuffer += sizeof(_cameraFarClip);
|
||||||
|
|
||||||
|
return sourceBuffer - startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 AvatarData::getBodyPosition() {
|
glm::vec3 AvatarData::getBodyPosition() {
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
|
|
||||||
#include <AgentData.h>
|
#include <AgentData.h>
|
||||||
|
|
||||||
const int BYTES_PER_AVATAR = 94;
|
|
||||||
|
|
||||||
class AvatarData : public AgentData {
|
class AvatarData : public AgentData {
|
||||||
public:
|
public:
|
||||||
AvatarData();
|
AvatarData();
|
||||||
|
@ -27,7 +25,7 @@ public:
|
||||||
void setHandPosition(glm::vec3 handPosition);
|
void setHandPosition(glm::vec3 handPosition);
|
||||||
|
|
||||||
int getBroadcastData(unsigned char* destinationBuffer);
|
int getBroadcastData(unsigned char* destinationBuffer);
|
||||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
int 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(unsigned char* sourceBuffer, int numBytes) = 0;
|
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
||||||
virtual AgentData* clone() const = 0;
|
virtual AgentData* clone() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) {
|
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) {
|
||||||
// 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);
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
|
||||||
|
|
||||||
unsigned char *startPosition = packetData;
|
unsigned char *startPosition = packetData;
|
||||||
unsigned char *currentPosition = startPosition + 1;
|
unsigned char *currentPosition = startPosition + 1;
|
||||||
unsigned char packetHolder[numBytesPerAgent + 1];
|
unsigned char packetHolder[numTotalBytes];
|
||||||
|
|
||||||
packetHolder[0] = PACKET_HEADER_HEAD_DATA;
|
packetHolder[0] = PACKET_HEADER_HEAD_DATA;
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
|
||||||
|
|
||||||
while ((currentPosition - startPosition) < numTotalBytes) {
|
while ((currentPosition - startPosition) < numTotalBytes) {
|
||||||
currentPosition += unpackAgentId(currentPosition, &agentID);
|
currentPosition += unpackAgentId(currentPosition, &agentID);
|
||||||
memcpy(packetHolder + 1, currentPosition, numBytesPerAgent);
|
memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition));
|
||||||
|
|
||||||
int matchingAgentIndex = indexOfMatchingAgent(agentID);
|
int matchingAgentIndex = indexOfMatchingAgent(agentID);
|
||||||
|
|
||||||
|
@ -138,22 +138,24 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
|
||||||
matchingAgentIndex = indexOfMatchingAgent(agentID);
|
matchingAgentIndex = indexOfMatchingAgent(agentID);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
|
currentPosition += updateAgentWithData(&agents[matchingAgentIndex],
|
||||||
|
packetHolder,
|
||||||
currentPosition += numBytesPerAgent;
|
numTotalBytes - (currentPosition - startPosition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
|
int 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);
|
||||||
|
|
||||||
if (agentIndex != -1) {
|
if (agentIndex != -1) {
|
||||||
updateAgentWithData(&agents[agentIndex], packetData, dataBytes);
|
return updateAgentWithData(&agents[agentIndex], packetData, dataBytes);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
|
int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
|
||||||
agent->setLastRecvTimeUsecs(usecTimestampNow());
|
agent->setLastRecvTimeUsecs(usecTimestampNow());
|
||||||
agent->recordBytesReceived(dataBytes);
|
agent->recordBytesReceived(dataBytes);
|
||||||
|
|
||||||
|
@ -163,7 +165,7 @@ void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
agent->getLinkedData()->parseData(packetData, dataBytes);
|
return agent->getLinkedData()->parseData(packetData, dataBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentList::indexOfMatchingAgent(sockaddr *senderAddress) {
|
int AgentList::indexOfMatchingAgent(sockaddr *senderAddress) {
|
||||||
|
|
|
@ -50,10 +50,10 @@ 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, unsigned char *packetData, size_t dataBytes);
|
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||||
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
|
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes);
|
||||||
|
|
||||||
void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
int updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||||
void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
|
int updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
|
||||||
|
|
||||||
void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
|
void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
|
||||||
char getOwnerType();
|
char getOwnerType();
|
||||||
|
|
|
@ -105,7 +105,7 @@ void AudioRingBuffer::setBearing(float newBearing) {
|
||||||
bearing = newBearing;
|
bearing = newBearing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
|
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
|
||||||
|
|
||||||
unsigned char *dataPtr = sourceBuffer + 1;
|
unsigned char *dataPtr = sourceBuffer + 1;
|
||||||
|
@ -140,7 +140,9 @@ void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
|
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
|
||||||
endOfLastWrite = buffer;
|
endOfLastWrite = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
short AudioRingBuffer::diffLastWriteNextOutput()
|
short AudioRingBuffer::diffLastWriteNextOutput()
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AudioRingBuffer : public AgentData {
|
||||||
~AudioRingBuffer();
|
~AudioRingBuffer();
|
||||||
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
||||||
|
|
||||||
void parseData(unsigned char* sourceBuffer, int numBytes);
|
int parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
AudioRingBuffer* clone() const;
|
AudioRingBuffer* clone() const;
|
||||||
|
|
||||||
int16_t* getNextOutput();
|
int16_t* getNextOutput();
|
||||||
|
|
|
@ -28,20 +28,24 @@ using shared_lib::printLog;
|
||||||
sockaddr_in destSockaddr, senderAddress;
|
sockaddr_in destSockaddr, senderAddress;
|
||||||
|
|
||||||
bool socketMatch(sockaddr *first, sockaddr *second) {
|
bool socketMatch(sockaddr *first, sockaddr *second) {
|
||||||
// utility function that indicates if two sockets are equivalent
|
if (first != NULL && second != NULL) {
|
||||||
|
// utility function that indicates if two sockets are equivalent
|
||||||
// currently only compares two IPv4 addresses
|
|
||||||
// expandable to IPv6 by adding else if for AF_INET6
|
|
||||||
|
|
||||||
if (first->sa_family != second->sa_family) {
|
|
||||||
// not the same family, can't be equal
|
|
||||||
return false;
|
|
||||||
} else if (first->sa_family == AF_INET) {
|
|
||||||
sockaddr_in *firstIn = (sockaddr_in *) first;
|
|
||||||
sockaddr_in *secondIn = (sockaddr_in *) second;
|
|
||||||
|
|
||||||
return firstIn->sin_addr.s_addr == secondIn->sin_addr.s_addr
|
// currently only compares two IPv4 addresses
|
||||||
|
// expandable to IPv6 by adding else if for AF_INET6
|
||||||
|
|
||||||
|
if (first->sa_family != second->sa_family) {
|
||||||
|
// not the same family, can't be equal
|
||||||
|
return false;
|
||||||
|
} else if (first->sa_family == AF_INET) {
|
||||||
|
sockaddr_in *firstIn = (sockaddr_in *) first;
|
||||||
|
sockaddr_in *secondIn = (sockaddr_in *) second;
|
||||||
|
|
||||||
|
return firstIn->sin_addr.s_addr == secondIn->sin_addr.s_addr
|
||||||
&& firstIn->sin_port == secondIn->sin_port;
|
&& firstIn->sin_port == secondIn->sin_port;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue