A9: In-game HUD, with a FEED message for the kill feed and who stands
The HUD (src/client/hud) is drawn in the paper-and-ink motifs of the style
guide:
- top centre: the tide post, the most prominent thing on screen. It is a
notched post with the sea filled in, the next level's rust notch and the
player's own height. Beside it are the phase, the time to the rise, both
levels and how far the player stands above or below the next line;
- top right: how many are standing, and the kill feed in words;
- bottom left: health and armour, each with a number, a word, quarter notches
and its own hatching. Low health adds LOW;
- bottom centre: the boathook and five slots, with names on two lines, rounds
and reserve or counts, and tier pips;
- bottom right: materials, and the build line ("NOT ENOUGH" when short).
Snapshots only carry nearby players, so the server now sends FEED (NetFeed,
reliable) when anyone is placed and at each phase change. It carries who is
standing, the match size and the newest 16 entries with names. Bots get crew
names (CrewNames). HudState works out what to show from the client, or from a
server's match for captures and tests, so the drawing never reaches into
either.
The project now stretches canvas items from a 1280x720 base, so the HUD scales
to any screen. make hud-captures renders it at 1280x720 and 3840x2160. The
parser fuzzer covers FEED.
Closes #49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,11 @@ var build_in_background: bool = false
|
||||
var fx: Array[Dictionary] = []
|
||||
## FX records received in all.
|
||||
var fx_received: int = 0
|
||||
## The kill feed as the server last told it (NetFeed entries, newest last), how many
|
||||
## are standing and how many began the match. For the HUD.
|
||||
var feed: Array[Dictionary] = []
|
||||
var standing: int = 0
|
||||
var match_size: int = 0
|
||||
## Called after each snapshot has been taken in, with no arguments. Soak tests use it
|
||||
## to compare the client's world with the server's at that moment.
|
||||
var on_snapshot: Callable = Callable()
|
||||
@@ -180,6 +185,14 @@ func _receive_now(channel: int, bytes: PackedByteArray) -> void:
|
||||
bad_packets += 1
|
||||
return
|
||||
_take_world(message)
|
||||
elif type == NetFeed.MSG_FEED:
|
||||
var told: Dictionary = NetFeed.decode(bytes)
|
||||
if told.is_empty():
|
||||
bad_packets += 1
|
||||
return
|
||||
feed = told["entries"]
|
||||
standing = told["standing"]
|
||||
match_size = told["total"]
|
||||
elif type == NetWorld.MSG_OWN:
|
||||
var carried: Dictionary = NetWorld.decode_own(bytes)
|
||||
if carried.is_empty():
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
## The kill feed and the count of who is standing, on the wire, for the HUD (A9).
|
||||
## Snapshots only carry players near the one a client watches, so the client can't
|
||||
## count the living or see eliminations across the island by itself; the server tells
|
||||
## everyone with a FEED message on the control channel (reliable) whenever someone is
|
||||
## placed, and when a match begins.
|
||||
##
|
||||
## server -> FEED
|
||||
## u8 type, u8 standing, u8 players in the match, u8 entry count, then entries:
|
||||
## s32 victim handle, s32 eliminator handle (0 = none), u8 cause (CAUSES),
|
||||
## u8 item code plus one (0 = none), u8 place, u8 flags (1 = tied),
|
||||
## str victim name, str eliminator name,
|
||||
## where str is u8 byte length then that many UTF-8 bytes (at most MAX_NAME_BYTES).
|
||||
##
|
||||
## The decoder returns an empty Dictionary for anything malformed and never raises.
|
||||
class_name NetFeed
|
||||
extends RefCounted
|
||||
|
||||
const MSG_FEED: int = 19
|
||||
## How an entry came about, by the Match's cause names.
|
||||
const CAUSES: Array[String] = ["none", "weapon", "fall", "drown", "tide", "left"]
|
||||
const HEADER_BYTES: int = 4
|
||||
const ENTRY_FIXED_BYTES: int = 12
|
||||
const MAX_ENTRIES: int = 16
|
||||
const MAX_NAME_BYTES: int = 32
|
||||
const FLAG_TIED: int = 1
|
||||
|
||||
|
||||
## Encodes the count and `entries`, newest last. Each entry has "victim", "by",
|
||||
## "cause" (a name in CAUSES), "item" (-1 none), "place", "tied", "victim_name" and
|
||||
## "by_name". Only the newest MAX_ENTRIES are kept.
|
||||
static func encode(standing: int, total: int, entries: Array[Dictionary]) -> PackedByteArray:
|
||||
var out: StreamPeerBuffer = StreamPeerBuffer.new()
|
||||
out.put_u8(MSG_FEED)
|
||||
out.put_u8(clampi(standing, 0, 255))
|
||||
out.put_u8(clampi(total, 0, 255))
|
||||
var first: int = maxi(0, entries.size() - MAX_ENTRIES)
|
||||
out.put_u8(entries.size() - first)
|
||||
for index: int in range(first, entries.size()):
|
||||
var entry: Dictionary = entries[index]
|
||||
out.put_32(int(entry.get("victim", 0)))
|
||||
out.put_32(int(entry.get("by", 0)))
|
||||
out.put_u8(maxi(0, CAUSES.find(String(entry.get("cause", "none")))))
|
||||
out.put_u8(clampi(int(entry.get("item", -1)) + 1, 0, 255))
|
||||
out.put_u8(clampi(int(entry.get("place", 0)), 0, 255))
|
||||
out.put_u8(FLAG_TIED if bool(entry.get("tied", false)) else 0)
|
||||
_put_name(out, String(entry.get("victim_name", "")))
|
||||
_put_name(out, String(entry.get("by_name", "")))
|
||||
return out.data_array
|
||||
|
||||
|
||||
## {"standing", "total", "entries": Array[Dictionary]} with the fields encode() takes,
|
||||
## or an empty Dictionary.
|
||||
static func decode(bytes: PackedByteArray) -> Dictionary:
|
||||
if bytes.size() < HEADER_BYTES or bytes[0] != MSG_FEED:
|
||||
return {}
|
||||
var count: int = bytes[3]
|
||||
if count > MAX_ENTRIES:
|
||||
return {}
|
||||
var entries: Array[Dictionary] = []
|
||||
var at: int = HEADER_BYTES
|
||||
for _index: int in count:
|
||||
if at + ENTRY_FIXED_BYTES > bytes.size():
|
||||
return {}
|
||||
var cause: int = bytes[at + 8]
|
||||
if cause >= CAUSES.size():
|
||||
return {}
|
||||
var entry: Dictionary = {
|
||||
"victim": bytes.decode_s32(at), "by": bytes.decode_s32(at + 4), "cause": CAUSES[cause],
|
||||
"item": int(bytes[at + 9]) - 1, "place": int(bytes[at + 10]), "tied": bytes[at + 11] & FLAG_TIED != 0,
|
||||
}
|
||||
at += ENTRY_FIXED_BYTES
|
||||
var names: Array[String] = []
|
||||
for _name: int in 2:
|
||||
if at >= bytes.size():
|
||||
return {}
|
||||
var length: int = bytes[at]
|
||||
if length > MAX_NAME_BYTES or at + 1 + length > bytes.size():
|
||||
return {}
|
||||
names.append(bytes.slice(at + 1, at + 1 + length).get_string_from_utf8())
|
||||
at += 1 + length
|
||||
entry["victim_name"] = names[0]
|
||||
entry["by_name"] = names[1]
|
||||
entries.append(entry)
|
||||
if at != bytes.size():
|
||||
return {}
|
||||
return {"standing": int(bytes[1]), "total": int(bytes[2]), "entries": entries}
|
||||
|
||||
|
||||
static func _put_name(out: StreamPeerBuffer, text: String) -> void:
|
||||
var raw: PackedByteArray = text.to_utf8_buffer()
|
||||
# Cut on a character boundary, never inside one.
|
||||
while raw.size() > MAX_NAME_BYTES:
|
||||
text = text.substr(0, text.length() - 1)
|
||||
raw = text.to_utf8_buffer()
|
||||
out.put_u8(raw.size())
|
||||
out.put_data(raw)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c3atn0r4ms2l6
|
||||
Reference in New Issue
Block a user