How I'm planning to fix lag

nice

2 Likes

I think a big way to fix optimization would be to not send info to the server for leaderboards as soon as a player gets XP, instead saving it until they die or disconnect. Unless you already do that.

4 Likes

I already do that actually, thanks for the suggestion though!

3 Likes

my next optimization goal

next i’m trying to completely move away from socket.io (current networking library), to pure websockets, which is much more reliable and faster…

note that swordbattle was always built around socket.io, and getting rid of completely won’t be so easy. it might take a week or 2, but this will probably eliminate the disconnection issue (which is now much better after the revert) .

some of my other games (like spicywar) use pure websockets, and it’s worked really well.


now since I reverted the code due to the disconnection issue, the first optimization was actually removed. don’t worrry, since I have all the code for it safe, and once the transition to ws is complete, it will be added.

same goes to the new evols and some of the new statistics features, which will also be added back shortly after the transition. I will update u guys about this transition here.

5 Likes

progress

everything is going MUCH better than expected. today I was able to migrate everything and get swordbattle running locally, fully on websockets

i still need to do some testing on actual servers, and see how better it is compared to socket.io

hopefully update will be out during sometime this weekend


technical details

The way I did it was I created a new class that basically acts as a converter from socket.io to websockets. So when a place in the code does .emit it will take that and change the contents to a JSON string and send’s it.

To the main code there isn’t any difference between socket.io and what I made. All I had to do was rename the import directory and it worked.

I had to do this in the client and the server, and what was especially annoying was socket.io had support for multiple arguments when emitting, but I was able to solve it using the ...args array and rewriting some of the packet listeners.

5 Likes

image

Testing beta update on a private server (hosted on replit) in a school chromebook. Much better results.

Usually school wifi is pretty bad and 62 ping is not bad at all. Also is really smooth aswell.

Now usually the game gets laggier with more ACTUAL players, this server is just with bots.


I am postponing the update to sunday because that’s when the lowest amount of people play so I can quickly fix without affecting many players if something goes wrong.

5 Likes

nice

1 Like

what will be added in the new update besides fixing lag? also good job on that

5 Likes

wait but if each player is updated slowly will throwing swords that go off your screen still work

2 Likes

yes it will still work, the update only affects players, in game throwing swords are treated like a completely different object

4 Likes

only lag fixes for now

3 Likes

ah, okay.

1 Like

the websocket update is pushed!

We have completely switched from socket.io, for me personally, not much difference in ping.

If you’re wondering what the heck am I talking about?

Well in short, socket.io was the old system we used for connections. It was super easy to use, even for beginners, that’s why I used it. But there were problems with it that caused players to disconnect. So I switched to WebSockets, which is the core system behind socket.io, and it will fix lag more.

The game seems much more stable now

Also i’ve been monitoring a more consistent TPS drop after the update… let me know if this becomes an issue

I think this will probably fix the disconnect issue but let’s wait and see

Thanks!

3 Likes

disconnect is less often

1 Like

looks like u fixed samuri too
image

1 Like

Wait you still got disconnected?

yesterday only twice i think

2 Likes

what about today because I just pushed update today

before update, it was bad, but no disconnections so far after

1 Like

havent played

1 Like