{"id":2807,"date":"2013-03-11T22:14:09","date_gmt":"2013-03-11T12:14:09","guid":{"rendered":"http:\/\/www.vectorstorm.org\/?p=2807"},"modified":"2013-03-11T22:14:09","modified_gmt":"2013-03-11T12:14:09","slug":"development-lesson-for-the-day","status":"publish","type":"post","link":"https:\/\/www.vectorstorm.com.au\/2013\/03\/11\/development-lesson-for-the-day\/","title":{"rendered":"Development lesson for the day"},"content":{"rendered":"

\"Screen<\/a>Always know when to say “maybe somebody else has already solved this problem”.<\/p>\n

In today’s screenshot, you can see (some of) the individual building blocks of the MMORPG Tycoon 2 terrain.\u00a0 I don’t know whether they will be visible in the final version of the game, but I thought you might like to see them now.<\/p>\n

In essence, the MMORPG Tycoon 2 map is constructed from the cells of a Voronoi Diagram<\/a>, with each game “region” composed of a single Voronoi cell.\u00a0 Each of these regions is itself filled with more Voronoi cells, and these central cells become very important to the underlying structure of the game.<\/p>\n

For me, the “maybe somebody else has already solved this problem” probably should have been two years ago, when I first set up this system.\u00a0 I wrote all of this geometry code myself, and while most of it worked really well, there was one bit of which which didn’t;\u00a0 clipping the embedded Voronoi cells inside each region, to maintain the region boundaries.\u00a0 I struggled with that code for many days, trying to make it work reliably.<\/p>\n

Don’t get me wrong;\u00a0 the code mostly worked.\u00a0 It worked about 99.9% of the time.\u00a0 There were only a few really awkward situations which would cause it to fail.\u00a0 But as you can see from the screenshot, there are actually a lot of Voronoi cells in a map — even a small one, like this.\u00a0 My code would tend to fail about one time per five maps.\u00a0 I’ve spent many, many days trying to make the system work consistently, over the years.<\/p>\n

Then today, after spending almost another full day debugging the problem, I finally thought, “I bet someone else has already solved this problem”.\u00a0 Fifteen minutes later, the problem is solved, simply by adding some source from The Clipper Library<\/a>.\u00a0 It’s much more powerful than what I actually need, but it handles my simple clipping problem without breaking a sweat.\u00a0 Big kudos to its author!<\/p>\n

So for future reference:\u00a0 When stumped, particularly on something geometry or physics-based, go looking for a library.\u00a0 They can save a huge amount of your time, and get you back to working on the things that you’re actually good at working on.<\/p>\n","protected":false},"excerpt":{"rendered":"

Always know when to say “maybe somebody else has already solved this problem”. In today’s screenshot, you can see (some of) the individual building blocks of the MMORPG Tycoon 2 terrain.\u00a0 I don’t know whether they will be visible in the final version of the game, but I thought you might like to see them…<\/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,7,25],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/po9WK-Jh","_links":{"self":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/2807"}],"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=2807"}],"version-history":[{"count":1,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/2807\/revisions"}],"predecessor-version":[{"id":2809,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/2807\/revisions\/2809"}],"wp:attachment":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media?parent=2807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/categories?post=2807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/tags?post=2807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}