summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop')
-rw-r--r--src/LivingVillage.Desktop/Game.fs89
-rw-r--r--src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj1
-rw-r--r--src/LivingVillage.Desktop/MenuAmbience.fs117
3 files changed, 199 insertions, 8 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs
index 3e39b09..578be72 100644
--- a/src/LivingVillage.Desktop/Game.fs
+++ b/src/LivingVillage.Desktop/Game.fs
@@ -321,6 +321,16 @@ type LivingVillageGame() as this =
let mutable p45Step = 0
let mutable p45PendingName = ""
let mutable p45Pending = false
+ // P46 证据钩子:LV_P46_SHOT=1 时拍 splash 涟漪中帧 + 云影两帧 + 菜单灯笼呼吸两相位,
+ // 全程走正常启动/菜单流程,仅按帧表落盘。
+ let p46ShotMode = Environment.GetEnvironmentVariable("LV_P46_SHOT") = "1"
+ let mutable p46PendingName = ""
+ let mutable p46Pending = false
+ let mutable p46SplashRippleDone = false
+ let mutable p46CloudEarlyDone = false
+ let mutable p46CloudLateDone = false
+ let mutable p46MenuADone = false
+ let mutable p46MenuBDone = false
let mutable autoplayFrames = 0
let mutable flowStep = 0
let mutable flowHold = 0
@@ -954,6 +964,45 @@ type LivingVillageGame() as this =
(sprintf "%A" spec.Frame)
p45Step <- p45Step + 1
+ /// P46 证据:Draw 末尾落盘。splash 阶段按帧阈值拍涟漪/云影,菜单阶段拍灯笼两相位。
+ member private this.CaptureP46Shot () =
+ let save (name: string) =
+ System.IO.Directory.CreateDirectory recordDirectory |> ignore
+ this.SaveBackBuffer(sprintf "%s/%s.png" recordDirectory name)
+ printfn "p46-shot=%s splashFrame=%d menuEntranceFrame=%d" name splashFrame menuEntranceFrame
+ if splashActive then
+ if not p46SplashRippleDone && splashFrame >= P46ShotScript.splashRippleFrame then
+ p46SplashRippleDone <- true
+ save P46ShotScript.splashRippleName
+ elif not p46CloudEarlyDone && splashFrame >= P46ShotScript.cloudEarlyFrame then
+ p46CloudEarlyDone <- true
+ save P46ShotScript.cloudEarlyName
+ elif not p46CloudLateDone && splashFrame >= P46ShotScript.cloudLateFrame then
+ p46CloudLateDone <- true
+ save P46ShotScript.cloudLateName
+ elif p46Pending then
+ p46Pending <- false
+ if p46PendingName = P46ShotScript.menuPeakName then p46MenuADone <- true
+ else p46MenuBDone <- true
+ save p46PendingName
+
+ /// P46 证据:菜单阶段按帧表把 menuEntranceFrame 钉到灯笼呼吸的波峰/波谷,拍两相位。
+ member private this.PrepareP46Shot () =
+ if p46MenuADone && p46MenuBDone then
+ printfn "p46-shot=done"
+ this.Exit()
+ elif not p46MenuADone then
+ // 每帧钉住目标帧,抵消 Update 末尾的自增,保证 Draw 看到精确相位。
+ menuEntranceFrame <- P46ShotScript.menuPeakFrame
+ if not p46Pending then
+ p46PendingName <- P46ShotScript.menuPeakName
+ p46Pending <- true
+ elif not p46MenuBDone then
+ menuEntranceFrame <- P46ShotScript.menuTroughFrame
+ if not p46Pending then
+ p46PendingName <- P46ShotScript.menuTroughName
+ p46Pending <- true
+
/// P20 第三步取证:真走位巡游(Sim.step 驱动)沿桥/路/民居门移动,用于桥面行走帧与昼夜录制。
member private this.RunRiverscapeTour () =
if not riverscapeTourWatchStarted then
@@ -1268,6 +1317,17 @@ type LivingVillageGame() as this =
let pressedAny (keys: Keys list) = keys |> List.exists pressed
if splashActive then
splashFrame <- splashFrame + 1L
+ if p46ShotMode && splashFrame >= 10L then
+ // P46 取证:等画面绘制稳定后,把 splashFrame 钉到下一个未取证的目标帧,
+ // 令 Draw 看到精确帧号(前若干帧 backbuffer 未铺满,故需 warm-up 门槛)。
+ let target =
+ if not p46SplashRippleDone then Some P46ShotScript.splashRippleFrame
+ elif not p46CloudEarlyDone then Some P46ShotScript.cloudEarlyFrame
+ elif not p46CloudLateDone then Some P46ShotScript.cloudLateFrame
+ else None
+ match target with
+ | Some t -> splashFrame <- t
+ | None -> ()
let skip = LaunchScreen.skipRequested (pressed Keys.Escape) (pressed Keys.Space)
if skip || LaunchScreen.isComplete splashFrame then
splashActive <- false
@@ -1322,6 +1382,9 @@ type LivingVillageGame() as this =
else this.DispatchMenuInput Confirm
elif menu.Page = Playing then
this.PrepareP45Shot()
+ elif p46ShotMode then
+ if menu.Page = MainMenu then
+ this.PrepareP46Shot()
elif menu.Page = Playing then
this.UpdatePlaying gameTime kb pressed pressedAny
elif menuShotMode then
@@ -1731,6 +1794,8 @@ type LivingVillageGame() as this =
this.CaptureP44Shot()
if p45ShotMode && menu.Page = Playing then
this.CaptureP45Shot()
+ if p46ShotMode then
+ this.CaptureP46Shot()
/// 启动画面:分层天色 + 屋脊/水面剪影 + 标题淡入上浮 + 跳过提示,全部为帧计数纯函数。
member private this.DrawSplash() =
@@ -1751,6 +1816,14 @@ type LivingVillageGame() as this =
let y1 = if index = bandCount - 1 then height else y0 + bandHeight
spriteBatch.Draw(pixel, Rectangle(0, y0, width, y1 - y0), Color(band.R, band.G, band.B))) layout.SkyBands
+ // ③ 屋脊上方的双层视差云影:纯水平位移(随帧缓慢漂移),低 alpha 预乘柔光,
+ // 只用椭圆行落成,绝不留大黑块/实心色块。
+ for layer in 0 .. MenuAmbience.cloudLayerCount - 1 do
+ let cloudColor = VillageArt.premultiply 214 228 236 (MenuAmbience.cloudLayerAlpha layer)
+ for (cx, cy, rx, ry) in MenuAmbience.cloudPuffs layer splashFrame width do
+ for (runX, runY, runW) in VillageArt.ellipseRuns cx cy rx ry do
+ spriteBatch.Draw(pixel, Rectangle(runX, runY, runW, 1), cloudColor)
+
// 屋脊剪影随暗幕退场而上浮就位。
let drop = int (28.0f * veil)
for x in 0 .. Sim.tilePixels .. width - 1 do
@@ -1765,22 +1838,22 @@ type LivingVillageGame() as this =
spriteBatch.Draw(artTextures.TileAtlas, Rectangle(x, row, Sim.tilePixels, Sim.tilePixels), VillageArt.atlasTileRectangle TitleScreen.waterSlot, waterColor)
for x in 0 .. Sim.tilePixels .. width - 1 do
let column = x / Sim.tilePixels
- let brightness = TitleScreen.waterRippleBrightness splashFrame column rowIndex
+ let brightness = MenuAmbience.waterColumnBrightness splashFrame column rowIndex
let crestColor =
Color(
min 255 (int (150.0f * brightness)),
min 255 (int (170.0f * brightness)),
min 255 (int (178.0f * brightness)),
waterAlpha)
- let lift = TitleScreen.waterRippleLift splashFrame column rowIndex
+ let lift = MenuAmbience.waterColumnLift splashFrame column rowIndex
spriteBatch.Draw(artTextures.TileAtlas, Rectangle(x, row + lift, Sim.tilePixels, Sim.tilePixels), VillageArt.atlasTileRectangle TitleScreen.waterSlot, crestColor)
- if TitleScreen.waterRippleCrest splashFrame column rowIndex then
+ if MenuAmbience.waterColumnCrest splashFrame column rowIndex then
spriteBatch.Draw(pixel, Rectangle(x, row + lift, Sim.tilePixels, 3), Color(225, 240, 245, waterAlpha))
// P42 屋檐灯笼呼吸光晕:复用 P14 预乘 alpha 径向路径,随帧与灯序号呼吸。
let lanternColor, _ = TitleScreen.lanternColors
for (lanternIndex, (lx, ly)) in List.indexed layout.Lanterns do
- let breath = TitleScreen.lanternBreathAlpha splashFrame lanternIndex
+ let breath = MenuAmbience.lanternBreathAlpha splashFrame lanternIndex
for (rect, color) in VillageArt.lanternGlowLayers lx ly 28 6 252 216 148 breath do
spriteBatch.Draw(pixel, rect, color)
spriteBatch.Draw(pixel, Rectangle(lx - 3, ly - 5, 8, 10), Color(lanternColor.R, lanternColor.G, lanternColor.B))
@@ -1875,22 +1948,22 @@ type LivingVillageGame() as this =
spriteBatch.Draw(artTextures.TileAtlas, Rectangle(x, row, Sim.tilePixels, Sim.tilePixels), VillageArt.atlasTileRectangle TitleScreen.waterSlot, waterColor)
for x in 0 .. Sim.tilePixels .. width - 1 do
let column = x / Sim.tilePixels
- let brightness = TitleScreen.waterRippleBrightness menuEntranceFrame column rowIndex
+ let brightness = MenuAmbience.waterColumnBrightness menuEntranceFrame column rowIndex
let crestColor =
Color(
min 255 (int (150.0f * brightness)),
min 255 (int (170.0f * brightness)),
min 255 (int (178.0f * brightness)),
waterAlpha)
- let lift = TitleScreen.waterRippleLift menuEntranceFrame column rowIndex
+ let lift = MenuAmbience.waterColumnLift menuEntranceFrame column rowIndex
spriteBatch.Draw(artTextures.TileAtlas, Rectangle(x, row + lift, Sim.tilePixels, Sim.tilePixels), VillageArt.atlasTileRectangle TitleScreen.waterSlot, crestColor)
- if TitleScreen.waterRippleCrest menuEntranceFrame column rowIndex then
+ if MenuAmbience.waterColumnCrest menuEntranceFrame column rowIndex then
spriteBatch.Draw(pixel, Rectangle(x, row + lift, Sim.tilePixels, 3), Color(225, 240, 245, waterAlpha))
// P42 bank lanterns breathe through the shared P14 premultiplied-alpha radial path.
let lanternColor, _ = TitleScreen.lanternColors
for (lanternIndex, (lx, ly)) in List.indexed layout.Lanterns do
- let breath = TitleScreen.lanternBreathAlpha menuEntranceFrame lanternIndex
+ let breath = MenuAmbience.lanternBreathAlpha menuEntranceFrame lanternIndex
for (rect, color) in VillageArt.lanternGlowLayers lx ly 28 6 252 216 148 breath do
spriteBatch.Draw(pixel, rect, color)
spriteBatch.Draw(pixel, Rectangle(lx - 3, ly - 5, 8, 10), Color(lanternColor.R, lanternColor.G, lanternColor.B))
diff --git a/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj b/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj
index 51fb32e..22d0d15 100644
--- a/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj
+++ b/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj
@@ -21,6 +21,7 @@
<Compile Include="M6Presentation.fs" />
<Compile Include="HudLayout.fs" />
<Compile Include="DialogOverlay.fs" />
+ <Compile Include="MenuAmbience.fs" />
<Compile Include="PerformanceSummary.fs" />
<Compile Include="TitleScreen.fs" />
diff --git a/src/LivingVillage.Desktop/MenuAmbience.fs b/src/LivingVillage.Desktop/MenuAmbience.fs
new file mode 100644
index 0000000..74fefeb
--- /dev/null
+++ b/src/LivingVillage.Desktop/MenuAmbience.fs
@@ -0,0 +1,117 @@
+namespace LivingVillage.Desktop
+
+/// P46 菜单/启动环境动效(纯函数层):
+/// ① 水面逐格涟漪 —— 复用 VillageArt.waterFrameTickAt 的相位索引,再叠加 32 tick 内的
+/// 分数相位,使相邻水格相位错开、且 32 tick 边界之间也连续波动;
+/// ② 灯笼呼吸光晕 —— alpha 在 [40,96] 间随帧数正弦呼吸,供 VillageArt.lanternGlowLayers 复用;
+/// ③ 启动画面屋脊上方双层视差云影 —— 纯水平位移、有界、随帧缓慢漂移。
+/// 全部为帧计数纯函数:同参数逐字节可复现,无时钟/随机源。
+module MenuAmbience =
+
+ open System
+
+ // ---------------- ① 水面逐格涟漪 ----------------
+
+ /// 涟漪幅度,沿用 P42 的可见性预算(>=0.25 才能在 1280x720 下读得出来)。
+ let waterRippleAmplitude = 0.32f
+
+ let private twoPiOverThree = 2.0f * float32 Math.PI / 3.0f
+
+ /// 逐格涟漪相位(弧度)。基相位直接调用 VillageArt.waterFrameTickAt(tick/32 + tileX +
+ /// 2*tileY 对 3 取模),再加 tick%32/32 的分数相位:在 32 tick 的整数边界上退化为
+ /// waterFrameTickAt 的 3 帧相位,边界之间则连续推进,所以既有逐列差异又有逐帧运动。
+ let waterPhase (frame: int64) (column: int) (rowIndex: int) : float32 =
+ let index = VillageArt.waterFrameTickAt frame column rowIndex
+ let fraction = float32 (frame % 32L) / 32.0f
+ (float32 index + fraction) * twoPiOverThree
+
+ /// 该水格的正弦波值,范围 [-1, 1]。
+ let waterWave (frame: int64) (column: int) (rowIndex: int) : float32 =
+ sin (waterPhase frame column rowIndex)
+
+ /// 该水格亮度倍率:1.0 ± waterRippleAmplitude。
+ let waterColumnBrightness (frame: int64) (column: int) (rowIndex: int) : float32 =
+ 1.0f + waterRippleAmplitude * waterWave frame column rowIndex
+
+ /// 该水格亮面整体抬升像素(-2..2),用于高光行位移而不留空洞。
+ let waterColumnLift (frame: int64) (column: int) (rowIndex: int) : int =
+ int (Math.Round(float (waterWave frame column rowIndex * 2.0f), MidpointRounding.AwayFromZero))
+
+ /// 是否处于波峰(正弦 > 0.7),渲染器会给这一列加一条高光。
+ let waterColumnCrest (frame: int64) (column: int) (rowIndex: int) : bool =
+ waterWave frame column rowIndex > 0.7f
+
+ // ---------------- ② 灯笼呼吸光晕 ----------------
+
+ /// 灯笼呼吸 alpha,界于 [40, 96];相位随帧与灯序号推进,邻灯不同步。
+ let lanternBreathAlpha (frame: int64) (index: int) : int =
+ let phase = float32 (frame % 4096L) / 22.0f + float32 index * 1.3f
+ 68 + int (Math.Round(float (sin phase * 28.0f), MidpointRounding.AwayFromZero))
+
+ // ---------------- ③ 屋脊上方双层视差云影 ----------------
+
+ let cloudLayerCount = 2
+
+ /// 两层云影的速度(px/帧),内层更慢,形成视差。
+ let cloudLayerSpeed (layer: int) : float32 =
+ if layer % cloudLayerCount = 0 then 0.5f else 1.0f
+
+ /// 云影中心 y。两层都落在屋脊(TitleScreen.RidgeY = 44)上方。
+ let cloudLayerY (layer: int) : int =
+ if layer % cloudLayerCount = 0 then 16 else 32
+
+ /// 云影 alpha(预乘绘制,低 alpha 柔光,绝不形成实心块)。外层更快、更实,便于量测视差。
+ let cloudLayerAlpha (layer: int) : int =
+ if layer % cloudLayerCount = 0 then 12 else 30
+
+ let cloudLayerRadiusX (layer: int) : int =
+ if layer % cloudLayerCount = 0 then 52 else 74
+
+ let cloudLayerRadiusY (layer: int) : int =
+ if layer % cloudLayerCount = 0 then 9 else 11
+
+ let private cloudBases =
+ [| [| 150; 520; 900; 1180 |]
+ [| 300; 700; 1050 |] |]
+
+ /// 云影水平位移(px),按图层速度随帧单调推进并按 (width+200) 环绕,保持有界。
+ let cloudOffsetPx (layer: int) (frame: int64) (width: int) : int =
+ let speed = cloudLayerSpeed layer
+ let travelled =
+ int (Math.Round(float (float32 (frame % 100000L) * speed), MidpointRounding.AwayFromZero))
+ let span = max 1 (width + 200)
+ ((travelled % span) + span) % span
+
+ /// 该图层若干云团中心 (x, y),x 已含位移并环绕,y 恒定在屋脊上方。
+ let cloudPuffCenters (layer: int) (frame: int64) (width: int) : (int * int) list =
+ let offset = cloudOffsetPx layer frame width
+ let span = max 1 (width + 200)
+ let y = cloudLayerY layer
+ cloudBases.[layer % cloudLayerCount]
+ |> Array.toList
+ |> List.map (fun baseX -> (((baseX + offset) % span) - 100), y)
+
+ /// 该图层的云团椭圆 (cx, cy, rx, ry),供渲染层用 VillageArt.ellipseRuns 落成柔边。
+ let cloudPuffs (layer: int) (frame: int64) (width: int) : (int * int * int * int) list =
+ let rx = cloudLayerRadiusX layer
+ let ry = cloudLayerRadiusY layer
+ cloudPuffCenters layer frame width |> List.map (fun (cx, cy) -> cx, cy, rx, ry)
+
+/// P46 取证:环境动效证据帧表(60Hz 帧号纯数据,Game 与回归测试共用)。
+/// * splash 涟漪中帧:水面仍可见(reveal<1);
+/// * 云影两帧:都由视差位移纯函数决定,帧差即云影位移;
+/// * 菜单灯笼两相位:入场完成后(>=120)的呼吸波峰/波谷,两帧 luma 差即呼吸幅度。
+module P46ShotScript =
+
+ let splashRippleName = "p46-splash-ripple"
+ let cloudEarlyName = "p46-cloud-a"
+ let cloudLateName = "p46-cloud-b"
+ let menuPeakName = "p46-menu-lantern-a"
+ let menuTroughName = "p46-menu-lantern-b"
+
+ let splashRippleFrame = 16L
+ let cloudEarlyFrame = 100L
+ let cloudLateFrame = 140L
+ // menuEntranceFrame 在 Update 末尾 +1,故设置值取目标相位帧的前一帧。
+ let menuPeakFrame = 172L
+ let menuTroughFrame = 241L