Thursday, 14 June 2007

The Great Magnification Commit

Yes, the Boundary magnification system at first glance and implementation seems to do the trick for generating very huge places to dwell with simple code like this:

World w = new World("world", null); w.setBoundaries(BoundaryUtils.createCubicBoundaries(1000, 1, 1, 1, 0, 0, 0));
Plain p = new Plain("2",null);
p.setBoundaries( BoundaryUtils.createCubicBoundaries (100, 1, 1, 1, 0, 0, 0));
w.geographies.put(, p);

Every place in general may have subplaces, call it smaller regions in it. This code will create an 1000x1000x1000 in game cube world in a single world cube, and in it a 100x100x100 in game cube grass Plain in a single Plain geography place cube. The Plain will take care of how it's in game cubes will look alike based on it's own algorithms or if the Plain will be divided into more subplaces with lesser magnification, those places will take care of a bigger and exact detail. How a plain have some trees on it? It can be pure mathematical with this concept, instead of designing every cube in a designer tool! Look at these codes:

The magnification trick in Boundaries is to divide real world coordinates with a Place's magnification level:

public boolean isInside(int absouluteX, int absoluteY, int absoluteZ) {
boolean ret = area.get(getKey(absouluteX/magnification, absoluteY/
magnification, absoluteZ/magnification))!=null;
return ret;

And the Plain returns a Cube based on real world coordinates:

public Cube getCube(int worldX, int worldY, int worldZ) {
return new Cube(this, Cube.DEFAULT_LEVEL,worldY==0?(worldX%10==0 && worldZ%10==0?TREE:GRASS): EMPTY,worldX,worldY,worldZ);

In real life imagine the concept like there are places that more or less look the same without interesting details, but they may contain specific places with interesting details. Like a barren plain and a house in it. The plain will be of magnification level 100, while the House will be of magnification level 1 -- "place cube" = "in-game cube".

No comments: