Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jeffrey Ventrella 2013-05-07 18:33:21 -07:00
commit 9d17df27bf
17 changed files with 320 additions and 269 deletions

View file

@ -60,7 +60,7 @@ const float DISTANCE_RATIO = 3.0f / 0.3f;
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
const int PHASE_DELAY_AT_90 = 20; const int PHASE_DELAY_AT_90 = 20;
const float MAX_OFF_AXIS_ATTENUATION = 0.5f; const float MAX_OFF_AXIS_ATTENUATION = 0.2f;
const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f; const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f;
void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) {
@ -111,7 +111,6 @@ void *sendBuffer(void *args) {
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData(); AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData();
float agentBearing = agentRingBuffer->getBearing();
int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {}; int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {};
@ -120,6 +119,13 @@ void *sendBuffer(void *args) {
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData(); AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
if (otherAgentBuffer->shouldBeAddedToMix()) { if (otherAgentBuffer->shouldBeAddedToMix()) {
float bearingRelativeAngleToSource = 0.f;
float attenuationCoefficient = 1.f;
int numSamplesDelay = 0;
float weakChannelAmplitudeRatio = 1.f;
if (otherAgent != agent) {
float *agentPosition = agentRingBuffer->getPosition(); float *agentPosition = agentRingBuffer->getPosition();
float *otherAgentPosition = otherAgentBuffer->getPosition(); float *otherAgentPosition = otherAgentBuffer->getPosition();
@ -144,8 +150,7 @@ void *sendBuffer(void *args) {
float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]), float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]),
fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI); fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI);
float absoluteAngleToSource = 0; float absoluteAngleToSource = 0;
float bearingRelativeAngleToSource = 0; bearingRelativeAngleToSource = 0;
// find the angle we need for calculation based on the orientation of the triangle // find the angle we need for calculation based on the orientation of the triangle
if (otherAgentPosition[0] > agentPosition[0]) { if (otherAgentPosition[0] > agentPosition[0]) {
@ -162,34 +167,38 @@ void *sendBuffer(void *args) {
} }
} }
if (absoluteAngleToSource > 180) { bearingRelativeAngleToSource = absoluteAngleToSource - agentRingBuffer->getBearing();
absoluteAngleToSource -= 360;
} else if (absoluteAngleToSource < -180) {
absoluteAngleToSource += 360;
}
bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; if (bearingRelativeAngleToSource > 180) {
bearingRelativeAngleToSource *= (M_PI / 180); bearingRelativeAngleToSource -= 360;
} else if (bearingRelativeAngleToSource < -180) {
bearingRelativeAngleToSource += 360;
}
float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing();
if (angleOfDelivery < -180) { if (angleOfDelivery > 180) {
angleOfDelivery -= 360;
} else if (angleOfDelivery < -180) {
angleOfDelivery += 360; angleOfDelivery += 360;
} }
float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
(OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f));
float attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex]
* otherAgentBuffer->getAttenuationRatio() * otherAgentBuffer->getAttenuationRatio()
* offAxisCoefficient; * offAxisCoefficient;
float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); bearingRelativeAngleToSource *= (M_PI / 180);
int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
float weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
int16_t* goodChannel = bearingRelativeAngleToSource > 0 ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; float sinRatio = fabsf(sinf(bearingRelativeAngleToSource));
int16_t* delayedChannel = bearingRelativeAngleToSource > 0 ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
}
int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix;
int16_t* delayedChannel = bearingRelativeAngleToSource > 0.0f ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer() int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer()
? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay
@ -199,9 +208,7 @@ void *sendBuffer(void *args) {
if (s < numSamplesDelay) { if (s < numSamplesDelay) {
// pull the earlier sample for the delayed channel // pull the earlier sample for the delayed channel
int earlierSample = delaySamplePointer[s] * attenuationCoefficient; int earlierSample = delaySamplePointer[s] * attenuationCoefficient;
plateauAdditionOfSamples(delayedChannel[s], earlierSample * weakChannelAmplitudeRatio); plateauAdditionOfSamples(delayedChannel[s], earlierSample * weakChannelAmplitudeRatio);
} }
@ -210,8 +217,7 @@ void *sendBuffer(void *args) {
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay],
currentSample * currentSample * weakChannelAmplitudeRatio);
weakChannelAmplitudeRatio);
} }
} }
} }
@ -276,8 +282,8 @@ int main(int argc, const char* argv[]) {
if(agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if(agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) {
if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) { if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) {
if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentId())) { if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentID())) {
agentList->increaseAgentId(); agentList->increaseAgentID();
} }
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);

View file

