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

This commit is contained in:
ZappoMan 2013-05-03 17:11:41 -07:00
commit f93bc98ec7
9 changed files with 181 additions and 100 deletions

View file

@ -8,5 +8,6 @@ add_subdirectory(domain-server)
add_subdirectory(eve) add_subdirectory(eve)
add_subdirectory(interface) add_subdirectory(interface)
add_subdirectory(injector) add_subdirectory(injector)
add_subdirectory(pairing-server)
add_subdirectory(space-server) add_subdirectory(space-server)
add_subdirectory(voxel-server) add_subdirectory(voxel-server)

View file

@ -80,10 +80,6 @@ timeval firstPlaybackTimer;
int packetsReceivedThisPlayback = 0; int packetsReceivedThisPlayback = 0;
float usecsAtStartup = 0; float usecsAtStartup = 0;
#define LOG_SAMPLE_DELAY 0
std::ofstream logFile;
/** /**
* Audio callback used by portaudio. * Audio callback used by portaudio.
* Communicates with Audio via a shared pointer to Audio::data. * Communicates with Audio via a shared pointer to Audio::data.
@ -315,34 +311,12 @@ void *receiveAudioViaUDP(void *args) {
stdev.reset(); stdev.reset();
if (LOG_SAMPLE_DELAY) {
char *directory = new char[50];
char *filename = new char[50];
sprintf(directory, "%s/Desktop/echo_tests", getenv("HOME"));
mkdir(directory, S_IRWXU | S_IRWXG | S_IRWXO);
sprintf(filename, "%s/%ld.csv", directory, previousReceiveTime.tv_sec);
logFile.open(filename, std::ios::out);
delete[] directory;
delete[] filename;
}
while (!stopAudioReceiveThread) { while (!stopAudioReceiveThread) {
if (sharedAudioData->audioSocket->receive((void *)receivedData, &receivedBytes)) { if (sharedAudioData->audioSocket->receive((void *)receivedData, &receivedBytes)) {
gettimeofday(&currentReceiveTime, NULL); gettimeofday(&currentReceiveTime, NULL);
totalPacketsReceived++; totalPacketsReceived++;
if (LOG_SAMPLE_DELAY) {
// write time difference (in microseconds) between packet receipts to file
double timeDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
logFile << timeDiff << std::endl;
}
double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime); double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
//printLog("tDiff %4.1f\n", tDiff); //printLog("tDiff %4.1f\n", tDiff);
@ -562,8 +536,7 @@ void Audio::render(int screenWidth, int screenHeight)
* @return Returns true if the initialization was successful, or false if an error occured. * @return Returns true if the initialization was successful, or false if an error occured.
The error code may be retrieved by Audio::getError(). The error code may be retrieved by Audio::getError().
*/ */
bool Audio::terminate () bool Audio::terminate() {
{
stopAudioReceiveThread = true; stopAudioReceiveThread = true;
pthread_join(audioReceiveThread, NULL); pthread_join(audioReceiveThread, NULL);
@ -577,7 +550,6 @@ bool Audio::terminate ()
if (paError != paNoError) goto error; if (paError != paNoError) goto error;
} }
logFile.close();
delete audioData; delete audioData;
return true; return true;

View file

@ -1539,3 +1539,23 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) {
return glm::vec3(0.f, 0.f, 0.f); return glm::vec3(0.f, 0.f, 0.f);
} }
} }
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";
void Avatar::writeAvatarDataToFile() {
// write the avatar position and yaw to a local file
FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "w");
if (avatarFile) {
fprintf(avatarFile, "%f,%f,%f %f", _position.x, _position.y, _position.z, _bodyYaw);
fclose(avatarFile);
}
}
void Avatar::readAvatarDataFromFile() {
FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "r");
if (avatarFile) {
fscanf(avatarFile, "%f,%f,%f %f", &_position.x, &_position.y, &_position.z, &_bodyYaw);
}
}

View file

@ -145,6 +145,9 @@ public:
// Find out what the local gravity vector is at this location // Find out what the local gravity vector is at this location
glm::vec3 getGravity(glm::vec3 pos); glm::vec3 getGravity(glm::vec3 pos);
void writeAvatarDataToFile();
void readAvatarDataFromFile();
private: private:

View file

