Compare commits
135 changed files with 18 additions and 32085 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -2,7 +2,3 @@
|
|||
__pycache__/
|
||||
/out/
|
||||
/scratch/
|
||||
bin/
|
||||
obj/
|
||||
.godot/
|
||||
.vs/
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<YmirRoot Condition="'$(YmirRoot)' == '' and '$(YMIR_ROOT)' != ''">$(YMIR_ROOT)</YmirRoot>
|
||||
<YmirRoot Condition="'$(YmirRoot)' == ''">$(MSBuildThisFileDirectory)..\Ymir</YmirRoot>
|
||||
<CultLibRoot Condition="'$(CultLibRoot)' == '' and '$(CULTLIB_ROOT)' != ''">$(CULTLIB_ROOT)</CultLibRoot>
|
||||
<CultLibRoot Condition="'$(CultLibRoot)' == ''">$(MSBuildThisFileDirectory)..\CultLib</CultLibRoot>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
59
README.md
59
README.md
|
|
@ -8,54 +8,21 @@ The lore lives in Weksa: `settings/rust-to-dust/` in
|
|||
[GameCult/Weksa](https://github.com/GameCult/Weksa) (setting, story, battle
|
||||
royale, aliens, language design). This repo holds no lore.
|
||||
|
||||
## What is live today (`nibu/rtd-prototype`)
|
||||
## What is here today
|
||||
|
||||
- **`RustToDust.Core`**:
|
||||
- Aetheria 2D grid chassis (`Dorsal` vehicles/quadrupeds and `Coronal` bipeds),
|
||||
conductive/radiative heat transfer, trapezoidal thermal plateau curves,
|
||||
localized armor + core destruction, and live cargo-to-hardpoint swapping.
|
||||
- 6 playable chassis (`buggy`, `technical`, `tank`, `manticore`, `raptor`,
|
||||
`paladin`), 8 human salvage modules, and 5 Imperial Tourist modules.
|
||||
- Shrinking `SpectatorRing` perimeter (`Tourist`, `Patron`, and `Exemplar`
|
||||
tiers with `Neutral` / `Cleared` / `Provoked` stances and Weksa-voiced
|
||||
`BroadcastFeed` commentary).
|
||||
- `TerrainField`: deterministic `1536m x 1536m` desert terrain divided into an
|
||||
`8x8` (`192m x 192m`) tile grid with procedural dunes, mesas, salvage pads,
|
||||
dirt roads, and runtime crater / tire-track / thermal-scorch stamping.
|
||||
- **`RustToDust.Ymir`**:
|
||||
- `ArenaSession` bridging `MatchState` onto Ymir's `Box3DSoaWorld` with
|
||||
4-corner spring-damper terrain support, raycast weapons, terrain crater/scorch
|
||||
impacts, and AI contenders + perimeter spectators.
|
||||
- **`tests/RustToDust.Tests`**:
|
||||
- Behavioral xUnit suite covering Aetheria grid heat, spectator ring clearance,
|
||||
Ymir vehicle driving/combat/swapping, and procedural/dynamic terrain relief.
|
||||
- **`client/` (Godot 4.7.2 Mono)**:
|
||||
- 3D desert client with a top-down orthographic `SubViewport` brush-to-tile PBR
|
||||
+ height displacement baker, procedural 3D chassis/spectator silhouettes,
|
||||
tactical radar, clickable Aetheria Hardpoint & Heat schematic, and Imperial
|
||||
Broadcast chyron.
|
||||
Nothing runnable yet. This repo is the home for the mech work now being
|
||||
prototyped:
|
||||
|
||||
## Build, test, and run
|
||||
- mechs kitbashed from parts with [Brokkr](https://eureka.gamecult.org/forge/GameCult/Brokkr)
|
||||
(armour shells, ribs, cuts, joints, hoses, frames);
|
||||
- a mechanical rig with one bone per degree of freedom, driven rams and linkages;
|
||||
- generic walk and combat animation retargeted onto each chassis.
|
||||
|
||||
Requires a sibling `Ymir` checkout beside `RustToDust` (or `YMIR_ROOT` set),
|
||||
CMake, a C compiler, .NET SDK 8/10, and Godot 4.7.2 Mono (`--path client`).
|
||||
That work currently lives on `nibu/fable-*` experiment branches in
|
||||
GameCult/Brokkr and moves here as it settles.
|
||||
|
||||
```bash
|
||||
# Run the behavioral test suite
|
||||
dotnet test tests/RustToDust.Tests/RustToDust.Tests.csproj -c Release
|
||||
## Planned, not live
|
||||
|
||||
# Build the Godot 4.7.2 Mono client assembly (also builds Ymir native Box3D)
|
||||
dotnet build client/RustToDust.Client.csproj -c Debug
|
||||
|
||||
# Run the playable 3D client
|
||||
godot --path client
|
||||
|
||||
# Run the headless Godot smoke test
|
||||
godot --headless --path client res://tests/Smoke.tscn
|
||||
```
|
||||
|
||||
## Planned, not live yet
|
||||
|
||||
- Kitbashed Brokkr mechanical rigs and goal-space walk/combat retargeting
|
||||
replacing the procedural box/cylinder silhouettes.
|
||||
- Multiplayer networking and audio synthesis.
|
||||
- Mech parts library and chassis definitions.
|
||||
- Rig generator and goal-space retargeting solver.
|
||||
- A playable walk-and-fight prototype.
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
<Solution>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/RustToDust.Core/RustToDust.Core.csproj" />
|
||||
<Project Path="src/RustToDust.Ymir/RustToDust.Ymir.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/tests/">
|
||||
<Project Path="tests/RustToDust.Tests/RustToDust.Tests.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 787 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 212 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 491 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,154 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "anvil",
|
||||
"name": "Anvil",
|
||||
"class": "Heavy Quad-Track Siege Tank",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.front",
|
||||
"kind": "armor",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 5,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.front"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.sponson_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.sponson_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.siege_l",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.siege_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.sides",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.armor.sides"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.siege_r",
|
||||
"kind": "weapon",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.siege_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.sponson_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.sponson_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.rear",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"w": 3,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.rear"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.l",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.r",
|
||||
"kind": "radiator",
|
||||
"x": 4,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.93,
|
||||
0.0,
|
||||
-2.8252
|
||||
],
|
||||
"max": [
|
||||
1.93,
|
||||
3.0266,
|
||||
2.8252
|
||||
],
|
||||
"size": [
|
||||
3.86,
|
||||
3.0266,
|
||||
5.6504
|
||||
]
|
||||
},
|
||||
"triCount": 18044
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,151 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "bastion",
|
||||
"name": "Bastion",
|
||||
"class": "Heavy Siege Quadruped",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 6,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.prow",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"w": 2,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.prow"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.turret_pd",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.turret_pd"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.turret_main",
|
||||
"kind": "weapon",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.turret_main"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.flank_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.flank_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.flank_r",
|
||||
"kind": "weapon",
|
||||
"x": 5,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.flank_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 3,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.rear_l",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.rear_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.rear_r",
|
||||
"kind": "radiator",
|
||||
"x": 4,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.rear_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-6.6043,
|
||||
0.0,
|
||||
-8.043
|
||||
],
|
||||
"max": [
|
||||
6.6094,
|
||||
9.625,
|
||||
6.7519
|
||||
],
|
||||
"size": [
|
||||
13.2137,
|
||||
9.625,
|
||||
14.7949
|
||||
]
|
||||
},
|
||||
"triCount": 36656
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
|
|
@ -1,225 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "condor",
|
||||
"name": "Condor",
|
||||
"class": "Heavy Quad-Thruster Assault VTOL",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.nose",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"w": 2,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.nose"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.hull",
|
||||
"kind": "armor",
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.hull"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.sponson_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.sponson_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.dorsal",
|
||||
"kind": "weapon",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.dorsal"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.sponson_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.sponson_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"w": 3,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.spine_l",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.spine_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.spine_r",
|
||||
"kind": "radiator",
|
||||
"x": 4,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.spine_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.nacelle_fl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_fl",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.nacelle_fr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_fr",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.nacelle_rl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_rl",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.nacelle_rr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_rr",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-2.3586,
|
||||
0.0,
|
||||
-3.1
|
||||
],
|
||||
"max": [
|
||||
2.3586,
|
||||
2.2046,
|
||||
2.7758
|
||||
],
|
||||
"size": [
|
||||
4.7172,
|
||||
2.2046,
|
||||
5.8758
|
||||
]
|
||||
},
|
||||
"triCount": 12960
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,100 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "ferret",
|
||||
"name": "Ferret",
|
||||
"class": "Light Tracked Scout Tankette",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 3,
|
||||
"gridHeight": 4,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.glacis",
|
||||
"kind": "armor",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 3,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.glacis"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.pod",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.pod"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.turret",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.turret"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.rear",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.rear"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.deck",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.deck"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.1075,
|
||||
0.0,
|
||||
-1.8009
|
||||
],
|
||||
"max": [
|
||||
1.1075,
|
||||
1.5523,
|
||||
1.869
|
||||
],
|
||||
"size": [
|
||||
2.215,
|
||||
1.5523,
|
||||
3.6699
|
||||
]
|
||||
},
|
||||
"triCount": 7612
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,143 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "hornet",
|
||||
"name": "Hornet",
|
||||
"class": "Light Ducted-Fan VTOL Gunship",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 4,
|
||||
"gridHeight": 4,
|
||||
"mask": [
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.chin",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.chin"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.nacelle_l",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.nacelle_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.nacelle_r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.nacelle_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.wing_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.wing_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.wing_r",
|
||||
"kind": "weapon",
|
||||
"x": 3,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.wing_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.nacelle_l",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_l",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.nacelle_r",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.rotor_r",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.65,
|
||||
-0.0,
|
||||
-2.6715
|
||||
],
|
||||
"max": [
|
||||
1.65,
|
||||
1.8235,
|
||||
2.0
|
||||
],
|
||||
"size": [
|
||||
3.3,
|
||||
1.8235,
|
||||
4.6715
|
||||
]
|
||||
},
|
||||
"triCount": 7252
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,126 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "ironclad",
|
||||
"name": "Ironclad",
|
||||
"class": "Medium Tracked Battle Tank",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 4,
|
||||
"gridHeight": 5,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.front",
|
||||
"kind": "armor",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 4,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.front"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.coax",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.coax"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.main",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.main"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.skirts",
|
||||
"kind": "armor",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.armor.skirts"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.l",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.rear",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.rear"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.5272,
|
||||
0.0,
|
||||
-2.4115
|
||||
],
|
||||
"max": [
|
||||
1.4934,
|
||||
1.792,
|
||||
2.3554
|
||||
],
|
||||
"size": [
|
||||
3.0206,
|
||||
1.792,
|
||||
4.7669
|
||||
]
|
||||
},
|
||||
"triCount": 16840
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,132 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "jackal",
|
||||
"name": "Jackal",
|
||||
"class": "Light Wheeled Dune Buggy",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 3,
|
||||
"gridHeight": 4,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.roof",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.roof"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.rear",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.rear"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.rear",
|
||||
"kind": "radiator",
|
||||
"x": 2,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.rear"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.steer_fl",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -32.0,
|
||||
"max": 32.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.steer_fr",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -32.0,
|
||||
"max": 32.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-0.9778,
|
||||
0.0,
|
||||
-1.5461
|
||||
],
|
||||
"max": [
|
||||
0.9778,
|
||||
1.5457,
|
||||
1.705
|
||||
],
|
||||
"size": [
|
||||
1.9556,
|
||||
1.5457,
|
||||
3.2511
|
||||
]
|
||||
},
|
||||
"triCount": 16068
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,133 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "kestrel",
|
||||
"name": "Kestrel",
|
||||
"class": "Light Scout Biped",
|
||||
"plane": "Coronal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 5,
|
||||
"mask": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.dorsal",
|
||||
"kind": "weapon",
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.dorsal"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.chest",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.chest"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.back",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.back"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.torso_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -90.0,
|
||||
"max": 90.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_l_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 60.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_r_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 60.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-2.6628,
|
||||
0.0,
|
||||
-2.0753
|
||||
],
|
||||
"max": [
|
||||
2.6048,
|
||||
9.7815,
|
||||
2.378
|
||||
],
|
||||
"size": [
|
||||
5.2676,
|
||||
9.7815,
|
||||
4.4533
|
||||
]
|
||||
},
|
||||
"triCount": 41374
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,259 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "mammoth",
|
||||
"name": "Mammoth",
|
||||
"class": "Heavy 8x8 Armored Fire Support Rig",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 4,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.glacis",
|
||||
"kind": "armor",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 4,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.glacis"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.bow",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.bow"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.turret_l",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.turret_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.turret_r",
|
||||
"kind": "weapon",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.turret_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.flanks",
|
||||
"kind": "armor",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.armor.flanks"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.rear",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.rear"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.l",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.steer_fl1",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -28.0,
|
||||
"max": 28.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fl1",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.steer_fr1",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -28.0,
|
||||
"max": 28.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fr1",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.steer_fl2",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -28.0,
|
||||
"max": 28.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fl2",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.steer_fr2",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -28.0,
|
||||
"max": 28.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fr2",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rl1",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rr1",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rl2",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rr2",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.turret_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -180.0,
|
||||
"max": 180.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.46,
|
||||
0.0,
|
||||
-2.64
|
||||
],
|
||||
"max": [
|
||||
1.46,
|
||||
2.3467,
|
||||
3.2249
|
||||
],
|
||||
"size": [
|
||||
2.92,
|
||||
2.3467,
|
||||
5.8649
|
||||
]
|
||||
},
|
||||
"triCount": 20512
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1,171 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "manticore",
|
||||
"name": "Manticore",
|
||||
"class": "Heavy Quadruped Scorpion",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 5,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.chin",
|
||||
"kind": "weapon",
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.chin"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.flank_l",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.flank_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.flank_r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.flank_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.l"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.r"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.prow",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.prow"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.tail_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -75.0,
|
||||
"max": 75.0
|
||||
},
|
||||
{
|
||||
"id": "joint.tail_s1",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -60.0,
|
||||
"max": 60.0
|
||||
},
|
||||
{
|
||||
"id": "joint.tail_s2",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -75.0,
|
||||
"max": 15.0
|
||||
},
|
||||
{
|
||||
"id": "joint.tail_s3",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -80.0,
|
||||
"max": 10.0
|
||||
},
|
||||
{
|
||||
"id": "joint.tail_elev",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -40.0,
|
||||
"max": 30.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-3.4374,
|
||||
0.0,
|
||||
-4.5621
|
||||
],
|
||||
"max": [
|
||||
3.4358,
|
||||
6.5001,
|
||||
4.547
|
||||
],
|
||||
"size": [
|
||||
6.8732,
|
||||
6.5001,
|
||||
9.1091
|
||||
]
|
||||
},
|
||||
"triCount": 33517
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,182 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "mule",
|
||||
"name": "Mule",
|
||||
"class": "Medium 6x6 Armored Gun Truck",
|
||||
"plane": "Dorsal",
|
||||
"gridWidth": 3,
|
||||
"gridHeight": 5,
|
||||
"mask": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.armor.front",
|
||||
"kind": "armor",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 3,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.front"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.left",
|
||||
"kind": "radiator",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.left"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.front",
|
||||
"kind": "engine",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.front"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.right",
|
||||
"kind": "radiator",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.radiator.right"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.cab",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 3,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.cab"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.bed_main",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.bed_main"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.steer_fl",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -30.0,
|
||||
"max": 30.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.steer_fr",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -30.0,
|
||||
"max": 30.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_fr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_ml",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_mr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rl",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
},
|
||||
{
|
||||
"id": "joint.wheel_rr",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -360.0,
|
||||
"max": 360.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-1.1938,
|
||||
0.0,
|
||||
-2.4067
|
||||
],
|
||||
"max": [
|
||||
1.1938,
|
||||
2.0889,
|
||||
2.46
|
||||
],
|
||||
"size": [
|
||||
2.3876,
|
||||
2.0889,
|
||||
4.8667
|
||||
]
|
||||
},
|
||||
"triCount": 13772
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,186 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "paladin",
|
||||
"name": "Paladin",
|
||||
"class": "Heavy Assault Biped",
|
||||
"plane": "Coronal",
|
||||
"gridWidth": 6,
|
||||
"gridHeight": 7,
|
||||
"mask": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.sh_l",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.sh_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.torso",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 2,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.torso"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.sh_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.sh_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.chest",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
"w": 2,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.chest"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_r",
|
||||
"kind": "weapon",
|
||||
"x": 5,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.back_l",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.back_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.legs",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 4,
|
||||
"w": 2,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.legs"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.back_r",
|
||||
"kind": "radiator",
|
||||
"x": 4,
|
||||
"y": 4,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.back_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.torso_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -90.0,
|
||||
"max": 90.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_l_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -40.0,
|
||||
"max": 70.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_r_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -40.0,
|
||||
"max": 70.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-4.4388,
|
||||
-0.0,
|
||||
-1.5109
|
||||
],
|
||||
"max": [
|
||||
4.4387,
|
||||
11.3161,
|
||||
2.4514
|
||||
],
|
||||
"size": [
|
||||
8.8775,
|
||||
11.3161,
|
||||
3.9623
|
||||
]
|
||||
},
|
||||
"triCount": 36463
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,128 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "raptor",
|
||||
"name": "Raptor",
|
||||
"class": "Medium Theropod Biped",
|
||||
"plane": "Coronal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.radiator.sh_l",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.sh_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.sh_r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.sh_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.chest",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.chest"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.arm_l_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 45.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_r_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 45.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-2.3822,
|
||||
0.0,
|
||||
-4.422
|
||||
],
|
||||
"max": [
|
||||
2.3822,
|
||||
6.9873,
|
||||
4.5553
|
||||
],
|
||||
"size": [
|
||||
4.7644,
|
||||
6.9873,
|
||||
8.9773
|
||||
]
|
||||
},
|
||||
"triCount": 36156
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,156 +0,0 @@
|
|||
{
|
||||
"schema": "rtd.vehicle.manifest.v1",
|
||||
"id": "spectre",
|
||||
"name": "Spectre",
|
||||
"class": "Medium Recon/Skirmisher Biped",
|
||||
"plane": "Coronal",
|
||||
"gridWidth": 5,
|
||||
"gridHeight": 6,
|
||||
"mask": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"hardpoints": [
|
||||
{
|
||||
"id": "hp.weapon.shoulder_l",
|
||||
"kind": "weapon",
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.weapon.shoulder_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.armor.torso",
|
||||
"kind": "armor",
|
||||
"x": 2,
|
||||
"y": 1,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.armor.torso"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_l",
|
||||
"kind": "weapon",
|
||||
"x": 0,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.back_l",
|
||||
"kind": "radiator",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.back_l"
|
||||
},
|
||||
{
|
||||
"id": "hp.engine.core",
|
||||
"kind": "engine",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.engine.core"
|
||||
},
|
||||
{
|
||||
"id": "hp.radiator.back_r",
|
||||
"kind": "radiator",
|
||||
"x": 3,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 1,
|
||||
"modelNodeId": "hp.radiator.back_r"
|
||||
},
|
||||
{
|
||||
"id": "hp.weapon.arm_r",
|
||||
"kind": "weapon",
|
||||
"x": 4,
|
||||
"y": 2,
|
||||
"w": 1,
|
||||
"h": 2,
|
||||
"modelNodeId": "hp.weapon.arm_r"
|
||||
}
|
||||
],
|
||||
"joints": [
|
||||
{
|
||||
"id": "joint.torso_yaw",
|
||||
"axis": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min": -90.0,
|
||||
"max": 90.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_l_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 60.0
|
||||
},
|
||||
{
|
||||
"id": "joint.arm_r_pitch",
|
||||
"axis": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"min": -45.0,
|
||||
"max": 60.0
|
||||
}
|
||||
],
|
||||
"bounds": {
|
||||
"min": [
|
||||
-3.4467,
|
||||
-0.0,
|
||||
-2.442
|
||||
],
|
||||
"max": [
|
||||
3.8332,
|
||||
8.9891,
|
||||
3.6426
|
||||
],
|
||||
"size": [
|
||||
7.2799,
|
||||
8.9891,
|
||||
6.0846
|
||||
]
|
||||
},
|
||||
"triCount": 40696
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,761 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Renders the 3D arena entities from <see cref="ArenaSession"/>:
|
||||
/// cover ruins, shrinking Safe Circle ring, real Brokkr vehicle/mech GLBs with hardpoint snap-on gear,
|
||||
/// live secondary mechanism animations, part-by-cell debris detachment, 3 alien spectator tiers + status halos/lock lasers,
|
||||
/// real gear/chassis salvage drops, and weapon tracers.
|
||||
/// </summary>
|
||||
public partial class ArenaRenderer : Node3D
|
||||
{
|
||||
private static readonly Color OlivePaint = Color.FromHtml("#9bb06a");
|
||||
private static readonly Color TouristGold = Color.FromHtml("#e6b838");
|
||||
private static readonly Color CyanSalvage = Color.FromHtml("#44d9e8");
|
||||
private static readonly Color CoverRust = Color.FromHtml("#4d433b");
|
||||
private static readonly Color BermDark = Color.FromHtml("#2c2723");
|
||||
|
||||
private sealed class ActorVisual
|
||||
{
|
||||
public required VehicleVisualInstance Visual;
|
||||
public MeshInstance3D? HaloMesh;
|
||||
public StandardMaterial3D? HaloMat;
|
||||
public MeshInstance3D? LaserMesh;
|
||||
public SpectatorStance? LastHaloStance;
|
||||
public bool LastLaserVisible;
|
||||
}
|
||||
|
||||
private sealed class DropVisualEntry
|
||||
{
|
||||
public required Node3D Node;
|
||||
public VehicleVisualInstance? ChassisVisual;
|
||||
public float BaseY;
|
||||
public int TileX;
|
||||
public int TileZ;
|
||||
public int TileVersion;
|
||||
}
|
||||
|
||||
private VehicleAssetCache _assetCache = null!;
|
||||
private Node3D _staticGroup = null!;
|
||||
private Node3D _actorsGroup = null!;
|
||||
private Node3D _dropsGroup = null!;
|
||||
private Node3D _tracersGroup = null!;
|
||||
private DebrisSystem _debris = null!;
|
||||
private MeshInstance3D _safeRingMesh = null!;
|
||||
private ImmediateMesh _safeRingImm = null!;
|
||||
|
||||
private readonly Dictionary<int, ActorVisual> _contenderVisuals = new();
|
||||
private readonly Dictionary<int, ActorVisual> _spectatorVisuals = new();
|
||||
private readonly Dictionary<int, DropVisualEntry> _dropVisuals = new();
|
||||
private readonly List<MeshInstance3D> _tracerPool = new();
|
||||
|
||||
private StandardMaterial3D _safeRingMat = null!;
|
||||
private StandardMaterial3D _coverMat = null!;
|
||||
private StandardMaterial3D _bermMat = null!;
|
||||
private StandardMaterial3D _humanBeaconMat = null!;
|
||||
private StandardMaterial3D _imperialBeaconMat = null!;
|
||||
private StandardMaterial3D _cyanBeaconMat = null!;
|
||||
private MatchState? _builtForState;
|
||||
private float _lastSafeRingRadius = -1f;
|
||||
|
||||
public VehicleAssetCache AssetCache => _assetCache;
|
||||
public DebrisSystem Debris => _debris;
|
||||
|
||||
public VehicleVisualInstance? GetContenderVisual(int contenderId) =>
|
||||
_contenderVisuals.TryGetValue(contenderId, out var vis) ? vis.Visual : null;
|
||||
|
||||
public VehicleVisualInstance? GetSpectatorVisual(int spectatorId) =>
|
||||
_spectatorVisuals.TryGetValue(spectatorId, out var vis) ? vis.Visual : null;
|
||||
|
||||
internal float? GetSpectatorHaloLocalY(int spectatorId) =>
|
||||
_spectatorVisuals.TryGetValue(spectatorId, out var vis) && vis.HaloMesh is not null
|
||||
? vis.HaloMesh.Position.Y
|
||||
: null;
|
||||
|
||||
internal int ActiveDropVisualCount => _dropVisuals.Count;
|
||||
internal int DropGroupChildCount => _dropsGroup.GetChildCount();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_assetCache = new VehicleAssetCache();
|
||||
|
||||
_staticGroup = new Node3D { Name = "StaticArena" };
|
||||
_actorsGroup = new Node3D { Name = "Actors" };
|
||||
_dropsGroup = new Node3D { Name = "GroundDrops" };
|
||||
_tracersGroup = new Node3D { Name = "Tracers" };
|
||||
_debris = new DebrisSystem { Name = "Debris" };
|
||||
AddChild(_staticGroup);
|
||||
AddChild(_actorsGroup);
|
||||
AddChild(_dropsGroup);
|
||||
AddChild(_tracersGroup);
|
||||
AddChild(_debris);
|
||||
|
||||
_coverMat = new StandardMaterial3D { AlbedoColor = CoverRust, Roughness = 0.88f, Metallic = 0.25f };
|
||||
_bermMat = new StandardMaterial3D { AlbedoColor = BermDark, Roughness = 0.94f, Metallic = 0.1f };
|
||||
_humanBeaconMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(OlivePaint.R, OlivePaint.G, OlivePaint.B, 0.72f),
|
||||
Roughness = 0.55f,
|
||||
Metallic = 0.35f,
|
||||
EmissionEnabled = true,
|
||||
Emission = OlivePaint,
|
||||
EmissionEnergyMultiplier = 0.6f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
_imperialBeaconMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(TouristGold.R, TouristGold.G, TouristGold.B, 0.82f),
|
||||
Roughness = 0.35f,
|
||||
Metallic = 0.8f,
|
||||
EmissionEnabled = true,
|
||||
Emission = TouristGold,
|
||||
EmissionEnergyMultiplier = 1.4f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
_cyanBeaconMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(CyanSalvage.R, CyanSalvage.G, CyanSalvage.B, 0.72f),
|
||||
EmissionEnabled = true,
|
||||
Emission = CyanSalvage,
|
||||
EmissionEnergyMultiplier = 1.5f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
|
||||
_safeRingImm = new ImmediateMesh();
|
||||
_safeRingMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(1.0f, 0.38f, 0.14f, 0.78f),
|
||||
EmissionEnabled = true,
|
||||
Emission = new Color(1.0f, 0.32f, 0.08f),
|
||||
EmissionEnergyMultiplier = 1.6f,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha,
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
CullMode = BaseMaterial3D.CullModeEnum.Disabled
|
||||
};
|
||||
_safeRingMesh = new MeshInstance3D
|
||||
{
|
||||
Name = "SafeRing",
|
||||
Mesh = _safeRingImm,
|
||||
MaterialOverride = _safeRingMat,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
AddChild(_safeRingMesh);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_assetCache?.Dispose();
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session, float elapsedSeconds, float dt = 1f / 60f)
|
||||
{
|
||||
var state = session.State;
|
||||
if (!ReferenceEquals(_builtForState, state))
|
||||
{
|
||||
RebuildStaticArena(state);
|
||||
ClearDynamicVisuals();
|
||||
_builtForState = state;
|
||||
}
|
||||
|
||||
Camera3D? cam = GetViewport()?.GetCamera3D();
|
||||
bool hasCam = cam is not null && cam.IsInsideTree();
|
||||
Vector3 camPos = hasCam ? cam!.GlobalPosition : Vector3.Zero;
|
||||
|
||||
UpdateSafeCircleRing(state.Terrain, state.Spectators.SafeRadius);
|
||||
SyncContenders(session, dt, hasCam, camPos);
|
||||
SyncSpectators(session, elapsedSeconds, dt, hasCam, camPos);
|
||||
SyncGroundDrops(state, elapsedSeconds, hasCam, camPos);
|
||||
SyncTracers(state.Tracers);
|
||||
_debris.Step(dt, state.Terrain);
|
||||
}
|
||||
|
||||
private void RebuildStaticArena(MatchState state)
|
||||
{
|
||||
ClearChildren(_staticGroup);
|
||||
|
||||
for (int i = 0; i < state.ArenaCoverBoxes.Count; i++)
|
||||
{
|
||||
var b = state.ArenaCoverBoxes[i];
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
||||
MaterialOverride = _coverMat,
|
||||
Position = new Vector3(b.X, b.Y, b.Z)
|
||||
};
|
||||
_staticGroup.AddChild(mesh);
|
||||
}
|
||||
|
||||
for (int i = 0; i < state.ArenaBoundaryBoxes.Count; i++)
|
||||
{
|
||||
var b = state.ArenaBoundaryBoxes[i];
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(b.HalfX * 2f, b.HalfY * 2f, b.HalfZ * 2f) },
|
||||
MaterialOverride = _bermMat,
|
||||
Position = new Vector3(b.X, b.Y, b.Z),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
_staticGroup.AddChild(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearDynamicVisuals()
|
||||
{
|
||||
ClearChildren(_actorsGroup);
|
||||
ClearChildren(_dropsGroup);
|
||||
_debris.ClearAll();
|
||||
_contenderVisuals.Clear();
|
||||
_spectatorVisuals.Clear();
|
||||
_dropVisuals.Clear();
|
||||
_lastSafeRingRadius = -1f;
|
||||
}
|
||||
|
||||
private void UpdateSafeCircleRing(TerrainField terrain, float safeRadius)
|
||||
{
|
||||
if (_lastSafeRingRadius >= 0f && MathF.Abs(safeRadius - _lastSafeRingRadius) < 0.15f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastSafeRingRadius = safeRadius;
|
||||
|
||||
_safeRingImm.ClearSurfaces();
|
||||
_safeRingImm.SurfaceBegin(Mesh.PrimitiveType.Triangles);
|
||||
|
||||
const int segments = 160;
|
||||
const float halfThick = 1.1f;
|
||||
float rInner = MathF.Max(2f, safeRadius - halfThick);
|
||||
float rOuter = safeRadius + halfThick;
|
||||
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
float a0 = (i / (float)segments) * MathF.Tau;
|
||||
float a1 = ((i + 1) / (float)segments) * MathF.Tau;
|
||||
float c0 = MathF.Cos(a0), s0 = MathF.Sin(a0);
|
||||
float c1 = MathF.Cos(a1), s1 = MathF.Sin(a1);
|
||||
|
||||
float x0i = c0 * rInner, z0i = s0 * rInner;
|
||||
float x0o = c0 * rOuter, z0o = s0 * rOuter;
|
||||
float x1i = c1 * rInner, z1i = s1 * rInner;
|
||||
float x1o = c1 * rOuter, z1o = s1 * rOuter;
|
||||
|
||||
float y0 = terrain.SampleHeight(c0 * safeRadius, s0 * safeRadius) + 0.42f;
|
||||
float y1 = terrain.SampleHeight(c1 * safeRadius, s1 * safeRadius) + 0.42f;
|
||||
|
||||
var p0i = new Vector3(x0i, y0, z0i);
|
||||
var p0o = new Vector3(x0o, y0, z0o);
|
||||
var p1i = new Vector3(x1i, y1, z1i);
|
||||
var p1o = new Vector3(x1o, y1, z1o);
|
||||
|
||||
_safeRingImm.SurfaceAddVertex(p0i);
|
||||
_safeRingImm.SurfaceAddVertex(p0o);
|
||||
_safeRingImm.SurfaceAddVertex(p1o);
|
||||
|
||||
_safeRingImm.SurfaceAddVertex(p0i);
|
||||
_safeRingImm.SurfaceAddVertex(p1o);
|
||||
_safeRingImm.SurfaceAddVertex(p1i);
|
||||
}
|
||||
|
||||
_safeRingImm.SurfaceEnd();
|
||||
}
|
||||
|
||||
private void SyncContenders(ArenaSession session, float dt, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var contenders = session.State.Contenders;
|
||||
|
||||
for (int i = 0; i < contenders.Count; i++)
|
||||
{
|
||||
var c = contenders[i];
|
||||
if (!c.Alive)
|
||||
{
|
||||
if (_contenderVisuals.TryGetValue(c.Id, out var deadVis))
|
||||
{
|
||||
// Flush any final stripped plates/gear into debris before hiding wreck
|
||||
deadVis.Visual.SyncDamageAndHeat(c.Grid, _debris, Vector3.Zero);
|
||||
deadVis.Visual.Root.Visible = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_contenderVisuals.TryGetValue(c.Id, out var vis) || vis.Visual.ChassisId != c.Grid.Spec.Id)
|
||||
{
|
||||
if (vis is not null)
|
||||
{
|
||||
vis.Visual.Root.QueueFree();
|
||||
}
|
||||
|
||||
var role = c.IsPlayer ? VehicleVisualRole.Player : VehicleVisualRole.Rival;
|
||||
var instance = VehicleVisualInstance.Create(_assetCache, c.Grid.Spec.Id, role);
|
||||
instance.SyncMountedGear(c.Grid);
|
||||
_actorsGroup.AddChild(instance.Root);
|
||||
vis = new ActorVisual { Visual = instance };
|
||||
_contenderVisuals[c.Id] = vis;
|
||||
}
|
||||
|
||||
vis.Visual.Root.Visible = true;
|
||||
|
||||
Vector3 pos;
|
||||
Vector3 vel;
|
||||
var body = session.GetContenderBody(c.Id);
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = new Vector3(c.X, c.Y, c.Z);
|
||||
vel = Vector3.Zero;
|
||||
vis.Visual.Root.Position = pos;
|
||||
vis.Visual.Root.Rotation = new Vector3(0f, c.Yaw, 0f);
|
||||
}
|
||||
|
||||
bool useStaticLod = false;
|
||||
bool castShadows = true;
|
||||
if (hasCam && !c.IsPlayer)
|
||||
{
|
||||
float distSq = pos.DistanceSquaredTo(camPos);
|
||||
useStaticLod = vis.Visual.IsStaticLod ? distSq > 126f * 126f : distSq > 130f * 130f;
|
||||
castShadows = distSq <= 150f * 150f;
|
||||
}
|
||||
vis.Visual.SetLodState(useStaticLod, castShadows);
|
||||
|
||||
if (!useStaticLod)
|
||||
{
|
||||
vis.Visual.SyncMountedGear(c.Grid);
|
||||
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, dt);
|
||||
vis.Visual.SyncDamageAndHeat(c.Grid, _debris, vel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncSpectators(ArenaSession session, float elapsedSeconds, float dt, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var specs = session.State.Spectators.Spectators;
|
||||
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
{
|
||||
var s = specs[i];
|
||||
if (!s.Alive)
|
||||
{
|
||||
if (_spectatorVisuals.TryGetValue(s.Id, out var deadVis))
|
||||
{
|
||||
deadVis.Visual.SyncDamageAndHeat(s.Grid, _debris, Vector3.Zero);
|
||||
deadVis.Visual.Root.Visible = false;
|
||||
if (deadVis.LaserMesh is not null)
|
||||
{
|
||||
deadVis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_spectatorVisuals.TryGetValue(s.Id, out var vis))
|
||||
{
|
||||
var role = s.Tier switch
|
||||
{
|
||||
SpectatorTier.Tourist => VehicleVisualRole.SpectatorTourist,
|
||||
SpectatorTier.Patron => VehicleVisualRole.SpectatorPatron,
|
||||
_ => VehicleVisualRole.SpectatorExemplar
|
||||
};
|
||||
var instance = VehicleVisualInstance.Create(
|
||||
_assetCache,
|
||||
s.Grid.Spec.Id,
|
||||
role,
|
||||
visualScale: 1f,
|
||||
targetHalfHeight: s.Grid.Spec.HalfHeight);
|
||||
instance.SyncMountedGear(s.Grid);
|
||||
_actorsGroup.AddChild(instance.Root);
|
||||
vis = CreateSpectatorVisualWrapper(instance);
|
||||
_spectatorVisuals[s.Id] = vis;
|
||||
}
|
||||
|
||||
vis.Visual.Root.Visible = true;
|
||||
var body = session.GetSpectatorBody(s.Id);
|
||||
Vector3 specPos;
|
||||
Vector3 vel;
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
specPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), specPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
specPos = new Vector3(s.X, s.Y, s.Z);
|
||||
vel = Vector3.Zero;
|
||||
vis.Visual.Root.Position = specPos;
|
||||
vis.Visual.Root.Rotation = new Vector3(0f, s.Yaw, 0f);
|
||||
}
|
||||
|
||||
bool useStaticLod = false;
|
||||
bool castShadows = true;
|
||||
if (hasCam)
|
||||
{
|
||||
float distSq = specPos.DistanceSquaredTo(camPos);
|
||||
useStaticLod = vis.Visual.IsStaticLod ? distSq > 126f * 126f : distSq > 130f * 130f;
|
||||
castShadows = distSq <= 150f * 150f;
|
||||
}
|
||||
vis.Visual.SetLodState(useStaticLod, castShadows);
|
||||
|
||||
ContenderState? target = s.TargetContenderId.HasValue &&
|
||||
s.TargetContenderId.Value >= 0 &&
|
||||
s.TargetContenderId.Value < session.State.Contenders.Count
|
||||
? session.State.Contenders[s.TargetContenderId.Value]
|
||||
: null;
|
||||
|
||||
if (!useStaticLod)
|
||||
{
|
||||
float aimYawWorld = s.Yaw;
|
||||
float aimPitchDeg = 0f;
|
||||
if (s.Stance != SpectatorStance.Neutral && target is { Alive: true })
|
||||
{
|
||||
float tdx = target.X - s.X;
|
||||
float tdz = target.Z - s.Z;
|
||||
if (tdx * tdx + tdz * tdz > 0.01f)
|
||||
{
|
||||
aimYawWorld = MathF.Atan2(tdx, tdz);
|
||||
float horiz = MathF.Sqrt(tdx * tdx + tdz * tdz);
|
||||
float eyeY = MatchRules.GetObserverEyeY(s.Y, s.Grid.Spec.HalfHeight);
|
||||
float targetY = MatchRules.GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight);
|
||||
aimPitchDeg = Mathf.RadToDeg(MathF.Atan2(targetY - eyeY, horiz));
|
||||
}
|
||||
}
|
||||
|
||||
var rigInput = new VehicleRigDriveInput(
|
||||
Velocity: vel,
|
||||
Yaw: s.Yaw,
|
||||
AimYawWorld: aimYawWorld,
|
||||
AimPitchDeg: aimPitchDeg,
|
||||
SteerCmd: 0f,
|
||||
ThrottleCmd: vel.Length() > 0.5f ? 0.6f : 0f,
|
||||
VerticalThrottleCmd: 0f,
|
||||
EngineThermalPerf: s.Grid.ComputeEngineThermalPerformance(),
|
||||
DeltaTime: dt,
|
||||
IsGrounded: !s.Grid.Spec.IsVtol);
|
||||
|
||||
vis.Visual.SyncMountedGear(s.Grid);
|
||||
VehicleRigAnimator.Update(vis.Visual, in rigInput, vis.Visual.Root.Basis);
|
||||
vis.Visual.SyncDamageAndHeat(s.Grid, _debris, vel);
|
||||
}
|
||||
|
||||
// Status halo
|
||||
if (vis.HaloMat is not null && vis.HaloMesh is not null &&
|
||||
(vis.LastHaloStance != s.Stance || s.Stance == SpectatorStance.Provoked))
|
||||
{
|
||||
vis.LastHaloStance = s.Stance;
|
||||
if (s.Stance == SpectatorStance.Neutral)
|
||||
{
|
||||
vis.HaloMat.AlbedoColor = new Color(0.88f, 0.65f, 0.25f, 0.45f);
|
||||
vis.HaloMat.Emission = new Color(0.88f, 0.65f, 0.25f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = 0.6f;
|
||||
}
|
||||
else if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.22f, 0.18f, 0.9f);
|
||||
vis.HaloMat.Emission = new Color(1.0f, 0.2f, 0.15f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float pulse = 1.6f + 1.2f * MathF.Sin(elapsedSeconds * 10f);
|
||||
vis.HaloMat.AlbedoColor = new Color(1.0f, 0.1f, 0.1f, 0.95f);
|
||||
vis.HaloMat.Emission = new Color(1.0f, 0.08f, 0.08f);
|
||||
vis.HaloMat.EmissionEnergyMultiplier = pulse;
|
||||
}
|
||||
}
|
||||
|
||||
// Lock-on laser beam when Cleared or Provoked
|
||||
if (vis.LaserMesh is not null)
|
||||
{
|
||||
if (s.Stance != SpectatorStance.Neutral && s.HasTargetLos && target is { Alive: true })
|
||||
{
|
||||
Vector3 start = specPos + new Vector3(0f, s.Grid.Spec.HalfHeight * 0.7f, 0f);
|
||||
Vector3 end = new Vector3(target.X, target.Y + target.Grid.Spec.HalfHeight * 0.3f, target.Z);
|
||||
float dist = start.DistanceTo(end);
|
||||
if (dist > 0.5f)
|
||||
{
|
||||
if (!vis.LastLaserVisible)
|
||||
{
|
||||
vis.LastLaserVisible = true;
|
||||
vis.LaserMesh.Visible = true;
|
||||
}
|
||||
vis.LaserMesh.GlobalPosition = (start + end) * 0.5f;
|
||||
Vector3 dir = (end - start).Normalized();
|
||||
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.99f ? Vector3.Right : Vector3.Up;
|
||||
vis.LaserMesh.LookAt(end, up);
|
||||
vis.LaserMesh.Scale = new Vector3(1f, 1f, dist);
|
||||
}
|
||||
else if (vis.LastLaserVisible)
|
||||
{
|
||||
vis.LastLaserVisible = false;
|
||||
vis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
else if (vis.LastLaserVisible)
|
||||
{
|
||||
vis.LastLaserVisible = false;
|
||||
vis.LaserMesh.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ActorVisual CreateSpectatorVisualWrapper(VehicleVisualInstance instance)
|
||||
{
|
||||
float haloY = MathF.Max(2.4f, instance.ComputeMountedMaxY() + 1.15f);
|
||||
var haloMat = new StandardMaterial3D
|
||||
{
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
EmissionEnabled = true,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
var halo = new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 2.4f, BottomRadius = 2.4f, Height = 0.1f, RadialSegments = 16 },
|
||||
MaterialOverride = haloMat,
|
||||
Position = new Vector3(0f, haloY, 0f),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
instance.Root.AddChild(halo);
|
||||
|
||||
var laserMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(1f, 0.15f, 0.15f, 0.85f),
|
||||
EmissionEnabled = true,
|
||||
Emission = new Color(1f, 0.12f, 0.1f),
|
||||
EmissionEnergyMultiplier = 2.2f,
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
Transparency = BaseMaterial3D.TransparencyEnum.Alpha
|
||||
};
|
||||
var laser = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(0.08f, 0.08f, 1.0f) },
|
||||
MaterialOverride = laserMat,
|
||||
Visible = false,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
_actorsGroup.AddChild(laser);
|
||||
|
||||
return new ActorVisual
|
||||
{
|
||||
Visual = instance,
|
||||
HaloMesh = halo,
|
||||
HaloMat = haloMat,
|
||||
LaserMesh = laser
|
||||
};
|
||||
}
|
||||
|
||||
private void SyncGroundDrops(MatchState state, float elapsedSeconds, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
for (int i = 0; i < state.GroundDrops.Count; i++)
|
||||
{
|
||||
var d = state.GroundDrops[i];
|
||||
if (d.PickedUp)
|
||||
{
|
||||
if (_dropVisuals.TryGetValue(d.Id, out var pickedEntry))
|
||||
{
|
||||
if (GodotObject.IsInstanceValid(pickedEntry.Node))
|
||||
{
|
||||
pickedEntry.Node.GetParent()?.RemoveChild(pickedEntry.Node);
|
||||
pickedEntry.Node.QueueFree();
|
||||
}
|
||||
_dropVisuals.Remove(d.Id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isNew = false;
|
||||
if (!_dropVisuals.TryGetValue(d.Id, out var entry))
|
||||
{
|
||||
Node3D node = BuildGroundDropVisual(d, out var chassisVis);
|
||||
_dropsGroup.AddChild(node);
|
||||
TerrainField.WorldToTile(d.X, d.Z, out int tx, out int tz);
|
||||
entry = new DropVisualEntry
|
||||
{
|
||||
Node = node,
|
||||
ChassisVisual = chassisVis,
|
||||
BaseY = state.Terrain.SampleHeight(d.X, d.Z),
|
||||
TileX = tx,
|
||||
TileZ = tz,
|
||||
TileVersion = state.Terrain.TileVersions[tx, tz]
|
||||
};
|
||||
_dropVisuals[d.Id] = entry;
|
||||
isNew = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ver = state.Terrain.TileVersions[entry.TileX, entry.TileZ];
|
||||
if (ver != entry.TileVersion)
|
||||
{
|
||||
entry.TileVersion = ver;
|
||||
entry.BaseY = state.Terrain.SampleHeight(d.X, d.Z);
|
||||
isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
entry.Node.Visible = true;
|
||||
}
|
||||
if (d.Module is not null)
|
||||
{
|
||||
float bob = MathF.Sin(elapsedSeconds * 2.5f + d.Id) * 0.12f;
|
||||
entry.Node.Position = new Vector3(d.X, entry.BaseY + bob, d.Z);
|
||||
entry.Node.Rotation = new Vector3(0f, elapsedSeconds * 0.9f + d.Id, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isNew)
|
||||
{
|
||||
entry.Node.Position = new Vector3(d.X, entry.BaseY, d.Z);
|
||||
}
|
||||
if (entry.ChassisVisual is { } cv)
|
||||
{
|
||||
bool useFarLod = false;
|
||||
bool castShadows = true;
|
||||
if (hasCam)
|
||||
{
|
||||
float d2 = new Vector3(d.X, entry.BaseY, d.Z).DistanceSquaredTo(camPos);
|
||||
useFarLod = cv.IsStaticLod ? d2 > 126f * 126f : d2 > 130f * 130f;
|
||||
castShadows = d2 <= 150f * 150f;
|
||||
}
|
||||
cv.SetLodState(useFarLod, castShadows);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncTracers(IReadOnlyList<TracerEvent> tracers)
|
||||
{
|
||||
while (_tracerPool.Count < tracers.Count)
|
||||
{
|
||||
var mat = new StandardMaterial3D
|
||||
{
|
||||
ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded,
|
||||
EmissionEnabled = true
|
||||
};
|
||||
var mesh = new MeshInstance3D
|
||||
{
|
||||
Mesh = new BoxMesh { Size = new Vector3(0.14f, 0.14f, 1.0f) },
|
||||
MaterialOverride = mat,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
_tracersGroup.AddChild(mesh);
|
||||
_tracerPool.Add(mesh);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tracerPool.Count; i++)
|
||||
{
|
||||
var m = _tracerPool[i];
|
||||
if (i >= tracers.Count)
|
||||
{
|
||||
m.Visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var t = tracers[i];
|
||||
var start = new Vector3(t.StartX, t.StartY, t.StartZ);
|
||||
var end = new Vector3(t.EndX, t.EndY, t.EndZ);
|
||||
float dist = start.DistanceTo(end);
|
||||
if (dist < 0.1f)
|
||||
{
|
||||
m.Visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
m.Visible = true;
|
||||
m.Position = (start + end) * 0.5f;
|
||||
Vector3 dir = (end - start).Normalized();
|
||||
Vector3 up = MathF.Abs(dir.Dot(Vector3.Up)) > 0.95f ? Vector3.Right : Vector3.Up;
|
||||
m.LookAt(end, up);
|
||||
m.Scale = new Vector3(1f, 1f, dist);
|
||||
|
||||
var col = new Color(
|
||||
((t.ColorRgba >> 24) & 0xFF) / 255f,
|
||||
((t.ColorRgba >> 16) & 0xFF) / 255f,
|
||||
((t.ColorRgba >> 8) & 0xFF) / 255f,
|
||||
1f);
|
||||
if (m.MaterialOverride is StandardMaterial3D sm)
|
||||
{
|
||||
sm.AlbedoColor = col;
|
||||
sm.Emission = col;
|
||||
sm.EmissionEnergyMultiplier = 2.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Node3D BuildGroundDropVisual(GroundDrop drop, out VehicleVisualInstance? chassisVisual)
|
||||
{
|
||||
chassisVisual = null;
|
||||
var root = new Node3D { Name = $"Drop_{drop.Id}" };
|
||||
if (drop.Module is { } mod)
|
||||
{
|
||||
var beaconMat = mod.IsImperial ? _imperialBeaconMat : _humanBeaconMat;
|
||||
root.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 0.72f, BottomRadius = 0.85f, Height = 0.14f, RadialSegments = 14 },
|
||||
MaterialOverride = beaconMat,
|
||||
Position = new Vector3(0f, 0.08f, 0f),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
});
|
||||
|
||||
// Real Brokkr gear GLB hovering cleanly above the salvage beacon disc
|
||||
Node3D gear = VehicleVisualInstance.CreateStandaloneGearVisual(_assetCache, mod);
|
||||
gear.Scale *= 1.45f;
|
||||
gear.Position += new Vector3(0f, 0.35f, 0f);
|
||||
root.AddChild(gear);
|
||||
|
||||
if (mod.IsImperial)
|
||||
{
|
||||
root.AddChild(new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 0.06f, BottomRadius = 0.22f, Height = 5.5f, RadialSegments = 8 },
|
||||
MaterialOverride = _imperialBeaconMat,
|
||||
Position = new Vector3(0f, 2.9f, 0f),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (drop.Chassis is { } ch)
|
||||
{
|
||||
const float dropScale = 0.85f;
|
||||
var hull = VehicleVisualInstance.Create(_assetCache, ch.Id, VehicleVisualRole.SalvageDrop, dropScale);
|
||||
chassisVisual = hull;
|
||||
// ModelRoot sits at -HalfHeight*dropScale inside hull.Root, so lifting hull.Root by +HalfHeight*dropScale grounds minY=0 on terrain
|
||||
hull.Root.Position = new Vector3(0f, ch.HalfHeight * dropScale, 0f);
|
||||
root.AddChild(hull.Root);
|
||||
|
||||
var ring = new MeshInstance3D
|
||||
{
|
||||
Mesh = new CylinderMesh { TopRadius = 2.6f, BottomRadius = 2.8f, Height = 0.14f, RadialSegments = 18 },
|
||||
MaterialOverride = _cyanBeaconMat,
|
||||
Position = new Vector3(0f, 0.12f, 0f),
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
root.AddChild(ring);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
private static void ClearChildren(Node parent)
|
||||
{
|
||||
for (int i = parent.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
parent.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,287 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Manages physically detached armor plates and sheared hardpoint gear as tumbling,
|
||||
/// terrain-bouncing debris pieces that settle and fade out cleanly after 8 seconds.
|
||||
/// </summary>
|
||||
public partial class DebrisSystem : Node3D
|
||||
{
|
||||
private const float Gravity = -20f;
|
||||
private const float DefaultLifetime = 8.0f;
|
||||
private const float FadeDuration = 2.0f;
|
||||
private const int MaxActiveDebris = 256;
|
||||
|
||||
private sealed class DebrisPiece
|
||||
{
|
||||
public required Node3D Node;
|
||||
public required Vector3 Velocity;
|
||||
public required Vector3 AngularVelocity;
|
||||
public required List<StandardMaterial3D> FadeMaterials;
|
||||
public required float[] BaseAlphas;
|
||||
public float Age;
|
||||
public float Lifetime;
|
||||
public bool Settled;
|
||||
}
|
||||
|
||||
private readonly List<DebrisPiece> _pieces = new();
|
||||
private uint _rngState = 0x9E3779B9u;
|
||||
|
||||
public int ActiveCount => _pieces.Count;
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
for (int i = 0; i < _pieces.Count; i++)
|
||||
{
|
||||
if (GodotObject.IsInstanceValid(_pieces[i].Node))
|
||||
{
|
||||
_pieces[i].Node.QueueFree();
|
||||
}
|
||||
}
|
||||
_pieces.Clear();
|
||||
|
||||
for (int i = GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
Node ch = GetChild(i);
|
||||
RemoveChild(ch);
|
||||
ch.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reparents <paramref name="part"/> from its vehicle hierarchy at its exact world transform
|
||||
/// into <see cref="DebrisSystem"/> and launches it with an outward blast impulse and tumble.
|
||||
/// </summary>
|
||||
public void SpawnDetachedPart(
|
||||
Node3D part,
|
||||
Vector3 blastOriginWorld,
|
||||
Vector3 inheritedVelocity,
|
||||
float impulseScale = 1.0f,
|
||||
bool applyScorch = true)
|
||||
{
|
||||
if (!GodotObject.IsInstanceValid(part))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Evict oldest settled or oldest piece if we hit the cap so debris never leaks indefinitely
|
||||
while (_pieces.Count >= MaxActiveDebris)
|
||||
{
|
||||
RemoveAt(0);
|
||||
}
|
||||
|
||||
Transform3D worldXform = part.IsInsideTree() ? part.GlobalTransform : part.Transform;
|
||||
Node? oldParent = part.GetParent();
|
||||
oldParent?.RemoveChild(part);
|
||||
AddChild(part);
|
||||
|
||||
if (part.IsInsideTree() && IsInsideTree())
|
||||
{
|
||||
part.GlobalTransform = worldXform;
|
||||
}
|
||||
else
|
||||
{
|
||||
part.Transform = worldXform;
|
||||
}
|
||||
|
||||
Vector3 outward = worldXform.Origin - blastOriginWorld;
|
||||
outward.Y = 0f;
|
||||
if (outward.LengthSquared() < 1e-4f)
|
||||
{
|
||||
float ang = NextFloat() * MathF.Tau;
|
||||
outward = new Vector3(MathF.Cos(ang), 0f, MathF.Sin(ang));
|
||||
}
|
||||
else
|
||||
{
|
||||
outward = outward.Normalized();
|
||||
}
|
||||
|
||||
float horizSpeed = (4.2f + NextFloat() * 4.8f) * impulseScale;
|
||||
float upSpeed = (4.0f + NextFloat() * 4.5f) * impulseScale;
|
||||
Vector3 vel = inheritedVelocity * 0.45f + outward * horizSpeed + Vector3.Up * upSpeed;
|
||||
|
||||
Vector3 angVel = new(
|
||||
(NextFloat() * 2f - 1f) * 7.5f,
|
||||
(NextFloat() * 2f - 1f) * 7.5f,
|
||||
(NextFloat() * 2f - 1f) * 7.5f);
|
||||
|
||||
var fadeMats = new List<StandardMaterial3D>();
|
||||
PrepareInstanceMaterials(part, fadeMats, applyScorch);
|
||||
var baseAlphas = new float[fadeMats.Count];
|
||||
for (int i = 0; i < fadeMats.Count; i++)
|
||||
{
|
||||
baseAlphas[i] = fadeMats[i].AlbedoColor.A;
|
||||
}
|
||||
|
||||
_pieces.Add(new DebrisPiece
|
||||
{
|
||||
Node = part,
|
||||
Velocity = vel,
|
||||
AngularVelocity = angVel,
|
||||
FadeMaterials = fadeMats,
|
||||
BaseAlphas = baseAlphas,
|
||||
Age = 0f,
|
||||
Lifetime = DefaultLifetime,
|
||||
Settled = false
|
||||
});
|
||||
}
|
||||
|
||||
public void Step(float dt, TerrainField terrain)
|
||||
{
|
||||
if (dt <= 0f || !float.IsFinite(dt))
|
||||
{
|
||||
return;
|
||||
}
|
||||
float stepDt = Math.Clamp(dt, 0f, 0.05f);
|
||||
|
||||
for (int i = _pieces.Count - 1; i >= 0; i--)
|
||||
{
|
||||
DebrisPiece p = _pieces[i];
|
||||
if (!GodotObject.IsInstanceValid(p.Node))
|
||||
{
|
||||
_pieces.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
p.Age += stepDt;
|
||||
if (p.Age >= p.Lifetime)
|
||||
{
|
||||
RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!p.Settled)
|
||||
{
|
||||
p.Velocity += new Vector3(0f, Gravity * stepDt, 0f);
|
||||
Vector3 pos = p.Node.Position + p.Velocity * stepDt;
|
||||
|
||||
Basis basis = p.Node.Basis;
|
||||
float spinLen = p.AngularVelocity.Length();
|
||||
if (spinLen > 1e-4f)
|
||||
{
|
||||
basis = new Basis(p.AngularVelocity / spinLen, spinLen * stepDt) * basis;
|
||||
basis = basis.Orthonormalized();
|
||||
}
|
||||
|
||||
float floorY = terrain.SampleHeight(pos.X, pos.Z) + 0.10f;
|
||||
if (pos.Y <= floorY)
|
||||
{
|
||||
pos.Y = floorY;
|
||||
if (p.Velocity.Y < -1.4f)
|
||||
{
|
||||
p.Velocity = new Vector3(
|
||||
p.Velocity.X * 0.62f,
|
||||
-p.Velocity.Y * 0.32f,
|
||||
p.Velocity.Z * 0.62f);
|
||||
p.AngularVelocity *= 0.55f;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Velocity = Vector3.Zero;
|
||||
p.AngularVelocity = Vector3.Zero;
|
||||
p.Settled = true;
|
||||
}
|
||||
}
|
||||
|
||||
p.Node.Position = pos;
|
||||
p.Node.Basis = basis;
|
||||
}
|
||||
|
||||
// Smooth alpha fade during final 2 seconds
|
||||
float remaining = p.Lifetime - p.Age;
|
||||
if (remaining < FadeDuration)
|
||||
{
|
||||
float alphaFrac = Math.Clamp(remaining / FadeDuration, 0f, 1f);
|
||||
for (int m = 0; m < p.FadeMaterials.Count; m++)
|
||||
{
|
||||
StandardMaterial3D sm = p.FadeMaterials[m];
|
||||
if (sm.Transparency == BaseMaterial3D.TransparencyEnum.Disabled)
|
||||
{
|
||||
sm.Transparency = BaseMaterial3D.TransparencyEnum.Alpha;
|
||||
}
|
||||
Color col = sm.AlbedoColor;
|
||||
col.A = p.BaseAlphas[m] * alphaFrac;
|
||||
sm.AlbedoColor = col;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveAt(int index)
|
||||
{
|
||||
DebrisPiece p = _pieces[index];
|
||||
_pieces.RemoveAt(index);
|
||||
if (GodotObject.IsInstanceValid(p.Node))
|
||||
{
|
||||
if (p.Node.GetParent() == this)
|
||||
{
|
||||
RemoveChild(p.Node);
|
||||
}
|
||||
p.Node.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrepareInstanceMaterials(Node cur, List<StandardMaterial3D> outMats, bool applyScorch)
|
||||
{
|
||||
if (cur is MeshInstance3D mi && mi.Mesh is not null)
|
||||
{
|
||||
if (mi.MaterialOverride is StandardMaterial3D ov)
|
||||
{
|
||||
var copy = (StandardMaterial3D)ov.Duplicate();
|
||||
if (applyScorch)
|
||||
{
|
||||
ApplyScorchTint(copy);
|
||||
}
|
||||
mi.MaterialOverride = copy;
|
||||
outMats.Add(copy);
|
||||
}
|
||||
else
|
||||
{
|
||||
int surfCount = mi.Mesh.GetSurfaceCount();
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
Material? src = mi.GetActiveMaterial(s);
|
||||
StandardMaterial3D copy = src is StandardMaterial3D sm
|
||||
? (StandardMaterial3D)sm.Duplicate()
|
||||
: new StandardMaterial3D { AlbedoColor = new Color(0.28f, 0.25f, 0.23f), Roughness = 0.78f, Metallic = 0.45f };
|
||||
if (applyScorch)
|
||||
{
|
||||
ApplyScorchTint(copy);
|
||||
}
|
||||
mi.SetSurfaceOverrideMaterial(s, copy);
|
||||
outMats.Add(copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int count = cur.GetChildCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
PrepareInstanceMaterials(cur.GetChild(i), outMats, applyScorch);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyScorchTint(StandardMaterial3D mat)
|
||||
{
|
||||
Color c = mat.AlbedoColor;
|
||||
mat.AlbedoColor = new Color(c.R * 0.42f + 0.04f, c.G * 0.36f + 0.03f, c.B * 0.34f + 0.02f, c.A);
|
||||
mat.Roughness = MathF.Max(mat.Roughness, 0.78f);
|
||||
mat.EmissionEnabled = true;
|
||||
mat.Emission = new Color(0.95f, 0.32f, 0.06f);
|
||||
mat.EmissionEnergyMultiplier = 0.35f;
|
||||
}
|
||||
|
||||
private float NextFloat()
|
||||
{
|
||||
uint x = _rngState;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
_rngState = x;
|
||||
return (x & 0x00FFFFFFu) / 16777216f;
|
||||
}
|
||||
}
|
||||
1040
client/Hud.cs
1040
client/Hud.cs
File diff suppressed because it is too large
Load diff
|
|
@ -1,783 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Godot Control owning <c>inventory_grid.gdshader</c>:
|
||||
/// packs a <see cref="ChassisGrid"/> into a 3W x H RGBA8 nearest-filter data texture
|
||||
/// and a W x H RGBA8 bilinear temperature texture, tracks hover and hit-pulse decay,
|
||||
/// and provides accurate mouse-to-cell hit-testing for HUD and Garage schematics.
|
||||
/// </summary>
|
||||
public partial class InventoryGridControl : Control
|
||||
{
|
||||
private static readonly Color ColBgIntact = Color.FromHtml("#263022");
|
||||
private static readonly Color ColBgArmorFull = Color.FromHtml("#4b6136");
|
||||
private static readonly Color ColBgDamaged = Color.FromHtml("#8a3c22");
|
||||
private static readonly Color ColBgStripped = Color.FromHtml("#2b1210");
|
||||
|
||||
private static readonly Color ColBorderHull = Color.FromHtml("#7a856e");
|
||||
private static readonly Color ColBorderRadiatorCell = Color.FromHtml("#44d9e8");
|
||||
private static readonly Color ColBorderWeapon = Color.FromHtml("#e08a4a");
|
||||
private static readonly Color ColBorderEngine = Color.FromHtml("#e6b838");
|
||||
private static readonly Color ColBorderRadiator = Color.FromHtml("#44d9e8");
|
||||
private static readonly Color ColBorderArmor = Color.FromHtml("#9bb06a");
|
||||
private static readonly Color ColBorderUtility = Color.FromHtml("#4ba8a5");
|
||||
private static readonly Color ColGold = Color.FromHtml("#e6b838");
|
||||
private static readonly Color ColTextLight = Color.FromHtml("#e4dfd2");
|
||||
|
||||
// 8-neighbor offsets in Aetheria mask order: N, E, S, W, NE, SE, SW, NW (screen Y-down)
|
||||
private static readonly (int Dx, int Dy)[] Offsets8 =
|
||||
{
|
||||
(0, -1), (1, 0), (0, 1), (-1, 0),
|
||||
(1, -1), (1, 1), (-1, 1), (-1, -1)
|
||||
};
|
||||
|
||||
private static Shader? _sharedShader;
|
||||
|
||||
private readonly TextureRect _gridSurface;
|
||||
private readonly LabelsOverlay _labelsOverlay;
|
||||
private readonly ShaderMaterial _material;
|
||||
|
||||
private Image? _dataImage;
|
||||
private ImageTexture? _dataTex;
|
||||
private Image? _tempImage;
|
||||
private ImageTexture? _tempTex;
|
||||
|
||||
private int _gridWidth;
|
||||
private int _gridHeight;
|
||||
private ChassisGrid? _grid;
|
||||
private ChassisSpec? _spec;
|
||||
private int _selectedCargoIndex = -1;
|
||||
private int _lastHitSequence = -1;
|
||||
|
||||
private HardpointSpec?[,] _hardpointLookup = new HardpointSpec?[0, 0];
|
||||
private float[,] _prevArmor = new float[0, 0];
|
||||
private float[,] _prevTemp = new float[0, 0];
|
||||
private float[,] _hitPulse = new float[0, 0];
|
||||
|
||||
private int _lastSelectedCargoIndex = int.MinValue;
|
||||
private int _lastMountedSig = int.MinValue;
|
||||
private Vector2I? _hoveredCell;
|
||||
private bool _thermalEnabled;
|
||||
private float _thermalBlend;
|
||||
private bool _dataDirty;
|
||||
private bool _tempDirty;
|
||||
|
||||
public InventoryGridControl()
|
||||
{
|
||||
MouseFilter = MouseFilterEnum.Stop;
|
||||
|
||||
_sharedShader ??= GD.Load<Shader>("res://inventory_grid.gdshader");
|
||||
_material = new ShaderMaterial { Shader = _sharedShader };
|
||||
|
||||
_gridSurface = new TextureRect
|
||||
{
|
||||
Name = "GridShaderSurface",
|
||||
MouseFilter = MouseFilterEnum.Ignore,
|
||||
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
|
||||
StretchMode = TextureRect.StretchModeEnum.Scale,
|
||||
Material = _material
|
||||
};
|
||||
_gridSurface.SetAnchorsPreset(LayoutPreset.FullRect);
|
||||
AddChild(_gridSurface);
|
||||
|
||||
_labelsOverlay = new LabelsOverlay(this)
|
||||
{
|
||||
Name = "GridLabelsOverlay",
|
||||
MouseFilter = MouseFilterEnum.Ignore
|
||||
};
|
||||
_labelsOverlay.SetAnchorsPreset(LayoutPreset.FullRect);
|
||||
AddChild(_labelsOverlay);
|
||||
|
||||
MouseExited += OnMouseExited;
|
||||
}
|
||||
|
||||
public ShaderMaterial ShaderMaterial => _material;
|
||||
public Control ShaderSurface => _gridSurface;
|
||||
public ChassisGrid? Grid => _grid;
|
||||
public Vector2I? HoveredCell => _hoveredCell;
|
||||
public HardpointSpec? HoveredHardpoint =>
|
||||
_hoveredCell is { } c && _grid is not null && c.X >= 0 && c.Y >= 0 && c.X < _gridWidth && c.Y < _gridHeight
|
||||
? _hardpointLookup[c.X, c.Y]
|
||||
: null;
|
||||
|
||||
public bool ThermalEnabled
|
||||
{
|
||||
get => _thermalEnabled;
|
||||
set
|
||||
{
|
||||
if (_thermalEnabled == value) return;
|
||||
_thermalEnabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float ThermalBlend => _thermalBlend;
|
||||
|
||||
public void SetThermalInstant(bool enabled)
|
||||
{
|
||||
_thermalEnabled = enabled;
|
||||
_thermalBlend = enabled ? 1f : 0f;
|
||||
_material.SetShaderParameter("thermal_mode", _thermalBlend);
|
||||
_labelsOverlay.QueueRedraw();
|
||||
}
|
||||
|
||||
public event Action<int, int>? CellClicked;
|
||||
public event Action<string>? HardpointClicked;
|
||||
public event Action<Vector2I?, HardpointSpec?>? HoverChanged;
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
if (what == NotificationResized)
|
||||
{
|
||||
SyncRectUniform();
|
||||
_labelsOverlay.QueueRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
float dt = (float)delta;
|
||||
bool needUniform = false;
|
||||
|
||||
float targetThermal = _thermalEnabled ? 1f : 0f;
|
||||
if (MathF.Abs(_thermalBlend - targetThermal) > 0.001f)
|
||||
{
|
||||
float t = dt >= 0.25f ? 1f : 1f - MathF.Exp(-dt * 14f);
|
||||
_thermalBlend = Mathf.Lerp(_thermalBlend, targetThermal, t);
|
||||
if (MathF.Abs(_thermalBlend - targetThermal) < 0.005f)
|
||||
{
|
||||
_thermalBlend = targetThermal;
|
||||
}
|
||||
needUniform = true;
|
||||
_labelsOverlay.QueueRedraw();
|
||||
}
|
||||
|
||||
if (needUniform)
|
||||
{
|
||||
_material.SetShaderParameter("thermal_mode", _thermalBlend);
|
||||
}
|
||||
|
||||
bool anyPulse = false;
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (_hitPulse[x, y] > 0f)
|
||||
{
|
||||
_hitPulse[x, y] = MathF.Max(0f, _hitPulse[x, y] - dt * 2.8f);
|
||||
anyPulse = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (anyPulse && _grid is not null)
|
||||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mm)
|
||||
{
|
||||
UpdateHover(mm.Position);
|
||||
return;
|
||||
}
|
||||
|
||||
if (@event is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||
{
|
||||
UpdateHover(mb.Position);
|
||||
if (TryGetCellAt(mb.Position, out var cell) && _grid is not null && _grid.Spec.IsActive(cell.X, cell.Y))
|
||||
{
|
||||
CellClicked?.Invoke(cell.X, cell.Y);
|
||||
var hp = _hardpointLookup[cell.X, cell.Y];
|
||||
if (hp is not null)
|
||||
{
|
||||
HardpointClicked?.Invoke(hp.Id);
|
||||
}
|
||||
AcceptEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGrid(ChassisGrid grid, int selectedCargoIndex = -1)
|
||||
{
|
||||
if (grid is null) throw new ArgumentNullException(nameof(grid));
|
||||
|
||||
bool gridIdentityChanged = !ReferenceEquals(_grid, grid)
|
||||
|| !ReferenceEquals(_spec, grid.Spec)
|
||||
|| _gridWidth != grid.Spec.Width
|
||||
|| _gridHeight != grid.Spec.Height;
|
||||
|
||||
_grid = grid;
|
||||
_spec = grid.Spec;
|
||||
_selectedCargoIndex = selectedCargoIndex;
|
||||
|
||||
if (gridIdentityChanged)
|
||||
{
|
||||
EnsureBackingBuffers(grid);
|
||||
_lastSelectedCargoIndex = selectedCargoIndex;
|
||||
_lastMountedSig = ComputeMountedSignature(grid);
|
||||
SnapshotTemperatures(grid);
|
||||
PackDataTexture(grid);
|
||||
PackTempTexture(grid);
|
||||
FlushTextures();
|
||||
SyncRectUniform();
|
||||
_labelsOverlay.QueueRedraw();
|
||||
return;
|
||||
}
|
||||
|
||||
bool dataChanged = DetectHits(grid);
|
||||
int mountedSig = ComputeMountedSignature(grid);
|
||||
if (_lastSelectedCargoIndex != selectedCargoIndex || _lastMountedSig != mountedSig)
|
||||
{
|
||||
_lastSelectedCargoIndex = selectedCargoIndex;
|
||||
_lastMountedSig = mountedSig;
|
||||
dataChanged = true;
|
||||
}
|
||||
|
||||
bool tempChanged = HasTemperatureChanged(grid);
|
||||
|
||||
if (dataChanged)
|
||||
{
|
||||
PackDataTexture(grid);
|
||||
_labelsOverlay.QueueRedraw();
|
||||
}
|
||||
if (tempChanged)
|
||||
{
|
||||
SnapshotTemperatures(grid);
|
||||
PackTempTexture(grid);
|
||||
}
|
||||
if (dataChanged || tempChanged)
|
||||
{
|
||||
FlushTextures();
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerHitPulse(int x, int y, float intensity = 1f)
|
||||
{
|
||||
if (_grid is null || x < 0 || y < 0 || x >= _gridWidth || y >= _gridHeight) return;
|
||||
if (!_grid.Spec.IsActive(x, y)) return;
|
||||
_hitPulse[x, y] = Math.Clamp(intensity, 0f, 1f);
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
}
|
||||
|
||||
public bool TryGetCellAt(Vector2 localPos, out Vector2I cell)
|
||||
{
|
||||
cell = default;
|
||||
if (_grid is null || _gridWidth <= 0 || _gridHeight <= 0) return false;
|
||||
ComputeCellLayout(out float cellSize, out Vector2 origin);
|
||||
if (cellSize <= 0.5f) return false;
|
||||
|
||||
Vector2 rel = (localPos - origin) / cellSize;
|
||||
int cx = Mathf.FloorToInt(rel.X);
|
||||
int cy = Mathf.FloorToInt(rel.Y);
|
||||
if (cx < 0 || cy < 0 || cx >= _gridWidth || cy >= _gridHeight) return false;
|
||||
cell = new Vector2I(cx, cy);
|
||||
return true;
|
||||
}
|
||||
|
||||
public HardpointSpec? GetHardpointAt(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x >= _gridWidth || y >= _gridHeight) return null;
|
||||
return _hardpointLookup[x, y];
|
||||
}
|
||||
|
||||
public void ComputeCellLayout(out float cellSize, out Vector2 origin)
|
||||
{
|
||||
int w = Math.Max(1, _gridWidth);
|
||||
int h = Math.Max(1, _gridHeight);
|
||||
Vector2 size = Size;
|
||||
if (size.X < 2f || size.Y < 2f)
|
||||
{
|
||||
size = CustomMinimumSize;
|
||||
}
|
||||
cellSize = MathF.Min(size.X / w, size.Y / h);
|
||||
origin = (size - new Vector2(w * cellSize, h * cellSize)) * 0.5f;
|
||||
}
|
||||
|
||||
private void OnMouseExited()
|
||||
{
|
||||
if (_hoveredCell.HasValue)
|
||||
{
|
||||
_hoveredCell = null;
|
||||
HoverChanged?.Invoke(null, null);
|
||||
if (_grid is not null)
|
||||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHover(Vector2 localPos)
|
||||
{
|
||||
Vector2I? next = null;
|
||||
if (TryGetCellAt(localPos, out var c) && _grid is not null && _grid.Spec.IsActive(c.X, c.Y))
|
||||
{
|
||||
next = c;
|
||||
}
|
||||
|
||||
if (_hoveredCell == next) return;
|
||||
_hoveredCell = next;
|
||||
HoverChanged?.Invoke(next, HoveredHardpoint);
|
||||
if (_grid is not null)
|
||||
{
|
||||
PackDataTexture(_grid);
|
||||
FlushTextures();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureBackingBuffers(ChassisGrid grid)
|
||||
{
|
||||
int w = grid.Spec.Width;
|
||||
int h = grid.Spec.Height;
|
||||
bool dimsChanged = w != _gridWidth || h != _gridHeight || _dataTex is null || _tempTex is null;
|
||||
|
||||
_gridWidth = w;
|
||||
_gridHeight = h;
|
||||
_hardpointLookup = new HardpointSpec?[w, h];
|
||||
for (int i = 0; i < grid.Spec.Hardpoints.Length; i++)
|
||||
{
|
||||
var hp = grid.Spec.Hardpoints[i];
|
||||
for (int dy = 0; dy < hp.Height; dy++)
|
||||
{
|
||||
for (int dx = 0; dx < hp.Width; dx++)
|
||||
{
|
||||
int hx = hp.X + dx;
|
||||
int hy = hp.Y + dy;
|
||||
if (hx >= 0 && hy >= 0 && hx < w && hy < h && grid.Spec.IsActive(hx, hy))
|
||||
{
|
||||
_hardpointLookup[hx, hy] = hp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_prevArmor = new float[w, h];
|
||||
_prevTemp = new float[w, h];
|
||||
_hitPulse = new float[w, h];
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
_prevArmor[x, y] = grid.Armor[x, y];
|
||||
_prevTemp[x, y] = grid.Temperature[x, y];
|
||||
}
|
||||
}
|
||||
_lastHitSequence = grid.HitSequence;
|
||||
bool hadHover = _hoveredCell.HasValue;
|
||||
_hoveredCell = null;
|
||||
|
||||
if (dimsChanged)
|
||||
{
|
||||
_dataImage = Image.CreateEmpty(Math.Max(1, w * 3), Math.Max(1, h), false, Image.Format.Rgba8);
|
||||
_dataTex = ImageTexture.CreateFromImage(_dataImage);
|
||||
_tempImage = Image.CreateEmpty(Math.Max(1, w), Math.Max(1, h), false, Image.Format.Rgba8);
|
||||
_tempTex = ImageTexture.CreateFromImage(_tempImage);
|
||||
|
||||
_gridSurface.Texture = _dataTex;
|
||||
_material.SetShaderParameter("data_tex", _dataTex);
|
||||
_material.SetShaderParameter("temp_tex", _tempTex);
|
||||
}
|
||||
|
||||
_material.SetShaderParameter("grid_size", new Vector2(w, h));
|
||||
_material.SetShaderParameter("thermal_mode", _thermalBlend);
|
||||
|
||||
if (hadHover)
|
||||
{
|
||||
HoverChanged?.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private bool DetectHits(ChassisGrid grid)
|
||||
{
|
||||
bool changed = false;
|
||||
if (grid.HitSequence != _lastHitSequence)
|
||||
{
|
||||
_lastHitSequence = grid.HitSequence;
|
||||
if (grid.LastHitX >= 0 && grid.LastHitY >= 0 && grid.LastHitX < _gridWidth && grid.LastHitY < _gridHeight)
|
||||
{
|
||||
_hitPulse[grid.LastHitX, grid.LastHitY] = 1f;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
float arm = grid.Armor[x, y];
|
||||
if (arm < _prevArmor[x, y] - 0.05f)
|
||||
{
|
||||
_hitPulse[x, y] = 1f;
|
||||
_prevArmor[x, y] = arm;
|
||||
changed = true;
|
||||
}
|
||||
else if (MathF.Abs(arm - _prevArmor[x, y]) > 0.01f)
|
||||
{
|
||||
_prevArmor[x, y] = arm;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static int ComputeMountedSignature(ChassisGrid grid)
|
||||
{
|
||||
var hc = new HashCode();
|
||||
hc.Add(grid.Mounted.Count);
|
||||
for (int i = 0; i < grid.Mounted.Count; i++)
|
||||
{
|
||||
var m = grid.Mounted[i];
|
||||
hc.Add(m.HardpointId);
|
||||
hc.Add(m.Spec.Id);
|
||||
hc.Add(m.CurrentPerformance > 0.05f);
|
||||
}
|
||||
return hc.ToHashCode();
|
||||
}
|
||||
|
||||
private bool HasTemperatureChanged(ChassisGrid grid)
|
||||
{
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (MathF.Abs(grid.Temperature[x, y] - _prevTemp[x, y]) >= 0.25f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SnapshotTemperatures(ChassisGrid grid)
|
||||
{
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
_prevTemp[x, y] = grid.Temperature[x, y];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PackDataTexture(ChassisGrid grid)
|
||||
{
|
||||
if (_dataImage is null) return;
|
||||
var spec = grid.Spec;
|
||||
|
||||
ModuleSpec? selectedCargo = _selectedCargoIndex >= 0 && _selectedCargoIndex < grid.Cargo.Count
|
||||
? grid.Cargo[_selectedCargoIndex]
|
||||
: null;
|
||||
|
||||
HardpointSpec? hoveredHp = HoveredHardpoint;
|
||||
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (!spec.IsActive(x, y))
|
||||
{
|
||||
var zero = new Color(0f, 0f, 0f, 0f);
|
||||
_dataImage.SetPixel(x * 3 + 0, y, zero);
|
||||
_dataImage.SetPixel(x * 3 + 1, y, zero);
|
||||
_dataImage.SetPixel(x * 3 + 2, y, zero);
|
||||
continue;
|
||||
}
|
||||
|
||||
var hp = _hardpointLookup[x, y];
|
||||
var mounted = hp is not null ? grid.GetMountedOn(hp.Id) : null;
|
||||
float maxArm = MathF.Max(1f, grid.MaxArmor[x, y]);
|
||||
float arm = grid.Armor[x, y];
|
||||
float armRatio = Math.Clamp(arm / maxArm, 0f, 1f);
|
||||
bool stripped = arm <= 0.01f;
|
||||
bool isBorder = grid.BorderCells[x, y];
|
||||
bool isCompatible = hp is not null && selectedCargo is not null && ChassisGrid.CanFit(hp, selectedCargo);
|
||||
bool isHovered = (_hoveredCell is { } hc && hc.X == x && hc.Y == y)
|
||||
|| (hoveredHp is not null && ReferenceEquals(hp, hoveredHp));
|
||||
|
||||
// 3x+0: Cell / item fill & armor tint
|
||||
Color fill;
|
||||
if (stripped)
|
||||
{
|
||||
fill = ColBgStripped;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color armorCol = armRatio > 0.5f
|
||||
? ColBgIntact.Lerp(ColBgArmorFull, (armRatio - 0.5f) * 2f)
|
||||
: ColBgDamaged.Lerp(ColBgIntact, armRatio * 2f);
|
||||
|
||||
if (mounted is not null)
|
||||
{
|
||||
Color modTint = mounted.Spec.IsImperial ? ColGold : KindColor(hp!.Kind);
|
||||
fill = armorCol.Lerp(modTint, 0.28f);
|
||||
}
|
||||
else
|
||||
{
|
||||
fill = armorCol;
|
||||
}
|
||||
}
|
||||
fill.A = stripped ? 0.92f : 0.86f;
|
||||
|
||||
// 3x+1: Border / L-bracket / pipe accent color
|
||||
Color accent;
|
||||
if (hp is not null)
|
||||
{
|
||||
if (isCompatible)
|
||||
{
|
||||
accent = ColGold;
|
||||
}
|
||||
else if (mounted is { Spec.IsImperial: true })
|
||||
{
|
||||
accent = ColGold;
|
||||
}
|
||||
else
|
||||
{
|
||||
accent = KindColor(hp.Kind);
|
||||
if (mounted is null)
|
||||
{
|
||||
accent = accent.Lerp(ColBorderHull, 0.45f);
|
||||
}
|
||||
}
|
||||
accent.A = 0.96f;
|
||||
}
|
||||
else if (isBorder)
|
||||
{
|
||||
accent = ColBorderHull.Lerp(ColBorderRadiatorCell, 0.28f);
|
||||
accent.A = 0.72f;
|
||||
}
|
||||
else
|
||||
{
|
||||
accent = ColBorderHull;
|
||||
accent.A = 0.62f;
|
||||
}
|
||||
|
||||
// 3x+2.R: 8-bit neighbor mismatch mask (Aetheria rule)
|
||||
byte mask = 0;
|
||||
for (int i = 0; i < Offsets8.Length; i++)
|
||||
{
|
||||
int nx = x + Offsets8[i].Dx;
|
||||
int ny = y + Offsets8[i].Dy;
|
||||
bool match;
|
||||
if (!spec.IsActive(nx, ny))
|
||||
{
|
||||
match = false;
|
||||
}
|
||||
else if (hp is not null)
|
||||
{
|
||||
match = ReferenceEquals(_hardpointLookup[nx, ny], hp);
|
||||
}
|
||||
else
|
||||
{
|
||||
match = _hardpointLookup[nx, ny] is null;
|
||||
}
|
||||
|
||||
if (!match)
|
||||
{
|
||||
mask |= (byte)(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
// 3x+2.G: flags byte
|
||||
int flags = 1; // bit 0: present
|
||||
if (mounted is not null) flags |= 2; // bit 1: mounted module / item
|
||||
if (isHovered) flags |= 4; // bit 2: hovered
|
||||
if (stripped) flags |= 8; // bit 3: stripped / Armor == 0
|
||||
if (isCompatible) flags |= 16; // bit 4: compatible cargo drop target
|
||||
if (isBorder) flags |= 32; // bit 5: border radiator cell
|
||||
|
||||
// 3x+2.B: 4-bit N/E/S/W thermal conductivity pipe mask
|
||||
byte cond = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int nx = x + Offsets8[i].Dx;
|
||||
int ny = y + Offsets8[i].Dy;
|
||||
if (spec.IsActive(nx, ny))
|
||||
{
|
||||
cond |= (byte)(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
float pulse = Math.Clamp(_hitPulse[x, y], 0f, 1f);
|
||||
var meta = new Color(mask / 255f, flags / 255f, cond / 255f, pulse);
|
||||
|
||||
_dataImage.SetPixel(x * 3 + 0, y, fill);
|
||||
_dataImage.SetPixel(x * 3 + 1, y, accent);
|
||||
_dataImage.SetPixel(x * 3 + 2, y, meta);
|
||||
}
|
||||
}
|
||||
|
||||
_dataDirty = true;
|
||||
}
|
||||
|
||||
private void PackTempTexture(ChassisGrid grid)
|
||||
{
|
||||
if (_tempImage is null) return;
|
||||
var spec = grid.Spec;
|
||||
|
||||
// First pass: active cells
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (!spec.IsActive(x, y)) continue;
|
||||
|
||||
float t = grid.Temperature[x, y];
|
||||
float normTemp = Math.Clamp((t - ChassisGrid.AmbientTemp) / 180f, 0f, 1f);
|
||||
|
||||
float stress = normTemp * 0.25f;
|
||||
var hp = _hardpointLookup[x, y];
|
||||
var mounted = hp is not null ? grid.GetMountedOn(hp.Id) : null;
|
||||
if (mounted is not null)
|
||||
{
|
||||
float highPlateau = mounted.Spec.OptimalTemp + mounted.Spec.PlateauWidth * 0.5f;
|
||||
if (t > highPlateau)
|
||||
{
|
||||
float overSpan = MathF.Max(1f, mounted.Spec.MaxTemp - highPlateau);
|
||||
stress = 0.5f + 0.5f * Math.Clamp((t - highPlateau) / overSpan, 0f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
stress = 0.5f * Math.Clamp(mounted.CurrentPerformance, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
_tempImage.SetPixel(x, y, new Color(normTemp, stress, 1f, 1f));
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass: extrapolate boundary temperature into inactive neighbor cells
|
||||
// so bilinear filter_linear sampling stays smooth without cold zero bleed at hull edges.
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (spec.IsActive(x, y)) continue;
|
||||
|
||||
float sumR = 0f;
|
||||
float sumG = 0f;
|
||||
int count = 0;
|
||||
for (int i = 0; i < Offsets8.Length; i++)
|
||||
{
|
||||
int nx = x + Offsets8[i].Dx;
|
||||
int ny = y + Offsets8[i].Dy;
|
||||
if (spec.IsActive(nx, ny))
|
||||
{
|
||||
var c = _tempImage.GetPixel(nx, ny);
|
||||
sumR += c.R;
|
||||
sumG += c.G;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
_tempImage.SetPixel(x, y, new Color(sumR / count, sumG / count, 0f, 1f));
|
||||
}
|
||||
else
|
||||
{
|
||||
_tempImage.SetPixel(x, y, new Color(0f, 0f, 0f, 1f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_tempDirty = true;
|
||||
}
|
||||
|
||||
private void FlushTextures()
|
||||
{
|
||||
if (_dataDirty && _dataTex is not null && _dataImage is not null)
|
||||
{
|
||||
_dataTex.Update(_dataImage);
|
||||
_dataDirty = false;
|
||||
}
|
||||
if (_tempDirty && _tempTex is not null && _tempImage is not null)
|
||||
{
|
||||
_tempTex.Update(_tempImage);
|
||||
_tempDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncRectUniform()
|
||||
{
|
||||
Vector2 size = Size;
|
||||
if (size.X < 2f || size.Y < 2f)
|
||||
{
|
||||
size = CustomMinimumSize;
|
||||
}
|
||||
_material.SetShaderParameter("rect_size", size);
|
||||
}
|
||||
|
||||
private static Color KindColor(HardpointKind kind) => kind switch
|
||||
{
|
||||
HardpointKind.Weapon => ColBorderWeapon,
|
||||
HardpointKind.Engine => ColBorderEngine,
|
||||
HardpointKind.Radiator => ColBorderRadiator,
|
||||
HardpointKind.Armor => ColBorderArmor,
|
||||
HardpointKind.Utility => ColBorderUtility,
|
||||
_ => ColTextLight
|
||||
};
|
||||
|
||||
private sealed partial class LabelsOverlay : Control
|
||||
{
|
||||
private readonly InventoryGridControl _owner;
|
||||
|
||||
public LabelsOverlay(InventoryGridControl owner) => _owner = owner;
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
var grid = _owner._grid;
|
||||
if (grid is null) return;
|
||||
|
||||
_owner.ComputeCellLayout(out float cellSize, out Vector2 origin);
|
||||
if (cellSize < 14f) return;
|
||||
|
||||
var spec = grid.Spec;
|
||||
int fontSize = cellSize >= 38f ? 10 : 9;
|
||||
float alpha = Mathf.Lerp(0.95f, 0.55f, _owner._thermalBlend);
|
||||
|
||||
for (int i = 0; i < spec.Hardpoints.Length; i++)
|
||||
{
|
||||
var hp = spec.Hardpoints[i];
|
||||
var mounted = grid.GetMountedOn(hp.Id);
|
||||
var pos = origin + new Vector2(hp.X * cellSize, hp.Y * cellSize);
|
||||
float maxW = MathF.Max(12f, hp.Width * cellSize - 6f);
|
||||
|
||||
string tag = mounted is not null
|
||||
? $"{mounted.Spec.Kind.ToString()[..1]}:{mounted.CurrentTemp:F0}°"
|
||||
: hp.Kind.ToString()[..3].ToUpperInvariant();
|
||||
|
||||
Color col = mounted is { Spec.IsImperial: true } ? ColGold : ColTextLight;
|
||||
col.A = alpha;
|
||||
|
||||
// Dark shadow for crisp legibility over bright thermal glow
|
||||
DrawString(
|
||||
ThemeDB.FallbackFont,
|
||||
pos + new Vector2(7f, fontSize + 6f),
|
||||
tag,
|
||||
HorizontalAlignment.Left,
|
||||
maxW - 2f,
|
||||
fontSize,
|
||||
new Color(0.04f, 0.05f, 0.04f, alpha * 0.9f));
|
||||
|
||||
DrawString(
|
||||
ThemeDB.FallbackFont,
|
||||
pos + new Vector2(6f, fontSize + 5f),
|
||||
tag,
|
||||
HorizontalAlignment.Left,
|
||||
maxW - 2f,
|
||||
fontSize,
|
||||
col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
592
client/Main.cs
592
client/Main.cs
|
|
@ -1,592 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Root Godot node for Rust to Dust.
|
||||
/// Godot physics is Dummy; <see cref="ArenaSession"/> owns 100% of vehicle, thermal, spectator, and terrain physics at 60 Hz.
|
||||
/// </summary>
|
||||
public partial class Main : Node3D
|
||||
{
|
||||
private TerrainRenderer _terrain = null!;
|
||||
private ArenaRenderer _arena = null!;
|
||||
private Camera3D _camera = null!;
|
||||
private Hud _hud = null!;
|
||||
private ArenaSession? _session;
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(12f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
||||
// Temporary Step 1/Step 3 perf probe (enabled only when RTD_PERF_FRAMES is set)
|
||||
private int _perfTargetFrames;
|
||||
private int _perfFrameCount;
|
||||
private int _perfPhysicsTicks;
|
||||
private long _perfLastFrameTick;
|
||||
private int _perfLastDirtyRebakes;
|
||||
private readonly List<double> _perfFrameMs = new();
|
||||
private readonly List<double> _perfPhysicsStepMs = new();
|
||||
private readonly List<double> _perfTerrainSyncMs = new();
|
||||
private readonly List<double> _perfArenaSyncMs = new();
|
||||
private readonly List<double> _perfHudMs = new();
|
||||
private readonly List<int> _perfDirtyRebakeDelta = new();
|
||||
private readonly List<double> _perfDrawCalls = new();
|
||||
private readonly List<double> _perfPrimitives = new();
|
||||
private readonly List<double> _perfObjects = new();
|
||||
private readonly List<double> _perfNodeCount = new();
|
||||
private readonly List<double> _perfTimeProcess = new();
|
||||
private readonly List<double> _perfTimePhysicsProcess = new();
|
||||
private double _perfPendingStepMs;
|
||||
private double _perfPendingTerrainMs;
|
||||
private double _perfPendingArenaMs;
|
||||
private double _perfCamMsSum;
|
||||
|
||||
public ArenaSession Session => _session ?? throw new InvalidOperationException($"No active ArenaSession ({Failure ?? "uninitialized"})");
|
||||
public TerrainRenderer Terrain => _terrain;
|
||||
public ArenaRenderer Arena => _arena;
|
||||
public Hud Hud => _hud;
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
public float CameraYaw => _cameraYaw;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetupLightingAndSky();
|
||||
|
||||
_terrain = new TerrainRenderer { Name = "Terrain" };
|
||||
AddChild(_terrain);
|
||||
|
||||
_arena = new ArenaRenderer { Name = "Arena" };
|
||||
AddChild(_arena);
|
||||
|
||||
_camera = new Camera3D
|
||||
{
|
||||
Name = "ShoulderCamera",
|
||||
Current = true,
|
||||
Fov = 58f,
|
||||
Far = 1800f
|
||||
};
|
||||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo, () => _cameraYaw) { Name = "Hud" };
|
||||
AddChild(_hud);
|
||||
|
||||
if (int.TryParse(System.Environment.GetEnvironmentVariable("RTD_PERF_FRAMES"), out int perfFrames) && perfFrames > 0)
|
||||
{
|
||||
_perfTargetFrames = perfFrames;
|
||||
ArenaSession.PerfEnabled = true;
|
||||
}
|
||||
|
||||
Reset(_seed);
|
||||
_perfLastFrameTick = Stopwatch.GetTimestamp();
|
||||
_perfLastDirtyRebakes = _terrain.DirtyRebakes;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
}
|
||||
|
||||
public void Reset(int seed)
|
||||
{
|
||||
_seed = seed;
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
Failure = null;
|
||||
|
||||
try
|
||||
{
|
||||
_session = new ArenaSession(seed);
|
||||
var p = _session.State.Player;
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_hud.Sync(_session);
|
||||
|
||||
if (DisplayServer.GetName() != "headless" && !_hud.GarageExpanded && _perfTargetFrames == 0)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Failure = ex.Message;
|
||||
GD.PushError("ArenaSession startup failed: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetScriptedInput(PlayerInput? input) => _scriptedInput = input;
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mm && Input.MouseMode == Input.MouseModeEnum.Captured)
|
||||
{
|
||||
_cameraYaw -= mm.Relative.X * 0.0028f;
|
||||
_cameraPitch = Math.Clamp(
|
||||
_cameraPitch + mm.Relative.Y * 0.0024f,
|
||||
Mathf.DegToRad(-78f),
|
||||
Mathf.DegToRad(62f));
|
||||
return;
|
||||
}
|
||||
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
switch (key.Keycode)
|
||||
{
|
||||
case Key.E:
|
||||
_interactQueued = true;
|
||||
break;
|
||||
case Key.Tab:
|
||||
_hud.ToggleGarage();
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = _hud.GarageExpanded
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
break;
|
||||
case Key.T:
|
||||
_hud.ToggleThermal();
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1);
|
||||
break;
|
||||
case Key.Escape:
|
||||
if (_hud.GarageExpanded)
|
||||
{
|
||||
_hud.ToggleGarage();
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
}
|
||||
}
|
||||
else if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Captured
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (@event is InputEventMouseButton mb && mb.Pressed)
|
||||
{
|
||||
if (mb.ButtonIndex == MouseButton.WheelUp)
|
||||
{
|
||||
_cameraZoom = Math.Clamp(_cameraZoom - 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.WheelDown)
|
||||
{
|
||||
_cameraZoom = Math.Clamp(_cameraZoom + 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.Left &&
|
||||
Input.MouseMode == Input.MouseModeEnum.Visible &&
|
||||
!_hud.GarageExpanded &&
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position) &&
|
||||
DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_elapsedSeconds += (float)delta;
|
||||
var input = _scriptedInput ?? GatherPlayerInput();
|
||||
_interactQueued = false;
|
||||
|
||||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
long t0 = Stopwatch.GetTimestamp();
|
||||
_session.Step(input);
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
long t2 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
long t3 = Stopwatch.GetTimestamp();
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
_perfPendingStepMs += (t1 - t0) * toMs;
|
||||
_perfPendingTerrainMs += (t2 - t1) * toMs;
|
||||
_perfPendingArenaMs += (t3 - t2) * toMs;
|
||||
_perfPhysicsTicks++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_session.Step(input);
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
long th0 = Stopwatch.GetTimestamp();
|
||||
_hud.Sync(_session);
|
||||
long th1 = Stopwatch.GetTimestamp();
|
||||
_perfCamMsSum += (th0 - tc0) * 1000.0 / Stopwatch.Frequency;
|
||||
double hudMs = (th1 - th0) * 1000.0 / Stopwatch.Frequency;
|
||||
|
||||
long now = Stopwatch.GetTimestamp();
|
||||
double frameMs = (now - _perfLastFrameTick) * 1000.0 / Stopwatch.Frequency;
|
||||
_perfLastFrameTick = now;
|
||||
|
||||
_perfFrameMs.Add(frameMs);
|
||||
_perfPhysicsStepMs.Add(_perfPendingStepMs);
|
||||
_perfTerrainSyncMs.Add(_perfPendingTerrainMs);
|
||||
_perfArenaSyncMs.Add(_perfPendingArenaMs);
|
||||
_perfHudMs.Add(hudMs);
|
||||
_perfPendingStepMs = 0;
|
||||
_perfPendingTerrainMs = 0;
|
||||
_perfPendingArenaMs = 0;
|
||||
|
||||
int rebakesNow = _terrain.DirtyRebakes;
|
||||
_perfDirtyRebakeDelta.Add(rebakesNow - _perfLastDirtyRebakes);
|
||||
_perfLastDirtyRebakes = rebakesNow;
|
||||
|
||||
_perfDrawCalls.Add(Performance.GetMonitor(Performance.Monitor.RenderTotalDrawCallsInFrame));
|
||||
_perfPrimitives.Add(Performance.GetMonitor(Performance.Monitor.RenderTotalPrimitivesInFrame));
|
||||
_perfObjects.Add(Performance.GetMonitor(Performance.Monitor.RenderTotalObjectsInFrame));
|
||||
_perfNodeCount.Add(Performance.GetMonitor(Performance.Monitor.ObjectNodeCount));
|
||||
_perfTimeProcess.Add(Performance.GetMonitor(Performance.Monitor.TimeProcess) * 1000.0);
|
||||
_perfTimePhysicsProcess.Add(Performance.GetMonitor(Performance.Monitor.TimePhysicsProcess) * 1000.0);
|
||||
|
||||
_perfFrameCount++;
|
||||
if (_perfFrameCount >= _perfTargetFrames)
|
||||
{
|
||||
PrintPerfSummaryAndQuit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCamera((float)delta);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
_hud.Sync(_session);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintPerfSummaryAndQuit()
|
||||
{
|
||||
static double Avg(List<double> v)
|
||||
{
|
||||
if (v.Count == 0) return 0;
|
||||
double s = 0;
|
||||
foreach (double x in v) s += x;
|
||||
return s / v.Count;
|
||||
}
|
||||
static double P95(List<double> v)
|
||||
{
|
||||
if (v.Count == 0) return 0;
|
||||
var sorted = new List<double>(v);
|
||||
sorted.Sort();
|
||||
int idx = Math.Clamp((int)Math.Ceiling(sorted.Count * 0.95) - 1, 0, sorted.Count - 1);
|
||||
return sorted[idx];
|
||||
}
|
||||
double totalMs = 0;
|
||||
foreach (double x in _perfFrameMs) totalMs += x;
|
||||
double fps = totalMs > 0 ? (_perfFrameMs.Count * 1000.0 / totalMs) : 0;
|
||||
double rebakeAvg = 0;
|
||||
int rebakeTotal = 0;
|
||||
foreach (int r in _perfDirtyRebakeDelta) rebakeTotal += r;
|
||||
rebakeAvg = _perfDirtyRebakeDelta.Count > 0 ? (double)rebakeTotal / _perfDirtyRebakeDelta.Count : 0;
|
||||
|
||||
double steadyMs = 0;
|
||||
int steadyCount = Math.Max(0, _perfFrameMs.Count - 10);
|
||||
for (int i = 10; i < _perfFrameMs.Count; i++) steadyMs += _perfFrameMs[i];
|
||||
double steadyAvgMs = steadyCount > 0 ? steadyMs / steadyCount : 0;
|
||||
double steadyFps = steadyAvgMs > 0 ? 1000.0 / steadyAvgMs : 0;
|
||||
|
||||
GD.Print("=== PERF BENCHMARK SUMMARY ===");
|
||||
GD.Print($"Frames={_perfFrameMs.Count} PhysicsTicks={_perfPhysicsTicks} AvgFPS={fps:F2} SteadyFPS(10..59)={steadyFps:F2} EngineFPS={Engine.GetFramesPerSecond():F1}");
|
||||
GD.Print($"frameMs: avg={Avg(_perfFrameMs):F2} steadyAvg={steadyAvgMs:F2} p95={P95(_perfFrameMs):F2}");
|
||||
GD.Print($"physicsStepMs/frame: avg={Avg(_perfPhysicsStepMs):F2} p95={P95(_perfPhysicsStepMs):F2}");
|
||||
GD.Print($"terrainSyncMs/frame: avg={Avg(_perfTerrainSyncMs):F2} p95={P95(_perfTerrainSyncMs):F2} dirtyRebakesTotal={rebakeTotal} dirtyRebakesAvg={rebakeAvg:F2}");
|
||||
GD.Print($"arenaSyncMs/frame: avg={Avg(_perfArenaSyncMs):F2} p95={P95(_perfArenaSyncMs):F2}");
|
||||
GD.Print($"hudMs/frame: avg={Avg(_perfHudMs):F2} p95={P95(_perfHudMs):F2}");
|
||||
GD.Print($"RenderTotalDrawCallsInFrame: avg={Avg(_perfDrawCalls):F0} max={P95(_perfDrawCalls):F0}");
|
||||
GD.Print($"RenderTotalPrimitivesInFrame: avg={Avg(_perfPrimitives):F0}");
|
||||
GD.Print($"RenderTotalObjectsInFrame: avg={Avg(_perfObjects):F0}");
|
||||
GD.Print($"ObjectNodeCount: avg={Avg(_perfNodeCount):F0}");
|
||||
GD.Print($"TimeProcessMs: avg={Avg(_perfTimeProcess):F2}");
|
||||
GD.Print($"TimePhysicsProcessMs: avg={Avg(_perfTimePhysicsProcess):F2}");
|
||||
GD.Print($"UpdateCameraMs/frame: avg={_perfCamMsSum / _perfFrameMs.Count:F2}");
|
||||
GD.Print($"StepBreakdownMs/tick: ring={ArenaSession.PerfRingMs / _perfPhysicsTicks:F2} ai={ArenaSession.PerfAiMs / _perfPhysicsTicks:F2} drive={ArenaSession.PerfDriveMs / _perfPhysicsTicks:F2} world={ArenaSession.PerfWorldMs / _perfPhysicsTicks:F2} sync={ArenaSession.PerfBodySyncMs / _perfPhysicsTicks:F2} detect={ArenaSession.PerfDetectMs / _perfPhysicsTicks:F2} weapons={ArenaSession.PerfWeaponsMs / _perfPhysicsTicks:F2}");
|
||||
foreach (var kv in _arena.AssetCache.Vehicles)
|
||||
{
|
||||
int tris = 0;
|
||||
var bm = kv.Value.BakedStaticMesh;
|
||||
for (int s = 0; s < bm.GetSurfaceCount(); s++)
|
||||
{
|
||||
var arr = bm.SurfaceGetArrays(s);
|
||||
if (arr.Count > (int)Mesh.ArrayType.Index && arr[(int)Mesh.ArrayType.Index].VariantType == Variant.Type.PackedInt32Array)
|
||||
tris += arr[(int)Mesh.ArrayType.Index].AsInt32Array().Length / 3;
|
||||
}
|
||||
int farTris = 0;
|
||||
var fm = kv.Value.BakedLodFarMesh;
|
||||
for (int s = 0; s < fm.GetSurfaceCount(); s++)
|
||||
{
|
||||
var arr = fm.SurfaceGetArrays(s);
|
||||
if (arr.Count > (int)Mesh.ArrayType.Index && arr[(int)Mesh.ArrayType.Index].VariantType == Variant.Type.PackedInt32Array)
|
||||
farTris += arr[(int)Mesh.ArrayType.Index].AsInt32Array().Length / 3;
|
||||
}
|
||||
int nodes = CountSubtreeNodes(kv.Value.SceneTemplate);
|
||||
GD.Print($" Vehicle '{kv.Key}': nodes={nodes} bakedTris={tris} farTris={farTris} surfs={bm.GetSurfaceCount()} farSurfs={fm.GetSurfaceCount()} detachChunks={kv.Value.DetachableParts.Count}");
|
||||
}
|
||||
if (_arena.AssetCache.Vehicles.TryGetValue("paladin", out var palTpl))
|
||||
{
|
||||
var names = new List<string>();
|
||||
CollectNodeNames(palTpl.SceneTemplate, names, 40);
|
||||
GD.Print($" Paladin sample nodes: {string.Join(", ", names)}");
|
||||
}
|
||||
GD.Print("=== END PERF BENCHMARK ===");
|
||||
GetTree().Quit(0);
|
||||
}
|
||||
|
||||
private static void CollectNodeNames(Node cur, List<string> outNames, int limit)
|
||||
{
|
||||
if (outNames.Count >= limit) return;
|
||||
outNames.Add($"{cur.Name}({cur.GetType().Name})");
|
||||
for (int i = 0; i < cur.GetChildCount(); i++) CollectNodeNames(cur.GetChild(i), outNames, limit);
|
||||
}
|
||||
|
||||
private static int CountSubtreeNodes(Node cur)
|
||||
{
|
||||
int n = 1;
|
||||
for (int i = 0; i < cur.GetChildCount(); i++) n += CountSubtreeNodes(cur.GetChild(i));
|
||||
return n;
|
||||
}
|
||||
|
||||
private PlayerInput GatherPlayerInput()
|
||||
{
|
||||
float throttle = 0f;
|
||||
if (Input.IsKeyPressed(Key.W) || Input.IsKeyPressed(Key.Up)) throttle += 1f;
|
||||
if (Input.IsKeyPressed(Key.S) || Input.IsKeyPressed(Key.Down)) throttle -= 1f;
|
||||
|
||||
float steer = 0f;
|
||||
if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right)) steer += 1f;
|
||||
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
|
||||
|
||||
bool isVtol = Session.State.Player.Grid.Spec.IsVtol;
|
||||
float verticalThrottle = 0f;
|
||||
if (Input.IsKeyPressed(Key.Space)) verticalThrottle += 1f;
|
||||
if (Input.IsKeyPressed(Key.C) || Input.IsKeyPressed(Key.Ctrl)) verticalThrottle -= 1f;
|
||||
|
||||
bool brake = isVtol ? Input.IsKeyPressed(Key.Shift) : Input.IsKeyPressed(Key.Space);
|
||||
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
|
||||
_hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition());
|
||||
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
|
||||
|
||||
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
|
||||
return new PlayerInput(
|
||||
Throttle: throttle,
|
||||
Steer: steer,
|
||||
AimWorldX: aimX,
|
||||
AimWorldZ: aimZ,
|
||||
Fire: fire,
|
||||
InteractPickup: _interactQueued,
|
||||
Brake: brake,
|
||||
AimWorldY: aimY,
|
||||
VerticalThrottle: verticalThrottle);
|
||||
}
|
||||
|
||||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Player;
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
{
|
||||
return (
|
||||
player.X + MathF.Sin(_cameraYaw) * 40f,
|
||||
player.Y,
|
||||
player.Z + MathF.Cos(_cameraYaw) * 40f);
|
||||
}
|
||||
|
||||
Vector2 center = screenSize * 0.5f;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(center);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(center);
|
||||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
|
||||
Vector3 castOrigin = rayOrigin;
|
||||
float remainingDist = maxAimDist;
|
||||
float boxDist = maxAimDist;
|
||||
Vector3 boxHitPt = Vector3.Zero;
|
||||
bool hasBoxHit = false;
|
||||
|
||||
// Cast against Ymir world, skipping the player's own chassis if hit along the shoulder ray.
|
||||
for (int attempt = 0; attempt < 2; attempt++)
|
||||
{
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(rayDir.X * remainingDist, rayDir.Y * remainingDist, rayDir.Z * remainingDist));
|
||||
if (!hit.Hit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
if (hit.StableId == playerStableId)
|
||||
{
|
||||
float skip = rayOrigin.DistanceTo(pt) + 0.4f;
|
||||
castOrigin = rayOrigin + rayDir * skip;
|
||||
remainingDist = MathF.Max(1f, maxAimDist - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
boxHitPt = pt;
|
||||
boxDist = rayOrigin.DistanceTo(pt);
|
||||
hasBoxHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
bool hasTerrainHit = Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: boxDist,
|
||||
out float tx, out float ty, out float tz, out float terrainDist);
|
||||
|
||||
if (hasTerrainHit && terrainDist <= boxDist)
|
||||
{
|
||||
return (tx, ty, tz);
|
||||
}
|
||||
|
||||
if (hasBoxHit)
|
||||
{
|
||||
return (boxHitPt.X, boxHitPt.Y, boxHitPt.Z);
|
||||
}
|
||||
|
||||
Vector3 farPt = rayOrigin + rayDir * 320f;
|
||||
return (farPt.X, farPt.Y, farPt.Z);
|
||||
}
|
||||
|
||||
private Vector3 ComputeTargetAnchor(ContenderState p)
|
||||
{
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float upOffset = Mathf.Lerp(3.2f, 6.5f, heightT);
|
||||
float rightOffset = Mathf.Lerp(1.6f, 2.8f, heightT);
|
||||
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
return new Vector3(p.X, p.Y + (upOffset - spec.HalfHeight), p.Z) + camRight * rightOffset;
|
||||
}
|
||||
|
||||
private void UpdateCamera(float dt)
|
||||
{
|
||||
var p = Session.State.Player;
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float backDist = Mathf.Lerp(7.5f, 12.5f, heightT) * _cameraZoom;
|
||||
|
||||
Vector3 targetAnchor = ComputeTargetAnchor(p);
|
||||
float blend = dt >= 1f ? 1f : 1f - MathF.Exp(-dt * 16f);
|
||||
_cameraSmoothedAnchor = _cameraSmoothedAnchor.Lerp(targetAnchor, blend);
|
||||
|
||||
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
|
||||
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
|
||||
|
||||
// Pull camera forward along arm if terrain or static cover blocks the shoulder-to-camera ray
|
||||
float effectiveBack = backDist;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z,
|
||||
-lookDir.X, -lookDir.Y, -lookDir.Z,
|
||||
backDist,
|
||||
out _, out _, out _, out float terrainDist))
|
||||
{
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, terrainDist - 0.6f));
|
||||
}
|
||||
|
||||
var boxHit = Session.World.CastRayClosest(
|
||||
(_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z),
|
||||
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
|
||||
if (boxHit.Hit && boxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(boxHit.Point.X, boxHit.Point.Y, boxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, _cameraSmoothedAnchor.DistanceTo(pt) - 0.5f));
|
||||
}
|
||||
|
||||
Vector3 camPos = _cameraSmoothedAnchor - lookDir * effectiveBack;
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
camPos.Y = minTerrainY;
|
||||
}
|
||||
|
||||
_camera.GlobalPosition = camPos;
|
||||
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
|
||||
}
|
||||
|
||||
private void OnEquipCargo(int cargoIndex, string hardpointId)
|
||||
{
|
||||
_session?.TryEquipCargo(cargoIndex, hardpointId);
|
||||
}
|
||||
|
||||
private void SetupLightingAndSky()
|
||||
{
|
||||
var sun = new DirectionalLight3D
|
||||
{
|
||||
Name = "DesertSun",
|
||||
LightColor = new Color(1.0f, 0.92f, 0.78f),
|
||||
LightEnergy = 1.45f,
|
||||
ShadowEnabled = true,
|
||||
DirectionalShadowMode = DirectionalLight3D.ShadowMode.Parallel2Splits,
|
||||
DirectionalShadowMaxDistance = 145f,
|
||||
RotationDegrees = new Vector3(-48f, 32f, 0f)
|
||||
};
|
||||
AddChild(sun);
|
||||
|
||||
var skyMat = new ProceduralSkyMaterial
|
||||
{
|
||||
SkyTopColor = new Color(0.24f, 0.34f, 0.44f),
|
||||
SkyHorizonColor = new Color(0.76f, 0.56f, 0.37f),
|
||||
GroundBottomColor = new Color(0.32f, 0.22f, 0.14f),
|
||||
GroundHorizonColor = new Color(0.70f, 0.50f, 0.33f)
|
||||
};
|
||||
var env = new Godot.Environment
|
||||
{
|
||||
BackgroundMode = Godot.Environment.BGMode.Sky,
|
||||
Sky = new Sky { SkyMaterial = skyMat },
|
||||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.55f,
|
||||
FogEnabled = true,
|
||||
FogMode = Godot.Environment.FogModeEnum.Depth,
|
||||
FogLightColor = new Color(0.76f, 0.57f, 0.39f),
|
||||
FogDensity = 0.72f,
|
||||
FogDepthBegin = 380f,
|
||||
FogDepthEnd = 1100f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://Main.cs" id="1"]
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Godot;
|
||||
using Ymir.Box3D;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Finds ymir_box3d for Ymir.Box3D's DllImports. Godot loads game assemblies into its own load context, so the
|
||||
/// default probing does not look beside them. A run from the editor or <c>--path</c> loads the library from the
|
||||
/// project's build directory; an exported run from the data folder Godot puts beside the executable.
|
||||
/// </summary>
|
||||
internal static class NativeLibraries
|
||||
{
|
||||
private const string Library = "ymir_box3d";
|
||||
|
||||
#pragma warning disable CA2255 // application code: the resolver must exist before the first DllImport
|
||||
[ModuleInitializer]
|
||||
internal static void Register() =>
|
||||
NativeLibrary.SetDllImportResolver(typeof(Box3DSoaWorld).Assembly, Resolve);
|
||||
|
||||
private static IntPtr Resolve(string name, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
if (name != Library) return IntPtr.Zero;
|
||||
string fileName = FileName();
|
||||
|
||||
if (OS.HasFeature("template"))
|
||||
{
|
||||
string exportPath = Path.Combine(
|
||||
Path.GetDirectoryName(OS.GetExecutablePath())!,
|
||||
$"data_RustToDust.Client_{Platform()}_{Arch()}",
|
||||
fileName);
|
||||
return File.Exists(exportPath) && NativeLibrary.TryLoad(exportPath, out var exportHandle)
|
||||
? exportHandle
|
||||
: IntPtr.Zero;
|
||||
}
|
||||
|
||||
string debugPath = Path.Combine(ProjectSettings.GlobalizePath("res://.godot/mono/temp/bin/Debug"), fileName);
|
||||
if (File.Exists(debugPath) && NativeLibrary.TryLoad(debugPath, out var debugHandle))
|
||||
{
|
||||
return debugHandle;
|
||||
}
|
||||
|
||||
string releasePath = Path.Combine(ProjectSettings.GlobalizePath("res://.godot/mono/temp/bin/Release"), fileName);
|
||||
return File.Exists(releasePath) && NativeLibrary.TryLoad(releasePath, out var releaseHandle)
|
||||
? releaseHandle
|
||||
: IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static string FileName() =>
|
||||
OperatingSystem.IsWindows() ? "ymir_box3d.dll" : OperatingSystem.IsMacOS() ? "libymir_box3d.dylib" : "libymir_box3d.so";
|
||||
|
||||
private static string Platform() =>
|
||||
OperatingSystem.IsWindows() ? "windows" : OperatingSystem.IsMacOS() ? "macos" : "linuxbsd";
|
||||
|
||||
private static string Arch() =>
|
||||
RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64 ? "arm64" : "x86_64";
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<Project Sdk="Godot.NET.Sdk/4.7.2">
|
||||
<!-- The Godot client: presentation and input over ArenaSession. Building it builds Ymir (cmake and a C compiler) and RustToDust into .godot/mono/temp/bin/Debug. -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>RustToDust.Client</AssemblyName>
|
||||
<RootNamespace>RustToDust.Client</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\src\RustToDust.Ymir\RustToDust.Ymir.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,466 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Top-down orthographic SubViewport brush-to-tile PBR + displacement terrain baker.
|
||||
/// Maintains an 8x8 grid of 192m x 192m terrain tiles covering [-768, +768] in X and Z.
|
||||
/// Only tiles whose <see cref="TerrainField.TileVersions"/> changed are re-baked.
|
||||
/// </summary>
|
||||
public partial class TerrainRenderer : Node3D
|
||||
{
|
||||
private const int ViewportSize = 256;
|
||||
private const float InnerTexelSpan = 253.0f; // texel 1 center (1.5) .. texel 254 center (254.5)
|
||||
private const float GutterCenterOffset = 1.5f;
|
||||
private const float PixelsPerMeter = InnerTexelSpan / TerrainField.TileSize;
|
||||
private const float HeightSpan = TerrainField.MaxWorldHeight - TerrainField.MinWorldHeight;
|
||||
private const float BaseHeightNorm = (0f - TerrainField.MinWorldHeight) / HeightSpan;
|
||||
|
||||
private static readonly Color HeightClearColor = new(BaseHeightNorm, 0.88f, 0.0f, 1.0f);
|
||||
private static readonly Color AlbedoClearColor = new(0.69f, 0.50f, 0.31f, 1.0f);
|
||||
private static readonly Vector2[] BrushUv =
|
||||
{
|
||||
new(0f, 0f),
|
||||
new(1f, 0f),
|
||||
new(1f, 1f),
|
||||
new(0f, 1f)
|
||||
};
|
||||
|
||||
private sealed class TileNode
|
||||
{
|
||||
public SubViewport HeightViewport = null!;
|
||||
public Node2D HeightCanvas = null!;
|
||||
public SubViewport AlbedoViewport = null!;
|
||||
public Node2D AlbedoCanvas = null!;
|
||||
public MeshInstance3D SurfaceMesh = null!;
|
||||
public int BakedVersion = -1;
|
||||
}
|
||||
|
||||
private readonly TileNode[,] _tiles = new TileNode[TerrainField.TileGridCount, TerrainField.TileGridCount];
|
||||
private PlaneMesh _nearPlaneMesh = null!;
|
||||
private PlaneMesh _farPlaneMesh = null!;
|
||||
private ImageTexture _white1x1 = null!;
|
||||
private Shader _clearShader = null!;
|
||||
private Shader _brushAddShader = null!;
|
||||
private Shader _brushSubShader = null!;
|
||||
private Shader _brushAlbedoShader = null!;
|
||||
private Shader _surfaceShader = null!;
|
||||
private const int MaxDirtyRebakesPerSync = 2;
|
||||
private TerrainField? _lastTerrain;
|
||||
private int _rebakeCursor;
|
||||
|
||||
public int BakedTileCount { get; private set; }
|
||||
public int DirtyRebakes { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var whiteImg = Image.CreateEmpty(1, 1, false, Image.Format.Rgba8);
|
||||
whiteImg.SetPixel(0, 0, Colors.White);
|
||||
_white1x1 = ImageTexture.CreateFromImage(whiteImg);
|
||||
|
||||
_nearPlaneMesh = new PlaneMesh
|
||||
{
|
||||
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
|
||||
SubdivideWidth = 64,
|
||||
SubdivideDepth = 64
|
||||
};
|
||||
_farPlaneMesh = new PlaneMesh
|
||||
{
|
||||
Size = new Vector2(TerrainField.TileSize, TerrainField.TileSize),
|
||||
SubdivideWidth = 16,
|
||||
SubdivideDepth = 16
|
||||
};
|
||||
|
||||
_clearShader = new Shader
|
||||
{
|
||||
Code = """
|
||||
shader_type canvas_item;
|
||||
render_mode blend_disabled;
|
||||
uniform vec4 clear_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
void fragment() {
|
||||
COLOR = clear_color;
|
||||
}
|
||||
"""
|
||||
};
|
||||
_brushAddShader = GD.Load<Shader>("res://terrain_brush.gdshader");
|
||||
_brushSubShader = GD.Load<Shader>("res://terrain_brush_sub.gdshader");
|
||||
_brushAlbedoShader = GD.Load<Shader>("res://terrain_brush_albedo.gdshader");
|
||||
_surfaceShader = GD.Load<Shader>("res://terrain_surface.gdshader");
|
||||
|
||||
BuildTileGrid();
|
||||
}
|
||||
|
||||
public void InvalidateAll()
|
||||
{
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
_tiles[tx, tz].BakedVersion = -1;
|
||||
}
|
||||
}
|
||||
BakedTileCount = 0;
|
||||
DirtyRebakes = 0;
|
||||
_lastTerrain = null;
|
||||
}
|
||||
|
||||
public void Sync(TerrainField terrain)
|
||||
{
|
||||
if (!ReferenceEquals(_lastTerrain, terrain))
|
||||
{
|
||||
InvalidateAll();
|
||||
_lastTerrain = terrain;
|
||||
}
|
||||
|
||||
const int totalTiles = TerrainField.TileGridCount * TerrainField.TileGridCount;
|
||||
|
||||
// 1. Always bake uninitialized tiles immediately
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
var tile = _tiles[tx, tz];
|
||||
int version = terrain.TileVersions[tx, tz];
|
||||
if (tile.BakedVersion < 0 && tile.BakedVersion != version)
|
||||
{
|
||||
BakeTile(tx, tz, tile, terrain);
|
||||
BakedTileCount++;
|
||||
tile.BakedVersion = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Budget dynamic tile rebakes (tracks/craters) to <= 2 per Sync in round-robin order
|
||||
int rebakedThisSync = 0;
|
||||
bool anyRemainingDirty = false;
|
||||
for (int step = 0; step < totalTiles; step++)
|
||||
{
|
||||
int idx = (_rebakeCursor + step) % totalTiles;
|
||||
int tx = idx % TerrainField.TileGridCount;
|
||||
int tz = idx / TerrainField.TileGridCount;
|
||||
var tile = _tiles[tx, tz];
|
||||
int version = terrain.TileVersions[tx, tz];
|
||||
if (tile.BakedVersion != version)
|
||||
{
|
||||
if (rebakedThisSync < MaxDirtyRebakesPerSync)
|
||||
{
|
||||
BakeTile(tx, tz, tile, terrain);
|
||||
DirtyRebakes++;
|
||||
tile.BakedVersion = version;
|
||||
rebakedThisSync++;
|
||||
_rebakeCursor = (idx + 1) % totalTiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
anyRemainingDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!anyRemainingDirty)
|
||||
{
|
||||
terrain.ClearDirtyMask();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTileLod(Vector3 camPos)
|
||||
{
|
||||
const float nearRadiusSq = 240f * 240f;
|
||||
const float shadowRadiusSq = 220f * 220f;
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
var tile = _tiles[tx, tz];
|
||||
if (tile?.SurfaceMesh is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Vector3 pos = tile.SurfaceMesh.Position;
|
||||
float dx = pos.X - camPos.X;
|
||||
float dz = pos.Z - camPos.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
PlaneMesh desired = d2 <= nearRadiusSq ? _nearPlaneMesh : _farPlaneMesh;
|
||||
if (!ReferenceEquals(tile.SurfaceMesh.Mesh, desired))
|
||||
{
|
||||
tile.SurfaceMesh.Mesh = desired;
|
||||
}
|
||||
var desiredShadow = d2 <= shadowRadiusSq
|
||||
? GeometryInstance3D.ShadowCastingSetting.On
|
||||
: GeometryInstance3D.ShadowCastingSetting.Off;
|
||||
if (tile.SurfaceMesh.CastShadow != desiredShadow)
|
||||
{
|
||||
tile.SurfaceMesh.CastShadow = desiredShadow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetHeightImageFormat(out Image.Format format)
|
||||
{
|
||||
format = Image.Format.Max;
|
||||
var img = _tiles[0, 0]?.HeightViewport?.GetTexture()?.GetImage();
|
||||
if (img is null || img.IsEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
format = img.GetFormat();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TrySampleBakedHeight(float wx, float wz, out float bakedHeight)
|
||||
{
|
||||
bakedHeight = 0f;
|
||||
float cx = Math.Clamp(wx, -TerrainField.HalfExtent, TerrainField.HalfExtent);
|
||||
float cz = Math.Clamp(wz, -TerrainField.HalfExtent, TerrainField.HalfExtent);
|
||||
TerrainField.WorldToTile(cx, cz, out int tx, out int tz);
|
||||
|
||||
var tile = _tiles[tx, tz];
|
||||
var tex = tile?.HeightViewport?.GetTexture();
|
||||
var img = tex?.GetImage();
|
||||
if (img is null || img.IsEmpty() || img.GetWidth() < ViewportSize || img.GetHeight() < ViewportSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float tileMinX = -TerrainField.HalfExtent + tx * TerrainField.TileSize;
|
||||
float tileMinZ = -TerrainField.HalfExtent + tz * TerrainField.TileSize;
|
||||
float px = GutterCenterOffset + (cx - tileMinX) * PixelsPerMeter;
|
||||
float py = GutterCenterOffset + (cz - tileMinZ) * PixelsPerMeter;
|
||||
|
||||
float fx = Math.Clamp(px - 0.5f, 0f, ViewportSize - 1.0001f);
|
||||
float fy = Math.Clamp(py - 0.5f, 0f, ViewportSize - 1.0001f);
|
||||
int x0 = (int)MathF.Floor(fx);
|
||||
int y0 = (int)MathF.Floor(fy);
|
||||
int x1 = Math.Min(x0 + 1, ViewportSize - 1);
|
||||
int y1 = Math.Min(y0 + 1, ViewportSize - 1);
|
||||
float txFrac = fx - x0;
|
||||
float tyFrac = fy - y0;
|
||||
|
||||
var c00 = img.GetPixel(x0, y0);
|
||||
if (c00.A < 0.5f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var c10 = img.GetPixel(x1, y0);
|
||||
var c01 = img.GetPixel(x0, y1);
|
||||
var c11 = img.GetPixel(x1, y1);
|
||||
|
||||
float r = (c00.R * (1f - txFrac) + c10.R * txFrac) * (1f - tyFrac) +
|
||||
(c01.R * (1f - txFrac) + c11.R * txFrac) * tyFrac;
|
||||
bakedHeight = TerrainField.MinWorldHeight + Math.Clamp(r, 0f, 1f) * HeightSpan;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BuildTileGrid()
|
||||
{
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
var tile = new TileNode();
|
||||
|
||||
tile.HeightViewport = CreateOrthoViewport($"Tile_{tx}_{tz}_Height", useHdr: true, out var heightCanvas);
|
||||
tile.HeightCanvas = heightCanvas;
|
||||
AddChild(tile.HeightViewport);
|
||||
|
||||
tile.AlbedoViewport = CreateOrthoViewport($"Tile_{tx}_{tz}_Albedo", useHdr: false, out var albedoCanvas);
|
||||
tile.AlbedoCanvas = albedoCanvas;
|
||||
AddChild(tile.AlbedoViewport);
|
||||
|
||||
var mat = new ShaderMaterial { Shader = _surfaceShader };
|
||||
mat.SetShaderParameter("height_tex", tile.HeightViewport.GetTexture());
|
||||
mat.SetShaderParameter("albedo_tex", tile.AlbedoViewport.GetTexture());
|
||||
mat.SetShaderParameter("height_min", TerrainField.MinWorldHeight);
|
||||
mat.SetShaderParameter("height_max", TerrainField.MaxWorldHeight);
|
||||
mat.SetShaderParameter("tile_size", TerrainField.TileSize);
|
||||
mat.SetShaderParameter("inner_span", InnerTexelSpan);
|
||||
mat.SetShaderParameter("tex_size", (float)ViewportSize);
|
||||
mat.SetShaderParameter("gutter_offset", GutterCenterOffset);
|
||||
|
||||
float centerX = -TerrainField.HalfExtent + (tx + 0.5f) * TerrainField.TileSize;
|
||||
float centerZ = -TerrainField.HalfExtent + (tz + 0.5f) * TerrainField.TileSize;
|
||||
|
||||
tile.SurfaceMesh = new MeshInstance3D
|
||||
{
|
||||
Name = $"Tile_{tx}_{tz}_Mesh",
|
||||
Mesh = _nearPlaneMesh,
|
||||
MaterialOverride = mat,
|
||||
Position = new Vector3(centerX, 0f, centerZ),
|
||||
CustomAabb = new Aabb(
|
||||
new Vector3(-TerrainField.TileSize * 0.5f, TerrainField.MinWorldHeight - 2f, -TerrainField.TileSize * 0.5f),
|
||||
new Vector3(TerrainField.TileSize, HeightSpan + 4f, TerrainField.TileSize))
|
||||
};
|
||||
AddChild(tile.SurfaceMesh);
|
||||
|
||||
_tiles[tx, tz] = tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SubViewport CreateOrthoViewport(string name, bool useHdr, out Node2D canvas)
|
||||
{
|
||||
var vp = new SubViewport
|
||||
{
|
||||
Name = name,
|
||||
Size = new Vector2I(ViewportSize, ViewportSize),
|
||||
Disable3D = true,
|
||||
UseHdr2D = useHdr,
|
||||
TransparentBg = false,
|
||||
Snap2DTransformsToPixel = false,
|
||||
Snap2DVerticesToPixel = false,
|
||||
RenderTargetClearMode = SubViewport.ClearMode.Always,
|
||||
RenderTargetUpdateMode = SubViewport.UpdateMode.Disabled
|
||||
};
|
||||
|
||||
var cam = new Camera2D
|
||||
{
|
||||
AnchorMode = Camera2D.AnchorModeEnum.FixedTopLeft,
|
||||
Position = Vector2.Zero,
|
||||
Enabled = true,
|
||||
PhysicsInterpolationMode = PhysicsInterpolationModeEnum.Off,
|
||||
ProcessCallback = Camera2D.Camera2DProcessCallback.Physics
|
||||
};
|
||||
vp.AddChild(cam);
|
||||
|
||||
canvas = new Node2D { Name = "Canvas" };
|
||||
vp.AddChild(canvas);
|
||||
return vp;
|
||||
}
|
||||
|
||||
private void BakeTile(int tx, int tz, TileNode tile, TerrainField terrain)
|
||||
{
|
||||
ClearCanvasChildren(tile.HeightCanvas);
|
||||
ClearCanvasChildren(tile.AlbedoCanvas);
|
||||
|
||||
// Full-tile base clear quads (Polygon2D avoids GUI pixel snapping)
|
||||
tile.HeightCanvas.AddChild(CreateClearQuad(HeightClearColor, _clearShader, _white1x1));
|
||||
tile.AlbedoCanvas.AddChild(CreateClearQuad(AlbedoClearColor, _clearShader, _white1x1));
|
||||
|
||||
float tileMinX = -TerrainField.HalfExtent + tx * TerrainField.TileSize;
|
||||
float tileMinZ = -TerrainField.HalfExtent + tz * TerrainField.TileSize;
|
||||
IReadOnlyList<int> indices = terrain.GetTileBrushIndices(tx, tz);
|
||||
var brushes = terrain.Brushes;
|
||||
|
||||
for (int i = 0; i < indices.Count; i++)
|
||||
{
|
||||
var b = brushes[indices[i]];
|
||||
if (b.RadiusX <= 0.05f || b.RadiusZ <= 0.05f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float px = GutterCenterOffset + (b.X - tileMinX) * PixelsPerMeter;
|
||||
float py = GutterCenterOffset + (b.Z - tileMinZ) * PixelsPerMeter;
|
||||
float rxPx = b.RadiusX * PixelsPerMeter;
|
||||
float rzPx = b.RadiusZ * PixelsPerMeter;
|
||||
int kindInt = (int)b.Kind;
|
||||
|
||||
// 1. Height+Material brush pass(es)
|
||||
if (b.Kind == TerrainBrushKind.Crater)
|
||||
{
|
||||
// Crater uses subtractive pit + additive ejecta rim/scorch
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta, _white1x1));
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta, _white1x1));
|
||||
}
|
||||
else if (b.Kind == TerrainBrushKind.Track)
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta, _white1x1));
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta, _white1x1));
|
||||
}
|
||||
else if (b.Kind == TerrainBrushKind.Road || b.HeightDelta < 0f)
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushSubShader, kindInt, b.HeightDelta, _white1x1));
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.HeightCanvas.AddChild(CreateBrushQuad(px, py, rxPx, rzPx, b.RotationRad, _brushAddShader, kindInt, b.HeightDelta, _white1x1));
|
||||
}
|
||||
|
||||
// 2. Albedo brush pass
|
||||
var albedoQuad = CreateOrientedQuad(px, py, rxPx, rzPx, b.RotationRad, _white1x1);
|
||||
var albedoMat = new ShaderMaterial { Shader = _brushAlbedoShader };
|
||||
albedoMat.SetShaderParameter("brush_kind", kindInt);
|
||||
albedoMat.SetShaderParameter("brush_albedo", new Vector3(b.AlbedoR, b.AlbedoG, b.AlbedoB));
|
||||
albedoMat.SetShaderParameter("height_delta", b.HeightDelta);
|
||||
albedoQuad.Material = albedoMat;
|
||||
tile.AlbedoCanvas.AddChild(albedoQuad);
|
||||
}
|
||||
|
||||
tile.HeightViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
|
||||
tile.AlbedoViewport.RenderTargetUpdateMode = SubViewport.UpdateMode.Once;
|
||||
}
|
||||
|
||||
private static Polygon2D CreateClearQuad(Color color, Shader clearShader, ImageTexture whiteTex)
|
||||
{
|
||||
var mat = new ShaderMaterial { Shader = clearShader };
|
||||
mat.SetShaderParameter("clear_color", color);
|
||||
return new Polygon2D
|
||||
{
|
||||
Polygon = new[]
|
||||
{
|
||||
new Vector2(0f, 0f),
|
||||
new Vector2(ViewportSize, 0f),
|
||||
new Vector2(ViewportSize, ViewportSize),
|
||||
new Vector2(0f, ViewportSize)
|
||||
},
|
||||
UV = BrushUv,
|
||||
Texture = whiteTex,
|
||||
Material = mat
|
||||
};
|
||||
}
|
||||
|
||||
private static Polygon2D CreateOrientedQuad(
|
||||
float px, float py,
|
||||
float rxPx, float rzPx,
|
||||
float rotationRad,
|
||||
ImageTexture whiteTex)
|
||||
{
|
||||
return new Polygon2D
|
||||
{
|
||||
Position = new Vector2(px, py),
|
||||
Rotation = rotationRad,
|
||||
Polygon = new[]
|
||||
{
|
||||
new Vector2(-rxPx, -rzPx),
|
||||
new Vector2(rxPx, -rzPx),
|
||||
new Vector2(rxPx, rzPx),
|
||||
new Vector2(-rxPx, rzPx)
|
||||
},
|
||||
UV = BrushUv,
|
||||
Texture = whiteTex
|
||||
};
|
||||
}
|
||||
|
||||
private static Polygon2D CreateBrushQuad(
|
||||
float px, float py,
|
||||
float rxPx, float rzPx,
|
||||
float rotationRad,
|
||||
Shader shader,
|
||||
int kindInt,
|
||||
float heightDelta,
|
||||
ImageTexture whiteTex)
|
||||
{
|
||||
var quad = CreateOrientedQuad(px, py, rxPx, rzPx, rotationRad, whiteTex);
|
||||
var mat = new ShaderMaterial { Shader = shader };
|
||||
mat.SetShaderParameter("brush_kind", kindInt);
|
||||
mat.SetShaderParameter("height_delta", heightDelta);
|
||||
mat.SetShaderParameter("height_span", HeightSpan);
|
||||
quad.Material = mat;
|
||||
return quad;
|
||||
}
|
||||
|
||||
private static void ClearCanvasChildren(Node2D canvas)
|
||||
{
|
||||
for (int i = canvas.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
var child = canvas.GetChild(i);
|
||||
canvas.RemoveChild(child);
|
||||
child.QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,906 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
public enum VehicleVisualRole
|
||||
{
|
||||
Player,
|
||||
Rival,
|
||||
SpectatorTourist,
|
||||
SpectatorPatron,
|
||||
SpectatorExemplar,
|
||||
SalvageDrop
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Live Godot 3D instance of a Brokkr vehicle/mech GLB, managing:
|
||||
/// - grounded model alignment (<c>minY = 0</c> at physics chassis bottom <c>-HalfHeight</c>),
|
||||
/// - exterior hardpoint anchor bindings and snap-on modular gear GLBs,
|
||||
/// - joint pivot bindings with rest transforms and vehicle-space axes,
|
||||
/// - part-by-cell armor/shroud detachment and hardpoint gear shearing into <see cref="DebrisSystem"/>,
|
||||
/// - per-cell scorch/damage darkening and thermal heat glow.
|
||||
/// </summary>
|
||||
public sealed class VehicleVisualInstance
|
||||
{
|
||||
public sealed class BoundJoint
|
||||
{
|
||||
public required string JointId;
|
||||
public required Node3D Node;
|
||||
public required Transform3D RestLocal;
|
||||
public required Vector3 AxisInParent;
|
||||
public required float MinRad;
|
||||
public required float MaxRad;
|
||||
}
|
||||
|
||||
private sealed class BoundHardpoint
|
||||
{
|
||||
public required HardpointSpec Spec;
|
||||
public required VehicleAssetCache.GlbAnchorInfo AnchorInfo;
|
||||
public required Node3D AnchorNode;
|
||||
public string? MountedModuleId;
|
||||
public Node3D? GearNode;
|
||||
public readonly List<StandardMaterial3D> GearHeatMaterials = new();
|
||||
}
|
||||
|
||||
private sealed class CellPartBinding
|
||||
{
|
||||
public required MeshInstance3D Node;
|
||||
public readonly List<(StandardMaterial3D Mat, Color BaseColor, float BaseRoughness)> Materials = new();
|
||||
public bool Detached;
|
||||
public float LastTintScore = -1f;
|
||||
}
|
||||
|
||||
private readonly record struct GearVisualRecipe(
|
||||
string GearGlbId,
|
||||
Vector3 VariantScale,
|
||||
Color? PaintTint,
|
||||
Color? AccentTint);
|
||||
|
||||
private static readonly Color RivalArmorColor = Color.FromHtml("#5d4d42");
|
||||
private static readonly Color RivalAccentColor = Color.FromHtml("#b64a32");
|
||||
private static readonly Color TouristGold = Color.FromHtml("#e6b838");
|
||||
private static readonly Color TouristIvory = Color.FromHtml("#f2ead8");
|
||||
private static readonly Color PatronTeal = Color.FromHtml("#2d7a78");
|
||||
private static readonly Color PatronBronze = Color.FromHtml("#a86c36");
|
||||
private static readonly Color ExemplarObsidian = Color.FromHtml("#1b1b22");
|
||||
private static readonly Color ExemplarCrimson = Color.FromHtml("#c92a2a");
|
||||
private static readonly Color SalvageSteel = Color.FromHtml("#545b5c");
|
||||
private static readonly Color SalvageCyan = Color.FromHtml("#44d9e8");
|
||||
|
||||
private readonly VehicleAssetCache _cache;
|
||||
private readonly VehicleAssetCache.VehicleTemplate _template;
|
||||
private readonly Dictionary<string, BoundHardpoint> _hardpoints = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, BoundJoint> _joints = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, Node3D> _namedNodes = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, Transform3D> _restLocalByName = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, Transform3D> _restModelByName = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<Node3D, Transform3D> _restModelByNode = new();
|
||||
private readonly List<CellPartBinding>[,] _cellParts;
|
||||
private readonly bool[,] _strippedCells;
|
||||
private readonly HashSet<string> _shearedHardpoints = new(StringComparer.Ordinal);
|
||||
private readonly VehicleRigAnimator.RigState _rigState = new();
|
||||
|
||||
private readonly string _chassisId;
|
||||
private MeshInstance3D? _lodStaticMesh;
|
||||
private bool _isStaticLod;
|
||||
private bool _castShadows = true;
|
||||
|
||||
private VehicleVisualInstance(
|
||||
VehicleAssetCache cache,
|
||||
VehicleAssetCache.VehicleTemplate template,
|
||||
Node3D root,
|
||||
Node3D modelRoot,
|
||||
string chassisId)
|
||||
{
|
||||
_cache = cache;
|
||||
_template = template;
|
||||
Root = root;
|
||||
ModelRoot = modelRoot;
|
||||
_chassisId = chassisId;
|
||||
|
||||
int w = template.Package.GridWidth;
|
||||
int h = template.Package.GridHeight;
|
||||
_cellParts = new List<CellPartBinding>[w, h];
|
||||
_strippedCells = new bool[w, h];
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
_cellParts[x, y] = new List<CellPartBinding>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Node3D Root { get; }
|
||||
public Node3D ModelRoot { get; }
|
||||
public VehicleAssetCache.VehicleTemplate Template => _template;
|
||||
public VehiclePackage Package => _template.Package;
|
||||
public string ChassisId => _chassisId;
|
||||
public string ModelId => _template.Package.Id;
|
||||
public VehicleRigAnimator.RigState RigState => _rigState;
|
||||
public IReadOnlyDictionary<string, BoundJoint> Joints => _joints;
|
||||
public int BoundHardpointCount => _hardpoints.Count;
|
||||
public bool IsStaticLod => _isStaticLod;
|
||||
|
||||
public void SetLodState(bool useStaticLod, bool castShadows)
|
||||
{
|
||||
if (_lodStaticMesh is null)
|
||||
{
|
||||
if (ModelRoot is MeshInstance3D dropMi)
|
||||
{
|
||||
if (_isStaticLod != useStaticLod)
|
||||
{
|
||||
_isStaticLod = useStaticLod;
|
||||
dropMi.Mesh = useStaticLod ? _template.BakedLodFarMesh : _template.BakedStaticMesh;
|
||||
}
|
||||
if (_castShadows != castShadows)
|
||||
{
|
||||
_castShadows = castShadows;
|
||||
dropMi.CastShadow = castShadows
|
||||
? GeometryInstance3D.ShadowCastingSetting.On
|
||||
: GeometryInstance3D.ShadowCastingSetting.Off;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_isStaticLod != useStaticLod)
|
||||
{
|
||||
_isStaticLod = useStaticLod;
|
||||
ModelRoot.Visible = !useStaticLod;
|
||||
ModelRoot.PhysicsInterpolationMode = useStaticLod
|
||||
? Node.PhysicsInterpolationModeEnum.Off
|
||||
: Node.PhysicsInterpolationModeEnum.Inherit;
|
||||
ModelRoot.ProcessMode = useStaticLod
|
||||
? Node.ProcessModeEnum.Disabled
|
||||
: Node.ProcessModeEnum.Inherit;
|
||||
_lodStaticMesh.Visible = useStaticLod;
|
||||
}
|
||||
if (_castShadows != castShadows)
|
||||
{
|
||||
_castShadows = castShadows;
|
||||
_lodStaticMesh.CastShadow = castShadows
|
||||
? GeometryInstance3D.ShadowCastingSetting.On
|
||||
: GeometryInstance3D.ShadowCastingSetting.Off;
|
||||
}
|
||||
}
|
||||
|
||||
public static VehicleVisualInstance Create(
|
||||
VehicleAssetCache cache,
|
||||
string chassisId,
|
||||
VehicleVisualRole role,
|
||||
float visualScale = 1.0f,
|
||||
float? targetHalfHeight = null)
|
||||
{
|
||||
var template = cache.GetOrLoadVehicle(chassisId);
|
||||
var pkg = template.Package;
|
||||
float halfHeight = targetHalfHeight ?? (pkg.HalfHeight * visualScale);
|
||||
float effectiveScale = targetHalfHeight.HasValue && pkg.HalfHeight > 1e-4f
|
||||
? visualScale * (targetHalfHeight.Value / pkg.HalfHeight)
|
||||
: visualScale;
|
||||
|
||||
var root = new Node3D { Name = $"Actor_{chassisId}" };
|
||||
Vector3 modelScale = new(effectiveScale, effectiveScale, effectiveScale);
|
||||
// Align glTF grounded minY=0 to physics chassis bottom (-halfHeight)
|
||||
Vector3 modelPos = new(0f, -halfHeight - template.MinY * effectiveScale, 0f);
|
||||
|
||||
if (role == VehicleVisualRole.SalvageDrop)
|
||||
{
|
||||
var dropMesh = new MeshInstance3D
|
||||
{
|
||||
Name = $"Model_{pkg.Id}",
|
||||
Mesh = template.BakedStaticMesh,
|
||||
Scale = modelScale,
|
||||
Position = modelPos
|
||||
};
|
||||
ApplyRoleTint(dropMesh, role);
|
||||
root.AddChild(dropMesh);
|
||||
return new VehicleVisualInstance(cache, template, root, dropMesh, chassisId);
|
||||
}
|
||||
|
||||
if (template.SceneTemplate.Duplicate() is not Node3D modelRoot)
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to duplicate GLB scene template for '{pkg.Id}'.");
|
||||
}
|
||||
modelRoot.Name = $"Model_{pkg.Id}";
|
||||
modelRoot.Scale = modelScale;
|
||||
modelRoot.Position = modelPos;
|
||||
root.AddChild(modelRoot);
|
||||
|
||||
var lodMesh = new MeshInstance3D
|
||||
{
|
||||
Name = $"LodStatic_{pkg.Id}",
|
||||
Mesh = template.BakedLodFarMesh,
|
||||
Scale = modelScale,
|
||||
Position = modelPos,
|
||||
Visible = false
|
||||
};
|
||||
if (role != VehicleVisualRole.Player)
|
||||
{
|
||||
ApplyRoleTint(lodMesh, role);
|
||||
}
|
||||
root.AddChild(lodMesh);
|
||||
|
||||
var instance = new VehicleVisualInstance(cache, template, root, modelRoot, chassisId)
|
||||
{
|
||||
_lodStaticMesh = lodMesh
|
||||
};
|
||||
instance.BindAll(role);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void BindAll(VehicleVisualRole role)
|
||||
{
|
||||
var pkg = _template.Package;
|
||||
|
||||
// Collect cumulative pure glTF model-space transforms (minY=0, unscaled) starting at ModelRoot = Identity
|
||||
var modelXforms = new Dictionary<Node, Transform3D>
|
||||
{
|
||||
[ModelRoot] = Transform3D.Identity
|
||||
};
|
||||
int modelChildCount = ModelRoot.GetChildCount();
|
||||
for (int i = 0; i < modelChildCount; i++)
|
||||
{
|
||||
CollectNodeTransforms(ModelRoot.GetChild(i), Transform3D.Identity, modelXforms);
|
||||
}
|
||||
|
||||
// Bind named nodes for procedural/mechanism rigs
|
||||
foreach (var (origName, relPath) in _template.NodesByOriginalName)
|
||||
{
|
||||
Node3D? node = ResolveRelative(ModelRoot, relPath);
|
||||
if (node is not null)
|
||||
{
|
||||
_namedNodes[origName] = node;
|
||||
_restLocalByName[origName] = node.Transform;
|
||||
if (modelXforms.TryGetValue(node, out var mxf))
|
||||
{
|
||||
_restModelByName[origName] = mxf;
|
||||
_restModelByNode[node] = mxf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bind all joints from rtd.joint metadata
|
||||
foreach (var (jointId, jInfo) in _template.Joints)
|
||||
{
|
||||
Node3D? jNode = ResolveRelative(ModelRoot, jInfo.RelativePath);
|
||||
if (jNode is null)
|
||||
{
|
||||
throw new InvalidOperationException($"{pkg.Id}: duplicated scene missing joint node '{jInfo.NodeName}' ({jointId}).");
|
||||
}
|
||||
|
||||
Basis parentModelBasis = Basis.Identity;
|
||||
Node? parent = jNode.GetParent();
|
||||
if (parent is not null && modelXforms.TryGetValue(parent, out var pxf))
|
||||
{
|
||||
parentModelBasis = pxf.Basis.Orthonormalized();
|
||||
}
|
||||
|
||||
Vector3 axisInParent = parentModelBasis.Inverse() * jInfo.Axis;
|
||||
axisInParent = axisInParent.LengthSquared() > 1e-6f ? axisInParent.Normalized() : Vector3.Up;
|
||||
|
||||
_joints[jointId] = new BoundJoint
|
||||
{
|
||||
JointId = jointId,
|
||||
Node = jNode,
|
||||
RestLocal = jNode.Transform,
|
||||
AxisInParent = axisInParent,
|
||||
MinRad = Mathf.DegToRad(jInfo.MinVal),
|
||||
MaxRad = Mathf.DegToRad(jInfo.MaxVal)
|
||||
};
|
||||
}
|
||||
|
||||
// Bind every ChassisSpec hardpoint to its exact exterior anchor Node3D
|
||||
ChassisSpec spec = pkg.ToChassisSpec();
|
||||
var pkgHpById = new Dictionary<string, VehicleHardpointRecord>(StringComparer.Ordinal);
|
||||
foreach (var rec in pkg.Hardpoints)
|
||||
{
|
||||
pkgHpById[rec.Id] = rec;
|
||||
}
|
||||
|
||||
for (int i = 0; i < spec.Hardpoints.Length; i++)
|
||||
{
|
||||
HardpointSpec hp = spec.Hardpoints[i];
|
||||
if (!pkgHpById.TryGetValue(hp.Id, out var rec) ||
|
||||
!_template.Anchors.TryGetValue(rec.AnchorId, out var anchorInfo))
|
||||
{
|
||||
throw new InvalidOperationException($"{pkg.Id}: missing AnchorId for hardpoint '{hp.Id}'.");
|
||||
}
|
||||
|
||||
Node3D? anchorNode = ResolveRelative(ModelRoot, anchorInfo.RelativePath);
|
||||
if (anchorNode is null)
|
||||
{
|
||||
throw new InvalidOperationException($"{pkg.Id}: duplicated scene missing anchor node '{rec.AnchorId}'.");
|
||||
}
|
||||
|
||||
_hardpoints[hp.Id] = new BoundHardpoint
|
||||
{
|
||||
Spec = hp,
|
||||
AnchorInfo = anchorInfo,
|
||||
AnchorNode = anchorNode
|
||||
};
|
||||
}
|
||||
|
||||
// Apply role palette tinting to painted hull meshes before binding per-cell damage clones
|
||||
if (role != VehicleVisualRole.Player)
|
||||
{
|
||||
ApplyRoleTint(ModelRoot, role);
|
||||
}
|
||||
|
||||
// Bind detachable exterior armor/shroud parts to their (CellX, CellY)
|
||||
int w = pkg.GridWidth;
|
||||
int h = pkg.GridHeight;
|
||||
foreach (var dp in _template.DetachableParts)
|
||||
{
|
||||
if (dp.CellX < 0 || dp.CellX >= w || dp.CellY < 0 || dp.CellY >= h)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ResolveRelative(ModelRoot, dp.RelativePath) is MeshInstance3D mi)
|
||||
{
|
||||
_cellParts[dp.CellX, dp.CellY].Add(new CellPartBinding { Node = mi });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Node3D? GetNamedNode(string name) =>
|
||||
_namedNodes.TryGetValue(name, out var n) && GodotObject.IsInstanceValid(n) ? n : null;
|
||||
|
||||
public bool TryGetRestLocal(string name, out Transform3D xform) =>
|
||||
_restLocalByName.TryGetValue(name, out xform);
|
||||
|
||||
public bool TryGetRestModel(string name, out Transform3D xform) =>
|
||||
_restModelByName.TryGetValue(name, out xform);
|
||||
|
||||
public bool TryGetRestModel(Node3D node, out Transform3D xform) =>
|
||||
_restModelByNode.TryGetValue(node, out xform);
|
||||
|
||||
public Node3D? GetHardpointAnchorNode(string hardpointId) =>
|
||||
_hardpoints.TryGetValue(hardpointId, out var bh) ? bh.AnchorNode : null;
|
||||
|
||||
public Node3D? GetMountedGearNode(string hardpointId) =>
|
||||
_hardpoints.TryGetValue(hardpointId, out var bh) && GodotObject.IsInstanceValid(bh.GearNode) ? bh.GearNode : null;
|
||||
|
||||
public int CountDetachablePartsForCell(int x, int y) =>
|
||||
x >= 0 && x < _template.Package.GridWidth && y >= 0 && y < _template.Package.GridHeight
|
||||
? _cellParts[x, y].Count
|
||||
: 0;
|
||||
|
||||
/// <summary>
|
||||
/// Synchronizes visible exterior gear GLBs on all hardpoint anchors with <paramref name="grid"/>.
|
||||
/// </summary>
|
||||
public void SyncMountedGear(ChassisGrid grid)
|
||||
{
|
||||
foreach (var bh in _hardpoints.Values)
|
||||
{
|
||||
if (_shearedHardpoints.Contains(bh.Spec.Id) || !grid.IsHardpointOperational(bh.Spec))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MountedModule? mounted = grid.GetMountedOn(bh.Spec.Id);
|
||||
string? desiredId = mounted?.Spec.Id;
|
||||
|
||||
if (string.Equals(bh.MountedModuleId, desiredId, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clear old gear visual if unmounted or swapped
|
||||
if (bh.GearNode is not null && GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
bh.GearNode.GetParent()?.RemoveChild(bh.GearNode);
|
||||
bh.GearNode.QueueFree();
|
||||
}
|
||||
bh.GearNode = null;
|
||||
bh.GearHeatMaterials.Clear();
|
||||
bh.MountedModuleId = desiredId;
|
||||
|
||||
if (mounted is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Node3D gearNode = InstantiateGearForHardpoint(mounted.Spec, bh.Spec, bh.AnchorInfo, bh.GearHeatMaterials);
|
||||
bh.AnchorNode.AddChild(gearNode);
|
||||
bh.GearNode = gearNode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches exterior armor/shroud plates when <c>Armor[x, y] <= 0.01f</c>,
|
||||
/// shears mounted gear off non-operational hardpoints, and applies scorch/heat glow.
|
||||
/// </summary>
|
||||
public void SyncDamageAndHeat(ChassisGrid grid, DebrisSystem debris, Vector3 vehicleVelocity)
|
||||
{
|
||||
int w = Math.Min(grid.Spec.Width, _template.Package.GridWidth);
|
||||
int h = Math.Min(grid.Spec.Height, _template.Package.GridHeight);
|
||||
Vector3 blastOrigin = Root.IsInsideTree() ? Root.GlobalPosition : Root.Position;
|
||||
|
||||
// 1. Part-by-cell detachment & cell scorch/heat tinting
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
if (!grid.Spec.IsActive(x, y))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float armor = grid.Armor[x, y];
|
||||
var parts = _cellParts[x, y];
|
||||
if (!_strippedCells[x, y] && armor <= 0.01f)
|
||||
{
|
||||
_strippedCells[x, y] = true;
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
var pb = parts[i];
|
||||
if (!pb.Detached && GodotObject.IsInstanceValid(pb.Node))
|
||||
{
|
||||
pb.Detached = true;
|
||||
debris.SpawnDetachedPart(pb.Node, blastOrigin, vehicleVelocity, impulseScale: 1.0f, applyScorch: true);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parts.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float maxArmor = MathF.Max(1f, grid.MaxArmor[x, y]);
|
||||
float dmgFrac = 1f - Math.Clamp(armor / maxArmor, 0f, 1f);
|
||||
float heatGlow = Math.Clamp((grid.Temperature[x, y] - 65f) / 110f, 0f, 1f);
|
||||
float tintScore = MathF.Round(dmgFrac * 20f) + MathF.Round(heatGlow * 20f) * 32f;
|
||||
|
||||
if (dmgFrac < 0.25f && heatGlow < 0.05f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
var pb = parts[i];
|
||||
if (pb.Detached || !GodotObject.IsInstanceValid(pb.Node))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (MathF.Abs(pb.LastTintScore - tintScore) < 0.5f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pb.LastTintScore = tintScore;
|
||||
ApplyCellDamageAndHeat(pb, dmgFrac, heatGlow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Hardpoint shear & mounted gear heat glow
|
||||
foreach (var bh in _hardpoints.Values)
|
||||
{
|
||||
if (!_shearedHardpoints.Contains(bh.Spec.Id) && !grid.IsHardpointOperational(bh.Spec))
|
||||
{
|
||||
_shearedHardpoints.Add(bh.Spec.Id);
|
||||
if (bh.GearNode is not null && GodotObject.IsInstanceValid(bh.GearNode))
|
||||
{
|
||||
Node3D sheared = bh.GearNode;
|
||||
bh.GearNode = null;
|
||||
bh.MountedModuleId = null;
|
||||
bh.GearHeatMaterials.Clear();
|
||||
debris.SpawnDetachedPart(sheared, blastOrigin, vehicleVelocity, impulseScale: 1.15f, applyScorch: true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bh.GearNode is null || bh.GearHeatMaterials.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MountedModule? mounted = grid.GetMountedOn(bh.Spec.Id);
|
||||
if (mounted is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float heatFrac = Math.Clamp((mounted.CurrentTemp - 65f) / 115f, 0f, 1f);
|
||||
for (int m = 0; m < bh.GearHeatMaterials.Count; m++)
|
||||
{
|
||||
StandardMaterial3D gm = bh.GearHeatMaterials[m];
|
||||
gm.EmissionEnabled = heatFrac > 0.02f;
|
||||
gm.Emission = new Color(1.0f, 0.34f, 0.08f);
|
||||
gm.EmissionEnergyMultiplier = heatFrac * 2.2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Node3D CreateStandaloneGearVisual(VehicleAssetCache cache, ModuleSpec mod)
|
||||
{
|
||||
var list = new List<StandardMaterial3D>();
|
||||
GearVisualRecipe recipe = ResolveGearRecipe(mod);
|
||||
var template = cache.GetOrLoadGear(recipe.GearGlbId);
|
||||
if (template.SceneTemplate.Duplicate() is not Node3D node)
|
||||
{
|
||||
return new Node3D { Name = $"Gear_{mod.Id}" };
|
||||
}
|
||||
node.Name = $"GearDrop_{mod.Id}";
|
||||
node.Scale = recipe.VariantScale;
|
||||
node.Position = new Vector3(0f, -template.MinY * recipe.VariantScale.Y, 0f);
|
||||
if (recipe.PaintTint.HasValue || recipe.AccentTint.HasValue)
|
||||
{
|
||||
ApplyGearVariantTint(node, recipe.PaintTint, recipe.AccentTint, list);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
private Node3D InstantiateGearForHardpoint(
|
||||
ModuleSpec mod,
|
||||
HardpointSpec hp,
|
||||
VehicleAssetCache.GlbAnchorInfo anchorInfo,
|
||||
List<StandardMaterial3D> heatMaterialsOut)
|
||||
{
|
||||
GearVisualRecipe recipe = ResolveGearRecipe(mod);
|
||||
VehicleAssetCache.GearTemplate gearTemplate = _cache.GetOrLoadGear(recipe.GearGlbId);
|
||||
if (gearTemplate.SceneTemplate.Duplicate() is not Node3D gearNode)
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to duplicate gear GLB '{recipe.GearGlbId}'.");
|
||||
}
|
||||
gearNode.Name = $"Mounted_{mod.Id}_{hp.Id}";
|
||||
|
||||
// Compute outward socket normal & desired gear forward direction in vehicle/model space
|
||||
Basis anchorModelBasis = anchorInfo.ModelSpaceTransform.Basis.Orthonormalized();
|
||||
Vector3 upOut = anchorModelBasis.Y.Normalized();
|
||||
if (upOut.LengthSquared() < 1e-6f) upOut = Vector3.Up;
|
||||
|
||||
Vector3 vehForward = new(0f, 0f, 1f);
|
||||
Vector3 desiredGearFwd;
|
||||
|
||||
if (hp.Kind == HardpointKind.Weapon)
|
||||
{
|
||||
// Special guard for forward-facing chin mounts (e.g. manticore hp.weapon.chin):
|
||||
// drop the turret base under the chin (-Y) so the barrel points straight forward (+Z) instead of up into the nose.
|
||||
if (upOut.Z > 0.72f)
|
||||
{
|
||||
upOut = upOut.Y <= 0.1f ? new Vector3(0f, -1f, 0f) : new Vector3(0f, 1f, 0f);
|
||||
desiredGearFwd = vehForward;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 proj = vehForward - upOut * vehForward.Dot(upOut);
|
||||
desiredGearFwd = proj.LengthSquared() > 1e-4f
|
||||
? proj.Normalized()
|
||||
: anchorModelBasis.Z.Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-weapon modules (radiator / engine / armor): align neatly to hull tangent plane
|
||||
if (MathF.Abs(upOut.Z) > 0.78f)
|
||||
{
|
||||
Vector3 upProj = Vector3.Up - upOut * Vector3.Up.Dot(upOut);
|
||||
desiredGearFwd = upProj.LengthSquared() > 1e-4f ? upProj.Normalized() : Vector3.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 proj = vehForward - upOut * vehForward.Dot(upOut);
|
||||
desiredGearFwd = proj.LengthSquared() > 1e-4f ? proj.Normalized() : Vector3.Up;
|
||||
}
|
||||
}
|
||||
|
||||
// Right-handed basis: Y = upOut, Z = desiredGearFwd, X = Y x Z
|
||||
Vector3 rightX = upOut.Cross(desiredGearFwd);
|
||||
if (rightX.LengthSquared() < 1e-5f)
|
||||
{
|
||||
rightX = Vector3.Right;
|
||||
}
|
||||
else
|
||||
{
|
||||
rightX = rightX.Normalized();
|
||||
}
|
||||
desiredGearFwd = rightX.Cross(upOut).Normalized();
|
||||
var desiredModelBasis = new Basis(rightX, upOut, desiredGearFwd);
|
||||
|
||||
// If the gear GLB's own forward points along -Z, rotate 180 deg around Y
|
||||
if (gearTemplate.LocalModelForward.Z < 0f)
|
||||
{
|
||||
desiredModelBasis *= new Basis(Vector3.Up, MathF.PI);
|
||||
}
|
||||
|
||||
Basis localBasis = anchorModelBasis.Inverse() * desiredModelBasis;
|
||||
|
||||
// Fit cleanly to the socket's physical rtd.size
|
||||
float sx = MathF.Max(0.25f, anchorInfo.Size.X);
|
||||
float sy = MathF.Max(0.25f, anchorInfo.Size.Y);
|
||||
Vector3 fitScale;
|
||||
if (hp.Kind == HardpointKind.Weapon)
|
||||
{
|
||||
float baseScale = Math.Clamp(MathF.Min(sx, sy) / 0.56f, 0.72f, 1.75f);
|
||||
fitScale = recipe.VariantScale * baseScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
float scaleX = Math.Clamp(sx / 0.48f, 0.72f, 2.15f);
|
||||
float scaleZ = Math.Clamp(sy / 0.45f, 0.72f, 2.15f);
|
||||
float scaleY = Math.Clamp(0.5f * (scaleX + scaleZ), 0.72f, 1.85f);
|
||||
fitScale = new Vector3(
|
||||
recipe.VariantScale.X * scaleX,
|
||||
recipe.VariantScale.Y * scaleY,
|
||||
recipe.VariantScale.Z * scaleZ);
|
||||
}
|
||||
|
||||
gearNode.Basis = localBasis * Basis.FromScale(fitScale);
|
||||
// Seat gear minY right on the anchor collar origin (with slight downward offset if chin flipped)
|
||||
float ySeat = -gearTemplate.MinY * fitScale.Y;
|
||||
gearNode.Position = (anchorModelBasis.Inverse() * upOut) * ySeat;
|
||||
|
||||
ApplyGearVariantTint(gearNode, recipe.PaintTint, recipe.AccentTint, heatMaterialsOut);
|
||||
return gearNode;
|
||||
}
|
||||
|
||||
private static GearVisualRecipe ResolveGearRecipe(ModuleSpec mod)
|
||||
{
|
||||
return mod.Id switch
|
||||
{
|
||||
"mg_762" => new("mg_762", Vector3.One, null, null),
|
||||
"autocannon" => new("autocannon", Vector3.One, null, null),
|
||||
"recoilless" => new("recoilless", Vector3.One, null, null),
|
||||
"copper_rad" => new("copper_rad", Vector3.One, null, null),
|
||||
"gilded_lance" => new("gilded_lance", Vector3.One, null, null),
|
||||
"gold_radiator" => new("gold_radiator", Vector3.One, null, null),
|
||||
|
||||
// Clean tint/scale variants from the 6 real gear GLBs
|
||||
"flak" => new("autocannon", new Vector3(1.12f, 0.92f, 0.68f), Color.FromHtml("#5a4a3f"), Color.FromHtml("#d96c27")),
|
||||
"pd_flak" => new("mg_762", new Vector3(1.22f, 1.10f, 0.85f), Color.FromHtml("#3d4440"), Color.FromHtml("#e08a4a")),
|
||||
"touring_plasma" => new("gilded_lance", new Vector3(1.05f, 0.96f, 0.72f), TouristIvory, Color.FromHtml("#38c9d8")),
|
||||
"aegis_pd" => new("gilded_lance", new Vector3(0.95f, 0.92f, 0.56f), TouristGold, Color.FromHtml("#38c9d8")),
|
||||
"diesel_core" => new("copper_rad", new Vector3(0.92f, 1.15f, 1.05f), Color.FromHtml("#363a38"), Color.FromHtml("#b35a2b")),
|
||||
"turbo_core" => new("copper_rad", new Vector3(1.12f, 1.28f, 1.38f), Color.FromHtml("#2a2f32"), Color.FromHtml("#e07024")),
|
||||
"noble_core" => new("gold_radiator", new Vector3(1.10f, 1.32f, 1.38f), TouristGold, Color.FromHtml("#38c9d8")),
|
||||
"welded_plate" => new("copper_rad", new Vector3(1.30f, 0.34f, 0.95f), Color.FromHtml("#4e5740"), Color.FromHtml("#6a6f66")),
|
||||
"gilded_plate" => new("gold_radiator", new Vector3(1.30f, 0.34f, 0.95f), TouristIvory, TouristGold),
|
||||
_ => new(mod.IsImperial ? "gilded_lance" : "mg_762", Vector3.One, null, null)
|
||||
};
|
||||
}
|
||||
|
||||
private static void ApplyGearVariantTint(
|
||||
Node cur,
|
||||
Color? paintTint,
|
||||
Color? accentTint,
|
||||
List<StandardMaterial3D> trackMaterials)
|
||||
{
|
||||
if (cur is MeshInstance3D mi && mi.Mesh is not null)
|
||||
{
|
||||
int surfCount = mi.Mesh.GetSurfaceCount();
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
Material? src = mi.GetActiveMaterial(s);
|
||||
if (src is not StandardMaterial3D sm)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var copy = (StandardMaterial3D)sm.Duplicate();
|
||||
string matName = (sm.ResourceName ?? string.Empty).ToLowerInvariant();
|
||||
if (accentTint.HasValue && (matName.Contains("copper") || matName.Contains("signal") || matName.Contains("cyan") || matName.Contains("gold")))
|
||||
{
|
||||
copy.AlbedoColor = accentTint.Value;
|
||||
}
|
||||
else if (paintTint.HasValue && (matName.Contains("olive") || matName.Contains("ivory") || matName.Contains("armor")))
|
||||
{
|
||||
copy.AlbedoColor = paintTint.Value;
|
||||
}
|
||||
|
||||
mi.SetSurfaceOverrideMaterial(s, copy);
|
||||
if (!matName.Contains("rubber") && !matName.Contains("glass"))
|
||||
{
|
||||
trackMaterials.Add(copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int count = cur.GetChildCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
ApplyGearVariantTint(cur.GetChild(i), paintTint, accentTint, trackMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyRoleTint(Node root, VehicleVisualRole role)
|
||||
{
|
||||
var (armorColor, accentColor) = role switch
|
||||
{
|
||||
VehicleVisualRole.Rival => (RivalArmorColor, RivalAccentColor),
|
||||
VehicleVisualRole.SpectatorTourist => (TouristGold, TouristIvory),
|
||||
VehicleVisualRole.SpectatorPatron => (PatronTeal, PatronBronze),
|
||||
VehicleVisualRole.SpectatorExemplar => (ExemplarObsidian, ExemplarCrimson),
|
||||
VehicleVisualRole.SalvageDrop => (SalvageSteel, SalvageCyan),
|
||||
_ => (RivalArmorColor, RivalAccentColor)
|
||||
};
|
||||
|
||||
var clonedCache = new Dictionary<StandardMaterial3D, StandardMaterial3D>();
|
||||
TintSubtreeRecursive(root, armorColor, accentColor, role, clonedCache);
|
||||
}
|
||||
|
||||
private static void TintSubtreeRecursive(
|
||||
Node cur,
|
||||
Color armorColor,
|
||||
Color accentColor,
|
||||
VehicleVisualRole role,
|
||||
Dictionary<StandardMaterial3D, StandardMaterial3D> clonedCache)
|
||||
{
|
||||
if (cur is MeshInstance3D mi && mi.Mesh is not null)
|
||||
{
|
||||
int surfCount = mi.Mesh.GetSurfaceCount();
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
if (mi.GetActiveMaterial(s) is not StandardMaterial3D sm)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string mName = (sm.ResourceName ?? string.Empty).ToLowerInvariant();
|
||||
bool isPrimaryPaint = mName.Contains("olive") || mName.Contains("khaki");
|
||||
bool isAccentPaint = mName.Contains("signal") || mName.Contains("orange");
|
||||
if (!isPrimaryPaint && !isAccentPaint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!clonedCache.TryGetValue(sm, out var copy))
|
||||
{
|
||||
copy = (StandardMaterial3D)sm.Duplicate();
|
||||
copy.AlbedoColor = isPrimaryPaint ? armorColor : accentColor;
|
||||
if (role == VehicleVisualRole.SpectatorTourist && isPrimaryPaint)
|
||||
{
|
||||
copy.Metallic = 0.72f;
|
||||
copy.Roughness = 0.30f;
|
||||
}
|
||||
else if (role == VehicleVisualRole.SpectatorExemplar && isAccentPaint)
|
||||
{
|
||||
copy.EmissionEnabled = true;
|
||||
copy.Emission = ExemplarCrimson;
|
||||
copy.EmissionEnergyMultiplier = 0.65f;
|
||||
}
|
||||
clonedCache[sm] = copy;
|
||||
}
|
||||
|
||||
mi.SetSurfaceOverrideMaterial(s, copy);
|
||||
}
|
||||
}
|
||||
|
||||
int count = cur.GetChildCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
TintSubtreeRecursive(cur.GetChild(i), armorColor, accentColor, role, clonedCache);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyCellDamageAndHeat(CellPartBinding binding, float dmgFrac, float heatGlow)
|
||||
{
|
||||
if (binding.Materials.Count == 0 && binding.Node.Mesh is not null)
|
||||
{
|
||||
int surfCount = binding.Node.Mesh.GetSurfaceCount();
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
Material? src = binding.Node.GetActiveMaterial(s);
|
||||
StandardMaterial3D copy = src is StandardMaterial3D sm
|
||||
? (StandardMaterial3D)sm.Duplicate()
|
||||
: new StandardMaterial3D { AlbedoColor = new Color(0.32f, 0.34f, 0.30f), Roughness = 0.6f, Metallic = 0.35f };
|
||||
binding.Node.SetSurfaceOverrideMaterial(s, copy);
|
||||
binding.Materials.Add((copy, copy.AlbedoColor, copy.Roughness));
|
||||
}
|
||||
}
|
||||
|
||||
float scorch = Math.Clamp((dmgFrac - 0.25f) / 0.75f, 0f, 1f) * 0.65f;
|
||||
for (int i = 0; i < binding.Materials.Count; i++)
|
||||
{
|
||||
var (mat, baseCol, baseRough) = binding.Materials[i];
|
||||
mat.AlbedoColor = new Color(
|
||||
baseCol.R * (1f - scorch) + 0.05f * scorch,
|
||||
baseCol.G * (1f - scorch) + 0.035f * scorch,
|
||||
baseCol.B * (1f - scorch) + 0.03f * scorch,
|
||||
baseCol.A);
|
||||
mat.Roughness = MathF.Min(0.95f, baseRough + scorch * 0.35f);
|
||||
mat.EmissionEnabled = heatGlow > 0.05f;
|
||||
mat.Emission = new Color(1.0f, 0.32f, 0.08f);
|
||||
mat.EmissionEnergyMultiplier = heatGlow * 1.4f;
|
||||
}
|
||||
}
|
||||
|
||||
private static Node3D? ResolveRelative(Node3D root, NodePath relPath)
|
||||
{
|
||||
if (relPath.IsEmpty)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return relPath.ToString() == "." ? root : root.GetNodeOrNull<Node3D>(relPath);
|
||||
}
|
||||
|
||||
private static void CollectNodeTransforms(Node cur, Transform3D parentXf, Dictionary<Node, Transform3D> map)
|
||||
{
|
||||
Transform3D xf = cur is Node3D n3d ? parentXf * n3d.Transform : parentXf;
|
||||
map[cur] = xf;
|
||||
int count = cur.GetChildCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
CollectNodeTransforms(cur.GetChild(i), xf, map);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the highest rendered vertex Y in <see cref="Root"/> local space across the hull
|
||||
/// and all currently mounted gear meshes.
|
||||
/// </summary>
|
||||
public float ComputeMountedMaxY()
|
||||
{
|
||||
float maxY = float.NegativeInfinity;
|
||||
AccumulateMaxYRecursive(ModelRoot, Transform3D.Identity, ref maxY, isRoot: true);
|
||||
if (!float.IsFinite(maxY))
|
||||
{
|
||||
return ModelRoot.Position.Y + _template.MaxY * ModelRoot.Scale.Y;
|
||||
}
|
||||
return maxY;
|
||||
}
|
||||
|
||||
private static void AccumulateMaxYRecursive(Node cur, Transform3D parentToRoot, ref float maxY, bool isRoot = false)
|
||||
{
|
||||
Transform3D toRoot = parentToRoot;
|
||||
if (cur is Node3D n3d)
|
||||
{
|
||||
if (!isRoot && !n3d.Visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
toRoot = parentToRoot * n3d.Transform;
|
||||
}
|
||||
|
||||
if (cur is MeshInstance3D mi && mi.Mesh is { } mesh)
|
||||
{
|
||||
int surfCount = mesh.GetSurfaceCount();
|
||||
bool foundVerts = false;
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
var arrays = mesh.SurfaceGetArrays(s);
|
||||
if (arrays.Count > (int)Mesh.ArrayType.Vertex &&
|
||||
arrays[(int)Mesh.ArrayType.Vertex].VariantType == Variant.Type.PackedVector3Array)
|
||||
{
|
||||
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
|
||||
for (int v = 0; v < verts.Length; v++)
|
||||
{
|
||||
float wy = (toRoot * verts[v]).Y;
|
||||
if (wy > maxY)
|
||||
{
|
||||
maxY = wy;
|
||||
}
|
||||
}
|
||||
foundVerts = true;
|
||||
}
|
||||
}
|
||||
if (!foundVerts)
|
||||
{
|
||||
Aabb aabb = mesh.GetAabb();
|
||||
for (int c = 0; c < 8; c++)
|
||||
{
|
||||
Vector3 corner = aabb.Position + new Vector3(
|
||||
(c & 1) != 0 ? aabb.Size.X : 0f,
|
||||
(c & 2) != 0 ? aabb.Size.Y : 0f,
|
||||
(c & 4) != 0 ? aabb.Size.Z : 0f);
|
||||
float wy = (toRoot * corner).Y;
|
||||
if (wy > maxY)
|
||||
{
|
||||
maxY = wy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int childCount = cur.GetChildCount();
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
AccumulateMaxYRecursive(cur.GetChild(i), toRoot, ref maxY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
shader_type spatial;
|
||||
render_mode blend_mix, depth_draw_never, cull_back;
|
||||
|
||||
// OpenGL 3.3 (gl_compatibility) Parallax Occlusion Mapping (POM) decal shader for MultiMeshInstance3D.
|
||||
// Renders hundreds of hard-surface vents, hatches, stencils, and live combat hits in 1 draw call.
|
||||
//
|
||||
// INSTANCE_CUSTOM layout:
|
||||
// x = tile_index (0..15 in 4x4 trim-sheet atlas)
|
||||
// y = heat_glow (0..1, incandescent glow on rolled rim & core of fresh combat hits)
|
||||
// z = opacity (0..1)
|
||||
// w = depth_scale (default ~0.06 when 0)
|
||||
//
|
||||
// Atlas textures (assets/decals/):
|
||||
// albedo_tex : RGBA albedo + alpha mask
|
||||
// normal_tex : tangent-space normal map (+X right, +Y down, +Z out)
|
||||
// ormh_tex : R=AO, G=Roughness, B=Metallic, A=Height (1.0=flush surface, 0.0=deep recess)
|
||||
|
||||
uniform sampler2D albedo_tex : source_color, filter_linear_mipmap, repeat_disable;
|
||||
uniform sampler2D normal_tex : hint_normal, filter_linear_mipmap, repeat_disable;
|
||||
uniform sampler2D ormh_tex : filter_linear_mipmap, repeat_disable;
|
||||
|
||||
uniform bool use_instance_custom = true;
|
||||
uniform float fallback_tile_index : hint_range(0.0, 15.0) = 0.0;
|
||||
uniform float fallback_heat_glow : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform float fallback_opacity : hint_range(0.0, 1.0) = 1.0;
|
||||
uniform float default_depth_scale : hint_range(0.0, 0.25) = 0.06;
|
||||
uniform float normal_offset : hint_range(0.0, 0.02) = 0.004;
|
||||
uniform float normal_depth : hint_range(0.0, 3.0) = 1.15;
|
||||
uniform float heat_emission_energy : hint_range(0.0, 10.0) = 2.6;
|
||||
|
||||
varying vec4 v_custom;
|
||||
|
||||
void vertex() {
|
||||
VERTEX += NORMAL * normal_offset;
|
||||
if (use_instance_custom) {
|
||||
v_custom = INSTANCE_CUSTOM;
|
||||
} else {
|
||||
v_custom = vec4(fallback_tile_index, fallback_heat_glow, fallback_opacity, default_depth_scale);
|
||||
}
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
const int POM_STEPS = 10;
|
||||
const float CELL_SIZE = 0.25;
|
||||
|
||||
float tile_idx = floor(clamp(v_custom.x + 0.5, 0.0, 15.0));
|
||||
float heat_glow = clamp(v_custom.y, 0.0, 1.0);
|
||||
float opacity = clamp(v_custom.z, 0.0, 1.0);
|
||||
float depth_scale = v_custom.w > 0.0001 ? v_custom.w : default_depth_scale;
|
||||
|
||||
float col_idx = mod(tile_idx, 4.0);
|
||||
float row_idx = floor(tile_idx * 0.25);
|
||||
vec2 cell_origin = vec2(col_idx, row_idx) * CELL_SIZE;
|
||||
|
||||
// Hoist screen-space derivatives above any non-uniform control flow / discard (GLSL 330 safety)
|
||||
vec2 d_uv_dx = dFdx(UV * CELL_SIZE);
|
||||
vec2 d_uv_dy = dFdy(UV * CELL_SIZE);
|
||||
|
||||
// Soft outer edge fade on local quad UV
|
||||
float edge_fade = smoothstep(0.0, 0.04, UV.x)
|
||||
* smoothstep(1.0, 0.96, UV.x)
|
||||
* smoothstep(0.0, 0.04, UV.y)
|
||||
* smoothstep(1.0, 0.96, UV.y);
|
||||
|
||||
// Tangent-space view ray (Godot fragment VIEW, TANGENT, BINORMAL, NORMAL are all in view space)
|
||||
vec3 t_dir = normalize(TANGENT);
|
||||
vec3 b_dir = normalize(BINORMAL);
|
||||
vec3 n_dir = normalize(NORMAL);
|
||||
vec3 view_ts = normalize(vec3(dot(VIEW, t_dir), dot(VIEW, b_dir), dot(VIEW, n_dir)));
|
||||
|
||||
// Clamp grazing Z so oblique rays stay well-behaved without sliding out of the tile
|
||||
float vz = max(view_ts.z, 0.22);
|
||||
vec2 p_dir = -(view_ts.xy / vz) * depth_scale;
|
||||
|
||||
// 10 linear POM steps from surface (layer_depth=0, height=1) into recess (layer_depth=1, height=0)
|
||||
float step_size = 1.0 / float(POM_STEPS);
|
||||
vec2 delta_uv = p_dir * step_size;
|
||||
|
||||
vec2 cur_uv = UV;
|
||||
float cur_layer_depth = 0.0;
|
||||
float cur_tex_depth = 1.0 - textureLod(ormh_tex, cell_origin + clamp(cur_uv, 0.002, 0.998) * CELL_SIZE, 0.0).a;
|
||||
|
||||
vec2 prev_uv = cur_uv;
|
||||
float prev_layer_depth = cur_layer_depth;
|
||||
float prev_tex_depth = cur_tex_depth;
|
||||
|
||||
for (int i = 0; i < POM_STEPS; i++) {
|
||||
if (cur_layer_depth >= cur_tex_depth) {
|
||||
break;
|
||||
}
|
||||
prev_uv = cur_uv;
|
||||
prev_layer_depth = cur_layer_depth;
|
||||
prev_tex_depth = cur_tex_depth;
|
||||
|
||||
cur_uv += delta_uv;
|
||||
cur_layer_depth += step_size;
|
||||
cur_tex_depth = 1.0 - textureLod(ormh_tex, cell_origin + clamp(cur_uv, 0.002, 0.998) * CELL_SIZE, 0.0).a;
|
||||
}
|
||||
|
||||
// 1 secant interpolation step
|
||||
float after_d = cur_tex_depth - cur_layer_depth;
|
||||
float before_d = prev_tex_depth - prev_layer_depth;
|
||||
float denom = after_d - before_d;
|
||||
float weight = abs(denom) > 1e-5 ? clamp(after_d / denom, 0.0, 1.0) : 0.0;
|
||||
vec2 final_uv = mix(cur_uv, prev_uv, weight);
|
||||
|
||||
// Discard cleanly outside tile bounds so adjacent atlas cells never bleed
|
||||
if (final_uv.x < 0.002 || final_uv.x > 0.998 || final_uv.y < 0.002 || final_uv.y > 0.998) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec2 atlas_uv = cell_origin + final_uv * CELL_SIZE;
|
||||
vec4 alb = textureGrad(albedo_tex, atlas_uv, d_uv_dx, d_uv_dy);
|
||||
vec3 nrm_sample = textureGrad(normal_tex, atlas_uv, d_uv_dx, d_uv_dy).rgb;
|
||||
vec4 ormh = textureGrad(ormh_tex, atlas_uv, d_uv_dx, d_uv_dy);
|
||||
|
||||
float out_alpha = alb.a * edge_fade * opacity;
|
||||
if (out_alpha < 0.015) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Emissive rim & molten crater mask for combat hits (Row 3: tiles 12..15)
|
||||
float is_combat = step(11.5, tile_idx);
|
||||
// Rolled metallic lip & crater wall glow hot while keeping pitch-black bore contrast
|
||||
float rim_band = smoothstep(0.94, 0.50, ormh.a) * smoothstep(0.08, 0.55, ormh.b);
|
||||
float bore_inner_ring = smoothstep(0.35, 0.10, ormh.a) * smoothstep(0.01, 0.16, ormh.a);
|
||||
float hot_mask = clamp((rim_band * 1.15 + bore_inner_ring * 0.45) * is_combat, 0.0, 1.0);
|
||||
float hot_intensity = heat_glow * hot_mask;
|
||||
vec3 hot_col = mix(vec3(0.95, 0.18, 0.02), vec3(1.0, 0.58, 0.14), smoothstep(0.25, 0.90, hot_intensity));
|
||||
|
||||
ALBEDO = alb.rgb;
|
||||
ALPHA = out_alpha;
|
||||
NORMAL_MAP = nrm_sample;
|
||||
NORMAL_MAP_DEPTH = normal_depth;
|
||||
AO = ormh.r;
|
||||
AO_LIGHT_AFFECT = 0.85;
|
||||
ROUGHNESS = clamp(ormh.g, 0.12, 0.98);
|
||||
METALLIC = clamp(ormh.b, 0.0, 1.0);
|
||||
EMISSION = hot_col * (hot_intensity * heat_emission_energy);
|
||||
}
|
||||
|
|
@ -1,251 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_premul_alpha;
|
||||
|
||||
// Port of Aetheria's UI/Inventory Grid shader to Godot 4 gl_compatibility (OpenGL 3.3).
|
||||
// Evaluates analytical corner-folded texel boxes for hull/hardpoint silhouettes, L-brackets,
|
||||
// hairline rules, and 2D Euclidean SDF thermal conduits with RoundUnion fillets.
|
||||
//
|
||||
// data_tex (3W x H, filter_nearest):
|
||||
// 3x + 0 : cell/item fill & armor tint (RGBA)
|
||||
// 3x + 1 : border/bracket/pipe accent color (RGBA)
|
||||
// 3x + 2 : R = 8-bit neighbor mismatch mask (N,E,S,W,NE,SE,SW,NW)
|
||||
// G = flags (bit0=present, bit1=item, bit2=hover, bit3=damaged/stripped, bit4=compatible, bit5=border_radiator)
|
||||
// B = 4-bit N/E/S/W thermal conductivity pipe mask
|
||||
// A = hit-pulse flash intensity (0..1)
|
||||
// temp_tex (W x H, filter_linear):
|
||||
// R = normalized temperature [20C..200C -> 0..1]
|
||||
// G = thermal plateau / overheat stress [0..0.5 optimal, 0.5..1.0 overheating]
|
||||
// B = active cell mask
|
||||
|
||||
uniform sampler2D data_tex : filter_nearest, repeat_disable;
|
||||
uniform sampler2D temp_tex : filter_linear, repeat_disable;
|
||||
|
||||
uniform vec2 grid_size = vec2(4.0, 5.0);
|
||||
uniform vec2 rect_size = vec2(180.0, 225.0);
|
||||
uniform float thermal_mode : hint_range(0.0, 1.0) = 0.0;
|
||||
|
||||
// Look parameters in Aetheria texel units
|
||||
uniform float icon_texel = 1.51515;
|
||||
uniform float bg_texel = 1.0;
|
||||
uniform float rule_inset = 1.5;
|
||||
uniform float rule_width = 1.0;
|
||||
uniform float arm_texels = 1.25;
|
||||
uniform float fill_inset = 2.6;
|
||||
uniform float softness = 1.0;
|
||||
uniform float rule_alpha = 0.34;
|
||||
uniform float bracket_alpha = 1.0;
|
||||
uniform float fill_alpha = 0.14;
|
||||
|
||||
// Thermal pipe SDF parameters (in cell fractions, edge ramp in pixels)
|
||||
uniform float blob_radius = 0.1272;
|
||||
uniform float pipe_half_width = 0.1261;
|
||||
uniform float fillet = 0.1172;
|
||||
uniform float pipe_soft = 1.212;
|
||||
|
||||
const float FAR = 1000.0;
|
||||
|
||||
float box_profile(float x, float lo, float hi, float soft) {
|
||||
if (hi < lo) {
|
||||
return 0.0;
|
||||
}
|
||||
float outside = max(max(lo - x, x - hi), 0.0);
|
||||
return clamp(1.0 - outside / soft, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float eval_layer(vec2 p, float cell_px, float texel, uint mask, bool is_item, bool is_icon, float aa_px) {
|
||||
float t = min(texel, cell_px / 8.0);
|
||||
bool left = p.x < cell_px * 0.5;
|
||||
bool top = p.y >= cell_px * 0.5;
|
||||
float max_t = max(cell_px * 0.5 / t, 4.0);
|
||||
float x = clamp((left ? p.x : cell_px - p.x) / t, 0.5, max_t);
|
||||
float y = clamp((top ? cell_px - p.y : p.y) / t, 0.5, max_t);
|
||||
|
||||
uint v_shift = top ? 0u : 2u;
|
||||
uint h_shift = left ? 3u : 1u;
|
||||
uint d_shift = top ? (left ? 7u : 4u) : (left ? 6u : 5u);
|
||||
bool v = ((mask >> v_shift) & 1u) != 0u;
|
||||
bool h = ((mask >> h_shift) & 1u) != 0u;
|
||||
bool d = ((mask >> d_shift) & 1u) != 0u;
|
||||
bool concave = !v && !h && d;
|
||||
|
||||
float soft = clamp(softness * aa_px / max(t, 0.25), 0.15, 2.0);
|
||||
float fill_lo = fill_inset + 0.5;
|
||||
float fx = h ? box_profile(x, fill_lo, FAR, soft) : 1.0;
|
||||
float fy = v ? box_profile(y, fill_lo, FAR, soft) : 1.0;
|
||||
float f = fx * fy;
|
||||
if (concave) {
|
||||
f -= box_profile(x, -FAR, fill_inset - 0.5, soft) * box_profile(y, -FAR, fill_inset - 0.5, soft);
|
||||
}
|
||||
f = clamp(f, 0.0, 1.0);
|
||||
if (!is_icon) {
|
||||
return f;
|
||||
}
|
||||
|
||||
float a = is_item ? fill_alpha * f : 0.0;
|
||||
float ri = rule_inset;
|
||||
float rlo = ri - (rule_width - 1.0) * 0.5;
|
||||
float rhi = ri + (rule_width - 1.0) * 0.5;
|
||||
float rx = box_profile(x, rlo, rhi, soft);
|
||||
float ry = box_profile(y, rlo, rhi, soft);
|
||||
float arms = arm_texels >= 1.0 ? 1.0 : 0.0;
|
||||
|
||||
if (v) {
|
||||
a += rule_alpha * ry * (h ? box_profile(x, ri, FAR, soft) : 1.0);
|
||||
}
|
||||
if (h) {
|
||||
a += rule_alpha * rx * (v ? box_profile(y, ri + 1.0, FAR, soft) : 1.0);
|
||||
}
|
||||
if (v && h) {
|
||||
a += (bracket_alpha - rule_alpha) * (ry * box_profile(x, ri, ri + arm_texels, soft) + arms * rx * box_profile(y, ri + 1.0, ri + arm_texels, soft));
|
||||
} else if (concave) {
|
||||
a += bracket_alpha * (ry * box_profile(x, ri - arm_texels, ri, soft) + arms * rx * box_profile(y, ri - arm_texels, ri - 1.0, soft));
|
||||
} else if (!v && !h) {
|
||||
// Faint cell subdivision hairline across matched internal cell boundaries
|
||||
float sub_x = box_profile(x, 0.0, 0.65, soft);
|
||||
float sub_y = box_profile(y, 0.0, 0.65, soft);
|
||||
a += 0.14 * max(sub_x, sub_y);
|
||||
}
|
||||
return clamp(a, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float round_union(float a, float b, float r) {
|
||||
vec2 u = max(vec2(r - a, r - b), vec2(0.0));
|
||||
return max(r, min(a, b)) - length(u);
|
||||
}
|
||||
|
||||
float eval_pipes(vec2 p, float cell_px, uint cond, float aa_px) {
|
||||
vec2 q = p / cell_px - 0.5;
|
||||
float d = length(q) - blob_radius;
|
||||
vec2 dirs[4];
|
||||
dirs[0] = vec2(0.0, 1.0);
|
||||
dirs[1] = vec2(1.0, 0.0);
|
||||
dirs[2] = vec2(0.0, -1.0);
|
||||
dirs[3] = vec2(-1.0, 0.0);
|
||||
|
||||
float bars[4];
|
||||
for (int b = 0; b < 4; b++) {
|
||||
float along = dot(q, dirs[b]);
|
||||
float perp = abs(dot(q, vec2(dirs[b].y, -dirs[b].x)));
|
||||
bool connected = ((cond >> uint(b)) & 1u) != 0u;
|
||||
bars[b] = !connected
|
||||
? FAR
|
||||
: (along >= 0.0 ? perp - pipe_half_width : length(vec2(perp, along)) - pipe_half_width);
|
||||
d = min(d, bars[b]);
|
||||
}
|
||||
for (int c = 0; c < 4; c++) {
|
||||
int n = (c + 1) % 4;
|
||||
if (bars[c] < FAR && bars[n] < FAR && dot(q, dirs[c] + dirs[n]) > 0.0) {
|
||||
d = min(d, round_union(bars[c], bars[n], fillet));
|
||||
}
|
||||
}
|
||||
return clamp(0.5 - d * cell_px / max(pipe_soft * aa_px, 0.25), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 thermal_ramp(float t) {
|
||||
vec3 c0 = vec3(0.11, 0.18, 0.24); // ambient cool slate
|
||||
vec3 c1 = vec3(0.24, 0.48, 0.34); // warm olive
|
||||
vec3 c2 = vec3(0.86, 0.64, 0.18); // optimal plateau amber-gold
|
||||
vec3 c3 = vec3(0.92, 0.28, 0.14); // hot crimson-orange
|
||||
vec3 c4 = vec3(1.00, 0.85, 0.58); // critical incandescent
|
||||
if (t < 0.25) return mix(c0, c1, t / 0.25);
|
||||
if (t < 0.55) return mix(c1, c2, (t - 0.25) / 0.30);
|
||||
if (t < 0.85) return mix(c2, c3, (t - 0.55) / 0.30);
|
||||
return mix(c3, c4, (t - 0.85) / 0.15);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 safe_grid = max(grid_size, vec2(1.0));
|
||||
vec2 cell_wh = rect_size / safe_grid;
|
||||
float S = min(cell_wh.x, cell_wh.y);
|
||||
vec2 grid_px = safe_grid * S;
|
||||
vec2 origin = (rect_size - grid_px) * 0.5;
|
||||
vec2 local_px = UV * rect_size - origin;
|
||||
|
||||
// Hoist derivatives and implicit-LOD texture lookup above non-uniform branches (GLSL 330 helper quads)
|
||||
float aa_px = clamp(max(fwidth(UV.x) * rect_size.x, fwidth(UV.y) * rect_size.y), 0.2, 2.0);
|
||||
vec4 temp_sample = texture(temp_tex, clamp(local_px / max(grid_px, vec2(1.0)), vec2(0.0), vec2(1.0)));
|
||||
|
||||
vec2 cellf = floor(local_px / S);
|
||||
if (cellf.x < 0.0 || cellf.y < 0.0 || cellf.x >= safe_grid.x || cellf.y >= safe_grid.y) {
|
||||
COLOR = vec4(0.0);
|
||||
} else {
|
||||
vec2 p_godot = local_px - cellf * S;
|
||||
// Flip Y inside cell to match Aetheria's y-up Layer / Pipes convention
|
||||
vec2 p = vec2(p_godot.x, S - p_godot.y);
|
||||
|
||||
float tex_w = safe_grid.x * 3.0;
|
||||
float ty = (cellf.y + 0.5) / safe_grid.y;
|
||||
vec4 cell_fill = textureLod(data_tex, vec2((cellf.x * 3.0 + 0.5) / tex_w, ty), 0.0);
|
||||
vec4 border_accent = textureLod(data_tex, vec2((cellf.x * 3.0 + 1.5) / tex_w, ty), 0.0);
|
||||
vec4 meta = textureLod(data_tex, vec2((cellf.x * 3.0 + 2.5) / tex_w, ty), 0.0);
|
||||
|
||||
uint mask = uint(round(meta.r * 255.0));
|
||||
uint flags = uint(round(meta.g * 255.0));
|
||||
uint cond = uint(round(meta.b * 255.0));
|
||||
float hit_pulse = meta.a;
|
||||
|
||||
if ((flags & 1u) == 0u) {
|
||||
COLOR = vec4(0.0);
|
||||
} else {
|
||||
bool is_item = (flags & 2u) != 0u;
|
||||
bool is_hover = (flags & 4u) != 0u;
|
||||
bool is_damaged = (flags & 8u) != 0u;
|
||||
bool is_compatible = (flags & 16u) != 0u;
|
||||
|
||||
float norm_temp = temp_sample.r;
|
||||
float plateau_stress = temp_sample.g;
|
||||
vec3 heat_col = thermal_ramp(norm_temp);
|
||||
|
||||
float a_bg = eval_layer(p, S, bg_texel, mask, false, false, aa_px) * cell_fill.a;
|
||||
float a_rules = eval_layer(p, S, icon_texel, mask, is_item, true, aa_px);
|
||||
float a_pipes = eval_pipes(p, S, cond, aa_px);
|
||||
|
||||
// Intact vs stripped (Armor == 0) interior fill
|
||||
vec3 base_rgb = mix(cell_fill.rgb, heat_col, mix(0.24, 0.84, thermal_mode));
|
||||
if (is_damaged) {
|
||||
// Diagonal fracture/exposed-core hatching at 45 deg
|
||||
float hatch_coord = (p_godot.x + p_godot.y) / max(S * 0.22, 4.0);
|
||||
float hatch_dist = abs(fract(hatch_coord) - 0.5);
|
||||
float hatch = 1.0 - smoothstep(0.10, 0.22, hatch_dist);
|
||||
base_rgb = mix(base_rgb * 0.55, vec3(0.82, 0.20, 0.14), hatch * 0.65);
|
||||
}
|
||||
|
||||
// Thermal plateau glow over hot cells
|
||||
float overheat_glow = max(plateau_stress - 0.5, 0.0) * 2.0;
|
||||
base_rgb += heat_col * (0.12 * norm_temp + 0.22 * overheat_glow);
|
||||
base_rgb = clamp(base_rgb, vec3(0.0), vec3(1.0));
|
||||
|
||||
if (is_hover) {
|
||||
base_rgb = mix(base_rgb, vec3(0.95, 0.94, 0.88), 0.16);
|
||||
}
|
||||
|
||||
// Active hit-pulse impact flash
|
||||
vec3 flash_col = vec3(1.0, 0.76, 0.38);
|
||||
base_rgb = clamp(mix(base_rgb, flash_col, hit_pulse * 0.85), vec3(0.0), vec3(1.0));
|
||||
|
||||
vec3 accent_rgb = border_accent.rgb;
|
||||
if (is_damaged) {
|
||||
accent_rgb = mix(accent_rgb, vec3(0.92, 0.26, 0.18), 0.70);
|
||||
}
|
||||
if (is_compatible) {
|
||||
float pulse = 0.72 + 0.28 * sin(TIME * 6.5);
|
||||
accent_rgb = mix(accent_rgb, vec3(0.96, 0.82, 0.30), pulse);
|
||||
a_rules = clamp(a_rules * 1.35, 0.0, 1.0);
|
||||
}
|
||||
if (is_hover) {
|
||||
accent_rgb = mix(accent_rgb, vec3(1.0), 0.35);
|
||||
a_rules = clamp(a_rules * 1.25, 0.0, 1.0);
|
||||
}
|
||||
accent_rgb = clamp(mix(accent_rgb, flash_col, hit_pulse * 0.90), vec3(0.0), vec3(1.0));
|
||||
|
||||
float icon_alpha = clamp(mix(a_rules * border_accent.a, max(a_rules * 0.26, a_pipes), thermal_mode), 0.0, 1.0);
|
||||
vec3 pipe_rgb = clamp(mix(accent_rgb, heat_col * 1.2 + vec3(0.14), 0.72), vec3(0.0), vec3(1.0));
|
||||
vec3 icon_rgb = clamp(mix(accent_rgb, pipe_rgb, thermal_mode * clamp(a_pipes * 1.2, 0.0, 1.0)), vec3(0.0), vec3(1.0));
|
||||
|
||||
float out_a = clamp(icon_alpha + a_bg * (1.0 - icon_alpha), 0.0, 1.0);
|
||||
vec3 out_rgb = min(icon_rgb * icon_alpha + base_rgb * a_bg * (1.0 - icon_alpha), vec3(out_a));
|
||||
out_rgb = max(out_rgb, vec3(0.0));
|
||||
COLOR = vec4(out_rgb, out_a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
shader_type spatial;
|
||||
render_mode cull_back, depth_draw_opaque;
|
||||
|
||||
// Real-time GLSL 330 (gl_compatibility) port of Brokkr's 6-layer MechPaint.
|
||||
// Samples 3D procedural noise in rest-pose object space (v_local_pos, v_local_nrm)
|
||||
// so weathering never swims during skeletal/joint animation or chassis motion.
|
||||
//
|
||||
// Expects baked vertex COLOR_0:
|
||||
// R = geometric cavity AO (0 = deep crevice, 1 = open exposed face)
|
||||
// G = convex dihedral edge curvature (0 = flat, 1 = sharp exposed edge)
|
||||
// B = per-island connected-component hash (0..1)
|
||||
// A = rest-pose height above ground (meters / 6.0, clamped 0..1)
|
||||
//
|
||||
// Live combat channels (via INSTANCE_CUSTOM or uniform fallback for non-MultiMesh):
|
||||
// INSTANCE_CUSTOM.x / scorch (0..1) -> char/soot darkening + matte roughness
|
||||
// INSTANCE_CUSTOM.y / heat_glow (0..1) -> incandescent orange-red emission without cloning materials
|
||||
|
||||
uniform vec4 base_color : source_color = vec4(0.306, 0.341, 0.251, 1.0);
|
||||
uniform float roughness : hint_range(0.0, 1.0) = 0.58;
|
||||
uniform float metallic : hint_range(0.0, 1.0) = 0.28;
|
||||
uniform float tone_variation : hint_range(0.0, 1.0) = 0.30;
|
||||
uniform float mottle : hint_range(0.0, 2.0) = 1.0;
|
||||
uniform float noise_scale : hint_range(0.1, 10.0) = 1.0;
|
||||
|
||||
uniform float grime : hint_range(0.0, 2.0) = 0.90;
|
||||
uniform vec4 grime_color : source_color = vec4(0.145, 0.133, 0.114, 1.0);
|
||||
|
||||
uniform float streaks : hint_range(0.0, 2.0) = 0.95;
|
||||
uniform float dust : hint_range(0.0, 2.0) = 0.55;
|
||||
uniform vec4 dust_color : source_color = vec4(0.451, 0.431, 0.388, 1.0);
|
||||
|
||||
uniform float wear : hint_range(0.0, 2.5) = 0.95;
|
||||
uniform vec4 chip_color : source_color = vec4(0.460, 0.470, 0.465, 1.0);
|
||||
uniform float chip_metallic : hint_range(0.0, 1.0) = 0.85;
|
||||
uniform float chip_roughness : hint_range(0.0, 1.0) = 0.28;
|
||||
uniform vec4 primer_color : source_color = vec4(0.345, 0.325, 0.286, 1.0);
|
||||
|
||||
uniform float mud : hint_range(0.0, 2.0) = 1.0;
|
||||
uniform float mud_top : hint_range(0.1, 5.0) = 1.45;
|
||||
uniform vec4 mud_color : source_color = vec4(0.180, 0.148, 0.118, 1.0);
|
||||
uniform float wet : hint_range(0.0, 2.0) = 0.60;
|
||||
uniform float wet_top : hint_range(0.1, 6.0) = 2.80;
|
||||
|
||||
uniform float scorch : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform float heat_glow : hint_range(0.0, 1.0) = 0.0;
|
||||
uniform float heat_emission_energy : hint_range(0.0, 8.0) = 2.6;
|
||||
|
||||
varying vec3 v_local_pos;
|
||||
varying vec3 v_local_nrm;
|
||||
varying vec4 v_color;
|
||||
varying float v_scorch;
|
||||
varying float v_heat;
|
||||
|
||||
// Safe remapping helper supporting inverted bounds (lo > hi) without GLSL smoothstep UB.
|
||||
float map_range(float v, float lo, float hi, float out_lo, float out_hi) {
|
||||
float denom = hi - lo;
|
||||
float t = abs(denom) > 1e-6 ? clamp((v - lo) / denom, 0.0, 1.0) : 0.0;
|
||||
t = t * t * (3.0 - 2.0 * t);
|
||||
return mix(out_lo, out_hi, t);
|
||||
}
|
||||
|
||||
float hash31(vec3 p) {
|
||||
p = fract(p * vec3(0.1031, 0.1030, 0.0973));
|
||||
p += dot(p, p.yxz + 33.33);
|
||||
return fract((p.x + p.y) * p.z);
|
||||
}
|
||||
|
||||
float noise3d(vec3 p) {
|
||||
vec3 i = floor(p);
|
||||
vec3 f = fract(p);
|
||||
vec3 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
|
||||
float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
|
||||
float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
|
||||
float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
|
||||
float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
|
||||
float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
|
||||
float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
|
||||
float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
|
||||
|
||||
float nx00 = mix(n000, n100, u.x);
|
||||
float nx10 = mix(n010, n110, u.x);
|
||||
float nx01 = mix(n001, n101, u.x);
|
||||
float nx11 = mix(n011, n111, u.x);
|
||||
float nxy0 = mix(nx00, nx10, u.y);
|
||||
float nxy1 = mix(nx01, nx11, u.y);
|
||||
return mix(nxy0, nxy1, u.z);
|
||||
}
|
||||
|
||||
float fbm2(vec3 p) {
|
||||
// Rotate second octave to eliminate cubic lattice grid alignment
|
||||
const mat3 rot = mat3(
|
||||
vec3(0.80, -0.48, 0.36),
|
||||
vec3(0.60, 0.64, -0.48),
|
||||
vec3(0.00, 0.60, 0.80)
|
||||
);
|
||||
float a = noise3d(p);
|
||||
float b = noise3d((rot * p) * 2.17 + vec3(17.3, 9.1, 23.7));
|
||||
float c = noise3d((rot * p) * 4.61 + vec3(5.7, 31.4, 11.2));
|
||||
return a * 0.55 + b * 0.30 + c * 0.15;
|
||||
}
|
||||
|
||||
vec3 rgb_to_hsv(vec3 c) {
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-6;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 hsv_to_rgb(vec3 c) {
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
v_local_pos = VERTEX;
|
||||
v_local_nrm = NORMAL;
|
||||
v_color = COLOR;
|
||||
v_scorch = clamp(max(INSTANCE_CUSTOM.x, scorch), 0.0, 1.0);
|
||||
v_heat = clamp(max(INSTANCE_CUSTOM.y, heat_glow), 0.0, 1.0);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec3 pos = v_local_pos * noise_scale;
|
||||
vec3 nrm = normalize(v_local_nrm);
|
||||
float up = nrm.y;
|
||||
|
||||
float occ = clamp(v_color.r, 0.0, 1.0);
|
||||
float edge = clamp(v_color.g, 0.0, 1.0);
|
||||
float island_rand = clamp(v_color.b, 0.0, 1.0);
|
||||
float height_m = clamp(v_color.a, 0.0, 1.0) * 6.0;
|
||||
|
||||
// Layer 1: Base paint + per-island tone variation + 2-octave 3D object-space mottle
|
||||
float rand2 = fract(island_rand * 7.31 + 0.37);
|
||||
vec3 hsv = rgb_to_hsv(base_color.rgb);
|
||||
hsv.x = fract(hsv.x + (rand2 - 0.5) * tone_variation * 0.14);
|
||||
hsv.y = clamp(hsv.y * (1.0 + (rand2 - 0.5) * tone_variation * 0.75), 0.0, 1.0);
|
||||
hsv.z = clamp(hsv.z * (1.0 + (island_rand * 2.0 - 1.0) * tone_variation * 0.65), 0.01, 2.0);
|
||||
vec3 col = hsv_to_rgb(hsv);
|
||||
|
||||
float blotch = fbm2(pos * 0.75);
|
||||
float speck = fbm2(pos * 26.0);
|
||||
float mid_n = fbm2(pos * 4.5);
|
||||
float shade = map_range(blotch, 0.25, 0.75, -0.14, 0.14)
|
||||
+ map_range(speck, 0.25, 0.75, -0.07, 0.07)
|
||||
+ map_range(mid_n, 0.25, 0.75, -0.09, 0.09);
|
||||
col *= clamp(1.0 + shade * mottle, 0.55, 1.35);
|
||||
|
||||
// Layer 2: Cavity grime darkening + roughness boost from (1 - AO)
|
||||
float cavity = clamp(map_range(occ, 0.90, 0.42, 0.0, 1.0) * map_range(fbm2(pos * 5.0), 0.30, 0.65, 0.45, 1.0) * grime, 0.0, 1.0);
|
||||
float film = clamp(map_range(fbm2(pos * 2.1), 0.54, 0.72, 0.0, 1.0) * 0.30 * grime, 0.0, 1.0);
|
||||
float grime_amt = max(cavity, film);
|
||||
col = mix(col, grime_color.rgb, min(grime_amt, 0.85));
|
||||
|
||||
// Layer 3: Vertical rain/oil streaks on upright surfaces boosted by cavity
|
||||
vec3 stretch = pos * vec3(13.0, 0.5, 13.0);
|
||||
float upright = map_range(abs(up), 0.80, 0.35, 0.0, 1.0);
|
||||
float under = map_range(occ, 0.96, 0.65, 0.40, 1.0);
|
||||
float broken = map_range(noise3d(pos * 1.4), 0.35, 0.55, 0.15, 1.0);
|
||||
float dark_run = clamp(map_range(fbm2(stretch), 0.52, 0.68, 0.0, 1.0) * upright * under * broken * streaks, 0.0, 1.0);
|
||||
float pale_run = clamp(map_range(fbm2(stretch + vec3(31.0, 5.0, 17.0)), 0.62, 0.76, 0.0, 1.0) * upright * 0.28 * streaks, 0.0, 1.0);
|
||||
col = mix(col, dust_color.rgb, pale_run);
|
||||
col = mix(col, grime_color.rgb, dark_run * 0.85);
|
||||
|
||||
// Layer 4: Pale dust on upward-facing normals (v_local_nrm.y)
|
||||
float dust_amt = clamp(map_range(up, 0.45, 0.95, 0.0, 1.0) * map_range(fbm2(pos * 3.0), 0.25, 0.70, 0.25, 1.0) * dust * 0.55, 0.0, 1.0);
|
||||
col = mix(col, dust_color.rgb, dust_amt);
|
||||
|
||||
// Layer 5: Metallic edge chipping + thin primer_color halo from edge_curvature * noise
|
||||
float exposed = map_range(occ, 0.42, 0.88, 0.0, 1.0);
|
||||
float edge_sharp = pow(edge, 1.85);
|
||||
float chip_n = map_range(fbm2(pos * 6.5), 0.30, 0.72, 0.0, 0.44)
|
||||
+ map_range(noise3d(pos * 46.0), 0.30, 0.70, -0.06, 0.06);
|
||||
float wear_level = chip_n + edge_sharp * exposed * wear * 0.56;
|
||||
float scuff = map_range(fbm2(pos * 4.5), 0.68, 0.72, 0.0, 1.0) * clamp(wear / 1.8, 0.0, 1.0) * 0.55;
|
||||
float chip_metal_mask = clamp(max(map_range(wear_level, 0.76, 0.80, 0.0, 1.0), scuff * 0.85), 0.0, 1.0);
|
||||
float primer_mask = clamp(max(map_range(wear_level, 0.71, 0.75, 0.0, 1.0), scuff), 0.0, 1.0);
|
||||
col = mix(col, primer_color.rgb, primer_mask * 0.75);
|
||||
col = mix(col, chip_color.rgb, chip_metal_mask);
|
||||
|
||||
// Layer 6: Lower-hull/foot mud & wet gloss driven by rest_height (COLOR.a)
|
||||
float wet_amt = clamp(map_range(height_m, wet_top, 0.0, 0.0, 1.0) * wet, 0.0, 1.0);
|
||||
col *= (1.0 - 0.50 * wet_amt);
|
||||
float mud_n = fbm2(pos * 3.2);
|
||||
float thick = map_range(height_m, mud_top, 0.0, 0.0, 1.0)
|
||||
* map_range(mud_n, 0.35, 0.62, 0.1, 1.5)
|
||||
* map_range(occ, 0.95, 0.50, 0.7, 1.6) * mud;
|
||||
float splash = map_range(fbm2(pos * 11.0), 0.62, 0.66, 0.0, 1.0)
|
||||
* map_range(height_m, mud_top * 2.2, mud_top * 0.4, 0.0, 1.0) * mud * 0.85;
|
||||
float mud_amt = clamp(max(map_range(thick, 0.20, 0.50, 0.0, 1.0), splash), 0.0, 1.0);
|
||||
col = mix(col, mud_color.rgb * map_range(mud_n, 0.30, 0.70, 0.70, 1.30), mud_amt);
|
||||
|
||||
// PBR metallic & roughness synthesis
|
||||
float out_metallic = mix(metallic, chip_metallic, chip_metal_mask);
|
||||
out_metallic *= (1.0 - mud_amt) * (1.0 - grime_amt * 0.70);
|
||||
|
||||
float out_rough = roughness + grime_amt * 0.22 + (1.0 - occ) * 0.12 * clamp(grime, 0.0, 1.0);
|
||||
out_rough = mix(out_rough, chip_roughness, chip_metal_mask);
|
||||
out_rough -= wet_amt * 0.18;
|
||||
out_rough += mud_amt * 0.18;
|
||||
out_rough = clamp(out_rough, 0.12, 0.98);
|
||||
|
||||
// Live combat channel 1: scorch (char/soot darkening + matte roughness)
|
||||
float soot_pat = mix(0.65, 1.0, fbm2(pos * 4.5));
|
||||
float scorch_mask = clamp(v_scorch * soot_pat, 0.0, 1.0);
|
||||
col = mix(col, vec3(0.022, 0.018, 0.016), scorch_mask * 0.88);
|
||||
out_metallic *= (1.0 - scorch_mask * 0.75);
|
||||
out_rough = mix(out_rough, 0.94, scorch_mask);
|
||||
|
||||
// Live combat channel 2: heat_glow (incandescent orange-red emission without cloning material)
|
||||
float heat_mod = mix(0.25, 1.15, pow(edge, 1.4) * 0.6 + fbm2(pos * 3.8) * 0.4);
|
||||
float h_val = clamp(v_heat * heat_mod, 0.0, 1.0);
|
||||
vec3 heat_col = mix(vec3(0.85, 0.12, 0.01), vec3(1.0, 0.52, 0.10), smoothstep(0.25, 0.95, h_val));
|
||||
|
||||
ALBEDO = col;
|
||||
METALLIC = clamp(out_metallic, 0.0, 1.0);
|
||||
ROUGHNESS = out_rough;
|
||||
AO = mix(1.0, occ, 0.65);
|
||||
AO_LIGHT_AFFECT = 0.65;
|
||||
EMISSION = heat_col * (pow(v_heat, 1.35) * heat_mod * heat_emission_energy);
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_premul_alpha;
|
||||
|
||||
// Resolution-independent industrial panel chrome using the same analytical corner-folded
|
||||
// Box / L-bracket + hairline border + inset fill math as inventory_grid.gdshader (1x1 cell).
|
||||
// Stays razor-sharp at 720p, 1080p, 1440p, and 4K.
|
||||
|
||||
uniform vec2 rect_size = vec2(320.0, 160.0);
|
||||
uniform float corner_len = 12.0;
|
||||
uniform float border_px = 1.5;
|
||||
uniform float fill_inset = 2.0;
|
||||
uniform float rule_inset = 1.5;
|
||||
uniform float rule_alpha = 0.55;
|
||||
uniform float bracket_alpha = 1.0;
|
||||
uniform float top_bar_px = 2.0;
|
||||
uniform float scanline_strength = 0.045;
|
||||
|
||||
uniform vec4 bg_color : source_color = vec4(0.075, 0.086, 0.075, 0.88);
|
||||
uniform vec4 border_color : source_color = vec4(0.243, 0.275, 0.220, 1.0);
|
||||
uniform vec4 accent_color : source_color = vec4(0.878, 0.541, 0.290, 1.0);
|
||||
|
||||
const float FAR = 10000.0;
|
||||
|
||||
float box_profile(float x, float lo, float hi, float soft) {
|
||||
if (hi < lo) {
|
||||
return 0.0;
|
||||
}
|
||||
float outside = max(max(lo - x, x - hi), 0.0);
|
||||
return clamp(1.0 - outside / max(soft, 0.05), 0.0, 1.0);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 size = max(rect_size, vec2(4.0));
|
||||
vec2 p = UV * size;
|
||||
float aa = clamp(max(fwidth(UV.x) * size.x, fwidth(UV.y) * size.y), 0.2, 2.0);
|
||||
|
||||
// Fold into nearest corner quadrant (1x1 cell, all 4 cardinal edges active)
|
||||
bool left = p.x < size.x * 0.5;
|
||||
bool top = p.y < size.y * 0.5;
|
||||
float x = max(left ? p.x : size.x - p.x, 0.5 * aa);
|
||||
float y = max(top ? p.y : size.y - p.y, 0.5 * aa);
|
||||
|
||||
// Inset background fill
|
||||
float fx = box_profile(x, fill_inset, FAR, aa);
|
||||
float fy = box_profile(y, fill_inset, FAR, aa);
|
||||
float fill_mask = fx * fy;
|
||||
|
||||
// Hairline border and corner L-brackets (logical thickness stays fixed in rect_size units)
|
||||
float ri = rule_inset;
|
||||
float half_w = max(border_px - 1.0, 0.0) * 0.5;
|
||||
float rlo = ri - half_w;
|
||||
float rhi = ri + half_w;
|
||||
float rx = box_profile(x, rlo, rhi, aa);
|
||||
float ry = box_profile(y, rlo, rhi, aa);
|
||||
|
||||
float rule_mask = max(ry * box_profile(x, rlo, FAR, aa), rx * box_profile(y, rlo, FAR, aa));
|
||||
float clen = min(corner_len, min(size.x, size.y) * 0.35);
|
||||
float bracket_mask = max(ry * box_profile(x, rlo, ri + clen, aa), rx * box_profile(y, rlo, ri + clen, aa));
|
||||
|
||||
// Subtle top-bar & micro-scanline accent inside the fill
|
||||
float top_bar = box_profile(p.y, fill_inset + 0.5, fill_inset + 0.5 + top_bar_px, aa) * fx;
|
||||
float scan = 1.0 - scanline_strength * (0.5 + 0.5 * sin(p.y * 2.0943951));
|
||||
|
||||
vec3 fill_rgb = mix(bg_color.rgb * scan, accent_color.rgb, top_bar * 0.24);
|
||||
float fill_a = fill_mask * bg_color.a;
|
||||
|
||||
float edge_rule = clamp(rule_mask - bracket_mask, 0.0, 1.0) * rule_alpha * border_color.a;
|
||||
float edge_bracket = bracket_mask * bracket_alpha * accent_color.a;
|
||||
|
||||
vec3 rgb = fill_rgb * fill_a;
|
||||
float alpha = fill_a;
|
||||
|
||||
rgb = border_color.rgb * edge_rule + rgb * (1.0 - edge_rule);
|
||||
alpha = edge_rule + alpha * (1.0 - edge_rule);
|
||||
|
||||
rgb = accent_color.rgb * edge_bracket + rgb * (1.0 - edge_bracket);
|
||||
alpha = edge_bracket + alpha * (1.0 - edge_bracket);
|
||||
|
||||
COLOR = vec4(rgb, clamp(alpha, 0.0, 1.0));
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Rust to Dust"
|
||||
run/main_scene="res://Main.tscn"
|
||||
config/features=PackedStringArray("4.7", "C#")
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1280
|
||||
window/size/viewport_height=720
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
[dotnet]
|
||||
|
||||
project/assembly_name="RustToDust.Client"
|
||||
|
||||
[physics]
|
||||
|
||||
; Godot's physics is switched off: Ymir is the only physics world. ArenaSession ticks at 60 Hz.
|
||||
3d/physics_engine="Dummy"
|
||||
common/physics_ticks_per_second=60
|
||||
common/physics_interpolation=true
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_add;
|
||||
|
||||
// Encodes positive height deltas into R ([-18m, +52m] => span 70m),
|
||||
// roughness delta into G, scorch/track wear into B, and ALWAYS A = 1.0
|
||||
// (required for gl_compatibility TransparentBg=false blend equations).
|
||||
uniform int brush_kind = 0;
|
||||
uniform float height_delta = 0.0;
|
||||
uniform float height_span = 70.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float pos_dh = 0.0;
|
||||
float pos_dg = 0.0;
|
||||
float d_scorch = 0.0;
|
||||
|
||||
if (brush_kind == 0) {
|
||||
// DuneRidge (positive)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
float asym = 1.0 + 0.32 * u;
|
||||
pos_dh = max(0.0, height_delta) * env * (0.35 + 0.65 * ridge) * asym;
|
||||
pos_dg = 0.02 * env;
|
||||
} else if (brush_kind == 1) {
|
||||
// Mesa
|
||||
float r = sqrt(r2);
|
||||
float t = clamp((1.0 - r) / 0.45, 0.0, 1.0);
|
||||
float plateau = t * t * (3.0 - 2.0 * t);
|
||||
pos_dh = max(0.0, height_delta) * plateau;
|
||||
} else if (brush_kind == 2) {
|
||||
// SalvagePad (positive part)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
pos_dh = max(0.0, height_delta) * env;
|
||||
pos_dg = 0.03 * env;
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater ejecta rim + slag/scorch
|
||||
float r = sqrt(r2);
|
||||
float depth = abs(height_delta);
|
||||
float rim_t = sin(3.14159265 * clamp((r - 0.55) / 0.45, 0.0, 1.0));
|
||||
pos_dh = 0.32 * depth * rim_t * rim_t;
|
||||
pos_dg = 0.04 * (1.0 - r);
|
||||
d_scorch = 0.78 * clamp(1.0 - r * 0.9, 0.0, 1.0);
|
||||
} else if (brush_kind == 5) {
|
||||
// Track wear
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
d_scorch = 0.32 * env;
|
||||
} else if (brush_kind == 6) {
|
||||
// Scorch
|
||||
float r = sqrt(r2);
|
||||
float mask = clamp(1.0 - r, 0.0, 1.0);
|
||||
mask = mask * mask;
|
||||
pos_dg = 0.02 * mask;
|
||||
d_scorch = 0.85 * mask;
|
||||
}
|
||||
|
||||
COLOR = vec4(pos_dh / height_span, pos_dg, d_scorch, 1.0);
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
||||
uniform int brush_kind = 0;
|
||||
uniform vec3 brush_albedo = vec3(0.72, 0.53, 0.33);
|
||||
uniform float height_delta = 0.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 col = brush_albedo;
|
||||
float alpha = 0.0;
|
||||
|
||||
if (brush_kind == 0) {
|
||||
// DuneRidge: windward sunlit crest vs dry wash
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
col = mix(brush_albedo * 0.90, brush_albedo * 1.12, ridge);
|
||||
alpha = env * 0.72;
|
||||
} else if (brush_kind == 1) {
|
||||
// Mesa: rust-basalt plateau + stratified skirt
|
||||
float r = sqrt(r2);
|
||||
float t = clamp((1.0 - r) / 0.45, 0.0, 1.0);
|
||||
float plateau = t * t * (3.0 - 2.0 * t);
|
||||
float cliff_band = clamp(1.0 - abs(r - 0.74) * 5.0, 0.0, 1.0);
|
||||
col = mix(brush_albedo, brush_albedo * 0.68, cliff_band);
|
||||
alpha = clamp(plateau + cliff_band * 0.5, 0.0, 0.94);
|
||||
} else if (brush_kind == 2) {
|
||||
// SalvagePad: compacted gravel & weathered concrete slab
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float border = smoothstep(0.75, 0.92, sqrt(r2));
|
||||
col = mix(brush_albedo, vec3(0.32, 0.28, 0.24), border * 0.45);
|
||||
alpha = clamp(env * 1.15, 0.0, 0.88);
|
||||
} else if (brush_kind == 3) {
|
||||
// Road: twin packed dirt ruts running longitudinally along u (cross-track offset abs(v))
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float rut = smoothstep(0.15, 0.45, abs(v)) * (1.0 - smoothstep(0.60, 0.92, abs(v)));
|
||||
col = mix(brush_albedo, brush_albedo * 0.76, rut);
|
||||
alpha = env * (0.45 + 0.35 * rut);
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater: charred pit center + bright rust ejecta rim
|
||||
float r = sqrt(r2);
|
||||
float pit = clamp(1.0 - r / 0.62, 0.0, 1.0);
|
||||
float rim = sin(3.14159265 * clamp((r - 0.55) / 0.45, 0.0, 1.0));
|
||||
vec3 ejecta = vec3(0.62, 0.38, 0.22);
|
||||
col = mix(ejecta, brush_albedo, clamp(pit * 1.3, 0.0, 1.0));
|
||||
alpha = clamp(max(pit * 0.94, rim * rim * 0.72), 0.0, 0.95);
|
||||
} else if (brush_kind == 5) {
|
||||
// Track: twin tire ruts along local X
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float treads = smoothstep(0.18, 0.45, abs(v)) * (1.0 - smoothstep(0.62, 0.92, abs(v)));
|
||||
col = brush_albedo;
|
||||
alpha = env * treads * 0.62;
|
||||
} else if (brush_kind == 6) {
|
||||
// Scorch
|
||||
float r = sqrt(r2);
|
||||
float mask = clamp(1.0 - r, 0.0, 1.0);
|
||||
col = brush_albedo;
|
||||
alpha = mask * mask * 0.88;
|
||||
}
|
||||
|
||||
COLOR = vec4(col, alpha);
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
render_mode blend_sub;
|
||||
|
||||
// Encodes negative height deltas (crater pits, dry washes, road ruts, tire ruts) into R.
|
||||
uniform int brush_kind = 0;
|
||||
uniform float height_delta = 0.0;
|
||||
uniform float height_span = 70.0;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_local = UV * 2.0 - 1.0;
|
||||
float u = uv_local.x;
|
||||
float v = uv_local.y;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float neg_dh = 0.0;
|
||||
float neg_dg = 0.0;
|
||||
if (brush_kind == 0) {
|
||||
// Dry wash (negative DuneRidge)
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
float ridge = max(0.0, 1.0 - u * u);
|
||||
float asym = 1.0 + 0.32 * u;
|
||||
neg_dh = max(0.0, -height_delta) * env * (0.35 + 0.65 * ridge) * asym;
|
||||
} else if (brush_kind == 2 || brush_kind == 3 || brush_kind == 5) {
|
||||
// SalvagePad (<0), Road, Track rut
|
||||
float env = 1.0 - r2;
|
||||
env *= env;
|
||||
neg_dh = max(0.0, -height_delta) * env;
|
||||
} else if (brush_kind == 4) {
|
||||
// Crater pit
|
||||
float r = sqrt(r2);
|
||||
float depth = abs(height_delta);
|
||||
float pit_t = clamp(1.0 - r / 0.62, 0.0, 1.0);
|
||||
neg_dh = depth * pit_t * pit_t * (3.0 - 2.0 * pit_t);
|
||||
}
|
||||
|
||||
COLOR = vec4(neg_dh / height_span, neg_dg, 0.0, 1.0);
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
shader_type spatial;
|
||||
render_mode cull_back, depth_draw_opaque;
|
||||
|
||||
uniform sampler2D height_tex : filter_linear, repeat_disable;
|
||||
uniform sampler2D albedo_tex : filter_linear, repeat_disable;
|
||||
uniform float height_min = -18.0;
|
||||
uniform float height_max = 52.0;
|
||||
uniform float tile_size = 192.0;
|
||||
uniform float inner_span = 253.0;
|
||||
uniform float tex_size = 256.0;
|
||||
uniform float gutter_offset = 1.5;
|
||||
|
||||
float decode_height(float h_norm) {
|
||||
return mix(height_min, height_max, clamp(h_norm, 0.0, 1.0));
|
||||
}
|
||||
|
||||
float hash21(vec2 p) {
|
||||
p = fract(p * vec2(123.34, 456.21));
|
||||
p += dot(p, p + 45.32);
|
||||
return fract(p.x * p.y);
|
||||
}
|
||||
|
||||
vec2 to_baked_uv(vec2 mesh_uv) {
|
||||
return (mesh_uv * inner_span + gutter_offset) / tex_size;
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
float h_norm = textureLod(height_tex, to_baked_uv(UV), 0.0).r;
|
||||
VERTEX.y += decode_height(h_norm);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 uv_baked = to_baked_uv(UV);
|
||||
float texel_step = 1.0 / tex_size;
|
||||
float world_step = tile_size / inner_span;
|
||||
|
||||
float hL = decode_height(texture(height_tex, uv_baked - vec2(texel_step, 0.0)).r);
|
||||
float hR = decode_height(texture(height_tex, uv_baked + vec2(texel_step, 0.0)).r);
|
||||
float hD = decode_height(texture(height_tex, uv_baked - vec2(0.0, texel_step)).r);
|
||||
float hU = decode_height(texture(height_tex, uv_baked + vec2(0.0, texel_step)).r);
|
||||
|
||||
vec3 world_normal = normalize(vec3(hL - hR, 2.0 * world_step, hD - hU));
|
||||
NORMAL = normalize((VIEW_MATRIX * vec4(world_normal, 0.0)).xyz);
|
||||
|
||||
vec4 mat = texture(height_tex, uv_baked);
|
||||
vec3 alb = texture(albedo_tex, uv_baked).rgb;
|
||||
|
||||
// Subtle desert sand grain so dunes read crisply under sunlight
|
||||
float grain = (hash21(floor(UV * 768.0)) - 0.5) * 0.045;
|
||||
float scorch = clamp(mat.b, 0.0, 1.0);
|
||||
alb = clamp(alb + vec3(grain), 0.0, 1.0) * (1.0 - 0.30 * scorch);
|
||||
|
||||
ALBEDO = alb;
|
||||
ROUGHNESS = clamp(mat.g, 0.25, 1.0);
|
||||
METALLIC = 0.05;
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/Smoke.cs" id="1"]
|
||||
|
||||
[node name="Smoke" type="Node"]
|
||||
script = ExtResource("1")
|
||||
|
|
@ -1,553 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace RustToDust.Client.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Live OpenGL 3.3 (gl_compatibility) visual verification probe for:
|
||||
/// - Baked COLOR_0 vertex weathering (AO, edge curvature, per-island hash, rest height)
|
||||
/// - Brokkr 6-layer MechPaint spatial shader (mech_paint.gdshader) + INSTANCE_CUSTOM scorch/heat
|
||||
/// - 4x4 POM MultiMesh decal atlas + decal_pom.gdshader in 1 draw call
|
||||
/// Captures a 1280x720 preview PNG to tools/decals/previews/visual_substrate_preview.png and %TEMP%.
|
||||
/// </summary>
|
||||
public partial class VisualProbe : Node3D
|
||||
{
|
||||
private readonly List<string> _failures = new();
|
||||
private readonly List<IDisposable> _disposables = new();
|
||||
|
||||
public override void _Ready() => _ = RunAsync();
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
foreach (var d in _disposables)
|
||||
{
|
||||
d.Dispose();
|
||||
}
|
||||
_disposables.Clear();
|
||||
}
|
||||
|
||||
private void Check(bool cond, string msg)
|
||||
{
|
||||
if (!cond)
|
||||
{
|
||||
_failures.Add(msg);
|
||||
GD.PushError("VISUAL_PROBE FAIL: " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
string repoRoot = Path.GetFullPath(Path.Combine(ProjectSettings.GlobalizePath("res://"), ".."));
|
||||
string decalsDir = Path.Combine(repoRoot, "assets", "decals");
|
||||
string previewRepoPath = Path.Combine(repoRoot, "tools", "decals", "previews", "visual_substrate_preview.png");
|
||||
string previewTempPath = Path.Combine(Path.GetTempPath(), "visual_substrate_preview.png");
|
||||
|
||||
SetupEnvironment();
|
||||
|
||||
var mechShader = GD.Load<Shader>("res://mech_paint.gdshader");
|
||||
var decalShader = GD.Load<Shader>("res://decal_pom.gdshader");
|
||||
Check(mechShader is not null, "Failed to load res://mech_paint.gdshader");
|
||||
Check(decalShader is not null, "Failed to load res://decal_pom.gdshader");
|
||||
if (mechShader is null || decalShader is null)
|
||||
{
|
||||
Finish(1);
|
||||
return;
|
||||
}
|
||||
|
||||
ImageTexture albedoTex = LoadTextureWithMips(Path.Combine(decalsDir, "decal_atlas_albedo.png"));
|
||||
ImageTexture normalTex = LoadTextureWithMips(Path.Combine(decalsDir, "decal_atlas_normal.png"));
|
||||
ImageTexture ormhTex = LoadTextureWithMips(Path.Combine(decalsDir, "decal_atlas_ormh.png"));
|
||||
|
||||
var cache = new VehicleAssetCache();
|
||||
_disposables.Add(cache);
|
||||
var paladinTpl = cache.GetOrLoadVehicle("paladin");
|
||||
var jackalTpl = cache.GetOrLoadVehicle("jackal");
|
||||
|
||||
VerifyBakedVertexColors("paladin", paladinTpl.BakedStaticMesh);
|
||||
VerifyBakedVertexColors("jackal", jackalTpl.BakedStaticMesh);
|
||||
|
||||
// Ground desert pad
|
||||
var groundMesh = new PlaneMesh { Size = new Vector2(48f, 48f) };
|
||||
var groundMat = new StandardMaterial3D
|
||||
{
|
||||
AlbedoColor = new Color(0.42f, 0.34f, 0.24f),
|
||||
Roughness = 0.94f,
|
||||
Metallic = 0.02f
|
||||
};
|
||||
AddChild(new MeshInstance3D { Name = "DesertPad", Mesh = groundMesh, MaterialOverride = groundMat });
|
||||
|
||||
// Shared MechPaint ShaderMaterial variants (zero per-hit cloning)
|
||||
var paladinArmorMat = MakeMechPaintMat(mechShader, new Color(0.306f, 0.341f, 0.251f), metallic: 0.22f, roughness: 0.58f, wear: 1.05f, grime: 0.95f, mud: 1.15f);
|
||||
var jackalArmorMat = MakeMechPaintMat(mechShader, new Color(0.388f, 0.345f, 0.255f), metallic: 0.20f, roughness: 0.56f, wear: 1.15f, grime: 0.95f, mud: 1.25f, mudTop: 0.95f);
|
||||
var gunmetalMat = MakeMechPaintMat(mechShader, new Color(0.173f, 0.188f, 0.180f), metallic: 0.78f, roughness: 0.42f, wear: 0.80f, grime: 1.10f, mud: 1.05f);
|
||||
var copperMat = MakeMechPaintMat(mechShader, new Color(0.612f, 0.353f, 0.204f), metallic: 0.86f, roughness: 0.34f, wear: 0.65f, grime: 0.90f, mud: 0.80f);
|
||||
var orangeMat = MakeMechPaintMat(mechShader, new Color(0.851f, 0.424f, 0.153f), metallic: 0.18f, roughness: 0.44f, wear: 1.10f, grime: 0.85f, mud: 0.90f);
|
||||
var markMat = MakeMechPaintMat(mechShader, new Color(0.760f, 0.730f, 0.640f), metallic: 0.10f, roughness: 0.62f, wear: 0.95f, grime: 0.80f, mud: 0.80f);
|
||||
|
||||
// Spawn Paladin (left-center, 3/4 view toward camera)
|
||||
var paladinMesh = (ArrayMesh)paladinTpl.BakedStaticMesh.Duplicate();
|
||||
ApplyMechPaintSurfaces(paladinMesh, paladinArmorMat, gunmetalMat, copperMat, orangeMat, markMat);
|
||||
var paladinXf = new Transform3D(new Basis(Vector3.Up, Mathf.DegToRad(24f)), new Vector3(-2.8f, 0f, -2.4f));
|
||||
var paladinMi = new MeshInstance3D
|
||||
{
|
||||
Name = "PaladinWeathered",
|
||||
Mesh = paladinMesh,
|
||||
Transform = paladinXf
|
||||
};
|
||||
AddChild(paladinMi);
|
||||
|
||||
// Spawn Jackal (right-midground, angled 3/4 toward camera)
|
||||
var jackalMesh = (ArrayMesh)jackalTpl.BakedStaticMesh.Duplicate();
|
||||
ApplyMechPaintSurfaces(jackalMesh, jackalArmorMat, gunmetalMat, copperMat, orangeMat, markMat);
|
||||
var jackalXf = new Transform3D(new Basis(Vector3.Up, Mathf.DegToRad(-38f)), new Vector3(3.4f, 0f, 1.2f));
|
||||
var jackalMi = new MeshInstance3D
|
||||
{
|
||||
Name = "JackalWeathered",
|
||||
Mesh = jackalMesh,
|
||||
Transform = jackalXf
|
||||
};
|
||||
AddChild(jackalMi);
|
||||
|
||||
// Foreground angled Armor Showcase Slab (MechPaint via MultiMesh showing clean vs INSTANCE_CUSTOM scorch+heat)
|
||||
var slabMesh = BuildBeveledShowcaseSlab(3.2f, 1.26f, 0.14f);
|
||||
var slabMm = new MultiMesh
|
||||
{
|
||||
TransformFormat = MultiMesh.TransformFormatEnum.Transform3D,
|
||||
UseCustomData = true,
|
||||
Mesh = slabMesh,
|
||||
InstanceCount = 2
|
||||
};
|
||||
var slabXf0 = new Transform3D(new Basis(Vector3.Up, Mathf.DegToRad(14f)) * new Basis(Vector3.Right, Mathf.DegToRad(-22f)), new Vector3(1.15f, 1.85f, 6.2f));
|
||||
var slabXf1 = new Transform3D(new Basis(Vector3.Up, Mathf.DegToRad(-18f)) * new Basis(Vector3.Right, Mathf.DegToRad(-18f)) * Basis.FromScale(new Vector3(0.45f, 0.55f, 1.0f)), new Vector3(5.35f, 0.85f, 3.8f));
|
||||
slabMm.SetInstanceTransform(0, slabXf0);
|
||||
slabMm.SetInstanceCustomData(0, new Color(0.0f, 0.0f, 0f, 0f)); // clean weathered chest-height plate
|
||||
slabMm.SetInstanceTransform(1, slabXf1);
|
||||
slabMm.SetInstanceCustomData(1, new Color(0.90f, 0.48f, 0f, 0f)); // live combat scorch + heat_glow without cloning!
|
||||
|
||||
var slabMmi = new MultiMeshInstance3D
|
||||
{
|
||||
Name = "ShowcaseArmorPlates",
|
||||
Multimesh = slabMm,
|
||||
MaterialOverride = paladinArmorMat
|
||||
};
|
||||
AddChild(slabMmi);
|
||||
|
||||
// Build 1 single MultiMeshInstance3D batch of POM decals across Paladin, Jackal, and the Showcase Slab
|
||||
var decalMat = new ShaderMaterial { Shader = decalShader };
|
||||
decalMat.SetShaderParameter("albedo_tex", albedoTex);
|
||||
decalMat.SetShaderParameter("normal_tex", normalTex);
|
||||
decalMat.SetShaderParameter("ormh_tex", ormhTex);
|
||||
decalMat.SetShaderParameter("use_instance_custom", true);
|
||||
decalMat.SetShaderParameter("default_depth_scale", 0.06f);
|
||||
decalMat.SetShaderParameter("normal_offset", 0.004f);
|
||||
|
||||
var decalPlacements = new List<(Transform3D Xform, Color Custom)>();
|
||||
|
||||
// Showcase slab POM decals (close 3/4 grazing angle so 3D depth & hot rims are unmistakable)
|
||||
AddSlabDecal(decalPlacements, slabXf0, -1.16f, 0.30f, 0.07f, 0.48f, tile: 0, heat: 0.0f, opacity: 1.0f, depth: 0.080f); // louvered vent
|
||||
AddSlabDecal(decalPlacements, slabXf0, -0.58f, 0.30f, 0.07f, 0.48f, tile: 1, heat: 0.0f, opacity: 1.0f, depth: 0.080f); // bolted hatch
|
||||
AddSlabDecal(decalPlacements, slabXf0, 0.00f, 0.30f, 0.07f, 0.48f, tile: 3, heat: 0.0f, opacity: 1.0f, depth: 0.080f); // slotted intake grille
|
||||
AddSlabDecal(decalPlacements, slabXf0, 0.58f, 0.30f, 0.07f, 0.48f, tile: 5, heat: 0.0f, opacity: 1.0f, depth: 0.070f); // welded patch
|
||||
AddSlabDecal(decalPlacements, slabXf0, 1.16f, 0.30f, 0.07f, 0.46f, tile: 8, heat: 0.0f, opacity: 0.96f, depth: 0.03f); // stencil "03"
|
||||
|
||||
AddSlabDecal(decalPlacements, slabXf0, -1.16f, -0.30f, 0.07f, 0.48f, tile: 6, heat: 0.0f, opacity: 1.0f, depth: 0.085f); // lift-lug pocket
|
||||
AddSlabDecal(decalPlacements, slabXf0, -0.58f, -0.30f, 0.07f, 0.48f, tile: 7, heat: 0.0f, opacity: 0.96f, depth: 0.04f); // hazard chevron
|
||||
AddSlabDecal(decalPlacements, slabXf0, 0.00f, -0.30f, 0.07f, 0.50f, tile: 12, heat: 0.95f, opacity: 1.0f, depth: 0.095f); // glowing AP hole
|
||||
AddSlabDecal(decalPlacements, slabXf0, 0.58f, -0.30f, 0.07f, 0.50f, tile: 13, heat: 0.75f, opacity: 1.0f, depth: 0.085f); // shrapnel gouge
|
||||
AddSlabDecal(decalPlacements, slabXf0, 1.16f, -0.30f, 0.07f, 0.50f, tile: 14, heat: 0.92f, opacity: 1.0f, depth: 0.090f); // molten plasma crater
|
||||
|
||||
// Raycast flush decals directly onto Paladin armor surfaces
|
||||
TryAddRayDecal(decalPlacements, paladinMesh, paladinXf, new Vector3(-2.6f, 8.2f, 3.0f), new Vector3(0f, -0.05f, -1f), 0.72f, tile: 0, heat: 0.0f, opacity: 1.0f, depth: 0.07f);
|
||||
TryAddRayDecal(decalPlacements, paladinMesh, paladinXf, new Vector3(-1.5f, 8.8f, 3.0f), new Vector3(-0.2f, -0.05f, -1f), 0.65f, tile: 8, heat: 0.0f, opacity: 0.95f, depth: 0.03f);
|
||||
TryAddRayDecal(decalPlacements, paladinMesh, paladinXf, new Vector3(-2.8f, 7.1f, 3.0f), new Vector3(0.05f, 0f, -1f), 0.72f, tile: 12, heat: 0.95f, opacity: 1.0f, depth: 0.09f);
|
||||
TryAddRayDecal(decalPlacements, paladinMesh, paladinXf, new Vector3(-3.6f, 7.8f, 3.0f), new Vector3(0.25f, 0f, -1f), 0.65f, tile: 10, heat: 0.0f, opacity: 0.95f, depth: 0.03f);
|
||||
|
||||
// Raycast flush decals onto Jackal armor surfaces
|
||||
TryAddRayDecal(decalPlacements, jackalMesh, jackalXf, new Vector3(3.4f, 3.0f, 1.5f), new Vector3(0f, -1f, 0.1f), 0.55f, tile: 9, heat: 0.0f, opacity: 0.95f, depth: 0.03f);
|
||||
TryAddRayDecal(decalPlacements, jackalMesh, jackalXf, new Vector3(3.1f, 2.5f, 2.1f), new Vector3(0.2f, -0.8f, -0.5f), 0.50f, tile: 14, heat: 0.85f, opacity: 1.0f, depth: 0.08f);
|
||||
|
||||
var decalQuad = new QuadMesh { Size = Vector2.One };
|
||||
var decalMm = new MultiMesh
|
||||
{
|
||||
TransformFormat = MultiMesh.TransformFormatEnum.Transform3D,
|
||||
UseCustomData = true,
|
||||
Mesh = decalQuad,
|
||||
InstanceCount = decalPlacements.Count
|
||||
};
|
||||
for (int i = 0; i < decalPlacements.Count; i++)
|
||||
{
|
||||
decalMm.SetInstanceTransform(i, decalPlacements[i].Xform);
|
||||
decalMm.SetInstanceCustomData(i, decalPlacements[i].Custom);
|
||||
}
|
||||
var decalMmi = new MultiMeshInstance3D
|
||||
{
|
||||
Name = "PomDecalsBatch",
|
||||
Multimesh = decalMm,
|
||||
MaterialOverride = decalMat,
|
||||
CastShadow = GeometryInstance3D.ShadowCastingSetting.Off
|
||||
};
|
||||
AddChild(decalMmi);
|
||||
|
||||
// Camera framing full Paladin (head to feet) + Jackal + close grazing showcase slab
|
||||
var cam = new Camera3D
|
||||
{
|
||||
Name = "ProbeCamera",
|
||||
Current = true,
|
||||
Fov = 48f,
|
||||
Near = 0.08f,
|
||||
Far = 200f
|
||||
};
|
||||
AddChild(cam);
|
||||
cam.GlobalPosition = new Vector3(2.8f, 4.3f, 13.4f);
|
||||
cam.LookAt(new Vector3(0.0f, 4.4f, 0.2f), Vector3.Up);
|
||||
|
||||
// Wait several rendered frames so OpenGL 3.3 compiles all shaders and finishes drawing
|
||||
for (int f = 0; f < 6; f++)
|
||||
{
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
}
|
||||
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Image? cap = GetViewport().GetTexture()?.GetImage();
|
||||
Check(cap is not null && cap.GetWidth() == 1280 && cap.GetHeight() == 720,
|
||||
$"Expected 1280x720 viewport capture, got {cap?.GetWidth()}x{cap?.GetHeight()}");
|
||||
if (cap is not null)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(previewRepoPath)!);
|
||||
cap.SavePng(previewRepoPath);
|
||||
cap.SavePng(previewTempPath);
|
||||
GD.Print($"VISUAL_PROBE SAVED: {previewRepoPath}");
|
||||
GD.Print($"VISUAL_PROBE SAVED: {previewTempPath}");
|
||||
}
|
||||
}
|
||||
|
||||
double drawCalls = RenderingServer.GetRenderingInfo(RenderingServer.RenderingInfo.TotalDrawCallsInFrame);
|
||||
GD.Print($"VISUAL_PROBE INFO: renderer={RenderingServer.GetVideoAdapterName()} drawCalls={drawCalls} pomDecals={decalPlacements.Count}");
|
||||
Check(_failures.Count == 0, $"Encountered {_failures.Count} failures");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check(false, ex.ToString());
|
||||
}
|
||||
|
||||
exitCode = _failures.Count == 0 ? 0 : 1;
|
||||
GD.Print(exitCode == 0 ? "VISUAL_PROBE RESULT: PASS" : $"VISUAL_PROBE RESULT: FAIL ({_failures.Count})");
|
||||
Finish(exitCode);
|
||||
}
|
||||
|
||||
private void Finish(int code)
|
||||
{
|
||||
GetTree().Quit(code);
|
||||
}
|
||||
|
||||
private void SetupEnvironment()
|
||||
{
|
||||
var sun = new DirectionalLight3D
|
||||
{
|
||||
Name = "DesertSun",
|
||||
LightColor = new Color(1.0f, 0.93f, 0.82f),
|
||||
LightEnergy = 1.85f,
|
||||
ShadowEnabled = true,
|
||||
DirectionalShadowMode = DirectionalLight3D.ShadowMode.Parallel2Splits,
|
||||
RotationDegrees = new Vector3(-38f, 36f, 0f)
|
||||
};
|
||||
AddChild(sun);
|
||||
|
||||
// Cool oblique fill light so POM recesses & metal rims catch clear specular highlights
|
||||
var fill = new DirectionalLight3D
|
||||
{
|
||||
Name = "SkyFill",
|
||||
LightColor = new Color(0.68f, 0.80f, 0.98f),
|
||||
LightEnergy = 0.55f,
|
||||
ShadowEnabled = false,
|
||||
RotationDegrees = new Vector3(-25f, -125f, 0f)
|
||||
};
|
||||
AddChild(fill);
|
||||
|
||||
var skyMat = new ProceduralSkyMaterial
|
||||
{
|
||||
SkyTopColor = new Color(0.24f, 0.34f, 0.44f),
|
||||
SkyHorizonColor = new Color(0.76f, 0.56f, 0.37f),
|
||||
GroundBottomColor = new Color(0.28f, 0.20f, 0.14f),
|
||||
GroundHorizonColor = new Color(0.68f, 0.48f, 0.32f)
|
||||
};
|
||||
var env = new Godot.Environment
|
||||
{
|
||||
BackgroundMode = Godot.Environment.BGMode.Sky,
|
||||
Sky = new Sky { SkyMaterial = skyMat },
|
||||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.65f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
}
|
||||
|
||||
private void VerifyBakedVertexColors(string name, ArrayMesh mesh)
|
||||
{
|
||||
int surfCount = mesh.GetSurfaceCount();
|
||||
bool foundColor = false;
|
||||
float minR = 1f, maxR = 0f, minG = 1f, maxG = 0f, minB = 1f, maxB = 0f, minA = 1f, maxA = 0f;
|
||||
int totalVerts = 0;
|
||||
for (int s = 0; s < surfCount; s++)
|
||||
{
|
||||
var arrays = mesh.SurfaceGetArrays(s);
|
||||
if (arrays.Count > (int)Mesh.ArrayType.Color &&
|
||||
arrays[(int)Mesh.ArrayType.Color].VariantType == Variant.Type.PackedColorArray)
|
||||
{
|
||||
Color[] cols = arrays[(int)Mesh.ArrayType.Color].AsColorArray();
|
||||
foundColor = true;
|
||||
totalVerts += cols.Length;
|
||||
foreach (Color c in cols)
|
||||
{
|
||||
if (c.R < minR) minR = c.R; if (c.R > maxR) maxR = c.R;
|
||||
if (c.G < minG) minG = c.G; if (c.G > maxG) maxG = c.G;
|
||||
if (c.B < minB) minB = c.B; if (c.B > maxB) maxB = c.B;
|
||||
if (c.A < minA) minA = c.A; if (c.A > maxA) maxA = c.A;
|
||||
}
|
||||
}
|
||||
}
|
||||
GD.Print($"COLOR_0 [{name}]: verts={totalVerts} AO=[{minR:F2},{maxR:F2}] Edge=[{minG:F2},{maxG:F2}] Island=[{minB:F2},{maxB:F2}] Height=[{minA:F2},{maxA:F2}]");
|
||||
Check(foundColor && totalVerts > 0, $"{name} missing baked COLOR_0 array");
|
||||
Check(minR < 0.35f && maxR > 0.85f, $"{name} AO range too narrow [{minR:F2},{maxR:F2}]");
|
||||
Check(maxG > 0.65f, $"{name} Edge curvature max too low ({maxG:F2})");
|
||||
Check(maxA - minA > 0.15f, $"{name} Rest height span too small [{minA:F2},{maxA:F2}]");
|
||||
}
|
||||
|
||||
private static ImageTexture LoadTextureWithMips(string path)
|
||||
{
|
||||
var img = Image.LoadFromFile(path);
|
||||
if (img is null)
|
||||
{
|
||||
throw new FileNotFoundException($"Could not load texture '{path}'", path);
|
||||
}
|
||||
img.GenerateMipmaps();
|
||||
return ImageTexture.CreateFromImage(img);
|
||||
}
|
||||
|
||||
private static ShaderMaterial MakeMechPaintMat(
|
||||
Shader shader,
|
||||
Color baseColor,
|
||||
float metallic,
|
||||
float roughness,
|
||||
float wear,
|
||||
float grime,
|
||||
float mud,
|
||||
float mudTop = 1.45f)
|
||||
{
|
||||
var mat = new ShaderMaterial { Shader = shader };
|
||||
mat.SetShaderParameter("base_color", baseColor);
|
||||
mat.SetShaderParameter("metallic", metallic);
|
||||
mat.SetShaderParameter("roughness", roughness);
|
||||
mat.SetShaderParameter("wear", wear);
|
||||
mat.SetShaderParameter("grime", grime);
|
||||
mat.SetShaderParameter("mud", mud);
|
||||
mat.SetShaderParameter("mud_top", mudTop);
|
||||
return mat;
|
||||
}
|
||||
|
||||
private static void ApplyMechPaintSurfaces(
|
||||
ArrayMesh mesh,
|
||||
ShaderMaterial armorMat,
|
||||
ShaderMaterial gunmetalMat,
|
||||
ShaderMaterial copperMat,
|
||||
ShaderMaterial orangeMat,
|
||||
ShaderMaterial markMat)
|
||||
{
|
||||
int n = mesh.GetSurfaceCount();
|
||||
for (int s = 0; s < n; s++)
|
||||
{
|
||||
Material? orig = mesh.SurfaceGetMaterial(s);
|
||||
string mName = (orig?.ResourceName ?? string.Empty).ToLowerInvariant();
|
||||
if (mName.Contains("glass") || mName.Contains("lamp") || mName.Contains("glow") || mName.Contains("cyan"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mName.Contains("copper"))
|
||||
{
|
||||
mesh.SurfaceSetMaterial(s, copperMat);
|
||||
}
|
||||
else if (mName.Contains("signal") || mName.Contains("orange"))
|
||||
{
|
||||
mesh.SurfaceSetMaterial(s, orangeMat);
|
||||
}
|
||||
else if (mName.Contains("mark") || mName.Contains("stencil"))
|
||||
{
|
||||
mesh.SurfaceSetMaterial(s, markMat);
|
||||
}
|
||||
else if (mName.Contains("gunmetal") || mName.Contains("metal") || mName.Contains("steel") || mName.Contains("socket") || mName.Contains("pit") || mName.Contains("rubber"))
|
||||
{
|
||||
mesh.SurfaceSetMaterial(s, gunmetalMat);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.SurfaceSetMaterial(s, armorMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayMesh BuildBeveledShowcaseSlab(float w, float h, float d)
|
||||
{
|
||||
// Build a subdivided box with baked COLOR_0 (flat faces G=0, sharp edges G=1, AO=0.9, island=0.42)
|
||||
float hw = w * 0.5f, hh = h * 0.5f, hd = d * 0.5f;
|
||||
var st = new SurfaceTool();
|
||||
st.Begin(Mesh.PrimitiveType.Triangles);
|
||||
|
||||
void AddQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 dPt, Vector3 nrm, float edgeA, float edgeB, float edgeC, float edgeD)
|
||||
{
|
||||
void V(Vector3 p, Vector2 uv, float edge)
|
||||
{
|
||||
float restH = Math.Clamp((p.Y + 4.2f) / 6.0f, 0f, 1f);
|
||||
st.SetColor(new Color(0.92f, edge, 0.42f, restH));
|
||||
st.SetNormal(nrm);
|
||||
st.SetUV(uv);
|
||||
st.AddVertex(p);
|
||||
}
|
||||
// Clockwise front-face winding for Godot Spatial cull_back
|
||||
V(a, new Vector2(0, 1), edgeA);
|
||||
V(c, new Vector2(1, 0), edgeC);
|
||||
V(b, new Vector2(1, 1), edgeB);
|
||||
V(a, new Vector2(0, 1), edgeA);
|
||||
V(dPt, new Vector2(0, 0), edgeD);
|
||||
V(c, new Vector2(1, 0), edgeC);
|
||||
}
|
||||
|
||||
// Front (+Z) subdivided 3x1 so center interior vertices have edge=0 and outer corners have edge=0.95
|
||||
float x0 = -hw, x1 = -hw * 0.72f, x2 = hw * 0.72f, x3 = hw;
|
||||
float y0 = -hh, y1 = -hh * 0.65f, y2 = hh * 0.65f, y3 = hh;
|
||||
float[] xs = { x0, x1, x2, x3 };
|
||||
float[] ys = { y0, y1, y2, y3 };
|
||||
float[,] edges = {
|
||||
{ 0.95f, 0.85f, 0.85f, 0.95f },
|
||||
{ 0.85f, 0.00f, 0.00f, 0.85f },
|
||||
{ 0.85f, 0.00f, 0.00f, 0.85f },
|
||||
{ 0.95f, 0.85f, 0.85f, 0.95f },
|
||||
};
|
||||
for (int iy = 0; iy < 3; iy++)
|
||||
{
|
||||
for (int ix = 0; ix < 3; ix++)
|
||||
{
|
||||
AddQuad(
|
||||
new Vector3(xs[ix], ys[iy], hd),
|
||||
new Vector3(xs[ix + 1], ys[iy], hd),
|
||||
new Vector3(xs[ix + 1], ys[iy + 1], hd),
|
||||
new Vector3(xs[ix], ys[iy + 1], hd),
|
||||
Vector3.Back,
|
||||
edges[iy, ix], edges[iy, ix + 1], edges[iy + 1, ix + 1], edges[iy + 1, ix]);
|
||||
}
|
||||
}
|
||||
// Back & sides
|
||||
AddQuad(new Vector3(hw, -hh, -hd), new Vector3(-hw, -hh, -hd), new Vector3(-hw, hh, -hd), new Vector3(hw, hh, -hd), Vector3.Forward, 0.9f, 0.9f, 0.9f, 0.9f);
|
||||
AddQuad(new Vector3(-hw, hh, hd), new Vector3(hw, hh, hd), new Vector3(hw, hh, -hd), new Vector3(-hw, hh, -hd), Vector3.Up, 0.95f, 0.95f, 0.95f, 0.95f);
|
||||
AddQuad(new Vector3(-hw, -hh, -hd), new Vector3(hw, -hh, -hd), new Vector3(hw, -hh, hd), new Vector3(-hw, -hh, hd), Vector3.Down, 0.95f, 0.95f, 0.95f, 0.95f);
|
||||
AddQuad(new Vector3(-hw, -hh, -hd), new Vector3(-hw, -hh, hd), new Vector3(-hw, hh, hd), new Vector3(-hw, hh, -hd), Vector3.Left, 0.95f, 0.95f, 0.95f, 0.95f);
|
||||
AddQuad(new Vector3(hw, -hh, hd), new Vector3(hw, -hh, -hd), new Vector3(hw, hh, -hd), new Vector3(hw, hh, hd), Vector3.Right, 0.95f, 0.95f, 0.95f, 0.95f);
|
||||
st.GenerateTangents();
|
||||
return st.Commit();
|
||||
}
|
||||
|
||||
private static void AddSlabDecal(
|
||||
List<(Transform3D, Color)> list,
|
||||
Transform3D slabXf,
|
||||
float lx,
|
||||
float ly,
|
||||
float lz,
|
||||
float size,
|
||||
int tile,
|
||||
float heat,
|
||||
float opacity,
|
||||
float depth)
|
||||
{
|
||||
var localXf = new Transform3D(Basis.FromScale(new Vector3(size, size, 1f)), new Vector3(lx, ly, lz));
|
||||
list.Add((slabXf * localXf, new Color(tile, heat, opacity, depth)));
|
||||
}
|
||||
|
||||
private static void TryAddRayDecal(
|
||||
List<(Transform3D, Color)> list,
|
||||
ArrayMesh mesh,
|
||||
Transform3D meshXf,
|
||||
Vector3 worldOrigin,
|
||||
Vector3 worldDir,
|
||||
float size,
|
||||
int tile,
|
||||
float heat,
|
||||
float opacity,
|
||||
float depth)
|
||||
{
|
||||
Transform3D inv = meshXf.AffineInverse();
|
||||
Vector3 localOrigin = inv * worldOrigin;
|
||||
Vector3 localDir = (inv.Basis * worldDir).Normalized();
|
||||
|
||||
float bestT = float.PositiveInfinity;
|
||||
Vector3 bestN = Vector3.Back;
|
||||
|
||||
for (int s = 0; s < mesh.GetSurfaceCount(); s++)
|
||||
{
|
||||
var arr = mesh.SurfaceGetArrays(s);
|
||||
if (arr.Count <= (int)Mesh.ArrayType.Vertex) continue;
|
||||
Vector3[] verts = arr[(int)Mesh.ArrayType.Vertex].AsVector3Array();
|
||||
int[]? indices = arr.Count > (int)Mesh.ArrayType.Index && arr[(int)Mesh.ArrayType.Index].VariantType == Variant.Type.PackedInt32Array
|
||||
? arr[(int)Mesh.ArrayType.Index].AsInt32Array()
|
||||
: null;
|
||||
int triCount = (indices is not null ? indices.Length : verts.Length) / 3;
|
||||
for (int t = 0; t < triCount; t++)
|
||||
{
|
||||
int i0 = indices is not null ? indices[t * 3] : t * 3;
|
||||
int i1 = indices is not null ? indices[t * 3 + 1] : t * 3 + 1;
|
||||
int i2 = indices is not null ? indices[t * 3 + 2] : t * 3 + 2;
|
||||
Vector3 v0 = verts[i0], v1 = verts[i1], v2 = verts[i2];
|
||||
if (RayTriangle(localOrigin, localDir, v0, v1, v2, out float hitT))
|
||||
{
|
||||
if (hitT < bestT)
|
||||
{
|
||||
Vector3 fn = (v1 - v0).Cross(v2 - v0);
|
||||
if (fn.LengthSquared() > 1e-10f)
|
||||
{
|
||||
fn = fn.Normalized();
|
||||
if (fn.Dot(-localDir) < 0f) fn = -fn;
|
||||
bestT = hitT;
|
||||
bestN = fn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!float.IsFinite(bestT))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 worldHit = meshXf * (localOrigin + localDir * bestT);
|
||||
Vector3 worldN = (meshXf.Basis.Inverse().Transposed() * bestN).Normalized();
|
||||
Vector3 upRef = MathF.Abs(worldN.Y) > 0.92f ? Vector3.Forward : Vector3.Up;
|
||||
Vector3 right = upRef.Cross(worldN).Normalized();
|
||||
Vector3 up = worldN.Cross(right).Normalized();
|
||||
var basis = new Basis(right * size, up * size, worldN);
|
||||
list.Add((new Transform3D(basis, worldHit), new Color(tile, heat, opacity, depth)));
|
||||
}
|
||||
|
||||
private static bool RayTriangle(Vector3 orig, Vector3 dir, Vector3 v0, Vector3 v1, Vector3 v2, out float t)
|
||||
{
|
||||
t = 0f;
|
||||
Vector3 e1 = v1 - v0;
|
||||
Vector3 e2 = v2 - v0;
|
||||
Vector3 pvec = dir.Cross(e2);
|
||||
float det = e1.Dot(pvec);
|
||||
if (MathF.Abs(det) < 1e-7f) return false;
|
||||
float invDet = 1f / det;
|
||||
Vector3 tvec = orig - v0;
|
||||
float u = tvec.Dot(pvec) * invDet;
|
||||
if (u < 0f || u > 1f) return false;
|
||||
Vector3 qvec = tvec.Cross(e1);
|
||||
float v = dir.Dot(qvec) * invDet;
|
||||
if (v < 0f || u + v > 1f) return false;
|
||||
t = e2.Dot(qvec) * invDet;
|
||||
return t > 0.01f;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/VisualProbe.cs" id="1"]
|
||||
|
||||
[node name="VisualProbe" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public enum BroadcastKind
|
||||
{
|
||||
MatchStart,
|
||||
TouristPull,
|
||||
ExemplarWakeup,
|
||||
PatronClearance,
|
||||
ChassisSwap,
|
||||
QuickBolt,
|
||||
Overheat,
|
||||
Elimination,
|
||||
Victory
|
||||
}
|
||||
|
||||
public readonly record struct BroadcastLine(float Timestamp, BroadcastKind Kind, string Text);
|
||||
|
||||
public sealed class BroadcastFeed
|
||||
{
|
||||
private const int MaxLines = 32;
|
||||
private readonly List<BroadcastLine> _lines = new();
|
||||
|
||||
public IReadOnlyList<BroadcastLine> Lines => _lines;
|
||||
public BroadcastLine? Latest => _lines.Count > 0 ? _lines[_lines.Count - 1] : null;
|
||||
public long Version { get; private set; }
|
||||
|
||||
public void Emit(float timestamp, BroadcastKind kind, string text)
|
||||
{
|
||||
if (_lines.Count >= MaxLines)
|
||||
{
|
||||
_lines.RemoveAt(0);
|
||||
}
|
||||
_lines.Add(new BroadcastLine(timestamp, kind, text));
|
||||
Version++;
|
||||
}
|
||||
|
||||
public void EmitMatchStart(float timestamp) =>
|
||||
Emit(timestamp, BroadcastKind.MatchStart,
|
||||
"Imperial Broadcast opens the desert ring. Twelve unvarnished rigs enter for the gallery's amusement.");
|
||||
|
||||
public void EmitTouristPull(float timestamp, int contenderId) =>
|
||||
Emit(timestamp, BroadcastKind.TouristPull,
|
||||
$"Contender {contenderId + 1:00} fires on a gilded tourist — crude, lucrative, and deeply impolite.");
|
||||
|
||||
public void EmitExemplarWakeup(float timestamp, int contenderId) =>
|
||||
Emit(timestamp, BroadcastKind.ExemplarWakeup,
|
||||
$"An ornate exemplar accepts the provocation of Contender {contenderId + 1:00}. The gallery hushes.");
|
||||
|
||||
public void EmitPatronClearance(float timestamp, int contenderId) =>
|
||||
Emit(timestamp, BroadcastKind.PatronClearance,
|
||||
$"Contender {contenderId + 1:00} breaches the perimeter line; ring patrons take clearance to correct their posture.");
|
||||
|
||||
public void EmitChassisSwap(float timestamp, int contenderId, string chassisName) =>
|
||||
Emit(timestamp, BroadcastKind.ChassisSwap,
|
||||
$"Contender {contenderId + 1:00} sheds a ruin and mounts a {chassisName}. Vulgar improvisation, yet watchable.");
|
||||
|
||||
public void EmitQuickBolt(float timestamp, int contenderId, string moduleName, string hardpointId) =>
|
||||
Emit(timestamp, BroadcastKind.QuickBolt,
|
||||
$"Contender {contenderId + 1:00} quick-bolts {moduleName} onto {hardpointId} mid-run. Crude fieldcraft, live fire ready.");
|
||||
|
||||
public void EmitOverheat(float timestamp, int contenderId) =>
|
||||
Emit(timestamp, BroadcastKind.Overheat,
|
||||
$"Contender {contenderId + 1:00} glows past the thermal plateau — the crowd admires the smoke.");
|
||||
|
||||
public void EmitElimination(float timestamp, string killerLabel, string victimLabel, bool bySpectator)
|
||||
{
|
||||
string line = bySpectator
|
||||
? $"{killerLabel} restores boundary decorum over {victimLabel}. Order keeps its shine."
|
||||
: $"{killerLabel} performs a decisive eviction on {victimLabel}. The gallery notes the sincerity.";
|
||||
Emit(timestamp, BroadcastKind.Elimination, line);
|
||||
}
|
||||
|
||||
public void EmitVictory(float timestamp, int winnerId) =>
|
||||
Emit(timestamp, BroadcastKind.Victory,
|
||||
$"Contender {winnerId + 1:00} outlasts the dust and the gallery's patience. Broadcast closes with reluctant applause.");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,494 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public static class Catalog
|
||||
{
|
||||
private static readonly Dictionary<string, VehiclePackage> _packagesById;
|
||||
private static readonly Dictionary<string, ChassisSpec> _chassisById;
|
||||
private static readonly IReadOnlyList<ChassisSpec> _allChassis;
|
||||
|
||||
static Catalog()
|
||||
{
|
||||
var loaded = VehicleCatalogLoader.LoadAll();
|
||||
_packagesById = new Dictionary<string, VehiclePackage>(StringComparer.OrdinalIgnoreCase);
|
||||
_chassisById = new Dictionary<string, ChassisSpec>(StringComparer.OrdinalIgnoreCase);
|
||||
var list = new List<ChassisSpec>(loaded.Count);
|
||||
|
||||
foreach (var (pkg, spec) in loaded)
|
||||
{
|
||||
_packagesById[pkg.Id] = pkg;
|
||||
_chassisById[spec.Id] = spec;
|
||||
list.Add(spec);
|
||||
}
|
||||
|
||||
_allChassis = list.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ChassisSpec RequireChassis(string id) =>
|
||||
_chassisById.TryGetValue(id, out var spec)
|
||||
? spec
|
||||
: throw new KeyNotFoundException($"Missing chassis '{id}' in loaded vehicle.cc catalog.");
|
||||
|
||||
// ---------------- CHASSIS (15 BROKKR PACKAGES LOADED FROM .CC) ----------------
|
||||
|
||||
public static ChassisSpec Jackal => RequireChassis("jackal");
|
||||
public static ChassisSpec Mule => RequireChassis("mule");
|
||||
public static ChassisSpec Ferret => RequireChassis("ferret");
|
||||
public static ChassisSpec Hornet => RequireChassis("hornet");
|
||||
public static ChassisSpec Mammoth => RequireChassis("mammoth");
|
||||
public static ChassisSpec Ironclad => RequireChassis("ironclad");
|
||||
public static ChassisSpec Anvil => RequireChassis("anvil");
|
||||
public static ChassisSpec Condor => RequireChassis("condor");
|
||||
public static ChassisSpec Breaker => RequireChassis("breaker");
|
||||
public static ChassisSpec Paladin => RequireChassis("paladin");
|
||||
public static ChassisSpec Raptor => RequireChassis("raptor");
|
||||
public static ChassisSpec Manticore => RequireChassis("manticore");
|
||||
public static ChassisSpec Bastion => RequireChassis("bastion");
|
||||
public static ChassisSpec Spectre => RequireChassis("spectre");
|
||||
public static ChassisSpec Kestrel => RequireChassis("kestrel");
|
||||
|
||||
// Backward-compatible aliases for legacy Cut 1/2 call sites
|
||||
public static ChassisSpec Buggy => Jackal;
|
||||
public static ChassisSpec Technical => Mule;
|
||||
public static ChassisSpec Tank => Anvil;
|
||||
|
||||
public static IReadOnlyList<ChassisSpec> AllChassis => _allChassis;
|
||||
public static IReadOnlyDictionary<string, ChassisSpec> ChassisById => _chassisById;
|
||||
public static IReadOnlyDictionary<string, VehiclePackage> PackagesById => _packagesById;
|
||||
|
||||
public static VehiclePackage? TryGetPackage(string id) =>
|
||||
_packagesById.TryGetValue(id, out var pkg) ? pkg : null;
|
||||
|
||||
// ---------------- HUMAN SALVAGE MODULES (9) ----------------
|
||||
|
||||
public static readonly ModuleSpec Mg762 = new(
|
||||
Id: "mg_762",
|
||||
Name: "7.62 Machine Gun",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 5f,
|
||||
Conductivity: 9f,
|
||||
OptimalTemp: 65f,
|
||||
PlateauWidth: 70f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 155f,
|
||||
HeatOutput: 34f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 12f,
|
||||
WeaponRange: 165f,
|
||||
FireCooldown: 0.22f,
|
||||
ProjectileSpeed: 220f,
|
||||
SpreadRad: 0.035f,
|
||||
BurstCount: 1);
|
||||
|
||||
public static readonly ModuleSpec Autocannon = new(
|
||||
Id: "autocannon",
|
||||
Name: "Twin 20mm Autocannon",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 2,
|
||||
IsImperial: false,
|
||||
ThermalMass: 10f,
|
||||
Conductivity: 10f,
|
||||
OptimalTemp: 75f,
|
||||
PlateauWidth: 70f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 170f,
|
||||
HeatOutput: 75f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 22f,
|
||||
WeaponRange: 210f,
|
||||
FireCooldown: 0.34f,
|
||||
ProjectileSpeed: 250f,
|
||||
SpreadRad: 0.025f,
|
||||
BurstCount: 2);
|
||||
|
||||
public static readonly ModuleSpec Flak = new(
|
||||
Id: "flak",
|
||||
Name: "Scrap Flak Scattergun",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 6f,
|
||||
Conductivity: 8f,
|
||||
OptimalTemp: 65f,
|
||||
PlateauWidth: 70f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 165f,
|
||||
HeatOutput: 90f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 8.5f,
|
||||
WeaponRange: 105f,
|
||||
FireCooldown: 0.65f,
|
||||
ProjectileSpeed: 185f,
|
||||
SpreadRad: 0.14f,
|
||||
BurstCount: 5);
|
||||
|
||||
public static readonly ModuleSpec PointDefenseFlak = new(
|
||||
Id: "pd_flak",
|
||||
Name: "Flak Point-Defense",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 6f,
|
||||
Conductivity: 10f,
|
||||
OptimalTemp: 65f,
|
||||
PlateauWidth: 80f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 165f,
|
||||
HeatOutput: 24f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 11f,
|
||||
WeaponRange: 175f,
|
||||
FireCooldown: 0.24f,
|
||||
ProjectileSpeed: 340f,
|
||||
SpreadRad: 0.045f,
|
||||
BurstCount: 3,
|
||||
IsWideArc: true,
|
||||
MinPitchDeg: -10f,
|
||||
MaxPitchDeg: 85f);
|
||||
|
||||
public static readonly ModuleSpec Recoilless = new(
|
||||
Id: "recoilless",
|
||||
Name: "105mm Recoilless Rifle",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 2,
|
||||
Height: 2,
|
||||
IsImperial: false,
|
||||
ThermalMass: 18f,
|
||||
Conductivity: 11f,
|
||||
OptimalTemp: 75f,
|
||||
PlateauWidth: 80f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 185f,
|
||||
HeatOutput: 190f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 85f,
|
||||
WeaponRange: 265f,
|
||||
FireCooldown: 1.45f,
|
||||
ProjectileSpeed: 280f,
|
||||
SpreadRad: 0.01f,
|
||||
BurstCount: 1);
|
||||
|
||||
public static readonly ModuleSpec DieselCore = new(
|
||||
Id: "diesel_core",
|
||||
Name: "Salvaged Diesel Core",
|
||||
Kind: HardpointKind.Engine,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 9f,
|
||||
Conductivity: 9f,
|
||||
OptimalTemp: 60f,
|
||||
PlateauWidth: 80f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 150f,
|
||||
HeatOutput: 45f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 4500f,
|
||||
TurnBonus: 0.4f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly ModuleSpec TurboCore = new(
|
||||
Id: "turbo_core",
|
||||
Name: "Supercharged V8",
|
||||
Kind: HardpointKind.Engine,
|
||||
Width: 1,
|
||||
Height: 2,
|
||||
IsImperial: false,
|
||||
ThermalMass: 14f,
|
||||
Conductivity: 10f,
|
||||
OptimalTemp: 75f,
|
||||
PlateauWidth: 70f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 170f,
|
||||
HeatOutput: 85f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 12500f,
|
||||
TurnBonus: 0.9f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly ModuleSpec CopperRad = new(
|
||||
Id: "copper_rad",
|
||||
Name: "Copper Fin Radiator",
|
||||
Kind: HardpointKind.Radiator,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 6f,
|
||||
Conductivity: 15f,
|
||||
OptimalTemp: 85f,
|
||||
PlateauWidth: 90f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 210f,
|
||||
HeatOutput: 0f,
|
||||
CoolingPower: 120f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly ModuleSpec WeldedPlate = new(
|
||||
Id: "welded_plate",
|
||||
Name: "Welded Scrap Plate",
|
||||
Kind: HardpointKind.Armor,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: false,
|
||||
ThermalMass: 12f,
|
||||
Conductivity: 6f,
|
||||
OptimalTemp: 60f,
|
||||
PlateauWidth: 120f,
|
||||
MinTemp: -20f,
|
||||
MaxTemp: 240f,
|
||||
HeatOutput: 0f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 45f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
// ---------------- IMPERIAL TOURIST HIGH-END MODULES (6) ----------------
|
||||
|
||||
public static readonly ModuleSpec GildedLance = new(
|
||||
Id: "gilded_lance",
|
||||
Name: "Gilded Thermal Lance",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 2,
|
||||
IsImperial: true,
|
||||
ThermalMass: 11f,
|
||||
Conductivity: 14f,
|
||||
OptimalTemp: 90f,
|
||||
PlateauWidth: 80f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 210f,
|
||||
HeatOutput: 95f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 54f,
|
||||
WeaponRange: 285f,
|
||||
FireCooldown: 0.55f,
|
||||
ProjectileSpeed: 400f,
|
||||
SpreadRad: 0.004f,
|
||||
BurstCount: 1);
|
||||
|
||||
public static readonly ModuleSpec TouringPlasma = new(
|
||||
Id: "touring_plasma",
|
||||
Name: "Touring Plasma Repeater",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: true,
|
||||
ThermalMass: 8f,
|
||||
Conductivity: 14f,
|
||||
OptimalTemp: 95f,
|
||||
PlateauWidth: 80f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 205f,
|
||||
HeatOutput: 68f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 26f,
|
||||
WeaponRange: 210f,
|
||||
FireCooldown: 0.18f,
|
||||
ProjectileSpeed: 310f,
|
||||
SpreadRad: 0.02f,
|
||||
BurstCount: 1);
|
||||
|
||||
public static readonly ModuleSpec ImperialAegisPd = new(
|
||||
Id: "aegis_pd",
|
||||
Name: "Aegis Imperial PD",
|
||||
Kind: HardpointKind.Weapon,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: true,
|
||||
ThermalMass: 8f,
|
||||
Conductivity: 16f,
|
||||
OptimalTemp: 90f,
|
||||
PlateauWidth: 90f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 215f,
|
||||
HeatOutput: 26f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 16f,
|
||||
WeaponRange: 215f,
|
||||
FireCooldown: 0.16f,
|
||||
ProjectileSpeed: 420f,
|
||||
SpreadRad: 0.015f,
|
||||
BurstCount: 2,
|
||||
IsWideArc: true,
|
||||
MinPitchDeg: -10f,
|
||||
MaxPitchDeg: 85f);
|
||||
|
||||
public static readonly ModuleSpec GoldRadiator = new(
|
||||
Id: "gold_radiator",
|
||||
Name: "Gold-Leaf Phase Radiator",
|
||||
Kind: HardpointKind.Radiator,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: true,
|
||||
ThermalMass: 7f,
|
||||
Conductivity: 24f,
|
||||
OptimalTemp: 100f,
|
||||
PlateauWidth: 110f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 260f,
|
||||
HeatOutput: 0f,
|
||||
CoolingPower: 290f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly ModuleSpec NobleCore = new(
|
||||
Id: "noble_core",
|
||||
Name: "Overclocked Noble Core",
|
||||
Kind: HardpointKind.Engine,
|
||||
Width: 1,
|
||||
Height: 2,
|
||||
IsImperial: true,
|
||||
ThermalMass: 15f,
|
||||
Conductivity: 16f,
|
||||
OptimalTemp: 105f,
|
||||
PlateauWidth: 90f,
|
||||
MinTemp: 0f,
|
||||
MaxTemp: 225f,
|
||||
HeatOutput: 110f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 19500f,
|
||||
TurnBonus: 1.45f,
|
||||
ArmorBonus: 0f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly ModuleSpec GildedPlate = new(
|
||||
Id: "gilded_plate",
|
||||
Name: "Gilded Ceramic Plate",
|
||||
Kind: HardpointKind.Armor,
|
||||
Width: 1,
|
||||
Height: 1,
|
||||
IsImperial: true,
|
||||
ThermalMass: 16f,
|
||||
Conductivity: 4f,
|
||||
OptimalTemp: 80f,
|
||||
PlateauWidth: 140f,
|
||||
MinTemp: -20f,
|
||||
MaxTemp: 280f,
|
||||
HeatOutput: 0f,
|
||||
CoolingPower: 0f,
|
||||
ThrustBonus: 0f,
|
||||
TurnBonus: 0f,
|
||||
ArmorBonus: 85f,
|
||||
WeaponDamage: 0f,
|
||||
WeaponRange: 0f,
|
||||
FireCooldown: 0f,
|
||||
ProjectileSpeed: 0f,
|
||||
SpreadRad: 0f,
|
||||
BurstCount: 0);
|
||||
|
||||
public static readonly IReadOnlyList<ModuleSpec> HumanModules = new[]
|
||||
{
|
||||
Mg762, Autocannon, Flak, PointDefenseFlak, Recoilless, DieselCore, TurboCore, CopperRad, WeldedPlate
|
||||
};
|
||||
|
||||
public static readonly IReadOnlyList<ModuleSpec> ImperialModules = new[]
|
||||
{
|
||||
GildedLance, TouringPlasma, ImperialAegisPd, GoldRadiator, NobleCore, GildedPlate
|
||||
};
|
||||
|
||||
public static readonly IReadOnlyList<ModuleSpec> AllModules = new[]
|
||||
{
|
||||
Mg762, Autocannon, Flak, PointDefenseFlak, Recoilless, DieselCore, TurboCore, CopperRad, WeldedPlate,
|
||||
GildedLance, TouringPlasma, ImperialAegisPd, GoldRadiator, NobleCore, GildedPlate
|
||||
};
|
||||
|
||||
public static readonly IReadOnlyDictionary<string, ModuleSpec> ModulesById =
|
||||
AllModules.ToDictionary(m => m.Id, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static ChassisGrid CreateStarterBuggy()
|
||||
{
|
||||
var grid = new ChassisGrid(Jackal);
|
||||
grid.TryMount(Mg762, "hp.weapon.roof");
|
||||
grid.TryMount(DieselCore, "hp.engine.rear");
|
||||
grid.TryMount(CopperRad, "hp.radiator.rear");
|
||||
return grid;
|
||||
}
|
||||
|
||||
public static ChassisGrid CreateWithDefaultLoadout(ChassisSpec spec)
|
||||
{
|
||||
var grid = new ChassisGrid(spec);
|
||||
if (_packagesById.TryGetValue(spec.Id, out var pkg))
|
||||
{
|
||||
foreach (var kvp in pkg.DefaultLoadout)
|
||||
{
|
||||
if (ModulesById.TryGetValue(kvp.Value, out var mod))
|
||||
{
|
||||
grid.TryMount(mod, kvp.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,532 +0,0 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public delegate bool LineOfSightCheck(float ax, float ay, float az, float bx, float by, float bz);
|
||||
|
||||
public static class MatchRules
|
||||
{
|
||||
public const float VtolMinClearanceAgl = 2.5f;
|
||||
|
||||
public static float GetObserverEyeY(float y, float halfHeight) => y + halfHeight * 1.4f;
|
||||
public static float GetTargetAimY(float y, float halfHeight) => y + halfHeight * 0.35f;
|
||||
|
||||
public static (float MinPitchDeg, float MaxPitchDeg) GetEffectivePitchArc(HardpointSpec hp, ModuleSpec? mod)
|
||||
{
|
||||
if (mod is not null && mod.IsWideArc)
|
||||
{
|
||||
return (MathF.Min(hp.MinPitchDeg, mod.MinPitchDeg), MathF.Max(hp.MaxPitchDeg, mod.MaxPitchDeg));
|
||||
}
|
||||
if (hp.IsWideArc)
|
||||
{
|
||||
return (MathF.Min(hp.MinPitchDeg, -10f), MathF.Max(hp.MaxPitchDeg, 85f));
|
||||
}
|
||||
return (hp.MinPitchDeg, hp.MaxPitchDeg);
|
||||
}
|
||||
|
||||
public static float ComputeLocalPitchDeg(Vector3 aimDelta, Quaternion chassisQuat)
|
||||
{
|
||||
Vector3 local = Vector3.Transform(aimDelta, Quaternion.Conjugate(chassisQuat));
|
||||
float horiz = MathF.Sqrt(local.X * local.X + local.Z * local.Z);
|
||||
return MathF.Atan2(local.Y, horiz) * (180f / MathF.PI);
|
||||
}
|
||||
|
||||
public static float NormalizeAngle(float rad)
|
||||
{
|
||||
if (!float.IsFinite(rad))
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
rad = MathF.IEEERemainder(rad, MathF.Tau);
|
||||
if (rad > MathF.PI) rad -= MathF.Tau;
|
||||
if (rad < -MathF.PI) rad += MathF.Tau;
|
||||
return rad;
|
||||
}
|
||||
|
||||
public static void ApplyPlayerInput(MatchState state, PlayerInput input)
|
||||
{
|
||||
var player = state.Player;
|
||||
if (!player.Alive)
|
||||
{
|
||||
player.ThrottleCmd = 0f;
|
||||
player.SteerCmd = 0f;
|
||||
player.VerticalThrottleCmd = 0f;
|
||||
player.FireCmd = false;
|
||||
player.BrakeCmd = true;
|
||||
return;
|
||||
}
|
||||
|
||||
player.ThrottleCmd = Math.Clamp(input.Throttle, -1f, 1f);
|
||||
player.SteerCmd = Math.Clamp(input.Steer, -1f, 1f);
|
||||
player.VerticalThrottleCmd = Math.Clamp(input.VerticalThrottle, -1f, 1f);
|
||||
player.AimX = input.AimWorldX;
|
||||
player.AimY = input.AimWorldY;
|
||||
player.AimZ = input.AimWorldZ;
|
||||
player.FireCmd = input.Fire;
|
||||
player.BrakeCmd = input.Brake;
|
||||
|
||||
if (input.InteractPickup)
|
||||
{
|
||||
state.TryInteractNearestDrop(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateAiContenders(MatchState state, float dt, LineOfSightCheck? hasLos = null, int tickIndex = -1)
|
||||
{
|
||||
float safeLimit = MathF.Max(30f, state.Spectators.SafeRadius - 25f);
|
||||
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var ai = state.Contenders[i];
|
||||
if (ai.IsPlayer || !ai.Alive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ai.AiScavengeCooldown = MathF.Max(0f, ai.AiScavengeCooldown - dt);
|
||||
AutoEquipAiCargo(state, ai);
|
||||
|
||||
float distFromCenter = MathF.Sqrt(ai.X * ai.X + ai.Z * ai.Z);
|
||||
float goalX = 0f;
|
||||
float goalZ = 0f;
|
||||
bool hasGoal = false;
|
||||
bool wantFire = false;
|
||||
float aimX = ai.X + MathF.Sin(ai.Yaw) * 25f;
|
||||
float aimZ = ai.Z + MathF.Cos(ai.Yaw) * 25f;
|
||||
|
||||
// 1. Stay inside the shrinking Safe Circle
|
||||
if (distFromCenter > safeLimit)
|
||||
{
|
||||
goalX = 0f;
|
||||
goalZ = 0f;
|
||||
hasGoal = true;
|
||||
}
|
||||
|
||||
// 2. Find nearest hostile contender with actual line-of-sight (staggered every 3 ticks when tickIndex >= 0)
|
||||
ContenderState? target = null;
|
||||
float bestEnemyDistSq = 215f * 215f;
|
||||
bool refreshLos = tickIndex < 0 || ((ai.Id + tickIndex) % 3 == 0);
|
||||
if (refreshLos)
|
||||
{
|
||||
float aiEyeY = GetObserverEyeY(ai.Y, ai.Grid.Spec.HalfHeight);
|
||||
for (int j = 0; j < state.Contenders.Count; j++)
|
||||
{
|
||||
var other = state.Contenders[j];
|
||||
if (other.Id == ai.Id || !other.Alive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = other.X - ai.X;
|
||||
float dz = other.Z - ai.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 >= bestEnemyDistSq)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasLos is not null &&
|
||||
!hasLos(ai.X, aiEyeY, ai.Z, other.X, GetTargetAimY(other.Y, other.Grid.Spec.HalfHeight), other.Z))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bestEnemyDistSq = d2;
|
||||
target = other;
|
||||
}
|
||||
ai.AiTargetContenderId = target?.Id;
|
||||
}
|
||||
else if (ai.AiTargetContenderId is { } tid && tid >= 0 && tid < state.Contenders.Count)
|
||||
{
|
||||
var cached = state.Contenders[tid];
|
||||
if (cached.Alive && cached.Id != ai.Id)
|
||||
{
|
||||
float dx = cached.X - ai.X;
|
||||
float dz = cached.Z - ai.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < bestEnemyDistSq)
|
||||
{
|
||||
bestEnemyDistSq = d2;
|
||||
target = cached;
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AiTargetContenderId = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AiTargetContenderId = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Scavenge nearby upgrades when safe
|
||||
if (!hasGoal && ai.AiScavengeCooldown <= 0f)
|
||||
{
|
||||
GroundDrop? bestDrop = null;
|
||||
float bestDropDistSq = 85f * 85f;
|
||||
for (int d = 0; d < state.GroundDrops.Count; d++)
|
||||
{
|
||||
var drop = state.GroundDrops[d];
|
||||
if (drop.PickedUp)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (drop.Chassis is not null && drop.Chassis.MassKg <= ai.Grid.Spec.MassKg)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = drop.X - ai.X;
|
||||
float dz = drop.Z - ai.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < bestDropDistSq)
|
||||
{
|
||||
bestDropDistSq = d2;
|
||||
bestDrop = drop;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestDrop is not null)
|
||||
{
|
||||
goalX = bestDrop.X;
|
||||
goalZ = bestDrop.Z;
|
||||
hasGoal = true;
|
||||
|
||||
if (bestDropDistSq <= MatchState.PickupRadius * MatchState.PickupRadius)
|
||||
{
|
||||
if (bestDrop.Module is not null)
|
||||
{
|
||||
state.TryPickupNearbyModule(ai.Id);
|
||||
}
|
||||
else if (bestDrop.Chassis is not null)
|
||||
{
|
||||
state.TrySwapNearbyChassis(ai.Id);
|
||||
}
|
||||
ai.AiScavengeCooldown = 2.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Combat or third-party gunfire investigation
|
||||
if (target is not null)
|
||||
{
|
||||
aimX = target.X;
|
||||
aimZ = target.Z;
|
||||
float dist = MathF.Sqrt(bestEnemyDistSq);
|
||||
wantFire = dist <= 165f;
|
||||
|
||||
if (!hasGoal)
|
||||
{
|
||||
if (dist > 75f)
|
||||
{
|
||||
goalX = target.X;
|
||||
goalZ = target.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Orbit target instead of ramming headlong
|
||||
float tangentAngle = MathF.Atan2(ai.Z - target.Z, ai.X - target.X) + 0.7f;
|
||||
goalX = target.X + MathF.Cos(tangentAngle) * 52f;
|
||||
goalZ = target.Z + MathF.Sin(tangentAngle) * 52f;
|
||||
}
|
||||
hasGoal = true;
|
||||
}
|
||||
}
|
||||
else if (!hasGoal && state.LastGunfireX.HasValue && state.LastGunfireZ.HasValue &&
|
||||
state.Time - state.LastGunfireTime < 12f)
|
||||
{
|
||||
float gdx = state.LastGunfireX.Value - ai.X;
|
||||
float gdz = state.LastGunfireZ.Value - ai.Z;
|
||||
if (gdx * gdx + gdz * gdz <= 340f * 340f)
|
||||
{
|
||||
goalX = state.LastGunfireX.Value;
|
||||
goalZ = state.LastGunfireZ.Value;
|
||||
hasGoal = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasGoal)
|
||||
{
|
||||
float patrolAngle = ai.Id * 0.9f + state.Time * 0.12f;
|
||||
float r = MathF.Min(safeLimit * 0.65f, 190f);
|
||||
goalX = MathF.Cos(patrolAngle) * r;
|
||||
goalZ = MathF.Sin(patrolAngle) * r;
|
||||
}
|
||||
|
||||
float toGoalX = goalX - ai.X;
|
||||
float toGoalZ = goalZ - ai.Z;
|
||||
float desiredYaw = MathF.Atan2(toGoalX, toGoalZ);
|
||||
float yawError = NormalizeAngle(desiredYaw - ai.Yaw);
|
||||
|
||||
ai.SteerCmd = Math.Clamp(yawError * 1.8f, -1f, 1f);
|
||||
ai.ThrottleCmd = MathF.Abs(yawError) > 1.25f ? 0.35f : 0.85f;
|
||||
ai.BrakeCmd = false;
|
||||
if (ai.Grid.Spec.IsVtol)
|
||||
{
|
||||
float groundH = state.Terrain.SampleHeight(ai.X, ai.Z);
|
||||
float currentAgl = ai.Y - ai.Grid.Spec.HalfHeight - groundH;
|
||||
float desiredAgl = target is null
|
||||
? MathF.Min(ai.Grid.Spec.HoverMaxAltitudeM * 0.6f, 22f)
|
||||
: MathF.Min(ai.Grid.Spec.HoverMaxAltitudeM * 0.45f, 14f + 4f * MathF.Sin(state.Time * 0.9f + ai.Id));
|
||||
ai.VerticalThrottleCmd = Math.Clamp((desiredAgl - currentAgl) * 0.25f, -1f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.VerticalThrottleCmd = 0f;
|
||||
}
|
||||
ai.AimX = aimX;
|
||||
ai.AimY = target is not null ? GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight) : float.NaN;
|
||||
ai.AimZ = aimZ;
|
||||
ai.FireCmd = wantFire;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ComputeSpectatorBehavior(
|
||||
SpectatorState spec,
|
||||
MatchState state,
|
||||
out float goalX,
|
||||
out float goalZ,
|
||||
out float aimX,
|
||||
out float aimZ,
|
||||
out bool shouldFire)
|
||||
{
|
||||
if (spec.Stance == SpectatorStance.Neutral || !spec.TargetContenderId.HasValue)
|
||||
{
|
||||
(goalX, goalZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes);
|
||||
aimX = 0f;
|
||||
aimZ = 0f;
|
||||
shouldFire = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ContenderState? target = null;
|
||||
int targetId = spec.TargetContenderId.Value;
|
||||
if (targetId >= 0 && targetId < state.Contenders.Count)
|
||||
{
|
||||
target = state.Contenders[targetId];
|
||||
}
|
||||
|
||||
if (target is null || !target.Alive)
|
||||
{
|
||||
(goalX, goalZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes);
|
||||
aimX = 0f;
|
||||
aimZ = 0f;
|
||||
shouldFire = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Occluded behind terrain/cover: never shoot through rock! Never fall back to live target.X/Z while occluded.
|
||||
if (!spec.HasTargetLos)
|
||||
{
|
||||
shouldFire = false;
|
||||
bool hasMemory = spec.TimeSinceLastSeen < SpectatorRing.TargetMemoryDuration;
|
||||
float focusX = spec.LastKnownTargetX;
|
||||
float focusZ = spec.LastKnownTargetZ;
|
||||
aimX = focusX;
|
||||
aimZ = focusZ;
|
||||
|
||||
if (!hasMemory)
|
||||
{
|
||||
var (anchorX, anchorZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes);
|
||||
float toFocusX = focusX - spec.X;
|
||||
float toFocusZ = focusZ - spec.Z;
|
||||
float toFocusLen = MathF.Sqrt(toFocusX * toFocusX + toFocusZ * toFocusZ);
|
||||
bool hasValidFocus = (focusX != 0f || focusZ != 0f) && toFocusLen > 12f && toFocusLen < 240f;
|
||||
float centerX = hasValidFocus ? focusX : anchorX;
|
||||
float centerZ = hasValidFocus ? focusZ : anchorZ;
|
||||
|
||||
float bestX = centerX;
|
||||
float bestZ = centerZ;
|
||||
float bestH = state.Terrain.SampleHeight(bestX, bestZ);
|
||||
float maxBound = TerrainField.HalfExtent - 18f;
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
float ang = spec.Id * 0.7f + k * (MathF.PI * 0.5f);
|
||||
float cx = Math.Clamp(centerX + MathF.Cos(ang) * 26f, -maxBound, maxBound);
|
||||
float cz = Math.Clamp(centerZ + MathF.Sin(ang) * 26f, -maxBound, maxBound);
|
||||
float h = state.Terrain.SampleHeight(cx, cz);
|
||||
if (h > bestH)
|
||||
{
|
||||
bestH = h;
|
||||
bestX = cx;
|
||||
bestZ = cz;
|
||||
}
|
||||
}
|
||||
|
||||
goalX = bestX;
|
||||
goalZ = bestZ;
|
||||
return;
|
||||
}
|
||||
|
||||
float fdx = focusX - spec.X;
|
||||
float fdz = focusZ - spec.Z;
|
||||
float fLen = MathF.Sqrt(fdx * fdx + fdz * fdz);
|
||||
if (fLen < 1f)
|
||||
{
|
||||
(goalX, goalZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes);
|
||||
return;
|
||||
}
|
||||
|
||||
float dirX = fdx / fLen;
|
||||
float dirZ = fdz / fLen;
|
||||
float perpX = -dirZ;
|
||||
float perpZ = dirX;
|
||||
float sideSign = (spec.Id & 1) == 0 ? 1f : -1f;
|
||||
|
||||
// Evaluate flanking steps (left flank, right flank, crest-climb toward last-known position)
|
||||
float step = MathF.Min(42f, fLen * 0.65f);
|
||||
float cand1X = spec.X + (dirX * 0.65f + perpX * 0.76f * sideSign) * step;
|
||||
float cand1Z = spec.Z + (dirZ * 0.65f + perpZ * 0.76f * sideSign) * step;
|
||||
float cand2X = spec.X + (dirX * 0.65f - perpX * 0.76f * sideSign) * step;
|
||||
float cand2Z = spec.Z + (dirZ * 0.65f - perpZ * 0.76f * sideSign) * step;
|
||||
|
||||
float h1 = state.Terrain.SampleHeight(cand1X, cand1Z);
|
||||
float h2 = state.Terrain.SampleHeight(cand2X, cand2Z);
|
||||
|
||||
// Prefer the flanking shoulder that gets higher ground (sightline over ridge) unless it is a steep cliff
|
||||
if (h1 >= h2)
|
||||
{
|
||||
goalX = cand1X;
|
||||
goalZ = cand1Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
goalX = cand2X;
|
||||
goalZ = cand2Z;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
aimX = target.X;
|
||||
aimZ = target.Z;
|
||||
|
||||
float dx = target.X - spec.X;
|
||||
float dz = target.Z - spec.Z;
|
||||
float dist = MathF.Sqrt(dx * dx + dz * dz);
|
||||
|
||||
if (dist > spec.PreferredRange)
|
||||
{
|
||||
goalX = target.X;
|
||||
goalZ = target.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
float angle = MathF.Atan2(spec.Z - target.Z, spec.X - target.X) + (spec.Tier == SpectatorTier.Exemplar ? 0.9f : 0.4f);
|
||||
goalX = target.X + MathF.Cos(angle) * (spec.PreferredRange * 0.85f);
|
||||
goalZ = target.Z + MathF.Sin(angle) * (spec.PreferredRange * 0.85f);
|
||||
}
|
||||
|
||||
shouldFire = dist <= 255f;
|
||||
|
||||
// Tourists self-throttle when their Imperial weapons run hot
|
||||
if (shouldFire && spec.Tier == SpectatorTier.Tourist)
|
||||
{
|
||||
for (int i = 0; i < spec.Grid.Mounted.Count; i++)
|
||||
{
|
||||
var m = spec.Grid.Mounted[i];
|
||||
if (m.Spec.Kind == HardpointKind.Weapon &&
|
||||
m.CurrentTemp > m.Spec.OptimalTemp + m.Spec.PlateauWidth * 0.45f)
|
||||
{
|
||||
shouldFire = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AdvanceTracers(MatchState state, float dt)
|
||||
{
|
||||
for (int i = state.Tracers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var t = state.Tracers[i];
|
||||
float nextTtl = t.Ttl - dt;
|
||||
if (nextTtl <= 0f)
|
||||
{
|
||||
state.Tracers.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Tracers[i] = t with { Ttl = nextTtl };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateMatchOutcome(MatchState state)
|
||||
{
|
||||
if (state.Phase != MatchPhase.Active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!state.Player.Alive)
|
||||
{
|
||||
state.Phase = MatchPhase.Defeat;
|
||||
return;
|
||||
}
|
||||
|
||||
int aliveCount = 0;
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
if (state.Contenders[i].Alive)
|
||||
{
|
||||
aliveCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (aliveCount <= 1 && state.Player.Alive)
|
||||
{
|
||||
state.Phase = MatchPhase.Victory;
|
||||
state.Broadcast.EmitVictory(state.Time, state.Player.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AutoEquipAiCargo(MatchState state, ContenderState ai)
|
||||
{
|
||||
if (ai.Grid.Cargo.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int c = ai.Grid.Cargo.Count - 1; c >= 0; c--)
|
||||
{
|
||||
var item = ai.Grid.Cargo[c];
|
||||
for (int h = 0; h < ai.Grid.Spec.Hardpoints.Length; h++)
|
||||
{
|
||||
var hp = ai.Grid.Spec.Hardpoints[h];
|
||||
if (!ChassisGrid.CanFit(hp, item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var mounted = ai.Grid.GetMountedOn(hp.Id);
|
||||
if (mounted is null || IsBetterModule(item, mounted.Spec))
|
||||
{
|
||||
state.TryEquipCargo(ai.Id, c, hp.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsBetterModule(ModuleSpec candidate, ModuleSpec current)
|
||||
{
|
||||
if (candidate.IsImperial && !current.IsImperial)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return candidate.Kind switch
|
||||
{
|
||||
HardpointKind.Weapon => candidate.WeaponDamage * MathF.Max(1, candidate.BurstCount) >
|
||||
current.WeaponDamage * MathF.Max(1, current.BurstCount),
|
||||
HardpointKind.Engine => candidate.ThrustBonus > current.ThrustBonus,
|
||||
HardpointKind.Radiator => candidate.CoolingPower > current.CoolingPower,
|
||||
HardpointKind.Armor => candidate.ArmorBonus > current.ArmorBonus,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,601 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public enum MatchPhase
|
||||
{
|
||||
Active,
|
||||
Victory,
|
||||
Defeat
|
||||
}
|
||||
|
||||
public readonly record struct PlayerInput(
|
||||
float Throttle,
|
||||
float Steer,
|
||||
float AimWorldX,
|
||||
float AimWorldZ,
|
||||
bool Fire,
|
||||
bool InteractPickup,
|
||||
bool Brake,
|
||||
float AimWorldY = float.NaN,
|
||||
float VerticalThrottle = 0f);
|
||||
|
||||
public readonly record struct TracerEvent(
|
||||
float StartX,
|
||||
float StartY,
|
||||
float StartZ,
|
||||
float EndX,
|
||||
float EndY,
|
||||
float EndZ,
|
||||
uint ColorRgba,
|
||||
float Ttl);
|
||||
|
||||
public readonly record struct ArenaBoxSpec(
|
||||
float X,
|
||||
float Y,
|
||||
float Z,
|
||||
float HalfX,
|
||||
float HalfY,
|
||||
float HalfZ,
|
||||
bool IsBoundary);
|
||||
|
||||
public sealed class PlayerContactMemory
|
||||
{
|
||||
public bool VisibleToPlayer { get; set; }
|
||||
public float LastSeenAge { get; set; } = float.PositiveInfinity;
|
||||
public float LastSeenX { get; set; }
|
||||
public float LastSeenZ { get; set; }
|
||||
public bool HasEverBeenSeen { get; set; }
|
||||
public bool FaintHorizonPing { get; set; }
|
||||
}
|
||||
|
||||
public sealed class GroundDrop
|
||||
{
|
||||
public GroundDrop(int id, float x, float z, ChassisSpec? chassis, ModuleSpec? module)
|
||||
{
|
||||
Id = id;
|
||||
X = x;
|
||||
Z = z;
|
||||
Chassis = chassis;
|
||||
Module = module;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public float X { get; }
|
||||
public float Z { get; }
|
||||
public ChassisSpec? Chassis { get; }
|
||||
public ModuleSpec? Module { get; }
|
||||
public bool PickedUp { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ContenderState
|
||||
{
|
||||
public ContenderState(int id, string name, bool isPlayer, ChassisGrid grid, float x, float z, float yaw)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
IsPlayer = isPlayer;
|
||||
Grid = grid;
|
||||
X = x;
|
||||
Y = grid.Spec.HalfHeight + 0.1f;
|
||||
Z = z;
|
||||
Yaw = yaw;
|
||||
AimX = x + MathF.Sin(yaw) * 20f;
|
||||
AimY = Y;
|
||||
AimZ = z + MathF.Cos(yaw) * 20f;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public bool IsPlayer { get; }
|
||||
public ChassisGrid Grid { get; }
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
public float AimX { get; set; }
|
||||
public float AimY { get; set; }
|
||||
public float AimZ { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public int Kills { get; set; }
|
||||
public bool OverheatWarned { get; set; }
|
||||
|
||||
public float ThrottleCmd { get; set; }
|
||||
public float SteerCmd { get; set; }
|
||||
public float VerticalThrottleCmd { get; set; }
|
||||
public float TargetHoverAltAgl { get; set; } = 3.0f;
|
||||
public bool FireCmd { get; set; }
|
||||
public bool BrakeCmd { get; set; }
|
||||
public float AiScavengeCooldown { get; set; }
|
||||
public int? AiTargetContenderId { get; set; }
|
||||
public bool AllWeaponsOutOfArc { get; set; }
|
||||
public int OutOfArcWeaponCount { get; set; }
|
||||
public int InArcWeaponCount { get; set; }
|
||||
public int DisabledWeaponCount { get; set; }
|
||||
|
||||
public bool Alive => !Grid.IsDestroyed;
|
||||
}
|
||||
|
||||
public sealed class MatchState
|
||||
{
|
||||
public const int ContenderCount = 12;
|
||||
public const float ArenaHalfExtent = 772f;
|
||||
public const float PickupRadius = 7.0f;
|
||||
public const float ContactGhostDuration = 5.0f;
|
||||
public const float TouristHorizonMaxRange = 420f;
|
||||
|
||||
private int _nextDropId = 1;
|
||||
|
||||
public MatchState(int seed = 42)
|
||||
{
|
||||
Seed = seed;
|
||||
Rng = new Random(seed);
|
||||
Spectators = new SpectatorRing(seed + 101);
|
||||
Broadcast = new BroadcastFeed();
|
||||
var rawCover = BuildCoverBoxes();
|
||||
Terrain = TerrainField.Generate((ulong)seed, rawCover);
|
||||
ArenaCoverBoxes = SeatBoxesOnTerrain(rawCover, Terrain);
|
||||
ArenaBoundaryBoxes = BuildBoundaryBoxes();
|
||||
|
||||
SpawnContenders();
|
||||
ScatterInitialLoot();
|
||||
Broadcast.EmitMatchStart(0f);
|
||||
}
|
||||
|
||||
public int Seed { get; }
|
||||
public Random Rng { get; }
|
||||
public float Time { get; set; }
|
||||
public MatchPhase Phase { get; set; } = MatchPhase.Active;
|
||||
|
||||
public TerrainField Terrain { get; }
|
||||
public List<ContenderState> Contenders { get; } = new();
|
||||
public SpectatorRing Spectators { get; }
|
||||
public List<GroundDrop> GroundDrops { get; } = new();
|
||||
public List<TracerEvent> Tracers { get; } = new();
|
||||
public BroadcastFeed Broadcast { get; }
|
||||
public IReadOnlyList<ArenaBoxSpec> ArenaCoverBoxes { get; }
|
||||
public IReadOnlyList<ArenaBoxSpec> ArenaBoundaryBoxes { get; }
|
||||
|
||||
public Dictionary<int, PlayerContactMemory> ContenderContacts { get; } = new();
|
||||
public Dictionary<int, PlayerContactMemory> SpectatorContacts { get; } = new();
|
||||
public int PlayerDetectedByCount { get; set; }
|
||||
|
||||
public float? LastGunfireX { get; set; }
|
||||
public float? LastGunfireZ { get; set; }
|
||||
public float LastGunfireTime { get; set; } = -100f;
|
||||
|
||||
public ContenderState Player => Contenders[0];
|
||||
|
||||
public event Action<ContenderState>? ChassisSwapped;
|
||||
|
||||
public static bool IsContactOnRadar(PlayerContactMemory? mem)
|
||||
{
|
||||
if (mem is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return mem.VisibleToPlayer || mem.FaintHorizonPing || (mem.HasEverBeenSeen && mem.LastSeenAge <= ContactGhostDuration);
|
||||
}
|
||||
|
||||
public PlayerContactMemory GetOrCreateContenderContact(int contenderId)
|
||||
{
|
||||
if (!ContenderContacts.TryGetValue(contenderId, out var mem))
|
||||
{
|
||||
mem = new PlayerContactMemory();
|
||||
ContenderContacts[contenderId] = mem;
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
public PlayerContactMemory GetOrCreateSpectatorContact(int spectatorId)
|
||||
{
|
||||
if (!SpectatorContacts.TryGetValue(spectatorId, out var mem))
|
||||
{
|
||||
mem = new PlayerContactMemory();
|
||||
SpectatorContacts[spectatorId] = mem;
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
public GroundDrop SpawnModuleDrop(float x, float z, ModuleSpec module)
|
||||
{
|
||||
var drop = new GroundDrop(_nextDropId++, x, z, null, module);
|
||||
GroundDrops.Add(drop);
|
||||
return drop;
|
||||
}
|
||||
|
||||
public GroundDrop SpawnChassisDrop(float x, float z, ChassisSpec chassis)
|
||||
{
|
||||
var drop = new GroundDrop(_nextDropId++, x, z, chassis, null);
|
||||
GroundDrops.Add(drop);
|
||||
return drop;
|
||||
}
|
||||
|
||||
public bool TryEquipCargo(int cargoIndex, string hardpointId) =>
|
||||
TryEquipCargo(0, cargoIndex, hardpointId);
|
||||
|
||||
public bool TryEquipCargo(int contenderId, int cargoIndex, string hardpointId)
|
||||
{
|
||||
if (contenderId < 0 || contenderId >= Contenders.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var contender = Contenders[contenderId];
|
||||
if (!contender.Alive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var displaced = new List<ModuleSpec>();
|
||||
bool ok = contender.Grid.TryEquipFromCargo(cargoIndex, hardpointId, displaced);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < displaced.Count; i++)
|
||||
{
|
||||
SpawnModuleDrop(contender.X + 1.5f, contender.Z + 1.5f, displaced[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public GroundDrop? FindNearestInteractableDrop(int contenderId = 0)
|
||||
{
|
||||
if (contenderId < 0 || contenderId >= Contenders.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var contender = Contenders[contenderId];
|
||||
if (!contender.Alive)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
GroundDrop? nearest = null;
|
||||
float bestDistSq = PickupRadius * PickupRadius;
|
||||
|
||||
for (int i = 0; i < GroundDrops.Count; i++)
|
||||
{
|
||||
var d = GroundDrops[i];
|
||||
if (d.PickedUp || (d.Module is null && d.Chassis is null))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = d.X - contender.X;
|
||||
float dz = d.Z - contender.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 <= bestDistSq)
|
||||
{
|
||||
bestDistSq = d2;
|
||||
nearest = d;
|
||||
}
|
||||
}
|
||||
|
||||
return nearest;
|
||||
}
|
||||
|
||||
public bool TryInteractNearestDrop(int contenderId = 0)
|
||||
{
|
||||
var nearest = FindNearestInteractableDrop(contenderId);
|
||||
if (nearest is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var contender = Contenders[contenderId];
|
||||
if (nearest.Module is not null)
|
||||
{
|
||||
return ExecuteModuleDropPickup(contenderId, contender, nearest);
|
||||
}
|
||||
if (nearest.Chassis is not null)
|
||||
{
|
||||
return ExecuteChassisDropSwap(contender, nearest);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryPickupNearbyModule(int contenderId = 0)
|
||||
{
|
||||
if (contenderId < 0 || contenderId >= Contenders.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var contender = Contenders[contenderId];
|
||||
if (!contender.Alive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GroundDrop? nearest = null;
|
||||
float bestDistSq = PickupRadius * PickupRadius;
|
||||
|
||||
for (int i = 0; i < GroundDrops.Count; i++)
|
||||
{
|
||||
var d = GroundDrops[i];
|
||||
if (d.PickedUp || d.Module is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = d.X - contender.X;
|
||||
float dz = d.Z - contender.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 <= bestDistSq)
|
||||
{
|
||||
bestDistSq = d2;
|
||||
nearest = d;
|
||||
}
|
||||
}
|
||||
|
||||
return nearest is not null && ExecuteModuleDropPickup(contenderId, contender, nearest);
|
||||
}
|
||||
|
||||
public bool TrySwapNearbyChassis(int contenderId = 0)
|
||||
{
|
||||
if (contenderId < 0 || contenderId >= Contenders.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var contender = Contenders[contenderId];
|
||||
if (!contender.Alive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GroundDrop? nearest = null;
|
||||
float bestDistSq = PickupRadius * PickupRadius;
|
||||
|
||||
for (int i = 0; i < GroundDrops.Count; i++)
|
||||
{
|
||||
var d = GroundDrops[i];
|
||||
if (d.PickedUp || d.Chassis is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = d.X - contender.X;
|
||||
float dz = d.Z - contender.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 <= bestDistSq)
|
||||
{
|
||||
bestDistSq = d2;
|
||||
nearest = d;
|
||||
}
|
||||
}
|
||||
|
||||
return nearest is not null && ExecuteChassisDropSwap(contender, nearest);
|
||||
}
|
||||
|
||||
private bool ExecuteModuleDropPickup(int contenderId, ContenderState contender, GroundDrop drop)
|
||||
{
|
||||
if (drop.Module is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!contender.Grid.TryQuickBoltOrCargo(drop.Module, out string? boltedHardpointId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
drop.PickedUp = true;
|
||||
if (boltedHardpointId is not null)
|
||||
{
|
||||
Broadcast.EmitQuickBolt(Time, contenderId, drop.Module.Name, boltedHardpointId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ExecuteChassisDropSwap(ContenderState contender, GroundDrop drop)
|
||||
{
|
||||
if (drop.Chassis is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var oldChassis = contender.Grid.Spec;
|
||||
var overflow = contender.Grid.SwapChassis(drop.Chassis);
|
||||
drop.PickedUp = true;
|
||||
|
||||
SpawnChassisDrop(contender.X - 2.2f, contender.Z - 2.2f, oldChassis);
|
||||
for (int i = 0; i < overflow.Count; i++)
|
||||
{
|
||||
SpawnModuleDrop(contender.X + 1.5f + i * 0.7f, contender.Z - 1.5f, overflow[i]);
|
||||
}
|
||||
|
||||
contender.TargetHoverAltAgl = contender.Grid.Spec.IsVtol ? 10.0f : 3.0f;
|
||||
contender.VerticalThrottleCmd = 0f;
|
||||
contender.Y = Terrain.SampleHeight(contender.X, contender.Z) + contender.Grid.Spec.HalfHeight +
|
||||
(contender.Grid.Spec.IsVtol ? contender.TargetHoverAltAgl : 0.15f);
|
||||
contender.AiScavengeCooldown = 4.0f;
|
||||
Broadcast.EmitChassisSwap(Time, contender.Id, contender.Grid.Spec.Name);
|
||||
ChassisSwapped?.Invoke(contender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SpawnContenders()
|
||||
{
|
||||
var aiRoster = new List<ChassisSpec>(Catalog.AllChassis);
|
||||
for (int k = aiRoster.Count - 1; k > 0; k--)
|
||||
{
|
||||
int j = Rng.Next(k + 1);
|
||||
(aiRoster[k], aiRoster[j]) = (aiRoster[j], aiRoster[k]);
|
||||
}
|
||||
|
||||
// Spawn 12 contenders (player + 11 AI) spread across r ~ 240..460m (well inside SafeRadius = 560m)
|
||||
for (int i = 0; i < ContenderCount; i++)
|
||||
{
|
||||
float angle = (i / (float)ContenderCount) * MathF.Tau + (float)(Rng.NextDouble() - 0.5) * 0.16f;
|
||||
float baseR = 250f + (float)Rng.NextDouble() * 195f;
|
||||
float x = MathF.Cos(angle) * baseR;
|
||||
float z = MathF.Sin(angle) * baseR;
|
||||
|
||||
// Nudge radially inside [240, 460] if landing on a steep mesa cliff edge
|
||||
for (int step = 0; step < 8; step++)
|
||||
{
|
||||
var (_, ny, _) = Terrain.SampleNormal(x, z);
|
||||
if (ny >= 0.88f)
|
||||
{
|
||||
break;
|
||||
}
|
||||
float r = 245f + ((baseR - 245f + step * 28f) % 210f);
|
||||
x = MathF.Cos(angle) * r;
|
||||
z = MathF.Sin(angle) * r;
|
||||
}
|
||||
|
||||
float yaw = MathF.Atan2(-x, -z);
|
||||
string name = i == 0 ? "Contender 01 (You)" : $"Contender {i + 1:00}";
|
||||
var grid = i == 0
|
||||
? Catalog.CreateStarterBuggy()
|
||||
: Catalog.CreateWithDefaultLoadout(aiRoster[(i - 1) % aiRoster.Count]);
|
||||
var contender = new ContenderState(i, name, i == 0, grid, x, z, yaw);
|
||||
if (grid.Spec.IsVtol)
|
||||
{
|
||||
contender.TargetHoverAltAgl = 10f;
|
||||
}
|
||||
contender.Y = Terrain.SampleHeight(x, z) + contender.Grid.Spec.HalfHeight +
|
||||
(grid.Spec.IsVtol ? contender.TargetHoverAltAgl : 0.15f);
|
||||
contender.AimY = contender.Y;
|
||||
Contenders.Add(contender);
|
||||
if (i > 0)
|
||||
{
|
||||
ContenderContacts[i] = new PlayerContactMemory();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Spectators.Spectators.Count; i++)
|
||||
{
|
||||
SpectatorContacts[Spectators.Spectators[i].Id] = new PlayerContactMemory();
|
||||
}
|
||||
}
|
||||
|
||||
private void ScatterInitialLoot()
|
||||
{
|
||||
// 14 deterministic salvageable chassis wrecks covering all non-starter vehicles in the 15-vehicle roster
|
||||
var chassisPool = new List<ChassisSpec>(Catalog.AllChassis.Count);
|
||||
for (int i = 0; i < Catalog.AllChassis.Count; i++)
|
||||
{
|
||||
var c = Catalog.AllChassis[i];
|
||||
if (!string.Equals(c.Id, Catalog.Jackal.Id, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
chassisPool.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < chassisPool.Count; i++)
|
||||
{
|
||||
float angle = (i / (float)chassisPool.Count) * MathF.Tau + 0.35f;
|
||||
float r = i >= chassisPool.Count - 3 ? (55f + (i % 3) * 18f) : (135f + (i % 4) * 85f);
|
||||
SpawnChassisDrop(MathF.Cos(angle) * r, MathF.Sin(angle) * r, chassisPool[i]);
|
||||
}
|
||||
|
||||
// 26 ground salvage module drops spread across canyons, passes, and ruins (including 1x1 Wide-Arc PD!)
|
||||
ModuleSpec[] salvagePool =
|
||||
{
|
||||
Catalog.Autocannon, Catalog.Flak, Catalog.PointDefenseFlak, Catalog.Recoilless,
|
||||
Catalog.TurboCore, Catalog.CopperRad, Catalog.WeldedPlate, Catalog.Mg762,
|
||||
Catalog.DieselCore, Catalog.PointDefenseFlak, Catalog.Autocannon, Catalog.Flak,
|
||||
Catalog.Recoilless, Catalog.TurboCore, Catalog.CopperRad, Catalog.WeldedPlate,
|
||||
Catalog.Autocannon, Catalog.PointDefenseFlak, Catalog.Recoilless, Catalog.Flak,
|
||||
Catalog.TurboCore, Catalog.CopperRad, Catalog.WeldedPlate, Catalog.Mg762,
|
||||
Catalog.Autocannon, Catalog.ImperialAegisPd
|
||||
};
|
||||
|
||||
for (int i = 0; i < salvagePool.Length; i++)
|
||||
{
|
||||
float angle = (i / (float)salvagePool.Length) * MathF.Tau + 0.19f;
|
||||
float r = 75f + (i % 5) * 95f;
|
||||
SpawnModuleDrop(MathF.Cos(angle) * r, MathF.Sin(angle) * r, salvagePool[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ArenaBoxSpec> BuildCoverBoxes()
|
||||
{
|
||||
// 36 deterministic ruin walls / cover blocks spaced >= 90m apart across the 1.5km valley
|
||||
var boxes = new List<ArenaBoxSpec>(36);
|
||||
|
||||
// Inner plaza ring (4 blocks at r = 68m)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float a = (i / 4f) * MathF.Tau + 0.35f;
|
||||
bool rot = i % 2 == 0;
|
||||
boxes.Add(new ArenaBoxSpec(
|
||||
MathF.Cos(a) * 68f, 2.0f, MathF.Sin(a) * 68f,
|
||||
rot ? 5.2f : 1.6f, 2.0f, rot ? 1.6f : 5.2f, false));
|
||||
}
|
||||
|
||||
// Inner-mid ruins (8 blocks at r = 175m)
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
float a = (i / 8f) * MathF.Tau + 0.15f;
|
||||
bool bunker = i % 3 == 0;
|
||||
boxes.Add(new ArenaBoxSpec(
|
||||
MathF.Cos(a) * 175f, 2.3f, MathF.Sin(a) * 175f,
|
||||
bunker ? 3.8f : (i % 2 == 0 ? 5.8f : 1.8f),
|
||||
2.3f,
|
||||
bunker ? 3.8f : (i % 2 == 0 ? 1.8f : 5.8f),
|
||||
false));
|
||||
}
|
||||
|
||||
// Mid-valley pass ruins (12 blocks at r = 335m)
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
float a = (i / 12f) * MathF.Tau + 0.22f;
|
||||
bool bunker = i % 2 == 0;
|
||||
boxes.Add(new ArenaBoxSpec(
|
||||
MathF.Cos(a) * 335f, 2.4f, MathF.Sin(a) * 335f,
|
||||
bunker ? 4.0f : 6.0f, 2.4f, bunker ? 4.0f : 1.8f, false));
|
||||
}
|
||||
|
||||
// Outer rim ruins (12 blocks at r = 515m)
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
float a = (i / 12f) * MathF.Tau + 0.08f;
|
||||
bool tall = i % 3 == 0;
|
||||
boxes.Add(new ArenaBoxSpec(
|
||||
MathF.Cos(a) * 515f, tall ? 2.8f : 2.2f, MathF.Sin(a) * 515f,
|
||||
tall ? 3.6f : 5.6f, tall ? 2.8f : 2.2f, tall ? 3.6f : 1.8f, false));
|
||||
}
|
||||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ArenaBoxSpec> SeatBoxesOnTerrain(IReadOnlyList<ArenaBoxSpec> raw, TerrainField terrain)
|
||||
{
|
||||
var seated = new ArenaBoxSpec[raw.Count];
|
||||
for (int i = 0; i < raw.Count; i++)
|
||||
{
|
||||
var b = raw[i];
|
||||
float minY = terrain.SampleHeight(b.X, b.Z);
|
||||
minY = MathF.Min(minY, terrain.SampleHeight(b.X - b.HalfX, b.Z - b.HalfZ));
|
||||
minY = MathF.Min(minY, terrain.SampleHeight(b.X + b.HalfX, b.Z - b.HalfZ));
|
||||
minY = MathF.Min(minY, terrain.SampleHeight(b.X - b.HalfX, b.Z + b.HalfZ));
|
||||
minY = MathF.Min(minY, terrain.SampleHeight(b.X + b.HalfX, b.Z + b.HalfZ));
|
||||
seated[i] = b with { Y = minY + b.HalfY };
|
||||
}
|
||||
return seated;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ArenaBoxSpec> BuildBoundaryBoxes()
|
||||
{
|
||||
const float wallY = 12f;
|
||||
const float wallHalfH = 60f;
|
||||
const float wallHalfThick = 4f;
|
||||
const float span = ArenaHalfExtent + wallHalfThick;
|
||||
return new ArenaBoxSpec[]
|
||||
{
|
||||
new(0f, wallY, ArenaHalfExtent, span, wallHalfH, wallHalfThick, true),
|
||||
new(0f, wallY, -ArenaHalfExtent, span, wallHalfH, wallHalfThick, true),
|
||||
new(ArenaHalfExtent, wallY, 0f, wallHalfThick, wallHalfH, span, true),
|
||||
new(-ArenaHalfExtent, wallY, 0f, wallHalfThick, wallHalfH, span, true)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(CultLibRoot)/src/GameCult.Caching/GameCult.Caching.csproj" />
|
||||
<ProjectReference Include="$(CultLibRoot)/src/GameCult.Caching.MessagePack/GameCult.Caching.MessagePack.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,831 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public enum SpectatorTier
|
||||
{
|
||||
Tourist,
|
||||
Patron,
|
||||
Exemplar
|
||||
}
|
||||
|
||||
public enum SpectatorStance
|
||||
{
|
||||
Neutral,
|
||||
Cleared,
|
||||
Provoked
|
||||
}
|
||||
|
||||
public readonly record struct RingContact(int Id, float X, float Z, bool Alive, float Y = 0f, float HalfHeight = 1f);
|
||||
|
||||
public sealed class SpectatorState
|
||||
{
|
||||
public SpectatorState(
|
||||
int id,
|
||||
SpectatorTier tier,
|
||||
ChassisGrid grid,
|
||||
float ringAngle,
|
||||
float ringOffset,
|
||||
float radarSignature,
|
||||
float aimSpreadRad,
|
||||
float maxSpeed,
|
||||
float preferredRange)
|
||||
{
|
||||
Id = id;
|
||||
Tier = tier;
|
||||
Grid = grid;
|
||||
RingAngle = ringAngle;
|
||||
RingOffset = ringOffset;
|
||||
RadarSignature = radarSignature;
|
||||
AimSpreadRad = aimSpreadRad;
|
||||
MaxSpeed = maxSpeed;
|
||||
PreferredRange = preferredRange;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public SpectatorTier Tier { get; }
|
||||
public ChassisGrid Grid { get; }
|
||||
public float RingAngle { get; set; }
|
||||
public float RingOffset { get; }
|
||||
public float RadarSignature { get; }
|
||||
public float AimSpreadRad { get; }
|
||||
public float MaxSpeed { get; }
|
||||
public float PreferredRange { get; }
|
||||
|
||||
public SpectatorStance Stance { get; set; } = SpectatorStance.Neutral;
|
||||
public int? TargetContenderId { get; set; }
|
||||
public bool BroadcastWakeupEmitted { get; set; }
|
||||
|
||||
public bool HasTargetLos { get; set; }
|
||||
public float LastKnownTargetX { get; set; }
|
||||
public float LastKnownTargetY { get; set; }
|
||||
public float LastKnownTargetZ { get; set; }
|
||||
public float TimeSinceLastSeen { get; set; } = float.PositiveInfinity;
|
||||
|
||||
public bool HasNeutralAnchor { get; set; }
|
||||
public float NeutralAnchorX { get; set; }
|
||||
public float NeutralAnchorZ { get; set; }
|
||||
public float NeutralAnchorSafeRadius { get; set; }
|
||||
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
public bool Alive => !Grid.IsDestroyed;
|
||||
}
|
||||
|
||||
public sealed class SpectatorRing
|
||||
{
|
||||
public const float InitialRadius = 560f;
|
||||
public const float MinRadius = 85f;
|
||||
public const float GraceDuration = 30f;
|
||||
public const float ShrinkDuration = 360f;
|
||||
public const int DefaultSpectatorCount = 56;
|
||||
public const float TargetMemoryDuration = 4.0f;
|
||||
|
||||
private sealed class ContenderAwareness
|
||||
{
|
||||
public bool HasKnownPos;
|
||||
public float LastKnownX;
|
||||
public float LastKnownY;
|
||||
public float LastKnownZ;
|
||||
public float TimeSinceSeen = TargetMemoryDuration + 1f;
|
||||
}
|
||||
|
||||
private readonly List<SpectatorState> _spectators = new();
|
||||
private readonly Dictionary<int, bool> _aliveById = new();
|
||||
private readonly Dictionary<int, ContenderAwareness> _awarenessByContender = new();
|
||||
|
||||
public SpectatorRing(int seed = 1337, int count = DefaultSpectatorCount)
|
||||
{
|
||||
var rng = new Random(seed);
|
||||
SafeRadius = InitialRadius;
|
||||
SpawnRing(rng, count);
|
||||
}
|
||||
|
||||
public float SafeRadius { get; private set; }
|
||||
public IReadOnlyList<SpectatorState> Spectators => _spectators;
|
||||
|
||||
public void UpdateSafeRadius(float matchTime)
|
||||
{
|
||||
if (matchTime <= GraceDuration)
|
||||
{
|
||||
SafeRadius = InitialRadius;
|
||||
return;
|
||||
}
|
||||
|
||||
float t = Math.Clamp((matchTime - GraceDuration) / ShrinkDuration, 0f, 1f);
|
||||
SafeRadius = InitialRadius + (MinRadius - InitialRadius) * t;
|
||||
}
|
||||
|
||||
public void UpdateClearance(ReadOnlySpan<RingContact> contenders) =>
|
||||
UpdateClearance(contenders, 0f, null);
|
||||
|
||||
public void UpdateClearance(
|
||||
ReadOnlySpan<RingContact> contenders,
|
||||
float dt,
|
||||
Func<SpectatorState, RingContact, bool>? hasLos,
|
||||
int tickIndex = -1)
|
||||
{
|
||||
_aliveById.Clear();
|
||||
for (int i = 0; i < contenders.Length; i++)
|
||||
{
|
||||
_aliveById[contenders[i].Id] = contenders[i].Alive;
|
||||
}
|
||||
|
||||
// Step 1: Update per-contender ring awareness ONLY from spectators with live LOS.
|
||||
for (int c = 0; c < contenders.Length; c++)
|
||||
{
|
||||
var contender = contenders[c];
|
||||
var aw = GetOrCreateAwareness(contender.Id);
|
||||
if (!contender.Alive || ComputeOutsideDist(contender) <= 0f)
|
||||
{
|
||||
aw.HasKnownPos = false;
|
||||
aw.TimeSinceSeen = TargetMemoryDuration + 1f;
|
||||
continue;
|
||||
}
|
||||
|
||||
aw.TimeSinceSeen += dt;
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (tickIndex >= 0 && spec.Stance == SpectatorStance.Neutral && ((spec.Id + tickIndex) % 6 != 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasLos is null || hasLos(spec, contender))
|
||||
{
|
||||
aw.HasKnownPos = true;
|
||||
aw.LastKnownX = contender.X;
|
||||
aw.LastKnownY = contender.Y;
|
||||
aw.LastKnownZ = contender.Z;
|
||||
aw.TimeSinceSeen = 0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Maintain existing Provoked and Cleared assignments sticky while target is valid.
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive)
|
||||
{
|
||||
ResetToNeutral(spec);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spec.Stance == SpectatorStance.Provoked)
|
||||
{
|
||||
if (!spec.TargetContenderId.HasValue ||
|
||||
!TryFindAliveContact(contenders, spec.TargetContenderId.Value, out var contact))
|
||||
{
|
||||
ResetToNeutral(spec);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateWatcherTracking(spec, contact, dt, hasLos);
|
||||
}
|
||||
}
|
||||
else if (spec.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
if (!spec.TargetContenderId.HasValue ||
|
||||
!TryFindAliveContact(contenders, spec.TargetContenderId.Value, out var contact) ||
|
||||
ComputeOutsideDist(contact) <= 0f)
|
||||
{
|
||||
ResetToNeutral(spec);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateWatcherTracking(spec, contact, dt, hasLos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spec.TargetContenderId = null;
|
||||
spec.HasTargetLos = false;
|
||||
spec.TimeSinceLastSeen = TargetMemoryDuration + 1f;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Balance Cleared assignments per outside contender without reading occluded coords.
|
||||
for (int c = 0; c < contenders.Length; c++)
|
||||
{
|
||||
var contender = contenders[c];
|
||||
if (!contender.Alive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float outsideDist = ComputeOutsideDist(contender);
|
||||
if (outsideDist <= 0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int allowedCleared = Math.Min(8, 1 + (int)(outsideDist / 12f));
|
||||
int currentCleared = CountClearedFor(contender.Id);
|
||||
|
||||
// Drop excess if outsideDist shrank (prefer dropping stale no-LOS watchers first).
|
||||
while (currentCleared > allowedCleared)
|
||||
{
|
||||
int dropIdx = FindExcessClearedToDrop(contender.Id);
|
||||
if (dropIdx < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
ResetToNeutral(_spectators[dropIdx]);
|
||||
currentCleared--;
|
||||
}
|
||||
|
||||
// If full with a stale expired no-LOS watcher while a Neutral watcher has live LOS, rotate one slot.
|
||||
if (currentCleared == allowedCleared && hasLos is not null && AnyNeutralHasLos(contender, hasLos, tickIndex))
|
||||
{
|
||||
int staleIdx = FindStaleNoLosCleared(contender.Id);
|
||||
if (staleIdx >= 0)
|
||||
{
|
||||
ResetToNeutral(_spectators[staleIdx]);
|
||||
currentCleared--;
|
||||
}
|
||||
}
|
||||
|
||||
// Pass 1: Spectators with direct live LOS to the offender.
|
||||
while (currentCleared < allowedCleared)
|
||||
{
|
||||
int bestIdx = -1;
|
||||
float bestDistSq = float.PositiveInfinity;
|
||||
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive || spec.Stance != SpectatorStance.Neutral)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (tickIndex >= 0 && ((spec.Id + tickIndex) % 6 != 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasLos is not null && !hasLos(spec, contender))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = spec.X - contender.X;
|
||||
float dz = spec.Z - contender.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < bestDistSq)
|
||||
{
|
||||
bestDistSq = d2;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestIdx < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var chosen = _spectators[bestIdx];
|
||||
chosen.Stance = SpectatorStance.Cleared;
|
||||
chosen.TargetContenderId = contender.Id;
|
||||
chosen.HasTargetLos = true;
|
||||
chosen.LastKnownTargetX = contender.X;
|
||||
chosen.LastKnownTargetY = contender.Y;
|
||||
chosen.LastKnownTargetZ = contender.Z;
|
||||
chosen.TimeSinceLastSeen = 0f;
|
||||
currentCleared++;
|
||||
}
|
||||
|
||||
// Pass 2: Reinforce from already-observed LastKnownPos ONLY (never read live occluded contender.X/Z).
|
||||
if (currentCleared < allowedCleared &&
|
||||
hasLos is not null &&
|
||||
_awarenessByContender.TryGetValue(contender.Id, out var aw) &&
|
||||
aw.HasKnownPos)
|
||||
{
|
||||
const float maxPass2RadiusSq = 240f * 240f;
|
||||
while (currentCleared < allowedCleared)
|
||||
{
|
||||
int bestIdx = -1;
|
||||
float bestDistSq = float.PositiveInfinity;
|
||||
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive || spec.Stance != SpectatorStance.Neutral)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dx = spec.X - aw.LastKnownX;
|
||||
float dz = spec.Z - aw.LastKnownZ;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 <= maxPass2RadiusSq && d2 < bestDistSq)
|
||||
{
|
||||
bestDistSq = d2;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestIdx < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var chosen = _spectators[bestIdx];
|
||||
chosen.Stance = SpectatorStance.Cleared;
|
||||
chosen.TargetContenderId = contender.Id;
|
||||
chosen.HasTargetLos = false;
|
||||
chosen.LastKnownTargetX = aw.LastKnownX;
|
||||
chosen.LastKnownTargetY = aw.LastKnownY;
|
||||
chosen.LastKnownTargetZ = aw.LastKnownZ;
|
||||
chosen.TimeSinceLastSeen = aw.TimeSinceSeen;
|
||||
currentCleared++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnSpectatorDamaged(
|
||||
SpectatorState spectator,
|
||||
int attackerContenderId,
|
||||
float? incomingDirX = null,
|
||||
float? incomingDirZ = null)
|
||||
{
|
||||
if (!spectator.Alive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (spectator.Stance == SpectatorStance.Neutral || spectator.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
bool sameTargetWithFreshMemory = spectator.TargetContenderId == attackerContenderId &&
|
||||
(spectator.HasTargetLos || spectator.TimeSinceLastSeen < TargetMemoryDuration);
|
||||
|
||||
spectator.Stance = SpectatorStance.Provoked;
|
||||
spectator.TargetContenderId = attackerContenderId;
|
||||
|
||||
if (!sameTargetWithFreshMemory)
|
||||
{
|
||||
spectator.HasTargetLos = false;
|
||||
if (_awarenessByContender.TryGetValue(attackerContenderId, out var aw) &&
|
||||
aw.HasKnownPos &&
|
||||
aw.TimeSinceSeen < TargetMemoryDuration)
|
||||
{
|
||||
spectator.LastKnownTargetX = aw.LastKnownX;
|
||||
spectator.LastKnownTargetY = aw.LastKnownY;
|
||||
spectator.LastKnownTargetZ = aw.LastKnownZ;
|
||||
spectator.TimeSinceLastSeen = aw.TimeSinceSeen;
|
||||
}
|
||||
else if (incomingDirX.HasValue && incomingDirZ.HasValue)
|
||||
{
|
||||
float dLen = MathF.Sqrt(incomingDirX.Value * incomingDirX.Value + incomingDirZ.Value * incomingDirZ.Value);
|
||||
float nx = dLen > 1e-4f ? incomingDirX.Value / dLen : MathF.Sin(spectator.Yaw);
|
||||
float nz = dLen > 1e-4f ? incomingDirZ.Value / dLen : MathF.Cos(spectator.Yaw);
|
||||
spectator.LastKnownTargetX = spectator.X + nx * 60f;
|
||||
spectator.LastKnownTargetY = spectator.Y;
|
||||
spectator.LastKnownTargetZ = spectator.Z + nz * 60f;
|
||||
spectator.TimeSinceLastSeen = 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
spectator.LastKnownTargetX = spectator.X + MathF.Sin(spectator.Yaw) * 40f;
|
||||
spectator.LastKnownTargetY = spectator.Y;
|
||||
spectator.LastKnownTargetZ = spectator.Z + MathF.Cos(spectator.Yaw) * 40f;
|
||||
spectator.TimeSinceLastSeen = TargetMemoryDuration;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private ContenderAwareness GetOrCreateAwareness(int contenderId)
|
||||
{
|
||||
if (!_awarenessByContender.TryGetValue(contenderId, out var aw))
|
||||
{
|
||||
aw = new ContenderAwareness();
|
||||
_awarenessByContender[contenderId] = aw;
|
||||
}
|
||||
return aw;
|
||||
}
|
||||
|
||||
private float ComputeOutsideDist(in RingContact contact)
|
||||
{
|
||||
float distFromCenter = MathF.Sqrt(contact.X * contact.X + contact.Z * contact.Z);
|
||||
return MathF.Max(0f, distFromCenter - SafeRadius);
|
||||
}
|
||||
|
||||
private static void ResetToNeutral(SpectatorState spec)
|
||||
{
|
||||
spec.Stance = SpectatorStance.Neutral;
|
||||
spec.TargetContenderId = null;
|
||||
spec.HasTargetLos = false;
|
||||
spec.TimeSinceLastSeen = TargetMemoryDuration + 1f;
|
||||
}
|
||||
|
||||
private static void UpdateWatcherTracking(
|
||||
SpectatorState spec,
|
||||
in RingContact contact,
|
||||
float dt,
|
||||
Func<SpectatorState, RingContact, bool>? hasLos)
|
||||
{
|
||||
bool los = hasLos is null || hasLos(spec, contact);
|
||||
if (los)
|
||||
{
|
||||
spec.HasTargetLos = true;
|
||||
spec.LastKnownTargetX = contact.X;
|
||||
spec.LastKnownTargetY = contact.Y;
|
||||
spec.LastKnownTargetZ = contact.Z;
|
||||
spec.TimeSinceLastSeen = 0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
spec.HasTargetLos = false;
|
||||
spec.TimeSinceLastSeen += dt;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryFindAliveContact(ReadOnlySpan<RingContact> contenders, int id, out RingContact contact)
|
||||
{
|
||||
for (int i = 0; i < contenders.Length; i++)
|
||||
{
|
||||
if (contenders[i].Id == id && contenders[i].Alive)
|
||||
{
|
||||
contact = contenders[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
contact = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private int FindExcessClearedToDrop(int contenderId)
|
||||
{
|
||||
int bestIdx = -1;
|
||||
bool bestNoLos = false;
|
||||
float bestAge = -1f;
|
||||
float bestDistSq = -1f;
|
||||
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive || spec.Stance != SpectatorStance.Cleared || spec.TargetContenderId != contenderId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool noLos = !spec.HasTargetLos;
|
||||
float age = spec.TimeSinceLastSeen;
|
||||
float dx = spec.X - spec.LastKnownTargetX;
|
||||
float dz = spec.Z - spec.LastKnownTargetZ;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
|
||||
if (bestIdx < 0 ||
|
||||
(noLos && !bestNoLos) ||
|
||||
(noLos == bestNoLos && (age > bestAge + 1e-4f || (MathF.Abs(age - bestAge) <= 1e-4f && d2 > bestDistSq))))
|
||||
{
|
||||
bestIdx = i;
|
||||
bestNoLos = noLos;
|
||||
bestAge = age;
|
||||
bestDistSq = d2;
|
||||
}
|
||||
}
|
||||
|
||||
return bestIdx;
|
||||
}
|
||||
|
||||
private bool AnyNeutralHasLos(in RingContact contender, Func<SpectatorState, RingContact, bool> hasLos, int tickIndex)
|
||||
{
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (spec.Alive && spec.Stance == SpectatorStance.Neutral &&
|
||||
(tickIndex < 0 || ((spec.Id + tickIndex) % 6 == 0)) &&
|
||||
hasLos(spec, contender))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int FindStaleNoLosCleared(int contenderId)
|
||||
{
|
||||
int bestIdx = -1;
|
||||
float bestAge = TargetMemoryDuration;
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (spec.Alive &&
|
||||
spec.Stance == SpectatorStance.Cleared &&
|
||||
spec.TargetContenderId == contenderId &&
|
||||
!spec.HasTargetLos &&
|
||||
spec.TimeSinceLastSeen >= bestAge)
|
||||
{
|
||||
bestAge = spec.TimeSinceLastSeen;
|
||||
bestIdx = i;
|
||||
}
|
||||
}
|
||||
return bestIdx;
|
||||
}
|
||||
|
||||
public void AdvancePerimeterOrbits(float dt)
|
||||
{
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var spec = _spectators[i];
|
||||
if (!spec.Alive || spec.Stance != SpectatorStance.Neutral)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only ostentatious Tourists orbit continuously in plain sight;
|
||||
// Patrons and Exemplars hold their chosen high-ground / ambush positions.
|
||||
if (spec.Tier == SpectatorTier.Tourist)
|
||||
{
|
||||
spec.RingAngle += 0.02f * dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public (float X, float Z) GetPerimeterSlot(SpectatorState spec)
|
||||
{
|
||||
float r = SafeRadius + spec.RingOffset;
|
||||
return (MathF.Cos(spec.RingAngle) * r, MathF.Sin(spec.RingAngle) * r);
|
||||
}
|
||||
|
||||
public (float X, float Z) GetNeutralGoal(
|
||||
SpectatorState spec,
|
||||
TerrainField? terrain,
|
||||
IReadOnlyList<ArenaBoxSpec>? coverBoxes)
|
||||
{
|
||||
if (spec.Tier == SpectatorTier.Tourist || terrain is null)
|
||||
{
|
||||
return GetPerimeterSlot(spec);
|
||||
}
|
||||
|
||||
if (spec.HasNeutralAnchor && MathF.Abs(SafeRadius - spec.NeutralAnchorSafeRadius) < 8f)
|
||||
{
|
||||
return (spec.NeutralAnchorX, spec.NeutralAnchorZ);
|
||||
}
|
||||
|
||||
float bestX = MathF.Cos(spec.RingAngle) * (SafeRadius + spec.RingOffset);
|
||||
float bestZ = MathF.Sin(spec.RingAngle) * (SafeRadius + spec.RingOffset);
|
||||
float bestScore = float.NegativeInfinity;
|
||||
float maxBound = TerrainField.HalfExtent - 18f;
|
||||
|
||||
for (int ai = -3; ai <= 3; ai++)
|
||||
{
|
||||
float angle = spec.RingAngle + ai * 0.075f;
|
||||
float cosA = MathF.Cos(angle);
|
||||
float sinA = MathF.Sin(angle);
|
||||
|
||||
for (int ri = 0; ri < 3; ri++)
|
||||
{
|
||||
float r = SafeRadius + 18f + ri * 26f;
|
||||
float cx = Math.Clamp(cosA * r, -maxBound, maxBound);
|
||||
float cz = Math.Clamp(sinA * r, -maxBound, maxBound);
|
||||
|
||||
float distLen = MathF.Sqrt(cx * cx + cz * cz);
|
||||
float inX = distLen > 1f ? -cx / distLen : 0f;
|
||||
float inZ = distLen > 1f ? -cz / distLen : -1f;
|
||||
|
||||
float hHere = terrain.SampleHeight(cx, cz);
|
||||
float hInward = terrain.SampleHeight(cx + inX * 26f, cz + inZ * 26f);
|
||||
|
||||
float score;
|
||||
if (spec.Tier == SpectatorTier.Patron)
|
||||
{
|
||||
// Patrons claim elevated vantage points overlooking the arena interior
|
||||
score = hHere * 2.0f + MathF.Max(0f, hHere - hInward) * 1.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Exemplars seek reverse-slope / low-profile / cover-adjacent ambush spots
|
||||
float reverseSlope = MathF.Max(0f, hInward - hHere) * 3.0f;
|
||||
float lowProfile = -hHere * 0.8f;
|
||||
float coverBonus = 0f;
|
||||
if (coverBoxes is not null)
|
||||
{
|
||||
for (int b = 0; b < coverBoxes.Count; b++)
|
||||
{
|
||||
var box = coverBoxes[b];
|
||||
float bx = box.X - cx;
|
||||
float bz = box.Z - cz;
|
||||
float bDist2 = bx * bx + bz * bz;
|
||||
if (bDist2 < 28f * 28f && bDist2 > 4f * 4f)
|
||||
{
|
||||
// Prefer cover standing between the exemplar and the interior
|
||||
float forwardDot = bx * inX + bz * inZ;
|
||||
if (forwardDot > 2f)
|
||||
{
|
||||
coverBonus = 14f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
score = reverseSlope + lowProfile + coverBonus;
|
||||
}
|
||||
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestX = cx;
|
||||
bestZ = cz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spec.NeutralAnchorX = bestX;
|
||||
spec.NeutralAnchorZ = bestZ;
|
||||
spec.NeutralAnchorSafeRadius = SafeRadius;
|
||||
spec.HasNeutralAnchor = true;
|
||||
return (bestX, bestZ);
|
||||
}
|
||||
|
||||
public int CountClearedFor(int contenderId)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var s = _spectators[i];
|
||||
if (s.Alive && s.Stance == SpectatorStance.Cleared && s.TargetContenderId == contenderId)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public int CountProvokedFor(int contenderId)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < _spectators.Count; i++)
|
||||
{
|
||||
var s = _spectators[i];
|
||||
if (s.Alive && s.Stance == SpectatorStance.Provoked && s.TargetContenderId == contenderId)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static List<ModuleSpec> RollSalvageDrops(SpectatorState spec, Random rng)
|
||||
{
|
||||
var drops = new List<ModuleSpec>();
|
||||
switch (spec.Tier)
|
||||
{
|
||||
case SpectatorTier.Tourist:
|
||||
{
|
||||
int count = rng.Next(1, 3);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
drops.Add(Catalog.ImperialModules[rng.Next(Catalog.ImperialModules.Count)]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SpectatorTier.Patron:
|
||||
{
|
||||
if (rng.NextDouble() < 0.5)
|
||||
{
|
||||
drops.Add(Catalog.ImperialModules[rng.Next(Catalog.ImperialModules.Count)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
drops.Add(Catalog.HumanModules[rng.Next(Catalog.HumanModules.Count)]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SpectatorTier.Exemplar:
|
||||
{
|
||||
if (rng.NextDouble() < 0.4)
|
||||
{
|
||||
drops.Add(Catalog.WeldedPlate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return drops;
|
||||
}
|
||||
|
||||
private void SpawnRing(Random rng, int count)
|
||||
{
|
||||
int touristCount = (int)MathF.Round(count * 0.45f);
|
||||
int patronCount = (int)MathF.Round(count * 0.35f);
|
||||
|
||||
var tiers = new List<SpectatorTier>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (i < touristCount) tiers.Add(SpectatorTier.Tourist);
|
||||
else if (i < touristCount + patronCount) tiers.Add(SpectatorTier.Patron);
|
||||
else tiers.Add(SpectatorTier.Exemplar);
|
||||
}
|
||||
|
||||
for (int i = tiers.Count - 1; i > 0; i--)
|
||||
{
|
||||
int j = rng.Next(i + 1);
|
||||
(tiers[i], tiers[j]) = (tiers[j], tiers[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
float angle = (i / (float)count) * MathF.Tau;
|
||||
float ringOffset = 25f + (float)rng.NextDouble() * 50f;
|
||||
var tier = tiers[i];
|
||||
|
||||
var spec = CreateSpectator(1000 + i, tier, angle, ringOffset);
|
||||
(float px, float pz) = GetPerimeterSlot(spec);
|
||||
spec.X = px;
|
||||
spec.Y = spec.Grid.Spec.HalfHeight + 0.1f;
|
||||
spec.Z = pz;
|
||||
spec.Yaw = MathF.Atan2(-px, -pz);
|
||||
_spectators.Add(spec);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MountRequired(ChassisGrid grid, ModuleSpec mod, string hardpointId)
|
||||
{
|
||||
if (!grid.TryMount(mod, hardpointId))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to mount '{mod.Id}' onto '{grid.Spec.Id}.{hardpointId}'.");
|
||||
}
|
||||
}
|
||||
|
||||
private static SpectatorState CreateSpectator(int id, SpectatorTier tier, float angle, float ringOffset)
|
||||
{
|
||||
switch (tier)
|
||||
{
|
||||
case SpectatorTier.Tourist:
|
||||
{
|
||||
var grid = new ChassisGrid(Catalog.Paladin);
|
||||
MountRequired(grid, Catalog.GildedLance, "hp.weapon.arm_l");
|
||||
MountRequired(grid, Catalog.ImperialAegisPd, "hp.weapon.sh_l");
|
||||
MountRequired(grid, Catalog.TouringPlasma, "hp.weapon.sh_r");
|
||||
MountRequired(grid, Catalog.NobleCore, "hp.engine.chest");
|
||||
MountRequired(grid, Catalog.GoldRadiator, "hp.radiator.back_l");
|
||||
MountRequired(grid, Catalog.GildedPlate, "hp.armor.torso");
|
||||
return new SpectatorState(
|
||||
id, tier, grid, angle, ringOffset,
|
||||
radarSignature: 1.0f,
|
||||
aimSpreadRad: 0.14f,
|
||||
maxSpeed: 18f,
|
||||
preferredRange: 95f);
|
||||
}
|
||||
case SpectatorTier.Patron:
|
||||
{
|
||||
var grid = new ChassisGrid(Catalog.Raptor);
|
||||
MountRequired(grid, Catalog.Autocannon, "hp.weapon.arm_l");
|
||||
MountRequired(grid, Catalog.Flak, "hp.weapon.arm_r");
|
||||
MountRequired(grid, Catalog.TurboCore, "hp.engine.chest");
|
||||
MountRequired(grid, Catalog.CopperRad, "hp.radiator.sh_l");
|
||||
return new SpectatorState(
|
||||
id, tier, grid, angle, ringOffset,
|
||||
radarSignature: 0.6f,
|
||||
aimSpreadRad: 0.055f,
|
||||
maxSpeed: 26f,
|
||||
preferredRange: 82f);
|
||||
}
|
||||
default: // Exemplar
|
||||
{
|
||||
var exemplarSpec = Catalog.Raptor with
|
||||
{
|
||||
Id = "exemplar_frame",
|
||||
Name = "Exemplar Frame",
|
||||
BaseCellArmor = 22f,
|
||||
MassKg = 1150f,
|
||||
BaseThrust = 26000f,
|
||||
BaseTurnRate = 6.2f,
|
||||
MaxSpeed = 40f,
|
||||
HalfWidth = 0.8f,
|
||||
HalfHeight = 1.55f,
|
||||
HalfLength = 0.8f
|
||||
};
|
||||
var grid = new ChassisGrid(exemplarSpec);
|
||||
MountRequired(grid, Catalog.GildedLance, "hp.weapon.arm_r");
|
||||
MountRequired(grid, Catalog.TouringPlasma, "hp.weapon.arm_l");
|
||||
MountRequired(grid, Catalog.NobleCore, "hp.engine.chest");
|
||||
MountRequired(grid, Catalog.GoldRadiator, "hp.radiator.sh_l");
|
||||
MountRequired(grid, Catalog.GoldRadiator, "hp.radiator.sh_r");
|
||||
return new SpectatorState(
|
||||
id, tier, grid, angle, ringOffset,
|
||||
radarSignature: 0.18f,
|
||||
aimSpreadRad: 0.006f,
|
||||
maxSpeed: 40f,
|
||||
preferredRange: 58f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,712 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public enum TerrainBrushKind
|
||||
{
|
||||
DuneRidge,
|
||||
Mesa,
|
||||
SalvagePad,
|
||||
Road,
|
||||
Crater,
|
||||
Track,
|
||||
Scorch
|
||||
}
|
||||
|
||||
public readonly record struct TerrainBrush(
|
||||
int Id,
|
||||
TerrainBrushKind Kind,
|
||||
float X,
|
||||
float Z,
|
||||
float RotationRad,
|
||||
float RadiusX,
|
||||
float RadiusZ,
|
||||
float HeightDelta,
|
||||
float Roughness,
|
||||
float Metallic,
|
||||
float AlbedoR,
|
||||
float AlbedoG,
|
||||
float AlbedoB,
|
||||
bool Dynamic);
|
||||
|
||||
public sealed class TerrainField
|
||||
{
|
||||
public const float ArenaSize = 1536f;
|
||||
public const float HalfExtent = 768f;
|
||||
public const int TileGridCount = 8;
|
||||
public const float TileSize = ArenaSize / TileGridCount; // 192m
|
||||
public const float MinWorldHeight = -18f;
|
||||
public const float MaxWorldHeight = 52f;
|
||||
public const float HeightSpan = MaxWorldHeight - MinWorldHeight; // 70m
|
||||
public const int MaxDynamicDecals = 256;
|
||||
|
||||
private readonly record struct BrushPrecomp(
|
||||
float CosR,
|
||||
float SinR,
|
||||
float InvRx,
|
||||
float InvRz,
|
||||
float MaxRadiusSq)
|
||||
{
|
||||
public static BrushPrecomp From(in TerrainBrush b)
|
||||
{
|
||||
float maxR = MathF.Max(0.1f, MathF.Max(b.RadiusX, b.RadiusZ));
|
||||
return new BrushPrecomp(
|
||||
MathF.Cos(b.RotationRad),
|
||||
MathF.Sin(b.RotationRad),
|
||||
1f / MathF.Max(0.1f, b.RadiusX),
|
||||
1f / MathF.Max(0.1f, b.RadiusZ),
|
||||
maxR * maxR);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<TerrainBrush> _brushes = new();
|
||||
private readonly List<BrushPrecomp> _brushPrecomps = new();
|
||||
private readonly List<int>[,] _tileBrushIndices = new List<int>[TileGridCount, TileGridCount];
|
||||
private readonly float[,] _tileMaxHeight = new float[TileGridCount, TileGridCount];
|
||||
private readonly Queue<int> _dynamicDecalSlots = new();
|
||||
private int _nextBrushId = 1;
|
||||
|
||||
public TerrainField(ulong seed)
|
||||
{
|
||||
Seed = seed;
|
||||
TileVersions = new int[TileGridCount, TileGridCount];
|
||||
for (int tz = 0; tz < TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TileGridCount; tx++)
|
||||
{
|
||||
_tileBrushIndices[tx, tz] = new List<int>(32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ulong Seed { get; }
|
||||
public IReadOnlyList<TerrainBrush> Brushes => _brushes;
|
||||
public int[,] TileVersions { get; }
|
||||
public ulong DirtyTileMask { get; private set; }
|
||||
|
||||
public void ClearDirtyMask() => DirtyTileMask = 0UL;
|
||||
|
||||
public IReadOnlyList<int> GetTileBrushIndices(int tx, int tz) => _tileBrushIndices[tx, tz];
|
||||
|
||||
public static TerrainField Generate(ulong seed, IReadOnlyList<ArenaBoxSpec> coverBoxes)
|
||||
{
|
||||
var field = new TerrainField(seed);
|
||||
var rng = new Random((int)(seed ^ (seed >> 32)));
|
||||
|
||||
// 1. Flat compacted salvage pads around cover ruins & center plaza (keeps cover seated cleanly near ~0m)
|
||||
field.AddBrush(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.SalvagePad,
|
||||
X: 0f,
|
||||
Z: 0f,
|
||||
RotationRad: 0f,
|
||||
RadiusX: 28f,
|
||||
RadiusZ: 28f,
|
||||
HeightDelta: 0.20f,
|
||||
Roughness: 0.90f,
|
||||
Metallic: 0.05f,
|
||||
AlbedoR: 0.44f,
|
||||
AlbedoG: 0.40f,
|
||||
AlbedoB: 0.35f,
|
||||
Dynamic: false));
|
||||
|
||||
for (int i = 0; i < coverBoxes.Count; i++)
|
||||
{
|
||||
var box = coverBoxes[i];
|
||||
float padR = MathF.Max(box.HalfX, box.HalfZ) + 12f;
|
||||
field.AddBrush(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.SalvagePad,
|
||||
X: box.X,
|
||||
Z: box.Z,
|
||||
RotationRad: 0f,
|
||||
RadiusX: padR,
|
||||
RadiusZ: padR,
|
||||
HeightDelta: 0.10f + (float)rng.NextDouble() * 0.25f,
|
||||
Roughness: 0.92f,
|
||||
Metallic: 0.04f,
|
||||
AlbedoR: 0.42f,
|
||||
AlbedoG: 0.38f,
|
||||
AlbedoB: 0.34f,
|
||||
Dynamic: false));
|
||||
}
|
||||
|
||||
// 2. Dirt track ring segments around the mid-valley loop (r ~ 260..290m)
|
||||
const int roadCount = 16;
|
||||
for (int i = 0; i < roadCount; i++)
|
||||
{
|
||||
float angle = (i / (float)roadCount) * MathF.Tau + 0.14f;
|
||||
float r = 275f + (float)(rng.NextDouble() * 20.0 - 10.0);
|
||||
float rx = MathF.Cos(angle) * r;
|
||||
float rz = MathF.Sin(angle) * r;
|
||||
float tangentRot = angle + MathF.PI * 0.5f;
|
||||
field.AddBrush(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.Road,
|
||||
X: rx,
|
||||
Z: rz,
|
||||
RotationRad: tangentRot,
|
||||
RadiusX: 64f,
|
||||
RadiusZ: 11f,
|
||||
HeightDelta: -0.22f,
|
||||
Roughness: 0.94f,
|
||||
Metallic: 0.02f,
|
||||
AlbedoR: 0.56f,
|
||||
AlbedoG: 0.40f,
|
||||
AlbedoB: 0.25f,
|
||||
Dynamic: false));
|
||||
}
|
||||
|
||||
// 3. Tall flat-topped rust mesas & buttes (+22m..+44m, radius 45..110m) for huge landmarks and full hull-down cover
|
||||
int mesaCount = 0;
|
||||
int attempts = 0;
|
||||
while (mesaCount < 14 && attempts < 500)
|
||||
{
|
||||
attempts++;
|
||||
float angle = (float)(rng.NextDouble() * MathF.Tau);
|
||||
float dist = 125f + (float)rng.NextDouble() * 520f;
|
||||
float x = MathF.Cos(angle) * dist;
|
||||
float z = MathF.Sin(angle) * dist;
|
||||
float rx = 45f + (float)rng.NextDouble() * 65f;
|
||||
float rz = 45f + (float)rng.NextDouble() * 65f;
|
||||
|
||||
if (MathF.Abs(field.SampleHeight(x, z)) > 4.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var candidate = new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.Mesa,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: (float)(rng.NextDouble() * MathF.PI),
|
||||
RadiusX: rx,
|
||||
RadiusZ: rz,
|
||||
HeightDelta: 22f + (float)rng.NextDouble() * 22f,
|
||||
Roughness: 0.86f,
|
||||
Metallic: 0.08f,
|
||||
AlbedoR: 0.48f,
|
||||
AlbedoG: 0.25f,
|
||||
AlbedoB: 0.17f,
|
||||
Dynamic: false);
|
||||
|
||||
if (!IsBrushClearOfCover(in candidate, coverBoxes))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
field.AddBrush(candidate);
|
||||
mesaCount++;
|
||||
}
|
||||
|
||||
// 4. Sweeping high sand dune ridges (+10m..+26m, RadiusX 90..180m, RadiusZ 30..65m) forming blind crests
|
||||
int duneCount = 0;
|
||||
attempts = 0;
|
||||
while (duneCount < 30 && attempts < 700)
|
||||
{
|
||||
attempts++;
|
||||
float x = (float)(rng.NextDouble() * 1280.0 - 640.0);
|
||||
float z = (float)(rng.NextDouble() * 1280.0 - 640.0);
|
||||
float radiusX = 90f + (float)rng.NextDouble() * 90f;
|
||||
float radiusZ = 30f + (float)rng.NextDouble() * 35f;
|
||||
|
||||
if (field.SampleHeight(x, z) > 15f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float heightDelta = 10f + (float)rng.NextDouble() * 16f;
|
||||
float rot = (float)(rng.NextDouble() * MathF.PI);
|
||||
var candidate = new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.DuneRidge,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: rot,
|
||||
RadiusX: radiusX,
|
||||
RadiusZ: radiusZ,
|
||||
HeightDelta: heightDelta,
|
||||
Roughness: 0.89f,
|
||||
Metallic: 0.02f,
|
||||
AlbedoR: 0.78f,
|
||||
AlbedoG: 0.56f,
|
||||
AlbedoB: 0.34f,
|
||||
Dynamic: false);
|
||||
|
||||
if (!IsBrushClearOfCover(in candidate, coverBoxes))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
field.AddBrush(candidate);
|
||||
duneCount++;
|
||||
}
|
||||
|
||||
// 5. Deep dry canyons / arroyos (-8m..-16m carved washes) letting buggies run concealed below the skyline
|
||||
int canyonCount = 0;
|
||||
attempts = 0;
|
||||
while (canyonCount < 12 && attempts < 450)
|
||||
{
|
||||
attempts++;
|
||||
float x = (float)(rng.NextDouble() * 1160.0 - 580.0);
|
||||
float z = (float)(rng.NextDouble() * 1160.0 - 580.0);
|
||||
float radiusX = 42f + (float)rng.NextDouble() * 34f;
|
||||
float radiusZ = 115f + (float)rng.NextDouble() * 85f;
|
||||
|
||||
float curH = field.SampleHeight(x, z);
|
||||
if (curH < -2.5f || curH > 12f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float heightDelta = -(8f + (float)rng.NextDouble() * 7.5f);
|
||||
float rot = (float)(rng.NextDouble() * MathF.PI);
|
||||
var candidate = new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.DuneRidge,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: rot,
|
||||
RadiusX: radiusX,
|
||||
RadiusZ: radiusZ,
|
||||
HeightDelta: heightDelta,
|
||||
Roughness: 0.96f,
|
||||
Metallic: 0.02f,
|
||||
AlbedoR: 0.54f,
|
||||
AlbedoG: 0.38f,
|
||||
AlbedoB: 0.25f,
|
||||
Dynamic: false);
|
||||
|
||||
if (!IsBrushClearOfCover(in candidate, coverBoxes))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
field.AddBrush(candidate);
|
||||
canyonCount++;
|
||||
}
|
||||
|
||||
// Bump all initial tile versions to 1 so clients detect initial bake needed
|
||||
for (int tz = 0; tz < TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TileGridCount; tx++)
|
||||
{
|
||||
field.TileVersions[tx, tz] = 1;
|
||||
field.DirtyTileMask |= 1UL << (tz * TileGridCount + tx);
|
||||
}
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
public void StampCrater(float x, float z, float radius, float depth)
|
||||
{
|
||||
float clampedR = Math.Clamp(radius, 1.2f, 16f);
|
||||
float clampedDepth = Math.Clamp(MathF.Abs(depth), 0.15f, 4.5f);
|
||||
AddBrush(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.Crater,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: 0f,
|
||||
RadiusX: clampedR,
|
||||
RadiusZ: clampedR,
|
||||
HeightDelta: -clampedDepth,
|
||||
Roughness: 0.96f,
|
||||
Metallic: 0.12f,
|
||||
AlbedoR: 0.15f,
|
||||
AlbedoG: 0.12f,
|
||||
AlbedoB: 0.10f,
|
||||
Dynamic: true));
|
||||
}
|
||||
|
||||
public void StampTrack(float x, float z, float yaw, float width, float length)
|
||||
{
|
||||
SetDynamicDecal(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.Track,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: -yaw + MathF.PI * 0.5f,
|
||||
RadiusX: Math.Clamp(length * 0.5f, 0.8f, 6f),
|
||||
RadiusZ: Math.Clamp(width * 0.5f, 0.5f, 4f),
|
||||
HeightDelta: -0.04f,
|
||||
Roughness: 0.95f,
|
||||
Metallic: 0.02f,
|
||||
AlbedoR: 0.42f,
|
||||
AlbedoG: 0.29f,
|
||||
AlbedoB: 0.18f,
|
||||
Dynamic: true));
|
||||
}
|
||||
|
||||
public void StampScorch(float x, float z, float radius)
|
||||
{
|
||||
float r = Math.Clamp(radius, 0.8f, 10f);
|
||||
SetDynamicDecal(new TerrainBrush(
|
||||
Id: 0,
|
||||
Kind: TerrainBrushKind.Scorch,
|
||||
X: x,
|
||||
Z: z,
|
||||
RotationRad: 0f,
|
||||
RadiusX: r,
|
||||
RadiusZ: r,
|
||||
HeightDelta: 0f,
|
||||
Roughness: 0.95f,
|
||||
Metallic: 0.10f,
|
||||
AlbedoR: 0.14f,
|
||||
AlbedoG: 0.11f,
|
||||
AlbedoB: 0.10f,
|
||||
Dynamic: true));
|
||||
}
|
||||
|
||||
public float SampleHeight(float x, float z)
|
||||
{
|
||||
float cx = Math.Clamp(x, -HalfExtent, HalfExtent);
|
||||
float cz = Math.Clamp(z, -HalfExtent, HalfExtent);
|
||||
WorldToTile(cx, cz, out int tx, out int tz);
|
||||
|
||||
float h = 0f;
|
||||
var indices = _tileBrushIndices[tx, tz];
|
||||
for (int i = 0; i < indices.Count; i++)
|
||||
{
|
||||
int idx = indices[i];
|
||||
var b = _brushes[idx];
|
||||
if (b.Kind == TerrainBrushKind.Scorch)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
h += EvaluateBrushHeightFast(in b, _brushPrecomps[idx], cx, cz);
|
||||
}
|
||||
|
||||
return Math.Clamp(h, MinWorldHeight, MaxWorldHeight);
|
||||
}
|
||||
|
||||
public (float Nx, float Ny, float Nz) SampleNormal(float x, float z)
|
||||
{
|
||||
const float eps = 0.5f;
|
||||
float hL = SampleHeight(x - eps, z);
|
||||
float hR = SampleHeight(x + eps, z);
|
||||
float hD = SampleHeight(x, z - eps);
|
||||
float hU = SampleHeight(x, z + eps);
|
||||
|
||||
float nx = hL - hR;
|
||||
float ny = 2f * eps;
|
||||
float nz = hD - hU;
|
||||
float len = MathF.Sqrt(nx * nx + ny * ny + nz * nz);
|
||||
if (len < 1e-5f)
|
||||
{
|
||||
return (0f, 1f, 0f);
|
||||
}
|
||||
return (nx / len, ny / len, nz / len);
|
||||
}
|
||||
|
||||
public bool Raycast(
|
||||
float ox, float oy, float oz,
|
||||
float dx, float dy, float dz,
|
||||
float maxDistance,
|
||||
out float hitX, out float hitY, out float hitZ, out float hitDist)
|
||||
{
|
||||
float prevT = 0f;
|
||||
float prevDiff = oy - SampleHeight(ox, oz);
|
||||
if (prevDiff <= 0f)
|
||||
{
|
||||
hitX = ox;
|
||||
hitY = oy;
|
||||
hitZ = oz;
|
||||
hitDist = 0f;
|
||||
return true;
|
||||
}
|
||||
|
||||
float t = 1.5f;
|
||||
while (prevT < maxDistance)
|
||||
{
|
||||
float ct = MathF.Min(t, maxDistance);
|
||||
float px = ox + dx * ct;
|
||||
float py = oy + dy * ct;
|
||||
float pz = oz + dz * ct;
|
||||
|
||||
float cx = Math.Clamp(px, -HalfExtent, HalfExtent);
|
||||
float cz = Math.Clamp(pz, -HalfExtent, HalfExtent);
|
||||
WorldToTile(cx, cz, out int tx, out int tz);
|
||||
if (py <= _tileMaxHeight[tx, tz])
|
||||
{
|
||||
float diff = py - SampleHeight(px, pz);
|
||||
if (diff <= 0f)
|
||||
{
|
||||
// Binary refine between prevT and ct
|
||||
float lo = prevT;
|
||||
float hi = ct;
|
||||
for (int iter = 0; iter < 5; iter++)
|
||||
{
|
||||
float mid = 0.5f * (lo + hi);
|
||||
float mx = ox + dx * mid;
|
||||
float my = oy + dy * mid;
|
||||
float mz = oz + dz * mid;
|
||||
if (my - SampleHeight(mx, mz) > 0f)
|
||||
{
|
||||
lo = mid;
|
||||
}
|
||||
else
|
||||
{
|
||||
hi = mid;
|
||||
}
|
||||
}
|
||||
|
||||
hitDist = 0.5f * (lo + hi);
|
||||
hitX = ox + dx * hitDist;
|
||||
hitZ = oz + dz * hitDist;
|
||||
hitY = SampleHeight(hitX, hitZ);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
prevT = ct;
|
||||
if (ct >= maxDistance)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
float step = ct < 160f ? 1.5f : 2.5f;
|
||||
if (py > _tileMaxHeight[tx, tz] + 1.5f)
|
||||
{
|
||||
float farT = MathF.Min(ct + 14f, maxDistance);
|
||||
float fx = Math.Clamp(ox + dx * farT, -HalfExtent, HalfExtent);
|
||||
float fz = Math.Clamp(oz + dz * farT, -HalfExtent, HalfExtent);
|
||||
WorldToTile(fx, fz, out int ftx, out int ftz);
|
||||
float fy = oy + dy * farT;
|
||||
if (ftx == tx && ftz == tz && fy > _tileMaxHeight[tx, tz] + 0.5f)
|
||||
{
|
||||
step = MathF.Max(step, farT - ct);
|
||||
}
|
||||
}
|
||||
t = ct + step;
|
||||
}
|
||||
|
||||
hitX = 0f;
|
||||
hitY = 0f;
|
||||
hitZ = 0f;
|
||||
hitDist = maxDistance;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static float EvaluateBrushHeightFast(in TerrainBrush b, in BrushPrecomp p, float worldX, float worldZ)
|
||||
{
|
||||
float dx = worldX - b.X;
|
||||
float dz = worldZ - b.Z;
|
||||
if (dx * dx + dz * dz >= p.MaxRadiusSq)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
float lx = dx * p.CosR + dz * p.SinR;
|
||||
float lz = -dx * p.SinR + dz * p.CosR;
|
||||
|
||||
float u = lx * p.InvRx;
|
||||
float v = lz * p.InvRz;
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1f)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return EvaluateBrushKernel(in b, u, r2);
|
||||
}
|
||||
|
||||
public static float EvaluateBrushHeight(in TerrainBrush b, float worldX, float worldZ)
|
||||
{
|
||||
float dx = worldX - b.X;
|
||||
float dz = worldZ - b.Z;
|
||||
float cosR = MathF.Cos(b.RotationRad);
|
||||
float sinR = MathF.Sin(b.RotationRad);
|
||||
float lx = dx * cosR + dz * sinR;
|
||||
float lz = -dx * sinR + dz * cosR;
|
||||
|
||||
float u = lx / MathF.Max(0.1f, b.RadiusX);
|
||||
float v = lz / MathF.Max(0.1f, b.RadiusZ);
|
||||
float r2 = u * u + v * v;
|
||||
if (r2 >= 1f)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return EvaluateBrushKernel(in b, u, r2);
|
||||
}
|
||||
|
||||
private static float EvaluateBrushKernel(in TerrainBrush b, float u, float r2)
|
||||
{
|
||||
switch (b.Kind)
|
||||
{
|
||||
case TerrainBrushKind.DuneRidge:
|
||||
{
|
||||
float env = 1f - r2;
|
||||
env *= env;
|
||||
float ridge = MathF.Max(0f, 1f - u * u);
|
||||
float asym = 1f + 0.32f * u;
|
||||
return b.HeightDelta * env * (0.35f + 0.65f * ridge) * asym;
|
||||
}
|
||||
case TerrainBrushKind.Mesa:
|
||||
{
|
||||
float r = MathF.Sqrt(r2);
|
||||
float t = Math.Clamp((1f - r) / 0.45f, 0f, 1f);
|
||||
float plateau = t * t * (3f - 2f * t);
|
||||
return b.HeightDelta * plateau;
|
||||
}
|
||||
case TerrainBrushKind.SalvagePad:
|
||||
case TerrainBrushKind.Road:
|
||||
case TerrainBrushKind.Track:
|
||||
{
|
||||
float env = 1f - r2;
|
||||
return b.HeightDelta * env * env;
|
||||
}
|
||||
case TerrainBrushKind.Crater:
|
||||
{
|
||||
float r = MathF.Sqrt(r2);
|
||||
float depth = MathF.Abs(b.HeightDelta);
|
||||
float pitT = Math.Clamp(1f - r / 0.62f, 0f, 1f);
|
||||
float pit = -depth * pitT * pitT * (3f - 2f * pitT);
|
||||
float rimT = MathF.Sin(MathF.PI * Math.Clamp((r - 0.55f) / 0.45f, 0f, 1f));
|
||||
float rim = (0.32f * depth) * rimT * rimT;
|
||||
return pit + rim;
|
||||
}
|
||||
default:
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
private TerrainBrush AddBrush(TerrainBrush template)
|
||||
{
|
||||
var brush = template with { Id = _nextBrushId++ };
|
||||
int index = _brushes.Count;
|
||||
_brushes.Add(brush);
|
||||
_brushPrecomps.Add(BrushPrecomp.From(in brush));
|
||||
RegisterBrushInTiles(index, in brush, incrementTileVersion: true);
|
||||
return brush;
|
||||
}
|
||||
|
||||
private TerrainBrush SetDynamicDecal(TerrainBrush template)
|
||||
{
|
||||
var brush = template with { Id = _nextBrushId++ };
|
||||
if (_dynamicDecalSlots.Count >= MaxDynamicDecals)
|
||||
{
|
||||
int slot = _dynamicDecalSlots.Dequeue();
|
||||
var prev = _brushes[slot];
|
||||
UnregisterBrushFromTiles(slot, in prev);
|
||||
_brushes[slot] = brush;
|
||||
_brushPrecomps[slot] = BrushPrecomp.From(in brush);
|
||||
RegisterBrushInTiles(slot, in brush, incrementTileVersion: true);
|
||||
_dynamicDecalSlots.Enqueue(slot);
|
||||
return brush;
|
||||
}
|
||||
|
||||
int index = _brushes.Count;
|
||||
_brushes.Add(brush);
|
||||
_brushPrecomps.Add(BrushPrecomp.From(in brush));
|
||||
RegisterBrushInTiles(index, in brush, incrementTileVersion: true);
|
||||
_dynamicDecalSlots.Enqueue(index);
|
||||
return brush;
|
||||
}
|
||||
|
||||
private static float GetBrushMaxPositiveHeight(in TerrainBrush b) => b.Kind switch
|
||||
{
|
||||
TerrainBrushKind.DuneRidge => b.HeightDelta > 0f ? b.HeightDelta * 1.33f : 0f,
|
||||
TerrainBrushKind.Mesa => b.HeightDelta > 0f ? b.HeightDelta : 0f,
|
||||
TerrainBrushKind.SalvagePad or TerrainBrushKind.Road or TerrainBrushKind.Track => b.HeightDelta > 0f ? b.HeightDelta : 0f,
|
||||
TerrainBrushKind.Crater => 0.33f * MathF.Abs(b.HeightDelta),
|
||||
_ => 0f
|
||||
};
|
||||
|
||||
private void RecomputeTileMaxHeight(int tx, int tz)
|
||||
{
|
||||
float sum = 0f;
|
||||
var indices = _tileBrushIndices[tx, tz];
|
||||
for (int i = 0; i < indices.Count; i++)
|
||||
{
|
||||
sum += GetBrushMaxPositiveHeight(_brushes[indices[i]]);
|
||||
}
|
||||
_tileMaxHeight[tx, tz] = Math.Min(MaxWorldHeight, sum + 0.05f);
|
||||
}
|
||||
|
||||
private void RegisterBrushInTiles(int index, in TerrainBrush brush, bool incrementTileVersion)
|
||||
{
|
||||
float maxPos = GetBrushMaxPositiveHeight(in brush);
|
||||
GetBrushTileBounds(in brush, out int minTx, out int maxTx, out int minTz, out int maxTz);
|
||||
for (int tz = minTz; tz <= maxTz; tz++)
|
||||
{
|
||||
for (int tx = minTx; tx <= maxTx; tx++)
|
||||
{
|
||||
_tileBrushIndices[tx, tz].Add(index);
|
||||
_tileMaxHeight[tx, tz] = Math.Min(MaxWorldHeight, _tileMaxHeight[tx, tz] + maxPos + 0.05f);
|
||||
if (incrementTileVersion)
|
||||
{
|
||||
TileVersions[tx, tz]++;
|
||||
DirtyTileMask |= 1UL << (tz * TileGridCount + tx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UnregisterBrushFromTiles(int index, in TerrainBrush brush)
|
||||
{
|
||||
GetBrushTileBounds(in brush, out int minTx, out int maxTx, out int minTz, out int maxTz);
|
||||
for (int tz = minTz; tz <= maxTz; tz++)
|
||||
{
|
||||
for (int tx = minTx; tx <= maxTx; tx++)
|
||||
{
|
||||
_tileBrushIndices[tx, tz].Remove(index);
|
||||
RecomputeTileMaxHeight(tx, tz);
|
||||
TileVersions[tx, tz]++;
|
||||
DirtyTileMask |= 1UL << (tz * TileGridCount + tx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetBrushTileBounds(in TerrainBrush brush, out int minTx, out int maxTx, out int minTz, out int maxTz)
|
||||
{
|
||||
const float gutterPaddingMeters = 3.5f;
|
||||
float extent = MathF.Sqrt(brush.RadiusX * brush.RadiusX + brush.RadiusZ * brush.RadiusZ) + gutterPaddingMeters;
|
||||
float minX = brush.X - extent;
|
||||
float maxX = brush.X + extent;
|
||||
float minZ = brush.Z - extent;
|
||||
float maxZ = brush.Z + extent;
|
||||
|
||||
WorldToTile(Math.Clamp(minX, -HalfExtent, HalfExtent), Math.Clamp(minZ, -HalfExtent, HalfExtent), out minTx, out minTz);
|
||||
WorldToTile(Math.Clamp(maxX, -HalfExtent, HalfExtent), Math.Clamp(maxZ, -HalfExtent, HalfExtent), out maxTx, out maxTz);
|
||||
}
|
||||
|
||||
public static void WorldToTile(float x, float z, out int tx, out int tz)
|
||||
{
|
||||
float nx = (x + HalfExtent) / TileSize;
|
||||
float nz = (z + HalfExtent) / TileSize;
|
||||
tx = Math.Clamp((int)MathF.Floor(nx), 0, TileGridCount - 1);
|
||||
tz = Math.Clamp((int)MathF.Floor(nz), 0, TileGridCount - 1);
|
||||
}
|
||||
|
||||
private static bool IsBrushClearOfCover(in TerrainBrush candidate, IReadOnlyList<ArenaBoxSpec> coverBoxes)
|
||||
{
|
||||
if (MathF.Abs(EvaluateBrushHeight(in candidate, 0f, 0f)) > 0.25f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const float margin = 2.0f;
|
||||
for (int i = 0; i < coverBoxes.Count; i++)
|
||||
{
|
||||
var c = coverBoxes[i];
|
||||
float hx = c.HalfX + margin;
|
||||
float hz = c.HalfZ + margin;
|
||||
|
||||
if (MathF.Abs(EvaluateBrushHeight(in candidate, c.X, c.Z)) > 0.25f ||
|
||||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X - hx, c.Z - hz)) > 0.25f ||
|
||||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X + hx, c.Z - hz)) > 0.25f ||
|
||||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X - hx, c.Z + hz)) > 0.25f ||
|
||||
MathF.Abs(EvaluateBrushHeight(in candidate, c.X + hx, c.Z + hz)) > 0.25f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public static class VehicleCatalogLoader
|
||||
{
|
||||
public static string LocateVehiclesDirectory()
|
||||
{
|
||||
string? envRoot = Environment.GetEnvironmentVariable("RTD_ASSETS_DIR");
|
||||
if (!string.IsNullOrWhiteSpace(envRoot))
|
||||
{
|
||||
string envVehicles = Path.Combine(envRoot, "vehicles");
|
||||
if (HasVehiclePackages(envVehicles))
|
||||
{
|
||||
return Path.GetFullPath(envVehicles);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string start in new[] { AppContext.BaseDirectory, Directory.GetCurrentDirectory() })
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(start) || !Directory.Exists(start))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dir = new DirectoryInfo(Path.GetFullPath(start));
|
||||
while (dir is not null)
|
||||
{
|
||||
string candidate = Path.Combine(dir.FullName, "assets", "vehicles");
|
||||
if (HasVehiclePackages(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException(
|
||||
$"Could not locate 'assets/vehicles' containing vehicle.cc packages from BaseDirectory '{AppContext.BaseDirectory}' or CurrentDirectory '{Directory.GetCurrentDirectory()}'.");
|
||||
}
|
||||
|
||||
private static bool HasVehiclePackages(string vehiclesDir)
|
||||
{
|
||||
if (!Directory.Exists(vehiclesDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Directory.EnumerateFiles(vehiclesDir, "vehicle.cc", SearchOption.AllDirectories).Any();
|
||||
}
|
||||
|
||||
public static IReadOnlyList<(VehiclePackage Package, ChassisSpec Spec)> LoadAll(string? vehiclesDirectory = null)
|
||||
{
|
||||
string root = vehiclesDirectory ?? LocateVehiclesDirectory();
|
||||
if (!Directory.Exists(root))
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Vehicles directory not found: {root}");
|
||||
}
|
||||
|
||||
var results = new List<(VehiclePackage Package, ChassisSpec Spec)>();
|
||||
foreach (string dir in Directory.GetDirectories(root).OrderBy(d => d, StringComparer.Ordinal))
|
||||
{
|
||||
string ccPath = Path.Combine(dir, "vehicle.cc");
|
||||
if (!File.Exists(ccPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var pkg = VehiclePackageStore.Read(ccPath);
|
||||
var spec = pkg.ToChassisSpec();
|
||||
results.Add((pkg, spec));
|
||||
}
|
||||
|
||||
if (results.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"No vehicle.cc archives found under {root}.");
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,339 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using MessagePack;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
[CultDocument("rtd.vehicle_package", "1"), MessagePackObject]
|
||||
public sealed class VehiclePackage
|
||||
{
|
||||
[CultName, Key(0)] public string Id { get; set; } = string.Empty;
|
||||
[Key(1)] public string Name { get; set; } = string.Empty;
|
||||
[Key(2)] public string VehicleClass { get; set; } = string.Empty;
|
||||
[Key(3)] public MobilityKind Mobility { get; set; }
|
||||
[Key(4)] public GridPlane Plane { get; set; }
|
||||
[Key(5)] public int GridWidth { get; set; }
|
||||
[Key(6)] public int GridHeight { get; set; }
|
||||
[Key(7)] public string[] Mask { get; set; } = Array.Empty<string>();
|
||||
[Key(8)] public float MassKg { get; set; }
|
||||
[Key(9)] public float MaxSpeed { get; set; }
|
||||
[Key(10)] public float TurnRate { get; set; }
|
||||
[Key(11)] public float ThrustNewtons { get; set; }
|
||||
[Key(12)] public float HoverMaxAltitudeM { get; set; }
|
||||
[Key(13)] public float ArmorPerCell { get; set; }
|
||||
[Key(14)] public float Conductivity { get; set; }
|
||||
[Key(15)] public int CargoCapacity { get; set; }
|
||||
[Key(16)] public float HalfWidth { get; set; }
|
||||
[Key(17)] public float HalfHeight { get; set; }
|
||||
[Key(18)] public float HalfLength { get; set; }
|
||||
[Key(19)] public string ModelAsset { get; set; } = string.Empty;
|
||||
[Key(20)] public Dictionary<string, string> DefaultLoadout { get; set; } = new();
|
||||
[Key(21)] public List<VehicleHardpointRecord> Hardpoints { get; set; } = new();
|
||||
[Key(22)] public List<VehicleJointRecord> Joints { get; set; } = new();
|
||||
[Key(23)] public VehicleMechanismsRecord? Mechanisms { get; set; }
|
||||
[Key(24)] public List<VehiclePartCellRecord> PartCells { get; set; } = new();
|
||||
[Key(25)] public float BaseCellThermalMass { get; set; } = 12f;
|
||||
|
||||
public ChassisSpec ToChassisSpec()
|
||||
{
|
||||
bool[] boolMask = ParseMaskRows(Mask, GridWidth, GridHeight);
|
||||
var hps = new HardpointSpec[Hardpoints.Count];
|
||||
for (int i = 0; i < Hardpoints.Count; i++)
|
||||
{
|
||||
var hp = Hardpoints[i];
|
||||
hps[i] = new HardpointSpec(
|
||||
Id: hp.Id,
|
||||
Kind: hp.Kind,
|
||||
X: hp.X,
|
||||
Y: hp.Y,
|
||||
Width: hp.W,
|
||||
Height: hp.H,
|
||||
ArmorBonus: hp.ArmorBonus,
|
||||
MinPitchDeg: hp.MinPitchDeg,
|
||||
MaxPitchDeg: hp.MaxPitchDeg,
|
||||
IsWideArc: hp.IsWideArc);
|
||||
}
|
||||
|
||||
return new ChassisSpec(
|
||||
Id: Id,
|
||||
Name: Name,
|
||||
Plane: Plane,
|
||||
Width: GridWidth,
|
||||
Height: GridHeight,
|
||||
Mask: boolMask,
|
||||
Hardpoints: hps,
|
||||
HullConductivity: Conductivity,
|
||||
BaseCellThermalMass: BaseCellThermalMass,
|
||||
BaseCellArmor: ArmorPerCell,
|
||||
MassKg: MassKg,
|
||||
BaseThrust: ThrustNewtons,
|
||||
BaseTurnRate: TurnRate,
|
||||
MaxSpeed: MaxSpeed,
|
||||
HalfWidth: HalfWidth,
|
||||
HalfHeight: HalfHeight,
|
||||
HalfLength: HalfLength,
|
||||
CargoCapacity: CargoCapacity,
|
||||
Mobility: Mobility,
|
||||
HoverMaxAltitudeM: HoverMaxAltitudeM,
|
||||
VehicleClass: VehicleClass);
|
||||
}
|
||||
|
||||
public static bool[] ParseMaskRows(string[] rows, int width, int height)
|
||||
{
|
||||
if (rows.Length != height)
|
||||
{
|
||||
throw new InvalidOperationException($"Mask row count {rows.Length} != GridHeight {height}.");
|
||||
}
|
||||
|
||||
var mask = new bool[width * height];
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
if (rows[y].Length != width)
|
||||
{
|
||||
throw new InvalidOperationException($"Mask row {y} length {rows[y].Length} != GridWidth {width}.");
|
||||
}
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
mask[y * width + x] = rows[y][x] == '#';
|
||||
}
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class VehicleHardpointRecord
|
||||
{
|
||||
[Key(0)] public string Id { get; set; } = string.Empty;
|
||||
[Key(1)] public string AnchorId { get; set; } = string.Empty;
|
||||
[Key(2)] public HardpointKind Kind { get; set; }
|
||||
[Key(3)] public int X { get; set; }
|
||||
[Key(4)] public int Y { get; set; }
|
||||
[Key(5)] public int W { get; set; }
|
||||
[Key(6)] public int H { get; set; }
|
||||
[Key(7)] public float MinPitchDeg { get; set; }
|
||||
[Key(8)] public float MaxPitchDeg { get; set; }
|
||||
[Key(9)] public bool IsWideArc { get; set; }
|
||||
[Key(10)] public float ArmorBonus { get; set; }
|
||||
[Key(11), CultElementId(nameof(Id))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class VehicleJointRecord
|
||||
{
|
||||
[Key(0)] public string Id { get; set; } = string.Empty;
|
||||
[Key(1)] public string NodeName { get; set; } = string.Empty;
|
||||
[Key(2)] public float[] Axis { get; set; } = Array.Empty<float>();
|
||||
[Key(3)] public float MinVal { get; set; }
|
||||
[Key(4)] public float MaxVal { get; set; }
|
||||
[Key(5), CultElementId(nameof(Id))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class VehiclePartCellRecord
|
||||
{
|
||||
[Key(0)] public string NodeName { get; set; } = string.Empty;
|
||||
[Key(1)] public int CellX { get; set; }
|
||||
[Key(2)] public int CellY { get; set; }
|
||||
[Key(3)] public string Kind { get; set; } = string.Empty;
|
||||
[Key(4), CultElementId] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class VehicleMechanismsRecord
|
||||
{
|
||||
[Key(0)] public string Frame { get; set; } = string.Empty;
|
||||
[Key(1)] public float[] RootOrigin { get; set; } = Array.Empty<float>();
|
||||
[Key(2)] public List<MechanismDofRecord> Dofs { get; set; } = new();
|
||||
[Key(3)] public List<MechanismRamRecord> Rams { get; set; } = new();
|
||||
[Key(4)] public List<MechanismScissorRecord> Scissors { get; set; } = new();
|
||||
[Key(5)] public List<MechanismStrutRecord> Struts { get; set; } = new();
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class MechanismDofRecord
|
||||
{
|
||||
[Key(0)] public string Name { get; set; } = string.Empty;
|
||||
[Key(1)] public int Parent { get; set; }
|
||||
[Key(2)] public string Kind { get; set; } = string.Empty;
|
||||
[Key(3)] public string? Mechanism { get; set; }
|
||||
[Key(4)] public string? Side { get; set; }
|
||||
[Key(5)] public float[] Origin { get; set; } = Array.Empty<float>();
|
||||
[Key(6)] public float[] Axis { get; set; } = Array.Empty<float>();
|
||||
[Key(7)] public float Lo { get; set; }
|
||||
[Key(8)] public float Hi { get; set; }
|
||||
[Key(9)] public int Depth { get; set; }
|
||||
[Key(10)] public string? StoppedBy { get; set; }
|
||||
[Key(11)] public float? ComplianceDampingRatio { get; set; }
|
||||
[Key(12)] public float? ComplianceHertz { get; set; }
|
||||
[Key(13), CultElementId(nameof(Name))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class MechanismRamRecord
|
||||
{
|
||||
[Key(0)] public string Name { get; set; } = string.Empty;
|
||||
[Key(1)] public string BarrelBone { get; set; } = string.Empty;
|
||||
[Key(2)] public string RodBone { get; set; } = string.Empty;
|
||||
[Key(3)] public string[] Spans { get; set; } = Array.Empty<string>();
|
||||
[Key(4)] public float Bore { get; set; }
|
||||
[Key(5)] public float Body { get; set; }
|
||||
[Key(6)] public float Inner { get; set; }
|
||||
[Key(7)] public float Extension { get; set; }
|
||||
[Key(8)] public float Rest { get; set; }
|
||||
[Key(9)] public float[] Stroke { get; set; } = Array.Empty<float>();
|
||||
[Key(10)] public int? AParentDof { get; set; }
|
||||
[Key(11)] public float[]? APos { get; set; }
|
||||
[Key(12)] public int? BParentDof { get; set; }
|
||||
[Key(13)] public float[]? BPos { get; set; }
|
||||
[Key(14)] public float[]? PinDir { get; set; }
|
||||
[Key(15), CultElementId(nameof(Name))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class MechanismScissorRecord
|
||||
{
|
||||
[Key(0)] public string Name { get; set; } = string.Empty;
|
||||
[Key(1)] public string UpperBone { get; set; } = string.Empty;
|
||||
[Key(2)] public string LowerBone { get; set; } = string.Empty;
|
||||
[Key(3)] public float Arm { get; set; }
|
||||
[Key(4)] public int? AParentDof { get; set; }
|
||||
[Key(5)] public float[]? APos { get; set; }
|
||||
[Key(6)] public int? BParentDof { get; set; }
|
||||
[Key(7)] public float[]? BPos { get; set; }
|
||||
[Key(8)] public float[]? OutDir { get; set; }
|
||||
[Key(9), CultElementId(nameof(Name))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class MechanismStrutRecord
|
||||
{
|
||||
[Key(0)] public string Name { get; set; } = string.Empty;
|
||||
[Key(1)] public string? Side { get; set; }
|
||||
[Key(2)] public string Dof { get; set; } = string.Empty;
|
||||
[Key(3)] public float Travel { get; set; }
|
||||
[Key(4)] public float Hertz { get; set; }
|
||||
[Key(5)] public float DampingRatio { get; set; }
|
||||
[Key(6), CultElementId(nameof(Name))] public string ElementId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public static class VehiclePackageStore
|
||||
{
|
||||
public static CultDocumentRegistry Registry { get; } =
|
||||
CultDocumentRegistry.ForTypes(new[] { typeof(VehiclePackage) });
|
||||
|
||||
public static CultRecordKey PackageKey(string id) => new("vehicle:" + id);
|
||||
|
||||
public static CultCache Open(string path, bool writable = false)
|
||||
{
|
||||
var options = new CultCacheOpenOptions
|
||||
{
|
||||
Registry = Registry,
|
||||
ReadOnly = !writable,
|
||||
FlushOnDispose = false,
|
||||
StoreFlushOnDispose = false,
|
||||
UseDirectoryStore = false
|
||||
};
|
||||
return CultCacheMessagePack.Create(path, options);
|
||||
}
|
||||
|
||||
public static VehiclePackage Read(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException($"Vehicle package archive not found: {path}", path);
|
||||
}
|
||||
|
||||
using var cache = Open(path, writable: false);
|
||||
var records = cache.GetAll<VehiclePackage>().ToArray();
|
||||
if (records.Length != 1)
|
||||
{
|
||||
throw new InvalidOperationException($"{path} must contain exactly 1 VehiclePackage record, found {records.Length}.");
|
||||
}
|
||||
|
||||
var pkg = records[0];
|
||||
Validate(pkg, path);
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public static void Write(string path, VehiclePackage pkg)
|
||||
{
|
||||
if (pkg is null) throw new ArgumentNullException(nameof(pkg));
|
||||
Validate(pkg, path);
|
||||
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string dir = Path.GetDirectoryName(fullPath) ?? ".";
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
string workspace = fullPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
|
||||
string tempFile = Path.Combine(workspace, "vehicle.cc");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(workspace);
|
||||
using (var cache = Open(tempFile, writable: true))
|
||||
{
|
||||
cache.UpsertAsync(typeof(VehiclePackage), pkg, PackageKey(pkg.Id)).GetAwaiter().GetResult();
|
||||
cache.FlushAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
if (File.Exists(fullPath))
|
||||
{
|
||||
File.Replace(tempFile, fullPath, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Move(tempFile, fullPath);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(workspace))
|
||||
{
|
||||
Directory.Delete(workspace, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Validate(VehiclePackage pkg, string sourcePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pkg.Id))
|
||||
throw new InvalidOperationException($"{sourcePath}: VehiclePackage.Id is empty.");
|
||||
if (string.IsNullOrWhiteSpace(pkg.ModelAsset))
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: ModelAsset is empty.");
|
||||
if (pkg.GridWidth <= 0 || pkg.GridHeight <= 0)
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: invalid grid dimensions {pkg.GridWidth}x{pkg.GridHeight}.");
|
||||
|
||||
bool[] mask = VehiclePackage.ParseMaskRows(pkg.Mask, pkg.GridWidth, pkg.GridHeight);
|
||||
foreach (var hp in pkg.Hardpoints)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(hp.Id) || string.IsNullOrWhiteSpace(hp.AnchorId))
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: hardpoint has empty Id or AnchorId.");
|
||||
if (hp.X < 0 || hp.Y < 0 || hp.W <= 0 || hp.H <= 0 || hp.X + hp.W > pkg.GridWidth || hp.Y + hp.H > pkg.GridHeight)
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: hardpoint {hp.Id} out of grid bounds.");
|
||||
for (int cy = hp.Y; cy < hp.Y + hp.H; cy++)
|
||||
{
|
||||
for (int cx = hp.X; cx < hp.X + hp.W; cx++)
|
||||
{
|
||||
if (!mask[cy * pkg.GridWidth + cx])
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: hardpoint {hp.Id} covers inactive cell ({cx},{cy}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pkg.PartCells.Count == 0)
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: PartCells is empty.");
|
||||
|
||||
foreach (var pc in pkg.PartCells)
|
||||
{
|
||||
if (pc.CellX < 0 || pc.CellX >= pkg.GridWidth || pc.CellY < 0 || pc.CellY >= pkg.GridHeight || !mask[pc.CellY * pkg.GridWidth + pc.CellX])
|
||||
{
|
||||
throw new InvalidOperationException($"{sourcePath}: {pkg.Id}: PartCell '{pc.NodeName}' mapped to inactive/out-of-bounds cell ({pc.CellX},{pc.CellY}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,14 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RustToDust.Core\RustToDust.Core.csproj" />
|
||||
<ProjectReference Include="$(YmirRoot)/src/Ymir.Box3D/Ymir.Box3D.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
using System;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class ArenaSessionTests
|
||||
{
|
||||
[Fact]
|
||||
public void DrivingAndFiring_MovesBuggyInYmirAndBuildsWeaponHeat()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
var player = session.State.Player;
|
||||
float startX = player.X;
|
||||
float startZ = player.Z;
|
||||
float startYaw = player.Yaw;
|
||||
int tracerTicks = 0;
|
||||
|
||||
for (int tick = 0; tick < 120; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0.45f,
|
||||
AimWorldX: player.X + 40f,
|
||||
AimWorldZ: player.Z + 10f,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
|
||||
if (session.State.Tracers.Count > 0)
|
||||
{
|
||||
tracerTicks++;
|
||||
}
|
||||
}
|
||||
|
||||
float dx = player.X - startX;
|
||||
float dz = player.Z - startZ;
|
||||
float displacement = MathF.Sqrt(dx * dx + dz * dz);
|
||||
float yawDelta = MathF.Abs(MatchRules.NormalizeAngle(player.Yaw - startYaw));
|
||||
|
||||
Assert.True(displacement > 10f, $"Expected >10m displacement, got {displacement:F2}m");
|
||||
Assert.True(yawDelta > 0.2f, $"Expected yaw change >0.2 rad, got {yawDelta:F2} rad");
|
||||
|
||||
var weapon = player.Grid.GetMountedOn("hp.weapon.roof");
|
||||
Assert.NotNull(weapon);
|
||||
Assert.True(weapon!.CurrentTemp > ChassisGrid.AmbientTemp + 5f);
|
||||
Assert.True(tracerTicks > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChassisSwap_ToManticoreAndRaptor_ReplacesBodyWithoutLeakingYmirLanes()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 77);
|
||||
var player = session.State.Player;
|
||||
int initialFreeSlots = session.World.FreeBodySlots;
|
||||
|
||||
// Step once to settle world
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
|
||||
// Spawn Manticore (Dorsal) right beside player and swap
|
||||
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Manticore);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal("manticore", player.Grid.Spec.Id);
|
||||
Assert.Equal(GridPlane.Dorsal, player.Grid.Spec.Plane);
|
||||
|
||||
// Step so Ymir reclaims old tombstone lane
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
|
||||
|
||||
// Now spawn Raptor (Coronal) beside player and swap
|
||||
session.State.SpawnChassisDrop(player.X + 1f, player.Z + 1f, Catalog.Raptor);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal("raptor", player.Grid.Spec.Id);
|
||||
Assert.Equal(GridPlane.Coronal, player.Grid.Spec.Plane);
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, 0f, 0f, false, false, false));
|
||||
Assert.Equal(initialFreeSlots, session.World.FreeBodySlots);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Raycast_RespectsStaticCoverWalls()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12);
|
||||
var c0 = session.State.ArenaCoverBoxes[0];
|
||||
float rayStartZ = c0.Z - c0.HalfZ - 5f;
|
||||
float raySpanZ = c0.HalfZ * 2f + 10f;
|
||||
|
||||
// A ray from one side of cover block #0 to the other must hit the static cover wall!
|
||||
var blockedHit = session.World.CastRayClosest((c0.X, c0.Y, rayStartZ), (0f, 0f, raySpanZ));
|
||||
Assert.True(blockedHit.Hit);
|
||||
Assert.True(blockedHit.Point.Z < c0.Z, $"Expected cover hit before z={c0.Z:F2}, got z={blockedHit.Point.Z:F2}");
|
||||
Assert.InRange(blockedHit.StableId, 10UL, 99UL); // Static cover StableId range
|
||||
|
||||
// Ray high above the cover block passes unobstructed
|
||||
var clearHit = session.World.CastRayClosest((c0.X, c0.Y + c0.HalfY + 2.0f, rayStartZ), (0f, 0f, raySpanZ));
|
||||
Assert.False(clearHit.Hit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BroadsideFire_UsesDirectionalSupportRadiusNotMaxExtent()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 19);
|
||||
var player = session.State.Player;
|
||||
|
||||
// Swap to Tank / Anvil (HalfWidth = 1.93m, HalfLength = 2.83m) where broadside vs forward differs by ~0.9m.
|
||||
session.State.SpawnChassisDrop(player.X + 0.5f, player.Z + 0.5f, Catalog.Tank);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal(Catalog.Tank.Id, player.Grid.Spec.Id);
|
||||
|
||||
// Step once to settle body, then aim strictly perpendicular (broadside) to player's Yaw.
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, false));
|
||||
float broadsideX = MathF.Cos(player.Yaw);
|
||||
float broadsideZ = -MathF.Sin(player.Yaw);
|
||||
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: player.X + broadsideX * 30f,
|
||||
AimWorldZ: player.Z + broadsideZ * 30f,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true));
|
||||
|
||||
Assert.NotEmpty(session.State.Tracers);
|
||||
var tracer = session.State.Tracers[^1];
|
||||
float dx = tracer.StartX - player.X;
|
||||
float dz = tracer.StartZ - player.Z;
|
||||
float muzzleHorizDist = MathF.Sqrt(dx * dx + dz * dz);
|
||||
|
||||
// Expected broadside clearance = HalfWidth (1.65) + 0.35 = 2.00m (well below HalfLength + 0.55 = 3.20m)
|
||||
Assert.InRange(muzzleHorizDist, player.Grid.Spec.HalfWidth + 0.25f, player.Grid.Spec.HalfWidth + 0.50f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,424 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class DetectionLosTests
|
||||
{
|
||||
private static TerrainBrush FindTallMesa(TerrainField terrain)
|
||||
{
|
||||
for (int i = 0; i < terrain.Brushes.Count; i++)
|
||||
{
|
||||
var b = terrain.Brushes[i];
|
||||
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
throw new InvalidOperationException("Expected at least one tall Mesa in generated terrain.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MesaBetweenSpectatorAndContender_BlocksLosAndPreventsFiringThroughTerrain()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
var mesa = FindTallMesa(session.State.Terrain);
|
||||
var player = session.State.Player;
|
||||
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
|
||||
|
||||
// Place player and spectator on opposite sides of the tall mesa
|
||||
float playerX = mesa.X - mesa.RadiusX - 18f;
|
||||
float specX = mesa.X + mesa.RadiusX + 18f;
|
||||
session.SetContenderPose(player.Id, playerX, mesa.Z);
|
||||
session.SetSpectatorPose(spec.Id, specX, mesa.Z);
|
||||
|
||||
// Provoke this spectator onto the player so it actively hunts, while terrain blocks sightline
|
||||
session.State.Spectators.OnSpectatorDamaged(spec, player.Id);
|
||||
float initialCoreHp = player.Grid.CoreHp;
|
||||
|
||||
for (int tick = 0; tick < 10; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
|
||||
Assert.False(session.HasLineOfSight(
|
||||
spec.X, MatchRules.GetObserverEyeY(spec.Y, spec.Grid.Spec.HalfHeight), spec.Z,
|
||||
player.X, MatchRules.GetTargetAimY(player.Y, player.Grid.Spec.HalfHeight), player.Z));
|
||||
Assert.False(spec.HasTargetLos);
|
||||
|
||||
MatchRules.ComputeSpectatorBehavior(spec, session.State, out _, out _, out _, out _, out bool shouldFire);
|
||||
Assert.False(shouldFire, "Occluded spectator must NOT fire through a mesa");
|
||||
}
|
||||
|
||||
Assert.Equal(initialCoreHp, player.Grid.CoreHp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CrestingRidge_RestoresLosAndAllowsSpectatorEngagement()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
var mesa = FindTallMesa(session.State.Terrain);
|
||||
var player = session.State.Player;
|
||||
var spec = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Patron);
|
||||
|
||||
// Start occluded across the mesa
|
||||
session.SetContenderPose(player.Id, mesa.X - mesa.RadiusX - 18f, mesa.Z);
|
||||
session.SetSpectatorPose(spec.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
|
||||
session.State.Spectators.OnSpectatorDamaged(spec, player.Id);
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
Assert.False(spec.HasTargetLos);
|
||||
|
||||
// Now player crests onto the high mesa plateau overlooking the spectator
|
||||
session.SetContenderPose(player.Id, mesa.X + mesa.RadiusX * 0.25f, mesa.Z);
|
||||
session.SetSpectatorPose(spec.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
|
||||
|
||||
bool sawTracer = false;
|
||||
for (int tick = 0; tick < 30; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
if (session.State.Tracers.Count > 0)
|
||||
{
|
||||
sawTracer = true;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(spec.HasTargetLos, "Cresting the mesa must restore spectator LOS");
|
||||
MatchRules.ComputeSpectatorBehavior(spec, session.State, out _, out _, out _, out _, out bool shouldFire);
|
||||
Assert.True(shouldFire, "Spectator with restored LOS within range should be cleared to fire");
|
||||
Assert.True(sawTracer, "Expected spectator to fire weapons once LOS was restored");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LowSignatureExemplar_HiddenBehindRidge_IsInvisibleOnRadar_WhileInLosContactIsVisible()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
var mesa = FindTallMesa(session.State.Terrain);
|
||||
var player = session.State.Player;
|
||||
var exemplar = session.State.Spectators.Spectators.First(s => s.Tier == SpectatorTier.Exemplar);
|
||||
var visibleRival = session.State.Contenders[1];
|
||||
|
||||
Assert.True(exemplar.RadarSignature <= 0.25f);
|
||||
|
||||
// Reset memory so exemplar has never been seen yet, then hide it on the far side of the mesa
|
||||
session.State.SpectatorContacts[exemplar.Id] = new PlayerContactMemory();
|
||||
session.SetContenderPose(player.Id, mesa.X - mesa.RadiusX - 18f, mesa.Z);
|
||||
session.SetSpectatorPose(exemplar.Id, mesa.X + mesa.RadiusX + 18f, mesa.Z);
|
||||
|
||||
// Place rival contender nearby in clear open LOS on the player's side of the mesa
|
||||
session.SetContenderPose(visibleRival.Id, mesa.X - mesa.RadiusX - 50f, mesa.Z + 12f);
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
|
||||
var exMem = session.State.SpectatorContacts[exemplar.Id];
|
||||
Assert.False(exMem.VisibleToPlayer);
|
||||
Assert.False(exMem.FaintHorizonPing);
|
||||
Assert.False(MatchState.IsContactOnRadar(exMem), "Hidden low-signature Exemplar must vanish off player radar");
|
||||
|
||||
var rivalMem = session.State.ContenderContacts[visibleRival.Id];
|
||||
Assert.True(rivalMem.VisibleToPlayer, "In-LOS contact must be live-visible to player");
|
||||
Assert.True(MatchState.IsContactOnRadar(rivalMem));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaticCoverWall_BlocksLineOfSight()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 12);
|
||||
var box = session.State.ArenaCoverBoxes[0];
|
||||
var player = session.State.Player;
|
||||
var rival = session.State.Contenders[1];
|
||||
|
||||
// Ensure rival is a low-profile ground vehicle shorter than the 4m ruin cover wall
|
||||
if (rival.Grid.Spec.IsVtol || rival.Grid.Spec.HalfHeight * 2f >= box.HalfY * 2f)
|
||||
{
|
||||
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
|
||||
session.State.SpawnChassisDrop(box.X, box.Z + box.HalfZ + 4f, Catalog.Jackal);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(rival.Id));
|
||||
}
|
||||
|
||||
session.SetContenderPose(player.Id, box.X, box.Z - box.HalfZ - 4f);
|
||||
session.SetContenderPose(rival.Id, box.X, box.Z + box.HalfZ + 4f);
|
||||
|
||||
bool los = session.HasLineOfSight(
|
||||
player.X, MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight), player.Z,
|
||||
rival.X, MatchRules.GetTargetAimY(rival.Y, rival.Grid.Spec.HalfHeight), rival.Z);
|
||||
|
||||
Assert.False(los, "Static cover ruin wall between two vehicles must block HasLineOfSight");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NeutralTierPositioning_PatronsClaimHigherGroundThanTouristsAndExemplars_AndHoldSpots()
|
||||
{
|
||||
var state = new MatchState(seed: 42);
|
||||
var ring = state.Spectators;
|
||||
|
||||
var touristHeights = new List<float>();
|
||||
var patronHeights = new List<float>();
|
||||
var exemplarHeights = new List<float>();
|
||||
var initialGoals = new Dictionary<int, (float X, float Z)>();
|
||||
|
||||
for (int i = 0; i < ring.Spectators.Count; i++)
|
||||
{
|
||||
var s = ring.Spectators[i];
|
||||
var (gx, gz) = ring.GetNeutralGoal(s, state.Terrain, state.ArenaCoverBoxes);
|
||||
initialGoals[s.Id] = (gx, gz);
|
||||
float h = state.Terrain.SampleHeight(gx, gz);
|
||||
|
||||
switch (s.Tier)
|
||||
{
|
||||
case SpectatorTier.Tourist: touristHeights.Add(h); break;
|
||||
case SpectatorTier.Patron: patronHeights.Add(h); break;
|
||||
case SpectatorTier.Exemplar: exemplarHeights.Add(h); break;
|
||||
}
|
||||
}
|
||||
|
||||
float avgPatronH = patronHeights.Average();
|
||||
float avgTouristH = touristHeights.Average();
|
||||
float avgExemplarH = exemplarHeights.Average();
|
||||
|
||||
Assert.True(avgPatronH > avgTouristH + 1.0f,
|
||||
$"Expected Patrons ({avgPatronH:F2}m) to claim higher ground than Tourists ({avgTouristH:F2}m)");
|
||||
Assert.True(avgPatronH > avgExemplarH + 1.0f,
|
||||
$"Expected Patrons ({avgPatronH:F2}m) to claim higher ground than Exemplars ({avgExemplarH:F2}m)");
|
||||
|
||||
// Advance perimeter orbits while SafeRadius is within grace period: Tourists orbit, Patrons & Exemplars hold!
|
||||
ring.AdvancePerimeterOrbits(15f);
|
||||
|
||||
for (int i = 0; i < ring.Spectators.Count; i++)
|
||||
{
|
||||
var s = ring.Spectators[i];
|
||||
var (gx, gz) = ring.GetNeutralGoal(s, state.Terrain, state.ArenaCoverBoxes);
|
||||
var prev = initialGoals[s.Id];
|
||||
float moved = MathF.Sqrt((gx - prev.X) * (gx - prev.X) + (gz - prev.Z) * (gz - prev.Z));
|
||||
|
||||
if (s.Tier == SpectatorTier.Tourist)
|
||||
{
|
||||
Assert.True(moved > 10f, "Expected Neutral Tourists to continue orbiting perimeter");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(moved < 0.01f, $"Expected Neutral {s.Tier} to hold chosen vantage/ambush spot, moved {moved:F2}m");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OccludedSpectators_DoNotLeakLiveTargetAfterMemoryExpires_FiveSeconds()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42);
|
||||
// Shrink safe circle so the tall mesa perimeter is outside SafeRadius
|
||||
session.State.Time = 360f;
|
||||
session.State.Spectators.UpdateSafeRadius(session.State.Time);
|
||||
|
||||
TerrainBrush mesa = default;
|
||||
float bestMinRadius = -1f;
|
||||
for (int i = 0; i < session.State.Terrain.Brushes.Count; i++)
|
||||
{
|
||||
var b = session.State.Terrain.Brushes[i];
|
||||
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 22f)
|
||||
{
|
||||
float minR = MathF.Min(b.RadiusX, b.RadiusZ);
|
||||
if (minR > bestMinRadius)
|
||||
{
|
||||
bestMinRadius = minR;
|
||||
mesa = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(bestMinRadius > 0f, "Expected at least one tall Mesa in generated terrain.");
|
||||
|
||||
var player = session.State.Player;
|
||||
var tourists = session.State.Spectators.Spectators.Where(s => s.Tier == SpectatorTier.Tourist).ToList();
|
||||
var provokedSpec = tourists[0];
|
||||
var clearedSpec = tourists[1];
|
||||
|
||||
// Place player on the side of the mesa further from center (strictly outside SafeRadius)
|
||||
float xNeg = mesa.X - mesa.RadiusX - 18f;
|
||||
float xPos = mesa.X + mesa.RadiusX + 18f;
|
||||
bool negIsFurther = (xNeg * xNeg + mesa.Z * mesa.Z) >= (xPos * xPos + mesa.Z * mesa.Z);
|
||||
float occludedX = negIsFurther ? xNeg : xPos;
|
||||
float specSideX = negIsFurther ? (mesa.X + mesa.RadiusX + 45f) : (mesa.X - mesa.RadiusX - 45f);
|
||||
|
||||
// Keep AI contenders safely inside the safe circle and other spectators behind the mesa shadow so they don't peek around the flank
|
||||
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
session.SetContenderPose(session.State.Contenders[i].Id, (i - 6) * 12f, 0f);
|
||||
}
|
||||
for (int i = 0; i < session.State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var other = session.State.Spectators.Spectators[i];
|
||||
if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id)
|
||||
{
|
||||
float farX = (mesa.X >= 0f ? -1f : 1f) * 680f;
|
||||
float farZ = (mesa.Z >= 0f ? -1f : 1f) * 680f;
|
||||
session.SetSpectatorPose(other.Id, farX, farZ);
|
||||
}
|
||||
}
|
||||
|
||||
// Briefly establish visual contact for provokedSpec at initial spot, then move player behind the mesa
|
||||
session.SetContenderPose(player.Id, specSideX - (negIsFurther ? 12f : -12f), mesa.Z);
|
||||
session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z);
|
||||
session.State.Spectators.OnSpectatorDamaged(provokedSpec, player.Id);
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
Assert.True(provokedSpec.HasTargetLos, "Expected initial LOS before player drops behind cover");
|
||||
|
||||
float provokedKnownX = provokedSpec.LastKnownTargetX;
|
||||
float provokedKnownZ = provokedSpec.LastKnownTargetZ;
|
||||
|
||||
// Now hide player behind the mesa and place clearedSpec on the opposite side closest to the breach
|
||||
session.SetContenderPose(player.Id, occludedX, mesa.Z - 14f);
|
||||
session.SetSpectatorPose(provokedSpec.Id, specSideX, mesa.Z - 4f);
|
||||
session.SetSpectatorPose(clearedSpec.Id, specSideX, mesa.Z + 4f);
|
||||
|
||||
// Verify clearedSpec gets Pass-2 Cleared assignment without LOS
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
Assert.False(provokedSpec.HasTargetLos);
|
||||
Assert.Equal(SpectatorStance.Cleared, clearedSpec.Stance);
|
||||
Assert.False(clearedSpec.HasTargetLos);
|
||||
|
||||
float clearedInitialKnownX = clearedSpec.LastKnownTargetX;
|
||||
float clearedInitialKnownZ = clearedSpec.LastKnownTargetZ;
|
||||
|
||||
// Run 300 ticks (5.0s > 4.0s TargetMemoryDuration) while player moves laterally behind cover
|
||||
for (int tick = 0; tick < 300; tick++)
|
||||
{
|
||||
float latZ = mesa.Z - 14f + (tick / 299f) * 28f;
|
||||
if (tick % 10 == 0)
|
||||
{
|
||||
session.SetContenderPose(player.Id, occludedX, latZ);
|
||||
}
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
|
||||
Assert.False(provokedSpec.HasTargetLos, $"Provoked spectator regained unexpected LOS at tick {tick}");
|
||||
Assert.False(clearedSpec.HasTargetLos, $"Cleared spectator regained unexpected LOS at tick {tick}");
|
||||
|
||||
if (tick == 270) // 4.5s > 4.0s memory window
|
||||
{
|
||||
Assert.True(provokedSpec.TimeSinceLastSeen >= 4.5f,
|
||||
$"Provoked TimeSinceLastSeen reset unexpectedly: {provokedSpec.TimeSinceLastSeen:F2}s");
|
||||
Assert.True(clearedSpec.TimeSinceLastSeen >= 4.5f,
|
||||
$"Cleared TimeSinceLastSeen reset unexpectedly: {clearedSpec.TimeSinceLastSeen:F2}s");
|
||||
}
|
||||
}
|
||||
|
||||
// Neither spectator's LastKnownTarget or aim vector may track the player's new occluded position
|
||||
float provokedDistToPlayer = MathF.Sqrt(
|
||||
(provokedSpec.LastKnownTargetX - player.X) * (provokedSpec.LastKnownTargetX - player.X) +
|
||||
(provokedSpec.LastKnownTargetZ - player.Z) * (provokedSpec.LastKnownTargetZ - player.Z));
|
||||
Assert.Equal(provokedKnownX, provokedSpec.LastKnownTargetX, precision: 3);
|
||||
Assert.Equal(provokedKnownZ, provokedSpec.LastKnownTargetZ, precision: 3);
|
||||
Assert.True(provokedDistToPlayer > 25f,
|
||||
$"Provoked LastKnownTarget leaked live player position (dist={provokedDistToPlayer:F2}m)");
|
||||
|
||||
float clearedDistToPlayer = MathF.Sqrt(
|
||||
(clearedSpec.LastKnownTargetX - player.X) * (clearedSpec.LastKnownTargetX - player.X) +
|
||||
(clearedSpec.LastKnownTargetZ - player.Z) * (clearedSpec.LastKnownTargetZ - player.Z));
|
||||
Assert.Equal(clearedInitialKnownX, clearedSpec.LastKnownTargetX, precision: 3);
|
||||
Assert.Equal(clearedInitialKnownZ, clearedSpec.LastKnownTargetZ, precision: 3);
|
||||
Assert.True(clearedDistToPlayer > 20f,
|
||||
$"Cleared LastKnownTarget leaked live player position (dist={clearedDistToPlayer:F2}m)");
|
||||
|
||||
MatchRules.ComputeSpectatorBehavior(provokedSpec, session.State, out _, out _, out float pAimX, out float pAimZ, out bool pFire);
|
||||
Assert.False(pFire);
|
||||
Assert.Equal(provokedKnownX, pAimX, precision: 3);
|
||||
Assert.Equal(provokedKnownZ, pAimZ, precision: 3);
|
||||
|
||||
MatchRules.ComputeSpectatorBehavior(clearedSpec, session.State, out _, out _, out float cAimX, out float cAimZ, out bool cFire);
|
||||
Assert.False(cFire);
|
||||
Assert.Equal(clearedInitialKnownX, cAimX, precision: 3);
|
||||
Assert.Equal(clearedInitialKnownZ, cAimZ, precision: 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Probe2_OccludedLateralArc_FullRingDoesNotLeakOrTrackPlayerPosition()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 42);
|
||||
Assert.Equal(56, ring.Spectators.Count);
|
||||
const float dt = 1f / 60f;
|
||||
|
||||
// Phase 1 (10 ticks): Player pops out of safe circle briefly at 0 degrees with LOS to nearby 0-deg watchers.
|
||||
float startR = ring.SafeRadius + 15f;
|
||||
for (int tick = 0; tick < 10; tick++)
|
||||
{
|
||||
var contact = new RingContact(0, startR, 0f, true);
|
||||
ring.UpdateClearance(new[] { contact }, dt, (spec, _) =>
|
||||
{
|
||||
float specAng = MathF.Atan2(spec.Z, spec.X);
|
||||
return MathF.Abs(specAng) < 0.45f;
|
||||
});
|
||||
}
|
||||
|
||||
int initialCleared = ring.CountClearedFor(0);
|
||||
Assert.True(initialCleared >= 1, "Expected at least one Cleared spectator at 0 degrees during initial pop-out");
|
||||
Assert.Contains(ring.Spectators, s => s.Stance == SpectatorStance.Cleared && s.HasTargetLos);
|
||||
|
||||
// Phase 2 (600 ticks = 10s): 100% occlusion while player moves laterally 0 -> 80 deg and steps further out.
|
||||
float playerX = startR;
|
||||
float playerZ = 0f;
|
||||
float maxArcRad = 80f * (MathF.PI / 180f);
|
||||
|
||||
for (int tick = 0; tick < 600; tick++)
|
||||
{
|
||||
float t = tick / 599f;
|
||||
float angle = t * maxArcRad;
|
||||
float r = ring.SafeRadius + 15f + t * 70f;
|
||||
playerX = MathF.Cos(angle) * r;
|
||||
playerZ = MathF.Sin(angle) * r;
|
||||
|
||||
var contact = new RingContact(0, playerX, playerZ, true);
|
||||
ring.UpdateClearance(new[] { contact }, dt, static (_, _) => false);
|
||||
|
||||
foreach (var s in ring.Spectators)
|
||||
{
|
||||
Assert.False(s.HasTargetLos, $"No spectator may have LOS during occluded arc (tick {tick}, spec {s.Id})");
|
||||
if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
float targetAngle = MathF.Atan2(s.LastKnownTargetZ, s.LastKnownTargetX);
|
||||
Assert.True(MathF.Abs(targetAngle) < 0.35f,
|
||||
$"Cleared spectator {s.Id} leaked lateral angle {targetAngle * 180f / MathF.PI:F1} deg at tick {tick}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// At end of 80-deg hidden move, no spectator has LastKnownTarget near the player's hidden position,
|
||||
// and spectators stationed along 35..90 degrees remain Neutral.
|
||||
foreach (var s in ring.Spectators)
|
||||
{
|
||||
if (s.Stance == SpectatorStance.Cleared)
|
||||
{
|
||||
float dx = s.LastKnownTargetX - playerX;
|
||||
float dz = s.LastKnownTargetZ - playerZ;
|
||||
float distToHiddenPlayer = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Assert.True(distToHiddenPlayer > 400f,
|
||||
$"Cleared spectator {s.Id} LastKnownTarget ({s.LastKnownTargetX:F1}, {s.LastKnownTargetZ:F1}) too close to hidden player ({distToHiddenPlayer:F1}m)");
|
||||
}
|
||||
|
||||
float specAngleDeg = MathF.Atan2(s.Z, s.X) * (180f / MathF.PI);
|
||||
if (specAngleDeg >= 35f && specAngleDeg <= 95f)
|
||||
{
|
||||
Assert.Equal(SpectatorStance.Neutral, s.Stance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnSpectatorDamaged_WithoutLos_SeedsIncomingDirectionInsteadOfStaleTarget()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 77);
|
||||
var spec = ring.Spectators[0];
|
||||
spec.LastKnownTargetX = 0f;
|
||||
spec.LastKnownTargetZ = 0f;
|
||||
|
||||
bool provoked = ring.OnSpectatorDamaged(spec, attackerContenderId: 0, incomingDirX: 0f, incomingDirZ: 1f);
|
||||
Assert.True(provoked);
|
||||
Assert.Equal(SpectatorStance.Provoked, spec.Stance);
|
||||
Assert.False(spec.HasTargetLos);
|
||||
Assert.True(spec.LastKnownTargetZ > spec.Z + 10f,
|
||||
$"Expected LastKnownTarget to point along incoming +Z direction, got Z={spec.LastKnownTargetZ:F1} vs spec.Z={spec.Z:F1}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using RustToDust.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class GridHeatTests
|
||||
{
|
||||
[Fact]
|
||||
public void Conduction_SpreadsHeatFromHotHardpointToNeighbors()
|
||||
{
|
||||
var grid = Catalog.CreateStarterBuggy();
|
||||
// hp.weapon.roof is at (1, 0) 1x2. Neighbors (0, 0) and (1, 2) start at ambient 20f.
|
||||
grid.InjectHardpointHeat("hp.weapon.roof", 600f);
|
||||
float hotBefore = grid.Temperature[1, 0];
|
||||
Assert.True(hotBefore > ChassisGrid.AmbientTemp + 20f);
|
||||
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[0, 0]);
|
||||
Assert.Equal(ChassisGrid.AmbientTemp, grid.Temperature[1, 2]);
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
grid.StepHeat(1f / 60f);
|
||||
}
|
||||
|
||||
Assert.True(grid.Temperature[0, 0] > ChassisGrid.AmbientTemp + 1f);
|
||||
Assert.True(grid.Temperature[1, 2] > ChassisGrid.AmbientTemp + 1f);
|
||||
Assert.True(grid.Temperature[1, 0] < hotBefore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Radiation_CoolsBorderCellsWhileInteriorCellsDoNotRadiateDirectly()
|
||||
{
|
||||
var grid = new ChassisGrid(Catalog.Tank); // 4x5 full grid: interior cells exist at (1..2, 1..3)
|
||||
for (int y = 0; y < grid.Spec.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < grid.Spec.Width; x++)
|
||||
{
|
||||
grid.Temperature[x, y] = 120f;
|
||||
}
|
||||
}
|
||||
|
||||
// Single 60Hz substep: neighbors are all 120f so net conduction is 0.
|
||||
// Only BorderCells lose heat to radiation; interior cell (1, 2) must stay at 120f.
|
||||
grid.StepHeat(1f / 60f);
|
||||
|
||||
Assert.True(grid.BorderCells[0, 0]);
|
||||
Assert.False(grid.BorderCells[1, 2]);
|
||||
Assert.True(grid.Temperature[0, 0] < 120f);
|
||||
Assert.Equal(120f, grid.Temperature[1, 2], precision: 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModulePerformance_MatchesTrapezoidalPlateauCurve()
|
||||
{
|
||||
var mod = Catalog.Mg762; // Min=0, Optimal=65, Plateau=70 => [30, 100], Max=155
|
||||
|
||||
Assert.Equal(0f, mod.Performance(-5f));
|
||||
Assert.Equal(0f, mod.Performance(0f));
|
||||
Assert.Equal(0.5f, mod.Performance(15f), precision: 4);
|
||||
Assert.Equal(1f, mod.Performance(30f), precision: 4);
|
||||
Assert.Equal(1f, mod.Performance(65f), precision: 4);
|
||||
Assert.Equal(1f, mod.Performance(100f), precision: 4);
|
||||
Assert.Equal(0.5f, mod.Performance(127.5f), precision: 4);
|
||||
Assert.Equal(0f, mod.Performance(155f));
|
||||
Assert.Equal(0f, mod.Performance(210f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DorsalHit_FrontStrikesFrontRowAndRearStrikesRearRow()
|
||||
{
|
||||
var grid = new ChassisGrid(Catalog.Tank);
|
||||
|
||||
var frontHit = grid.ApplyHit(localRight: 0f, localForward: 1f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
||||
var rearHit = grid.ApplyHit(localRight: 0f, localForward: -1f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
||||
var leftHit = grid.ApplyHit(localRight: -1f, localForward: 0f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
||||
var rightHit = grid.ApplyHit(localRight: 1f, localForward: 0f, localHeightNorm: 0.5f, damage: 15f, heatTransfer: 0f);
|
||||
|
||||
Assert.Equal(0, frontHit.CellY);
|
||||
Assert.Equal(grid.Spec.Height - 1, rearHit.CellY);
|
||||
Assert.Equal(0, leftHit.CellX);
|
||||
Assert.Equal(grid.Spec.Width - 1, rightHit.CellX);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CoronalHit_HighVsLowElevationStrikesUpperVsLowerBipedCells()
|
||||
{
|
||||
var grid = new ChassisGrid(Catalog.Raptor);
|
||||
float initialLegs = grid.LegIntegrity;
|
||||
Assert.Equal(1f, initialLegs);
|
||||
|
||||
var highHit = grid.ApplyHit(localRight: 0f, localForward: 1f, localHeightNorm: 0.95f, damage: 20f, heatTransfer: 0f);
|
||||
var lowHit = grid.ApplyHit(localRight: -0.4f, localForward: 1f, localHeightNorm: 0.05f, damage: 35f, heatTransfer: 0f);
|
||||
|
||||
Assert.True(highHit.CellY <= 1);
|
||||
Assert.True(lowHit.CellY >= grid.Spec.Height - 2);
|
||||
Assert.True(grid.LegIntegrity < initialLegs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LooseFitAndSwapChassis_PreservesCompatibleGearAndStowsOverflow()
|
||||
{
|
||||
// Ironclad has 2x2 main turret hardpoint: smaller 1x1 weapon fits loosely; 2x2 weapon must NOT fit 1x2 Jackal roof.
|
||||
var tankGrid = new ChassisGrid(Catalog.Ironclad);
|
||||
Assert.True(tankGrid.TryMount(Catalog.Recoilless, "hp.weapon.main")); // 2x2 into 2x2
|
||||
Assert.True(tankGrid.TryMount(Catalog.Mg762, "hp.weapon.coax")); // 1x1 into 1x1
|
||||
Assert.True(tankGrid.TryMount(Catalog.TurboCore, "hp.engine.rear")); // 1x2 into 2x2
|
||||
Assert.True(tankGrid.TryMount(Catalog.GoldRadiator, "hp.radiator.l")); // 1x1 into 1x2
|
||||
Assert.True(tankGrid.TryMount(Catalog.WeldedPlate, "hp.armor.front")); // 1x1 into 4x1
|
||||
Assert.True(tankGrid.TryMount(Catalog.GildedPlate, "hp.armor.skirts")); // 1x1 into 1x2
|
||||
|
||||
// Fill cargo so swapping down to Jackal (capacity 4) overflows 2 items to ground!
|
||||
Assert.True(tankGrid.TryAddCargo(Catalog.Flak));
|
||||
Assert.True(tankGrid.TryAddCargo(Catalog.CopperRad));
|
||||
Assert.True(tankGrid.TryAddCargo(Catalog.DieselCore));
|
||||
|
||||
List<ModuleSpec> dropped = tankGrid.SwapChassis(Catalog.Jackal);
|
||||
|
||||
// Jackal has 1x2 Weapon (mg_762 fits, recoilless 2x2 does not!), 1x2 Engine (turbo_core fits), 1x1 Radiator (gold_radiator fits), 0 Armor hardpoints.
|
||||
Assert.Equal("jackal", tankGrid.Spec.Id);
|
||||
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "mg_762");
|
||||
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "turbo_core");
|
||||
Assert.Contains(tankGrid.Mounted, m => m.Spec.Id == "gold_radiator");
|
||||
Assert.DoesNotContain(tankGrid.Mounted, m => m.Spec.Id == "recoilless");
|
||||
|
||||
// 6 mounted on Ironclad: 3 transferred, 3 leftover + 3 cargo = 6 items -> 4 in Jackal Cargo, 2 dropped!
|
||||
Assert.Equal(Catalog.Jackal.CargoCapacity, tankGrid.Cargo.Count);
|
||||
Assert.Equal(2, dropped.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\RustToDust.Core\RustToDust.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\RustToDust.Ymir\RustToDust.Ymir.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using RustToDust.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class SpectatorRingTests
|
||||
{
|
||||
[Fact]
|
||||
public void Clearance_ZeroInsideSafeCircle_MonotonicOutside()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 101);
|
||||
float r = ring.SafeRadius; // 560f
|
||||
Assert.Equal(56, ring.Spectators.Count);
|
||||
|
||||
// Inside safe circle -> 0 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r - 20f, 0f, true) });
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
|
||||
// Just outside safe circle (+5m) -> 1 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 5f, 0f, true) });
|
||||
int clearedNear = ring.CountClearedFor(0);
|
||||
Assert.Equal(1, clearedNear);
|
||||
|
||||
// Further outside (+30m) -> 1 + floor(30/12) = 3 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 30f, 0f, true) });
|
||||
int clearedMid = ring.CountClearedFor(0);
|
||||
Assert.True(clearedMid > clearedNear);
|
||||
|
||||
// Far outside (+100m) -> capped at 8 cleared
|
||||
ring.UpdateClearance(new[] { new RingContact(0, r + 100f, 0f, true) });
|
||||
int clearedFar = ring.CountClearedFor(0);
|
||||
Assert.Equal(8, clearedFar);
|
||||
|
||||
// Stepping back inside safe circle revokes non-provoked clearance back to 0
|
||||
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, true) });
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Provocation_AttackingNeutralSpectatorLocksOntoAttackerEvenInsideSafeCircle()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 202);
|
||||
var targetSpec = ring.Spectators[0];
|
||||
Assert.Equal(SpectatorStance.Neutral, targetSpec.Stance);
|
||||
|
||||
// Contender 0 is dead center (well inside SafeRadius)
|
||||
var contenders = new[] { new RingContact(0, 0f, 0f, true) };
|
||||
ring.UpdateClearance(contenders);
|
||||
Assert.Equal(0, ring.CountClearedFor(0));
|
||||
|
||||
bool provoked = ring.OnSpectatorDamaged(targetSpec, attackerContenderId: 0);
|
||||
Assert.True(provoked);
|
||||
Assert.Equal(SpectatorStance.Provoked, targetSpec.Stance);
|
||||
Assert.Equal(0, targetSpec.TargetContenderId);
|
||||
|
||||
// Subsequent clearance updates inside the safe circle must NOT clear Provoked lock
|
||||
ring.UpdateClearance(contenders);
|
||||
Assert.Equal(SpectatorStance.Provoked, targetSpec.Stance);
|
||||
Assert.Equal(1, ring.CountProvokedFor(0));
|
||||
|
||||
// Once attacker dies, provocation reverts to Neutral
|
||||
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, false) });
|
||||
Assert.Equal(SpectatorStance.Neutral, targetSpec.Stance);
|
||||
Assert.Null(targetSpec.TargetContenderId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SalvageDrops_TouristDropsImperialGearWhileExemplarDoesNot()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 303);
|
||||
var rng = new Random(99);
|
||||
|
||||
var tourists = ring.Spectators.Where(s => s.Tier == SpectatorTier.Tourist).ToList();
|
||||
var exemplars = ring.Spectators.Where(s => s.Tier == SpectatorTier.Exemplar).ToList();
|
||||
|
||||
Assert.NotEmpty(tourists);
|
||||
Assert.NotEmpty(exemplars);
|
||||
|
||||
foreach (var tourist in tourists)
|
||||
{
|
||||
var drops = SpectatorRing.RollSalvageDrops(tourist, rng);
|
||||
Assert.InRange(drops.Count, 1, 2);
|
||||
Assert.All(drops, d => Assert.True(d.IsImperial));
|
||||
}
|
||||
|
||||
foreach (var exemplar in exemplars)
|
||||
{
|
||||
var drops = SpectatorRing.RollSalvageDrops(exemplar, rng);
|
||||
Assert.DoesNotContain(drops, d => d.IsImperial);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpawnedSpectators_EveryTierMountsEngineAndWeapon()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 42);
|
||||
|
||||
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Tourist);
|
||||
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Patron);
|
||||
Assert.Contains(ring.Spectators, s => s.Tier == SpectatorTier.Exemplar);
|
||||
|
||||
foreach (var spec in ring.Spectators)
|
||||
{
|
||||
Assert.Contains(spec.Grid.Mounted, m => m.Spec.Kind == HardpointKind.Engine);
|
||||
Assert.Contains(spec.Grid.Mounted, m => m.Spec.Kind == HardpointKind.Weapon);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Provocation_AttackingClearedSpectatorSwitchesToProvokedAndPersistsInsideSafeCircle()
|
||||
{
|
||||
var ring = new SpectatorRing(seed: 505);
|
||||
float outsideR = ring.SafeRadius + 15f;
|
||||
|
||||
// Contender 0 steps outside safe circle -> clears at least 1 spectator
|
||||
ring.UpdateClearance(new[] { new RingContact(0, outsideR, 0f, true) });
|
||||
var clearedSpec = ring.Spectators.FirstOrDefault(s => s.Stance == SpectatorStance.Cleared);
|
||||
Assert.NotNull(clearedSpec);
|
||||
|
||||
// Contender 0 fights back against the Cleared spectator
|
||||
bool provoked = ring.OnSpectatorDamaged(clearedSpec!, attackerContenderId: 0);
|
||||
Assert.True(provoked);
|
||||
Assert.Equal(SpectatorStance.Provoked, clearedSpec!.Stance);
|
||||
Assert.Equal(0, clearedSpec.TargetContenderId);
|
||||
|
||||
// Returning inside the safe circle must NOT clear the Provoked lock
|
||||
ring.UpdateClearance(new[] { new RingContact(0, 0f, 0f, true) });
|
||||
Assert.Equal(SpectatorStance.Provoked, clearedSpec.Stance);
|
||||
Assert.Equal(1, ring.CountProvokedFor(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BroadcastFeed_VersionAdvancesPastRingBufferCap()
|
||||
{
|
||||
var feed = new BroadcastFeed();
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
long prev = feed.Version;
|
||||
feed.Emit(i, BroadcastKind.TouristPull, $"line-{i}");
|
||||
Assert.Equal(prev + 1, feed.Version);
|
||||
}
|
||||
|
||||
Assert.Equal(32, feed.Lines.Count);
|
||||
Assert.Equal(40, feed.Version);
|
||||
Assert.Equal("line-39", feed.Latest?.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue