diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9129b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mapgen2.swf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..827a7ef --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third-party/as3delaunay"] + path = third-party/as3delaunay + url = git://github.com/amitp/as3delaunay.git diff --git a/README.md b/README.md index d87e796..134b656 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ available. The [full process is described here](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/). -History: +History +------- * I started out with C++ code that used mountains, soil erosion, water flow, water erosion, water evaporation, volanoes, lava flow, and other physical processes to sculpt terrain expressed in a 2d array of tiles. However as described [in this blog post](http://simblob.blogspot.com/2010/06/teleological-vs-ontogenetic-map.html) I decided to abandon this approach. @@ -40,7 +41,20 @@ History: * The voronoi_set.as prototype worked well and I continued adding to it (instead of converting to C++). It supports terrain types: ocean, land, beach, lake, forest, swamp, desert, ice, rocky, grassland, savannah. It has rivers and roads. I decided not to convert it to C++ for now. Instead, I've refactored it into the core map generation (Map.as), display and GUI (mapgen2.as), graph representation (graph/*.as), decorative elements (Roads.as, Lava.as), and noisy edge generation (NoisyEdges.as). -** Requirements: +Requirements +------------ + +These third-party requirements have been added to the ``third-party`` directory: * [My fork of as3delaunay](http://github.com/amitp/as3delaunay) * The AS3 version of [de.polygonal.math.PM_PRNG.as](http://lab.polygonal.de/2007/04/21/a-good-pseudo-random-number-generator-prng/) + +Make sure you run ``git submodule update --init`` to check out the third-party libraries. + +Compiling +--------- + +To compile ``mapgen2.as`` to ``mapgen2.swf``, use the following command: + + mxmlc -source-path+=third-party/PM_PRNG -source-path+=third-party/as3delaunay/src mapgen2.as + diff --git a/third-party/PM_PRNG/de/polygonal/math/PM_PRNG.as b/third-party/PM_PRNG/de/polygonal/math/PM_PRNG.as new file mode 100644 index 0000000..d245410 --- /dev/null +++ b/third-party/PM_PRNG/de/polygonal/math/PM_PRNG.as @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2009 Michael Baczynski, http://www.polygonal.de + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Implementation of the Park Miller (1988) "minimal standard" linear + * congruential pseudo-random number generator. + * + * For a full explanation visit: http://www.firstpr.com.au/dsp/rand31/ + * + * The generator uses a modulus constant (m) of 2^31 - 1 which is a + * Mersenne Prime number and a full-period-multiplier of 16807. + * Output is a 31 bit unsigned integer. The range of values output is + * 1 to 2,147,483,646 (2^31-1) and the seed must be in this range too. + * + * David G. Carta's optimisation which needs only 32 bit integer math, + * and no division is actually *slower* in flash (both AS2 & AS3) so + * it's better to use the double-precision floating point version. + * + * @author Michael Baczynski, www.polygonal.de + */ +package de.polygonal.math +{ + public class PM_PRNG + { + /** + * set seed with a 31 bit unsigned integer + * between 1 and 0X7FFFFFFE inclusive. don't use 0! + */ + public var seed:uint; + + public function PM_PRNG() + { + seed = 1; + } + + /** + * provides the next pseudorandom number + * as an unsigned integer (31 bits) + */ + public function nextInt():uint + { + return gen(); + } + + /** + * provides the next pseudorandom number + * as a float between nearly 0 and nearly 1.0. + */ + public function nextDouble():Number + { + return (gen() / 2147483647); + } + + /** + * provides the next pseudorandom number + * as an unsigned integer (31 bits) betweeen + * a given range. + */ + public function nextIntRange(min:Number, max:Number):uint + { + min -= .4999; + max += .4999; + return Math.round(min + ((max - min) * nextDouble())); + } + + /** + * provides the next pseudorandom number + * as a float between a given range. + */ + public function nextDoubleRange(min:Number, max:Number):Number + { + return min + ((max - min) * nextDouble()); + } + + /** + * generator: + * new-value = (old-value * 16807) mod (2^31 - 1) + */ + private function gen():uint + { + //integer version 1, for max int 2^46 - 1 or larger. + return seed = (seed * 16807) % 2147483647; + + /** + * integer version 2, for max int 2^31 - 1 (slowest) + */ + //var test:int = 16807 * (seed % 127773 >> 0) - 2836 * (seed / 127773 >> 0); + //return seed = (test > 0 ? test : test + 2147483647); + + /** + * david g. carta's optimisation is 15% slower than integer version 1 + */ + //var hi:uint = 16807 * (seed >> 16); + //var lo:uint = 16807 * (seed & 0xFFFF) + ((hi & 0x7FFF) << 16) + (hi >> 15); + //return seed = (lo > 0x7FFFFFFF ? lo - 0x7FFFFFFF : lo); + } + } +} \ No newline at end of file diff --git a/third-party/as3delaunay b/third-party/as3delaunay new file mode 160000 index 0000000..0c2114d --- /dev/null +++ b/third-party/as3delaunay @@ -0,0 +1 @@ +Subproject commit 0c2114d805433aec93fec5c94ae429aba45300d8