ImmersiveMC

ImmersiveMC

2M Downloads

Mega Packets

hammy275 opened this issue ยท 3 comments

commented

ImmersiveMC is a very packet-heavy mod, both due to some unideal design decisions early on, and just the need to send so much around in worst-case scenarios.

To account for this, we should switch to using larger packets. To do this, we should create a wrapper for Architectury's SimpleChannel:

  • Registering a packet, encoder, decoder, and handler should create an object storing all of that information and put it into an ArrayList.
  • The server has a HashMap with a key of players and a value of a buffer. The client just has a single buffer for sending to the server.
  • When calling to send , we instead write the index from the ArrayList immediately followed by the buffer for the object to the buffer above.
  • At the end of each tick, the server sends all buffers it has to clients and clients send all of their buffers to server. Hopefully size limits are okay, since iirc, servers have a lot of room in their buffers, and we shouldn't ever reach 32k on the clients.
  • On receiving a mega packet, we loop, reading the index into the ArrayList, calling the decode function, then calling the handle function. Note that the mega packet should NOT enqueue this work, as the handle functions of all of the other packets already do this.
commented

Looking around, we should be good on S2C packet sizes being massive. As of 1.18.2, the maximum size is 8MB https://bugs.mojang.com/browse/MC-185901

commented

A couple of changes have been made since the initial planning:

  • Encoding also writes the number of packets we're sending so decode can easily get the correct amount out from the buffer.
  • Haha funny casting makes me cry (but it works!)
commented

Things to still do:

  • See if we can optimize getEncode and/or getHandler
  • Test Fabric and Forge
  • Test dedicated server