Problems building or running the engine, queries about how to use features etc.
r0ut
Halfling
Posts: 44 Joined: Mon Feb 22, 2021 6:25 pm
x 2
Quote
0
login to like this post
Post
by r0ut » Thu Feb 25, 2021 2:14 pm
Ogre Version: 1.12
I'm currently converting my old code which uses Mogro to get rid of it and use the new Ogre C# bindings. I've stumbled on a issue:
How can I convert Events or ResourceGroupListeners?
This is the Mogre code:
Code: Select all
ResourceGroupManager.Singleton.ScriptParseStarted += Singleton_ScriptParseStarted;
Root.RenderSystem.EventOccurred += new RenderSystem.Listener.EventOccurredHandler(RenderSystem_EventOccurred);
Root.RenderSystem.EventOccurred += RenderSystem_EventOccurred;
Root.Singleton.RenderSystem.EventOccurred += RenderSystem_EventOccurred;
How can I do the equivalent in Ogre? I can't see scriptParseStarted under getSingleton() method
Code: Select all
ResourceGroupManager.getSingleton().???????? += Singleton_ScriptParseStarted;
root.getRenderSystem().?????? += new RenderSystem.Listener.EventOccurredHandler(RenderSystem_EventOccurred);
root.getRenderSystem().?????? += RenderSystem_EventOccurred;
Root.getSingleton().getRenderSystem().?????? += RenderSystem_EventOccurred;
paroj
OGRE Team Member
Posts: 1995 Joined: Sun Mar 30, 2014 2:51 pm
x 1075
Contact:
Quote
0
login to like this post
Post
by paroj » Thu Feb 25, 2021 3:40 pm
r0ut
Halfling
Posts: 44 Joined: Mon Feb 22, 2021 6:25 pm
x 2
Quote
0
login to like this post
Post
by r0ut » Tue Mar 02, 2021 3:05 pm
Sorry for the late reply but that's what I've tried so far:
Code: Select all
RenderSystem.Listener.SwigDelegateListener_1 test = new RenderSystem.Listener.SwigDelegateListener_1(RenderSystem_EventOccurred);
root.getRenderSystem().addListener(test);
But I get a type error which is obvious:
Code: Select all
cannot convert from 'org.ogre.RenderSystem.Listener.SwigDelegateListener_1' to 'org.ogre.RenderSystem.Listener'
but RenderSystem.Listener() doesn't have a constructor that has 1 argument so I had to use SwigDelegateListener_1
How can I convert it so It doesn't throw an error at .addListener(test)?
r0ut
Halfling
Posts: 44 Joined: Mon Feb 22, 2021 6:25 pm
x 2
Quote
0
login to like this post
Post
by r0ut » Tue Mar 02, 2021 4:40 pm
I can't do the same way because the constructor doesn't have any arguments.
Code: Select all
'RenderSystem.Listener' does not contain a constructor that takes 1 arguments
Code: Select all
RenderSystem.Listener renderSystemListener;
renderSystemListener = new RenderSystem.Listener(RenderSystem_EventOccurred);
The only way I found to bind the method to it is using SwigDelegateListener_1 but that's not the expected type in addListener()
r0ut
Halfling
Posts: 44 Joined: Mon Feb 22, 2021 6:25 pm
x 2
Quote
0
login to like this post
Post
by r0ut » Tue Mar 02, 2021 5:01 pm
Will this work as expected?
Code: Select all
public class EventListener : RenderSystem.Listener
{
private bool isDeviceLost;
public EventListener() { }
public override void eventOccurred(string eventName)
{
if (eventName.Equals("DeviceLost"))
{
this.isDeviceLost = true;
}
else if (eventName.Equals("DeviceRestored"))
{
this.isDeviceLost = false;
}
}
}
RenderSystem.Listener renderSystemListener = new EventListener();
root.getRenderSystem().addListener(renderSystemListener);
paroj
OGRE Team Member
Posts: 1995 Joined: Sun Mar 30, 2014 2:51 pm
x 1075
Contact:
Quote
0
login to like this post
Post
by paroj » Tue Mar 02, 2021 6:03 pm
probably