While I was trying to implement an Area of Interest feature into Colyseus, I realized it would make more sense to turn the Room class into even more of an abstract class.
The new Room class
Room.ts is now simply the base class of all rooms, and contains the core methods a Room needs, like _OnJoin, _OnLeave, Disconnect, etc. You can then really easily extend off of it to create a room with custom logic.
This opens so many doors for people developing games with Colyzeus. They can now extend off of Room to create ANY kind of room they want for their game/app. I had been messing around with it all day yesterday and it's crazy fun. :)
What exactly does this offer though?
One of the coolest things is that, when extending the room class, the user has to implement functions called mapClients, addToClients, and getNumClients. This means that Clients can be any type of collection! All you have to do is provide a few utility functions and everything else just works!
We also now have access to the broadcast and broadcastPatch function, allowing use to change who gets messages and when.
Here is the updated code for Room (the base Room class), and RoomAll (the implementation of the default room that is provided). Let me know what you guys think!
What I'm working on now
Note: I'm going on vacation this week so I'll have time to work on it after!
I'm currently working on a system for Area of Interest. The idea is that users will be placed into regions within a room, and the server will, instead of checking and publishing the entire state to users, only send the binary difference of each region to the player. There is also a global state that gets sent to players. There's still a few things I haven't implemented, but here's what I have so far:
I have all of this on a branch of the Colyseus repo. I've only changed Index.ts, Room.ts and RoomAll.ts and it works perfectly with the rest of the library. :)
I'm also planning on replacing Fossils algorithm with FlatBuffers to reduce serialization and deserialization time on both the client and the server. This is especially important for the Unity client, because the deserialization process is super expensive and slows down the client.