Resolving conflicts

This commit is contained in:
Leonardo Murillo 2013-03-22 13:40:16 -06:00
commit e5b0843212
13 changed files with 188 additions and 68 deletions

View file

@ -7,4 +7,9 @@ MACRO(LINK_HIFI_SHARED_LIBRARY TARGET)
get_directory_property(HIFI_SHARED_LIBRARY DIRECTORY ../shared DEFINITION HIFI_SHARED_LIBRARY)
add_dependencies(${TARGET} ${HIFI_SHARED_LIBRARY})
target_link_libraries(${TARGET} ${HIFI_SHARED_LIBRARY})
if (APPLE)
# link in required OS X framework
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreServices")
endif (APPLE)
ENDMACRO(LINK_HIFI_SHARED_LIBRARY _target)

View file

@ -35,7 +35,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif _WIN32
#endif
const int DOMAIN_LISTEN_PORT = 40102;
unsigned char packetData[MAX_PACKET_SIZE];

View file

@ -10,7 +10,7 @@ project(interface)
if (APPLE)
# 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 -framework GLUT")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreServices -framework Carbon -framework GLUT")
set(GL_HEADERS "#include <GLUT/glut.h>\n#include <OpenGL/glext.h>")
else (APPLE)
# include the right GL headers for UNIX

View file

