mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 23:32:48 +02:00
use AgentData class to abstract implemenation of linked data
This commit is contained in:
parent
c57380012e
commit
060f4dceca
12 changed files with 181 additions and 226 deletions
|
@ -36,18 +36,24 @@ unsigned char packetData[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
const int LOGOFF_CHECK_INTERVAL = 5000;
|
const int LOGOFF_CHECK_INTERVAL = 5000;
|
||||||
|
|
||||||
|
#define DEBUG_TO_SELF 0
|
||||||
|
|
||||||
int lastActiveCount = 0;
|
int lastActiveCount = 0;
|
||||||
AgentList agentList(DOMAIN_LISTEN_PORT);
|
AgentList agentList(DOMAIN_LISTEN_PORT);
|
||||||
|
|
||||||
int listForBroadcast(unsigned char *listBuffer) {
|
int listForBroadcast(unsigned char *listBuffer, sockaddr *agentPublicAddress, sockaddr *agentLocalAddress, char agentType) {
|
||||||
unsigned char *currentBufferPos = listBuffer + 1;
|
unsigned char *currentBufferPos = listBuffer + 1;
|
||||||
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;
|
*currentBufferPos++ = agent->type;
|
||||||
|
|
||||||
currentBufferPos += packSocket(currentBufferPos, agent->publicSocket);
|
if (DEBUG_TO_SELF || !agent->matches(agentPublicAddress, agentLocalAddress, agentType)) {
|
||||||
currentBufferPos += packSocket(currentBufferPos, agent->localSocket);
|
*currentBufferPos++ = agent->type;
|
||||||
|
|
||||||
|
currentBufferPos += packSocket(currentBufferPos, agent->publicSocket);
|
||||||
|
currentBufferPos += packSocket(currentBufferPos, agent->localSocket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1 + (currentBufferPos - startPointer); // 1 is added for the leading 'D'
|
return 1 + (currentBufferPos - startPointer); // 1 is added for the leading 'D'
|
||||||
|
@ -71,7 +77,7 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType);
|
agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType);
|
||||||
|
|
||||||
int listBytes = listForBroadcast(broadcastPacket);
|
int listBytes = listForBroadcast(broadcastPacket, (sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType);
|
||||||
|
|
||||||
if (listBytes > 0) {
|
if (listBytes > 0) {
|
||||||
agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, listBytes);
|
agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, listBytes);
|
||||||
|
|
|
@ -9,12 +9,12 @@ set(PORTAUDIO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
|
||||||
project(interface)
|
project(interface)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# link in required OS X frameworks and include the right GL headers
|
# link in required OS X frameworks and include the right GL headers
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreServices -framework Carbon")
|
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreServices -framework Carbon")
|
||||||
set(GL_HEADERS "#include <GLUT/glut.h>\n#include <OpenGL/glext.h>")
|
set(GL_HEADERS "#include <GLUT/glut.h>\n#include <OpenGL/glext.h>")
|
||||||
else (APPLE)
|
else (APPLE)
|
||||||
# include the right GL headers for UNIX
|
# include the right GL headers for UNIX
|
||||||
set(GL_HEADERS "#include <GL/gl.h>\n#include <GL/glut.h>\n#include <GL/glext.h>")
|
set(GL_HEADERS "#include <GL/gl.h>\n#include <GL/glut.h>\n#include <GL/glext.h>")
|
||||||
endif (APPLE)
|
endif (APPLE)
|
||||||
|
|
||||||
# create the InterfaceConfig.h file based on GL_HEADERS above
|
# create the InterfaceConfig.h file based on GL_HEADERS above
|
||||||
|
|
|
@ -272,7 +272,7 @@ void *receiveAudioViaUDP(void *args) {
|
||||||
* @return Returns true if successful or false if an error occurred.
|
* @return Returns true if successful or false if an error occurred.
|
||||||
Use Audio::getError() to retrieve the error code.
|
Use Audio::getError() to retrieve the error code.
|
||||||
*/
|
*/
|
||||||
Audio::Audio(Head *mainHead, Oscilloscope * s)
|
Audio::Audio(Oscilloscope * s)
|
||||||
{
|
{
|
||||||
paError = Pa_Initialize();
|
paError = Pa_Initialize();
|
||||||
if (paError != paNoError) goto error;
|
if (paError != paNoError) goto error;
|
||||||
|
@ -292,8 +292,6 @@ Audio::Audio(Head *mainHead, Oscilloscope * s)
|
||||||
|
|
||||||
pthread_create(&audioReceiveThread, NULL, receiveAudioViaUDP, (void *) &threadArgs);
|
pthread_create(&audioReceiveThread, NULL, receiveAudioViaUDP, (void *) &threadArgs);
|
||||||
|
|
||||||
audioData->linkedHead = mainHead;
|
|
||||||
|
|
||||||
paError = Pa_OpenDefaultStream(&stream,
|
paError = Pa_OpenDefaultStream(&stream,
|
||||||
2, // input channels
|
2, // input channels
|
||||||
2, // output channels
|
2, // output channels
|
||||||
|
|
|
@ -11,14 +11,13 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
#include "Head.h"
|
|
||||||
#include "AudioData.h"
|
#include "AudioData.h"
|
||||||
#include "Oscilloscope.h"
|
#include "Oscilloscope.h"
|
||||||
|
|
||||||
class Audio {
|
class Audio {
|
||||||
public:
|
public:
|
||||||
// initializes audio I/O
|
// initializes audio I/O
|
||||||
Audio(Head* mainHead, Oscilloscope * s);
|
Audio(Oscilloscope * s);
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
void render(int screenWidth, int screenHeight);
|
void render(int screenWidth, int screenHeight);
|
||||||
|
|
|
@ -12,13 +12,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "AudioRingBuffer.h"
|
#include "AudioRingBuffer.h"
|
||||||
#include "Head.h"
|
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
class AudioData {
|
class AudioData {
|
||||||
public:
|
public:
|
||||||
Head *linkedHead;
|
|
||||||
|
|
||||||
AudioRingBuffer *ringBuffer;
|
AudioRingBuffer *ringBuffer;
|
||||||
|
|
||||||
UDPSocket *audioSocket;
|
UDPSocket *audioSocket;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "Head.h"
|
#include "Head.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "SerialInterface.h"
|
#include "SerialInterface.h"
|
||||||
#include "Audio.h"
|
|
||||||
|
|
||||||
float skinColor[] = {1.0, 0.84, 0.66};
|
float skinColor[] = {1.0, 0.84, 0.66};
|
||||||
float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0};
|
float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0};
|
||||||
|
@ -60,6 +59,10 @@ Head::Head()
|
||||||
setNoise(0);
|
setNoise(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Head::~Head() {
|
||||||
|
// all data is primitive, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
void Head::reset()
|
void Head::reset()
|
||||||
{
|
{
|
||||||
Pitch = Yaw = Roll = 0;
|
Pitch = Yaw = Roll = 0;
|
||||||
|
@ -328,7 +331,6 @@ void Head::render(int faceToFace, float * myLocation)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Transmit data to agents requesting it
|
// Transmit data to agents requesting it
|
||||||
|
|
||||||
int Head::getBroadcastData(char* data)
|
int Head::getBroadcastData(char* data)
|
||||||
|
@ -341,12 +343,12 @@ int Head::getBroadcastData(char* data)
|
||||||
return strlen(data);
|
return strlen(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::recvBroadcastData(char * data, int size)
|
void Head::parseData(void *data, int size) {
|
||||||
{
|
// parse head data for this agent
|
||||||
sscanf(data, "%f,%f,%f,%f,%f,%f,%f,%f", &Pitch, &Yaw, &Roll,
|
sscanf((char *)data, "%f,%f,%f,%f,%f,%f,%f,%f",
|
||||||
|
&Pitch, &Yaw, &Roll,
|
||||||
&position.x, &position.y, &position.z,
|
&position.x, &position.y, &position.z,
|
||||||
&loudness, &averageLoudness);
|
&loudness, &averageLoudness);
|
||||||
//printf("%f,%f,%f,%f,%f,%f\n", Pitch, Yaw, Roll, position.x, position.y, position.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::SetNewHeadTarget(float pitch, float yaw)
|
void Head::SetNewHeadTarget(float pitch, float yaw)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define __interface__head__
|
#define __interface__head__
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "AgentData.h"
|
||||||
#include "Field.h"
|
#include "Field.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
@ -17,83 +18,84 @@
|
||||||
|
|
||||||
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
||||||
|
|
||||||
class Head {
|
class Head : public AgentData {
|
||||||
float noise;
|
public:
|
||||||
float Pitch;
|
Head();
|
||||||
float Yaw;
|
~Head();
|
||||||
float Roll;
|
void reset();
|
||||||
float PitchRate;
|
void UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
|
||||||
float YawRate;
|
void setNoise (float mag) { noise = mag; }
|
||||||
float RollRate;
|
void setPitch(float p) {Pitch = p; }
|
||||||
float EyeballPitch[2];
|
void setYaw(float y) {Yaw = y; }
|
||||||
float EyeballYaw[2];
|
void setRoll(float r) {Roll = r; };
|
||||||
float EyebrowPitch[2];
|
void setScale(float s) {scale = s; };
|
||||||
float EyebrowRoll[2];
|
void setRenderYaw(float y) {renderYaw = y;}
|
||||||
float EyeballScaleX, EyeballScaleY, EyeballScaleZ;
|
void setRenderPitch(float p) {renderPitch = p;}
|
||||||
float interPupilDistance;
|
float getRenderYaw() {return renderYaw;}
|
||||||
float interBrowDistance;
|
float getRenderPitch() {return renderPitch;}
|
||||||
float NominalPupilSize;
|
void setLeanForward(float dist);
|
||||||
float PupilSize;
|
void setLeanSideways(float dist);
|
||||||
float MouthPitch;
|
void addPitch(float p) {Pitch -= p; }
|
||||||
float MouthYaw;
|
void addYaw(float y){Yaw -= y; }
|
||||||
float MouthWidth;
|
void addRoll(float r){Roll += r; }
|
||||||
float MouthHeight;
|
void addLean(float x, float z);
|
||||||
float leanForward;
|
float getPitch() {return Pitch;}
|
||||||
float leanSideways;
|
float getRoll() {return Roll;}
|
||||||
float PitchTarget;
|
float getYaw() {return Yaw;}
|
||||||
float YawTarget;
|
|
||||||
float NoiseEnvelope;
|
|
||||||
float PupilConverge;
|
|
||||||
float scale;
|
|
||||||
|
|
||||||
// Sound loudness information
|
void render(int faceToFace, float * myLocation);
|
||||||
float loudness;
|
void simulate(float);
|
||||||
float averageLoudness;
|
|
||||||
|
|
||||||
glm::vec3 position;
|
// Send and receive network data
|
||||||
int eyeContact;
|
int getBroadcastData(char * data);
|
||||||
eyeContactTargets eyeContactTarget;
|
void parseData(void *data, int size);
|
||||||
void readSensors();
|
|
||||||
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
|
||||||
|
|
||||||
|
float getLoudness() {return loudness;};
|
||||||
|
float getAverageLoudness() {return averageLoudness;};
|
||||||
|
void setAverageLoudness(float al) {averageLoudness = al;};
|
||||||
|
void setLoudness(float l) {loudness = l;};
|
||||||
|
|
||||||
public:
|
void SetNewHeadTarget(float, float);
|
||||||
Head(void);
|
glm::vec3 getPos() { return position; };
|
||||||
void reset();
|
void setPos(glm::vec3 newpos) { position = newpos; };
|
||||||
void UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
|
private:
|
||||||
void setNoise (float mag) { noise = mag; }
|
float noise;
|
||||||
void setPitch(float p) {Pitch = p; }
|
float Pitch;
|
||||||
void setYaw(float y) {Yaw = y; }
|
float Yaw;
|
||||||
void setRoll(float r) {Roll = r; };
|
float Roll;
|
||||||
void setScale(float s) {scale = s; };
|
float PitchRate;
|
||||||
void setRenderYaw(float y) {renderYaw = y;}
|
float YawRate;
|
||||||
void setRenderPitch(float p) {renderPitch = p;}
|
float RollRate;
|
||||||
float getRenderYaw() {return renderYaw;}
|
float EyeballPitch[2];
|
||||||
float getRenderPitch() {return renderPitch;}
|
float EyeballYaw[2];
|
||||||
void setLeanForward(float dist);
|
float EyebrowPitch[2];
|
||||||
void setLeanSideways(float dist);
|
float EyebrowRoll[2];
|
||||||
void addPitch(float p) {Pitch -= p; }
|
float EyeballScaleX, EyeballScaleY, EyeballScaleZ;
|
||||||
void addYaw(float y){Yaw -= y; }
|
float interPupilDistance;
|
||||||
void addRoll(float r){Roll += r; }
|
float interBrowDistance;
|
||||||
void addLean(float x, float z);
|
float NominalPupilSize;
|
||||||
float getPitch() {return Pitch;}
|
float PupilSize;
|
||||||
float getRoll() {return Roll;}
|
float MouthPitch;
|
||||||
float getYaw() {return Yaw;}
|
float MouthYaw;
|
||||||
|
float MouthWidth;
|
||||||
|
float MouthHeight;
|
||||||
|
float leanForward;
|
||||||
|
float leanSideways;
|
||||||
|
float PitchTarget;
|
||||||
|
float YawTarget;
|
||||||
|
float NoiseEnvelope;
|
||||||
|
float PupilConverge;
|
||||||
|
float scale;
|
||||||
|
|
||||||
void render(int faceToFace, float * myLocation);
|
// Sound loudness information
|
||||||
void simulate(float);
|
float loudness;
|
||||||
// Send and receive network data
|
float averageLoudness;
|
||||||
int getBroadcastData(char* data);
|
|
||||||
void recvBroadcastData(char * data, int size);
|
|
||||||
|
|
||||||
float getLoudness() {return loudness;};
|
glm::vec3 position;
|
||||||
float getAverageLoudness() {return averageLoudness;};
|
int eyeContact;
|
||||||
void setAverageLoudness(float al) {averageLoudness = al;};
|
eyeContactTargets eyeContactTarget;
|
||||||
void setLoudness(float l) {loudness = l;};
|
void readSensors();
|
||||||
|
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
||||||
void SetNewHeadTarget(float, float);
|
|
||||||
glm::vec3 getPos() { return position; };
|
|
||||||
void setPos(glm::vec3 newpos) { position = newpos; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -107,7 +107,7 @@ Lattice lattice(160,100);
|
||||||
Finger myFinger(WIDTH, HEIGHT);
|
Finger myFinger(WIDTH, HEIGHT);
|
||||||
Field field;
|
Field field;
|
||||||
|
|
||||||
Audio audio(&myHead, &audioScope);
|
Audio audio(&audioScope);
|
||||||
|
|
||||||
#define RENDER_FRAME_MSECS 8
|
#define RENDER_FRAME_MSECS 8
|
||||||
int steps_per_frame = 0;
|
int steps_per_frame = 0;
|
||||||
|
@ -512,7 +512,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);
|
||||||
// broadcastToAgents(&agentSocket, broadcast_string, broadcast_bytes, sendToSelf);
|
agentList.broadcastToAgents(broadcast_string, broadcast_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_test_spot = WIDTH/2;
|
int render_test_spot = WIDTH/2;
|
||||||
|
@ -561,7 +561,11 @@ void display(void)
|
||||||
if (display_field) field.render();
|
if (display_field) field.render();
|
||||||
|
|
||||||
// Render heads of other agents
|
// Render heads of other agents
|
||||||
// render_agents(sendToSelf, &location[0]);
|
for(std::vector<Agent>::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) {
|
||||||
|
if (agent->linkedData != NULL) {
|
||||||
|
((Head *)agent->linkedData)->render(0, &location[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (display_hand) myHand.render();
|
if (display_hand) myHand.render();
|
||||||
|
|
||||||
|
@ -648,22 +652,6 @@ void display(void)
|
||||||
sprintf(agents, "Agents nearby: %d\n", nearbyAgents);
|
sprintf(agents, "Agents nearby: %d\n", nearbyAgents);
|
||||||
drawtext(WIDTH-200,20, 0.10, 0, 1.0, 0, agents, 1, 1, 0);
|
drawtext(WIDTH-200,20, 0.10, 0, 1.0, 0, agents, 1, 1, 0);
|
||||||
|
|
||||||
|
|
||||||
#ifdef MARKER_CAPTURE
|
|
||||||
/* Render marker acquisition stuff */
|
|
||||||
pthread_mutex_lock(&frame_lock);
|
|
||||||
if(marker_capture_frame){
|
|
||||||
marker_acq_view.render(marker_capture_frame); // render the acquisition view, if it's visible.
|
|
||||||
}
|
|
||||||
// Draw marker images, if requested.
|
|
||||||
if (marker_capture_enabled && marker_capture_display && marker_capture_frame){
|
|
||||||
marker_capturer.glDrawIplImage(marker_capture_frame, WIDTH - 140, 10, 0.1, -0.1);
|
|
||||||
marker_capturer.glDrawIplImage(marker_capture_blob_frame, WIDTH - 280, 10, 0.1, -0.1);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&frame_lock);
|
|
||||||
/* Done rendering marker acquisition stuff */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
@ -694,22 +682,6 @@ void key(unsigned char k, int x, int y)
|
||||||
// Process keypresses
|
// Process keypresses
|
||||||
if (k == 'q') ::terminate();
|
if (k == 'q') ::terminate();
|
||||||
|
|
||||||
// marker capture
|
|
||||||
#ifdef MARKER_CAPTURE
|
|
||||||
if(k == 'x'){
|
|
||||||
printf("Toggling marker capture display.\n");
|
|
||||||
marker_capture_display = !marker_capture_display;
|
|
||||||
marker_capture_display ? marker_acq_view.show() : marker_acq_view.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// delegate keypresses to the marker acquisition view when it's visible;
|
|
||||||
// override other key mappings by returning...
|
|
||||||
if(marker_acq_view.visible){
|
|
||||||
marker_acq_view.handle_key(k);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (k == '/') stats_on = !stats_on; // toggle stats
|
if (k == '/') stats_on = !stats_on; // toggle stats
|
||||||
if (k == 'n')
|
if (k == 'n')
|
||||||
{
|
{
|
||||||
|
@ -762,7 +734,7 @@ void *networkReceive(void *args)
|
||||||
{
|
{
|
||||||
sockaddr senderAddress;
|
sockaddr senderAddress;
|
||||||
ssize_t bytesReceived;
|
ssize_t bytesReceived;
|
||||||
unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE];
|
char *incomingPacket = new char[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (agentList.getAgentSocket()->receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
if (agentList.getAgentSocket()->receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
|
@ -770,49 +742,6 @@ void *networkReceive(void *args)
|
||||||
bytescount += bytesReceived;
|
bytescount += bytesReceived;
|
||||||
|
|
||||||
agentList.processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
agentList.processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
|
|
||||||
|
|
||||||
// // If packet is a Mouse data packet, copy it over
|
|
||||||
// if (incomingPacket[0] == 'P') {
|
|
||||||
// //
|
|
||||||
// // Got Ping, reply immediately!
|
|
||||||
// //
|
|
||||||
// //printf("Replying to ping!\n");
|
|
||||||
// char reply[] = "R";
|
|
||||||
// agentList.getAgentSocket()->send(&senderAddress, reply, 1);
|
|
||||||
// } else if (incomingPacket[0] == 'R') {
|
|
||||||
// //
|
|
||||||
// // Got Reply, record as appropriate
|
|
||||||
// //
|
|
||||||
//// setAgentPing(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port));
|
|
||||||
//
|
|
||||||
// } else if (incomingPacket[0] == 'M') {
|
|
||||||
// //
|
|
||||||
// // mouse location packet
|
|
||||||
// //
|
|
||||||
// sscanf(incomingPacket, "M %d %d", &target_x, &target_y);
|
|
||||||
// target_display = 1;
|
|
||||||
// //printf("X = %d Y = %d\n", target_x, target_y);
|
|
||||||
// } else if (incomingPacket[0] == 'D') {
|
|
||||||
// //
|
|
||||||
// // Message from domainserver
|
|
||||||
// //
|
|
||||||
// //printf("agent list received!\n");
|
|
||||||
// nearbyAgents = agentList.updateList(&incomingPacket[1]);
|
|
||||||
// std::cout << "Received " << nearbyAgents << " from DS!\n";
|
|
||||||
//// kludgyMixerUpdate(audio);
|
|
||||||
// } else if (incomingPacket[0] == 'H') {
|
|
||||||
// //
|
|
||||||
// // Broadcast packet from another agent
|
|
||||||
// //
|
|
||||||
// //printf("broadcast received");
|
|
||||||
//// update_agent(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), &incomingPacket[1], bytesReceived - 1);
|
|
||||||
// } else if (incomingPacket[0] == 'T') {
|
|
||||||
// // Received a self-test packet (to get one's own IP), copy it to local variable!
|
|
||||||
//// printf("My Address: %s:%u\n",
|
|
||||||
//// inet_ntoa(senderAddress.sin_addr),
|
|
||||||
//// senderAddress.sin_port);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -915,14 +844,9 @@ void mouseoverFunc( int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void attachNewHeadToAgent(Agent *newAgent) {
|
||||||
#ifdef MARKER_CAPTURE
|
newAgent->linkedData = new Head();
|
||||||
void *poll_marker_capture(void *threadarg){
|
|
||||||
while(1){
|
|
||||||
marker_capturer.tick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -952,13 +876,6 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
} else printf("Using static domainserver IP: %s\n", DOMAIN_IP);
|
} else printf("Using static domainserver IP: %s\n", DOMAIN_IP);
|
||||||
|
|
||||||
//std::cout << "Test address: " << inet_ntoa(testAddress.sin_addr) << "\n";
|
|
||||||
|
|
||||||
//gethostbyname(hostname);
|
|
||||||
// Send one test packet to detect own IP, port:
|
|
||||||
//char selfTest[] = "T";
|
|
||||||
//agentSocket.send((char *)"127.0.0.1", AGENT_UDP_PORT, selfTest, 1);
|
|
||||||
|
|
||||||
printf("Testing stats math... ");
|
printf("Testing stats math... ");
|
||||||
StDev stdevtest;
|
StDev stdevtest;
|
||||||
stdevtest.reset();
|
stdevtest.reset();
|
||||||
|
@ -983,6 +900,8 @@ int main(int argc, char** argv)
|
||||||
printf("Stdev=FAIL ");
|
printf("Stdev=FAIL ");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
// the callback for our instance of AgentList is attachNewHeadToAgent
|
||||||
|
agentList.newAgentCallback = &attachNewHeadToAgent;
|
||||||
|
|
||||||
// create thread for receipt of data via UDP
|
// create thread for receipt of data via UDP
|
||||||
pthread_t networkReceiveThread;
|
pthread_t networkReceiveThread;
|
||||||
|
@ -1014,28 +933,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
glutTimerFunc(1000, Timer, 0);
|
glutTimerFunc(1000, Timer, 0);
|
||||||
|
|
||||||
#ifdef MARKER_CAPTURE
|
|
||||||
|
|
||||||
if (marker_capture_enabled) {
|
|
||||||
// start capture thread
|
|
||||||
if (pthread_mutex_init(&frame_lock, NULL) != 0){
|
|
||||||
printf("Frame lock mutext init failed. Exiting.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pthread_t capture_thread;
|
|
||||||
pthread_create(&capture_thread, NULL, poll_marker_capture, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
#ifdef MARKER_CAPTURE
|
|
||||||
if (marker_capture_enabled) {
|
|
||||||
pthread_mutex_destroy(&frame_lock);
|
|
||||||
pthread_exit(NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pthread_join(networkReceiveThread, NULL);
|
pthread_join(networkReceiveThread, NULL);
|
||||||
::terminate();
|
::terminate();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -44,8 +44,10 @@ Agent::Agent(const Agent &otherAgent) {
|
||||||
|
|
||||||
type = otherAgent.type;
|
type = otherAgent.type;
|
||||||
|
|
||||||
|
|
||||||
|
linkedData = (AgentData *) malloc(sizeof(otherAgent.linkedData));
|
||||||
// copy over linkedData
|
// copy over linkedData
|
||||||
linkedData = NULL;
|
memcpy((void*)linkedData, (void *)otherAgent.linkedData, sizeof(otherAgent.linkedData));
|
||||||
}
|
}
|
||||||
|
|
||||||
Agent& Agent::operator=(Agent otherAgent) {
|
Agent& Agent::operator=(Agent otherAgent) {
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
class AgentData {
|
class AgentData {
|
||||||
public:
|
public:
|
||||||
virtual ~AgentData();
|
virtual ~AgentData() = 0;
|
||||||
|
virtual void parseData(void * data, int size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,14 +21,19 @@ UDPSocket * AgentList::getAgentSocket() {
|
||||||
return &agentSocket;
|
return &agentSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
|
void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes) {
|
||||||
switch (packetData[0]) {
|
switch (((char *)packetData)[0]) {
|
||||||
case 'D':
|
case 'D':
|
||||||
{
|
{
|
||||||
// list of agents from domain server
|
// list of agents from domain server
|
||||||
updateList(packetData, dataBytes);
|
updateList((unsigned char *)packetData, dataBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'H':
|
||||||
|
{
|
||||||
|
// head data from another agent
|
||||||
|
updateAgentWithData(senderAddress, packetData, dataBytes);
|
||||||
|
}
|
||||||
case 'P':
|
case 'P':
|
||||||
{
|
{
|
||||||
// ping from another agent
|
// ping from another agent
|
||||||
|
@ -45,6 +50,30 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes) {
|
||||||
|
// find the agent by the sockaddr
|
||||||
|
int agentIndex = indexOfMatchingAgent(senderAddress);
|
||||||
|
|
||||||
|
if (agentIndex != -1) {
|
||||||
|
Agent matchingAgent = agents[agentIndex];
|
||||||
|
|
||||||
|
if (matchingAgent.linkedData != NULL) {
|
||||||
|
matchingAgent.linkedData->parseData(packetData, dataBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int AgentList::indexOfMatchingAgent(sockaddr *senderAddress) {
|
||||||
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
|
if (socketMatch(agent->activeSocket, senderAddress)) {
|
||||||
|
return agent - agents.begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
|
int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
|
||||||
int readAgents = 0;
|
int readAgents = 0;
|
||||||
|
|
||||||
|
@ -84,8 +113,15 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
// we didn't have this agent, so add them
|
// we didn't have this agent, so add them
|
||||||
Agent newAgent = Agent(publicSocket, localSocket, agentType);
|
Agent newAgent = Agent(publicSocket, localSocket, agentType);
|
||||||
|
|
||||||
|
if (socketMatch(publicSocket, localSocket)) {
|
||||||
|
// likely debugging scenario with DS + agent on local network
|
||||||
|
// set the agent active right away
|
||||||
|
newAgent.activeSocket = newAgent.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;
|
||||||
|
@ -95,6 +131,16 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
||||||
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
|
if (agent->activeSocket != NULL) {
|
||||||
|
// we know which socket is good for this agent, send there
|
||||||
|
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, sizeof(&broadcastData));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AgentList::pingAgents() {
|
void AgentList::pingAgents() {
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
char payload[] = "P";
|
char payload[] = "P";
|
||||||
|
@ -126,6 +172,7 @@ void AgentList::handlePingReply(sockaddr *agentAddress) {
|
||||||
if (matchedSocket != NULL) {
|
if (matchedSocket != NULL) {
|
||||||
// matched agent, stop checking
|
// matched agent, stop checking
|
||||||
// update the agent's ping
|
// update the agent's ping
|
||||||
|
agent->activeSocket = matchedSocket;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,19 @@ class AgentList {
|
||||||
AgentList();
|
AgentList();
|
||||||
AgentList(int socketListenPort);
|
AgentList(int socketListenPort);
|
||||||
std::vector<Agent> agents;
|
std::vector<Agent> agents;
|
||||||
|
void(*newAgentCallback)(Agent *);
|
||||||
|
|
||||||
UDPSocket* getAgentSocket();
|
UDPSocket* getAgentSocket();
|
||||||
|
|
||||||
int updateList(unsigned char *packetData, size_t dataBytes);
|
int updateList(unsigned char *packetData, size_t dataBytes);
|
||||||
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType);
|
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType);
|
||||||
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
||||||
void broadcastToAgents(char *broadcastData, size_t dataBytes, bool sendToSelf);
|
void broadcastToAgents(char *broadcastData, size_t dataBytes);
|
||||||
void pingAgents();
|
void pingAgents();
|
||||||
private:
|
private:
|
||||||
UDPSocket agentSocket;
|
UDPSocket agentSocket;
|
||||||
|
int indexOfMatchingAgent(sockaddr *senderAddress);
|
||||||
|
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
|
||||||
void handlePingReply(sockaddr *agentAddress);
|
void handlePingReply(sockaddr *agentAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue