Creating object

Apr 9, 2009 at 4:12 AM
Edited Apr 9, 2009 at 5:01 AM
So when i create an object that is derived from DistributableObject;

When I create it on specific client and use a constructor that takes arguments it will work on that specific client
but when the server creates it on all the other clients it will call the constructor that takes zero arguments.

So how do i get those arguments for the client?


localTank= new Tank(new Vector2(300, 300), graphics);

this is a particular interesting case because i want the tank to start at the same position for all clients Vector2(300,300),
but it to have the local GraphicsDeviceManager so it can draw itself.
this will work for the Client that's creating this tank but I'm not sure how to get the tank to grab the local GraphicsDeviceManager  when its is created on other clients.

Coordinator
Apr 9, 2009 at 7:11 AM
Hi epixl33t,

the localTank as DistributableObject must have a parameterless constructor (zero arguments), therefore you cannot create it in your described way.
If you use the DistribussionSession.DistributeObject() it will propagate all serializable public properties of the object, but the "graphics" is a reference type, so this is not possible.
What is possible is to expose an event when the object is created on clients side. Then using a method of the Tank class, set the graphics object to a private field . That would mean to override the default client dictionary (DistributableObjects) in the DistribussionSession.
I will maybe implement such behavior, it is quite simple..

Thanks,
David



Apr 9, 2009 at 11:52 PM
I'll be awaiting your next version then ;-)
Jan 11, 2010 at 4:00 AM

Could you elaborate some on that last part about triggering an event for current clients when a new client connects?  Basically I want to load model data so they can be drawn.

Thanks

Coordinator
Jan 11, 2010 at 6:03 AM

Hi,

the event triggering is described in the Advanced tutorial in "Handling events from server" part. You can implement a class say ClientConnector which will have one distributable property. If server changes this property value, an event will be raised on all clients. Maybe you can use this as a trigger for your model data loading logic.

David