@ -24,7 +24,6 @@ using namespace std;
// no clue which versions are affected... // no clue which versions are affected...
#define WORKAROUND_BROKEN_GLUT_STROKES #define WORKAROUND_BROKEN_GLUT_STROKES
// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html // see http://www.opengl.org/resources/libraries/glut/spec3/node78.html
static float MONO_STROKE_WIDTH_GLUT = 104.76;
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * right, glm::vec3 * up) { void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * right, glm::vec3 * up) {
// //
@ -172,7 +171,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
// //
// Draws text on screen as stroked so it can be resized // Draws text on screen as stroked so it can be resized
// //
int len, i;
glPushMatrix(); glPushMatrix();
glTranslatef( static_cast<float>(x), static_cast<float>(y), 0.0f); glTranslatef( static_cast<float>(x), static_cast<float>(y), 0.0f);
glColor3f(r,g,b); glColor3f(r,g,b);

View file

@ -344,7 +344,9 @@ void init(void)
void terminate () { void terminate () {
// Close serial port // Close serial port
//close(serial_fd); // close(serial_fd);
myAvatar.writeAvatarDataToFile();
#ifndef _WIN32 #ifndef _WIN32
audio.terminate(); audio.terminate();
@ -847,13 +849,13 @@ void displayOculus(Camera& whichCamera) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glUseProgramObjectARB(::oculusProgramID); glUseProgramObjectARB(::oculusProgramID);
glUniform1fARB(textureLocation, 0); glUniform1iARB(textureLocation, 0);
glUniform2fARB(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29 glUniform2fARB(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29
glUniform2fARB(screenCenterLocation, 0.25, 0.5); glUniform2fARB(screenCenterLocation, 0.25, 0.5);
glUniform2fARB(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio); glUniform2fARB(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio);
glUniform2fARB(scaleInLocation, 4, 2 / aspectRatio); glUniform2fARB(scaleInLocation, 4, 2 / aspectRatio);
glUniform4fARB(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0); glUniform4fARB(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0);
glColor3f(1, 0, 1); glColor3f(1, 0, 1);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
@ -1290,7 +1292,6 @@ int doRandomizeVoxelColors(int state) {
return state; return state;
} }
int doFalseRandomizeVoxelColors(int state) { int doFalseRandomizeVoxelColors(int state) {
if (state == MENU_ROW_PICKED) { if (state == MENU_ROW_PICKED) {
::voxels.falseColorizeRandom(); ::voxels.falseColorizeRandom();
@ -1322,7 +1323,6 @@ int doFalseColorizeInView(int state) {
return state; return state;
} }
const char* modeAll = " - All "; const char* modeAll = " - All ";
const char* modeVectors = " - Vectors "; const char* modeVectors = " - Vectors ";
const char* modePlanes = " - Planes "; const char* modePlanes = " - Planes ";
@ -1396,8 +1396,7 @@ void testPointToVoxel()
float y=0; float y=0;
float z=0; float z=0;
float s=0.1; float s=0.1;
for (float x=0; x<=1; x+= 0.05) for (float x=0; x<=1; x+= 0.05) {
{
printLog(" x=%f"); printLog(" x=%f");
unsigned char red = 200; //randomColorValue(65); unsigned char red = 200; //randomColorValue(65);
@ -1486,11 +1485,9 @@ void specialkeyUp(int k, int x, int y) {
myAvatar.setDriveKeys(RIGHT, 0); myAvatar.setDriveKeys(RIGHT, 0);
myAvatar.setDriveKeys(ROT_RIGHT, 0); myAvatar.setDriveKeys(ROT_RIGHT, 0);
} }
} }
void specialkey(int k, int x, int y) void specialkey(int k, int x, int y) {
{
if (::chatEntryOn) { if (::chatEntryOn) {
chatEntry.specialKey(k); chatEntry.specialKey(k);
return; return;
@ -1532,7 +1529,6 @@ void keyUp(unsigned char k, int x, int y) {
if (k == 's') myAvatar.setDriveKeys(BACK, 0); if (k == 's') myAvatar.setDriveKeys(BACK, 0);
if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 0); if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 0);
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)
@ -1624,8 +1620,7 @@ void key(unsigned char k, int x, int y)
} }
// Receive packets from other agents/servers and decide what to do with them! // Receive packets from other agents/servers and decide what to do with them!
void* networkReceive(void* args) void* networkReceive(void* args) {
{
sockaddr senderAddress; sockaddr senderAddress;
ssize_t bytesReceived; ssize_t bytesReceived;
@ -1697,9 +1692,7 @@ void idle(void) {
handControl.stop(); handControl.stop();
} }
//
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents // Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
//
updateAvatar(deltaTime); updateAvatar(deltaTime);
// read incoming packets from network // read incoming packets from network
@ -1730,9 +1723,7 @@ void idle(void) {
} }
} }
void reshape(int width, int height) {
void reshape(int width, int height)
{
WIDTH = width; WIDTH = width;
HEIGHT = height; HEIGHT = height;
aspectRatio = ((float)width/(float)height); // based on screen resize aspectRatio = ((float)width/(float)height); // based on screen resize
@ -1748,21 +1739,22 @@ void reshape(int width, int height)
camera.setAspectRatio(aspectRatio *= 0.5); camera.setAspectRatio(aspectRatio *= 0.5);
camera.setFieldOfView(fov = 2 * atan((0.0468 * ::oculusDistortionScale) / 0.041) * (180 / PI)); camera.setFieldOfView(fov = 2 * atan((0.0468 * ::oculusDistortionScale) / 0.041) * (180 / PI));
// resize the render texture
if (::oculusTextureID != 0) {
glBindTexture(GL_TEXTURE_2D, ::oculusTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
} else { } else {
camera.setFieldOfView(fov = 60); camera.setFieldOfView(fov = 60);
} }
//printLog("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n",
// width,height,aspectRatio,fov,nearClip,farClip);
// Tell our viewFrustum about this change // Tell our viewFrustum about this change
::viewFrustum.setAspectRatio(aspectRatio); ::viewFrustum.setAspectRatio(aspectRatio);
glViewport(0, 0, width, height); // shouldn't this account for the menu??? glViewport(0, 0, width, height); // shouldn't this account for the menu???
glMatrixMode(GL_PROJECTION); //hello glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
// XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that
@ -1779,46 +1771,34 @@ void reshape(int width, int height)
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
} }
void mouseFunc( int button, int state, int x, int y ) void mouseFunc(int button, int state, int x, int y) {
{ if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
{
if (!menu.mouseClick(x, y)) {
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;
mousePressed = 1; mousePressed = 1;
} else if (state == GLUT_UP) {
mouseX = x;
mouseY = y;
mousePressed = 0;
} }
} }
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
mouseX = x;
mouseY = y;
mousePressed = 0;
}
} }
void motionFunc( int x, int y) void motionFunc(int x, int y) {
{
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;
} }
void mouseoverFunc( int x, int y) void mouseoverFunc(int x, int y){
{
menu.mouseOver(x, y); menu.mouseOver(x, y);
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;
if (mousePressed == 0)
{}
} }
void attachNewHeadToAgent(Agent *newAgent) { void attachNewHeadToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Avatar(false)); newAgent->setLinkedData(new Avatar(false));
@ -1940,6 +1920,8 @@ int main(int argc, const char * argv[])
printLog("Network receive thread created.\n"); printLog("Network receive thread created.\n");
} }
myAvatar.readAvatarDataFromFile();
glutTimerFunc(1000, Timer, 0); glutTimerFunc(1000, Timer, 0);
glutMainLoop(); glutMainLoop();

