Skip to content

Commit 1a31e01

Browse files
committed
chore: run fantomas
1 parent 25d51fe commit 1a31e01

30 files changed

Lines changed: 1659 additions & 716 deletions

samples/PlatformerSample/Constants.fs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,55 @@ module PlatformerSample.Constants
22

33
open System.Numerics
44

5+
[<Literal>]
56
let tileSize = 64.0f
7+
8+
[<Literal>]
69
let chunkCells = 32
7-
let chunkWorldSize = float32 chunkCells * tileSize // 2048
10+
11+
let chunkWorldSize = float32 chunkCells * tileSize // 2048
12+
13+
[<Literal>]
814
let playerWidth = 40.0f
15+
16+
[<Literal>]
917
let playerHeight = 54.0f
18+
19+
[<Literal>]
1020
let gravity = 1200.0f
21+
22+
[<Literal>]
1123
let moveSpeed = 300.0f
24+
25+
[<Literal>]
1226
let jumpSpeed = -700.0f
27+
28+
[<Literal>]
1329
let worldHeight = 12.0f
30+
1431
let groundLevel = worldHeight * tileSize
1532
let groundSurface = groundLevel - tileSize
33+
34+
[<Literal>]
1635
let chunkLoadRadius = 2
36+
37+
[<Literal>]
1738
let chunkEvictRadius = 4
39+
40+
[<Literal>]
1841
let maxOccluders = 128
42+
43+
[<Literal>]
1944
let maxTorchLights = 16
45+
46+
[<Literal>]
2047
let viewportWidth = 1280.0f
48+
49+
[<Literal>]
2150
let viewportHeight = 720.0f
51+
52+
[<Literal>]
2253
let spawnX = 200.0f
23-
let spawnProtectedCells = 5 // first 5 cells (0-320px) are pit-free
54+
55+
[<Literal>]
56+
let spawnProtectedCells = 5 // first 5 cells (0-320px) are pit-free

