M8: Complete offline match
`make match` plays one whole match from the lobby to the results and back to the lobby: one scripted player and 23 bots on a local server, with no script errors. - CommandLog records the seed, the rules and every command the server is given. MatchReplay plays a log again with nobody thinking and ends on the same state hash; `make match` saves the log, reads it back and checks that. - ServerLoop.submit() is now the one way commands reach the simulation, so a recording server sees them all. - ScriptedPlayer plays a human seat: it drops, loots, fights and flees as a bot does, and also cuts driftwood and builds a breakwater and a wall. - Bots draw randomness from their own per-bot generators, not the simulation's streams. A bot thinking no longer changes the simulation's state, which a replay without bots needs. - MatchView and EntityView draw a match from one Simulation: terrain, sea, points of interest, props, pieces, players, the barge, items and chests, with stand-in shapes for the art pass to replace. - `make match-captures` renders eight stages of the recorded match. Closes #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
## Draws what moves in a match: players, the sky barge while it crosses, items lying
|
||||
## in the world and sea chests. `sync()` matches everything to the simulation as it is
|
||||
## now. These are stand-in shapes built in code, in the weathered seafaring palette of
|
||||
## docs/ORIGINALITY.md: an oilskin coat, a sou'wester and a canvas wing-sail. The art
|
||||
## pass replaces them. Nothing here is ever used for collision.
|
||||
class_name EntityView
|
||||
extends Node3D
|
||||
|
||||
## Oilskin colours. A player's is picked by entity ID; the local player wears the first.
|
||||
const OILSKINS: Array[Color] = [
|
||||
Color(0.86, 0.66, 0.16), Color(0.56, 0.27, 0.20), Color(0.33, 0.55, 0.56), Color(0.36, 0.40, 0.30),
|
||||
Color(0.48, 0.46, 0.44), Color(0.30, 0.36, 0.48), Color(0.62, 0.44, 0.28),
|
||||
]
|
||||
const SKIN: Color = Color(0.74, 0.58, 0.46)
|
||||
const CANVAS: Color = Color(0.84, 0.80, 0.68)
|
||||
const TAR: Color = Color(0.19, 0.16, 0.13)
|
||||
const PLANK: Color = Color(0.50, 0.45, 0.37)
|
||||
const CHEST_SHUT: Color = Color(0.33, 0.55, 0.56)
|
||||
const CHEST_OPEN: Color = Color(0.22, 0.20, 0.18)
|
||||
const ITEM: Color = Color(0.93, 0.80, 0.42)
|
||||
## How far apart passengers stand on the barge's deck, in metres. The simulation
|
||||
## carries them all at one point; this only spreads them out to be seen.
|
||||
const DECK_SPACING: float = 1.3
|
||||
const DECK_ROWS: int = 4
|
||||
|
||||
## The entity drawn in the brightest oilskin, or 0.
|
||||
var local_id: int = 0
|
||||
|
||||
var _sim: Simulation
|
||||
## Entity ID -> the figure's root node.
|
||||
var _figures: Dictionary = {}
|
||||
var _barge: Node3D
|
||||
var _pickups: MultiMeshInstance3D
|
||||
var _chests: MultiMeshInstance3D
|
||||
|
||||
|
||||
func setup(sim: Simulation) -> void:
|
||||
_sim = sim
|
||||
_barge = _build_barge()
|
||||
_barge.visible = false
|
||||
add_child(_barge)
|
||||
_pickups = _box_field("Pickups", Vector3(0.34, 0.34, 0.34), true)
|
||||
add_child(_pickups)
|
||||
_chests = _box_field("Chests", Vector3(0.9, 0.55, 0.6), false)
|
||||
add_child(_chests)
|
||||
sync()
|
||||
|
||||
|
||||
func figure_count() -> int:
|
||||
return _figures.size()
|
||||
|
||||
|
||||
## The figure drawn for a player, or null.
|
||||
func figure_of(entity_id: int) -> Node3D:
|
||||
return _figures.get(entity_id)
|
||||
|
||||
|
||||
func barge() -> Node3D:
|
||||
return _barge
|
||||
|
||||
|
||||
func sync() -> void:
|
||||
if _sim == null:
|
||||
return
|
||||
var drop: Drop = _sim.drop
|
||||
var crossing: bool = drop != null and not drop.finished
|
||||
var heading: float = 0.0
|
||||
if drop != null:
|
||||
var along: Vector3 = drop.finish - drop.start
|
||||
heading = atan2(along.x, along.z)
|
||||
_barge.visible = crossing
|
||||
if crossing:
|
||||
_barge.position = drop.barge_position(_sim.tick)
|
||||
_barge.rotation.y = heading
|
||||
|
||||
var seen: Dictionary = {}
|
||||
var aboard: int = 0
|
||||
for entity: SimEntity in _sim.entities.entities():
|
||||
if entity.archetype != SimEntity.ARCHETYPE_PLAYER:
|
||||
continue
|
||||
seen[entity.id] = true
|
||||
var figure: Node3D = _figures.get(entity.id)
|
||||
if figure == null:
|
||||
figure = _build_figure(entity.id)
|
||||
_figures[entity.id] = figure
|
||||
add_child(figure)
|
||||
figure.visible = not entity.eliminated
|
||||
figure.position = entity.position
|
||||
figure.rotation.y = float(entity.yaw) / PlayerCommand.YAW_STEPS * TAU
|
||||
if entity.drop_state == Drop.ABOARD:
|
||||
var column: int = aboard / DECK_ROWS
|
||||
var row: int = aboard % DECK_ROWS
|
||||
var offset: Vector3 = Vector3((row - (DECK_ROWS - 1) * 0.5) * DECK_SPACING, 0.0, (2.5 - column) * DECK_SPACING)
|
||||
figure.position += offset.rotated(Vector3.UP, heading)
|
||||
figure.rotation.y = heading
|
||||
aboard += 1
|
||||
figure.scale.y = Tuning.CROUCH_HEIGHT / Tuning.PLAYER_HEIGHT if entity.crouching else 1.0
|
||||
(figure.get_node("Sail") as Node3D).visible = entity.drop_state == Drop.GLIDING
|
||||
for entity_id: int in _figures.keys():
|
||||
if not seen.has(entity_id):
|
||||
_figures[entity_id].queue_free()
|
||||
_figures.erase(entity_id)
|
||||
|
||||
var items: MultiMesh = _pickups.multimesh
|
||||
items.instance_count = _sim.pickups.size()
|
||||
for index: int in _sim.pickups.size():
|
||||
var pickup: SimEntity = _sim.entities.find(_sim.pickups[index])
|
||||
var at: Vector3 = pickup.position + Vector3(0.0, 0.3, 0.0) if pickup != null else Vector3(0.0, -1000.0, 0.0)
|
||||
items.set_instance_transform(index, Transform3D(Basis(Vector3.UP, 0.6 * index), at))
|
||||
items.set_instance_color(index, ITEM)
|
||||
var chests: MultiMesh = _chests.multimesh
|
||||
chests.instance_count = _sim.loot.chest_positions.size()
|
||||
for index: int in _sim.loot.chest_positions.size():
|
||||
chests.set_instance_transform(index, Transform3D(Basis.IDENTITY, _sim.loot.chest_positions[index] + Vector3(0.0, 0.28, 0.0)))
|
||||
chests.set_instance_color(index, CHEST_OPEN if _sim.loot.chest_opened[index] != 0 else CHEST_SHUT)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
sync()
|
||||
|
||||
|
||||
func _build_figure(entity_id: int) -> Node3D:
|
||||
var coat: Color = OILSKINS[0] if entity_id == local_id else OILSKINS[1 + entity_id % (OILSKINS.size() - 1)]
|
||||
var figure: Node3D = Node3D.new()
|
||||
figure.name = "player_%d" % entity_id
|
||||
var legs: BoxMesh = BoxMesh.new()
|
||||
legs.size = Vector3(0.42, 0.8, 0.26)
|
||||
figure.add_child(_part(legs, TAR, Vector3(0.0, 0.4, 0.0)))
|
||||
var body: CapsuleMesh = CapsuleMesh.new()
|
||||
body.radius = 0.3
|
||||
body.height = 0.95
|
||||
figure.add_child(_part(body, coat, Vector3(0.0, 1.05, 0.0)))
|
||||
var head: SphereMesh = SphereMesh.new()
|
||||
head.radius = 0.16
|
||||
head.height = 0.32
|
||||
figure.add_child(_part(head, SKIN, Vector3(0.0, 1.6, 0.0)))
|
||||
var brim: CylinderMesh = CylinderMesh.new()
|
||||
brim.top_radius = 0.17
|
||||
brim.bottom_radius = 0.33
|
||||
brim.height = 0.16
|
||||
# The sou'wester's brim runs long at the back.
|
||||
figure.add_child(_part(brim, coat.darkened(0.25), Vector3(0.0, 1.76, -0.05)))
|
||||
var sail_mesh: BoxMesh = BoxMesh.new()
|
||||
sail_mesh.size = Vector3(2.6, 0.04, 0.9)
|
||||
var sail: MeshInstance3D = _part(sail_mesh, CANVAS, Vector3(0.0, 2.15, -0.1))
|
||||
sail.name = "Sail"
|
||||
sail.rotation.x = deg_to_rad(-8.0)
|
||||
sail.visible = false
|
||||
figure.add_child(sail)
|
||||
return figure
|
||||
|
||||
|
||||
## A flat-bottomed hull hung under a canvas envelope. Its deck is at the origin, where
|
||||
## the simulation carries the passengers.
|
||||
func _build_barge() -> Node3D:
|
||||
var barge: Node3D = Node3D.new()
|
||||
barge.name = "Barge"
|
||||
var deck: BoxMesh = BoxMesh.new()
|
||||
deck.size = Vector3(7.5, 0.3, 11.0)
|
||||
barge.add_child(_part(deck, PLANK, Vector3(0.0, -0.15, 0.0)))
|
||||
var hull: BoxMesh = BoxMesh.new()
|
||||
hull.size = Vector3(6.4, 1.3, 9.6)
|
||||
barge.add_child(_part(hull, TAR, Vector3(0.0, -0.95, 0.0)))
|
||||
for side: float in [-1.0, 1.0]:
|
||||
var rail: BoxMesh = BoxMesh.new()
|
||||
rail.size = Vector3(0.15, 0.7, 11.0)
|
||||
barge.add_child(_part(rail, TAR, Vector3(side * 3.68, 0.35, 0.0)))
|
||||
for end: float in [-1.0, 1.0]:
|
||||
var rope: CylinderMesh = CylinderMesh.new()
|
||||
rope.top_radius = 0.05
|
||||
rope.bottom_radius = 0.05
|
||||
rope.height = 7.0
|
||||
barge.add_child(_part(rope, PLANK.darkened(0.3), Vector3(side * 3.4, 3.5, end * 4.6)))
|
||||
var envelope: SphereMesh = SphereMesh.new()
|
||||
envelope.radius = 1.0
|
||||
envelope.height = 2.0
|
||||
var bag: MeshInstance3D = _part(envelope, CANVAS, Vector3(0.0, 10.5, 0.0))
|
||||
bag.scale = Vector3(5.2, 3.8, 9.0)
|
||||
barge.add_child(bag)
|
||||
return barge
|
||||
|
||||
|
||||
func _part(mesh: PrimitiveMesh, colour: Color, at: Vector3) -> MeshInstance3D:
|
||||
var material: StandardMaterial3D = StandardMaterial3D.new()
|
||||
material.albedo_color = colour
|
||||
material.roughness = 0.85
|
||||
mesh.material = material
|
||||
var instance: MeshInstance3D = MeshInstance3D.new()
|
||||
instance.mesh = mesh
|
||||
instance.position = at
|
||||
return instance
|
||||
|
||||
|
||||
func _box_field(node_name: String, size: Vector3, glow: bool) -> MultiMeshInstance3D:
|
||||
var material: StandardMaterial3D = StandardMaterial3D.new()
|
||||
material.vertex_color_use_as_albedo = true
|
||||
material.roughness = 0.7
|
||||
if glow:
|
||||
material.emission_enabled = true
|
||||
material.emission = ITEM
|
||||
material.emission_energy_multiplier = 0.5
|
||||
var mesh: BoxMesh = BoxMesh.new()
|
||||
mesh.size = size
|
||||
mesh.material = material
|
||||
var multimesh: MultiMesh = MultiMesh.new()
|
||||
multimesh.transform_format = MultiMesh.TRANSFORM_3D
|
||||
multimesh.use_colors = true
|
||||
multimesh.mesh = mesh
|
||||
var instance: MultiMeshInstance3D = MultiMeshInstance3D.new()
|
||||
instance.name = node_name
|
||||
instance.multimesh = multimesh
|
||||
instance.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
return instance
|
||||
@@ -0,0 +1 @@
|
||||
uid://cx6ttunmd4ng4
|
||||
@@ -0,0 +1,148 @@
|
||||
## The client's picture of one match: sky, sun, terrain, sea, points of interest, props,
|
||||
## built pieces and everything that moves, all drawn from one Simulation, with the
|
||||
## third-person camera on a player's shoulder. It only reads the simulation.
|
||||
##
|
||||
## A match gets a new Simulation, so it gets a new MatchView. Until snapshots arrive
|
||||
## (v0.5) the simulation it reads is the local server's or a replay's.
|
||||
class_name MatchView
|
||||
extends Node3D
|
||||
|
||||
var sim: Simulation
|
||||
var terrain: TerrainView
|
||||
var water: WaterView
|
||||
var pois: PoiView
|
||||
var props: PropView
|
||||
var structures: StructureView
|
||||
var entities: EntityView
|
||||
var camera: Camera3D
|
||||
var rig: CameraRig = CameraRig.new()
|
||||
|
||||
|
||||
## Builds the scene for `simulation`. `local_id` is the player this client plays, or 0.
|
||||
func setup(simulation: Simulation, local_id: int = 0) -> void:
|
||||
sim = simulation
|
||||
var sky_material: ProceduralSkyMaterial = ProceduralSkyMaterial.new()
|
||||
sky_material.sky_top_color = Color(0.32, 0.5, 0.68)
|
||||
sky_material.sky_horizon_color = Color(0.82, 0.78, 0.68)
|
||||
sky_material.ground_bottom_color = Color(0.18, 0.2, 0.2)
|
||||
sky_material.ground_horizon_color = Color(0.82, 0.78, 0.68)
|
||||
var sky: Sky = Sky.new()
|
||||
sky.sky_material = sky_material
|
||||
var environment: Environment = Environment.new()
|
||||
environment.background_mode = Environment.BG_SKY
|
||||
environment.sky = sky
|
||||
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
|
||||
environment.ambient_light_energy = 0.45
|
||||
environment.tonemap_mode = Environment.TONE_MAPPER_FILMIC
|
||||
environment.fog_enabled = true
|
||||
environment.fog_light_color = Color(0.78, 0.78, 0.74)
|
||||
environment.fog_density = 0.0005
|
||||
environment.fog_aerial_perspective = 0.4
|
||||
var world: WorldEnvironment = WorldEnvironment.new()
|
||||
world.environment = environment
|
||||
add_child(world)
|
||||
var sun: DirectionalLight3D = DirectionalLight3D.new()
|
||||
sun.rotation_degrees = Vector3(-35.0, -130.0, 0.0)
|
||||
sun.light_energy = 0.95
|
||||
sun.shadow_enabled = true
|
||||
sun.directional_shadow_max_distance = 400.0
|
||||
add_child(sun)
|
||||
|
||||
camera = Camera3D.new()
|
||||
camera.near = CameraRig.NEAR
|
||||
camera.far = 2500.0
|
||||
camera.fov = CameraRig.FOV
|
||||
add_child(camera)
|
||||
camera.make_current()
|
||||
|
||||
if sim.island != null:
|
||||
terrain = TerrainView.new()
|
||||
terrain.setup(sim.island)
|
||||
add_child(terrain)
|
||||
water = WaterView.new()
|
||||
add_child(water)
|
||||
pois = PoiView.new()
|
||||
pois.setup(sim.pois)
|
||||
add_child(pois)
|
||||
props = PropView.new()
|
||||
props.setup(sim.props)
|
||||
add_child(props)
|
||||
structures = StructureView.new()
|
||||
structures.setup(sim.structures)
|
||||
add_child(structures)
|
||||
entities = EntityView.new()
|
||||
entities.local_id = local_id
|
||||
entities.setup(sim)
|
||||
add_child(entities)
|
||||
sync()
|
||||
|
||||
|
||||
## Matches everything drawn to the simulation as it is now.
|
||||
func sync() -> void:
|
||||
water.follow(sim)
|
||||
props.sync()
|
||||
structures.sync()
|
||||
entities.sync()
|
||||
|
||||
|
||||
## Puts the camera on a player's shoulder, looking where they look. `pitch` replaces
|
||||
## their own pitch when given, in radians, for views such as looking down from a glide.
|
||||
func follow(entity_id: int, pitch: float = NAN) -> bool:
|
||||
var player: SimEntity = sim.entities.find(entity_id)
|
||||
if player == null:
|
||||
return false
|
||||
var yaw: float = float(player.yaw) / PlayerCommand.YAW_STEPS * TAU
|
||||
var look_pitch: float = pitch if not is_nan(pitch) else float(player.pitch) / PlayerCommand.PITCH_MAX * (PI * 0.5)
|
||||
camera.transform = rig.solve(player.position, yaw, look_pitch, player.crouching, sim.ground)
|
||||
camera.fov = rig.fov()
|
||||
_focus()
|
||||
return true
|
||||
|
||||
|
||||
## Frames a player from outside: the camera stands `distance` metres off at `height`
|
||||
## above their feet and looks at them, from the first of eight directions that has a
|
||||
## clear line and no prop around the lens. With `beyond` given, it starts on the far
|
||||
## side of the player from that point, so the point is in the picture behind them.
|
||||
func frame(entity_id: int, distance: float = 6.0, height: float = 2.6, beyond: Vector3 = Vector3.INF) -> bool:
|
||||
var player: SimEntity = sim.entities.find(entity_id)
|
||||
if player == null:
|
||||
return false
|
||||
var chest: Vector3 = player.position + Vector3(0.0, 1.2, 0.0)
|
||||
var first: float = float(player.yaw) / PlayerCommand.YAW_STEPS * TAU + PI
|
||||
if beyond != Vector3.INF:
|
||||
first = atan2(player.position.x - beyond.x, player.position.z - beyond.z)
|
||||
var eye: Vector3 = chest
|
||||
for turn: int in 8:
|
||||
# Straight on first, then alternately to each side.
|
||||
var angle: float = first + (turn + 1) / 2 * (PI / 4.0) * (1.0 if turn % 2 == 1 else -1.0)
|
||||
eye = player.position + Vector3(sin(angle) * distance, height, cos(angle) * distance)
|
||||
eye.y = maxf(eye.y, sim.ground.terrain_height(eye.x, eye.z) + 1.0)
|
||||
var feet: Vector3 = Vector3(eye.x, sim.ground.terrain_height(eye.x, eye.z), eye.z)
|
||||
if sim.ground.raycast(chest, eye) >= 1.0 and sim.props.near(feet, 5.0).is_empty():
|
||||
break
|
||||
look_from(eye, chest if beyond == Vector3.INF else chest.lerp(beyond, 0.35))
|
||||
return true
|
||||
|
||||
|
||||
## Puts the camera at `eye`, looking at `target`.
|
||||
func look_from(eye: Vector3, target: Vector3) -> void:
|
||||
camera.transform = Transform3D(Basis.IDENTITY, eye).looking_at(target, Vector3.UP)
|
||||
camera.fov = CameraRig.FOV
|
||||
_focus()
|
||||
|
||||
|
||||
## The whole island from high over its south-west, as the lobby shows it.
|
||||
func overview() -> void:
|
||||
var size: float = Tuning.WORLD_SIZE_METRES
|
||||
look_from(Vector3(size * 0.2, 300.0, size * 0.92), Vector3(size * 0.5, 0.0, size * 0.47))
|
||||
|
||||
|
||||
## Builds every terrain chunk for the current camera at once. For loading and captures.
|
||||
func settle() -> void:
|
||||
if terrain != null:
|
||||
terrain.build_all_now()
|
||||
|
||||
|
||||
func _focus() -> void:
|
||||
if terrain != null:
|
||||
terrain.focus = camera.position
|
||||
@@ -0,0 +1 @@
|
||||
uid://ctcbsm7hld1dc
|
||||
Reference in New Issue
Block a user