Permalink
Browse files

Merge remote-tracking branch 'jterrace/master'

  • Loading branch information...
2 parents e64e345 + bedb3d3 commit 6a7d9afa035c7d5dd8e7edb407c0ab811b4394b3 @amitp committed May 2, 2012
Showing with 147 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 .gitmodules
  3. +16 −2 README.md
  4. +10 −10 mapgen2.as
  5. +116 −0 third-party/PM_PRNG/de/polygonal/math/PM_PRNG.as
  6. +1 −0 third-party/as3delaunay
View
@@ -0,0 +1 @@
+mapgen2.swf
View
@@ -0,0 +1,3 @@
+[submodule "third-party/as3delaunay"]
+ path = third-party/as3delaunay
+ url = git://github.com/amitp/as3delaunay.git
View
@@ -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:
* [as3delaunay](https://github.com/nodename/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
+
View
@@ -1013,13 +1013,13 @@ package {
accum.splice(0, accum.length);
for each (r in p.neighbors) {
- accum.push(<center id={r.index}/>.toString());
+ accum.push(<center id={r.index}/>.toXMLString());
}
for each (edge in p.borders) {
- accum.push(<edge id={edge.index}/>.toString());
+ accum.push(<edge id={edge.index}/>.toXMLString());
}
for each (q in p.corners) {
- accum.push(<corner id={q.index}/>.toString());
+ accum.push(<corner id={q.index}/>.toXMLString());
}
dnodes.push
@@ -1030,7 +1030,7 @@ package {
biome={p.biome}
elevation={p.elevation} moisture={p.moisture}>
<REPLACE/>
- </center>.toString().replace("<REPLACE/>", accum.join("")));
+ </center>.toXMLString().replace("<REPLACE/>", accum.join("")));
}
for each (edge in map.edges) {
@@ -1044,19 +1044,19 @@ package {
if (edge.d1 != null) edgeNode.@center1 = edge.d1.index;
if (edge.v0 != null) edgeNode.@corner0 = edge.v0.index;
if (edge.v1 != null) edgeNode.@corner1 = edge.v1.index;
- edges.push(edgeNode.toString());
+ edges.push(edgeNode.toXMLString());
}
for each (q in map.corners) {
accum.splice(0, accum.length);
for each (p in q.touches) {
- accum.push(<center id={p.index}/>.toString());
+ accum.push(<center id={p.index}/>.toXMLString());
}
for each (edge in q.protrudes) {
- accum.push(<edge id={edge.index}/>.toString());
+ accum.push(<edge id={edge.index}/>.toXMLString());
}
for each (s in q.adjacent) {
- accum.push(<corner id={s.index}/>.toString());
+ accum.push(<corner id={s.index}/>.toXMLString());
}
vnodes.push
@@ -1067,10 +1067,10 @@ package {
elevation={q.elevation} moisture={q.moisture}
river={q.river} downslope={q.downslope?q.downslope.index:-1}>
<REPLACE/>
- </corner>.toString().replace("<REPLACE/>", accum.join("")));
+ </corner>.toXMLString().replace("<REPLACE/>", accum.join("")));
}
- var out:String = top.toString();
+ var out:String = top.toXMLString();
accum = [].concat("<centers>",
dnodes, "</centers><edges>",
edges, "</edges><corners>",
@@ -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);
+ }
+ }
+}
Submodule as3delaunay added at 0c2114

0 comments on commit 6a7d9af

Please sign in to comment.