adds logging support to voxels library

This commit is contained in:
tosh 2013-04-17 20:01:58 +02:00
parent c261449937
commit f899ff9378
5 changed files with 61 additions and 49 deletions

View file

@ -48,6 +48,8 @@
#include <glm/gtc/type_ptr.hpp>
#include "Log.h"
#include "shared_Log.h"
#include "voxels_Log.h"
#include "Field.h"
#include "world.h"
@ -134,7 +136,7 @@ Cloud cloud(0, // Particles
false // Wrap
);
VoxelSystem voxels;
VoxelSystem voxSys;
Field field;
#ifndef _WIN32
@ -243,28 +245,28 @@ void displayStats(void)
}
std::stringstream voxelStats;
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
voxelStats << "Voxels Rendered: " << voxSys.getVoxelsRendered();
drawtext(10, statsVerticalOffset + 70, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() << " (" << voxels.getVoxelsCreatedRunningAverage()
voxelStats << "Voxels Created: " << voxSys.getVoxelsCreated() << " (" << voxSys.getVoxelsCreatedRunningAverage()
<< "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
drawtext(10, statsVerticalOffset + 250, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() << " (" << voxels.getVoxelsColoredRunningAverage()
voxelStats << "Voxels Colored: " << voxSys.getVoxelsColored() << " (" << voxSys.getVoxelsColoredRunningAverage()
<< "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
drawtext(10, statsVerticalOffset + 270, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
voxelStats << "Voxels Bytes Read: " << voxels.getVoxelsBytesRead()
<< " (" << voxels.getVoxelsBytesReadRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
voxelStats << "Voxels Bytes Read: " << voxSys.getVoxelsBytesRead()
<< " (" << voxSys.getVoxelsBytesReadRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
drawtext(10, statsVerticalOffset + 290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
voxelStats.str("");
long int voxelsBytesPerColored = voxels.getVoxelsColored() ? voxels.getVoxelsBytesRead()/voxels.getVoxelsColored() : 0;
long int voxelsBytesPerColoredAvg = voxels.getVoxelsColoredRunningAverage() ?
voxels.getVoxelsBytesReadRunningAverage()/voxels.getVoxelsColoredRunningAverage() : 0;
long int voxelsBytesPerColored = voxSys.getVoxelsColored() ? voxSys.getVoxelsBytesRead()/voxSys.getVoxelsColored() : 0;
long int voxelsBytesPerColoredAvg = voxSys.getVoxelsColoredRunningAverage() ?
voxSys.getVoxelsBytesReadRunningAverage()/voxSys.getVoxelsColoredRunningAverage() : 0;
voxelStats << "Voxels Bytes per Colored: " << voxelsBytesPerColored
<< " (" << voxelsBytesPerColoredAvg << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) ";
@ -301,8 +303,8 @@ void initDisplay(void)
void init(void)
{
voxels.init();
voxels.setViewerHead(&myAvatar);
voxSys.init();
voxSys.setViewerHead(&myAvatar);
myAvatar.setRenderYaw(startYaw);
headMouseX = WIDTH/2;
@ -817,7 +819,7 @@ void display(void)
// Draw voxels
if ( showingVoxels )
{
voxels.render();
voxSys.render();
}
// Draw field vectors
@ -1151,7 +1153,7 @@ void addRandomSphere(bool wantColorRandomizer)
printLog("yc=%f\n",yc);
printLog("zc=%f\n",zc);
voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
voxSys.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
}
@ -1313,7 +1315,7 @@ void *networkReceive(void *args)
case PACKET_HEADER_VOXEL_DATA:
case PACKET_HEADER_Z_COMMAND:
case PACKET_HEADER_ERASE_VOXEL:
voxels.parseData(incomingPacket, bytesReceived);
voxSys.parseData(incomingPacket, bytesReceived);
break;
case PACKET_HEADER_BULK_AVATAR_DATA:
AgentList::getInstance()->processBulkAgentData(&senderAddress,
@ -1515,7 +1517,7 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
int main(int argc, const char * argv[])
{
shared::printLog = ::printLog;
voxels::printLog = ::printLog;
// Quick test of the Orientation class on startup!
testOrientationClass();
@ -1599,7 +1601,7 @@ int main(int argc, const char * argv[])
// Voxel File. If so, load it now.
const char* voxelsFilename = getCmdOption(argc, argv, "-i");
if (voxelsFilename) {
voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
voxSys.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
printLog("Local Voxel File loaded.\n");
}

View file

@ -5,6 +5,10 @@
#include "Plane.h"
#include <stdio.h>
#include "voxels_Log.h"
using voxels::printLog;
// These are some useful utilities that vec3 is missing
float vec3_length(const glm::vec3& v) {
return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
@ -79,5 +83,5 @@ float Plane::distance(const glm::vec3 &p) {
}
void Plane::print() {
//printf("Plane(");normal.print();printf("# %f)",d);
//printLog("Plane(");normal.print();printLog("# %f)",d);
}

View file

@ -9,6 +9,9 @@
//
#include "ViewFrustum.h"
#include "voxels_Log.h"
using voxels::printLog;
ViewFrustum::ViewFrustum() :
_position(glm::vec3(0,0,0)),
@ -95,39 +98,39 @@ void ViewFrustum::calculate() {
void ViewFrustum::dump() {
printf("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z);
printf("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z);
printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z);
printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z);
printLog("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z);
printLog("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z);
printLog("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z);
printLog("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z);
printf("farDist=%f\n", this->_farClip);
printf("farHeight=%f\n", this->_farHeight);
printf("farWidth=%f\n", this->_farWidth);
printLog("farDist=%f\n", this->_farClip);
printLog("farHeight=%f\n", this->_farHeight);
printLog("farWidth=%f\n", this->_farWidth);
printf("nearDist=%f\n", this->_nearClip);
printf("nearHeight=%f\n", this->_nearHeight);
printf("nearWidth=%f\n", this->_nearWidth);
printLog("nearDist=%f\n", this->_nearClip);
printLog("nearHeight=%f\n", this->_nearHeight);
printLog("nearWidth=%f\n", this->_nearWidth);
printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",
printLog("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",
this->_farCenter.x, this->_farCenter.y, this->_farCenter.z);
printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",
printLog("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",
this->_farTopLeft.x, this->_farTopLeft.y, this->_farTopLeft.z);
printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",
printLog("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",
this->_farTopRight.x, this->_farTopRight.y, this->_farTopRight.z);
printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",
printLog("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",
this->_farBottomLeft.x, this->_farBottomLeft.y, this->_farBottomLeft.z);
printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",
printLog("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",
this->_farBottomRight.x, this->_farBottomRight.y, this->_farBottomRight.z);
printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",
printLog("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",
this->_nearCenter.x, this->_nearCenter.y, this->_nearCenter.z);
printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",
printLog("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",
this->_nearTopLeft.x, this->_nearTopLeft.y, this->_nearTopLeft.z);
printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",
printLog("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",
this->_nearTopRight.x, this->_nearTopRight.y, this->_nearTopRight.z);
printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",
printLog("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",
this->_nearBottomLeft.x, this->_nearBottomLeft.y, this->_nearBottomLeft.z);
printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",
printLog("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",
this->_nearBottomRight.x, this->_nearBottomRight.y, this->_nearBottomRight.z);
}

View file

@ -8,6 +8,7 @@
#include <cstring>
#include "SharedUtil.h"
//#include "voxels_Log.h"
#include "VoxelNode.h"
#include "OctalCode.h"
@ -76,7 +77,7 @@ bool VoxelNode::collapseIdenticalLeaves() {
// if no child, or child doesn't have a color
if (children[i] == NULL || children[i]->color[3] != 1) {
allChildrenMatch=false;
//printf("SADNESS child missing or not colored! i=%d\n",i);
//printLog("SADNESS child missing or not colored! i=%d\n",i);
break;
} else {
if (i==0) {
@ -92,7 +93,7 @@ bool VoxelNode::collapseIdenticalLeaves() {
if (allChildrenMatch) {
//printf("allChildrenMatch: pruning tree\n");
//printLog("allChildrenMatch: pruning tree\n");
for (int i = 0; i < 8; i++) {
delete children[i]; // delete all the child nodes
children[i]=NULL; // set it to NULL
@ -111,4 +112,4 @@ void VoxelNode::setRandomColor(int minimumBrightness) {
}
color[3] = 1;
}
}

View file

@ -13,6 +13,7 @@
#include <cstdio>
#include <cmath>
#include "SharedUtil.h"
#include "voxels_Log.h"
#include "PacketHeaders.h"
#include "CounterStats.h"
#include "OctalCode.h"
@ -20,6 +21,7 @@
#include <iostream> // to load voxels from file
#include <fstream> // to load voxels from file
using voxels::printLog;
int boundaryDistanceForRenderLevel(unsigned int renderLevel) {
switch (renderLevel) {
@ -416,7 +418,7 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
// XXXBHG: validate buffer is at least 4 bytes long? other guards??
unsigned short int itemNumber = (*((unsigned short int*)&bitstream[1]));
printf("processRemoveVoxelBitstream() receivedBytes=%d itemNumber=%d\n",bufferSizeBytes,itemNumber);
printLog("processRemoveVoxelBitstream() receivedBytes=%d itemNumber=%d\n",bufferSizeBytes,itemNumber);
int atByte = 3;
unsigned char* pVoxelData = (unsigned char*)&bitstream[3];
while (atByte < bufferSizeBytes) {
@ -424,7 +426,7 @@ void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int buffe
int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color!
float* vertices = firstVertexForCode(pVoxelData);
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
printLog("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
delete []vertices;
deleteVoxelCodeFromTree(pVoxelData);
@ -510,11 +512,11 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
int totalBytesRead = 0;
if(file.is_open()) {
printf("loading file...\n");
printLog("loading file...\n");
bool bail = false;
while (!file.eof() && !bail) {
file.get(octets);
//printf("octets=%d...\n",octets);
//printLog("octets=%d...\n",octets);
totalBytesRead++;
lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1;
unsigned char * voxelData = new unsigned char[lengthInBytes+1+3];
@ -536,14 +538,14 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
file.get(colorRead);
blue = (unsigned char)colorRead;
printf("voxel color from file red:%d, green:%d, blue:%d \n",red,green,blue);
printLog("voxel color from file red:%d, green:%d, blue:%d \n",red,green,blue);
vCount++;
int colorRandomizer = wantColorRandomizer ? randIntInRange (-5, 5) : 0;
voxelData[lengthInBytes+1] = std::max(0,std::min(255,red + colorRandomizer));
voxelData[lengthInBytes+2] = std::max(0,std::min(255,green + colorRandomizer));
voxelData[lengthInBytes+3] = std::max(0,std::min(255,blue + colorRandomizer));
printf("voxel color after rand red:%d, green:%d, blue:%d\n",
printLog("voxel color after rand red:%d, green:%d, blue:%d\n",
voxelData[lengthInBytes+1], voxelData[lengthInBytes+2], voxelData[lengthInBytes+3]);
//printVoxelCode(voxelData);
@ -608,7 +610,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
// If you also iterate form the interior of the sphere to the radius, makeing
// larger and larger sphere's you'd end up with a solid sphere. And lots of voxels!
for (; ri <= (r+(s/2.0)); ri+=s) {
//printf("radius: ri=%f ri+s=%f (r+(s/2.0))=%f\n",ri,ri+s,(r+(s/2.0)));
//printLog("radius: ri=%f ri+s=%f (r+(s/2.0))=%f\n",ri,ri+s,(r+(s/2.0)));
for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) {
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
t++; // total voxels
@ -622,7 +624,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
// only use our actual desired color on the outer edge, otherwise
// use our "average" color
if (ri+(s*2.0)>=r) {
//printf("painting candy shell radius: ri=%f r=%f\n",ri,r);
//printLog("painting candy shell radius: ri=%f r=%f\n",ri,r);
red = wantColorRandomizer ? randomColorValue(165) : r1+((r2-r1)*gradient);
green = wantColorRandomizer ? randomColorValue(165) : g1+((g2-g1)*gradient);
blue = wantColorRandomizer ? randomColorValue(165) : b1+((b2-b1)*gradient);
@ -630,7 +632,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
this->readCodeColorBufferToTree(voxelData);
//printf("voxel data for x:%f y:%f z:%f s:%f\n",x,y,z,s);
//printLog("voxel data for x:%f y:%f z:%f s:%f\n",x,y,z,s);
//printVoxelCode(voxelData);
delete voxelData;
}