2021-01-11 09:33:20 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Scenes.Test.Load where
|
|
|
|
|
|
|
|
import qualified Graphics.Rendering.OpenGL as GL
|
|
|
|
|
|
|
|
import qualified Data.Vector.Storable as VS
|
|
|
|
|
|
|
|
import Control.Concurrent.STM
|
|
|
|
|
|
|
|
import Control.Monad (void)
|
|
|
|
|
|
|
|
import Linear
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import Classes
|
|
|
|
import Map
|
|
|
|
import Scenes.Test.Types
|
|
|
|
import Scenes.Test.Util
|
|
|
|
|
|
|
|
load
|
|
|
|
:: Test
|
|
|
|
-> TMVar Progress
|
|
|
|
-> IO ()
|
|
|
|
load level progress = do
|
|
|
|
atomically $ do
|
|
|
|
void $ takeTMVar progress
|
|
|
|
putTMVar progress (0, "Loading test level...")
|
|
|
|
loadedMap <- constructMap testLevelDesc 0
|
|
|
|
atomically $ putTMVar (testMap level) loadedMap
|
|
|
|
void $ atomically $ do
|
|
|
|
void $ takeTMVar progress
|
|
|
|
putTMVar progress (0.5, "Loaded test level map!")
|
|
|
|
void $ atomically $ swapTVar (testLoaded level) True
|
|
|
|
|
|
|
|
let projection = ortho 0 800 0 600 (-1) 1 :: M44 GL.GLfloat
|
|
|
|
view = mkTransformationMat
|
|
|
|
(identity :: M33 GL.GLfloat)
|
|
|
|
(V3 0 ((-64) * 32 + 600) 0)
|
|
|
|
model = mkTransformationMat (identity :: M33 GL.GLfloat) (V3 0 0 0)
|
|
|
|
|
|
|
|
vertexArray <- newVertexArray
|
|
|
|
|
|
|
|
bind vertexArray
|
|
|
|
|
|
|
|
vertexBuffer <- newVertexBuffer 1024
|
|
|
|
|
|
|
|
bind vertexBuffer
|
|
|
|
|
|
|
|
let vertices = VS.fromList (createQuad (V2 (400 - 16) (300 - 16)) 0)
|
|
|
|
|
|
|
|
write vertexBuffer 0 vertices
|
|
|
|
|
|
|
|
indexBuffer <- newIndexBuffer 1024
|
|
|
|
|
|
|
|
bind indexBuffer
|
|
|
|
|
|
|
|
let indices = VS.fromList [0, 1, 2, 2, 3, 0]
|
|
|
|
|
|
|
|
write indexBuffer 0 indices
|
|
|
|
|
|
|
|
addBuffer (undefined :: Vertex) vertexBuffer
|
|
|
|
|
|
|
|
(_, tex) <- newTexture "res/pituicat/pituicat.png" 1
|
|
|
|
bind tex
|
|
|
|
|
|
|
|
shader <- newShader
|
|
|
|
[ ShaderSource GL.VertexShader "./res/shaders/vert.shader"
|
|
|
|
, ShaderSource GL.FragmentShader "./res/shaders/frag.shader"
|
|
|
|
]
|
|
|
|
|
|
|
|
bind shader
|
|
|
|
setUniform shader "u_mvp" (projection !*! view !*! model)
|
|
|
|
setUniformList
|
|
|
|
shader
|
|
|
|
"u_textures"
|
|
|
|
(map
|
|
|
|
textureSlot
|
|
|
|
[ (tileMapTexture $ mapTileMap loadedMap)
|
|
|
|
, tex
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
let pituicat = Pituicat
|
|
|
|
(V2 100 1948)
|
2021-01-14 22:08:24 +00:00
|
|
|
(V2 0 1)
|
2021-01-11 09:33:20 +00:00
|
|
|
(V2 0 0)
|
|
|
|
(V2 0 0)
|
|
|
|
100
|
|
|
|
tex
|
2021-01-11 23:51:58 +00:00
|
|
|
False
|
2021-01-12 02:12:02 +00:00
|
|
|
Nothing
|
2021-01-11 09:33:20 +00:00
|
|
|
|
|
|
|
unbind vertexArray
|
|
|
|
unbind vertexBuffer
|
|
|
|
unbind indexBuffer
|
|
|
|
unbind tex
|
|
|
|
unbind shader
|
|
|
|
|
|
|
|
atomically $ do
|
|
|
|
putTMVar (testGraphics level)
|
|
|
|
(GLAssets vertexArray vertexBuffer indexBuffer shader [tex])
|
2021-01-11 23:51:58 +00:00
|
|
|
writeTVar (testPlayer level) (Just pituicat)
|
2021-01-11 09:33:20 +00:00
|
|
|
writeTVar (testLoaded level) True
|
|
|
|
|
|
|
|
void $ atomically $ do
|
|
|
|
void $ takeTMVar progress
|
|
|
|
putTMVar progress (1, "Loaded graphics!")
|