Commit 003ce96
authored
Massively improve performance by rewriting the network core & rendering using burst jobs (#864)
* Add the Burst toolchain and project plumbing
Reference Unity.Burst, Unity.Collections, Unity.Mathematics and Unity.Jobs
from KSPBurst so the network model can be rewritten against the job system,
and pull in Krafs.Publicizer to expose UnityEngine.Object.m_CachedPtr (for
thread-safe null checks) and List<T>._items (for an AsSpan helper).
Expose internals to the RemoteTech.Tests and RemoteTech.InGameTests
assemblies, bump the language version to 13, and replace the .slnx with a
plain .sln.
* Add the RemoteTech.Collections helpers
Later work is going to need a number of utilities. This commit adds:
* an ArrayMap class that stores keys/values in arrays internally,
* an ArrayMinHeap struct that provides a burst-compatible min-heap,
* a number of extension helper methods for various types
* an ObjectHandle struct for passing managed types to burst jobs
* a IJobParallelForBatchDefer interface and extensions
* Rewrite the network model as a Burst job pipeline
Replace the managed graph/route computation with an unmanaged pipeline built
on the Unity job system. Satellite and antenna state is projected into native
arrays (NetworkState) once per update, and connectivity, routing and the
render geometry are computed by Burst jobs (NetworkUpdate, Edges,
NetworkUpdateMath, and the line/cone/mark mesh jobs).
Antennas publish their state through a pinned AntennaData registered with
StateManager, so the jobs can read them without touching managed memory.
ISatellite gains a flat SatelliteState snapshot and Antennas becomes an
IReadOnlyList; NetworkLink/NetworkRoute become readonly struct views over the
store rather than heap-allocated objects. The range models are unified behind
IRangeModel so the job path and the managed path share one implementation.
NetworkManager drives the pipeline and NetworkRenderer draws the computed
meshes directly, replacing the per-frame NetworkCone/NetworkLine GameObjects.
* Add test harnesses for the network jobs
RemoteTech.Tests runs the Burst/NativeArray math headlessly under xunit by
backing native arrays with Marshal.AllocHGlobal (NativeArena), covering the
range/geometry math. RemoteTech.InGameTests is a KSP.Testing plugin with an
in-game runner UI that exercises the jobs against real Unity Collections
(adjacency, edges, Dijkstra, mark/cone geometry, hashing).
* Migrate the API onto the NetworkState read seam
Route the public API methods through the precomputed NetworkState instead
of the old on-demand LINQ/route materialization:
- Add a GetRoute passthrough to the NetworkManager read seam.
- GetFirstHopToKSC / GetControlPath now read the groundOnly route directly
via GetRoute rather than filtering + Min()-ing over BuildConnections.
- HasDirectGroundStation / GetClosestDirectGroundStation now test the
satellite's direct adjacency row (GetLinks) for a ground-station target.
This treats any direct link to a ground station as qualifying (not only
first hops of a shortest route) and drops the empty/self-route NRE and
the empty-sequence Min() throw.
- Replace the O(n) Satellites.Where(...).FirstOrDefault() guid scans with
the O(1) Satellites[id] indexer; GetName / GetRangeDistance use the
Network[id] indexer so ground stations still resolve.
GetSignalDelayToSatellite's arbitrary A->B pathfind is left on
NetworkPathfinder; NetworkState has no point-to-point equivalent yet.
* Gate signal relay on transit rather than link existence
Relay capability now determines whether a node may forward a signal (transit),
not whether a link exists. IsEdgeTraversable previously required both endpoints
of every edge to be relay-capable, which wrongly disconnected powered non-relay
endpoints (e.g. passive-SPU vessels) — a route's own endpoints never forward, so
they should not need to relay.
ComputeAdjacencyLists now includes an edge whenever both endpoints are powered.
The relay check moves into a per-node CanTransit bitmask: the multi-source
Dijkstra records a node's score but only expands out of it when it can transit,
and roots (route endpoints) always expand.
* Add a point-to-point signal delay query to the API
Replace GetSignalDelayToSatellite's on-demand A* (NetworkPathfinder) with a
Burst NetworkPathfindJob run over the persisted NetworkState edge table, exposed
as NetworkState.ShortestDelayBetween plus a NetworkManager passthrough. Add the
NetworkUpdateMath.EncodePairIndex helper the job uses to index the triangular
edge table.
* Hide command-station routes rooted at filtered-out vessels
The multi-path overlay drew every tree edge in the command-station
forest, so a vessel hidden by the map view filter still showed its green
route back to control. Seed the on-path set by walking the predecessor
forest from each visible vessel instead, so a route is drawn only when a
visible vessel sits at its far end.
* Remove dead network-model code superseded by NetworkState
The migration onto the Burst NetworkState left the old managed routing
orphaned. Delete the A* NetworkPathfinder and the explicit-mode half of
NetworkRoute it fed (the freestanding-path ctor, Empty, Contains, and the
BidirectionalEdge it compared against), leaving the live value-type view
into the Dijkstra forests. Drop the unused NetworkManager.FindNeighbors /
ConnectionCache / Count, the NetworkState.GetRouteLength / GetRouteOrigin
guid wrappers (callers use the internal index versions), the unused
VesselSatellite.Connections seam, and the never-referenced Dish type.
* Properly install CKAN deps in CI
* Use KSPBT for the tests project1 parent dbb7299 commit 003ce96
88 files changed
Lines changed: 7969 additions & 1507 deletions
File tree
- src/RemoteTech
- API
- AddOns
- Collections
- FlightComputer
- Commands
- Modules
- Network
- RangeModel
- SimpleTypes
- UI
- tests
- RemoteTech.InGameTests
- Collections
- Network
- RemoteTech.Tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
This file was deleted.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| |||
98 | 107 | | |
99 | 108 | | |
100 | 109 | | |
101 | | - | |
| 110 | + | |
102 | 111 | | |
103 | 112 | | |
104 | 113 | | |
| |||
113 | 122 | | |
114 | 123 | | |
115 | 124 | | |
116 | | - | |
| 125 | + | |
117 | 126 | | |
118 | 127 | | |
| 128 | + | |
119 | 129 | | |
120 | 130 | | |
121 | 131 | | |
122 | 132 | | |
123 | 133 | | |
124 | | - | |
| 134 | + | |
125 | 135 | | |
126 | 136 | | |
127 | | - | |
128 | 137 | | |
129 | | - | |
130 | 138 | | |
131 | | - | |
132 | 139 | | |
133 | | - | |
134 | | - | |
| 140 | + | |
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
| |||
163 | 169 | | |
164 | 170 | | |
165 | 171 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
0 commit comments