View file

@ -459,11 +459,6 @@ namespace starfield {
private: // gl API handling private: // gl API handling
#ifdef __APPLE__
# define glBindVertexArray glBindVertexArrayAPPLE
# define glGenVertexArrays glGenVertexArraysAPPLE
# define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif
void glAlloc() { void glAlloc() {
GLchar const* const VERTEX_SHADER = GLchar const* const VERTEX_SHADER =
@ -487,26 +482,21 @@ namespace starfield {
_objProgram.addShader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER); _objProgram.addShader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
_objProgram.link(); _objProgram.link();
glGenVertexArrays(1, & _hndVertexArray); glGenBuffersARB(1, & _hndVertexArray);
} }
void glFree() { void glFree() {
glDeleteVertexArrays(1, & _hndVertexArray); glDeleteBuffersARB(1, & _hndVertexArray);
} }
void glUpload(GLsizei n) { void glUpload(GLsizei n) {
glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray);
GLuint vbo;
glGenBuffers(1, & vbo);
glBindVertexArray(_hndVertexArray);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, glBufferData(GL_ARRAY_BUFFER,
n * sizeof(GpuVertex), _arrData, GL_STATIC_DRAW); n * sizeof(GpuVertex), _arrData, GL_STATIC_DRAW);
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); //glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
glBindVertexArray(0); glBindBufferARB(GL_ARRAY_BUFFER, 0);
} }
void glBatch(GLfloat const* matrix, GLsizei n_ranges) { void glBatch(GLfloat const* matrix, GLsizei n_ranges) {
@ -538,14 +528,15 @@ namespace starfield {
// select shader and vertex array // select shader and vertex array
_objProgram.activate(); _objProgram.activate();
glBindVertexArray(_hndVertexArray); glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray);
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
// render // render
glMultiDrawArrays(GL_POINTS, glMultiDrawArrays(GL_POINTS,
_arrBatchOffs, _arrBatchCount, n_ranges); _arrBatchOffs, _arrBatchCount, n_ranges);
// restore state // restore state
glBindVertexArray(0); glBindBufferARB(GL_ARRAY_BUFFER, 0);
glUseProgram(0); glUseProgram(0);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDisable(GL_POINT_SMOOTH); glDisable(GL_POINT_SMOOTH);
@ -553,11 +544,6 @@ namespace starfield {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
} }
#ifdef __APPLE__
# undef glBindVertexArray
# undef glGenVertexArrays
# undef glDeleteVertexArrays
#endif
}; };
} // anonymous namespace } // anonymous namespace

