Skip to content

Commit a5b15fa

Browse files
committed
Updates for 0.11
1 parent d84b63c commit a5b15fa

14 files changed

+97
-154
lines changed

bower.json

+9-31
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,16 @@
2222
"package.json"
2323
],
2424
"dependencies": {
25-
"purescript-webgl": "^1.3.0",
26-
"purescript-datetime": "^2.0.0",
27-
"purescript-random": "^2.0.0",
28-
"purescript-extensions": "^1.2.1",
29-
"purescript-console": "^2.0.0",
30-
"purescript-now": "^2.0.0",
31-
"purescript-matrix": "^1.2.0",
32-
"purescript-vector": "^1.2.0",
33-
"purescript-typedarray": "^1.2.0"
25+
"purescript-webgl": "^2.0.0",
26+
"purescript-clock": "^0.1.0",
27+
"purescript-random": "^3.0.0",
28+
"purescript-extensions": "^2.0.0",
29+
"purescript-console": "^3.0.0",
30+
"purescript-matrix": "^2.0.0",
31+
"purescript-vector": "^2.0.0",
32+
"purescript-typedarray": "^2.0.0"
3433
},
3534
"resolutions": {
36-
"purescript-integers": "^2.0.0",
37-
"purescript-eff": "^2.0.0",
38-
"purescript-foldable-traversable": "^2.0.0",
39-
"purescript-prelude": "^2.1.0",
40-
"purescript-either": "^2.0.0",
41-
"purescript-maybe": "^2.0.0",
42-
"purescript-arrays": "^3.0.0",
43-
"purescript-functions": "^2.0.0",
44-
"purescript-unfoldable": "^2.0.0",
45-
"purescript-monoid": "^2.0.0",
46-
"purescript-control": "^2.0.0",
47-
"purescript-tuples": "^3.0.0",
48-
"purescript-invariant": "^2.0.0",
49-
"purescript-generics": "^3.0.0",
50-
"purescript-bifunctors": "^2.0.0",
51-
"purescript-st": "^2.0.0",
52-
"purescript-strings": "^2.0.0",
53-
"purescript-datetime": "^2.0.0",
54-
"purescript-enums": "^2.0.0",
55-
"purescript-random": "^2.0.0",
56-
"purescript-console": "^2.0.0",
57-
"purescript-now": "^2.0.0"
35+
"purescript-arraybuffer-types": "^2.0.0"
5836
}
5937
}

run.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ rm -r dist
55
mkdir dist
66

77
pulp build
8-
psc-bundle output/**/*.js -m Example1 -o dist/Main1.js
9-
psc-bundle output/**/*.js -m Example2 -o dist/Main2.js
10-
psc-bundle output/**/*.js -m Example3 -o dist/Main3.js
11-
psc-bundle output/**/*.js -m Example4 -o dist/Main4.js
12-
psc-bundle output/**/*.js -m Example5 -o dist/Main5.js
13-
psc-bundle output/**/*.js -m Example6 -o dist/Main6.js
14-
psc-bundle output/**/*.js -m Example7 -o dist/Main7.js
15-
psc-bundle output/**/*.js -m Example8 -o dist/Main8.js
16-
psc-bundle output/**/*.js -m Example9 -o dist/Main9.js
17-
psc-bundle output/**/*.js -m Example9ST -o dist/Main9ST.js
8+
purs bundle output/**/*.js -m Example1 -o dist/Main1.js
9+
purs bundle output/**/*.js -m Example2 -o dist/Main2.js
10+
purs bundle output/**/*.js -m Example3 -o dist/Main3.js
11+
purs bundle output/**/*.js -m Example4 -o dist/Main4.js
12+
purs bundle output/**/*.js -m Example5 -o dist/Main5.js
13+
purs bundle output/**/*.js -m Example6 -o dist/Main6.js
14+
purs bundle output/**/*.js -m Example7 -o dist/Main7.js
15+
purs bundle output/**/*.js -m Example8 -o dist/Main8.js
16+
purs bundle output/**/*.js -m Example9 -o dist/Main9.js
17+
purs bundle output/**/*.js -m Example9ST -o dist/Main9ST.js

src/Control/Monad/Eff/Alert.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Control.Monad.Eff.Alert where
22

