Support for muliple ISceneManagers would be cool

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
jun
Posts: 12
Joined: Thu Dec 07, 2006 5:00 pm

Support for muliple ISceneManagers would be cool

Post by jun »

This is just some concept code for something that would be cool if irrlicht allowed it. Does anyone know of a way to do this sort of thing with irrlicht as it stands right now? Is this sort of functionality something that could possibly be included in a future release?

Code: Select all

int currentScene = 0;
ISceneManager scene1  = device.SceneManager;
ISceneManager scene2  = new ISceneManager(device.SceneManager());
IVideoDriver driver   = device.VideoDriver;
IGUIEnvironment env   = device.GUIEnvironment;

//...add whatever to each scene
scene1.add(...);
scene2.add(...);

while (device.Run() && !ExitFlag) 
{ 
	if (device.WindowActive) 
	{
		device.VideoDriver.BeginScene(true, true, new Color(0, 200, 200, 200)); 
		device.SceneManager.DrawAll();
		switch(currentScene)
		{
		  case 0: 
		    scene1.DrawAll();
		    break;
		  case 1:
		    scene2.DrawAll();
		    break;
		}
		device.VideoDriver.EndScene(); 
	} 
}
jun
Posts: 12
Joined: Thu Dec 07, 2006 5:00 pm

Post by jun »

it appears that maybe this is supported in c++ but not c#.net? is that true?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Multiple scene managers are most definitely supported in C++. It looks like you should be able to do it in C#, but I'm no C# programmer. Does the code you've presented not work? Seems like this should work...

Code: Select all

ISceneManager scene1  = device.SceneManager; 
ISceneManager scene2  = new ISceneManager(scene1); 
I think you'd want to remove the line below. If you don't you'll be rendering both scenes when you probably only want to render one of them...

Code: Select all

      device.SceneManager.DrawAll(); 
jun
Posts: 12
Joined: Thu Dec 07, 2006 5:00 pm

Post by jun »

vitek wrote:Multiple scene managers are most definitely supported in C++. It looks like you should be able to do it in C#, but I'm no C# programmer. Does the code you've presented not work? Seems like this should work...
The C# constructor for ISceneManager is

Code: Select all

public ISceneManager( ISceneManager* manager );
but the problem is the pointer. I tried setting Visual Studio Express to allow unsafe code, and placing the "unsafe" keyword in front of my function

Code: Select all

unsafe public void run()
{
  //...
}
and then I tried all of the following, but they all refuse to compile:

Code: Select all

ISceneManager scene1  = device.SceneManager; 
ISceneManager scene2  = new ISceneManager(scene1); 
Error: The best overloaded method match for 'Irrlicht.Scene.ISceneManager.ISceneManager(irr.scene.ISceneManager*)' has some invalid arguments

Code: Select all

ISceneManager* p  = device.SceneManager; 
ISceneManager scene2  = new ISceneManager(p); 
Error: Cannot take the address of, get the size of, or declare a pointer to a managed type ('Irrlicht.Scene.ISceneManager')

Code: Select all

ISceneManager scene1  = device.SceneManager; 
ISceneManager scene2  = new ISceneManager(&scene1); 
Error: Cannot take the address of, get the size of, or declare a pointer to a managed type ('Irrlicht.Scene.ISceneManager')

I even just saw something about using fixed with pointers in c#

Code: Select all

			ISceneManager smgr=device.SceneManager;
            fixed (ISceneManager* p = &smgr)
            {
                ISceneManager s2 = new ISceneManager(p);
            }
Still, Error: Cannot take the address of, get the size of, or declare a pointer to a managed type ('Irrlicht.Scene.ISceneManager')

It just looks to me like I'm going to have to go back to C++. The .NET framework is kinda iffy anyway, I suppose, especially since VS.NET Express would require the end-user to have version 2 of the framework.
jun
Posts: 12
Joined: Thu Dec 07, 2006 5:00 pm

Post by jun »

Now I see the problem. The irrlicht documentation simply shows the C# constructor as

Code: Select all

public ISceneManager( ISceneManager* manager );
But in reality (as I determined via MS VS.NET's intelisense) it is:

Code: Select all

public Irrlicht.Scene.ISceneManager( irr.scene.ISceneManager* manager );
Seeing as how these are two different types, and the ISceneManager that is contained inside Device is an Irrlicht.Scene.ISceneManager and not a irr.scene.ISceneManager, that makes this constructor totally useless and makes it totally impossible to create a new Irrlicht.Scene.ISceneManager other than the one that comes with the Device.
Post Reply