integrates logging for interface

This commit is contained in:
tosh 2013-04-17 19:04:10 +02:00
parent e7810179de
commit 349e89aaa6
13 changed files with 96 additions and 89 deletions

View file

@ -19,6 +19,7 @@
#include <PacketHeaders.h>
#include "Audio.h"
#include "Util.h"
#include "Log.h"
Oscilloscope * scope;
@ -115,7 +116,7 @@ int audioCallback (const void *inputBuffer,
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
// int16_t *inputRight = ((int16_t **) inputBuffer)[1];
//printf("Audio callback at %6.0f\n", usecTimestampNow()/1000);
//printLog("Audio callback at %6.0f\n", usecTimestampNow()/1000);
if (inputLeft != NULL) {
@ -231,21 +232,21 @@ int audioCallback (const void *inputBuffer,
if (ringBuffer->getEndOfLastWrite() != NULL) {
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) {
//printf("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES);
//printLog("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES);
} else if (ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES) {
ringBuffer->setStarted(false);
starve_counter++;
packetsReceivedThisPlayback = 0;
//printf("Starved #%d\n", starve_counter);
//printLog("Starved #%d\n", starve_counter);
data->wasStarved = 10; // Frames to render the indication that the system was starved.
} else {
if (!ringBuffer->isStarted()) {
ringBuffer->setStarted(true);
//printf("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0);
//printLog("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0);
} else {
//printf("pushing buffer\n");
//printLog("pushing buffer\n");
}
// play whatever we have in the audio buffer
@ -391,12 +392,12 @@ void *receiveAudioViaUDP(void *args) {
}
double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
//printf("tDiff %4.1f\n", tDiff);
//printLog("tDiff %4.1f\n", tDiff);
// Discard first few received packets for computing jitter (often they pile up on start)
if (totalPacketsReceived > 3) stdev.addValue(tDiff);
if (stdev.getSamples() > 500) {
sharedAudioData->measuredJitter = stdev.getStDev();
//printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter);
//printLog("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter);
stdev.reset();
}
@ -407,7 +408,7 @@ void *receiveAudioViaUDP(void *args) {
packetsReceivedThisPlayback++;
}
else {
//printf("Audio packet received at %6.0f\n", usecTimestampNow()/1000);
//printLog("Audio packet received at %6.0f\n", usecTimestampNow()/1000);
}
if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL);
@ -494,8 +495,8 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead)
return;
error:
fprintf(stderr, "-- Failed to initialize portaudio --\n");
fprintf(stderr, "PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
printLog("-- Failed to initialize portaudio --\n");
printLog("PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
initialized = false;
delete[] audioData;
}
@ -629,8 +630,8 @@ bool Audio::terminate ()
return true;
error:
fprintf(stderr, "-- portaudio termination error --\n");
fprintf(stderr, "PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
printLog("-- portaudio termination error --\n");
printLog("PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
return false;
}

View file

@ -6,6 +6,7 @@
//---------------------------------------------------------------------
#include <SharedUtil.h>
// #include "Log.h"
#include "Camera.h"
@ -67,6 +68,6 @@ void Camera::update( float deltaTime )
_orientation.pitch ( _pitch );
_orientation.roll ( _roll );
//printf( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z );
//printLog( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z );
}

View file

@ -346,13 +346,13 @@ void Head::simulate(float deltaTime) {
if (! previousHandBeingMoved ){
initializeBodySprings();
usingSprings = true;
//printf( "just started moving hand\n" );
//printLog( "just started moving hand\n" );
}
}
else {
if ( previousHandBeingMoved ){
usingSprings = false;
//printf( "just stopped moving hand\n" );
//printLog( "just stopped moving hand\n" );
}
}
@ -962,7 +962,7 @@ void Head::updateSkeleton() {
for (int b=0; b<NUM_AVATAR_BONES; b++) {
if ( bone[b].parent == AVATAR_BONE_NULL ) {
bone[b].orientation.set(avatar.orientation);
//printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z );
//printLog( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z );
glm::vec3 ppp = _bodyPosition;
// ppp.y += 0.2;

View file

@ -2,18 +2,19 @@
#define __interface__OpenGlSupport__
#include "InterfaceConfig.h"
#include "Log.h"
/**
* Macro to log OpenGl errors to stderr.
* Example: oglLog( glPushMatrix() );
*/
//
// Macro to log OpenGl errors.
// Example: oglLog( glPushMatrix() );
//
#define oGlLog(stmt) \
stmt; \
{ \
GLenum e = glGetError(); \
if (e != GL_NO_ERROR) { \
fprintf(stderr, __FILE__ ":" oGlLog_stringize(__LINE__) \
" [OpenGL] %s\n", gluErrorString(e)); \
printLog(__FILE__ ":" oGlLog_stringize(__LINE__) \
" [OpenGL] %s\n", gluErrorString(e)); \
} \
} \
(void) 0
@ -21,10 +22,10 @@
#define oGlLog_stringize(x) oGlLog_stringize_i(x)
#define oGlLog_stringize_i(x) # x
/**
* Encapsulation of the otherwise lengthy call sequence to compile
* and link shading pipelines.
*/
//
// Encapsulation of the otherwise lengthy call sequence to compile
// and link shading pipelines.
//
class OGlProgram {
GLuint _hndProg;
@ -54,10 +55,10 @@ public:
}
#endif
/**
* Activates the executable for rendering.
* Shaders must be added and linked before this will work.
*/
//
// Activates the executable for rendering.
// Shaders must be added and linked before this will work.
//
void activate() const {
if (_hndProg != 0u) {
@ -66,17 +67,17 @@ public:
}
}
/**
* Adds a shader to the program.
*/
//
// Adds a shader to the program.
//
bool addShader(GLenum type, GLchar const* cString) {
return addShader(type, 1, & cString);
}
/**
* Adds a shader to the program and logs to stderr.
*/
//
// Adds a shader to the program and logs to stderr.
//
bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) {
if (! _hndProg && !! glCreateProgram) {
@ -100,9 +101,9 @@ public:
return !! status;
}
/**
* Links the program and logs to stderr.
*/
//
// Links the program and logs to stderr.
//
bool link() {
if (! _hndProg) { return false; }
@ -136,7 +137,7 @@ private:
if (!! logLength) {
GLchar* message = new GLchar[logLength];
getLog(handle, logLength, 0l, message);
fprintf(stderr, "%s\n", message);
printLog("%s\n", message);
delete[] message;
}
}

View file

@ -67,10 +67,10 @@ int SerialInterface::initializePort(char* portname, int baud)
#ifdef __APPLE__
serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
printf("Opening SerialUSB %s: ", portname);
printLog("Opening SerialUSB %s: ", portname);
if (serialFd == -1) {
printf("Failed.\n");
printLog("Failed.\n");
return -1; // Failed to open port
}
struct termios options;
@ -101,7 +101,7 @@ int SerialInterface::initializePort(char* portname, int baud)
tcsetattr(serialFd,TCSANOW,&options);
printf("Connected.\n");
printLog("Connected.\n");
resetSerial();
active = true;
#endif

View file

@ -10,6 +10,7 @@
#include "Util.h"
#include "world.h"
#include "InterfaceConfig.h"
#include "Log.h"
#include <iostream>
// These includes are for serial port reading/writing

View file

@ -13,6 +13,7 @@
#include <glm/glm.hpp>
#include <SharedUtil.h>
#include "Log.h"
#include "world.h"
#include "Util.h"
@ -258,7 +259,7 @@ void renderOrientationDirections( glm::vec3 position, Orientation orientation, f
}
void testOrientationClass() {
printf("\n----------\ntestOrientationClass()\n----------\n\n");
printLog("\n----------\ntestOrientationClass()\n----------\n\n");
oTestCase tests[] = {
// - inputs ------------, outputs -------------------- ------------------- ----------------------------
@ -297,43 +298,43 @@ void testOrientationClass() {
glm::vec3 up = o1.getUp();
glm::vec3 right = o1.getRight();
printf("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n\n",i+1,yaw,pitch,roll);
printLog("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n\n",i+1,yaw,pitch,roll);
printf(" +front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
printLog(" +front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
if (front.x == tests[i].frontX && front.y == tests[i].frontY && front.z == tests[i].frontZ) {
printf(" front vector PASSES!\n");
printLog(" front vector PASSES!\n");
} else {
printf(" front vector FAILED! expected: \n");
printf(" front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
printLog(" front vector FAILED! expected: \n");
printLog(" front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
passed = false;
}
printf(" +up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
printLog(" +up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
if (up.x == tests[i].upX && up.y == tests[i].upY && up.z == tests[i].upZ) {
printf(" up vector PASSES!\n");
printLog(" up vector PASSES!\n");
} else {
printf(" up vector FAILED! expected: \n");
printf(" up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
printLog(" up vector FAILED! expected: \n");
printLog(" up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
passed = false;
}
printf(" +right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
printLog(" +right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
if (right.x == tests[i].rightX && right.y == tests[i].rightY && right.z == tests[i].rightZ) {
printf(" right vector PASSES!\n");
printLog(" right vector PASSES!\n");
} else {
printf(" right vector FAILED! expected: \n");
printf(" right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
printLog(" right vector FAILED! expected: \n");
printLog(" right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
passed = false;
}
if (!passed) {
printf("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
printLog("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
failedCount++;
}
}
printf("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
printf("\n----------DONE----------\n\n");
printLog("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
printLog("\n----------DONE----------\n\n");
}

View file

@ -17,6 +17,8 @@
#include <PacketHeaders.h>
#include <OctalCode.h>
#include <pthread.h>
#include "Log.h"
#include "VoxelSystem.h"
const int MAX_VOXELS_PER_SYSTEM = 250000;
@ -136,15 +138,15 @@ void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
int commandLength = strlen(command); // commands are null terminated strings
int totalLength = 1+commandLength+1;
printf("got Z message len(%d)= %s\n", numBytes, command);
printLog("got Z message len(%d)= %s\n", numBytes, command);
while (totalLength <= numBytes) {
if (0==strcmp(command,(char*)"erase all")) {
printf("got Z message == erase all\n");
printLog("got Z message == erase all\n");
tree->eraseAllVoxels();
}
if (0==strcmp(command,(char*)"add scene")) {
printf("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
printLog("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
}
totalLength += commandLength+1;
}
@ -194,14 +196,14 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
float viewerZ = swapXandZ ? viewerPosition[0] : viewerPosition[2];
// debugging code.
//printf("treeToArrays() halfUnitForVoxel=%f\n",halfUnitForVoxel);
//printf("treeToArrays() viewerPosition {x,y,z or [0],[1],[2]} ={%f,%f,%f}\n",
// viewerPosition[0],viewerPosition[1],viewerPosition[2]);
//printf("treeToArrays() nodePosition {x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
// nodePosition[0],nodePosition[1],nodePosition[2]);
//printLog("treeToArrays() halfUnitForVoxel=%f\n",halfUnitForVoxel);
//printLog("treeToArrays() viewerPosition {x,y,z or [0],[1],[2]} ={%f,%f,%f}\n",
// viewerPosition[0],viewerPosition[1],viewerPosition[2]);
//printLog("treeToArrays() nodePosition {x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
// nodePosition[0],nodePosition[1],nodePosition[2]);
//float* vertices = firstVertexForCode(currentNode->octalCode);
//printf("treeToArrays() firstVerticesForCode(currentNode->octalCode)={x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
// vertices[0],vertices[1],vertices[2]);
//printLog("treeToArrays() firstVerticesForCode(currentNode->octalCode)={x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
// vertices[0],vertices[1],vertices[2]);
//delete []vertices;
float distanceToVoxelCenter = sqrtf(powf(viewerX - nodePosition[0] - halfUnitForVoxel, 2) +
@ -209,7 +211,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
powf(viewerZ - nodePosition[2] - halfUnitForVoxel, 2));
int boundaryPosition = boundaryDistanceForRenderLevel(*currentNode->octalCode + 1);
//printf("treeToArrays() distanceToVoxelCenter=%f boundaryPosition=%d\n",distanceToVoxelCenter,boundaryPosition);
//printLog("treeToArrays() distanceToVoxelCenter=%f boundaryPosition=%d\n",distanceToVoxelCenter,boundaryPosition);
bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring

View file

@ -151,7 +151,7 @@ float renderPitchRate = 0.f;
// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program)
glm::vec3 start_location(6.1f, 0, 1.4f);
int statsOn = 0; // Whether to show onscreen text overlay with stats
bool statsOn = true; // Whether to show onscreen text overlay with stats
bool starsOn = false; // Whether to display the stars
bool paintOn = false; // Whether to paint voxels as you fly around
VoxelDetail paintingVoxel; // The voxel we're painting if we're painting

View file

@ -39,6 +39,7 @@
#include "InterfaceConfig.h"
#include "OGlProgram.h"
#include "Log.h"
#include <cstddef>
#include <cfloat>

View file

@ -211,7 +211,7 @@ namespace starfield {
return false;
}
// fprintf(stderr, "Stars.cpp: setResolution(%d)\n", k);
// printLog("Stars.cpp: setResolution(%d)\n", k);
#if STARFIELD_MULTITHREADING
if (k != _valTileResolution.load(memory_order_relaxed))
@ -251,7 +251,7 @@ namespace starfield {
VertexOrder scanner(tiling);
radix2InplaceSort(_seqInput.begin(), _seqInput.end(), scanner);
// fprintf(stderr,
// printLog(
// "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin);
recreateRenderer(n, k, b, bMin);
@ -266,7 +266,7 @@ namespace starfield {
assert(overalloc >= realloc && realloc >= 0.0);
assert(overalloc <= 1.0 && realloc <= 1.0);
// fprintf(stderr,
// printLog(
// "Stars.cpp: changeLOD(%lf, %lf, %lf)\n", factor, overalloc, realloc);
size_t n, nRender;
@ -307,7 +307,7 @@ namespace starfield {
_valLodBrightness = b;
#endif
// fprintf(stderr, "Stars.cpp: "
// printLog("Stars.cpp: "
// "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n",
// fraction, oaFract, toBufSize(oaFract * last)), n, bMin, b);
@ -327,7 +327,7 @@ namespace starfield {
recreateRenderer(n, _valTileResolution, b, bMin);
// fprintf(stderr, "Stars.cpp: LOD reallocation\n");
// printLog("Stars.cpp: LOD reallocation\n");
// publish new lod state

View file

@ -45,13 +45,12 @@ namespace starfield {
if (! UrlReader::readUrl(url, *this))
{
fprintf(stderr, "%s:%d: %s\n",
printLog("%s:%d: %s\n",
_strUrl, _valLineNo, getError());
return false;
}
fprintf(stderr, "Stars.cpp: read %u vertices, using %lu\n",
_valRecordsRead, _ptrVertices->size());
printLog("Stars.cpp: read %u vertices, using %lu\n", _valRecordsRead, _ptrVertices->size());
return true;
}
@ -72,7 +71,7 @@ namespace starfield {
_ptrVertices->clear();
_ptrVertices->reserve(_valLimit);
// fprintf(stderr, "Stars.cpp: loader begin %s\n", url);
// printLog("Stars.cpp: loader begin %s\n", url);
}
size_t transfer(char* input, size_t bytes) {
@ -111,7 +110,7 @@ namespace starfield {
} else {
fprintf(stderr, "Stars.cpp:%d: Bad input from %s\n",
printLog("Stars.cpp:%d: Bad input from %s\n",
_valLineNo, _strUrl);
}
@ -136,7 +135,7 @@ namespace starfield {
// remember the brightness at its top
if (_valRecordsRead == _valLimit) {
// fprintf(stderr, "Stars.cpp: vertex limit reached -> heap mode\n");
// printLog("Stars.cpp: vertex limit reached -> heap mode\n");
make_heap(
_ptrVertices->begin(), _ptrVertices->end(),

View file

@ -125,7 +125,7 @@ namespace starfield {
mat4 const& orientation,
BrightnessLevel minBright) {
// fprintf(stderr, "
// printLog("
// Stars.cpp: rendering at minimal brightness %d\n", minBright);
float halfPersp = perspective * 0.5f;
@ -160,7 +160,7 @@ namespace starfield {
unsigned tileIndex =
_objTiling.getTileIndex(azimuth, altitude);
// fprintf(stderr, "Stars.cpp: starting on tile #%d\n", tileIndex);
// printLog("Stars.cpp: starting on tile #%d\n", tileIndex);
#if STARFIELD_DEBUG_LOD
@ -245,7 +245,7 @@ namespace starfield {
if (bv >= b)
++count_active;
// fprintf(stderr, "Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex);
// printLog("Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex);
// write converted vertex
_arrData[vertexIndex++] = *i;
@ -376,7 +376,7 @@ namespace starfield {
float dal = halfSlice;
float adjustedNear = cos(_valHalfPersp + sqrt(daz * daz + dal * dal));
// fprintf(stderr, "Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip);
// printLog("Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip);
return w > adjustedNear;
}
@ -486,10 +486,10 @@ namespace starfield {
void glBatch(GLfloat const* matrix, GLsizei n_ranges) {
// fprintf(stderr, "Stars.cpp: rendering %d-multibatch\n", n_ranges);
// printLog("Stars.cpp: rendering %d-multibatch\n", n_ranges);
// for (int i = 0; i < n_ranges; ++i)
// fprintf(stderr, "Stars.cpp: Batch #%d - %d stars @ %d\n", i,
// printLog("Stars.cpp: Batch #%d - %d stars @ %d\n", i,
// _arrBatchOffs[i], _arrBatchCount[i]);
glDisable(GL_DEPTH_TEST);