From 29076c1d894b2cef1acb3534556724d1aa05ee17 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Mon, 21 Jan 2019 22:18:56 -0500 Subject: [PATCH] ignore 'info' messages from assimp --- TODO.md | 1 - src/mesh.cpp | 18 +++++++++----- src/util.cpp | 69 +++++++++++++++++++++++++++++++++------------------- src/util.h | 15 ++++++++++++ 4 files changed, 71 insertions(+), 32 deletions(-) diff --git a/TODO.md b/TODO.md index 5edf212..d1fd732 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ ## TODO: -- reduce verbosity of assimp loading - make hashmap grid type - find a better alternative to g_data_dir in scene_loader.cpp - position entities on grid hexes diff --git a/src/mesh.cpp b/src/mesh.cpp index 9225cc3..7c49e3c 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -14,23 +14,21 @@ // forward declarations +void assimpLogCB(const char* message, char* user); meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture); void freeMesh(meMeshInfo* mesh); inline glm::vec3 copyVector(aiVector3D v_in, glm::vec3& v_out); meMeshInfo* copyMeshInfo(const char* data_dir, const aiScene* scene, aiMesh* mesh); - // interface bool meInitAssimp() { LOG(INFO) << "Initializing Assimp\n"; - /* get a handle to the predefined STDOUT log stream and attach - * it to the logging system. It remains active for all further - * calls to aiImportFile(Ex) and aiApplyPostProcessing. */ - aiLogStream stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); - aiAttachLogStream(&stream); + aiLogStream ls; + ls.callback = assimpLogCB; + aiAttachLogStream(&ls); return true; } @@ -82,6 +80,14 @@ meShutdownAssimp() // internal +void +assimpLogCB(const char* message, char* user) +{ + // NOTE: filter 'info' messages from assimp + if (!utilMatchPrefix(message, "Info,", 5)) + LOG(INFO) << message << "\n"; +} + meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture) { diff --git a/src/util.cpp b/src/util.cpp index 0f3569f..d0dd037 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -19,6 +19,9 @@ const uint MAX_FILESIZE = 2 * 1024 * 1024; // 2MB const uint MAX_STRING_LENGTH = 1024; +//----------------- +// C Strings + const char* utilBaseName(const char* path_str) { @@ -59,6 +62,45 @@ utilConcatPath(char* out, const char* base_dir, const char* file_name, uint max_ return false; } +bool +utilMatchPrefix(const char* lhs, const char* rhs, int sz) +{ + int rc = strncmp(lhs, rhs, sz); + return (rc >= 0); +} + +//----------------- +// Memory allocation + +void * +utilLogAlloc(uint item_count, uint type_size, const char* file_name, const int line) +{ + assert(item_count > 0); // that was a fun bug + + void* mem = std::calloc(item_count, type_size); + + if (mem == nullptr) { + LOG(ERROR) << "Memory allocation failed, called from " + << file_name << ":" << line; + } + + assert(mem != nullptr); // might as well stop execution here + + return mem; +} + +// TODO: search/replace other calls to std::free with this +void utilSafeFree(const void* mem) +{ + if (mem != nullptr) { + std::free((void *) mem); + mem = nullptr; + } +} + +//----------------- +// File I/O + // TODO: don't use ftell() to get filesize // https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek%28%29+and+ftell%28%29+to+compute+the+size+of+a+regular+file char * @@ -112,31 +154,8 @@ utilWriteTextFile(const char* filename, const char* text) return false; } -void * -utilLogAlloc(uint item_count, uint type_size, const char* file_name, const int line) -{ - assert(item_count > 0); // that was a fun bug - - void* mem = std::calloc(item_count, type_size); - - if (mem == nullptr) { - LOG(ERROR) << "Memory allocation failed, called from " - << file_name << ":" << line; - } - - assert(mem != nullptr); // might as well stop execution here - - return mem; -} - -// TODO: search/replace other calls to std::free with this -void utilSafeFree(const void* mem) -{ - if (mem != nullptr) { - std::free((void *) mem); - mem = nullptr; - } -} +//----------------- +// utilImage util_image utilLoadImage(const char* base_dir, const char* filename) diff --git a/src/util.h b/src/util.h index 9538994..263111a 100644 --- a/src/util.h +++ b/src/util.h @@ -101,6 +101,9 @@ utilConvertColor(GLfloat buf[3], uint32 color) buf[2] = (GLfloat) ((color >> 8) & 0xFF) / (GLfloat) 255; } +//----------------- +// C Strings + // NOTE: max_len should be the allocated size of dest bool utilCopyCStr(char* dest, const char* src, uint max_len); @@ -110,16 +113,28 @@ bool utilConcatPath(char* out, const char* base_dir, const char* file_name, uint const char* utilBaseName(const char* path_str); +// NOTE: returns true if the first 'sz' characters from each string match +bool utilMatchPrefix(const char* lhs, const char* rhs, int sz); + +//----------------- +// Memory allocation + // NOTE: Wrapper for calloc that will send error message on out of memory #define UTIL_ALLOC(len, type) (type *) utilLogAlloc((len), sizeof(type), __FILE__, __LINE__) void* utilLogAlloc(uint item_count, uint type_size, const char* file_name, const int line); void utilSafeFree(const void* mem); +//----------------- +// File I/O + char* utilDumpTextFile(const char* filename); bool utilWriteTextFile(const char* filename, const char* text); +//----------------- +// utilImage + util_image utilLoadImage(const char* base_dir, const char* filename); void utilFreeImage(util_image image);