Gingerbeard5773 / Shiprekt

A King Arthurs Gold mod with top-down naval combat.
2 stars 5 forks source link

Lag spikes improvement #78

Closed Gingerbeard5773 closed 2 years ago

Gingerbeard5773 commented 2 years ago

In order for ships to be generated, shiprekt uses a block connection system that finds blocks on a server and then distinguishes if they are connected together- if they are, then classify those connected blocks as a ship. Any block in the process of being generated into a ship is referred to as "dirty". Here's where it becomes a problem in the case of lag: any time a block is placed or destroyed, ALL blocks become dirty and the block connection sequence activates (this is called dirty islands). Basically, if you place/destroy a block on your ship- ALL blocks become dirty despite the fact that it really should only be happening in your ship. Lets say that joey has a large ship with couplings all covering it. johnny comes along and rams into all the couplings and destroys them all at practically the same time. What happens? Server goes wacky mode because it is doing dirty islands for every single coupling that was destroyed.

So whats the solution? The solution is to isolate every case to its own situation.

Gingerbeard5773 commented 2 years ago

Performance with "dirty ships" has been improved. Now, if you were to break a block- in every scenario, "dirty ships" will not be called but rather a specific sequence would activate for the specific scenario (e.g ship separation). That means no large lag-spikes!

'Dirty ships' will still be activated when a block is placed outside of a ship and must create a new ship- or when two or more ships are combining together (like docking). But these instances usually will be less common and will not generate noticeable lag unless there is a large count of blocks on the map.