{"id":2251,"date":"2015-03-12T21:42:00","date_gmt":"2015-03-12T21:42:00","guid":{"rendered":"http:\/\/www.spellcasterstudios.com\/?p=2251"},"modified":"2015-03-06T21:53:48","modified_gmt":"2015-03-06T21:53:48","slug":"optimization-failed","status":"publish","type":"post","link":"https:\/\/www.spellcasterstudios.com\/?p=2251","title":{"rendered":"Optimization: failed!"},"content":{"rendered":"<p align=\"justify\">Today I spent my evening trying to optimize the map generation (when the player lands on a planet) and the area generation (when the player changes areas).<\/p>\n<p align=\"justify\">The map generation takes about 15 seconds on a normal map (this can be a bit more or less, but this is a good average), which is very long. The problem is that most of this time is unavoidable\u2026<\/p>\n<p align=\"justify\">Doing some profiling on it yielded the following results:<\/p>\n<p align=\"justify\">T(setup)=5 ms   <br \/>T(base_generation)=373 ms    <br \/>T(blurring)=1566 ms    <br \/>T(normalize_heights)=18 ms    <br \/>T(rock_spawns_normal)=3 ms    <br \/>T(caves)=0 ms    <br \/>T(water)=11224 ms    <br \/>T(trees)=8 ms    <br \/>T(process_heightmap)=921 ms    <br \/>T(special_process)=0 ms    <br \/>T(pirate_lairs)=0 ms    <br \/>T(temples)=0 ms    <br \/>T(camps)=0 ms    <br \/>Total(build_heightmap)=14121 ms    <\/p>\n<p align=\"justify\">As you can see, most of the time is generating the water courses, and that part is already quite optimized\u2026 It\u2019s something that takes time to do well\u2026 Reducing that time would have a significant impact on the rivers and lakes\u2026 I might be able to do something more on the pathfinder I use to create the river, but I don\u2019t believe I\u2019ll be able to get that time down much\u2026<\/p>\n<p align=\"justify\">Then we have the area generation\u2026 This one takes currently about 600 ms on average, 95% of it in generating the navigation mesh, and I already squeezed that one as much as I can (most of the code belongs to Recast, the library I use for navigation mesh generation).<\/p>\n<p align=\"justify\">So I have about 200 ms shaved on the map generation to show for my efforts tonight, which is kind of sucky\u2026<\/p>\n<p align=\"justify\">I think I\u2019ll be able to multithread the map generation, so the player won\u2019t be waiting 15 seconds do be able to land on a planet\u2026 I\u2019ve already separated the code with that in mind, so except for some sync points where I create the flow map texture, I should be able to run it in a separate thread that gets launched as soon as the player goes into hyperspace to a new planet\u2026 Between the hyperspace travel, and running to the lander, that\u2019s at least 10 seconds of time I can hide, and the rest I can hide on a \u201cin the atmosphere\u201d cutscene.<\/p>\n<p align=\"justify\">Next step in the polish is to grab the lava worlds and see what can be done there with the water algorithm, glows and maybe some fire jets on the lava pools\u2026 A \u201cfire snow\u201d like effect to simulate ash in the atmosphere might be also interesting.<\/p>\n<p align=\"justify\">I\u2019m also guessing I\u2019ll find some bugs (I always do when I revisit planets), and this is one of the planets where a new camera algorithm\/occlusion handling would be useful, so I expect about a week of fun\u2026 <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-disappointedsmile\" style=\"border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none\" alt=\"Disappointed smile\" src=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/03\/wlEmoticon-disappointedsmile.png\" \/><\/p>\n<p align=\"justify\"><em>Now listening to \u201cViva Hades\u201d by \u201cMono Inc.\u201d<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I spent my evening trying to optimize the map generation (when the player lands on a planet) and the area generation (when the player changes areas). The map generation takes about 15 seconds on a normal map (this can be a bit more or less, but this is a good average), which is very [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,147,8],"tags":[97],"class_list":["post-2251","post","type-post","status-publish","format-standard","hentry","category-development","category-chrome-hunter","category-technology","tag-optimization"],"_links":{"self":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2251"}],"version-history":[{"count":1,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2251\/revisions"}],"predecessor-version":[{"id":2252,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2251\/revisions\/2252"}],"wp:attachment":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}