{"id":781,"date":"2009-09-19T23:09:41","date_gmt":"2009-09-19T13:09:41","guid":{"rendered":"http:\/\/www.vectorstorm.org\/?p=781"},"modified":"2009-09-20T00:25:08","modified_gmt":"2009-09-19T14:25:08","slug":"you-werent-using-that-100mb-were-you","status":"publish","type":"post","link":"https:\/\/www.vectorstorm.com.au\/2009\/09\/19\/you-werent-using-that-100mb-were-you\/","title":{"rendered":"You weren’t using that 100MB, were you?"},"content":{"rendered":"
So I was grumbling to myself today about how tricky it is to be dealing with such a large world in MMORPG Tycoon 2; \u00a0since the world terrain is generated procedurally as you move around in the world, it means that data such as the height of the terrain simply isn’t stored anywhere for locations which aren’t currently near the camera.<\/p>\n
This can be a problem in many situations. \u00a0One example is when you have AI developers putting monsters into a quest zone. \u00a0The AI developers know approximately where the quest zone is, but if the camera isn’t actually near the quest zone, they have no way of knowing what the slope of the ground is, or precisely how high the ground might be. \u00a0Often, I’ve found that these quest areas end up having all their monsters placed down at sea level, with the terrain being twenty or thirty meters above there, so the monsters can never actually be reached by the players.<\/p>\n
As I was thinking about the problem, I worked out the maths and calculated that for the size world I’m talking about (20km x 20km), it would take nearly 100 megabytes of memory to store the terrain height, if I kept the whole world in memory at once. \u00a0My old-school programmer brain immediately told me that this was complete madness, and threw away the possibility of doing this, and I went back to designing complicated queued fetch-and-correct systems for placing objects when not all the required data was actually present in memory, and it wasn’t until almost ten minutes later that something in the back of my mind clicked, and realised that no, 100 megabytes isn’t very much any more. \u00a0So I did it.<\/p>\n
As a result, I’ve increased MMORPG Tycoon 2’s memory footprint from 256 megabytes of RAM to 384 megabytes of RAM to store this terrain data. \u00a0(To a programmer, those are nice round numbers; \u00a0256 is 2^8, and 384 is 2^8 + 2^7. \u00a0Aren’t those nice and round?)<\/p>\n
Anyhow. \u00a0I set the game up to procedurally generate the whole world’s terrain when it starts. \u00a0And on my (rather fast) computer, it takes between 70 and 90 seconds to do so. \u00a0Which is completely unacceptable to me, so I changed the system to generate-and-cache-upon-demand, which means that the first time you visit an area, it runs at about the same speed as it did before, but is substantially faster each time you revisit an area you’ve been to before. \u00a0This also solves the “no terrain data for areas which are far away from the camera” problem, solves lots and lots of different of bugs, and actually makes the terrain generation code much simpler overall. \u00a0I’m quite pleased with how it’s turned out. \u00a0And I could quite probably create a background thread to generate terrain data for areas you haven’t visited yet, while you’re working on other things.<\/p>\n
But it does now use an extra 128 megabytes of RAM. \u00a0This thing certainly won’t ever be running on the iPhone!<\/p>\n","protected":false},"excerpt":{"rendered":"
So I was grumbling to myself today about how tricky it is to be dealing with such a large world in MMORPG Tycoon 2; \u00a0since the world terrain is generated procedurally as you move around in the world, it means that data such as the height of the terrain simply isn’t stored anywhere for locations…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[24,25],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/po9WK-cB","_links":{"self":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/781"}],"collection":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/comments?post=781"}],"version-history":[{"count":0,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/781\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media?parent=781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/categories?post=781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/tags?post=781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}