summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/LivingVillage.Desktop.Tests/DesktopTests.fs15
-rw-r--r--src/LivingVillage.Desktop/Game.fs7
-rw-r--r--src/LivingVillage.Desktop/WorldBootstrap.fs10
3 files changed, 29 insertions, 3 deletions
diff --git a/src/LivingVillage.Desktop.Tests/DesktopTests.fs b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
index 20cbbe9..667ab69 100644
--- a/src/LivingVillage.Desktop.Tests/DesktopTests.fs
+++ b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
@@ -124,3 +124,18 @@ type DesktopTests () =
Assert.IsTrue(day.WorldTint.R > day.WorldTint.G)
Assert.IsTrue(day.WorldTint.G > day.WorldTint.B)
+
+ [<TestMethod>]
+ member _.DaylightAutoplayBootstrapStartsAtDawnAndPreservesDefaultStart () =
+ let dawnTick = 6L * Sim.ticksPerDay / 24L
+ let daylightWorld = WorldBootstrap.initialWorldForDaylight true 42UL Sim.npcCount
+ let defaultWorld = WorldBootstrap.initialWorldForDaylight false 42UL Sim.npcCount
+ let daylightProfile = M6Presentation.profileAtTick daylightWorld.Tick
+ let defaultProfile = M6Presentation.profileAtTick defaultWorld.Tick
+
+ Assert.AreEqual<int64>(dawnTick, daylightWorld.Tick)
+ Assert.IsTrue(abs (daylightWorld.Time - float dawnTick * Sim.dtSeconds) < 1e-9)
+ Assert.AreEqual<M6DayNight>(Day, daylightProfile.Mode)
+ Assert.AreEqual<int64>(0L, defaultWorld.Tick)
+ Assert.AreEqual<float>(0.0, defaultWorld.Time)
+ Assert.AreEqual<M6DayNight>(Night, defaultProfile.Mode)
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs
index 27e44a7..62102a7 100644
--- a/src/LivingVillage.Desktop/Game.fs
+++ b/src/LivingVillage.Desktop/Game.fs
@@ -97,6 +97,7 @@ type LivingVillageGame() as this =
let autoplay = Environment.GetEnvironmentVariable("LV_AUTOPLAY") = "1"
let autoplayFlow = Environment.GetEnvironmentVariable("LV_AUTOPLAY_FLOW") = "1"
let sampleMode = Environment.GetEnvironmentVariable("LV_AUTOPLAY_SAMPLE") = "1"
+ let daylightAutoplay = Environment.GetEnvironmentVariable("LV_AUTOPLAY_DAYLIGHT") = "1"
let automated = autoplay || autoplayFlow
let modeName =
if sampleMode then "sample"
@@ -124,7 +125,9 @@ type LivingVillageGame() as this =
let mutable cjkAtlas = Unchecked.defaultof<Texture2D>
let mutable pixel = Unchecked.defaultof<Texture2D>
let renderPlan = VillageArt.sampleRenderPlan ()
- let mutable world = WorldBootstrap.initialWorld 42UL Sim.npcCount
+ let createInitialWorld () =
+ WorldBootstrap.initialWorldForDaylight daylightAutoplay 42UL Sim.npcCount
+ let mutable world = createInitialWorld ()
let mutable camera = Vector2.Zero
let mutable avatarFacing = VillageArt.SouthFacing
let mutable fpsFrames = 0
@@ -168,7 +171,7 @@ type LivingVillageGame() as this =
this.CenterCamera()
member private this.StartNewGame() =
- world <- WorldBootstrap.initialWorld 42UL Sim.npcCount
+ world <- createInitialWorld ()
this.ResetWorldView()
menu <- menu |> MenuState.setCurrentWorld true |> MenuState.enterGame
printfn $"new-game=ok seed=42 npcs={Sim.npcCount}"
diff --git a/src/LivingVillage.Desktop/WorldBootstrap.fs b/src/LivingVillage.Desktop/WorldBootstrap.fs
index 612931b..d6b906d 100644
--- a/src/LivingVillage.Desktop/WorldBootstrap.fs
+++ b/src/LivingVillage.Desktop/WorldBootstrap.fs
@@ -16,10 +16,13 @@ module WorldBootstrap =
let private avatarSpawnPosition = tileCenter 31 25
- let initialWorld (seed: uint64) (count: int) : World =
+ let private daylightStartTick = 6L * Sim.ticksPerDay / 24L
+
+ let initialWorldForDaylight (startAtDaylight: bool) (seed: uint64) (count: int) : World =
if count < 0 || count > npcSpawnTiles.Length then
invalidArg (nameof count) "Desktop bootstrap supports at most 30 NPCs."
+ let startTick = if startAtDaylight then daylightStartTick else 0L
let baseWorld = Sim.initialWorldN seed count
let avatar =
{ baseWorld.Avatar with
@@ -32,5 +35,10 @@ module WorldBootstrap =
{ npc with Pos = tileCenter x y })
{ baseWorld with
+ Tick = startTick
+ Time = float startTick * Sim.dtSeconds
Avatar = avatar
Npcs = npcs }
+
+ let initialWorld (seed: uint64) (count: int) : World =
+ initialWorldForDaylight false seed count