Merge branch 'master' of github.com:/worklist/hifi into 19179

This commit is contained in:
Leonardo Murillo 2013-03-21 14:25:35 -06:00
commit d8b80006b8
22 changed files with 16118 additions and 79 deletions

View file

@ -28,8 +28,8 @@
#include "SharedUtil.h" #include "SharedUtil.h"
#ifdef _WIN32 #ifdef _WIN32
#include "Syssocket.h"
#include "Systime.h" #include "Systime.h"
#include <winsock2.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>

View file

@ -65,14 +65,24 @@ include_directories(
) )
# link target to external libraries # link target to external libraries
target_link_libraries(interface if (WIN32)
target_link_libraries(interface
${OPENGL_LIBRARY}
${CMAKE_CURRENT_SOURCE_DIR}/external/glut/Release/glew32.lib
${CMAKE_CURRENT_SOURCE_DIR}/external/glut/Release/freeglut.lib
${CMAKE_CURRENT_SOURCE_DIR}/external/glut/Release/pthread_lib.lib
${CMAKE_CURRENT_SOURCE_DIR}/external/glut/Release/lodepng.lib
wsock32.lib
)
else (WIN32)
target_link_libraries(interface
${OPENGL_LIBRARY} ${OPENGL_LIBRARY}
${GLUT_LIBRARY} ${GLUT_LIBRARY}
${LODEPNG_LIBRARY} ${LODEPNG_LIBRARY}
) )
endif (WIN32)
if (WIN32) if (NOT WIN32)
else (WIN32)
# include PortAudio as external project # include PortAudio as external project
include(ExternalProject) include(ExternalProject)
set(PORTAUDIO_PROJ_DIR external/portaudio) set(PORTAUDIO_PROJ_DIR external/portaudio)
@ -96,7 +106,7 @@ else (WIN32)
ExternalProject_Get_Property(portaudio binary_dir) ExternalProject_Get_Property(portaudio binary_dir)
target_link_libraries(interface ${binary_dir}/lib/.libs/libportaudio.a) target_link_libraries(interface ${binary_dir}/lib/.libs/libportaudio.a)
endif (WIN32) endif (NOT WIN32)
# link required libraries on UNIX # link required libraries on UNIX
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -33,6 +33,8 @@
#if !defined( PTHREAD_H ) #if !defined( PTHREAD_H )
#define PTHREAD_H #define PTHREAD_H
#define PTW32_STATIC_LIB
/* /*
* See the README file for an explanation of the pthreads-win32 version * See the README file for an explanation of the pthreads-win32 version
* numbering scheme and how the DLL is named etc. * numbering scheme and how the DLL is named etc.

View file

@ -5,22 +5,17 @@
// Created by Stephen Birarda on 1/22/13. // Created by Stephen Birarda on 1/22/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
// //
#ifndef _WIN32
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <pthread.h> #include <pthread.h>
#ifdef _WIN32
#include "Systime.h"
#else
#include <sys/time.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <cstring> #include <cstring>
#include <SharedUtil.h>
#include <StdDev.h> #include <StdDev.h>
#include <UDPSocket.h> #include <UDPSocket.h>
#include <SharedUtil.h>
#include "Audio.h" #include "Audio.h"
#include "Util.h" #include "Util.h"
@ -578,3 +573,4 @@ error:
return false; return false;
} }
#endif

View file

@ -10,6 +10,7 @@
#define __interface__Audio__ #define __interface__Audio__
#include <iostream> #include <iostream>
#include <portaudio.h> #include <portaudio.h>
#include "AudioData.h" #include "AudioData.h"
#include "Oscilloscope.h" #include "Oscilloscope.h"

View file

@ -5,6 +5,7 @@
// Created by Stephen Birarda on 1/29/13. // Created by Stephen Birarda on 1/29/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
// //
#ifndef _WIN32
#include "AudioData.h" #include "AudioData.h"
@ -24,4 +25,6 @@ AudioData::AudioData() {
AudioData::~AudioData() { AudioData::~AudioData() {
delete audioSocket; delete audioSocket;
} }
#endif

View file

@ -101,9 +101,9 @@ int SerialInterface::init(char* portname, int baud)
printf("Serial interface opened!\n"); printf("Serial interface opened!\n");
resetSerial(); resetSerial();
active = true; active = true;
#endif
return 0; return 0;
#endif
} }
// Reset Trailing averages to the current measurement // Reset Trailing averages to the current measurement

15955
interface/src/glew.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -24,8 +24,8 @@
#include <stdlib.h> #include <stdlib.h>
#ifdef _WIN32 #ifdef _WIN32
#include "Syssocket.h"
#include "Systime.h" #include "Systime.h"
#include <winsock2.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -38,7 +38,9 @@
#include "Field.h" #include "Field.h"
#include "world.h" #include "world.h"
#include "Util.h" #include "Util.h"
#ifndef _WIN32
#include "Audio.h" #include "Audio.h"
#endif
#include "Head.h" #include "Head.h"
#include "Hand.h" #include "Hand.h"
#include "Particle.h" #include "Particle.h"
@ -98,12 +100,12 @@ glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
ParticleSystem balls(0, ParticleSystem balls(0,
box, box,
false, // Wrap? false, // Wrap?
0.02, // Noise 0.02f, // Noise
0.3, // Size scale 0.3f, // Size scale
0.0 // Gravity 0.0 // Gravity
); );
Cloud cloud(0, // Particles Cloud cloud(20000, // Particles
box, // Bounding Box box, // Bounding Box
false // Wrap false // Wrap
); );
@ -114,7 +116,9 @@ Lattice lattice(160,100);
Finger myFinger(WIDTH, HEIGHT); Finger myFinger(WIDTH, HEIGHT);
Field field; Field field;
#ifndef _WIN32
Audio audio(&audioScope, &myHead); Audio audio(&audioScope, &myHead);
#endif
#define RENDER_FRAME_MSECS 8 #define RENDER_FRAME_MSECS 8
int steps_per_frame = 0; int steps_per_frame = 0;
@ -132,7 +136,7 @@ GLfloat fwd_vec[] = {0.0, 0.0, 1.0};
//GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0}; //GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0};
//GLfloat start_location[] = { 0.1, -0.15, 0.1}; //GLfloat start_location[] = { 0.1, -0.15, 0.1};
GLfloat start_location[] = {6.1, 0, 1.4}; GLfloat start_location[] = {6.1f, 0, 1.4f};
GLfloat location[] = {start_location[0], start_location[1], start_location[2]}; GLfloat location[] = {start_location[0], start_location[1], start_location[2]};
float fwd_vel = 0.0f; float fwd_vel = 0.0f;
@ -247,7 +251,7 @@ void Timer(int extra)
// agentSocket.send((char *)"192.168.1.38", AGENT_UDP_PORT, junk, 1000); // agentSocket.send((char *)"192.168.1.38", AGENT_UDP_PORT, junk, 1000);
} }
gettimeofday(&endtest, NULL); gettimeofday(&endtest, NULL);
float sendTime = diffclock(&starttest, &endtest); float sendTime = static_cast<float>( diffclock(&starttest, &endtest) );
printf("packet test = %4.1f\n", sendTime); printf("packet test = %4.1f\n", sendTime);
} }
@ -261,16 +265,16 @@ void display_stats(void)
{ {
// bitmap chars are about 10 pels high // bitmap chars are about 10 pels high
char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio"; char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio";
drawtext(10, 15, 0.10, 0, 1.0, 0, legend); drawtext(10, 15, 0.10f, 0, 1.0, 0, legend);
char stats[200]; char stats[200];
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d ", sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d ",
FPS, packets_per_second, bytes_per_second); FPS, packets_per_second, bytes_per_second);
drawtext(10, 30, 0.10, 0, 1.0, 0, stats); drawtext(10, 30, 0.10f, 0, 1.0, 0, stats);
if (serialPort.active) { if (serialPort.active) {
sprintf(stats, "ADC samples = %d, LED = %d", sprintf(stats, "ADC samples = %d, LED = %d",
serialPort.getNumSamples(), serialPort.getLED()); serialPort.getNumSamples(), serialPort.getLED());
drawtext(300, 30, 0.10, 0, 1.0, 0, stats); drawtext(300, 30, 0.10f, 0, 1.0, 0, stats);
} }
// Output the ping times to the various agents // Output the ping times to the various agents
@ -283,7 +287,7 @@ void display_stats(void)
std::stringstream voxelStats; std::stringstream voxelStats;
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
drawtext(10,70,0.10, 0, 1.0, 0, (char *)voxelStats.str().c_str()); drawtext(10,70,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
/* /*
@ -364,7 +368,9 @@ void terminate () {
// Close serial port // Close serial port
//close(serial_fd); //close(serial_fd);
#ifndef _WIN32
audio.terminate(); audio.terminate();
#endif
stopNetworkReceiveThread = true; stopNetworkReceiveThread = true;
pthread_join(networkReceiveThread, NULL); pthread_join(networkReceiveThread, NULL);
@ -426,7 +432,7 @@ void simulateHead(float frametime)
// Update head_mouse model // Update head_mouse model
const float MIN_MOUSE_RATE = 30.0; const float MIN_MOUSE_RATE = 30.0;
const float MOUSE_SENSITIVITY = 0.1; const float MOUSE_SENSITIVITY = 0.1f;
if (powf(measured_yaw_rate*measured_yaw_rate + if (powf(measured_yaw_rate*measured_yaw_rate +
measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE) measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE)
{ {
@ -522,9 +528,11 @@ void simulateHead(float frametime)
// Get audio loudness data from audio input device // Get audio loudness data from audio input device
float loudness, averageLoudness; float loudness, averageLoudness;
#ifndef _WIN32
audio.getInputLoudness(&loudness, &averageLoudness); audio.getInputLoudness(&loudness, &averageLoudness);
myHead.setLoudness(loudness); myHead.setLoudness(loudness);
myHead.setAverageLoudness(averageLoudness); myHead.setAverageLoudness(averageLoudness);
#endif
// Send my streaming head data to agents that are nearby and need to see it! // Send my streaming head data to agents that are nearby and need to see it!
const int MAX_BROADCAST_STRING = 200; const int MAX_BROADCAST_STRING = 200;
@ -623,8 +631,10 @@ void display(void)
// lattice.render(WIDTH, HEIGHT); // lattice.render(WIDTH, HEIGHT);
// myFinger.render(); // myFinger.render();
#ifndef _WIN32
audio.render(WIDTH, HEIGHT); audio.render(WIDTH, HEIGHT);
if (audioScope.getState()) audioScope.render(); if (audioScope.getState()) audioScope.render();
#endif
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0); //drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
@ -725,7 +735,9 @@ void key(unsigned char k, int x, int y)
if (k == 'h') { if (k == 'h') {
display_head = !display_head; display_head = !display_head;
#ifndef _WIN32
audio.setMixerLoopbackFlag(display_head); audio.setMixerLoopbackFlag(display_head);
#endif
} }
if (k == 'm') head_mirror = !head_mirror; if (k == 'm') head_mirror = !head_mirror;
@ -781,6 +793,7 @@ void *networkReceive(void *args)
} }
pthread_exit(0); pthread_exit(0);
return NULL;
} }
void idle(void) void idle(void)
@ -880,9 +893,11 @@ void attachNewHeadToAgent(Agent *newAgent) {
} }
} }
#ifndef _WIN32
void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
audio.updateMixerParams(newMixerAddress, newMixerPort); audio.updateMixerParams(newMixerAddress, newMixerPort);
} }
#endif
void voxelServerAddCallback(sockaddr *voxelServerAddress) { void voxelServerAddCallback(sockaddr *voxelServerAddress) {
char voxelAsk[] = "I"; char voxelAsk[] = "I";
@ -892,6 +907,7 @@ void voxelServerAddCallback(sockaddr *voxelServerAddress) {
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#ifndef _WIN32
struct ifaddrs * ifAddrStruct=NULL; struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL; struct ifaddrs * ifa=NULL;
@ -903,7 +919,7 @@ int main(int argc, char** argv)
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
} }
} }
#endif
// Lookup the IP address of things we have hostnames // Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) { if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo; struct hostent* pHostInfo;
@ -920,17 +936,28 @@ int main(int argc, char** argv)
// the callback for our instance of AgentList is attachNewHeadToAgent // the callback for our instance of AgentList is attachNewHeadToAgent
agentList.linkedDataCreateCallback = &attachNewHeadToAgent; agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
#ifndef _WIN32
agentList.audioMixerSocketUpdate = &audioMixerUpdate; agentList.audioMixerSocketUpdate = &audioMixerUpdate;
#endif
agentList.voxelServerAddCallback = &voxelServerAddCallback; agentList.voxelServerAddCallback = &voxelServerAddCallback;
// start the thread which checks for silent agents // start the thread which checks for silent agents
agentList.startSilentAgentRemovalThread(); agentList.startSilentAgentRemovalThread();
#ifdef _WIN32
WSADATA WsaData;
int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData );
#endif
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT); glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Interface"); glutCreateWindow("Interface");
#ifdef _WIN32
glewInit();
#endif
printf( "Created Display Window.\n" ); printf( "Created Display Window.\n" );
initDisplay(); initDisplay();

View file

@ -1,3 +1,5 @@
#ifndef _WIN32
#include <iostream> #include <iostream>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -14,8 +16,9 @@
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"
#ifdef _WIN32 #ifdef _WIN32
#include "Syssocket.h"
#include "Systime.h" #include "Systime.h"
#include <winsock2.h> #include <math.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -28,7 +31,7 @@ const unsigned short MIXER_LISTEN_PORT = 55443;
const float SAMPLE_RATE = 22050.0; const float SAMPLE_RATE = 22050.0;
const short JITTER_BUFFER_MSECS = 5; const short JITTER_BUFFER_MSECS = 5;
const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_MSECS * (SAMPLE_RATE / 1000.0); const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_MSECS * (SAMPLE_RATE / 1000.0f);
const int BUFFER_LENGTH_BYTES = 1024; const int BUFFER_LENGTH_BYTES = 1024;
const int BUFFER_LENGTH_SAMPLES_PER_CHANNEL = (BUFFER_LENGTH_BYTES / 2) / sizeof(int16_t); const int BUFFER_LENGTH_SAMPLES_PER_CHANNEL = (BUFFER_LENGTH_BYTES / 2) / sizeof(int16_t);
@ -41,8 +44,8 @@ const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SA
const long MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max(); const long MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max();
const long MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min(); const long MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
const float DISTANCE_RATIO = 3.0/4.2; const float DISTANCE_RATIO = 3.0f/4.2f;
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5f;
const int PHASE_DELAY_AT_90 = 20; const int PHASE_DELAY_AT_90 = 20;
@ -346,3 +349,11 @@ int main(int argc, const char * argv[])
return 0; return 0;
} }
#else
int main(int argc, const char * argv[])
{
return 0;
}
#endif _WIN32

View file

@ -12,7 +12,7 @@
#include "SharedUtil.h" #include "SharedUtil.h"
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include "Syssocket.h"
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif

View file

@ -13,7 +13,7 @@
#include "AgentData.h" #include "AgentData.h"
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include "Syssocket.h"
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif

View file

@ -11,7 +11,7 @@
#include "SharedUtil.h" #include "SharedUtil.h"
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include "Syssocket.h"
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
@ -248,10 +248,15 @@ void *removeSilentAgents(void *args) {
sleepTime = AGENT_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs); sleepTime = AGENT_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs);
#ifdef _WIN32
Sleep( static_cast<int>(1000.0f*sleepTime) );
#else
usleep(sleepTime); usleep(sleepTime);
#endif
} }
pthread_exit(0); pthread_exit(0);
return NULL;
} }
void AgentList::startSilentAgentRemovalThread() { void AgentList::startSilentAgentRemovalThread() {

View file

@ -14,6 +14,10 @@
#include "Agent.h" #include "Agent.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#ifdef _WIN32
#include "pthread.h"
#endif
const int MAX_PACKET_SIZE = 1500; const int MAX_PACKET_SIZE = 1500;
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103; const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000; const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;

17
shared/src/Syssocket.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef __Syssocket__
#define __Syssocket__
#ifdef _WIN32
#define WINSOCK_API_LINKAGE
#include <winsock2.h>
#define _timeval_
typedef SSIZE_T ssize_t;
typedef ULONG32 in_addr_t;
typedef USHORT in_port_t;
typedef USHORT uint16_t;
typedef ULONG32 socklen_t;
#endif _Win32
#endif __Syssocket__

View file

@ -24,5 +24,4 @@ int gettimeofday( struct timeval* p_tv, struct timezone* p_tz );
#endif _Win32 #endif _Win32
#endif __Systime__ #endif __Systime__

View file

@ -13,7 +13,7 @@
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include "Syssocket.h"
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -96,7 +96,11 @@ UDPSocket::UDPSocket(int listeningPort) {
} }
UDPSocket::~UDPSocket() { UDPSocket::~UDPSocket() {
#ifdef _WIN32
closesocket(handle);
#else
close(handle); close(handle);
#endif
} }
// Receive data on this socket with retrieving address of sender // Receive data on this socket with retrieving address of sender
@ -110,8 +114,8 @@ bool UDPSocket::receive(sockaddr *recvAddress, void *receivedData, ssize_t *rece
socklen_t addressSize = sizeof(&recvAddress); socklen_t addressSize = sizeof(&recvAddress);
*receivedBytes = recvfrom(handle, receivedData, MAX_BUFFER_LENGTH_BYTES, *receivedBytes = recvfrom(handle, static_cast<char*>(receivedData), MAX_BUFFER_LENGTH_BYTES,
0, recvAddress, &addressSize); 0, recvAddress, reinterpret_cast<int*>(&addressSize));
return (*receivedBytes > 0); return (*receivedBytes > 0);
} }

View file

@ -12,7 +12,7 @@
#include <iostream> #include <iostream>
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include "Syssocket.h"
#else #else
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>

View file

@ -11,14 +11,13 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
#include <SharedUtil.h>
#include <OctalCode.h> #include <OctalCode.h>
#include <AgentList.h> #include <AgentList.h>
#include <VoxelTree.h> #include <VoxelTree.h>
#ifdef _WIN32 #ifdef _WIN32
#include "Syssocket.h"
#include "Systime.h" #include "Systime.h"
#include <winsock2.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -36,7 +35,7 @@ const int VOXELS_PER_PACKET = (MAX_PACKET_SIZE - 1) / VOXEL_SIZE_BYTES;
const int MIN_BRIGHTNESS = 64; const int MIN_BRIGHTNESS = 64;
const float DEATH_STAR_RADIUS = 4.0; const float DEATH_STAR_RADIUS = 4.0;
const float MAX_CUBE = 0.05; const float MAX_CUBE = 0.05f;
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
@ -48,22 +47,26 @@ AgentList agentList(VOXEL_LISTEN_PORT);
in_addr_t localAddress; in_addr_t localAddress;
void *reportAliveToDS(void *args) { void *reportAliveToDS(void *args) {
timeval lastSend; timeval lastSend;
unsigned char output[7]; unsigned char output[7];
while (true) { while (true) {
gettimeofday(&lastSend, NULL); gettimeofday(&lastSend, NULL);
*output = 'V'; *output = 'V';
packSocket(output + 1, 895283510, htons(VOXEL_LISTEN_PORT)); packSocket(output + 1, 895283510, htons(VOXEL_LISTEN_PORT));
// packSocket(output + 1, 788637888, htons(VOXEL_LISTEN_PORT)); // packSocket(output + 1, 788637888, htons(VOXEL_LISTEN_PORT));
agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7); agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
double usecToSleep = 1000000 - (usecTimestampNow() - usecTimestamp(&lastSend)); double usecToSleep = 1000000 - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) { if (usecToSleep > 0) {
#ifdef _WIN32
Sleep( static_cast<int>(1000.0f*usecToSleep) );
#else
usleep(usecToSleep); usleep(usecToSleep);
#endif
} else { } else {
std::cout << "No sleep required!"; std::cout << "No sleep required!";
} }
@ -74,40 +77,40 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
// randomly generate children for this node // randomly generate children for this node
// the first level of the tree (where levelsToGo = MAX_VOXEL_TREE_DEPTH_LEVELS) has all 8 // the first level of the tree (where levelsToGo = MAX_VOXEL_TREE_DEPTH_LEVELS) has all 8
if (levelsToGo > 0) { if (levelsToGo > 0) {
int grandChildrenFromNode = 0; int grandChildrenFromNode = 0;
bool createdChildren = false; bool createdChildren = false;
int colorArray[4] = {}; int colorArray[4] = {};
createdChildren = false; createdChildren = false;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (randomBoolean() || levelsToGo == MAX_VOXEL_TREE_DEPTH_LEVELS) { if (randomBoolean() || levelsToGo == MAX_VOXEL_TREE_DEPTH_LEVELS) {
// create a new VoxelNode to put here // create a new VoxelNode to put here
currentRootNode->children[i] = new VoxelNode(); currentRootNode->children[i] = new VoxelNode();
// give this child it's octal code // give this child it's octal code
currentRootNode->children[i]->octalCode = childOctalCode(currentRootNode->octalCode, i); currentRootNode->children[i]->octalCode = childOctalCode(currentRootNode->octalCode, i);
// fill out the lower levels of the tree using that node as the root node // fill out the lower levels of the tree using that node as the root node
grandChildrenFromNode = randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]); grandChildrenFromNode = randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]);
if (currentRootNode->children[i]->color[3] == 1) { if (currentRootNode->children[i]->color[3] == 1) {
for (int c = 0; c < 3; c++) { for (int c = 0; c < 3; c++) {
colorArray[c] += currentRootNode->children[i]->color[c]; colorArray[c] += currentRootNode->children[i]->color[c];
} }
colorArray[3]++; colorArray[3]++;
} }
if (grandChildrenFromNode > 0) { if (grandChildrenFromNode > 0) {
currentRootNode->childMask += (1 << (7 - i)); currentRootNode->childMask += (1 << (7 - i));
} }
createdChildren = true; createdChildren = true;
} }
} }
if (!createdChildren) { if (!createdChildren) {
// we didn't create any children for this node, making it a leaf // we didn't create any children for this node, making it a leaf
// give it a random color // give it a random color
@ -116,12 +119,12 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
// set the color value for this node // set the color value for this node
currentRootNode->setColorFromAverageOfChildren(colorArray); currentRootNode->setColorFromAverageOfChildren(colorArray);
} }
return createdChildren; return createdChildren;
} else { } else {
// this is a leaf node, just give it a color // this is a leaf node, just give it a color
currentRootNode->setRandomColor(MIN_BRIGHTNESS); currentRootNode->setRandomColor(MIN_BRIGHTNESS);
return 0; return 0;
} }
} }
@ -129,20 +132,22 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
#ifndef _WIN32
// get the local address of the voxel server // get the local address of the voxel server
struct ifaddrs * ifAddrStruct=NULL; struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL; struct ifaddrs * ifa=NULL;
getifaddrs(&ifAddrStruct); getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4 if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
// is a valid IP4 Address // is a valid IP4 Address
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
} }
} }
#endif
// Lookup the IP address of things we have hostnames // Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) { if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo; struct hostent* pHostInfo;
@ -151,58 +156,58 @@ int main(int argc, const char * argv[])
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length); memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr)); strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP); printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP);
} else { } else {
printf("Failed lookup domainserver\n"); printf("Failed lookup domainserver\n");
} }
} else { } else {
printf("Using static domainserver IP: %s\n", DOMAIN_IP); printf("Using static domainserver IP: %s\n", DOMAIN_IP);
} }
// setup the agentSocket to report to domain server // setup the agentSocket to report to domain server
pthread_t reportAliveThread; pthread_t reportAliveThread;
pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL); pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL);
srand((unsigned)time(0)); srand((unsigned)time(0));
// use our method to create a random voxel tree // use our method to create a random voxel tree
VoxelTree randomTree; VoxelTree randomTree;
// create an octal code buffer and load it with 0 so that the recursive tree fill can give // create an octal code buffer and load it with 0 so that the recursive tree fill can give
// octal codes to the tree nodes that it is creating // octal codes to the tree nodes that it is creating
randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode); randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode);
unsigned char *voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE]; unsigned char *voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE];
unsigned char *voxelPacketEnd; unsigned char *voxelPacketEnd;
unsigned char *stopOctal; unsigned char *stopOctal;
int packetCount; int packetCount;
int totalBytesSent; int totalBytesSent;
sockaddr_in agentPublicAddress; sockaddr_in agentPublicAddress;
char *packetData = new char[MAX_PACKET_SIZE]; char *packetData = new char[MAX_PACKET_SIZE];
ssize_t receivedBytes; ssize_t receivedBytes;
// loop to send to agents requesting data // loop to send to agents requesting data
while (true) { while (true) {
if (agentList.getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) { if (agentList.getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) {
if (packetData[0] == 'I') { if (packetData[0] == 'I') {
stopOctal = randomTree.rootNode->octalCode; stopOctal = randomTree.rootNode->octalCode;
packetCount = 0; packetCount = 0;
while (stopOctal != NULL) { while (stopOctal != NULL) {
voxelPacketEnd = voxelPacket; voxelPacketEnd = voxelPacket;
stopOctal = randomTree.loadBitstreamBuffer(voxelPacketEnd, stopOctal, randomTree.rootNode); stopOctal = randomTree.loadBitstreamBuffer(voxelPacketEnd, stopOctal, randomTree.rootNode);
agentList.getAgentSocket().send((sockaddr *)&agentPublicAddress, agentList.getAgentSocket().send((sockaddr *)&agentPublicAddress,
voxelPacket, voxelPacket,
voxelPacketEnd - voxelPacket); voxelPacketEnd - voxelPacket);
packetCount++; packetCount++;
totalBytesSent += voxelPacketEnd - voxelPacket; totalBytesSent += voxelPacketEnd - voxelPacket;
} }
printf("%d packets sent to agent %s totalling %d bytes\n", printf("%d packets sent to agent %s totalling %d bytes\n",
packetCount, packetCount,
inet_ntoa(agentPublicAddress.sin_addr), inet_ntoa(agentPublicAddress.sin_addr),
@ -210,8 +215,8 @@ int main(int argc, const char * argv[])
} }
} }
} }
pthread_join(reportAliveThread, NULL); pthread_join(reportAliveThread, NULL);
return 0; return 0;
} }