From 90a08b4dd86fa8c89ee725117cb71427c628018d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 May 2013 14:45:47 -0700 Subject: [PATCH 1/5] cleanup in Audio and Util --- interface/src/Audio.cpp | 7 ++----- interface/src/Util.cpp | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index a83bf5e4d5..69e0b148f3 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -317,8 +317,8 @@ void *receiveAudioViaUDP(void *args) { if (LOG_SAMPLE_DELAY) { - char *directory = new char[50]; - char *filename = new char[50]; + char directory[50]; + char filename[50]; sprintf(directory, "%s/Desktop/echo_tests", getenv("HOME")); @@ -326,9 +326,6 @@ void *receiveAudioViaUDP(void *args) { sprintf(filename, "%s/%ld.csv", directory, previousReceiveTime.tv_sec); logFile.open(filename, std::ios::out); - - delete[] directory; - delete[] filename; } while (!stopAudioReceiveThread) { diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 138ae7aef4..aeba937e0a 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -24,7 +24,6 @@ using namespace std; // no clue which versions are affected... #define WORKAROUND_BROKEN_GLUT_STROKES // 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) { // @@ -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 // - int len, i; glPushMatrix(); glTranslatef( static_cast(x), static_cast(y), 0.0f); glColor3f(r,g,b); From 1a8564f9d9b48acbd5645b3f96a57ecf9548517f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 May 2013 15:05:28 -0700 Subject: [PATCH 2/5] store avatar position and yaw in file to restore on relaunch --- interface/src/Avatar.cpp | 20 ++++++++++++++++++++ interface/src/Avatar.h | 3 +++ interface/src/main.cpp | 6 +++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 7a4468d608..675d4ce1c0 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1539,3 +1539,23 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) { 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); + } +} diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index e327df25c2..d2570d1976 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -145,6 +145,9 @@ public: // Find out what the local gravity vector is at this location glm::vec3 getGravity(glm::vec3 pos); + + void writeAvatarDataToFile(); + void readAvatarDataFromFile(); private: diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7bf7a181ff..125cc07597 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -344,7 +344,9 @@ void init(void) void terminate () { // Close serial port - //close(serial_fd); + // close(serial_fd); + + myAvatar.writeAvatarDataToFile(); #ifndef _WIN32 audio.terminate(); @@ -1944,6 +1946,8 @@ int main(int argc, const char * argv[]) printLog("Network receive thread created.\n"); } + myAvatar.readAvatarDataFromFile(); + glutTimerFunc(1000, Timer, 0); glutMainLoop(); From da93b596de05c6b9eb9e355002998335280fcd37 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 May 2013 15:08:48 -0700 Subject: [PATCH 3/5] some deletion cleanup in main.cpp --- interface/src/main.cpp | 50 ++++++++++++------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 125cc07597..990f4e8197 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1491,8 +1491,7 @@ void specialkeyUp(int k, int x, int y) { } -void specialkey(int k, int x, int y) -{ +void specialkey(int k, int x, int y) { if (::chatEntryOn) { chatEntry.specialKey(k); return; @@ -1534,7 +1533,6 @@ void keyUp(unsigned char k, int x, int y) { if (k == 's') myAvatar.setDriveKeys(BACK, 0); if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 0); if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0); - } void key(unsigned char k, int x, int y) @@ -1626,8 +1624,7 @@ void key(unsigned char k, int x, int y) } // Receive packets from other agents/servers and decide what to do with them! -void* networkReceive(void* args) -{ +void* networkReceive(void* args) { sockaddr senderAddress; ssize_t bytesReceived; @@ -1699,9 +1696,7 @@ void idle(void) { handControl.stop(); } - // // Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents - // updateAvatar(deltaTime); // read incoming packets from network @@ -1732,9 +1727,7 @@ void idle(void) { } } - -void reshape(int width, int height) -{ +void reshape(int width, int height) { WIDTH = width; HEIGHT = height; aspectRatio = ((float)width/(float)height); // based on screen resize @@ -1760,17 +1753,12 @@ void reshape(int width, int height) 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 ::viewFrustum.setAspectRatio(aspectRatio); - glViewport(0, 0, width, height); // shouldn't this account for the menu??? - glMatrixMode(GL_PROJECTION); //hello - + glMatrixMode(GL_PROJECTION); glLoadIdentity(); // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that @@ -1787,42 +1775,32 @@ void reshape(int width, int height) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - - } -void mouseFunc( int button, int state, int x, int y ) -{ - if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) - { - if (!menu.mouseClick(x, y)) { +void mouseFunc(int button, int state, int x, int y) { + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { + if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { mouseX = x; mouseY = y; 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; mouseY = y; } -void mouseoverFunc( int x, int y) -{ +void mouseoverFunc(int x, int y){ menu.mouseOver(x, y); mouseX = x; mouseY = y; - if (mousePressed == 0) - {} } void attachNewHeadToAgent(Agent *newAgent) { From 31e9c1834619fd8b9af55ae83073e0e035d8f898 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 May 2013 15:09:44 -0700 Subject: [PATCH 4/5] couple of extra line deletions in main.cpp --- interface/src/main.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 990f4e8197..8f5a70cbe6 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1292,7 +1292,6 @@ int doRandomizeVoxelColors(int state) { return state; } - int doFalseRandomizeVoxelColors(int state) { if (state == MENU_ROW_PICKED) { ::voxels.falseColorizeRandom(); @@ -1324,7 +1323,6 @@ int doFalseColorizeInView(int state) { return state; } - const char* modeAll = " - All "; const char* modeVectors = " - Vectors "; const char* modePlanes = " - Planes "; @@ -1398,8 +1396,7 @@ void testPointToVoxel() float y=0; float z=0; 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"); unsigned char red = 200; //randomColorValue(65); @@ -1488,7 +1485,6 @@ void specialkeyUp(int k, int x, int y) { myAvatar.setDriveKeys(RIGHT, 0); myAvatar.setDriveKeys(ROT_RIGHT, 0); } - } void specialkey(int k, int x, int y) { From bd3c902b683520985d1d30993a70cfc0a589a589 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 3 May 2013 15:13:38 -0700 Subject: [PATCH 5/5] remove logging of audio stats --- interface/src/Audio.cpp | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 69e0b148f3..7474f434b7 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -80,10 +80,6 @@ timeval firstPlaybackTimer; int packetsReceivedThisPlayback = 0; float usecsAtStartup = 0; -#define LOG_SAMPLE_DELAY 0 - -std::ofstream logFile; - /** * Audio callback used by portaudio. * Communicates with Audio via a shared pointer to Audio::data. @@ -315,31 +311,12 @@ void *receiveAudioViaUDP(void *args) { stdev.reset(); - if (LOG_SAMPLE_DELAY) { - - char directory[50]; - char filename[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); - } - while (!stopAudioReceiveThread) { if (sharedAudioData->audioSocket->receive((void *)receivedData, &receivedBytes)) { gettimeofday(¤tReceiveTime, NULL); totalPacketsReceived++; - - if (LOG_SAMPLE_DELAY) { - // write time difference (in microseconds) between packet receipts to file - double timeDiff = diffclock(&previousReceiveTime, ¤tReceiveTime); - logFile << timeDiff << std::endl; - } double tDiff = diffclock(&previousReceiveTime, ¤tReceiveTime); //printLog("tDiff %4.1f\n", tDiff); @@ -559,8 +536,7 @@ void Audio::render(int screenWidth, int screenHeight) * @return Returns true if the initialization was successful, or false if an error occured. The error code may be retrieved by Audio::getError(). */ -bool Audio::terminate () -{ +bool Audio::terminate() { stopAudioReceiveThread = true; pthread_join(audioReceiveThread, NULL); @@ -574,7 +550,6 @@ bool Audio::terminate () if (paError != paNoError) goto error; } - logFile.close(); delete audioData; return true;