C-C-Minetest-Server / advtrains_doors

Other
0 stars 0 forks source link

Improve and Optimize train detection code #1

Open Emojigit opened 4 months ago

Emojigit commented 4 months ago

Current solution

Find train entities around the platform door; Problems:

  1. Longer trains may not be detected by doors far away
  2. excess ABM calls

Advtrains Occupation System (attempt-occ)

Get the train occupying the track behind the door; Problems:

  1. Relatively slow; running complex table lookup for every loaded platform doors
  2. excess ABM calls

Let the trains handle the doors (I don't know if it is possible)

Hook a callback into the train's door state change code, find all platform doors next to the occupied tracks, and change their state according to the train's state. An ABM with increased interval and decreased chance will still exist (using the OCC method) to fix malfunction doors with lower time cost.

Emojigit commented 4 months ago

... so much fun. the performance of occ-cached is even worse than occ.

In terms of long train compatibility, attempt-occ > attempt-occ-cached > master.

Entity iteration (master)

圖片

OCC without cache (attempt-occ)

圖片

OCC with cache (attempt-occ-cached)

圖片

Emojigit commented 2 months ago

Should probably wait for Advtra__ to implement door API