Dyson Sphere Program
You are viewing a potentially older version of this package. View Latest Version
Install with App

Details

Date Uploaded
Downloads
5
Size
29KB

Fast Blueprint Paste(蓝图粘贴加速)

Pasting a large blueprint no longer freezes longer and longer as more buildings wait to be built on the planet or stand beside the new sheet. 粘贴大蓝图时,点下去那一下不再随着星球上的待建建筑越多(或旁边的建筑越密)而越卡越久。

Nothing about what may be built changes: every check gives the same answer as the game's own code. Nothing is saved; remove the mod and the game is vanilla again.

What was slow

When a blueprint is clicked down, the game checks every building of the blueprint (BuildTool_BlueprintPaste.CheckBuildConditions) — twice per paste: on the click that fixes the position and on the click that confirms.

  1. Walking every unbuilt building, per blueprint building. For each blueprint building that is not a sorter and reaches higher than 4.9 m (assemblers, labs, chemical plants, refineries, raised belts …) the game walks the planet's whole list of unbuilt buildings to see whether an unbuilt EM-Rail Ejector is too close, with two dictionary lookups per entry. Power nodes, stations, turrets and a few others do similar walks. Cost = blueprint buildings × unbuilt buildings on the planet. Measured in a running game: one walk over 52 000 unbuilt buildings takes 1.24 ms, a 10 000-building sheet does about 3 800 of them per check — close to 5 s per check, 10 s per paste, for nothing (there was not one ejector among them).
  2. Looking up colliders one by one. Every collider an overlap test returns is turned into the game's collider id by comparing it with every active collider in turn (NearColliderLogic.FindColliderId). Beside dense buildings or earlier unbuilt sheets thousands of colliders are active, and a collider that is not in the table (the blueprint's own preview colliders) costs the full walk.

What the mod does

  1. Skipping irrelevant unbuilt buildings — once per check it notes which unbuilt buildings the walks can react to at all (ejectors, power nodes, stations, turrets, field generators, battlefield bases, markers, geothermal plants: usually a few hundred) and the eight walks step over only those.
  2. Fast collider lookup — the collider id comes from a dictionary filled when the game activates a collider.

If a game update changes the checked method so that the eight loops are no longer found, the first fix switches itself off and says so in the BepInEx log; the game's own code then runs unchanged.

Measured

Empty planet, a 27 085-building sheet pasted eight times side by side, nothing built in between. Time of one check (a paste does two), with 36 other mods installed:

sheet unbuilt buildings standing vanilla with the mod
1 0 0.54 s 0.53 s
2 27 085 14.1 s 0.58 s
4 81 255 41.1 s 0.66 s
6 135 425 65.1 s 0.73 s
8 189 595 92.5 s 0.81 s

Vanilla grows by about 4.5 s per 10 000 unbuilt buildings, with the mod by 15 ms. The check results of all 216 680 blueprint buildings were compared with the mod off and on: no difference.

Config (BepInEx/config/com.github.jiesiluo.fastblueprintpaste.cfg)

key default
Enabled true master switch for both fixes
FastColliderLookup true fix 2
LogTiming false write the duration of every paste check and of the prebuild creation to the log

Tests

  • tests/Offline — on the real game assembly, without the game: exactly eight loops are found and only their add is replaced.
  • tests/InGameTests + tools/run-ingame-tests.ps1 — the scenario above in a throw-away game, with the mod alone and with a full mod list (BlueprintTweaks, UXAssist, BuildToolOpt among them); see tests/README.md.
Thunderstore development is made possible with ads. Please consider making an exception to your adblock.