Hi Nathan!
Thanks for sharing this project. I think it could be very interesting and useful for some game developers. With that in mind, I have some suggestions and feedback I'd like to send your way.
The code is currently tied directly to
socket.io, which isn't a bad thing per se, but it creates an unnecessary dependency on a
socket.io environment. I've played with
socket.io briefly, and I was really unhappy about how it requires self-hosting. Anyway, it would be nice if your framework was made protocol independent so that it isn't tied to any particular communication stack. You can design the API to be compatible with
socket.io if you like, it just shouldn't have a strong dependence on it. Different drop-in connectors could be added for pure websockets, webRTC data channels, or PubNub...
socketClient.js exposes a lot of variables to the global scope. Please wrap these in an anonymous self-executing function to minimize polluting the global namespace. socketObjectEntity.js in turn uses these global variables, which is a design pattern that is difficult to swallow. Structure it so that socketClient.js creates a single globally-accessible variable that exposes its internals as object properties. Then socketObjectEntity.js can access those internal properties via the single global variable. This containment will help with maintenance, debugging, and performance.
The socketObjectStructure is not a future-proof means of accessing object properties. Starting in melonJS 1.1.0, the Entity class (was ObjectEntity) no longer has a position or velocity; those properties live on the body property, E.g. Entity.body.pos A better way to reference the values you wish to transmit is actually to reference them directly. This would be an example:
this.socketObjectStructure = { "GUID" : this.GUID,
"pos" : this.body.pos,
"vel" : this.body.vel
"settings" : settings,
"currentAnim" : this.renderable.getCurrentAnimationFrame()
Now it's future-proof, as far as I don't necessarily have to update the socketObject code when I update melonJS; The most I might have to change is the list of items referenced by the socketObjectStructure.
And my final, and perhaps most important comment, is that this framework creates a great opportunity to fill a HUGE gap in JavaScript networking multiplayer game development; doing the HARD STUFF like interpolation and prediction. There are commercial game engines that do this, but not any really good open source ones that integrate with other game engines in a seamless manner. It's actually very easy to do real-time network synchronization using dumb message passing. The results are "ok", but far from ideal. Heck, I built just that in an evening using about 60 lines of code:
http://www.pubnub.com/blog/lightweight-multiplayer-html5-games-with-pubnub-and-melonjs/ The actual value of a networking multiplayer framework, IMHO, will come from the HARD STUFF.
Here are some articles I want to share, which all deal with the HARD STUFF:
Of course, there is some reliance on the game engine, like being able to operate the frame rate independent of the physics and network updates. There's an open ticket in melonJS for this:
https://github.com/melonjs/melonJS/issues/99
And finally, I will leave you with a list of other concepts and ideas that you should focus on, if you want to make this framework useful beyond dumb message passing:
Features of Entertainment & Gaming:
And Wrappers / Modules Like:
- Game Lobby Room
- Game Room Chat
- Game World Rules
- Geo Hashing in Game World
- Game Room Splitting
- Matchmaking and Skill Ranking
- Ghosting and Spectators