33
import Prelude (Unit)
4-
import Control.Monad.Eff (Eff)
4+
import Control.Monad.Eff (kind Effect, Eff)
55

6-
foreign import data Alert :: !
6+
foreign import data Alert :: Effect
77

88
foreign import alert :: forall eff. String -> Eff (alert :: Alert | eff) Unit

src/Example1.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Example1 where
22

3-
import Prelude (Unit, bind, negate, (/))
3+
import Prelude
44
import Graphics.WebGLAll (Mat4, Uniform, Vec3, Attribute, Capacity(DEPTH_TEST), Mask(DEPTH_BUFFER_BIT, COLOR_BUFFER_BIT), Mode(TRIANGLE_STRIP, TRIANGLES), Shaders(Shaders), drawArr, makeBufferFloat, setUniformFloats, clear, viewport, getCanvasHeight, getCanvasWidth, enable, clearColor, withShaders, runWebGL)
55
import Data.Matrix4 (translate, identity, makePerspective) as M
66
import Data.Matrix (toArray) as M

src/Example2.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Example2 where
22

3-
import Prelude (Unit, bind, negate, (/))
3+
import Prelude
44
import Graphics.WebGLAll (Mat4, Uniform, Vec3, Attribute, Capacity(DEPTH_TEST), Mask(DEPTH_BUFFER_BIT, COLOR_BUFFER_BIT), Mode(TRIANGLE_STRIP, TRIANGLES), Shaders(Shaders), drawArr, bindBufAndSetVertexAttr, setUniformFloats, clear, viewport, getCanvasHeight, getCanvasWidth, makeBufferFloat, enable, clearColor, withShaders, runWebGL)
55
import Data.Matrix4 (translate, identity, makePerspective) as M
66
import Data.Matrix (toArray) as M

src/Example3.purs

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module Example3 where
33
import Prelude
44
import Control.Monad.Eff (Eff)
55
import Control.Monad.Eff.Console (CONSOLE, log)
6-
import Control.Monad.Eff.Now (NOW, now)
7-
import Data.DateTime.Instant (unInstant)
8-
import Data.Time.Duration (Milliseconds(Milliseconds))
6+
import System.Clock (CLOCK, milliseconds)
97
import Data.Maybe (Maybe(Just, Nothing))
108
import Math (pi)
119
import Data.Int (toNumber)
@@ -64,7 +62,7 @@ type State = {
6462
rSquare :: Number
6563
}
6664

67-
main :: Eff (console :: CONSOLE, alert :: Alert, now :: NOW) Unit
65+
main :: Eff (console :: CONSOLE, alert :: Alert, clock :: CLOCK) Unit
6866
main =
6967
runWebGL
7068
"glcanvas"
@@ -110,20 +108,17 @@ main =
110108
}
111109
tick state
112110

113-
tick :: forall eff. State -> EffWebGL (now :: NOW |eff) Unit
111+
tick :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) Unit
114112
tick state = do
115113
-- trace ("tick: " ++ show state.lastTime)
116114
drawScene state
117115
state' <- animate state
118116
pure unit
119117
requestAnimationFrame (tick state')
120118

121-
unpackMilliseconds :: Milliseconds -> Number
122-
unpackMilliseconds (Milliseconds n) = n
123-
124-
animate :: forall eff. State -> EffWebGL (now :: NOW |eff) State
119+
animate :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) State
125120
animate state = do
126-
timeNow <- liftM1 (unpackMilliseconds <<< unInstant) now
121+
timeNow <- milliseconds
127122
case state.lastTime of
128123
Nothing -> pure state {lastTime = Just timeNow}
129124
Just lastt ->
@@ -132,7 +127,7 @@ animate state = do
132127
rTri = state.rTri + (90.0 * elapsed) / 1000.0,
133128
rSquare = state.rSquare + (75.0 * elapsed) / 1000.0}
134129

135-
drawScene :: forall eff. State -> EffWebGL (now :: NOW |eff) Unit
130+
drawScene :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) Unit
136131
drawScene s = do
137132
canvasWidth <- getCanvasWidth s.context
138133
canvasHeight <- getCanvasHeight s.context

