Skip to content

Commit 1bc85a4

Browse files
committedMar 12, 2021
Avoid unnecessary copies during media/mesh loading
1 parent cff35cf commit 1bc85a4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎src/client/client.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,15 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
663663
io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
664664
video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();
665665

666+
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
667+
io::IReadFile *rfile = irrfs->createMemoryReadFile(
668+
data.c_str(), data.size(), "_tempreadfile");
669+
#else
666670
// Silly irrlicht's const-incorrectness
667671
Buffer<char> data_rw(data.c_str(), data.size());
668-
669-
// Create an irrlicht memory file
670672
io::IReadFile *rfile = irrfs->createMemoryReadFile(
671673
*data_rw, data_rw.getSize(), "_tempreadfile");
674+
#endif
672675

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

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.