onedayitwillmake / RealtimeMultiplayerNodeJs

Realtime Mutliplayer Game Engine using Node.js / websockets for HTML5 that uses a client-server approach in which the clients send only sampled input to the server
548 stars 112 forks source link

"wantsFullUpdate" & full/half "EntityDescription" #4

Open morfeus87 opened 12 years ago

morfeus87 commented 12 years ago

Hi, congratulations for this framework, but especially for having released as open-source. I'm starting to use your framework for the construction of a multiplayer game (or at least I try). I did some initial adjustment to adapt the framework to the latest version of socketio.

the "constructEntityDescription" In "GameEntity" allows for "wantsFullUpdate" but then not used within the function. "If true, Certain Things That are only sent When changed are always sent" You have commented.

What can I do about this parameter?

Another related problem is that I would send over the network initially and then only when asked for a full "EntityDescription" to initialize the object (bodymass, bodyfriction, geometryWidth, geometryHeight etc. ..) Then inside the loop send a simple "EntityDescription" that contains only "position, rotation and id .."

I hope I was clear and I apologize in advance for my English "google translated"

onedayitwillmake commented 12 years ago

Hi morfeus87,

Thank you - and please be sure to make an official fork and put any changes you've made updating the code back into the stream.

I will look at your question in a little more detail later, but yes that should be possible in the framework in fact if you look at the DemoBox2D you can see how I approach this.

The gist of it is that, the framework will automatically call 'createEntityFromDesc' (which you should overwrite for your specific game) on the client side, when it comes across an entity it didn't have in the last frame. On the server side whatever information included it will be passed.

So what I would do - create for your game a GameEntity subclass that is 'smart' about it's first call to 'constructEntityDescription' with a firstUpdate flag or something that only publishes those extra details once.....

From a performance point of view, don't do anything 'too javascripty' such as removing and deleting and recreating the prototype chain after the first update, as this will most likely remove the function as a candidate for optimization by V8... This talk explains what i mean http://www.youtube.com/watch?v=XAqIpGU8ZZk - lots of good info in there for creating a js multiplayer engine running on v8

morfeus87 commented 12 years ago

I have already created a subclass "PlayerEntity" extending "GameEntity" that has inside a method "constructEntityDescription" as your commented example in "GameEntity".

But the method "constructEntityDescription" is not only called on the server? Calling this method the first time I set the flag "firstUpdate" to false on this entity, but then the next client will not receive the full version of the entity description. I'm wrong? I do not understand :(

ps: I had already watched the video on youtube and found it really interesting, along with almost all other Google Video Team and GDC12 video. Unfortunately, there is already Ammo.js doing 'too much javascript'

ps2: my changes seem fairly home-made even if they are working. However if you want I can make a official fork.

Thank you for your attention!