mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:49:12 +02:00
Added agentTypes to AgentList::broadcastToAgents()
Make voxel server rebroadcast "remove voxel" messages to all it's connected heads Cleaned up processing of Remove voxel messages to live in VoxelTree
This commit is contained in:
parent
407fa95195
commit
9220ba3ee5
7 changed files with 56 additions and 30 deletions
|
@ -84,11 +84,20 @@ void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bo
|
||||||
|
|
||||||
|
|
||||||
void VoxelSystem::parseData(void *data, int size) {
|
void VoxelSystem::parseData(void *data, int size) {
|
||||||
// output the bits received from the voxel server
|
|
||||||
|
unsigned char command = *(unsigned char*)data;
|
||||||
unsigned char *voxelData = (unsigned char *) data + 1;
|
unsigned char *voxelData = (unsigned char *) data + 1;
|
||||||
|
|
||||||
// ask the VoxelTree to read the bitstream into the tree
|
switch(command) {
|
||||||
tree->readBitstreamToTree(voxelData, size - 1);
|
case 'V':
|
||||||
|
// ask the VoxelTree to read the bitstream into the tree
|
||||||
|
tree->readBitstreamToTree(voxelData, size - 1);
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
// ask the tree to read the "remove" bitstream
|
||||||
|
tree->processRemoveVoxelBitstream((unsigned char*)data,size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
setupNewVoxelsForDrawing();
|
setupNewVoxelsForDrawing();
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,7 +467,7 @@ void simulateHead(float frametime)
|
||||||
const int MAX_BROADCAST_STRING = 200;
|
const int MAX_BROADCAST_STRING = 200;
|
||||||
char broadcast_string[MAX_BROADCAST_STRING];
|
char broadcast_string[MAX_BROADCAST_STRING];
|
||||||
int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
|
int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
|
||||||
agentList.broadcastToAgents(broadcast_string, broadcast_bytes);
|
agentList.broadcastToAgents(broadcast_string, broadcast_bytes,AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_test_spot = WIDTH/2;
|
int render_test_spot = WIDTH/2;
|
||||||
|
@ -790,14 +790,13 @@ void *networkReceive(void *args)
|
||||||
|
|
||||||
while (!stopNetworkReceiveThread) {
|
while (!stopNetworkReceiveThread) {
|
||||||
if (agentList.getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
if (agentList.getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
PerfStat("networkReceive receive()");
|
|
||||||
packetcount++;
|
packetcount++;
|
||||||
bytescount += bytesReceived;
|
bytescount += bytesReceived;
|
||||||
|
|
||||||
if (incomingPacket[0] == 't') {
|
if (incomingPacket[0] == 't') {
|
||||||
// Pass everything but transmitter data to the agent list
|
// Pass everything but transmitter data to the agent list
|
||||||
myHead.hand->processTransmitterData(incomingPacket, bytesReceived);
|
myHead.hand->processTransmitterData(incomingPacket, bytesReceived);
|
||||||
} else if (incomingPacket[0] == 'V') {
|
} else if (incomingPacket[0] == 'V' || incomingPacket[0] == 'R') {
|
||||||
voxels.parseData(incomingPacket, bytesReceived);
|
voxels.parseData(incomingPacket, bytesReceived);
|
||||||
} else {
|
} else {
|
||||||
agentList.processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
agentList.processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
|
|
|
@ -209,11 +209,13 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
const char* AgentList::AGENTS_OF_TYPE_HEAD = "H";
|
||||||
|
const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI";
|
||||||
|
|
||||||
|
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes,const char* agentTypes) {
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
// for now assume we only want to send to other interface clients
|
// only send to the AgentTypes we are asked to send to.
|
||||||
// until the Audio class uses the AgentList
|
if (agent->getActiveSocket() != NULL && strchr(agentTypes,agent->getType())) {
|
||||||
if (agent->getActiveSocket() != NULL && (agent->getType() == 'I' || agent->getType() == 'V')) {
|
|
||||||
// we know which socket is good for this agent, send there
|
// we know which socket is good for this agent, send there
|
||||||
agentSocket.send(agent->getActiveSocket(), broadcastData, dataBytes);
|
agentSocket.send(agent->getActiveSocket(), broadcastData, dataBytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern char DOMAIN_HOSTNAME[];
|
||||||
extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup
|
extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup
|
||||||
extern const int DOMAINSERVER_PORT;
|
extern const int DOMAINSERVER_PORT;
|
||||||
|
|
||||||
|
|
||||||
class AgentList {
|
class AgentList {
|
||||||
|
|
||||||
UDPSocket agentSocket;
|
UDPSocket agentSocket;
|
||||||
|
@ -56,7 +57,7 @@ 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, void *packetData, size_t dataBytes);
|
||||||
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
||||||
void broadcastToAgents(char *broadcastData, size_t dataBytes);
|
void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes);
|
||||||
void pingAgents();
|
void pingAgents();
|
||||||
char getOwnerType();
|
char getOwnerType();
|
||||||
unsigned int getSocketListenPort();
|
unsigned int getSocketListenPort();
|
||||||
|
@ -65,6 +66,10 @@ public:
|
||||||
void stopSilentAgentRemovalThread();
|
void stopSilentAgentRemovalThread();
|
||||||
void startDomainServerCheckInThread();
|
void startDomainServerCheckInThread();
|
||||||
void stopDomainServerCheckInThread();
|
void stopDomainServerCheckInThread();
|
||||||
|
|
||||||
|
static const char* AGENTS_OF_TYPE_HEAD;
|
||||||
|
static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int unpackAgentId(unsigned char *packedData, uint16_t *agentId);
|
int unpackAgentId(unsigned char *packedData, uint16_t *agentId);
|
||||||
|
|
|
@ -388,6 +388,27 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
|
||||||
return childStopOctalCode;
|
return childStopOctalCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
||||||
|
// XXXBHG: validate buffer is at least 4 bytes long? other guards??
|
||||||
|
unsigned short int itemNumber = (*((unsigned short int*)&bitstream[1]));
|
||||||
|
printf("processRemoveVoxelBitstream() receivedBytes=%d itemNumber=%d\n",bufferSizeBytes,itemNumber);
|
||||||
|
int atByte = 3;
|
||||||
|
unsigned char* pVoxelData = (unsigned char*)&bitstream[3];
|
||||||
|
while (atByte < bufferSizeBytes) {
|
||||||
|
unsigned char octets = (unsigned char)*pVoxelData;
|
||||||
|
int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color!
|
||||||
|
|
||||||
|
float* vertices = firstVertexForCode(pVoxelData);
|
||||||
|
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
||||||
|
delete []vertices;
|
||||||
|
|
||||||
|
deleteVoxelCodeFromTree(pVoxelData);
|
||||||
|
|
||||||
|
pVoxelData+=voxelDataSize;
|
||||||
|
atByte+=voxelDataSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VoxelTree::printTreeForDebugging(VoxelNode *startNode) {
|
void VoxelTree::printTreeForDebugging(VoxelNode *startNode) {
|
||||||
int colorMask = 0;
|
int colorMask = 0;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ public:
|
||||||
|
|
||||||
VoxelNode *rootNode;
|
VoxelNode *rootNode;
|
||||||
int leavesWrittenToBitstream;
|
int leavesWrittenToBitstream;
|
||||||
|
|
||||||
|
void processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes);
|
||||||
void readBitstreamToTree(unsigned char * bitstream, int bufferSizeBytes);
|
void readBitstreamToTree(unsigned char * bitstream, int bufferSizeBytes);
|
||||||
void readCodeColorBufferToTree(unsigned char *codeColorBuffer);
|
void readCodeColorBufferToTree(unsigned char *codeColorBuffer);
|
||||||
void deleteVoxelCodeFromTree(unsigned char *codeBuffer);
|
void deleteVoxelCodeFromTree(unsigned char *codeBuffer);
|
||||||
|
|
|
@ -292,26 +292,15 @@ int main(int argc, const char * argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (packetData[0] == 'R') {
|
if (packetData[0] == 'R') {
|
||||||
unsigned short int itemNumber = (*((unsigned short int*)&packetData[1]));
|
|
||||||
printf("got R - remove voxels - command from client receivedBytes=%ld itemNumber=%d\n",receivedBytes,itemNumber);
|
|
||||||
int atByte = 3;
|
|
||||||
unsigned char* pVoxelData = (unsigned char*)&packetData[3];
|
|
||||||
while (atByte < receivedBytes) {
|
|
||||||
unsigned char octets = (unsigned char)*pVoxelData;
|
|
||||||
int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color!
|
|
||||||
|
|
||||||
float* vertices = firstVertexForCode(pVoxelData);
|
// Send these bits off to the VoxelTree class to process them
|
||||||
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
printf("got Remove Voxels message, have voxel tree do the work... randomTree.processRemoveVoxelBitstream()\n");
|
||||||
delete []vertices;
|
randomTree.processRemoveVoxelBitstream((unsigned char*)packetData,receivedBytes);
|
||||||
|
|
||||||
randomTree.deleteVoxelCodeFromTree(pVoxelData);
|
// Now send this to the connected agents so they know to delete
|
||||||
|
printf("rebroadcasting delete voxel message to connected agents... agentList.broadcastToAgents()\n");
|
||||||
|
agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD);
|
||||||
//printf("readCodeColorBufferToTree() of size=%d atByte=%d receivedBytes=%ld\n",voxelDataSize,atByte,receivedBytes);
|
|
||||||
// skip to next
|
|
||||||
pVoxelData+=voxelDataSize;
|
|
||||||
atByte+=voxelDataSize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (packetData[0] == 'H') {
|
if (packetData[0] == 'H') {
|
||||||
if (agentList.addOrUpdateAgent(&agentPublicAddress,
|
if (agentList.addOrUpdateAgent(&agentPublicAddress,
|
||||||
|
|
Loading…
Reference in a new issue