@ -51,8 +51,7 @@ void attachAvatarDataToAgent(Agent *newAgent) {
} }
} }
int main(int argc, const char* argv[]) int main(int argc, const char* argv[]) {
{
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT);
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
@ -70,31 +69,31 @@ int main(int argc, const char* argv[])
unsigned char* currentBufferPosition = NULL; unsigned char* currentBufferPosition = NULL;
uint16_t agentID = 0;
while (true) { while (true) {
if (agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if (agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_HEADER_HEAD_DATA: case PACKET_HEADER_HEAD_DATA:
// add this agent if we don't have them yet // grab the agent ID from the packet
if (agentList->addOrUpdateAgent(agentAddress, agentAddress, AGENT_TYPE_AVATAR, agentList->getLastAgentId())) { unpackAgentId(packetData + 1, &agentID);
agentList->increaseAgentId();
}
// this is positional data from an agent // add or update the agent in our list
agentList->addOrUpdateAgent(agentAddress, agentAddress, AGENT_TYPE_AVATAR, agentID);
// parse positional data from an agent
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
currentBufferPosition = broadcastPacket + 1; currentBufferPosition = broadcastPacket + 1;
// send back a packet with other active agent data to this agent // send back a packet with other active agent data to this agent
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getLinkedData() != NULL if (agent->getLinkedData() && !socketMatch(agentAddress, agent->getActiveSocket())) {
&& !socketMatch(agentAddress, agent->getActiveSocket())) {
currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*agent); currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*agent);
} }
} }
agentList->getAgentSocket().send(agentAddress, agentList->getAgentSocket().send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket);
broadcastPacket,
currentBufferPosition - broadcastPacket);
break; break;
case PACKET_HEADER_DOMAIN: case PACKET_HEADER_DOMAIN:

View file

@ -86,7 +86,6 @@ int main(int argc, const char * argv[])
unsigned char* currentBufferPos; unsigned char* currentBufferPos;
unsigned char* startPointer; unsigned char* startPointer;
int packetBytesWithoutLeadingChar;
sockaddr_in agentPublicAddress, agentLocalAddress; sockaddr_in agentPublicAddress, agentLocalAddress;
agentLocalAddress.sin_family = AF_INET; agentLocalAddress.sin_family = AF_INET;
@ -95,6 +94,8 @@ int main(int argc, const char * argv[])
agentList->startSilentAgentRemovalThread(); agentList->startSilentAgentRemovalThread();
uint16_t packetAgentID = 0;
while (true) { while (true) {
if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) && if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) &&
(packetData[0] == PACKET_HEADER_DOMAIN_RFD || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) { (packetData[0] == PACKET_HEADER_DOMAIN_RFD || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) {
@ -117,8 +118,8 @@ int main(int argc, const char * argv[])
if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress, if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress,
(sockaddr*) &agentLocalAddress, (sockaddr*) &agentLocalAddress,
agentType, agentType,
agentList->getLastAgentId())) { agentList->getLastAgentID())) {
agentList->increaseAgentId(); agentList->increaseAgentID();
} }
currentBufferPos = broadcastPacket + 1; currentBufferPos = broadcastPacket + 1;
@ -143,9 +144,13 @@ int main(int argc, const char * argv[])
} }
} else { } else {
double timeNow = usecTimestampNow(); double timeNow = usecTimestampNow();
// this is the agent, just update last receive to now // this is the agent, just update last receive to now
agent->setLastHeardMicrostamp(timeNow); agent->setLastHeardMicrostamp(timeNow);
// grab the ID for this agent so we can send it back with the packet
packetAgentID = agent->getAgentId();
if (packetData[0] == PACKET_HEADER_DOMAIN_RFD if (packetData[0] == PACKET_HEADER_DOMAIN_RFD
&& memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) {
agent->setWakeMicrostamp(timeNow); agent->setWakeMicrostamp(timeNow);
@ -160,11 +165,13 @@ int main(int argc, const char * argv[])
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second); currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second);
} }
if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) { // add the agent ID to the end of the pointer
currentBufferPos += packAgentId(currentBufferPos, packetAgentID);
// send the constructed list back to this agent
agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress, agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress,
broadcastPacket, broadcastPacket,
packetBytesWithoutLeadingChar + 1); (currentBufferPos - startPointer) + 1);
}
} }
} }

View file

