{"id":927,"date":"2015-09-06T13:15:05","date_gmt":"2015-09-06T17:15:05","guid":{"rendered":"http:\/\/www.bootdiskrevolution.com\/?p=927"},"modified":"2015-09-06T13:15:05","modified_gmt":"2015-09-06T17:15:05","slug":"optimization","status":"publish","type":"post","link":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/optimization\/","title":{"rendered":"Optimization"},"content":{"rendered":"<p style=\"text-align: center;\">The fifth level is finally finished!!<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-929\" src=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/0.jpg?resize=792%2C446\" alt=\"\" width=\"792\" height=\"446\" srcset=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/0.jpg?w=1024&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/0.jpg?resize=300%2C169&amp;ssl=1 300w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/p>\n<p>Man it feels good to have that one behind me. It only took five friggin&#8217; weeks to get it up to snuff. Once it was done, I celebrated by just playing MGS for a few days, because I&#8217;m a hopeless fanboy and I needed a break. But you&#8217;re not here to read about me playing MGS, so let&#8217;s talk a little about optimization.<\/p>\n<p>There&#8217;s one area of the fifth level that can have a loooot of baddies on screen &#8212; like, 100 at once if you let things get out of hand. Enemies don&#8217;t usually collide with each other, so normally it wouldn&#8217;t be worth mentioning, but these enemies get in each other&#8217;s way and so they all have to collision-detect each other, which can get ugly fast.<\/p>\n<p>If you didn&#8217;t read last week&#8217;s blog: it takes 4 calculations to see if two entities touch. If you add up the calculations of 100 entities checking each other, it&#8217;s something around 40,000 calculations (every 1\/60th of a second!) and that can really slow a machine down. That&#8217;s when optimization is needed!<\/p>\n<p><!--more--><\/p>\n<p>We&#8217;ve seen that in code, entities are rectangles &#8212; the four calculations compare the four sides against each other. But if you add another calculation before those &#8212; one that treats the entities as circles instead of squares &#8212; it cuts down the overall calculations immensely.<\/p>\n<figure id=\"attachment_930\" aria-describedby=\"caption-attachment-930\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-930 size-full\" src=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/1.jpg?resize=500%2C320\" alt=\"\" width=\"500\" height=\"320\" srcset=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/1.jpg?w=500&amp;ssl=1 500w, https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/1.jpg?resize=300%2C192&amp;ssl=1 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption id=\"caption-attachment-930\" class=\"wp-caption-text\">Creating a circle from an entity&#8217;s rectangular hitbox.<\/figcaption><\/figure>\n<p>It only takes 1 calculation to see if two circles touch (if the distance between two circles is greater than the sum of their radiuses, they aren&#8217;t touching.) This lets you decide if it&#8217;s even worth doing the other 4 calculations &#8212; if the entities&#8217; circles don&#8217;t touch, then their rectangles won&#8217;t either!<\/p>\n<figure id=\"attachment_928\" aria-describedby=\"caption-attachment-928\" style=\"width: 700px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-928 size-full\" src=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/2.jpg?resize=700%2C500\" alt=\"\" width=\"700\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/2.jpg?w=700&amp;ssl=1 700w, https:\/\/i0.wp.com\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-content\/uploads\/2015\/09\/2.jpg?resize=300%2C214&amp;ssl=1 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption id=\"caption-attachment-928\" class=\"wp-caption-text\">See? If the distance between the circles is greater than their added radiuses, there&#8217;s no way they touch.<\/figcaption><\/figure>\n<p>Worst case, the entities are touching, so you&#8217;ve made the computer do 5 calculations instead of 4. But in most cases it&#8217;s only had to do 1, and you&#8217;ve cut the work down to 1\/4th of what it used to be!<\/p>\n<p>There&#8217;s tons of other ways to optimize games, but I won&#8217;t get into them now. MGS ain&#8217;t gonna play itself! I promise lots of moving, colourful pictures next week. I pinky-swear.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The fifth level is finally finished!! Man it feels good to have that one behind me. It only took five friggin&#8217; weeks to get it up to snuff. Once it was done, I celebrated by just playing MGS for a few days, because I&#8217;m a hopeless fanboy and I needed a break. But you&#8217;re not <a class=\"read-more\" href=\"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/optimization\/\">[&hellip;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-927","post","type-post","status-publish","format-standard","hentry","category-bleed-2"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/posts\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":2,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/posts\/927\/revisions"}],"predecessor-version":[{"id":932,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/posts\/927\/revisions\/932"}],"wp:attachment":[{"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/media?parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/categories?post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bootdiskrevolution.com\/NEW_BLOG\/wp-json\/wp\/v2\/tags?post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}