samples/PlatformerSample/DayNight.fs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open PlatformerSample.Constants
88
// -------------------------------------------------------------
99
// Day / Night Cycle
1010
// -------------------------------------------------------------
11-
11+
[<Struct>]
1212
type State = {
1313
TimeOfDay: float32
1414
DayDuration: float32
@@ -21,10 +21,15 @@ let initial = {
2121

2222
let inline update dt state =
2323
let hoursPerSecond = 24.0f / state.DayDuration
24-
{ state with TimeOfDay = (state.TimeOfDay + dt * hoursPerSecond) % 24.0f }
24+
25+
{
26+
state with
27+
TimeOfDay = (state.TimeOfDay + dt * hoursPerSecond) % 24.0f
28+
}
2529

2630
let inline lerpColor (a: Color) (b: Color) (t: float32) =
2731
let t = Math.Clamp(t, 0.0f, 1.0f)
32+
2833
Color(
2934
byte(float32 a.R + t * (float32 b.R - float32 a.R)),
3035
byte(float32 a.G + t * (float32 b.G - float32 a.G)),
@@ -58,30 +63,31 @@ let getSkyColors time : Color * Color =
5863

5964
let getAmbientColor time : Color =
6065
let top, bot = getSkyColors time
66+
6167
let avg =
62-
(int top.R + int top.G + int top.B + int bot.R + int bot.G + int bot.B)
63-
/ 6
68+
(int top.R + int top.G + int top.B + int bot.R + int bot.G + int bot.B) / 6
6469
|> float32
70+
6571
let intensity = MathF.Max(avg / 255.0f, 0.12f)
72+
6673
Color(
6774
byte(intensity * 255.0f),
6875
byte(intensity * 245.0f),
6976
byte(intensity * 230.0f),
7077
255uy
7178
)
7279

80+
// Sun and moon are mutually exclusive — never active simultaneously.
81+
// This avoids doubling directional-light uniform uploads and SDF
82+
// raymarch cost during dawn/dusk.
7383
let getSunIntensity time : float32 =
74-
if time < 6.0f || time > 18.0f then 0.0f
75-
elif time < 8.0f then (time - 6.0f) / 2.0f
76-
elif time < 16.0f then 1.0f
77-
else (18.0f - time) / 2.0f
84+
if time < 5.0f || time > 19.0f then 0.0f
85+
elif time < 7.0f then (time - 5.0f) / 2.0f
86+
elif time < 17.0f then 1.0f
87+
else (19.0f - time) / 2.0f
7888

7989
let getMoonIntensity time : float32 =
80-
if time > 6.0f && time < 18.0f then 0.0f
81-
elif time < 8.0f then 1.0f - (time - 6.0f) / 2.0f
82-
elif time < 16.0f then 0.0f
83-
elif time < 18.0f then (time - 16.0f) / 2.0f
84-
else 1.0f
90+
if time >= 5.0f && time <= 19.0f then 0.0f else 1.0f
8591

8692
let orbitalPositions (centerX: float32) (state: State) =
8793
let centerY = groundLevel - 200.0f

samples/PlatformerSample/Physics.fs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,28 @@ open PlatformerSample.Types
99
// Player Bounds & Collision
1010
// -------------------------------------------------------------
1111

12-
let playerBounds(pos: Vector2) =
12+
let inline playerBounds(pos: Vector2) =
1313
Rectangle(pos.X, pos.Y, playerWidth, playerHeight)
1414

1515
let inline checkCollision (a: Rectangle) (b: Rectangle) =
16-
a.X < b.X + b.Width && a.X + a.Width > b.X && a.Y < b.Y + b.Height && a.Y + a.Height > b.Y
16+
a.X < b.X + b.Width
17+
&& a.X + a.Width > b.X
18+
&& a.Y < b.Y + b.Height
19+
&& a.Y + a.Height > b.Y
1720

1821
let resolvePlatformCollision
1922
(prevPos: Vector2)
2023
(newPos: Vector2)
2124
(velocity: Vector2)
22-
(platforms: Rectangle[])
25+
(platforms: ResizeArray<Rectangle>)
2326
: struct (Vector2 * Vector2 * bool) =
2427
let mutable pos = newPos
2528
let mutable vel = velocity
2629
let mutable grounded = false
2730

28-
for pb in platforms do
31+
for i = 0 to platforms.Count - 1 do
32+
let pb = platforms[i]
33+
2934
if checkCollision (playerBounds pos) pb then
3035
let prevFeetY = prevPos.Y + playerHeight
3136
let currFeetY = pos.Y + playerHeight
@@ -54,7 +59,10 @@ let resolvePlatformCollision
5459

5560
let getAnimationState (velocity: Vector2) (isGrounded: bool) =
5661
if not isGrounded then
57-
if velocity.Y > 0.0f then AnimationState.Fall else AnimationState.Jump
62+
if velocity.Y > 0.0f then
63+
AnimationState.Fall
64+
else
65+
AnimationState.Jump
5866
elif abs velocity.X > 1.0f then
5967
AnimationState.Walk
6068
else

samples/PlatformerSample/Program.fs

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open PlatformerSample.WorldGen
1919
let inline r (x: int) (y: int) (w: int) (h: int) =
2020
Rectangle(float32 x, float32 y, float32 w, float32 h)
2121

22-
let loadAssets (ctx: GameContext) : SpriteAssets =
22+
let loadAssets(ctx: GameContext) : SpriteAssets =
2323
let assets = GameContext.getService<IAssets> ctx
2424

2525
let playerTex =
@@ -36,29 +36,50 @@ let loadAssets (ctx: GameContext) : SpriteAssets =
3636
let jumpSound = assets.Sound("assets/sfx_jump.ogg")
3737

3838
// White 1x1 texture for particles (black would multiply to zero)
39-
let particleImg = Raylib.GenImageColor(1, 1, Color(255uy, 255uy, 255uy, 255uy))
39+
let particleImg =
40+
Raylib.GenImageColor(1, 1, Color(255uy, 255uy, 255uy, 255uy))
41+
4042
let particleTex = Raylib.LoadTextureFromImage(particleImg)
4143
Raylib.UnloadImage(particleImg)
4244

4345
let playerSheet =
44-
SpriteSheet.fromFrames
45-
playerTex
46-
(Vector2(64.0f, 64.0f))
47-
[|
48-
struct ("idle", { Frames = [| r 645 0 128 128 |]; FrameDuration = 1.0f; Loop = false })
49-
struct ("walk", { Frames = [| r 0 129 128 128; r 129 129 128 128 |]; FrameDuration = 0.1f; Loop = true })
50-
struct ("jump", { Frames = [| r 774 0 128 128 |]; FrameDuration = 1.0f; Loop = false })
51-
struct ("fall", { Frames = [| r 774 0 128 128 |]; FrameDuration = 1.0f; Loop = false })
52-
|]
46+
SpriteSheet.fromFrames playerTex (Vector2(64.0f, 64.0f)) [|
47+
struct ("idle",
48+
{
49+
Frames = [| r 645 0 128 128 |]
50+
FrameDuration = 1.0f
51+
Loop = false
52+
})
53+
struct ("walk",
54+
{
55+
Frames = [| r 0 129 128 128; r 129 129 128 128 |]
56+
FrameDuration = 0.1f
57+
Loop = true
58+
})
59+
struct ("jump",
60+
{
61+
Frames = [| r 774 0 128 128 |]
62+
FrameDuration = 1.0f
63+
Loop = false
64+
})
65+
struct ("fall",
66+
{
67+
Frames = [| r 774 0 128 128 |]
68+
FrameDuration = 1.0f
69+
Loop = false
70+
})
71+
|]
5372

5473
// torch_on_a (65,1105) and torch_on_b (130,1105) — 64x64 each
5574
let torchSheet =
56-
SpriteSheet.fromFrames
57-
tileTex
58-
(Vector2(32.0f, 32.0f))
59-
[|
60-
struct ("lit", { Frames = [| r 65 1105 64 64; r 130 1105 64 64 |]; FrameDuration = 0.15f; Loop = true })
61-
|]
75+
SpriteSheet.fromFrames tileTex (Vector2(32.0f, 32.0f)) [|
76+
struct ("lit",
77+
{
78+
Frames = [| r 65 1105 64 64; r 130 1105 64 64 |]
79+
FrameDuration = 0.15f
80+
Loop = true
81+
})
82+
|]
6283

6384
{
6485
PlayerSheet = playerSheet
@@ -73,7 +94,7 @@ let loadAssets (ctx: GameContext) : SpriteAssets =
7394
// Init
7495
// -------------------------------------------------------------
7596

76-
let init (ctx: GameContext) =
97+
let init(ctx: GameContext) =
7798
let assets = loadAssets ctx
7899

79100
let inputMap =
@@ -97,14 +118,22 @@ let init (ctx: GameContext) =
97118
// Pre-load spawn chunks
98119
let spawnChunkX = 0
99120
let spawnChunkY = 0
121+
100122
for x in spawnChunkX - chunkLoadRadius .. spawnChunkX + chunkLoadRadius do
101123
for y in spawnChunkY - chunkLoadRadius .. spawnChunkY + chunkLoadRadius do
102124
if x >= 0 then
103-
model.Chunks[struct(x, y)] <- generateChunk x y seed
125+
model.Chunks[struct (x, y)] <- generateChunk x y seed
104126

105127
model.PlayerPosition <- Vector2(spawnX, spawnY)
106-
model.CameraPos <- Vector2(spawnX, spawnY)
128+
129+
model.Camera <-
130+
Camera2D.create
131+
(Vector2(spawnX, spawnY))
132+
1.0f
133+
(Vector2(viewportWidth, viewportHeight))
134+
107135
model.Seed <- seed
136+
108137
model.Lighting <-
109138
new LightContext2D(softness = 0.05f, maxShadowDistance = 2000.0f)
110139

0 commit comments

Comments
 (0)