mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
Merge branch 'master' of github.com:worklist/hifi
This commit is contained in:
commit
0b48eab1fb
22 changed files with 16118 additions and 79 deletions
|
@ -28,8 +28,8 @@
|
|||
#include "SharedUtil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Syssocket.h"
|
||||
#include "Systime.h"
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
|
|
@ -65,14 +65,24 @@ include_directories(
|
|||
)
|
||||
|
||||
# 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}
|
||||
${GLUT_LIBRARY}
|
||||
${LODEPNG_LIBRARY}
|
||||
)
|
||||
)
|
||||
endif (WIN32)
|
||||
|
||||
if (WIN32)
|
||||
else (WIN32)
|
||||
if (NOT WIN32)
|
||||
# include PortAudio as external project
|
||||
include(ExternalProject)
|
||||
set(PORTAUDIO_PROJ_DIR external/portaudio)
|
||||
|
@ -96,7 +106,7 @@ else (WIN32)
|
|||
ExternalProject_Get_Property(portaudio binary_dir)
|
||||
target_link_libraries(interface ${binary_dir}/lib/.libs/libportaudio.a)
|
||||
|
||||
endif (WIN32)
|
||||
endif (NOT WIN32)
|
||||
|
||||
# link required libraries on UNIX
|
||||
if (UNIX AND NOT APPLE)
|
||||
|
|
BIN
interface/external/glut/Release/lodepng.lib
vendored
Normal file
BIN
interface/external/glut/Release/lodepng.lib
vendored
Normal file
Binary file not shown.
BIN
interface/external/glut/Release/lodepngd.lib
vendored
Normal file
BIN
interface/external/glut/Release/lodepngd.lib
vendored
Normal file
Binary file not shown.
BIN
interface/external/glut/Release/pthread_lib.lib
vendored
BIN
interface/external/glut/Release/pthread_lib.lib
vendored
Binary file not shown.
2
interface/external/glut/include/pthread.h
vendored
2
interface/external/glut/include/pthread.h
vendored
|
@ -33,6 +33,8 @@
|
|||
#if !defined( PTHREAD_H )
|
||||
#define PTHREAD_H
|
||||
|
||||
#define PTW32_STATIC_LIB
|
||||
|
||||
/*
|
||||
* See the README file for an explanation of the pthreads-win32 version
|
||||
* numbering scheme and how the DLL is named etc.
|
||||
|
|
|
@ -5,22 +5,17 @@
|
|||
// Created by Stephen Birarda on 1/22/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <cstring>
|
||||
#include <SharedUtil.h>
|
||||
#include <StdDev.h>
|
||||
#include <UDPSocket.h>
|
||||
#include <SharedUtil.h>
|
||||
#include "Audio.h"
|
||||
#include "Util.h"
|
||||
|
||||
|
@ -632,3 +627,4 @@ error:
|
|||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __interface__Audio__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <portaudio.h>
|
||||
#include "AudioData.h"
|
||||
#include "Oscilloscope.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// Created by Stephen Birarda on 1/29/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "AudioData.h"
|
||||
|
||||
|
@ -24,4 +25,6 @@ AudioData::AudioData() {
|
|||
|
||||
AudioData::~AudioData() {
|
||||
delete audioSocket;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,9 +101,9 @@ int SerialInterface::init(char* portname, int baud)
|
|||
printf("Serial interface opened!\n");
|
||||
resetSerial();
|
||||
active = true;
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Reset Trailing averages to the current measurement
|
||||
|
|
15955
interface/src/glew.cpp
Normal file
15955
interface/src/glew.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -24,8 +24,8 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Syssocket.h"
|
||||
#include "Systime.h"
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
|
@ -38,7 +38,9 @@
|
|||
#include "Field.h"
|
||||
#include "world.h"
|
||||
#include "Util.h"
|
||||
#ifndef _WIN32
|
||||
#include "Audio.h"
|
||||
#endif
|
||||
#include "Head.h"
|
||||
#include "Hand.h"
|
||||
#include "Particle.h"
|
||||
|
@ -98,12 +100,12 @@ glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
|
|||
ParticleSystem balls(0,
|
||||
box,
|
||||
false, // Wrap?
|
||||
0.02, // Noise
|
||||
0.3, // Size scale
|
||||
0.02f, // Noise
|
||||
0.3f, // Size scale
|
||||
0.0 // Gravity
|
||||
);
|
||||
|
||||
Cloud cloud(0, // Particles
|
||||
Cloud cloud(20000, // Particles
|
||||
box, // Bounding Box
|
||||
false // Wrap
|
||||
);
|
||||
|
@ -114,7 +116,9 @@ Lattice lattice(160,100);
|
|||
Finger myFinger(WIDTH, HEIGHT);
|
||||
Field field;
|
||||
|
||||
#ifndef _WIN32
|
||||
Audio audio(&audioScope, &myHead);
|
||||
#endif
|
||||
|
||||
#define RENDER_FRAME_MSECS 8
|
||||
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[] = { 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]};
|
||||
float fwd_vel = 0.0f;
|
||||
|
@ -245,7 +249,7 @@ void Timer(int extra)
|
|||
// agentSocket.send((char *)"192.168.1.38", AGENT_UDP_PORT, junk, 1000);
|
||||
}
|
||||
gettimeofday(&endtest, NULL);
|
||||
float sendTime = diffclock(&starttest, &endtest);
|
||||
float sendTime = static_cast<float>( diffclock(&starttest, &endtest) );
|
||||
printf("packet test = %4.1f\n", sendTime);
|
||||
}
|
||||
|
||||
|
@ -259,16 +263,16 @@ void display_stats(void)
|
|||
{
|
||||
// bitmap chars are about 10 pels high
|
||||
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];
|
||||
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d ",
|
||||
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) {
|
||||
sprintf(stats, "ADC samples = %d, LED = %d",
|
||||
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
|
||||
|
@ -281,7 +285,7 @@ void display_stats(void)
|
|||
|
||||
std::stringstream voxelStats;
|
||||
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());
|
||||
|
||||
|
||||
/*
|
||||
|
@ -362,7 +366,9 @@ void terminate () {
|
|||
// Close serial port
|
||||
//close(serial_fd);
|
||||
|
||||
#ifndef _WIN32
|
||||
audio.terminate();
|
||||
#endif
|
||||
stopNetworkReceiveThread = true;
|
||||
pthread_join(networkReceiveThread, NULL);
|
||||
|
||||
|
@ -424,7 +430,7 @@ void simulateHead(float frametime)
|
|||
|
||||
// Update head_mouse model
|
||||
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 +
|
||||
measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE)
|
||||
{
|
||||
|
@ -520,9 +526,11 @@ void simulateHead(float frametime)
|
|||
|
||||
// Get audio loudness data from audio input device
|
||||
float loudness, averageLoudness;
|
||||
#ifndef _WIN32
|
||||
audio.getInputLoudness(&loudness, &averageLoudness);
|
||||
myHead.setLoudness(loudness);
|
||||
myHead.setAverageLoudness(averageLoudness);
|
||||
#endif
|
||||
|
||||
// Send my streaming head data to agents that are nearby and need to see it!
|
||||
const int MAX_BROADCAST_STRING = 200;
|
||||
|
@ -621,8 +629,10 @@ void display(void)
|
|||
|
||||
// lattice.render(WIDTH, HEIGHT);
|
||||
// myFinger.render();
|
||||
#ifndef _WIN32
|
||||
audio.render(WIDTH, HEIGHT);
|
||||
if (audioScope.getState()) audioScope.render();
|
||||
#endif
|
||||
|
||||
|
||||
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
|
||||
|
@ -726,7 +736,9 @@ void key(unsigned char k, int x, int y)
|
|||
|
||||
if (k == 'h') {
|
||||
display_head = !display_head;
|
||||
#ifndef _WIN32
|
||||
audio.setMixerLoopbackFlag(display_head);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (k == 'm') head_mirror = !head_mirror;
|
||||
|
@ -782,6 +794,7 @@ void *networkReceive(void *args)
|
|||
}
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void idle(void)
|
||||
|
@ -881,9 +894,11 @@ void attachNewHeadToAgent(Agent *newAgent) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
||||
audio.updateMixerParams(newMixerAddress, newMixerPort);
|
||||
}
|
||||
#endif
|
||||
|
||||
void voxelServerAddCallback(sockaddr *voxelServerAddress) {
|
||||
char voxelAsk[] = "I";
|
||||
|
@ -893,6 +908,7 @@ void voxelServerAddCallback(sockaddr *voxelServerAddress) {
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
struct ifaddrs * ifAddrStruct=NULL;
|
||||
struct ifaddrs * ifa=NULL;
|
||||
|
||||
|
@ -904,7 +920,7 @@ int main(int argc, char** argv)
|
|||
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
// Lookup the IP address of things we have hostnames
|
||||
if (atoi(DOMAIN_IP) == 0) {
|
||||
struct hostent* pHostInfo;
|
||||
|
@ -921,17 +937,28 @@ int main(int argc, char** argv)
|
|||
|
||||
// the callback for our instance of AgentList is attachNewHeadToAgent
|
||||
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
|
||||
#ifndef _WIN32
|
||||
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
|
||||
#endif
|
||||
agentList.voxelServerAddCallback = &voxelServerAddCallback;
|
||||
|
||||
// start the thread which checks for silent agents
|
||||
agentList.startSilentAgentRemovalThread();
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA WsaData;
|
||||
int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData );
|
||||
#endif
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(WIDTH, HEIGHT);
|
||||
glutCreateWindow("Interface");
|
||||
|
||||
#ifdef _WIN32
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
printf( "Created Display Window.\n" );
|
||||
|
||||
initDisplay();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#ifndef _WIN32
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
@ -14,8 +16,9 @@
|
|||
#include "AudioRingBuffer.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Syssocket.h"
|
||||
#include "Systime.h"
|
||||
#include <winsock2.h>
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -28,7 +31,7 @@ const unsigned short MIXER_LISTEN_PORT = 55443;
|
|||
const float SAMPLE_RATE = 22050.0;
|
||||
|
||||
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_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 MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
|
||||
|
||||
const float DISTANCE_RATIO = 3.0/4.2;
|
||||
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
|
||||
const float DISTANCE_RATIO = 3.0f/4.2f;
|
||||
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5f;
|
||||
const int PHASE_DELAY_AT_90 = 20;
|
||||
|
||||
|
||||
|
@ -346,3 +349,11 @@ int main(int argc, const char * argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif _WIN32
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "SharedUtil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include "Syssocket.h"
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "AgentData.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include "Syssocket.h"
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "SharedUtil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include "Syssocket.h"
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
@ -245,10 +245,15 @@ void *removeSilentAgents(void *args) {
|
|||
|
||||
|
||||
sleepTime = AGENT_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs);
|
||||
#ifdef _WIN32
|
||||
Sleep( static_cast<int>(1000.0f*sleepTime) );
|
||||
#else
|
||||
usleep(sleepTime);
|
||||
#endif
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void AgentList::startSilentAgentRemovalThread() {
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
#include "Agent.h"
|
||||
#include "UDPSocket.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "pthread.h"
|
||||
#endif
|
||||
|
||||
const int MAX_PACKET_SIZE = 1500;
|
||||
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
|
||||
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;
|
||||
|
|
17
shared/src/Syssocket.h
Normal file
17
shared/src/Syssocket.h
Normal 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__
|
|
@ -24,5 +24,4 @@ int gettimeofday( struct timeval* p_tv, struct timezone* p_tz );
|
|||
|
||||
#endif _Win32
|
||||
|
||||
|
||||
#endif __Systime__
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include "Syssocket.h"
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
@ -96,7 +96,11 @@ UDPSocket::UDPSocket(int listeningPort) {
|
|||
}
|
||||
|
||||
UDPSocket::~UDPSocket() {
|
||||
#ifdef _WIN32
|
||||
closesocket(handle);
|
||||
#else
|
||||
close(handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
*receivedBytes = recvfrom(handle, receivedData, MAX_BUFFER_LENGTH_BYTES,
|
||||
0, recvAddress, &addressSize);
|
||||
*receivedBytes = recvfrom(handle, static_cast<char*>(receivedData), MAX_BUFFER_LENGTH_BYTES,
|
||||
0, recvAddress, reinterpret_cast<int*>(&addressSize));
|
||||
|
||||
return (*receivedBytes > 0);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include "Syssocket.h"
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
|
|
@ -11,14 +11,13 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <SharedUtil.h>
|
||||
#include <OctalCode.h>
|
||||
#include <AgentList.h>
|
||||
#include <VoxelTree.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Syssocket.h"
|
||||
#include "Systime.h"
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/time.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 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_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;
|
||||
|
||||
void *reportAliveToDS(void *args) {
|
||||
|
||||
|
||||
timeval lastSend;
|
||||
unsigned char output[7];
|
||||
|
||||
|
||||
while (true) {
|
||||
gettimeofday(&lastSend, NULL);
|
||||
|
||||
|
||||
*output = 'V';
|
||||
packSocket(output + 1, 895283510, htons(VOXEL_LISTEN_PORT));
|
||||
// packSocket(output + 1, 788637888, htons(VOXEL_LISTEN_PORT));
|
||||
agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
|
||||
|
||||
|
||||
double usecToSleep = 1000000 - (usecTimestampNow() - usecTimestamp(&lastSend));
|
||||
|
||||
|
||||
if (usecToSleep > 0) {
|
||||
#ifdef _WIN32
|
||||
Sleep( static_cast<int>(1000.0f*usecToSleep) );
|
||||
#else
|
||||
usleep(usecToSleep);
|
||||
#endif
|
||||
} else {
|
||||
std::cout << "No sleep required!";
|
||||
}
|
||||
|
@ -74,40 +77,40 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
// randomly generate children for this node
|
||||
// the first level of the tree (where levelsToGo = MAX_VOXEL_TREE_DEPTH_LEVELS) has all 8
|
||||
if (levelsToGo > 0) {
|
||||
|
||||
|
||||
int grandChildrenFromNode = 0;
|
||||
bool createdChildren = false;
|
||||
int colorArray[4] = {};
|
||||
|
||||
|
||||
createdChildren = false;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (randomBoolean() || levelsToGo == MAX_VOXEL_TREE_DEPTH_LEVELS) {
|
||||
// create a new VoxelNode to put here
|
||||
currentRootNode->children[i] = new VoxelNode();
|
||||
|
||||
|
||||
// give this child it's octal code
|
||||
currentRootNode->children[i]->octalCode = childOctalCode(currentRootNode->octalCode, i);
|
||||
|
||||
|
||||
// fill out the lower levels of the tree using that node as the root node
|
||||
grandChildrenFromNode = randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]);
|
||||
|
||||
|
||||
if (currentRootNode->children[i]->color[3] == 1) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
colorArray[c] += currentRootNode->children[i]->color[c];
|
||||
}
|
||||
|
||||
|
||||
colorArray[3]++;
|
||||
}
|
||||
|
||||
|
||||
if (grandChildrenFromNode > 0) {
|
||||
currentRootNode->childMask += (1 << (7 - i));
|
||||
}
|
||||
|
||||
|
||||
createdChildren = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!createdChildren) {
|
||||
// we didn't create any children for this node, making it a leaf
|
||||
// give it a random color
|
||||
|
@ -116,12 +119,12 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
// set the color value for this node
|
||||
currentRootNode->setColorFromAverageOfChildren(colorArray);
|
||||
}
|
||||
|
||||
|
||||
return createdChildren;
|
||||
} else {
|
||||
// this is a leaf node, just give it a color
|
||||
currentRootNode->setRandomColor(MIN_BRIGHTNESS);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -129,20 +132,22 @@ int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
int main(int argc, const char * argv[])
|
||||
{
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
// get the local address of the voxel server
|
||||
struct ifaddrs * ifAddrStruct=NULL;
|
||||
struct ifaddrs * ifa=NULL;
|
||||
|
||||
|
||||
getifaddrs(&ifAddrStruct);
|
||||
|
||||
|
||||
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
|
||||
// is a valid IP4 Address
|
||||
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Lookup the IP address of things we have hostnames
|
||||
if (atoi(DOMAIN_IP) == 0) {
|
||||
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);
|
||||
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
|
||||
printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP);
|
||||
|
||||
|
||||
} else {
|
||||
printf("Failed lookup domainserver\n");
|
||||
}
|
||||
} else {
|
||||
printf("Using static domainserver IP: %s\n", DOMAIN_IP);
|
||||
}
|
||||
|
||||
|
||||
// setup the agentSocket to report to domain server
|
||||
pthread_t reportAliveThread;
|
||||
pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL);
|
||||
|
||||
|
||||
srand((unsigned)time(0));
|
||||
|
||||
|
||||
// use our method to create a random voxel tree
|
||||
VoxelTree randomTree;
|
||||
|
||||
|
||||
// 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
|
||||
randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode);
|
||||
|
||||
|
||||
unsigned char *voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE];
|
||||
unsigned char *voxelPacketEnd;
|
||||
|
||||
|
||||
unsigned char *stopOctal;
|
||||
int packetCount;
|
||||
int totalBytesSent;
|
||||
|
||||
sockaddr_in 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') {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
printf("%d packets sent to agent %s totalling %d bytes\n",
|
||||
packetCount,
|
||||
inet_ntoa(agentPublicAddress.sin_addr),
|
||||
|
@ -210,8 +215,8 @@ int main(int argc, const char * argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pthread_join(reportAliveThread, NULL);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue