About movement - is it just me, or does it make no sense?

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
toddhd
Posts: 3
Joined: Sat Mar 11, 2006 3:01 am
Location: Downingtown, PA
Contact:

About movement - is it just me, or does it make no sense?

Post by toddhd »

Hi guys,

First off, I am a total noob to Irrlicht, so pardon me if this is a stupid question or if I don't understand how things are supposed to work.

Having examined the .NET Hello World example, the first thing I wanted to implement was some extra input routines. So I followed the C++ tutorial for movement, and implemented it as C#/VB, but right away it smacks me as not making sense.

The problem I see is that the MyEventHandler class we define is expected to actually handle the results of the input. This is a little weird. Basically, it forces us to use global variables of some kind. Either we need to define our game nodes as globals so that the MyEventHandler can do something with them (if W is pressed, then move NodeA) or define a global KeyPressed variable so that MyEventHandler can assign a value to it (if W is pressed, then KeyPressed = W) and the main loop can react to it. And either way, we just return a Boolean from the event.

This is not how .NET works, nor is it a good model for execution. The OnEvent() function should not be returning a boolean, it should be raising an event, and passing eventinfo through the delegate which contains stuff like what event took place, and the particulars (keypressed, mousex, whatever) . We then just react to the event appropriately.

So is it just me? Am I misunderstanding how this works? Is this just a hack because of the way it is handled in C++?
-Todd Davis
http://www.SeaburyDesign.com

"Windows has detected that your mouse has moved. Please reboot for the changes to take effect."
toddhd
Posts: 3
Joined: Sat Mar 11, 2006 3:01 am
Location: Downingtown, PA
Contact:

Post by toddhd »

Just a little more thought on the subject. I think it is probably easy enough to just declare and raise an event from our handler, like this: (Sorry, it's in VB, let's all scream in unison...)

Class MyEventReceiver
Implements IEventReceiver

Public Event InputEvent(ByVal e As [Event])

Public Overridable Function OnEvent(ByVal e As [Event]) As Boolean Implements Irrlicht.IEventReceiver.OnEvent
RaiseEvent InputEvent(e)
Return True
End Function
End Class

So basically, we're just doing what the wrapper should do in the first place, which is raise an event with the event arguments being passed. Now the main program can catch and address the event properly, and we don't need to maintain global variables, which as we all know, can be troublesome at times. I won't say that I never use Globals, but I like to limit them whenever possible.
-Todd Davis
http://www.SeaburyDesign.com

"Windows has detected that your mouse has moved. Please reboot for the changes to take effect."
Locked