Skip to content

Commit 1aaadae

Browse files
committed
Rearranged ProcessFn sig.
1 parent f9f22d4 commit 1aaadae

4 files changed

Lines changed: 60 additions & 66 deletions

File tree

Nu/Nu/BlockMap/BlockMap.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ type Processor =
154154
ProcessParams = processParams
155155
ProcessFnName = processFnName }
156156

157+
type ProcessEffect<'p, 'w> =
158+
'p -> 'w -> unit
159+
157160
type ProcessFn<'p, 'w> =
158-
Vector3i -> Affine -> Map<string, ProcessParam> -> Chunk -> ('p -> 'w -> Chunk) option
161+
Vector3i -> Affine -> Map<string, ProcessParam> -> Chunk -> (ProcessEffect<'p, 'w> * Chunk) option
159162

160163
type Pass =
161164
{ Processors : Processor array }
@@ -330,7 +333,7 @@ type BlockEditor =
330333
module ProcessFns =
331334

332335
let Id _ _ _ block =
333-
Some (fun _ _ -> block)
336+
Some ((fun _ _ -> ()), block)
334337

335338
let ProcessFns<'p, 'w> : Map<string, ProcessFn<'p, 'w>> =
336339
[(nameof Id, Id)]

Nu/Nu/World/WorldBlockMap.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module BlockEditor =
6363
BlockMap.Chunk.make chunkBounds blocks
6464
let subchunk' =
6565
match fn volume affine processor.ProcessParams subchunk with
66-
| Some effect -> effect parent world
66+
| Some (effect, subchunk') -> effect parent world; subchunk'
6767
| None -> subchunk
6868
for struct (positionI, block) in subchunk'.Blocks.Pairs' do
6969
match BlockMap.Chunk.trySetBlock (chunkBounds.Min + positionI) block chunk with
@@ -218,7 +218,6 @@ type BlockMapDispatcher () =
218218
let b = Vector3 (bounds.Max.X, y, z)
219219
Segment3 (a, b)|]
220220

221-
222221
// draw grid line segments
223222
let gridColor = Color (64uy, 64uy, 64uy, 255uy) // TODO: make constant.
224223
World.imGuiSegments3d segments 1.0f gridColor world
@@ -294,13 +293,13 @@ type BlockMapDispatcher () =
294293
viewportOverlay.EditContext.Snapshot ClearBlocks world
295294
blockEditor <- BlockEditor.clear blockEditor entity world
296295

296+
// finish block editor window
297297
ImGui.End ()
298298

299299
// paint block when ungenerated
300300
if not blockEditor.Generated &&
301301
World.isMouseButtonDown MouseLeft world then
302-
if World.isMouseButtonPressed MouseLeft world then
303-
viewportOverlay.EditContext.Snapshot PaintBlocks world
302+
if World.isMouseButtonPressed MouseLeft world then viewportOverlay.EditContext.Snapshot PaintBlocks world
304303
let position = entity.GetPosition world
305304
let ray = World.getMouseRay3dWorld world
306305
match BlockEditor.tryPickPositionI ray position blockEditor with

