{"id":1128,"date":"2011-04-11T14:43:19","date_gmt":"2011-04-11T13:43:19","guid":{"rendered":"http:\/\/positech.co.uk\/cliffsblog\/?p=1128"},"modified":"2011-04-10T14:50:42","modified_gmt":"2011-04-10T13:50:42","slug":"work-for-idle-hands","status":"publish","type":"post","link":"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/04\/11\/work-for-idle-hands\/","title":{"rendered":"Work For Idle Hands"},"content":{"rendered":"<p>One thing GSB does that I&#8217;m quite proud of, is run an &#8216;idle manager&#8217; to smooth out the frame rate. In concept, it&#8217;s pretty simple. There are some jobs that need doing in the near future, but not *NOW*, and some that are optional. The idle manager works out that we have some spare time, and does them accordingly. In code terms it&#8217;s a lot more involved.<\/p>\n<p>GSB has a target frame rate, and checks the time since last frame in the main game loop. If there is some &#8216;spare&#8217; time before the next frame, it tells the idlemanager, and checks again once the idlemanager has finished. The idle manager has a list of tasks, and it cycles through them in turn. Two of the common tasks are these:<\/p>\n<p>1) Check that we aren&#8217;t running low on any pre-cached particle effects, and if we are, pre-cache some new ones ready for future use<\/p>\n<p>2) Check if any laser blasts which are missing their target happen to intersect with some debris. If they do, make the debris explode.<\/p>\n<p>task 1) is vital for performance, task 2) is optional graphical fluff.<\/p>\n<p>The implementation of an idle manager is cool because it allows you to use the fluctuating rendering-demands per frame to your advantage. It also means you eek as much usage as possible out of a single processor core. In multi-core, multi-threaded systems, this is all done much better by having a separate thread, which can spin off and do this stuff at your leisure. There can be synchronisation issues in that case though (I don&#8217;t want to change the list of cached particles while another thread is altering them too etc).<\/p>\n<p>If you can&#8217;t be bothered with the hassle of multithreading, I recommend implementing something like this idle manager at the very least, assuming performance is vaguely an issue for you. I&#8217;m writing the idle code for my new game right now, and it will be a bit cleverer, and more involevd and possibly multithread stuff too. I hate to think the game would drop a frame when it could be avoided by doing this sort of stuff.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One thing GSB does that I&#8217;m quite proud of, is run an &#8216;idle manager&#8217; to smooth out the frame rate. In concept, it&#8217;s pretty simple. There are some jobs that need doing in the near future, but not *NOW*, and some that are optional. The idle manager works out that we have some spare time,<\/p>\n<p class=\"text-right\"><span class=\"screen-reader-text\">Continue Reading&#8230; Work For Idle Hands<\/span><a class=\"btn btn-secondary continue-reading\" href=\"https:\/\/www.positech.co.uk\/cliffsblog\/2011\/04\/11\/work-for-idle-hands\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,4],"tags":[],"class_list":["post-1128","post","type-post","status-publish","format-standard","hentry","category-gratuitous-space-battles","category-programming"],"_links":{"self":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/comments?post=1128"}],"version-history":[{"count":2,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1128\/revisions"}],"predecessor-version":[{"id":1131,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/1128\/revisions\/1131"}],"wp:attachment":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/media?parent=1128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/categories?post=1128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/tags?post=1128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}