mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-18 05:33:52 +01:00
Drop dependency on FileSystem from SceneManager
This commit is contained in:
parent
0160cdc51d
commit
52a0b9d8e5
@ -85,8 +85,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const io::path mediaPath = getExampleMediaPath();
|
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");
|
check(mesh, "mesh loading");
|
||||||
|
if (mesh_file)
|
||||||
|
mesh_file->drop();
|
||||||
if (mesh)
|
if (mesh)
|
||||||
{
|
{
|
||||||
video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");
|
video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");
|
||||||
|
@ -318,20 +318,10 @@ namespace scene
|
|||||||
* \endcode
|
* \endcode
|
||||||
* If you would like to implement and add your own file format loader to Irrlicht,
|
* If you would like to implement and add your own file format loader to Irrlicht,
|
||||||
* see addExternalMeshLoader().
|
* see addExternalMeshLoader().
|
||||||
* \param filename: Filename of the mesh to load.
|
* \param file File handle 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)
|
|
||||||
* \return Null if failed, otherwise pointer to the mesh.
|
* \return Null if failed, otherwise pointer to the mesh.
|
||||||
* This pointer should not be dropped. See IReferenceCounted::drop() for more information.
|
* 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;
|
virtual IAnimatedMesh* getMesh(io::IReadFile* file) = 0;
|
||||||
|
|
||||||
//! Get interface to the mesh cache which is shared between all existing scene managers.
|
//! 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. */
|
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
|
||||||
virtual video::IVideoDriver* getVideoDriver() = 0;
|
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.
|
//! Adds a scene node for rendering an animated mesh model.
|
||||||
/** \param mesh: Pointer to the loaded animated mesh to be displayed.
|
/** \param mesh: Pointer to the loaded animated mesh to be displayed.
|
||||||
\param parent: Parent of the scene node. Can be NULL if no parent.
|
\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);
|
GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
|
||||||
|
|
||||||
// create Scene manager
|
// create Scene manager
|
||||||
SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl);
|
SceneManager = scene::createSceneManager(VideoDriver, CursorControl);
|
||||||
|
|
||||||
setEventReceiver(UserReceiver);
|
setEventReceiver(UserReceiver);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace irr
|
|||||||
|
|
||||||
namespace scene
|
namespace scene
|
||||||
{
|
{
|
||||||
ISceneManager* createSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, gui::ICursorControl* cc);
|
ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
|
@ -33,9 +33,9 @@ namespace scene
|
|||||||
{
|
{
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
|
CSceneManager::CSceneManager(video::IVideoDriver* driver,
|
||||||
gui::ICursorControl* cursorControl, IMeshCache* cache)
|
gui::ICursorControl* cursorControl, IMeshCache* cache)
|
||||||
: ISceneNode(0, 0), Driver(driver), FileSystem(fs),
|
: ISceneNode(0, 0), Driver(driver),
|
||||||
CursorControl(cursorControl),
|
CursorControl(cursorControl),
|
||||||
ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0),
|
ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0),
|
||||||
MeshCache(cache), CurrentRenderPass(ESNRP_NONE)
|
MeshCache(cache), CurrentRenderPass(ESNRP_NONE)
|
||||||
@ -51,9 +51,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
|
|||||||
if (Driver)
|
if (Driver)
|
||||||
Driver->grab();
|
Driver->grab();
|
||||||
|
|
||||||
if (FileSystem)
|
|
||||||
FileSystem->grab();
|
|
||||||
|
|
||||||
if (CursorControl)
|
if (CursorControl)
|
||||||
CursorControl->grab();
|
CursorControl->grab();
|
||||||
|
|
||||||
@ -92,9 +89,6 @@ CSceneManager::~CSceneManager()
|
|||||||
if (Driver)
|
if (Driver)
|
||||||
Driver->removeAllHardwareBuffers();
|
Driver->removeAllHardwareBuffers();
|
||||||
|
|
||||||
if (FileSystem)
|
|
||||||
FileSystem->drop();
|
|
||||||
|
|
||||||
if (CursorControl)
|
if (CursorControl)
|
||||||
CursorControl->drop();
|
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.
|
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
|
||||||
IAnimatedMesh* CSceneManager::getMesh(io::IReadFile* file)
|
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
|
//! adds a scene node for rendering a static mesh
|
||||||
//! the returned pointer must not be dropped.
|
//! the returned pointer must not be dropped.
|
||||||
IMeshSceneNode* CSceneManager::addMeshSceneNode(IMesh* mesh, ISceneNode* parent, s32 id,
|
IMeshSceneNode* CSceneManager::addMeshSceneNode(IMesh* mesh, ISceneNode* parent, s32 id,
|
||||||
@ -875,7 +837,7 @@ IMeshCache* CSceneManager::getMeshCache()
|
|||||||
//! Creates a new scene manager.
|
//! Creates a new scene manager.
|
||||||
ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent)
|
ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent)
|
||||||
{
|
{
|
||||||
CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache);
|
CSceneManager* manager = new CSceneManager(Driver, CursorControl, MeshCache);
|
||||||
|
|
||||||
if (cloneContent)
|
if (cloneContent)
|
||||||
manager->cloneMembers(this, manager);
|
manager->cloneMembers(this, manager);
|
||||||
@ -912,10 +874,9 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type)
|
|||||||
|
|
||||||
|
|
||||||
// creates a scenemanager
|
// creates a scenemanager
|
||||||
ISceneManager* createSceneManager(video::IVideoDriver* driver,
|
ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorcontrol)
|
||||||
io::IFileSystem* fs, gui::ICursorControl* cursorcontrol)
|
|
||||||
{
|
{
|
||||||
return new CSceneManager(driver, fs, cursorcontrol, nullptr);
|
return new CSceneManager(driver, cursorcontrol, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,15 +31,11 @@ namespace scene
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
|
CSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorControl, IMeshCache* cache = 0);
|
||||||
gui::ICursorControl* cursorControl, IMeshCache* cache = nullptr);
|
|
||||||
|
|
||||||
//! destructor
|
//! destructor
|
||||||
virtual ~CSceneManager();
|
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.
|
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
|
||||||
IAnimatedMesh* getMesh(io::IReadFile* file) override;
|
IAnimatedMesh* getMesh(io::IReadFile* file) override;
|
||||||
|
|
||||||
@ -49,9 +45,6 @@ namespace scene
|
|||||||
//! returns the video driver
|
//! returns the video driver
|
||||||
video::IVideoDriver* getVideoDriver() override;
|
video::IVideoDriver* getVideoDriver() override;
|
||||||
|
|
||||||
//! return the filesystem
|
|
||||||
io::IFileSystem* getFileSystem() override;
|
|
||||||
|
|
||||||
//! adds a scene node for rendering an animated mesh model
|
//! adds a scene node for rendering an animated mesh model
|
||||||
virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,
|
virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,
|
||||||
const core::vector3df& position = core::vector3df(0,0,0),
|
const core::vector3df& position = core::vector3df(0,0,0),
|
||||||
@ -278,9 +271,6 @@ namespace scene
|
|||||||
//! video driver
|
//! video driver
|
||||||
video::IVideoDriver* Driver;
|
video::IVideoDriver* Driver;
|
||||||
|
|
||||||
//! file system
|
|
||||||
io::IFileSystem* FileSystem;
|
|
||||||
|
|
||||||
//! cursor control
|
//! cursor control
|
||||||
gui::ICursorControl* CursorControl;
|
gui::ICursorControl* CursorControl;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user