src/Example4.purs

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module Example4 where
33
import Prelude
44
import Control.Monad.Eff (Eff)
55
import Control.Monad.Eff.Console (CONSOLE, log)
6-
import Control.Monad.Eff.Now (NOW, now)
7-
import Data.DateTime.Instant (unInstant)
8-
import Data.Time.Duration (Milliseconds(Milliseconds))
6+
import System.Clock (CLOCK, milliseconds)
97
import Data.Maybe (Maybe(Just, Nothing))
108
import Data.Array (concatMap, concat)
119
import Math (pi)
@@ -64,7 +62,7 @@ type State = {
6462
rCube :: Number
6563
}
6664

67-
main :: Eff (console :: CONSOLE, alert :: Alert, now :: NOW) Unit
65+
main :: Eff (console :: CONSOLE, alert :: Alert, clock :: CLOCK) Unit
6866
main =
6967
runWebGL
7068
"glcanvas"
@@ -184,19 +182,16 @@ main =
184182
}
185183
tick state
186184

187-
tick :: forall eff. State -> EffWebGL (console :: CONSOLE, now :: NOW |eff) Unit
185+
tick :: forall eff. State -> EffWebGL (console :: CONSOLE, clock :: CLOCK |eff) Unit
188186
tick state = do
189187
-- log ("tick: " ++ show state.lastTime)
190188
drawScene state
191189
state' <- animate state
192190
requestAnimationFrame (tick state')
193191

194-
unpackMilliseconds :: Milliseconds -> Number
195-
unpackMilliseconds (Milliseconds n) = n
196-
197-
animate :: forall eff. State -> EffWebGL (now :: NOW |eff) State
192+
animate :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) State
198193
animate state = do
199-
timeNow <- liftM1 (unpackMilliseconds <<< unInstant) now
194+
timeNow <- milliseconds
200195
case state.lastTime of
201196
Nothing -> pure state {lastTime = Just timeNow}
202197
Just lastt ->
@@ -205,7 +200,7 @@ animate state = do
205200
rPyramid = state.rPyramid + (90.0 * elapsed) / 1000.0,
206201
rCube = state.rCube + (75.0 * elapsed) / 1000.0}
207202

208-
drawScene :: forall eff. State -> EffWebGL (now :: NOW |eff) Unit
203+
drawScene :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) Unit
209204
drawScene s = do
210205
canvasWidth <- getCanvasWidth s.context
211206
canvasHeight <- getCanvasHeight s.context

src/Example5.purs

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ module Example5 where
44
import Prelude
55
import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Console (CONSOLE, log)
7-
import Control.Monad.Eff.Now (NOW, now)
8-
import Data.DateTime.Instant (unInstant)
9-
import Data.Time.Duration (Milliseconds(Milliseconds))
7+
import System.Clock (CLOCK, milliseconds)
108
import Data.Maybe (Maybe(Just, Nothing))
119
import Math (pi)
1210
import Data.Int (toNumber)
@@ -75,7 +73,7 @@ type State =
7573
rot :: Number
7674
}
7775

78-
main :: Eff (console :: CONSOLE, alert :: Alert, now :: NOW) Unit
76+
main :: Eff (console :: CONSOLE, alert :: Alert, clock :: CLOCK) Unit
7977
main = do
8078
-- let stupid = Mat3 "stupid"
8179
runWebGL
@@ -191,19 +189,16 @@ main = do
191189
}
192190

193191

194-
tick :: forall eff. State -> EffWebGL (console :: CONSOLE, now :: NOW |eff) Unit
192+
tick :: forall eff. State -> EffWebGL (console :: CONSOLE, clock :: CLOCK |eff) Unit
195193
tick state = do
196194
-- log ("tick: " ++ show state.lastTime)
197195
drawScene state
198196
state' <- animate state
199197
requestAnimationFrame (tick state')
200198

201-
unpackMilliseconds :: Milliseconds -> Number
202-
unpackMilliseconds (Milliseconds n) = n
203-
204-
animate :: forall eff. State -> EffWebGL (now :: NOW |eff) State
199+
animate :: forall eff. State -> EffWebGL (clock :: CLOCK |eff) State
205200
animate state = do
206-
timeNow <- liftM1 (unpackMilliseconds <<< unInstant) now
201+
timeNow <- milliseconds
207202
case state.lastTime of
208203
Nothing -> pure state {lastTime = Just timeNow}
209204
Just lastt ->
@@ -212,7 +207,7 @@ animate state = do
212207
rot = state.rot + (90.0 * elapsed) / 1000.0
213208
}
214209

