[Unity] Test-driving the API

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

benblo
Posts: 1
Joined: 11 Sep 2008, 09:07

[Unity] Test-driving the API

Postby benblo » 11 Sep 2008, 09:59

Hello Thomas and others!
I just test-drove the API and it looks sweet, after loading the test project I just had to enter my server's url and it connected on the very first attempt, so congrats!

And now for the critics... I'm giving you my comments as they came while testing (I've only little practice with the Flash version of SFS so pardon me if some remarks are dumb) (BTW, do you by any chance come from Flash? The way you organize the game objects --layers ;) ?, and the syntax you use makes me think so...).
  • Connection attempts aren't asynchronous and lock up the game... there should be a way to use coroutine sweetness.
  • OnConnection isn't fired if connection fails... (try with wrong port)
  • OnApplicationQuit isn't fired in the editor, so disconnection doesn't occur.
  • anyway SmartFoxClient should clean itself up IMO, maybe by implementing a destructor, or System.IDisposable?
    This way you wouldn't even need a manager in the scene, all static!
  • I was surprised by the way you use events... I actually didn't know you could += a delegate without new EventHandler(method)!
    Thanks for the tip, it's cleaner code! Also, so cool to see real events in Unity, I'm so sick of the SendMessage() madness... but don't events cause you problems? I'm thinking in particular of the webplayer.
I've re-organized your test project a bit, rewrote some code (my personal way of getting to know an API... results here):
  • renamed GameManager (too generic) to SmartFox, removed the useless 'instance'.
  • made Get/SetSmartFoxConnection() into a static property: Connection.
  • In the same way room.Get/SetName() could become room.name (*), smartFox.IsConnected() => smartFox.isConnected, etc.
  • ConnectionGUI: exposed serverName & serverPort (now an int) so you can configure it in the editor.
  • overall, I cleaned up the code a bit:
    • removed 'using System' (I don't like having this because it creates an ambiguous reference between System.Object and UnityEngine.Object)
    • String => string, Boolean => bool
    • event handlers don't need to be public
(*) I realize this would break habits for those used to the Flash API, but Unity coders will hate it. Also I think AS doesn't have getter/setters so now is the chance to improve!
By .NET standards a property should be called ie room.Name, whereas Unity conventions favor room.name... depends on what audience you're aiming for.
I'd be happy to do it (VS refactoring makes this easy) but I suppose the code I downloaded is already obsolete...


That's it for today... I can't wait to use SFS in our game, users have been asking for a pre-match lobby for a while and SFS would be perfect for this!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 13 Sep 2008, 10:50

Ahhhh!!! Where have you been benblo! Just been waiting for replies like yours :-D

Firstly I'm glad you found it useful and got it running with minimal work.

The for the critics part - definitely feel free to critizise _everything_. That is definitely part of an improvement process, and the code is "only" in beta1 for the exact same reason. Any improvements that might break the API should be added now and not after final release.

That goes both for the example as well as the API itself.

The basis for the .NET api is the ActionScript3 API, but with some .NET improvements - so the API is already different from that.

In general I am definitely aware of the connection (especially failed connection) issues. There is an exception in there that basically eats every connection problem and ignores it. That also has the effect of the API not falling over to the http protocol when sockets fail (if anyone noticed yet).

That will be fixed for beta 2 (my internal target milestone feature wise).

* Connection attempts aren't asynchronous and lock up the game... there should be a way to use coroutine sweetness.


Yeah true - if you got any ideas on how to do this, then I'm very open for code donations. Preferably in the API itself, secondary in the example :-)

* OnConnection isn't fired if connection fails... (try with wrong port)


Yep. Wrong port should (as mentioned above) also trigger attemping the http protocol before failing.

* OnApplicationQuit isn't fired in the editor, so disconnection doesn't occur.


Aha!!! Thanks. That explains the issues with start/stop the demo in the editor, with crashes as a result.

* anyway SmartFoxClient should clean itself up IMO, maybe by implementing a destructor, or System.IDisposable?
This way you wouldn't even need a manager in the scene, all static!


Will at least add a destructor for beta 2!

* I was surprised by the way you use events... I actually didn't know you could += a delegate without new EventHandler(method)!
Thanks for the tip, it's cleaner code! Also, so cool to see real events in Unity, I'm so sick of the SendMessage() madness... but don't events cause you problems? I'm thinking in particular of the webplayer.


Yeah - I think the += and -= of delegates is pretty beautiful. It does have a drawback/feature/bonus effect. You can add multiple events to be fired on the callbacks - separating different areas of responsibility into separate methods. But it also "allows" you to add the same delegate twice and thus get 2 callbacks for each event. Just beware of this!

For your demo changes:
If its OK with you, I will selectively pick out your improvements and add to the demo. I dont want to have a 100% flash compatible API, but something that works for .NET clients. It still has to be 100% compatible on the server side and cross platform client, but the API itself doesnt need to mimick Flash all the way. Thats already true in the beta 1 API, so a few improvements on top wont be a bad thing.

On a side note - I'm currently writing a few articles for the Unity Developer Magazine about the API + writing a complete lobby system as a tutorial. So any comments on the lobby demo now would be most welcome (like scroll bars in the chat window - hehe).

Keep comments flowing!!!

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 18 guests