Browse Source

ignore 'info' messages from assimp

master
cinnaboot 8 years ago
parent
commit
29076c1d89
  1. 1
      TODO.md
  2. 18
      src/mesh.cpp
  3. 69
      src/util.cpp
  4. 15
      src/util.h

1
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

18
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)
{

69
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)

15
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);

Loading…
Cancel
Save