215-
drawScene :: forall eff. State -> EffWebGL (now :: NOW | eff) Unit
210+
drawScene :: forall eff. State -> EffWebGL (clock :: CLOCK | eff) Unit
216211
drawScene s = do
217212
canvasWidth <- getCanvasWidth s.context
218213
canvasHeight <- getCanvasHeight s.context

src/Example6.purs

+9-14
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import Prelude
44
import Control.Monad.Eff (Eff)
55
import Control.Monad.ST (ST, STRef, writeSTRef, readSTRef, newSTRef, runST)
66
import Control.Monad.Eff.Console (CONSOLE, log)
7-
import Control.Monad.Eff.Now (NOW, now)
8-
import Data.DateTime.Instant (unInstant)
9-
import Data.Time.Duration (Milliseconds(Milliseconds))
7+
import System.Clock (CLOCK, milliseconds)
108
import Data.Maybe (Maybe(..), fromJust)
119
import Data.Array (delete, elemIndex, (:), null, (!!))
1210
import Math (pi)
@@ -170,7 +168,7 @@ type State = {
170168
currentlyPressedKeys :: Array Int
171169
}
172170

173-
main :: Eff (console :: CONSOLE, alert :: Alert, now :: NOW) Unit
171+
main :: Eff (console :: CONSOLE, alert :: Alert, clock :: CLOCK) Unit
174172
main = do
175173
runWebGL
176174
"glcanvas"
@@ -218,21 +216,18 @@ main = do
218216
onKeyUp (handleKeyU stRef)
219217
tick stRef
220218

221-
tick :: forall h eff. STRef h State -> EffWebGL (st :: ST h, console :: CONSOLE, now :: NOW |eff) Unit
219+
tick :: forall h eff. STRef h State -> EffWebGL (st :: ST h, console :: CONSOLE, clock :: CLOCK |eff) Unit
222220
tick stRef = do
223221
drawScene stRef
224222
handleKeys stRef
225223
animate stRef
226224
requestAnimationFrame (tick stRef)
227225

228-
unpackMilliseconds :: Milliseconds -> Number
229-
unpackMilliseconds (Milliseconds n) = n
230-
231-
animate :: forall h eff . STRef h State -> EffWebGL (st :: ST h, now :: NOW |eff) Unit
226+
animate :: forall h eff . STRef h State -> EffWebGL (st :: ST h, clock :: CLOCK |eff) Unit
232227
animate stRef = do
233228
s <- readSTRef stRef
234-
timeNow <- liftM1 (unpackMilliseconds <<< unInstant) now
235-
case s.lastTime of
229+
timeNow <- milliseconds
230+
_ <- case s.lastTime of
236231
Nothing -> writeSTRef stRef (s {lastTime = Just timeNow})
237232
Just lastt ->
238233
let elapsed = timeNow - lastt
@@ -304,7 +299,7 @@ handleKeys stRef = do
304299
Just _ -> xSpeed' + 1.0
305300
Nothing -> xSpeed'
306301
in do
307-
writeSTRef stRef (s{z=z'',ySpeed=ySpeed'',xSpeed=xSpeed''})
302+
_ <- writeSTRef stRef (s{z=z'',ySpeed=ySpeed'',xSpeed=xSpeed''})
308303
-- log (show s.currentlyPressedKeys)
309304
pure unit
310305

@@ -322,7 +317,7 @@ handleKeyD stRef event = do
322317
Just _ -> s.currentlyPressedKeys
323318
Nothing -> key : s.currentlyPressedKeys
324319
log ("filterInd: " <> show f)
325-
writeSTRef stRef (s {currentlyPressedKeys = cp, filterInd = f})
320+
_ <- writeSTRef stRef (s {currentlyPressedKeys = cp, filterInd = f})
326321
-- log (show s.currentlyPressedKeys)
327322
pure unit
328323

@@ -334,6 +329,6 @@ handleKeyU stRef event = do
334329
case elemIndex key s.currentlyPressedKeys of
335330
Nothing -> pure unit
336331
Just _ -> do
337-
writeSTRef stRef (s {currentlyPressedKeys = delete key s.currentlyPressedKeys})
332+
_ <- writeSTRef stRef (s {currentlyPressedKeys = delete key s.currentlyPressedKeys})
338333
-- log (show s.currentlyPressedKeys)
339334
pure unit

