A2: Player figure and animation
The islander is built in headless Blender (tools/models/figure.py, `make figure`, `make art`) as twelve rigid parts with their origins at their joints: an oilskin coat, a sou'wester, sea boots, a bedding roll and the canvas wing-sail. Debian's Blender can't write glTF, so the figure is jointed rather than skinned. FigureRig hangs the parts on pivots, paints them from Palette with the coat in the player's own oilskin, and plays FigurePoses' hand-written key poses through one AnimationTree: idle, walk and run by speed, crouch and creep, air, skydive, glide, swim and aboard; long, short and carried holds; reload and use layers; fire, boathook swing, keg throw and building as one-shots; and a flinch when health drops. The chest takes a third of the pitch and the held item all of it. Figures animate from replicated state only: positions, look, health, the held item and the FLAG_ bits (reloading and using now reach mirrored players), with actions from FX. Every boathook swing is now a sim "swing" event, sent as a SHOT with no item, so misses are seen and heard; the new FX kind PLACE shows pieces placed. Protocol version 4. Tests: test_figure_rig (15), plus swing and PLACE cases in test_harvest and test_net_fx. make check passes (604 tests); make client-check passes. Captures: figure_states, figure_actions, figure_close (make figure-captures), client_glide and client_landed. Closes #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -148,6 +148,9 @@ func _show_player(entity: SimEntity, record: PackedInt32Array, shown: Dictionary
|
||||
entity.swimming = flags & NetSnapshot.FLAG_SWIMMING != 0
|
||||
entity.eliminated = flags & NetSnapshot.FLAG_ELIMINATED != 0
|
||||
entity.drop_state = (flags >> NetSnapshot.FLAG_DROP_SHIFT) & 3
|
||||
# Only whether they last, for drawing: the ticks left aren't replicated.
|
||||
entity.reload_ticks = 1 if flags & NetSnapshot.FLAG_RELOADING != 0 else 0
|
||||
entity.use_ticks = 1 if flags & NetSnapshot.FLAG_USING != 0 else 0
|
||||
# What is in the player's hands, for whoever draws it: the item's code, or -1.
|
||||
entity.item = record[NetSnapshot.R_HELD] - 1
|
||||
if entity.drop_state == Drop.ABOARD and barge_at != Vector3.INF:
|
||||
@@ -165,5 +168,8 @@ func _show_own(entity: SimEntity, game: ClientGame) -> void:
|
||||
entity.crouching = me.crouching
|
||||
entity.swimming = me.swimming
|
||||
entity.drop_state = me.drop_state
|
||||
entity.velocity = me.velocity
|
||||
entity.reload_ticks = me.reload_ticks
|
||||
entity.use_ticks = me.use_ticks
|
||||
if me.drop_state == Drop.ABOARD and barge_at != Vector3.INF:
|
||||
entity.position = barge_at
|
||||
|
||||
+28
-10
@@ -1,5 +1,5 @@
|
||||
## Things that happen and are gone, on the wire: shots fired, where shots landed, and
|
||||
## harvesting swings. They change nothing a client keeps (damage, broken props and
|
||||
## Things that happen and are gone, on the wire: shots fired and boathook swings,
|
||||
## where shots landed, harvesting hits and pieces placed. They change nothing a client keeps (damage, broken props and
|
||||
## pieces arrive in snapshots and WORLD), so they are only for drawing and sound: an
|
||||
## FX message goes unreliably on the state channel next to each snapshot, and a lost
|
||||
## one is a missed flash, not a wrong world. Sending them reliably would add to the
|
||||
@@ -11,9 +11,12 @@
|
||||
## s16 x 3 position in decimetres,
|
||||
## SHOT: s16 yaw and s16 pitch of the aim, in 1/10000 radian,
|
||||
## IMPACT: u8 what was hit (Weapons.HIT_), varint target,
|
||||
## HARVEST: varint prop, or 0 and varint piece plus one for a piece.
|
||||
## HARVEST: varint prop, or 0 and varint piece plus one for a piece,
|
||||
## PLACE: varint piece.
|
||||
##
|
||||
## Positions are where the shot began, where it landed, or the swinging player's feet.
|
||||
## A boathook swing is a SHOT with no item (code -1). Positions are where the shot or
|
||||
## swing began, where it landed, the swinging player's feet for HARVEST, or the
|
||||
## placed piece's centre.
|
||||
## The decoder returns an empty Dictionary for anything malformed and never raises.
|
||||
class_name NetFx
|
||||
extends RefCounted
|
||||
@@ -23,7 +26,8 @@ const MSG_FX: int = 18
|
||||
const SHOT: int = 1
|
||||
const IMPACT: int = 2
|
||||
const HARVEST: int = 3
|
||||
const KIND_NAMES: Array[String] = ["", "shot", "impact", "harvest"]
|
||||
const PLACE: int = 4
|
||||
const KIND_NAMES: Array[String] = ["", "shot", "impact", "harvest", "place"]
|
||||
|
||||
const HEADER_BYTES: int = 6
|
||||
const MAX_EVENTS: int = 255
|
||||
@@ -33,13 +37,14 @@ const ANGLE_SCALE: float = 10000.0
|
||||
|
||||
|
||||
## The FX record for a simulation event, or an empty Dictionary for events that aren't
|
||||
## FX. `players` maps entity IDs to their feet, for harvest swings.
|
||||
static func from_event(event: Dictionary, tick: int, players: Dictionary = {}) -> Dictionary:
|
||||
## FX. `players` maps entity IDs to their feet, for harvest swings; `pieces` maps
|
||||
## piece IDs to their centres, for pieces placed.
|
||||
static func from_event(event: Dictionary, tick: int, players: Dictionary = {}, pieces: Dictionary = {}) -> Dictionary:
|
||||
match String(event.get("type", "")):
|
||||
"shot":
|
||||
"shot", "swing":
|
||||
var direction: Vector3 = event["direction"]
|
||||
return {
|
||||
"kind": SHOT, "tick": tick, "player": int(event["player"]), "item": int(event["item"]),
|
||||
"kind": SHOT, "tick": tick, "player": int(event["player"]), "item": int(event.get("item", -1)),
|
||||
"position": event["from"],
|
||||
"yaw": atan2(direction.x, direction.z), "pitch": asin(clampf(direction.y, -1.0, 1.0)),
|
||||
}
|
||||
@@ -55,6 +60,12 @@ static func from_event(event: Dictionary, tick: int, players: Dictionary = {}) -
|
||||
"position": players.get(player, Vector3.ZERO),
|
||||
"prop": int(event.get("prop", -1)), "piece": int(event.get("piece", 0)),
|
||||
}
|
||||
"piece_placed":
|
||||
return {
|
||||
"kind": PLACE, "tick": tick, "player": int(event["player"]), "item": -1,
|
||||
"position": pieces.get(int(event["piece"]), players.get(int(event["player"]), Vector3.ZERO)),
|
||||
"piece": int(event["piece"]),
|
||||
}
|
||||
return {}
|
||||
|
||||
|
||||
@@ -109,6 +120,8 @@ static func _encode_one(record: Dictionary, back: int) -> PackedByteArray:
|
||||
HARVEST:
|
||||
NetSnapshot._put_varint(out, maxi(int(record["prop"]), -1) + 1)
|
||||
NetSnapshot._put_varint(out, maxi(int(record["piece"]), 0))
|
||||
PLACE:
|
||||
NetSnapshot._put_varint(out, maxi(int(record["piece"]), 0))
|
||||
return out.data_array
|
||||
|
||||
|
||||
@@ -127,7 +140,7 @@ static func decode(bytes: PackedByteArray) -> Dictionary:
|
||||
var kind: int = bytes[cursor[0]]
|
||||
var back: int = bytes[cursor[0] + 1]
|
||||
cursor[0] += 2
|
||||
if kind < SHOT or kind > HARVEST:
|
||||
if kind < SHOT or kind > PLACE:
|
||||
return {}
|
||||
var player: int = NetSnapshot._read_varint(bytes, cursor)
|
||||
if player < 0 or cursor[0] + 7 > bytes.size():
|
||||
@@ -161,6 +174,11 @@ static func decode(bytes: PackedByteArray) -> Dictionary:
|
||||
return {}
|
||||
record["prop"] = prop - 1
|
||||
record["piece"] = piece
|
||||
PLACE:
|
||||
var placed: int = NetSnapshot._read_varint(bytes, cursor)
|
||||
if placed < 0:
|
||||
return {}
|
||||
record["piece"] = placed
|
||||
events.append(record)
|
||||
if cursor[0] != bytes.size():
|
||||
return {}
|
||||
|
||||
@@ -16,7 +16,7 @@ class_name NetProtocol
|
||||
extends RefCounted
|
||||
|
||||
## Raised whenever the wire format changes in a way old clients can't read.
|
||||
const VERSION: int = 3
|
||||
const VERSION: int = 4
|
||||
const MAGIC: String = "TDWL"
|
||||
const CHANNEL_CONTROL: int = 0
|
||||
## Unreliable game traffic: commands up, snapshots down.
|
||||
|
||||
Reference in New Issue
Block a user