Projects/Sand Box 3d/Assets/Gameplay/Scene.nugroup

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
[Static True]]
1111
[]]
1212
[Light3dDispatcher
13-
[[AttenuationLinear 0.010416667]
14-
[AttenuationQuadratic 0.00032552084]
13+
[[AttenuationLinear 0.013888889]
14+
[AttenuationQuadratic 0.0005787037]
1515
[DesireShadows True]
16-
[LightCutoff 32]
16+
[LightCutoff 24]
1717
[LightType [DirectionalLight 18]]
1818
[MountOpt [Some ^]]
1919
[Name Light3d]
2020
[Position [0 2.5 0]]
2121
[Presence Omnipresent]
2222
[Rotation [0.13247053 0.50053895 0.2188759 0.8270464]]
23-
[Size [64 64 64]]
23+
[Size [48 48 48]]
2424
[Static True]]
2525
[]]
2626
[BlockMapDispatcher

Projects/Sand Box 3d/SandBox3dPlugin.fs

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,112 +12,104 @@ type SandBox3dPlugin () =
1212

1313
let WallColor = Palette.BaseColorValues.[0]
1414

15-
let wallSlice (center : Vector3i) chunk =
16-
match chunk.Blocks.TryGetValue center with
17-
| (true, middleBlock) when middleBlock.Color = WallColor ->
18-
match chunk.Blocks.TryGetValue (center + v3iUp) with
19-
| (true, topBlock) when topBlock.Color = WallColor ->
20-
match chunk.Blocks.TryGetValue (v3iOne + v3iDown) with
21-
| (true, bottomBlock) when bottomBlock.Color = WallColor -> Some (bottomBlock, middleBlock, topBlock)
22-
| (_, _) -> None
23-
| (_, _) -> None
24-
| (_, _) -> None
25-
26-
let createWallModel horizonal halfDirectionOpt (affine : Affine) (parent : Entity) world =
15+
let createWallModel lateral halfDirectionOpt (affine : Affine) (parent : Entity) world =
2716
let name = "Wall" + string Gen.id64
2817
let surnames = Array.add name parent.Surnames
2918
let entity = World.createEntity<RigidModelDispatcher> (Some Address.parent) NoOverlay (Some surnames) parent.Group world
3019
let (translation, scale) =
31-
if horizonal then
20+
if lateral then
3221
match halfDirectionOpt with
3322
| Some false -> (v3 -0.25f 0.0f 0.0f, v3 0.5f 3.0f 0.5f)
3423
| Some true -> (v3 0.25f 0.0f 0.0f, v3 0.5f 3.0f 0.5f)
3524
| None -> (v3Zero, v3 1.0f 3.0f 0.5f)
3625
else
3726
match halfDirectionOpt with
38-
| Some false -> (v3 0.0f 0.0f -0.25f, v3 1.0f 3.0f 0.5f)
39-
| Some true -> (v3 0.0f 0.0f 0.25f, v3 1.0f 3.0f 0.5f)
27+
| Some false -> (v3 0.0f 0.0f -0.25f, v3 0.5f 3.0f 0.5f)
28+
| Some true -> (v3 0.0f 0.0f 0.25f, v3 0.5f 3.0f 0.5f)
4029
| None -> (v3Zero, v3 0.5f 3.0f 1.0f)
41-
42-
entity.SetStaticModel Assets.Default.StaticModel world
4330
entity.SetPositionLocal (translation + affine.Translation) world
4431
entity.SetRotationLocal affine.Rotation world
4532
entity.SetScaleLocal (scale * affine.Scale) world
33+
entity.SetStaticModel Assets.Default.StaticModel world
4634

47-
let wall volume affine params chunk =
35+
let wallSlice (center : Vector3i) chunk =
36+
match chunk.Blocks.TryGetValue center with
37+
| (true, middleBlock) when middleBlock.Color = WallColor ->
38+
match chunk.Blocks.TryGetValue (center + v3iUp) with
39+
| (true, topBlock) when topBlock.Color = WallColor ->
40+
match chunk.Blocks.TryGetValue (v3iOne + v3iDown) with
41+
| (true, bottomBlock) when bottomBlock.Color = WallColor -> Some (bottomBlock, middleBlock, topBlock)
42+
| (_, _) -> None
43+
| (_, _) -> None
44+
| (_, _) -> None
45+
46+
let wall _ affine _ chunk =
4847
let center = v3iOne
49-
match wallSlice center chunk with
50-
| Some (bottomBlock, middleBlock, topBlock) ->
48+
let centerWallOpt = wallSlice center chunk
49+
if centerWallOpt.IsSome then
5150
let forwardWallOpt = wallSlice (center + v3iForward) chunk
5251
let rightWallOpt = wallSlice (center + v3iRight) chunk
5352
let backWallOpt = wallSlice (center + v3iBack) chunk
5453
let leftWallOpt = wallSlice (center + v3iLeft) chunk
5554
if forwardWallOpt.IsSome && rightWallOpt.IsSome && backWallOpt.IsSome && leftWallOpt.IsSome then
56-
let effect (parent : Entity) world =
55+
let effect parent world =
5756
createWallModel false None affine parent world
5857
createWallModel true None affine parent world
59-
chunk
60-
Some effect
58+
Some (effect, chunk)
6159
elif forwardWallOpt.IsSome && backWallOpt.IsSome && rightWallOpt.IsSome then
62-
let effect (parent : Entity) world =
60+
let effect parent world =
6361
createWallModel false None affine parent world
6462
createWallModel true (Some true) affine parent world
65-
chunk
66-
Some effect
63+
Some (effect, chunk)
6764
elif forwardWallOpt.IsSome && backWallOpt.IsSome && leftWallOpt.IsSome then
68-
let effect (parent : Entity) world =
65+
let effect parent world =
6966
createWallModel false None affine parent world
7067
createWallModel true (Some false) affine parent world
71-
chunk
72-
Some effect
68+
Some (effect, chunk)
7369
elif leftWallOpt.IsSome && rightWallOpt.IsSome && forwardWallOpt.IsSome then
74-
let effect (parent : Entity) world =
70+
let effect parent world =
7571
createWallModel true None affine parent world
7672
createWallModel false (Some false) affine parent world
77-
chunk
78-
Some effect
73+
Some (effect, chunk)
7974
elif leftWallOpt.IsSome && rightWallOpt.IsSome && backWallOpt.IsSome then
80-
let effect (parent : Entity) world =
75+
let effect parent world =
8176
createWallModel true None affine parent world
8277
createWallModel false (Some true) affine parent world
83-
chunk
84-
Some effect
78+
Some (effect, chunk)
8579
elif forwardWallOpt.IsSome && backWallOpt.IsSome then
86-
let effect (parent : Entity) world =
87-
createWallModel false None affine parent world
88-
chunk
89-
Some effect
80+
let effect parent world = createWallModel false None affine parent world
81+
Some (effect, chunk)
9082
elif leftWallOpt.IsSome && rightWallOpt.IsSome then
91-
let effect (parent : Entity) world =
92-
createWallModel true None affine parent world
93-
chunk
94-
Some effect
83+
let effect parent world = createWallModel true None affine parent world
84+
Some (effect, chunk)
9585
elif forwardWallOpt.IsSome && rightWallOpt.IsSome then
96-
let effect (parent : Entity) world =
86+
let effect parent world =
9787
createWallModel false (Some false) affine parent world
9888
createWallModel true (Some true) affine parent world
99-
chunk
100-
Some effect
89+
Some (effect, chunk)
10190
elif forwardWallOpt.IsSome && leftWallOpt.IsSome then
102-
let effect (parent : Entity) world =
91+
let effect parent world =
10392
createWallModel false (Some false) affine parent world
10493
createWallModel true (Some false) affine parent world
105-
chunk
106-
Some effect
94+
Some (effect, chunk)
10795
elif backWallOpt.IsSome && rightWallOpt.IsSome then
108-
let effect (parent : Entity) world =
96+
let effect parent world =
10997
createWallModel false (Some true) affine parent world
11098
createWallModel true (Some true) affine parent world
111-
chunk
112-
Some effect
99+
Some (effect, chunk)
113100
elif backWallOpt.IsSome && leftWallOpt.IsSome then
114-
let effect (parent : Entity) world =
101+
let effect parent world =
115102
createWallModel false (Some true) affine parent world
116103
createWallModel true (Some false) affine parent world
117-
chunk
118-
Some effect
104+
Some (effect, chunk)
105+
elif forwardWallOpt.IsSome || backWallOpt.IsSome then
106+
let effect parent world = createWallModel false None affine parent world
107+
Some (effect, chunk)
108+
elif rightWallOpt.IsSome || leftWallOpt.IsSome then
109+
let effect parent world = createWallModel true None affine parent world
110+
Some (effect, chunk)
119111
else None
120-
| None -> None
112+
else None
121113

122114
// this exposes different editing modes in the editor.
123115
override this.EditModes =

0 commit comments

Comments
 (0)