OGRE v ODN: small difference noticed in Intermed Tutorial 1

DigitalCyborg

10-04-2006 20:23:09

While working on porting Intermediate Tutorial 1 :
http://www.ogre3d.org/wiki/index.php/Intermediate_Tutorial_1

I noticed a small difference between what the OGRE folks have in setup() and what ODN has in Setup()

In the setup method in OGRE::ExampleApplication in ExampleApplication,h : ~line 95
( ogrenew/Samples/Common/include/ExampleApplication.h )
CreateScene() is called before createFrameListener().

// Create the scene
createScene();

createFrameListener();


In OgreDotNet.ExampleApplication in ExampleApplication.cs : ~line 86
( ogreaddons/ogredotnet/OgreNet/Custom/ExampleApplication.cs )
CreateEventHandler() is called before CreateScene().

CreateEventHandler();
...
CreateScene();


The problem is that Clay's tutorial is dependent on the call order of those 2 functions. He passes a variable that is initialized during createScene (mEntity) into the Constructor for createFrameListener.


void createFrameListener(void)
{
mFrameListener= new MoveDemoListener(mWindow, mCamera, mNode, mEntity, mWalkList);
...
}


mEntity is null unless CreateScene is called:


void createScene(void)
{
// Create the entity
mEntity = mSceneMgr->createEntity( "Robot", "robot.mesh" );
}


Now, after all that blathering, I guess I can get to my first question.

Is there a reason that the ordering differs in the OgreDotNet version of ExampleApplication?

I was going change the order of those two function & recompile OgreDotNet to see if it worked the other way around, but I didn't since I don't want our ports of the tutorials to require recompiling OgreDotNet.

The other thing about this tutorial that is really messing with me is not having pointers in C#. ( I think I've mentioned before that im a C programmer by trade, so naturally i've grown to know & love pointers) (also, I'm new to C# so if this next part is a stupid n00b question, please tell me where to look, even its RTFM for C#)

In Clay's tutorial (the cpp version) both the FrameListener and the Application maintain pointers to the Entity and its SceneNode and from what I gather a the walklist deque lives in the application and the Framelisters walklist deque is only a reference (since the FrameListener is only passed the address of it)

In both classes:

Entity *mEntity; // The entity of the object we are animating
SceneNode *mNode; // The SceneNode of the object we are ,oving
std::deque<Vector3> mWalkList; // A deque containing the waypoints


the EventListener constructor

MoveDemoListener(RenderWindow* win, Camera* cam, SceneNode *sn,
Entity *ent, deque<Vector3> &walk)
: ExampleFrameListener(win, cam, false, false), mNode(sn), mEntity(ent), mWalkList( walk )


So I guess what Im getting at here is what's the proper way to do this in C#??
I did a little reading and I think i've got it correct, but I have no way of knowing for sure unless I ask.

In the C# version of the tutorial, I have the following in both the EventHandler and the MoveDemoApplication class.


Entity mEntity; // The entity of the object we are animating
SceneNode mNode; // The SceneNode of the object we are ,oving
LinkedList<Vector3> mWalkList; // A deque containing the waypoints


and I made the constructor for
MoveDemoEventHandler : OgreDotNet.EventHandler
look like this:


MoveDemoListener(ref Root _root, ref RenderWindow win, ref Camera cam, ref SceneNode sn, ref Entity ent, ref LinkedList<Vector3> walk)
: base(_root,win)
{
mNode = sn;
mEntity =ent;
mWalkList = walk;
}


I know I should be able to initialize mNode, mEntity & mWalklist on the constructor line instead of inside the body, but I decided to worry about that later.

So my question about all of that is:
Does passing the arguements with the ref keyword prevent deep copies? especially for the walklist?

Thanks
DC

rastaman

10-04-2006 21:32:01

Hi DC
I don't think there is any reason CreateEventHandler is before CreateScene it was just created that way and not been changed. It should be changed so that it’s as close to the C++ ExampleApplication.

As for using the ref keyword, I'm not sure if that’s needed. They are all objects which are references. Using "ref" would be more if you wanted to create a new object and send it back to the calling function.
Or point the calling functions parameters to another object.

DigitalCyborg

10-04-2006 22:52:20


I don't think there is any reason CreateEventHandler is before CreateScene it was just created that way and not been changed. It should be changed so that it’s as close to the C++ ExampleApplication.


Ok I'll change it in my local sandbox and recompile ODN. If everything works for me after I make the change, Will you do some more extensive testing & check it into the ogreaddons/ogredotnet CVS ?


As for using the ref keyword, I'm not sure if that’s needed. They are all objects which are references. Using "ref" would be more if you wanted to create a new object and send it back to the calling function.
Or point the calling functions parameters to another object.


Ok thanks. I also found this Whiteboard with Anders Hejlsberg .. at some point ~19m in .. he explains out vs ref in C#. also some other good stuff in here..
http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20040624csharpah/manifest.xml


Thanks RASTAMAN!