![]() |
|
|
|||||||
| Programmer's Cubicle A place where some code snippets and other nerdy things will be posted for the general programmer community's benefit. Note that this is not a programming HELP forum. Posts not about the code here will be deleted or moved. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||||
|
||||||
|
Aragon Online has a very large World, 97 x 97 hexes, in which the game is played. Each hex can be zoomed to display the Region map, which is 25 x 25 hexes. In turn, each Region hex can be zoomed into to show the tactical map. There are 9,409 region maps, and 5,880,625 tactical maps. Each is unique.
So, how did we draw about 6 million maps? Well, we didn't. The World map was created with an editor program, but both the region and tactical maps are generated with a procedural method. Each is unique, and can be reliably generated at will for any hex, and will always be the same. (A "random" method wouldn't repeatable, in general, though there are ways of overcoming that.) Only a handful of maps are ever saved in the database. (If we saved every tactical map, we'd have a table containing 3,675,390,625 hexes, which would be a very huge data set!) The map generation routine uses the World hex characteristics to get the general contour of the map, then a Perlin Noise generator to fill-in the details. Note: Ken Perlin invented this algorithm in the 1980s, and won an Academy Award for his work advancing the state of the art of computer graphics: http://mrl.nyu.edu/~perlin/doc/oscar.html This algorithm is very widely used in computer graphics, and for many other applications, like this map system. Here is my PHP implementation of the "improved" Perlin Noise generation. PHP Code:
PHP Code:
__________________
Do not meddle in the affairs of wizards, for they are subtle and quick to anger. The Lord of the Rings Gildor, Chapter 'Three is Company'. Last edited by Merlin; 03-07-2010 at 07:28 PM. |
|
#2
|
||||||
|
||||||
|
Hey Merlin,
not to nitpick at code or anything but my years of experience with PHP has taught me to append string the output statement and instead of echos. I append the data to a output string var such as sOutputString for example and then just echo the output string at the end of the processing. Each echo acts as a function call, and function calls take more time than a simple append ie ( $sOutputString .= thisInfo ) This would improve your speeds when processing big areas, or even the little areas Telarion
__________________
Something Profound goes Here |
|
#3
|
||||||
|
||||||
|
Thanks for the tip - every little bit of speed helps.
That's probably unimportant in the test function, but I'll review other code and see where that can be improved. My older code, especially probably over uses echo. (I started this in 2003 as a PHP newb... Now I have a lot more experience using the language.)
__________________
Do not meddle in the affairs of wizards, for they are subtle and quick to anger. The Lord of the Rings Gildor, Chapter 'Three is Company'. |
|
#4
|
||||||
|
||||||
|
Oh I hear you on the overuse of certain functions.
I am still cleaning up code from when I was a php newb
__________________
Something Profound goes Here |
![]() |
| Bookmarks |
| Tags |
| code, noise, perlin, php, procedural map |
| Thread Tools | |
| Display Modes | |
|
|