{"action":"created","issue":{"url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/4","repository_url":"https://api.github.com/repos/fable-compiler/fable-graphics","labels_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/4/comments","events_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/4/events","html_url":"https://github.com/fable-compiler/fable-graphics/issues/4","id":176410196,"number":4,"title":"Functional game engine","user":{"login":"alfonsogarciacaro","id":8275461,"avatar_url":"https://avatars.githubusercontent.com/u/8275461?v=3","gravatar_id":"","url":"https://api.github.com/users/alfonsogarciacaro","html_url":"https://github.com/alfonsogarciacaro","followers_url":"https://api.github.com/users/alfonsogarciacaro/followers","following_url":"https://api.github.com/users/alfonsogarciacaro/following{/other_user}","gists_url":"https://api.github.com/users/alfonsogarciacaro/gists{/gist_id}","starred_url":"https://api.github.com/users/alfonsogarciacaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfonsogarciacaro/subscriptions","organizations_url":"https://api.github.com/users/alfonsogarciacaro/orgs","repos_url":"https://api.github.com/users/alfonsogarciacaro/repos","events_url":"https://api.github.com/users/alfonsogarciacaro/events{/privacy}","received_events_url":"https://api.github.com/users/alfonsogarciacaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2016-09-12T15:44:00Z","updated_at":"2016-09-23T18:39:20Z","closed_at":null,"body":"Hi @whitetigle and @MangelMaxime! Let's start a new issue as the previous one went off-topic long ago ;)\r\n\r\nI've a bit of experience with game engines in the past (before I learnt functional programming) so here are my thoughts:\r\n\r\n- We must do as @whitetigle says and start by creating a comparison with a pure JS sample like http://www.goodboydigital.com/pixijs/bunnymark_v3/ so we can always compare how well our engine performs against raw JS.\r\n- @MangelMaxime's [adaptation of Fable architecture](https://github.com/fable-compiler/fable-graphics/tree/feature/fable-architecture/samples/pixi/fable-architecture) is a good start but there's room for improvement. I guess we can still remove some steps while keeping an API similar to the one for fable-virtualdom.\r\n- The idea of `render` with something like Canvas is different from a GUI framework like DOM (or Windows Forms or whatever). In the latter, `render` means updating the GUI component hierarchy to make some changes. This is expensive and it doesn't need to be done for every frame (actually the concept of frame is foreign to GUI frameworks), but virtualdom allows us to update the state without worrying too much about the actual DOM. On the other hand, with Canvas you draw raw pixel and everything must be rendered every frame (the only optimisation is to skip rendering of elements that are completely hidden).\r\n- Optimisation in games usually have to do with the `update` method, as it often involves expensive physic calculations. We need to receive the time elapsed (the argument in the callback to animation frame), first to do calculations by time and not by time frame (e.g. so bunnies rotate at the same speed even if the frame rate drops) and second to skip calculations that are not needed at that point.\r\n\r\nSo we need to take the classic game loop and try to make it more functional:\r\n\r\n```fsharp\r\nlet gameLoop(dt) =\r\n    update(dt)\r\n    render()\r\n    window.requestAnimationFrame(gameLoop)\r\n```\r\n\r\nI have a couple of concerns at the moment:\r\n\r\n- **Events**: we could take the events happening in every frame and put them in a buffer that is passed to the `update` function. Any ideas?\r\n- **State**: when dealing with thousand of sprites on screen I guess it's going to be difficult to keep the state functional and immutable. We'll probably have to use a mutable state, but we could try to do it in an elegant way."},"comment":{"url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/comments/249270553","html_url":"https://github.com/fable-compiler/fable-graphics/issues/4#issuecomment-249270553","issue_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/4","id":249270553,"user":{"login":"MangelMaxime","id":4760796,"avatar_url":"https://avatars.githubusercontent.com/u/4760796?v=3","gravatar_id":"","url":"https://api.github.com/users/MangelMaxime","html_url":"https://github.com/MangelMaxime","followers_url":"https://api.github.com/users/MangelMaxime/followers","following_url":"https://api.github.com/users/MangelMaxime/following{/other_user}","gists_url":"https://api.github.com/users/MangelMaxime/gists{/gist_id}","starred_url":"https://api.github.com/users/MangelMaxime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MangelMaxime/subscriptions","organizations_url":"https://api.github.com/users/MangelMaxime/orgs","repos_url":"https://api.github.com/users/MangelMaxime/repos","events_url":"https://api.github.com/users/MangelMaxime/events{/privacy}","received_events_url":"https://api.github.com/users/MangelMaxime/received_events","type":"User","site_admin":false},"created_at":"2016-09-23T18:39:19Z","updated_at":"2016-09-23T18:39:19Z","body":"Really nice work @whitetigle \r\n\r\nI wish to have more time next week to be able to work on some IMGUI code. But it's really impressive to see how the code is expressive from your sample :) Great work once again"}}
{"actor":{"display_login":"MangelMaxime"}}