Files
transcience/src/core/sim_config.gd
T
Adyrem e2b849c6ef
ci / verify (push) Successful in 45s
Fix lobby/HUD UI pinned at (0,0); shrink player hitbox below visual size
The lobby connect menu and three pieces of the HUD (hit-flash overlay, boss
bar centering, death-message centering, hint label) were all silently broken
by the same Godot gotcha: set_anchors_preset(preset) with the default
keep_offsets=false does NOT zero the offsets to the preset's margins -- it
recomputes them to preserve the control's *current* rect, which for a
freshly constructed Control is (0,0). Anchors end up correct; the actual
rect stays pinned to the top-left corner regardless. Fixed by switching to
set_anchors_and_offsets_preset() everywhere a Control is built in code, and
by using offset_left/offset_top (anchor-relative) instead of .position
(absolute) for the HUD hint label. Documented as gotcha #5 in CLAUDE.md.

Also split PLAYER_RADIUS into two constants: PLAYER_RADIUS (6.0, the
authoritative hitbox used by SimWorld) and PLAYER_VISUAL_RADIUS (13.0,
view-only, used by world_view.gd). The client renders every ship a little
late relative to the server -- interpolation delay, reconciliation
smoothing -- so a hitbox that matched the sprite would let bullets connect
against a ship the player watched dodge clear of them. A smaller hitbox
means the occasional bullet visibly clips the sprite without a hit, which
reads as more forgiving of latency than the reverse.

Verified headlessly: a throwaway scene instantiating MainMenu/HUD under a
real 1280x720 viewport, asserting the panel is centered and _canvas.size /
hint position resolve correctly, before and after each fix. check.sh,
test.sh (78/78) and smoke.sh all pass.
2026-09-03 16:58:42 +02:00

74 lines
3.2 KiB
GDScript

class_name SimConfig
extends RefCounted
## Tuning constants shared verbatim by the server simulation and the client
## replica. Nothing here may differ between the two builds -- if a value needs
## to differ, it belongs in [GameConfig], not here.
# --- Time -------------------------------------------------------------------
const TICK_RATE := 60
const TICK_DELTA := 1.0 / 60.0
## Server sends a snapshot every N ticks (60 / 3 = 20 Hz).
const SNAPSHOT_INTERVAL := 3
## How far behind the newest snapshot the client renders remote actors.
const INTERPOLATION_DELAY_TICKS := 6
# --- Arena ------------------------------------------------------------------
const ARENA_HALF := Vector2(620.0, 340.0)
## Bullets are culled once they leave the arena by this margin.
const BULLET_CULL_MARGIN := 64.0
# --- Player -----------------------------------------------------------------
const PLAYER_SPEED := 240.0
## Authoritative hitbox. Smaller than PLAYER_VISUAL_RADIUS on purpose: a client
## renders its own and everyone else's ship a little late (interpolation delay,
## reconciliation smoothing), so a hitbox that matched the sprite exactly would
## let bullets connect against a ship the player watched dodge clear of them.
## Erring small means the occasional bullet visibly clips the ship without a
## hit -- a client-side illusion, but the one that reads as fair, versus a
## bullet that visibly missed still registering as a hit.
const PLAYER_RADIUS := 6.0
## Render-only. Used by src/view/, never by anything under src/sim/.
const PLAYER_VISUAL_RADIUS := 13.0
const PLAYER_MAX_HP := 100
const PLAYER_FIRE_COOLDOWN := 7 # ticks
const PLAYER_BULLET_SPEED := 620.0
const PLAYER_BULLET_RADIUS := 4.0
const PLAYER_BULLET_LIFETIME := 90 # ticks
const PLAYER_BULLET_DAMAGE := 6
const PLAYER_IFRAMES := 36 # ticks of invulnerability after a hit
const PLAYER_RESPAWN_DELAY := 180 # ticks
# --- Anti-cheat guards ------------------------------------------------------
## Inputs older than this (relative to the newest accepted) are discarded.
const INPUT_MAX_AGE := 30
## Inputs claiming to be further ahead than this of the server tick are clamped.
const INPUT_MAX_LEAD := 12
## Hard ceiling on inputs consumed from one peer in a single tick.
const INPUT_MAX_PER_TICK := 4
# --- Emergency escape -------------------------------------------------------
const ESCAPE_CHANNEL_TICKS := 180 # 3 seconds
## Taking damage while channelling cancels the escape.
const ESCAPE_BREAK_ON_DAMAGE := true
# --- Bullets ----------------------------------------------------------------
const MAX_BULLETS := 4096
const TEAM_PLAYER := 0
const TEAM_ENEMY := 1
# --- Bullet visual kinds (index into the renderer's atlas) ------------------
const KIND_PLAYER_SHOT := 0
const KIND_ORB := 1
const KIND_NEEDLE := 2
const KIND_HEAVY := 3
# --- Instances --------------------------------------------------------------
const LOBBY_INSTANCE_ID := 1
const DUNGEON_PARTY_MAX := 4
## How long a forming dungeon waits for more players before it locks.
const DUNGEON_FORMING_TICKS := 300
# --- Portal -----------------------------------------------------------------
const PORTAL_POS := Vector2(0.0, -220.0)
const PORTAL_RADIUS := 60.0