@ -17,7 +17,7 @@
const int EVE_AGENT_LISTEN_PORT = 55441; const int EVE_AGENT_LISTEN_PORT = 55441;
const float RANDOM_POSITION_MAX_DIMENSION = 5.0f; const float RANDOM_POSITION_MAX_DIMENSION = 10.0f;
const float DATA_SEND_INTERVAL_MSECS = 15; const float DATA_SEND_INTERVAL_MSECS = 15;
const float MIN_AUDIO_SEND_INTERVAL_SECS = 10; const float MIN_AUDIO_SEND_INTERVAL_SECS = 10;
@ -25,6 +25,12 @@ const int MIN_ITERATIONS_BETWEEN_AUDIO_SENDS = (MIN_AUDIO_SEND_INTERVAL_SECS * 1
const int MAX_AUDIO_SEND_INTERVAL_SECS = 15; const int MAX_AUDIO_SEND_INTERVAL_SECS = 15;
const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS; const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS;
const int ITERATIONS_BEFORE_HAND_GRAB = 100;
const int HAND_GRAB_DURATION_ITERATIONS = 50;
const int HAND_TIMER_SLEEP_ITERATIONS = 50;
const float EVE_PELVIS_HEIGHT = 0.5f;
bool stopReceiveAgentDataThread; bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false; bool injectAudioThreadRunning = false;
@ -48,7 +54,7 @@ void *receiveAgentData(void *args) {
// avatar mixer - this makes sure it won't be killed during silent agent removal // avatar mixer - this makes sure it won't be killed during silent agent removal
avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
if (avatarMixer != NULL) { if (avatarMixer) {
avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); avatarMixer->setLastHeardMicrostamp(usecTimestampNow());
} }
@ -73,9 +79,9 @@ void *injectAudio(void *args) {
// look for an audio mixer in our agent list // look for an audio mixer in our agent list
Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER); Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
if (audioMixer != NULL) { if (audioMixer) {
// until the audio mixer is setup for ping-reply, activate the public socket if it's not active // until the audio mixer is setup for ping-reply, activate the public socket if it's not active
if (audioMixer->getActiveSocket() == NULL) { if (!audioMixer->getActiveSocket()) {
audioMixer->activatePublicSocket(); audioMixer->activatePublicSocket();
} }
@ -113,9 +119,9 @@ int main(int argc, const char* argv[]) {
// move eve away from the origin // move eve away from the origin
// pick a random point inside a 10x10 grid // pick a random point inside a 10x10 grid
eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), eve.setPosition(glm::vec3(randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION),
1.33, // this should be the same as the avatar's pelvis standing height EVE_PELVIS_HEIGHT, // this should be the same as the avatar's pelvis standing height
randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION)));
// face any instance of eve down the z-axis // face any instance of eve down the z-axis
eve.setBodyYaw(0); eve.setBodyYaw(0);
@ -130,8 +136,6 @@ int main(int argc, const char* argv[]) {
unsigned char broadcastPacket[MAX_PACKET_SIZE]; unsigned char broadcastPacket[MAX_PACKET_SIZE];
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA; broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
int numBytesToSend = 0;
timeval thisSend; timeval thisSend;
double numMicrosecondsSleep = 0; double numMicrosecondsSleep = 0;
@ -145,15 +149,18 @@ int main(int argc, const char* argv[]) {
gettimeofday(&thisSend, NULL); gettimeofday(&thisSend, NULL);
// find the current avatar mixer // find the current avatar mixer
Agent *avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); Agent* avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
// make sure we actually have an avatar mixer with an active socket // make sure we actually have an avatar mixer with an active socket
if (avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) { if (agentList->getOwnerID() != UNKNOWN_AGENT_ID && avatarMixer && avatarMixer->getActiveSocket() != NULL) {
unsigned char* packetPosition = broadcastPacket + sizeof(PACKET_HEADER);
packetPosition += packAgentId(packetPosition, agentList->getOwnerID());
// use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer // use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer
numBytesToSend = eve.getBroadcastData((broadcastPacket + 1)); packetPosition += eve.getBroadcastData(packetPosition);
// use the UDPSocket instance attached to our agent list to send avatar data to mixer // use the UDPSocket instance attached to our agent list to send avatar data to mixer
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, numBytesToSend); agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket);
} }
// temporarily disable Eve's audio sending until the file is actually available on EC2 box // temporarily disable Eve's audio sending until the file is actually available on EC2 box
@ -175,13 +182,12 @@ int main(int argc, const char* argv[]) {
// simulate the effect of pressing and un-pressing the mouse button/pad // simulate the effect of pressing and un-pressing the mouse button/pad
handStateTimer++; handStateTimer++;
if ( handStateTimer == 100 ) {
if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB) {
eve.setHandState(1); eve.setHandState(1);
} } else if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS) {
if ( handStateTimer == 150 ) {
eve.setHandState(0); eve.setHandState(0);
} } else if (handStateTimer >= ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS + HAND_TIMER_SLEEP_ITERATIONS) {
if ( handStateTimer >= 200 ) {
handStateTimer = 0; handStateTimer = 0;
} }
} }

View file

@ -62,8 +62,8 @@ bool usingBigSphereCollisionTest = true;
char iris_texture_file[] = "resources/images/green_eye.png"; char iris_texture_file[] = "resources/images/green_eye.png";
float chatMessageScale = 0.001; float chatMessageScale = 0.0015;
float chatMessageHeight = 0.4; float chatMessageHeight = 0.45;
vector<unsigned char> iris_texture; vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512; unsigned int iris_texture_width = 512;
@ -452,6 +452,14 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); Avatar *otherAvatar = (Avatar *)agent->getLinkedData();
/*
// Test: Show angle between your fwd vector and nearest avatar
glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) -
getJointPosition(AVATAR_JOINT_PELVIS);
glm::vec3 myForwardVector = _orientation.getFront();
printLog("Angle between: %f\n", angleBetween(&vectorBetweenUs, &myForwardVector));
*/
// test whether shoulders are close enough to allow for reaching to touch hands // test whether shoulders are close enough to allow for reaching to touch hands
glm::vec3 v(_position - otherAvatar->_position); glm::vec3 v(_position - otherAvatar->_position);
float distance = glm::length(v); float distance = glm::length(v);

View file