src/Example7.purs

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import Control.Monad.Eff.Alert (Alert, alert)
55
import Control.Monad.Eff (Eff)
66
import Control.Monad.ST (ST, STRef, writeSTRef, readSTRef, newSTRef, runST)
77
import Control.Monad.Eff.Console (CONSOLE, log)
8-
import Control.Monad.Eff.Now (NOW, now)
9-
import Data.DateTime.Instant (unInstant)
10-
import Data.Time.Duration (Milliseconds(Milliseconds))
8+
import System.Clock (CLOCK, milliseconds)
119
import Data.Maybe (Maybe(Just, Nothing), fromJust)
1210
import Data.Array (delete, elemIndex, (:), null)
1311
import Math (pi)
@@ -230,7 +228,7 @@ type State bindings = {
230228
currentlyPressedKeys :: Array Int
231229
}
232230

233-
main :: Eff (console :: CONSOLE, alert :: Alert, now :: NOW) Unit
231+
main :: Eff (console :: CONSOLE, alert :: Alert, clock :: CLOCK) Unit
234232
main = do
235233
runWebGL
236234
"glcanvas"
@@ -273,21 +271,19 @@ main = do
273271
onKeyUp (handleKeyU stRef)
274272
tick stRef
275273

276-
tick :: forall h eff. STRef h (State MyBindings) -> EffWebGL (st :: ST h, console :: CONSOLE, now :: NOW |eff) Unit
274+
tick :: forall h eff. STRef h (State MyBindings) -> EffWebGL (st :: ST h, console :: CONSOLE, clock :: CLOCK |eff) Unit
277275
tick stRef = do
278276
drawScene stRef
279277
handleKeys stRef
280278
animate stRef
281279
requestAnimationFrame (tick stRef)
282280

283-
unpackMilliseconds :: Milliseconds -> Number
284-
unpackMilliseconds (Milliseconds n) = n
285281

286-
animate :: forall h eff . STRef h (State MyBindings) -> EffWebGL (st :: ST h, now :: NOW |eff) Unit
282+
animate :: forall h eff . STRef h (State MyBindings) -> EffWebGL (st :: ST h, clock :: CLOCK |eff) Unit
287283
animate stRef = do
288284
s <- readSTRef stRef
289-
timeNow <- liftM1 (unpackMilliseconds <<< unInstant) now
290-
case s.lastTime of
285+
timeNow <- milliseconds
286+
_ <- case s.lastTime of
291287
Nothing -> writeSTRef stRef (s {lastTime = Just timeNow})
292288
Just lastt ->
293289
let elapsed = timeNow - lastt
@@ -385,7 +381,7 @@ handleKeys stRef = do
385381
Just _ -> xSpeed' + 1.0
386382
Nothing -> xSpeed'
387383
in do
388-
writeSTRef stRef (s{z=z'',ySpeed=ySpeed'',xSpeed=xSpeed''})
384+
_ <- writeSTRef stRef (s{z=z'',ySpeed=ySpeed'',xSpeed=xSpeed''})
389385
-- log (show s.currentlyPressedKeys)
390386
pure unit
391387

@@ -397,7 +393,7 @@ handleKeyD stRef event = do
397393
let cp = case elemIndex key s.currentlyPressedKeys of
398394
Just _ -> s.currentlyPressedKeys
399395
Nothing -> key : s.currentlyPressedKeys
400-
writeSTRef stRef (s {currentlyPressedKeys = cp})
396+
_ <- writeSTRef stRef (s {currentlyPressedKeys = cp})
401397
-- log (show s.currentlyPressedKeys)
402398
pure unit
403399

@@ -409,6 +405,6 @@ handleKeyU stRef event = do
409405
case elemIndex key s.currentlyPressedKeys of
410406
Nothing -> pure unit
411407
Just _ -> do
412-
writeSTRef stRef (s {currentlyPressedKeys = delete key s.currentlyPressedKeys})
408+
_ <- writeSTRef stRef (s {currentlyPressedKeys = delete key s.currentlyPressedKeys})
413409
-- log (show s.currentlyPressedKeys)
414410
pure unit

0 commit comments

Comments
 (0)