Merge pull request #247 from ZappoMan/render_voxels_optimization

Use different voxel persist files for local or server mode
This commit is contained in:
ZappoMan 2013-05-08 12:22:03 -07:00
commit ed9a7ae900
5 changed files with 19 additions and 10 deletions

View file

@ -503,6 +503,7 @@ bool VoxelSystem::trueColorizeOperation(VoxelNode* node, void* extraData) {
}
void VoxelSystem::trueColorize() {
PerformanceWarning warn(true, "trueColorize()",true);
_nodeCount = 0;
_tree->recurseTreeWithOperation(trueColorizeOperation);
printLog("setting true color for %d nodes\n", _nodeCount);

View file

@ -108,15 +108,16 @@ int PerfStat::DumpStats(char** array) {
PerformanceWarning::~PerformanceWarning() {
double end = usecTimestampNow();
double elapsedmsec = (end - _start) / 1000.0;
if (_renderWarningsOn && elapsedmsec > 1) {
if ((_alwaysDisplay || _renderWarningsOn) && elapsedmsec > 1) {
if (elapsedmsec > 1000) {
double elapsedsec = (end - _start) / 1000000.0;
printLog("WARNING! %s took %lf seconds\n", _message, elapsedsec);
} else {
printLog("WARNING! %s took %lf milliseconds\n", _message, elapsedmsec);
}
} else if (_alwaysDisplay) {
printLog("WARNING! %s took %lf milliseconds\n", _message, elapsedmsec);
}
};

View file

@ -87,11 +87,13 @@ private:
double _start;
const char* _message;
bool _renderWarningsOn;
bool _alwaysDisplay;
public:
PerformanceWarning(bool renderWarnings, const char* message) :
PerformanceWarning(bool renderWarnings, const char* message, bool alwaysDisplay = false) :
_start(usecTimestampNow()),
_message(message),
_renderWarningsOn(renderWarnings) { };
_renderWarningsOn(renderWarnings),
_alwaysDisplay(alwaysDisplay) { };
~PerformanceWarning();
};

View file

@ -933,7 +933,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
bool VoxelTree::readFromFileV2(const char* fileName) {
std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
if(file.is_open()) {
printLog("loading file...\n");
printLog("loading file %s...\n", fileName);
// get file length....
unsigned long fileLength = file.tellg();
@ -956,6 +956,8 @@ void VoxelTree::writeToFileV2(const char* fileName) const {
std::ofstream file(fileName, std::ios::out|std::ios::binary);
if(file.is_open()) {
printLog("saving to file %s...\n", fileName);
VoxelNodeBag nodeBag;
nodeBag.insert(rootNode);

View file

@ -28,7 +28,8 @@
#include <ifaddrs.h>
#endif
const char* VOXELS_PERSIST_FILE = "resources/voxels.hio2";
const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.hio2";
const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.hio2";
const int VOXEL_LISTEN_PORT = 40106;
@ -47,6 +48,8 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
VoxelTree randomTree;
bool wantVoxelPersist = true;
bool wantLocalDomain = false;
bool wantColorRandomizer = false;
bool debugVoxelSending = false;
@ -207,7 +210,7 @@ void persistVoxelsWhenDirty() {
// check the dirty bit and persist here...
if (::wantVoxelPersist && ::randomTree.isDirty()) {
printf("saving voxels to file...\n");
randomTree.writeToFileV2(VOXELS_PERSIST_FILE);
randomTree.writeToFileV2(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
randomTree.clearDirtyBit(); // tree is clean after saving
printf("DONE saving voxels to file...\n");
}
@ -270,8 +273,8 @@ int main(int argc, const char * argv[])
// Handle Local Domain testing with the --local command line
const char* local = "--local";
bool wantLocalDomain = cmdOptionExists(argc, argv,local);
if (wantLocalDomain) {
::wantLocalDomain = cmdOptionExists(argc, argv,local);
if (::wantLocalDomain) {
printf("Local Domain MODE!\n");
int ip = getLocalAddress();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
@ -302,7 +305,7 @@ int main(int argc, const char * argv[])
bool persistantFileRead = false;
if (::wantVoxelPersist) {
printf("loading voxels from file...\n");
persistantFileRead = ::randomTree.readFromFileV2(VOXELS_PERSIST_FILE);
persistantFileRead = ::randomTree.readFromFileV2(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
::randomTree.clearDirtyBit(); // the tree is clean since we just loaded it
printf("DONE loading voxels from file... fileRead=%s\n", persistantFileRead ? "yes" : "no" );
unsigned long nodeCount = ::randomTree.getVoxelCount();