@ -33,12 +33,6 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to
const bool USING_INVENSENSE_MPU9150 = 1; const bool USING_INVENSENSE_MPU9150 = 1;
SerialInterface::~SerialInterface() {
#ifdef __APPLE__
close(_serialDescriptor);
#endif
}
void SerialInterface::pair() { void SerialInterface::pair() {
#ifdef __APPLE__ #ifdef __APPLE__

View file

@ -38,7 +38,6 @@ class SerialInterface {
public: public:
SerialInterface() : active(false), SerialInterface() : active(false),
_failedOpenAttempts(0) {} _failedOpenAttempts(0) {}
~SerialInterface();
void pair(); void pair();
void readData(); void readData();

View file

@ -11,6 +11,7 @@
#include <cstring> #include <cstring>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/noise.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include <SharedUtil.h> #include <SharedUtil.h>
@ -65,81 +66,108 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw; return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw;
} }
void render_vector(glm::vec3 * vec) // Helper function returns the positive angle in degrees between two 3D vectors
{ float angleBetween(glm::vec3 * v1, glm::vec3 * v2) {
// Show edge of world return acos((glm::dot(*v1, *v2)) / (glm::length(*v1) * glm::length(*v2))) * 180.f / PI;
glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, 1.0);
glLineWidth(1.0);
glBegin(GL_LINES);
// Draw axes
glColor3f(1,0,0);
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glColor3f(0,1,0);
glVertex3f(0,-1,0);
glVertex3f(0, 1, 0);
glColor3f(0,0,1);
glVertex3f(0,0,-1);
glVertex3f(0, 0, 1);
// Draw vector
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(vec->x, vec->y, vec->z);
// Draw marker dots for magnitude
glEnd();
float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
float particleAttenuationConstant[] = { 1.0f, 0.0f, 0.0f };
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic );
glEnable(GL_POINT_SMOOTH);
glPointSize(10.0);
glBegin(GL_POINTS);
glColor3f(1,0,0);
glVertex3f(vec->x,0,0);
glColor3f(0,1,0);
glVertex3f(0,vec->y,0);
glColor3f(0,0,1);
glVertex3f(0,0,vec->z);
glEnd();
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant );
} }
void render_world_box() // Draw a 3D vector floating in space
{ void drawVector(glm::vec3 * vector) {
glDisable(GL_LIGHTING);
glEnable(GL_POINT_SMOOTH);
glPointSize(3.0);
glLineWidth(2.0);
// Draw axes
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glColor3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0, 1, 0);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(0, 0, 1);
glEnd();
// Draw the vector itself
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(vector->x, vector->y, vector->z);
glEnd();
// Draw spheres for magnitude
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(vector->x, 0, 0);
glutSolidSphere(0.02, 10, 10);
glColor3f(0,1,0);
glTranslatef(-vector->x, vector->y, 0);
glutSolidSphere(0.02, 10, 10);
glColor3f(0,0,1);
glTranslatef(0, -vector->y, vector->z);
glutSolidSphere(0.02, 10, 10);
glPopMatrix();
}
// Render a 2D set of squares using perlin/fractal noise
void noiseTest(int w, int h) {
const float CELLS = 500;
const float NOISE_SCALE = 10.0;
float xStep = (float) w / CELLS;
float yStep = (float) h / CELLS;
glBegin(GL_QUADS);
for (float x = 0; x < (float)w; x += xStep) {
for (float y = 0; y < (float)h; y += yStep) {
// Generate a vector varying between 0-1 corresponding to the screen location
glm::vec2 position(NOISE_SCALE * x / (float) w, NOISE_SCALE * y / (float) h);
// Set the cell color using the noise value at that location
float color = glm::perlin(position);
glColor4f(color, color, color, 1.0);
glVertex2f(x, y);
glVertex2f(x + xStep, y);
glVertex2f(x + xStep, y + yStep);
glVertex2f(x, y + yStep);
}
}
glEnd();
}
void render_world_box() {
// Show edge of world // Show edge of world
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, 1.0); glColor4f(1.0, 1.0, 1.0, 1.0);
glLineWidth(1.0); glLineWidth(1.0);
glBegin(GL_LINES); glBegin(GL_LINES);
glColor3f(1,0,0); glColor3f(1, 0, 0);
glVertex3f(0,0,0); glVertex3f(0, 0, 0);
glVertex3f(WORLD_SIZE,0,0); glVertex3f(WORLD_SIZE, 0, 0);
glColor3f(0,1,0); glColor3f(0, 1, 0);
glVertex3f(0,0,0); glVertex3f(0, 0, 0);
glVertex3f(0, WORLD_SIZE, 0); glVertex3f(0, WORLD_SIZE, 0);
glColor3f(0,0,1); glColor3f(0, 0, 1);
glVertex3f(0,0,0); glVertex3f(0, 0, 0);
glVertex3f(0, 0, WORLD_SIZE); glVertex3f(0, 0, WORLD_SIZE);
glEnd(); glEnd();
// Draw little marker dots along the axis // Draw little marker dots along the axis
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glPushMatrix(); glPushMatrix();
glTranslatef(WORLD_SIZE,0,0); glTranslatef(WORLD_SIZE, 0, 0);
glColor3f(1,0,0); glColor3f(1, 0, 0);
glutSolidSphere(0.125,10,10); glutSolidSphere(0.125, 10, 10);
glPopMatrix(); glPopMatrix();
glPushMatrix(); glPushMatrix();
glTranslatef(0,WORLD_SIZE,0); glTranslatef(0, WORLD_SIZE, 0);
glColor3f(0,1,0); glColor3f(0, 1, 0);
glutSolidSphere(0.125,10,10); glutSolidSphere(0.125, 10, 10);
glPopMatrix(); glPopMatrix();
glPushMatrix(); glPushMatrix();
glTranslatef(0,0,WORLD_SIZE); glTranslatef(0, 0, WORLD_SIZE);
glColor3f(0,0,1); glColor3f(0, 0, 1);
glutSolidSphere(0.125,10,10); glutSolidSphere(0.125, 10, 10);
glPopMatrix(); glPopMatrix();
} }
@ -166,8 +194,7 @@ float widthChar(float scale, int mono, char ch) {
} }
void drawtext(int x, int y, float scale, float rotate, float thick, int mono, void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
char const* string, float r, float g, float b) char const* string, float r, float g, float b) {
{
// //
// Draws text on screen as stroked so it can be resized // Draws text on screen as stroked so it can be resized
// //
@ -184,7 +211,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
} }
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) { void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
// //
// Draws text on screen as stroked so it can be resized // Draws text on screen as stroked so it can be resized
@ -207,6 +233,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
glPopMatrix(); glPopMatrix();
} }
void drawGroundPlaneGrid(float size) { void drawGroundPlaneGrid(float size) {
glColor3f(0.4f, 0.5f, 0.3f); glColor3f(0.4f, 0.5f, 0.3f);
glLineWidth(2.0); glLineWidth(2.0);

View file

@ -33,13 +33,19 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
float randFloat(); float randFloat();
void render_world_box(); void render_world_box();
void render_vector(glm::vec3 * vec);
int widthText(float scale, int mono, char const* string); int widthText(float scale, int mono, char const* string);
float widthChar(float scale, int mono, char ch); float widthChar(float scale, int mono, char ch);
void drawtext(int x, int y, float scale, float rotate, float thick, int mono, void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
char const* string, float r=1.0, float g=1.0, float b=1.0); char const* string, float r=1.0, float g=1.0, float b=1.0);
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
float r=1.0, float g=1.0, float b=1.0); float r=1.0, float g=1.0, float b=1.0);
void noiseTest(int w, int h);
void drawVector(glm::vec3* vector);
float angleBetween(glm::vec3 * v1, glm::vec3 * v2);
double diffclock(timeval *clock1,timeval *clock2); double diffclock(timeval *clock1,timeval *clock2);
void drawGroundPlaneGrid(float size); void drawGroundPlaneGrid(float size);

