HGamer3D-API 0.1.5 → 0.1.6
raw patch · 4 files changed
+280/−174 lines, 4 filesdep +HGamer3D-SFML-Bindingdep −HGamer3D-OIS-Binding
Dependencies added: HGamer3D-SFML-Binding
Dependencies removed: HGamer3D-OIS-Binding
Files
- HGamer3D-API.cabal +7/−11
- HGamer3D/APIs/One.hs +10/−163
- HGamer3D/APIs/Two/Audio.hs +174/−0
- HGamer3D/APIs/Two/InputSystem.hs +89/−0
HGamer3D-API.cabal view
@@ -1,17 +1,13 @@ Name: HGamer3D-API -Version: 0.1.5 +Version: 0.1.6 Synopsis: Library to enable 3D game development for Haskell - API Description: Library, to enable 3D game development for Haskell, based on bindings to 3D Graphics, Audio and GUI libraries. - THIS MODULE: APIs - List of features and modules: - Data Module (Basic Data Types), - OGRE Binding (3D Graphics Engine), - OIS Binding (Input System), - cAudio Binding (Audio), - CEGUI Binding (GUI System), - APIs (Haskell style APIs, different ways, to approach API) + + This is the API module, which gives the higher level API for primary + use. + Platform: Windows only License: Apache License, Version 2.0 Install: see http://www.althainz.de/HGamer3D/Download-and-Installation.html @@ -27,9 +23,9 @@ Extra-source-files: Setup.hs Library - Build-Depends: base >= 3 && < 5, HGamer3D-Data == 0.1.5, HGamer3D-Ogre-Binding == 0.1.5, HGamer3D-OIS-Binding == 0.1.5 + Build-Depends: base >= 3 && < 5, HGamer3D-Data == 0.1.5, HGamer3D-Ogre-Binding == 0.1.5, HGamer3D-SFML-Binding == 0.1.6 - Exposed-modules: HGamer3D.APIs.One + Exposed-modules: HGamer3D.APIs.One,HGamer3D.APIs.Two.Audio,HGamer3D.APIs.Two.InputSystem Other-modules: c-sources:
HGamer3D/APIs/One.hs view
@@ -46,7 +46,6 @@ -- Data types - basic systems - InputSystem (InputSystem, isOisbSystem, isOisbSchema), ViewSystem (ViewSystem, vsCamera, vsRenderWindow, vsViewport), EngineSystem (EngineSystem, esRoot, esSceneManager, esResourceGroupManager, esTextureManager, esControllerManager), @@ -115,26 +114,6 @@ -- Time Functions getTime, - -- Event Functions - Action (Action), - createTriggerAction, - bindKey, - isActionActive, - createAnalogAxisAction, - bindMouseAxis, - bindJoystickAxis, - bindMouseButton, - bindJoystickButton, - getActionAbsoluteValue, - getActionRelativeValue, - - isMouseAvailable, - isJoystickAvailable, - getAvailableAxisMouse, - getAvailableButtonsMouse, - getAvailableAxisJoystick, - getAvailableButtonsJoystick, - -- run it renderLoop, @@ -145,8 +124,6 @@ import GHC.Ptr import HGamer3D.Bindings.Ogre.ClassPtr -import HGamer3D.Bindings.OIS.ClassPtr - import HGamer3D.Bindings.Ogre.Utils import HGamer3D.Data.Colour @@ -187,17 +164,6 @@ import HGamer3D.Bindings.Ogre.TypeHG3DClass import HGamer3D.Bindings.Ogre.EnumPrefabType -import HGamer3D.Bindings.OIS.Utils -import HGamer3D.Bindings.OIS.ClassSystem -import HGamer3D.Bindings.OIS.ClassAction -import HGamer3D.Bindings.OIS.ClassActionSchema -import HGamer3D.Bindings.OIS.ClassAnalogAxisAction -import HGamer3D.Bindings.OIS.EnumActionType -import HGamer3D.Bindings.OIS.ClassDevice - - -import HGamer3D.Bindings.OIS.TypeHG3DClass - import HGamer3D.Data.HG3DClass @@ -206,12 +172,6 @@ --- --- |The encapsulation of the state of input devices, like keyboard, mouse, ... -data InputSystem = InputSystem { - isOisbSystem::HG3DClass, - isOisbSchema::HG3DClass -} deriving (Show, Eq) - -- |The encapsulation of the state of the view, camera, window and viewport data ViewSystem = ViewSystem { vsCamera::HG3DClass, @@ -320,7 +280,7 @@ -- the graphics engine, the input system and the view initializeHG3D :: String -- ^Name of the window, displayed -> String -- ^SceneManager type used - -> IO (EngineSystem, ViewSystem, InputSystem) + -> IO (EngineSystem, ViewSystem) initializeHG3D windowName sceneManagerType = do root <- cRNew @@ -328,11 +288,6 @@ fUAddResourceLocations "resources.cfg" renderWindow <-cRInitialise root True windowName "" - fUInitializeOis renderWindow - oisbSystem <- cSyGetSingletonPtr - oisbSchema <- cSyGetDefaultActionSchemaAutoCreate oisbSystem - - sceneManager <- cRCreateSceneManager root sceneManagerType "SceneManager" camera <- cSmCreateCamera sceneManager "SimpleCamera" @@ -359,8 +314,7 @@ return ( EngineSystem root sceneManager rgm tm cm, - ViewSystem camera renderWindow viewport, - InputSystem oisbSystem oisbSchema + ViewSystem camera renderWindow viewport ) @@ -612,120 +566,13 @@ return (Time time) --- event functions, OIS stuff - -data Action = Action HG3DClass - -runIsFrame :: InputSystem -> Float -> IO () -runIsFrame is delta = do - cSyProcess (isOisbSystem is) delta - return () - -createTriggerAction :: InputSystem -> String -> IO (Action) -createTriggerAction is actionName = do - let schema = isOisbSchema is - action <- cAsCreateTriggerAction schema actionName - return (Action action) -createAnalogAxisAction :: InputSystem -> Float -> Float -> String -> IO (Action) -createAnalogAxisAction is minval maxval actionName = do - let schema = isOisbSchema is - action <- cAsCreateAnalogAxisAction schema actionName - cAaaSetMinimumValue action minval - cAaaSetMaximumValue action maxval - return (Action action) - -bindKey :: Action -> String -> IO () -bindKey (Action action) keyChar = do - cABind4 action ("Keyboard/" ++ keyChar) - return () - -isMouseAvailable :: InputSystem -> IO (Bool) -isMouseAvailable is = do - avail <- cSyHasDevice (isOisbSystem is) "Mouse" - return (avail) - -bindMouseAxis :: Action -> String -> IO () -bindMouseAxis (Action action) axisName = do - cABind4 action ("Mouse/" ++ axisName) - return () - -bindMouseButton :: Action -> String -> IO () -bindMouseButton (Action action) buttonName = do - cABind4 action ("Mouse/" ++ buttonName) - return () - -isJoystickAvailable :: InputSystem -> String -> IO (Bool) -isJoystickAvailable is name = do - avail <- cSyHasDevice (isOisbSystem is) name - return (avail) - -bindJoystickAxis :: Action -> String -> String -> IO () -bindJoystickAxis (Action action) joystickName axisName = do - cABind4 action (joystickName ++ "/" ++ axisName) - return () - -bindJoystickButton :: Action -> String -> String -> IO () -bindJoystickButton (Action action) joystickName buttonName = do - cABind4 action (joystickName ++ "/" ++ buttonName) - return () - - -getAvailableAxisMouse :: InputSystem -> IO [String] -getAvailableAxisMouse is = do - dev <- cSyGetDevice (isOisbSystem is) "Mouse" - let axes = map (\x -> x ++ " Axis") ["X", "Y", "Z"] - bools <- mapM (cDHasState dev) axes - let avail = map fst $ filter snd (zip axes bools) - return (avail) - -getAvailableButtonsMouse :: InputSystem -> IO [String] -getAvailableButtonsMouse is = do - dev <- cSyGetDevice (isOisbSystem is) "Mouse" - let buttons = (map (\bt -> "Button " ++ (show bt)) [0..50]) ++ (map (\bt -> bt ++ " Button") ["Left", "Middle", "Right"]) - bools <- mapM (cDHasState dev) buttons - let avail = map fst $ filter snd (zip buttons bools) - return (avail) - -getAvailableAxisJoystick :: InputSystem -> String -> IO [String] -getAvailableAxisJoystick is name = do - dev <- cSyGetDevice (isOisbSystem is) name - let axes = (map (\x -> "Axis " ++ (show x)) [0..50]) ++ (map (\x -> "Slider " ++ (show x)) [0..50]) - bools <- mapM (cDHasState dev) axes - let avail = map fst $ filter snd (zip axes bools) - return (avail) - -getAvailableButtonsJoystick :: InputSystem -> String -> IO [String] -getAvailableButtonsJoystick is name = do - dev <- cSyGetDevice (isOisbSystem is) name - let buttons = (map (\bt -> "Button " ++ (show bt)) [0..50]) - bools <- mapM (cDHasState dev) buttons - let avail = map fst $ filter snd (zip buttons bools) - return (avail) - - -isActionActive :: Action -> IO (Bool) -isActionActive (Action action) = do - flag <- cAIsActive action - return (flag) - -getActionAbsoluteValue :: Action -> IO (Float) -getActionAbsoluteValue (Action action) = do - val <- cAaaGetAbsoluteValue action - return (val) - -getActionRelativeValue :: Action -> IO (Float) -getActionRelativeValue (Action action) = do - val <- cAaaGetRelativeValue action - return (val) - --- renderStep a :: EngineSystem -> ViewSystem -> InputSystem -> Time -> a -> IO (Bool, a) +-- renderStep a :: EngineSystem -> ViewSystem -> Time -> a -> IO (Bool, a) -renderInternalStep :: EngineSystem -> ViewSystem -> InputSystem -> Time -> IO (Bool, Time) -renderInternalStep es vs is (Time lastTime) = do +renderInternalStep :: EngineSystem -> ViewSystem -> Time -> IO (Bool, Time) +renderInternalStep es vs (Time lastTime) = do (Time time) <- getTime es let delta = time - lastTime - runIsFrame is delta fUMessagePump closed <- cRwIsClosed (vsRenderWindow vs) if (closed) then @@ -734,12 +581,12 @@ cRRenderOneFrame (esRoot es) return (True, (Time time)) -renderLoop :: EngineSystem -> ViewSystem -> InputSystem -> Time -> a -> (EngineSystem -> ViewSystem -> InputSystem -> Time -> a -> IO (Bool, a)) -> IO () -renderLoop es vs is t a renderStep = do - (flagStep, time) <- renderInternalStep es vs is t - (flagLoop, a) <- renderStep es vs is time a +renderLoop :: EngineSystem -> ViewSystem -> Time -> a -> (EngineSystem -> ViewSystem -> Time -> a -> IO (Bool, a)) -> IO () +renderLoop es vs t a renderStep = do + (flagStep, time) <- renderInternalStep es vs t + (flagLoop, a) <- renderStep es vs time a if (flagStep && flagLoop) then do - renderLoop es vs is time a renderStep + renderLoop es vs time a renderStep else return ()
+ HGamer3D/APIs/Two/Audio.hs view
@@ -0,0 +1,174 @@+-- 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) 2011 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.++-- InputSystem.hs++-- |This module is one sub module of the second attempt, to provide an +-- abstracted interface to the HGamer3D API Bindings. It is named 'Two',+-- submodule Audio and handles Music and Sound.++module HGamer3D.APIs.Two.Audio++(+ -- Enums+ --+ module HGamer3D.Bindings.SFML.EnumSoundSourceStatus,+ + + -- Low Level Interface+ --+ + -- Listener Functions+ setAudioVolume,+ getAudioVolume,+ setAudioPosition,+ setAudioDirection,++ -- Music Functions+ newMusic,+ deleteMusic,+ openMusicFromFile,+ + -- Sound Functions+ newSound,+ deleteSound,+ setSoundBuffer,++ playSound,+ pauseSound,+ stopSound,++ setSoundLoop,+ getSoundLoop,+ resetSoundBuffer,+ + -- SoundBuffer Functions+ newBuffer, + deleteBuffer, + loadBufferFromFile, ++ -- SoundSource Functions+ setSourcePitch,+ setSourceVolume,+ setSourcePosition,+ setSourceAttenuation,++ getSourcePitch,+ getSourceVolume,+ getSourceMinDistance,+ getSourceAttenuation,++ attachSourceToListener,+ isSourceAttachedToListener,++ -- SoundStream Functions+ playStream,+ pauseStream,+ stopStream,++ setStreamLoop,+ getStreamLoop,++ +)++where++import GHC.Ptr++import HGamer3D.Bindings.SFML.ClassPtr+import HGamer3D.Bindings.SFML.Utils++import qualified HGamer3D.Bindings.SFML.ClassListener as Listener+import qualified HGamer3D.Bindings.SFML.ClassMusic as Music +import qualified HGamer3D.Bindings.SFML.ClassSound as Sound+import qualified HGamer3D.Bindings.SFML.ClassSoundBuffer as SoundBuffer+import qualified HGamer3D.Bindings.SFML.ClassSoundSource as SoundSource+import qualified HGamer3D.Bindings.SFML.ClassSoundStream as SoundStream+import HGamer3D.Bindings.SFML.EnumSoundSourceStatus+++-- Low Level Interface+--++-- Listener Functions++setAudioVolume = Listener.setGlobalVolume+getAudioVolume = Listener.getGlobalVolume+setAudioPosition = Listener.setPosition+setAudioDirection = Listener.setDirection+++-- Music Functions+--++newMusic = Music.new+deleteMusic = Music.delete+openMusicFromFile = Music.openFromFile++-- Sound Functions+--++newSound = Sound.new+deleteSound = Sound.delete++playSound = Sound.play+pauseSound = Sound.pause+stopSound = Sound.stop++setSoundBuffer = Sound.setBuffer+setSoundLoop = Sound.setLoop+getSoundLoop = Sound.getLoop+resetSoundBuffer = Sound.resetBuffer++-- Sound Buffer Functions+--++newBuffer = SoundBuffer.new+deleteBuffer = SoundBuffer.delete+loadBufferFromFile = SoundBuffer.loadFromFile++-- Sound Source Functions+--++setSourcePitch = SoundSource.setPitch+setSourceVolume = SoundSource.setVolume+setSourcePosition = SoundSource.setPosition+setSourceAttenuation = SoundSource.setAttenuation++getSourcePitch = SoundSource.getPitch+getSourceVolume = SoundSource.getVolume+getSourceMinDistance = SoundSource.getMinDistance+getSourceAttenuation = SoundSource.getAttenuation++attachSourceToListener = SoundSource.setRelativeToListener+isSourceAttachedToListener = SoundSource.isRelativeToListener+++-- Sound Stream Functions+--++playStream = SoundStream.play+pauseStream = SoundStream.pause+stopStream = SoundStream.stop++setStreamLoop = SoundStream.setLoop+getStreamLoop = SoundStream.getLoop+++
+ HGamer3D/APIs/Two/InputSystem.hs view
@@ -0,0 +1,89 @@+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.althainz.de/HGamer3D.html+--+-- (c) 2011 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.++-- InputSystem.hs++-- |This module is one sub module of the second attempt, to provide an +-- abstracted interface to the HGamer3D API Bindings. It is named 'Two',+-- submodule Input System and handles Mouse, Keyboard and Joystick Input.++module HGamer3D.APIs.Two.InputSystem++(+ -- Enums+ --+ module HGamer3D.Bindings.SFML.EnumJoystickAxis,+ module HGamer3D.Bindings.SFML.EnumKey,+ module HGamer3D.Bindings.SFML.EnumMouseButton,+ + -- Joystick Functions+ isJoystickConnected,+ updateJoystickStatus,+ getJoystickButtonCount,+ isJoystickButtonPressed,+ hasJoystickAxis,+ getJoystickPosition,+ + -- Keyboard Functions+ isKeyPressed,+ + -- Mouse Functions+ isMouseButtonPressed,+ getMousePosition,+ + + +)++where++import GHC.Ptr++import HGamer3D.Bindings.SFML.ClassPtr+import HGamer3D.Bindings.SFML.Utils++import qualified HGamer3D.Bindings.SFML.ClassJoystick as Joystick+import qualified HGamer3D.Bindings.SFML.ClassKeyboard as Keyboard+import qualified HGamer3D.Bindings.SFML.ClassMouse as Mouse+import qualified HGamer3D.Bindings.SFML.ClassMouseHG3D as Mouse2+import HGamer3D.Bindings.SFML.EnumJoystickAxis+import HGamer3D.Bindings.SFML.EnumKey+import HGamer3D.Bindings.SFML.EnumMouseButton++-- Joystick funtions+--++isJoystickConnected = Joystick.isConnected+updateJoystickStatus = Joystick.update+getJoystickButtonCount = Joystick.getButtonCount+isJoystickButtonPressed = Joystick.isButtonPressed+hasJoystickAxis = Joystick.hasAxis+getJoystickPosition = Joystick.getAxisPosition++-- Keyboard functions+--++isKeyPressed = Keyboard.isKeyPressed++-- Mouse functions+--++isMouseButtonPressed = Mouse.isButtonPressed+getMousePosition = Mouse2.getPosition++