diff --git a/extlibs/CMakeLists.txt b/extlibs/CMakeLists.txt index 1b730c5..8315cac 100644 --- a/extlibs/CMakeLists.txt +++ b/extlibs/CMakeLists.txt @@ -20,6 +20,12 @@ add_library(sp2freetype STATIC ${FREETYPE_SOURCES}) target_include_directories(sp2freetype PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/freetype-2.9/include") target_compile_definitions(sp2freetype PRIVATE "-DFT2_BUILD_LIBRARY") +target_compile_options(box2d PRIVATE -fPIC) +target_compile_options(bullet PRIVATE -fPIC) +target_compile_options(lua PRIVATE -fPIC) +target_compile_options(miniz PRIVATE -fPIC) +target_compile_options(sp2freetype PRIVATE -fPIC) + if(SP2_OPTIMIZE_LIBS) target_compile_options(box2d PRIVATE ${OPTIMIZER_FLAGS}) target_compile_options(bullet PRIVATE ${OPTIMIZER_FLAGS}) diff --git a/include/sp2/graphics/mesh/glb.h b/include/sp2/graphics/mesh/glb.h index 0b7f102..6dcd661 100644 --- a/include/sp2/graphics/mesh/glb.h +++ b/include/sp2/graphics/mesh/glb.h @@ -31,6 +31,7 @@ class GLBLoader }; static const GLBFile& get(string resource_name); + static std::shared_ptr getMesh(string resource_name); private: GLBLoader(string resource_name); void handleNode(int node_id, GLBFile::Node& node); @@ -43,7 +44,8 @@ class GLBLoader nlohmann::json json; std::vector bindata; - static inline std::unordered_map files; + static std::unordered_map fileCache; + static std::unordered_map> meshCache; }; }//namespace sp diff --git a/src/graphics/mesh/glb.cpp b/src/graphics/mesh/glb.cpp index 1bd6c8b..6a203ed 100644 --- a/src/graphics/mesh/glb.cpp +++ b/src/graphics/mesh/glb.cpp @@ -3,6 +3,9 @@ namespace sp { +std::unordered_map GLBLoader::fileCache; +std::unordered_map> GLBLoader::meshCache; + std::shared_ptr GLBLoader::GLBFile::flatMesh() const { sp::MeshData::Vertices vertices; sp::MeshData::Indices indices; @@ -32,14 +35,24 @@ void GLBLoader::GLBFile::addToFlat(sp::MeshData::Vertices& vertices, sp::MeshDat addToFlat(vertices, indices, child, transform); } -const GLBLoader::GLBFile& GLBLoader::get(string resource_name) { - auto it = files.find(resource_name); - if (it != files.end()) +const GLBLoader::GLBFile& GLBLoader::get(string resource_name) +{ + auto it = fileCache.find(resource_name); + if (it != fileCache.end()) return it->second; - files[resource_name] = GLBLoader(resource_name).result; + fileCache[resource_name] = GLBLoader(resource_name).result; return get(resource_name); } +std::shared_ptr GLBLoader::getMesh(string resource_name) +{ + auto it = meshCache.find(resource_name); + if (it != meshCache.end()) + return it->second; + meshCache[resource_name] = get(resource_name).flatMesh(); + return getMesh(resource_name); +} + GLBLoader::GLBLoader(string resource_name) { auto resource = io::ResourceProvider::get(resource_name);