Skip to content

Commit

Permalink
Making separate function for destroying SDL components.
Browse files Browse the repository at this point in the history
  • Loading branch information
smparsons committed Sep 7, 2018
1 parent 233aa9e commit 85c995a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ startEmulator :: String -> Emulator ()
startEmulator filepath = do
initializeChip8State
loadGameByFilePath filepath

(window, renderer, texture) <- liftIO setupSDLComponents

(window, renderer, texture) <- liftIO setupSDLComponents
emulatorLoop renderer texture

SDL.destroyTexture texture
SDL.destroyRenderer renderer
SDL.destroyWindow window
liftIO $ destroySDLComponents window renderer texture

setupSDLComponents :: IO (SDL.Window, SDL.Renderer, SDL.Texture)
setupSDLComponents = do
Expand All @@ -50,6 +45,12 @@ setupSDLComponents = do
texture <- SDL.createTexture renderer SDL.RGBA8888 SDL.TextureAccessStatic (SDL.V2 64 32)
return (window, renderer, texture)

destroySDLComponents :: SDL.Window -> SDL.Renderer -> SDL.Texture -> IO ()
destroySDLComponents window renderer texture = do
SDL.destroyTexture texture
SDL.destroyRenderer renderer
SDL.destroyWindow window

initializeChip8State :: Emulator ()
initializeChip8State = do
newSeed <- liftIO newStdGen
Expand All @@ -66,7 +67,7 @@ emulatorLoop renderer texture = do
hoist emulateCpuCycle
updatedTexture <- drawGraphicsIfNecessary renderer texture

events <- liftIO SDL.pollEvents
events <- liftIO SDL.pollEvents
let userHasQuit = any isQuitEvent events
keyPressChanges = getKeyPressChanges events

Expand Down

0 comments on commit 85c995a

Please sign in to comment.