HGamer3D 0.3.3 → 0.9.5
raw patch · 51 files changed
Files
- HGamer3D.cabal +12/−15
- HGamer3D.hs +197/−84
- HGamer3D/Audio.hs +29/−0
- HGamer3D/Audio/SoundListener.hs +22/−0
- HGamer3D/Audio/SoundSource.hs +58/−0
- HGamer3D/Audio/Volume.hs +41/−0
- HGamer3D/Data.hs +69/−0
- HGamer3D/Data/Angle.hs +102/−0
- HGamer3D/Data/Colour.hs +121/−0
- HGamer3D/Data/GameTime.hs +97/−0
- HGamer3D/Data/Geometry2D.hs +46/−0
- HGamer3D/Data/LMH.hs +53/−0
- HGamer3D/Data/Label.hs +17/−0
- HGamer3D/Data/LogMessage.hs +25/−0
- HGamer3D/Data/Parent.hs +32/−0
- HGamer3D/Data/PlayCmd.hs +49/−0
- HGamer3D/Data/ScreenRect.hs +39/−0
- HGamer3D/Data/Transform3D.hs +60/−0
- HGamer3D/Data/TypeSynonyms.hs +42/−0
- HGamer3D/Data/Vector.hs +75/−0
- HGamer3D/Data/Visible.hs +30/−0
- HGamer3D/Data/Window.hs +30/−0
- HGamer3D/Data/WindowEvent.hs +31/−0
- HGamer3D/GUI.hs +38/−0
- HGamer3D/GUI/Button.hs +39/−0
- HGamer3D/GUI/CheckBox.hs +30/−0
- HGamer3D/GUI/DropDownList.hs +53/−0
- HGamer3D/GUI/EditText.hs +30/−0
- HGamer3D/GUI/Slider.hs +47/−0
- HGamer3D/GUI/Sprite.hs +24/−0
- HGamer3D/GUI/Text.hs +32/−0
- HGamer3D/GUI/UIElement.hs +31/−0
- HGamer3D/Graphics3D.hs +51/−0
- HGamer3D/Graphics3D/Camera.hs +72/−0
- HGamer3D/Graphics3D/Geometry.hs +89/−0
- HGamer3D/Graphics3D/Graphics3DCommand.hs +53/−0
- HGamer3D/Graphics3D/Graphics3DConfig.hs +135/−0
- HGamer3D/Graphics3D/Light.hs +59/−0
- HGamer3D/Graphics3D/Material.hs +150/−0
- HGamer3D/Graphics3D/Particles.hs +26/−0
- HGamer3D/Graphics3D/Scene.hs +30/−0
- HGamer3D/Graphics3D/Skybox.hs +26/−0
- HGamer3D/Graphics3D/Text3D.hs +55/−0
- HGamer3D/Input.hs +37/−0
- HGamer3D/Input/Joystick.hs +148/−0
- HGamer3D/Input/Keyboard.hs +56/−0
- HGamer3D/Input/Mouse.hs +106/−0
- HGamer3D/Util.hs +36/−0
- HGamer3D/Util/FileLocation.hs +50/−0
- HGamer3D/Util/UniqueName.hs +48/−0
- HGamer3D/Util/Variable.hs +55/−0
HGamer3D.cabal view
@@ -1,14 +1,10 @@ Name: HGamer3D -Version: 0.3.3 -Synopsis: A Game Engine for the Haskell Programmer +Version: 0.9.5 +Synopsis: Toolset for the Haskell Game Programmer Description: - HGamer3D is a game engine for developing 3D games in the programming - language Haskell. The game engine uses available libraries for 3D graphics, - sound, input device handling, gui programming and other areas and make - those functions available for the Haskell programmer by providing - a Haskell API on top of that. HGamer3D is available on Windows and Linux. - This package includes 3D Graphics, GUI and WinEvent. - + HGamer3D is a toolset for developing 3D games in the programming + language Haskell. + License: OtherLicense License-file: LICENSE Author: Peter Althainz @@ -18,11 +14,12 @@ Homepage: http://www.hgamer3d.org Category: Game Engine Extra-source-files: Setup.hs - + Library - Build-Depends: base >= 3 && < 5, HGamer3D-Data >= 0.3.0 && < 0.4.0, HGamer3D-Graphics3D >= 0.3.0 && < 0.4.0, HGamer3D-WinEvent >= 0.3.0 && < 0.4.0, HGamer3D-GUI >= 0.3.0 && < 0.4.0 + Build-Depends: base >= 4.9 && < 4.10, containers, bytestring, text, filepath, directory, vect, binary-serialise-cbor, clock, cereal, fresco-binding - Exposed-modules: HGamer3D + Exposed-modules: HGamer3D.Data.Angle, HGamer3D.Data.Colour, HGamer3D.Data.LMH, HGamer3D.Data.GameTime, HGamer3D.Data.ScreenRect, HGamer3D.Data.Transform3D, HGamer3D.Data.Visible, HGamer3D.Data.TypeSynonyms, HGamer3D.Data.Label, HGamer3D.Data.LogMessage, HGamer3D.Data.Vector, HGamer3D.Data.Window, HGamer3D.Data.PlayCmd, HGamer3D.Data.Parent, HGamer3D.Data.Geometry2D, HGamer3D.Data, HGamer3D.Data.WindowEvent, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util.Variable, HGamer3D.Util, HGamer3D.Graphics3D.Scene, HGamer3D.Graphics3D.Skybox, HGamer3D.Graphics3D.Particles, HGamer3D.Graphics3D.Camera, HGamer3D.Graphics3D.Text3D, HGamer3D.Graphics3D.Graphics3DCommand, HGamer3D.Graphics3D.Geometry, HGamer3D.Graphics3D.Graphics3DConfig, HGamer3D.Graphics3D.Light, HGamer3D.Graphics3D.Material, HGamer3D.Input.Mouse, HGamer3D.Input.Keyboard, HGamer3D.Input.Joystick, HGamer3D.Input, HGamer3D.Graphics3D, HGamer3D.GUI.UIElement, HGamer3D.GUI.Sprite, HGamer3D.GUI.Button, HGamer3D.GUI.EditText, HGamer3D.GUI.DropDownList, HGamer3D.GUI.Slider, HGamer3D.GUI.Text, HGamer3D.GUI.CheckBox, HGamer3D.GUI, HGamer3D.Audio.SoundSource, HGamer3D.Audio.SoundListener, HGamer3D.Audio.Volume, HGamer3D.Audio, HGamer3D + Other-modules: c-sources: @@ -30,6 +27,6 @@ ghc-options: cc-options: -Wno-attributes hs-source-dirs: . - Include-dirs: . - build-depends: - extra-libraries: + Include-dirs: . + build-depends: +
HGamer3D.hs view
@@ -1,84 +1,197 @@--- This source file is part of HGamer3D--- (A project to enable 3D game development in Haskell)--- For the latest info, see http://www.althainz.de/HGamer3D.html------ (c) 2014 Peter Althainz------ Licensed under the Apache License, Version 2.0 (the "License");--- you may not use this file except in compliance with the License.--- You may obtain a copy of the License at------ http://www.apache.org/licenses/LICENSE-2.0------ Unless required by applicable law or agreed to in writing, software--- distributed under the License is distributed on an "AS IS" BASIS,--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.--- See the License for the specific language governing permissions and--- limitations under the License.---- HGamer3D Main Module------- | HGamer3D - A game engine for the Haskell Programmer-module HGamer3D --(- HG3DEvent (..),- - module HGamer3D.Graphics3D,- module HGamer3D.WinEvent,- module HGamer3D.GUI,-- loopHGamer3D,- initHGamer3D,- exitHGamer3D- - ) where-- import HGamer3D.Graphics3D hiding (initHGamer3D, loopHGamer3D, exitHGamer3D)- import HGamer3D.WinEvent hiding (initHGamer3D, loopHGamer3D, exitHGamer3D)- import HGamer3D.GUI- import qualified System.Info as SI-- data HG3DEvent = EventWindow SDLEvent | EventGUI [GUIEvent]-- exitHGamer3D :: Graphics3DSystem -> GUISystem -> IO ()- exitHGamer3D g3ds guis = do - exitGraphics3D g3ds--- -- the game loops works in a way, that window events are much faster processed then - -- update of rendering -> all events needs to be cleared, then next renderOneFrame is processed-- loopHGamer3D :: Graphics3DSystem -> GUISystem -> IO (Maybe HG3DEvent, Bool)- loopHGamer3D g3ds guis = do-- -- this one is quite tricky, on Linux we need to call the message loop in addition to WinEvent!- if SI.os /= "mingw32" then graphics3DPumpWindowMessages else return ()- i <- checkQuitReceived-- evt <- pollWinEvent- case evt of- Just sdlEvt -> do- injectWinEventToGUI guis sdlEvt -- inject event into gui- return (Just (EventWindow sdlEvt), (i == 1) )- _ -> do- gevts <- pollGUIEvents guis- if length gevts > 0 then- return (Just (EventGUI gevts), (i == 1) )- else do- renderOneFrame g3ds- return (Nothing, (i == 1) )--- initHGamer3D :: String -- ^ Window Title- -> Bool -- ^ Flag show config dialogue- -> Bool -- ^ Flag logging enabled- -> Bool -- ^ show Graphics Cursor- -> IO (Graphics3DSystem, GUISystem, Camera, Viewport)- initHGamer3D windowTitle fConfigDialogue fLog fGraphicsCursor = do- success <- initWinEvent [WEV_INIT_EVENTS, WEV_INIT_TIMER, WEV_INIT_VIDEO]- (g3ds, camera, viewport, window) <- initGraphics3D windowTitle "DefaultSceneManager" fConfigDialogue fLog- win <- attachToWindow window- guis <- initGUI fLog fGraphicsCursor- return (g3ds, guis, camera, viewport)+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- HGamer3D +-- + +-- | Main module, to include API +module HGamer3D + +( + module Fresco, + module HGamer3D.Data, + module HGamer3D.Util, + module HGamer3D.Graphics3D, + module HGamer3D.Input, + module HGamer3D.GUI, + module HGamer3D.Audio, + + HG3D, + GameLogicFunction, + runGame, + + registerCallback, + isExitHG3D, + resetExitHG3D, + exitHG3D, + newE, + +-- ctParent, + EntityTree (..), + newET, + delET, + + (<:), + (<|), + (-:), + (-|), + + (#) +) + +where + +import Fresco hiding (newE) +import qualified Fresco as F (newE) +import HGamer3D.Data +import HGamer3D.Util +import HGamer3D.Graphics3D +import HGamer3D.Input +import HGamer3D.GUI +import HGamer3D.Audio + +import Control.Concurrent +import Control.Monad +import Control.Concurrent.MVar +import Data.IORef + +import qualified Data.Map as M +import Data.Word +import Data.Maybe + +-- Opaque Value to denote some game-loop data +data HG3D = HG3D ObjectLibSystem CallbackSystem (Var Bool) + +-- runHG3D runs the engine in the main loop (for Mac) and executes game logic +type GameLogicFunction = HG3D -> IO () + +-- runGame, runs the game in the main loop, creates threads for GameLogicFunctions +runGame :: Graphics3DConfig -> GameLogicFunction -> GameTime -> IO () +runGame conf glf loopSleepTime = do + + ols <- createOLS + cbs <- createCBS + varExit <- makeVar False + + let hg3d = HG3D ols cbs varExit + + forkIO $ do + -- create graphics system + eG3D <- newE hg3d [ + ctGraphics3DConfig #: conf, + ctGraphics3DCommand #: NoCmd + ] + + ere <- newE hg3d [ + ctExitRequestedEvent #: () + ] + + -- create callback loop, handle windows exit command + forkIO $ do + registerReceiverCBS cbs ere ctExitRequestedEvent (\_ -> writeVar varExit True >> return ()) + forever $ (stepCBS cbs) + + -- create game logic loop + forkIO $ glf hg3d + + -- create game step loop + let gameStep = do + setC eG3D ctGraphics3DCommand Step + sleepFor loopSleepTime + gameStep + + forkIO $ gameStep + + return () + + -- enter into endless game loop + let loopGame = do + stepOLS ols + ex <- readVar varExit + if ex + then return () + else loopGame + + loopGame + +isExitHG3D (HG3D ols cbs varExit) = do + ise <- readVar varExit + return ise + +resetExitHG3D (HG3D ols cbs varExit) = writeVar varExit False + +exitHG3D (HG3D ols cbs varExit) = do + writeVar varExit True >> return () + +registerCallback (HG3D ols cbs varExit) e ct f = do + registerReceiverCBS cbs e ct f + +newE (HG3D ols cbs varExit) creationList = do + e <- F.newE creationList + addEntityOLS ols e + return e + + + +data EntityTree = ETNode (Maybe String) [(Word64, Component)] + | ETChild (Maybe String) [(Word64, Component)] [EntityTree] + | ETList [EntityTree] + +createET :: HG3D -> EntityTree -> Maybe Entity -> IO [(String, Entity)] + +createET hg3d (ETNode label clist) parent = do + clist' <- case parent of + Just p -> idE p >>= \id -> return ((ctParent #: id) : filter (\(ct, c) -> (ComponentType ct) /= ctParent) clist) + Nothing -> return clist + e <- newE hg3d clist' + case label of + Just l -> return [(l, e)] + Nothing -> return [] + +createET hg3d (ETList tlist) parent = do + l <- mapM (\et -> createET hg3d et parent) tlist + return (Prelude.concat l) + +createET hg3d (ETChild label clist tlist) parent = do + [(_, e1)] <- createET hg3d (ETNode (Just "label") clist) parent + let l1 = case label of + Just l -> [(l, e1)] + Nothing -> [("", e1)] + l2 <- createET hg3d (ETList tlist) (Just e1) + return (l1 ++ l2) + +newET :: HG3D -> [EntityTree] -> IO ([(String, Entity)]) +newET hg3d et = createET hg3d (ETList et) Nothing + +delET :: [(String, Entity)] -> IO () +delET l = mapM (\(s, e) -> delE e) l >> return () + +(<:) :: String -> [(Word64, Component)] -> EntityTree +label <: clist = ETNode (Just label) clist + +(<|) :: String -> ([(Word64, Component)], [EntityTree]) -> EntityTree +label <| (clist, tlist) = ETChild (Just label) clist tlist + +(-:) :: () -> [(Word64, Component)] -> EntityTree +() -: clist = ETNode Nothing clist + +(-|) :: () -> ([(Word64, Component)], [EntityTree]) -> EntityTree +() -| (clist, tlist) = ETChild Nothing clist tlist + +(#) :: [(String, Entity)] -> String -> Entity +m # s = snd . head $ (filter (\(s', e) -> s == s') m)
+ HGamer3D/Audio.hs view
@@ -0,0 +1,29 @@+{- + Sound and Music + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Audio.hs +-} + + +-- | Audio for HGamer3D +module HGamer3D.Audio + +( + module HGamer3D.Audio.SoundSource + , module HGamer3D.Audio.SoundListener + , module HGamer3D.Audio.Volume +) + +where + +import HGamer3D.Audio.SoundSource +import HGamer3D.Audio.SoundListener +import HGamer3D.Audio.Volume + +
+ HGamer3D/Audio/SoundListener.hs view
@@ -0,0 +1,22 @@+{- + Audio: Listener for sound, specifies mainyl the position for 3D sound + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Audio/SoundListener.hs +-} + +-- | Sound Listener +module HGamer3D.Audio.SoundListener +where + +import Fresco + +type SoundListener = () + +ctSoundListener :: ComponentType SoundListener +ctSoundListener = ComponentType 0x7aacf4ee5bd2f958
+ HGamer3D/Audio/SoundSource.hs view
@@ -0,0 +1,58 @@+{- + Sound Source + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Audio/SoundSource.hs +-} + +-- | Module providing a Sound Source +module HGamer3D.Audio.SoundSource +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Decoding +import Data.Binary.Serialise.CBOR.Encoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +data SoundType = Sound + | Sound3D + | Music + deriving (Eq, Read, Show) + +data SoundSource = SoundSource { + soundSourceType::SoundType, + soundSourceResource::Text, + soundSourceLoop::Bool, + soundSourceVolume::Float, + soundSourceVolumeGroup::Text + } deriving (Eq, Read, Show) + +ctSoundSource :: ComponentType SoundSource +ctSoundSource = ComponentType 0xafcef7aa41d88c0d + +instance Serialise SoundType where + encode (Sound) = encodeListLen 1 <> encode (0::Int) + encode (Sound3D) = encodeListLen 1 <> encode (1::Int) + encode (Music) = encodeListLen 1 <> encode (2::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure Sound) + 1 -> (pure Sound3D) + 2 -> (pure Music) + +instance Serialise SoundSource where + encode (SoundSource v1 v2 v3 v4 v5) = encodeListLen 5 <> encode v1 <> encode v2 <> encode v3 <> encode v4 <> encode v5 + decode = decodeListLenOf 5 >> SoundSource <$> decode <*> decode <*> decode <*> decode <*> decode + +
+ HGamer3D/Audio/Volume.hs view
@@ -0,0 +1,41 @@+{- + Audio: Master Volume for different categories + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Audio/Volume.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.Audio.Volume +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Volume = Volume { + volumeGroup::Text, + volumeGain::Float + } deriving (Eq, Read, Show) + +ctVolume :: ComponentType Volume +ctVolume = ComponentType 0x659d20e6e65f85fe + +instance Serialise Volume where + encode (Volume v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> Volume <$> decode <*> decode + + + +
+ HGamer3D/Data.hs view
@@ -0,0 +1,69 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2015 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- HGamer3D/Data.hs +-- + +-- | Common data definitions for HGamer3D +module HGamer3D.Data + +( + -- * Baisc Datatypes + module HGamer3D.Data.Angle, + module HGamer3D.Data.Colour, + module HGamer3D.Data.LMH, + module HGamer3D.Data.GameTime, + module HGamer3D.Data.Visible, + module HGamer3D.Data.Label, + module HGamer3D.Data.LogMessage, + + -- * Geometry Datatypes + module HGamer3D.Data.Vector, + module HGamer3D.Data.ScreenRect, + module HGamer3D.Data.Geometry2D, + module HGamer3D.Data.Transform3D, + module HGamer3D.Data.TypeSynonyms, + + -- * Misc + module HGamer3D.Data.PlayCmd, + module HGamer3D.Data.Parent, + + -- * Implementation + module HGamer3D.Data.Window, + module HGamer3D.Data.WindowEvent +) + +where + +import HGamer3D.Data.Angle +import HGamer3D.Data.Colour +import HGamer3D.Data.LMH +import HGamer3D.Data.GameTime +import HGamer3D.Data.Visible +import HGamer3D.Data.Label +import HGamer3D.Data.LogMessage +import HGamer3D.Data.ScreenRect +import HGamer3D.Data.Geometry2D +import HGamer3D.Data.Transform3D +import HGamer3D.Data.TypeSynonyms +import HGamer3D.Data.Vector +import HGamer3D.Data.Window +import HGamer3D.Data.WindowEvent +import HGamer3D.Data.PlayCmd +import HGamer3D.Data.Parent +
+ HGamer3D/Data/Angle.hs view
@@ -0,0 +1,102 @@+{- + Datatypes to specify a geometric angle + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Angle.hs +-} + +-- | Angles as Degrees or Radians, based on Float datatype +module HGamer3D.Data.Angle + +( + -- * Data definitions and conversions + Angle (..), + asRad, + asDeg, + + -- * Mathematical functions + addA, + subA, + mulA, + divA, + sinA, + cosA, + tanA, + asinA, + acosA, + atanA, +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Angle = Rad Float + | Deg Float + deriving (Eq, Read, Show) + +instance Serialise Angle where + encode (Rad v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + encode (Deg v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (Rad <$> decode) + 1 -> (Deg <$> decode) + + +-- | value of an Angle as radiant +asRad :: Angle -> Float +asRad (Rad f) = f +asRad (Deg d) = d/180*pi + +-- | value of an Angle as degree +asDeg :: Angle -> Float +asDeg (Deg f) = f +asDeg (Rad d) = d/pi*180 + + +sinA :: Angle -> Float +sinA = sin . asRad + +cosA :: Angle -> Float +cosA = cos . asRad + +tanA :: Angle -> Float +tanA = tan . asRad + +asinA :: Float -> Angle +asinA = Rad . asin + +acosA :: Float -> Angle +acosA = Rad . acos + +atanA :: Float -> Angle +atanA = Rad . atan + +addA :: Angle -> Angle -> Angle +addA a b = Rad $ (asRad a) + (asRad b) + +subA :: Angle -> Angle -> Angle +subA a b = Rad $ (asRad a) - (asRad b) + +mulA :: Angle -> Float -> Angle +mulA a b = Rad $ (asRad a) * b + +divA :: Angle -> Float -> Angle +divA a b = Rad $ (asRad a) / b +
+ HGamer3D/Data/Colour.hs view
@@ -0,0 +1,121 @@+{- + Datatypes to specify a geometric angle + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Colour.hs +-} + +-- | The Colour type and some standard colours +module HGamer3D.Data.Colour + +( + Colour (..), + ctColour, + white, + silver, + grey, + darkgrey, + black, + red, + maroon, + yellow, + olive, + lime, + green, + aqua, + teal, + blue, + navy, + fuchsia, + purple +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Decoding +import Data.Binary.Serialise.CBOR.Encoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Colour = Colour { + colourRed::Float, + colourGreen::Float, + colourBlue::Float, + colourAlpha::Float + } deriving (Eq, Read, Show) + +ctColour :: ComponentType Colour +ctColour = ComponentType 0xe202add0521cde41 + + +instance Serialise Colour where + encode (Colour v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> Colour <$> decode <*> decode <*> decode <*> decode + + + +-- generated + +white :: Colour +white = Colour 1.0 1.0 1.0 1.0 + +silver:: Colour +silver = Colour 0.75 0.75 0.75 1.0 + +grey:: Colour +grey = Colour 0.5 0.5 0.5 1.0 + +darkgrey :: Colour +darkgrey = Colour 0.25 0.25 0.25 1.0 + +black :: Colour +black = Colour 0.0 0.0 0.0 1.0 + +red :: Colour +red = Colour 1.0 0.0 0.0 1.0 + +maroon :: Colour +maroon = Colour 0.5 0.0 0.0 1.0 + +yellow :: Colour +yellow = Colour 1.0 1.0 0.0 1.0 + +olive :: Colour +olive = Colour 0.5 0.5 0.0 1.0 + +lime :: Colour +lime = Colour 0.0 1.0 0.0 1.0 + +green :: Colour +green = Colour 0.0 0.5 0.0 1.0 + +aqua :: Colour +aqua = Colour 0.0 1.0 1.0 1.0 + +teal :: Colour +teal = Colour 0.0 0.5 0.5 1.0 + +blue :: Colour +blue = Colour 0.0 0.0 1.0 1.0 + +navy :: Colour +navy = Colour 0.0 0.0 0.5 1.0 + +fuchsia :: Colour +fuchsia = Colour 1.0 0.0 1.0 1.0 + +purple :: Colour +purple = Colour 0.5 0.0 0.5 1.0 + + +
+ HGamer3D/Data/GameTime.hs view
@@ -0,0 +1,97 @@+{- + Time datatypes and functions + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/GameTime.hs +-} + + +{-# LANGUAGE TypeSynonymInstances, CPP #-} + +-- | The time type for HGamer3D +module HGamer3D.Data.GameTime + +( + GameTime, + + -- * functions, to convert time into a value + sec, + msec, + usec, + + -- * functions to create a time from a value + secT, + msecT, + usecT, + + -- * functions, which handle different aspects of time + getTime, + getThreadCPUTime, + getProcessCPUTime, + sleepFor +) + +where + +import Control.Concurrent +import qualified System.Clock as C + +type GameTime = C.TimeSpec + +_toInteger :: C.TimeSpec -> Integer +_toInteger ts = let + s = (fromIntegral (C.sec ts)) :: Integer + ns = (fromIntegral (C.nsec ts)) :: Integer + in s * 1000000000 + ns + +_fromInteger :: Integer -> C.TimeSpec +_fromInteger i = let + s = fromIntegral (i `quot` 1000000000) + ns = fromIntegral (i `rem` 1000000000) + in C.TimeSpec s ns + +-- | time to seconds +sec :: C.TimeSpec -> Int +sec ts = fromIntegral ((_toInteger ts) `quot` 1000000000) + +-- | time to milliseconds +msec :: C.TimeSpec -> Int +msec ts = fromIntegral ((_toInteger ts) `quot` 1000000) + +-- | time to microseconds +usec :: C.TimeSpec -> Int +usec ts = fromIntegral ((_toInteger ts) `quot` 1000) + +-- | create time from seconds +secT :: Int -> C.TimeSpec +secT i = _fromInteger ((fromIntegral i) * 1000000000) + +-- | create time from milliseconds +msecT :: Int -> C.TimeSpec +msecT i = _fromInteger ((fromIntegral i) * 1000000) + +-- | create time from microseconds +usecT :: Int -> C.TimeSpec +usecT i = _fromInteger ((fromIntegral i) * 1000) + +-- | get current time +getTime :: IO GameTime +getTime = C.getTime C.Realtime + +-- | get thread time +getThreadCPUTime :: IO GameTime +getThreadCPUTime = C.getTime C.ThreadCPUTime + +-- | get process cpu time +getProcessCPUTime :: IO GameTime +getProcessCPUTime = C.getTime C.ProcessCPUTime + +-- | sleep for time intervall +sleepFor :: GameTime -> IO () +sleepFor gt = threadDelay (usec gt) +
+ HGamer3D/Data/Geometry2D.hs view
@@ -0,0 +1,46 @@+{- + 2D Geometry + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Geometry2D.hs +-} + +{-# LANGUAGE FlexibleInstances #-} + +-- | Type definitions for 2D geometry +module HGamer3D.Data.Geometry2D +where + +import HGamer3D.Data.ScreenRect +import Fresco +import Data.Int + +-- | A point has two coordinates an x and y one +data Point = Point { + ptX :: Int, + ptY :: Int + } deriving (Eq, Show) + +-- | derive a rectangle from upper left and lower right points +rectFromPoints :: (Point, Point) -> ScreenRect +rectFromPoints (upperLeft, lowerRight) = ScreenRect rx ry rw rh where + rx = ptX upperLeft + ry = ptY upperLeft + rw = (ptY lowerRight) - rx + rh = (ptY lowerRight) - ry + +-- | get upper left and lower right point from a rect +pointsFromRect :: ScreenRect -> (Point, Point) +pointsFromRect rect = (ul, lr) where + rx = screenRectX rect + ry = screenRectY rect + rx' = rx + (screenRectWidth rect) + ry' = ry + (screenRectHeight rect) + ul = Point rx ry + lr = Point rx' ry' +
+ HGamer3D/Data/LMH.hs view
@@ -0,0 +1,53 @@+{- + Low, Medium, High Datatype + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/LMH.hs +-} + +-- | Data type to specify a 3 choice volume of anything: Low, Medium, High +module HGamer3D.Data.LMH +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type Switch = Bool + +ctSwitch :: ComponentType Switch +ctSwitch = ComponentType 0x30b235f8b63df8b0 + +data LMH = Low + | Medium + | High + deriving (Eq, Read, Show) + +type QualityLMH = LMH + +ctQualityLMH :: ComponentType QualityLMH +ctQualityLMH = ComponentType 0xd632bb5447a6c93c + +instance Serialise LMH where + encode (Low) = encodeListLen 1 <> encode (0::Int) + encode (Medium) = encodeListLen 1 <> encode (1::Int) + encode (High) = encodeListLen 1 <> encode (2::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure Low) + 1 -> (pure Medium) + 2 -> (pure High) +
+ HGamer3D/Data/Label.hs view
@@ -0,0 +1,17 @@+module HGamer3D.Data.Label where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type Label = Text + +ctLabel :: ComponentType Label +ctLabel = ComponentType 0xf98939ae4b0d693a +
+ HGamer3D/Data/LogMessage.hs view
@@ -0,0 +1,25 @@+module HGamer3D.Data.LogMessage where + +import Fresco +import HGamer3D.Graphics3D.Graphics3DConfig +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data LogMessage = LogMessage { + logMessageLevel::LogLevel, + logMessageMessage::Text + } deriving (Eq, Read, Show) + +ctLogMessage :: ComponentType LogMessage +ctLogMessage = ComponentType 0x1c94738af20a0ac6 + +instance Serialise LogMessage where + encode (LogMessage v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> LogMessage <$> decode <*> decode +
+ HGamer3D/Data/Parent.hs view
@@ -0,0 +1,32 @@+{- + Datatypes to specify a parent by id + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Colour.hs +-} + +-- | The Parent component type +module HGamer3D.Data.Parent + +( + Parent, + ctParent +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Decoding +import Data.ByteString.Lazy + +type Parent = ByteString + +ctParent :: ComponentType Parent +ctParent = ComponentType 0xbadd24df00e737d8 +
+ HGamer3D/Data/PlayCmd.hs view
@@ -0,0 +1,49 @@+{- + The Play Command + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/PlayCmd.hs +-} + +-- | Type for a generic play command +module HGamer3D.Data.PlayCmd +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data PlayCmd = Play + | Pause + | Stop + deriving (Eq, Read, Show) + +ctPlayCmd :: ComponentType PlayCmd +ctPlayCmd = ComponentType 0x35f7752020f7f1cd + +instance Serialise PlayCmd where + encode (Play) = encodeListLen 1 <> encode (0::Int) + encode (Pause) = encodeListLen 1 <> encode (1::Int) + encode (Stop) = encodeListLen 1 <> encode (2::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure Play) + 1 -> (pure Pause) + 2 -> (pure Stop) + + + +
+ HGamer3D/Data/ScreenRect.hs view
@@ -0,0 +1,39 @@+{- + Datatypes to specify a geometric angle + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/ScreenRect.hs +-} + +module HGamer3D.Data.ScreenRect + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data ScreenRect = ScreenRect { + screenRectX::Int, + screenRectY::Int, + screenRectWidth::Int, + screenRectHeight::Int + } deriving (Eq, Read, Show) + +ctScreenRect :: ComponentType ScreenRect +ctScreenRect = ComponentType 0x16877957e32da6b1 + +instance Serialise ScreenRect where + encode (ScreenRect v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> ScreenRect <$> decode <*> decode <*> decode <*> decode
+ HGamer3D/Data/Transform3D.hs view
@@ -0,0 +1,60 @@+{- + Transformation of 3D entities by scale, position, ... + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Transform3D.hs +-} + +-- | Functions for basic 3D transformations +module HGamer3D.Data.Transform3D +( + translate, + scale, + yaw, + pitch, + roll +) + +where + +import HGamer3D.Data.Vector +import HGamer3D.Data.Angle + +type Position = Vec3 +type Orientation = UnitQuaternion +type Size = Vec3 + +-- | move the position +translate :: Position -> Position -> Position +translate = (&+) + +-- | scale the size +scale :: Size -> Vec3 -> Size +scale = (&!) + +-- yaw, roll, pitch functions +-- functions, to rotate on axis, relative to object +rotRelativeToObjectAxis :: Orientation -> Vec3 -> Float -> Orientation +rotRelativeToObjectAxis ori axis val = let + odir = actU ori axis + qrot = rotU odir val + nrot = qrot .*. ori + in nrot + +-- | rotate object on own axis (yaw) by angle +yaw :: Orientation -> Angle -> Orientation +yaw ori val = rotRelativeToObjectAxis ori vec3Y (asRad val) + +-- | rotate object on own axis (roll) by angle +roll :: Orientation -> Angle -> Orientation +roll ori val = rotRelativeToObjectAxis ori vec3Z (asRad val) + +-- | rotate object on own axis (pitch) by angle +pitch :: Orientation -> Angle -> Orientation +pitch ori val = rotRelativeToObjectAxis ori vec3X (asRad val) +
+ HGamer3D/Data/TypeSynonyms.hs view
@@ -0,0 +1,42 @@+{- + Transformation of 3D entities by scale, position, ... + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/TypeSynonyms.hs +-} + +-- | Some common type synonyms +module HGamer3D.Data.TypeSynonyms + +where + +import Fresco +import HGamer3D.Data.Vector + +-- | Size implemented as a Vec3 +type Scale = Vec3 + +-- | Position implemented as a Vec3 +type Position = Vec3 + +-- | Orientation implemented as a UnitQuaternion +type Orientation = UnitQuaternion + +-- properties +ctPosition :: ComponentType Position +ctPosition = ComponentType 0x29aacbbb10c84016 + +ctScale :: ComponentType Scale +ctScale = ComponentType 0x2f9c124bc8fd41c4 + +-- HGamer3D website, entities and events, example ComponentType +ctOrientation :: ComponentType Orientation +ctOrientation = ComponentType 0x815eb4d9c7bfaa74 +-- end of website text + +
+ HGamer3D/Data/Vector.hs view
@@ -0,0 +1,75 @@+{- + Vector library, imported from package Vect + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Vector.hs +-} + +{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving #-} + +-- | Vector library for HGamer3D +module HGamer3D.Data.Vector +( + + -- * the Vect libray of Balazs Komuves, see: <http://hackage.haskell.org/package/vect> + + module Data.Vect.Float, + module Data.Vect.Float.Util.Quaternion, + + -- * some constants + + zeroVec2, + unitVec2, + + zeroVec3, + unitVec3 + +) + +where + +import Data.Vect.Float +import Data.Vect.Float.Util.Quaternion + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Decoding +import Data.Binary.Serialise.CBOR.Encoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +deriving instance Eq UnitQuaternion +deriving instance Eq Vec2 +deriving instance Eq Vec3 +deriving instance Eq Vec4 + + +-- | the 2d zero vector +zeroVec2 = Vec2 0.0 0.0 + +-- | the 2d unity vector +unitVec2 = Vec2 1.0 1.0 + +-- | the 3d Zero vector +zeroVec3 = Vec3 0.0 0.0 0.0 + +-- | the 3d Unity vector +unitVec3 = Vec3 1.0 1.0 1.0 + +instance Serialise Vec3 where + encode (Vec3 v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> Vec3 <$> decode <*> decode <*> decode + +instance Serialise UnitQuaternion where + encode (U (Vec4 v1 v2 v3 v4)) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> do + v <- Vec4 <$> decode <*> decode <*> decode <*> decode + return $ U v +
+ HGamer3D/Data/Visible.hs view
@@ -0,0 +1,30 @@+{- + Visible Datatype + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Visible.hs +-} + +-- | Data type to specify if something is visible +module HGamer3D.Data.Visible +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type Visible = Bool + +ctVisible :: ComponentType Visible +ctVisible = ComponentType 0x98e7a78e949e1c6e
+ HGamer3D/Data/Window.hs view
@@ -0,0 +1,30 @@+{- + The Window Instance Type + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Data/Window.hs +-} + +-- | Type for a system window as its window handle +module HGamer3D.Data.Window +( + -- * A Window Handle as Int + Window (..), + ctWindow + +) where + +import Fresco + +type Window = Int + +-- properties +ctWindow :: ComponentType Window +ctWindow = ComponentType 0xad5b3c63f7f7dd1b + +
+ HGamer3D/Data/WindowEvent.hs view
@@ -0,0 +1,31 @@+module HGamer3D.Data.WindowEvent where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data ScreenModeEvent = ScreenModeEvent { + screenModeEventWidth::Int, + screenModeEventHeight::Int, + screenModeEventFullscreen::Bool, + screenModeEventBorderless::Bool + } deriving (Eq, Read, Show) + +ctScreenModeEvent :: ComponentType ScreenModeEvent +ctScreenModeEvent = ComponentType 0x7534a286d000125c + +type ExitRequestedEvent = () + +ctExitRequestedEvent :: ComponentType ExitRequestedEvent +ctExitRequestedEvent = ComponentType 0xbd86f89ddca9280f + +instance Serialise ScreenModeEvent where + encode (ScreenModeEvent v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> ScreenModeEvent <$> decode <*> decode <*> decode <*> decode +
+ HGamer3D/GUI.hs view
@@ -0,0 +1,38 @@+{- + Graphical User Interface - GUI + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI.hs +-} + +-- | GUI for HGamer3D +module HGamer3D.GUI + +( + module HGamer3D.GUI.Button + , module HGamer3D.GUI.EditText + , module HGamer3D.GUI.Text + , module HGamer3D.GUI.Slider + , module HGamer3D.GUI.DropDownList + , module HGamer3D.GUI.CheckBox + , module HGamer3D.GUI.Sprite +) + + +where + +import HGamer3D.GUI.UIElement +import HGamer3D.GUI.Button +import HGamer3D.GUI.EditText +import HGamer3D.GUI.Text +import HGamer3D.GUI.Slider +import HGamer3D.GUI.DropDownList +import HGamer3D.GUI.CheckBox +import HGamer3D.GUI.Sprite + +
+ HGamer3D/GUI/Button.hs view
@@ -0,0 +1,39 @@+{- + GUI: Button functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/Button.hs +-} + +-- | Module providing the Button functionality and settings +module HGamer3D.GUI.Button +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Button = Button { + buttonPressed::Bool, + buttonLabel::Text + } deriving (Eq, Read, Show) + +ctButton :: ComponentType Button +ctButton = ComponentType 0x68a1857c27690b30 + +instance Serialise Button where + encode (Button v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> Button <$> decode <*> decode + +
+ HGamer3D/GUI/CheckBox.hs view
@@ -0,0 +1,30 @@+{- + GUI: Checkbox functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/CheckBox.hs +-} + +-- | Module providing the CheckBox gui element +module HGamer3D.GUI.CheckBox +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type CheckBox = Bool + +ctCheckBox :: ComponentType CheckBox +ctCheckBox = ComponentType 0xd2425f880fcdd9a4
+ HGamer3D/GUI/DropDownList.hs view
@@ -0,0 +1,53 @@+{- + GUI: DropDownList functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/DropDownList.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.GUI.DropDownList +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data TextSelection = Selection Int + | NoSelection + deriving (Eq, Read, Show) + +data DropDownList = DropDownList { + dropDownListContent::[Text], + dropDownListSelected::TextSelection + } deriving (Eq, Read, Show) + +ctDropDownList :: ComponentType DropDownList +ctDropDownList = ComponentType 0x200de0e837a8e590 + +instance Serialise TextSelection where + encode (Selection v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + encode (NoSelection) = encodeListLen 1 <> encode (1::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (Selection <$> decode) + 1 -> (pure NoSelection) + +instance Serialise DropDownList where + encode (DropDownList v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> DropDownList <$> decode <*> decode + +
+ HGamer3D/GUI/EditText.hs view
@@ -0,0 +1,30 @@+{- + GUI: EditText functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/EditText.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.GUI.EditText +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type EditText = Text + +ctEditText :: ComponentType EditText +ctEditText = ComponentType 0x8c79de2199331f3a
+ HGamer3D/GUI/Slider.hs view
@@ -0,0 +1,47 @@+{- + GUI: Slider functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/Slider.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.GUI.Slider +( + ctSlider, + Slider (..) +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Slider = Slider { + sliderRange::Float, + sliderValue::Float + } deriving (Eq, Read, Show) + +ctSlider :: ComponentType Slider +ctSlider = ComponentType 0x60636b107c77a533 + +instance Serialise Slider where + encode (Slider v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> Slider <$> decode <*> decode + + + + +
+ HGamer3D/GUI/Sprite.hs view
@@ -0,0 +1,24 @@+module HGamer3D.GUI.Sprite where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Sprite = Sprite { + spriteResource::Text, + spriteOpacity::Float + } deriving (Eq, Read, Show) + +ctSprite :: ComponentType Sprite +ctSprite = ComponentType 0x39b4f64b33f5cb41 + +instance Serialise Sprite where + encode (Sprite v1 v2) = encodeListLen 2 <> encode v1 <> encode v2 + decode = decodeListLenOf 2 >> Sprite <$> decode <*> decode +
+ HGamer3D/GUI/Text.hs view
@@ -0,0 +1,32 @@+{- + GUI: Text functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/Text.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.GUI.Text +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type StaticText = Text + +ctStaticText :: ComponentType StaticText +ctStaticText = ComponentType 0xda9601eaf3319280 + +
+ HGamer3D/GUI/UIElement.hs view
@@ -0,0 +1,31 @@+{- + GUI: Button functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/Button.hs +-} + +-- | Module providing the Button functionality and settings +module HGamer3D.GUI.UIElement +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +type UIElement = () + +ctUIElement :: ComponentType UIElement +ctUIElement = ComponentType 0xd5b79f5837e52274 +
+ HGamer3D/Graphics3D.hs view
@@ -0,0 +1,51 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2015 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- HGamer3D/Graphics3D.hs +-- + +-- | 3D Graphics for HGamer3D +module HGamer3D.Graphics3D + +( + module HGamer3D.Graphics3D.Camera, + module HGamer3D.Graphics3D.Geometry, + module HGamer3D.Graphics3D.Light, + module HGamer3D.Graphics3D.Material, + module HGamer3D.Graphics3D.Graphics3DCommand, + module HGamer3D.Graphics3D.Graphics3DConfig, + module HGamer3D.Graphics3D.Scene, + module HGamer3D.Graphics3D.Skybox, + module HGamer3D.Graphics3D.Text3D, + module HGamer3D.Graphics3D.Particles, +) + +where + +import HGamer3D.Graphics3D.Camera +import HGamer3D.Graphics3D.Geometry +import HGamer3D.Graphics3D.Light +import HGamer3D.Graphics3D.Material +import HGamer3D.Graphics3D.Graphics3DCommand +import HGamer3D.Graphics3D.Graphics3DConfig +import HGamer3D.Graphics3D.Scene +import HGamer3D.Graphics3D.Skybox +import HGamer3D.Graphics3D.Text3D +import HGamer3D.Graphics3D.Particles + +
+ HGamer3D/Graphics3D/Camera.hs view
@@ -0,0 +1,72 @@+{- + Camera Datatype + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011-2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Graphics3D/Camera.hs +-} + +-- | Module providing the Camera type +module HGamer3D.Graphics3D.Camera + +( + Camera (..), + ctCamera, + + Frustum (..), + ctFrustum +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +import HGamer3D.Data.Angle +import HGamer3D.Data.ScreenRect + +data Camera = FullViewCamera + | OverlayCamera ScreenRect Float + deriving (Eq, Read, Show) + +ctCamera :: ComponentType Camera +ctCamera = ComponentType 0xd3b0d455ab1f4716 + +data Frustum = Frustum { + frustumNearDistance::Float, + frustumFarDistance::Float, + frustumFieldOfViewHorizontal::Angle + } deriving (Eq, Read, Show) + +ctFrustum :: ComponentType Frustum +ctFrustum = ComponentType 0xf3ce3235d4f8e73d + +instance Serialise Camera where + encode (FullViewCamera) = encodeListLen 1 <> encode (0::Int) + encode (OverlayCamera v1 v2) = encodeListLen 3 <> encode (1::Int) <> encode v1<> encode v2 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure FullViewCamera) + 1 -> (OverlayCamera <$> decode <*> decode) + +instance Serialise Frustum where + encode (Frustum v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> Frustum <$> decode <*> decode <*> decode + + + + + +
+ HGamer3D/Graphics3D/Geometry.hs view
@@ -0,0 +1,89 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- HGamer3D/Graphics3D/Geometry.hs + +-- | Module providing the Geometry type +module HGamer3D.Graphics3D.Geometry + +( + Shape (..), + Geometry (..), + ctGeometry, + ctGraphicsElement +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Shape = Sphere + | Cube + | Plane + | Cylinder + | Pyramid + | Torus + deriving (Eq, Read, Show) + +data Geometry = ShapeGeometry Shape + | ResourceGeometry Text + deriving (Eq, Read, Show) + +ctGeometry :: ComponentType Geometry +ctGeometry = ComponentType 0xee433d1a4b964591 + +ctGraphicsElement :: ComponentType () +ctGraphicsElement = ComponentType 0x65114ba821671643 + +instance Serialise Shape where + encode (Sphere) = encodeListLen 1 <> encode (0::Int) + encode (Cube) = encodeListLen 1 <> encode (1::Int) + encode (Plane) = encodeListLen 1 <> encode (2::Int) + encode (Cylinder) = encodeListLen 1 <> encode (3::Int) + encode (Pyramid) = encodeListLen 1 <> encode (4::Int) + encode (Torus) = encodeListLen 1 <> encode (5::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure Sphere) + 1 -> (pure Cube) + 2 -> (pure Plane) + 3 -> (pure Cylinder) + 4 -> (pure Pyramid) + 5 -> (pure Torus) + +instance Serialise Geometry where + encode (ShapeGeometry v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + encode (ResourceGeometry v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (ShapeGeometry <$> decode) + 1 -> (ResourceGeometry <$> decode) + +
+ HGamer3D/Graphics3D/Graphics3DCommand.hs view
@@ -0,0 +1,53 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- HGamer3D/Graphics3D/Graphics3DCommand.hs + +-- | Module providing the CmdGraphics3D type +module HGamer3D.Graphics3D.Graphics3DCommand +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Graphics3DCommand = NoCmd + | Step + deriving (Eq, Read, Show) + + +instance Serialise Graphics3DCommand where + encode (NoCmd) = encodeListLen 1 <> encode (0::Int) + encode (Step) = encodeListLen 1 <> encode (1::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure NoCmd) + 1 -> (pure Step) + + +ctGraphics3DCommand :: ComponentType Graphics3DCommand +ctGraphics3DCommand = ComponentType 0xea06bc20a9334af3 +
+ HGamer3D/Graphics3D/Graphics3DConfig.hs view
@@ -0,0 +1,135 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- file: HGamer3D/Graphics3D/Graphics3DConfig.hs + +{-# LANGUAGE OverloadedStrings #-} + +module HGamer3D.Graphics3D.Graphics3DConfig +where + +-- output sinopia starts here + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Decoding +import Data.Binary.Serialise.CBOR.Encoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +import HGamer3D.Data.LMH + + +data EngineConfig = EngineConfig { + engineConfigHeadless::Bool, + engineConfigFlushGPU::Bool, + engineConfigThreads::Bool, + engineConfigForceGL2::Bool + } deriving (Eq, Read, Show) + + +data LogLevel = Warning + | Info + | Debug + deriving (Eq, Read, Show) + + +data Logging = Logging { + loggingLogLevel::LogLevel, + loggingQuietLogging::Bool, + loggingLogFileName::Text + } deriving (Eq, Read, Show) + + +data WindowG3D = WindowG3D { + windowG3DWidth::Int, + windowG3DHeight::Int, + windowG3DBorderless::Bool, + windowG3DFullScreen::Bool, + windowG3DResizable::Bool + } deriving (Eq, Read, Show) + + +data GraphicsQuality = GraphicsQuality { + graphicsQualityShadow::LMH, + graphicsQualityMaterial::LMH, + graphicsQualityTexture::LMH, + graphicsQualityMultisample::LMH + } deriving (Eq, Read, Show) + + +data Graphics3DConfig = Graphics3DConfig { + graphics3DConfigEngine::EngineConfig, + graphics3DConfigQuality::GraphicsQuality, + graphics3DConfigLogging::Logging, + graphics3DConfigWindow::WindowG3D + } deriving (Eq, Read, Show) + + +ctGraphics3DConfig :: ComponentType Graphics3DConfig +ctGraphics3DConfig = ComponentType 0x884eb62b6674bff + +instance Serialise EngineConfig where + encode (EngineConfig v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> EngineConfig <$> decode <*> decode <*> decode <*> decode + +instance Serialise LogLevel where + encode (Warning) = encodeListLen 1 <> encode (0::Int) + encode (Info) = encodeListLen 1 <> encode (1::Int) + encode (Debug) = encodeListLen 1 <> encode (2::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure Warning) + 1 -> (pure Info) + 2 -> (pure Debug) + +instance Serialise Logging where + encode (Logging v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> Logging <$> decode <*> decode <*> decode + +instance Serialise WindowG3D where + encode (WindowG3D v1 v2 v3 v4 v5) = encodeListLen 5 <> encode v1 <> encode v2 <> encode v3 <> encode v4 <> encode v5 + decode = decodeListLenOf 5 >> WindowG3D <$> decode <*> decode <*> decode <*> decode <*> decode + +instance Serialise GraphicsQuality where + encode (GraphicsQuality v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> GraphicsQuality <$> decode <*> decode <*> decode <*> decode + +instance Serialise Graphics3DConfig where + encode (Graphics3DConfig v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> Graphics3DConfig <$> decode <*> decode <*> decode <*> decode + + + + +-- output sinopia ends here + +standardGraphics3DConfig = Graphics3DConfig + (EngineConfig False False True False) + (GraphicsQuality Medium Medium Medium Medium) + (Logging Debug False "hgamer3d.log") + (WindowG3D 800 600 False False True) + + + + +
+ HGamer3D/Graphics3D/Light.hs view
@@ -0,0 +1,59 @@+{- + Light Datatype + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2011 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Graphics3D/Light.hs +-} + +-- | Module providing the Light type +module HGamer3D.Graphics3D.Light +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +import HGamer3D.Data.Angle + + +data LightType = PointLight + | DirectionalLight + | SpotLight Angle Float + deriving (Eq, Read, Show) + +data Light = Light { + lightType::LightType, + lightBrightness::Float, + lightRange::Float, + lightSpecularIntensity::Float + } deriving (Eq, Read, Show) + +ctLight :: ComponentType Light +ctLight = ComponentType 0x981e80e50d994ea9 + +instance Serialise LightType where + encode (PointLight) = encodeListLen 1 <> encode (0::Int) + encode (DirectionalLight) = encodeListLen 1 <> encode (1::Int) + encode (SpotLight v1 v2) = encodeListLen 3 <> encode (2::Int) <> encode v1<> encode v2 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure PointLight) + 1 -> (pure DirectionalLight) + 2 -> (SpotLight <$> decode <*> decode) + +instance Serialise Light where + encode (Light v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> Light <$> decode <*> decode <*> decode <*> decode +
+ HGamer3D/Graphics3D/Material.hs view
@@ -0,0 +1,150 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2017 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- HGamer3D/Graphics3D/Camera.hs + +{-# LANGUAGE OverloadedStrings #-} + +-- | Module providing the Material type +module HGamer3D.Graphics3D.Material + +( + -- * The Material Type and ComponentType + Material (..), + ctMaterial, + + -- * Some materials to play with + matOrangeCrossMetal, + matCrossMetal, + matCrossMetalBlue, + matMetal, + matMetalZigZag, + matMetalBumps, + matFishEye, + matMetalOrnament, + matMetalScratch, + matMetalLine, + matGreenGrass, + matBrownGrass, + matGreyGrass, + matSand, + matRedRock, + matBlackRock, + matBrownStone, + matStoneMetalWall, + matCoalWall, + matBrickWallGray, + matBrickWallRed, + matTilesOrange, + matWoodTiles, + matColourTiles, + matBlackTiles, + + matWhite, + matSilver, + matGrey, + matDarkGrey, + matBlack, + matRed, + matMaroon, + matYellow, + matOlive, + matLime, + matGreen, + matAqua, + matTeal, + matBlue, + matNavy, + matFuchsia, + matPurple +) + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Material = ResourceMaterial Text + deriving (Eq, Read, Show) + +ctMaterial :: ComponentType Material +ctMaterial = ComponentType 0xb4bae8b0d0d8c162 + +instance Serialise Material where + encode (ResourceMaterial v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (ResourceMaterial <$> decode) + +-- some materials from the material folder +matOrangeCrossMetal = ResourceMaterial "Materials/Pattern_01.xml" +matCrossMetal = ResourceMaterial "Materials/Pattern_03.xml" +matCrossMetalBlue = ResourceMaterial "Materials/Pattern_04.xml" +matMetal = ResourceMaterial "Materials/Pattern_12.xml" +matMetalZigZag = ResourceMaterial "Materials/Pattern_13.xml" +matMetalBumps = ResourceMaterial "Materials/Pattern_14.xml" +matFishEye = ResourceMaterial "Materials/Pattern_15.xml" +matMetalOrnament = ResourceMaterial "Materials/Pattern_29.xml" +matMetalScratch = ResourceMaterial "Materials/Pattern_30.xml" +matMetalLine = ResourceMaterial "Materials/Pattern_31.xml" +matGreenGrass = ResourceMaterial "Materials/Pattern_42.xml" +matBrownGrass = ResourceMaterial "Materials/Pattern_43.xml" +matGreyGrass = ResourceMaterial "Materials/Pattern_44.xml" +matSand = ResourceMaterial "Materials/Pattern_45.xml" +matRedRock = ResourceMaterial "Materials/Pattern_46.xml" +matBlackRock = ResourceMaterial "Materials/Pattern_124.xml" +matBrownStone = ResourceMaterial "Materials/Pattern_125.xml" +matStoneMetalWall = ResourceMaterial "Materials/Pattern_126.xml" +matCoalWall = ResourceMaterial "Materials/Pattern_127.xml" +matBrickWallGray = ResourceMaterial "Materials/Pattern_100.xml" +matBrickWallRed = ResourceMaterial "Materials/Pattern_102.xml" +matTilesOrange = ResourceMaterial "Materials/Pattern_270.xml" +matWoodTiles = ResourceMaterial "Materials/Pattern_271.xml" +matColourTiles = ResourceMaterial "Materials/Pattern_272.xml" +matBlackTiles = ResourceMaterial "Materials/Pattern_273.xml" + +matWhite = ResourceMaterial "Materials/ColourWhite.xml" +matSilver = ResourceMaterial "Materials/ColourSilver.xml" +matGrey = ResourceMaterial "Materials/ColourGrey.xml" +matDarkGrey = ResourceMaterial "Materials/ColourDarkGrey.xml" +matBlack = ResourceMaterial "Materials/ColourBlack.xml" +matRed = ResourceMaterial "Materials/ColourRed.xml" +matMaroon = ResourceMaterial "Materials/ColourMaroon.xml" +matYellow = ResourceMaterial "Materials/ColourYellow.xml" +matOlive = ResourceMaterial "Materials/ColourOlive.xml" +matLime = ResourceMaterial "Materials/ColourLime.xml" +matGreen = ResourceMaterial "Materials/ColourGreen.xml" +matAqua = ResourceMaterial "Materials/ColourAqua.xml" +matTeal = ResourceMaterial "Materials/ColourTeal.xml" +matBlue = ResourceMaterial "Materials/ColourBlue.xml" +matNavy = ResourceMaterial "Materials/ColourNavy.xml" +matFuchsia = ResourceMaterial "Materials/ColourFuchsia.xml" +matPurple = ResourceMaterial "Materials/ColourPurple.xml" + +-- end of website text + +
+ HGamer3D/Graphics3D/Particles.hs view
@@ -0,0 +1,26 @@+module HGamer3D.Graphics3D.Particles where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Particles = ParticleEffectResource Text + deriving (Eq, Read, Show) + +ctParticles :: ComponentType Particles +ctParticles = ComponentType 0x5009dcc85ea5f959 + +instance Serialise Particles where + encode (ParticleEffectResource v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (ParticleEffectResource <$> decode) +
+ HGamer3D/Graphics3D/Scene.hs view
@@ -0,0 +1,30 @@+module HGamer3D.Graphics3D.Scene where + +import Fresco + +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Scene = XmlScene Text + | BinaryScene Text + deriving (Eq, Read, Show) + +ctScene :: ComponentType Scene +ctScene = ComponentType 0x829863cdd141007e + +instance Serialise Scene where + encode (XmlScene v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + encode (BinaryScene v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (XmlScene <$> decode) + 1 -> (BinaryScene <$> decode) +
+ HGamer3D/Graphics3D/Skybox.hs view
@@ -0,0 +1,26 @@+module HGamer3D.Graphics3D.Skybox where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Skybox = SkyboxMaterial Text + deriving (Eq, Read, Show) + +ctSkybox :: ComponentType Skybox +ctSkybox = ComponentType 0x457ac00afe66a3a4 + +instance Serialise Skybox where + encode (SkyboxMaterial v1) = encodeListLen 2 <> encode (0::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (SkyboxMaterial <$> decode) +
+ HGamer3D/Graphics3D/Text3D.hs view
@@ -0,0 +1,55 @@+module HGamer3D.Graphics3D.Text3D where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data FaceCameraMode = FCNone + | FCRotateXYZ + | FCRotateY + | FCLookatXYZ + | FCLookatY + | FCLookatMixed + | FCDirection + deriving (Eq, Read, Show) + +data Text3D = Text3D { + text3DFont::Text, + text3DFontSize::Int, + text3DFCMode::FaceCameraMode, + text3DFixedScreenSize::Bool + } deriving (Eq, Read, Show) + +ctText3D :: ComponentType Text3D +ctText3D = ComponentType 0x620bb5dd7dfca052 + +instance Serialise FaceCameraMode where + encode (FCNone) = encodeListLen 1 <> encode (0::Int) + encode (FCRotateXYZ) = encodeListLen 1 <> encode (1::Int) + encode (FCRotateY) = encodeListLen 1 <> encode (2::Int) + encode (FCLookatXYZ) = encodeListLen 1 <> encode (3::Int) + encode (FCLookatY) = encodeListLen 1 <> encode (4::Int) + encode (FCLookatMixed) = encodeListLen 1 <> encode (5::Int) + encode (FCDirection) = encodeListLen 1 <> encode (6::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure FCNone) + 1 -> (pure FCRotateXYZ) + 2 -> (pure FCRotateY) + 3 -> (pure FCLookatXYZ) + 4 -> (pure FCLookatY) + 5 -> (pure FCLookatMixed) + 6 -> (pure FCDirection) + +instance Serialise Text3D where + encode (Text3D v1 v2 v3 v4) = encodeListLen 4 <> encode v1 <> encode v2 <> encode v3 <> encode v4 + decode = decodeListLenOf 4 >> Text3D <$> decode <*> decode <*> decode <*> decode +
+ HGamer3D/Input.hs view
@@ -0,0 +1,37 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2015 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- HGamer3D/Input.hs +-- + +-- | Input Devices for HGamer3D +module HGamer3D.Input + +( + module HGamer3D.Input.Mouse, + module HGamer3D.Input.Keyboard, + module HGamer3D.Input.Joystick +) + +where + +import HGamer3D.Input.Mouse +import HGamer3D.Input.Keyboard +import HGamer3D.Input.Joystick + +
+ HGamer3D/Input/Joystick.hs view
@@ -0,0 +1,148 @@+{- + Joystick functionality and settings + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Input/Joystick.hs +-} + +-- | Module providing the Joystick functionality and settings +module HGamer3D.Input.Joystick + +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data Joystick = Joystick { + -- | index of joystick, starting at 0 (first one) + joystickIndex::Int + } deriving (Eq, Read, Show) + +ctJoystick :: ComponentType Joystick +ctJoystick = ComponentType 0xe5ea0d693a04ff71 + +data JoystickEvent = NoJoystickEvent + | ButtonDown Int -- ^ Button Id + | ButtonUp Int -- ^ Button Id + | AxisMove Int Float -- ^ Axis Id, Move Position + | HatMove Int Int -- ^ Axis Id, Hat Position + | JoystickChange Int Int -- ^ joystick plugged, unplugged, min, max indicees + deriving (Eq, Read, Show) + +ctJoystickEvent :: ComponentType JoystickEvent +ctJoystickEvent = ComponentType 0x1cdc5b0a65479346 + +data JoystickButton = A + | B + | Back + | DPadDown + | DPadLeft + | DPadRight + | DPadUp + | Guide + | LeftShoulder + | LeftStick + | RightShoulder + | RightStick + | Start + | X + | Y + deriving (Eq, Read, Show) + +data JoystickAxis = LeftX + | LeftY + | RightX + | RightY + | TriggerLeft + | TriggerRight + deriving (Eq, Read, Show) + +instance Serialise Joystick where + encode (Joystick v1) = encodeListLen 1 <> encode v1 + decode = decodeListLenOf 1 >> Joystick <$> decode + +instance Serialise JoystickEvent where + encode (NoJoystickEvent) = encodeListLen 1 <> encode (0::Int) + encode (ButtonDown v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + encode (ButtonUp v1) = encodeListLen 2 <> encode (2::Int) <> encode v1 + encode (AxisMove v1 v2) = encodeListLen 3 <> encode (3::Int) <> encode v1<> encode v2 + encode (HatMove v1 v2) = encodeListLen 3 <> encode (4::Int) <> encode v1<> encode v2 + encode (JoystickChange v1 v2) = encodeListLen 3 <> encode (5::Int) <> encode v1<> encode v2 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure NoJoystickEvent) + 1 -> (ButtonDown <$> decode) + 2 -> (ButtonUp <$> decode) + 3 -> (AxisMove <$> decode <*> decode) + 4 -> (HatMove <$> decode <*> decode) + 5 -> (JoystickChange <$> decode <*> decode) + +instance Serialise JoystickButton where + encode (A) = encodeListLen 1 <> encode (0::Int) + encode (B) = encodeListLen 1 <> encode (1::Int) + encode (Back) = encodeListLen 1 <> encode (2::Int) + encode (DPadDown) = encodeListLen 1 <> encode (3::Int) + encode (DPadLeft) = encodeListLen 1 <> encode (4::Int) + encode (DPadRight) = encodeListLen 1 <> encode (5::Int) + encode (DPadUp) = encodeListLen 1 <> encode (6::Int) + encode (Guide) = encodeListLen 1 <> encode (7::Int) + encode (LeftShoulder) = encodeListLen 1 <> encode (8::Int) + encode (LeftStick) = encodeListLen 1 <> encode (9::Int) + encode (RightShoulder) = encodeListLen 1 <> encode (10::Int) + encode (RightStick) = encodeListLen 1 <> encode (11::Int) + encode (Start) = encodeListLen 1 <> encode (12::Int) + encode (X) = encodeListLen 1 <> encode (13::Int) + encode (Y) = encodeListLen 1 <> encode (14::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure A) + 1 -> (pure B) + 2 -> (pure Back) + 3 -> (pure DPadDown) + 4 -> (pure DPadLeft) + 5 -> (pure DPadRight) + 6 -> (pure DPadUp) + 7 -> (pure Guide) + 8 -> (pure LeftShoulder) + 9 -> (pure LeftStick) + 10 -> (pure RightShoulder) + 11 -> (pure RightStick) + 12 -> (pure Start) + 13 -> (pure X) + 14 -> (pure Y) + +instance Serialise JoystickAxis where + encode (LeftX) = encodeListLen 1 <> encode (0::Int) + encode (LeftY) = encodeListLen 1 <> encode (1::Int) + encode (RightX) = encodeListLen 1 <> encode (2::Int) + encode (RightY) = encodeListLen 1 <> encode (3::Int) + encode (TriggerLeft) = encodeListLen 1 <> encode (4::Int) + encode (TriggerRight) = encodeListLen 1 <> encode (5::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure LeftX) + 1 -> (pure LeftY) + 2 -> (pure RightX) + 3 -> (pure RightY) + 4 -> (pure TriggerLeft) + 5 -> (pure TriggerRight) + +
+ HGamer3D/Input/Keyboard.hs view
@@ -0,0 +1,56 @@+{- + Keyboard functionality and settings + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Input/Keyboard.hs +-} + +-- | Module providing the keyboard functionality and settings +module HGamer3D.Input.Keyboard +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + +import Debug.Trace + +data KeyData = KeyData { + keyDataKey::Int, + keyDataScancode::Int, + keyDataName::Text + } deriving (Eq, Read, Show) + +data KeyEvent = NoKeyEvent + | KeyUpEvent KeyData + | KeyDownEvent KeyData + deriving (Eq, Read, Show) + +ctKeyEvent :: ComponentType KeyEvent +ctKeyEvent = ComponentType 0x07995a794e698f4b + +instance Serialise KeyData where + encode (KeyData v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> KeyData <$> decode <*> decode <*> decode + +instance Serialise KeyEvent where + encode (NoKeyEvent) = encodeListLen 1 <> encode (0::Int) + encode (KeyUpEvent v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + encode (KeyDownEvent v1) = encodeListLen 2 <> encode (2::Int) <> encode v1 + decode = do + decodeListLen + i <- (decode :: Decoder s Int) + case i of + 0 -> (pure NoKeyEvent) + 1 -> (KeyUpEvent <$> decode) + 2 -> (KeyDownEvent <$> decode)
+ HGamer3D/Input/Mouse.hs view
@@ -0,0 +1,106 @@+{- + Mouse functionality and settings + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 - 2017 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/Input/Mouse.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.Input.Mouse +where + +import Fresco +import Data.Binary.Serialise.CBOR +import Data.Binary.Serialise.CBOR.Encoding +import Data.Binary.Serialise.CBOR.Decoding + +import Data.Text +import Data.Monoid +import Control.Applicative + + +data MouseMode = MMAbsolute + | MMRelative + | MMWrap + deriving (Eq, Read, Show) + +ctMouse :: ComponentType MouseMode +ctMouse = ComponentType 0x07669c3c292bf265 + +data MouseButtonData = MouseButtonData { + mouseButtonDataButton::Int, + mouseButtonDataButtons::Int, + mouseButtonDataQualifiers::Int + } deriving (Eq, Read, Show) + +data MouseMoveData = MouseMoveData { + mouseMoveDataX::Int, + mouseMoveDataY::Int, + mouseMoveDataDx::Int, + mouseMoveDataDy::Int, + mouseMoveDataButtons::Int, + mouseMoveDataQualifiers::Int + } deriving (Eq, Read, Show) + +data MouseWheelData = MouseWheelData { + mouseWheelDataWheel::Int, + mouseWheelDataButtons::Int, + mouseWheelDataQualifiers::Int + } deriving (Eq, Read, Show) + +data MouseEvent = NoMouseEvent + | MouseButtonUpEvent MouseButtonData + | MouseButtonDownEvent MouseButtonData + | MouseMoveEvent MouseMoveData + | MouseWheelEvent MouseWheelData + deriving (Eq, Read, Show) + +ctMouseEvent :: ComponentType MouseEvent +ctMouseEvent = ComponentType 0x8a73da7bdfbe4ccc + +instance Serialise MouseMode where + encode (MMAbsolute) = encodeListLen 1 <> encode (0::Int) + encode (MMRelative) = encodeListLen 1 <> encode (1::Int) + encode (MMWrap) = encodeListLen 1 <> encode (2::Int) + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure MMAbsolute) + 1 -> (pure MMRelative) + 2 -> (pure MMWrap) + +instance Serialise MouseButtonData where + encode (MouseButtonData v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> MouseButtonData <$> decode <*> decode <*> decode + +instance Serialise MouseMoveData where + encode (MouseMoveData v1 v2 v3 v4 v5 v6) = encodeListLen 6 <> encode v1 <> encode v2 <> encode v3 <> encode v4 <> encode v5 <> encode v6 + decode = decodeListLenOf 6 >> MouseMoveData <$> decode <*> decode <*> decode <*> decode <*> decode <*> decode + +instance Serialise MouseWheelData where + encode (MouseWheelData v1 v2 v3) = encodeListLen 3 <> encode v1 <> encode v2 <> encode v3 + decode = decodeListLenOf 3 >> MouseWheelData <$> decode <*> decode <*> decode + +instance Serialise MouseEvent where + encode (NoMouseEvent) = encodeListLen 1 <> encode (0::Int) + encode (MouseButtonUpEvent v1) = encodeListLen 2 <> encode (1::Int) <> encode v1 + encode (MouseButtonDownEvent v1) = encodeListLen 2 <> encode (2::Int) <> encode v1 + encode (MouseMoveEvent v1) = encodeListLen 2 <> encode (3::Int) <> encode v1 + encode (MouseWheelEvent v1) = encodeListLen 2 <> encode (4::Int) <> encode v1 + decode = do + decodeListLen + i <- decode :: Decoder s Int + case i of + 0 -> (pure NoMouseEvent) + 1 -> (MouseButtonUpEvent <$> decode) + 2 -> (MouseButtonDownEvent <$> decode) + 3 -> (MouseMoveEvent <$> decode) + 4 -> (MouseWheelEvent <$> decode) + +
+ HGamer3D/Util.hs view
@@ -0,0 +1,36 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2015 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- HGamer3D/Data.hs +-- + +-- | Common utilities for HGamer3D +module HGamer3D.Util + +( + module HGamer3D.Util.FileLocation, + module HGamer3D.Util.UniqueName, + module HGamer3D.Util.Variable +) + +where + +import HGamer3D.Util.FileLocation +import HGamer3D.Util.UniqueName +import HGamer3D.Util.Variable +
+ HGamer3D/Util/FileLocation.hs view
@@ -0,0 +1,50 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011 - 2015 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- Util.hs + +-- | Utility to provide file location information to other parts of HGamer3D +module HGamer3D.Util.FileLocation + +( + + -- * Directories relative to the user-related application directory for HGamer3D + getAppDirectory, + getMediaDirectory, + getConfigDirectory, + + -- * General utilities for path handling and finding files + pathSeparator +) + +where + +import Control.Monad +import Control.Exception +import System.FilePath +import System.Directory + +-- | path of subdirectory within platform specific application directories +getAppDirectory = getAppUserDataDirectory + +-- | path of HGamer3D Media Directory +getMediaDirectory = getAppDirectory ("HGamer3D" ++ [pathSeparator] ++ "media") + +-- | path of HGamer3D configuration directory +getConfigDirectory = getAppDirectory ("HGamer3D" ++ [pathSeparator] ++ "config") +
+ HGamer3D/Util/UniqueName.hs view
@@ -0,0 +1,48 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011-2013 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- UniqueName.hs + +-- | Utility to provide a unique name, carries internal state in a IORef +module HGamer3D.Util.UniqueName +( + + UniqueName, + createUniqueName, + nextUniqueName + +) where + +import Data.IORef + +data UniqueName = UniqueName String (IORef [Int]) + +-- | creates a unique name holder +createUniqueName :: String -> IO UniqueName +createUniqueName baseName = do + ref <- newIORef [0..] + return $ UniqueName baseName ref + +-- | delivers the next unique name from the name holder +nextUniqueName :: UniqueName -> IO String +nextUniqueName (UniqueName baseName ref) = do + name <- atomicModifyIORef ref (\ilist -> (tail ilist, baseName ++ (show (head ilist)))) + return name + + +
+ HGamer3D/Util/Variable.hs view
@@ -0,0 +1,55 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011-2013 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- Variable.hs + +-- | :-) I'm fundamentally convinced this is missing in Haskell, urs of the backwoods + +module HGamer3D.Util.Variable +( + Var, + makeVar, + readVar, + writeVar, + writeVar', + updateVar, + updateVar' +) where + +import Data.IORef + +newtype Var a = Var (IORef a) + +makeVar :: a -> IO (Var a) +makeVar v = Var <$> newIORef v + +readVar :: Var a -> IO a +readVar (Var r) = readIORef r + +writeVar :: Var a -> a -> IO a +writeVar (Var r) val = atomicModifyIORef r (\old -> (val, old)) + +writeVar' :: Var a -> a -> IO a +writeVar' (Var r) val = atomicModifyIORef' r (\old -> (val, old)) + +updateVar :: Var a -> (a -> (a, b)) -> IO b +updateVar (Var r) f = atomicModifyIORef r f + +updateVar' :: Var a -> (a -> (a, b)) -> IO b +updateVar' (Var r) f = atomicModifyIORef' r f +