Status, thread safety in Unity and new API version soon

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

Moderators: Lapo, Bax

ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Status, thread safety in Unity and new API version soon

Postby ThomasLund » 13 Feb 2009, 06:17

It has now been a few months since the 1.0 release of the C#/Unity API, and things have quieted down a little here - but definitely not in my end.

Things have gone from "working on API" to "working with API" to actually make games with it. Eat your own medicine as we say where I come from.

During development a few small issues have started to float up - but nothing major, so really happy with the launch and the API from my end.

To give a little status, I have been working on a game that will be published as a SFS tutorial in the Unity Developer Magazine (http://www.unitydeveloper.com/). It will be a small - but fully working - turn based tactical combat game over 3 articles/issues.

I have also been doing some work on tutorial "ports" from the Flash ones in the documentation. So soon those will be released and help you along.

But back to the issues - these revolve mainly around Unity and its lack of thread safety.

While working on a first person MMO type tutorial I kept running into errors inside Unity, where it complained about array contents being modified while rendering it as GUI components. Talking to others who had done similar "real time" games using the API it quickly lead to the info on Unity NOT liking the API to send data into it whenever receiving data. What I call a "push mode". Network traffic comes in, API calls delegate right away, that updates something inside the game (like pushes chat messages onto an array).

If that array is being rendered in an OnGui right then, that will lead to errors on your console.

So updating some kinds of data structures is fine in push mode - but you got to watch what you do and beware. Not the optimal situation.

What I saw from 2 projects working with this, they had both implemented a queue system in their Unity games. They took whatever came in from the API, placed it in a queue and then processed the queue in either Update or FixedUpdate inside Unity.

Other ways to ensure that things dont clash could be to use synchronized collections and/or use locking mechanisms. But all these things are irritating and lots of people will forget (or simply dont know about it). And why should they care? They want to be able to simply plug in their game code and have the API take care of those things.

So what I then did lately was to put this queue system into the API instead, and inventing the "pull" mode for the next version API.

You simply specify the mode that you want to run the API in (default push or the new pull). If running in pull mode, the API will queue up events internally instead of calling the delegates. Whenever your game code is ready - like in Update or FixedUpdate - you then tell the API to "Process Event Queue" and it will empty the queue and call the delegates as usual.

This makes it safe to e.g. put chat messages into arrays, as Unity is not in a state where its rendering or anything else.

This new API version will most likely be packed up during the next days and then hopefully get released soon after.

The new version will also have some smaller bug fixes included. The "biggest" of those being a weirdness applying to the version of mono that Unity ships with (reeeaaaaaalllly old). Sending floats/doubles between machines that use different punctuation for the separation of the 2 parts is buggy. The US will write "two and a half" as 2.5, while here in Scandinavia we write it 2,5. Localization usually takes care of this way down in the operating system or similar, but the mono bug doesnt fix this behind the scenes for us. The bug fix/workaround is to enforce US settings when parsing the string into a number (had to pick one of the 2 and chose that).

Just wanted to give you a heads up on this one.

What did not make it into this release is a non-static SFSEvent. Its still on the idea list to talk with Marco about. Its not forgotten.

/Thomas
seb
Posts: 2
Joined: 10 Jan 2009, 22:32
Location: Lille, FR

Postby seb » 13 Feb 2009, 20:46

This next release will be very helpful. I just realised of these thread safety issues when I saw your post.

I then wanted to implement an event queue in my code, but Pull mode will be really great, and will save me a lot of time ! :)

Can't wait to try the upcoming release, Thanks.

Sebastien
ringhino
Posts: 8
Joined: 19 Dec 2008, 08:33

Postby ringhino » 20 Feb 2009, 20:04

Hi Thomas,

we are developing a web application using your Unity API (thank you for your work!)

this tool is really useful, and we are approaching Smartfox thanks to that!

I would like to know what is the best method to syncronize position and rotation between the avatars.

we are using setuservar and getuservar but we don't know if there is a better way to do this.

the major problem we are experiencing is that if we are moving together 2 players connected through the same public IP, the server kicks the third one that is using a different IP. (like if the values between the same IPs are corrupted).

I would also like to read your tutorials, but I didn't find a "pdf" version of the magazine to buy... and I think that the real one will get too slow to my company (we are in italy)..

do you know if they sell also an electronic version?

If we need your (paid) support to develop our multiplayer logic, are you available also as a consultant?

let me know.


thanks in advance for your reply

Francesco from Italy.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 20 Feb 2009, 22:25

Hi Francesco

Thanks a lot - it is really great to hear that people are using it and it being helpful in their game development.

Within a few days or so (depending on when Marco gets it released) there will be several more Unity tutorials available.

One of those is a real time "3d chat world demo" - its the Unity Island demo that has been SFS'ified to support multiple users joining the island and seeing each other and chat.

It features amongst other things sending position, rotation and animation states to clients - as well as interpolation and other small utility methods.

The source code will be freely available, and it sounds like something along what you are struggling with.

But yes - I am a full time consultant, and always happy to help!

PM me if interested. I can also link you up with the tutorial if Marco is too slow (hint hint Marco!! :wink: )

Best
Thomas
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 21 Feb 2009, 07:54

Thomas, feel free send pre releases while I am finishing the packages :D
Lapo
--
gotoAndPlay()
...addicted to flash games
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 21 Feb 2009, 08:11

Ahh yes - I forgot to answer the question on the PDF version of the Unity Developer Magazine.

Contact Charles directly - the guy who publishes it. I know he has PDF versions of it that he sends out to subscribers on demand.

The latest version 3 should be in your mail within a week or so - should have been out around new year, but it got delayed due to lots of irritating reasons.

That and the next 2 versions will have SFS content in it. I am making a very small, but full featured, turn based game together with Charles. Source code included.

So poke him, and I'm sure he gives you a copy. With that said - I subscribed on a Thursday and got my physical copy on the following Tuesday. So less than a week for post to arrive here in Europe. So it can come very quickly, and is a really nice high quality magazine.

Best
Thomas
ringhino
Posts: 8
Joined: 19 Dec 2008, 08:33

Postby ringhino » 22 Feb 2009, 20:02

Thank you Thomas, I've wrote you a PM.

I've done the subscription to unitydeveloper magazine... I hope that italian postal service will do his work..

to Lapo: are you italian?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 23 Feb 2009, 07:34

to Lapo: are you italian?

Yes, provincia di Cuneo, Piemonte :)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 17 guests