HGamer3D 0.6.0 → 0.6.1
raw patch · 39 files changed
+2472/−2322 lines, 39 filesdep ~messagepacksetup-changed
Dependency ranges changed: messagepack
Files
- HGamer3D.cabal +5/−5
- HGamer3D.hs +39/−39
- HGamer3D/Binding.hs +34/−34
- HGamer3D/Binding/CFunctions.chs.h +3/−0
- HGamer3D/Binding/CFunctions.hs +1/−1
- HGamer3D/Binding/Helper.hs +75/−75
- HGamer3D/Data.hs +57/−57
- HGamer3D/Data/Angle.hs +87/−96
- HGamer3D/Data/Colour.hs +104/−112
- HGamer3D/Data/Component.hs +57/−61
- HGamer3D/Data/GameTime.hs +97/−101
- HGamer3D/Data/Geometry2D.hs +75/−83
- HGamer3D/Data/LMH.hs +48/−49
- HGamer3D/Data/Transform3D.hs +60/−68
- HGamer3D/Data/TypeSynonyms.hs +43/−37
- HGamer3D/Data/Vector.hs +77/−85
- HGamer3D/Data/Window.hs +31/−41
- HGamer3D/ECS.hs +34/−34
- HGamer3D/ECS/Entity.hs +181/−181
- HGamer3D/ECS/System.hs +255/−255
- HGamer3D/Graphics3D.hs +47/−47
- HGamer3D/Graphics3D/Camera.hs +59/−66
- HGamer3D/Graphics3D/Geometry.hs +78/−68
- HGamer3D/Graphics3D/Graphics3DCommand.hs +51/−51
- HGamer3D/Graphics3D/Graphics3DConfig.hs +129/−129
- HGamer3D/Graphics3D/Light.hs +53/−58
- HGamer3D/Graphics3D/Material.hs +138/−101
- HGamer3D/Graphics3D/SystemGraphics3D.hs +112/−99
- HGamer3D/Graphics3D/Window.hs +54/−54
- HGamer3D/Input.hs +37/−33
- HGamer3D/Input/InputEvents.hs +8/−7
- HGamer3D/Input/Joystick.hs +25/−0
- HGamer3D/Input/Keyboard.hs +43/−0
- HGamer3D/Input/Mouse.hs +80/−0
- HGamer3D/Util.hs +34/−34
- HGamer3D/Util/FileLocation.hs +50/−50
- HGamer3D/Util/UniqueName.hs +47/−47
- LICENSE +42/−42
- Setup.hs +22/−22
HGamer3D.cabal view
@@ -1,5 +1,5 @@ Name: HGamer3D -Version: 0.6.0 +Version: 0.6.1 Synopsis: Toolset for the Haskell Game Programmer Description: HGamer3D is a toolset for developing 3D games in the programming @@ -16,9 +16,9 @@ Extra-source-files: Setup.hs Library - Build-Depends: base >= 3 && < 5, containers, bytestring, text, filepath, directory, vect >=0.4 && <0.5, messagepack >=0.5 && <0.6, clock >=0.5 && <0.6, cereal >=0.4 && < 0.5 + Build-Depends: base >= 3 && < 5, containers, bytestring, text, filepath, directory, vect >=0.4 && <0.5, messagepack >=0.4 && <0.5, clock >=0.5 && <0.6, cereal >=0.4 && < 0.5 - Exposed-modules: HGamer3D.Binding.CFunctions, HGamer3D.Binding.Helper, HGamer3D.Binding, HGamer3D.Data.Angle, HGamer3D.Data.Colour, HGamer3D.Data.LMH, HGamer3D.Data.GameTime, HGamer3D.Data.Geometry2D, HGamer3D.Data.Transform3D, HGamer3D.Data.TypeSynonyms, HGamer3D.Data.Vector, HGamer3D.Data.Window, HGamer3D.Data, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util, HGamer3D.ECS.Entity, HGamer3D.Data.Component, HGamer3D.ECS.System, HGamer3D.ECS, HGamer3D.Graphics3D.Camera, HGamer3D.Graphics3D.Graphics3DCommand, HGamer3D.Graphics3D.Geometry, HGamer3D.Graphics3D.Graphics3DConfig, HGamer3D.Graphics3D.Light, HGamer3D.Graphics3D.Material, HGamer3D.Graphics3D.Window, HGamer3D.Input.InputEvents, HGamer3D.Input, HGamer3D.Graphics3D.SystemGraphics3D, HGamer3D.Graphics3D, HGamer3D + Exposed-modules: HGamer3D.Binding.CFunctions, HGamer3D.Binding.Helper, HGamer3D.Binding, HGamer3D.Data.Angle, HGamer3D.Data.Colour, HGamer3D.Data.LMH, HGamer3D.Data.GameTime, HGamer3D.Data.Geometry2D, HGamer3D.Data.Transform3D, HGamer3D.Data.TypeSynonyms, HGamer3D.Data.Vector, HGamer3D.Data.Window, HGamer3D.Data, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util, HGamer3D.ECS.Entity, HGamer3D.Data.Component, HGamer3D.ECS.System, HGamer3D.ECS, HGamer3D.Graphics3D.Camera, HGamer3D.Graphics3D.Graphics3DCommand, HGamer3D.Graphics3D.Geometry, HGamer3D.Graphics3D.Graphics3DConfig, HGamer3D.Graphics3D.Light, HGamer3D.Graphics3D.Material, HGamer3D.Graphics3D.Window, HGamer3D.Input.Mouse, HGamer3D.Input.Keyboard, HGamer3D.Input.Joystick, HGamer3D.Input, HGamer3D.Graphics3D.SystemGraphics3D, HGamer3D.Graphics3D, HGamer3D Other-modules: @@ -30,7 +30,7 @@ Include-dirs: . build-depends: if os(windows) - extra-libraries: hgamer3d0 + extra-libraries: hgamer3d061 else - extra-libraries: hgamer3d0, Urho3D + extra-libraries: hgamer3d061, Urho3D
HGamer3D.hs view
@@ -1,39 +1,39 @@--- 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--- ---- | Main module, to include API-module HGamer3D--(- module HGamer3D.Data,- module HGamer3D.Util,- module HGamer3D.ECS,- module HGamer3D.Graphics3D,- module HGamer3D.Input-)--where--import HGamer3D.Data-import HGamer3D.Util-import HGamer3D.ECS-import HGamer3D.Graphics3D-import HGamer3D.Input+-- 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 +-- + +-- | Main module, to include API +module HGamer3D + +( + module HGamer3D.Data, + module HGamer3D.Util, + module HGamer3D.ECS, + module HGamer3D.Graphics3D, + module HGamer3D.Input +) + +where + +import HGamer3D.Data +import HGamer3D.Util +import HGamer3D.ECS +import HGamer3D.Graphics3D +import HGamer3D.Input
HGamer3D/Binding.hs view
@@ -1,34 +1,34 @@--- 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/Binding.hs--- ---- | Binding utility functions for HGamer3D-module HGamer3D.Binding--(- module HGamer3D.Binding.CFunctions,- module HGamer3D.Binding.Helper-)--where--import HGamer3D.Binding.CFunctions-import HGamer3D.Binding.Helper-+-- 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/Binding.hs +-- + +-- | Binding utility functions for HGamer3D +module HGamer3D.Binding + +( + module HGamer3D.Binding.CFunctions, + module HGamer3D.Binding.Helper +) + +where + +import HGamer3D.Binding.CFunctions +import HGamer3D.Binding.Helper +
+ HGamer3D/Binding/CFunctions.chs.h view
@@ -0,0 +1,3 @@+#define C2HS_MIN_VERSION(mj,mn,rv) ((mj)<=C2HS_VERSION_MAJOR && (mn)<=C2HS_VERSION_MINOR && (rv)<=C2HS_VERSION_REV) +#include "interface.h" +#include "interface.h"
HGamer3D/Binding/CFunctions.hs view
@@ -1,4 +1,4 @@--- GENERATED by C->Haskell Compiler, version 0.23.1 Snowbounder, 31 Oct 2014 (Haskell) +-- GENERATED by C->Haskell Compiler, version 0.25.2 Snowboundest, 31 Oct 2014 (Haskell) -- Edit the ORIGNAL .chs file instead!
HGamer3D/Binding/Helper.hs view
@@ -1,75 +1,75 @@--- 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/Binding/Helper.hs--{-# LANGUAGE ForeignFunctionInterface #-}---- | Helper functions for binding ffi, encoding, decoding via messagepack-module HGamer3D.Binding.Helper--where--import Data.ByteString-import Data.ByteString.Unsafe-import qualified Data.ByteString.Lazy as BL-import Data.MessagePack-import Data.Either-import Data.Maybe-import Data.Serialize--import Foreign-import Foreign.C-import Foreign.Ptr--import HGamer3D.Binding.CFunctions-import HGamer3D.Data.Component--toMsg :: ComponentClass o => o -> ByteString-toMsg o = encode (toObj o)--fromMsg :: ComponentClass o => ByteString -> Maybe o-fromMsg bs = case decode bs of - Right o -> Just $ fromObj o- _ -> Nothing---- helper functions--type MsgFunction = Ptr () -> Ptr CChar -> CInt -> IO CInt-foreign import ccall "dynamic" - mkMsgFun :: FunPtr MsgFunction -> MsgFunction-foreign import ccall "wrapper"- mkMsgFunPtr :: MsgFunction -> IO (FunPtr MsgFunction)--callMsgFunction :: FunPtr MsgFunction -> Ptr () -> ByteString -> IO Int-callMsgFunction mf p msg = do- let f = mkMsgFun mf- let dat = msg- unsafeUseAsCStringLen' dat $ \(dat'1, dat'2) -> f p dat'1 dat'2 >>= \res -> return (fromIntegral res)--- unsafeUseAsCStringLen' dat $ \(dat'1, dat'2) -> print "msgfun" >> print dat'1 >> print dat'2 >> f p dat'1 dat'2 >>= \res -> return (fromIntegral res)--type InitFunction = Ptr () -> IO CInt-foreign import ccall "dynamic" - mkInitFun :: FunPtr InitFunction -> InitFunction--callInitFunction :: FunPtr InitFunction -> Ptr () -> IO Int-callInitFunction ifp p = do- let f = mkInitFun ifp- res <- f p- return (fromIntegral res)-+-- 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/Binding/Helper.hs + +{-# LANGUAGE ForeignFunctionInterface #-} + +-- | Helper functions for binding ffi, encoding, decoding via messagepack +module HGamer3D.Binding.Helper + +where + +import Data.ByteString +import Data.ByteString.Unsafe +import qualified Data.ByteString.Lazy as BL +import Data.MessagePack +import Data.Either +import Data.Maybe +import Data.Serialize + +import Foreign +import Foreign.C +import Foreign.Ptr + +import HGamer3D.Binding.CFunctions +import HGamer3D.Data.Component + +toMsg :: ComponentClass o => o -> ByteString +toMsg o = encode (toObj o) + +fromMsg :: ComponentClass o => ByteString -> Maybe o +fromMsg bs = case decode bs of + Right o -> Just $ fromObj o + _ -> Nothing + +-- helper functions + +type MsgFunction = Ptr () -> Ptr CChar -> CInt -> IO CInt +foreign import ccall "dynamic" + mkMsgFun :: FunPtr MsgFunction -> MsgFunction +foreign import ccall "wrapper" + mkMsgFunPtr :: MsgFunction -> IO (FunPtr MsgFunction) + +callMsgFunction :: FunPtr MsgFunction -> Ptr () -> ByteString -> IO Int +callMsgFunction mf p msg = do + let f = mkMsgFun mf + let dat = msg + unsafeUseAsCStringLen' dat $ \(dat'1, dat'2) -> f p dat'1 dat'2 >>= \res -> return (fromIntegral res) +-- unsafeUseAsCStringLen' dat $ \(dat'1, dat'2) -> print "msgfun" >> print dat'1 >> print dat'2 >> f p dat'1 dat'2 >>= \res -> return (fromIntegral res) + +type InitFunction = Ptr () -> IO CInt +foreign import ccall "dynamic" + mkInitFun :: FunPtr InitFunction -> InitFunction + +callInitFunction :: FunPtr InitFunction -> Ptr () -> IO Int +callInitFunction ifp p = do + let f = mkInitFun ifp + res <- f p + return (fromIntegral res) +
HGamer3D/Data.hs view
@@ -1,57 +1,57 @@--- 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,-- -- * Geometry Datatypes- module HGamer3D.Data.Vector,- module HGamer3D.Data.Geometry2D,- module HGamer3D.Data.Transform3D,- module HGamer3D.Data.TypeSynonyms,-- -- * Entity Component System, Index Type- module HGamer3D.Data.Component,-- -- * Implementation - module HGamer3D.Data.Window-)--where--import HGamer3D.Data.Angle-import HGamer3D.Data.Colour-import HGamer3D.Data.LMH-import HGamer3D.Data.GameTime-import HGamer3D.Data.Geometry2D-import HGamer3D.Data.Transform3D-import HGamer3D.Data.TypeSynonyms-import HGamer3D.Data.Vector-import HGamer3D.Data.Window-import HGamer3D.Data.Component-+-- 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, + + -- * Geometry Datatypes + module HGamer3D.Data.Vector, + module HGamer3D.Data.Geometry2D, + module HGamer3D.Data.Transform3D, + module HGamer3D.Data.TypeSynonyms, + + -- * Entity Component System, Index Type + module HGamer3D.Data.Component, + + -- * Implementation + module HGamer3D.Data.Window +) + +where + +import HGamer3D.Data.Angle +import HGamer3D.Data.Colour +import HGamer3D.Data.LMH +import HGamer3D.Data.GameTime +import HGamer3D.Data.Geometry2D +import HGamer3D.Data.Transform3D +import HGamer3D.Data.TypeSynonyms +import HGamer3D.Data.Vector +import HGamer3D.Data.Window +import HGamer3D.Data.Component +
HGamer3D/Data/Angle.hs view
@@ -1,96 +1,87 @@--- 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/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 Data.MessagePack-import HGamer3D.Data.Component---- | construct an Angle either by giving it in degrees or radians-data Angle = Rad Float | Deg Float deriving (Eq, Ord, Show)---- | 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--instance ComponentClass Angle where- toObj a = ObjectFloat (asRad a)- fromObj (ObjectFloat f) = Rad f - - +{- + Datatypes to specify a geometric angle + 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/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 Data.MessagePack +import HGamer3D.Data.Component + +-- | construct an Angle either by giving it in degrees or radians +data Angle = Rad Float | Deg Float deriving (Eq, Ord, Show) + +-- | 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 + +instance ComponentClass Angle where + toObj a = ObjectFloat (asRad a) + fromObj (ObjectFloat f) = Rad f +
HGamer3D/Data/Colour.hs view
@@ -1,112 +1,104 @@--- 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/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 Data.MessagePack-import HGamer3D.Data.Component--data Colour = Colour {cRed::Float, cGreen::Float, cBlue::Float, cAlpha::Float} deriving (Eq, Show)--instance ComponentClass Colour where- toObj (Colour r g b a) = ObjectArray [ObjectFloat r, ObjectFloat g, ObjectFloat b, ObjectFloat a]- fromObj (ObjectArray [ObjectFloat r, ObjectFloat g, ObjectFloat b, ObjectFloat a]) = (Colour r g b a)--ctColour :: ComponentType Colour-ctColour = ComponentType 0xe202add0521cde41--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---+{- + Datatypes to specify a geometric angle + 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/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 Data.MessagePack +import HGamer3D.Data.Component + +data Colour = Colour {cRed::Float, cGreen::Float, cBlue::Float, cAlpha::Float} deriving (Eq, Show) + +instance ComponentClass Colour where + toObj (Colour r g b a) = ObjectArray [ObjectFloat r, ObjectFloat g, ObjectFloat b, ObjectFloat a] + fromObj (ObjectArray [ObjectFloat r, ObjectFloat g, ObjectFloat b, ObjectFloat a]) = (Colour r g b a) + +ctColour :: ComponentType Colour +ctColour = ComponentType 0xe202add0521cde41 + +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/Component.hs view
@@ -1,61 +1,57 @@--- 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) 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/Component.hs--{-# LANGUAGE TypeSynonymInstances #-}---- | Components of the Entity Component System of HGamer3D-module HGamer3D.Data.Component-(- ComponentType (..),- Component,- ComponentClass (..)-)-where--import Data.Word-import Data.MessagePack-import Data.ByteString-import Data.Text-import Data.Text.Encoding---- | Components in Entities are indexed by ComponentType-data ComponentType a = ComponentType Word64---- | Components are stored as ByteString-type Component = ByteString---- | ComponentClass is the typeclass of data types, which can be components-class ComponentClass a where- toObj :: a -> Object- fromObj :: Object -> a--instance ComponentClass () where- toObj () = ObjectNil- fromObj ObjectNil = ()--instance ComponentClass Text where- toObj text = ObjectString (encodeUtf8 text)- fromObj (ObjectString bs) = decodeUtf8 bs --instance ComponentClass (ComponentType a) where- toObj (ComponentType i) = ObjectInt (fromIntegral i)- fromObj (ObjectInt i) = ComponentType (fromIntegral i)--+{- + Components are pieces of the handcrafted record system + 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/Data/Component.hs +-} + +{-# LANGUAGE TypeSynonymInstances #-} + +-- | Components of the Entity Component System of HGamer3D +module HGamer3D.Data.Component +( + ComponentType (..), + Component, + ComponentClass (..) +) +where + +import Data.Word +import Data.MessagePack +import Data.ByteString +import Data.Text +import Data.Text.Encoding + +-- | Components in Entities are indexed by ComponentType +data ComponentType a = ComponentType Word64 deriving (Eq, Show, Ord) + +-- | Components are stored as ByteString +type Component = ByteString + +-- | ComponentClass is the typeclass of data types, which can be components +class ComponentClass a where + toObj :: a -> Object + fromObj :: Object -> a + +instance ComponentClass () where + toObj () = ObjectNil + fromObj ObjectNil = () + +instance ComponentClass Text where + toObj text = ObjectString (encodeUtf8 text) + fromObj (ObjectString bs) = decodeUtf8 bs + +instance ComponentClass (ComponentType a) where + toObj (ComponentType i) = ObjectInt (fromIntegral i) + fromObj (ObjectInt i) = ComponentType (fromIntegral i) + +instance ComponentClass Bool where + toObj b = ObjectBool b + fromObj (ObjectBool b) = b + +
HGamer3D/Data/GameTime.hs view
@@ -1,101 +1,97 @@--- 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/GameTime.hs--{-# LANGUAGE TypeSynonymInstances, CPP #-}---- | The time type for HGamer3D-module HGamer3D.Data.GameTime--(- GameTime,- sec,- msec,- usec,- - secT,- msecT,- usecT,- - 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)-+{- + 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
@@ -1,83 +1,75 @@--- 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) 2014 - 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/Geometry2D.hs--{-# LANGUAGE FlexibleInstances #-}---- | Type definitions for 2D geometry -module HGamer3D.Data.Geometry2D-(- -- * Geometry- Point (..),- Rectangle (..),- rectFromPoints,- pointsFromRect- -) where- -import Data.MessagePack-import HGamer3D.Data.Component---- | A point has two coordinates an x and y one-data Num a => Point a = Point {- ptX :: a,- ptY :: a- } deriving (Eq, Show)--instance ComponentClass (Point Float) where- toObj (Point a b) = ObjectArray [ObjectFloat a, ObjectFloat b]- fromObj (ObjectArray [ObjectFloat a, ObjectFloat b]) = (Point a b)- -instance ComponentClass (Point Int) where- toObj (Point a b) = ObjectArray [ObjectInt (fromIntegral a), ObjectInt (fromIntegral b)]- fromObj (ObjectArray [ObjectInt a, ObjectInt b]) = (Point (fromIntegral a) (fromIntegral b))- --- | A rectangle has an a position as x and y and widht and height-data Num a => Rectangle a = Rectangle {- rectX :: a,- rectY :: a,- rectWidth :: a,- rectHeight :: a } deriving (Eq, Show)--instance ComponentClass (Rectangle Float) where- toObj (Rectangle x y w h) = ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat w, ObjectFloat h]- fromObj (ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat w, ObjectFloat h]) = (Rectangle x y w h)--instance ComponentClass (Rectangle Int) where- toObj (Rectangle x y w h) = ObjectArray [ObjectInt (fromIntegral x), ObjectInt (fromIntegral y), ObjectInt (fromIntegral w), ObjectInt (fromIntegral h)]- fromObj (ObjectArray [ObjectInt x, ObjectInt y, ObjectInt w, ObjectInt h]) = Rectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)---- | derive a rectangle from upper left and lower right points-rectFromPoints :: Num a => Point a -> Point a -> Rectangle a-rectFromPoints upperLeft lowerRight = Rectangle 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 :: Num a => Rectangle a -> (Point a, Point a)-pointsFromRect rect = (ul, lr) where- rx = rectX rect- ry = rectY rect- rx' = rx + (rectWidth rect)- ry' = ry + (rectHeight rect)- ul = Point rx ry- lr = Point rx' ry'- +{- + 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 +( + -- * Geometry + Point (..), + Rectangle (..), + rectFromPoints, + pointsFromRect + +) where + +import Data.MessagePack +import HGamer3D.Data.Component + +-- | A point has two coordinates an x and y one +data Num a => Point a = Point { + ptX :: a, + ptY :: a + } deriving (Eq, Show) + +instance ComponentClass (Point Float) where + toObj (Point a b) = ObjectArray [ObjectFloat a, ObjectFloat b] + fromObj (ObjectArray [ObjectFloat a, ObjectFloat b]) = (Point a b) + +instance ComponentClass (Point Int) where + toObj (Point a b) = ObjectArray [ObjectInt (fromIntegral a), ObjectInt (fromIntegral b)] + fromObj (ObjectArray [ObjectInt a, ObjectInt b]) = (Point (fromIntegral a) (fromIntegral b)) + +-- | A rectangle has an a position as x and y and widht and height +data Num a => Rectangle a = Rectangle { + rectX :: a, + rectY :: a, + rectWidth :: a, + rectHeight :: a } deriving (Eq, Show) + +instance ComponentClass (Rectangle Float) where + toObj (Rectangle x y w h) = ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat w, ObjectFloat h] + fromObj (ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat w, ObjectFloat h]) = (Rectangle x y w h) + +instance ComponentClass (Rectangle Int) where + toObj (Rectangle x y w h) = ObjectArray [ObjectInt (fromIntegral x), ObjectInt (fromIntegral y), ObjectInt (fromIntegral w), ObjectInt (fromIntegral h)] + fromObj (ObjectArray [ObjectInt x, ObjectInt y, ObjectInt w, ObjectInt h]) = Rectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) + +-- | derive a rectangle from upper left and lower right points +rectFromPoints :: Num a => Point a -> Point a -> Rectangle a +rectFromPoints upperLeft lowerRight = Rectangle 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 :: Num a => Rectangle a -> (Point a, Point a) +pointsFromRect rect = (ul, lr) where + rx = rectX rect + ry = rectY rect + rx' = rx + (rectWidth rect) + ry' = ry + (rectHeight rect) + ul = Point rx ry + lr = Point rx' ry' +
HGamer3D/Data/LMH.hs view
@@ -1,49 +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 - 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/LMH.hs---- | Low Medium High qualification-module HGamer3D.Data.LMH--(- LMH (..)-)--where--import Data.MessagePack-import HGamer3D.Data.Component--data LMH = Disabled- | Low- | Medium- | High--instance ComponentClass LMH where- toObj lmh = case lmh of- Disabled -> ObjectInt 0- Low -> ObjectInt 1- Medium -> ObjectInt 2- High -> ObjectInt 3- fromObj (ObjectInt n) = case n of- 0 -> Disabled- 1 -> Low- 2 -> Medium- 3 -> High-+{- + Low, Medium, High 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/Data/LMH.hs +-} + +-- | Data type to specify a 3 choice volume of anything: Low, Medium, High +module HGamer3D.Data.LMH +( + ctOnOff, + LMH (..), + ctLMH +) + +where + +import Data.MessagePack +import HGamer3D.Data.Component + +ctOnOff :: ComponentType Bool +ctOnOff = ComponentType 0x30b235f8b63df8b0 + +data LMH = Low + | Medium + | High + deriving (Eq, Ord, Show) + +instance ComponentClass LMH where + toObj lmh = case lmh of + Low -> ObjectInt 1 + Medium -> ObjectInt 2 + High -> ObjectInt 3 + fromObj (ObjectInt n) = case n of + 1 -> Low + 2 -> Medium + 3 -> High + +ctLMH :: ComponentType LMH +ctLMH = ComponentType 0xd632bb5447a6c93c + + +
HGamer3D/Data/Transform3D.hs view
@@ -1,68 +1,60 @@--- 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.---- 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)-+{- + 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
@@ -1,37 +1,43 @@--- 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-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/Data/TypeSynonyms.hs---- | Some common type synonyms-module HGamer3D.Data.TypeSynonyms--where--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--+{- + 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/TypeSynonyms.hs +-} + +-- | Some common type synonyms +module HGamer3D.Data.TypeSynonyms + +where + +import HGamer3D.Data.Component +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 + +ctOrientation :: ComponentType Orientation +ctOrientation = ComponentType 0x815eb4d9c7bfaa74 + +ctVisible :: ComponentType Bool +ctVisible = ComponentType 0x98e7a78e949e1c6e + +
HGamer3D/Data/Vector.hs view
@@ -1,85 +1,77 @@--- 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/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 Data.MessagePack-import HGamer3D.Data.Component--deriving instance Eq UnitQuaternion-deriving instance Eq Vec2-deriving instance Eq Vec3-deriving instance Eq Vec4--instance ComponentClass Vec2 where- toObj (Vec2 x y) = ObjectArray [ObjectFloat x, ObjectFloat y]- fromObj (ObjectArray [ObjectFloat x, ObjectFloat y]) = (Vec2 x y)--instance ComponentClass Vec3 where- toObj (Vec3 x y z) = ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat z]- fromObj (ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat z]) = (Vec3 x y z)--instance ComponentClass Vec4 where- toObj (Vec4 w x y z) = ObjectArray [ObjectFloat w, ObjectFloat x, ObjectFloat y, ObjectFloat z]- fromObj (ObjectArray [ObjectFloat w, ObjectFloat x, ObjectFloat y, ObjectFloat z]) = (Vec4 w x y z)--instance ComponentClass Quaternion where- toObj (Q v) = toObj v- fromObj o = Q (fromObj o) --instance ComponentClass UnitQuaternion where- toObj (U v) = toObj v- fromObj o = U (fromObj o) ---- | 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-+{- + 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 Data.MessagePack +import HGamer3D.Data.Component + +deriving instance Eq UnitQuaternion +deriving instance Eq Vec2 +deriving instance Eq Vec3 +deriving instance Eq Vec4 + +instance ComponentClass Vec2 where + toObj (Vec2 x y) = ObjectArray [ObjectFloat x, ObjectFloat y] + fromObj (ObjectArray [ObjectFloat x, ObjectFloat y]) = (Vec2 x y) + +instance ComponentClass Vec3 where + toObj (Vec3 x y z) = ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat z] + fromObj (ObjectArray [ObjectFloat x, ObjectFloat y, ObjectFloat z]) = (Vec3 x y z) + +instance ComponentClass Vec4 where + toObj (Vec4 w x y z) = ObjectArray [ObjectFloat w, ObjectFloat x, ObjectFloat y, ObjectFloat z] + fromObj (ObjectArray [ObjectFloat w, ObjectFloat x, ObjectFloat y, ObjectFloat z]) = (Vec4 w x y z) + +instance ComponentClass Quaternion where + toObj (Q v) = toObj v + fromObj o = Q (fromObj o) + +instance ComponentClass UnitQuaternion where + toObj (U v) = toObj v + fromObj o = U (fromObj o) + +-- | 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 +
HGamer3D/Data/Window.hs view
@@ -1,41 +1,31 @@--- 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) 2014 - 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/Window.hs---- | Type for a system window as its window handle-module HGamer3D.Data.Window-(- -- * Windowing- Window (..),- - -) where--import Data.MessagePack-import HGamer3D.Data.Component---- | A window is simply represented by it's window id, an unsigned C int-data Window = Window Int deriving (Eq, Show)---- | Window i-instance ComponentClass Window where- toObj (Window i) = ObjectInt (fromIntegral i)- fromObj (ObjectInt i) = Window (fromIntegral i)--+{- + 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 Data.MessagePack +import HGamer3D.Data.Component + +type Window = Int + +-- properties +ctWindow :: ComponentType Window +ctWindow = ComponentType 0xad5b3c63f7f7dd1b + +
HGamer3D/ECS.hs view
@@ -1,34 +1,34 @@--- 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/ECS.hs--- ---- | Entity - Component - System for HGamer3D -module HGamer3D.ECS--(- module HGamer3D.ECS.Entity,- module HGamer3D.ECS.System-)--where--import HGamer3D.ECS.Entity-import HGamer3D.ECS.System-+-- 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/ECS.hs +-- + +-- | Entity - Component - System for HGamer3D +module HGamer3D.ECS + +( + module HGamer3D.ECS.Entity, + module HGamer3D.ECS.System +) + +where + +import HGamer3D.ECS.Entity +import HGamer3D.ECS.System +
HGamer3D/ECS/Entity.hs view
@@ -1,181 +1,181 @@--- 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) 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/ECS/Entity--{-# Language ExistentialQuantification #-}---- | Entity of the Entity ComponentType System for HGamer3D-module HGamer3D.ECS.Entity (---- * Entity Data Type--- Entities are a kind of simplified extensible record system. They are basically a Map from ComponentType (64 bit id) to a data item with --- ComponentClass Typeclass. Basic entities are non-mutable but their exists the entity reference.-- Entity,- (#:),- (#?),- (#),---- * ERef Data Type--- The ERef type, which puts an Entity into--- an IORef and serves as mutable data structure.--- In HGamer3D those ERefs are also used as thread-safe communication vehicle towards the C/C++ implementation of multimedia functionality.-- ERef (..),- newE,- readE,- readC,- updateC,- setC,- _setC',---- * Listener--- Mechanism to register listener on ComponentTypes of ERef-- addListener,- clearListeners--)-where--import Data.Maybe-import Data.ByteString---import Data.Dynamic---import Data.Typeable-import qualified Data.Map as M-import Data.IORef--import Control.Concurrent-import Control.Applicative--import Foreign-import Foreign.C--import HGamer3D.Binding-import HGamer3D.Data ---- | Entity, a simple non-mutable record type, implemented as Map-type Entity = M.Map Word64 Component---- | pair builder for nice construction syntax, allows [ ct #: val, ...] syntax-(#:) :: ComponentClass a => ComponentType a -> a -> (Word64, Component)-(ComponentType c) #: val = (c, toMsg val)---- | Builder for entities, allows newE = entity [ct #: val, ...] syntax-entity :: [(Word64, Component)] -> Entity-entity clist = M.fromList clist---- | does the entity have the ComponentType-(#?) :: Entity -> ComponentType a -> Bool-e #? (ComponentType c) = Prelude.elem c $ M.keys e---- | get the ComponentType, throws exception, if ComponentType not present-(#) :: ComponentClass a => Entity -> ComponentType a -> a-e # (ComponentType c) = fromJust $ M.lookup c e >>= fromMsg---- | get the ComponentType as an maybe, in case wrong type-(?#) :: ComponentClass a => Entity -> ComponentType a -> Maybe a-e ?# (ComponentType c) = M.lookup c e >>= fromMsg---- | modification function, throws exception, if ComponentType not present-updateEntity :: ComponentClass a => Entity -> ComponentType a -> (a -> a) -> Entity-updateEntity e c'@(ComponentType c) f = M.insert c ((toMsg . f) (e # c')) e---- | modification function, sets entity ComponentType, needed for events-setComponentType :: ComponentClass a => Entity -> ComponentType a -> a -> Entity-setComponentType e (ComponentType c) val = M.insert c (toMsg val) e----- References to Entities---- besides Entity, we need atomic references to entities, we call them ERef--- ERefs also have listeners for updates---- Listener Map, for each k, manages a map of writers, writers geting the old and the new value after a change--type Listeners = IORef (M.Map Word64 [Entity -> Entity -> IO ()])---- | ERef, composable objects, referenced Entities with listeners-data ERef = ERef (IORef Entity) Listeners deriving (Eq)---- | Add an action (IO function), which will be executed when value of ComponentType is changed-addListener :: ERef -> ComponentType a -> (Entity -> Entity -> IO ()) -> IO ()-addListener (ERef _ tls) (ComponentType c) l = atomicModifyIORef tls (\m -> let- l' = case M.lookup c m of- Just ol -> ol ++ [l]- Nothing -> [l]- in (M.insert c l' m, ()))---- | Clear all listeners from ERef-clearListeners :: ERef -> IO ()-clearListeners (ERef _ tls) = atomicWriteIORef tls (M.fromList [])--fireListeners :: ERef -> ComponentType a -> Entity -> Entity -> IO ()-fireListeners (ERef _ tls) (ComponentType c) val val' = do- ls <- readIORef tls- case M.lookup c ls of- Just l -> mapM (\f -> f val val') l >> return ()- Nothing -> return ()---- | creates an ERef-newE :: [(Word64, Component)] -> IO ERef-newE inlist = do- let e = entity inlist- te <- newIORef e- tl <- newIORef (M.fromList [])- return $ ERef te tl---- | reads the Entity from an ERef-readE :: ERef -> IO Entity-readE (ERef te _) = readIORef te---- | reads one ComponentType, throws exception, if ComponentType not present, or wrong type-readC :: ComponentClass a => ERef -> ComponentType a -> IO a-readC er c = readE er >>= \e -> return (e # c)---- | updates one ComponentType-updateC :: ComponentClass a => ERef -> ComponentType a -> (a -> a) -> IO ()-updateC er@(ERef te tl) c f = do- (e, e') <- atomicModifyIORef te (\olde -> let- newe = updateEntity olde c f- in (newe, (olde, newe)))- fireListeners er c e e'- return ()---- | sets one ComponentType-setC :: ComponentClass a => ERef -> ComponentType a -> a -> IO ()-setC er@(ERef te tl) c val = do- (e, e') <- atomicModifyIORef te (\olde -> let- newe = setComponentType olde c val- in (newe, (olde, newe)))- fireListeners er c e e'- return ()---- | sets one ComponentType as Component-_setC' :: ERef -> Word64 -> Component -> IO ()-_setC' er@(ERef te tls) c val = do- (e, e') <- atomicModifyIORef te (\olde -> let- newe = M.insert c val olde- in (newe, (olde, newe)))- ls <- readIORef tls- case M.lookup c ls of- Just l -> mapM (\f -> f e e') l >> return ()- Nothing -> return ()- return ()-+-- 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) 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/ECS/Entity + +{-# Language ExistentialQuantification #-} + +-- | Entity of the Entity ComponentType System for HGamer3D +module HGamer3D.ECS.Entity ( + +-- * Entity Data Type +-- Entities are a kind of simplified extensible record system. They are basically a Map from ComponentType (64 bit id) to a data item with +-- ComponentClass Typeclass. Basic entities are non-mutable but their exists the entity reference. + + Entity, + (#:), + (#?), + (#), + +-- * ERef Data Type +-- The ERef type, which puts an Entity into +-- an IORef and serves as mutable data structure. +-- In HGamer3D those ERefs are also used as thread-safe communication vehicle towards the C/C++ implementation of multimedia functionality. + + ERef (..), + newE, + readE, + readC, + updateC, + setC, + _setC', + +-- * Listener +-- Mechanism to register listener on ComponentTypes of ERef + + addListener, + clearListeners + +) +where + +import Data.Maybe +import Data.ByteString +--import Data.Dynamic +--import Data.Typeable +import qualified Data.Map as M +import Data.IORef + +import Control.Concurrent +import Control.Applicative + +import Foreign +import Foreign.C + +import HGamer3D.Binding +import HGamer3D.Data + +-- | Entity, a simple non-mutable record type, implemented as Map +type Entity = M.Map Word64 Component + +-- | pair builder for nice construction syntax, allows [ ct #: val, ...] syntax +(#:) :: ComponentClass a => ComponentType a -> a -> (Word64, Component) +(ComponentType c) #: val = (c, toMsg val) + +-- | Builder for entities, allows newE = entity [ct #: val, ...] syntax +entity :: [(Word64, Component)] -> Entity +entity clist = M.fromList clist + +-- | does the entity have the ComponentType +(#?) :: Entity -> ComponentType a -> Bool +e #? (ComponentType c) = Prelude.elem c $ M.keys e + +-- | get the ComponentType, throws exception, if ComponentType not present +(#) :: ComponentClass a => Entity -> ComponentType a -> a +e # (ComponentType c) = fromJust $ M.lookup c e >>= fromMsg + +-- | get the ComponentType as an maybe, in case wrong type +(?#) :: ComponentClass a => Entity -> ComponentType a -> Maybe a +e ?# (ComponentType c) = M.lookup c e >>= fromMsg + +-- | modification function, throws exception, if ComponentType not present +updateEntity :: ComponentClass a => Entity -> ComponentType a -> (a -> a) -> Entity +updateEntity e c'@(ComponentType c) f = M.insert c ((toMsg . f) (e # c')) e + +-- | modification function, sets entity ComponentType, needed for events +setComponentType :: ComponentClass a => Entity -> ComponentType a -> a -> Entity +setComponentType e (ComponentType c) val = M.insert c (toMsg val) e + + +-- References to Entities + +-- besides Entity, we need atomic references to entities, we call them ERef +-- ERefs also have listeners for updates + +-- Listener Map, for each k, manages a map of writers, writers geting the old and the new value after a change + +type Listeners = IORef (M.Map Word64 [Entity -> Entity -> IO ()]) + +-- | ERef, composable objects, referenced Entities with listeners +data ERef = ERef (IORef Entity) Listeners deriving (Eq) + +-- | Add an action (IO function), which will be executed when value of ComponentType is changed +addListener :: ERef -> ComponentType a -> (Entity -> Entity -> IO ()) -> IO () +addListener (ERef _ tls) (ComponentType c) l = atomicModifyIORef tls (\m -> let + l' = case M.lookup c m of + Just ol -> ol ++ [l] + Nothing -> [l] + in (M.insert c l' m, ())) + +-- | Clear all listeners from ERef +clearListeners :: ERef -> IO () +clearListeners (ERef _ tls) = atomicWriteIORef tls (M.fromList []) + +fireListeners :: ERef -> ComponentType a -> Entity -> Entity -> IO () +fireListeners (ERef _ tls) (ComponentType c) val val' = do + ls <- readIORef tls + case M.lookup c ls of + Just l -> mapM (\f -> f val val') l >> return () + Nothing -> return () + +-- | creates an ERef +newE :: [(Word64, Component)] -> IO ERef +newE inlist = do + let e = entity inlist + te <- newIORef e + tl <- newIORef (M.fromList []) + return $ ERef te tl + +-- | reads the Entity from an ERef +readE :: ERef -> IO Entity +readE (ERef te _) = readIORef te + +-- | reads one ComponentType, throws exception, if ComponentType not present, or wrong type +readC :: ComponentClass a => ERef -> ComponentType a -> IO a +readC er c = readE er >>= \e -> return (e # c) + +-- | updates one ComponentType +updateC :: ComponentClass a => ERef -> ComponentType a -> (a -> a) -> IO () +updateC er@(ERef te tl) c f = do + (e, e') <- atomicModifyIORef te (\olde -> let + newe = updateEntity olde c f + in (newe, (olde, newe))) + fireListeners er c e e' + return () + +-- | sets one ComponentType +setC :: ComponentClass a => ERef -> ComponentType a -> a -> IO () +setC er@(ERef te tl) c val = do + (e, e') <- atomicModifyIORef te (\olde -> let + newe = setComponentType olde c val + in (newe, (olde, newe))) + fireListeners er c e e' + return () + +-- | sets one ComponentType as Component +_setC' :: ERef -> Word64 -> Component -> IO () +_setC' er@(ERef te tls) c val = do + (e, e') <- atomicModifyIORef te (\olde -> let + newe = M.insert c val olde + in (newe, (olde, newe))) + ls <- readIORef tls + case M.lookup c ls of + Just l -> mapM (\f -> f e e') l >> return () + Nothing -> return () + return () +
HGamer3D/ECS/System.hs view
@@ -1,255 +1,255 @@--- 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) 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/ECS/System.hs--{-# LANGUAGE ForeignFunctionInterface #-}---- | System of the Entity Component System for HGamer3D-module HGamer3D.ECS.System-(- SystemData (..),- runSystem,- addToWorld,- removeFromWorld-)-where--import Data.Maybe-import Data.Dynamic-import Data.Typeable-import Data.List as L-import qualified Data.Map as M-import Data.IORef--import qualified Data.ByteString as B-import qualified Data.ByteString.Unsafe as BU--import Foreign-import Foreign.C-import Foreign.C.String-import Foreign.Ptr--import Control.Concurrent-import Control.Applicative--import HGamer3D.Binding-import HGamer3D.Data -import HGamer3D.ECS.Entity----- System----- ComponentListener, used internally in sytems--type ComponentListener = IORef (Maybe (Entity, Entity))--componentListener :: ERef -> ComponentType a -> IO ComponentListener-componentListener er@(ERef te tl) c = do- tv <- newIORef Nothing- let w e e' = atomicModifyIORef tv (\old -> let- new = case old of- Nothing -> Just (e, e')- Just (o, o') -> Just (o, e')- in (new, ()))- addListener er c w- return tv--queryComponentListener :: ComponentListener -> IO (Maybe (Entity, Entity))-queryComponentListener tv = atomicModifyIORef tv (\val -> (Nothing, val))---{-- A system reacts towards changes/updates in entities and their components. The system does it by creating for each component it handles an internal represenation, which it modifies upon changes to this component and to potentially additional changes in other components. For example an entity representing a light could have a Light component, which is created and modified upon change in the light component data. The entity may well have also a position component and the light entity is moved, in case the position component is modified.-- In general the system works by keeping a list of component listener on each added (each observes one component of an entity) and functions, which are called, in case the component listener exhibits a component change. ---}--type OnUpdateFunction = Entity -> Entity -> IO ()-type OnDeleteFunction = IO ()-type SystemRecord = (ERef, Either (ComponentListener, OnUpdateFunction) OnDeleteFunction)-type SystemFunction = SystemData -> ERef -> IO [SystemRecord]---- | this data specifies the type of system-data SystemData = SystemData {- sdLock :: MVar (),- sdNewERefs :: IORef [ERef], - sdDelERefs :: IORef [ERef],- sdRecords :: [SystemRecord],- sdComponents :: [Word64],- sdProperties :: [Word64],- sdEvents :: [Word64],-- sdCreateItem :: Word64 -> B.ByteString -> IO (- Int, - Ptr () - ),- sdDestroyItem :: Word64 -> (Ptr ()) -> IO ((Int)),- sdGetMessageSender :: Word64 -> Word64 -> IO ((Int), (FunPtr (Ptr () -> Ptr CChar -> CInt -> IO CInt))),- sdRegisterMessageReceiver :: Word64 -> Word64 -> (Ptr ()) -> (FunPtr (Ptr () -> Ptr CChar -> CInt -> IO CInt)) -> IO Int,- sdErrorMessage :: (Int) -> IO ((String))-}--addERef :: SystemData -> ERef -> IO ()-addERef sd eref = atomicModifyIORef (sdNewERefs sd) (\a -> (eref : a, ()))--removeERef :: SystemData -> ERef -> IO ()-removeERef sd eref = atomicModifyIORef (sdDelERefs sd) (\a -> (eref : a, ()))--stepRecord (er, Left (listener, updateF)) = do- me <- queryComponentListener listener- case me of- Just (e, e') -> do- updateF e e'- return ()--- stepRecord (er, Left (listener, updateF))- Nothing -> return ()-stepRecord (er, Right deleteF) = return ()--stepSystem :: SystemData -> IO Bool -> IO (SystemData, Bool)-stepSystem sd@(SystemData lock nrefs drefs records cs ps es ci di gm rm em) stepF = do-- -- add and delete erefs- adds <- atomicModifyIORef nrefs (\a -> ([],a))- dels <- atomicModifyIORef drefs (\a -> ([],a))-- -- remove instances- let delrecs = filter (\r -> (fst r) `elem` dels) records- mapM (\r -> clearListeners (fst r)) delrecs- mapM (\r -> case snd r of- Right delF -> do- delF -- execute delete function- return ()- _ -> return ()) delrecs- let records' = filter (\r -> not ((fst r) `elem` dels)) records- - -- add new instances- newRecords <- mapM (systemFunction sd) (reverse adds)- let records'' = (concat newRecords) ++ records'-- -- run specific stepSystem- qFlag <- stepF-- -- run stepfunction on tuples - mapM stepRecord records'' -- -- return new values- let newSD = (SystemData lock nrefs drefs records'' cs ps es ci di gm rm em)- return (newSD, qFlag) -- need to add quit condition here- -runS s stepF stepT = do- nowT <- getTime- (s', qFlag) <- stepSystem s stepF- if qFlag then do- shutdownSystem s'- return ()- else do- nowT' <- getTime- let timeUsed = nowT' - nowT- if timeUsed < stepT then do- threadDelay ((fromIntegral . usec) (stepT - timeUsed) )- else do- return ()- runS s' stepF stepT---- | start a new thread, which runs the system-runSystem :: IO Bool -> GameTime -> SystemData -> IO ()-runSystem stepF stepT systemData = do- forkOS $ runS systemData stepF stepT - return ()---- called within the run loop--systemFunction sd eref = do-- let components = sdComponents sd- let properties = sdProperties sd- let events = sdEvents sd-- let createItem = sdCreateItem sd - let destroyItem = sdDestroyItem sd- let getMessageSender = sdGetMessageSender sd- let registerMessageReceiver = sdRegisterMessageReceiver sd- let errorMessage = sdErrorMessage sd-- let r = []- e <- readE eref-- -- create system records, (ERef, Either (Listener, UdateF) DeleteF)-- rs <- mapM (\c -> if c `elem` components- then do (res, rep) <- createItem c (e M.! c) -- create the item- if res == 0 - then do let ir = (eref, Right (destroyItem c rep >> return ()))-- -- add property records with listeners, also components can act as property- prs <- mapM (\p -> if p `elem` (properties ++ components) - then do (res', propF) <- getMessageSender c p- if res' == 0 - then do lp <- componentListener eref (ComponentType p)- let uf = (\oe ne -> callMsgFunction propF rep (ne M.! p) >> return ())- uf e e -- call message function, update component with this property right away- return [(eref, Left (lp, uf) )]- else return []- else return []- ) (M.keys e)-- let prs' = concat prs-- -- add event writer, in case applicable- mapM (\p -> if p `elem` events - then do let fwrite = (\_ msgData msgLen -> do bData <- B.packCStringLen (msgData, fromIntegral msgLen)- _setC' eref p bData- return 0)- fwritePtr <- mkMsgFunPtr fwrite- registerMessageReceiver c p rep fwritePtr- -- we would also need to delete the funptr later with "freeHaskellFunPtr" currently not implemented- return ()- else return ()- ) (M.keys e)-- return $ (ir : prs')- else return []-- else return []- ) (M.keys e) -- return $ concat rs---shutdownSystem :: SystemData -> IO ()-shutdownSystem system = print "Shutdown System received" >> return ()----- management of systems------- | add an ERef to the world, thread safe -addToWorld :: [SystemData] -> ERef -> IO ()-addToWorld systems e = mapM (\s -> addERef s e) systems >> return () ---- | remove an ERef from the world, thread safe -removeFromWorld :: [SystemData] -> ERef -> IO ()-removeFromWorld systems e = mapM (\s -> removeERef s e) systems >> return ()- ---- +-- 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) 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/ECS/System.hs + +{-# LANGUAGE ForeignFunctionInterface #-} + +-- | System of the Entity Component System for HGamer3D +module HGamer3D.ECS.System +( + SystemData (..), + runSystem, + addToWorld, + removeFromWorld +) +where + +import Data.Maybe +import Data.Dynamic +import Data.Typeable +import Data.List as L +import qualified Data.Map as M +import Data.IORef + +import qualified Data.ByteString as B +import qualified Data.ByteString.Unsafe as BU + +import Foreign +import Foreign.C +import Foreign.C.String +import Foreign.Ptr + +import Control.Concurrent +import Control.Applicative + +import HGamer3D.Binding +import HGamer3D.Data +import HGamer3D.ECS.Entity + + +-- System + + +-- ComponentListener, used internally in sytems + +type ComponentListener = IORef (Maybe (Entity, Entity)) + +componentListener :: ERef -> ComponentType a -> IO ComponentListener +componentListener er@(ERef te tl) c = do + tv <- newIORef Nothing + let w e e' = atomicModifyIORef tv (\old -> let + new = case old of + Nothing -> Just (e, e') + Just (o, o') -> Just (o, e') + in (new, ())) + addListener er c w + return tv + +queryComponentListener :: ComponentListener -> IO (Maybe (Entity, Entity)) +queryComponentListener tv = atomicModifyIORef tv (\val -> (Nothing, val)) + + +{- + A system reacts towards changes/updates in entities and their components. The system does it by creating for each component it handles an internal represenation, which it modifies upon changes to this component and to potentially additional changes in other components. For example an entity representing a light could have a Light component, which is created and modified upon change in the light component data. The entity may well have also a position component and the light entity is moved, in case the position component is modified. + + In general the system works by keeping a list of component listener on each added (each observes one component of an entity) and functions, which are called, in case the component listener exhibits a component change. + +-} + +type OnUpdateFunction = Entity -> Entity -> IO () +type OnDeleteFunction = IO () +type SystemRecord = (ERef, Either (ComponentListener, OnUpdateFunction) OnDeleteFunction) +type SystemFunction = SystemData -> ERef -> IO [SystemRecord] + +-- | this data specifies the type of system +data SystemData = SystemData { + sdLock :: MVar (), + sdNewERefs :: IORef [ERef], + sdDelERefs :: IORef [ERef], + sdRecords :: [SystemRecord], + sdComponents :: [Word64], + sdProperties :: [Word64], + sdEvents :: [Word64], + + sdCreateItem :: Word64 -> B.ByteString -> IO ( + Int, + Ptr () + ), + sdDestroyItem :: Word64 -> (Ptr ()) -> IO ((Int)), + sdGetMessageSender :: Word64 -> Word64 -> IO ((Int), (FunPtr (Ptr () -> Ptr CChar -> CInt -> IO CInt))), + sdRegisterMessageReceiver :: Word64 -> Word64 -> (Ptr ()) -> (FunPtr (Ptr () -> Ptr CChar -> CInt -> IO CInt)) -> IO Int, + sdErrorMessage :: (Int) -> IO ((String)) +} + +addERef :: SystemData -> ERef -> IO () +addERef sd eref = atomicModifyIORef (sdNewERefs sd) (\a -> (eref : a, ())) + +removeERef :: SystemData -> ERef -> IO () +removeERef sd eref = atomicModifyIORef (sdDelERefs sd) (\a -> (eref : a, ())) + +stepRecord (er, Left (listener, updateF)) = do + me <- queryComponentListener listener + case me of + Just (e, e') -> do + updateF e e' + return () +-- stepRecord (er, Left (listener, updateF)) + Nothing -> return () +stepRecord (er, Right deleteF) = return () + +stepSystem :: SystemData -> IO Bool -> IO (SystemData, Bool) +stepSystem sd@(SystemData lock nrefs drefs records cs ps es ci di gm rm em) stepF = do + + -- add and delete erefs + adds <- atomicModifyIORef nrefs (\a -> ([],a)) + dels <- atomicModifyIORef drefs (\a -> ([],a)) + + -- remove instances + let delrecs = filter (\r -> (fst r) `elem` dels) records + mapM (\r -> clearListeners (fst r)) delrecs + mapM (\r -> case snd r of + Right delF -> do + delF -- execute delete function + return () + _ -> return ()) delrecs + let records' = filter (\r -> not ((fst r) `elem` dels)) records + + -- add new instances + newRecords <- mapM (systemFunction sd) (reverse adds) + let records'' = (concat newRecords) ++ records' + + -- run specific stepSystem + qFlag <- stepF + + -- run stepfunction on tuples + mapM stepRecord records'' + + -- return new values + let newSD = (SystemData lock nrefs drefs records'' cs ps es ci di gm rm em) + return (newSD, qFlag) -- need to add quit condition here + +runS s stepF stepT = do + nowT <- getTime + (s', qFlag) <- stepSystem s stepF + if qFlag then do + shutdownSystem s' + return () + else do + nowT' <- getTime + let timeUsed = nowT' - nowT + if timeUsed < stepT then do + threadDelay ((fromIntegral . usec) (stepT - timeUsed) ) + else do + return () + runS s' stepF stepT + +-- | start a new thread, which runs the system +runSystem :: IO Bool -> GameTime -> SystemData -> IO () +runSystem stepF stepT systemData = do + forkOS $ runS systemData stepF stepT + return () + +-- called within the run loop + +systemFunction sd eref = do + + let components = sdComponents sd + let properties = sdProperties sd + let events = sdEvents sd + + let createItem = sdCreateItem sd + let destroyItem = sdDestroyItem sd + let getMessageSender = sdGetMessageSender sd + let registerMessageReceiver = sdRegisterMessageReceiver sd + let errorMessage = sdErrorMessage sd + + let r = [] + e <- readE eref + + -- create system records, (ERef, Either (Listener, UdateF) DeleteF) + + rs <- mapM (\c -> if c `elem` components + then do (res, rep) <- createItem c (e M.! c) -- create the item + if res == 0 + then do let ir = (eref, Right (destroyItem c rep >> return ())) + + -- add property records with listeners, also components can act as property + prs <- mapM (\p -> if p `elem` (properties ++ components) + then do (res', propF) <- getMessageSender c p + if res' == 0 + then do lp <- componentListener eref (ComponentType p) + let uf = (\oe ne -> callMsgFunction propF rep (ne M.! p) >> return ()) + uf e e -- call message function, update component with this property right away + return [(eref, Left (lp, uf) )] + else return [] + else return [] + ) (M.keys e) + + let prs' = concat prs + + -- add event writer, in case applicable + mapM (\p -> if p `elem` events + then do let fwrite = (\_ msgData msgLen -> do bData <- B.packCStringLen (msgData, fromIntegral msgLen) + _setC' eref p bData + return 0) + fwritePtr <- mkMsgFunPtr fwrite + registerMessageReceiver c p rep fwritePtr + -- we would also need to delete the funptr later with "freeHaskellFunPtr" currently not implemented + return () + else return () + ) (M.keys e) + + return $ (ir : prs') + else return [] + + else return [] + ) (M.keys e) + + return $ concat rs + + +shutdownSystem :: SystemData -> IO () +shutdownSystem system = print "Shutdown System received" >> return () + + +-- management of systems +-- + +-- | add an ERef to the world, thread safe +addToWorld :: [SystemData] -> ERef -> IO () +addToWorld systems e = mapM (\s -> addERef s e) systems >> return () + +-- | remove an ERef from the world, thread safe +removeFromWorld :: [SystemData] -> ERef -> IO () +removeFromWorld systems e = mapM (\s -> removeERef s e) systems >> return () + + + + +
HGamer3D/Graphics3D.hs view
@@ -1,47 +1,47 @@--- 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/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.Window,- module HGamer3D.Graphics3D.Graphics3DCommand,- module HGamer3D.Graphics3D.Graphics3DConfig,- module HGamer3D.Graphics3D.SystemGraphics3D-)--where--import HGamer3D.Graphics3D.Camera-import HGamer3D.Graphics3D.Geometry-import HGamer3D.Graphics3D.Light-import HGamer3D.Graphics3D.Material-import HGamer3D.Graphics3D.Window-import HGamer3D.Graphics3D.Graphics3DCommand-import HGamer3D.Graphics3D.Graphics3DConfig-import HGamer3D.Graphics3D.SystemGraphics3D--+-- 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/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.Window, + module HGamer3D.Graphics3D.Graphics3DCommand, + module HGamer3D.Graphics3D.Graphics3DConfig, + module HGamer3D.Graphics3D.SystemGraphics3D +) + +where + +import HGamer3D.Graphics3D.Camera +import HGamer3D.Graphics3D.Geometry +import HGamer3D.Graphics3D.Light +import HGamer3D.Graphics3D.Material +import HGamer3D.Graphics3D.Window +import HGamer3D.Graphics3D.Graphics3DCommand +import HGamer3D.Graphics3D.Graphics3DConfig +import HGamer3D.Graphics3D.SystemGraphics3D + +
HGamer3D/Graphics3D/Camera.hs view
@@ -1,66 +1,59 @@--- 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/Graphics3D/Camera.hs---- | Module providing the Camera type-module HGamer3D.Graphics3D.Camera--(- Camera (..),- ctCamera,-- Frustum (..),- ctFrustum-)--where--import Data.MessagePack-import HGamer3D.Data-import HGamer3D.ECS--data Camera = MainCamera- | OverlayCamera (Rectangle Float)- deriving (Eq, Show)--ctCamera :: ComponentType Camera-ctCamera = ComponentType 0xd3b0d455ab1f4716 --instance ComponentClass Camera where- toObj MainCamera = ObjectArray [ObjectInt 0]- toObj (OverlayCamera rec) = ObjectArray [ObjectInt 1, toObj rec]- fromObj (ObjectArray [ObjectInt 0]) = MainCamera- fromObj (ObjectArray [ObjectInt 1, rec_ob]) = OverlayCamera (fromObj rec_ob)--data Frustum = Frustum {- frNearDistance :: Float,- frFarDistance :: Float,- frFieldOfViewHorizontal :: Angle-} deriving (Eq, Show)--instance ComponentClass Frustum where- toObj (Frustum nd fd fovh) = ObjectArray [ObjectFloat nd, ObjectFloat fd, toObj fovh]- fromObj (ObjectArray [ObjectFloat nd, ObjectFloat fd, fovh_o]) = Frustum nd fd (fromObj fovh_o)--ctFrustum :: ComponentType Frustum-ctFrustum = ComponentType 0xf3ce3235d4f8e73d----+{- + 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 Data.MessagePack +import HGamer3D.Data +import HGamer3D.ECS + +-- | The Camera Data Type +data Camera = FullViewCamera -- ^ a camera using the full view + | OverlayCamera (Rectangle Float) -- ^ a camera using only parts of the view (overlay) + deriving (Eq, Show) + +ctCamera :: ComponentType Camera +ctCamera = ComponentType 0xd3b0d455ab1f4716 + +instance ComponentClass Camera where + toObj FullViewCamera = ObjectArray [ObjectInt 0] + toObj (OverlayCamera rec) = ObjectArray [ObjectInt 1, toObj rec] + fromObj (ObjectArray [ObjectInt 0]) = FullViewCamera + fromObj (ObjectArray [ObjectInt 1, rec_ob]) = OverlayCamera (fromObj rec_ob) + +data Frustum = Frustum { + frNearDistance :: Float, + frFarDistance :: Float, + frFieldOfViewHorizontal :: Angle +} deriving (Eq, Show) + +instance ComponentClass Frustum where + toObj (Frustum nd fd fovh) = ObjectArray [ObjectFloat nd, ObjectFloat fd, toObj fovh] + fromObj (ObjectArray [ObjectFloat nd, ObjectFloat fd, fovh_o]) = Frustum nd fd (fromObj fovh_o) + +ctFrustum :: ComponentType Frustum +ctFrustum = ComponentType 0xf3ce3235d4f8e73d + + + +
HGamer3D/Graphics3D/Geometry.hs view
@@ -1,68 +1,78 @@--- 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/Graphics3D/Geometry.hs---- | Module providing the Geometry type-module HGamer3D.Graphics3D.Geometry--(- Shape (..),- Geometry (..),- ctGeometry-)--where--import Data.MessagePack-import Data.Text--import HGamer3D.Data-import HGamer3D.Graphics3D.Material---- | A shape is a basic geometric form-data Shape = Sphere - | Cube- | Plane- deriving (Eq, Show)--instance ComponentClass Shape where- toObj Sphere = ObjectInt 1- toObj Cube = ObjectInt 2- toObj Plane = ObjectInt 3- fromObj (ObjectInt i) = case i of- 1 -> Sphere- 2 -> Cube- 3 -> Plane---- | A geometry is the basic drawable item, it can be a shape or a mesh loaded from a resource-data Geometry = ShapeGeometry Shape- | ResourceGeometry Text- deriving (Eq, Show)---- | Component Type for the Geometry-ctGeometry :: ComponentType Geometry-ctGeometry = ComponentType 0xee433d1a4b964591 --instance ComponentClass Geometry where- toObj (ShapeGeometry sh) = ObjectArray [ObjectInt 1, toObj sh]- toObj (ResourceGeometry mesh) = ObjectArray [ObjectInt 2, toObj mesh]- fromObj (ObjectArray [ObjectInt 1, sh_ob]) = ShapeGeometry (fromObj sh_ob) - fromObj (ObjectArray [ObjectInt 2, mesh_o]) = ResourceGeometry (fromObj mesh_o)--+-- 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/Graphics3D/Geometry.hs + +-- | Module providing the Geometry type +module HGamer3D.Graphics3D.Geometry + +( + Shape (..), + Geometry (..), + ctGeometry +) + +where + +import Data.MessagePack +import Data.Text + +import HGamer3D.Data +import HGamer3D.Graphics3D.Material + +-- | A shape is a basic geometric form +data Shape = Sphere + | Cube + | Plane + | Cylinder + | Pyramid + | Torus + deriving (Eq, Show) + +instance ComponentClass Shape where + toObj shape = case shape of + Sphere -> (ObjectInt 1) + Cube -> (ObjectInt 2) + Plane -> (ObjectInt 3) + Cylinder -> (ObjectInt 4) + Pyramid -> (ObjectInt 5) + Torus -> (ObjectInt 6) + fromObj (ObjectInt i) = case i of + 1 -> Sphere + 2 -> Cube + 3 -> Plane + 4 -> Cylinder + 5 -> Pyramid + 6 -> Torus + +-- | A geometry is the basic drawable item, it can be a shape or a mesh loaded from a resource +data Geometry = ShapeGeometry Shape + | ResourceGeometry Text + deriving (Eq, Show) + +-- | Component Type for the Geometry +ctGeometry :: ComponentType Geometry +ctGeometry = ComponentType 0xee433d1a4b964591 + +instance ComponentClass Geometry where + toObj (ShapeGeometry sh) = ObjectArray [ObjectInt 1, toObj sh] + toObj (ResourceGeometry mesh) = ObjectArray [ObjectInt 2, toObj mesh] + fromObj (ObjectArray [ObjectInt 1, sh_ob]) = ShapeGeometry (fromObj sh_ob) + fromObj (ObjectArray [ObjectInt 2, mesh_o]) = ResourceGeometry (fromObj mesh_o) + +
HGamer3D/Graphics3D/Graphics3DCommand.hs view
@@ -1,51 +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) 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/Graphics3D/Graphics3DCommand.hs---- | Module providing the CmdGraphics3D type-module HGamer3D.Graphics3D.Graphics3DCommand--(- Graphics3DCommand (..),- ctGraphics3DCommand-)--where--import Data.MessagePack-import HGamer3D.Data---- | Commands, which can be sent to graphics system-data Graphics3DCommand = NoCmd - | Step - deriving (Eq, Show)---- | Component Type of Graphics3DCommand-ctGraphics3DCommand :: ComponentType Graphics3DCommand-ctGraphics3DCommand = ComponentType 0xea06bc20a9334af3--instance ComponentClass Graphics3DCommand where- toObj c = case c of- NoCmd -> ObjectArray [ObjectInt 0]- Step -> ObjectArray [ObjectInt 1]-- fromObj c = case c of- (ObjectArray [ObjectInt 0]) -> NoCmd- (ObjectArray [ObjectInt 1]) -> Step-+-- 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/Graphics3D/Graphics3DCommand.hs + +-- | Module providing the CmdGraphics3D type +module HGamer3D.Graphics3D.Graphics3DCommand + +( + Graphics3DCommand (..), + ctGraphics3DCommand +) + +where + +import Data.MessagePack +import HGamer3D.Data + +-- | Commands, which can be sent to graphics system +data Graphics3DCommand = NoCmd + | Step + deriving (Eq, Show) + +-- | Component Type of Graphics3DCommand +ctGraphics3DCommand :: ComponentType Graphics3DCommand +ctGraphics3DCommand = ComponentType 0xea06bc20a9334af3 + +instance ComponentClass Graphics3DCommand where + toObj c = case c of + NoCmd -> ObjectArray [ObjectInt 0] + Step -> ObjectArray [ObjectInt 1] + + fromObj c = case c of + (ObjectArray [ObjectInt 0]) -> NoCmd + (ObjectArray [ObjectInt 1]) -> Step +
HGamer3D/Graphics3D/Graphics3DConfig.hs view
@@ -1,129 +1,129 @@--- 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/Graphics3D/Graphics3DConfig.hs---- | Module providing the InitGraphics3D type-module HGamer3D.Graphics3D.Graphics3DConfig--(- EngineConfig (..),-- LogLevel (..),- Logging (..),- ctLogging,-- GraphicsQuality(..),- ctGraphicsQuality,-- Graphics3DConfig (..),- ctGraphics3DConfig,-- standardGraphics3DConfig-)--where--import Data.MessagePack-import Data.Text--import HGamer3D.Data-import HGamer3D.ECS-import HGamer3D.Graphics3D.Window---- ENGINE CONFIG---- | Base Configuration or Graphics Engine-data EngineConfig = EngineConfig {- ig3dHeadless :: Bool, -- ^ run without graphics output- ig3dFlushGPU :: Bool, - ig3dThreads :: Bool, -- ^ multi threading enabled- ig3dForceGL2 :: Bool -- ^ only GL2 mode, no GL3-}--instance ComponentClass EngineConfig where- toObj (EngineConfig hl fg th fgl2) = ObjectArray [ObjectBool hl, ObjectBool fg, ObjectBool th, ObjectBool fgl2]- fromObj (ObjectArray [ObjectBool hl, ObjectBool fg, ObjectBool th, ObjectBool fgl2]) = EngineConfig hl fg th fgl2--stdEngineConfig = EngineConfig False False True False---- LOGGING CONFIG--data LogLevel = WarningLogLevel | InfoLogLevel | DebugLogLevel--data Logging = Logging {- logLevel :: LogLevel,- quietLogging :: Bool, -- ^ Logging only to file, not to std output- logFileName :: Text -}--instance ComponentClass LogLevel where- toObj WarningLogLevel = ObjectInt 0- toObj InfoLogLevel = ObjectInt 1- toObj DebugLogLevel = ObjectInt 2- fromObj (ObjectInt 0) = WarningLogLevel- fromObj (ObjectInt 1) = InfoLogLevel- fromObj (ObjectInt 2) = DebugLogLevel--instance ComponentClass Logging where- toObj (Logging l q fn) = ObjectArray [toObj l, ObjectBool q, toObj fn]- fromObj (ObjectArray [l, (ObjectBool q), fn_o]) = Logging (fromObj l) q (fromObj fn_o)--ctLogging :: ComponentType Logging-ctLogging = ComponentType 0x86bc15156976f061---- GRAPHICS QUALITY---- | Graphics Quality Setting-data GraphicsQuality = GraphicsQuality {- gqShadow :: LMH, -- ^ Shadow Quality- gqMaterial :: LMH, -- ^ Material Quality- gqTexture :: LMH, -- ^ Texture Quality- gqMultisample :: LMH -- ^ Multisampling Quality-}--instance ComponentClass GraphicsQuality where- toObj (GraphicsQuality sq mq tq ms) = ObjectArray [toObj sq, toObj mq, toObj tq, toObj ms]- fromObj (ObjectArray [sq, mq, tq, ms]) = GraphicsQuality (fromObj sq) (fromObj mq) (fromObj tq) (fromObj ms)--ctGraphicsQuality :: ComponentType GraphicsQuality-ctGraphicsQuality = ComponentType 0x7d9cff864f27c6d2---- GRAPHICS CONFIG---- | Initial Configuration of Graphics Engine-data Graphics3DConfig = Graphics3DConfig EngineConfig WindowG3D (Maybe Logging) (Maybe GraphicsQuality)--mbToObj mbA = case mbA of - Just a -> toObj a- Nothing -> ObjectNil--objToMb o = case o of- ObjectNil -> Nothing- _ -> Just (fromObj o)--instance ComponentClass Graphics3DConfig where- toObj (Graphics3DConfig ec wc mbL mbGQ) = ObjectArray [toObj ec, toObj wc, mbToObj mbL, mbToObj mbGQ]- fromObj (ObjectArray [ec_o, wc_o, l_o, gq_o]) = Graphics3DConfig (fromObj ec_o) (fromObj wc_o) (objToMb l_o) (objToMb gq_o)--standardGraphics3DConfig = Graphics3DConfig stdEngineConfig (xyWindow 800 600) Nothing Nothing --ctGraphics3DConfig :: ComponentType Graphics3DConfig-ctGraphics3DConfig = ComponentType 0x0884eb62b6674bff--+-- 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/Graphics3D/Graphics3DConfig.hs + +-- | Module providing the InitGraphics3D type +module HGamer3D.Graphics3D.Graphics3DConfig + +( + EngineConfig (..), + + LogLevel (..), + Logging (..), + ctLogging, + + GraphicsQuality(..), + ctGraphicsQuality, + + Graphics3DConfig (..), + ctGraphics3DConfig, + + standardGraphics3DConfig +) + +where + +import Data.MessagePack +import Data.Text + +import HGamer3D.Data +import HGamer3D.ECS +import HGamer3D.Graphics3D.Window + +-- ENGINE CONFIG + +-- | Base Configuration or Graphics Engine +data EngineConfig = EngineConfig { + ig3dHeadless :: Bool, -- ^ run without graphics output + ig3dFlushGPU :: Bool, + ig3dThreads :: Bool, -- ^ multi threading enabled + ig3dForceGL2 :: Bool -- ^ only GL2 mode, no GL3 +} + +instance ComponentClass EngineConfig where + toObj (EngineConfig hl fg th fgl2) = ObjectArray [ObjectBool hl, ObjectBool fg, ObjectBool th, ObjectBool fgl2] + fromObj (ObjectArray [ObjectBool hl, ObjectBool fg, ObjectBool th, ObjectBool fgl2]) = EngineConfig hl fg th fgl2 + +stdEngineConfig = EngineConfig False False True False + +-- LOGGING CONFIG + +data LogLevel = WarningLogLevel | InfoLogLevel | DebugLogLevel + +data Logging = Logging { + logLevel :: LogLevel, + quietLogging :: Bool, -- ^ Logging only to file, not to std output + logFileName :: Text +} + +instance ComponentClass LogLevel where + toObj WarningLogLevel = ObjectInt 0 + toObj InfoLogLevel = ObjectInt 1 + toObj DebugLogLevel = ObjectInt 2 + fromObj (ObjectInt 0) = WarningLogLevel + fromObj (ObjectInt 1) = InfoLogLevel + fromObj (ObjectInt 2) = DebugLogLevel + +instance ComponentClass Logging where + toObj (Logging l q fn) = ObjectArray [toObj l, ObjectBool q, toObj fn] + fromObj (ObjectArray [l, (ObjectBool q), fn_o]) = Logging (fromObj l) q (fromObj fn_o) + +ctLogging :: ComponentType Logging +ctLogging = ComponentType 0x86bc15156976f061 + +-- GRAPHICS QUALITY + +-- | Graphics Quality Setting +data GraphicsQuality = GraphicsQuality { + gqShadow :: LMH, -- ^ Shadow Quality + gqMaterial :: LMH, -- ^ Material Quality + gqTexture :: LMH, -- ^ Texture Quality + gqMultisample :: LMH -- ^ Multisampling Quality +} + +instance ComponentClass GraphicsQuality where + toObj (GraphicsQuality sq mq tq ms) = ObjectArray [toObj sq, toObj mq, toObj tq, toObj ms] + fromObj (ObjectArray [sq, mq, tq, ms]) = GraphicsQuality (fromObj sq) (fromObj mq) (fromObj tq) (fromObj ms) + +ctGraphicsQuality :: ComponentType GraphicsQuality +ctGraphicsQuality = ComponentType 0x7d9cff864f27c6d2 + +-- GRAPHICS CONFIG + +-- | Initial Configuration of Graphics Engine +data Graphics3DConfig = Graphics3DConfig EngineConfig WindowG3D (Maybe Logging) (Maybe GraphicsQuality) + +mbToObj mbA = case mbA of + Just a -> toObj a + Nothing -> ObjectNil + +objToMb o = case o of + ObjectNil -> Nothing + _ -> Just (fromObj o) + +instance ComponentClass Graphics3DConfig where + toObj (Graphics3DConfig ec wc mbL mbGQ) = ObjectArray [toObj ec, toObj wc, mbToObj mbL, mbToObj mbGQ] + fromObj (ObjectArray [ec_o, wc_o, l_o, gq_o]) = Graphics3DConfig (fromObj ec_o) (fromObj wc_o) (objToMb l_o) (objToMb gq_o) + +standardGraphics3DConfig = Graphics3DConfig stdEngineConfig (xyWindow 800 600) Nothing Nothing + +ctGraphics3DConfig :: ComponentType Graphics3DConfig +ctGraphics3DConfig = ComponentType 0x0884eb62b6674bff + +
HGamer3D/Graphics3D/Light.hs view
@@ -1,58 +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 - 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/Graphics3D/Light.hs---- | Module providing the Light type-module HGamer3D.Graphics3D.Light--(- Light (..),- LightParameter (..),- ctLight-)--where--import Data.MessagePack-import HGamer3D.Data--data LightParameter = LightParameter Float Float Float Bool -- brightness, range, spec intesity, per vertex- deriving (Eq, Show)--instance ComponentClass LightParameter where- toObj (LightParameter br ra si pv) = ObjectArray [ObjectFloat br, ObjectFloat ra, ObjectFloat si, ObjectBool pv]- fromObj (ObjectArray [ObjectFloat br, ObjectFloat ra, ObjectFloat si, ObjectBool pv]) = LightParameter br ra si pv--data Light = PointLight LightParameter- | DirectionalLight LightParameter- | SpotLight LightParameter Angle Float -- fiel of view, aspect ratio- deriving (Eq, Show)--instance ComponentClass Light where- toObj (PointLight lp) = ObjectArray [ObjectInt 0, toObj lp]- toObj (DirectionalLight lp) = ObjectArray [ObjectInt 1, toObj lp]- toObj (SpotLight lp fov ar) = ObjectArray [ObjectInt 2, toObj lp, toObj fov, ObjectFloat ar]-- fromObj (ObjectArray [ObjectInt 0, lp_o]) = PointLight (fromObj lp_o)- fromObj (ObjectArray [ObjectInt 1, lp_o]) = DirectionalLight (fromObj lp_o)- fromObj (ObjectArray [ObjectInt 2, lp_o, fov_o, ObjectFloat ar]) = SpotLight (fromObj lp_o) (fromObj fov_o) ar--ctLight :: ComponentType Light-ctLight = ComponentType 0x981e80e50d994ea9-+{- + Light 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/Light.hs +-} + +-- | Module providing the Light type +module HGamer3D.Graphics3D.Light + +( + LightType (..), + Light (..), + ctLight +) + +where + +import Data.MessagePack +import HGamer3D.Data + +data LightType = PointLight -- ^ casting light in all directions, from position + | DirectionalLight -- ^ like a very far light source (the Sun) + | SpotLight Angle Float -- ^ a light with a field of view (Angle) and an aspect-ratio (Float) + +instance ComponentClass LightType where + toObj PointLight = ObjectArray [ObjectInt 0] + toObj DirectionalLight = ObjectArray [ObjectInt 1] + toObj (SpotLight fov ar) = ObjectArray [ObjectInt 2, toObj fov, ObjectFloat ar] + + fromObj (ObjectArray [ObjectInt 0]) = PointLight + fromObj (ObjectArray [ObjectInt 1]) = DirectionalLight + fromObj (ObjectArray [ObjectInt 2, fov_o, ObjectFloat ar]) = SpotLight (fromObj fov_o) ar + + +data Light = Light + LightType -- ^ Type of light + Float -- ^ brighness + Float -- ^ range + Float -- ^ specular intensity + +instance ComponentClass Light where + toObj (Light lt b r s) = ObjectArray [toObj lt, ObjectFloat b, ObjectFloat r, ObjectFloat s] + fromObj (ObjectArray [lt_o, ObjectFloat b, ObjectFloat r, ObjectFloat s]) = Light (fromObj lt_o) b r s + +ctLight :: ComponentType Light +ctLight = ComponentType 0x981e80e50d994ea9 +
HGamer3D/Graphics3D/Material.hs view
@@ -1,101 +1,138 @@--- 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/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,- matGrayGrass,- matSand,- matRedRock,- matBlackRock,- matBrownStone,- matStoneMetalWall,- matCoalWall,- matBrickWallGray,- matBrickWallRed,- matTilesOrange,- matWoodTiles,- matColourTiles,- matBlackTiles-)--where--import Data.MessagePack-import Data.Text--import HGamer3D.Data--data Material = ResourceMaterial Text deriving (Eq, Show)--ctMaterial :: ComponentType Material-ctMaterial = ComponentType 0xb4bae8b0d0d8c162--instance ComponentClass Material where- toObj (ResourceMaterial resource) = ObjectArray [ObjectInt 1, toObj resource]- fromObj ( (ObjectArray [ObjectInt 1, resource_o])) = ResourceMaterial (fromObj resource_o)---- 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"-matGrayGrass = 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"-+-- 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/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 Data.MessagePack +import Data.Text + +import HGamer3D.Data + +data Material = ResourceMaterial Text deriving (Eq, Show) + +ctMaterial :: ComponentType Material +ctMaterial = ComponentType 0xb4bae8b0d0d8c162 + +instance ComponentClass Material where + toObj (ResourceMaterial resource) = ObjectArray [ObjectInt 1, toObj resource] + fromObj ( (ObjectArray [ObjectInt 1, resource_o])) = ResourceMaterial (fromObj resource_o) + +-- 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" + +
HGamer3D/Graphics3D/SystemGraphics3D.hs view
@@ -1,99 +1,112 @@--- 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.---- | the Graphics3D System of the Entity-Component-System World--{-# LANGUAGE StandaloneDeriving, OverloadedStrings, ForeignFunctionInterface #-}-{-# OPTIONS_HADDOCK hide #-}--module HGamer3D.Graphics3D.SystemGraphics3D--( - ctPosition,- ctScale,- ctOrientation,-- forkGraphics3DWorld-)--where--import Control.Monad-import Control.Concurrent.MVar-import Data.Maybe-import Data.Typeable-import Data.Dynamic-import Data.IORef-import Data.Map-import qualified Data.ByteString as B--import qualified Data.Text as T-import Data.Word--import Foreign-import Foreign.C-import Foreign.Ptr--import HGamer3D.Data-import HGamer3D.ECS-import HGamer3D.Util--import qualified HGamer3D.Binding as B-import HGamer3D.Graphics3D.Graphics3DConfig-import HGamer3D.Graphics3D.Graphics3DCommand-import HGamer3D.Graphics3D.Light-import HGamer3D.Graphics3D.Window-import HGamer3D.Graphics3D.Camera-import HGamer3D.Graphics3D.Geometry-import HGamer3D.Graphics3D.Material-import HGamer3D.Input.InputEvents---w64 (ComponentType w) = w---- properties-ctPosition :: ComponentType Position-ctPosition = ComponentType 0x29aacbbb10c84016--ctScale :: ComponentType Scale-ctScale = ComponentType 0x2f9c124bc8fd41c4--ctOrientation :: ComponentType Orientation-ctOrientation = ComponentType 0x815eb4d9c7bfaa74--systemData = do- lock <- newMVar ()- ne <- newIORef []- de <- newIORef []- return $ SystemData lock ne de []- [w64 ctGraphics3DConfig, w64 ctCamera, w64 ctLight, w64 ctGeometry, w64 ctInputEventHub]- [w64 ctPosition, w64 ctScale, w64 ctOrientation, w64 ctGraphics3DCommand, w64 ctMaterial]- [w64 ctMouseEvent]- B.createItem- B.destroyItem- B.getMessageSender- B.registerMessageReceiver- B.errorMessage---- | start a graphics world-forkGraphics3DWorld :: IO Bool -> GameTime -> IO [SystemData] -forkGraphics3DWorld stepF sleepT = do- sd <- systemData- runSystem stepF sleepT sd- return $ [sd]- +-- 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. + +-- | the Graphics3D System of the Entity-Component-System World + +{-# LANGUAGE StandaloneDeriving, OverloadedStrings, ForeignFunctionInterface #-} +{-# OPTIONS_HADDOCK hide #-} + +module HGamer3D.Graphics3D.SystemGraphics3D + +( + forkGraphics3DWorld +) + +where + +import Control.Monad +import Control.Concurrent.MVar +import Data.Maybe +import Data.Typeable +import Data.Dynamic +import Data.IORef +import Data.Map +import qualified Data.ByteString as B + +import qualified Data.Text as T +import Data.Word + +import Foreign +import Foreign.C +import Foreign.Ptr + +import HGamer3D.Data +import HGamer3D.ECS +import HGamer3D.Util + +import qualified HGamer3D.Binding as B +import HGamer3D.Graphics3D.Graphics3DConfig +import HGamer3D.Graphics3D.Graphics3DCommand +import HGamer3D.Graphics3D.Light +import HGamer3D.Graphics3D.Window +import HGamer3D.Graphics3D.Camera +import HGamer3D.Graphics3D.Geometry +import HGamer3D.Graphics3D.Material +import HGamer3D.Input + + +w64 (ComponentType w) = w + +systemData = do + lock <- newMVar () + ne <- newIORef [] + de <- newIORef [] + return $ SystemData lock ne de [] + -- TABLE OF RECOGNIZED COMPONENTS + + -- Components, which can be created: + [ + w64 ctGraphics3DConfig, + w64 ctCamera, + w64 ctLight, + w64 ctGeometry, + w64 ctMouse, + w64 ctKeyEvent + ] + + -- Properties, which receive messages: + [ + w64 ctPosition, + w64 ctScale, + w64 ctOrientation, + w64 ctGraphics3DCommand, + w64 ctMaterial, + w64 ctColour, + w64 ctVisible + ] + + -- Properties, which send messages: + [ + w64 ctMouseEvent, + w64 ctVisible, + w64 ctKeyEvent + ] + + B.createItem + B.destroyItem + B.getMessageSender + B.registerMessageReceiver + B.errorMessage + +-- | start a graphics world +forkGraphics3DWorld :: IO Bool -> GameTime -> IO [SystemData] +forkGraphics3DWorld stepF sleepT = do + sd <- systemData + runSystem stepF sleepT sd + return $ [sd] +
HGamer3D/Graphics3D/Window.hs view
@@ -1,54 +1,54 @@--- 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/Graphics3D/Camera.hs---- | Module providing the Window type-module HGamer3D.Graphics3D.Window--(- WindowG3D (..),- ctWGr,- xyWindow,- fullScreen-)--where--import Data.MessagePack-import HGamer3D.Data-import HGamer3D.ECS--data WindowG3D = WindowG3D {- wg3dWindowWidth :: Int,- wg3dWindowHeight :: Int,- wg3dBorderless :: Bool,- wg3dFullScreen :: Bool,- wg3dWindowResizable :: Bool-}--instance ComponentClass WindowG3D where- toObj (WindowG3D ww wh bl fs wr) = ObjectArray [ObjectInt (fromIntegral ww), ObjectInt (fromIntegral wh), ObjectBool bl, ObjectBool fs, ObjectBool wr]- fromObj (ObjectArray [ObjectInt ww, ObjectInt wh, ObjectBool bl, ObjectBool fs, ObjectBool wr]) = WindowG3D (fromIntegral ww) (fromIntegral wh) bl fs wr--ctWGr :: ComponentType WindowG3D-ctWGr = ComponentType 0xed96843bfb53d99e--xyWindow x y = WindowG3D x y False False True-fullScreen = WindowG3D 0 0 True True False-+-- 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/Graphics3D/Camera.hs + +-- | Module providing the Window type +module HGamer3D.Graphics3D.Window + +( + WindowG3D (..), + ctWGr, + xyWindow, + fullScreen +) + +where + +import Data.MessagePack +import HGamer3D.Data +import HGamer3D.ECS + +data WindowG3D = WindowG3D { + wg3dWindowWidth :: Int, + wg3dWindowHeight :: Int, + wg3dBorderless :: Bool, + wg3dFullScreen :: Bool, + wg3dWindowResizable :: Bool +} + +instance ComponentClass WindowG3D where + toObj (WindowG3D ww wh bl fs wr) = ObjectArray [ObjectInt (fromIntegral ww), ObjectInt (fromIntegral wh), ObjectBool bl, ObjectBool fs, ObjectBool wr] + fromObj (ObjectArray [ObjectInt ww, ObjectInt wh, ObjectBool bl, ObjectBool fs, ObjectBool wr]) = WindowG3D (fromIntegral ww) (fromIntegral wh) bl fs wr + +ctWGr :: ComponentType WindowG3D +ctWGr = ComponentType 0xed96843bfb53d99e + +xyWindow x y = WindowG3D x y False False True +fullScreen = WindowG3D 0 0 True True False +
HGamer3D/Input.hs view
@@ -1,33 +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.InputEvents-)--where--import HGamer3D.Input.InputEvents--+-- 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/InputEvents.hs view
@@ -44,15 +44,16 @@ ctMouseEvent = ComponentType 0x27eaf3fd46595d08 data MouseEvent = MousePosition Int Int- | MouseLeftClick- | MouseRightClick- deriving (Eq, Show)+ | MouseButtonUp Int+ | MouseButtonDown Int+ deriving (Eq, Show) instance ComponentClass MouseEvent where toObj (MousePosition x y) = ObjectArray [ObjectInt 1, ObjectInt (fromIntegral x), ObjectInt (fromIntegral y)]- toObj MouseLeftClick = ObjectArray [ObjectInt 2]- toObj MouseRightClick = ObjectArray [ObjectInt 3]+ toObj (MouseButtonDown b) = ObjectArray [ObjectInt 2, ObjectInt (fromIntegral b)]+ toObj (MouseButtonUp b) =ObjectArray [ObjectInt 3, ObjectInt (fromIntegral b)] fromObj (ObjectArray [ObjectInt 1, ObjectInt x, ObjectInt y]) = MousePosition (fromIntegral x) (fromIntegral y)- fromObj (ObjectArray [ObjectInt 2]) = MouseLeftClick- fromObj (ObjectArray [ObjectInt 3]) = MouseRightClick+ fromObj (ObjectArray [ObjectInt 2, ObjectInt b]) = MouseButtonDown (fromIntegral b)+ fromObj (ObjectArray [ObjectInt 3, ObjectInt b]) = MouseButtonUp (fromIntegral b)+ fromObj obj = trace (show obj) (MousePosition 0 0)
+ HGamer3D/Input/Joystick.hs view
@@ -0,0 +1,25 @@+{- + 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 Data.MessagePack +import Debug.Trace +import Data.Text + +import HGamer3D.Data +
+ HGamer3D/Input/Keyboard.hs view
@@ -0,0 +1,43 @@+{- + 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 + +( + KeyEvent (..), + ctKeyEvent +) + +where + +import Data.MessagePack +import Debug.Trace +import Data.Text + +import HGamer3D.Data + +data KeyEvent = KeyUp Int Int Text -- Key, Scancode, Name + | KeyDown Int Int Text -- Key, Scancode, Name + deriving (Eq, Show) + +instance ComponentClass KeyEvent where + toObj (KeyUp k s n) = ObjectArray [ObjectInt 1, ObjectInt (fromIntegral k), ObjectInt (fromIntegral s), toObj n] + toObj (KeyDown k s n) = ObjectArray [ObjectInt 2, ObjectInt (fromIntegral k), ObjectInt (fromIntegral s), toObj n] + fromObj (ObjectArray [ObjectInt 1, ObjectInt k, ObjectInt s, n_o]) = KeyUp (fromIntegral k) (fromIntegral s) (fromObj n_o) + fromObj (ObjectArray [ObjectInt 2, ObjectInt k, ObjectInt s, n_o]) = KeyDown (fromIntegral k) (fromIntegral s) (fromObj n_o) + +ctKeyEvent :: ComponentType KeyEvent +ctKeyEvent = ComponentType 0x5ba1617fb50e97e5 + + +
+ HGamer3D/Input/Mouse.hs view
@@ -0,0 +1,80 @@+{- + Mouse 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/Mouse.hs +-} + +-- | Module providing the Mouse functionality and settings +module HGamer3D.Input.Mouse +( + MouseMode (..), + Mouse (..), + MouseEvent (..), + ctMouse, + ctMouseEvent +) + +where + +import Data.MessagePack +import Debug.Trace +import Data.Text + +import HGamer3D.Data + + +-- Mouse mode and Mouse datatype + +data MouseMode = MMAbsolute + | MMRelative + | MMWrap + deriving (Eq, Show) + +instance ComponentClass MouseMode where + toObj MMAbsolute = ObjectInt 1 + toObj MMRelative = ObjectInt 2 + toObj MMWrap = ObjectInt 3 + fromObj (ObjectInt 1) = MMAbsolute + fromObj (ObjectInt 2) = MMRelative + fromObj (ObjectInt 3) = MMWrap + +data Mouse = Mouse MouseMode deriving (Eq, Show) + +instance ComponentClass Mouse where + toObj (Mouse mm) = ObjectArray [ObjectInt 1, toObj mm] + fromObj (ObjectArray [ObjectInt 1, mm_o]) = Mouse (fromObj mm_o) + +ctMouse :: ComponentType Mouse +ctMouse = ComponentType 0xa532f43b1c1c6bc7 + +-- Mouse Events + +data MouseEvent = MouseButtonUp Int Int Int -- Button, Buttons, Qualifiers + | MouseButtonDown Int Int Int -- Button, Buttons, Qualifiers + | MouseMove Int Int Int Int Int Int -- X, Y, DX, DY, Buttons, Qualifiers + | MouseWheel Int Int Int -- Wheel, Buttons, Qualifiers + | MouseVisibleChanged Bool -- Visible + deriving (Eq, Show) + +instance ComponentClass MouseEvent where + toObj (MouseButtonUp b bs qs) = ObjectArray [ObjectInt 1, ObjectInt (fromIntegral b), ObjectInt (fromIntegral bs), ObjectInt (fromIntegral qs)] + toObj (MouseButtonDown b bs qs) = ObjectArray [ObjectInt 2, ObjectInt (fromIntegral b), ObjectInt (fromIntegral bs), ObjectInt (fromIntegral qs)] + toObj (MouseMove x y dx dy bs qs) = ObjectArray [ObjectInt 3, ObjectInt (fromIntegral x), ObjectInt (fromIntegral y), ObjectInt (fromIntegral dx), ObjectInt (fromIntegral dy), ObjectInt (fromIntegral bs), ObjectInt (fromIntegral qs)] + toObj (MouseWheel w bs qs) = ObjectArray [ObjectInt 4, ObjectInt (fromIntegral w), ObjectInt (fromIntegral bs), ObjectInt (fromIntegral qs)] + toObj (MouseVisibleChanged v) = ObjectArray [ObjectInt 5, ObjectBool v] + + fromObj (ObjectArray [ObjectInt 1, ObjectInt b, ObjectInt bs, ObjectInt qs]) = MouseButtonUp (fromIntegral b) (fromIntegral bs) (fromIntegral qs) + fromObj (ObjectArray [ObjectInt 2, ObjectInt b, ObjectInt bs, ObjectInt qs]) = MouseButtonDown (fromIntegral b) (fromIntegral bs) (fromIntegral qs) + fromObj (ObjectArray [ObjectInt 3, ObjectInt x, ObjectInt y, ObjectInt dx, ObjectInt dy, ObjectInt bs, ObjectInt qs]) = MouseMove (fromIntegral x) (fromIntegral y) (fromIntegral dx) (fromIntegral dy) (fromIntegral bs) (fromIntegral qs) + fromObj (ObjectArray [ObjectInt 4, ObjectInt w, ObjectInt bs, ObjectInt qs]) = MouseWheel (fromIntegral w) (fromIntegral bs) (fromIntegral qs) + fromObj (ObjectArray [ObjectInt 5, ObjectBool v]) = MouseVisibleChanged v + +ctMouseEvent :: ComponentType MouseEvent +ctMouseEvent = ComponentType 0x27eaf3fd46595d08 +
HGamer3D/Util.hs view
@@ -1,34 +1,34 @@--- 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-)--where--import HGamer3D.Util.FileLocation-import HGamer3D.Util.UniqueName-+-- 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 +) + +where + +import HGamer3D.Util.FileLocation +import HGamer3D.Util.UniqueName +
HGamer3D/Util/FileLocation.hs view
@@ -1,50 +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")-+-- 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
@@ -1,48 +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- - +-- 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 + +
LICENSE view
@@ -1,42 +1,42 @@-LICENSE----------(c) 2011-2014 Peter Althainz---HGamer3D (http://www.hgamer3d.org)-------------------------------------HGamer3D is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software 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.---Source Code-------------You can obtain the latest version of the source code under http://www.bitbucket.org/althainz/HGamer3D---Open Source Software Used - Module HGamer3D----------------------------------------------HGamer3D uses a number of open source software libraries. You are responsible to comply to the licenses of those packages and the licenses of software used by those packages if you use HGamer3D. --The HGamer3D module uses the following Haskell libraries from Hackage:--base, license: BSD3-containers, license: BSD3-text, license: BSD3-directory, license: BSD3-mtl, license: BSD3-FindBin, license: BSD3-monad-loops, license: PublicDomain, BSD3 similar-split, license: BSD3-netwire, license: BSD3-HGamer3D-Data, license: Apache 2.0-HGamer3D-Ogre-Binding, license: Apache 2.0 and dependencies see in that module-HGamer3D-SFML-Binding, license: Apache 2.0 and dependencies see in that module -HGamer3D-CEGUI-Binding, license: Apache 2.0 and dependencies see in that module-HGamer3D-Enet-Binding, license: Apache 2.0 and dependencies see in that module+LICENSE +------- + +(c) 2011-2014 Peter Althainz + + +HGamer3D (http://www.hgamer3d.org) +---------------------------------- + +HGamer3D is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software 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. + + +Source Code +----------- +You can obtain the latest version of the source code under http://www.bitbucket.org/althainz/HGamer3D + + +Open Source Software Used - Module HGamer3D +------------------------------------------- + +HGamer3D uses a number of open source software libraries. You are responsible to comply to the licenses of those packages and the licenses of software used by those packages if you use HGamer3D. + +The HGamer3D module uses the following Haskell libraries from Hackage: + +base, license: BSD3 +containers, license: BSD3 +text, license: BSD3 +directory, license: BSD3 +mtl, license: BSD3 +FindBin, license: BSD3 +monad-loops, license: PublicDomain, BSD3 similar +split, license: BSD3 +netwire, license: BSD3 +HGamer3D-Data, license: Apache 2.0 +HGamer3D-Ogre-Binding, license: Apache 2.0 and dependencies see in that module +HGamer3D-SFML-Binding, license: Apache 2.0 and dependencies see in that module +HGamer3D-CEGUI-Binding, license: Apache 2.0 and dependencies see in that module +HGamer3D-Enet-Binding, license: Apache 2.0 and dependencies see in that module
Setup.hs view
@@ -1,22 +1,22 @@--- 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.---- Setup.hs--import Distribution.Simple-main = defaultMain+-- 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. + +-- Setup.hs + +import Distribution.Simple +main = defaultMain