Drop dependency on FileSystem from SceneManager

This commit is contained in:
numzero 2023-03-14 18:34:47 +03:00 committed by sfan5
parent 0160cdc51d
commit 52a0b9d8e5
6 changed files with 14 additions and 74 deletions

@ -85,8 +85,12 @@ int main(int argc, char *argv[])
const io::path mediaPath = getExampleMediaPath();
scene::IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "coolguy_opt.x");
auto mesh_file = device->getFileSystem()->createAndOpenFile(mediaPath + "coolguy_opt.x");
check(mesh_file, "mesh file loading");
scene::IAnimatedMesh* mesh = smgr->getMesh(mesh_file);
check(mesh, "mesh loading");
if (mesh_file)
mesh_file->drop();
if (mesh)
{
video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");

@ -318,20 +318,10 @@ namespace scene
* \endcode
* If you would like to implement and add your own file format loader to Irrlicht,
* see addExternalMeshLoader().
* \param filename: Filename of the mesh to load.
* \param alternativeCacheName: In case you want to have the mesh under another name in the cache (to create real copies)
* \param file File handle of the mesh to load.
* \return Null if failed, otherwise pointer to the mesh.
* This pointer should not be dropped. See IReferenceCounted::drop() for more information.
**/
virtual IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName=io::path("")) = 0;
//! Get pointer to an animateable mesh. Loads the file if not loaded already.
/** Works just as getMesh(const char* filename). If you want to
remove a loaded mesh from the cache again, use removeMesh().
\param file File handle of the mesh to load.
\return NULL if failed and pointer to the mesh if successful.
This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */
virtual IAnimatedMesh* getMesh(io::IReadFile* file) = 0;
//! Get interface to the mesh cache which is shared between all existing scene managers.
@ -345,11 +335,6 @@ namespace scene
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
virtual video::IVideoDriver* getVideoDriver() = 0;
//! Get the active FileSystem
/** \return Pointer to the FileSystem
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
virtual io::IFileSystem* getFileSystem() = 0;
//! Adds a scene node for rendering an animated mesh model.
/** \param mesh: Pointer to the loaded animated mesh to be displayed.
\param parent: Parent of the scene node. Can be NULL if no parent.

@ -92,7 +92,7 @@ void CIrrDeviceStub::createGUIAndScene()
GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
// create Scene manager
SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl);
SceneManager = scene::createSceneManager(VideoDriver, CursorControl);
setEventReceiver(UserReceiver);
}

@ -24,7 +24,7 @@ namespace irr
namespace scene
{
ISceneManager* createSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, gui::ICursorControl* cc);
ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cc);
}
namespace io

@ -33,9 +33,9 @@ namespace scene
{
//! constructor
CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
CSceneManager::CSceneManager(video::IVideoDriver* driver,
gui::ICursorControl* cursorControl, IMeshCache* cache)
: ISceneNode(0, 0), Driver(driver), FileSystem(fs),
: ISceneNode(0, 0), Driver(driver),
CursorControl(cursorControl),
ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0),
MeshCache(cache), CurrentRenderPass(ESNRP_NONE)
@ -51,9 +51,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
if (Driver)
Driver->grab();
if (FileSystem)
FileSystem->grab();
if (CursorControl)
CursorControl->grab();
@ -92,9 +89,6 @@ CSceneManager::~CSceneManager()
if (Driver)
Driver->removeAllHardwareBuffers();
if (FileSystem)
FileSystem->drop();
if (CursorControl)
CursorControl->drop();
@ -125,29 +119,6 @@ CSceneManager::~CSceneManager()
}
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* CSceneManager::getMesh(const io::path& filename, const io::path& alternativeCacheName)
{
io::path cacheName = alternativeCacheName.empty() ? filename : alternativeCacheName;
IAnimatedMesh* msh = MeshCache->getMeshByName(cacheName);
if (msh)
return msh;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (!file)
{
os::Printer::log("Could not load mesh, because file could not be opened: ", filename, ELL_ERROR);
return 0;
}
msh = getUncachedMesh(file, filename, cacheName);
file->drop();
return msh;
}
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* CSceneManager::getMesh(io::IReadFile* file)
{
@ -202,15 +173,6 @@ video::IVideoDriver* CSceneManager::getVideoDriver()
}
//! Get the active FileSystem
/** \return Pointer to the FileSystem
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
io::IFileSystem* CSceneManager::getFileSystem()
{
return FileSystem;
}
//! adds a scene node for rendering a static mesh
//! the returned pointer must not be dropped.
IMeshSceneNode* CSceneManager::addMeshSceneNode(IMesh* mesh, ISceneNode* parent, s32 id,
@ -875,7 +837,7 @@ IMeshCache* CSceneManager::getMeshCache()
//! Creates a new scene manager.
ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent)
{
CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache);
CSceneManager* manager = new CSceneManager(Driver, CursorControl, MeshCache);
if (cloneContent)
manager->cloneMembers(this, manager);
@ -912,10 +874,9 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type)
// creates a scenemanager
ISceneManager* createSceneManager(video::IVideoDriver* driver,
io::IFileSystem* fs, gui::ICursorControl* cursorcontrol)
ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorcontrol)
{
return new CSceneManager(driver, fs, cursorcontrol, nullptr);
return new CSceneManager(driver, cursorcontrol, nullptr);
}

@ -31,15 +31,11 @@ namespace scene
public:
//! constructor
CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
gui::ICursorControl* cursorControl, IMeshCache* cache = nullptr);
CSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorControl, IMeshCache* cache = 0);
//! destructor
virtual ~CSceneManager();
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName) override;
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* getMesh(io::IReadFile* file) override;
@ -49,9 +45,6 @@ namespace scene
//! returns the video driver
video::IVideoDriver* getVideoDriver() override;
//! return the filesystem
io::IFileSystem* getFileSystem() override;
//! adds a scene node for rendering an animated mesh model
virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
@ -278,9 +271,6 @@ namespace scene
//! video driver
video::IVideoDriver* Driver;
//! file system
io::IFileSystem* FileSystem;
//! cursor control
gui::ICursorControl* CursorControl;