{"action":"created","comment":{"url":"https://api.github.com/repos/JoelOtter/termloop/pulls/comments/43126118","id":43126118,"diff_hunk":"@@ -99,9 +103,8 @@ mainloop:\n \t\tdefault:\n \t\t\tg.screen.Tick(Event{Type: EventNone})\n \t\t}\n-\t\tupdate := time.Now()\n-\t\tg.screen.delta = update.Sub(clock).Seconds()\n-\t\tclock = update\n+\n \t\tg.screen.Draw()\n+\t\ttime.Sleep(time.Duration((update.Sub(time.Now()).Seconds()*1000.0)+1000.0/g.screen.fps) * time.Millisecond)","path":"game.go","position":20,"original_position":20,"commit_id":"45fd8dfcb668456ae007167330e823d30886579f","original_commit_id":"45fd8dfcb668456ae007167330e823d30886579f","user":{"login":"JoelOtter","id":2765356,"avatar_url":"https://avatars.githubusercontent.com/u/2765356?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelOtter","html_url":"https://github.com/JoelOtter","followers_url":"https://api.github.com/users/JoelOtter/followers","following_url":"https://api.github.com/users/JoelOtter/following{/other_user}","gists_url":"https://api.github.com/users/JoelOtter/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelOtter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelOtter/subscriptions","organizations_url":"https://api.github.com/users/JoelOtter/orgs","repos_url":"https://api.github.com/users/JoelOtter/repos","events_url":"https://api.github.com/users/JoelOtter/events{/privacy}","received_events_url":"https://api.github.com/users/JoelOtter/received_events","type":"User","site_admin":false},"body":"Won't this line result in a divide-by-zero error, by default?","created_at":"2015-10-27T14:14:24Z","updated_at":"2015-10-27T14:14:24Z","html_url":"https://github.com/JoelOtter/termloop/pull/20#discussion_r43126118","pull_request_url":"https://api.github.com/repos/JoelOtter/termloop/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/comments/43126118"},"html":{"href":"https://github.com/JoelOtter/termloop/pull/20#discussion_r43126118"},"pull_request":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/JoelOtter/termloop/pulls/20","id":48400942,"html_url":"https://github.com/JoelOtter/termloop/pull/20","diff_url":"https://github.com/JoelOtter/termloop/pull/20.diff","patch_url":"https://github.com/JoelOtter/termloop/pull/20.patch","issue_url":"https://api.github.com/repos/JoelOtter/termloop/issues/20","number":20,"state":"open","locked":false,"title":"Allow user to set FPS","user":{"login":"jodizzle","id":672268,"avatar_url":"https://avatars.githubusercontent.com/u/672268?v=3","gravatar_id":"","url":"https://api.github.com/users/jodizzle","html_url":"https://github.com/jodizzle","followers_url":"https://api.github.com/users/jodizzle/followers","following_url":"https://api.github.com/users/jodizzle/following{/other_user}","gists_url":"https://api.github.com/users/jodizzle/gists{/gist_id}","starred_url":"https://api.github.com/users/jodizzle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodizzle/subscriptions","organizations_url":"https://api.github.com/users/jodizzle/orgs","repos_url":"https://api.github.com/users/jodizzle/repos","events_url":"https://api.github.com/users/jodizzle/events{/privacy}","received_events_url":"https://api.github.com/users/jodizzle/received_events","type":"User","site_admin":false},"body":"As discussed on Gitter and in accordance with #18, these changes make it possible to set a relative cap on the frames per second of a screen.  For example, running \r\n```Go\r\ng := termloop.NewGame()\r\ng.Screen().SetFps(60)\r\n```\r\nwould handle input and draw to the screen at a rate of no more than around 60 FPS.  This is done through a simple sleep command, as per http://gameprogrammingpatterns.com/game-loop.html#take-a-little-nap.  By default (or by running ```SetFps(0)```) no FPS is set.  I've also edited ```_examples/collision.go``` as a further example of ```screen.SetFps``` in action.\r\n\r\nThe main motivation for setting the FPS is to reduce the impact on system resources; running termloop with the mainloop executing as fast as possible can result in high CPU usage, for instance.  Establishing a reasonable limit can greatly improve performance without much or any impact on gameplay.\r\n\r\nSince the current approach is fairly basic, there's still room for improvement.  Updating a game based on ```screen.TimeDelta()``` should still function properly, though the FpsText utility seems to be a bit buggy.  Also (and possibly related to the FpsText bugginess), a simple sleep doesn't prevent the game from running *slower* than the set FPS, but that's less critical to the use case as of right now.","created_at":"2015-10-21T23:22:51Z","updated_at":"2015-10-27T14:14:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2bb6918ae6ede12c73fd1f86507c7917c301f976","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JoelOtter/termloop/pulls/20/commits","review_comments_url":"https://api.github.com/repos/JoelOtter/termloop/pulls/20/comments","review_comment_url":"https://api.github.com/repos/JoelOtter/termloop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JoelOtter/termloop/issues/20/comments","statuses_url":"https://api.github.com/repos/JoelOtter/termloop/statuses/45fd8dfcb668456ae007167330e823d30886579f","head":{"label":"jodizzle:develop/fps","ref":"develop/fps","sha":"45fd8dfcb668456ae007167330e823d30886579f","user":{"login":"jodizzle","id":672268,"avatar_url":"https://avatars.githubusercontent.com/u/672268?v=3","gravatar_id":"","url":"https://api.github.com/users/jodizzle","html_url":"https://github.com/jodizzle","followers_url":"https://api.github.com/users/jodizzle/followers","following_url":"https://api.github.com/users/jodizzle/following{/other_user}","gists_url":"https://api.github.com/users/jodizzle/gists{/gist_id}","starred_url":"https://api.github.com/users/jodizzle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodizzle/subscriptions","organizations_url":"https://api.github.com/users/jodizzle/orgs","repos_url":"https://api.github.com/users/jodizzle/repos","events_url":"https://api.github.com/users/jodizzle/events{/privacy}","received_events_url":"https://api.github.com/users/jodizzle/received_events","type":"User","site_admin":false},"repo":{"id":43628649,"name":"termloop","full_name":"jodizzle/termloop","owner":{"login":"jodizzle","id":672268,"avatar_url":"https://avatars.githubusercontent.com/u/672268?v=3","gravatar_id":"","url":"https://api.github.com/users/jodizzle","html_url":"https://github.com/jodizzle","followers_url":"https://api.github.com/users/jodizzle/followers","following_url":"https://api.github.com/users/jodizzle/following{/other_user}","gists_url":"https://api.github.com/users/jodizzle/gists{/gist_id}","starred_url":"https://api.github.com/users/jodizzle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodizzle/subscriptions","organizations_url":"https://api.github.com/users/jodizzle/orgs","repos_url":"https://api.github.com/users/jodizzle/repos","events_url":"https://api.github.com/users/jodizzle/events{/privacy}","received_events_url":"https://api.github.com/users/jodizzle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jodizzle/termloop","description":"Terminal-based game engine for Go, built on top of Termbox","fork":true,"url":"https://api.github.com/repos/jodizzle/termloop","forks_url":"https://api.github.com/repos/jodizzle/termloop/forks","keys_url":"https://api.github.com/repos/jodizzle/termloop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jodizzle/termloop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jodizzle/termloop/teams","hooks_url":"https://api.github.com/repos/jodizzle/termloop/hooks","issue_events_url":"https://api.github.com/repos/jodizzle/termloop/issues/events{/number}","events_url":"https://api.github.com/repos/jodizzle/termloop/events","assignees_url":"https://api.github.com/repos/jodizzle/termloop/assignees{/user}","branches_url":"https://api.github.com/repos/jodizzle/termloop/branches{/branch}","tags_url":"https://api.github.com/repos/jodizzle/termloop/tags","blobs_url":"https://api.github.com/repos/jodizzle/termloop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jodizzle/termloop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jodizzle/termloop/git/refs{/sha}","trees_url":"https://api.github.com/repos/jodizzle/termloop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jodizzle/termloop/statuses/{sha}","languages_url":"https://api.github.com/repos/jodizzle/termloop/languages","stargazers_url":"https://api.github.com/repos/jodizzle/termloop/stargazers","contributors_url":"https://api.github.com/repos/jodizzle/termloop/contributors","subscribers_url":"https://api.github.com/repos/jodizzle/termloop/subscribers","subscription_url":"https://api.github.com/repos/jodizzle/termloop/subscription","commits_url":"https://api.github.com/repos/jodizzle/termloop/commits{/sha}","git_commits_url":"https://api.github.com/repos/jodizzle/termloop/git/commits{/sha}","comments_url":"https://api.github.com/repos/jodizzle/termloop/comments{/number}","issue_comment_url":"https://api.github.com/repos/jodizzle/termloop/issues/comments{/number}","contents_url":"https://api.github.com/repos/jodizzle/termloop/contents/{+path}","compare_url":"https://api.github.com/repos/jodizzle/termloop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jodizzle/termloop/merges","archive_url":"https://api.github.com/repos/jodizzle/termloop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jodizzle/termloop/downloads","issues_url":"https://api.github.com/repos/jodizzle/termloop/issues{/number}","pulls_url":"https://api.github.com/repos/jodizzle/termloop/pulls{/number}","milestones_url":"https://api.github.com/repos/jodizzle/termloop/milestones{/number}","notifications_url":"https://api.github.com/repos/jodizzle/termloop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jodizzle/termloop/labels{/name}","releases_url":"https://api.github.com/repos/jodizzle/termloop/releases{/id}","created_at":"2015-10-04T07:31:51Z","updated_at":"2015-10-04T07:31:52Z","pushed_at":"2015-10-22T03:29:14Z","git_url":"git://github.com/jodizzle/termloop.git","ssh_url":"git@github.com:jodizzle/termloop.git","clone_url":"https://github.com/jodizzle/termloop.git","svn_url":"https://github.com/jodizzle/termloop","homepage":null,"size":443,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JoelOtter:master","ref":"master","sha":"890ec1ebd22faa60f6f3e2d17ad007a79c5b6288","user":{"login":"JoelOtter","id":2765356,"avatar_url":"https://avatars.githubusercontent.com/u/2765356?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelOtter","html_url":"https://github.com/JoelOtter","followers_url":"https://api.github.com/users/JoelOtter/followers","following_url":"https://api.github.com/users/JoelOtter/following{/other_user}","gists_url":"https://api.github.com/users/JoelOtter/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelOtter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelOtter/subscriptions","organizations_url":"https://api.github.com/users/JoelOtter/orgs","repos_url":"https://api.github.com/users/JoelOtter/repos","events_url":"https://api.github.com/users/JoelOtter/events{/privacy}","received_events_url":"https://api.github.com/users/JoelOtter/received_events","type":"User","site_admin":false},"repo":{"id":36133658,"name":"termloop","full_name":"JoelOtter/termloop","owner":{"login":"JoelOtter","id":2765356,"avatar_url":"https://avatars.githubusercontent.com/u/2765356?v=3","gravatar_id":"","url":"https://api.github.com/users/JoelOtter","html_url":"https://github.com/JoelOtter","followers_url":"https://api.github.com/users/JoelOtter/followers","following_url":"https://api.github.com/users/JoelOtter/following{/other_user}","gists_url":"https://api.github.com/users/JoelOtter/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelOtter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelOtter/subscriptions","organizations_url":"https://api.github.com/users/JoelOtter/orgs","repos_url":"https://api.github.com/users/JoelOtter/repos","events_url":"https://api.github.com/users/JoelOtter/events{/privacy}","received_events_url":"https://api.github.com/users/JoelOtter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JoelOtter/termloop","description":"Terminal-based game engine for Go, built on top of Termbox","fork":false,"url":"https://api.github.com/repos/JoelOtter/termloop","forks_url":"https://api.github.com/repos/JoelOtter/termloop/forks","keys_url":"https://api.github.com/repos/JoelOtter/termloop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JoelOtter/termloop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JoelOtter/termloop/teams","hooks_url":"https://api.github.com/repos/JoelOtter/termloop/hooks","issue_events_url":"https://api.github.com/repos/JoelOtter/termloop/issues/events{/number}","events_url":"https://api.github.com/repos/JoelOtter/termloop/events","assignees_url":"https://api.github.com/repos/JoelOtter/termloop/assignees{/user}","branches_url":"https://api.github.com/repos/JoelOtter/termloop/branches{/branch}","tags_url":"https://api.github.com/repos/JoelOtter/termloop/tags","blobs_url":"https://api.github.com/repos/JoelOtter/termloop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JoelOtter/termloop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JoelOtter/termloop/git/refs{/sha}","trees_url":"https://api.github.com/repos/JoelOtter/termloop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JoelOtter/termloop/statuses/{sha}","languages_url":"https://api.github.com/repos/JoelOtter/termloop/languages","stargazers_url":"https://api.github.com/repos/JoelOtter/termloop/stargazers","contributors_url":"https://api.github.com/repos/JoelOtter/termloop/contributors","subscribers_url":"https://api.github.com/repos/JoelOtter/termloop/subscribers","subscription_url":"https://api.github.com/repos/JoelOtter/termloop/subscription","commits_url":"https://api.github.com/repos/JoelOtter/termloop/commits{/sha}","git_commits_url":"https://api.github.com/repos/JoelOtter/termloop/git/commits{/sha}","comments_url":"https://api.github.com/repos/JoelOtter/termloop/comments{/number}","issue_comment_url":"https://api.github.com/repos/JoelOtter/termloop/issues/comments{/number}","contents_url":"https://api.github.com/repos/JoelOtter/termloop/contents/{+path}","compare_url":"https://api.github.com/repos/JoelOtter/termloop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JoelOtter/termloop/merges","archive_url":"https://api.github.com/repos/JoelOtter/termloop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JoelOtter/termloop/downloads","issues_url":"https://api.github.com/repos/JoelOtter/termloop/issues{/number}","pulls_url":"https://api.github.com/repos/JoelOtter/termloop/pulls{/number}","milestones_url":"https://api.github.com/repos/JoelOtter/termloop/milestones{/number}","notifications_url":"https://api.github.com/repos/JoelOtter/termloop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JoelOtter/termloop/labels{/name}","releases_url":"https://api.github.com/repos/JoelOtter/termloop/releases{/id}","created_at":"2015-05-23T17:12:34Z","updated_at":"2015-10-27T02:26:30Z","pushed_at":"2015-10-22T03:29:15Z","git_url":"git://github.com/JoelOtter/termloop.git","ssh_url":"git@github.com:JoelOtter/termloop.git","clone_url":"https://github.com/JoelOtter/termloop.git","svn_url":"https://github.com/JoelOtter/termloop","homepage":null,"size":749,"stargazers_count":540,"watchers_count":540,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":2,"forks":26,"open_issues":2,"watchers":540,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/20"},"html":{"href":"https://github.com/JoelOtter/termloop/pull/20"},"issue":{"href":"https://api.github.com/repos/JoelOtter/termloop/issues/20"},"comments":{"href":"https://api.github.com/repos/JoelOtter/termloop/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JoelOtter/termloop/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/JoelOtter/termloop/statuses/45fd8dfcb668456ae007167330e823d30886579f"}}}}