@ -900,12 +900,6 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
}
#endif
void voxelServerAddCallback(sockaddr *voxelServerAddress) {
char voxelAsk[] = "I";
printf("Asking VS for data!\n");
agentList.getAgentSocket().send(voxelServerAddress, voxelAsk, 1);
}
int main(int argc, char** argv)
{
#ifndef _WIN32
@ -941,8 +935,7 @@ int main(int argc, char** argv)
#ifndef _WIN32
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
#endif
agentList.voxelServerAddCallback = &voxelServerAddCallback;
// start the thread which checks for silent agents
agentList.startSilentAgentRemovalThread();

View file

@ -30,7 +30,7 @@ const unsigned short MIXER_LISTEN_PORT = 55443;
const float SAMPLE_RATE = 22050.0;
const short JITTER_BUFFER_MSECS = 5;
const short JITTER_BUFFER_MSECS = 12;
const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_MSECS * (SAMPLE_RATE / 1000.0f);
const int BUFFER_LENGTH_BYTES = 1024;

View file

@ -24,15 +24,14 @@ pthread_mutex_t vectorChangeMutex = PTHREAD_MUTEX_INITIALIZER;
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
linkedDataCreateCallback = NULL;
audioMixerSocketUpdate = NULL;
voxelServerAddCallback = NULL;
lastAgentId = 1;
}
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
linkedDataCreateCallback = NULL;
audioMixerSocketUpdate = NULL;
voxelServerAddCallback = NULL;
lastAgentId = 1;
}
AgentList::~AgentList() {
@ -181,8 +180,8 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
// to use the local socket information the domain server gave us
sockaddr_in *localSocketIn = (sockaddr_in *)localSocket;
audioMixerSocketUpdate(localSocketIn->sin_addr.s_addr, localSocketIn->sin_port);
} else if (newAgent.getType() == 'V' && voxelServerAddCallback != NULL) {
voxelServerAddCallback(localSocket);
} else if (newAgent.getType() == 'V') {
newAgent.activateLocalSocket();
}
std::cout << "Added agent - " << &newAgent << "\n";
@ -209,7 +208,7 @@ void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
// for now assume we only want to send to other interface clients
// until the Audio class uses the AgentList
if (agent->getActiveSocket() != NULL && agent->getType() == 'I') {
if (agent->getActiveSocket() != NULL && (agent->getType() == 'I' || agent->getType() == 'V')) {
// we know which socket is good for this agent, send there
agentSocket.send(agent->getActiveSocket(), broadcastData, dataBytes);
}

View file

@ -31,12 +31,12 @@ class AgentList {
void(*linkedDataCreateCallback)(Agent *);
void(*audioMixerSocketUpdate)(in_addr_t, in_port_t);
void(*voxelServerAddCallback)(sockaddr *);
std::vector<Agent>& getAgents();
UDPSocket& getAgentSocket();
int updateList(unsigned char *packetData, size_t dataBytes);
int indexOfMatchingAgent(sockaddr *senderAddress);
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
@ -50,7 +50,6 @@ class AgentList {
std::vector<Agent> agents;
pthread_t removeSilentAgentsThread;
uint16_t lastAgentId;
int indexOfMatchingAgent(sockaddr *senderAddress);
void handlePingReply(sockaddr *agentAddress);
};

View file

@ -66,13 +66,11 @@ void switchToResourcesIfRequired() {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) // Error: expected unqualified-id before 'if'
{
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) {
// error!
}
CFRelease(resourcesURL); // error: expected constructor, destructor or type conversion before '(' token
CFRelease(resourcesURL);
chdir(path); // error: expected constructor, destructor or type conversion before '(' token
std::cout << "Current Path: " << path << std::endl; // error: expected constructor, destructor or type conversion before '<<' token
chdir(path);
#endif
}

View file

@ -7,6 +7,7 @@
//
#include <cstring>
#include <cmath>
#include "SharedUtil.h"
#include "OctalCode.h"
#include "VoxelTree.h"
@ -27,6 +28,22 @@ VoxelTree::~VoxelTree() {
}
}
int VoxelTree::levelForViewerPosition(float *position) {
// get the distance to the viewer
// for now the voxel tree starts at 0,0,0
float distance = sqrtf(powf(position[0] + 30, 2) + powf(position[2] + 30, 2));
// go through the if else branch to return the right level
// this is a gross way to do this for now for a friday demo
if (distance >= 50) {
return 3;
} else if (distance >= 20) {
return 4;
} else {
return 5;
}
}
VoxelNode * VoxelTree::nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * needleCode) {
// find the appropriate branch index based on this ancestorNode
if (*needleCode == 0) {
@ -133,9 +150,24 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, int bufferSizeByt
readNodeData(bitstreamRootNode, bitstream + octalCodeBytes, bufferSizeBytes - octalCodeBytes);
}
void VoxelTree::readCodeColorBufferToTree(unsigned char *codeColorBuffer) {
int octalCodeBytes = bytesRequiredForCodeLength(*codeColorBuffer);
VoxelNode *lastCreatedNode = nodeForOctalCode(rootNode, codeColorBuffer);
// create the node if it does not exist
if (*lastCreatedNode->octalCode != *codeColorBuffer) {
lastCreatedNode = createMissingNode(lastCreatedNode, codeColorBuffer);
}
// give this node its color
memcpy(lastCreatedNode->color, codeColorBuffer + octalCodeBytes, 3);
lastCreatedNode->color[3] = 1;
}
unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
unsigned char * stopOctalCode,
VoxelNode *currentVoxelNode)
VoxelNode *currentVoxelNode,
int deepestLevel)
{
static unsigned char *initialBitstreamPos = bitstreamBuffer;
@ -188,7 +220,9 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
// copy the childMask to the current position of the bitstreamBuffer
// and push the buffer pointer forwards
*(bitstreamBuffer++) = currentVoxelNode->childMask;
*(bitstreamBuffer++) = *currentVoxelNode->octalCode < deepestLevel
? currentVoxelNode->childMask
: 0;
} else {
firstIndexToCheck = *stopOctalCode > 0
? branchIndexWithDescendant(currentVoxelNode->octalCode, stopOctalCode)
@ -197,26 +231,28 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
unsigned char * childStopOctalCode = NULL;
for (int i = firstIndexToCheck; i < 8; i ++) {
// ask the child to load this bitstream buffer
// if they or their descendants fill the MTU we will receive the childStopOctalCode back
if (currentVoxelNode->children[i] != NULL) {
if (*currentVoxelNode->octalCode < *stopOctalCode
&& i > firstIndexToCheck
&& childStopOctalCode == NULL) {
return currentVoxelNode->children[i]->octalCode;
} else {
if (oneAtBit(currentVoxelNode->childMask, i)) {
childStopOctalCode = loadBitstreamBuffer(bitstreamBuffer, stopOctalCode, currentVoxelNode->children[i]);
if (*currentVoxelNode->octalCode < deepestLevel) {
for (int i = firstIndexToCheck; i < 8; i ++) {
// ask the child to load this bitstream buffer
// if they or their descendants fill the MTU we will receive the childStopOctalCode back
if (currentVoxelNode->children[i] != NULL) {
if (*currentVoxelNode->octalCode < *stopOctalCode
&& i > firstIndexToCheck
&& childStopOctalCode == NULL) {
return currentVoxelNode->children[i]->octalCode;
} else {
childStopOctalCode = NULL;
if (oneAtBit(currentVoxelNode->childMask, i)) {
childStopOctalCode = loadBitstreamBuffer(bitstreamBuffer, stopOctalCode, currentVoxelNode->children[i], deepestLevel);
} else {
childStopOctalCode = NULL;
}
}
}
}
if (childStopOctalCode != NULL) {
break;
if (childStopOctalCode != NULL) {
break;
}
}
}

View file

@ -24,10 +24,13 @@ public:
VoxelNode *rootNode;
int levelForViewerPosition(float * position);
void readBitstreamToTree(unsigned char * bitstream, int bufferSizeBytes);
void readCodeColorBufferToTree(unsigned char *codeColorBuffer);
unsigned char * loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
unsigned char * octalCode,
VoxelNode *currentVoxelNode);
unsigned char * octalCode,
VoxelNode *currentVoxelNode,
int deepestLevel);
void printTreeForDebugging(VoxelNode *startNode);
};

View file

@ -0,0 +1,35 @@
//
// VoxelAgentData.cpp
// hifi
//
// Created by Stephen Birarda on 3/21/13.
//
//
#include "VoxelAgentData.h"
#include <cstring>
#include <cstdio>
VoxelAgentData::VoxelAgentData() {
lastSentLevel = 0;
}
VoxelAgentData::~VoxelAgentData() {
// nothing to explicitly destroy here
}
VoxelAgentData::VoxelAgentData(const VoxelAgentData &otherAgentData) {
lastSentLevel = otherAgentData.lastSentLevel;
memcpy(position, otherAgentData.position, sizeof(float) * 3);
}
VoxelAgentData* VoxelAgentData::clone() const {
return new VoxelAgentData(*this);
}
void VoxelAgentData::parseData(void *data, int size) {
// pull the position from the interface agent data packet
sscanf((char *)data,
"H%*f,%*f,%*f,%f,%f,%f",
&position[0], &position[1], &position[2]);
}

View file

@ -0,0 +1,28 @@
//
// VoxelAgentData.h
// hifi
//
// Created by Stephen Birarda on 3/21/13.
//
//
#ifndef __hifi__VoxelAgentData__
#define __hifi__VoxelAgentData__
#include <AgentData.h>
#include <iostream>
class VoxelAgentData : public AgentData {
public:
float position[3];
int lastSentLevel;
VoxelAgentData();
~VoxelAgentData();
VoxelAgentData(const VoxelAgentData &otherAgentData);
void parseData(void *data, int size);
VoxelAgentData* clone() const;
};
#endif /* defined(__hifi__VoxelAgentData__) */

View file

@ -14,6 +14,8 @@
#include <OctalCode.h>
#include <AgentList.h>
#include <VoxelTree.h>
#include "VoxelAgentData.h"
#include <SharedUtil.h>
#ifdef _WIN32
#include "Syssocket.h"
@ -41,7 +43,7 @@ char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102;
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 6;
AgentList agentList(VOXEL_LISTEN_PORT);
in_addr_t localAddress;
@ -85,7 +87,7 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
createdChildren = false;
for (int i = 0; i < 8; i++) {
if (randomBoolean() || levelsToGo == MAX_VOXEL_TREE_DEPTH_LEVELS) {
if (((i == 0 || i == 1 | i == 4 | i == 5) && (randomBoolean() || levelsToGo != 1)) ) {
// create a new VoxelNode to put here
currentRootNode->children[i] = new VoxelNode();
@ -129,6 +131,13 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
}
}
void attachVoxelAgentDataToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new VoxelAgentData());
}
}
int main(int argc, const char * argv[])
{
setvbuf(stdout, NULL, _IOLBF, 0);
@ -168,6 +177,9 @@ int main(int argc, const char * argv[])
pthread_t reportAliveThread;
pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL);
agentList.linkedDataCreateCallback = &attachVoxelAgentDataToAgent;
agentList.startSilentAgentRemovalThread();
srand((unsigned)time(0));
// use our method to create a random voxel tree
@ -184,39 +196,51 @@ int main(int argc, const char * argv[])
int packetCount;
int totalBytesSent;
sockaddr_in agentPublicAddress;
sockaddr agentPublicAddress;
char *packetData = new char[MAX_PACKET_SIZE];
ssize_t receivedBytes;
// loop to send to agents requesting data
while (true) {
if (agentList.getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) {
if (packetData[0] == 'I') {
stopOctal = randomTree.rootNode->octalCode;
packetCount = 0;
while (stopOctal != NULL) {
voxelPacketEnd = voxelPacket;
stopOctal = randomTree.loadBitstreamBuffer(voxelPacketEnd, stopOctal, randomTree.rootNode);
agentList.getAgentSocket().send((sockaddr *)&agentPublicAddress,
voxelPacket,
voxelPacketEnd - voxelPacket);
packetCount++;
totalBytesSent += voxelPacketEnd - voxelPacket;
if (agentList.getAgentSocket().receive(&agentPublicAddress, packetData, &receivedBytes)) {
if (packetData[0] == 'H') {
agentList.addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, packetData[0]);
agentList.updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes);
VoxelAgentData *agentData = (VoxelAgentData *) agentList.getAgents()[agentList.indexOfMatchingAgent(&agentPublicAddress)].getLinkedData();
int newLevel = 6;
if (newLevel > agentData->lastSentLevel) {
// the agent has already received a deeper level than this from us
// do nothing
stopOctal = randomTree.rootNode->octalCode;
packetCount = 0;
totalBytesSent = 0;
while (stopOctal != NULL) {
voxelPacketEnd = voxelPacket;
stopOctal = randomTree.loadBitstreamBuffer(voxelPacketEnd,
stopOctal,
randomTree.rootNode,
newLevel);
agentList.getAgentSocket().send((sockaddr *)&agentPublicAddress,
voxelPacket,
voxelPacketEnd - voxelPacket);
packetCount++;
totalBytesSent += voxelPacketEnd - voxelPacket;
}
agentData->lastSentLevel = newLevel;
}
printf("%d packets sent to agent %s totalling %d bytes\n",
packetCount,
inet_ntoa(agentPublicAddress.sin_addr),
totalBytesSent);
}
}
}
pthread_join(reportAliveThread, NULL);
agentList.stopSilentAgentRemovalThread();
return 0;
}