View file

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
set(TARGET_NAME pairing-server)
include(${MACRO_DIR}/SetupHifiProject.cmake)
setup_hifi_project(${TARGET_NAME})
# link the shared hifi library
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})

106
pairing-server/src/main.cpp Normal file
View file

@ -0,0 +1,106 @@
//
// main.cpp
// pairing-server
//
// Created by Stephen Birarda on 5/1/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <UDPSocket.h>
#include <arpa/inet.h>
const int PAIRING_SERVER_LISTEN_PORT = 7247;
const int MAX_PACKET_SIZE_BYTES = 1400;
struct PairableDevice {
char identifier[64];
char name[64];
sockaddr_in sendingSocket;
sockaddr_in localSocket;
};
int indexOfFirstOccurenceOfCharacter(char* haystack, char needle) {
int currentIndex = 0;
while (haystack[currentIndex] != '\0' && haystack[currentIndex] != needle) {
currentIndex++;
}
return currentIndex;
}
int main(int argc, const char* argv[]) {
UDPSocket serverSocket(PAIRING_SERVER_LISTEN_PORT);
sockaddr_in senderSocket;
char senderData[MAX_PACKET_SIZE_BYTES] = {};
ssize_t receivedBytes = 0;
std::vector<PairableDevice> devices;
while (true) {
if (serverSocket.receive((sockaddr *)&senderSocket, &senderData, &receivedBytes)) {
if (senderData[0] == 'A') {
// this is a device reporting itself as available
// create a new PairableDevice
PairableDevice newDevice = {};
int addressBytes[4];
int socketPort = 0;
int numMatches = sscanf(senderData, "Available %s %d.%d.%d.%d:%d %s",
newDevice.identifier,
&addressBytes[3],
&addressBytes[2],
&addressBytes[1],
&addressBytes[0],
&socketPort,
newDevice.name);
if (numMatches >= 6) {
// if we have fewer than 6 matches the packet wasn't properly formatted
// setup the localSocket for the pairing device
newDevice.localSocket.sin_family = AF_INET;
newDevice.localSocket.sin_addr.s_addr = (addressBytes[3] |
addressBytes[2] << 8 |
addressBytes[1] << 16 |
addressBytes[0] << 24);
newDevice.localSocket.sin_port = socketPort;
// store this device's sending socket so we can talk back to it
newDevice.sendingSocket = senderSocket;
// push this new device into the vector
printf("Adding device %s (%s) to list\n", newDevice.identifier, newDevice.name);
devices.push_back(newDevice);
}
} else if (senderData[0] == 'F') {
// this is a client looking to pair with a device
// send the most recent device this address so it can attempt to pair
char requestorAddress[INET_ADDRSTRLEN] = {};
int requestorPort = 0;
int requestorMatches = sscanf(senderData, "Find %[^:]:%d", requestorAddress, &requestorPort);
if (requestorMatches == 2) {
PairableDevice lastDevice = devices[devices.size() - 1];
char pairData[INET_ADDRSTRLEN + 6] = {};
sprintf(pairData, "%s:%d", requestorAddress, requestorPort);
serverSocket.send((sockaddr*) &lastDevice.sendingSocket, pairData, strlen(pairData));
}
}
}
}
}