game programming in haskell
play

Game programming in Haskell Alexander Berntsen Stian A. Ellingsen - PowerPoint PPT Presentation

Outline Our project Welcome to the functional paradigm of Haskell Game programming in Haskell Alexander Berntsen Stian A. Ellingsen September 18, 2013 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell Outline Our project


  1. Outline Our project Welcome to the functional paradigm of Haskell Game programming in Haskell Alexander Berntsen Stian A. Ellingsen September 18, 2013 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  2. Outline Our project Welcome to the functional paradigm of Haskell Our project Current game programming paradigms Solving those problems Welcome to the functional paradigm of Haskell Declarative programming Haskell Functional reactive programming Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  3. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Object-Oriented Programming ◮ In OOP we try to represent our game world with object models ◮ Objects are usually instances of classes that interact with each other ◮ Objects have methods through which they perform said interaction f o r ( std : : vector < E n t i t i e s ∗ > :: c o n s t i t e r a t o r ent = e n t i t i e s . begin ( ) ; ent != e n t i t i e s . end ( ) ; ( ∗ ent) − > handle ( event ) , ++ent ) ; Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  4. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Component-Entity Systems ◮ components (single purpose bits of state) ◮ entities (unique ids) ◮ systems (single purpose functions that take a set of entities with specific component(s) and update them) ( defn r e n d e r e r [ r e n d e r a b l e s ] ( doseq [ e r e n d e r a b l e s ] ( l e t [ rend ( as e : r e n d e r a b l e ) ] (( rend : fn ) e ) ) ) ) Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  5. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell Some of the problems with these paradigms ◮ no rigorous definitions ◮ used as a herding mechanism to keep mediocre programmers occupied (which may lead to mediocre programs) ◮ heavy use of state makes refactoring a nightmare ◮ lots of boilerplate code ◮ tight coupling ◮ bloated core code Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  6. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell We think that ◮ functional purity may eliminate these problems ◮ pure functional programming can be used efficiently for game programming Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  7. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell What we will try to figure out ◮ how to do a by nature heavily stateful computation (games) in a pure paradigm (Haskell) ◮ whether this results in a higher quality of source code ◮ what types of games are most compatible with PFP Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  8. Outline Current game programming paradigms Our project Solving those problems Welcome to the functional paradigm of Haskell By doing this ◮ analyse Haskell games’ source code (“frag”, “Nikki and the Robots”) ◮ analyse Haskell game libraries (“Hipmunk”, “SDL”) ◮ analyse other heavily state-reliant Haskell projects (“xmonad”, “AMuZed and ZooM”, “Yi”) ◮ try to apply what we learn through this Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  9. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  10. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  11. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 # wtf ? why are you changing your # mind about what ’ a ’ i s ? a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  12. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming The imperative way is confusing and low-level a = 2 # wtf ? why are you changing your # mind about what ’ a ’ i s ? a += 1 Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  13. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming / ∗ P r i n t ” h e l l o ” 3 times ∗ / main () { i ; int for ( i = 0; i < 3; ++i ) p r i n t f ( ”%s ” , i != 3 ? ” h e l l o ” : ” h e l l o \ n” ) ; } Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  14. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming / ∗ ∗ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ∗ Filename : l o l . c ∗ D e s c r i p t i o n : This program p r i n t s ” h e l l o h e l l o h e l l o ” ∗ Version : 1.0 ∗ Created : 17/09/13 11:59:11 ∗ R e v i s i o n : none ∗ Compiler : gcc ∗ Author : Foo Bar ( foo@bar . com ) , ∗ O r g a n i z a t i o n : Fubaz , Inc . ∗ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ∗ / #i n c l u d e < s t d i o . h > #i f d e f GNUC # d e f i n e UNUSED( x ) UNUSED # # x a t t r i b u t e ( ( u n u s e d )) #e l s e # d e f i n e UNUSED( x ) UNUSED # # x #e n d i f #i f d e f GNUC # d e f i n e UNUSED FUNCTION( x ) a t t r i b u t e ( ( u n u s e d ) ) UNUSED # # x #e l s e d e f i n e UNUSED FUNCTION( x ) UNUSED # # x # #e n d i f main ( i n t ∗ UNUSED( argc ) , char UNUSED( argv ) ) { i n t const i ; i n t char msg [ 6 ] = ” h e l l o ” ; ( i = 0; i < 3 ; ++i ) { f o r p r i n t f ( ”%s ” , msg ) ; } p r i n t f ( ” \ n” ) ; } Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  15. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  16. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it r e p l i c a t e 3 ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  17. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So we describe what we want, instead of how to achieve it unwords $ r e p l i c a t e 3 ” h e l l o ” Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  18. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which often leads to . . . ◮ looser coupling ◮ a more high-level approach ◮ parallellisation and optimisation out of the box ◮ rapid implementation, freeing up development time Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  19. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which means . . . ◮ less bloated code ◮ less code, period (LOC) ◮ fewer bugs/errors ◮ faster debugging cycles ◮ source code maintainability and reusability Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  20. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming Which makes imperative programming look like this in comparison OBTW THIS PROGRAM PRINTS HELLO HELLO HELLO TLDR HAI 1.2 CAN HAS STDIO? IM IN YR LOOP UPPIN YR VAR BOTH SAEM VAR AN 3 , O RLY? YA RLY, GTFO NO WAI, VAR, WTF? OMG 2 VISIBLE ”HELLO” GTFO OMGWTF VISIBLE ”HELLO ”! OIC OIC IM OUTTA YR LOOP KTHXBYE Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

  21. Outline Declarative programming Our project Haskell Welcome to the functional paradigm of Haskell Functional reactive programming So there’s this thing called Haskell Alexander Berntsen, Stian A. Ellingsen Game programming in Haskell

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend