Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid unnecessary copies during media/mesh loading
  • Loading branch information
sfan5 committed Mar 12, 2021
1 parent cff35cf commit 1bc85a4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/client/client.cpp
Expand Up @@ -663,12 +663,15 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
io::IFileSystem *irrfs = RenderingEngine::get_filesystem(); io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
video::IVideoDriver *vdrv = RenderingEngine::get_video_driver(); video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();


#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
io::IReadFile *rfile = irrfs->createMemoryReadFile(
data.c_str(), data.size(), "_tempreadfile");
#else
// Silly irrlicht's const-incorrectness // Silly irrlicht's const-incorrectness
Buffer<char> data_rw(data.c_str(), data.size()); Buffer<char> data_rw(data.c_str(), data.size());

// Create an irrlicht memory file
io::IReadFile *rfile = irrfs->createMemoryReadFile( io::IReadFile *rfile = irrfs->createMemoryReadFile(
*data_rw, data_rw.getSize(), "_tempreadfile"); *data_rw, data_rw.getSize(), "_tempreadfile");
#endif


FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file."); FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file.");


Expand Down Expand Up @@ -1914,9 +1917,14 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache)


// Create the mesh, remove it from cache and return it // Create the mesh, remove it from cache and return it
// This allows unique vertex colors and other properties for each instance // This allows unique vertex colors and other properties for each instance
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile(
data.c_str(), data.size(), filename.c_str());
#else
Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht
io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile( io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile(
*data_rw, data_rw.getSize(), filename.c_str()); *data_rw, data_rw.getSize(), filename.c_str());
#endif
FATAL_ERROR_IF(!rfile, "Could not create/open RAM file"); FATAL_ERROR_IF(!rfile, "Could not create/open RAM file");


scene::IAnimatedMesh *mesh = RenderingEngine::get_scene_manager()->getMesh(rfile); scene::IAnimatedMesh *mesh = RenderingEngine::get_scene_manager()->getMesh(rfile);
Expand Down

0 comments on commit 1bc85a4

Please sign in to comment.