mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:23:06 +02:00
fix unecessary copy of Agent, blow away linkedData to rebuild it
This commit is contained in:
parent
ea43988173
commit
9ec51116d5
6 changed files with 20 additions and 16 deletions
|
@ -46,7 +46,6 @@ int listForBroadcast(unsigned char *listBuffer, sockaddr *agentPublicAddress, so
|
||||||
unsigned char *startPointer = currentBufferPos;
|
unsigned char *startPointer = currentBufferPos;
|
||||||
|
|
||||||
for(std::vector<Agent>::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) {
|
||||||
*currentBufferPos++ = agent->type;
|
|
||||||
|
|
||||||
if (DEBUG_TO_SELF || !agent->matches(agentPublicAddress, agentLocalAddress, agentType)) {
|
if (DEBUG_TO_SELF || !agent->matches(agentPublicAddress, agentLocalAddress, agentType)) {
|
||||||
*currentBufferPos++ = agent->type;
|
*currentBufferPos++ = agent->type;
|
||||||
|
|
|
@ -339,13 +339,13 @@ int Head::getBroadcastData(char* data)
|
||||||
sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f", getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
|
sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f", getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
|
||||||
position.x + leanSideways, position.y, position.z + leanForward,
|
position.x + leanSideways, position.y, position.z + leanForward,
|
||||||
loudness, averageLoudness);
|
loudness, averageLoudness);
|
||||||
//printf("x: %3.1f\n", position.x);
|
|
||||||
return strlen(data);
|
return strlen(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::parseData(void *data, int size) {
|
void Head::parseData(void *data, int size) {
|
||||||
// parse head data for this agent
|
// parse head data for this agent
|
||||||
sscanf((char *)data, "%f,%f,%f,%f,%f,%f,%f,%f",
|
std::cout << "HD: " << (char *)data << "\n";
|
||||||
|
sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f",
|
||||||
&Pitch, &Yaw, &Roll,
|
&Pitch, &Yaw, &Roll,
|
||||||
&position.x, &position.y, &position.z,
|
&position.x, &position.y, &position.z,
|
||||||
&loudness, &averageLoudness);
|
&loudness, &averageLoudness);
|
||||||
|
|
|
@ -523,6 +523,7 @@ void update_pos(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);
|
||||||
|
std::cout << "BS: " << broadcast_string << "\n";
|
||||||
agentList.broadcastToAgents(broadcast_string, broadcast_bytes);
|
agentList.broadcastToAgents(broadcast_string, broadcast_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,7 +868,10 @@ void mouseoverFunc( int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
void attachNewHeadToAgent(Agent *newAgent) {
|
void attachNewHeadToAgent(Agent *newAgent) {
|
||||||
newAgent->linkedData = new Head();
|
if (newAgent->linkedData == NULL) {
|
||||||
|
newAgent->linkedData = new Head();
|
||||||
|
std::cout << "LD: " << newAgent->linkedData << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -923,7 +927,7 @@ int main(int argc, char** argv)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
// the callback for our instance of AgentList is attachNewHeadToAgent
|
// the callback for our instance of AgentList is attachNewHeadToAgent
|
||||||
agentList.newAgentCallback = &attachNewHeadToAgent;
|
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
|
||||||
|
|
||||||
// create thread for receipt of data via UDP
|
// create thread for receipt of data via UDP
|
||||||
pthread_t networkReceiveThread;
|
pthread_t networkReceiveThread;
|
||||||
|
|
|
@ -44,10 +44,8 @@ Agent::Agent(const Agent &otherAgent) {
|
||||||
|
|
||||||
type = otherAgent.type;
|
type = otherAgent.type;
|
||||||
|
|
||||||
|
// linked data is transient, gets re-assigned on next packet receive
|
||||||
linkedData = (AgentData *) malloc(sizeof(otherAgent.linkedData));
|
linkedData = NULL;
|
||||||
// copy over linkedData
|
|
||||||
memcpy((void*)linkedData, (void *)otherAgent.linkedData, sizeof(otherAgent.linkedData));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Agent& Agent::operator=(Agent otherAgent) {
|
Agent& Agent::operator=(Agent otherAgent) {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
||||||
|
linkedDataCreateCallback = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
||||||
|
@ -55,11 +55,15 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, s
|
||||||
int agentIndex = indexOfMatchingAgent(senderAddress);
|
int agentIndex = indexOfMatchingAgent(senderAddress);
|
||||||
|
|
||||||
if (agentIndex != -1) {
|
if (agentIndex != -1) {
|
||||||
Agent matchingAgent = agents[agentIndex];
|
Agent *matchingAgent = &agents[agentIndex];
|
||||||
|
|
||||||
if (matchingAgent.linkedData != NULL) {
|
if (matchingAgent->linkedData == NULL) {
|
||||||
matchingAgent.linkedData->parseData(packetData, dataBytes);
|
if (linkedDataCreateCallback != NULL) {
|
||||||
|
linkedDataCreateCallback(matchingAgent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchingAgent->linkedData->parseData(packetData, dataBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,6 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
|
|
||||||
std::cout << "Added agent - " << &newAgent << "\n";
|
std::cout << "Added agent - " << &newAgent << "\n";
|
||||||
|
|
||||||
newAgentCallback(&newAgent);
|
|
||||||
agents.push_back(newAgent);
|
agents.push_back(newAgent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -135,7 +138,7 @@ void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
if (agent->activeSocket != NULL) {
|
if (agent->activeSocket != NULL) {
|
||||||
// we know which socket is good for this agent, send there
|
// we know which socket is good for this agent, send there
|
||||||
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, sizeof(&broadcastData));
|
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, dataBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ class AgentList {
|
||||||
AgentList();
|
AgentList();
|
||||||
AgentList(int socketListenPort);
|
AgentList(int socketListenPort);
|
||||||
std::vector<Agent> agents;
|
std::vector<Agent> agents;
|
||||||
void(*newAgentCallback)(Agent *);
|
void(*linkedDataCreateCallback)(Agent *);
|
||||||
|
|
||||||
UDPSocket* getAgentSocket();
|
UDPSocket* getAgentSocket();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue