Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. diericx
  3. Posts
  • Profile
  • More
    • Continue chat with diericx
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Posts made by diericx

I re-designed how Rooms work, making them customizable and have started implementing an AOI feature.

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.

The Code
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!

Room.ts

RoomAll.ts

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:

RoomAOI

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.

posted in Showcase • 17 Mar 2018, 17:59
RE: Is there any way to implement Area of Interest?

@endel I just finished an implementation of AI that puts players into "Regions". The server will broadcast a global state for messages, trades, etc. and then only broadcasts data from that region.

I have to work on sending the unseen state of a new region to a player when they first get into it and making the change more user friendly, but I'll try to upload my code soon!

posted in Questions & Help • 17 Mar 2018, 03:46
Is there any way to implement Area of Interest?

So far, it looks like the entire state is sent over to the client. Is there any way to implement some sort of area of interest algorithm so only a portion of the state is sent over? Possible split the state up into arrays for portions of the map and only send patches from a certain portion to the player?

I'm sure I could disconnect all the data from the state itself and send it when need be with client.send, but that seems like it defeats the purpose of Colyseus hahaha

posted in Questions & Help • 16 Mar 2018, 18:26
RE: Crazy lag on Unity Client while trying to deserialize MsgPack data. Issue with patching. (SOLVED)

@endel Worked perfectly!! Thank you so much man, this is really cool.

posted in Questions & Help • 16 Mar 2018, 18:23
RE: Unity Client Broken? (SOLVED)

@talothman I had a similar issue. I realized that the client is trying to instantiate the player twice. Add this to the top of your OnPlayerChange in the "add" opratin:

if (players.ContainsKey(changePathId)) { return; }

posted in Questions & Help • 16 Mar 2018, 11:32
Crazy lag on Unity Client while trying to deserialize MsgPack data. Issue with patching. (SOLVED)

I have been developing a small game using Unity as the client. I downloaded your source code and it was working until I put about 400 world objects down. These objects do not move or update at all.

Now, when the player moves, there are huge lag spikes. I narrowed it down to line 180 in Room.cs (Patch function):

var newState = MsgPack.Deserialize<IndexedDictionary<string, object>> (new MemoryStream(this._previousState));

I believe this is because any time there is an update, it attempts to deserialize the entire state, when it only needs to actually deserialize the difference and apply it.

Does anyone have any ideas on how to fix this?

The only solution I can think of would be to have a different room for the static world objects so that they would not need to get serialized for every patch... this seems like a bit of a hack though.

I do realize it is expensive to load the world from the server, but I would like the world to be randomly generated and then sent to the player as they load sections. Is this possible with Colyseus?

posted in Questions & Help • 16 Mar 2018, 10:10

© 2023 Endel Dreyer