Refactor code that was causing massive slowdown
I don't know why I thought it was a good idea to use `concat`, but I'm not making that mistake again.
This commit is contained in:
parent
ef52a8f702
commit
fb18cce4ec
|
@ -2,6 +2,7 @@ module Render.Scene
|
||||||
|
|
||||||
import Data.DPair
|
import Data.DPair
|
||||||
import Data.Vect
|
import Data.Vect
|
||||||
|
import Data.IORef
|
||||||
import Data.Buffer
|
import Data.Buffer
|
||||||
import System.File
|
import System.File
|
||||||
import Render.Color
|
import Render.Color
|
||||||
|
@ -44,10 +45,14 @@ renderToPPM dest cam sc = do
|
||||||
| Nothing => pure $ Right ()
|
| Nothing => pure $ Right ()
|
||||||
|
|
||||||
let pic = render cam sc
|
let pic = render cam sc
|
||||||
for_ (zip (tabulate fst) (concat pic)) $ \(i,[r,g,b]) => do
|
ind <- newIORef 0
|
||||||
setByte buf (cast i * 3) (cast $ r * 255)
|
for_ pic $ traverse_ $ \[r,g,b] => do
|
||||||
setByte buf (cast i * 3 + 1) (cast $ g * 255)
|
i <- readIORef ind
|
||||||
setByte buf (cast i * 3 + 2) (cast $ b * 255)
|
setByte buf (i) (cast $ r * 255)
|
||||||
|
setByte buf (i + 1) (cast $ g * 255)
|
||||||
|
setByte buf (i + 2) (cast $ b * 255)
|
||||||
|
modifyIORef ind (+3)
|
||||||
|
|
||||||
|
|
||||||
_ <- if !(exists dest) then removeFile {io} dest else pure $ Right ()
|
_ <- if !(exists dest) then removeFile {io} dest else pure $ Right ()
|
||||||
Right h <- openFile dest Append
|
Right h <- openFile dest Append
|
||||||
|
|
Loading…
Reference in a new issue