N11: Build ghost, client flood and shot effects in the playable client
- Build ghost: ClientSession shows a BuildGhost in build mode while the client plays, asking Building.check() of its own world and predicted player with the mouse's newest look, so it agrees with the server. - Flooded basins: ClientMirror.follow_flood() spreads the client's flood as the server's tide tick does, from the tide and the pieces it has. WaterView passes a mask of flooded cells (Flood.pours says when it changed) to the sea shader, which leaves dry cells undrawn. - Shots, impacts and swings: a new FX message (NetFx) goes unreliably on the state channel next to each snapshot, with what happened within NET_FX_RADIUS_METRES of what the client watches or involving that player. ClientGame keeps them in `fx` for views and sound. They change no state, so a lost one is a missed flash; sending them reliably would add to the traffic a bad link can least afford (N8). The fuzzer covers the new parser. - Captures: client_build and client_build_refused show the ghost in its allowed and refused tints; client_basin rings shore ground with breakwaters and plays until the tide stands over it, and the server, the client's flood and the drawn sea all keep the basin dry. - Tests: NetFx round trips, limits and malformed input; a landed player's shots and impacts reach a client, each matching a server event; the client keeps a ringed basin dry through the first rise, floods it with no ring, catches up after a long frame; the water mask follows pours. The held item is still not drawn; that needs the models (A4, #44). Closes #78 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,12 @@ uniform float depth_scale = 7.0;
|
||||
// Width of the foam at the waterline, in metres of water thickness.
|
||||
uniform float foam_width = 0.6;
|
||||
uniform float ripple_strength = 0.25;
|
||||
// Where the flood reaches: one texel per flood cell, white where flooded, covering
|
||||
// [0, flood_extent] metres on both axes. Dry cells inside it aren't drawn; outside it
|
||||
// is open sea.
|
||||
uniform bool use_flood_mask = false;
|
||||
uniform sampler2D flood_mask : filter_nearest, repeat_disable;
|
||||
uniform float flood_extent = 1024.0;
|
||||
|
||||
varying vec3 world_position;
|
||||
|
||||
@@ -44,6 +50,12 @@ void vertex() {
|
||||
void fragment() {
|
||||
vec2 p = world_position.xz;
|
||||
float t = TIME;
|
||||
if (use_flood_mask) {
|
||||
vec2 cell_uv = p / flood_extent;
|
||||
if (all(greaterThanEqual(cell_uv, vec2(0.0))) && all(lessThan(cell_uv, vec2(1.0))) && texture(flood_mask, cell_uv).r < 0.5) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
// Thickness of water between this surface and whatever is behind it.
|
||||
float scene_depth = texture(depth_texture, SCREEN_UV).r;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
## Draws the sea: one flat surface at the simulation's sea level, wide enough to reach
|
||||
## past the horizon from anywhere on the island. `follow(sim)` moves it whenever the
|
||||
## tide changes the level, so what players see is always the level the server uses.
|
||||
## Where the simulation has a flood, the sea is only drawn over the cells it reaches:
|
||||
## a mask texture of the flooded cells goes to the shader, which leaves dry cells
|
||||
## (a basin behind a breakwater) bare. The mask is rebuilt only when the flood pours.
|
||||
## The surface is the only thing here; drowning and swimming live in the simulation.
|
||||
class_name WaterView
|
||||
extends Node3D
|
||||
@@ -14,6 +17,10 @@ const SUBDIVISIONS: int = 32
|
||||
var level: float = 0.0
|
||||
|
||||
var _surface: MeshInstance3D
|
||||
var _material: ShaderMaterial
|
||||
var _mask: ImageTexture = null
|
||||
var _mask_flood: Flood = null
|
||||
var _mask_pours: int = -1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -29,10 +36,49 @@ func set_level(sea_level: float) -> void:
|
||||
_surface.position.y = sea_level
|
||||
|
||||
|
||||
## Matches the surface to the simulation's current sea level.
|
||||
## Matches the surface to the simulation's current sea level and flood.
|
||||
func follow(sim: Simulation) -> void:
|
||||
if not is_equal_approx(sim.sea_level, level) or _surface == null:
|
||||
set_level(sim.sea_level)
|
||||
set_flood(sim.flood)
|
||||
|
||||
|
||||
## Draws the sea only over `flood`'s flooded cells, or everywhere for null. Cheap
|
||||
## when nothing has poured since the last call.
|
||||
func set_flood(flood: Flood) -> void:
|
||||
if _surface == null:
|
||||
_build()
|
||||
if flood == null:
|
||||
_mask_flood = null
|
||||
_mask_pours = -1
|
||||
_material.set_shader_parameter("use_flood_mask", false)
|
||||
return
|
||||
if flood == _mask_flood and flood.pours == _mask_pours:
|
||||
return
|
||||
_mask_flood = flood
|
||||
_mask_pours = flood.pours
|
||||
var bytes: PackedByteArray = flood.flooded.duplicate()
|
||||
for index: int in bytes.size():
|
||||
if bytes[index] != 0:
|
||||
bytes[index] = 255
|
||||
var image: Image = Image.create_from_data(flood.side, flood.side, false, Image.FORMAT_R8, bytes)
|
||||
if _mask == null or _mask.get_width() != flood.side:
|
||||
_mask = ImageTexture.create_from_image(image)
|
||||
else:
|
||||
_mask.update(image)
|
||||
_material.set_shader_parameter("flood_mask", _mask)
|
||||
_material.set_shader_parameter("flood_extent", flood.side * flood.cell)
|
||||
_material.set_shader_parameter("use_flood_mask", true)
|
||||
|
||||
|
||||
## True if the sea is drawn over the world point (x, z): flooded, or off the grid.
|
||||
func shows_water_at(x: float, z: float) -> bool:
|
||||
if _mask_flood == null:
|
||||
return true
|
||||
var extent: float = _mask_flood.side * _mask_flood.cell
|
||||
if x < 0.0 or z < 0.0 or x >= extent or z >= extent:
|
||||
return true
|
||||
return _mask_flood.is_flooded(x, z)
|
||||
|
||||
|
||||
func surface() -> MeshInstance3D:
|
||||
@@ -46,9 +92,9 @@ func _build() -> void:
|
||||
mesh.size = Vector2(SIZE, SIZE)
|
||||
mesh.subdivide_width = SUBDIVISIONS
|
||||
mesh.subdivide_depth = SUBDIVISIONS
|
||||
var material: ShaderMaterial = ShaderMaterial.new()
|
||||
material.shader = SHADER
|
||||
mesh.material = material
|
||||
_material = ShaderMaterial.new()
|
||||
_material.shader = SHADER
|
||||
mesh.material = _material
|
||||
_surface = MeshInstance3D.new()
|
||||
_surface.name = "Sea"
|
||||
_surface.mesh = mesh
|
||||
|
||||
Reference in New Issue
Block a user