From 9757f020c1c1372766dcf8a94309012dc7a66713 Mon Sep 17 00:00:00 2001 From: Urs of the Backwoods Date: Sun, 14 Aug 2016 18:44:22 +0200 Subject: [PATCH] Version 0.8, running in main thread (Mac), examples fix, gui brush up --- create_project/CreateProject | 4 +- create_project/CreateProject-0.8 | 42 +++++ create_project/CreateProject-0.8.sig | 2 + create_project/create_project.lua | 38 ++-- examples/Billion.hs | 56 +++--- examples/Cuboid2.hs | 70 ++++---- examples/Gui1.hs | 69 ++++--- examples/Materials.hs | 31 ++-- examples/Mouse.hs | 93 ++++++++++ examples/RotatingCube.hs | 103 +++++------ examples/RotatingCube2.hs | 76 ++++++++ examples/SoundEffects.hs | 37 ++-- examples/SpaceInvaders.hs | 62 ++++--- examples/TestDel.hs | 112 ++++++++++++ examples/stack.yaml | 7 +- src/CFunctions.chs | 74 -------- src/HGamer3D.cabal | 6 +- src/HGamer3D.cabal.tmpl | 32 ---- src/HGamer3D.hs | 189 ++++++++++++++------ src/HGamer3D/Data.hs | 2 + src/HGamer3D/Data/Geometry2D.hs | 2 +- src/HGamer3D/Data/Parent.hs | 31 ++++ src/HGamer3D/Data/TypeSynonyms.hs | 4 +- src/HGamer3D/GUI.hs | 2 + src/HGamer3D/GUI/Button.hs | 19 +- src/HGamer3D/GUI/UIElement.hs | 31 ++++ src/HGamer3D/Graphics3D/Geometry.hs | 11 +- src/HGamer3D/Graphics3D/Graphics3DConfig.hs | 2 + src/HGamer3D/Graphics3D/Light.hs | 8 +- src/HGamer3D/Util.hs | 6 +- src/HGamer3D/Util/EntityTree.hs | 34 ++++ src/stack.yaml | 2 +- tools/random.txt | 8 +- 33 files changed, 824 insertions(+), 441 deletions(-) create mode 100644 create_project/CreateProject-0.8 create mode 100644 create_project/CreateProject-0.8.sig create mode 100644 examples/Mouse.hs create mode 100644 examples/RotatingCube2.hs create mode 100644 examples/TestDel.hs delete mode 100644 src/CFunctions.chs delete mode 100644 src/HGamer3D.cabal.tmpl create mode 100644 src/HGamer3D/Data/Parent.hs create mode 100644 src/HGamer3D/GUI/UIElement.hs create mode 100644 src/HGamer3D/Util/EntityTree.hs diff --git a/create_project/CreateProject b/create_project/CreateProject index a0d5064..a40292d 100644 --- a/create_project/CreateProject +++ b/create_project/CreateProject @@ -28,9 +28,9 @@ limitations under the License. signingkey = "https://www.github.com/urs-of-the-backwoods.keys" [[Impls]] - location = "http://www.hgamer3d.org/downloads/scripts-0.1.3.tar.gz" + location = "http://www.hgamer3d.org/downloads/scripts-0.2.0.tar.gz" signingkey = "https://www.github.com/urs-of-the-backwoods.keys" - version = "0.1.3" + version = "0.2.0" architecture = "*" os = "*" command = "create_project.lua" diff --git a/create_project/CreateProject-0.8 b/create_project/CreateProject-0.8 new file mode 100644 index 0000000..84fe6ef --- /dev/null +++ b/create_project/CreateProject-0.8 @@ -0,0 +1,42 @@ +# arriccio.toml file for HGamer3D - Create Project utility script + +Id = "http://www.hgamer3d.org/component/CreateProject-0.8" +Purpose = "Scaffolding a basic HGamer3D project" +Description = """ + Using this command you can create a basic project in the current folder. + Make sure you start it in an empty target folder. +""" + +License = "Apache 2.0 License" + +FullLicenseText = """ +Copyright 2016 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. +""" + +signingkey = "https://www.github.com/urs-of-the-backwoods.keys" + +[[Impls]] + location = "http://www.hgamer3d.org/downloads/scripts-0.2.0.tar.gz" + signingkey = "https://www.github.com/urs-of-the-backwoods.keys" + version = "0.2.0" + architecture = "*" + os = "*" + command = "create_project.lua" + environment = ["add-path LUA_PATH ./?.lua"] + +[[Impls.dependencies]] + Id = "http://www.hgamer3d.org/component/Lua" + VersionConstraint = "5.2" + diff --git a/create_project/CreateProject-0.8.sig b/create_project/CreateProject-0.8.sig new file mode 100644 index 0000000..d2868ce --- /dev/null +++ b/create_project/CreateProject-0.8.sig @@ -0,0 +1,2 @@ +ssh-rsa +NkY8A0UzK7o00P3c6MgvrtSSNim+AOPXXZRhMvUB/wiJ5QiJf5Mkpg+xmPvtGK2aKJTHoKaHYmKzfZegb0Dc0PElvbe7659qBIglewFzt5N4nBzCdSCZ6JCV+rjbL4KZBFoBYCuaJooWu2mKbBw/qh53nGROq2bHa7JwAXLd0Nap8aMLs5mnb6k5CdtOPLXdogJA3HezcKHJOn3lq9MsY4hhOgQaI5Y9lUZu2YdDAmIOjJWB/UY+uTgkH9z8QVci2URHl4KHzsFbkWR+9UIZSx6N7Msz/FYtfoO5uJ6TY5HLx1nWTkcyHWGx+1t0y1CRVlSGNN6WGn6g/biX6GgRdUx++R7xx4a0mbd0kjtCLM6LkxOuEL5nOjSno/MRZmMGFA8MPBJ1+3VU/fEh0FFioJpIrsRkTERa776LvdvPF/5IlfIMWtIjzvuaeqotb+nKmm/KugY/6uGMTgCqKD9RB9H1mciiVNXKW1vAh9mfeSwzHtmWwu1jeBZg5550ghUm1TdYfKl3iR81eDHFvyhy/cwCuCCCSlsQb8m5+0QgWlmvzMQgb1eBJkWH72uoXx6cnUL6PqvqiOFh8biB4/bnDFFBUycmHEcgRehrtlKBq8SQGUtckL416Xt+y+gDaBuWhVm5bHBHSeU52jcDIk5QUsqTyrLeM7aHA54m+tCIitI= diff --git a/create_project/create_project.lua b/create_project/create_project.lua index 89c2ca4..271c608 100644 --- a/create_project/create_project.lua +++ b/create_project/create_project.lua @@ -24,7 +24,7 @@ executable game hs-source-dirs: . main-is: game.hs ghc-options: -threaded -rtsopts -with-rtsopts=-N - build-depends: base, text, HGamer3D >= 0.7.1 + build-depends: base, text, HGamer3D (>= 0.8.0 && < 2.0.0) default-language: Haskell2010 ]] @@ -67,7 +67,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ]] yaml_file = [[ -extra-deps: ["HGamer3D-0.7.1", "fresco-binding-0.1.1", "vect-0.4.7"] +extra-deps: ["HGamer3D-0.8.0", "fresco-binding-0.2.0", "vect-0.4.7"] resolver: lts-5.8 flags: {} packages: ["."] @@ -84,13 +84,10 @@ import Control.Concurrent import Control.Monad import System.Exit -start = do - - -- initialize system - hg3d <- configureHG3D -- initialize +gameLogic hg3d = do -- create minimum elements, like a camera - eCam <- newE [ + eCam <- newE hg3d [ ctCamera #: FullViewCamera, ctPosition #: Vec3 1 1 (-30.0), ctLight #: Light PointLight 1.0 1000.0 1.0 @@ -99,12 +96,12 @@ start = do -- do something interesting here, in this example case, it is a text and -- a rotating cube - eText <- newE [ + eText <- newE hg3d [ ctText #: "Rotating Cube Example", ctScreenRect #: Rectangle 10 10 100 25 ] - eGeo <- newE [ + eGeo <- newE hg3d [ ctGeometry #: ShapeGeometry Cube, ctMaterial #: matBlue, ctScale #: Vec3 10.0 10.0 10.0, @@ -112,20 +109,17 @@ start = do ctOrientation #: unitU ] - return (eGeo, hg3d) - + let rotateCube = do + forever $ do + updateC eGeo ctOrientation (\u -> (rotU vec3Z 0.02) .*. u) + updateC eGeo ctOrientation (\u -> (rotU vec3X 0.015) .*. u) + sleepFor (msecT 12) -rotateCube eGeo = do - forever $ do - updateC eGeo ctOrientation (\u -> (rotU vec3Z 0.02) .*. u) - updateC eGeo ctOrientation (\u -> (rotU vec3X 0.015) .*. u) - sleepFor (msecT 12) + forkIO rotateCube return () main = do - (eGeo, hg3d) <- start - forkIO $ rotateCube eGeo - loopHG3D hg3d (msecT 20) (return True) -- allow close on windows click + runGame standardGraphics3DConfig gameLogic (msecT 20) return () ]] @@ -143,11 +137,11 @@ writeIt("Setup.hs", setup_file) writeIt("game.cabal", cabal_file) run_file = [[ -aio start http://www.hgamer3d.org/component/Run-0.7 ./game +aio start http://www.hgamer3d.org/component/Run-1 ./game ]] run_file_windows = [[ -aio start http://www.hgamer3d.org/component/Run-0.7 game.exe +aio start http://www.hgamer3d.org/component/Run-1 game.exe ]] if this_os == "Windows" then @@ -158,7 +152,7 @@ else end repl_file = [[ -aio http://www.hgamer3d.org/component/Run-0.7 aio http://www.hgamer3d.org/component/Stack ghci +aio http://www.hgamer3d.org/component/Run-1 aio http://www.hgamer3d.org/component/Stack ghci ]] if this_os == "Windows" then diff --git a/examples/Billion.hs b/examples/Billion.hs index 28c8125..ab855f5 100755 --- a/examples/Billion.hs +++ b/examples/Billion.hs @@ -23,22 +23,19 @@ import Control.Monad import Data.List -startWorld = do - eG3D <- configureHG3D - return eG3D -- CH3-2e -- CH3-3s -- small tool, to create entities -creator l = newE l +creator w l = newE w l -- entity creation tools -camera pos = creator [ +camera w pos = creator w [ ctCamera #: FullViewCamera, ctPosition #: pos ] -item pos shape mat = creator [ +item w pos shape mat = creator w [ ctMaterial #: mat, ctGeometry #: ShapeGeometry shape, ctPosition #: pos, @@ -46,18 +43,18 @@ item pos shape mat = creator [ ctOrientation #: unitU ] -light pos = creator [ +light w pos = creator w [ ctLight #: Light PointLight 1.0 1000.0 1.0, ctPosition #: pos, ctColour #: white ] -textOne = creator [ +textOne w = creator w [ ctText #: "Billion\n" , ctScreenRect #: Rectangle 10 10 120 25 ] -textTwo = creator [ +textTwo w = creator w [ ctText #: "" , ctScreenRect #: Rectangle 10 50 200 500 ] @@ -66,12 +63,12 @@ showText e t = setC e ctText t type Cube = [[[Entity]]] -itemCube shape offset mat = do +itemCube w shape offset mat = do let r = [2.5, 5.0 .. 25.0] cubes <- mapM (\z -> mapM (\y -> - mapM (\x -> item ((Vec3 x y z) &+ offset) shape mat) r + mapM (\x -> item w ((Vec3 x y z) &+ offset) shape mat) r ) r ) r return cubes @@ -113,7 +110,7 @@ fUX = Vec3 0.05 0.0 0.0 fUY = Vec3 0.0 0.05 0.0 fUZ = Vec3 0.0 0.0 0.05 -commandInterpreter cam t2 refCubes refSel cmd = do +commandInterpreter w cam t2 refCubes refSel cmd = do case cmd of MoveCamera listOfMoves deltaTime -> do let oneMove (s, d) = do @@ -146,7 +143,7 @@ commandInterpreter cam t2 refCubes refSel cmd = do Cubes shape off mat -> do cubes <- readVar refCubes - newCube <- itemCube shape off mat + newCube <- itemCube w shape off mat writeVar refCubes (cubes ++ [newCube]) writeVar refSel newCube return () @@ -219,16 +216,16 @@ installText w ieh t2 = do _ -> return () registerCallback w ieh ctKeyEvent (\key -> handleKeys key) -main = do - w <- startWorld - c <- camera (Vec3 0.0 0.0 0.0) +gameLogic w = do + + c <- camera w (Vec3 0.0 0.0 0.0) - cubes <- itemCube Pyramid zeroVec3 matBlue + cubes <- itemCube w Pyramid zeroVec3 matBlue - l <- light (Vec3 10.0 10.0 0.0) - ieh <- creator [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] - t1 <- textOne - t2 <- textTwo + l <- light w (Vec3 10.0 10.0 0.0) + ieh <- creator w [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] + t1 <- textOne w + t2 <- textTwo w refK <- makeVar [] installKeyPressed w ieh refK @@ -238,8 +235,8 @@ main = do refCubes <- makeVar [cubes] refSel <- makeVar cubes - forkIO $ loopHG3D w (msecT 30) (return True) - mapM (\cmd -> commandInterpreter c t2 refCubes refSel cmd) ( + + mapM (\cmd -> commandInterpreter w c t2 refCubes refSel cmd) ( [ -- Intro @@ -293,20 +290,19 @@ main = do [ - SetText ("imagine each cube is one year\nthere are 1000 green pyramids, 1000 years ...\n\nlet's add 4000 years"), - Cubes Pyramid (Vec3 (-30) 0.0 0.0) matAqua, - Cubes Pyramid (Vec3 (-60) 0.0 0.0) matTeal, - Cubes Pyramid (Vec3 (-90) 0.0 0.0) matBlue, - Cubes Pyramid (Vec3 (-120) 0.0 0.0) matNavy, - - MoveCamera [(Fast, NegZ), (Fast, NegX)] (secT 60) + SetText ("to be continued ..."), + Wait (secT 30) ] -- ) + exitHG3D w return () -- CH3-4e +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/Cuboid2.hs b/examples/Cuboid2.hs index 9507a6c..836348a 100644 --- a/examples/Cuboid2.hs +++ b/examples/Cuboid2.hs @@ -75,44 +75,42 @@ steps start move level = ------------------------------------ -- setup basic 3D world -setupWorld = do - -- initialize - hg3d <- configureHG3D +setupWorld hg3d = do -- camera and light - cam <- newE [ctCamera #: FullViewCamera, ctPosition #: Vec3 0 0 0, ctOrientation #: unitU] + cam <- newE hg3d [ctCamera #: FullViewCamera, ctPosition #: Vec3 0 0 0, ctOrientation #: unitU] -- CH3-8s - light1 <- newE [ctLight #: Light (SpotLight (Deg 50) 1.0) 1.0 100.0 1.0, ctPosition #: Vec3 (10) (-10) (-10.0)] - light2 <- newE [ctLight #: Light PointLight 0.5 1000.0 0.8, ctPosition #: Vec3 0 0 (-50)] - light3 <- newE [ctLight #: Light DirectionalLight 1.0 1000.0 1.0, ctOrientation #: (rotU vec3Y 45 .*. rotU vec3X 45)] + light1 <- newE hg3d [ctLight #: Light (SpotLight (Deg 50) 1.0) 1.0 100.0 1.0, ctPosition #: Vec3 (10) (-10) (-10.0)] + light2 <- newE hg3d [ctLight #: Light PointLight 0.5 1000.0 0.8, ctPosition #: Vec3 0 0 (-50)] + light3 <- newE hg3d [ctLight #: Light DirectionalLight 1.0 1000.0 1.0, ctOrientation #: (rotU vec3Y 45 .*. rotU vec3X 45)] -- CH3-8e + -- HGamer3D website, entities and events, event listener for keys -- key input - -- CH5-2s - ieh <- newE [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] - -- CH5-2e - return (hg3d, cam, ieh) + ieh <- newE hg3d [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] + -- end of website text + return (cam, ieh) -- quat from 2 vectors, normalized input ufrom2v u v = let (Vec3 x y z) = u &^ v in mkU (Vec4 (1.0 + (u &. v)) x y z ) -- create a line -line :: Material -> Vec3 -> Vec3 -> Float -> IO Entity -line m p1 p2 t = do +line :: HG3D -> Material -> Vec3 -> Vec3 -> Float -> IO Entity +line hg3d m p1 p2 t = do let d = p2 &- p1 let l = len d let u = ufrom2v (normalize (Vec3 0 l 0)) (normalize d) - l <- newE [ctMaterial #: m, ctGeometry #: ShapeGeometry Cube, + l <- newE hg3d [ctMaterial #: m, ctGeometry #: ShapeGeometry Cube, ctPosition #: (p1 &+ (d &* 0.5)) , ctScale #: (Vec3 t l t), ctOrientation #: u] return l -- create a sphere -sphere m p s = do - s' <- newE [ctMaterial #: m, ctGeometry #: ShapeGeometry Sphere, +sphere hg3d m p s = do + s' <- newE hg3d [ctMaterial #: m, ctGeometry #: ShapeGeometry Sphere, ctPosition #: p, ctScale #: s, ctOrientation #: unitU] return s' -- create a cube -cube m p s = do - s' <- newE [ctMaterial #: m, ctGeometry #: ShapeGeometry Cube, +cube hg3d m p s = do + s' <- newE hg3d [ctMaterial #: m, ctGeometry #: ShapeGeometry Cube, ctPosition #: p, ctScale #: s, ctOrientation #: unitU] return s' @@ -142,17 +140,17 @@ f2pos pos@(x, y, z) = let in oC &+ (sC *& vs') -- draw the static frame around the cubes -drawCubeFrame = do +drawCubeFrame hg3d = do let (corners, edges) = cubeOutline oC (unitVec3 &* (sC * 1.05)) - mapM (\(a, b) -> line matMetal a b (0.05 * sC) ) edges - mapM (\v -> sphere matMetal v (unitVec3 &* (sC * 0.12))) corners + mapM (\(a, b) -> line hg3d matMetal a b (0.05 * sC) ) edges + mapM (\v -> sphere hg3d matMetal v (unitVec3 &* (sC * 0.12))) corners -- create all used sphere -createSpheresAndCubes = do +createSpheresAndCubes hg3d = do let sphereSize = unitVec3 &* (2.0 * sC / (fromIntegral maxDim)) - cubes <- mapM (\_ -> cube matBlue (f2pos spC) (sphereSize &* 0.9)) [0.. (maxDim * maxDim) -1] - startSphere <- sphere matLime (f2pos spC) sphereSize - endSphere <- sphere matRed (f2pos spC) sphereSize + cubes <- mapM (\_ -> cube hg3d matBlue (f2pos spC) (sphereSize &* 0.9)) [0.. (maxDim * maxDim) -1] + startSphere <- sphere hg3d matLime (f2pos spC) sphereSize + endSphere <- sphere hg3d matRed (f2pos spC) sphereSize return (startSphere, endSphere, cubes) setPos er fp = setC er ctPosition (f2pos fp) @@ -160,8 +158,8 @@ setPos er fp = setC er ctPosition (f2pos fp) -- Low Level Event Routines --------------------------- +-- HGamer3D website, entities and events, WASD logic -- install key handler, moves each key up and currently pressed keys in variable --- CH5-3s installKeyHandler :: HG3D -> Var [T.Text] -> Var [T.Text] -> Entity -> IO () installKeyHandler hg3d varKeysUp varKeysPressed ieh = do let handleKeys ke = do @@ -175,7 +173,6 @@ installKeyHandler hg3d varKeysUp varKeysPressed ieh = do _ -> return () registerCallback hg3d ieh ctKeyEvent (\k -> handleKeys k) return () --- CH5-3e -- camera movement installMoveCamera cam varKeysPressed = do @@ -190,20 +187,19 @@ installMoveCamera cam varKeysPressed = do return () forkIO $ forever $ move >> sleepFor (msecT 50) return() - +-- end of website text -- Game Preparation Work ------------------------ -startWorld = do - (hg3d, cam, inputHandler) <- setupWorld - forkIO $ loopHG3D hg3d (msecT 30) (return True) -- allow exit, per windows close +startWorld hg3d = do + (cam, inputHandler) <- setupWorld hg3d varKeysUp <- makeVar [] varKeysPressed <- makeVar [] installKeyHandler hg3d varKeysUp varKeysPressed inputHandler installMoveCamera cam varKeysPressed - drawCubeFrame - (startSphere, endSphere, cubes) <- createSpheresAndCubes + drawCubeFrame hg3d + (startSphere, endSphere, cubes) <- createSpheresAndCubes hg3d return (varKeysUp, (startSphere, endSphere, cubes)) @@ -282,11 +278,15 @@ runLevel varKeysUp allS@(sS, eS, ss) level = do loopKey (lStart level) -- CH3-11e -main = do - (varKeysUp, allS) <- startWorld +gameLogic hg3d = do + (varKeysUp, allS) <- startWorld hg3d mapM (\l -> runLevel varKeysUp allS l) gameData return () +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () + {- :s OverloadedStrings diff --git a/examples/Gui1.hs b/examples/Gui1.hs index a11dfe7..3c65738 100644 --- a/examples/Gui1.hs +++ b/examples/Gui1.hs @@ -8,9 +8,8 @@ import qualified Data.Text as T import Control.Concurrent import Control.Monad -createAll = do - hg3d <- configureHG3D - res <- mapM newE [ +createEntities hg3d = do + res <- mapM (newE hg3d) [ [ -- camera ctCamera #: FullViewCamera, ctPosition #: Vec3 1 1 (-30.0), @@ -28,13 +27,9 @@ createAll = do , ctScreenRect #: Rectangle 10 10 120 25 ] ,[ -- button - ctButton #: False + ctButton #: Button False "Press Me" , ctScreenRect #: Rectangle 130 10 100 25 ] - ,[ -- button text - ctText #: "Press Me" - , ctScreenRect #: Rectangle 140 12 100 25 - ] ,[ -- descriptive text ctText #: "A Checkbox: \n" , ctScreenRect #: Rectangle 10 40 120 25 @@ -75,36 +70,40 @@ createAll = do ] ] - return (res, hg3d) + let [camera, cube, _, button, _, checkbox, _, edittext, _, slider, _, dropdownlist, output] = res + return (camera, cube, button, checkbox, edittext, slider, dropdownlist, output) + + +startRotation cube = do + let rotate = do + updateC cube ctOrientation (\u -> (rotU vec3Y 0.02) .*. (rotU vec3X 0.005) .*. u) + sleepFor (msecT 20) + rotate + forkIO $ rotate -rotate eGeo hg3d = do - updateC eGeo ctOrientation (\u -> (rotU vec3Y 0.02) .*. (rotU vec3X 0.005) .*. u) - stepHG3D hg3d - ex <- isExitHG3D hg3d - if not ex then - do - sleepFor (msecT 20) - rotate eGeo hg3d - else + +startPrintEvents button checkbox edittext slider dropdownlist output = do + let printEvents = do + forever $ do + textOut <- do + t1 <- readC button ctButton + t2 <- readC checkbox ctCheckBox + t3 <- readC edittext ctEditText + t4 <- readC slider ctSlider + t5 <- readC dropdownlist ctDropDownList + return (T.pack ("button: " ++ (show t1) ++ "\ncheckbox: " ++ (show t2) ++ "\nedittext: " ++ (show t3) ++ "\nslider: " ++ (show t4) ++ "\ndropdownlist: " ++ (show t5) ++ "\n\n")) + setC output ctText textOut + sleepFor (msecT 200) return () + forkIO $ printEvents + --- CH6-2s -printEvents button checkbox edittext slider dropdownlist output = do - forever $ do - textOut <- do - t1 <- readC button ctButton - t2 <- readC checkbox ctCheckBox - t3 <- readC edittext ctEditText - t4 <- readC slider ctSlider - t5 <- readC dropdownlist ctDropDownList - return (T.pack ("button: " ++ (show t1) ++ "\ncheckbox: " ++ (show t2) ++ "\nedittext: " ++ (show t3) ++ "\nslider: " ++ (show t4) ++ "\ndropdownlist: " ++ (show t5) ++ "\n\n")) - setC output ctText textOut - sleepFor (msecT 200) - return () --- CH6-2e +gameLogic hg3d = do + (camera, cube, button, checkbox, edittext, slider, dropdownlist, output) <- createEntities hg3d + startRotation cube + startPrintEvents button checkbox edittext slider dropdownlist output + return () main = do - ([camera, cube, _, button, _, _, checkbox, _, edittext, _, slider, _, dropdownlist, output], hg3d) <- createAll - forkIO $ printEvents button checkbox edittext slider dropdownlist output - rotate cube hg3d + runGame standardGraphics3DConfig gameLogic (msecT 20) return () diff --git a/examples/Materials.hs b/examples/Materials.hs index 32dd5eb..2333674 100644 --- a/examples/Materials.hs +++ b/examples/Materials.hs @@ -42,28 +42,26 @@ mats = [ -- START SYSTEM --------------- -go = do +go hg3d = do - hg3d <- configureHG3D - - cam <- newE [ + cam <- newE hg3d [ ctCamera #: FullViewCamera, ctPosition #: Vec3 1.0 1.0 (-30.0), ctOrientation #: unitU ] - li <- newE [ + li <- newE hg3d [ ctLight #: Light PointLight 1.0 1000.0 1.0, ctPosition #: Vec3 1.0 1.0 (-30.0) ] - return (hg3d, li, cam) + return (li, cam) -- CONTENT CREATION -- create cube with material, position at n of m -makeCube mat n m = do - eCube <- newE [ +makeCube hg3d mat n m = do + eCube <- newE hg3d [ ctGeometry #: ShapeGeometry Cube, ctMaterial #: mat, ctScale #: Vec3 10.0 10.0 10.0, @@ -73,13 +71,13 @@ makeCube mat n m = do ] return eCube -allCubes mats = do +allCubes hg3d mats = do let m = length mats - cubes <- mapM (\(mat, n) -> makeCube mat n m) (zip mats [1..m]) + cubes <- mapM (\(mat, n) -> makeCube hg3d mat n m) (zip mats [1..m]) return cubes camy c d = do - updateC c ctOrientation (\u -> (rotU vec3Y d) .*. u) + updateC c ctOrientation (\u -> (rotU vec3Y d) .*. u) updateC c ctPosition (\p -> rotate3 d vec3Y p) rotateWorld c cs d = forever $ do @@ -88,14 +86,13 @@ rotateWorld c cs d = forever $ do sleepFor (msecT 20) -demo = do - (hg3d, l1, c) <- go - cubes <- allCubes mats - forkIO $ loopHG3D hg3d (msecT 20) (return True) -- allow close on windows click +gameLogic hg3d = do + (l1, c) <- go hg3d + cubes <- allCubes hg3d mats rotateWorld c cubes (-0.05) return () main = do - demo - return () + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/Mouse.hs b/examples/Mouse.hs new file mode 100644 index 0000000..9ab0c9f --- /dev/null +++ b/examples/Mouse.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import HGamer3D + +import qualified Data.Text as T +import Control.Concurrent +import Control.Monad + +createAll hg3d = do + + -- create all elements + res <- mapM (newE hg3d) [ + + [ -- camera + ctCamera #: FullViewCamera, + ctPosition #: Vec3 1 1 (-30.0), + ctLight #: Light PointLight 1.0 1000.0 1.0 + ] + ,[ -- blue cube + ctGeometry #: ShapeGeometry Cube, + ctMaterial #: matBlue, + ctScale #: Vec3 5.0 5.0 5.0, + ctPosition #: Vec3 0.0 0.0 0.0, + ctOrientation #: unitU + ] + + ,[ + ctMouse #: Mouse MMAbsolute + ] + + ,[ + ctInputEventHandler #: DefaultEventHandler, + ctKeyEvent #: NoKeyEvent, + ctMouseEvent #: NoMouseEvent + ] + + ,[ + ctText #: "Keys: A - Absolute Mouse Mode, R - Relative Mouse Mode, W - Wrap Mouse Mode", + ctScreenRect #: Rectangle 10 10 200 10 + ] + + ,[ + ctText #: "Mouse Mode Set To ...", + ctScreenRect #: Rectangle 10 25 200 10 + ] + + ,[ + ctText #: "Mouse Event", + ctScreenRect #: Rectangle 10 40 200 10 + ] + + ] + let [cam, geo, mode, event, _, txtMode, txtEvent] = res + return (geo, mode, event, txtMode, txtEvent) + + +showMode mode txtMode = do + forever $ do + m <- readC mode ctMouse + setC txtMode ctText (T.pack (show m)) + sleepFor (msecT 20) + return () + +addMouseEventCallback hg3d event txtEvent = registerCallback hg3d event ctMouseEvent (\evt -> setC txtEvent ctText (T.pack (show evt))) +addKeyEventCallback hg3d event mode = registerCallback hg3d event ctKeyEvent (\evt -> case evt of + KeyUp _ _ "A" -> setC mode ctMouse (Mouse MMAbsolute) + KeyUp _ _ "R" -> setC mode ctMouse (Mouse MMRelative) + KeyUp _ _ "W" -> setC mode ctMouse (Mouse MMWrap) + _ -> return ()) + +rotateCube cube = do + forever $ do + updateC cube ctOrientation (\u -> (rotU vec3Z 0.021) .*. u) + updateC cube ctOrientation (\u -> (rotU vec3X 0.012) .*. u) + sleepFor (msecT 30) + return () + + +gameLogic hg3d = do + (cube, mode, event, txtMode, txtEvent) <- createAll hg3d + forkIO $ showMode mode txtMode + forkIO $ rotateCube cube + addMouseEventCallback hg3d event txtEvent + addKeyEventCallback hg3d event mode + return () + +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () + + diff --git a/examples/RotatingCube.hs b/examples/RotatingCube.hs index 8c81b7c..ffa7e25 100644 --- a/examples/RotatingCube.hs +++ b/examples/RotatingCube.hs @@ -1,9 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{- -:l RotatingCube -main --} - module Main where import HGamer3D @@ -13,63 +8,45 @@ import Control.Concurrent import Control.Monad import System.Exit -start = do - - hg3d <- configureHG3D -- initialize - - -- create camera - eCam <- newE [ - ctCamera #: FullViewCamera, - ctPosition #: Vec3 1 1 (-30.0), - ctLight #: Light PointLight 1.0 1000.0 1.0 - ] - - eText <- newE [ - ctText #: "Rotating Cube Example", - ctScreenRect #: Rectangle 10 10 100 25 - ] - - -- CH5-1s - eButton <- newE [ - ctButton #: False, - ctText #: " Exit", - ctScreenRect #: Rectangle 200 10 50 25 - ] - - registerCallback hg3d eButton ctButton (\flag -> if not flag then exitHG3D hg3d else return ()) - -- CH5-1e - - -- create cube - -- CH4-1s - eGeo <- newE [ - ctGeometry #: ShapeGeometry Cube, - ctMaterial #: matBlue, - ctScale #: Vec3 10.0 10.0 10.0, - ctPosition #: Vec3 0.0 0.0 0.0, - ctOrientation #: unitU - ] - -- CH4-1e - - return (eGeo, eCam, hg3d) - --- rotate the cube -rotateZ eGeo = do - forever $ do - updateC eGeo ctOrientation (\u -> (rotU vec3Z 0.021) .*. u) - sleepFor (msecT 12) - return () - --- CH4-2s -rotateX eGeo = do - forever $ do - updateC eGeo ctOrientation (\u -> (rotU vec3X 0.012) .*. u) - sleepFor (msecT 16) - return () --- CH4-2e +gameLogic hg3d = do + + -- create minimum elements, like a camera + eCam <- newE hg3d [ + ctCamera #: FullViewCamera, + ctPosition #: Vec3 1 1 (-30.0), + ctLight #: Light PointLight 1.0 1000.0 1.0 + ] + + -- create a text + eText <- newE hg3d [ + ctText #: "Rotating Cube Example", + ctScreenRect #: Rectangle 10 10 100 25 + ] + +-- HGamer3D website, entities and events, example entity + -- create the cube geometry entity + eGeo <- newE hg3d [ + ctGeometry #: ShapeGeometry Cube, + ctMaterial #: matBlue, + ctScale #: Vec3 10.0 10.0 10.0, + ctPosition #: Vec3 0.0 0.0 0.0, + ctOrientation #: unitU + ] +-- end of website text + +-- HGamer3D website, entities and events, rotation explanation + -- rotate the cube around 2 axes + let rotateCube = do + forever $ do + updateC eGeo ctOrientation (\u -> (rotU vec3Z 0.02) .*. u) + updateC eGeo ctOrientation (\u -> (rotU vec3X 0.015) .*. u) + sleepFor (msecT 12) + + forkIO rotateCube +-- end of website text + + return () main = do - (eGeo, eCam, hg3d) <- start - forkIO $ rotateZ eGeo - forkIO $ rotateX eGeo - loopHG3D hg3d (msecT 20) (return True) -- allow close on windows click - return () + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/RotatingCube2.hs b/examples/RotatingCube2.hs new file mode 100644 index 0000000..9c66aa7 --- /dev/null +++ b/examples/RotatingCube2.hs @@ -0,0 +1,76 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import HGamer3D +import Control.Concurrent +import Control.Monad + +gameLogic hg3d = do + + es <- newET hg3d [ + -- create camera + () -: [ + ctCamera #: FullViewCamera, + ctPosition #: Vec3 1 1 (-30.0), + ctLight #: Light PointLight 1.0 1000.0 1.0 + ], + -- create text + () -: [ + ctText #: "Rotating Cube Example", + ctScreenRect #: Rectangle 10 10 100 25 + ], + -- create geometry, with child geometry items + "eGeo" <| ([ + ctGeometry #: ShapeGeometry Cube, + ctMaterial #: matBlue, + ctScale #: Vec3 5.0 5.0 5.0, + ctPosition #: Vec3 0.0 0.0 0.0, + ctOrientation #: unitU + ], [ + "eSmall" <| ([ + ctGeometry #: ShapeGeometry Sphere, + ctMaterial #: matGreen, + ctPosition #: Vec3 (-0.5) 0.5 (-0.5), + ctScale #: Vec3 0.8 0.8 0.8, + ctOrientation #: unitU + ], + [ + () -: [ + ctGeometry #: ShapeGeometry Sphere, + ctMaterial #: matRed, + ctScale #: Vec3 0.5 0.5 0.5, + ctPosition #: Vec3 (0.0) (-0.5) (-0.5), + ctOrientation #: unitU + ] + ]) + ]), + +-- HGamer3D website, entities and events, example exit button with callback + -- create button + "eButton" <: [ + ctButton #: Button False "Exit", + ctScreenRect #: Rectangle 200 10 50 25 + ] + + ] + + registerCallback hg3d (es # "eButton") ctButton (\(Button flag _) -> if not flag then exitHG3D hg3d else return ()) +-- end of website text + + -- rotate the cube + let rotate = do + forever $ do + updateC (es # "eGeo") ctOrientation (\u -> (rotU vec3X 0.0013) .*. u) + updateC (es # "eGeo") ctOrientation (\u -> (rotU vec3Y 0.005) .*. u) + updateC (es # "eSmall") ctOrientation (\u -> (rotU (Vec3 (-1.0) 1.0 (-1.0)) 0.05) .*. u) + sleepFor (msecT 20) + return () + + forkIO $ rotate + + return () + +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/SoundEffects.hs b/examples/SoundEffects.hs index a243932..e03d4aa 100644 --- a/examples/SoundEffects.hs +++ b/examples/SoundEffects.hs @@ -8,12 +8,10 @@ import qualified Data.Text as T import Control.Concurrent import Control.Monad -createAll = do - - hg3d <- configureHG3D -- initialize +createAll hg3d = do -- create all elements - res <- mapM newE [ + res <- mapM (newE hg3d) [ [ -- camera ctCamera #: FullViewCamera, @@ -31,24 +29,21 @@ createAll = do -- SOUND BUTTONS AND SOUNDSOURCE ,[ -- metal-clash button and sound - ctText #: "metal clash" - , ctButton #: False + ctButton #: Button False "metal clash" , ctScreenRect #: Rectangle 10 10 150 50 , ctSoundSource #: Sound "Sounds/inventory_sound_effects/metal-clash.wav" 1.0 False "Sounds" , ctPlayCmd #: Stop ] -- CH7-1s ,[ -- ring-inventory button and sound - ctText #: "ring inventory" - , ctButton #: False + ctButton #: Button False "ring inventory" , ctScreenRect #: Rectangle 180 10 150 50 , ctSoundSource #: Sound "Sounds/inventory_sound_effects/ring_inventory.wav" 1.0 False "Sounds" , ctPlayCmd #: Stop ] -- CH7-1e ,[ -- sell_buy_item button and sound - ctText #: "sell buy item" - , ctButton #: False + ctButton #: Button False "sell buy item" , ctScreenRect #: Rectangle 350 10 150 50 , ctSoundSource #: Sound "Sounds/inventory_sound_effects/sell_buy_item.wav" 1.0 False "Sounds" , ctPlayCmd #: Stop @@ -57,13 +52,11 @@ createAll = do -- MUSIC BUTTONS AND SLIDERS ,[ -- Music Start - ctText #: "Start Music" - , ctButton #: False + ctButton #: Button False "Start Music" , ctScreenRect #: Rectangle 10 80 150 50 ] ,[ -- Music Start - ctText #: "Stop Music" - , ctButton #: False + ctButton #: Button False "Stop Music" , ctScreenRect #: Rectangle 180 80 150 50 ] ,[ -- Music item @@ -100,7 +93,7 @@ createAll = do ] - return (res, hg3d) + return res rotate eGeo = do forever $ do @@ -108,7 +101,7 @@ rotate eGeo = do sleepFor (msecT 20) return () -addActionButton hg3d button action = registerCallback hg3d button ctButton (\flag -> if flag then action else return ()) +addActionButton hg3d button action = registerCallback hg3d button ctButton (\(Button flag _) -> if flag then action else return ()) registerSoundButtons hg3d sound1 sound2 sound3 = do mapM (\sound -> addActionButton hg3d sound (setC sound ctPlayCmd Play)) [sound1, sound2, sound3] @@ -124,15 +117,19 @@ registerVolumeSliders hg3d sliderSound sliderMusic volume = do registerCallback hg3d sliderMusic ctSlider (\val -> setC volume ctVolume (Volume "Music" (sliderVal val))) -- CH7-3e -main = do - ([camera, cube, +gameLogic hg3d = do + [camera, cube, sound1, sound2, sound3, musicStart, musicStop, music, _, - sliderSound, sliderMusic, volume, _, _], hg3d) <- createAll + sliderSound, sliderMusic, volume, _, _] <- createAll hg3d registerSoundButtons hg3d sound1 sound2 sound3 registerMusicButtons hg3d musicStart musicStop music registerVolumeSliders hg3d sliderSound sliderMusic volume forkIO $ rotate cube - loopHG3D hg3d (msecT 20) (return True) -- allow close return () +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () + + diff --git a/examples/SpaceInvaders.hs b/examples/SpaceInvaders.hs index 9f465e7..333fdc5 100644 --- a/examples/SpaceInvaders.hs +++ b/examples/SpaceInvaders.hs @@ -13,6 +13,7 @@ import Data.Maybe data ActorType = Canon | Boulder | Invader Int | Shot deriving (Eq, Show, Ord) +-- HGamer3D website, code space invaders 2d, artwork arts :: M.Map ActorType (T.Text, T.Text, Int, Int) arts = M.fromList [ (Canon, ("___/=\\___\n### ###", "", 76, 30)), @@ -22,6 +23,7 @@ arts = M.fromList [ (Invader 3, (" #+++#\n# . . #\nx- x-", " #+++#\n# . . #\n-x -x", 54, 45)), (Shot, ("\"\"", "", 14, 4)) ] +-- end of website text instance Show Entity where show e = "Entity: " @@ -82,22 +84,26 @@ invaderData = [ -- actors and collisions ------------------------ -createActor :: ActorType -> Int -> Int -> IO Actor -createActor atype x y = do +-- HGamer3D website, code space invaders 2d, create actors +createActor :: HG3D -> ActorType -> Int -> Int -> IO Actor +createActor hg3d atype x y = do let (t, _, w, h) = fromJust (M.lookup atype arts) - e <- newE [ ctText #: t, ctScreenRect #: Rectangle x y w h] + e <- newE hg3d [ ctText #: t, ctScreenRect #: Rectangle x y w h] return $ Actor atype e -createActors actorData = mapM (\(a, x, y) -> createActor a x y) actorData +createActors hg3d actorData = mapM (\(a, x, y) -> createActor hg3d a x y) actorData +-- end of website text posActor (Actor _ e) = readC e ctScreenRect >>= \(Rectangle x y _ _) -> return (x, y) moveActor (Actor _ e) (x, y) = updateC e ctScreenRect (\(Rectangle a b c d) -> (Rectangle (a+x) (b+y) c d)) +-- HGamer3D website, actions and do notation, first example swapPic (Actor atype e) = do let (t1, t2, w, h) = fromJust (M.lookup atype arts) oldt <- readC e ctText if oldt == t1 then setC e ctText t2 >> return () else setC e ctText t1 >> return () +-- end of website text hit (Rectangle x y w h) (Rectangle x' y' w' h') = (not (x > x' + w' || x' > x + w)) && (not (y > y' + h' || y' > y + h)) @@ -116,22 +122,23 @@ getCollisions (Actor a e) actors = -- music and sound ------------------ -music = newE [ +music hg3d = newE hg3d [ ctSoundSource #: Music "Sounds/RMN-Music-Pack/OGG/CD 3 - Clash of Wills/3-04 Joyful Ocean.ogg" 1.0 True "Music", ctPlayCmd #: Stop ] >>= \m -> setC m ctPlayCmd Play -sounds = do - ping <- newE [ ctSoundSource #: Sound "Sounds/inventory_sound_effects/ring_inventory.wav" 1.0 False "Sounds" +sounds hg3d = do + ping <- newE hg3d [ ctSoundSource #: Sound "Sounds/inventory_sound_effects/ring_inventory.wav" 1.0 False "Sounds" , ctPlayCmd #: Stop ] -- creates a sound - clash <- newE [ ctSoundSource #: Sound "Sounds/inventory_sound_effects/metal-clash.wav" 1.0 False "Sounds" + clash <- newE hg3d [ ctSoundSource #: Sound "Sounds/inventory_sound_effects/metal-clash.wav" 1.0 False "Sounds" , ctPlayCmd #: Stop ] -- creates another sound return (ping, clash) -- key handling --------------- - + +-- HGamer3D website, code space invaders 2d, move canon data CanonMove = NotMoving | MovingRight | MovingLeft deriving (Show) @@ -145,14 +152,16 @@ handleKey k (varMoveState, varNumShots) = _ -> return () installKeyHandler hg3d varMoveState varNumShots = do - ieh <- newE [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] + ieh <- newE hg3d [ctInputEventHandler #: DefaultEventHandler, ctKeyEvent #: NoKeyEvent] registerCallback hg3d ieh ctKeyEvent (\k -> handleKey k (varMoveState, varNumShots)) +-- end of website text + -- canon movements, shooting ---------------------------- -canonLoop canon varShots varMoveState varNumShots = do +canonLoop hg3d canon varShots varMoveState varNumShots = do (x, y) <- posActor canon moving <- readVar varMoveState isShot <- updateVar varNumShots (\n -> if n > 0 then (n-1, True) else (0, False)) @@ -161,10 +170,10 @@ canonLoop canon varShots varMoveState varNumShots = do MovingRight -> if x < 720 then moveActor canon (5, 0) else return () _ -> return () if isShot - then createActor Shot (x + 28) (y - 6) >>= \s -> updateVar varShots (\l -> (s:l, ())) + then createActor hg3d Shot (x + 28) (y - 6) >>= \s -> updateVar varShots (\l -> (s:l, ())) else return () sleepFor (msecT 20) - canonLoop canon varShots varMoveState varNumShots + canonLoop hg3d canon varShots varMoveState varNumShots -- bullets flying @@ -246,23 +255,22 @@ collisionLoop varInvaders varShots varEnd boulders ping clash = do handleEnd hg3d varEnd = do end <- readVar varEnd if end > 0 - then newE [ ctText #: "Congratulations, you won!", + then newE hg3d [ ctText #: "Congratulations, you won!", ctScreenRect #: Rectangle 300 180 100 30] >> sleepFor (secT 10) >> exitHG3D hg3d else if end < 0 - then newE [ ctText #: "The invaders got you! Try again!", + then newE hg3d [ ctText #: "The invaders got you! Try again!", ctScreenRect #: Rectangle 300 180 100 30] >> sleepFor (secT 10) >> exitHG3D hg3d else return () sleepFor (secT 1) handleEnd hg3d varEnd - -main = do - hg3d <- configureHG3D - music - (ping, clash) <- sounds +-- HGamer3D website, code space invaders 2d, game logic +gameLogic hg3d = do + music hg3d + (ping, clash) <- sounds hg3d - (canon : boulders) <- createActors canonBouldersData - invaders <- createActors invaderData + (canon : boulders) <- createActors hg3d canonBouldersData + invaders <- createActors hg3d invaderData varInvaders <- makeVar invaders varMoveState <- makeVar NotMoving @@ -272,11 +280,15 @@ main = do installKeyHandler hg3d varMoveState varNumShots - forkIO (canonLoop canon varShots varMoveState varNumShots) + forkIO (canonLoop hg3d canon varShots varMoveState varNumShots) forkIO (shotsLoop varShots) forkIO (invadersLoop varInvaders True 0 varEnd) forkIO (collisionLoop varInvaders varShots varEnd boulders ping clash) forkIO (handleEnd hg3d varEnd) + + return () +-- end of website text - loopHG3D hg3d (msecT 30) (return True) - +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/TestDel.hs b/examples/TestDel.hs new file mode 100644 index 0000000..4c0c5bf --- /dev/null +++ b/examples/TestDel.hs @@ -0,0 +1,112 @@ +{-# LANGUAGE OverloadedStrings #-} +{- +:l RotatingCube +main +-} + +module Main where + +import HGamer3D + +import qualified Data.Text as T +import Control.Concurrent +import Control.Monad +import System.Exit + +gameLogic hg3d = do + + -- create camera + eCam <- newE hg3d [ + ctCamera #: FullViewCamera, + ctPosition #: Vec3 1 1 (-30.0), + ctLight #: Light PointLight 1.0 1000.0 1.0 + ] + + eText <- newE hg3d [ + ctText #: "Rotating Cube Example", + ctScreenRect #: Rectangle 10 10 100 25 + ] + + -- CH5-1s + eButton <- newE hg3d [ + ctButton #: Button False "Exit", + ctScreenRect #: Rectangle 200 10 50 25 + ] + + eButtonNew <- newE hg3d [ + ctButton #: Button False "New", + ctScreenRect #: Rectangle 200 70 50 25 + ] + + eButtonDel <- newE hg3d [ + ctButton #: Button False "Del", + ctScreenRect #: Rectangle 200 130 50 25 + ] + + eGeo <- newE hg3d [ + ctGeometry #: ShapeGeometry Cube, + ctMaterial #: matBlue, + ctScale #: Vec3 10.0 10.0 10.0, + ctPosition #: Vec3 0.0 0.0 0.0, + ctOrientation #: unitU + ] + + varGeo <- makeVar (Just eGeo) + + let createCube = do + + eGeo' <- newE hg3d [ + ctGeometry #: ShapeGeometry Cube, + ctMaterial #: matBlue, + ctScale #: Vec3 10.0 10.0 10.0, + ctPosition #: Vec3 0.0 0.0 0.0, + ctOrientation #: unitU + ] + idE eGeo' >>= print + writeVar varGeo (Just eGeo') + return () + + let delCube = do + eGeo' <- writeVar varGeo Nothing + case eGeo' of + Just g -> delE g >> return () + Nothing -> return () + + registerCallback hg3d eButton ctButton (\(Button flag _) -> if not flag then exitHG3D hg3d else return ()) + registerCallback hg3d eButtonNew ctButton (\(Button flag _) -> if not flag then createCube else return ()) + registerCallback hg3d eButtonDel ctButton (\(Button flag _) -> if not flag then delCube else return ()) + -- CH5-1e + + -- rotate the cube + let rotateZ = do + forever $ do + eGeo' <- readVar varGeo + case eGeo' of + Just g -> updateC g ctOrientation (\u -> (rotU vec3Z 0.021) .*. u) + Nothing -> return () + sleepFor (msecT 12) + return () + + + -- CH4-2s + let rotateX = do + forever $ do + eGeo' <- readVar varGeo + case eGeo' of + Just g -> updateC g ctOrientation (\u -> (rotU vec3X 0.012) .*. u) + Nothing -> return () + sleepFor (msecT 16) + return () +-- CH4-2e + + + forkIO $ rotateZ + + forkIO $ rotateX + + return () + + +main = do + runGame standardGraphics3DConfig gameLogic (msecT 20) + return () diff --git a/examples/stack.yaml b/examples/stack.yaml index 78e166b..5c37373 100644 --- a/examples/stack.yaml +++ b/examples/stack.yaml @@ -1,4 +1,7 @@ -extra-deps: ["HGamer3D-0.7.1", "fresco-binding-0.1.1", "vect-0.4.7"] +extra-deps: ["fresco-binding-0.2.0", "vect-0.4.7"] resolver: lts-5.8 flags: {} -packages: [] +packages: +- '../src' +- '../../fresco-haskell' + diff --git a/src/CFunctions.chs b/src/CFunctions.chs deleted file mode 100644 index a08b117..0000000 --- a/src/CFunctions.chs +++ /dev/null @@ -1,74 +0,0 @@ --- 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/Binding/CFunctions.hs --- - -{-# LANGUAGE ForeignFunctionInterface #-} - -#include "interface.h" - --- | C-function interface towards the urho3d dll -module HGamer3D.Binding.CFunctions where - -import Foreign -import Foreign.C -import Data.Word -import Data.ByteString -import Data.ByteString.Unsafe - -type CStringCLen i = (CString, i) - -unsafeUseAsCStringLen' :: (Integral i) => ByteString -> (CStringCLen i -> IO a) -> IO a -unsafeUseAsCStringLen' str fn = - unsafeUseAsCStringLen str (\(ptr, len) -> fn (ptr, fromIntegral len)) - -{#fun entity_create as entityCreate - { - unsafeUseAsCStringLen'* `ByteString'& , - alloca- `Ptr ()' peek* - } -> `()' -#} - -{#fun entity_set as entitySet - { - unsafeUseAsCStringLen'* `ByteString'& , - `Ptr ()' - } -> `()' -#} - -{#fun callback_system_create as callbackSystemCreate - { - alloca- `Ptr ()' peek* - } -> `()' -#} - -{#fun callback_system_register_receiver as callbackSystemRegisterReceiver - { - id `Ptr ()', - id `Ptr ()', - `Word64', - id `FunPtr (Ptr () -> Ptr CChar -> CInt -> IO CInt)' - } -> `()' -#} - -{#fun callback_system_step as callbackSystemStep - { - id `Ptr ()' - } -> `()' -#} diff --git a/src/HGamer3D.cabal b/src/HGamer3D.cabal index 5f09617..543e1e4 100644 --- a/src/HGamer3D.cabal +++ b/src/HGamer3D.cabal @@ -1,5 +1,5 @@ Name: HGamer3D -Version: 0.7.1 +Version: 0.8.0 Synopsis: Toolset for the Haskell Game Programmer Description: HGamer3D is a toolset for developing 3D games in the programming @@ -16,9 +16,9 @@ Category: Game Engine 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.6 && <0.7, cereal >=0.5 && < 0.6, fresco-binding >= 0.1.0 && < 0.2.0 + Build-Depends: base >= 3 && < 5, containers, bytestring, text, filepath, directory, vect >=0.4 && <0.5, messagepack >=0.5 && <0.6, clock >=0.6 && <0.7, cereal >=0.5 && < 0.6, fresco-binding >= 0.2.0 && < 0.3.0 - Exposed-modules: 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.PlayCmd, HGamer3D.Data, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util.Variable, HGamer3D.Util, 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.InputEventHandler, HGamer3D.Input, HGamer3D.Graphics3D, HGamer3D.GUI.Button, HGamer3D.GUI.EditText, HGamer3D.GUI.DropDownList, HGamer3D.GUI.Slider, HGamer3D.GUI.Text, HGamer3D.GUI.CheckBox, HGamer3D.GUI, HGamer3D.Audio.SoundSource, HGamer3D.Audio.SoundListener, HGamer3D.Audio.Volume, HGamer3D.Audio, HGamer3D + Exposed-modules: 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.PlayCmd, HGamer3D.Data.Parent, HGamer3D.Data, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util.Variable, HGamer3D.Util, 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.InputEventHandler, HGamer3D.Input, HGamer3D.Graphics3D, HGamer3D.GUI.UIElement, HGamer3D.GUI.Button, HGamer3D.GUI.EditText, HGamer3D.GUI.DropDownList, HGamer3D.GUI.Slider, HGamer3D.GUI.Text, HGamer3D.GUI.CheckBox, HGamer3D.GUI, HGamer3D.Audio.SoundSource, HGamer3D.Audio.SoundListener, HGamer3D.Audio.Volume, HGamer3D.Audio, HGamer3D Other-modules: diff --git a/src/HGamer3D.cabal.tmpl b/src/HGamer3D.cabal.tmpl deleted file mode 100644 index 1e9c9f7..0000000 --- a/src/HGamer3D.cabal.tmpl +++ /dev/null @@ -1,32 +0,0 @@ -Name: HGamer3D -Version: {version} -Synopsis: Toolset for the Haskell Game Programmer -Description: - HGamer3D is a toolset for developing 3D games in the programming - language Haskell. - -License: OtherLicense -License-file: LICENSE -Author: Peter Althainz -Maintainer: althainz@gmail.com -Build-Type: Simple -Cabal-Version: >=1.4 -Homepage: http://www.hgamer3d.org -Category: Game Engine -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.6 && <0.7, cereal >=0.5 && < 0.6, fresco-binding >= 0.1.0 && < 0.2.0 - - Exposed-modules: 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.PlayCmd, HGamer3D.Data, HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Util.Variable, HGamer3D.Util, 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.InputEventHandler, HGamer3D.Input, HGamer3D.Graphics3D, HGamer3D.GUI.Button, HGamer3D.GUI.EditText, HGamer3D.GUI.DropDownList, HGamer3D.GUI.Slider, HGamer3D.GUI.Text, HGamer3D.GUI.CheckBox, HGamer3D.GUI, HGamer3D.Audio.SoundSource, HGamer3D.Audio.SoundListener, HGamer3D.Audio.Volume, HGamer3D.Audio, HGamer3D - - Other-modules: - - c-sources: - - ghc-options: - cc-options: -Wno-attributes - hs-source-dirs: . - Include-dirs: . - build-depends: - diff --git a/src/HGamer3D.hs b/src/HGamer3D.hs index 0029880..64a5d69 100644 --- a/src/HGamer3D.hs +++ b/src/HGamer3D.hs @@ -23,27 +23,40 @@ module HGamer3D ( - module Fresco, - module HGamer3D.Data, - module HGamer3D.Util, - module HGamer3D.Graphics3D, - module HGamer3D.Input, + module Fresco, + module HGamer3D.Data, + module HGamer3D.Util, + module HGamer3D.Graphics3D, + module HGamer3D.Input, module HGamer3D.GUI, module HGamer3D.Audio, - configureHG3D, - stepHG3D, - loopHG3D, + HG3D, + GameLogicFunction, + runGame, + registerCallback, isExitHG3D, + resetExitHG3D, exitHG3D, + newE, - HG3D, +-- ctParent, + EntityTree (..), + newET, + + (<:), + (<|), + (-:), + (-|), + + (#) ) where -import Fresco +import Fresco hiding (newE) +import qualified Fresco as F (newE) import HGamer3D.Data import HGamer3D.Util import HGamer3D.Graphics3D @@ -56,65 +69,127 @@ import Control.Monad import Control.Concurrent.MVar import Data.IORef --- run loop +import qualified Data.Map as M +import Data.Word +import Data.Maybe + +-- Opaque Value to denote some game-loop data +data HG3D = HG3D ObjectLibSystem CallbackSystem (Var Bool) + +-- runHG3D runs the engine in the main loop (for Mac) and executes game logic +type GameLogicFunction = HG3D -> IO () + +-- runGame, runs the game in the main loop, creates threads for GameLogicFunctions +runGame :: Graphics3DConfig -> GameLogicFunction -> GameTime -> IO () +runGame conf glf loopSleepTime = do + + ols <- createOLS + cbs <- createCBS + varExit <- makeVar False + + let hg3d = HG3D ols cbs varExit + + forkIO $ do + + -- create graphics system + eG3D <- newE hg3d [ + ctGraphics3DConfig #: conf, + ctGraphics3DCommand #: NoCmd + ] + + eih <- newE hg3d [ + ctInputEventHandler #: DefaultEventHandler, + ctExitRequestedEvent #: ExitRequestedEvent + ] + + -- create callback loop, handle windows exit command + forkIO $ do + registerReceiverCBS cbs eih ctExitRequestedEvent (\_ -> writeVar varExit True >> return ()) + forever $ (stepCBS cbs) + + -- create game logic loop + forkIO $ glf hg3d + + -- create game step loop + let gameStep = do + setC eG3D ctGraphics3DCommand Step + sleepFor loopSleepTime + gameStep + + forkIO $ gameStep + + return () + + -- enter into endless game loop + let loopGame = do + stepOLS ols + ex <- readVar varExit + if ex + then return () + else loopGame + + loopGame + +isExitHG3D (HG3D ols cbs varExit) = do + ise <- readVar varExit + return ise + +resetExitHG3D (HG3D ols cbs varExit) = writeVar varExit False + +exitHG3D (HG3D ols cbs varExit) = do + writeVar varExit True >> return () -type HG3D = (Entity, CallbackSystem, Var Bool) +registerCallback (HG3D ols cbs varExit) e ct f = do + registerReceiverCBS cbs e ct f -configureHG3D = do +newE (HG3D ols cbs varExit) creationList = do + e <- F.newE creationList + addEntityOLS ols e + return e - cbsRef <- newEmptyMVar - -- create graphics system - eG3D <- newE [ - ctGraphics3DConfig #: standardGraphics3DConfig, - ctGraphics3DCommand #: NoCmd - ] - eih <- newE [ - ctInputEventHandler #: DefaultEventHandler, - ctExitRequestedEvent #: ExitRequestedEvent - ] +data EntityTree = ETNode (Maybe String) [(Word64, Component)] + | ETChild (Maybe String) [(Word64, Component)] [EntityTree] + | ETList [EntityTree] - varExit <- makeVar False +createET :: HG3D -> EntityTree -> Maybe Entity -> IO [(String, Entity)] - -- create callback loop - forkIO $ do - cbs <- createCBS - registerCallback (eG3D, cbs, varExit) eih ctExitRequestedEvent (\_ -> writeVar varExit True >> return ()) - putMVar cbsRef cbs - forever (stepCBS cbs) +createET hg3d (ETNode label clist) parent = do + clist' <- case parent of + Just p -> idE p >>= \id -> return ((ctParent #: id) : filter (\(ct, c) -> (ComponentType ct) /= ctParent) clist) + Nothing -> return clist + e <- newE hg3d clist' + case label of + Just l -> return [(l, e)] + Nothing -> return [] - cbs <- takeMVar cbsRef +createET hg3d (ETList tlist) parent = do + l <- mapM (\et -> createET hg3d et parent) tlist + return (Prelude.concat l) - return (eG3D, cbs, varExit) +createET hg3d (ETChild label clist tlist) parent = do + [(_, e1)] <- createET hg3d (ETNode (Just "label") clist) parent + let l1 = case label of + Just l -> [(l, e1)] + Nothing -> [] + l2 <- createET hg3d (ETList tlist) (Just e1) + return (l1 ++ l2) -stepHG3D (eG3D, cbs, varExit) = do - setC eG3D ctGraphics3DCommand Step +newET :: HG3D -> [EntityTree] -> IO (M.Map String Entity) +newET hg3d et = createET hg3d (ETList et) Nothing >>= \l -> return (M.fromList l) -isExitHG3D (eG3D, cbs, varExit) = do - ise <- readVar varExit - return ise +(<:) :: String -> [(Word64, Component)] -> EntityTree +label <: clist = ETNode (Just label) clist -resetExitHG3D (eG3D, cbs, varExit) = writeVar varExit False +(<|) :: String -> ([(Word64, Component)], [EntityTree]) -> EntityTree +label <| (clist, tlist) = ETChild (Just label) clist tlist -loopHG3D hg3d loopSleepTime checkExit = do - stepHG3D hg3d - sleepFor loopSleepTime - ise <- do - ise' <- isExitHG3D hg3d - if ise' then do - resetExitHG3D hg3d - checkExit - else - return False - if not ise then do - loopHG3D hg3d loopSleepTime checkExit - return () - else - return () +(-:) :: () -> [(Word64, Component)] -> EntityTree +() -: clist = ETNode Nothing clist -exitHG3D (eG3D, cvs, varExit) = do - writeVar varExit True >> return () +(-|) :: () -> ([(Word64, Component)], [EntityTree]) -> EntityTree +() -| (clist, tlist) = ETChild Nothing clist tlist -registerCallback (eG3D, cbs, varExit) e ct f = do - registerReceiverCBS cbs e ct f \ No newline at end of file +(#) :: (M.Map String Entity) -> String -> Entity +m # s = fromJust $ M.lookup s m \ No newline at end of file diff --git a/src/HGamer3D/Data.hs b/src/HGamer3D/Data.hs index e385ac4..a475ab3 100644 --- a/src/HGamer3D/Data.hs +++ b/src/HGamer3D/Data.hs @@ -37,6 +37,7 @@ module HGamer3D.Data -- * Misc module HGamer3D.Data.PlayCmd, + module HGamer3D.Data.Parent, -- * Implementation module HGamer3D.Data.Window @@ -54,4 +55,5 @@ import HGamer3D.Data.TypeSynonyms import HGamer3D.Data.Vector import HGamer3D.Data.Window import HGamer3D.Data.PlayCmd +import HGamer3D.Data.Parent diff --git a/src/HGamer3D/Data/Geometry2D.hs b/src/HGamer3D/Data/Geometry2D.hs index 8a84007..ed5e4fc 100644 --- a/src/HGamer3D/Data/Geometry2D.hs +++ b/src/HGamer3D/Data/Geometry2D.hs @@ -10,7 +10,7 @@ file: HGamer3D/Data/Geometry2D.hs -} -{-# LANGUAGE FlexibleInstances, DatatypeContexts #-} +{-# LANGUAGE FlexibleInstances #-} -- | Type definitions for 2D geometry module HGamer3D.Data.Geometry2D diff --git a/src/HGamer3D/Data/Parent.hs b/src/HGamer3D/Data/Parent.hs new file mode 100644 index 0000000..246db59 --- /dev/null +++ b/src/HGamer3D/Data/Parent.hs @@ -0,0 +1,31 @@ +{- + Datatypes to specify a parent by id + 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 Parent component type +module HGamer3D.Data.Parent + +( + Parent, + ctParent +) + +where + +import Data.MessagePack +import Data.ByteString +import Fresco + +type Parent = ByteString + +ctParent :: ComponentType Parent +ctParent = ComponentType 0xbadd24df00e737d8 + diff --git a/src/HGamer3D/Data/TypeSynonyms.hs b/src/HGamer3D/Data/TypeSynonyms.hs index d35aaa3..b815e7c 100644 --- a/src/HGamer3D/Data/TypeSynonyms.hs +++ b/src/HGamer3D/Data/TypeSynonyms.hs @@ -34,10 +34,10 @@ ctPosition = ComponentType 0x29aacbbb10c84016 ctScale :: ComponentType Scale ctScale = ComponentType 0x2f9c124bc8fd41c4 --- CH4-3s +-- HGamer3D website, entities and events, example ComponentType ctOrientation :: ComponentType Orientation ctOrientation = ComponentType 0x815eb4d9c7bfaa74 --- CH4-3e +-- end of website text ctVisible :: ComponentType Bool ctVisible = ComponentType 0x98e7a78e949e1c6e diff --git a/src/HGamer3D/GUI.hs b/src/HGamer3D/GUI.hs index b237bc3..bce2f05 100644 --- a/src/HGamer3D/GUI.hs +++ b/src/HGamer3D/GUI.hs @@ -22,8 +22,10 @@ module HGamer3D.GUI , module HGamer3D.GUI.CheckBox ) + where +import HGamer3D.GUI.UIElement import HGamer3D.GUI.Button import HGamer3D.GUI.EditText import HGamer3D.GUI.Text diff --git a/src/HGamer3D/GUI/Button.hs b/src/HGamer3D/GUI/Button.hs index 4193021..b0c86bb 100644 --- a/src/HGamer3D/GUI/Button.hs +++ b/src/HGamer3D/GUI/Button.hs @@ -10,9 +10,10 @@ file: HGamer3D/GUI/Button.hs -} --- | Module providing the Mouse functionality and settings +-- | Module providing the Button functionality and settings module HGamer3D.GUI.Button ( + Button (..), ctButton ) @@ -21,10 +22,20 @@ where import Fresco import Debug.Trace import Data.Text +import Data.MessagePack import HGamer3D.Data -ctButton :: ComponentType Bool -ctButton = ComponentType 0x68a1857c27690b30 - + +data Button = Button { + buttonPressed::Bool, + buttonLabel::Text +} deriving (Eq, Show, Read) + +instance ComponentClass Button where + toObj (Button v1 v2) = ObjectArray [ObjectBool v1, (toObj v2)] + fromObj (ObjectArray [ObjectBool v1, v2]) = Button v1 (fromObj v2) + +ctButton :: ComponentType Button +ctButton = ComponentType 0x68a1857c27690b30 diff --git a/src/HGamer3D/GUI/UIElement.hs b/src/HGamer3D/GUI/UIElement.hs new file mode 100644 index 0000000..55073af --- /dev/null +++ b/src/HGamer3D/GUI/UIElement.hs @@ -0,0 +1,31 @@ +{- + GUI: Button functionality + HGamer3D Library (A project to enable 3D game development in Haskell) + Copyright 2015 Peter Althainz + + Distributed under the Apache License, Version 2.0 + (See attached file LICENSE or copy at + http://www.apache.org/licenses/LICENSE-2.0) + + file: HGamer3D/GUI/Button.hs +-} + +-- | Module providing the Button functionality and settings +module HGamer3D.GUI.UIElement +( + ctUIElement +) + +where + +import Fresco +import Debug.Trace +import Data.Text +import Data.MessagePack + +import HGamer3D.Data + +ctUIElement :: ComponentType () +ctUIElement = ComponentType 0xd5b79f5837e52274; + + diff --git a/src/HGamer3D/Graphics3D/Geometry.hs b/src/HGamer3D/Graphics3D/Geometry.hs index 725547e..2b05959 100644 --- a/src/HGamer3D/Graphics3D/Geometry.hs +++ b/src/HGamer3D/Graphics3D/Geometry.hs @@ -24,7 +24,8 @@ module HGamer3D.Graphics3D.Geometry ( Shape (..), Geometry (..), - ctGeometry + ctGeometry, + ctGraphicsElement ) where @@ -39,9 +40,8 @@ import HGamer3D.Graphics3D.Material -- generated --- CH4-4s +-- HGamer3D website, entities and events, Geometry data type and component -- | A shape is a basic geometric formd - data Shape = Sphere | Cube | Plane @@ -77,6 +77,7 @@ instance ComponentClass Geometry where ctGeometry :: ComponentType Geometry ctGeometry = ComponentType 0xee433d1a4b964591 --- CH4-4e +ctGraphicsElement :: ComponentType () +ctGraphicsElement = ComponentType 0x65114ba821671643 +-- end of website text --- generated diff --git a/src/HGamer3D/Graphics3D/Graphics3DConfig.hs b/src/HGamer3D/Graphics3D/Graphics3DConfig.hs index 7fdb345..daff3e5 100644 --- a/src/HGamer3D/Graphics3D/Graphics3DConfig.hs +++ b/src/HGamer3D/Graphics3D/Graphics3DConfig.hs @@ -122,3 +122,5 @@ ctGraphics3DConfig :: ComponentType Graphics3DConfig ctGraphics3DConfig = ComponentType 0x0884eb62b6674bff + + diff --git a/src/HGamer3D/Graphics3D/Light.hs b/src/HGamer3D/Graphics3D/Light.hs index 2251304..36384ed 100644 --- a/src/HGamer3D/Graphics3D/Light.hs +++ b/src/HGamer3D/Graphics3D/Light.hs @@ -40,10 +40,10 @@ instance ComponentClass LightType where data Light = Light - LightType -- ^ Type of light - Float -- ^ brighness - Float -- ^ range - Float -- ^ specular intensity + LightType + Float + Float + Float -- ^ floats: brightness, range, specular intensity instance ComponentClass Light where toObj (Light lt b r s) = ObjectArray [toObj lt, ObjectFloat b, ObjectFloat r, ObjectFloat s] diff --git a/src/HGamer3D/Util.hs b/src/HGamer3D/Util.hs index be5488b..600e8f1 100644 --- a/src/HGamer3D/Util.hs +++ b/src/HGamer3D/Util.hs @@ -23,9 +23,9 @@ module HGamer3D.Util ( - module HGamer3D.Util.FileLocation, - module HGamer3D.Util.UniqueName, - module HGamer3D.Util.Variable + module HGamer3D.Util.FileLocation, + module HGamer3D.Util.UniqueName, + module HGamer3D.Util.Variable ) where diff --git a/src/HGamer3D/Util/EntityTree.hs b/src/HGamer3D/Util/EntityTree.hs new file mode 100644 index 0000000..be2483f --- /dev/null +++ b/src/HGamer3D/Util/EntityTree.hs @@ -0,0 +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-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. + +-- EntityTree.hs +-- build trees of items with parent, child relationship, by utilizing id mechanism + +module HGamer3D.Util.EntityTree +( + +) where + +import Fresco +import HGamer3D.Data +import HGamer3D.Graphics3D +import HGamer3D.GUI + + + + diff --git a/src/stack.yaml b/src/stack.yaml index 1562f07..813d3c1 100644 --- a/src/stack.yaml +++ b/src/stack.yaml @@ -3,5 +3,5 @@ resolver: lts-5.8 flags: {} packages: - '.' -- '../../fresco/haskell' +- '../../fresco-haskell' extra-lib-dirs: diff --git a/tools/random.txt b/tools/random.txt index 5cc370c..087daca 100644 --- a/tools/random.txt +++ b/tools/random.txt @@ -8,10 +8,10 @@ -badd24df00e737d8 112cc0dc2647d39e -8a4376986a589bd3 1d813af21d95b77b -77834a16c475d96f def9d856332b402a -d5b79f5837e52274 65114ba821671643 + + + + e5ea0d693a04ff71 1cdc5b0a65479346 829863cdd141007e 457ac00afe66a3a4