From 31e518ebfde0f02c9bb72cdc10d8e768b3a07e3e Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 15 May 2013 14:21:32 +0200 Subject: [PATCH 01/17] moves dependency to new gl-program class to starfield/Config.h (where all the other dependencies to components outside the 'starfield' folder live) and removes dependency to obsolete OGlProgram.h --- interface/src/starfield/Config.h | 2 +- interface/src/starfield/renderer/Renderer.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/interface/src/starfield/Config.h b/interface/src/starfield/Config.h index 92d4a05723..c11fe68e38 100644 --- a/interface/src/starfield/Config.h +++ b/interface/src/starfield/Config.h @@ -38,7 +38,7 @@ // #include "InterfaceConfig.h" -#include "OGlProgram.h" +#include "renderer/ProgramObject.h" #include "Log.h" #include diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index 8a7e4bd6de..b30a174d4f 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -13,8 +13,6 @@ #error "This is an implementation file - not intended for direct inclusion." #endif -#include "renderer/ProgramObject.h" - #include "starfield/Config.h" #include "starfield/data/InputVertex.h" #include "starfield/data/BrightnessLevel.h" From 9765ce7b9c57ba32cb052770fa8b9a4edd8a8ed5 Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 15 May 2013 14:25:40 +0200 Subject: [PATCH 02/17] removes obsolete OGlProgram.h, moves utility macro for logging gl errors to Log.h --- interface/src/Log.h | 19 ++++- interface/src/OGlProgram.h | 146 ------------------------------------- 2 files changed, 18 insertions(+), 147 deletions(-) delete mode 100644 interface/src/OGlProgram.h diff --git a/interface/src/Log.h b/interface/src/Log.h index 30f9098bc9..beaca0abf0 100644 --- a/interface/src/Log.h +++ b/interface/src/Log.h @@ -21,12 +21,29 @@ class Log; // int printLog(char const* fmt, ...); +// +// Macro to log OpenGl errors. +// Example: oglLog( glPushMatrix() ); +// +#define oGlLog(stmt) \ + stmt; \ + { \ + GLenum e = glGetError(); \ + if (e != GL_NO_ERROR) { \ + printLog(__FILE__ ":" oGlLog_stringize(__LINE__) \ + " [OpenGL] %s\n", gluErrorString(e)); \ + } \ + } \ + (void) 0 + +#define oGlLog_stringize(x) oGlLog_stringize_i(x) +#define oGlLog_stringize_i(x) # x + // // Global instance. // extern Log logger; - // // Logging subsystem. // diff --git a/interface/src/OGlProgram.h b/interface/src/OGlProgram.h deleted file mode 100644 index ac1ea019bd..0000000000 --- a/interface/src/OGlProgram.h +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef __interface__OpenGlSupport__ -#define __interface__OpenGlSupport__ - -#include "InterfaceConfig.h" -#include "Log.h" - -// -// Macro to log OpenGl errors. -// Example: oglLog( glPushMatrix() ); -// -#define oGlLog(stmt) \ - stmt; \ - { \ - GLenum e = glGetError(); \ - if (e != GL_NO_ERROR) { \ - printLog(__FILE__ ":" oGlLog_stringize(__LINE__) \ - " [OpenGL] %s\n", gluErrorString(e)); \ - } \ - } \ - (void) 0 - -#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. -// -class OGlProgram { - - GLuint _hndProg; - -public: - - OGlProgram() : _hndProg(0) { } - - ~OGlProgram() { if (_hndProg != 0u) { glDeleteProgram(_hndProg); } } - - // no copy/assign - OGlProgram(OGlProgram const&); // = delete; - OGlProgram& operator=(OGlProgram const&); // = delete; - -#if 0 // let's keep this commented, for now (C++11) - - OGlProgram(OGlProgram&& disposable) : _hndProg(disposable._hndProg) { - - disposable._hndProg = 0; - } - - OGlProgram& operator=(OGlProgram&& disposable) { - - GLuint tmp = _hndProg; - _hndProg = disposable._hndProg; - disposable._hndProg = tmp; - } -#endif - - // - // Activates the executable for rendering. - // Shaders must be added and linked before this will work. - // - void activate() const { - - if (_hndProg != 0u) { - - oGlLog( glUseProgram(_hndProg) ); - } - } - - // - // 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. - // - bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) { - - if (! _hndProg && !! glCreateProgram) { - - _hndProg = glCreateProgram(); - } - if (! _hndProg) { return false; } - - GLuint s = glCreateShader(type); - glShaderSource(s, nStrings, strings, 0l); - glCompileShader(s); - GLint status; - glGetShaderiv(s, GL_COMPILE_STATUS, & status); - if (status != 0) - glAttachShader(_hndProg, s); -#ifdef NDEBUG // always fetch log in debug mode - else -#endif - fetchLog(s, glGetShaderiv, glGetShaderInfoLog); - glDeleteShader(s); - return !! status; - } - - // - // Links the program and logs to stderr. - // - bool link() { - - if (! _hndProg) { return false; } - - glLinkProgram(_hndProg); - GLint status; - glGetProgramiv(_hndProg, GL_LINK_STATUS, & status); -#ifndef NDEBUG // always fetch log in debug mode - fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog); -#endif - if (status == 0) { -#ifdef NDEBUG // only on error in release mode - fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog); -#endif - glDeleteProgram(_hndProg); - _hndProg = 0u; - return false; - - } else { - - return true; - } - } - -private: - - template< typename ParamFunc, typename GetLogFunc > - void fetchLog(GLint handle, ParamFunc getParam, GetLogFunc getLog) { - GLint logLength = 0; - getParam(handle, GL_INFO_LOG_LENGTH, &logLength); - if (!! logLength) { - GLchar* message = new GLchar[logLength]; - getLog(handle, logLength, 0l, message); - printLog("%s\n", message); - delete[] message; - } - } -}; - -#endif From 6a47db91dad8caa1a4c4a12118fa4be95f830148 Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 15 May 2013 15:29:02 +0200 Subject: [PATCH 03/17] tidies up UrlReader component --- libraries/shared/src/UrlReader.cpp | 154 +++++++++++++++++++---------- libraries/shared/src/UrlReader.h | 49 +++++---- 2 files changed, 129 insertions(+), 74 deletions(-) diff --git a/libraries/shared/src/UrlReader.cpp b/libraries/shared/src/UrlReader.cpp index 8814de899a..e069c0cb73 100644 --- a/libraries/shared/src/UrlReader.cpp +++ b/libraries/shared/src/UrlReader.cpp @@ -10,62 +10,83 @@ #include -#ifdef _WIN32 -#define NOCURL_IN_WINDOWS -#endif - #include #include -#ifndef NOCURL_IN_WINDOWS -#include -size_t const UrlReader::max_read_ahead = CURL_MAX_WRITE_SIZE; -#else -size_t const UrlReader::max_read_ahead = 0; -#endif +#include "shared_Log.h" +using shared_lib::printLog; -char const* const UrlReader::success = "UrlReader: Success!"; -char const* const UrlReader::success_cached = "UrlReader:: Using local file."; +#ifndef _WIN32 +// (Windows port is incomplete and the build files do not support CURL, yet) + +#include + + +// +// ATTENTION: A certain part of the implementation lives in inlined code +// (see the bottom of the header file). +// +// Why? Because it allows stream parsing without having to call around a +// lot (one static and one dynamic call per character if the parser just +// reads one character at a time). +// +// Here is an overview of the code structure: +// +// readUrl +// -> transferBegin (sets up state) +// -> perform (starts CURL transfer) +// -> (specialized, type-erased) callback_template +// -> getInfo (fetches HTTP header, eventually initiates caching) +// -> stream.begin (client code - called once) +// -> feedBuffered (the buffering logic) +// -> stream.transfer (client code - called repeatedly) +// -> stream.end (client code - called when the transfer is done) +// -> transferEnd (closes cache file, if used) +// +// "->" means "calls or inlines", here +// + +size_t const UrlReader::max_read_ahead = CURL_MAX_WRITE_SIZE; + +char const* const UrlReader::success = "UrlReader: Success!"; +char const* const UrlReader::success_cached = "UrlReader: Using local file."; char const* const UrlReader::error_init_failed = "UrlReader: Initialization failed."; char const* const UrlReader::error_aborted = "UrlReader: Processing error."; char const* const UrlReader::error_buffer_overflow = "UrlReader: Buffer overflow."; char const* const UrlReader::error_leftover_input = "UrlReader: Incomplete processing."; -#define hnd_curl static_cast(_ptrImpl) +#define _ptrCurl static_cast(_hndCurl) UrlReader::UrlReader() - : _ptrImpl(0l), _arrXtra(0l), _strError(0l), _arrCacheRdBuf(0l) { + : _hndCurl(0l), _arrXtra(0l), _strError(0l), _arrCacheRdBuf(0l) { _arrXtra = new(std::nothrow) char[max_read_ahead]; if (! _arrXtra) { _strError = error_init_failed; return; } -#ifndef NOCURL_IN_WINDOWS - _ptrImpl = curl_easy_init(); - if (! _ptrImpl) { _strError = error_init_failed; return; } - curl_easy_setopt(hnd_curl, CURLOPT_NOSIGNAL, 1l); - curl_easy_setopt(hnd_curl, CURLOPT_FAILONERROR, 1l); - curl_easy_setopt(hnd_curl, CURLOPT_FILETIME, 1l); - curl_easy_setopt(hnd_curl, CURLOPT_ENCODING, ""); -#endif + _hndCurl = curl_easy_init(); + if (! _hndCurl) { _strError = error_init_failed; return; } + curl_easy_setopt(_ptrCurl, CURLOPT_NOSIGNAL, 1l); + curl_easy_setopt(_ptrCurl, CURLOPT_FAILONERROR, 1l); + curl_easy_setopt(_ptrCurl, CURLOPT_FILETIME, 1l); + curl_easy_setopt(_ptrCurl, CURLOPT_ENCODING, ""); } UrlReader::~UrlReader() { delete[] _arrXtra; delete[] _arrCacheRdBuf; -#ifndef NOCURL_IN_WINDOWS - if (! hnd_curl) return; - curl_easy_cleanup(hnd_curl); -#endif + if (! _hndCurl) { + return; + } + curl_easy_cleanup(_ptrCurl); } -bool UrlReader::perform(char const* url, transfer_callback* cb) { -#ifndef NOCURL_IN_WINDOWS +void UrlReader::perform(char const* url, transfer_callback* cb) { - curl_easy_setopt(hnd_curl, CURLOPT_URL, url); - curl_easy_setopt(hnd_curl, CURLOPT_WRITEFUNCTION, cb); - curl_easy_setopt(hnd_curl, CURLOPT_WRITEDATA, this); + curl_easy_setopt(_ptrCurl, CURLOPT_URL, url); + curl_easy_setopt(_ptrCurl, CURLOPT_WRITEFUNCTION, cb); + curl_easy_setopt(_ptrCurl, CURLOPT_WRITEDATA, this); - CURLcode rc = curl_easy_perform(hnd_curl); + CURLcode rc = curl_easy_perform(_ptrCurl); if (rc == CURLE_OK) { @@ -74,20 +95,33 @@ bool UrlReader::perform(char const* url, transfer_callback* cb) { } else if (_strError == success) _strError = curl_easy_strerror(rc); - - return rc == CURLE_OK; -#else - return false; -#endif } -void UrlReader::getinfo(char const*& url, - char const*& type, int64_t& length, int64_t& stardate) { -#ifndef NOCURL_IN_WINDOWS +void UrlReader::transferBegin(void* stream, char const* cacheFile) { + _strError = success; + _ptrStream = stream; + _strCacheFile = cacheFile; + _ptrCacheFile = 0l; + _valCacheMode = no_cache; + _valXtraSize = ~size_t(0); +} + +void UrlReader::getInfo(char const*& url, + char const*& type, int64_t& length, int64_t& stardate) { + + // fetch information from HTTP header double clen; long time; - curl_easy_getinfo(hnd_curl, CURLINFO_FILETIME, & time); + curl_easy_getinfo(_ptrCurl, CURLINFO_FILETIME, & time); + curl_easy_getinfo(_ptrCurl, CURLINFO_EFFECTIVE_URL, & url); + curl_easy_getinfo(_ptrCurl, CURLINFO_CONTENT_TYPE, & type); + curl_easy_getinfo(_ptrCurl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, & clen); + length = static_cast(clen); + curl_easy_getinfo(_ptrCurl, CURLINFO_FILETIME, & time); + stardate = time; + + printLog("UrlReader: Ready to transfer from URL '%s'\n", url); // check caching file time whether we actually want to download anything if (_strCacheFile != 0l) { @@ -96,7 +130,7 @@ void UrlReader::getinfo(char const*& url, if (time > s.st_mtime) { // file on server is newer -> update cache file _ptrCacheFile = fopen(_strCacheFile, "wb"); - printf("From URL: "); + printLog("UrlReader: Also writing content to cache file '%s'\n", _strCacheFile); if (_ptrCacheFile != 0l) { _valCacheMode = cache_write; } @@ -105,26 +139,38 @@ void UrlReader::getinfo(char const*& url, if (! _arrCacheRdBuf) { _arrCacheRdBuf = new (std::nothrow) char[max_read_ahead]; if (! _arrCacheRdBuf) { - _valCacheMode = no_cache; + // out of memory, no caching, have CURL catch it + return; } } _ptrCacheFile = fopen(_strCacheFile, "rb"); - printf("From file: "); + printLog("UrlReader: Delivering cached content from file '%s'\n", _strCacheFile); if (_ptrCacheFile != 0l) { _valCacheMode = cache_read; } + // override error code returned by CURL when we abort the download _strError = success_cached; } } - - curl_easy_getinfo(hnd_curl, CURLINFO_EFFECTIVE_URL, & url); - curl_easy_getinfo(hnd_curl, CURLINFO_CONTENT_TYPE, & type); - - curl_easy_getinfo(hnd_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, & clen); - length = static_cast(clen); - - curl_easy_getinfo(hnd_curl, CURLINFO_FILETIME, & time); - stardate = time; -#endif } +void UrlReader::transferEnd() { + + if (_ptrCacheFile != 0l) { + fclose(_ptrCacheFile); + } +} + +#else // no-op version for incomplete Windows build: + +UrlReader::UrlReader() : _ptrImpl(0l) { } +UrlReader::~UrlReader() { } +void UrlReader::perform(char const* url, transfer_callback* cb) { } +void UrlReader::transferBegin(void* stream, char const* cacheFile) { } +void UrlReader::getInfo(char const*& url, char const*& type, + int64_t& length, int64_t& stardate) { } +void UrlReader::transferEnd() { } + +#endif + + diff --git a/libraries/shared/src/UrlReader.h b/libraries/shared/src/UrlReader.h index 9ad77d27ff..ebd11a21ab 100644 --- a/libraries/shared/src/UrlReader.h +++ b/libraries/shared/src/UrlReader.h @@ -22,7 +22,7 @@ class UrlReader { enum CacheMode { no_cache, cache_write, cache_read }; - void* _ptrImpl; + void* _hndCurl; char* _arrXtra; char const* _strError; void* _ptrStream; @@ -145,13 +145,18 @@ class UrlReader { UrlReader(UrlReader const&); // = delete; UrlReader& operator=(UrlReader const&); // = delete; + inline bool isSuccess(); + // entrypoints to compiled code typedef size_t transfer_callback(char*, size_t, size_t, void*); - bool perform(char const* url, transfer_callback* transfer); + void transferBegin(void* stream, char const* cacheFile); + void transferEnd(); - void getinfo(char const*& url, + void perform(char const* url, transfer_callback* transfer); + + void getInfo(char const*& url, char const*& type, int64_t& length, int64_t& stardate); // synthesized callback @@ -163,33 +168,37 @@ class UrlReader { char* input, size_t size); }; -template< class ContentStream > -bool UrlReader::readUrl(char const* url, ContentStream& s, char const* cacheFile) { - if (! _ptrImpl) return false; - _strCacheFile = cacheFile; - _ptrCacheFile = 0l; - _valCacheMode = no_cache; // eventually set later - _strError = success; - _ptrStream = & s; - _valXtraSize = ~size_t(0); - this->perform(url, & callback_template); - s.end(_strError == success); - if (_ptrCacheFile != 0l) { - fclose(_ptrCacheFile); - } +inline char const* UrlReader::getError() const { + + return _strError; +} + +bool UrlReader::isSuccess() { + return _strError == success || _strError == success_cached; } -inline char const* UrlReader::getError() const { return this->_strError; } +template< class ContentStream > +bool UrlReader::readUrl(char const* url, ContentStream& s, char const* cacheFile) { + if (! _hndCurl) return false; + + this->transferBegin(& s, cacheFile); + this->perform(url, & callback_template); + this->transferEnd(); + bool ok = isSuccess(); + s.end(ok); + return ok; +} inline void UrlReader::setError(char const* staticCstring) { - if (this->_strError == success || this->_strError == success_cached) + if (this->isSuccess()) this->_strError = staticCstring; } template< class Stream > size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { + size_t inputOffset = 0u; while (true) { @@ -263,7 +272,7 @@ size_t UrlReader::callback_template(char *input, size_t size, size_t nmemb, void // extract meta information and call 'begin' char const* url, * type; int64_t length, stardate; - me->getinfo(url, type, length, stardate); + me->getInfo(url, type, length, stardate); if (me->_valCacheMode != cache_read) { stream->begin(url, type, length, stardate); } From 168bd24342070f08793d9c7eeffeb8d03085cceb Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 15 May 2013 16:16:53 +0200 Subject: [PATCH 04/17] comments out logging, after testing all is fine --- libraries/shared/src/UrlReader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/shared/src/UrlReader.cpp b/libraries/shared/src/UrlReader.cpp index e069c0cb73..66a72a8c8a 100644 --- a/libraries/shared/src/UrlReader.cpp +++ b/libraries/shared/src/UrlReader.cpp @@ -121,7 +121,7 @@ void UrlReader::getInfo(char const*& url, curl_easy_getinfo(_ptrCurl, CURLINFO_FILETIME, & time); stardate = time; - printLog("UrlReader: Ready to transfer from URL '%s'\n", url); +// printLog("UrlReader: Ready to transfer from URL '%s'\n", url); // check caching file time whether we actually want to download anything if (_strCacheFile != 0l) { @@ -130,7 +130,7 @@ void UrlReader::getInfo(char const*& url, if (time > s.st_mtime) { // file on server is newer -> update cache file _ptrCacheFile = fopen(_strCacheFile, "wb"); - printLog("UrlReader: Also writing content to cache file '%s'\n", _strCacheFile); +// printLog("UrlReader: Also writing content to cache file '%s'\n", _strCacheFile); if (_ptrCacheFile != 0l) { _valCacheMode = cache_write; } @@ -144,7 +144,7 @@ void UrlReader::getInfo(char const*& url, } } _ptrCacheFile = fopen(_strCacheFile, "rb"); - printLog("UrlReader: Delivering cached content from file '%s'\n", _strCacheFile); +// printLog("UrlReader: Delivering cached content from file '%s'\n", _strCacheFile); if (_ptrCacheFile != 0l) { _valCacheMode = cache_read; } From 989256aad068ddf6342a41b06f26ec83d47fefda Mon Sep 17 00:00:00 2001 From: tosh Date: Sat, 18 May 2013 13:33:01 +0200 Subject: [PATCH 05/17] clarifies some names --- interface/src/starfield/Controller.h | 10 +++++----- interface/src/starfield/renderer/Renderer.h | 18 +++++++++--------- interface/src/starfield/renderer/Tiling.h | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h index 93dc134392..3bbb7009a7 100644 --- a/interface/src/starfield/Controller.h +++ b/interface/src/starfield/Controller.h @@ -70,7 +70,7 @@ namespace starfield { double _valLodHighWaterMark; double _valLodOveralloc; size_t _valLodNalloc; - size_t _valLodNrender; + size_t _valLodNRender; BrightnessLevels _seqLodBrightness; #if STARFIELD_MULTITHREADING @@ -103,7 +103,7 @@ namespace starfield { _valLodHighWaterMark(1.0), _valLodOveralloc(1.2), _valLodNalloc(0), - _valLodNrender(0), + _valLodNRender(0), _valLodBrightness(0), _valLodAllocBrightness(0), _ptrRenderer(0l) { @@ -156,7 +156,7 @@ namespace starfield { // cannot allocate or render more than we have n = min(newLast, _valLodNalloc); - nRender = min(newLast, _valLodNrender); + nRender = min(newLast, _valLodNRender); } // determine new minimum brightness levels @@ -192,7 +192,7 @@ namespace starfield { _valLodHighWaterMark *= rcpChange; _valLodOveralloc *= rcpChange; _valLodNalloc = n; - _valLodNrender = nRender; + _valLodNRender = nRender; _valLodAllocBrightness = bMin; #if STARFIELD_MULTITHREADING _valLodBrightness.store(b, memory_order_relaxed); @@ -334,7 +334,7 @@ namespace starfield { { lock _(_mtxLodState); _valLodNalloc = n; - _valLodNrender = nRender; + _valLodNRender = nRender; _valLodFraction = fraction; _valLodLowWaterMark = fraction * (1.0 - realloc); diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index 415068ae35..cf7cee6234 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -71,13 +71,13 @@ namespace starfield { GLsizei* _arrBatchCount; GLuint _hndVertexArray; ProgramObject _objProgram; - int _alphaLocation; + int _alphaLocationHandle; Tiling _objTiling; unsigned* _itrOutIndex; - vec3 _vecWxform; - float _valHalfPersp; + vec3 _vecWRow; + float _valHalfPerspectiveAngle; BrightnessLevel _valMinBright; public: @@ -173,8 +173,8 @@ namespace starfield { matrix = glm::frustum(-hw,hw, -hh,hh, nearClip,10.0f) * glm::affineInverse(matrix); this->_itrOutIndex = (unsigned*) _arrBatchOffs; - this->_vecWxform = vec3(row(matrix, 3)); - this->_valHalfPersp = halfPersp; + this->_vecWRow = vec3(row(matrix, 3)); + this->_valHalfPerspectiveAngle = halfPersp; this->_valMinBright = minBright; TileSelection::Cursor cursor; @@ -397,11 +397,11 @@ namespace starfield { float gz = -cos(azimuth); float exz = cos(altitude); vec3 tileCenter = vec3(gx * exz, sin(altitude), gz * exz); - float w = dot(_vecWxform, tileCenter); + float w = dot(_vecWRow, tileCenter); float daz = halfSlice * cos(std::max(0.0f, abs(altitude) - halfSlice)); float dal = halfSlice; - float adjustedNear = cos(_valHalfPersp + sqrt(daz * daz + dal * dal)); + float adjustedNear = cos(_valHalfPerspectiveAngle + sqrt(daz * daz + dal * dal)); // printLog("Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip); @@ -484,7 +484,7 @@ namespace starfield { "}\n"; _objProgram.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); _objProgram.link(); - _alphaLocation = _objProgram.uniformLocation("alpha"); + _alphaLocationHandle = _objProgram.uniformLocation("alpha"); glGenBuffersARB(1, & _hndVertexArray); } @@ -532,7 +532,7 @@ namespace starfield { // select shader and vertex array _objProgram.bind(); - _objProgram.setUniformValue(_alphaLocation, alpha); + _objProgram.setUniformValue(_alphaLocationHandle, alpha); glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray); glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h index 56df23f30c..4737e318f9 100644 --- a/interface/src/starfield/renderer/Tiling.h +++ b/interface/src/starfield/renderer/Tiling.h @@ -21,19 +21,19 @@ namespace starfield { unsigned _valK; float _valRcpSlice; - unsigned _valBits; + unsigned _valNBits; public: Tiling(unsigned k) : _valK(k), _valRcpSlice(k / Radians::twicePi()) { - _valBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 + _valNBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 } unsigned getAzimuthalTiles() const { return _valK; } unsigned getAltitudinalTiles() const { return _valK / 2 + 1; } - unsigned getTileIndexBits() const { return _valBits; } + unsigned getTileIndexBits() const { return _valNBits; } unsigned getTileCount() const { return getAzimuthalTiles() * getAltitudinalTiles(); From 4f3f5e1abef6a04591083f59580e08c078b0f16b Mon Sep 17 00:00:00 2001 From: tosh Date: Sat, 18 May 2013 13:35:06 +0200 Subject: [PATCH 06/17] clarifies some names --- interface/src/Oscilloscope.cpp | 6 +++--- interface/src/Oscilloscope.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index 088ef6ac14..d4b6a103bb 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -35,7 +35,7 @@ namespace { // everything in here only exists while compiling this .cpp file Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : _valWidth(w), _valHeight(h), _arrSamples(0l), _arrVertices(0l), - _valLowpass(0.4f), _valDownsample(3), + _valLowpassFactor(0.4f), _valDownsampleFactor(3), enabled(isEnabled), inputPaused(false) { // allocate enough space for the sample data and to turn it into @@ -95,8 +95,8 @@ void Oscilloscope::render(int x, int y) { } // determine lowpass / downsample factors - int lowpass = -int(std::numeric_limits::min()) * _valLowpass; - unsigned downsample = _valDownsample; + int lowpass = -int(std::numeric_limits::min()) * _valLowpassFactor; + unsigned downsample = _valDownsampleFactor; // keep half of the buffer for writing and ensure an even vertex count unsigned usedWidth = min(_valWidth, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; unsigned usedSamples = usedWidth * downsample; diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index 8c0b727b6e..23a6632896 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -26,8 +26,8 @@ public: volatile bool enabled; volatile bool inputPaused; - void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _valLowpass = w; } - void setDownsampling(unsigned f) { assert(f > 0); _valDownsample = f; } + void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _valLowpassFactor = w; } + void setDownsampling(unsigned f) { assert(f > 0); _valDownsampleFactor = f; } private: // don't copy/assign @@ -42,8 +42,8 @@ private: short* _arrVertices; unsigned _arrWritePos[MAX_CHANNELS]; - float _valLowpass; - unsigned _valDownsample; + float _valLowpassFactor; + unsigned _valDownsampleFactor; }; #endif /* defined(__interface__oscilloscope__) */ From fc2de0685b4d6a217259bcf4a693732bd58496ba Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 12:48:17 +0200 Subject: [PATCH 07/17] adjusts naming and formatting of class definition --- libraries/shared/src/UrlReader.cpp | 98 +++++----- libraries/shared/src/UrlReader.h | 298 +++++++++++++++-------------- 2 files changed, 200 insertions(+), 196 deletions(-) diff --git a/libraries/shared/src/UrlReader.cpp b/libraries/shared/src/UrlReader.cpp index 66a72a8c8a..2e641b5a64 100644 --- a/libraries/shared/src/UrlReader.cpp +++ b/libraries/shared/src/UrlReader.cpp @@ -55,56 +55,56 @@ char const* const UrlReader::error_aborted = "UrlReader: Processing err char const* const UrlReader::error_buffer_overflow = "UrlReader: Buffer overflow."; char const* const UrlReader::error_leftover_input = "UrlReader: Incomplete processing."; -#define _ptrCurl static_cast(_hndCurl) +#define _curlPtr static_cast(_curlHandle) UrlReader::UrlReader() - : _hndCurl(0l), _arrXtra(0l), _strError(0l), _arrCacheRdBuf(0l) { + : _curlHandle(0l), _xtraArray(0l), _errorStr(0l), _cacheRdBufArray(0l) { - _arrXtra = new(std::nothrow) char[max_read_ahead]; - if (! _arrXtra) { _strError = error_init_failed; return; } - _hndCurl = curl_easy_init(); - if (! _hndCurl) { _strError = error_init_failed; return; } - curl_easy_setopt(_ptrCurl, CURLOPT_NOSIGNAL, 1l); - curl_easy_setopt(_ptrCurl, CURLOPT_FAILONERROR, 1l); - curl_easy_setopt(_ptrCurl, CURLOPT_FILETIME, 1l); - curl_easy_setopt(_ptrCurl, CURLOPT_ENCODING, ""); + _xtraArray = new(std::nothrow) char[max_read_ahead]; + if (! _xtraArray) { _errorStr = error_init_failed; return; } + _curlHandle = curl_easy_init(); + if (! _curlHandle) { _errorStr = error_init_failed; return; } + curl_easy_setopt(_curlPtr, CURLOPT_NOSIGNAL, 1l); + curl_easy_setopt(_curlPtr, CURLOPT_FAILONERROR, 1l); + curl_easy_setopt(_curlPtr, CURLOPT_FILETIME, 1l); + curl_easy_setopt(_curlPtr, CURLOPT_ENCODING, ""); } UrlReader::~UrlReader() { - delete[] _arrXtra; - delete[] _arrCacheRdBuf; - if (! _hndCurl) { + delete[] _xtraArray; + delete[] _cacheRdBufArray; + if (! _curlHandle) { return; } - curl_easy_cleanup(_ptrCurl); + curl_easy_cleanup(_curlPtr); } void UrlReader::perform(char const* url, transfer_callback* cb) { - curl_easy_setopt(_ptrCurl, CURLOPT_URL, url); - curl_easy_setopt(_ptrCurl, CURLOPT_WRITEFUNCTION, cb); - curl_easy_setopt(_ptrCurl, CURLOPT_WRITEDATA, this); + curl_easy_setopt(_curlPtr, CURLOPT_URL, url); + curl_easy_setopt(_curlPtr, CURLOPT_WRITEFUNCTION, cb); + curl_easy_setopt(_curlPtr, CURLOPT_WRITEDATA, this); - CURLcode rc = curl_easy_perform(_ptrCurl); + CURLcode rc = curl_easy_perform(_curlPtr); if (rc == CURLE_OK) { - while (_valXtraSize > 0 && _strError == success) + while (_xtraSize > 0 && _errorStr == success) cb(0l, 0, 0, this); } - else if (_strError == success) - _strError = curl_easy_strerror(rc); + else if (_errorStr == success) + _errorStr = curl_easy_strerror(rc); } void UrlReader::transferBegin(void* stream, char const* cacheFile) { - _strError = success; - _ptrStream = stream; - _strCacheFile = cacheFile; - _ptrCacheFile = 0l; - _valCacheMode = no_cache; - _valXtraSize = ~size_t(0); + _errorStr = success; + _streamPtr = stream; + _cacheFileStr = cacheFile; + _cacheFilePtr = 0l; + _cacheMode = no_cache; + _xtraSize = ~size_t(0); } void UrlReader::getInfo(char const*& url, @@ -113,57 +113,57 @@ void UrlReader::getInfo(char const*& url, // fetch information from HTTP header double clen; long time; - curl_easy_getinfo(_ptrCurl, CURLINFO_FILETIME, & time); - curl_easy_getinfo(_ptrCurl, CURLINFO_EFFECTIVE_URL, & url); - curl_easy_getinfo(_ptrCurl, CURLINFO_CONTENT_TYPE, & type); - curl_easy_getinfo(_ptrCurl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, & clen); + curl_easy_getinfo(_curlPtr, CURLINFO_FILETIME, & time); + curl_easy_getinfo(_curlPtr, CURLINFO_EFFECTIVE_URL, & url); + curl_easy_getinfo(_curlPtr, CURLINFO_CONTENT_TYPE, & type); + curl_easy_getinfo(_curlPtr, CURLINFO_CONTENT_LENGTH_DOWNLOAD, & clen); length = static_cast(clen); - curl_easy_getinfo(_ptrCurl, CURLINFO_FILETIME, & time); + curl_easy_getinfo(_curlPtr, CURLINFO_FILETIME, & time); stardate = time; // printLog("UrlReader: Ready to transfer from URL '%s'\n", url); // check caching file time whether we actually want to download anything - if (_strCacheFile != 0l) { + if (_cacheFileStr != 0l) { struct stat s; - stat(_strCacheFile, & s); + stat(_cacheFileStr, & s); if (time > s.st_mtime) { // file on server is newer -> update cache file - _ptrCacheFile = fopen(_strCacheFile, "wb"); -// printLog("UrlReader: Also writing content to cache file '%s'\n", _strCacheFile); - if (_ptrCacheFile != 0l) { - _valCacheMode = cache_write; + _cacheFilePtr = fopen(_cacheFileStr, "wb"); +// printLog("UrlReader: Also writing content to cache file '%s'\n", _cacheFileStr); + if (_cacheFilePtr != 0l) { + _cacheMode = cache_write; } } else { // file on server is older -> use cache file - if (! _arrCacheRdBuf) { - _arrCacheRdBuf = new (std::nothrow) char[max_read_ahead]; - if (! _arrCacheRdBuf) { + if (! _cacheRdBufArray) { + _cacheRdBufArray = new (std::nothrow) char[max_read_ahead]; + if (! _cacheRdBufArray) { // out of memory, no caching, have CURL catch it return; } } - _ptrCacheFile = fopen(_strCacheFile, "rb"); -// printLog("UrlReader: Delivering cached content from file '%s'\n", _strCacheFile); - if (_ptrCacheFile != 0l) { - _valCacheMode = cache_read; + _cacheFilePtr = fopen(_cacheFileStr, "rb"); +// printLog("UrlReader: Delivering cached content from file '%s'\n", _cacheFileStr); + if (_cacheFilePtr != 0l) { + _cacheMode = cache_read; } // override error code returned by CURL when we abort the download - _strError = success_cached; + _errorStr = success_cached; } } } void UrlReader::transferEnd() { - if (_ptrCacheFile != 0l) { - fclose(_ptrCacheFile); + if (_cacheFilePtr != 0l) { + fclose(_cacheFilePtr); } } #else // no-op version for incomplete Windows build: -UrlReader::UrlReader() : _ptrImpl(0l) { } +UrlReader::UrlReader() : _curlHandle(0l) { } UrlReader::~UrlReader() { } void UrlReader::perform(char const* url, transfer_callback* cb) { } void UrlReader::transferBegin(void* stream, char const* cacheFile) { } diff --git a/libraries/shared/src/UrlReader.h b/libraries/shared/src/UrlReader.h index ebd11a21ab..9e70555184 100644 --- a/libraries/shared/src/UrlReader.h +++ b/libraries/shared/src/UrlReader.h @@ -19,168 +19,172 @@ // via URLs. Use one per thread. // class UrlReader { +public: - enum CacheMode { no_cache, cache_write, cache_read }; + // + // Constructor - performs initialization, never throws. + // + UrlReader(); - void* _hndCurl; - char* _arrXtra; - char const* _strError; - void* _ptrStream; - char const* _strCacheFile; - FILE* _ptrCacheFile; - char* _arrCacheRdBuf; - CacheMode _valCacheMode; - size_t _valXtraSize; - public: + // + // Destructor - frees resources, never throws. + // + ~UrlReader(); - // - // Constructor - performs initialization, never throws. - // - UrlReader(); + // + // Reads data from an URL and forwards it to the instance of a class + // fulfilling the ContentStream concept. + // + // The call protocol on the ContentStream is detailed as follows: + // + // 1. begin(char const* url, + // char const* content_type, uint64_t bytes, uint64_t stardate) + // + // All information except 'url' is optional; 'content_type' can + // be a null pointer - 'bytes' and 'stardate' can be equal to + // to 'unavailable'. + // + // 2. transfer(char* buffer, size_t bytes) + // + // Called until all data has been received. The number of bytes + // actually processed should be returned. + // Unprocessed data is stored in an extra buffer whose size is + // given by the constant UrlReader::max_read_ahead - it can be + // assumed to be reasonably large for on-the-fly parsing. + // + // 3. end(bool ok) + // + // Called at the end of the transfer. + // + // Returns the same success code + // + template< class ContentStream > + bool readUrl(char const* url, ContentStream& s, char const* cacheFile = 0l); - // - // Destructor - frees resources, never throws. - // - ~UrlReader(); + // + // Returns a pointer to a static C-string that describes the error + // condition. + // + inline char const* getError() const; - // - // Reads data from an URL and forwards it to the instance of a class - // fulfilling the ContentStream concept. - // - // The call protocol on the ContentStream is detailed as follows: - // - // 1. begin(char const* url, - // char const* content_type, uint64_t bytes, uint64_t stardate) - // - // All information except 'url' is optional; 'content_type' can - // be a null pointer - 'bytes' and 'stardate' can be equal to - // to 'unavailable'. - // - // 2. transfer(char* buffer, size_t bytes) - // - // Called until all data has been received. The number of bytes - // actually processed should be returned. - // Unprocessed data is stored in an extra buffer whose size is - // given by the constant UrlReader::max_read_ahead - it can be - // assumed to be reasonably large for on-the-fly parsing. - // - // 3. end(bool ok) - // - // Called at the end of the transfer. - // - // Returns the same success code - // - template< class ContentStream > - bool readUrl(char const* url, ContentStream& s, char const* cacheFile = 0l); + // + // Can be called by the stream to set a user-defined error string. + // + inline void setError(char const* static_c_string); - // - // Returns a pointer to a static C-string that describes the error - // condition. - // - inline char const* getError() const; + // + // Pointer to the C-string returned by a call to 'readUrl' when no + // error occurred. + // + static char const* const success; - // - // Can be called by the stream to set a user-defined error string. - // - inline void setError(char const* static_c_string); + // + // Pointer to the C-string returned by a call to 'readUrl' when no + // error occurred and a local file has been read instead of the + // network stream. + // + static char const* const success_cached; - // - // Pointer to the C-string returned by a call to 'readUrl' when no - // error occurred. - // - static char const* const success; + // + // Pointer to the C-string returned by a call to 'readUrl' when the + // initialization has failed. + // + static char const* const error_init_failed; - // - // Pointer to the C-string returned by a call to 'readUrl' when no - // error occurred and a local file has been read instead of the - // network stream. - // - static char const* const success_cached; - - // - // Pointer to the C-string returned by a call to 'readUrl' when the - // initialization has failed. - // - static char const* const error_init_failed; + // + // Pointer to the C-string returned by a call to 'readUrl' when the + // transfer has been aborted by the client. + // + static char const* const error_aborted; - // - // Pointer to the C-string returned by a call to 'readUrl' when the - // transfer has been aborted by the client. - // - static char const* const error_aborted; + // + // Pointer to the C-string returned by a call to 'readUrl' when + // leftover input from incomplete processing caused a buffer + // overflow. + // + static char const* const error_buffer_overflow; - // - // Pointer to the C-string returned by a call to 'readUrl' when - // leftover input from incomplete processing caused a buffer - // overflow. - // - static char const* const error_buffer_overflow; + // + // Pointer to the C-string return by a call to 'readUrl' when the + // input provided was not completely consumed. + // + static char const* const error_leftover_input; - // - // Pointer to the C-string return by a call to 'readUrl' when the - // input provided was not completely consumed. - // - static char const* const error_leftover_input; + // + // Constant of the maximum number of bytes that are buffered + // between invocations of 'transfer'. + // + static size_t const max_read_ahead; - // - // Constant of the maximum number of bytes that are buffered - // between invocations of 'transfer'. - // - static size_t const max_read_ahead; + // + // Constant representing absent information in the call to the + // 'begin' member function of the target stream. + // + static int const unavailable = -1; - // - // Constant representing absent information in the call to the - // 'begin' member function of the target stream. - // - static int const unavailable = -1; + // + // Constant for requesting to abort the current transfer when + // returned by the 'transfer' member function of the target stream. + // + static size_t const abort = ~0u; - // - // Constant for requesting to abort the current transfer when - // returned by the 'transfer' member function of the target stream. - // - static size_t const abort = ~0u; +private: + // instances of this class shall not be copied + UrlReader(UrlReader const&); // = delete; + UrlReader& operator=(UrlReader const&); // = delete; - private: - // instances of this class shall not be copied - UrlReader(UrlReader const&); // = delete; - UrlReader& operator=(UrlReader const&); // = delete; + inline bool isSuccess(); - inline bool isSuccess(); + // entrypoints to compiled code - // entrypoints to compiled code + typedef size_t transfer_callback(char*, size_t, size_t, void*); - typedef size_t transfer_callback(char*, size_t, size_t, void*); + enum CacheMode { no_cache, cache_write, cache_read }; - void transferBegin(void* stream, char const* cacheFile); - void transferEnd(); + void transferBegin(void* stream, char const* cacheFile); + void transferEnd(); - void perform(char const* url, transfer_callback* transfer); + void perform(char const* url, transfer_callback* transfer); - void getInfo(char const*& url, - char const*& type, int64_t& length, int64_t& stardate); + void getInfo(char const*& url, + char const*& type, int64_t& length, int64_t& stardate); - // synthesized callback + // synthesized callback - template< class Stream > static size_t callback_template(char *input, size_t size, - size_t nmemb, void* thiz); + template< class Stream > static size_t callback_template(char *input, size_t size, + size_t nmemb, void* thiz); - template< class Stream > size_t feedBuffered(Stream* stream, - char* input, size_t size); + template< class Stream > size_t feedBuffered(Stream* stream, + char* input, size_t size); + + // state + + void* _curlHandle; + char* _xtraArray; + char const* _errorStr; + void* _streamPtr; + char const* _cacheFileStr; + FILE* _cacheFilePtr; + char* _cacheRdBufArray; + CacheMode _cacheMode; + size_t _xtraSize; }; +// inline functions + inline char const* UrlReader::getError() const { - return _strError; + return _errorStr; } bool UrlReader::isSuccess() { - return _strError == success || _strError == success_cached; + return _errorStr == success || _errorStr == success_cached; } template< class ContentStream > bool UrlReader::readUrl(char const* url, ContentStream& s, char const* cacheFile) { - if (! _hndCurl) return false; + if (! _curlHandle) return false; this->transferBegin(& s, cacheFile); this->perform(url, & callback_template); @@ -193,7 +197,7 @@ bool UrlReader::readUrl(char const* url, ContentStream& s, char const* cacheFile inline void UrlReader::setError(char const* staticCstring) { if (this->isSuccess()) - this->_strError = staticCstring; + this->_errorStr = staticCstring; } template< class Stream > @@ -207,15 +211,15 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { size_t bytes = size - inputOffset; // data in extra buffer? - if (_valXtraSize > 0) { + if (_xtraSize > 0) { // fill extra buffer with beginning of input - size_t fill = max_read_ahead - _valXtraSize; + size_t fill = max_read_ahead - _xtraSize; if (bytes < fill) fill = bytes; - memcpy(_arrXtra + _valXtraSize, buffer, fill); + memcpy(_xtraArray + _xtraSize, buffer, fill); // use extra buffer for next transfer - buffer = _arrXtra; - bytes = _valXtraSize + fill; + buffer = _xtraArray; + bytes = _xtraSize + fill; inputOffset += fill; } @@ -234,9 +238,9 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { size_t unprocessed = bytes - processed; // can switch to input buffer, now? - if (buffer == _arrXtra && unprocessed <= inputOffset) { + if (buffer == _xtraArray && unprocessed <= inputOffset) { - _valXtraSize = 0u; + _xtraSize = 0u; inputOffset -= unprocessed; } else { // no? unprocessed data -> extra buffer @@ -246,10 +250,10 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { setError(error_buffer_overflow); return 0; } - _valXtraSize = unprocessed; - memmove(_arrXtra, buffer + processed, unprocessed); + _xtraSize = unprocessed; + memmove(_xtraArray, buffer + processed, unprocessed); - if (inputOffset == size || buffer != _arrXtra) { + if (inputOffset == size || buffer != _xtraArray) { return size; } @@ -262,18 +266,18 @@ size_t UrlReader::callback_template(char *input, size_t size, size_t nmemb, void size_t result = 0u; UrlReader* me = static_cast(thiz); - Stream* stream = static_cast(me->_ptrStream); + Stream* stream = static_cast(me->_streamPtr); size *= nmemb; // first call? - if (me->_valXtraSize == ~size_t(0)) { + if (me->_xtraSize == ~size_t(0)) { - me->_valXtraSize = 0u; + me->_xtraSize = 0u; // extract meta information and call 'begin' char const* url, * type; int64_t length, stardate; me->getInfo(url, type, length, stardate); - if (me->_valCacheMode != cache_read) { + if (me->_cacheMode != cache_read) { stream->begin(url, type, length, stardate); } } @@ -281,20 +285,20 @@ size_t UrlReader::callback_template(char *input, size_t size, size_t nmemb, void // will have to repeat from here when reading a local file // read from cache file? - if (me->_valCacheMode == cache_read) { + if (me->_cacheMode == cache_read) { // change input buffer and start - input = me->_arrCacheRdBuf; - size = fread(input, 1, max_read_ahead, me->_ptrCacheFile); + input = me->_cacheRdBufArray; + size = fread(input, 1, max_read_ahead, me->_cacheFilePtr); nmemb = 1; - } else if (me->_valCacheMode == cache_write) { - fwrite(input, 1, size, me->_ptrCacheFile); + } else if (me->_cacheMode == cache_write) { + fwrite(input, 1, size, me->_cacheFilePtr); } result = me->feedBuffered(stream, input, size); - } while (me->_valCacheMode == cache_read && result != 0 && ! feof(me->_ptrCacheFile)); + } while (me->_cacheMode == cache_read && result != 0 && ! feof(me->_cacheFilePtr)); - return me->_valCacheMode != cache_read ? result : 0; + return me->_cacheMode != cache_read ? result : 0; } #endif /* defined(__hifi__UrlReader__) */ From de665c2d48cfe4e2189d0150480f6d3513c8ab4e Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 13:01:57 +0200 Subject: [PATCH 08/17] adjusts names --- interface/src/Log.cpp | 160 +++++++-------- interface/src/Log.h | 34 ++-- interface/src/LogStream.h | 36 ++-- interface/src/Oscilloscope.cpp | 44 ++-- interface/src/Oscilloscope.h | 18 +- interface/src/Stars.cpp | 14 +- interface/src/Stars.h | 2 +- interface/src/starfield/Controller.h | 188 +++++++++--------- interface/src/starfield/Loader.h | 66 +++--- interface/src/starfield/data/GpuVertex.h | 6 +- interface/src/starfield/data/InputVertex.h | 18 +- interface/src/starfield/renderer/Renderer.h | 176 ++++++++-------- interface/src/starfield/renderer/Tiling.h | 14 +- .../src/starfield/renderer/VertexOrder.h | 6 +- 14 files changed, 391 insertions(+), 391 deletions(-) diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp index 9b57df1694..5b50074444 100644 --- a/interface/src/Log.cpp +++ b/interface/src/Log.cpp @@ -49,27 +49,27 @@ namespace { Log::Log(FILE* tPipeTo, unsigned bufferedLines, unsigned defaultLogWidth, unsigned defaultCharWidth, unsigned defaultCharHeight) : - _ptrStream(tPipeTo), - _arrChars(0l), - _arrLines(0l), - _valLogWidth(defaultLogWidth) { + _stream(tPipeTo), + _chars(0l), + _lines(0l), + _logWidth(defaultLogWidth) { - pthread_mutex_init(& _mtx, 0l); + pthread_mutex_init(& _mutex, 0l); // allocate twice as much (so we have spare space for a copy not to block // logging from other threads during 'render') - _arrChars = new char[CHARACTER_BUFFER_SIZE * 2]; - _ptrCharsEnd = _arrChars + CHARACTER_BUFFER_SIZE; - _arrLines = new char*[LINE_BUFFER_SIZE * 2]; - _ptrLinesEnd = _arrLines + LINE_BUFFER_SIZE; + _chars = new char[CHARACTER_BUFFER_SIZE * 2]; + _charsEnd = _chars + CHARACTER_BUFFER_SIZE; + _lines = new char*[LINE_BUFFER_SIZE * 2]; + _linesEnd = _lines + LINE_BUFFER_SIZE; // initialize the log to all empty lines - _arrChars[0] = '\0'; - _itrWritePos = _arrChars; - _itrWriteLineStart = _arrChars; - _itrLastLine = _arrLines; - _valWrittenInLine = 0; - memset(_arrLines, 0, LINE_BUFFER_SIZE * sizeof(char*)); + _chars[0] = '\0'; + _writePos = _chars; + _writeLineStartPos = _chars; + _lastLinePos = _lines; + _writtenInLine = 0; + memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); setCharacterSize(defaultCharWidth, defaultCharHeight); } @@ -77,8 +77,8 @@ Log::Log(FILE* tPipeTo, unsigned bufferedLines, Log::~Log() { - delete[] _arrChars; - delete[] _arrLines; + delete[] _chars; + delete[] _lines; } inline void Log::addMessage(char const* ptr) { @@ -86,8 +86,8 @@ inline void Log::addMessage(char const* ptr) { // precondition: mutex is locked so noone gets in our way // T-pipe, if requested - if (_ptrStream != 0l) { - fprintf(_ptrStream, "%s", ptr); + if (_stream != 0l) { + fprintf(_stream, "%s", ptr); } while (*ptr != '\0') { @@ -104,51 +104,51 @@ inline void Log::addMessage(char const* ptr) { // found LF -> write NUL (c == '\0' tells us to wrap, below) c = '\0'; } - *_itrWritePos++ = c; + *_writePos++ = c; - if (_itrWritePos == _ptrCharsEnd) { + if (_writePos == _charsEnd) { // reached the end of the circular character buffer? -> start over - _itrWritePos = _arrChars; + _writePos = _chars; } - if (++_valWrittenInLine >= _valLineLength || c == '\0') { + if (++_writtenInLine >= _lineLength || c == '\0') { // new line? store its start to the line buffer and mark next line as empty - ++_itrLastLine; + ++_lastLinePos; - if (_itrLastLine == _ptrLinesEnd) { - _itrLastLine = _arrLines; - _itrLastLine[1] = 0l; - } else if (_itrLastLine + 1 != _ptrLinesEnd) { - _itrLastLine[1] = 0l; + if (_lastLinePos == _linesEnd) { + _lastLinePos = _lines; + _lastLinePos[1] = 0l; + } else if (_lastLinePos + 1 != _linesEnd) { + _lastLinePos[1] = 0l; } else { - _arrLines[0] = 0l; + _lines[0] = 0l; } - *_itrLastLine = _itrWriteLineStart; + *_lastLinePos = _writeLineStartPos; // debug mode: make sure all line pointers we write here are valid - assert(! (_itrLastLine < _arrLines || _itrLastLine >= _ptrLinesEnd)); - assert(! (*_itrLastLine < _arrChars || *_itrLastLine >= _ptrCharsEnd)); + assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); + assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); // terminate line, unless done already if (c != '\0') { - *_itrWritePos++ = '\0'; + *_writePos++ = '\0'; - if (_itrWritePos == _ptrCharsEnd) { - _itrWritePos = _arrChars; + if (_writePos == _charsEnd) { + _writePos = _chars; } } // remember start position in character buffer for next line and reset character count - _itrWriteLineStart = _itrWritePos; - _valWrittenInLine = 0; + _writeLineStartPos = _writePos; + _writtenInLine = 0; } } } int Log::vprint(char const* fmt, va_list args) { - pthread_mutex_lock(& _mtx); + pthread_mutex_lock(& _mutex); // print to buffer char buf[MAX_MESSAGE_LENGTH]; @@ -161,11 +161,11 @@ int Log::vprint(char const* fmt, va_list args) { } else { // error? -> mutter on stream or stderr - fprintf(_ptrStream != 0l ? _ptrStream : stderr, + fprintf(_stream != 0l ? _stream : stderr, "Log: Failed to log message with format string = \"%s\".\n", fmt); } - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); return n; } @@ -179,22 +179,22 @@ void Log::operator()(char const* fmt, ...) { void Log::setLogWidth(unsigned pixels) { - pthread_mutex_lock(& _mtx); - _valLogWidth = pixels; - _valLineLength = _valLogWidth / _valCharWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_lock(& _mutex); + _logWidth = pixels; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); } void Log::setCharacterSize(unsigned width, unsigned height) { - pthread_mutex_lock(& _mtx); - _valCharWidth = width; - _valCharHeight = height; - _valCharYoffset = height * CHAR_FRACT_BASELINE; - _valCharScale = float(width) / CHAR_WIDTH; - _valCharAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT); - _valLineLength = _valLogWidth / _valCharWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_lock(& _mutex); + _charWidth = width; + _charHeight = height; + _charYoffset = height * CHAR_FRACT_BASELINE; + _charScale = float(width) / CHAR_WIDTH; + _charAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT); + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); } static TextRenderer* textRenderer() { @@ -206,17 +206,17 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { // rendering might take some time, so create a local copy of the portion we need // instead of having to hold the mutex all the time - pthread_mutex_lock(& _mtx); + pthread_mutex_lock(& _mutex); // determine number of visible lines - unsigned showLines = divRoundUp(screenHeight, _valCharHeight); + unsigned showLines = divRoundUp(screenHeight, _charHeight); - char** lastLine = _itrLastLine; - char** firstLine = _itrLastLine; + char** lastLine = _lastLinePos; + char** firstLine = _lastLinePos; if (! *lastLine) { // empty log - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); return; } @@ -225,8 +225,8 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { char** prevFirstLine = firstLine; --firstLine; - if (firstLine < _arrLines) { - firstLine = _ptrLinesEnd - 1; + if (firstLine < _lines) { + firstLine = _linesEnd - 1; } if (! *firstLine) { firstLine = prevFirstLine; @@ -235,37 +235,37 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { } // debug mode: make sure all line pointers we find here are valid - assert(! (firstLine < _arrLines || firstLine >= _ptrLinesEnd)); - assert(! (*firstLine < _arrChars || *firstLine >= _ptrCharsEnd)); + assert(! (firstLine < _lines || firstLine >= _linesEnd)); + assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); } - // copy the line buffer portion into a contiguous region at _ptrLinesEnd + // copy the line buffer portion into a contiguous region at _linesEnd if (firstLine <= lastLine) { - memcpy(_ptrLinesEnd, firstLine, showLines * sizeof(char*)); + memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); } else { - unsigned atEnd = _ptrLinesEnd - firstLine; - memcpy(_ptrLinesEnd, firstLine, atEnd * sizeof(char*)); - memcpy(_ptrLinesEnd + atEnd, _arrLines, (showLines - atEnd) * sizeof(char*)); + unsigned atEnd = _linesEnd - firstLine; + memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); + memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); } // copy relevant char buffer portion and determine information to remap the pointers char* firstChar = *firstLine; char* lastChar = *lastLine + strlen(*lastLine) + 1; - ptrdiff_t charOffset = _ptrCharsEnd - firstChar, charOffsetBeforeFirst = 0; + ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; if (firstChar <= lastChar) { - memcpy(_ptrCharsEnd, firstChar, lastChar - firstChar + 1); + memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); } else { - unsigned atEnd = _ptrCharsEnd - firstChar; - memcpy(_ptrCharsEnd, firstChar, atEnd); - memcpy(_ptrCharsEnd + atEnd, _arrChars, lastChar + 1 - _arrChars); + unsigned atEnd = _charsEnd - firstChar; + memcpy(_charsEnd, firstChar, atEnd); + memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); - charOffsetBeforeFirst = _ptrCharsEnd + atEnd - _arrChars; + charOffsetBeforeFirst = _charsEnd + atEnd - _chars; } // get values for rendering @@ -273,31 +273,31 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { int yStart = screenHeight - textRenderer()->metrics().descent(); // render text - char** line = _ptrLinesEnd + showLines; - int x = screenWidth - _valLogWidth; + char** line = _linesEnd + showLines; + int x = screenWidth - _logWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); // ok, we got all we need for (int y = yStart; y > 0; y -= yStep) { // debug mode: check line pointer is valid - assert(! (line < _ptrLinesEnd || line >= _ptrLinesEnd + (_ptrLinesEnd - _arrLines))); + assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); // get character pointer - if (--line < _ptrLinesEnd) { + if (--line < _linesEnd) { break; } char* chars = *line; // debug mode: check char pointer we find is valid - assert(! (chars < _arrChars || chars >= _ptrCharsEnd)); + assert(! (chars < _chars || chars >= _charsEnd)); // remap character pointer it to copied buffer chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; // debug mode: check char pointer is still valid (in new range) - assert(! (chars < _ptrCharsEnd || chars >= _ptrCharsEnd + (_ptrCharsEnd - _arrChars))); + assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); // render the string glColor3f(TEXT_RED, TEXT_GREEN, TEXT_BLUE); diff --git a/interface/src/Log.h b/interface/src/Log.h index beaca0abf0..17c693142c 100644 --- a/interface/src/Log.h +++ b/interface/src/Log.h @@ -48,26 +48,26 @@ extern Log logger; // Logging subsystem. // class Log { - FILE* _ptrStream; - char* _arrChars; - char* _ptrCharsEnd; - char** _arrLines; - char** _ptrLinesEnd; + FILE* _stream; + char* _chars; + char* _charsEnd; + char** _lines; + char** _linesEnd; - char* _itrWritePos; // character position to write to - char* _itrWriteLineStart; // character position where line being written starts - char** _itrLastLine; // last line in the log - unsigned _valWrittenInLine; // character counter for line wrapping - unsigned _valLineLength; // number of characters before line wrap + char* _writePos; // character position to write to + char* _writeLineStartPos; // character position where line being written starts + char** _lastLinePos; // last line in the log + unsigned _writtenInLine; // character counter for line wrapping + unsigned _lineLength; // number of characters before line wrap - unsigned _valLogWidth; // width of the log in pixels - unsigned _valCharWidth; // width of a character in pixels - unsigned _valCharHeight; // height of a character in pixels - unsigned _valCharYoffset; // baseline offset in pixels - float _valCharScale; // scale factor - float _valCharAspect; // aspect (h/w) + unsigned _logWidth; // width of the log in pixels + unsigned _charWidth; // width of a character in pixels + unsigned _charHeight; // height of a character in pixels + unsigned _charYoffset; // baseline offset in pixels + float _charScale; // scale factor + float _charAspect; // aspect (h/w) - pthread_mutex_t _mtx; + pthread_mutex_t _mutex; public: diff --git a/interface/src/LogStream.h b/interface/src/LogStream.h index 88e5d4fff0..2b8cc25669 100644 --- a/interface/src/LogStream.h +++ b/interface/src/LogStream.h @@ -26,9 +26,9 @@ // lOut << "Hello there!" << std::endl; // class LogStream { - std::ostringstream _objOutStream; - Log& _refLog; - bool _flgThreadSafe; + std::ostringstream _outStream; + Log& _logRef; + bool _isThreadSafe; public: inline LogStream(Log& log, bool threadSafe = false); @@ -46,26 +46,26 @@ private: }; inline LogStream::LogStream(Log& log, bool threadSafe) : - _objOutStream(std::ios_base::out), _refLog(log), _flgThreadSafe(threadSafe) { } + _outStream(std::ios_base::out), _logRef(log), _isThreadSafe(threadSafe) { } inline void LogStream::ostreamBegin() { - if (_flgThreadSafe) { + if (_isThreadSafe) { // the user wants to share this LogStream among threads, // so lock the global log here, already - pthread_mutex_lock(& _refLog._mtx); + pthread_mutex_lock(& _logRef._mutex); } - _objOutStream.str(""); + _outStream.str(""); } inline void LogStream::ostreamEnd() { - if (! _flgThreadSafe) { + if (! _isThreadSafe) { // haven't locked, so far (we have memory for each thread) - pthread_mutex_lock(& _refLog._mtx); + pthread_mutex_lock(& _logRef._mutex); } - _refLog.addMessage(_objOutStream.str().c_str()); - pthread_mutex_unlock(& _refLog._mtx); + _logRef.addMessage(_outStream.str().c_str()); + pthread_mutex_unlock(& _logRef._mutex); } @@ -73,22 +73,22 @@ inline void LogStream::ostreamEnd() { // The Log::StreamRef class makes operator<< work. It... // class LogStream::StreamRef { - mutable LogStream* _ptrLogStream; + mutable LogStream* _logStream; typedef std::ostream& (*manipulator)(std::ostream&); friend class LogStream; template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&); - StreamRef(LogStream* log) : _ptrLogStream(log) { } + StreamRef(LogStream* log) : _logStream(log) { } public: // ...forwards << operator calls to stringstream... - template< typename T > StreamRef const operator<<(T const& x) const { _ptrLogStream->_objOutStream << x; return *this; } + template< typename T > StreamRef const operator<<(T const& x) const { _logStream->_outStream << x; return *this; } // ...has to dance around to make manipulators (such as std::hex, std::endl) work... - StreamRef const operator<<(manipulator x) const { _ptrLogStream->_objOutStream << x; return *this; } + StreamRef const operator<<(manipulator x) const { _logStream->_outStream << x; return *this; } // ...informs the logger that a stream has ended when it has the responsibility... - ~StreamRef() { if (_ptrLogStream != 0l) { _ptrLogStream->ostreamEnd(); } } + ~StreamRef() { if (_logStream != 0l) { _logStream->ostreamEnd(); } } // ...which is passed on upon copy. - StreamRef(StreamRef const& other) : _ptrLogStream(other._ptrLogStream) { other._ptrLogStream = 0l; } + StreamRef(StreamRef const& other) : _logStream(other._logStream) { other._logStream = 0l; } private: // don't @@ -98,7 +98,7 @@ private: template< typename T > inline LogStream::StreamRef const operator<<(LogStream& s, T const& x) { s.ostreamBegin(); - s._objOutStream << x; + s._outStream << x; return LogStream::StreamRef(& s); // calls streamEnd at the end of the stream expression } diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index d4b6a103bb..e5f076c7b3 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -33,26 +33,26 @@ namespace { // everything in here only exists while compiling this .cpp file Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : - _valWidth(w), _valHeight(h), - _arrSamples(0l), _arrVertices(0l), - _valLowpassFactor(0.4f), _valDownsampleFactor(3), + _width(w), _height(h), + _samples(0l), _vertices(0l), + _lowpassFactor(0.4f), _downsampleFactor(3), enabled(isEnabled), inputPaused(false) { // allocate enough space for the sample data and to turn it into // vertices and since they're all 'short', do so in one shot - _arrSamples = new short[N_INT16_TO_ALLOC]; - memset(_arrSamples, 0, N_INT16_TO_ALLOC * sizeof(short)); - _arrVertices = _arrSamples + MAX_SAMPLES; + _samples = new short[N_INT16_TO_ALLOC]; + memset(_samples, 0, N_INT16_TO_ALLOC * sizeof(short)); + _vertices = _samples + MAX_SAMPLES; // initialize write positions to start of each channel's region for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { - _arrWritePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; + _writePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; } } Oscilloscope::~Oscilloscope() { - delete[] _arrSamples; + delete[] _samples; } void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { @@ -66,7 +66,7 @@ void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { unsigned endOffs = baseOffs + MAX_SAMPLES_PER_CHANNEL; // fetch write position for this channel - unsigned writePos = _arrWritePos[ch]; + unsigned writePos = _writePos[ch]; // determine write position after adding the samples unsigned newWritePos = writePos + n; @@ -79,13 +79,13 @@ void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { } // copy data - memcpy(_arrSamples + writePos, data, n * sizeof(short)); + memcpy(_samples + writePos, data, n * sizeof(short)); if (n2 > 0) { - memcpy(_arrSamples + baseOffs, data + n, n2 * sizeof(short)); + memcpy(_samples + baseOffs, data + n, n2 * sizeof(short)); } // set new write position for this channel - _arrWritePos[ch] = newWritePos; + _writePos[ch] = newWritePos; } void Oscilloscope::render(int x, int y) { @@ -95,19 +95,19 @@ void Oscilloscope::render(int x, int y) { } // determine lowpass / downsample factors - int lowpass = -int(std::numeric_limits::min()) * _valLowpassFactor; - unsigned downsample = _valDownsampleFactor; + int lowpass = -int(std::numeric_limits::min()) * _lowpassFactor; + unsigned downsample = _downsampleFactor; // keep half of the buffer for writing and ensure an even vertex count - unsigned usedWidth = min(_valWidth, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; + unsigned usedWidth = min(_width, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; unsigned usedSamples = usedWidth * downsample; // expand samples to vertex data for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { // for each channel: determine memory regions - short const* basePtr = _arrSamples + MAX_SAMPLES_PER_CHANNEL * ch; + short const* basePtr = _samples + MAX_SAMPLES_PER_CHANNEL * ch; short const* endPtr = basePtr + MAX_SAMPLES_PER_CHANNEL; - short const* inPtr = _arrSamples + _arrWritePos[ch]; - short* outPtr = _arrVertices + MAX_COORDS_PER_CHANNEL * ch; + short const* inPtr = _samples + _writePos[ch]; + short* outPtr = _vertices + MAX_COORDS_PER_CHANNEL * ch; int sample = 0, x = usedWidth; for (int i = int(usedSamples); --i >= 0 ;) { if (inPtr == basePtr) { @@ -124,13 +124,13 @@ void Oscilloscope::render(int x, int y) { } } - // set up rendering state (vertex data lives at _arrVertices) + // set up rendering state (vertex data lives at _vertices) glLineWidth(1.0); glDisable(GL_LINE_SMOOTH); glPushMatrix(); - glTranslatef((float)x + 0.0f, (float)y + _valHeight / 2.0f, 0.0f); - glScaled(1.0f, _valHeight / 32767.0f, 1.0f); - glVertexPointer(2, GL_SHORT, 0, _arrVertices); + glTranslatef((float)x + 0.0f, (float)y + _height / 2.0f, 0.0f); + glScaled(1.0f, _height / 32767.0f, 1.0f); + glVertexPointer(2, GL_SHORT, 0, _vertices); glEnableClientState(GL_VERTEX_ARRAY); // render channel 0 diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index 23a6632896..e13ecb1ce9 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -26,8 +26,8 @@ public: volatile bool enabled; volatile bool inputPaused; - void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _valLowpassFactor = w; } - void setDownsampling(unsigned f) { assert(f > 0); _valDownsampleFactor = f; } + void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _lowpassFactor = w; } + void setDownsampling(unsigned f) { assert(f > 0); _downsampleFactor = f; } private: // don't copy/assign @@ -36,14 +36,14 @@ private: // state variables - unsigned _valWidth; - unsigned _valHeight; - short* _arrSamples; - short* _arrVertices; - unsigned _arrWritePos[MAX_CHANNELS]; + unsigned _width; + unsigned _height; + short* _samples; + short* _vertices; + unsigned _writePos[MAX_CHANNELS]; - float _valLowpassFactor; - unsigned _valDownsampleFactor; + float _lowpassFactor; + unsigned _downsampleFactor; }; #endif /* defined(__interface__oscilloscope__) */ diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index e8e0222420..7934190e4c 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -14,24 +14,24 @@ #undef __interface__Starfield_impl__ Stars::Stars() : - _ptrController(0l) { - _ptrController = new starfield::Controller; + _controller(0l) { + _controller = new starfield::Controller; } Stars::~Stars() { - delete _ptrController; + delete _controller; } bool Stars::readInput(const char* url, const char* cacheFile, unsigned limit) { - return _ptrController->readInput(url, cacheFile, limit); + return _controller->readInput(url, cacheFile, limit); } bool Stars::setResolution(unsigned k) { - return _ptrController->setResolution(k); + return _controller->setResolution(k); } float Stars::changeLOD(float fraction, float overalloc, float realloc) { - return float(_ptrController->changeLOD(fraction, overalloc, realloc)); + return float(_controller->changeLOD(fraction, overalloc, realloc)); } void Stars::render(float fovY, float aspect, float nearZ, float alpha) { @@ -46,7 +46,7 @@ void Stars::render(float fovY, float aspect, float nearZ, float alpha) { // pull the modelview matrix off the GL stack glm::mat4 view; glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(view)); - _ptrController->render(fovDiagonal, aspect, glm::affineInverse(view), alpha); + _controller->render(fovDiagonal, aspect, glm::affineInverse(view), alpha); } diff --git a/interface/src/Stars.h b/interface/src/Stars.h index 7088bee36e..8fa425f3a6 100644 --- a/interface/src/Stars.h +++ b/interface/src/Stars.h @@ -18,7 +18,7 @@ namespace starfield { class Controller; } // class Stars { - starfield::Controller* _ptrController; + starfield::Controller* _controller; public: diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h index 3bbb7009a7..3ac15712d6 100644 --- a/interface/src/starfield/Controller.h +++ b/interface/src/starfield/Controller.h @@ -56,35 +56,35 @@ namespace starfield { class Controller { - InputVertices _seqInput; + InputVertices _inputSequence; #if STARFIELD_MULTITHREADING - mutex _mtxInput; - atomic _valTileResolution; + mutex _inputMutex; + atomic _tileResolution; - mutex _mtxLodState; + mutex _lodStateMutex; #else - unsigned _valTileResolution; + unsigned _tileResolution; #endif - double _valLodFraction; - double _valLodLowWaterMark; - double _valLodHighWaterMark; - double _valLodOveralloc; - size_t _valLodNalloc; - size_t _valLodNRender; - BrightnessLevels _seqLodBrightness; + double _lodFraction; + double _lodLowWaterMark; + double _lodHighWaterMark; + double _lodOveralloc; + size_t _lodNalloc; + size_t _lodNRender; + BrightnessLevels _lodBrightnessSequence; #if STARFIELD_MULTITHREADING - atomic _valLodBrightness; - BrightnessLevel _valLodAllocBrightness; + atomic _lodBrightness; + BrightnessLevel _lodAllocBrightness; - atomic _ptrRenderer; + atomic _renderer; typedef lock_guard lock; #else - BrightnessLevel _valLodBrightness; - BrightnessLevel _valLodAllocBrightness; + BrightnessLevel _lodBrightness; + BrightnessLevel _lodAllocBrightness; - Renderer* _ptrRenderer; + Renderer* _renderer; #define lock #define _(x) @@ -97,16 +97,16 @@ namespace starfield { public: Controller() : - _valTileResolution(20), - _valLodFraction(1.0), - _valLodLowWaterMark(0.8), - _valLodHighWaterMark(1.0), - _valLodOveralloc(1.2), - _valLodNalloc(0), - _valLodNRender(0), - _valLodBrightness(0), - _valLodAllocBrightness(0), - _ptrRenderer(0l) { + _tileResolution(20), + _lodFraction(1.0), + _lodLowWaterMark(0.8), + _lodHighWaterMark(1.0), + _lodOveralloc(1.2), + _lodNalloc(0), + _lodNRender(0), + _lodBrightness(0), + _lodAllocBrightness(0), + _renderer(0l) { } bool readInput(const char* url, const char* cacheFile, unsigned limit) @@ -121,13 +121,13 @@ namespace starfield { // input is read, now run the entire data pipeline on the new input - { lock _(_mtxInput); + { lock _(_inputMutex); - _seqInput.swap(vertices); + _inputSequence.swap(vertices); #if STARFIELD_MULTITHREADING - unsigned k = _valTileResolution.load(memory_order_relaxed); + unsigned k = _tileResolution.load(memory_order_relaxed); #else - unsigned k = _valTileResolution; + unsigned k = _tileResolution; #endif size_t n, nRender; BrightnessLevel bMin, b; @@ -136,27 +136,27 @@ namespace starfield { // we'll have to build a new LOD state for a new total N, // ideally keeping allocation size and number of vertices - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - size_t newLast = _seqInput.size() - 1; + size_t newLast = _inputSequence.size() - 1; // reciprocal change N_old/N_new tells us how to scale // the fractions - rcpChange = min(1.0, double(vertices.size()) / _seqInput.size()); + rcpChange = min(1.0, double(vertices.size()) / _inputSequence.size()); // initialization? use defaults / previously set values if (rcpChange == 0.0) { rcpChange = 1.0; - nRender = toBufSize(_valLodFraction * newLast); - n = min(newLast, toBufSize(_valLodOveralloc * nRender)); + nRender = toBufSize(_lodFraction * newLast); + n = min(newLast, toBufSize(_lodOveralloc * nRender)); } else { // cannot allocate or render more than we have - n = min(newLast, _valLodNalloc); - nRender = min(newLast, _valLodNRender); + n = min(newLast, _lodNalloc); + nRender = min(newLast, _lodNRender); } // determine new minimum brightness levels @@ -178,26 +178,26 @@ namespace starfield { } catch (...) { // rollback transaction and rethrow - vertices.swap(_seqInput); + vertices.swap(_inputSequence); throw; } // finally publish the new LOD state - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - _seqLodBrightness.swap(brightness); - _valLodFraction *= rcpChange; - _valLodLowWaterMark *= rcpChange; - _valLodHighWaterMark *= rcpChange; - _valLodOveralloc *= rcpChange; - _valLodNalloc = n; - _valLodNRender = nRender; - _valLodAllocBrightness = bMin; + _lodBrightnessSequence.swap(brightness); + _lodFraction *= rcpChange; + _lodLowWaterMark *= rcpChange; + _lodHighWaterMark *= rcpChange; + _lodOveralloc *= rcpChange; + _lodNalloc = n; + _lodNRender = nRender; + _lodAllocBrightness = bMin; #if STARFIELD_MULTITHREADING - _valLodBrightness.store(b, memory_order_relaxed); + _lodBrightness.store(b, memory_order_relaxed); #else - _valLodBrightness = b; + _lodBrightness = b; #endif } } @@ -214,24 +214,24 @@ namespace starfield { // printLog("Stars.cpp: setResolution(%d)\n", k); #if STARFIELD_MULTITHREADING - if (k != _valTileResolution.load(memory_order_relaxed)) + if (k != _tileResolution.load(memory_order_relaxed)) #else - if (k != _valTileResolution) + if (k != _tileResolution) #endif - { lock _(_mtxInput); + { lock _(_inputMutex); unsigned n; BrightnessLevel b, bMin; - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - n = _valLodNalloc; + n = _lodNalloc; #if STARFIELD_MULTITHREADING - b = _valLodBrightness.load(memory_order_relaxed); + b = _lodBrightness.load(memory_order_relaxed); #else - b = _valLodBrightness; + b = _lodBrightness; #endif - bMin = _valLodAllocBrightness; + bMin = _lodAllocBrightness; } this->retile(n, k, b, bMin); @@ -249,14 +249,14 @@ namespace starfield { Tiling tiling(k); VertexOrder scanner(tiling); - radix2InplaceSort(_seqInput.begin(), _seqInput.end(), scanner); + radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner); // printLog( // "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin); recreateRenderer(n, k, b, bMin); - _valTileResolution = k; + _tileResolution = k; } public: @@ -273,13 +273,13 @@ namespace starfield { BrightnessLevel bMin, b; double fraction, lwm, hwm; - { lock _(_mtxLodState); + { lock _(_lodStateMutex); // acuire a consistent copy of the current LOD state - fraction = _valLodFraction; - lwm = _valLodLowWaterMark; - hwm = _valLodHighWaterMark; - size_t last = _seqLodBrightness.size() - 1; + fraction = _lodFraction; + lwm = _lodLowWaterMark; + hwm = _lodHighWaterMark; + size_t last = _lodBrightnessSequence.size() - 1; // apply factor fraction = max(0.0, min(1.0, fraction * factor)); @@ -288,23 +288,23 @@ namespace starfield { // threshold double oaFract = std::min(fraction * (1.0 + overalloc), 1.0); n = toBufSize(oaFract * last); - bMin = _seqLodBrightness[n]; + bMin = _lodBrightnessSequence[n]; n = std::upper_bound( - _seqLodBrightness.begin() + n - 1, - _seqLodBrightness.end(), - bMin, GreaterBrightness() ) - _seqLodBrightness.begin(); + _lodBrightnessSequence.begin() + n - 1, + _lodBrightnessSequence.end(), + bMin, GreaterBrightness() ) - _lodBrightnessSequence.begin(); // also determine number of vertices to render and brightness nRender = toBufSize(fraction * last); // Note: nRender does not have to be accurate - b = _seqLodBrightness[nRender]; + b = _lodBrightnessSequence[nRender]; // this setting controls the renderer, also keep b as the // brightness becomes volatile as soon as the mutex is // released, so keep b #if STARFIELD_MULTITHREADING - _valLodBrightness.store(b, memory_order_relaxed); + _lodBrightness.store(b, memory_order_relaxed); #else - _valLodBrightness = b; + _lodBrightness = b; #endif // printLog("Stars.cpp: " @@ -313,34 +313,34 @@ namespace starfield { // will not have to reallocate? set new fraction right away // (it is consistent with the rest of the state in this case) - if (fraction >= _valLodLowWaterMark - && fraction <= _valLodHighWaterMark) { + if (fraction >= _lodLowWaterMark + && fraction <= _lodHighWaterMark) { - _valLodFraction = fraction; + _lodFraction = fraction; return fraction; } } // reallocate - { lock _(_mtxInput); + { lock _(_inputMutex); - recreateRenderer(n, _valTileResolution, b, bMin); + recreateRenderer(n, _tileResolution, b, bMin); // printLog("Stars.cpp: LOD reallocation\n"); // publish new lod state - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - _valLodNalloc = n; - _valLodNRender = nRender; + _lodNalloc = n; + _lodNRender = nRender; - _valLodFraction = fraction; - _valLodLowWaterMark = fraction * (1.0 - realloc); - _valLodHighWaterMark = fraction * (1.0 + realloc); - _valLodOveralloc = fraction * (1.0 + overalloc); - _valLodAllocBrightness = bMin; + _lodFraction = fraction; + _lodLowWaterMark = fraction * (1.0 - realloc); + _lodHighWaterMark = fraction * (1.0 + realloc); + _lodOveralloc = fraction * (1.0 + overalloc); + _lodAllocBrightness = bMin; } } return fraction; @@ -352,10 +352,10 @@ namespace starfield { BrightnessLevel b, BrightnessLevel bMin) { #if STARFIELD_MULTITHREADING - delete _ptrRenderer.exchange(new Renderer(_seqInput, n, k, b, bMin) ); + delete _renderer.exchange(new Renderer(_inputSequence, n, k, b, bMin) ); #else - delete _ptrRenderer; - _ptrRenderer = new Renderer(_seqInput, n, k, b, bMin); + delete _renderer; + _renderer = new Renderer(_inputSequence, n, k, b, bMin); #endif } @@ -365,17 +365,17 @@ namespace starfield { #if STARFIELD_MULTITHREADING // check out renderer - Renderer* renderer = _ptrRenderer.exchange(0l); + Renderer* renderer = _renderer.exchange(0l); #else - Renderer* renderer = _ptrRenderer; + Renderer* renderer = _renderer; #endif // have it render if (renderer != 0l) { #if STARFIELD_MULTITHREADING - BrightnessLevel b = _valLodBrightness.load(memory_order_relaxed); + BrightnessLevel b = _lodBrightness.load(memory_order_relaxed); #else - BrightnessLevel b = _valLodBrightness; + BrightnessLevel b = _lodBrightness; #endif renderer->render(perspective, angle, orientation, b, alpha); } @@ -383,7 +383,7 @@ namespace starfield { #if STARFIELD_MULTITHREADING // check in - or dispose if there is a new one Renderer* newOne = 0l; - if (! _ptrRenderer.compare_exchange_strong(newOne, renderer)) { + if (! _renderer.compare_exchange_strong(newOne, renderer)) { assert(!! newOne); delete renderer; diff --git a/interface/src/starfield/Loader.h b/interface/src/starfield/Loader.h index 79ae7f7700..9bb0aa076c 100644 --- a/interface/src/starfield/Loader.h +++ b/interface/src/starfield/Loader.h @@ -24,35 +24,35 @@ namespace starfield { class Loader : UrlReader { - InputVertices* _ptrVertices; - unsigned _valLimit; + InputVertices* _vertices; + unsigned _limit; - unsigned _valLineNo; - char const* _strUrl; + unsigned _lineNo; + char const* _urlStr; - unsigned _valRecordsRead; - BrightnessLevel _valMinBrightness; + unsigned _recordsRead; + BrightnessLevel _minBrightness; public: bool loadVertices( InputVertices& destination, char const* url, char const* cacheFile, unsigned limit) { - _ptrVertices = & destination; - _valLimit = limit; + _vertices = & destination; + _limit = limit; #if STARFIELD_SAVE_MEMORY - if (_valLimit == 0 || _valLimit > 60000u) - _valLimit = 60000u; + if (_limit == 0 || _limit > 60000u) + _limit = 60000u; #endif - _strUrl = url; // in case we fail early + _urlStr = url; // in case we fail early if (! UrlReader::readUrl(url, *this, cacheFile)) { printLog("%s:%d: %s\n", - _strUrl, _valLineNo, getError()); + _urlStr, _lineNo, getError()); return false; } - printLog("Loaded %u stars.\n", _valRecordsRead); + printLog("Loaded %u stars.\n", _recordsRead); return true; } @@ -66,13 +66,13 @@ namespace starfield { int64_t size, int64_t stardate) { - _valLineNo = 0u; - _strUrl = url; // new value in http redirect + _lineNo = 0u; + _urlStr = url; // new value in http redirect - _valRecordsRead = 0u; + _recordsRead = 0u; - _ptrVertices->clear(); - _ptrVertices->reserve(_valLimit); + _vertices->clear(); + _vertices->reserve(_limit); // printLog("Stars.cpp: loader begin %s\n", url); } @@ -88,7 +88,7 @@ namespace starfield { for (; next != end && isspace(*next); ++next); consumed = next - input; line = next; - ++_valLineNo; + ++_lineNo; for (; next != end && *next != '\n' && *next != '\r'; ++next); if (next == end) return consumed; @@ -109,12 +109,12 @@ namespace starfield { storeVertex(azi, alt, c); } - ++_valRecordsRead; + ++_recordsRead; } else { printLog("Stars.cpp:%d: Bad input from %s\n", - _valLineNo, _strUrl); + _lineNo, _urlStr); } } @@ -126,7 +126,7 @@ namespace starfield { private: - bool atLimit() { return _valLimit > 0u && _valRecordsRead >= _valLimit; } + bool atLimit() { return _limit > 0u && _recordsRead >= _limit; } bool spaceFor(BrightnessLevel b) { @@ -136,42 +136,42 @@ namespace starfield { // just reached the limit? -> establish a minimum heap and // remember the brightness at its top - if (_valRecordsRead == _valLimit) { + if (_recordsRead == _limit) { // printLog("Stars.cpp: vertex limit reached -> heap mode\n"); make_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _valMinBrightness = getBrightness( - _ptrVertices->begin()->getColor() ); + _minBrightness = getBrightness( + _vertices->begin()->getColor() ); } // not interested? say so - if (_valMinBrightness >= b) + if (_minBrightness >= b) return false; // otherwise free up space for the new vertex pop_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _ptrVertices->pop_back(); + _vertices->pop_back(); return true; } void storeVertex(float azi, float alt, unsigned color) { - _ptrVertices->push_back(InputVertex(azi, alt, color)); + _vertices->push_back(InputVertex(azi, alt, color)); if (atLimit()) { push_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _valMinBrightness = getBrightness( - _ptrVertices->begin()->getColor() ); + _minBrightness = getBrightness( + _vertices->begin()->getColor() ); } } }; diff --git a/interface/src/starfield/data/GpuVertex.h b/interface/src/starfield/data/GpuVertex.h index 6de3b5a15f..1cc3e001a9 100644 --- a/interface/src/starfield/data/GpuVertex.h +++ b/interface/src/starfield/data/GpuVertex.h @@ -19,7 +19,7 @@ namespace starfield { class GpuVertex { - unsigned _valColor; + unsigned _color; float _valX; float _valY; float _valZ; @@ -29,7 +29,7 @@ namespace starfield { GpuVertex(InputVertex const& in) { - _valColor = in.getColor(); + _color = in.getColor(); float azi = in.getAzimuth(); float alt = in.getAltitude(); @@ -44,7 +44,7 @@ namespace starfield { _valZ = gz * exz; } - unsigned getColor() const { return _valColor; } + unsigned getColor() const { return _color; } }; } // anonymous namespace diff --git a/interface/src/starfield/data/InputVertex.h b/interface/src/starfield/data/InputVertex.h index 670056bd74..bfc8093f86 100644 --- a/interface/src/starfield/data/InputVertex.h +++ b/interface/src/starfield/data/InputVertex.h @@ -19,14 +19,14 @@ namespace starfield { class InputVertex { - unsigned _valColor; - float _valAzimuth; - float _valAltitude; + unsigned _color; + float _azimuth; + float _altitude; public: InputVertex(float azimuth, float altitude, unsigned color) { - _valColor = ((color >> 16) & 0xffu) | (color & 0xff00u) | + _color = ((color >> 16) & 0xffu) | (color & 0xff00u) | ((color << 16) & 0xff0000u) | 0xff000000u; azimuth = angleConvert(azimuth); @@ -34,13 +34,13 @@ namespace starfield { angleHorizontalPolar(azimuth, altitude); - _valAzimuth = azimuth; - _valAltitude = altitude; + _azimuth = azimuth; + _altitude = altitude; } - float getAzimuth() const { return _valAzimuth; } - float getAltitude() const { return _valAltitude; } - unsigned getColor() const { return _valColor; } + float getAzimuth() const { return _azimuth; } + float getAltitude() const { return _altitude; } + unsigned getColor() const { return _color; } }; typedef std::vector InputVertices; diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index cf7cee6234..1d08951d03 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -65,20 +65,20 @@ namespace starfield { class Renderer { - GpuVertex* _arrData; - Tile* _arrTile; - GLint* _arrBatchOffs; - GLsizei* _arrBatchCount; - GLuint _hndVertexArray; - ProgramObject _objProgram; + GpuVertex* _dataArray; + Tile* _tileArray; + GLint* _batchOffs; + GLsizei* _batchCountArray; + GLuint _vertexArrayHandle; + ProgramObject _program; int _alphaLocationHandle; - Tiling _objTiling; + Tiling _tiling; - unsigned* _itrOutIndex; - vec3 _vecWRow; - float _valHalfPerspectiveAngle; - BrightnessLevel _valMinBright; + unsigned* _outIndexPos; + vec3 _wRowVec; + float _halfPerspectiveAngle; + BrightnessLevel _minBright; public: @@ -88,9 +88,9 @@ namespace starfield { BrightnessLevel b, BrightnessLevel bMin) : - _arrData(0l), - _arrTile(0l), - _objTiling(k) { + _dataArray(0l), + _tileArray(0l), + _tiling(k) { this->glAlloc(); @@ -101,10 +101,10 @@ namespace starfield { // REVISIT: batch arrays are probably oversized, but - hey - they // are not very large (unless for insane tiling) and we're better // off safe than sorry - _arrData = new GpuVertex[n]; - _arrTile = new Tile[nTiles + 1]; - _arrBatchOffs = new GLint[nTiles * 2]; - _arrBatchCount = new GLsizei[nTiles * 2]; + _dataArray = new GpuVertex[n]; + _tileArray = new Tile[nTiles + 1]; + _batchOffs = new GLint[nTiles * 2]; + _batchCountArray = new GLsizei[nTiles * 2]; prepareVertexData(src, n, tiling, b, bMin); @@ -113,10 +113,10 @@ namespace starfield { ~Renderer() { - delete[] _arrData; - delete[] _arrTile; - delete[] _arrBatchCount; - delete[] _arrBatchOffs; + delete[] _dataArray; + delete[] _tileArray; + delete[] _batchCountArray; + delete[] _batchOffs; this->glFree(); } @@ -172,23 +172,23 @@ namespace starfield { matrix = glm::frustum(-hw,hw, -hh,hh, nearClip,10.0f) * glm::affineInverse(matrix); - this->_itrOutIndex = (unsigned*) _arrBatchOffs; - this->_vecWRow = vec3(row(matrix, 3)); - this->_valHalfPerspectiveAngle = halfPersp; - this->_valMinBright = minBright; + this->_outIndexPos = (unsigned*) _batchOffs; + this->_wRowVec = vec3(row(matrix, 3)); + this->_halfPerspectiveAngle = halfPersp; + this->_minBright = minBright; TileSelection::Cursor cursor; - cursor.current = _arrTile + _objTiling.getTileIndex(azimuth, altitude); - cursor.firstInRow = _arrTile + _objTiling.getTileIndex(0.0f, altitude); + cursor.current = _tileArray + _tiling.getTileIndex(azimuth, altitude); + cursor.firstInRow = _tileArray + _tiling.getTileIndex(0.0f, altitude); - floodFill(cursor, TileSelection(*this, _arrTile, _arrTile + _objTiling.getTileCount(), - (TileSelection::Cursor*) _arrBatchCount)); + floodFill(cursor, TileSelection(*this, _tileArray, _tileArray + _tiling.getTileCount(), + (TileSelection::Cursor*) _batchCountArray)); #if STARFIELD_DEBUG_CULLING # define matrix matrix_debug #endif this->glBatch(glm::value_ptr(matrix), prepareBatch( - (unsigned*) _arrBatchOffs, _itrOutIndex), alpha); + (unsigned*) _batchOffs, _outIndexPos), alpha); #if STARFIELD_DEBUG_CULLING # undef matrix @@ -206,9 +206,9 @@ namespace starfield { size_t nTiles = tiling.getTileCount(); size_t vertexIndex = 0u, currTileIndex = 0u, count_active = 0u; - _arrTile[0].offset = 0u; - _arrTile[0].lod = b; - _arrTile[0].flags = 0u; + _tileArray[0].offset = 0u; + _tileArray[0].lod = b; + _tileArray[0].flags = 0u; for (InputVertices::const_iterator i = src.begin(), e = src.end(); i != e; ++i) { @@ -225,8 +225,8 @@ namespace starfield { // moved on to another tile? -> flush if (tileIndex != currTileIndex) { - Tile* t = _arrTile + currTileIndex; - Tile* tLast = _arrTile + tileIndex; + Tile* t = _tileArray + currTileIndex; + Tile* tLast = _tileArray + tileIndex; // set count of active vertices (upcoming lod) t->count = count_active; @@ -251,14 +251,14 @@ namespace starfield { // printLog("Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex); // write converted vertex - _arrData[vertexIndex++] = *i; + _dataArray[vertexIndex++] = *i; } } assert(vertexIndex == n); // flush last tile (see above) - Tile* t = _arrTile + currTileIndex; + Tile* t = _tileArray + currTileIndex; t->count = count_active; - for (Tile* e = _arrTile + nTiles + 1; ++t != e;) { + for (Tile* e = _tileArray + nTiles + 1; ++t != e;) { t->offset = vertexIndex, t->count = 0u, t->lod = b, t->flags = 0; } @@ -275,22 +275,22 @@ namespace starfield { public: struct Cursor { Tile* current, * firstInRow; }; private: - Renderer& _refRenderer; - Cursor* const _arrStack; - Cursor* _itrStack; - Tile const* const _arrTile; - Tile const* const _ptrTilesEnd; + Renderer& _rendererRef; + Cursor* const _stackArray; + Cursor* _stackPos; + Tile const* const _tileArray; + Tile const* const _tilesEnd; public: TileSelection(Renderer& renderer, Tile const* tiles, Tile const* tiles_end, Cursor* stack) : - _refRenderer(renderer), - _arrStack(stack), - _itrStack(stack), - _arrTile(tiles), - _ptrTilesEnd(tiles_end) { + _rendererRef(renderer), + _stackArray(stack), + _stackPos(stack), + _tileArray(tiles), + _tilesEnd(tiles_end) { } protected: @@ -300,7 +300,7 @@ namespace starfield { bool select(Cursor const& c) { Tile* t = c.current; - if (t < _arrTile || t >= _ptrTilesEnd || + if (t < _tileArray || t >= _tilesEnd || !! (t->flags & Tile::checked)) { // out of bounds or been here already @@ -309,7 +309,7 @@ namespace starfield { // will check now and never again t->flags |= Tile::checked; - if (_refRenderer.visitTile(t)) { + if (_rendererRef.visitTile(t)) { // good one -> remember (for batching) and propagate t->flags |= Tile::render; @@ -332,39 +332,39 @@ namespace starfield { void right(Cursor& c) const { c.current += 1; - if (c.current == c.firstInRow + _refRenderer._objTiling.getAzimuthalTiles()) { + if (c.current == c.firstInRow + _rendererRef._tiling.getAzimuthalTiles()) { c.current = c.firstInRow; } } void left(Cursor& c) const { if (c.current == c.firstInRow) { - c.current = c.firstInRow + _refRenderer._objTiling.getAzimuthalTiles(); + c.current = c.firstInRow + _rendererRef._tiling.getAzimuthalTiles(); } c.current -= 1; } void up(Cursor& c) const { - unsigned d = _refRenderer._objTiling.getAzimuthalTiles(); + unsigned d = _rendererRef._tiling.getAzimuthalTiles(); c.current += d; c.firstInRow += d; } void down(Cursor& c) const { - unsigned d = _refRenderer._objTiling.getAzimuthalTiles(); + unsigned d = _rendererRef._tiling.getAzimuthalTiles(); c.current -= d; c.firstInRow -= d; } void defer(Cursor const& t) { - *_itrStack++ = t; + *_stackPos++ = t; } bool deferred(Cursor& cursor) { - if (_itrStack != _arrStack) { - cursor = *--_itrStack; + if (_stackPos != _stackArray) { + cursor = *--_stackPos; return true; } return false; @@ -373,35 +373,35 @@ namespace starfield { bool visitTile(Tile* t) { - unsigned index = t - _arrTile; - *_itrOutIndex++ = index; + unsigned index = t - _tileArray; + *_outIndexPos++ = index; if (! tileVisible(t, index)) { return false; } - if (t->lod != _valMinBright) { - updateVertexCount(t, _valMinBright); + if (t->lod != _minBright) { + updateVertexCount(t, _minBright); } return true; } bool tileVisible(Tile* t, unsigned i) { - float slice = _objTiling.getSliceAngle(); + float slice = _tiling.getSliceAngle(); float halfSlice = 0.5f * slice; - unsigned stride = _objTiling.getAzimuthalTiles(); + unsigned stride = _tiling.getAzimuthalTiles(); float azimuth = (i % stride) * slice; float altitude = (i / stride) * slice - Radians::halfPi(); float gx = sin(azimuth); float gz = -cos(azimuth); float exz = cos(altitude); vec3 tileCenter = vec3(gx * exz, sin(altitude), gz * exz); - float w = dot(_vecWRow, tileCenter); + float w = dot(_wRowVec, tileCenter); float daz = halfSlice * cos(std::max(0.0f, abs(altitude) - halfSlice)); float dal = halfSlice; - float adjustedNear = cos(_valHalfPerspectiveAngle + sqrt(daz * daz + dal * dal)); + float adjustedNear = cos(_halfPerspectiveAngle + sqrt(daz * daz + dal * dal)); // printLog("Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip); @@ -415,8 +415,8 @@ namespace starfield { // perform a binary search in the so found partition for the // new vertex count of this tile - GpuVertex const* start = _arrData + t[0].offset; - GpuVertex const* end = _arrData + t[1].offset; + GpuVertex const* start = _dataArray + t[0].offset; + GpuVertex const* end = _dataArray + t[1].offset; assert(end >= start); @@ -431,9 +431,9 @@ namespace starfield { end = std::upper_bound( start, end, minBright, GreaterBrightness()); - assert(end >= _arrData + t[0].offset); + assert(end >= _dataArray + t[0].offset); - t->count = end - _arrData - t[0].offset; + t->count = end - _dataArray - t[0].offset; t->lod = minBright; } @@ -441,13 +441,13 @@ namespace starfield { unsigned const* indicesEnd) { unsigned nRanges = 0u; - GLint* offs = _arrBatchOffs; - GLsizei* count = _arrBatchCount; + GLint* offs = _batchOffs; + GLsizei* count = _batchCountArray; - for (unsigned* i = (unsigned*) _arrBatchOffs; + for (unsigned* i = (unsigned*) _batchOffs; i != indicesEnd; ++i) { - Tile* t = _arrTile + *i; + Tile* t = _tileArray + *i; if ((t->flags & Tile::render) > 0u && t->count > 0u) { *offs++ = t->offset; @@ -476,28 +476,28 @@ namespace starfield { " gl_PointSize = s;\n" "}\n"; - _objProgram.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER); + _program.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER); GLchar const* const FRAGMENT_SHADER = "#version 120\n" "void main(void) {\n" " gl_FragColor = gl_Color;\n" "}\n"; - _objProgram.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); - _objProgram.link(); - _alphaLocationHandle = _objProgram.uniformLocation("alpha"); + _program.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); + _program.link(); + _alphaLocationHandle = _program.uniformLocation("alpha"); - glGenBuffersARB(1, & _hndVertexArray); + glGenBuffersARB(1, & _vertexArrayHandle); } void glFree() { - glDeleteBuffersARB(1, & _hndVertexArray); + glDeleteBuffersARB(1, & _vertexArrayHandle); } void glUpload(GLsizei n) { - glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray); + glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); glBufferData(GL_ARRAY_BUFFER, - n * sizeof(GpuVertex), _arrData, GL_STATIC_DRAW); + n * sizeof(GpuVertex), _dataArray, GL_STATIC_DRAW); //glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); glBindBufferARB(GL_ARRAY_BUFFER, 0); @@ -509,7 +509,7 @@ namespace starfield { // for (int i = 0; i < n_ranges; ++i) // printLog("Stars.cpp: Batch #%d - %d stars @ %d\n", i, -// _arrBatchOffs[i], _arrBatchCount[i]); +// _batchOffs[i], _batchCountArray[i]); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); @@ -531,18 +531,18 @@ namespace starfield { glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); // select shader and vertex array - _objProgram.bind(); - _objProgram.setUniformValue(_alphaLocationHandle, alpha); - glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray); + _program.bind(); + _program.setUniformValue(_alphaLocationHandle, alpha); + glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); // render glMultiDrawArrays(GL_POINTS, - _arrBatchOffs, _arrBatchCount, n_ranges); + _batchOffs, _batchCountArray, n_ranges); // restore state glBindBufferARB(GL_ARRAY_BUFFER, 0); - _objProgram.release(); + _program.release(); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); glDisable(GL_POINT_SMOOTH); glPopMatrix(); diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h index 4737e318f9..6e7d7e46de 100644 --- a/interface/src/starfield/renderer/Tiling.h +++ b/interface/src/starfield/renderer/Tiling.h @@ -20,20 +20,20 @@ namespace starfield { class Tiling { unsigned _valK; - float _valRcpSlice; - unsigned _valNBits; + float _rcpSlice; + unsigned _nBits; public: Tiling(unsigned k) : _valK(k), - _valRcpSlice(k / Radians::twicePi()) { - _valNBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 + _rcpSlice(k / Radians::twicePi()) { + _nBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 } unsigned getAzimuthalTiles() const { return _valK; } unsigned getAltitudinalTiles() const { return _valK / 2 + 1; } - unsigned getTileIndexBits() const { return _valNBits; } + unsigned getTileIndexBits() const { return _nBits; } unsigned getTileCount() const { return getAzimuthalTiles() * getAltitudinalTiles(); @@ -45,14 +45,14 @@ namespace starfield { } float getSliceAngle() const { - return 1.0f / _valRcpSlice; + return 1.0f / _rcpSlice; } private: unsigned discreteAngle(float unsigned_angle) const { - return unsigned(floor(unsigned_angle * _valRcpSlice + 0.5f)); + return unsigned(floor(unsigned_angle * _rcpSlice + 0.5f)); } unsigned discreteAzimuth(float a) const { diff --git a/interface/src/starfield/renderer/VertexOrder.h b/interface/src/starfield/renderer/VertexOrder.h index 13784de53e..7f652b8dcd 100644 --- a/interface/src/starfield/renderer/VertexOrder.h +++ b/interface/src/starfield/renderer/VertexOrder.h @@ -25,7 +25,7 @@ namespace starfield { */ class VertexOrder : public Radix2IntegerScanner { - Tiling _objTiling; + Tiling _tiling; typedef Radix2IntegerScanner base; public: @@ -33,14 +33,14 @@ namespace starfield { explicit VertexOrder(Tiling const& tiling) : base(tiling.getTileIndexBits() + BrightnessBits), - _objTiling(tiling) { + _tiling(tiling) { } bool bit(InputVertex const& v, state_type const& s) const { // inspect (tile_index, brightness) tuples unsigned key = getBrightness(v.getColor()) ^ BrightnessMask; - key |= _objTiling.getTileIndex( + key |= _tiling.getTileIndex( v.getAzimuth(), v.getAltitude()) << BrightnessBits; return base::bit(key, s); } From b3085debb80db4d8bc4f0376a85afc6d63392559 Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 13:22:37 +0200 Subject: [PATCH 09/17] further adjusts naming --- libraries/shared/src/UrlReader.cpp | 40 +++++++++++++++--------------- libraries/shared/src/UrlReader.h | 26 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libraries/shared/src/UrlReader.cpp b/libraries/shared/src/UrlReader.cpp index 2e641b5a64..305db63667 100644 --- a/libraries/shared/src/UrlReader.cpp +++ b/libraries/shared/src/UrlReader.cpp @@ -58,10 +58,10 @@ char const* const UrlReader::error_leftover_input = "UrlReader: Incomplete pro #define _curlPtr static_cast(_curlHandle) UrlReader::UrlReader() - : _curlHandle(0l), _xtraArray(0l), _errorStr(0l), _cacheRdBufArray(0l) { + : _curlHandle(0l), _xtraBuffer(0l), _errorStr(0l), _cacheReadBuffer(0l) { - _xtraArray = new(std::nothrow) char[max_read_ahead]; - if (! _xtraArray) { _errorStr = error_init_failed; return; } + _xtraBuffer = new(std::nothrow) char[max_read_ahead]; + if (! _xtraBuffer) { _errorStr = error_init_failed; return; } _curlHandle = curl_easy_init(); if (! _curlHandle) { _errorStr = error_init_failed; return; } curl_easy_setopt(_curlPtr, CURLOPT_NOSIGNAL, 1l); @@ -72,8 +72,8 @@ UrlReader::UrlReader() UrlReader::~UrlReader() { - delete[] _xtraArray; - delete[] _cacheRdBufArray; + delete[] _xtraBuffer; + delete[] _cacheReadBuffer; if (! _curlHandle) { return; } @@ -101,8 +101,8 @@ void UrlReader::transferBegin(void* stream, char const* cacheFile) { _errorStr = success; _streamPtr = stream; - _cacheFileStr = cacheFile; - _cacheFilePtr = 0l; + _cacheFileName = cacheFile; + _cacheFile = 0l; _cacheMode = no_cache; _xtraSize = ~size_t(0); } @@ -124,28 +124,28 @@ void UrlReader::getInfo(char const*& url, // printLog("UrlReader: Ready to transfer from URL '%s'\n", url); // check caching file time whether we actually want to download anything - if (_cacheFileStr != 0l) { + if (_cacheFileName != 0l) { struct stat s; - stat(_cacheFileStr, & s); + stat(_cacheFileName, & s); if (time > s.st_mtime) { // file on server is newer -> update cache file - _cacheFilePtr = fopen(_cacheFileStr, "wb"); -// printLog("UrlReader: Also writing content to cache file '%s'\n", _cacheFileStr); - if (_cacheFilePtr != 0l) { + _cacheFile = fopen(_cacheFileName, "wb"); +// printLog("UrlReader: Also writing content to cache file '%s'\n", _cacheFileName); + if (_cacheFile != 0l) { _cacheMode = cache_write; } } else { // file on server is older -> use cache file - if (! _cacheRdBufArray) { - _cacheRdBufArray = new (std::nothrow) char[max_read_ahead]; - if (! _cacheRdBufArray) { + if (! _cacheReadBuffer) { + _cacheReadBuffer = new (std::nothrow) char[max_read_ahead]; + if (! _cacheReadBuffer) { // out of memory, no caching, have CURL catch it return; } } - _cacheFilePtr = fopen(_cacheFileStr, "rb"); -// printLog("UrlReader: Delivering cached content from file '%s'\n", _cacheFileStr); - if (_cacheFilePtr != 0l) { + _cacheFile = fopen(_cacheFileName, "rb"); +// printLog("UrlReader: Delivering cached content from file '%s'\n", _cacheFileName); + if (_cacheFile != 0l) { _cacheMode = cache_read; } // override error code returned by CURL when we abort the download @@ -156,8 +156,8 @@ void UrlReader::getInfo(char const*& url, void UrlReader::transferEnd() { - if (_cacheFilePtr != 0l) { - fclose(_cacheFilePtr); + if (_cacheFile != 0l) { + fclose(_cacheFile); } } diff --git a/libraries/shared/src/UrlReader.h b/libraries/shared/src/UrlReader.h index 9e70555184..8a9084ce32 100644 --- a/libraries/shared/src/UrlReader.h +++ b/libraries/shared/src/UrlReader.h @@ -160,12 +160,12 @@ private: // state void* _curlHandle; - char* _xtraArray; + char* _xtraBuffer; char const* _errorStr; void* _streamPtr; - char const* _cacheFileStr; - FILE* _cacheFilePtr; - char* _cacheRdBufArray; + char const* _cacheFileName; + FILE* _cacheFile; + char* _cacheReadBuffer; CacheMode _cacheMode; size_t _xtraSize; }; @@ -216,9 +216,9 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { // fill extra buffer with beginning of input size_t fill = max_read_ahead - _xtraSize; if (bytes < fill) fill = bytes; - memcpy(_xtraArray + _xtraSize, buffer, fill); + memcpy(_xtraBuffer + _xtraSize, buffer, fill); // use extra buffer for next transfer - buffer = _xtraArray; + buffer = _xtraBuffer; bytes = _xtraSize + fill; inputOffset += fill; } @@ -238,7 +238,7 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { size_t unprocessed = bytes - processed; // can switch to input buffer, now? - if (buffer == _xtraArray && unprocessed <= inputOffset) { + if (buffer == _xtraBuffer && unprocessed <= inputOffset) { _xtraSize = 0u; inputOffset -= unprocessed; @@ -251,9 +251,9 @@ size_t UrlReader::feedBuffered(Stream* stream, char* input, size_t size) { return 0; } _xtraSize = unprocessed; - memmove(_xtraArray, buffer + processed, unprocessed); + memmove(_xtraBuffer, buffer + processed, unprocessed); - if (inputOffset == size || buffer != _xtraArray) { + if (inputOffset == size || buffer != _xtraBuffer) { return size; } @@ -287,16 +287,16 @@ size_t UrlReader::callback_template(char *input, size_t size, size_t nmemb, void // read from cache file? if (me->_cacheMode == cache_read) { // change input buffer and start - input = me->_cacheRdBufArray; - size = fread(input, 1, max_read_ahead, me->_cacheFilePtr); + input = me->_cacheReadBuffer; + size = fread(input, 1, max_read_ahead, me->_cacheFile); nmemb = 1; } else if (me->_cacheMode == cache_write) { - fwrite(input, 1, size, me->_cacheFilePtr); + fwrite(input, 1, size, me->_cacheFile); } result = me->feedBuffered(stream, input, size); - } while (me->_cacheMode == cache_read && result != 0 && ! feof(me->_cacheFilePtr)); + } while (me->_cacheMode == cache_read && result != 0 && ! feof(me->_cacheFile)); return me->_cacheMode != cache_read ? result : 0; } From 2120ab9b1ee7327baf59578e52041dd043704100 Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 13:23:04 +0200 Subject: [PATCH 10/17] puts member variables last but first --- interface/src/Stars.h | 8 +- interface/src/starfield/Controller.h | 142 +++++++++--------- interface/src/starfield/Loader.h | 21 +-- interface/src/starfield/data/GpuVertex.h | 14 +- interface/src/starfield/data/InputVertex.h | 9 +- interface/src/starfield/data/Tile.h | 1 + interface/src/starfield/renderer/Renderer.h | 42 +++--- interface/src/starfield/renderer/Tiling.h | 10 +- .../src/starfield/renderer/VertexOrder.h | 9 +- 9 files changed, 129 insertions(+), 127 deletions(-) diff --git a/interface/src/Stars.h b/interface/src/Stars.h index 8fa425f3a6..ac2abcde42 100644 --- a/interface/src/Stars.h +++ b/interface/src/Stars.h @@ -17,11 +17,7 @@ namespace starfield { class Controller; } // Starfield rendering component. // class Stars { - - starfield::Controller* _controller; - public: - Stars(); ~Stars(); @@ -73,6 +69,10 @@ class Stars { // don't copy/assign Stars(Stars const&); // = delete; Stars& operator=(Stars const&); // delete; + + // variables + + starfield::Controller* _controller; }; diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h index 3ac15712d6..cefe46664e 100644 --- a/interface/src/starfield/Controller.h +++ b/interface/src/starfield/Controller.h @@ -55,45 +55,6 @@ namespace starfield { class Controller { - - InputVertices _inputSequence; -#if STARFIELD_MULTITHREADING - mutex _inputMutex; - atomic _tileResolution; - - mutex _lodStateMutex; -#else - unsigned _tileResolution; -#endif - double _lodFraction; - double _lodLowWaterMark; - double _lodHighWaterMark; - double _lodOveralloc; - size_t _lodNalloc; - size_t _lodNRender; - BrightnessLevels _lodBrightnessSequence; - -#if STARFIELD_MULTITHREADING - atomic _lodBrightness; - BrightnessLevel _lodAllocBrightness; - - atomic _renderer; - - typedef lock_guard lock; -#else - BrightnessLevel _lodBrightness; - BrightnessLevel _lodAllocBrightness; - - Renderer* _renderer; - - #define lock - #define _(x) -#endif - - static inline size_t toBufSize(double f) { - return size_t(floor(f + 0.5f)); - } - public: Controller() : @@ -109,6 +70,11 @@ namespace starfield { _renderer(0l) { } +#if !STARFIELD_MULTITHREADING + #define lock + #define _(x) +#endif + bool readInput(const char* url, const char* cacheFile, unsigned limit) { InputVertices vertices; @@ -242,25 +208,6 @@ namespace starfield { } } - private: - - void retile(size_t n, unsigned k, - BrightnessLevel b, BrightnessLevel bMin) { - - Tiling tiling(k); - VertexOrder scanner(tiling); - radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner); - -// printLog( -// "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin); - - recreateRenderer(n, k, b, bMin); - - _tileResolution = k; - } - - public: - double changeLOD(double factor, double overalloc, double realloc) { assert(overalloc >= realloc && realloc >= 0.0); @@ -346,21 +293,6 @@ namespace starfield { return fraction; } - private: - - void recreateRenderer(size_t n, unsigned k, - BrightnessLevel b, BrightnessLevel bMin) { - -#if STARFIELD_MULTITHREADING - delete _renderer.exchange(new Renderer(_inputSequence, n, k, b, bMin) ); -#else - delete _renderer; - _renderer = new Renderer(_inputSequence, n, k, b, bMin); -#endif - } - - public: - void render(float perspective, float angle, mat4 const& orientation, float alpha) { #if STARFIELD_MULTITHREADING @@ -396,6 +328,37 @@ namespace starfield { private: + void retile(size_t n, unsigned k, + BrightnessLevel b, BrightnessLevel bMin) { + + Tiling tiling(k); + VertexOrder scanner(tiling); + radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner); + +// printLog( +// "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin); + + recreateRenderer(n, k, b, bMin); + + _tileResolution = k; + } + + void recreateRenderer(size_t n, unsigned k, + BrightnessLevel b, BrightnessLevel bMin) { + +#if STARFIELD_MULTITHREADING + delete _renderer.exchange(new Renderer(_inputSequence, n, k, b, bMin) ); +#else + delete _renderer; + _renderer = new Renderer(_inputSequence, n, k, b, bMin); +#endif + } + + + static inline size_t toBufSize(double f) { + return size_t(floor(f + 0.5f)); + } + struct BrightnessSortScanner : Radix2IntegerScanner { typedef Radix2IntegerScanner base; @@ -420,6 +383,39 @@ namespace starfield { radix2InplaceSort(dst.begin(), dst.end(), BrightnessSortScanner()); } + InputVertices _inputSequence; +#if STARFIELD_MULTITHREADING + mutex _inputMutex; + atomic _tileResolution; + + mutex _lodStateMutex; +#else + unsigned _tileResolution; +#endif + double _lodFraction; + double _lodLowWaterMark; + double _lodHighWaterMark; + double _lodOveralloc; + size_t _lodNalloc; + size_t _lodNRender; + BrightnessLevels _lodBrightnessSequence; + +#if STARFIELD_MULTITHREADING + atomic _lodBrightness; + BrightnessLevel _lodAllocBrightness; + + atomic _renderer; + + typedef lock_guard lock; +#else + BrightnessLevel _lodBrightness; + BrightnessLevel _lodAllocBrightness; + + Renderer* _renderer; + + #undef lock + #undef _ +#endif }; } diff --git a/interface/src/starfield/Loader.h b/interface/src/starfield/Loader.h index 9bb0aa076c..e4e87516ea 100644 --- a/interface/src/starfield/Loader.h +++ b/interface/src/starfield/Loader.h @@ -23,15 +23,6 @@ namespace starfield { class Loader : UrlReader { - - InputVertices* _vertices; - unsigned _limit; - - unsigned _lineNo; - char const* _urlStr; - - unsigned _recordsRead; - BrightnessLevel _minBrightness; public: bool loadVertices( @@ -58,7 +49,6 @@ namespace starfield { } protected: - friend class UrlReader; void begin(char const* url, @@ -174,6 +164,17 @@ namespace starfield { _vertices->begin()->getColor() ); } } + + // variables + + InputVertices* _vertices; + unsigned _limit; + + unsigned _lineNo; + char const* _urlStr; + + unsigned _recordsRead; + BrightnessLevel _minBrightness; }; } // anonymous namespace diff --git a/interface/src/starfield/data/GpuVertex.h b/interface/src/starfield/data/GpuVertex.h index 1cc3e001a9..c194e8cdb9 100644 --- a/interface/src/starfield/data/GpuVertex.h +++ b/interface/src/starfield/data/GpuVertex.h @@ -18,13 +18,7 @@ namespace starfield { class GpuVertex { - - unsigned _color; - float _valX; - float _valY; - float _valZ; public: - GpuVertex() { } GpuVertex(InputVertex const& in) { @@ -44,7 +38,13 @@ namespace starfield { _valZ = gz * exz; } - unsigned getColor() const { return _color; } + unsigned getColor() const { return _color; } + + private: + unsigned _color; + float _valX; + float _valY; + float _valZ; }; } // anonymous namespace diff --git a/interface/src/starfield/data/InputVertex.h b/interface/src/starfield/data/InputVertex.h index bfc8093f86..ca247a3ba4 100644 --- a/interface/src/starfield/data/InputVertex.h +++ b/interface/src/starfield/data/InputVertex.h @@ -18,10 +18,6 @@ namespace starfield { class InputVertex { - - unsigned _color; - float _azimuth; - float _altitude; public: InputVertex(float azimuth, float altitude, unsigned color) { @@ -41,6 +37,11 @@ namespace starfield { float getAzimuth() const { return _azimuth; } float getAltitude() const { return _altitude; } unsigned getColor() const { return _color; } + + private: + unsigned _color; + float _azimuth; + float _altitude; }; typedef std::vector InputVertices; diff --git a/interface/src/starfield/data/Tile.h b/interface/src/starfield/data/Tile.h index 6d51921ce9..a7c26c7c8f 100644 --- a/interface/src/starfield/data/Tile.h +++ b/interface/src/starfield/data/Tile.h @@ -25,6 +25,7 @@ namespace starfield { BrightnessLevel lod; nuint flags; + // flags static uint16_t const checked = 1; static uint16_t const visited = 2; static uint16_t const render = 4; diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index 1d08951d03..75f93e0367 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -64,22 +64,6 @@ namespace starfield { class Renderer { - - GpuVertex* _dataArray; - Tile* _tileArray; - GLint* _batchOffs; - GLsizei* _batchCountArray; - GLuint _vertexArrayHandle; - ProgramObject _program; - int _alphaLocationHandle; - - Tiling _tiling; - - unsigned* _outIndexPos; - vec3 _wRowVec; - float _halfPerspectiveAngle; - BrightnessLevel _minBright; - public: Renderer(InputVertices const& src, @@ -195,7 +179,8 @@ namespace starfield { #endif } - private: // renderer construction + private: + // renderer construction void prepareVertexData(InputVertices const& src, size_t n, // <-- at bMin and brighter @@ -264,8 +249,7 @@ namespace starfield { } } - - private: // FOV culling / LOD + // FOV culling / LOD class TileSelection; friend class Renderer::TileSelection; @@ -459,7 +443,7 @@ namespace starfield { return nRanges; } - private: // gl API handling + // GL API handling void glAlloc() { @@ -549,6 +533,24 @@ namespace starfield { glMatrixMode(GL_MODELVIEW); glPopMatrix(); } + + // variables + + GpuVertex* _dataArray; + Tile* _tileArray; + GLint* _batchOffs; + GLsizei* _batchCountArray; + GLuint _vertexArrayHandle; + ProgramObject _program; + int _alphaLocationHandle; + + Tiling _tiling; + + unsigned* _outIndexPos; + vec3 _wRowVec; + float _halfPerspectiveAngle; + BrightnessLevel _minBright; + }; } // anonymous namespace diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h index 6e7d7e46de..fdec54dfc7 100644 --- a/interface/src/starfield/renderer/Tiling.h +++ b/interface/src/starfield/renderer/Tiling.h @@ -18,11 +18,6 @@ namespace starfield { class Tiling { - - unsigned _valK; - float _rcpSlice; - unsigned _nBits; - public: Tiling(unsigned k) : @@ -64,6 +59,11 @@ namespace starfield { discreteAngle(a + Radians::halfPi()) ); } + // variables + + unsigned _valK; + float _rcpSlice; + unsigned _nBits; }; } // anonymous namespace diff --git a/interface/src/starfield/renderer/VertexOrder.h b/interface/src/starfield/renderer/VertexOrder.h index 7f652b8dcd..d74864af18 100644 --- a/interface/src/starfield/renderer/VertexOrder.h +++ b/interface/src/starfield/renderer/VertexOrder.h @@ -25,11 +25,7 @@ namespace starfield { */ class VertexOrder : public Radix2IntegerScanner { - Tiling _tiling; - - typedef Radix2IntegerScanner base; public: - explicit VertexOrder(Tiling const& tiling) : base(tiling.getTileIndexBits() + BrightnessBits), @@ -44,6 +40,11 @@ namespace starfield { v.getAzimuth(), v.getAltitude()) << BrightnessBits; return base::bit(key, s); } + + private: + Tiling _tiling; + + typedef Radix2IntegerScanner base; }; } // anonymous namespace From cfd4100c6e387a72d344b5c22d0e693c1349f341 Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 14:52:01 +0200 Subject: [PATCH 11/17] revises log display --- interface/src/Application.cpp | 2 +- interface/src/Log.cpp | 505 ++++++++++++++++++---------------- interface/src/Log.h | 99 +++---- 3 files changed, 310 insertions(+), 296 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1f34ed3c09..3f9186946a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1690,7 +1690,7 @@ void Application::displayOverlay() { glPointSize(1.0f); if (_renderStatsOn->isChecked()) { displayStats(); } - if (_logOn->isChecked()) { logger.render(_glWidget->width(), _glWidget->height()); } + if (_logOn->isChecked()) { logdisplay::Render(_glWidget->width(), _glWidget->height()); } // Show chat entry field if (_chatEntryOn) { diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp index 5b50074444..af3b2f90fb 100644 --- a/interface/src/Log.cpp +++ b/interface/src/Log.cpp @@ -8,313 +8,356 @@ #include "Log.h" -#include "InterfaceConfig.h" #include #include +#include + +#include "InterfaceConfig.h" #include "Util.h" #include "ui/TextRenderer.h" -namespace { - // anonymous namespace - everything in here only exists within this very .cpp file - // just as 'static' on every effective line in plain C - unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered - unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered - unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message +namespace logdisplay { - const char* FONT_FAMILY = SANS_FONT_FAMILY; - - bool const TEXT_MONOSPACED = true; + class Logger { + public: + Logger(); + ~Logger(); - float const TEXT_RED = 0.7f; - float const TEXT_GREEN = 0.6f; - float const TEXT_BLUE = 1.0f; + inline void render(unsigned screenWidth, unsigned screenHeight); - // magic constants from the GLUT spec - // http://www.opengl.org/resources/libraries/glut/spec3/node78.html - // ultimately this stuff should be in Util.h?? - float const CHAR_UP = 119.05f; - float const CHAR_DOWN = 33.33f; - float const CHAR_WIDTH = 104.76f; - // derived values - float const CHAR_HEIGHT = CHAR_UP + CHAR_DOWN; - float const CHAR_FRACT_BASELINE = CHAR_DOWN / CHAR_HEIGHT; + inline void setStream(FILE* stream); + inline void setLogWidth(unsigned pixels); + inline void setCharacterSize(unsigned width, unsigned height); - // unsigned integer division rounded towards infinity - unsigned divRoundUp(unsigned l, unsigned r) { return (l + r - 1) / r; } -} + // format, eventually forward, and add the log message (called by printLog) + inline int vprint(char const* fmt, va_list); -Log::Log(FILE* tPipeTo, unsigned bufferedLines, - unsigned defaultLogWidth, unsigned defaultCharWidth, unsigned defaultCharHeight) : + private: + // don't copy/assign + Logger(Logger const&); // = delete; + Logger& operator=(Logger const&); // = delete; - _stream(tPipeTo), - _chars(0l), - _lines(0l), - _logWidth(defaultLogWidth) { + // add formatted message for console diplay (called by vprint) + inline void addMessage(char const*); - pthread_mutex_init(& _mutex, 0l); + TextRenderer _textRenderer; + FILE* _stream; // FILE as secondary destination for log messages + char* _chars; // character buffer base address + char* _charsEnd; // character buffer, exclusive end + char** _lines; // line buffer base address + char** _linesEnd; // line buffer, exclusive end - // allocate twice as much (so we have spare space for a copy not to block - // logging from other threads during 'render') - _chars = new char[CHARACTER_BUFFER_SIZE * 2]; - _charsEnd = _chars + CHARACTER_BUFFER_SIZE; - _lines = new char*[LINE_BUFFER_SIZE * 2]; - _linesEnd = _lines + LINE_BUFFER_SIZE; + char* _writePos; // character position to write to + char* _writeLineStartPos; // character position where line being written starts + char** _lastLinePos; // last line in the log + unsigned _writtenInLine; // character counter for line wrapping + unsigned _lineLength; // number of characters before line wrap - // initialize the log to all empty lines - _chars[0] = '\0'; - _writePos = _chars; - _writeLineStartPos = _chars; - _lastLinePos = _lines; - _writtenInLine = 0; - memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); + unsigned _logWidth; // width of the log in pixels + unsigned _charWidth; // width of a character in pixels + unsigned _charHeight; // height of a character in pixels - setCharacterSize(defaultCharWidth, defaultCharHeight); -} + pthread_mutex_t _mutex; + }; -Log::~Log() { + // + // Initialization / state management + // - delete[] _chars; - delete[] _lines; -} + Logger::Logger() : -inline void Log::addMessage(char const* ptr) { + _textRenderer(MONO_FONT_FAMILY, -1, -1, false, TextRenderer::SHADOW_EFFECT), + _stream(DEFAULT_STREAM), + _chars(0l), + _lines(0l), + _logWidth(DEFAULT_CONSOLE_WIDTH) { - // precondition: mutex is locked so noone gets in our way + pthread_mutex_init(& _mutex, 0l); - // T-pipe, if requested - if (_stream != 0l) { - fprintf(_stream, "%s", ptr); + // allocate twice as much (so we have spare space for a copy not to block + // logging from other threads during 'render') + _chars = new char[CHARACTER_BUFFER_SIZE * 2]; + _charsEnd = _chars + CHARACTER_BUFFER_SIZE; + _lines = new char*[LINE_BUFFER_SIZE * 2]; + _linesEnd = _lines + LINE_BUFFER_SIZE; + + // initialize the log to all empty lines + _chars[0] = '\0'; + _writePos = _chars; + _writeLineStartPos = _chars; + _lastLinePos = _lines; + _writtenInLine = 0; + memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); + + setCharacterSize(DEFAULT_CHAR_WIDTH, DEFAULT_CHAR_HEIGHT); } - while (*ptr != '\0') { - // process the characters - char c = *ptr++; - if (c == '\t') { + Logger::~Logger() { - // found TAB -> write SPACE - c = ' '; + delete[] _chars; + delete[] _lines; + } - } else if (c == '\n') { + inline void Logger::setStream(FILE* stream) { - // found LF -> write NUL (c == '\0' tells us to wrap, below) - c = '\0'; - } - *_writePos++ = c; + pthread_mutex_lock(& _mutex); + _stream = stream; + pthread_mutex_unlock(& _mutex); + } - if (_writePos == _charsEnd) { - // reached the end of the circular character buffer? -> start over - _writePos = _chars; + inline void Logger::setLogWidth(unsigned pixels) { + + pthread_mutex_lock(& _mutex); + _logWidth = pixels; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); + } + + inline void Logger::setCharacterSize(unsigned width, unsigned height) { + + pthread_mutex_lock(& _mutex); + _charWidth = width; + _charHeight = height; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); + } + + // + // Logging + // + + inline int Logger::vprint(char const* fmt, va_list args) { + pthread_mutex_lock(& _mutex); + + // print to buffer + char buf[MAX_MESSAGE_LENGTH]; + int n = vsnprintf(buf, MAX_MESSAGE_LENGTH, fmt, args); + if (n > 0) { + + // all fine? log the message + addMessage(buf); + + } else { + + // error? -> mutter on stream or stderr + fprintf(_stream != 0l ? _stream : stderr, + "Log: Failed to log message with format string = \"%s\".\n", fmt); } - if (++_writtenInLine >= _lineLength || c == '\0') { + pthread_mutex_unlock(& _mutex); + return n; + } - // new line? store its start to the line buffer and mark next line as empty - ++_lastLinePos; - - if (_lastLinePos == _linesEnd) { - _lastLinePos = _lines; - _lastLinePos[1] = 0l; - } else if (_lastLinePos + 1 != _linesEnd) { - _lastLinePos[1] = 0l; - } else { - _lines[0] = 0l; - } - *_lastLinePos = _writeLineStartPos; + inline void Logger::addMessage(char const* ptr) { - // debug mode: make sure all line pointers we write here are valid - assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); - assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); + // precondition: mutex is locked so noone gets in our way - // terminate line, unless done already - if (c != '\0') { - *_writePos++ = '\0'; + // T-pipe, if requested + if (_stream != 0l) { + fprintf(_stream, "%s", ptr); + } - if (_writePos == _charsEnd) { - _writePos = _chars; - } + while (*ptr != '\0') { + // process the characters + char c = *ptr++; + + if (c == '\t') { + + // found TAB -> write SPACE + c = ' '; + + } else if (c == '\n') { + + // found LF -> write NUL (c == '\0' tells us to wrap, below) + c = '\0'; + } + *_writePos++ = c; + + if (_writePos == _charsEnd) { + // reached the end of the circular character buffer? -> start over + _writePos = _chars; } - // remember start position in character buffer for next line and reset character count - _writeLineStartPos = _writePos; - _writtenInLine = 0; + if (++_writtenInLine >= _lineLength || c == '\0') { + + // new line? store its start to the line buffer and mark next line as empty + ++_lastLinePos; + + if (_lastLinePos == _linesEnd) { + _lastLinePos = _lines; + _lastLinePos[1] = 0l; + } else if (_lastLinePos + 1 != _linesEnd) { + _lastLinePos[1] = 0l; + } else { + _lines[0] = 0l; + } + *_lastLinePos = _writeLineStartPos; + + // debug mode: make sure all line pointers we write here are valid + assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); + assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); + + // terminate line, unless done already + if (c != '\0') { + *_writePos++ = '\0'; + + if (_writePos == _charsEnd) { + _writePos = _chars; + } + } + + // remember start position in character buffer for next line and reset character count + _writeLineStartPos = _writePos; + _writtenInLine = 0; + } } + } -} + // + // Rendering + // -int Log::vprint(char const* fmt, va_list args) { - pthread_mutex_lock(& _mutex); + inline void Logger::render(unsigned screenWidth, unsigned screenHeight) { - // print to buffer - char buf[MAX_MESSAGE_LENGTH]; - int n = vsnprintf(buf, MAX_MESSAGE_LENGTH, fmt, args); - if (n > 0) { + // rendering might take some time, so create a local copy of the portion we need + // instead of having to hold the mutex all the time + pthread_mutex_lock(& _mutex); - // all fine? log the message - addMessage(buf); + // determine number of visible lines (integer division rounded up) + unsigned showLines = (screenHeight + _charHeight - 1) / _charHeight; - } else { + char** lastLine = _lastLinePos; + char** firstLine = _lastLinePos; - // error? -> mutter on stream or stderr - fprintf(_stream != 0l ? _stream : stderr, - "Log: Failed to log message with format string = \"%s\".\n", fmt); - } + if (! *lastLine) { + // empty log + pthread_mutex_unlock(& _mutex); + return; + } - pthread_mutex_unlock(& _mutex); - return n; -} + // scan for first line + for (int n = 2; n <= showLines; ++n) { -void Log::operator()(char const* fmt, ...) { + char** prevFirstLine = firstLine; + --firstLine; + if (firstLine < _lines) { + firstLine = _linesEnd - 1; + } + if (! *firstLine) { + firstLine = prevFirstLine; + showLines = n - 1; + break; + } - va_list args; - va_start(args,fmt); - vprint(fmt, args); - va_end(args); -} + // debug mode: make sure all line pointers we find here are valid + assert(! (firstLine < _lines || firstLine >= _linesEnd)); + assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); + } -void Log::setLogWidth(unsigned pixels) { + // copy the line buffer portion into a contiguous region at _linesEnd + if (firstLine <= lastLine) { - pthread_mutex_lock(& _mutex); - _logWidth = pixels; - _lineLength = _logWidth / _charWidth; - pthread_mutex_unlock(& _mutex); -} + memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); -void Log::setCharacterSize(unsigned width, unsigned height) { + } else { - pthread_mutex_lock(& _mutex); - _charWidth = width; - _charHeight = height; - _charYoffset = height * CHAR_FRACT_BASELINE; - _charScale = float(width) / CHAR_WIDTH; - _charAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT); - _lineLength = _logWidth / _charWidth; - pthread_mutex_unlock(& _mutex); -} + unsigned atEnd = _linesEnd - firstLine; + memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); + memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); + } -static TextRenderer* textRenderer() { - static TextRenderer* renderer = new TextRenderer(FONT_FAMILY, -1, -1, false, TextRenderer::SHADOW_EFFECT); - return renderer; -} + // copy relevant char buffer portion and determine information to remap the pointers + char* firstChar = *firstLine; + char* lastChar = *lastLine + strlen(*lastLine) + 1; + ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; + if (firstChar <= lastChar) { -void Log::render(unsigned screenWidth, unsigned screenHeight) { + memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); - // rendering might take some time, so create a local copy of the portion we need - // instead of having to hold the mutex all the time - pthread_mutex_lock(& _mutex); + } else { - // determine number of visible lines - unsigned showLines = divRoundUp(screenHeight, _charHeight); + unsigned atEnd = _charsEnd - firstChar; + memcpy(_charsEnd, firstChar, atEnd); + memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); - char** lastLine = _lastLinePos; - char** firstLine = _lastLinePos; + charOffsetBeforeFirst = _charsEnd + atEnd - _chars; + } - if (! *lastLine) { - // empty log + // determine geometry information from font metrics + QFontMetrics const& fontMetrics = _textRenderer.metrics(); + int yStep = fontMetrics.lineSpacing(); + // scale + float xScale = float(_charWidth) / fontMetrics.width('*'); + float yScale = float(_charHeight) / yStep; + // scaled translation + int xStart = int((screenWidth - _logWidth) / xScale); + int yStart = screenHeight / yScale - fontMetrics.descent(); + + // first line to render + char** line = _linesEnd + showLines; + + // ok, now the lock can be released - we have all we need + // and won't hold it while talking to OpenGL pthread_mutex_unlock(& _mutex); - return; - } - // scan for first line - for (int n = 2; n <= showLines; ++n) { + glPushMatrix(); + glScalef(xScale, yScale, 1.0f); + for (int y = yStart; y > 0; y -= yStep) { - char** prevFirstLine = firstLine; - --firstLine; - if (firstLine < _lines) { - firstLine = _linesEnd - 1; + // debug mode: check line pointer is valid + assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); + + // get character pointer + if (--line < _linesEnd) { + break; + } + char* chars = *line; + + // debug mode: check char pointer we find is valid + assert(! (chars < _chars || chars >= _charsEnd)); + + // remap character pointer it to copied buffer + chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; + + // debug mode: check char pointer is still valid (in new range) + assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); + + // render the string + glColor3f(TEXT_COLOR_RED, TEXT_COLOR_GREEN, TEXT_COLOR_BLUE); + _textRenderer.draw(xStart, y, chars); + + //fprintf(stderr, "Logger::render, message = \"%s\"\n", chars); } - if (! *firstLine) { - firstLine = prevFirstLine; - showLines = n - 1; - break; - } - - // debug mode: make sure all line pointers we find here are valid - assert(! (firstLine < _lines || firstLine >= _linesEnd)); - assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); + glPopMatrix(); } - // copy the line buffer portion into a contiguous region at _linesEnd - if (firstLine <= lastLine) { - memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); + // + // There's one Logger and it exists globally... + // + Logger logger; - } else { + // Entrypoints + void Render(unsigned screenWidth, unsigned screenHeight) { logger.render(screenWidth, screenHeight); } + void SetStream(FILE* stream) { logger.setStream(stream); } + void SetLogWidth(unsigned pixels) { logger.setLogWidth(pixels); } + void SetCharacterSize(unsigned width, unsigned height) { logger.setCharacterSize(width, height); } - unsigned atEnd = _linesEnd - firstLine; - memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); - memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); - } +} // namespace logdisplay - // copy relevant char buffer portion and determine information to remap the pointers - char* firstChar = *firstLine; - char* lastChar = *lastLine + strlen(*lastLine) + 1; - ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; - if (firstChar <= lastChar) { - - memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); - - } else { - - unsigned atEnd = _charsEnd - firstChar; - memcpy(_charsEnd, firstChar, atEnd); - memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); - - charOffsetBeforeFirst = _charsEnd + atEnd - _chars; - } - - // get values for rendering - int yStep = textRenderer()->metrics().lineSpacing(); - int yStart = screenHeight - textRenderer()->metrics().descent(); - - // render text - char** line = _linesEnd + showLines; - int x = screenWidth - _logWidth; - - pthread_mutex_unlock(& _mutex); - // ok, we got all we need - - for (int y = yStart; y > 0; y -= yStep) { - - // debug mode: check line pointer is valid - assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); - - // get character pointer - if (--line < _linesEnd) { - break; - } - char* chars = *line; - - // debug mode: check char pointer we find is valid - assert(! (chars < _chars || chars >= _charsEnd)); - - // remap character pointer it to copied buffer - chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; - - // debug mode: check char pointer is still valid (in new range) - assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); - - // render the string - glColor3f(TEXT_RED, TEXT_GREEN, TEXT_BLUE); - textRenderer()->draw(x, y, chars); - -//fprintf(stderr, "Log::render, message = \"%s\"\n", chars); - } -} - -Log logger; int printLog(char const* fmt, ...) { int result; va_list args; va_start(args,fmt); - result = logger.vprint(fmt, args); + result = logdisplay::logger.vprint(fmt, args); va_end(args); return result; } diff --git a/interface/src/Log.h b/interface/src/Log.h index 17c693142c..55c22064a8 100644 --- a/interface/src/Log.h +++ b/interface/src/Log.h @@ -11,87 +11,58 @@ #include #include -#include -#include - -class Log; // -// Call it as you would call 'printf'. +// Log function. Call it as you would call 'printf'. // int printLog(char const* fmt, ...); +// +// Logging control. +// +namespace logdisplay { + + void Render(unsigned screenWidth, unsigned screenHeight); + + // settings + + static float const TEXT_COLOR_RED = 0.7f; + static float const TEXT_COLOR_GREEN = 0.6f; + static float const TEXT_COLOR_BLUE = 1.0f; + + static FILE* DEFAULT_STREAM = stdout; + static unsigned const DEFAULT_CHAR_WIDTH = 7; + static unsigned const DEFAULT_CHAR_HEIGHT = 16; + static unsigned const DEFAULT_CONSOLE_WIDTH = 400; + + void SetStream(FILE* stream); + void SetLogWidth(unsigned pixels); + void SetCharacterSize(unsigned width, unsigned height); + + // limits + + unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered + unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered + unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message +} + // // Macro to log OpenGl errors. -// Example: oglLog( glPushMatrix() ); +// Example: printGlError( glPushMatrix() ); // -#define oGlLog(stmt) \ +#define printLogGlError(stmt) \ stmt; \ { \ GLenum e = glGetError(); \ if (e != GL_NO_ERROR) { \ - printLog(__FILE__ ":" oGlLog_stringize(__LINE__) \ + printLog(__FILE__ ":" printLogGlError_stringize(__LINE__) \ " [OpenGL] %s\n", gluErrorString(e)); \ } \ } \ (void) 0 -#define oGlLog_stringize(x) oGlLog_stringize_i(x) -#define oGlLog_stringize_i(x) # x - -// -// Global instance. -// -extern Log logger; - -// -// Logging subsystem. -// -class Log { - FILE* _stream; - char* _chars; - char* _charsEnd; - char** _lines; - char** _linesEnd; - - char* _writePos; // character position to write to - char* _writeLineStartPos; // character position where line being written starts - char** _lastLinePos; // last line in the log - unsigned _writtenInLine; // character counter for line wrapping - unsigned _lineLength; // number of characters before line wrap - - unsigned _logWidth; // width of the log in pixels - unsigned _charWidth; // width of a character in pixels - unsigned _charHeight; // height of a character in pixels - unsigned _charYoffset; // baseline offset in pixels - float _charScale; // scale factor - float _charAspect; // aspect (h/w) - - pthread_mutex_t _mutex; - -public: - - explicit Log(FILE* tPipeTo = stdout, unsigned bufferedLines = 1024, - unsigned defaultLogWidth = 400, unsigned defaultCharWidth = 6, unsigned defaultCharHeight = 20); - ~Log(); - - void setLogWidth(unsigned pixels); - void setCharacterSize(unsigned width, unsigned height); - - void render(unsigned screenWidth, unsigned screenHeight); - - void operator()(char const* fmt, ...); - int vprint(char const* fmt, va_list); - -private: - // don't copy/assign - Log(Log const&); // = delete; - Log& operator=(Log const&); // = delete; - - inline void addMessage(char const*); - - friend class LogStream; // for optional iostream-style interface that has to be #included separately -}; +#define printLogGlError_stringize(x) printLogGlError_stringize_i(x) +#define printLogGlError_stringize_i(x) # x #endif From fbdda8bce4da14cf64b6a115f8719897564c43cf Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 15:07:48 +0200 Subject: [PATCH 12/17] adds comments --- interface/src/Log.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/interface/src/Log.h b/interface/src/Log.h index 55c22064a8..2293c39a76 100644 --- a/interface/src/Log.h +++ b/interface/src/Log.h @@ -26,14 +26,14 @@ namespace logdisplay { // settings - static float const TEXT_COLOR_RED = 0.7f; - static float const TEXT_COLOR_GREEN = 0.6f; - static float const TEXT_COLOR_BLUE = 1.0f; + static float const TEXT_COLOR_RED = 0.7f; // text foreground color, red component + static float const TEXT_COLOR_GREEN = 0.6f; // text foreground color, green component + static float const TEXT_COLOR_BLUE = 1.0f; // text foregdound color, blue component - static FILE* DEFAULT_STREAM = stdout; - static unsigned const DEFAULT_CHAR_WIDTH = 7; - static unsigned const DEFAULT_CHAR_HEIGHT = 16; - static unsigned const DEFAULT_CONSOLE_WIDTH = 400; + static FILE* DEFAULT_STREAM = stdout; // stream to also log to + static unsigned const DEFAULT_CHAR_WIDTH = 7; // width of a single character + static unsigned const DEFAULT_CHAR_HEIGHT = 16; // height of a single character + static unsigned const DEFAULT_CONSOLE_WIDTH = 400; // width of the (right-aligned) log console void SetStream(FILE* stream); void SetLogWidth(unsigned pixels); @@ -41,13 +41,13 @@ namespace logdisplay { // limits - unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered - unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered - unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message + unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered + unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered + unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message } // -// Macro to log OpenGl errors. +// Macro to log OpenGL errors. // Example: printGlError( glPushMatrix() ); // #define printLogGlError(stmt) \ From e99a41f41b4f0f50f4027417291071cc7d24986c Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 16:28:49 +0200 Subject: [PATCH 13/17] revises oscilloscope --- interface/src/Oscilloscope.cpp | 13 ++++++----- interface/src/Oscilloscope.h | 42 +++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index e5f076c7b3..9e2d3167ca 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -34,8 +34,9 @@ namespace { // everything in here only exists while compiling this .cpp file Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : _width(w), _height(h), - _samples(0l), _vertices(0l), - _lowpassFactor(0.4f), _downsampleFactor(3), + _samples(0l), _vertices(0l), + // three in -> one out, some filtering (see details in Log.h) + _lowPassCoeff(0.4f), _downsampleRatio(3), enabled(isEnabled), inputPaused(false) { // allocate enough space for the sample data and to turn it into @@ -94,9 +95,9 @@ void Oscilloscope::render(int x, int y) { return; } - // determine lowpass / downsample factors - int lowpass = -int(std::numeric_limits::min()) * _lowpassFactor; - unsigned downsample = _downsampleFactor; + // fetch low pass factor (and convert to fix point) / downsample factor + int lowPassFixPt = -int(std::numeric_limits::min()) * _lowPassCoeff; + unsigned downsample = _downsampleRatio; // keep half of the buffer for writing and ensure an even vertex count unsigned usedWidth = min(_width, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; unsigned usedSamples = usedWidth * downsample; @@ -115,7 +116,7 @@ void Oscilloscope::render(int x, int y) { inPtr = endPtr; } // read and (eventually) filter sample - sample += ((*--inPtr - sample) * lowpass) >> 15; + sample += ((*--inPtr - sample) * lowPassFixPt) >> 15; // write every nth as y with a corresponding x-coordinate if (i % downsample == 0) { *outPtr++ = short(--x); diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index e13ecb1ce9..fcf362b6bc 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -17,17 +17,43 @@ public: ~Oscilloscope(); void addSamples(unsigned ch, short const* data, unsigned n); - + void render(int x, int y); - static unsigned const MAX_CHANNELS = 3; - static unsigned const MAX_SAMPLES_PER_CHANNEL = 4096; - + // Switches: On/Off, Stop Time volatile bool enabled; volatile bool inputPaused; - void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _lowpassFactor = w; } - void setDownsampling(unsigned f) { assert(f > 0); _downsampleFactor = f; } + // Limits + static unsigned const MAX_CHANNELS = 3; + static unsigned const MAX_SAMPLES_PER_CHANNEL = 4096; + + // Controls a simple one pole IIR low pass filter that is provided to + // reduce high frequencies aliasing (to lower ones) when downsampling. + // + // The parameter sets the influence of the input in respect to the + // feed-back signal on the output. + // + // +---------+ + // in O--------------|+ ideal |--o--------------O out + // .---|- op amp | | + // | +---------+ | + // | | + // o-------||-------o + // | | + // | __V__ + // -------------|_____|-------+ + // : : | + // 0.0 - 1.0 (GND) + // + // The values in range 0.0 - 1.0 correspond to "all closed" (input has + // no influence on the output) to "all open" (feedback has no influence + // on the output) configurations. + void setLowpassOpenness(float w) { assert(w >= 0.0f && w <= 1.0f); _lowPassCoeff = w; } + + // Sets the number of input samples per output sample. Without filtering + // just uses every nTh sample. + void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; } private: // don't copy/assign @@ -42,8 +68,8 @@ private: short* _vertices; unsigned _writePos[MAX_CHANNELS]; - float _lowpassFactor; - unsigned _downsampleFactor; + float _lowpassCoeff; + unsigned _downsampleRatio; }; #endif /* defined(__interface__oscilloscope__) */ From e70efe74814df0c85ad469b52c7156229429501e Mon Sep 17 00:00:00 2001 From: tosh Date: Mon, 20 May 2013 23:37:06 +0200 Subject: [PATCH 14/17] fixes improper merge / changes --- interface/src/Oscilloscope.cpp | 3 +-- interface/src/Oscilloscope.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index 87fa1e3688..5fbd747f0d 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -32,7 +32,6 @@ namespace { // everything in here only exists while compiling this .cpp file } -<<<<<<< HEAD Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : enabled(isEnabled), inputPaused(false), @@ -44,7 +43,7 @@ Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : _lowPassCoeff(0.4f), // three in -> one out _downsampleRatio(3) { -{ + // allocate enough space for the sample data and to turn it into // vertices and since they're all 'short', do so in one shot _samples = new short[N_INT16_TO_ALLOC]; diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index fcf362b6bc..65616e701b 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -68,7 +68,7 @@ private: short* _vertices; unsigned _writePos[MAX_CHANNELS]; - float _lowpassCoeff; + float _lowPassCoeff; unsigned _downsampleRatio; }; From 4385fc31e89d12b938e65c12aafabd069b888703 Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 21 May 2013 00:59:29 +0200 Subject: [PATCH 15/17] adds missing include "InterfaceConfig.h" for OpenGL types --- interface/src/ui/TextRenderer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 643c3ede8c..ff484066d8 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -15,6 +15,8 @@ #include #include +#include "InterfaceConfig.h" + // a special "character" that renders as a solid block const char SOLID_BLOCK_CHAR = 127; From a86b8a1d93ea9c31e298f5c03474eb7f39cede72 Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 21 May 2013 01:00:10 +0200 Subject: [PATCH 16/17] refactors logging --- interface/src/Application.cpp | 11 +- interface/src/Log.cpp | 364 ------------------ interface/src/Log.h | 68 ---- interface/src/LogDisplay.cpp | 306 +++++++++++++++ interface/src/LogDisplay.h | 80 ++++ interface/src/LogStream.h | 106 ----- libraries/avatars/src/AvatarData.cpp | 4 +- libraries/avatars/src/Orientation.cpp | 3 - libraries/avatars/src/avatars_Log.cpp | 17 - libraries/avatars/src/avatars_Log.h | 20 - libraries/shared/src/Agent.cpp | 6 +- libraries/shared/src/AgentList.cpp | 4 +- .../src/voxels_Log.cpp => shared/src/Log.cpp} | 10 +- libraries/shared/src/{shared_Log.h => Log.h} | 15 +- libraries/shared/src/OctalCode.cpp | 4 +- libraries/shared/src/PerfStat.cpp | 4 +- libraries/shared/src/SharedUtil.cpp | 4 +- libraries/shared/src/UDPSocket.cpp | 4 +- libraries/shared/src/UrlReader.cpp | 3 +- libraries/shared/src/shared_Log.cpp | 17 - libraries/voxels/src/Plane.cpp | 5 +- libraries/voxels/src/ViewFrustum.cpp | 3 +- libraries/voxels/src/VoxelNode.cpp | 5 +- libraries/voxels/src/VoxelTree.cpp | 4 +- libraries/voxels/src/voxels_Log.h | 20 - 25 files changed, 414 insertions(+), 673 deletions(-) delete mode 100644 interface/src/Log.cpp delete mode 100644 interface/src/Log.h create mode 100644 interface/src/LogDisplay.cpp create mode 100644 interface/src/LogDisplay.h delete mode 100644 interface/src/LogStream.h delete mode 100644 libraries/avatars/src/avatars_Log.cpp delete mode 100644 libraries/avatars/src/avatars_Log.h rename libraries/{voxels/src/voxels_Log.cpp => shared/src/Log.cpp} (50%) rename libraries/shared/src/{shared_Log.h => Log.h} (50%) delete mode 100644 libraries/shared/src/shared_Log.cpp delete mode 100644 libraries/voxels/src/voxels_Log.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 711f6d17a7..5db6bf2562 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -37,13 +37,10 @@ #include #include #include -#include -#include -#include #include "Application.h" #include "InterfaceConfig.h" -#include "Log.h" +#include "LogDisplay.h" #include "OculusManager.h" #include "Util.h" #include "renderer/ProgramObject.h" @@ -159,10 +156,6 @@ Application::Application(int& argc, char** argv) : _voxels.setViewFrustum(&_viewFrustum); - shared_lib::printLog = & ::printLog; - voxels_lib::printLog = & ::printLog; - avatars_lib::printLog = & ::printLog; - unsigned int listenPort = AGENT_SOCKET_LISTEN_PORT; const char** constArgv = const_cast(argv); const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); @@ -1772,7 +1765,7 @@ void Application::displayOverlay() { glPointSize(1.0f); if (_renderStatsOn->isChecked()) { displayStats(); } - if (_logOn->isChecked()) { logdisplay::Render(_glWidget->width(), _glWidget->height()); } + if (_logOn->isChecked()) { LogDisplay::instance.render(_glWidget->width(), _glWidget->height()); } // Show chat entry field if (_chatEntryOn) { diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp deleted file mode 100644 index af3b2f90fb..0000000000 --- a/interface/src/Log.cpp +++ /dev/null @@ -1,364 +0,0 @@ -// -// Log.cpp -// interface -// -// Created by Tobias Schwinger on 4/14/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#include "Log.h" - - -#include -#include -#include - -#include "InterfaceConfig.h" - -#include "Util.h" -#include "ui/TextRenderer.h" - - -namespace logdisplay { - - class Logger { - public: - Logger(); - ~Logger(); - - inline void render(unsigned screenWidth, unsigned screenHeight); - - inline void setStream(FILE* stream); - inline void setLogWidth(unsigned pixels); - inline void setCharacterSize(unsigned width, unsigned height); - - // format, eventually forward, and add the log message (called by printLog) - inline int vprint(char const* fmt, va_list); - - private: - // don't copy/assign - Logger(Logger const&); // = delete; - Logger& operator=(Logger const&); // = delete; - - // add formatted message for console diplay (called by vprint) - inline void addMessage(char const*); - - TextRenderer _textRenderer; - FILE* _stream; // FILE as secondary destination for log messages - char* _chars; // character buffer base address - char* _charsEnd; // character buffer, exclusive end - char** _lines; // line buffer base address - char** _linesEnd; // line buffer, exclusive end - - char* _writePos; // character position to write to - char* _writeLineStartPos; // character position where line being written starts - char** _lastLinePos; // last line in the log - unsigned _writtenInLine; // character counter for line wrapping - unsigned _lineLength; // number of characters before line wrap - - unsigned _logWidth; // width of the log in pixels - unsigned _charWidth; // width of a character in pixels - unsigned _charHeight; // height of a character in pixels - - pthread_mutex_t _mutex; - }; - - - // - // Initialization / state management - // - - Logger::Logger() : - - _textRenderer(MONO_FONT_FAMILY, -1, -1, false, TextRenderer::SHADOW_EFFECT), - _stream(DEFAULT_STREAM), - _chars(0l), - _lines(0l), - _logWidth(DEFAULT_CONSOLE_WIDTH) { - - pthread_mutex_init(& _mutex, 0l); - - // allocate twice as much (so we have spare space for a copy not to block - // logging from other threads during 'render') - _chars = new char[CHARACTER_BUFFER_SIZE * 2]; - _charsEnd = _chars + CHARACTER_BUFFER_SIZE; - _lines = new char*[LINE_BUFFER_SIZE * 2]; - _linesEnd = _lines + LINE_BUFFER_SIZE; - - // initialize the log to all empty lines - _chars[0] = '\0'; - _writePos = _chars; - _writeLineStartPos = _chars; - _lastLinePos = _lines; - _writtenInLine = 0; - memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); - - setCharacterSize(DEFAULT_CHAR_WIDTH, DEFAULT_CHAR_HEIGHT); - } - - - Logger::~Logger() { - - delete[] _chars; - delete[] _lines; - } - - inline void Logger::setStream(FILE* stream) { - - pthread_mutex_lock(& _mutex); - _stream = stream; - pthread_mutex_unlock(& _mutex); - } - - inline void Logger::setLogWidth(unsigned pixels) { - - pthread_mutex_lock(& _mutex); - _logWidth = pixels; - _lineLength = _logWidth / _charWidth; - pthread_mutex_unlock(& _mutex); - } - - inline void Logger::setCharacterSize(unsigned width, unsigned height) { - - pthread_mutex_lock(& _mutex); - _charWidth = width; - _charHeight = height; - _lineLength = _logWidth / _charWidth; - pthread_mutex_unlock(& _mutex); - } - - // - // Logging - // - - inline int Logger::vprint(char const* fmt, va_list args) { - pthread_mutex_lock(& _mutex); - - // print to buffer - char buf[MAX_MESSAGE_LENGTH]; - int n = vsnprintf(buf, MAX_MESSAGE_LENGTH, fmt, args); - if (n > 0) { - - // all fine? log the message - addMessage(buf); - - } else { - - // error? -> mutter on stream or stderr - fprintf(_stream != 0l ? _stream : stderr, - "Log: Failed to log message with format string = \"%s\".\n", fmt); - } - - pthread_mutex_unlock(& _mutex); - return n; - } - - inline void Logger::addMessage(char const* ptr) { - - // precondition: mutex is locked so noone gets in our way - - // T-pipe, if requested - if (_stream != 0l) { - fprintf(_stream, "%s", ptr); - } - - while (*ptr != '\0') { - // process the characters - char c = *ptr++; - - if (c == '\t') { - - // found TAB -> write SPACE - c = ' '; - - } else if (c == '\n') { - - // found LF -> write NUL (c == '\0' tells us to wrap, below) - c = '\0'; - } - *_writePos++ = c; - - if (_writePos == _charsEnd) { - // reached the end of the circular character buffer? -> start over - _writePos = _chars; - } - - if (++_writtenInLine >= _lineLength || c == '\0') { - - // new line? store its start to the line buffer and mark next line as empty - ++_lastLinePos; - - if (_lastLinePos == _linesEnd) { - _lastLinePos = _lines; - _lastLinePos[1] = 0l; - } else if (_lastLinePos + 1 != _linesEnd) { - _lastLinePos[1] = 0l; - } else { - _lines[0] = 0l; - } - *_lastLinePos = _writeLineStartPos; - - // debug mode: make sure all line pointers we write here are valid - assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); - assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); - - // terminate line, unless done already - if (c != '\0') { - *_writePos++ = '\0'; - - if (_writePos == _charsEnd) { - _writePos = _chars; - } - } - - // remember start position in character buffer for next line and reset character count - _writeLineStartPos = _writePos; - _writtenInLine = 0; - } - } - - } - - // - // Rendering - // - - inline void Logger::render(unsigned screenWidth, unsigned screenHeight) { - - // rendering might take some time, so create a local copy of the portion we need - // instead of having to hold the mutex all the time - pthread_mutex_lock(& _mutex); - - // determine number of visible lines (integer division rounded up) - unsigned showLines = (screenHeight + _charHeight - 1) / _charHeight; - - char** lastLine = _lastLinePos; - char** firstLine = _lastLinePos; - - if (! *lastLine) { - // empty log - pthread_mutex_unlock(& _mutex); - return; - } - - // scan for first line - for (int n = 2; n <= showLines; ++n) { - - char** prevFirstLine = firstLine; - --firstLine; - if (firstLine < _lines) { - firstLine = _linesEnd - 1; - } - if (! *firstLine) { - firstLine = prevFirstLine; - showLines = n - 1; - break; - } - - // debug mode: make sure all line pointers we find here are valid - assert(! (firstLine < _lines || firstLine >= _linesEnd)); - assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); - } - - // copy the line buffer portion into a contiguous region at _linesEnd - if (firstLine <= lastLine) { - - memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); - - } else { - - unsigned atEnd = _linesEnd - firstLine; - memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); - memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); - } - - // copy relevant char buffer portion and determine information to remap the pointers - char* firstChar = *firstLine; - char* lastChar = *lastLine + strlen(*lastLine) + 1; - ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; - if (firstChar <= lastChar) { - - memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); - - } else { - - unsigned atEnd = _charsEnd - firstChar; - memcpy(_charsEnd, firstChar, atEnd); - memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); - - charOffsetBeforeFirst = _charsEnd + atEnd - _chars; - } - - // determine geometry information from font metrics - QFontMetrics const& fontMetrics = _textRenderer.metrics(); - int yStep = fontMetrics.lineSpacing(); - // scale - float xScale = float(_charWidth) / fontMetrics.width('*'); - float yScale = float(_charHeight) / yStep; - // scaled translation - int xStart = int((screenWidth - _logWidth) / xScale); - int yStart = screenHeight / yScale - fontMetrics.descent(); - - // first line to render - char** line = _linesEnd + showLines; - - // ok, now the lock can be released - we have all we need - // and won't hold it while talking to OpenGL - pthread_mutex_unlock(& _mutex); - - glPushMatrix(); - glScalef(xScale, yScale, 1.0f); - for (int y = yStart; y > 0; y -= yStep) { - - // debug mode: check line pointer is valid - assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); - - // get character pointer - if (--line < _linesEnd) { - break; - } - char* chars = *line; - - // debug mode: check char pointer we find is valid - assert(! (chars < _chars || chars >= _charsEnd)); - - // remap character pointer it to copied buffer - chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; - - // debug mode: check char pointer is still valid (in new range) - assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); - - // render the string - glColor3f(TEXT_COLOR_RED, TEXT_COLOR_GREEN, TEXT_COLOR_BLUE); - _textRenderer.draw(xStart, y, chars); - - //fprintf(stderr, "Logger::render, message = \"%s\"\n", chars); - } - glPopMatrix(); - } - - - // - // There's one Logger and it exists globally... - // - Logger logger; - - // Entrypoints - void Render(unsigned screenWidth, unsigned screenHeight) { logger.render(screenWidth, screenHeight); } - void SetStream(FILE* stream) { logger.setStream(stream); } - void SetLogWidth(unsigned pixels) { logger.setLogWidth(pixels); } - void SetCharacterSize(unsigned width, unsigned height) { logger.setCharacterSize(width, height); } - -} // namespace logdisplay - - -int printLog(char const* fmt, ...) { - - int result; - va_list args; - va_start(args,fmt); - result = logdisplay::logger.vprint(fmt, args); - va_end(args); - return result; -} - diff --git a/interface/src/Log.h b/interface/src/Log.h deleted file mode 100644 index 2293c39a76..0000000000 --- a/interface/src/Log.h +++ /dev/null @@ -1,68 +0,0 @@ -// -// Log.h -// interface -// -// Created by Tobias Schwinger on 4/14/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__Log__ -#define __interface__Log__ - -#include -#include - -// -// Log function. Call it as you would call 'printf'. -// -int printLog(char const* fmt, ...); - -// -// Logging control. -// -namespace logdisplay { - - void Render(unsigned screenWidth, unsigned screenHeight); - - // settings - - static float const TEXT_COLOR_RED = 0.7f; // text foreground color, red component - static float const TEXT_COLOR_GREEN = 0.6f; // text foreground color, green component - static float const TEXT_COLOR_BLUE = 1.0f; // text foregdound color, blue component - - static FILE* DEFAULT_STREAM = stdout; // stream to also log to - static unsigned const DEFAULT_CHAR_WIDTH = 7; // width of a single character - static unsigned const DEFAULT_CHAR_HEIGHT = 16; // height of a single character - static unsigned const DEFAULT_CONSOLE_WIDTH = 400; // width of the (right-aligned) log console - - void SetStream(FILE* stream); - void SetLogWidth(unsigned pixels); - void SetCharacterSize(unsigned width, unsigned height); - - // limits - - unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered - unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered - unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message -} - -// -// Macro to log OpenGL errors. -// Example: printGlError( glPushMatrix() ); -// -#define printLogGlError(stmt) \ - stmt; \ - { \ - GLenum e = glGetError(); \ - if (e != GL_NO_ERROR) { \ - printLog(__FILE__ ":" printLogGlError_stringize(__LINE__) \ - " [OpenGL] %s\n", gluErrorString(e)); \ - } \ - } \ - (void) 0 - -#define printLogGlError_stringize(x) printLogGlError_stringize_i(x) -#define printLogGlError_stringize_i(x) # x - -#endif - diff --git a/interface/src/LogDisplay.cpp b/interface/src/LogDisplay.cpp new file mode 100644 index 0000000000..fc1f1abf23 --- /dev/null +++ b/interface/src/LogDisplay.cpp @@ -0,0 +1,306 @@ +// +// LogDisplay.cpp +// interface +// +// Created by Tobias Schwinger on 4/14/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include "LogDisplay.h" + +#include +#include +#include + +#include "Util.h" + +using namespace std; +FILE* const LogDisplay::DEFAULT_STREAM = stdout; + +// +// Singleton constructor +// +LogDisplay LogDisplay::instance; + +// +// State management +// + +LogDisplay::LogDisplay() : + + _textRenderer(MONO_FONT_FAMILY, -1, -1, false, TextRenderer::SHADOW_EFFECT), + _stream(DEFAULT_STREAM), + _chars(0l), + _lines(0l), + _logWidth(DEFAULT_CONSOLE_WIDTH) { + + pthread_mutex_init(& _mutex, 0l); + + // allocate twice as much (so we have spare space for a copy not to block + // logging from other threads during 'render') + _chars = new char[CHARACTER_BUFFER_SIZE * 2]; + _charsEnd = _chars + CHARACTER_BUFFER_SIZE; + _lines = new char*[LINE_BUFFER_SIZE * 2]; + _linesEnd = _lines + LINE_BUFFER_SIZE; + + // initialize the log to all empty lines + _chars[0] = '\0'; + _writePos = _chars; + _writeLineStartPos = _chars; + _lastLinePos = _lines; + _writtenInLine = 0; + memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); + + setCharacterSize(DEFAULT_CHAR_WIDTH, DEFAULT_CHAR_HEIGHT); + + printLog = & printLogHandler; +} + + +LogDisplay::~LogDisplay() { + + delete[] _chars; + delete[] _lines; +} + +void LogDisplay::setStream(FILE* stream) { + + pthread_mutex_lock(& _mutex); + _stream = stream; + pthread_mutex_unlock(& _mutex); +} + +void LogDisplay::setLogWidth(unsigned pixels) { + + pthread_mutex_lock(& _mutex); + _logWidth = pixels; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); +} + +void LogDisplay::setCharacterSize(unsigned width, unsigned height) { + + pthread_mutex_lock(& _mutex); + _charWidth = width; + _charHeight = height; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); +} + +// +// Logging +// + +int LogDisplay::printLogHandler(char const* fmt, ...) { + + va_list args; + int n; + char buf[MAX_MESSAGE_LENGTH]; + va_start(args,fmt); + + // print to buffer + n = vsnprintf(buf, MAX_MESSAGE_LENGTH, fmt, args); + if (n > 0) { + + // all fine? log the message + instance.addMessage(buf); + + } else { + + // error? -> mutter on stream or stderr + fprintf(instance._stream != 0l ? instance._stream : stderr, + "Log: Failed to log message with format string = \"%s\".\n", fmt); + } + + va_end(args); + return n; +} + +inline void LogDisplay::addMessage(char const* ptr) { + + pthread_mutex_lock(& _mutex); + + // T-pipe, if requested + if (_stream != 0l) { + fprintf(_stream, "%s", ptr); + } + + while (*ptr != '\0') { + // process the characters + char c = *ptr++; + + if (c == '\t') { + + // found TAB -> write SPACE + c = ' '; + + } else if (c == '\n') { + + // found LF -> write NUL (c == '\0' tells us to wrap, below) + c = '\0'; + } + *_writePos++ = c; + + if (_writePos == _charsEnd) { + // reached the end of the circular character buffer? -> start over + _writePos = _chars; + } + + if (++_writtenInLine >= _lineLength || c == '\0') { + + // new line? store its start to the line buffer and mark next line as empty + ++_lastLinePos; + + if (_lastLinePos == _linesEnd) { + _lastLinePos = _lines; + _lastLinePos[1] = 0l; + } else if (_lastLinePos + 1 != _linesEnd) { + _lastLinePos[1] = 0l; + } else { + _lines[0] = 0l; + } + *_lastLinePos = _writeLineStartPos; + + // debug mode: make sure all line pointers we write here are valid + assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); + assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); + + // terminate line, unless done already + if (c != '\0') { + *_writePos++ = '\0'; + + if (_writePos == _charsEnd) { + _writePos = _chars; + } + } + + // remember start position in character buffer for next line and reset character count + _writeLineStartPos = _writePos; + _writtenInLine = 0; + } + } + + pthread_mutex_unlock(& _mutex); +} + +// +// Rendering +// + +void LogDisplay::render(unsigned screenWidth, unsigned screenHeight) { + + // rendering might take some time, so create a local copy of the portion we need + // instead of having to hold the mutex all the time + pthread_mutex_lock(& _mutex); + + // determine number of visible lines (integer division rounded up) + unsigned showLines = (screenHeight + _charHeight - 1) / _charHeight; + + char** lastLine = _lastLinePos; + char** firstLine = _lastLinePos; + + if (! *lastLine) { + // empty log + pthread_mutex_unlock(& _mutex); + return; + } + + // scan for first line + for (int n = 2; n <= showLines; ++n) { + + char** prevFirstLine = firstLine; + --firstLine; + if (firstLine < _lines) { + firstLine = _linesEnd - 1; + } + if (! *firstLine) { + firstLine = prevFirstLine; + showLines = n - 1; + break; + } + + // debug mode: make sure all line pointers we find here are valid + assert(! (firstLine < _lines || firstLine >= _linesEnd)); + assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); + } + + // copy the line buffer portion into a contiguous region at _linesEnd + if (firstLine <= lastLine) { + + memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); + + } else { + + unsigned atEnd = _linesEnd - firstLine; + memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); + memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); + } + + // copy relevant char buffer portion and determine information to remap the pointers + char* firstChar = *firstLine; + char* lastChar = *lastLine + strlen(*lastLine) + 1; + ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; + if (firstChar <= lastChar) { + + memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); + + } else { + + unsigned atEnd = _charsEnd - firstChar; + memcpy(_charsEnd, firstChar, atEnd); + memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); + + charOffsetBeforeFirst = _charsEnd + atEnd - _chars; + } + + // determine geometry information from font metrics + QFontMetrics const& fontMetrics = _textRenderer.metrics(); + int yStep = fontMetrics.lineSpacing(); + // scale + float xScale = float(_charWidth) / fontMetrics.width('*'); + float yScale = float(_charHeight) / yStep; + // scaled translation + int xStart = int((screenWidth - _logWidth) / xScale); + int yStart = screenHeight / yScale - fontMetrics.descent(); + + // first line to render + char** line = _linesEnd + showLines; + + // ok, now the lock can be released - we have all we need + // and won't hold it while talking to OpenGL + pthread_mutex_unlock(& _mutex); + + glPushMatrix(); + glScalef(xScale, yScale, 1.0f); + for (int y = yStart; y > 0; y -= yStep) { + + // debug mode: check line pointer is valid + assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); + + // get character pointer + if (--line < _linesEnd) { + break; + } + char* chars = *line; + + // debug mode: check char pointer we find is valid + assert(! (chars < _chars || chars >= _charsEnd)); + + // remap character pointer it to copied buffer + chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; + + // debug mode: check char pointer is still valid (in new range) + assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); + + // render the string + glColor3ub(GLubyte(TEXT_COLOR >> 16), + GLubyte((TEXT_COLOR >> 8) & 0xff), + GLubyte(TEXT_COLOR & 0xff)); + _textRenderer.draw(xStart, y, chars); + +//fprintf(stderr, "LogDisplay::render, message = \"%s\"\n", chars); + } + glPopMatrix(); +} + + diff --git a/interface/src/LogDisplay.h b/interface/src/LogDisplay.h new file mode 100644 index 0000000000..625e84be25 --- /dev/null +++ b/interface/src/LogDisplay.h @@ -0,0 +1,80 @@ +// +// LogDisplay.h +// interface +// +// Created by Tobias Schwinger on 4/14/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__LogDisplay__ +#define __interface__LogDisplay__ + +#include +#include + +#include "Log.h" +#include "ui/TextRenderer.h" + +class LogDisplay { +public: + + static LogDisplay instance; + + void render(unsigned screenWidth, unsigned screenHeight); + + // settings + + static unsigned const TEXT_COLOR = 0xb299ff; // text foreground color (bytes, RGB) + + static FILE* const DEFAULT_STREAM; // = stdout; // stream to also log to (defined in .cpp) + static unsigned const DEFAULT_CHAR_WIDTH = 7; // width of a single character + static unsigned const DEFAULT_CHAR_HEIGHT = 16; // height of a single character + static unsigned const DEFAULT_CONSOLE_WIDTH = 400; // width of the (right-aligned) log console + + void setStream(FILE* stream); + void setLogWidth(unsigned pixels); + void setCharacterSize(unsigned width, unsigned height); + + // limits + + static unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered + static unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered + static unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message + +private: + // use static 'instance' to access the single instance + LogDisplay(); + ~LogDisplay(); + + // don't copy/assign + LogDisplay(LogDisplay const&); // = delete; + LogDisplay& operator=(LogDisplay const&); // = delete; + + // format and log message - entrypoint used to replace global 'printLog' + static int static printLogHandler(char const* fmt, ...); + + // log formatted message (called by printLogHandler) + inline void addMessage(char const*); + + TextRenderer _textRenderer; + FILE* _stream; // FILE as secondary destination for log messages + char* _chars; // character buffer base address + char* _charsEnd; // character buffer, exclusive end + char** _lines; // line buffer base address + char** _linesEnd; // line buffer, exclusive end + + char* _writePos; // character position to write to + char* _writeLineStartPos; // character position where line being written starts + char** _lastLinePos; // last line in the log + unsigned _writtenInLine; // character counter for line wrapping + unsigned _lineLength; // number of characters before line wrap + + unsigned _logWidth; // width of the log in pixels + unsigned _charWidth; // width of a character in pixels + unsigned _charHeight; // height of a character in pixels + + pthread_mutex_t _mutex; +}; + +#endif + diff --git a/interface/src/LogStream.h b/interface/src/LogStream.h deleted file mode 100644 index 2b8cc25669..0000000000 --- a/interface/src/LogStream.h +++ /dev/null @@ -1,106 +0,0 @@ -// -// LogStream.h -// interface -// -// Created by Tobias Schwinger on 4/17/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__LogStream__ -#define __interface__LogStream__ - -#include - -#include "Log.h" - -// -// Makes the logging facility accessible as a C++ stream. -// -// Example: -// -// // somewhere central - ideally one per thread (else pass 'true' as -// // second constructor argument and compromise some efficiency) -// LogStream lOut(printLog); -// -// // elsewhere: -// lOut << "Hello there!" << std::endl; -// -class LogStream { - std::ostringstream _outStream; - Log& _logRef; - bool _isThreadSafe; -public: - inline LogStream(Log& log, bool threadSafe = false); - - class StreamRef; friend class StreamRef; - - template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&); - -private: - // don't - LogStream(LogStream const&); // = delete; - LogStream& operator=(LogStream const&); // = delete; - - inline void ostreamBegin(); - inline void ostreamEnd(); -}; - -inline LogStream::LogStream(Log& log, bool threadSafe) : - _outStream(std::ios_base::out), _logRef(log), _isThreadSafe(threadSafe) { } - -inline void LogStream::ostreamBegin() { - - if (_isThreadSafe) { - // the user wants to share this LogStream among threads, - // so lock the global log here, already - pthread_mutex_lock(& _logRef._mutex); - } - _outStream.str(""); -} - -inline void LogStream::ostreamEnd() { - - if (! _isThreadSafe) { - // haven't locked, so far (we have memory for each thread) - pthread_mutex_lock(& _logRef._mutex); - } - _logRef.addMessage(_outStream.str().c_str()); - pthread_mutex_unlock(& _logRef._mutex); -} - - -// -// The Log::StreamRef class makes operator<< work. It... -// -class LogStream::StreamRef { - mutable LogStream* _logStream; - typedef std::ostream& (*manipulator)(std::ostream&); - - friend class LogStream; - - template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&); - StreamRef(LogStream* log) : _logStream(log) { } -public: - // ...forwards << operator calls to stringstream... - template< typename T > StreamRef const operator<<(T const& x) const { _logStream->_outStream << x; return *this; } - // ...has to dance around to make manipulators (such as std::hex, std::endl) work... - StreamRef const operator<<(manipulator x) const { _logStream->_outStream << x; return *this; } - // ...informs the logger that a stream has ended when it has the responsibility... - ~StreamRef() { if (_logStream != 0l) { _logStream->ostreamEnd(); } } - // ...which is passed on upon copy. - StreamRef(StreamRef const& other) : _logStream(other._logStream) { other._logStream = 0l; } - -private: - // don't - StreamRef& operator=(StreamRef const&); // = delete; -}; - -template< typename T > inline LogStream::StreamRef const operator<<(LogStream& s, T const& x) { - - s.ostreamBegin(); - s._outStream << x; - return LogStream::StreamRef(& s); // calls streamEnd at the end of the stream expression -} - - -#endif diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 22dd33ae65..dc875fd4db 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -14,10 +14,8 @@ #include #include "AvatarData.h" -#include "avatars_Log.h" using namespace std; -using avatars_lib::printLog; int packFloatAngleToTwoByte(unsigned char* buffer, float angle) { const float ANGLE_CONVERSION_RATIO = (std::numeric_limits::max() / 360.0); @@ -224,4 +222,4 @@ void AvatarData::setHeadPitch(float p) { const float MAX_PITCH = 60; const float MIN_PITCH = -60; _headPitch = glm::clamp(p, MIN_PITCH, MAX_PITCH); -} \ No newline at end of file +} diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index 6466eb802c..1d26e99e49 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -7,9 +7,6 @@ #include "Orientation.h" #include "SharedUtil.h" -//#include "avatars_Log.h" - -//using avatars_lib::printLog; static const bool USING_QUATERNIONS = true; diff --git a/libraries/avatars/src/avatars_Log.cpp b/libraries/avatars/src/avatars_Log.cpp deleted file mode 100644 index da8712b755..0000000000 --- a/libraries/avatars/src/avatars_Log.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// avatars_Log.cpp -// hifi -// -// Created by Tobias Schwinger on 4/17/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#include "shared_Log.h" - -#include - -namespace avatars_lib { - using namespace std; - - int (* printLog)(char const*, ...) = & printf; -} diff --git a/libraries/avatars/src/avatars_Log.h b/libraries/avatars/src/avatars_Log.h deleted file mode 100644 index 1d07cf46bf..0000000000 --- a/libraries/avatars/src/avatars_Log.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// avatars_Log.h -// hifi -// -// Created by Tobias Schwinger on 4/17/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#ifndef __hifi__avatars_Log__ -#define __hifi__avatars_Log__ - -namespace avatars_lib { - - // variable that can be set from outside to redirect the log output - // of this library - extern int (* printLog)(char const*, ...); -} - -#endif /* defined(__hifi__avatars_Log__) */ - diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index f21f06eba6..9bddd45b84 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -10,7 +10,7 @@ #include "Agent.h" #include "AgentTypes.h" #include -#include "shared_Log.h" +#include "Log.h" #include "UDPSocket.h" #include "SharedUtil.h" @@ -20,8 +20,6 @@ #include #endif -using shared_lib::printLog; - int unpackAgentId(unsigned char* packedData, uint16_t* agentId) { memcpy(agentId, packedData, sizeof(uint16_t)); return sizeof(uint16_t); @@ -150,4 +148,4 @@ void Agent::printLog(Agent const& agent) { agent._type, publicAddressBuffer, publicAddressPort); -} \ No newline at end of file +} diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 3da956a04a..be7459b450 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -15,7 +15,7 @@ #include "AgentTypes.h" #include "PacketHeaders.h" #include "SharedUtil.h" -#include "shared_Log.h" +#include "Log.h" #ifdef _WIN32 #include "Syssocket.h" @@ -23,8 +23,6 @@ #include #endif -using shared_lib::printLog; - const char SOLO_AGENT_TYPES[3] = { AGENT_TYPE_AVATAR_MIXER, AGENT_TYPE_AUDIO_MIXER, diff --git a/libraries/voxels/src/voxels_Log.cpp b/libraries/shared/src/Log.cpp similarity index 50% rename from libraries/voxels/src/voxels_Log.cpp rename to libraries/shared/src/Log.cpp index 6fd637a1ec..2db1ab4288 100644 --- a/libraries/voxels/src/voxels_Log.cpp +++ b/libraries/shared/src/Log.cpp @@ -1,17 +1,15 @@ // -// voxels_Log.cpp +// Log.cpp // hifi // // Created by Tobias Schwinger on 4/17/13. // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // -#include "voxels_Log.h" +#include "Log.h" #include -namespace voxels_lib { - using namespace std; +using namespace std; +int (* printLog)(char const*, ...) = & printf; - int (* printLog)(char const*, ...) = & printf; -} diff --git a/libraries/shared/src/shared_Log.h b/libraries/shared/src/Log.h similarity index 50% rename from libraries/shared/src/shared_Log.h rename to libraries/shared/src/Log.h index 29c1a4ed57..e2bc77e1e8 100644 --- a/libraries/shared/src/shared_Log.h +++ b/libraries/shared/src/Log.h @@ -1,5 +1,5 @@ // -// shared_Log.h +// Log.h // hifi // // Created by Tobias Schwinger on 4/17/13. @@ -9,12 +9,13 @@ #ifndef __hifi__shared_Log__ #define __hifi__shared_Log__ -namespace shared_lib { - - // variable that can be set from outside to redirect the log output - // of this library - extern int (* printLog)(char const*, ...); -} +// +// Pointer to log function +// +// An application may reset this variable to receive the log messages +// issued using 'printLog'. It defaults to a pointer to 'printf'. +// +extern int (* printLog)(char const*, ...); #endif /* defined(__hifi__shared_Log__) */ diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index da2b017875..d218639882 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -11,9 +11,7 @@ #include #include "SharedUtil.h" #include "OctalCode.h" -#include "shared_Log.h" - -using shared_lib::printLog; +#include "Log.h" int numberOfThreeBitSectionsInCode(unsigned char * octalCode) { if (*octalCode == 255) { diff --git a/libraries/shared/src/PerfStat.cpp b/libraries/shared/src/PerfStat.cpp index 87998599aa..3c30c62993 100644 --- a/libraries/shared/src/PerfStat.cpp +++ b/libraries/shared/src/PerfStat.cpp @@ -14,9 +14,7 @@ #include #include -#include "shared_Log.h" - -using shared_lib::printLog; +#include "Log.h" // Static class members initialization here! std::map > PerfStat::groupHistoryMap; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 113b3fdda0..6e23413ea7 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -14,7 +14,7 @@ #ifdef _WIN32 #include "Syssocket.h" #endif -#include "shared_Log.h" +#include "Log.h" #include "SharedUtil.h" #include "OctalCode.h" @@ -22,8 +22,6 @@ #include #endif -using shared_lib::printLog; - double usecTimestamp(timeval *time) { return (time->tv_sec * 1000000.0 + time->tv_usec); } diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index 88930d4af4..48fc18ef04 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -21,9 +21,7 @@ #include #endif -#include "shared_Log.h" - -using shared_lib::printLog; +#include "Log.h" sockaddr_in destSockaddr, senderAddress; diff --git a/libraries/shared/src/UrlReader.cpp b/libraries/shared/src/UrlReader.cpp index 305db63667..638134f4dd 100644 --- a/libraries/shared/src/UrlReader.cpp +++ b/libraries/shared/src/UrlReader.cpp @@ -13,8 +13,7 @@ #include #include -#include "shared_Log.h" -using shared_lib::printLog; +#include "Log.h" #ifndef _WIN32 // (Windows port is incomplete and the build files do not support CURL, yet) diff --git a/libraries/shared/src/shared_Log.cpp b/libraries/shared/src/shared_Log.cpp deleted file mode 100644 index 93a5c74714..0000000000 --- a/libraries/shared/src/shared_Log.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// shared_Log.cpp -// hifi -// -// Created by Tobias Schwinger on 4/17/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#include "shared_Log.h" - -#include - -namespace shared_lib { - using namespace std; - - int (* printLog)(char const*, ...) = & printf; -} diff --git a/libraries/voxels/src/Plane.cpp b/libraries/voxels/src/Plane.cpp index d999306794..5a99bf29c4 100755 --- a/libraries/voxels/src/Plane.cpp +++ b/libraries/voxels/src/Plane.cpp @@ -9,11 +9,10 @@ // #include "Plane.h" + #include -#include "voxels_Log.h" - -using voxels_lib::printLog; +#include "Log.h" // These are some useful utilities that vec3 is missing void printVec3(const char* name, const glm::vec3& v) { diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index cce3eac76f..ba712c9655 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -14,9 +14,8 @@ #include "ViewFrustum.h" #include "SharedUtil.h" -#include "voxels_Log.h" +#include "Log.h" -using voxels_lib::printLog; using namespace std; ViewFrustum::ViewFrustum() : diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 6bab72cf61..5c983bda6b 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -10,14 +10,11 @@ #include #include #include "SharedUtil.h" -#include "voxels_Log.h" +#include "Log.h" #include "VoxelNode.h" #include "VoxelConstants.h" #include "OctalCode.h" #include "AABox.h" -using voxels_lib::printLog; - -// using voxels_lib::printLog; VoxelNode::VoxelNode() { unsigned char* rootCode = new unsigned char[1]; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 249a70212e..2c8943497d 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -13,7 +13,7 @@ #include #include #include "SharedUtil.h" -#include "voxels_Log.h" +#include "Log.h" #include "PacketHeaders.h" #include "OctalCode.h" #include "VoxelTree.h" @@ -24,8 +24,6 @@ #include -using voxels_lib::printLog; - int boundaryDistanceForRenderLevel(unsigned int renderLevel) { float voxelSizeScale = 50000.0f; return voxelSizeScale / powf(2, renderLevel); diff --git a/libraries/voxels/src/voxels_Log.h b/libraries/voxels/src/voxels_Log.h deleted file mode 100644 index 3403058a3d..0000000000 --- a/libraries/voxels/src/voxels_Log.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// voxels_Log.h -// hifi -// -// Created by Tobias Schwinger on 4/17/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#ifndef __hifi__voxels_Log__ -#define __hifi__voxels_Log__ - -namespace voxels_lib { - - // variable that can be set from outside to redirect the log output - // of this library - extern int (* printLog)(char const*, ...); -} - -#endif /* defined(__hifi__voxels_Log__) */ - From 0261f5029823886af08941688ca29185a6ce9ebc Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 21 May 2013 23:13:03 +0200 Subject: [PATCH 17/17] merge up --- libraries/avatars/src/AvatarData.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 5aaae9f3ad..e74cee6408 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -14,10 +14,8 @@ #include #include "AvatarData.h" -#include "avatars_Log.h" using namespace std; -using avatars_lib::printLog; int packFloatAngleToTwoByte(unsigned char* buffer, float angle) { const float ANGLE_CONVERSION_RATIO = (std::numeric_limits::max() / 360.0); @@ -238,4 +236,4 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { _wantDelta = oneAtBit(wantItems,WANT_DELTA_AT_BIT); return sourceBuffer - startPosition; -} \ No newline at end of file +}