Co-op voice/session work, config retune, net budget tool, overhaul plan
Snapshot of in-progress work before the alien overhaul so worker worktrees branch from current code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2e6638b744
commit
39f9d15cfe
15 changed files with 1394 additions and 339 deletions
29
.claude/agents/explorer.md
Normal file
29
.claude/agents/explorer.md
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
---
|
||||||
|
name: explorer
|
||||||
|
description: Read-only codebase explorer. Use before implementing a task to locate relevant files, existing patterns, conventions, and tests. Never edits anything.
|
||||||
|
tools: Read, Grep, Glob
|
||||||
|
model: haiku
|
||||||
|
---
|
||||||
|
|
||||||
|
You are a read-only codebase explorer. You never modify files.
|
||||||
|
|
||||||
|
When given a task, find and report:
|
||||||
|
|
||||||
|
1. **Relevant files**: exact paths the task will likely touch, plus files that
|
||||||
|
depend on them (callers, importers, tests).
|
||||||
|
2. **Existing patterns**: how similar features are already implemented here
|
||||||
|
(naming, structure, error handling, data access), with file:line references.
|
||||||
|
3. **Conventions**: lint/format rules, test framework and location, config or
|
||||||
|
env patterns the new code should follow.
|
||||||
|
4. **Verification**: the exact commands or test files that will confirm the
|
||||||
|
task works.
|
||||||
|
5. **Risks**: shared files, tricky coupling, or anything likely to conflict
|
||||||
|
with other in-flight work.
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
|
||||||
|
- Be concrete. Give paths and line numbers, not general descriptions.
|
||||||
|
- Quote only short snippets (a few lines) when they clarify a pattern.
|
||||||
|
- If something you were asked about doesn't exist, say so plainly rather than
|
||||||
|
guessing.
|
||||||
|
- Keep the report under 400 words. Lead with the most important findings.
|
||||||
11
.claude/agents/impl-worker.md
Normal file
11
.claude/agents/impl-worker.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
name: impl-worker
|
||||||
|
description: Implements one task from docs/tasks.md per docs/plan.md, then runs its verification step
|
||||||
|
model: sonnet
|
||||||
|
isolation: worktree
|
||||||
|
---
|
||||||
|
|
||||||
|
You implement exactly one assigned task. Read docs/plan.md for the files and
|
||||||
|
approach. Stay inside the files listed for your task. Run the task's
|
||||||
|
verification (tests/lint) before reporting back. Summarize what changed and
|
||||||
|
anything you couldn't finish.
|
||||||
12
AGENTS.md
Normal file
12
AGENTS.md
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
## graphify
|
||||||
|
|
||||||
|
This project has a knowledge graph at graphify-out/ with god nodes, community structure, and cross-file relationships.
|
||||||
|
|
||||||
|
When the user types `/graphify`, use the installed graphify skill or instructions before doing anything else.
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
- For codebase questions, first run `graphify query "<question>"` when graphify-out/graph.json exists. Use `graphify path "<A>" "<B>"` for relationships and `graphify explain "<concept>"` for focused concepts. These return a scoped subgraph, usually much smaller than GRAPH_REPORT.md or raw grep output.
|
||||||
|
- Dirty graphify-out/ files are expected after hooks or incremental updates; dirty graph files are not a reason to skip graphify. Only skip graphify if the task is about stale or incorrect graph output, or the user explicitly says not to use it.
|
||||||
|
- If graphify-out/wiki/index.md exists, use it for broad navigation instead of raw source browsing.
|
||||||
|
- Read graphify-out/GRAPH_REPORT.md only for broad architecture review or when query/path/explain do not surface enough context.
|
||||||
|
- After modifying code, run `graphify update .` to keep the graph current (AST-only, no API cost).
|
||||||
143
alien-overhaul-plan.md
Normal file
143
alien-overhaul-plan.md
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
# Harvest Season — alien overhaul: review, decisions, and task plan
|
||||||
|
|
||||||
|
Status: planning complete, decisions resolved, implementation not started. Codebase review was
|
||||||
|
run against the "Farm Defense Game" alien-invasion spec (Supply Shed, Workbench, alien-themed
|
||||||
|
enemy roster, etc.) and compared to the existing prototype, which at review time had **zero**
|
||||||
|
alien/UFO/robot/goop content anywhere (confirmed by independent greps across `game/scripts`,
|
||||||
|
`game/resources`, and all `.md` docs). This is a full overhaul of the existing systems, not a
|
||||||
|
different build — see Decision 1 below.
|
||||||
|
|
||||||
|
The live task list (with status/dependencies) is tracked in the session's Task tool as tasks
|
||||||
|
`#1`–`#15`; this document is the narrative record of *why* those tasks exist and what was decided.
|
||||||
|
Use `TaskList`/`TaskGet` for current status; use this file for the reasoning and open assumptions.
|
||||||
|
|
||||||
|
## Headline finding from the review
|
||||||
|
|
||||||
|
A scarecrow defends a farm against three mundane enemy types (`thief`, `crow`, `breaker`) for 5
|
||||||
|
configurable nights. Several systems already match the spec's *behavior* closely (enemy roles,
|
||||||
|
fear mechanic, most upgrade math) even though none of the alien theming or several structural
|
||||||
|
pieces (Workbench gating, Animal Pen as a buildable, staged crop fields, hidden shop items) exist
|
||||||
|
yet. Two numeric values that initial sub-research disagreed on were verified directly against
|
||||||
|
`game_config.gd`/`game_config.tres`: Rapid Fire is already a live 3.0x (the `.tres` resource
|
||||||
|
overrides the `.gd` script's stale `1.333` default), and Straw Bandages' base HP is 3 (not 10 —
|
||||||
|
`FarmState`'s `10` default is overwritten by `GameConfig.scarecrow_max_hp=3` at campaign setup),
|
||||||
|
so `+2` from `straw_stuffing` already lands exactly on the spec's "5 HP."
|
||||||
|
|
||||||
|
## Decisions (resolved)
|
||||||
|
|
||||||
|
1. **Scope**: full overhaul of this codebase, not a separate/different build.
|
||||||
|
2. **Weapons**: Potato Cannon, Shurikens, Propane Torch, Alien Ray, Radar are new weapons/items to
|
||||||
|
build — not renames of existing ones. Corn Shooter and Pumpkin Bombs stay as-is.
|
||||||
|
3. **Workbench**: auto-granted (not player-built), but becomes targetable by enemies — destructible
|
||||||
|
and repairable like a structure.
|
||||||
|
4. **Animal Pen**: becomes a player-built structure; animal start-state inverts to wandering. **Correction
|
||||||
|
(verified against code 2026-10-05)**: this is not a new buildable type. `FarmZone.Kind.ANIMAL_PEN`
|
||||||
|
already exists and its rect already drives nav/flow-fields (`farm_sim.gd:123,143,162,175-176`);
|
||||||
|
`AnimalSystem.update_pen_open()` (`animal_system.gd:203`) already implements "open if there's a way
|
||||||
|
out crossing no structure" — it just has nothing real to check today because the pen's fence in
|
||||||
|
`farm.tscn` (23 `fence_024` instances under `Zones/AnimalPen`) is static decoration, not
|
||||||
|
`StructureSystem` entries. The actual work is: delete the decorative fence meshes, let players build
|
||||||
|
ordinary `fence`/`gate` structures (already in `StructureSystem.ORDER`) around the existing pen rect,
|
||||||
|
and set animals' initial status to the existing DROPPED/loose state (not HOME/"wander", which already
|
||||||
|
means something else — in-pen grazing — in `animal_system.gd`). No new structure type, no new
|
||||||
|
`ORDER` entry.
|
||||||
|
5. **Hidden shop items**: show a "?" icon with no details until their reveal condition (Alien Goop
|
||||||
|
collected) is met; then they become visible *and* purchasable for their defined cost.
|
||||||
|
6. **Crop field growth trigger**: automatic, tied to a night threshold (see Decision 15). Fields
|
||||||
|
should sit on "the two dirt fields on the map" — **research could not confirm this zone exists**
|
||||||
|
(see Open assumptions below).
|
||||||
|
7. **Turret L3**: 3 projectiles in a triangle spread pattern. **Tar Patch**: size doubles (L2, vs.
|
||||||
|
original/L1 size).
|
||||||
|
8. **Buildable upgrades**: per-instance, not account-wide — each placed turret/tar patch is
|
||||||
|
upgraded independently of every other one of its type.
|
||||||
|
9. **Sprint**: move to spec values (1.8x speed for 4s; cooldown stays 10s, already matched).
|
||||||
|
10. **Pouch capacity**: base drops to 8, upgrade raises it to 16 (currently a flat, non-upgradable 16).
|
||||||
|
11. **Alien Goop drop**: 1x quantity, ~33% drop rate from Aliens (the `thief`-type enemy), both
|
||||||
|
values GameConfig-tunable.
|
||||||
|
12. **New enemy (UFO) stats**: any reasonable default is fine as long as it's config-tunable.
|
||||||
|
13. **New weapon/item costs**: defaults are fine, must be config-tunable.
|
||||||
|
14. **Turret fire-rate upgrade**: matches the player's Rapid Fire multiplier — 3x.
|
||||||
|
15. **Night count**: stays at 5 for now (the previously-discussed 30-night scale pass is deferred
|
||||||
|
until after this overhaul is tested). New crop fields sprout after Night 2 and Night 4
|
||||||
|
respectively (ties into Decision 6).
|
||||||
|
16. **Radar function** (asked separately after the above): **minimap reveal** — adds a map overlay
|
||||||
|
showing enemy positions once purchased, not directional pings or an audio-only warning.
|
||||||
|
|
||||||
|
## Open assumptions (flagged, not yet confirmed)
|
||||||
|
|
||||||
|
These were defaulted under "any default is fine as long as it's configurable," except the first
|
||||||
|
two, which are factual/design gaps rather than balance numbers — worth a deliberate confirm before
|
||||||
|
or during their task:
|
||||||
|
|
||||||
|
- **Crop field placement** (blocks part of task #13): no "dirt field" zone currently exists in
|
||||||
|
`game/scenes/farm.tscn` or `game/LAYOUT.md` — old decorative bare-soil patches were removed in a
|
||||||
|
past layout cleanup (`game/LAYOUT.md`'s changelog: "the north-west field's soil tile" removed,
|
||||||
|
"1,122 plants in the three fields outside the map" removed). Default: place both new fields
|
||||||
|
*inside* the perimeter fence (defendable, like the existing Crop Field), not in the outside
|
||||||
|
gather zones. Needs an in-editor pick of two actual open rectangles.
|
||||||
|
- **Tar Patch L3 size**: Decision 7 only confirmed L2 doubles. Defaulting L3 to triple (matching
|
||||||
|
the original spec's "+200%"), not explicitly reconfirmed.
|
||||||
|
- **Turret L3 fire rate**: defaulting to retaining L2's 3x fire rate in addition to the triangle
|
||||||
|
multishot (upgrade-stacking convention), not explicitly reconfirmed.
|
||||||
|
- **Workbench destroy/rebuild**: defaulting to repair-only (same proportional repair-cost pattern
|
||||||
|
as other structures), not a full destroy-then-rebuild-from-scratch state.
|
||||||
|
- **Workbench wiring gap (found 2026-10-05, unresolved)**: the repair-cost-pattern default above
|
||||||
|
assumes Workbench is "like other structures," but it currently isn't wired to be one at all.
|
||||||
|
`StructureSystem.structures` is only ever populated via `place()` — player-initiated, cost-checked,
|
||||||
|
validated against the build grid. `workbench.gd` is a bespoke `Node3D` with no HP and no presence in
|
||||||
|
that array. Before starting #9, decide: (a) inject Workbench into `structures` via a non-purchased,
|
||||||
|
unvalidated variant of `place()` so it rides the existing damage/repair pipeline, or (b) give it
|
||||||
|
bespoke duplicate HP/damage/repair logic outside `StructureSystem`. This is a design decision, not
|
||||||
|
just a numeric default.
|
||||||
|
- **Supply Shed as a real purchase UI**: the review flagged that `shed_stock.gd` is currently just
|
||||||
|
a stockpile zone, not a store — all purchasing happens through the Workbench's `UpgradePanel`.
|
||||||
|
Proceeding on the assumption that Supply Shed becomes its own purchase surface for weapons/items
|
||||||
|
(matching the spec's two-store structure), separate from Workbench's player/weapon/buildable
|
||||||
|
stat upgrades.
|
||||||
|
- **Per-instance upgrade trigger**: assuming the upgrade prompt for a specific turret/tar patch
|
||||||
|
opens by interacting with that structure in the world, not through a global menu.
|
||||||
|
|
||||||
|
## Task breakdown (mirrors Task tool `#1`–`#15`)
|
||||||
|
|
||||||
|
No dependency chain | Independent, safe to start anytime:
|
||||||
|
|
||||||
|
1. Rename Turret/Tar Patch display labels (`automated_defense`→Turret, `slowing_trap`→Tar Patch;
|
||||||
|
UI text only, internal IDs unchanged for save compatibility).
|
||||||
|
2. Sprint rebalance: `sprint_speed_mult` 1.6→1.8, `sprint_time` 3.0→4.0 (cooldown unchanged at 10s).
|
||||||
|
3. Pouch capacity rework: base 16→8, new `pouch_upgrade` entry raises it to 16.
|
||||||
|
4. Alien Goop resource + drop-on-kill from `thief`/Alien enemies (config: `alien_goop_drop_chance`
|
||||||
|
default 0.33, `alien_goop_drop_qty` default 1).
|
||||||
|
9. Workbench: auto-grant after Night 1, becomes a destructible/repairable world object. **Blocked on
|
||||||
|
a wiring decision** — see Open assumptions ("Workbench wiring gap"): it has no path into
|
||||||
|
`StructureSystem.structures` today since that array is only populated via player `place()`.
|
||||||
|
10. Per-instance Turret/Tar Patch leveling (L1-L3), independent per placed structure.
|
||||||
|
11. Animal Pen: **not a new buildable type** (see corrected Decision 4) — remove the static decorative
|
||||||
|
fence (`Zones/AnimalPen` in `farm.tscn`) and make its boundary buildable using the existing
|
||||||
|
`fence`/`gate` structure types around the already-existing `FarmZone.Kind.ANIMAL_PEN` rect.
|
||||||
|
13. Two new crop fields with staged growth (sprout after Night 2 / Night 4) — placement TBD, see
|
||||||
|
Open assumptions.
|
||||||
|
14. Enemy roster reskin: `thief`→"Alien" display name, `breaker`→"Alien Robot" display name, `crow`
|
||||||
|
keeps its name plus alien-mind-control narrative framing. Zero behavior change, no visual/model
|
||||||
|
work (placeholders stay, per standing guidance to defer visuals).
|
||||||
|
15. UFO enemy: new `flying:true` 4th enemy type, reuses existing generic flying-nav infrastructure,
|
||||||
|
needs a new FIGHT-capable flying attack behavior since `crow`'s land-and-flee logic never
|
||||||
|
fights.
|
||||||
|
|
||||||
|
Dependency chain | Blocked until their prerequisite lands:
|
||||||
|
|
||||||
|
5. Hidden/reveal shop item system — blocked by **#4** (needs Alien Goop to gate on).
|
||||||
|
6. Supply Shed as a real purchase surface — blocked by **#5**.
|
||||||
|
7. New weapons (Potato Cannon, Shurikens, Propane Torch, Alien Ray) — blocked by **#6**.
|
||||||
|
8. Radar item (minimap reveal, function now confirmed) — blocked by **#6**.
|
||||||
|
12. Invert animal start-state: set initial status to the existing DROPPED/loose state (not HOME/
|
||||||
|
"wander", which is already in-pen grazing in `animal_system.gd`) — blocked by **#11** (needs a
|
||||||
|
buildable pen boundary to herd back into).
|
||||||
|
|
||||||
|
Each task's full description and acceptance criteria live on its Task-tool entry (`TaskGet`); this
|
||||||
|
list is the dependency map and one-line summary for quick reference.
|
||||||
|
|
||||||
|
## Suggested starting order
|
||||||
|
|
||||||
|
`#1`, `#2`, `#3`, `#14` first (zero risk, no dependencies, small diffs) → `#4` → `#9`, `#10`, `#11`
|
||||||
|
in parallel → `#5` → `#6` → `#7`, `#8`, `#12`, `#13` once their blockers clear → `#15` whenever
|
||||||
|
convenient (fully independent).
|
||||||
53
game/COOP.md
53
game/COOP.md
|
|
@ -37,8 +37,10 @@ the keys leak somewhere they shouldn't, make new ones at gd-sync.com.
|
||||||
|
|
||||||
### Voice chat
|
### Voice chat
|
||||||
|
|
||||||
On by default when both are in: your microphone is sent whenever it's above room noise (GD-Sync's
|
On by default when both are in: your microphone is sent while you talk, and your friend's voice
|
||||||
`VoiceChat`), and your friend's voice plays on the Voice bus.
|
plays on the Voice bus. It opens on about a tenth of a second of sound over room noise (a click or
|
||||||
|
a knock alone doesn't open it) and stays open for 0.4 s after you stop. Talking costs about
|
||||||
|
10 KB/s online.
|
||||||
- **[M]** mutes and unmutes your microphone; Settings → Co-op does the same.
|
- **[M]** mutes and unmutes your microphone; Settings → Co-op does the same.
|
||||||
- Settings → Audio → "Voice chat (your friend)" sets their volume.
|
- Settings → Audio → "Voice chat (your friend)" sets their volume.
|
||||||
- While your friend is talking, a speaker mark shows on their panel.
|
- While your friend is talking, a speaker mark shows on their panel.
|
||||||
|
|
@ -81,21 +83,46 @@ it acts.
|
||||||
|
|
||||||
| Piece | File | Does |
|
| Piece | File | Does |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `CoopSession` | `game/scripts/coop_session.gd` | The protocol, on both sides: the welcome, snapshots (the clock, both scarecrows with the weapon in hand and the bomb's recharge, animals, enemies in 16-byte records, shots) 20 times a second, the farm state and the loot when they change, news in order (phase changes, the end, sounds, toasts, loot news, breaches, fear bursts, attacks, pumpkin bombs thrown, gather popups), and the partner's input (with its pick of weapon) and requests. The partner's own weapons only aim and show their motion: the host attacks for it, so nothing is hit twice |
|
| `CoopSession` | `game/scripts/coop_session.gd` | The protocol, on both sides: the welcome, snapshots in packed bytes 15 times a second (the clock, both scarecrows with the weapon in hand and the bomb's recharge, animals, shots, and the enemies that are due, in 16-byte records), the farm state and the loot when they change, news in order (phase changes, the end, sounds, toasts, loot news, breaches, fear bursts, attacks, pumpkin bombs thrown, gather popups), and the partner's input (with its pick of weapon) and requests. The partner's own weapons only aim and show their motion: the host attacks for it, so nothing is hit twice |
|
||||||
| `CoopLink`, `GDSyncLink` | `coop_link.gd`, `gdsync_link.gd` | The wire: GD-Sync remote calls, reliable or not; a loopback pair for tests |
|
| `CoopLink`, `GDSyncLink` | `coop_link.gd`, `gdsync_link.gd` | The wire: GD-Sync remote calls, reliable or not, large messages compressed; the packing helpers; a loopback pair for tests |
|
||||||
| `CoopLobby` | `coop_lobby.gd` | GD-Sync's LAN and online modes, lobbies, join by address |
|
| `CoopLobby` | `coop_lobby.gd` | GD-Sync's LAN and online modes, lobbies, join by address |
|
||||||
| `RemoteControls` | `remote_controls.gd` | The partner's buttons as the host sees them: held state, press counts (a lost packet never loses a press), aim, build mode, menus |
|
| `RemoteControls` | `remote_controls.gd` | The partner's buttons as the host sees them: held state, press counts (a lost packet never loses a press), aim, build mode, menus; its input record, 39 bytes |
|
||||||
| `Avatar` | `avatar.gd` | One scarecrow and its kit, weapons, and hands; `FarmSim.avatars` holds both |
|
| `Avatar` | `avatar.gd` | One scarecrow and its kit, weapons, and hands; `FarmSim.avatars` holds both |
|
||||||
| `CoopVoice` | `coop_voice.gd` | GD-Sync's `VoiceChat`, one per player, owned by that player |
|
| `CoopVoice` | `coop_voice.gd` | GD-Sync's `VoiceChat` (the microphone and the playback), one per player, owned by that player; sends speech as 4-bit ADPCM in 60 ms pieces, through its own gate |
|
||||||
| `CoopHud`, `CoopMenu` | `coop_hud.gd`, `coop_menu.gd` | The partner panel and arrow; the menu |
|
| `CoopHud`, `CoopMenu` | `coop_hud.gd`, `coop_menu.gd` | The partner panel and arrow; the menu |
|
||||||
|
|
||||||
Messages that may be lost (snapshots, input) stay under 1,100 bytes. GD-Sync splits datagrams at
|
Messages that may be lost (snapshots, input) stay under 1,100 bytes. GD-Sync splits datagrams at
|
||||||
1,200. Nothing depends on any one of them arriving: an enemy missed by a snapshot appears in the
|
1,200. Nothing depends on any one of them arriving, and removals are reliable.
|
||||||
next, and removals are reliable.
|
|
||||||
|
|
||||||
Measured on the loopback test with 90 enemies and a third of the snapshots dropped: about 31 KB/s
|
### Data use (GD-Sync's allowance)
|
||||||
from the host and 10 KB/s from the partner, with the largest message under the limit. That's
|
|
||||||
nothing on a LAN. Online, check it against your GD-Sync plan's data allowance.
|
Online, every byte goes through GD-Sync's servers, and plans are sold by data transfer (the free
|
||||||
|
one has 200 MB a day). GD-Sync doesn't say whether the relay out to the other player counts too.
|
||||||
|
What keeps co-op small:
|
||||||
|
- **Packed snapshots.** Snapshots and the partner's input are packed bytes, not Dictionaries,
|
||||||
|
where every key's name went out with every value.
|
||||||
|
- **Few messages.** GD-Sync adds about 220 bytes to each unreliable message (its request, a
|
||||||
|
signature, the packet's envelope), so a snapshot is one message: shots and the enemies ride
|
||||||
|
in it.
|
||||||
|
- **Only what changed.** The farm state goes out when it changes (the phase clock alone doesn't
|
||||||
|
count: every snapshot has it), the loot likewise, and the partner's input when it changes or
|
||||||
|
every 0.25 s.
|
||||||
|
- **Dead reckoning for enemies.** The partner moves each enemy on at the velocity of its last
|
||||||
|
record, and the host sends a new one only when that guess is 25 cm off, or the velocity,
|
||||||
|
heading, altitude, or state changed, or it was hit, and at least every second. New and changed
|
||||||
|
records go out twice more, in case one is lost. In the test's crowd of 64, that's a tenth of
|
||||||
|
the records.
|
||||||
|
- **Compression.** Messages over 256 bytes (the welcome, the farm state, the loot, big news
|
||||||
|
batches) are compressed with zstd before GD-Sync gets them. GD-Sync compresses packets only
|
||||||
|
after encrypting them, which saves nothing.
|
||||||
|
- **Voice** goes out as 4-bit ADPCM at 12 kHz, only while you talk: about 10 KB/s, against about
|
||||||
|
60 KB/s for GD-Sync's own `VoiceChat`, which sends raw samples whenever the microphone peaks.
|
||||||
|
|
||||||
|
`game/tools/net_budget.gd` measured a whole vacation (5 nights, 32 minutes, the partner always
|
||||||
|
moving, no voice): 22 MB sent to the server, against 113 MB before (2026-10-04). That's about 12
|
||||||
|
KB/s: 6 from the host, 5.5 from the partner. Both machines must run the same version of the game:
|
||||||
|
the hello and the welcome carry `CoopSession.PROTOCOL`, and a mismatch ends the session with a
|
||||||
|
message on both sides.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
|
@ -109,6 +136,10 @@ nothing on a LAN. Online, check it against your GD-Sync plan's data allowance.
|
||||||
`--discover` uses the network announcements instead. `--online` plays through GD-Sync's
|
`--discover` uses the network announcements instead. `--online` plays through GD-Sync's
|
||||||
servers (needs the keys): the partner finds the host's lobby in the online list. Give both
|
servers (needs the keys): the partner finds the host's lobby in the online list. Give both
|
||||||
sides the same `--host-name`, so an old lobby from an earlier run isn't picked by mistake.
|
sides the same `--host-name`, so an old lobby from an earlier run isn't picked by mistake.
|
||||||
|
- **`game/tools/net_budget.gd`** measures the traffic for the GD-Sync data allowance: it plays
|
||||||
|
whole days and nights over a loopback link that packs every message the way GD-Sync does
|
||||||
|
online, and reports what each side sends to the server, by message kind and by phase, plus
|
||||||
|
voice chat's rate while talking. `--nights=5` is a whole vacation.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=host &
|
godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=host &
|
||||||
|
|
|
||||||
|
|
@ -1,144 +1,19 @@
|
||||||
[gd_resource type="Resource" script_class="GameConfig" format=3]
|
[gd_resource type="Resource" script_class="GameConfig" format=3 uid="uid://cqvl4hhgydj86"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://game/scripts/game_config.gd" id="1_cfg"]
|
[ext_resource type="Script" uid="uid://bow5a4dimtdto" path="res://game/scripts/game_config.gd" id="1_cfg"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_cfg")
|
script = ExtResource("1_cfg")
|
||||||
campaign_nights = 5
|
|
||||||
day_length = 180.0
|
|
||||||
dusk_length = 30.0
|
|
||||||
night_length = 150.0
|
|
||||||
dawn_grace = 20.0
|
|
||||||
allow_early_night = false
|
|
||||||
scarecrow_max_hp = 3
|
|
||||||
start_crops = 30
|
|
||||||
start_animals = 8
|
|
||||||
start_structures = Array[Dictionary]([{
|
|
||||||
"rot": 2,
|
|
||||||
"type": "gate",
|
|
||||||
"x": 4.0,
|
|
||||||
"z": -6.0
|
|
||||||
}])
|
|
||||||
fear_drops_loot = true
|
|
||||||
loot_returns_at_dawn = true
|
|
||||||
max_following_animals = 5
|
|
||||||
crop_steal_time = 2.5
|
|
||||||
animal_capture_time = 2.0
|
|
||||||
supply_steal_time = 1.0
|
|
||||||
supply_bundle = 5
|
|
||||||
stray_speed = 1.1
|
|
||||||
animal_wander_interval = 10.0
|
|
||||||
animal_calm_time = 30.0
|
|
||||||
follow_speed = 6.0
|
|
||||||
target_weights = {
|
|
||||||
"animals": 1.0,
|
|
||||||
"crops": 2.0,
|
|
||||||
"supplies": 1.0
|
|
||||||
}
|
|
||||||
pickup_radius = 1.3
|
|
||||||
combat_height = 1.8
|
|
||||||
pitchfork_reach = 2.2
|
|
||||||
pitchfork_arc = 100.0
|
|
||||||
pitchfork_damage = 2
|
|
||||||
pitchfork_targets = 3
|
|
||||||
pitchfork_interval = 0.5
|
|
||||||
bomb_range = 10.0
|
|
||||||
bomb_min_range = 2.0
|
|
||||||
bomb_speed = 12.0
|
|
||||||
bomb_radius = 3.0
|
|
||||||
bomb_damage = 3
|
|
||||||
bomb_cooldown = 4.0
|
|
||||||
fire_rate = 6.0
|
|
||||||
projectile_speed = 24.0
|
|
||||||
projectile_lifetime = 2.0
|
|
||||||
projectile_capacity = 64
|
|
||||||
muzzle_distance = 1.05
|
|
||||||
aim_dead_zone = 0.3
|
|
||||||
mouse_switch_threshold = 12.0
|
|
||||||
enemy_capacity = 800
|
|
||||||
enemy_radius = 0.3
|
|
||||||
nav_cell_size = 0.5
|
|
||||||
nav_inflate_margin = 0.05
|
|
||||||
separation_radius = 0.8
|
|
||||||
separation_weight = 1.4
|
|
||||||
max_correction_per_tick = 0.15
|
|
||||||
direct_seek_distance = 12.0
|
|
||||||
night_thieves = 0
|
|
||||||
thief_spawn_interval = 6.0
|
|
||||||
trickle_type = "crow"
|
|
||||||
trickle_target = "any"
|
|
||||||
enemy_types = {
|
|
||||||
"breaker": {
|
|
||||||
"acceleration": 8.0,
|
|
||||||
"aggression": "fight",
|
|
||||||
"aggro_range": 4.0,
|
|
||||||
"carry_speed": 0.0,
|
|
||||||
"damage": 2,
|
|
||||||
"flying": false,
|
|
||||||
"hit_interval": 1.5,
|
|
||||||
"hit_radius": 0.55,
|
|
||||||
"hp": 6,
|
|
||||||
"speed": 1.9,
|
|
||||||
"steal_time": 0.0,
|
|
||||||
"structure_damage": 8,
|
|
||||||
"targets": ["structures"]
|
|
||||||
},
|
|
||||||
"crow": {
|
|
||||||
"acceleration": 18.0,
|
|
||||||
"aggression": "none",
|
|
||||||
"aggro_range": 0.0,
|
|
||||||
"carry_speed": 0.75,
|
|
||||||
"damage": 0,
|
|
||||||
"flying": true,
|
|
||||||
"hit_interval": 1.0,
|
|
||||||
"hit_radius": 0.45,
|
|
||||||
"hp": 1,
|
|
||||||
"speed": 5.5,
|
|
||||||
"steal_time": 0.8,
|
|
||||||
"structure_damage": 0,
|
|
||||||
"targets": ["crops"]
|
|
||||||
},
|
|
||||||
"thief": {
|
|
||||||
"acceleration": 14.0,
|
|
||||||
"aggression": "contact",
|
|
||||||
"aggro_range": 0.0,
|
|
||||||
"carry_speed": 0.7,
|
|
||||||
"damage": 1,
|
|
||||||
"flying": false,
|
|
||||||
"hit_interval": 1.2,
|
|
||||||
"hit_radius": 0.4,
|
|
||||||
"hp": 3,
|
|
||||||
"speed": 3.0,
|
|
||||||
"steal_time": 1.0,
|
|
||||||
"structure_damage": 2,
|
|
||||||
"targets": ["animals", "supplies"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cruise_altitude = 3.2
|
|
||||||
land_altitude = 1.55
|
|
||||||
guard_range = 6.0
|
|
||||||
invulnerability_time = 1.0
|
|
||||||
fear_radius = 6.0
|
|
||||||
fear_cooldown = 12.0
|
|
||||||
fear_duration = 2.0
|
|
||||||
patch_time = 2.0
|
|
||||||
patch_heal = 3
|
|
||||||
sprint_speed_mult = 1.6
|
|
||||||
sprint_time = 3.0
|
|
||||||
sprint_cooldown = 10.0
|
|
||||||
enemy_attack_reach = 0.25
|
|
||||||
flee_speed_factor = 1.15
|
|
||||||
start_wood = 4
|
|
||||||
start_scrap = 2
|
|
||||||
start_straw = 4
|
|
||||||
pouch_capacity = 16
|
|
||||||
gather_time = 1.5
|
|
||||||
costs = {
|
costs = {
|
||||||
"automated_defense": {
|
"automated_defense": {
|
||||||
"scrap": 6,
|
"scrap": 6,
|
||||||
"straw": 2,
|
"straw": 2,
|
||||||
"wood": 2
|
"wood": 2
|
||||||
},
|
},
|
||||||
|
"corn_shooter": {
|
||||||
|
"scrap": 10,
|
||||||
|
"wood": 4
|
||||||
|
},
|
||||||
"fence": {
|
"fence": {
|
||||||
"wood": 2
|
"wood": 2
|
||||||
},
|
},
|
||||||
|
|
@ -146,82 +21,127 @@ costs = {
|
||||||
"scrap": 1,
|
"scrap": 1,
|
||||||
"wood": 4
|
"wood": 4
|
||||||
},
|
},
|
||||||
"patch": {
|
|
||||||
"straw": 2
|
|
||||||
},
|
|
||||||
"slowing_trap": {
|
|
||||||
"scrap": 3,
|
|
||||||
"wood": 1
|
|
||||||
},
|
|
||||||
"straw_stuffing": {
|
|
||||||
"straw": 12,
|
|
||||||
"wood": 4
|
|
||||||
},
|
|
||||||
"sprint": {
|
|
||||||
"straw": 6,
|
|
||||||
"wood": 8
|
|
||||||
},
|
|
||||||
"corn_shooter": {
|
|
||||||
"scrap": 10,
|
|
||||||
"wood": 4
|
|
||||||
},
|
|
||||||
"pumpkin_bomb": {
|
|
||||||
"scrap": 6,
|
|
||||||
"straw": 12
|
|
||||||
},
|
|
||||||
"rapid_fire": {
|
|
||||||
"scrap": 12,
|
|
||||||
"wood": 8
|
|
||||||
},
|
|
||||||
"heavy_seeds": {
|
"heavy_seeds": {
|
||||||
"scrap": 14,
|
"scrap": 14,
|
||||||
"straw": 10
|
"straw": 10
|
||||||
},
|
},
|
||||||
"wide_fear": {
|
|
||||||
"straw": 20,
|
|
||||||
"wood": 4
|
|
||||||
},
|
|
||||||
"quick_fear": {
|
|
||||||
"scrap": 6,
|
|
||||||
"straw": 16
|
|
||||||
},
|
|
||||||
"reinforced_fences": {
|
|
||||||
"scrap": 6,
|
|
||||||
"wood": 20
|
|
||||||
},
|
|
||||||
"long_range": {
|
"long_range": {
|
||||||
"scrap": 14,
|
"scrap": 14,
|
||||||
"wood": 10
|
"wood": 10
|
||||||
},
|
},
|
||||||
|
"patch": {
|
||||||
|
"straw": 2
|
||||||
|
},
|
||||||
|
"pumpkin_bomb": {
|
||||||
|
"scrap": 6,
|
||||||
|
"straw": 12
|
||||||
|
},
|
||||||
|
"quick_fear": {
|
||||||
|
"scrap": 6,
|
||||||
|
"straw": 16
|
||||||
|
},
|
||||||
|
"rapid_fire": {
|
||||||
|
"scrap": 12,
|
||||||
|
"straw": 12,
|
||||||
|
"wood": 8
|
||||||
|
},
|
||||||
|
"reinforced_fences": {
|
||||||
|
"scrap": 6,
|
||||||
|
"wood": 20
|
||||||
|
},
|
||||||
|
"slowing_trap": {
|
||||||
|
"scrap": 3,
|
||||||
|
"wood": 1
|
||||||
|
},
|
||||||
|
"sprint": {
|
||||||
|
"straw": 6,
|
||||||
|
"wood": 8
|
||||||
|
},
|
||||||
"sticky_tar": {
|
"sticky_tar": {
|
||||||
"scrap": 6,
|
"scrap": 6,
|
||||||
"straw": 14
|
"straw": 14
|
||||||
|
},
|
||||||
|
"straw_stuffing": {
|
||||||
|
"straw": 12,
|
||||||
|
"wood": 4
|
||||||
|
},
|
||||||
|
"wide_fear": {
|
||||||
|
"straw": 20,
|
||||||
|
"wood": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shot_damage = 1
|
|
||||||
upgrades = {
|
upgrades = {
|
||||||
"corn_shooter": {"name": "Corn shooter", "text": "A gun that fires corn kernels, from afar", "track": "Weapon"},
|
"corn_shooter": {
|
||||||
"heavy_seeds": {"add": 1, "name": "Heavy seeds", "requires": "corn_shooter", "stat": "shot_damage", "text": "Each kernel does 2 damage", "track": "Weapon"},
|
"name": "Corn shooter",
|
||||||
"long_range": {"mult": 1.3, "name": "Long-range defenses", "stat": "turret_range", "text": "Automated defenses reach 30% farther", "track": "Defenses"},
|
"text": "A gun that fires corn kernels, from afar",
|
||||||
"pumpkin_bomb": {"name": "Pumpkin bombs", "text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)", "track": "Weapon"},
|
"track": "Weapon"
|
||||||
"quick_fear": {"mult": 0.8, "name": "Quick fear", "stat": "fear_cooldown", "text": "Fear recharges 20% faster", "track": "Fear"},
|
},
|
||||||
"rapid_fire": {"mult": 1.333, "name": "Rapid fire", "requires": "corn_shooter", "stat": "fire_rate", "text": "The corn shooter fires a third faster", "track": "Weapon"},
|
"heavy_seeds": {
|
||||||
"reinforced_fences": {"mult": 1.5, "name": "Reinforced fences", "stat": "barrier_hp", "text": "Fences and gates +50% health", "track": "Defenses"},
|
"add": 1,
|
||||||
"sprint": {"name": "Sprint", "text": "Sprint 60% faster for 3 s at a time, every 10 s", "track": "Scarecrow"},
|
"name": "Heavy seeds",
|
||||||
"sticky_tar": {"mult": 1.5, "name": "Sticky tar", "stat": "trap_slow_time", "text": "Slowing traps hold 50% longer", "track": "Defenses"},
|
"requires": "corn_shooter",
|
||||||
"straw_stuffing": {"add": 2, "name": "Straw stuffing", "stat": "scarecrow_max_hp", "text": "+2 max health", "track": "Scarecrow"},
|
"stat": "shot_damage",
|
||||||
"wide_fear": {"mult": 1.3, "name": "Wide fear", "stat": "fear_radius", "text": "Fear reaches 30% farther", "track": "Fear"}
|
"text": "Each kernel does 2 damage",
|
||||||
|
"track": "Weapon"
|
||||||
|
},
|
||||||
|
"long_range": {
|
||||||
|
"mult": 1.3,
|
||||||
|
"name": "Long-range defenses",
|
||||||
|
"stat": "turret_range",
|
||||||
|
"text": "Automated defenses reach 30% farther",
|
||||||
|
"track": "Defenses"
|
||||||
|
},
|
||||||
|
"pumpkin_bomb": {
|
||||||
|
"name": "Pumpkin bombs",
|
||||||
|
"text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)",
|
||||||
|
"track": "Weapon"
|
||||||
|
},
|
||||||
|
"quick_fear": {
|
||||||
|
"mult": 0.8,
|
||||||
|
"name": "Quick fear",
|
||||||
|
"stat": "fear_cooldown",
|
||||||
|
"text": "Fear recharges 20% faster",
|
||||||
|
"track": "Fear"
|
||||||
|
},
|
||||||
|
"rapid_fire": {
|
||||||
|
"mult": 3.0,
|
||||||
|
"name": "Rapid fire",
|
||||||
|
"requires": "corn_shooter",
|
||||||
|
"stat": "fire_rate",
|
||||||
|
"text": "The corn shooter fires 3x faster!!!!!",
|
||||||
|
"track": "Weapon"
|
||||||
|
},
|
||||||
|
"reinforced_fences": {
|
||||||
|
"mult": 1.5,
|
||||||
|
"name": "Reinforced fences",
|
||||||
|
"stat": "barrier_hp",
|
||||||
|
"text": "Fences and gates +50% health",
|
||||||
|
"track": "Defenses"
|
||||||
|
},
|
||||||
|
"sprint": {
|
||||||
|
"name": "Sprint",
|
||||||
|
"text": "Sprint 60% faster for 3 s at a time, every 10 s",
|
||||||
|
"track": "Scarecrow"
|
||||||
|
},
|
||||||
|
"sticky_tar": {
|
||||||
|
"mult": 1.5,
|
||||||
|
"name": "Sticky tar",
|
||||||
|
"stat": "trap_slow_time",
|
||||||
|
"text": "Slowing traps hold 50% longer",
|
||||||
|
"track": "Defenses"
|
||||||
|
},
|
||||||
|
"straw_stuffing": {
|
||||||
|
"add": 2,
|
||||||
|
"name": "Straw stuffing",
|
||||||
|
"stat": "scarecrow_max_hp",
|
||||||
|
"text": "+2 max health",
|
||||||
|
"track": "Scarecrow"
|
||||||
|
},
|
||||||
|
"wide_fear": {
|
||||||
|
"mult": 1.3,
|
||||||
|
"name": "Wide fear",
|
||||||
|
"stat": "fear_radius",
|
||||||
|
"text": "Fear reaches 30% farther",
|
||||||
|
"track": "Fear"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fence_hp = 20
|
|
||||||
gate_hp = 30
|
|
||||||
trap_triggers = 10
|
|
||||||
turret_hp = 25
|
|
||||||
trap_slow_factor = 0.5
|
|
||||||
trap_slow_time = 2.0
|
|
||||||
turret_range = 7.0
|
|
||||||
turret_fire_interval = 1.0
|
|
||||||
build_range = 9.0
|
|
||||||
barrier_detour = 18.0
|
|
||||||
repair_time = 1.5
|
|
||||||
dismantle_refund = 0.5
|
|
||||||
flow_slice_cells = 2000
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
[gd_scene format=3 uid="uid://dfg4ba00jby52"]
|
[gd_scene format=3 uid="uid://dfg4ba00jby52"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" path="res://game/scenes/player.tscn" id="1_player"]
|
[ext_resource type="PackedScene" path="res://game/scenes/player.tscn" id="1_player"]
|
||||||
[ext_resource type="PackedScene" uid="uid://jrpjchi0u7h1" path="res://assets/farm/ithappy/farm/prefabs/assets/ground/ground_004.tscn" id="2_aqlkk"]
|
|
||||||
[ext_resource type="Script" uid="uid://bdlmtj20npler" path="res://game/scripts/follow_camera.gd" id="2_camera"]
|
[ext_resource type="Script" uid="uid://bdlmtj20npler" path="res://game/scripts/follow_camera.gd" id="2_camera"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bq421knnjuapb" path="res://assets/farm/ithappy/farm/textures/Skybox_3.png" id="3_sky"]
|
[ext_resource type="Texture2D" uid="uid://bq421knnjuapb" path="res://assets/farm/ithappy/farm/textures/Skybox_3.png" id="3_sky"]
|
||||||
[ext_resource type="PackedScene" uid="uid://wbiymevvh11y" path="res://assets/farm/ithappy/farm/prefabs/assets/ground/ground_008.tscn" id="4_wbrnf"]
|
[ext_resource type="PackedScene" uid="uid://wbiymevvh11y" path="res://assets/farm/ithappy/farm/prefabs/assets/ground/ground_008.tscn" id="4_wbrnf"]
|
||||||
|
|
@ -61,6 +60,8 @@
|
||||||
[ext_resource type="PackedScene" uid="uid://cnbrd60dxlvir" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/firewood_007.tscn" id="62_ibwhs"]
|
[ext_resource type="PackedScene" uid="uid://cnbrd60dxlvir" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/firewood_007.tscn" id="62_ibwhs"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bmvokusoktgrl" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/barrel_009.tscn" id="63_ocduh"]
|
[ext_resource type="PackedScene" uid="uid://bmvokusoktgrl" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/barrel_009.tscn" id="63_ocduh"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bm13bxk1epllr" path="res://assets/farm/ithappy/farm/prefabs/assets/box/box_005.tscn" id="67_1l04x"]
|
[ext_resource type="PackedScene" uid="uid://bm13bxk1epllr" path="res://assets/farm/ithappy/farm/prefabs/assets/box/box_005.tscn" id="67_1l04x"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://xk5grl6lppsb" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/pig_003.tscn" id="83_ii3ah"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bmouuf8wgqyih" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/pig_004.tscn" id="84_pjvu8"]
|
||||||
[ext_resource type="Script" uid="uid://dh1gl5p44sjb1" path="res://game/scripts/campaign_controller.gd" id="100_campaign"]
|
[ext_resource type="Script" uid="uid://dh1gl5p44sjb1" path="res://game/scripts/campaign_controller.gd" id="100_campaign"]
|
||||||
[ext_resource type="Script" uid="uid://bvvdfx5idf2u5" path="res://game/scripts/campaign_debug.gd" id="101_campaign_debug"]
|
[ext_resource type="Script" uid="uid://bvvdfx5idf2u5" path="res://game/scripts/campaign_debug.gd" id="101_campaign_debug"]
|
||||||
[ext_resource type="Script" uid="uid://c6auf64ahke4k" path="res://game/scripts/farm_sim.gd" id="102_farm_sim"]
|
[ext_resource type="Script" uid="uid://c6auf64ahke4k" path="res://game/scripts/farm_sim.gd" id="102_farm_sim"]
|
||||||
|
|
@ -95,8 +96,6 @@
|
||||||
[ext_resource type="PackedScene" uid="uid://dw1k3ilpn8nll" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/coop_002.tscn" id="217_coop_002"]
|
[ext_resource type="PackedScene" uid="uid://dw1k3ilpn8nll" path="res://assets/farm/ithappy/farm/prefabs/assets/prop/coop_002.tscn" id="217_coop_002"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cr17qkqcl5n5k" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/chicken_001.tscn" id="218_chicken_001"]
|
[ext_resource type="PackedScene" uid="uid://cr17qkqcl5n5k" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/chicken_001.tscn" id="218_chicken_001"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b1awnl6wg6nur" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/chicken_003.tscn" id="219_chicken_003"]
|
[ext_resource type="PackedScene" uid="uid://b1awnl6wg6nur" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/chicken_003.tscn" id="219_chicken_003"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bcf3tnu5qstko" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/pig_001.tscn" id="220_pig_001"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://db8s5hgxgc7v1" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/pig_002.tscn" id="221_pig_002"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://luky4yj34cxl" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/sheep_001.tscn" id="222_sheep_001"]
|
[ext_resource type="PackedScene" uid="uid://luky4yj34cxl" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/sheep_001.tscn" id="222_sheep_001"]
|
||||||
[ext_resource type="PackedScene" uid="uid://lu1yig6lm1cf" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/sheep_002.tscn" id="223_sheep_002"]
|
[ext_resource type="PackedScene" uid="uid://lu1yig6lm1cf" path="res://assets/farm/ithappy/farm/prefabs/assets/animal/sheep_002.tscn" id="223_sheep_002"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bama3ewighjxc" path="res://assets/farm/ithappy/farm/prefabs/assets/tree/dry_wood_008.tscn" id="224_dry_wood_008"]
|
[ext_resource type="PackedScene" uid="uid://bama3ewighjxc" path="res://assets/farm/ithappy/farm/prefabs/assets/tree/dry_wood_008.tscn" id="224_dry_wood_008"]
|
||||||
|
|
@ -164,9 +163,6 @@ shape = SubResource("Box_ground")
|
||||||
|
|
||||||
[node name="Level" type="Node3D" parent="." unique_id=809922080]
|
[node name="Level" type="Node3D" parent="." unique_id=809922080]
|
||||||
|
|
||||||
[node name="ground_004_005" parent="Level" unique_id=261290431 instance=ExtResource("2_aqlkk")]
|
|
||||||
transform = Transform3D(1.4, 0, 0, 0, 1, 0, 0, 0, 1.4, 20.554321, -1.1, -31.602497)
|
|
||||||
|
|
||||||
[node name="ground_008_004" parent="Level" unique_id=975238962 instance=ExtResource("4_wbrnf")]
|
[node name="ground_008_004" parent="Level" unique_id=975238962 instance=ExtResource("4_wbrnf")]
|
||||||
transform = Transform3D(-0.45, 0, 3.115315e-07, 0, 1, 0, -1.7523647e-07, 0, -0.8, -7.1738434, 0.20026417, 30.275806)
|
transform = Transform3D(-0.45, 0, 3.115315e-07, 0, 1, 0, -1.7523647e-07, 0, -0.8, -7.1738434, 0.20026417, 30.275806)
|
||||||
|
|
||||||
|
|
@ -219,7 +215,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 52.55432, -0.15, -39.402496)
|
||||||
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 52.55432, -0.15, -52.402496)
|
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 52.55432, -0.15, -52.402496)
|
||||||
|
|
||||||
[node name="road_007_214" parent="Level" unique_id=133188723 instance=ExtResource("20_jcd8b")]
|
[node name="road_007_214" parent="Level" unique_id=133188723 instance=ExtResource("20_jcd8b")]
|
||||||
transform = Transform3D(1.7444279e-06, 0, 0.99999994, 0, 1, 0, -0.99999994, 0, 1.7444279e-06, 38.55432, -0.15, -39.402496)
|
transform = Transform3D(1.7444279e-06, 0, 0.99999994, 0, 1, 0, -0.99999994, 0, 1.7444279e-06, 44.45688, -0.15, -39.402496)
|
||||||
|
|
||||||
[node name="road_003_003" parent="Level" unique_id=1458630441 instance=ExtResource("7_km4uj")]
|
[node name="road_003_003" parent="Level" unique_id=1458630441 instance=ExtResource("7_km4uj")]
|
||||||
transform = Transform3D(-1, 0, -1.509958e-07, 0, 1, 0, 1.509958e-07, 0, -1, 50.55432, -0.15, 50.597504)
|
transform = Transform3D(-1, 0, -1.509958e-07, 0, 1, 0, 1.509958e-07, 0, -1, 50.55432, -0.15, 50.597504)
|
||||||
|
|
@ -351,7 +347,7 @@ transform = Transform3D(1.9470717e-07, 0, -0.99999994, 0, 1, 0, 0.99999994, 0, 1
|
||||||
transform = Transform3D(1.9470717e-07, 0, -0.99999994, 0, 1, 0, 0.99999994, 0, 1.9470717e-07, -5.442215, 0.21197988, -25.499416)
|
transform = Transform3D(1.9470717e-07, 0, -0.99999994, 0, 1, 0, 0.99999994, 0, 1.9470717e-07, -5.442215, 0.21197988, -25.499416)
|
||||||
|
|
||||||
[node name="tractor_004_002" parent="Level" unique_id=501002737 instance=ExtResource("40_ckas0")]
|
[node name="tractor_004_002" parent="Level" unique_id=501002737 instance=ExtResource("40_ckas0")]
|
||||||
transform = Transform3D(0.9348669, 0, 0.3549982, 0, 1, 0, -0.3549982, 0, 0.9348669, 29.917847, 0.33919105, -24.772142)
|
transform = Transform3D(0.49243984, 0, 0.8703466, 0, 1, 0, -0.8703466, 0, 0.49243984, -17.001213, 0.33919105, 7.986433)
|
||||||
|
|
||||||
[node name="truck_003_005" parent="Level" unique_id=444048277 instance=ExtResource("42_dbth4")]
|
[node name="truck_003_005" parent="Level" unique_id=444048277 instance=ExtResource("42_dbth4")]
|
||||||
transform = Transform3D(0.999992, 0, -0.0039759804, 0, 1, 0, 0.0039759804, 0, 0.999992, -31.17688, 0.42419434, -30.661972)
|
transform = Transform3D(0.999992, 0, -0.0039759804, 0, 1, 0, 0.0039759804, 0, 0.999992, -31.17688, 0.42419434, -30.661972)
|
||||||
|
|
@ -360,13 +356,13 @@ transform = Transform3D(0.999992, 0, -0.0039759804, 0, 1, 0, 0.0039759804, 0, 0.
|
||||||
transform = Transform3D(0.9998416, 0, 0.017796231, 0, 1, 0, -0.017796231, 0, 0.9998416, -31.17688, 0.42419434, -35.130516)
|
transform = Transform3D(0.9998416, 0, 0.017796231, 0, 1, 0, -0.017796231, 0, 0.9998416, -31.17688, 0.42419434, -35.130516)
|
||||||
|
|
||||||
[node name="house_009_001" parent="Level" unique_id=2142693081 instance=ExtResource("44_7r7nk")]
|
[node name="house_009_001" parent="Level" unique_id=2142693081 instance=ExtResource("44_7r7nk")]
|
||||||
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, 0.30000007, -25.502497)
|
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, -0.049314618, -25.502497)
|
||||||
|
|
||||||
[node name="house_025_001" parent="Level" unique_id=895264324 instance=ExtResource("45_bx6mg")]
|
[node name="house_025_001" parent="Level" unique_id=895264324 instance=ExtResource("45_bx6mg")]
|
||||||
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 24.754318, 5, -25.502493)
|
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 24.754318, 4.856963, -25.502493)
|
||||||
|
|
||||||
[node name="house_027_001" parent="Level" unique_id=560007779 instance=ExtResource("46_45nvc")]
|
[node name="house_027_001" parent="Level" unique_id=560007779 instance=ExtResource("46_45nvc")]
|
||||||
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, 4.8, -25.902496)
|
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, 4.5445137, -25.902496)
|
||||||
|
|
||||||
[node name="house_026_001" parent="Level" unique_id=237182657 instance=ExtResource("47_7fcm6")]
|
[node name="house_026_001" parent="Level" unique_id=237182657 instance=ExtResource("47_7fcm6")]
|
||||||
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, 5, -27.302496)
|
transform = Transform3D(-1, 0, 3.8941437e-07, 0, 1, 0, -3.8941437e-07, 0, -1, 20.554321, 5, -27.302496)
|
||||||
|
|
@ -843,7 +839,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 28.329895, 0.048398007, -47.9
|
||||||
transform = Transform3D(0.27501097, 0, -0.9614411, 0, 1, 0, 0.9614411, 0, 0.27501097, 34.74295, 0.037176825, -43.372574)
|
transform = Transform3D(0.27501097, 0, -0.9614411, 0, 1, 0, 0.9614411, 0, 0.27501097, 34.74295, 0.037176825, -43.372574)
|
||||||
|
|
||||||
[node name="firewood_007_001" parent="Level" unique_id=461904041 instance=ExtResource("62_ibwhs")]
|
[node name="firewood_007_001" parent="Level" unique_id=461904041 instance=ExtResource("62_ibwhs")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 20.58171, -0.14911968, -19.34561)
|
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -24.96482, -0.14911968, -14.9785795)
|
||||||
|
|
||||||
[node name="fence_020_126" parent="Level" unique_id=338697674 instance=ExtResource("48_nml3e")]
|
[node name="fence_020_126" parent="Level" unique_id=338697674 instance=ExtResource("48_nml3e")]
|
||||||
transform = Transform3D(1.9470717e-07, 0, 0.99999994, 0, 1, 0, -0.99999994, 0, 1.9470717e-07, 56.054337, -0.1, 53.42751)
|
transform = Transform3D(1.9470717e-07, 0, 0.99999994, 0, 1, 0, -0.99999994, 0, 1.9470717e-07, 56.054337, -0.1, 53.42751)
|
||||||
|
|
@ -1006,7 +1002,7 @@ sim = NodePath("../FarmSim")
|
||||||
script = ExtResource("200_farm_zones")
|
script = ExtResource("200_farm_zones")
|
||||||
|
|
||||||
[node name="CropField" type="Node3D" parent="Zones" unique_id=1332218493]
|
[node name="CropField" type="Node3D" parent="Zones" unique_id=1332218493]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 0, -3.6)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 30, -0.36018944, -3.6)
|
||||||
script = ExtResource("201_farm_zone")
|
script = ExtResource("201_farm_zone")
|
||||||
display_name = "Crop Field"
|
display_name = "Crop Field"
|
||||||
size = Vector2(32, 30)
|
size = Vector2(32, 30)
|
||||||
|
|
@ -2287,7 +2283,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.8, 0, 2.4)
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.7, 0, 2.9)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.7, 0, 2.9)
|
||||||
|
|
||||||
[node name="WorkArea" type="Node3D" parent="Zones" unique_id=1622333960]
|
[node name="WorkArea" type="Node3D" parent="Zones" unique_id=1622333960]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 0, -19.5)
|
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 28.599358, 0, -25.317692)
|
||||||
script = ExtResource("201_farm_zone")
|
script = ExtResource("201_farm_zone")
|
||||||
kind = 3
|
kind = 3
|
||||||
display_name = "Work Area"
|
display_name = "Work Area"
|
||||||
|
|
@ -2404,18 +2400,18 @@ transform = Transform3D(-0.866025, 0, 0.5, 0, 1, 0, -0.5, 0, -0.866025, -2.4, 0,
|
||||||
[node name="chicken_003_2" parent="Zones/AnimalPen" unique_id=1156792561 instance=ExtResource("219_chicken_003")]
|
[node name="chicken_003_2" parent="Zones/AnimalPen" unique_id=1156792561 instance=ExtResource("219_chicken_003")]
|
||||||
transform = Transform3D(-0.087156, 0, 0.996195, 0, 1, 0, -0.996195, 0, -0.087156, -5.2, 0, 0)
|
transform = Transform3D(-0.087156, 0, 0.996195, 0, 1, 0, -0.996195, 0, -0.087156, -5.2, 0, 0)
|
||||||
|
|
||||||
[node name="pig_001_1" parent="Zones/AnimalPen" unique_id=2083549518 instance=ExtResource("220_pig_001")]
|
|
||||||
transform = Transform3D(0.34202, 0, 0.939693, 0, 1, 0, -0.939693, 0, 0.34202, 1.4, 0, -3.4)
|
|
||||||
|
|
||||||
[node name="pig_002_1" parent="Zones/AnimalPen" unique_id=334475536 instance=ExtResource("221_pig_002")]
|
|
||||||
transform = Transform3D(-0.5, 0, -0.866025, 0, 1, 0, 0.866025, 0, -0.5, 4, 0, -1.4)
|
|
||||||
|
|
||||||
[node name="sheep_001_1" parent="Zones/AnimalPen" unique_id=1531276024 instance=ExtResource("222_sheep_001")]
|
[node name="sheep_001_1" parent="Zones/AnimalPen" unique_id=1531276024 instance=ExtResource("222_sheep_001")]
|
||||||
transform = Transform3D(0.939693, 0, 0.34202, 0, 1, 0, -0.34202, 0, 0.939693, -0.2, 0, 2.6)
|
transform = Transform3D(0.939693, 0, 0.34202, 0, 1, 0, -0.34202, 0, 0.939693, -0.2, 0, 2.6)
|
||||||
|
|
||||||
[node name="sheep_002_1" parent="Zones/AnimalPen" unique_id=872389713 instance=ExtResource("223_sheep_002")]
|
[node name="sheep_002_1" parent="Zones/AnimalPen" unique_id=872389713 instance=ExtResource("223_sheep_002")]
|
||||||
transform = Transform3D(-0.939693, 0, -0.34202, 0, 1, 0, 0.34202, 0, -0.939693, 4.2, 0, 3)
|
transform = Transform3D(-0.939693, 0, -0.34202, 0, 1, 0, 0.34202, 0, -0.939693, 4.2, 0, 3)
|
||||||
|
|
||||||
|
[node name="pig_0032_1" parent="Zones/AnimalPen" unique_id=313335186 instance=ExtResource("83_ii3ah")]
|
||||||
|
transform = Transform3D(0.8137072, 0, 0.58127505, 0, 1, 0, -0.58127505, 0, 0.8137072, -0.96089816, 0.14581093, -1.607707)
|
||||||
|
|
||||||
|
[node name="pig_0042_1" parent="Zones/AnimalPen" unique_id=1811673858 instance=ExtResource("84_pjvu8")]
|
||||||
|
transform = Transform3D(0.7902554, 0, -0.61277753, 0, 1, 0, 0.61277753, 0, 0.7902554, 3.4401367, 0.13621469, -1.7759986)
|
||||||
|
|
||||||
[node name="Wood" type="Node3D" parent="Zones" unique_id=971465957]
|
[node name="Wood" type="Node3D" parent="Zones" unique_id=971465957]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 42, 0, -28)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 42, 0, -28)
|
||||||
script = ExtResource("201_farm_zone")
|
script = ExtResource("201_farm_zone")
|
||||||
|
|
@ -2712,7 +2708,7 @@ tint = Color(0.55, 0.65, 0.8, 1)
|
||||||
outside = true
|
outside = true
|
||||||
|
|
||||||
[node name="RoadsideCar" type="Node3D" parent="Zones/EastRoad" unique_id=1986628569]
|
[node name="RoadsideCar" type="Node3D" parent="Zones/EastRoad" unique_id=1986628569]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.87, 0, 0.62)
|
transform = Transform3D(0.9081948, 0, 0.41854778, 0, 1, 0, -0.41854778, 0, 0.9081948, 4.010315, 0, 3.4309368)
|
||||||
script = ExtResource("108_gather")
|
script = ExtResource("108_gather")
|
||||||
material = "scrap"
|
material = "scrap"
|
||||||
max_charges = 4
|
max_charges = 4
|
||||||
|
|
@ -2724,7 +2720,7 @@ clip = &"Hammering"
|
||||||
transform = Transform3D(-1, 0, -3.8941437e-07, 0, 1, 0, 3.8941437e-07, 0, -1, -0.0017, 0.48251343, -0.001)
|
transform = Transform3D(-1, 0, -3.8941437e-07, 0, 1, 0, 3.8941437e-07, 0, -1, -0.0017, 0.48251343, -0.001)
|
||||||
|
|
||||||
[node name="RoadsideBarrels" type="Node3D" parent="Zones/EastRoad" unique_id=1131456836]
|
[node name="RoadsideBarrels" type="Node3D" parent="Zones/EastRoad" unique_id=1131456836]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, -5.5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.0526924, 0, -10.6225815)
|
||||||
script = ExtResource("108_gather")
|
script = ExtResource("108_gather")
|
||||||
material = "scrap"
|
material = "scrap"
|
||||||
max_charges = 3
|
max_charges = 3
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ class_name CoopLink
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## The wire between the two machines of a co-op game (CoopSession talks only to this). send()
|
## The wire between the two machines of a co-op game (CoopSession talks only to this). send()
|
||||||
## delivers one message (a kind and a Variant) to the other side, reliably (in order, never
|
## delivers one message (a kind and a Variant) to the other side, reliably (in order, never
|
||||||
## lost) or not (may be dropped; for the 20 Hz snapshots and the partner's input, which the next
|
## lost) or not (may be dropped; for the snapshots and the partner's input, which the next one
|
||||||
## one replaces). received is emitted on the other side.
|
## replaces). received is emitted on the other side.
|
||||||
|
## Messages over COMPRESS_OVER bytes go out compressed (kind "z": [size, zstd bytes]) and are
|
||||||
|
## unpacked by receive(). GD-Sync compresses its packets only after encrypting them, which saves
|
||||||
|
## nothing, so this is the only compression co-op traffic gets.
|
||||||
## GDSyncLink is the real one (GD-Sync, LAN or online). CoopLink.pair() makes two loopback links
|
## GDSyncLink is the real one (GD-Sync, LAN or online). CoopLink.pair() makes two loopback links
|
||||||
## for tests: messages go through var_to_bytes / bytes_to_var like on the wire, and are delivered
|
## for tests: messages go through var_to_bytes / bytes_to_var like on the wire, and are delivered
|
||||||
## when the receiving side polls. Every link counts what it sends; unreliable messages over
|
## when the receiving side polls. Every link counts what it sends; unreliable messages over
|
||||||
|
|
@ -12,18 +15,35 @@ extends RefCounted
|
||||||
signal received(kind: String, data: Variant)
|
signal received(kind: String, data: Variant)
|
||||||
|
|
||||||
const UNRELIABLE_LIMIT := 1100
|
const UNRELIABLE_LIMIT := 1100
|
||||||
|
const COMPRESS_OVER := 256
|
||||||
|
## The largest message receive() unpacks (bytes, uncompressed).
|
||||||
|
const UNPACK_LIMIT := 1 << 20
|
||||||
|
|
||||||
var sent_messages: int = 0
|
var sent_messages: int = 0
|
||||||
var sent_bytes: int = 0
|
var sent_bytes: int = 0
|
||||||
## The largest unreliable message so far (bytes) and how many were over the limit.
|
## The largest unreliable message so far (bytes) and how many were over the limit.
|
||||||
var largest_unreliable: int = 0
|
var largest_unreliable: int = 0
|
||||||
var oversized: int = 0
|
var oversized: int = 0
|
||||||
|
## kind -> [messages, bytes] sent (bytes as sent, after compression).
|
||||||
|
var sent_kinds := {}
|
||||||
## Set when the other side went away.
|
## Set when the other side went away.
|
||||||
var closed := false
|
var closed := false
|
||||||
|
|
||||||
|
|
||||||
func send(kind: String, data: Variant, reliable: bool) -> void:
|
func send(kind: String, data: Variant, reliable: bool) -> void:
|
||||||
var size := var_to_bytes([kind, data]).size()
|
var label := kind
|
||||||
|
var bytes := var_to_bytes([kind, data])
|
||||||
|
var size := bytes.size()
|
||||||
|
if size > COMPRESS_OVER:
|
||||||
|
var packed := bytes.compress(FileAccess.COMPRESSION_ZSTD)
|
||||||
|
if packed.size() + 16 < size:
|
||||||
|
kind = "z"
|
||||||
|
data = [size, packed]
|
||||||
|
size = var_to_bytes([kind, data]).size()
|
||||||
|
var tally: Array = sent_kinds.get(label, [0, 0])
|
||||||
|
tally[0] += 1
|
||||||
|
tally[1] += size
|
||||||
|
sent_kinds[label] = tally
|
||||||
sent_messages += 1
|
sent_messages += 1
|
||||||
sent_bytes += size
|
sent_bytes += size
|
||||||
if not reliable:
|
if not reliable:
|
||||||
|
|
@ -33,6 +53,22 @@ func send(kind: String, data: Variant, reliable: bool) -> void:
|
||||||
_deliver(kind, data, reliable)
|
_deliver(kind, data, reliable)
|
||||||
|
|
||||||
|
|
||||||
|
## Messages of a kind sent so far.
|
||||||
|
func sent_count(kind: String) -> int:
|
||||||
|
return int(sent_kinds.get(kind, [0, 0])[0])
|
||||||
|
|
||||||
|
|
||||||
|
## A message from the other side (unpacked if it came compressed): emits received.
|
||||||
|
func receive(kind: String, data: Variant) -> void:
|
||||||
|
if kind == "z":
|
||||||
|
var m: Variant = _unpack(data)
|
||||||
|
if m == null:
|
||||||
|
return
|
||||||
|
kind = String(m[0])
|
||||||
|
data = m[1]
|
||||||
|
received.emit(kind, data)
|
||||||
|
|
||||||
|
|
||||||
## Delivers what has arrived (loopback links; GD-Sync delivers on its own).
|
## Delivers what has arrived (loopback links; GD-Sync delivers on its own).
|
||||||
func poll() -> void:
|
func poll() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
@ -46,6 +82,84 @@ func _deliver(_kind: String, _data: Variant, _reliable: bool) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
static func _unpack(data: Variant) -> Variant:
|
||||||
|
if not (data is Array) or (data as Array).size() != 2 or not (data[1] is PackedByteArray):
|
||||||
|
return null
|
||||||
|
var size := int(data[0])
|
||||||
|
if size <= 0 or size > UNPACK_LIMIT:
|
||||||
|
return null
|
||||||
|
var bytes := (data[1] as PackedByteArray).decompress(size, FileAccess.COMPRESSION_ZSTD)
|
||||||
|
if bytes.size() != size:
|
||||||
|
return null
|
||||||
|
var m: Variant = bytes_to_var(bytes)
|
||||||
|
if not (m is Array) or (m as Array).size() != 2 or not (m[0] is String):
|
||||||
|
return null
|
||||||
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
# --- Packing: the binary messages (CoopSession's snapshots, RemoteControls' input) -----------
|
||||||
|
|
||||||
|
static func reader(bytes: PackedByteArray) -> StreamPeerBuffer:
|
||||||
|
var b := StreamPeerBuffer.new()
|
||||||
|
b.data_array = bytes
|
||||||
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
## A length in centimeters (s16: up to 327 m either way).
|
||||||
|
static func put_cm(b: StreamPeerBuffer, v: float) -> void:
|
||||||
|
b.put_16(clampi(roundi(v * 100.0), -32768, 32767))
|
||||||
|
|
||||||
|
|
||||||
|
static func get_cm(b: StreamPeerBuffer) -> float:
|
||||||
|
return b.get_16() / 100.0
|
||||||
|
|
||||||
|
|
||||||
|
static func put_v3(b: StreamPeerBuffer, v: Vector3) -> void:
|
||||||
|
put_cm(b, v.x)
|
||||||
|
put_cm(b, v.y)
|
||||||
|
put_cm(b, v.z)
|
||||||
|
|
||||||
|
|
||||||
|
static func get_v3(b: StreamPeerBuffer) -> Vector3:
|
||||||
|
var x := get_cm(b)
|
||||||
|
var y := get_cm(b)
|
||||||
|
return Vector3(x, y, get_cm(b))
|
||||||
|
|
||||||
|
|
||||||
|
## An angle in radians (s16).
|
||||||
|
static func put_angle(b: StreamPeerBuffer, a: float) -> void:
|
||||||
|
b.put_16(roundi(wrapf(a, -PI, PI) * 10000.0))
|
||||||
|
|
||||||
|
|
||||||
|
static func get_angle(b: StreamPeerBuffer) -> float:
|
||||||
|
return b.get_16() / 10000.0
|
||||||
|
|
||||||
|
|
||||||
|
## A timer in centiseconds (u16: 0 to 655 s).
|
||||||
|
static func put_time(b: StreamPeerBuffer, t: float) -> void:
|
||||||
|
b.put_u16(clampi(roundi(t * 100.0), 0, 65535))
|
||||||
|
|
||||||
|
|
||||||
|
static func get_time(b: StreamPeerBuffer) -> float:
|
||||||
|
return b.get_u16() / 100.0
|
||||||
|
|
||||||
|
|
||||||
|
## A short text: a length byte, then up to 255 bytes of UTF-8.
|
||||||
|
static func put_text(b: StreamPeerBuffer, s: String) -> void:
|
||||||
|
var u := s.to_utf8_buffer()
|
||||||
|
if u.size() > 255:
|
||||||
|
u = u.slice(0, 255)
|
||||||
|
b.put_u8(u.size())
|
||||||
|
b.put_data(u)
|
||||||
|
|
||||||
|
|
||||||
|
static func get_text(b: StreamPeerBuffer) -> String:
|
||||||
|
var n := b.get_u8()
|
||||||
|
if n == 0:
|
||||||
|
return ""
|
||||||
|
return (b.get_data(n)[1] as PackedByteArray).get_string_from_utf8()
|
||||||
|
|
||||||
|
|
||||||
## Two loopback links, each the other's far end.
|
## Two loopback links, each the other's far end.
|
||||||
static func pair() -> Array[CoopLink]:
|
static func pair() -> Array[CoopLink]:
|
||||||
var a := Loopback.new()
|
var a := Loopback.new()
|
||||||
|
|
@ -75,7 +189,7 @@ class Loopback extends CoopLink:
|
||||||
_inbox = []
|
_inbox = []
|
||||||
for bytes: PackedByteArray in batch:
|
for bytes: PackedByteArray in batch:
|
||||||
var m: Array = bytes_to_var(bytes)
|
var m: Array = bytes_to_var(bytes)
|
||||||
received.emit(String(m[0]), m[1])
|
receive(String(m[0]), m[1])
|
||||||
|
|
||||||
func close() -> void:
|
func close() -> void:
|
||||||
closed = true
|
closed = true
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,29 @@ extends Node
|
||||||
##
|
##
|
||||||
## Host -> partner
|
## Host -> partner
|
||||||
## welcome (reliable, once) the farm state, the phase, tonight's time, the loot, the names
|
## welcome (reliable, once) the farm state, the phase, tonight's time, the loot, the names
|
||||||
|
## refused (reliable) the partner's game speaks another PROTOCOL
|
||||||
## batch (reliable, each tick with news) events in order: phase changes (with the state),
|
## batch (reliable, each tick with news) events in order: phase changes (with the state),
|
||||||
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
|
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
|
||||||
## breaches, fear bursts, gather popups, the workbench; enemies removed
|
## breaches, fear bursts, gather popups, the workbench; enemies removed
|
||||||
## state (reliable, at most STATE_HZ, when it changed) the farm state
|
## state (reliable, at most STATE_HZ, when it changed) the farm state (the phase clock
|
||||||
|
## alone isn't a change: it is in every snapshot)
|
||||||
## loot (reliable, at most LOOT_HZ, when it changed) every item
|
## loot (reliable, at most LOOT_HZ, when it changed) every item
|
||||||
## snap (unreliable, SNAP_HZ) the phase clock, both scarecrows, the animals
|
## snap (unreliable, SNAP_HZ) packed bytes: the phase clock, both scarecrows, the
|
||||||
## foes (unreliable, SNAP_HZ, in chunks) every enemy, 16 bytes each
|
## animals, the shots in flight, and the enemies that are due (as many as fit)
|
||||||
## shots (unreliable, SNAP_HZ) the shots in flight
|
## foes (unreliable, with a snapshot) the due enemies that didn't fit, 16 bytes each
|
||||||
## Partner -> host
|
## Partner -> host
|
||||||
## hello (reliable) its player's name
|
## hello (reliable) its player's name and PROTOCOL
|
||||||
## input (unreliable, INPUT_HZ) its scarecrow's position and facing, held buttons and press
|
## input (unreliable, up to INPUT_HZ when it changed, else every INPUT_KEEPALIVE) its
|
||||||
## counts, aim, build mode, the upgrade menu (RemoteControls)
|
## scarecrow's position and facing, held buttons and press counts, aim, build mode,
|
||||||
|
## the upgrade menu (RemoteControls, packed bytes)
|
||||||
## req (reliable) start the day, start the night early, retry the night, build,
|
## req (reliable) start the day, start the night early, retry the night, build,
|
||||||
## dismantle, buy an upgrade
|
## dismantle, buy an upgrade
|
||||||
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
|
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
|
||||||
## arriving (enemies missed by a snapshot appear in the next; removals are reliable).
|
## arriving. Enemies go by dead reckoning: the partner moves each one on at the velocity of its
|
||||||
|
## last record, and the host sends a new record only when that guess drifts (FOE_DRIFT, or the
|
||||||
|
## velocity, heading, altitude, state, or a hit), at least every FOE_REFRESH seconds, and a
|
||||||
|
## record sent for a change (or a new enemy) goes out again in the next snapshots in case one is
|
||||||
|
## lost. Removals are reliable. Large messages go out compressed (CoopLink).
|
||||||
## Voice chat (GD-Sync only, start_voice): a CoopVoice per player, owned by that player's client.
|
## Voice chat (GD-Sync only, start_voice): a CoopVoice per player, owned by that player's client.
|
||||||
|
|
||||||
enum Role { SOLO, HOST, CLIENT }
|
enum Role { SOLO, HOST, CLIENT }
|
||||||
|
|
@ -35,12 +42,29 @@ signal ended(reason: String)
|
||||||
## Partner: the first full state arrived; the game is on.
|
## Partner: the first full state arrived; the game is on.
|
||||||
signal welcomed
|
signal welcomed
|
||||||
|
|
||||||
const SNAP_EVERY := 3 # physics ticks: 20 Hz
|
## The wire format: both machines must speak the same one (hello and welcome carry it).
|
||||||
const INPUT_EVERY := 2 # 30 Hz
|
const PROTOCOL := 2
|
||||||
|
const SNAP_EVERY := 4 # physics ticks: 15 Hz
|
||||||
|
const INPUT_EVERY := 3 # 20 Hz, when it changed
|
||||||
|
## Seconds: the partner's input goes out at least this often, changed or not.
|
||||||
|
const INPUT_KEEPALIVE := 0.25
|
||||||
const STATE_EVERY := 15 # 4 Hz
|
const STATE_EVERY := 15 # 4 Hz
|
||||||
const LOOT_EVERY := 6 # 10 Hz
|
const LOOT_EVERY := 6 # 10 Hz
|
||||||
const ENEMY_CHUNK := 56
|
|
||||||
const MAX_SHOTS := 60
|
const MAX_SHOTS := 60
|
||||||
|
## Bytes of packed data in one snapshot or foes message (the wrapping keeps it under
|
||||||
|
## CoopLink.UNRELIABLE_LIMIT).
|
||||||
|
const PACK_LIMIT := 1000
|
||||||
|
const FOE_RECORD := 16
|
||||||
|
## An enemy record's velocity, in 1/VEL_SCALE m/s (s8: up to 12.7 m/s).
|
||||||
|
const VEL_SCALE := 10.0
|
||||||
|
## Dead reckoning: a new record goes out when the partner's guess is this far off (m), its
|
||||||
|
## velocity this far (m/s), its heading turned past FOE_TURN (cosine: 20 degrees), its altitude
|
||||||
|
## FOE_ALT_DRIFT off (m), or FOE_REFRESH seconds after the last one.
|
||||||
|
const FOE_DRIFT := 0.25
|
||||||
|
const FOE_VEL_DRIFT := 0.75
|
||||||
|
const FOE_TURN := 0.94
|
||||||
|
const FOE_ALT_DRIFT := 0.25
|
||||||
|
const FOE_REFRESH := 1.0
|
||||||
## Partner: seconds without a word from the host before it counts as gone.
|
## Partner: seconds without a word from the host before it counts as gone.
|
||||||
const TIMEOUT := 8.0
|
const TIMEOUT := 8.0
|
||||||
|
|
||||||
|
|
@ -56,8 +80,15 @@ var quiet: float = 0.0
|
||||||
var voices: Array[CoopVoice] = []
|
var voices: Array[CoopVoice] = []
|
||||||
var microphone := true
|
var microphone := true
|
||||||
|
|
||||||
|
## Seconds since the session started (physics time).
|
||||||
|
var clock: float = 0.0
|
||||||
|
|
||||||
# Host
|
# Host
|
||||||
var _events: Array = []
|
var _events: Array = []
|
||||||
|
## Enemy records sent so far (each 16 bytes).
|
||||||
|
var foe_records: int = 0
|
||||||
|
## What the partner last got for each enemy: host handle -> [clock, record, times to send again].
|
||||||
|
var _foe_sent := {}
|
||||||
var _removed: Array = []
|
var _removed: Array = []
|
||||||
var _state_hash: int = 0
|
var _state_hash: int = 0
|
||||||
var _loot_hash: int = 0
|
var _loot_hash: int = 0
|
||||||
|
|
@ -67,6 +98,8 @@ var _map := {} # host enemy handle -> local handle
|
||||||
var _gone := {} # host handles already removed (a late snapshot mustn't bring them back)
|
var _gone := {} # host handles already removed (a late snapshot mustn't bring them back)
|
||||||
var _targets := {} # local handle -> PackedFloat32Array [x, z, hx, hz, vx, vz, alt]
|
var _targets := {} # local handle -> PackedFloat32Array [x, z, hx, hz, vx, vz, alt]
|
||||||
var _sender := RemoteControls.Sender.new()
|
var _sender := RemoteControls.Sender.new()
|
||||||
|
var _last_input := PackedByteArray()
|
||||||
|
var _input_age: float = 0.0
|
||||||
var _snap_tick: int = -1
|
var _snap_tick: int = -1
|
||||||
var _structures_json := ""
|
var _structures_json := ""
|
||||||
var _shed_json := ""
|
var _shed_json := ""
|
||||||
|
|
@ -95,7 +128,9 @@ func start_host(p_sim: FarmSim, p_link: CoopLink, p_my_name: String, p_partner_n
|
||||||
my_name = p_my_name
|
my_name = p_my_name
|
||||||
partner_name = p_partner_name
|
partner_name = p_partner_name
|
||||||
ticks = 0
|
ticks = 0
|
||||||
|
clock = 0.0
|
||||||
quiet = 0.0
|
quiet = 0.0
|
||||||
|
_foe_sent.clear()
|
||||||
link.received.connect(_on_message)
|
link.received.connect(_on_message)
|
||||||
sim.avatars[0].player_name = my_name
|
sim.avatars[0].player_name = my_name
|
||||||
var a := sim.add_partner(false, partner_name)
|
var a := sim.add_partner(false, partner_name)
|
||||||
|
|
@ -104,12 +139,15 @@ func start_host(p_sim: FarmSim, p_link: CoopLink, p_my_name: String, p_partner_n
|
||||||
_tag_all()
|
_tag_all()
|
||||||
_hook(sim.campaign.phase_changed, func(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void:
|
_hook(sim.campaign.phase_changed, func(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void:
|
||||||
_events.append(["phase", int(phase), int(previous), sim.campaign.state.to_dict(), sim.campaign.state.phase_time_left])
|
_events.append(["phase", int(phase), int(previous), sim.campaign.state.to_dict(), sim.campaign.state.phase_time_left])
|
||||||
if phase == CampaignController.Phase.MORNING and sim.partner != null:
|
if phase == CampaignController.Phase.MORNING:
|
||||||
_ensure_coop())
|
_foe_sent.clear() # the partner forgets the night's enemies too
|
||||||
|
if sim.partner != null:
|
||||||
|
_ensure_coop())
|
||||||
_hook(sim.campaign.campaign_ended, func(outcome: CampaignController.Outcome) -> void:
|
_hook(sim.campaign.campaign_ended, func(outcome: CampaignController.Outcome) -> void:
|
||||||
_events.append(["ended", int(outcome), sim.campaign.state.to_dict()]))
|
_events.append(["ended", int(outcome), sim.campaign.state.to_dict()]))
|
||||||
_hook(sim.enemies.enemy_removed, func(h: int, reason: EnemySystem.Removal, x: float, z: float, _c: int, _t: int) -> void:
|
_hook(sim.enemies.enemy_removed, func(h: int, reason: EnemySystem.Removal, x: float, z: float, _c: int, _t: int) -> void:
|
||||||
_removed.append([h, int(reason), x, z]))
|
_removed.append([h, int(reason), x, z])
|
||||||
|
_foe_sent.erase(h))
|
||||||
_hook(sim.waves.arrived, func(h: int, at: Vector2) -> void:
|
_hook(sim.waves.arrived, func(h: int, at: Vector2) -> void:
|
||||||
var d := sim.enemies.resolve_handle(h)
|
var d := sim.enemies.resolve_handle(h)
|
||||||
_events.append(["arrived", sim.enemies.type[d] if d >= 0 else 0, at]))
|
_events.append(["arrived", sim.enemies.type[d] if d >= 0 else 0, at]))
|
||||||
|
|
@ -146,8 +184,11 @@ func start_client(p_sim: FarmSim, p_link: CoopLink, p_my_name: String) -> void:
|
||||||
role = Role.CLIENT
|
role = Role.CLIENT
|
||||||
my_name = p_my_name
|
my_name = p_my_name
|
||||||
ticks = 0
|
ticks = 0
|
||||||
|
clock = 0.0
|
||||||
quiet = 0.0
|
quiet = 0.0
|
||||||
_is_welcomed = false
|
_is_welcomed = false
|
||||||
|
_snap_tick = -1
|
||||||
|
_last_input = PackedByteArray()
|
||||||
link.received.connect(_on_message)
|
link.received.connect(_on_message)
|
||||||
var c := sim.campaign
|
var c := sim.campaign
|
||||||
c.save_path = "" # only the host saves
|
c.save_path = "" # only the host saves
|
||||||
|
|
@ -236,13 +277,14 @@ func partner_speaking() -> bool:
|
||||||
## GD-Sync calls this on the other machine (GDSyncLink).
|
## GD-Sync calls this on the other machine (GDSyncLink).
|
||||||
func net_receive(kind: String, data: Variant) -> void:
|
func net_receive(kind: String, data: Variant) -> void:
|
||||||
if link != null:
|
if link != null:
|
||||||
link.received.emit(kind, data)
|
link.receive(kind, data)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(dt: float) -> void:
|
func _physics_process(dt: float) -> void:
|
||||||
if role == Role.SOLO or link == null:
|
if role == Role.SOLO or link == null:
|
||||||
return
|
return
|
||||||
ticks += 1
|
ticks += 1
|
||||||
|
clock += dt
|
||||||
quiet += dt
|
quiet += dt
|
||||||
if role == Role.HOST:
|
if role == Role.HOST:
|
||||||
link.poll()
|
link.poll()
|
||||||
|
|
@ -256,9 +298,11 @@ func _physics_process(dt: float) -> void:
|
||||||
_hello_wait -= dt
|
_hello_wait -= dt
|
||||||
if _hello_wait <= 0.0:
|
if _hello_wait <= 0.0:
|
||||||
_hello_wait = 1.0
|
_hello_wait = 1.0
|
||||||
link.send("hello", {"name": my_name}, true)
|
link.send("hello", {"name": my_name, "v": PROTOCOL}, true)
|
||||||
elif ticks % INPUT_EVERY == 0:
|
else:
|
||||||
_send_input()
|
_input_age += dt
|
||||||
|
if ticks % INPUT_EVERY == 0:
|
||||||
|
_send_input()
|
||||||
if link.closed or (role == Role.CLIENT and quiet > TIMEOUT):
|
if link.closed or (role == Role.CLIENT and quiet > TIMEOUT):
|
||||||
stop("The host left the game" if link.closed else "Lost the connection to the host")
|
stop("The host left the game" if link.closed else "Lost the connection to the host")
|
||||||
|
|
||||||
|
|
@ -270,7 +314,10 @@ func _host_tick() -> void:
|
||||||
_send_snapshot()
|
_send_snapshot()
|
||||||
if ticks % STATE_EVERY == 0:
|
if ticks % STATE_EVERY == 0:
|
||||||
var d := sim.campaign.state.to_dict()
|
var d := sim.campaign.state.to_dict()
|
||||||
|
var left: float = d["phase_time_left"]
|
||||||
|
d["phase_time_left"] = 0.0 # ticks down all day and night; every snapshot has it
|
||||||
var h := hash(d)
|
var h := hash(d)
|
||||||
|
d["phase_time_left"] = left
|
||||||
if h != _state_hash:
|
if h != _state_hash:
|
||||||
_state_hash = h
|
_state_hash = h
|
||||||
link.send("state", d, true)
|
link.send("state", d, true)
|
||||||
|
|
@ -289,32 +336,98 @@ func _host_tick() -> void:
|
||||||
func _welcome() -> Dictionary:
|
func _welcome() -> Dictionary:
|
||||||
var c := sim.campaign
|
var c := sim.campaign
|
||||||
return {"state": c.state.to_dict(), "phase": int(c.state.phase), "time": c.state.phase_time_left, "outcome": int(c.outcome),
|
return {"state": c.state.to_dict(), "phase": int(c.state.phase), "time": c.state.phase_time_left, "outcome": int(c.outcome),
|
||||||
"night_time": sim.waves.night_time, "loot": sim.loot.replica_record(), "host": my_name}
|
"night_time": sim.waves.night_time, "loot": sim.loot.replica_record(), "host": my_name, "v": PROTOCOL}
|
||||||
|
|
||||||
|
|
||||||
|
## One snapshot: the clock, the scarecrows, the animals, the shots, and the enemies that are due,
|
||||||
|
## packed; the due enemies that don't fit follow in foes messages.
|
||||||
func _send_snapshot() -> void:
|
func _send_snapshot() -> void:
|
||||||
var avs: Array = []
|
var b := StreamPeerBuffer.new()
|
||||||
|
b.put_u32(ticks)
|
||||||
|
b.put_float(sim.campaign.state.phase_time_left)
|
||||||
|
b.put_float(sim.waves.night_time)
|
||||||
|
b.put_u8(sim.avatars.size())
|
||||||
for a in sim.avatars:
|
for a in sim.avatars:
|
||||||
avs.append(_avatar_record(a))
|
_put_avatar(b, a)
|
||||||
link.send("snap", {"t": ticks, "time": sim.campaign.state.phase_time_left, "night": sim.waves.night_time, "av": avs,
|
var an := sim.animals.replica_record() # x, z, yaw, speed per animal
|
||||||
"an": sim.animals.replica_record()}, false)
|
b.put_u8(an.size() / 4)
|
||||||
|
for k in range(0, an.size(), 4):
|
||||||
|
CoopLink.put_cm(b, an[k])
|
||||||
|
CoopLink.put_cm(b, an[k + 1])
|
||||||
|
CoopLink.put_angle(b, an[k + 2])
|
||||||
|
b.put_u8(clampi(roundi(an[k + 3] * 20.0), 0, 255))
|
||||||
|
var shots := sim.projectiles.replica_record(MAX_SHOTS) # x, z, direction per shot
|
||||||
|
b.put_u8(shots.size() / 4)
|
||||||
|
for k in range(0, shots.size(), 4):
|
||||||
|
CoopLink.put_cm(b, shots[k])
|
||||||
|
CoopLink.put_cm(b, shots[k + 1])
|
||||||
|
b.put_8(clampi(roundi(shots[k + 2] * 127.0), -127, 127))
|
||||||
|
b.put_8(clampi(roundi(shots[k + 3] * 127.0), -127, 127))
|
||||||
|
var foes := _due_foes()
|
||||||
|
var n := foes.size() / FOE_RECORD
|
||||||
|
var fit := mini(n, (PACK_LIMIT - b.get_size() - 2) / FOE_RECORD)
|
||||||
|
b.put_u16(fit)
|
||||||
|
b.put_data(foes.slice(0, fit * FOE_RECORD))
|
||||||
|
link.send("snap", b.data_array, false)
|
||||||
|
var per := (PACK_LIMIT - 6) / FOE_RECORD
|
||||||
|
while fit < n:
|
||||||
|
var take := mini(n - fit, per)
|
||||||
|
var c := StreamPeerBuffer.new()
|
||||||
|
c.put_u32(ticks)
|
||||||
|
c.put_u16(take)
|
||||||
|
c.put_data(foes.slice(fit * FOE_RECORD, (fit + take) * FOE_RECORD))
|
||||||
|
link.send("foes", c.data_array, false)
|
||||||
|
fit += take
|
||||||
|
|
||||||
|
|
||||||
|
## The records of the enemies the partner needs news of (dead reckoning, see the top), noted as
|
||||||
|
## sent.
|
||||||
|
func _due_foes() -> PackedByteArray:
|
||||||
var es := sim.enemies
|
var es := sim.enemies
|
||||||
var chunk := PackedByteArray()
|
var out := PackedByteArray()
|
||||||
for d in es.active_count:
|
for d in es.active_count:
|
||||||
if es.alive[d] == 0:
|
if es.alive[d] == 0:
|
||||||
continue
|
continue
|
||||||
chunk.append_array(_enemy_bytes(es, d))
|
var h := es.handle_of(d)
|
||||||
if chunk.size() >= ENEMY_CHUNK * 16:
|
var last: Array = _foe_sent.get(h, [])
|
||||||
link.send("foes", chunk, false)
|
var again := 0
|
||||||
chunk = PackedByteArray()
|
if last.is_empty():
|
||||||
if not chunk.is_empty():
|
again = 2 # a new enemy: in the next two snapshots too
|
||||||
link.send("foes", chunk, false)
|
elif int(last[2]) > 0:
|
||||||
link.send("shots", sim.projectiles.replica_record(MAX_SHOTS), false)
|
again = int(last[2]) - 1
|
||||||
|
elif _foe_changed(es, d, last[1], clock - float(last[0])):
|
||||||
|
again = 1
|
||||||
|
elif clock - float(last[0]) < FOE_REFRESH:
|
||||||
|
continue
|
||||||
|
var rec := _enemy_bytes(es, d)
|
||||||
|
_foe_sent[h] = [clock, rec, again]
|
||||||
|
out.append_array(rec)
|
||||||
|
foe_records += 1
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Whether enemy d is off from the partner's guess: its last record r, moved on for age seconds.
|
||||||
|
func _foe_changed(es: EnemySystem, d: int, r: PackedByteArray, age: float) -> bool:
|
||||||
|
if r[4] != es.type[d] or r[5] != es.state[d]:
|
||||||
|
return true
|
||||||
|
if es.hurt[d] > maxf(r[6] / 255.0 - age * EnemySystem.HURT_FADE, 0.0) + 0.15:
|
||||||
|
return true # hit again
|
||||||
|
if absf(es.alt[d] - r[7] / 40.0) > FOE_ALT_DRIFT:
|
||||||
|
return true
|
||||||
|
var vx := r.decode_s8(14) / VEL_SCALE
|
||||||
|
var vz := r.decode_s8(15) / VEL_SCALE
|
||||||
|
var off := Vector2(es.pos_x[d] - (r.decode_s16(8) / 100.0 + vx * age), es.pos_z[d] - (r.decode_s16(10) / 100.0 + vz * age))
|
||||||
|
if off.length_squared() > FOE_DRIFT * FOE_DRIFT:
|
||||||
|
return true
|
||||||
|
if Vector2(es.vel_x[d] - vx, es.vel_z[d] - vz).length_squared() > FOE_VEL_DRIFT * FOE_VEL_DRIFT:
|
||||||
|
return true
|
||||||
|
var head := Vector2(r.decode_s8(12), r.decode_s8(13))
|
||||||
|
return head.length_squared() > 0.0 and Vector2(es.head_x[d], es.head_z[d]).dot(head.normalized()) < FOE_TURN
|
||||||
|
|
||||||
|
|
||||||
static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
|
static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
|
||||||
var b := PackedByteArray()
|
var b := PackedByteArray()
|
||||||
b.resize(16)
|
b.resize(FOE_RECORD)
|
||||||
b.encode_s32(0, es.handle_of(d))
|
b.encode_s32(0, es.handle_of(d))
|
||||||
b[4] = es.type[d]
|
b[4] = es.type[d]
|
||||||
b[5] = es.state[d]
|
b[5] = es.state[d]
|
||||||
|
|
@ -324,20 +437,31 @@ static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
|
||||||
b.encode_s16(10, clampi(roundi(es.pos_z[d] * 100.0), -32768, 32767))
|
b.encode_s16(10, clampi(roundi(es.pos_z[d] * 100.0), -32768, 32767))
|
||||||
b.encode_s8(12, clampi(roundi(es.head_x[d] * 127.0), -127, 127))
|
b.encode_s8(12, clampi(roundi(es.head_x[d] * 127.0), -127, 127))
|
||||||
b.encode_s8(13, clampi(roundi(es.head_z[d] * 127.0), -127, 127))
|
b.encode_s8(13, clampi(roundi(es.head_z[d] * 127.0), -127, 127))
|
||||||
b.encode_s8(14, clampi(roundi(es.vel_x[d] * 20.0), -127, 127))
|
b.encode_s8(14, clampi(roundi(es.vel_x[d] * VEL_SCALE), -127, 127))
|
||||||
b.encode_s8(15, clampi(roundi(es.vel_z[d] * 20.0), -127, 127))
|
b.encode_s8(15, clampi(roundi(es.vel_z[d] * VEL_SCALE), -127, 127))
|
||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
func _avatar_record(a: Avatar) -> Dictionary:
|
## A scarecrow in a snapshot: slot, position, facing, speed, alive and patching, health, its
|
||||||
|
## timers (invulnerable, fear, bomb recharge, patch, gather, repair), the weapon, the channel
|
||||||
|
## clip and what it is focused on and gathering (names), and the repair's target and progress.
|
||||||
|
func _put_avatar(b: StreamPeerBuffer, a: Avatar) -> void:
|
||||||
var it := a.interactions
|
var it := a.interactions
|
||||||
var k := a.kit
|
var k := a.kit
|
||||||
return {"s": a.slot, "p": a.body.global_position, "y": a.body.model.rotation.y, "v": a.body.move_strength(),
|
b.put_u8(a.slot)
|
||||||
"a": k.alive, "hp": k.hp(), "inv": k.invulnerable_left, "fl": k.fear_left,
|
CoopLink.put_v3(b, a.body.global_position)
|
||||||
"w": int(a.combat.weapon), "bl": a.combat.bomb_left,
|
CoopLink.put_angle(b, a.body.model.rotation.y)
|
||||||
"pt": k.patch_elapsed if k.patching else -1.0, "ch": String(a.body.channel_clip) if a.body.rooted else "",
|
b.put_u8(clampi(roundi(a.body.move_strength() * 100.0), 0, 255))
|
||||||
"fo": String(it.focus.name) if it.focus != null else "", "ga": String(it.gathering.name) if it.gathering != null else "",
|
b.put_u8((1 if k.alive else 0) | (2 if k.patching else 0))
|
||||||
"ge": it.gather_elapsed, "rt": it.repair_target, "rp": it.repairing, "re": it.repair_elapsed}
|
b.put_u8(clampi(k.hp(), 0, 255))
|
||||||
|
for t: float in [k.invulnerable_left, k.fear_left, a.combat.bomb_left, k.patch_elapsed, it.gather_elapsed, it.repair_elapsed]:
|
||||||
|
CoopLink.put_time(b, t)
|
||||||
|
b.put_u8(int(a.combat.weapon))
|
||||||
|
CoopLink.put_text(b, String(a.body.channel_clip) if a.body.rooted else "")
|
||||||
|
CoopLink.put_text(b, String(it.focus.name) if it.focus != null else "")
|
||||||
|
CoopLink.put_text(b, String(it.gathering.name) if it.gathering != null else "")
|
||||||
|
b.put_32(it.repair_target)
|
||||||
|
b.put_32(it.repairing)
|
||||||
|
|
||||||
|
|
||||||
func _on_message(kind: String, data: Variant) -> void:
|
func _on_message(kind: String, data: Variant) -> void:
|
||||||
|
|
@ -354,20 +478,28 @@ func _host_message(kind: String, data: Variant) -> void:
|
||||||
return
|
return
|
||||||
match kind:
|
match kind:
|
||||||
"hello":
|
"hello":
|
||||||
partner_name = String((data as Dictionary).get("name", partner_name))
|
var hello := data as Dictionary
|
||||||
|
partner_name = String(hello.get("name", partner_name))
|
||||||
|
if int(hello.get("v", 1)) != PROTOCOL:
|
||||||
|
link.send("refused", {"v": PROTOCOL}, true)
|
||||||
|
var who := _display(partner_name, "Your friend")
|
||||||
|
stop()
|
||||||
|
if sim.toasts != null:
|
||||||
|
sim.toasts.push("%s has another version of the game: update both to play together" % who, Color(1.0, 0.6, 0.4))
|
||||||
|
return
|
||||||
a.player_name = partner_name
|
a.player_name = partner_name
|
||||||
_tag_all()
|
_tag_all()
|
||||||
if not _welcome_sent:
|
if not _welcome_sent:
|
||||||
_welcome_sent = true
|
_welcome_sent = true
|
||||||
_events.clear()
|
_events.clear()
|
||||||
_removed.clear()
|
_removed.clear()
|
||||||
|
_foe_sent.clear() # the partner starts with no enemies
|
||||||
link.send("welcome", _welcome(), true)
|
link.send("welcome", _welcome(), true)
|
||||||
"input":
|
"input":
|
||||||
var rec := data as Dictionary
|
if data is PackedByteArray and a.remote.apply(data):
|
||||||
a.remote.apply(rec)
|
a.body.net_position = a.remote.position
|
||||||
a.body.net_position = rec.get("p", a.body.net_position)
|
a.body.net_yaw = a.remote.yaw
|
||||||
a.body.net_yaw = float(rec.get("y", a.body.net_yaw))
|
a.body.net_speed = a.remote.speed
|
||||||
a.body.net_speed = float(rec.get("v", 0.0))
|
|
||||||
"req":
|
"req":
|
||||||
_do_request(data as Array)
|
_do_request(data as Array)
|
||||||
|
|
||||||
|
|
@ -429,11 +561,15 @@ func _client_message(kind: String, data: Variant) -> void:
|
||||||
"loot":
|
"loot":
|
||||||
sim.loot.apply_replica(data as Dictionary, _local_handle)
|
sim.loot.apply_replica(data as Dictionary, _local_handle)
|
||||||
"snap":
|
"snap":
|
||||||
_apply_snap(data as Dictionary)
|
if data is PackedByteArray:
|
||||||
|
_apply_snap(data)
|
||||||
"foes":
|
"foes":
|
||||||
_apply_foes(data as PackedByteArray)
|
if data is PackedByteArray and (data as PackedByteArray).size() >= 6:
|
||||||
"shots":
|
var c := CoopLink.reader(data)
|
||||||
sim.projectiles.apply_replica(data as PackedFloat32Array)
|
if c.get_u32() >= _snap_tick: # not from an older snapshot than the last
|
||||||
|
_apply_foes((data as PackedByteArray).slice(6, 6 + c.get_u16() * FOE_RECORD))
|
||||||
|
"refused":
|
||||||
|
stop("The host has another version of the game: update both to play together")
|
||||||
"batch":
|
"batch":
|
||||||
var b := data as Dictionary
|
var b := data as Dictionary
|
||||||
for r: Array in b.get("removed", []):
|
for r: Array in b.get("removed", []):
|
||||||
|
|
@ -443,6 +579,9 @@ func _client_message(kind: String, data: Variant) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _welcome_received(w: Dictionary) -> void:
|
func _welcome_received(w: Dictionary) -> void:
|
||||||
|
if int(w.get("v", 1)) != PROTOCOL:
|
||||||
|
stop("The host has another version of the game: update both to play together")
|
||||||
|
return
|
||||||
var c := sim.campaign
|
var c := sim.campaign
|
||||||
partner_name = String(w.get("host", ""))
|
partner_name = String(w.get("host", ""))
|
||||||
sim.avatars[0].player_name = partner_name
|
sim.avatars[0].player_name = partner_name
|
||||||
|
|
@ -545,19 +684,55 @@ func _apply_event(e: Array) -> void:
|
||||||
sim.upgrade_panel.open()
|
sim.upgrade_panel.open()
|
||||||
|
|
||||||
|
|
||||||
func _apply_snap(snap: Dictionary) -> void:
|
func _apply_snap(data: PackedByteArray) -> void:
|
||||||
var t := int(snap.get("t", 0))
|
var b := CoopLink.reader(data)
|
||||||
|
var t := b.get_u32()
|
||||||
if t <= _snap_tick:
|
if t <= _snap_tick:
|
||||||
return # an older one, out of order
|
return # an older one, out of order
|
||||||
_snap_tick = t
|
_snap_tick = t
|
||||||
sim.campaign.state.phase_time_left = float(snap["time"])
|
sim.campaign.state.phase_time_left = b.get_float()
|
||||||
sim.waves.night_time = float(snap["night"])
|
sim.waves.night_time = b.get_float()
|
||||||
for rec: Dictionary in snap["av"]:
|
for i in b.get_u8():
|
||||||
var slot := int(rec["s"])
|
var slot := b.get_u8()
|
||||||
if slot >= sim.avatars.size():
|
var rec := _read_avatar(b)
|
||||||
continue
|
if slot < sim.avatars.size():
|
||||||
_apply_avatar(sim.avatars[slot], rec)
|
_apply_avatar(sim.avatars[slot], rec)
|
||||||
sim.animals.apply_replica(snap["an"])
|
var an := PackedFloat32Array()
|
||||||
|
for i in b.get_u8():
|
||||||
|
var x := CoopLink.get_cm(b)
|
||||||
|
var z := CoopLink.get_cm(b)
|
||||||
|
var yaw := CoopLink.get_angle(b)
|
||||||
|
an.append_array([x, z, yaw, b.get_u8() / 20.0])
|
||||||
|
sim.animals.apply_replica(an)
|
||||||
|
var shots := PackedFloat32Array()
|
||||||
|
for i in b.get_u8():
|
||||||
|
var x := CoopLink.get_cm(b)
|
||||||
|
var z := CoopLink.get_cm(b)
|
||||||
|
var dx := b.get_8() / 127.0
|
||||||
|
shots.append_array([x, z, dx, b.get_8() / 127.0])
|
||||||
|
sim.projectiles.apply_replica(shots)
|
||||||
|
var n := b.get_u16()
|
||||||
|
var at := b.get_position()
|
||||||
|
_apply_foes(data.slice(at, at + n * FOE_RECORD))
|
||||||
|
|
||||||
|
|
||||||
|
## A scarecrow from a snapshot (after its slot; see _put_avatar), by the names _apply_avatar uses.
|
||||||
|
func _read_avatar(b: StreamPeerBuffer) -> Dictionary:
|
||||||
|
var rec := {"p": CoopLink.get_v3(b), "y": CoopLink.get_angle(b), "v": b.get_u8() / 100.0}
|
||||||
|
var flags := b.get_u8()
|
||||||
|
rec["a"] = (flags & 1) != 0
|
||||||
|
rec["hp"] = b.get_u8()
|
||||||
|
for key: String in ["inv", "fl", "bl", "pt", "ge", "re"]:
|
||||||
|
rec[key] = CoopLink.get_time(b)
|
||||||
|
if (flags & 2) == 0:
|
||||||
|
rec["pt"] = -1.0 # not patching
|
||||||
|
rec["w"] = b.get_u8()
|
||||||
|
rec["ch"] = CoopLink.get_text(b)
|
||||||
|
rec["fo"] = CoopLink.get_text(b)
|
||||||
|
rec["ga"] = CoopLink.get_text(b)
|
||||||
|
rec["rt"] = b.get_32()
|
||||||
|
rec["rp"] = b.get_32()
|
||||||
|
return rec
|
||||||
|
|
||||||
|
|
||||||
func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
||||||
|
|
@ -581,9 +756,9 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
||||||
body.die()
|
body.die()
|
||||||
k.invulnerable_left = float(rec["inv"])
|
k.invulnerable_left = float(rec["inv"])
|
||||||
k.fear_left = float(rec["fl"])
|
k.fear_left = float(rec["fl"])
|
||||||
a.combat.bomb_left = float(rec.get("bl", 0.0))
|
a.combat.bomb_left = float(rec["bl"])
|
||||||
if not a.is_local:
|
if not a.is_local:
|
||||||
a.combat.show_weapon(int(rec.get("w", 0)))
|
a.combat.show_weapon(int(rec["w"]))
|
||||||
var pt := float(rec["pt"])
|
var pt := float(rec["pt"])
|
||||||
k.patching = pt >= 0.0
|
k.patching = pt >= 0.0
|
||||||
k.patch_elapsed = maxf(pt, 0.0)
|
k.patch_elapsed = maxf(pt, 0.0)
|
||||||
|
|
@ -616,7 +791,7 @@ func _gather_node(node_name: String) -> Node3D:
|
||||||
|
|
||||||
func _apply_foes(chunk: PackedByteArray) -> void:
|
func _apply_foes(chunk: PackedByteArray) -> void:
|
||||||
var es := sim.enemies
|
var es := sim.enemies
|
||||||
for o in range(0, chunk.size() - 15, 16):
|
for o in range(0, chunk.size() - FOE_RECORD + 1, FOE_RECORD):
|
||||||
var host := chunk.decode_s32(o)
|
var host := chunk.decode_s32(o)
|
||||||
if _gone.has(host):
|
if _gone.has(host):
|
||||||
continue
|
continue
|
||||||
|
|
@ -634,7 +809,7 @@ func _apply_foes(chunk: PackedByteArray) -> void:
|
||||||
es.state[d] = chunk[o + 5]
|
es.state[d] = chunk[o + 5]
|
||||||
es.hurt[d] = chunk[o + 6] / 255.0
|
es.hurt[d] = chunk[o + 6] / 255.0
|
||||||
var t := PackedFloat32Array([x, z, chunk.decode_s8(o + 12) / 127.0, chunk.decode_s8(o + 13) / 127.0,
|
var t := PackedFloat32Array([x, z, chunk.decode_s8(o + 12) / 127.0, chunk.decode_s8(o + 13) / 127.0,
|
||||||
chunk.decode_s8(o + 14) / 20.0, chunk.decode_s8(o + 15) / 20.0, chunk[o + 7] / 40.0])
|
chunk.decode_s8(o + 14) / VEL_SCALE, chunk.decode_s8(o + 15) / VEL_SCALE, chunk[o + 7] / 40.0])
|
||||||
_targets[h] = t
|
_targets[h] = t
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -689,6 +864,7 @@ func _replica_tick(dt: float) -> void:
|
||||||
es.vel_x[d] = t[4]
|
es.vel_x[d] = t[4]
|
||||||
es.vel_z[d] = t[5]
|
es.vel_z[d] = t[5]
|
||||||
es.alt[d] = lerpf(es.alt[d], t[6], 0.3)
|
es.alt[d] = lerpf(es.alt[d], t[6], 0.3)
|
||||||
|
es.hurt[d] = maxf(es.hurt[d] - dt * EnemySystem.HURT_FADE, 0.0) # as on the host, between records
|
||||||
sim.projectiles.advance_replica(dt)
|
sim.projectiles.advance_replica(dt)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -700,19 +876,16 @@ func _reset_world() -> void:
|
||||||
_targets.clear()
|
_targets.clear()
|
||||||
|
|
||||||
|
|
||||||
|
## The input record, when it changed or INPUT_KEEPALIVE after the last one (a lost one is
|
||||||
|
## replaced soon; standing still sends little).
|
||||||
func _send_input() -> void:
|
func _send_input() -> void:
|
||||||
var a := sim.local_avatar
|
var a := sim.local_avatar
|
||||||
var build_on := sim.build.active
|
|
||||||
var ui := sim.upgrade_panel != null and sim.upgrade_panel.is_open
|
var ui := sim.upgrade_panel != null and sim.upgrade_panel.is_open
|
||||||
var rec := _sender.record(a.combat.aim, a.combat.aim_point, int(a.combat.device), build_on, ui)
|
var rec := _sender.record(a.combat, a.body, sim.build.active, ui, sim.local_frozen)
|
||||||
if sim.local_frozen:
|
if rec != _last_input or _input_age >= INPUT_KEEPALIVE - 0.001: # (sums of 1/60 fall a hair short)
|
||||||
rec["held"] = 0 # a menu is up
|
_last_input = rec
|
||||||
rec["p"] = a.body.global_position
|
_input_age = 0.0
|
||||||
rec["y"] = a.body.model.rotation.y
|
link.send("input", rec, false)
|
||||||
rec["v"] = a.body.move_strength()
|
|
||||||
rec["weapon"] = int(a.combat.weapon)
|
|
||||||
rec["ground"] = a.combat.ground_point
|
|
||||||
link.send("input", rec, false)
|
|
||||||
_close_menu_if_needed()
|
_close_menu_if_needed()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,53 @@ class_name CoopVoice
|
||||||
extends VoiceChat
|
extends VoiceChat
|
||||||
## Voice chat in co-op: GD-Sync's VoiceChat, one per player at the same path on both machines
|
## Voice chat in co-op: GD-Sync's VoiceChat, one per player at the same path on both machines
|
||||||
## (CoopSession/Voice1 for player 1, Voice2 for player 2). Each is owned by its player's GD-Sync
|
## (CoopSession/Voice1 for player 1, Voice2 for player 2). Each is owned by its player's GD-Sync
|
||||||
## client: the owner's microphone is recorded (above GD-Sync's volume threshold) and sent, and
|
## client: the owner's microphone is recorded and sent, and the other machine plays it on the
|
||||||
## the other machine plays it on the Voice bus. This adds when the voice was last heard, for the
|
## Voice bus. GD-Sync's capture and playback are kept; the sending is this class's own: GD-Sync's
|
||||||
## "speaking" mark on the partner HUD and the name tag.
|
## sends the raw samples (32-bit floats) every frame the microphone peaks over a threshold, about
|
||||||
|
## 60 KB/s. Here the microphone is resampled to RATE and cut into pieces of CHUNK samples (60 ms),
|
||||||
|
## and each piece of speech goes out as 4-bit IMA ADPCM (encode, decode: 3 + CHUNK / 2 bytes, about
|
||||||
|
## 6 KB/s while talking). A piece is loud when at least LOUD_PARTS of its four 15 ms parts are
|
||||||
|
## (RMS over gate_rms), so a click or a knock spread over two pieces doesn't count; the gate opens
|
||||||
|
## after GATE_OPEN loud pieces in a row, sends the piece before them too (the start of the first
|
||||||
|
## word), and stays open GATE_HOLD seconds after the last loud piece. Each piece starts with the
|
||||||
|
## codec's state, so a lost one costs only its own 60 ms.
|
||||||
|
## This also notes when the voice was last heard, for the "speaking" mark on the partner HUD.
|
||||||
|
|
||||||
|
const RATE := 12000
|
||||||
|
const CHUNK := 720
|
||||||
|
const GATE_OPEN := 2
|
||||||
|
const LOUD_PARTS := 2
|
||||||
|
const GATE_HOLD := 0.4
|
||||||
|
## Seconds of voice the playback buffer holds (room for a piece that arrives late).
|
||||||
|
const BUFFER := 0.3
|
||||||
|
const STEPS: Array[int] = [7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
|
||||||
|
50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371,
|
||||||
|
408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
|
||||||
|
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,
|
||||||
|
10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767]
|
||||||
|
const INDEX_STEP: Array[int] = [-1, -1, -1, -1, 2, 4, 6, 8]
|
||||||
|
|
||||||
## Seconds of the game clock when audio last arrived (-1000 = never).
|
## Seconds of the game clock when audio last arrived (-1000 = never).
|
||||||
var last_heard: float = -1000.0
|
var last_heard: float = -1000.0
|
||||||
|
## A piece louder than this (RMS, full scale 1) counts as speech.
|
||||||
|
var gate_rms: float = 0.01
|
||||||
|
## Pieces sent so far (for tests and the traffic tool).
|
||||||
|
var pieces_sent: int = 0
|
||||||
|
|
||||||
|
# Sending: the resampler (a box filter), the piece being filled, the gate, the codec's state.
|
||||||
|
var _phase: float = 0.0
|
||||||
|
var _sum: float = 0.0
|
||||||
|
var _summed: int = 0
|
||||||
|
var _piece := PackedFloat32Array()
|
||||||
|
var _waiting: Array[PackedFloat32Array] = [] # pieces held while the gate is shut
|
||||||
|
var _loud: int = 0
|
||||||
|
var _open_left: float = 0.0
|
||||||
|
var _codec := [0, 0] # predictor, step index
|
||||||
|
|
||||||
|
|
||||||
static func make(slot: int) -> CoopVoice:
|
static func make(slot: int) -> CoopVoice:
|
||||||
var v := CoopVoice.new()
|
var v := CoopVoice.new()
|
||||||
v.name = "Voice%d" % (slot + 1)
|
v.name = "Voice%d" % (slot + 1)
|
||||||
v.input_volume_threshold = 0.025 # above room noise (GD-Sync's default is 0.01)
|
|
||||||
var out := AudioStreamPlayer.new()
|
var out := AudioStreamPlayer.new()
|
||||||
out.name = "Out"
|
out.name = "Out"
|
||||||
out.bus = &"Voice"
|
out.bus = &"Voice"
|
||||||
|
|
@ -22,10 +57,189 @@ static func make(slot: int) -> CoopVoice:
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
super()
|
||||||
|
if not Engine.is_editor_hint() and GDSync != null:
|
||||||
|
GDSync.expose_func(_receive_voice)
|
||||||
|
|
||||||
|
|
||||||
func speaking() -> bool:
|
func speaking() -> bool:
|
||||||
return Time.get_ticks_msec() / 1000.0 - last_heard < 0.35
|
return Time.get_ticks_msec() / 1000.0 - last_heard < 0.35
|
||||||
|
|
||||||
|
|
||||||
func _process_audio(audio: PackedFloat32Array, mixrate: float) -> void:
|
func mute_microphone() -> void:
|
||||||
|
super()
|
||||||
|
_reset_gate()
|
||||||
|
|
||||||
|
|
||||||
|
## Replaces GD-Sync's sending (see the top).
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
if GDSync == null or not _input_configured or not GDSync.is_gdsync_owner(self):
|
||||||
|
return
|
||||||
|
var n := _record_effect.get_frames_available()
|
||||||
|
if n <= 0:
|
||||||
|
return
|
||||||
|
if _muted:
|
||||||
|
_record_effect.clear_buffer()
|
||||||
|
return
|
||||||
|
for piece in feed(_record_effect.get_buffer(n), AudioServer.get_mix_rate()):
|
||||||
|
GDSync.call_func_relevant_unreliable(_receive_voice, piece)
|
||||||
|
|
||||||
|
|
||||||
|
## Microphone frames (stereo, at mix_rate) in; the encoded pieces to send out, if any.
|
||||||
|
func feed(frames: PackedVector2Array, mix_rate: float) -> Array[PackedByteArray]:
|
||||||
|
var out: Array[PackedByteArray] = []
|
||||||
|
var step := RATE / mix_rate
|
||||||
|
for f in frames:
|
||||||
|
_sum += (f.x + f.y) * 0.5
|
||||||
|
_summed += 1
|
||||||
|
_phase += step
|
||||||
|
if _phase < 1.0:
|
||||||
|
continue
|
||||||
|
_phase -= 1.0
|
||||||
|
_piece.append(_sum / _summed)
|
||||||
|
_sum = 0.0
|
||||||
|
_summed = 0
|
||||||
|
if _piece.size() == CHUNK:
|
||||||
|
_gate(_piece, out)
|
||||||
|
_piece = PackedFloat32Array()
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
func _gate(piece: PackedFloat32Array, out: Array[PackedByteArray]) -> void:
|
||||||
|
var loud := loud_parts(piece, gate_rms) >= LOUD_PARTS
|
||||||
|
_loud = _loud + 1 if loud else 0
|
||||||
|
if _open_left <= 0.0:
|
||||||
|
if _loud < GATE_OPEN:
|
||||||
|
_waiting.append(piece)
|
||||||
|
if _waiting.size() > GATE_OPEN:
|
||||||
|
_waiting.pop_front()
|
||||||
|
return
|
||||||
|
for held in _waiting: # the quiet piece before the speech, and its start
|
||||||
|
out.append(_encode_next(held))
|
||||||
|
_waiting.clear()
|
||||||
|
if loud:
|
||||||
|
_open_left = GATE_HOLD
|
||||||
|
else:
|
||||||
|
_open_left -= float(CHUNK) / RATE
|
||||||
|
out.append(_encode_next(piece))
|
||||||
|
|
||||||
|
|
||||||
|
func _encode_next(piece: PackedFloat32Array) -> PackedByteArray:
|
||||||
|
pieces_sent += 1
|
||||||
|
var bytes := encode(piece, _codec)
|
||||||
|
return bytes
|
||||||
|
|
||||||
|
|
||||||
|
func _reset_gate() -> void:
|
||||||
|
_waiting.clear()
|
||||||
|
_loud = 0
|
||||||
|
_open_left = 0.0
|
||||||
|
_piece = PackedFloat32Array()
|
||||||
|
|
||||||
|
|
||||||
|
## A piece from the other machine: decoded into the playback buffer.
|
||||||
|
func _receive_voice(piece: PackedByteArray) -> void:
|
||||||
last_heard = Time.get_ticks_msec() / 1000.0
|
last_heard = Time.get_ticks_msec() / 1000.0
|
||||||
super(audio, mixrate)
|
if _output_stream_playback == null:
|
||||||
|
return
|
||||||
|
var samples := decode(piece)
|
||||||
|
var room := mini(_output_stream_playback.get_frames_available(), samples.size())
|
||||||
|
var frames := PackedVector2Array()
|
||||||
|
frames.resize(room)
|
||||||
|
for i in room:
|
||||||
|
frames[i] = Vector2(samples[i], samples[i])
|
||||||
|
_output_stream_playback.push_buffer(frames)
|
||||||
|
|
||||||
|
|
||||||
|
## GD-Sync's raw audio (another build's VoiceChat): not played; this one's comes as pieces.
|
||||||
|
func _process_audio(_audio: PackedFloat32Array, _mixrate: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _configure_output() -> void:
|
||||||
|
if _output_configured:
|
||||||
|
return
|
||||||
|
_output_configured = true
|
||||||
|
_output_stream = AudioStreamGenerator.new()
|
||||||
|
_output_stream.mix_rate = RATE
|
||||||
|
_output_stream.buffer_length = BUFFER
|
||||||
|
_output_player.stream = _output_stream
|
||||||
|
_output_player.play()
|
||||||
|
_output_stream_playback = _output_player.get_stream_playback()
|
||||||
|
|
||||||
|
|
||||||
|
## How many of the piece's four parts are louder than threshold (RMS).
|
||||||
|
static func loud_parts(piece: PackedFloat32Array, threshold: float) -> int:
|
||||||
|
var n := 0
|
||||||
|
var part := piece.size() / 4
|
||||||
|
for p in 4:
|
||||||
|
var sum := 0.0
|
||||||
|
for i in range(p * part, (p + 1) * part):
|
||||||
|
sum += piece[i] * piece[i]
|
||||||
|
if sum / maxi(part, 1) >= threshold * threshold:
|
||||||
|
n += 1
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
## IMA ADPCM: the codec's state (predictor, step index) at the start, then two samples a byte
|
||||||
|
## (low nibble first). state carries over from piece to piece and is updated.
|
||||||
|
static func encode(samples: PackedFloat32Array, state: Array) -> PackedByteArray:
|
||||||
|
var predictor: int = state[0]
|
||||||
|
var index: int = state[1]
|
||||||
|
var out := PackedByteArray()
|
||||||
|
out.resize(3 + (samples.size() + 1) / 2)
|
||||||
|
out.encode_s16(0, predictor)
|
||||||
|
out[2] = index
|
||||||
|
for i in samples.size():
|
||||||
|
var target := clampi(roundi(samples[i] * 32767.0), -32768, 32767)
|
||||||
|
var step: int = STEPS[index]
|
||||||
|
var diff := target - predictor
|
||||||
|
var code := 0
|
||||||
|
if diff < 0:
|
||||||
|
code = 8
|
||||||
|
diff = -diff
|
||||||
|
var delta := step >> 3
|
||||||
|
if diff >= step:
|
||||||
|
code |= 4
|
||||||
|
diff -= step
|
||||||
|
delta += step
|
||||||
|
if diff >= step >> 1:
|
||||||
|
code |= 2
|
||||||
|
diff -= step >> 1
|
||||||
|
delta += step >> 1
|
||||||
|
if diff >= step >> 2:
|
||||||
|
code |= 1
|
||||||
|
delta += step >> 2
|
||||||
|
predictor = clampi(predictor - delta if code & 8 else predictor + delta, -32768, 32767)
|
||||||
|
index = clampi(index + INDEX_STEP[code & 7], 0, STEPS.size() - 1)
|
||||||
|
if i % 2 == 0:
|
||||||
|
out[3 + i / 2] = code
|
||||||
|
else:
|
||||||
|
out[3 + i / 2] |= code << 4
|
||||||
|
state[0] = predictor
|
||||||
|
state[1] = index
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
static func decode(piece: PackedByteArray) -> PackedFloat32Array:
|
||||||
|
var out := PackedFloat32Array()
|
||||||
|
if piece.size() < 3:
|
||||||
|
return out
|
||||||
|
var predictor := piece.decode_s16(0)
|
||||||
|
var index := clampi(piece[2], 0, STEPS.size() - 1)
|
||||||
|
out.resize((piece.size() - 3) * 2)
|
||||||
|
for i in out.size():
|
||||||
|
var code := (piece[3 + i / 2] >> (4 * (i % 2))) & 15
|
||||||
|
var step: int = STEPS[index]
|
||||||
|
var delta := step >> 3
|
||||||
|
if code & 4:
|
||||||
|
delta += step
|
||||||
|
if code & 2:
|
||||||
|
delta += step >> 1
|
||||||
|
if code & 1:
|
||||||
|
delta += step >> 2
|
||||||
|
predictor = clampi(predictor - delta if code & 8 else predictor + delta, -32768, 32767)
|
||||||
|
index = clampi(index + INDEX_STEP[code & 7], 0, STEPS.size() - 1)
|
||||||
|
out[i] = predictor / 32768.0
|
||||||
|
return out
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ enum Aggression { NONE, CONTACT, FIGHT }
|
||||||
|
|
||||||
const ID_BITS := 16
|
const ID_BITS := 16
|
||||||
const ID_MASK := (1 << ID_BITS) - 1
|
const ID_MASK := (1 << ID_BITS) - 1
|
||||||
|
## How fast a hit's flash (hurt) fades, per second.
|
||||||
|
const HURT_FADE := 4.0
|
||||||
const TYPE_THIEF := 0
|
const TYPE_THIEF := 0
|
||||||
const TYPE_CROW := 1
|
const TYPE_CROW := 1
|
||||||
const TYPE_BREAKER := 2
|
const TYPE_BREAKER := 2
|
||||||
|
|
@ -339,7 +341,7 @@ func step(dt: float, scarecrow: Vector2, scarecrow_radius: float) -> void:
|
||||||
var max_corr := cfg.max_correction_per_tick
|
var max_corr := cfg.max_correction_per_tick
|
||||||
var g := grid
|
var g := grid
|
||||||
for i in active_count:
|
for i in active_count:
|
||||||
hurt[i] = maxf(hurt[i] - dt * 4.0, 0.0)
|
hurt[i] = maxf(hurt[i] - dt * HURT_FADE, 0.0)
|
||||||
attack_cd[i] = maxf(attack_cd[i] - dt, 0.0)
|
attack_cd[i] = maxf(attack_cd[i] - dt, 0.0)
|
||||||
slow_left[i] = maxf(slow_left[i] - dt, 0.0)
|
slow_left[i] = maxf(slow_left[i] - dt, 0.0)
|
||||||
var x := pos_x[i]
|
var x := pos_x[i]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
class_name RemoteControls
|
class_name RemoteControls
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## What a scarecrow played on another machine wants this tick, as the host sees it (co-op,
|
## What a scarecrow played on another machine wants this tick, as the host sees it (co-op,
|
||||||
## CoopSession). The partner's game sends its input every frame: which actions are held, a
|
## CoopSession). The partner's game sends its input record (Sender.record, RECORD_SIZE bytes)
|
||||||
## running press count per action (so a press is never lost with a dropped packet: the host
|
## whenever it changes, and again at least every few frames: which actions are held, a running
|
||||||
## counts the new ones), its aim (and the ground point a pumpkin bomb would land on), the weapon
|
## press count per action (so a press is never lost with a dropped packet: the host counts the
|
||||||
## in hand, and whether it is building or has the upgrade menu open. The
|
## new ones), its aim (and the ground point a pumpkin bomb would land on), the weapon in hand,
|
||||||
## kit classes (Scarecrow, Interactions, ScarecrowCombat) read this instead of the local Input
|
## whether it is building or has the upgrade menu open, and where its scarecrow is. The kit
|
||||||
## when their remote is set.
|
## classes (Scarecrow, Interactions, ScarecrowCombat) read this instead of the local Input when
|
||||||
|
## their remote is set.
|
||||||
|
|
||||||
const ACTIONS: Array[StringName] = [&"fire", &"fear", &"patch", &"interact", &"offhand"]
|
const ACTIONS: Array[StringName] = [&"fire", &"fear", &"patch", &"interact", &"offhand"]
|
||||||
|
## Held bits, a 16-bit count per action, the aim (2 x s16), the aim and ground points and the
|
||||||
|
## scarecrow's position (3 x s16 cm each), device, weapon, flags, facing (s16), speed.
|
||||||
|
const RECORD_SIZE := 1 + 2 * 5 + 4 + 6 + 6 + 3 + 6 + 2 + 1
|
||||||
|
|
||||||
var aim := Vector2(0.0, -1.0)
|
var aim := Vector2(0.0, -1.0)
|
||||||
var aim_point := Vector3.ZERO
|
var aim_point := Vector3.ZERO
|
||||||
|
|
@ -19,6 +23,10 @@ var device: int = 0
|
||||||
var weapon: int = -1
|
var weapon: int = -1
|
||||||
var build_active := false
|
var build_active := false
|
||||||
var ui_open := false
|
var ui_open := false
|
||||||
|
## The partner's scarecrow, as its machine moved it (CoopSession puts this on the host's copy).
|
||||||
|
var position := Vector3.ZERO
|
||||||
|
var yaw: float = 0.0
|
||||||
|
var speed: float = 0.0
|
||||||
|
|
||||||
var _held := 0
|
var _held := 0
|
||||||
var _presses := RemoteControls.counts()
|
var _presses := RemoteControls.counts()
|
||||||
|
|
@ -46,21 +54,29 @@ func take(action: StringName) -> bool:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
## The partner's input record (CoopSession): {"held": bits, "presses": counts, "aim": Vector2,
|
## The partner's input record (Sender.record). False if it isn't one.
|
||||||
## "aim_point": Vector3, "ground": Vector3, "device", "weapon", "build", "ui"}.
|
func apply(rec: PackedByteArray) -> bool:
|
||||||
func apply(rec: Dictionary) -> void:
|
if rec.size() != RECORD_SIZE:
|
||||||
_held = int(rec.get("held", 0))
|
return false
|
||||||
var p: Variant = rec.get("presses", [])
|
var b := CoopLink.reader(rec)
|
||||||
var counts: Array = Array(p) if p is PackedInt32Array else (p if p is Array else [])
|
_held = b.get_u8()
|
||||||
for i in mini(ACTIONS.size(), counts.size()):
|
for i in ACTIONS.size():
|
||||||
_presses[i] = maxi(_presses[i], int(counts[i]))
|
var step := (b.get_u16() - _presses[i]) & 0xFFFF # the counts go round at 65536
|
||||||
aim = rec.get("aim", aim)
|
if step < 0x8000:
|
||||||
aim_point = rec.get("aim_point", aim_point)
|
_presses[i] += step
|
||||||
ground_point = rec.get("ground", ground_point)
|
var ax := b.get_16() / 10000.0
|
||||||
device = int(rec.get("device", device))
|
aim = Vector2(ax, b.get_16() / 10000.0)
|
||||||
weapon = int(rec.get("weapon", weapon))
|
aim_point = CoopLink.get_v3(b)
|
||||||
build_active = bool(rec.get("build", false))
|
ground_point = CoopLink.get_v3(b)
|
||||||
ui_open = bool(rec.get("ui", false))
|
device = b.get_u8()
|
||||||
|
weapon = b.get_8()
|
||||||
|
var flags := b.get_u8()
|
||||||
|
build_active = (flags & 1) != 0
|
||||||
|
ui_open = (flags & 2) != 0
|
||||||
|
position = CoopLink.get_v3(b)
|
||||||
|
yaw = CoopLink.get_angle(b)
|
||||||
|
speed = b.get_u8() / 100.0
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
## Forget held actions (the partner left, or a new morning).
|
## Forget held actions (the partner left, or a new morning).
|
||||||
|
|
@ -81,7 +97,9 @@ class Sender:
|
||||||
presses[i] += 1
|
presses[i] += 1
|
||||||
_was[i] = 1
|
_was[i] = 1
|
||||||
|
|
||||||
func record(aim: Vector2, aim_point: Vector3, device: int, build: bool, ui: bool) -> Dictionary:
|
## The input record (RemoteControls.apply): the actions held now (none while frozen: a menu
|
||||||
|
## is up), every press so far, and the scarecrow.
|
||||||
|
func record(combat: ScarecrowCombat, body: PlayerCharacter, build: bool, ui: bool, frozen: bool) -> PackedByteArray:
|
||||||
var bits := 0
|
var bits := 0
|
||||||
for i in RemoteControls.ACTIONS.size():
|
for i in RemoteControls.ACTIONS.size():
|
||||||
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
|
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
|
||||||
|
|
@ -90,5 +108,18 @@ class Sender:
|
||||||
if _was[i] == 0: # pressed without an event (simulated input)
|
if _was[i] == 0: # pressed without an event (simulated input)
|
||||||
presses[i] += 1
|
presses[i] += 1
|
||||||
_was[i] = 1 if down else 0
|
_was[i] = 1 if down else 0
|
||||||
return {"held": bits, "presses": presses.duplicate(), "aim": aim, "aim_point": aim_point, "device": device,
|
var b := StreamPeerBuffer.new()
|
||||||
"build": build, "ui": ui}
|
b.put_u8(0 if frozen else bits)
|
||||||
|
for i in RemoteControls.ACTIONS.size():
|
||||||
|
b.put_u16(presses[i] & 0xFFFF)
|
||||||
|
b.put_16(clampi(roundi(combat.aim.x * 10000.0), -32767, 32767))
|
||||||
|
b.put_16(clampi(roundi(combat.aim.y * 10000.0), -32767, 32767))
|
||||||
|
CoopLink.put_v3(b, combat.aim_point)
|
||||||
|
CoopLink.put_v3(b, combat.ground_point)
|
||||||
|
b.put_u8(int(combat.device))
|
||||||
|
b.put_8(int(combat.weapon))
|
||||||
|
b.put_u8((1 if build else 0) | (2 if ui else 0))
|
||||||
|
CoopLink.put_v3(b, body.global_position)
|
||||||
|
CoopLink.put_angle(b, body.model.rotation.y)
|
||||||
|
b.put_u8(clampi(roundi(body.move_strength() * 100.0), 0, 255))
|
||||||
|
return b.data_array
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ extends RefCounted
|
||||||
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
|
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
|
||||||
## and shots reaching the replica,
|
## and shots reaching the replica,
|
||||||
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
|
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
|
||||||
## sizes with a crowd, dropped unreliable messages, and either side leaving.
|
## sizes with a crowd, dropped unreliable messages, and either side leaving. And the traffic: the
|
||||||
|
## farm state isn't resent for the clock alone, a partner standing still sends little, enemies go
|
||||||
|
## by dead reckoning, and voice chat's codec and gate (CoopVoice).
|
||||||
|
|
||||||
const P := CampaignController.Phase
|
const P := CampaignController.Phase
|
||||||
const DT := 1.0 / 60.0
|
const DT := 1.0 / 60.0
|
||||||
|
|
@ -29,6 +31,7 @@ func run(p_r: GameTestRunner) -> void:
|
||||||
await _setup()
|
await _setup()
|
||||||
_join()
|
_join()
|
||||||
_requests()
|
_requests()
|
||||||
|
_quiet_wire()
|
||||||
await _partner_moves_and_gathers()
|
await _partner_moves_and_gathers()
|
||||||
_night()
|
_night()
|
||||||
_partner_shoots()
|
_partner_shoots()
|
||||||
|
|
@ -36,6 +39,7 @@ func run(p_r: GameTestRunner) -> void:
|
||||||
_fall_rule()
|
_fall_rule()
|
||||||
_crowd()
|
_crowd()
|
||||||
_leaving()
|
_leaving()
|
||||||
|
_voice()
|
||||||
for l in links:
|
for l in links:
|
||||||
l.close()
|
l.close()
|
||||||
host_farm.queue_free()
|
host_farm.queue_free()
|
||||||
|
|
@ -137,6 +141,22 @@ func _requests() -> void:
|
||||||
"the partner buys an upgrade at the workbench (the host does it)")
|
"the partner buys an upgrade at the workbench (the host does it)")
|
||||||
|
|
||||||
|
|
||||||
|
## Standing still by day: the clock runs, nothing else changes.
|
||||||
|
func _quiet_wire() -> void:
|
||||||
|
_pump(30) # the requests' news settles
|
||||||
|
var states := links[0].sent_count("state")
|
||||||
|
var inputs := links[1].sent_count("input")
|
||||||
|
var left := host.campaign.state.phase_time_left
|
||||||
|
_pump(120)
|
||||||
|
r.check(host.campaign.state.phase_time_left < left - 1.5 and links[0].sent_count("state") == states,
|
||||||
|
"the day's clock runs on both farms, but the farm state isn't resent for it")
|
||||||
|
var n := links[1].sent_count("input") - inputs
|
||||||
|
r.check(n >= 7 and n <= 9, "the partner standing still sends its input %d times in 2 s (every %.2f s, not every frame)"
|
||||||
|
% [n, CoopSession.INPUT_KEEPALIVE])
|
||||||
|
r.check(absf(client.campaign.state.phase_time_left - host.campaign.state.phase_time_left) < 0.2,
|
||||||
|
"and the partner's clock follows the host's (from the snapshots)")
|
||||||
|
|
||||||
|
|
||||||
func _partner_moves_and_gathers() -> void:
|
func _partner_moves_and_gathers() -> void:
|
||||||
var tree: GatherNode
|
var tree: GatherNode
|
||||||
for n in host.interactions.nodes:
|
for n in host.interactions.nodes:
|
||||||
|
|
@ -303,6 +323,19 @@ func _crowd() -> void:
|
||||||
r.info("co-op traffic: host sent %d messages, %.1f KB in %d ticks; partner %d messages" % [links[0].sent_messages,
|
r.info("co-op traffic: host sent %d messages, %.1f KB in %d ticks; partner %d messages" % [links[0].sent_messages,
|
||||||
links[0].sent_bytes / 1024.0, hs.ticks, links[1].sent_messages])
|
links[0].sent_bytes / 1024.0, hs.ticks, links[1].sent_messages])
|
||||||
links[0].drop_every = 0
|
links[0].drop_every = 0
|
||||||
|
# Dead reckoning: two seconds of the crowd, against every enemy in every snapshot.
|
||||||
|
var records := hs.foe_records
|
||||||
|
var bytes := links[0].sent_bytes
|
||||||
|
var partner_bytes := links[1].sent_bytes
|
||||||
|
var snaps := links[0].sent_count("snap")
|
||||||
|
var crowd := host.enemies.alive_count()
|
||||||
|
_pump(120)
|
||||||
|
var every := crowd * (links[0].sent_count("snap") - snaps)
|
||||||
|
r.check(hs.foe_records - records < every / 2, "the host sends %d enemy records in 2 s, not %d (only the ones the partner's guess drifted from)"
|
||||||
|
% [hs.foe_records - records, every])
|
||||||
|
r.check(_enemies_match(1.0), "and the partner's crowd still matches the host's")
|
||||||
|
r.info("crowd of %d: host %.1f KB/s, partner %.1f KB/s (before GD-Sync's wrapping)" % [crowd,
|
||||||
|
(links[0].sent_bytes - bytes) / 2048.0, (links[1].sent_bytes - partner_bytes) / 2048.0])
|
||||||
|
|
||||||
|
|
||||||
func _leaving() -> void:
|
func _leaving() -> void:
|
||||||
|
|
@ -319,6 +352,60 @@ func _leaving() -> void:
|
||||||
r.check(not host.campaign.state.coop, "a co-op morning played alone goes back to the solo rules")
|
r.check(not host.campaign.state.coop, "a co-op morning played alone goes back to the solo rules")
|
||||||
|
|
||||||
|
|
||||||
|
## Voice chat's sending, without GD-Sync: the gate, the pieces, and the codec.
|
||||||
|
func _voice() -> void:
|
||||||
|
var v := CoopVoice.new()
|
||||||
|
var mix := 48000.0
|
||||||
|
var hum := _frames(mix, 1.0, func(t: float) -> float: return 0.003 * sin(TAU * 50.0 * t))
|
||||||
|
r.check(v.feed(hum, mix).is_empty(), "voice: a quiet microphone (room hum) sends nothing")
|
||||||
|
var click := _frames(mix, 0.03, func(t: float) -> float: return 0.6 if int(t * 4000.0) % 2 == 0 else -0.6)
|
||||||
|
var sent := v.feed(click, mix)
|
||||||
|
sent.append_array(v.feed(hum, mix))
|
||||||
|
r.check(sent.is_empty(), "a click alone doesn't open the gate")
|
||||||
|
var words := v.feed(_frames(mix, 0.6, func(t: float) -> float: return 0.2 * sin(TAU * 220.0 * t)), mix)
|
||||||
|
words.append_array(v.feed(hum, mix))
|
||||||
|
var size := 3 + CoopVoice.CHUNK / 2
|
||||||
|
var all_sized := true
|
||||||
|
for piece in words:
|
||||||
|
all_sized = all_sized and piece.size() == size
|
||||||
|
r.check(words.size() >= 12 and words.size() <= 22 and all_sized,
|
||||||
|
"speech opens it: %d pieces of %d bytes (0.6 s of voice, the piece before, and the hold)" % [words.size(), size])
|
||||||
|
r.check(v.feed(hum, mix).is_empty(), "and the gate shuts again after the hold")
|
||||||
|
var kbs := size * float(CoopVoice.RATE) / CoopVoice.CHUNK / 1024.0
|
||||||
|
r.check(kbs < 7.0, "talking costs %.1f KB/s before GD-Sync's wrapping (GD-Sync's raw VoiceChat: about 47)" % kbs)
|
||||||
|
v.free()
|
||||||
|
var tone := PackedFloat32Array()
|
||||||
|
for i in 2 * CoopVoice.CHUNK:
|
||||||
|
tone.append(0.25 * sin(TAU * 300.0 * i / CoopVoice.RATE) + 0.1 * sin(TAU * 1100.0 * i / CoopVoice.RATE))
|
||||||
|
var state := [0, 0]
|
||||||
|
var first := CoopVoice.encode(tone.slice(0, CoopVoice.CHUNK), state)
|
||||||
|
var second := CoopVoice.encode(tone.slice(CoopVoice.CHUNK), state)
|
||||||
|
var snr_first := _snr(tone.slice(0, CoopVoice.CHUNK), CoopVoice.decode(first))
|
||||||
|
var snr_second := _snr(tone.slice(CoopVoice.CHUNK), CoopVoice.decode(second))
|
||||||
|
r.check(snr_first > 15.0 and snr_second > 25.0,
|
||||||
|
"ADPCM keeps the sound: %.0f dB signal to noise from a cold start (a few samples to adapt), %.0f dB running" % [snr_first, snr_second])
|
||||||
|
r.check(CoopVoice.decode(second).size() == CoopVoice.CHUNK, "and a piece decodes on its own (a lost one before it costs nothing more)")
|
||||||
|
|
||||||
|
|
||||||
|
## Stereo microphone frames: seconds of f(t) at mix Hz.
|
||||||
|
static func _frames(mix: float, seconds: float, f: Callable) -> PackedVector2Array:
|
||||||
|
var out := PackedVector2Array()
|
||||||
|
out.resize(roundi(mix * seconds))
|
||||||
|
for i in out.size():
|
||||||
|
var s: float = f.call(i / mix)
|
||||||
|
out[i] = Vector2(s, s)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
static func _snr(a: PackedFloat32Array, b: PackedFloat32Array) -> float:
|
||||||
|
var sig := 0.0
|
||||||
|
var noise := 0.0
|
||||||
|
for i in mini(a.size(), b.size()):
|
||||||
|
sig += a[i] * a[i]
|
||||||
|
noise += (a[i] - b[i]) * (a[i] - b[i])
|
||||||
|
return 10.0 * log(sig / maxf(noise, 1e-12)) / log(10.0)
|
||||||
|
|
||||||
|
|
||||||
func _types(es: EnemySystem) -> Dictionary:
|
func _types(es: EnemySystem) -> Dictionary:
|
||||||
var out := {}
|
var out := {}
|
||||||
for d in es.active_count:
|
for d in es.active_count:
|
||||||
|
|
|
||||||
291
game/tools/net_budget.gd
Normal file
291
game/tools/net_budget.gd
Normal file
|
|
@ -0,0 +1,291 @@
|
||||||
|
extends SceneTree
|
||||||
|
## Measures co-op traffic over whole days and nights, for the GD-Sync data allowance. The host's
|
||||||
|
## farm and the partner's run in one process (as in test_coop.gd) over a loopback link that also
|
||||||
|
## packs every message the way GD-Sync does online (RequestProcessor.package_requests): the
|
||||||
|
## remote call's request, the auth stamp on unreliable ones, one packet per tick per channel
|
||||||
|
## (unreliable ones split at 1200 bytes), AES padding, and the compressed envelope. Reports the
|
||||||
|
## bytes each side sends to GD-Sync's server, by message kind and by phase, and what voice chat
|
||||||
|
## adds. The host plays the real night plans; an auto-guard kills an enemy every --kill-every
|
||||||
|
## seconds (carriers first), and both scarecrows are invulnerable, so every night runs to dawn.
|
||||||
|
## The partner walks circles all the time (so its input changes, as in play).
|
||||||
|
## godot --headless --path . --script res://game/tools/net_budget.gd -- --nights=5
|
||||||
|
## Options: --nights=5, --day=180 (seconds of each day played; the rest is skipped),
|
||||||
|
## --kill-every=1.5, --mix=48000 (the microphone's mix rate, for the voice estimate), --fps=60.
|
||||||
|
|
||||||
|
const DT := 1.0 / 60.0
|
||||||
|
const P := CampaignController.Phase
|
||||||
|
|
||||||
|
var host: FarmSim
|
||||||
|
var client: FarmSim
|
||||||
|
var hs: CoopSession
|
||||||
|
var cs: CoopSession
|
||||||
|
var links: Array = []
|
||||||
|
## Phase name -> seconds played there.
|
||||||
|
var phase_time := {}
|
||||||
|
var peak_enemies: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
## GD-Sync's online packing of one side's messages (see the class comment).
|
||||||
|
class WireModel:
|
||||||
|
const CALL_FUNCTION_CACHED := 6
|
||||||
|
const CLIENT_REQUESTS := 1
|
||||||
|
const LIMIT := 1200
|
||||||
|
const CLIENT_ID := 0x2345678 # online client ids are server-given; any 30-bit one sizes the same
|
||||||
|
|
||||||
|
var reliable: Array = [] # [kind, request]
|
||||||
|
var unreliable: Array = []
|
||||||
|
var nonce: int = 1 << 40
|
||||||
|
## kind -> [messages, plain bytes (var_to_bytes([kind, data])), bytes on the wire]
|
||||||
|
var by_kind := {}
|
||||||
|
## phase -> bytes on the wire
|
||||||
|
var by_phase := {}
|
||||||
|
var phase := "?"
|
||||||
|
var packets: int = 0
|
||||||
|
var wire_bytes: int = 0
|
||||||
|
## Ciphertext size -> enveloped size (zstd on random bytes).
|
||||||
|
static var _enveloped := {}
|
||||||
|
static var _noise := PackedByteArray()
|
||||||
|
|
||||||
|
## A message as sent (kind may be CoopLink's "z" for a compressed one), counted as label.
|
||||||
|
func queue(label: String, kind: String, data: Variant, is_reliable: bool) -> void:
|
||||||
|
var request: Array = [CALL_FUNCTION_CACHED, 3, 7, CLIENT_ID, CLIENT_ID, [kind, data]]
|
||||||
|
var plain := var_to_bytes([kind, data]).size()
|
||||||
|
var t: Array = by_kind.get(label, [0, 0, 0])
|
||||||
|
t[0] += 1
|
||||||
|
t[1] += plain
|
||||||
|
by_kind[label] = t
|
||||||
|
(reliable if is_reliable else unreliable).append([label, request])
|
||||||
|
|
||||||
|
## One frame's packets (GD-Sync sends each channel's queue once per frame, at most eight
|
||||||
|
## unreliable packets).
|
||||||
|
func flush() -> void:
|
||||||
|
if not reliable.is_empty():
|
||||||
|
_packet(reliable)
|
||||||
|
reliable = []
|
||||||
|
var n := 0
|
||||||
|
while not unreliable.is_empty() and n < 8:
|
||||||
|
var fit := 1
|
||||||
|
while fit < unreliable.size() and _size(unreliable.slice(0, fit + 1), true) <= LIMIT:
|
||||||
|
fit += 1
|
||||||
|
_packet(unreliable.slice(0, fit), true)
|
||||||
|
unreliable = unreliable.slice(fit)
|
||||||
|
n += 1
|
||||||
|
|
||||||
|
func _stamped(request: Array) -> Array:
|
||||||
|
var mac := PackedByteArray()
|
||||||
|
mac.resize(32)
|
||||||
|
nonce += 1
|
||||||
|
return request + [{"_gdsn": [1, nonce, mac]}]
|
||||||
|
|
||||||
|
func _size(batch: Array, stamped: bool = false) -> int:
|
||||||
|
var reqs: Array = []
|
||||||
|
for e: Array in batch:
|
||||||
|
reqs.append(_stamped(e[1]) if stamped else e[1])
|
||||||
|
var plain := var_to_bytes({CLIENT_REQUESTS: reqs}).size()
|
||||||
|
var cipher := plain + (16 - plain % 16)
|
||||||
|
if not _enveloped.has(cipher):
|
||||||
|
if _noise.is_empty():
|
||||||
|
_noise.resize(1 << 16)
|
||||||
|
for i in _noise.size():
|
||||||
|
_noise[i] = randi() & 0xFF # ciphertext: zstd can't shrink it
|
||||||
|
var blob := _noise.slice(0, cipher) if cipher <= _noise.size() else _noise
|
||||||
|
_enveloped[cipher] = var_to_bytes([plain, 0, blob.compress(FileAccess.COMPRESSION_ZSTD)]).size()
|
||||||
|
return _enveloped[cipher]
|
||||||
|
|
||||||
|
func _packet(batch: Array, stamped: bool = false) -> void:
|
||||||
|
var size := _size(batch, stamped)
|
||||||
|
packets += 1
|
||||||
|
wire_bytes += size
|
||||||
|
by_phase[phase] = int(by_phase.get(phase, 0)) + size
|
||||||
|
var total := 0
|
||||||
|
for e: Array in batch:
|
||||||
|
total += var_to_bytes(e[1]).size()
|
||||||
|
for e: Array in batch:
|
||||||
|
var t: Array = by_kind[e[0]]
|
||||||
|
t[2] += roundi(size * float(var_to_bytes(e[1]).size()) / total)
|
||||||
|
|
||||||
|
|
||||||
|
class MeterLink extends CoopLink.Loopback:
|
||||||
|
var wire := WireModel.new()
|
||||||
|
var _label := ""
|
||||||
|
|
||||||
|
func send(kind: String, data: Variant, reliable: bool) -> void:
|
||||||
|
_label = kind
|
||||||
|
super(kind, data, reliable)
|
||||||
|
|
||||||
|
func _deliver(kind: String, data: Variant, reliable: bool) -> void:
|
||||||
|
wire.queue(_label, kind, data, reliable)
|
||||||
|
super(kind, data, reliable)
|
||||||
|
|
||||||
|
|
||||||
|
func _initialize() -> void:
|
||||||
|
_run.call_deferred()
|
||||||
|
|
||||||
|
|
||||||
|
func _run() -> void:
|
||||||
|
var nights := 5
|
||||||
|
var day := 180.0
|
||||||
|
var kill_every := 1.5
|
||||||
|
var mix := 48000.0
|
||||||
|
var fps := 60.0
|
||||||
|
for a in OS.get_cmdline_user_args():
|
||||||
|
var arg := String(a)
|
||||||
|
if arg.begins_with("--nights="):
|
||||||
|
nights = int(arg.trim_prefix("--nights="))
|
||||||
|
elif arg.begins_with("--day="):
|
||||||
|
day = float(arg.trim_prefix("--day="))
|
||||||
|
elif arg.begins_with("--kill-every="):
|
||||||
|
kill_every = float(arg.trim_prefix("--kill-every="))
|
||||||
|
elif arg.begins_with("--mix="):
|
||||||
|
mix = float(arg.trim_prefix("--mix="))
|
||||||
|
elif arg.begins_with("--fps="):
|
||||||
|
fps = float(arg.trim_prefix("--fps="))
|
||||||
|
await _setup()
|
||||||
|
var a := MeterLink.new()
|
||||||
|
var b := MeterLink.new()
|
||||||
|
a.other = b
|
||||||
|
b.other = a
|
||||||
|
links = [a, b]
|
||||||
|
hs.start_host(host, a, "Ana", "Ben")
|
||||||
|
cs.start_client(client, b, "Ben")
|
||||||
|
_pump(2)
|
||||||
|
var c := host.campaign
|
||||||
|
var kill_wait := kill_every
|
||||||
|
var t0 := Time.get_ticks_msec()
|
||||||
|
while c.state.nights_survived < nights and c.outcome != CampaignController.Outcome.VACATION_COMPLETE:
|
||||||
|
match c.state.phase:
|
||||||
|
P.MORNING:
|
||||||
|
c.begin_day()
|
||||||
|
P.GAME_OVER:
|
||||||
|
print(" game over on night %d: retrying" % c.state.night)
|
||||||
|
c.retry_night()
|
||||||
|
P.DAY:
|
||||||
|
if c.state.phase_time_left > 1.0 and host.config.day_length - c.state.phase_time_left >= day:
|
||||||
|
c.state.phase_time_left = 1.0 # the rest of the day is more of the same
|
||||||
|
for av in host.avatars:
|
||||||
|
av.kit.invulnerable_left = 1.0
|
||||||
|
var walk := hs.ticks * DT * 0.8
|
||||||
|
client.local_avatar.body.global_position = Vector3(10.0 + 4.0 * cos(walk), 0.0, -8.0 + 4.0 * sin(walk))
|
||||||
|
if c.state.phase == P.NIGHT or c.state.phase == P.DAWN:
|
||||||
|
kill_wait -= DT
|
||||||
|
if kill_wait <= 0.0:
|
||||||
|
kill_wait = kill_every
|
||||||
|
_kill_one()
|
||||||
|
var name := String(P.keys()[c.state.phase])
|
||||||
|
for l: MeterLink in links:
|
||||||
|
l.wire.phase = name
|
||||||
|
phase_time[name] = float(phase_time.get(name, 0.0)) + DT
|
||||||
|
peak_enemies = maxi(peak_enemies, host.enemies.alive_count())
|
||||||
|
_pump()
|
||||||
|
print("played %d nights (%.0f s of game time) in %.0f s" % [c.state.nights_survived, hs.ticks * DT, (Time.get_ticks_msec() - t0) / 1000.0])
|
||||||
|
_report(fps, mix)
|
||||||
|
for l: CoopLink in links:
|
||||||
|
l.close()
|
||||||
|
quit(0)
|
||||||
|
|
||||||
|
|
||||||
|
func _setup() -> void:
|
||||||
|
var scene := load("res://game/scenes/farm.tscn") as PackedScene
|
||||||
|
var host_farm := scene.instantiate() as Node3D
|
||||||
|
root.add_child(host_farm)
|
||||||
|
var viewport := SubViewport.new()
|
||||||
|
viewport.own_world_3d = true
|
||||||
|
viewport.size = Vector2i(320, 180)
|
||||||
|
var box := SubViewportContainer.new()
|
||||||
|
root.add_child(box)
|
||||||
|
box.add_child(viewport)
|
||||||
|
var client_farm := scene.instantiate() as Node3D
|
||||||
|
viewport.add_child(client_farm)
|
||||||
|
await process_frame
|
||||||
|
await physics_frame
|
||||||
|
host = host_farm.get_node("FarmSim") as FarmSim
|
||||||
|
client = client_farm.get_node("FarmSim") as FarmSim
|
||||||
|
for f: FarmSim in [host, client]:
|
||||||
|
f.set_physics_process(false)
|
||||||
|
f.coop.set_physics_process(false)
|
||||||
|
if f.tutorial != null:
|
||||||
|
f.tutorial.enabled = false
|
||||||
|
client.waves.enabled = false
|
||||||
|
hs = host.coop
|
||||||
|
cs = client.coop
|
||||||
|
|
||||||
|
|
||||||
|
func _pump(n: int = 1) -> void:
|
||||||
|
for i in n:
|
||||||
|
for f: FarmSim in [host, client]:
|
||||||
|
for av in f.avatars:
|
||||||
|
if av.body.remote_driven:
|
||||||
|
av.body._follow_net(DT)
|
||||||
|
host.step(DT)
|
||||||
|
hs._physics_process(DT)
|
||||||
|
client.step(DT)
|
||||||
|
cs._physics_process(DT)
|
||||||
|
for l: MeterLink in links:
|
||||||
|
l.wire.flush()
|
||||||
|
|
||||||
|
|
||||||
|
## The auto-guard: a carrier if there is one, else any enemy.
|
||||||
|
func _kill_one() -> void:
|
||||||
|
var es := host.enemies
|
||||||
|
var pick := -1
|
||||||
|
for d in es.active_count:
|
||||||
|
if es.alive[d] == 0:
|
||||||
|
continue
|
||||||
|
if pick < 0 or (es.carry[d] >= 0 and es.carry[pick] < 0):
|
||||||
|
pick = d
|
||||||
|
if pick >= 0:
|
||||||
|
es.apply_hit(pick, 99)
|
||||||
|
|
||||||
|
|
||||||
|
func _report(fps: float, mix: float) -> void:
|
||||||
|
var seconds := hs.ticks * DT
|
||||||
|
print("peak enemies alive: %d; seconds by phase: %s" % [peak_enemies, _rounded(phase_time)])
|
||||||
|
var total := 0
|
||||||
|
for side in 2:
|
||||||
|
var w: WireModel = links[side].wire
|
||||||
|
total += w.wire_bytes
|
||||||
|
print("\n%s -> server: %.1f MB, %.1f KB/s average, %d packets (%.0f/s)" % [["Host", "Partner"][side],
|
||||||
|
w.wire_bytes / 1048576.0, w.wire_bytes / 1024.0 / seconds, w.packets, w.packets / seconds])
|
||||||
|
print(" %-8s %9s %10s %10s %9s %8s" % ["kind", "messages", "plain KB", "wire KB", "KB/s", "share"])
|
||||||
|
var kinds: Array = w.by_kind.keys()
|
||||||
|
kinds.sort_custom(func(x: String, y: String) -> bool: return w.by_kind[x][2] > w.by_kind[y][2])
|
||||||
|
for k: String in kinds:
|
||||||
|
var t: Array = w.by_kind[k]
|
||||||
|
print(" %-8s %9d %10.0f %10.0f %9.2f %7.1f%%" % [k, t[0], t[1] / 1024.0, t[2] / 1024.0, t[2] / 1024.0 / seconds,
|
||||||
|
100.0 * t[2] / w.wire_bytes])
|
||||||
|
var by_phase := {}
|
||||||
|
for ph: String in w.by_phase:
|
||||||
|
by_phase[ph] = "%.1f KB/s" % (w.by_phase[ph] / 1024.0 / maxf(float(phase_time.get(ph, 1.0)), 0.001))
|
||||||
|
print(" by phase: %s" % [by_phase])
|
||||||
|
print("\nBoth sides to the server: %.1f MB in %.1f min of play (%.1f KB/s); if GD-Sync counts the relay out too, double it"
|
||||||
|
% [total / 1048576.0, seconds / 60.0, total / 1024.0 / seconds])
|
||||||
|
# Voice: GD-Sync's own VoiceChat sent a PackedFloat32Array of the frame's audio, at a quarter
|
||||||
|
# of the mix rate, every frame the microphone peaked over its threshold; CoopVoice sends ADPCM
|
||||||
|
# pieces (measured here on a steady tone, so the gate stays open).
|
||||||
|
var raw := WireModel.new()
|
||||||
|
var samples := PackedFloat32Array()
|
||||||
|
samples.resize(roundi(mix / 4.0 / fps))
|
||||||
|
var voice := CoopVoice.new()
|
||||||
|
var coded := WireModel.new()
|
||||||
|
var block := roundi(mix / fps)
|
||||||
|
var frames := PackedVector2Array()
|
||||||
|
frames.resize(block)
|
||||||
|
for i in roundi(fps * 10.0):
|
||||||
|
raw.queue("voice", "voice", samples, false)
|
||||||
|
raw.flush()
|
||||||
|
for j in block:
|
||||||
|
var v := 0.2 * sin(TAU * 180.0 * (i * block + j) / mix)
|
||||||
|
frames[j] = Vector2(v, v)
|
||||||
|
for piece in voice.feed(frames, mix):
|
||||||
|
coded.queue("voice", "voice", piece, false)
|
||||||
|
coded.flush()
|
||||||
|
voice.free()
|
||||||
|
print("Voice chat while talking (mix %.0f Hz, %.0f fps), per player talking: %.1f KB/s (%.0f MB an hour); GD-Sync's raw VoiceChat would be %.1f KB/s"
|
||||||
|
% [mix, fps, coded.wire_bytes / 1024.0 / 10.0, coded.wire_bytes / 10.0 * 3600.0 / 1048576.0, raw.wire_bytes / 1024.0 / 10.0])
|
||||||
|
|
||||||
|
|
||||||
|
static func _rounded(d: Dictionary) -> Dictionary:
|
||||||
|
var out := {}
|
||||||
|
for k in d:
|
||||||
|
out[k] = roundi(d[k])
|
||||||
|
return out
|
||||||
1
game/tools/net_budget.gd.uid
Normal file
1
game/tools/net_budget.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dm5f1cefi3tf
|
||||||
Loading…
Add table
Add a link
Reference in a new issue