View file

@ -14,14 +14,6 @@
// //
// Welcome Aboard! // Welcome Aboard!
// //
//
// Keyboard Commands:
//
// / = toggle stats display
// spacebar = reset gyros/head position
// h = render Head facing yourself (mirror)
// l = show incoming gyro levels
//
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include <math.h> #include <math.h>
@ -437,16 +429,21 @@ void updateAvatar(float frametime) {
myAvatar.setCameraNearClip(::viewFrustum.getNearClip()); myAvatar.setCameraNearClip(::viewFrustum.getNearClip());
myAvatar.setCameraFarClip(::viewFrustum.getFarClip()); myAvatar.setCameraFarClip(::viewFrustum.getFarClip());
// Send my stream of head/hand data to the avatar mixer and voxel server AgentList* agentList = AgentList::getInstance();
unsigned char broadcastString[200];
*broadcastString = PACKET_HEADER_HEAD_DATA;
int broadcastBytes = myAvatar.getBroadcastData(broadcastString + 1); if (agentList->getOwnerID() != UNKNOWN_AGENT_ID) {
broadcastBytes++; // if I know my ID, send head/hand data to the avatar mixer and voxel server
unsigned char broadcastString[200];
unsigned char* endOfBroadcastStringWrite = broadcastString;
*(endOfBroadcastStringWrite++) = PACKET_HEADER_HEAD_DATA;
endOfBroadcastStringWrite += packAgentId(endOfBroadcastStringWrite, agentList->getOwnerID());
endOfBroadcastStringWrite += myAvatar.getBroadcastData(endOfBroadcastStringWrite);
const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER};
AgentList::getInstance()->broadcastToAgents(broadcastString, endOfBroadcastStringWrite - broadcastString, broadcastReceivers, sizeof(broadcastReceivers));
AgentList::getInstance()->broadcastToAgents(broadcastString, broadcastBytes, broadcastReceivers, 2); }
// If I'm in paint mode, send a voxel out to VOXEL server agents. // If I'm in paint mode, send a voxel out to VOXEL server agents.
if (::paintOn) { if (::paintOn) {
@ -454,9 +451,9 @@ void updateAvatar(float frametime) {
glm::vec3 avatarPos = myAvatar.getPosition(); glm::vec3 avatarPos = myAvatar.getPosition();
// For some reason, we don't want to flip X and Z here. // For some reason, we don't want to flip X and Z here.
::paintingVoxel.x = avatarPos.x/10.0; ::paintingVoxel.x = avatarPos.x / 10.0;
::paintingVoxel.y = avatarPos.y/10.0; ::paintingVoxel.y = avatarPos.y / 10.0;
::paintingVoxel.z = avatarPos.z/10.0; ::paintingVoxel.z = avatarPos.z / 10.0;
unsigned char* bufferOut; unsigned char* bufferOut;
int sizeOut; int sizeOut;
@ -699,8 +696,7 @@ void displaySide(Camera& whichCamera) {
drawGroundPlaneGrid(10.f); drawGroundPlaneGrid(10.f);
// Draw voxels // Draw voxels
if (showingVoxels) if (showingVoxels) {
{
voxels.render(); voxels.render();
} }
@ -893,6 +889,8 @@ void displayOverlay() {
audioScope.render(); audioScope.render();
#endif #endif
//noiseTest(WIDTH, HEIGHT);
if (displayHeadMouse && !::lookingInMirror && statsOn) { if (displayHeadMouse && !::lookingInMirror && statsOn) {
// Display small target box at center or head mouse target that can also be used to measure LOD // Display small target box at center or head mouse target that can also be used to measure LOD
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -1067,7 +1065,17 @@ void display(void)
} }
// important... // important...
myCamera.update(1.f/FPS);
myCamera.update( 1.f/FPS );
// Render anything (like HUD items) that we want to be in 3D but not in worldspace
const float HUD_Z_OFFSET = -5.f;
glPushMatrix();
glm::vec3 test(0.5, 0.5, 0.5);
glTranslatef(1, 1, HUD_Z_OFFSET);
drawVector(&test);
glPopMatrix();
// Note: whichCamera is used to pick between the normal camera myCamera for our // Note: whichCamera is used to pick between the normal camera myCamera for our
// main camera, vs, an alternate camera. The alternate camera we support right now // main camera, vs, an alternate camera. The alternate camera we support right now
@ -1368,8 +1376,7 @@ void initMenu() {
menuColumnDebug->addRow("Show TRUE Colors", doTrueVoxelColors); menuColumnDebug->addRow("Show TRUE Colors", doTrueVoxelColors);
} }
void testPointToVoxel() void testPointToVoxel() {
{
float y=0; float y=0;
float z=0; float z=0;
float s=0.1; float s=0.1;
@ -1421,8 +1428,7 @@ void setupPaintingVoxel() {
shiftPaintingColor(); shiftPaintingColor();
} }
void addRandomSphere(bool wantColorRandomizer) void addRandomSphere(bool wantColorRandomizer) {
{
float r = randFloatInRange(0.05,0.1); float r = randFloatInRange(0.05,0.1);
float xc = randFloatInRange(r,(1-r)); float xc = randFloatInRange(r,(1-r));
float yc = randFloatInRange(r,(1-r)); float yc = randFloatInRange(r,(1-r));
@ -1439,7 +1445,6 @@ void addRandomSphere(bool wantColorRandomizer)
voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer); voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
} }
const float KEYBOARD_YAW_RATE = 0.8; const float KEYBOARD_YAW_RATE = 0.8;
const float KEYBOARD_PITCH_RATE = 0.6; const float KEYBOARD_PITCH_RATE = 0.6;
const float KEYBOARD_STRAFE_RATE = 0.03; const float KEYBOARD_STRAFE_RATE = 0.03;
@ -1493,7 +1498,6 @@ void specialkey(int k, int x, int y) {
} }
} }
void keyUp(unsigned char k, int x, int y) { void keyUp(unsigned char k, int x, int y) {
if (::chatEntryOn) { if (::chatEntryOn) {
myAvatar.setKeyState(NO_KEY_DOWN); myAvatar.setKeyState(NO_KEY_DOWN);
@ -1508,8 +1512,7 @@ void keyUp(unsigned char k, int x, int y) {
if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0); if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0);
} }
void key(unsigned char k, int x, int y) void key(unsigned char k, int x, int y) {
{
if (::chatEntryOn) { if (::chatEntryOn) {
if (chatEntry.key(k)) { if (chatEntry.key(k)) {
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
@ -1753,10 +1756,6 @@ void reshape(int width, int height) {
glLoadIdentity(); glLoadIdentity();
} }
//Find and return the gravity vector at this location //Find and return the gravity vector at this location
glm::vec3 getGravity(glm::vec3 pos) { glm::vec3 getGravity(glm::vec3 pos) {
// //
@ -1815,8 +1814,7 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
} }
#endif #endif
int main(int argc, const char * argv[]) int main(int argc, const char * argv[]) {
{
voxels.setViewFrustum(&::viewFrustum); voxels.setViewFrustum(&::viewFrustum);
shared_lib::printLog = & ::printLog; shared_lib::printLog = & ::printLog;

View file

@ -129,10 +129,13 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
// increment to push past the packet header // increment to push past the packet header
sourceBuffer++; sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA);
unsigned char* startPosition = sourceBuffer; unsigned char* startPosition = sourceBuffer;
// push past the agent ID
sourceBuffer += + sizeof(uint16_t);
// Body world position // Body world position
memcpy(&_position, sourceBuffer, sizeof(float) * 3); memcpy(&_position, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3; sourceBuffer += sizeof(float) * 3;

View file

@ -62,9 +62,10 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) :
_agentBuckets(), _agentBuckets(),
_numAgents(0), _numAgents(0),
agentSocket(newSocketListenPort), agentSocket(newSocketListenPort),
ownerType(newOwnerType), _ownerType(newOwnerType),
socketListenPort(newSocketListenPort), socketListenPort(newSocketListenPort),
lastAgentId(0) { _ownerID(UNKNOWN_AGENT_ID),
_lastAgentID(0) {
pthread_mutex_init(&mutex, 0); pthread_mutex_init(&mutex, 0);
} }
@ -81,10 +82,6 @@ UDPSocket& AgentList::getAgentSocket() {
return agentSocket; return agentSocket;
} }
char AgentList::getOwnerType() {
return ownerType;
}
unsigned int AgentList::getSocketListenPort() { unsigned int AgentList::getSocketListenPort() {
return socketListenPort; return socketListenPort;
} }
@ -92,7 +89,7 @@ unsigned int AgentList::getSocketListenPort() {
void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
switch (((char *)packetData)[0]) { switch (((char *)packetData)[0]) {
case PACKET_HEADER_DOMAIN: { case PACKET_HEADER_DOMAIN: {
updateList(packetData, dataBytes); processDomainServerList(packetData, dataBytes);
break; break;
} }
case PACKET_HEADER_PING: { case PACKET_HEADER_PING: {
@ -126,7 +123,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
uint16_t agentID = -1; uint16_t agentID = -1;
while ((currentPosition - startPosition) < numTotalBytes) { while ((currentPosition - startPosition) < numTotalBytes) {
currentPosition += unpackAgentId(currentPosition, &agentID); unpackAgentId(currentPosition, &agentID);
memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition)); memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition));
Agent* matchingAgent = agentWithID(agentID); Agent* matchingAgent = agentWithID(agentID);
@ -195,15 +192,7 @@ Agent* AgentList::agentWithID(uint16_t agentID) {
return NULL; return NULL;
} }
uint16_t AgentList::getLastAgentId() { int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) {
return lastAgentId;
}
void AgentList::increaseAgentId() {
++lastAgentId;
}
int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
int readAgents = 0; int readAgents = 0;
char agentType; char agentType;
@ -218,7 +207,7 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
unsigned char *readPtr = packetData + 1; unsigned char *readPtr = packetData + 1;
unsigned char *startPtr = packetData; unsigned char *startPtr = packetData;
while((readPtr - startPtr) < dataBytes) { while((readPtr - startPtr) < dataBytes - sizeof(uint16_t)) {
agentType = *readPtr++; agentType = *readPtr++;
readPtr += unpackAgentId(readPtr, (uint16_t *)&agentId); readPtr += unpackAgentId(readPtr, (uint16_t *)&agentId);
readPtr += unpackSocket(readPtr, (sockaddr *)&agentPublicSocket); readPtr += unpackSocket(readPtr, (sockaddr *)&agentPublicSocket);
@ -227,6 +216,9 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
addOrUpdateAgent((sockaddr *)&agentPublicSocket, (sockaddr *)&agentLocalSocket, agentType, agentId); addOrUpdateAgent((sockaddr *)&agentPublicSocket, (sockaddr *)&agentLocalSocket, agentType, agentId);
} }
// read out our ID from the packet
unpackAgentId(readPtr, &_ownerID);
return readAgents; return readAgents;
} }

View file

@ -31,6 +31,8 @@ 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;
const int UNKNOWN_AGENT_ID = -1;
class AgentListIterator; class AgentListIterator;
class AgentList { class AgentList {
@ -50,13 +52,10 @@ public:
UDPSocket& getAgentSocket(); UDPSocket& getAgentSocket();
uint16_t getLastAgentId();
void increaseAgentId();
void lock() { pthread_mutex_lock(&mutex); } void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); }
int updateList(unsigned char *packetData, size_t dataBytes); int processDomainServerList(unsigned char *packetData, size_t dataBytes);
Agent* agentWithAddress(sockaddr *senderAddress); Agent* agentWithAddress(sockaddr *senderAddress);
Agent* agentWithID(uint16_t agentID); Agent* agentWithID(uint16_t agentID);
@ -70,9 +69,16 @@ public:
int 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();
unsigned int getSocketListenPort(); unsigned int getSocketListenPort();
char getOwnerType() const { return _ownerType; }
uint16_t getLastAgentID() const { return _lastAgentID; }
void increaseAgentID() { ++_lastAgentID; }
uint16_t getOwnerID() const { return _ownerID; }
void setOwnerID(uint16_t ownerID) { _ownerID = ownerID; }
Agent* soloAgentOfType(char agentType); Agent* soloAgentOfType(char agentType);
void startSilentAgentRemovalThread(); void startSilentAgentRemovalThread();
@ -96,9 +102,10 @@ private:
Agent** _agentBuckets[MAX_NUM_AGENTS / AGENTS_PER_BUCKET]; Agent** _agentBuckets[MAX_NUM_AGENTS / AGENTS_PER_BUCKET];
int _numAgents; int _numAgents;
UDPSocket agentSocket; UDPSocket agentSocket;
char ownerType; char _ownerType;
unsigned int socketListenPort; unsigned int socketListenPort;
uint16_t lastAgentId; uint16_t _ownerID;
uint16_t _lastAgentID;
pthread_t removeSilentAgentsThread; pthread_t removeSilentAgentsThread;
pthread_t checkInWithDomainServerThread; pthread_t checkInWithDomainServerThread;
pthread_t pingUnknownAgentsThread; pthread_t pingUnknownAgentsThread;

View file

@ -113,6 +113,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
attenuationRatio = attenuationByte / 255.0f; attenuationRatio = attenuationByte / 255.0f;
memcpy(&bearing, dataPtr, sizeof(float)); memcpy(&bearing, dataPtr, sizeof(float));
dataPtr += sizeof(bearing);
if (bearing > 180 || bearing < -180) { if (bearing > 180 || bearing < -180) {
// we were passed an invalid bearing because this agent wants loopback (pressed the H key) // we were passed an invalid bearing because this agent wants loopback (pressed the H key)
@ -122,10 +123,10 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
bearing = bearing > 0 bearing = bearing > 0
? bearing - AGENT_LOOPBACK_MODIFIER ? bearing - AGENT_LOOPBACK_MODIFIER
: bearing + AGENT_LOOPBACK_MODIFIER; : bearing + AGENT_LOOPBACK_MODIFIER;
} else {
_shouldLoopbackForAgent = false;
} }
dataPtr += sizeof(float);
sourceBuffer = dataPtr; sourceBuffer = dataPtr;
} }

View file

@ -13,18 +13,19 @@
#ifndef hifi_PacketHeaders_h #ifndef hifi_PacketHeaders_h
#define hifi_PacketHeaders_h #define hifi_PacketHeaders_h
const char PACKET_HEADER_DOMAIN = 'D'; typedef char PACKET_HEADER;
const char PACKET_HEADER_PING = 'P'; const PACKET_HEADER PACKET_HEADER_DOMAIN = 'D';
const char PACKET_HEADER_PING_REPLY = 'R'; const PACKET_HEADER PACKET_HEADER_PING = 'P';
const char PACKET_HEADER_HEAD_DATA = 'H'; const PACKET_HEADER PACKET_HEADER_PING_REPLY = 'R';
const char PACKET_HEADER_Z_COMMAND = 'Z'; const PACKET_HEADER PACKET_HEADER_HEAD_DATA = 'H';
const char PACKET_HEADER_INJECT_AUDIO = 'I'; const PACKET_HEADER PACKET_HEADER_Z_COMMAND = 'Z';
const char PACKET_HEADER_SET_VOXEL = 'S'; const PACKET_HEADER PACKET_HEADER_INJECT_AUDIO = 'I';
const char PACKET_HEADER_ERASE_VOXEL = 'E'; const PACKET_HEADER PACKET_HEADER_SET_VOXEL = 'S';
const char PACKET_HEADER_VOXEL_DATA = 'V'; const PACKET_HEADER PACKET_HEADER_ERASE_VOXEL = 'E';
const char PACKET_HEADER_BULK_AVATAR_DATA = 'X'; const PACKET_HEADER PACKET_HEADER_VOXEL_DATA = 'V';
const char PACKET_HEADER_TRANSMITTER_DATA = 't'; const PACKET_HEADER PACKET_HEADER_BULK_AVATAR_DATA = 'X';
const char PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; const PACKET_HEADER PACKET_HEADER_TRANSMITTER_DATA = 't';
const char PACKET_HEADER_DOMAIN_RFD = 'C'; const PACKET_HEADER PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L';
const PACKET_HEADER PACKET_HEADER_DOMAIN_RFD = 'C';
#endif #endif

0
libraries/voxels/src/AABox.cpp Executable file → Normal file
View file

View file

@ -547,12 +547,9 @@ int main(int argc, const char * argv[])
// If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we // If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we
// need to make sure we have it in our agentList. // need to make sure we have it in our agentList.
if (packetData[0] == PACKET_HEADER_HEAD_DATA) { if (packetData[0] == PACKET_HEADER_HEAD_DATA) {
if (agentList->addOrUpdateAgent(&agentPublicAddress, uint16_t agentID = 0;
&agentPublicAddress, unpackAgentId(packetData + sizeof(PACKET_HEADER_HEAD_DATA), &agentID);
AGENT_TYPE_AVATAR, agentList->addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, AGENT_TYPE_AVATAR, agentID);
agentList->getLastAgentId())) {
agentList->increaseAgentId();
}
agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes); agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes);
} }