Skip to content

Commit a882092

Browse files
committed
- initial import
0 parents  commit a882092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7287
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.cproject
2+
.project
3+
.settings
4+
5+
*.o
6+
gmon.out

COPYING

+674
Large diffs are not rendered by default.

README

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# mapcrafter #
2+
3+
mapcrafter is a fast minecraft world renderer written in C++. It renders minecraft
4+
worlds to a bunch of images which are viewable in any webbrowser using the Google Maps API.
5+
6+
mapcrafter runs on linux (maybe also Mac OS or w****** with cygwin) and needs libpng,
7+
libpthread, libboost-iostreams,libboost-system, libboost-filesystem, and
8+
libboost-program-options (and libboost-test if you want to use the tests).
9+
You can build it with g++ and the supplied makefile.
10+
11+
mapcrafter is not yet finished. At the moment not all blocks are supported, but the
12+
basic rendering routines (also incremental rendering, multithreading) are implemented.
13+
The renderer works with the 'new' minecraft anvil worlds.
14+
15+
mapcrafter is free software and available under the GPL license.
16+
You can access the latest source of mapcrafter at: http://github.com/...
17+
18+
Please feel free to report bugs and errors you find when using mapcrafter.
19+
20+
Thanks to pigmap and Minecraft Overviewer, whose documentations and source code were
21+
very helpful.
22+
23+
## How to use the renderer ##
24+
25+
Here is a list of available command line options:
26+
27+
-h [--help]
28+
29+
This shows a help about the command line options.
30+
31+
-i [--input-dir=] (directory)
32+
33+
This is the directory of the minecraft world to render. The directory should contain a
34+
directory 'region' with the *.mca region files.
35+
36+
37+
-o [--output-dir=] (directory)
38+
39+
This is the directory, where mapcrafter saves the rendered map. Every time you render your
40+
map, the renderer copies the template files into this directory and overwrites them, if
41+
they already exist. The renderer creates an 'index.html' file you can open with your
42+
webbrowser. If you want to customize this html file, you should do this directly in the
43+
template (see data dir).
44+
45+
-d [--data-dir=] (directory)
46+
47+
This is the directory with a template directory and the minecraft images needed for the
48+
rendering.
49+
50+
You need here the terrain.png, chest.png, enderchest.png and largechest.png (probably
51+
from your minecraft.jar). You can use the python script in the data directory to extract
52+
the images from your minecraft.jar.
53+
54+
The web templates are stored inside the data directory in the directory 'template'. You
55+
can make a copy of the data directory and customize the templates.
56+
57+
-j [--jobs=] (number)
58+
59+
This is the count of threads to use (default 1), when rendering the highest zoom level
60+
tiles (the tiles which are directly rendered from the world data). The rendering
61+
performance also depends heavily on your disk. You can render the map to a solid state
62+
disk or a ramdisk to improve the performance.
63+
64+
At the moment the other tiles (composite tiles), which are composed of the top level
65+
tiles and other composite tiles, are rendered by a single thread.
66+
67+
-u [--incremental]
68+
69+
When you specify this, the renderer checks, which chunks were changed since the last
70+
rendering of the world. It calculates then the tiles, which need to get rendered. You can
71+
use this, if you already rendered your map completely. Incremental rendering is much
72+
faster than a full rendering, if there are only a few changes in your minecraft world.
73+
74+
75+
76+
**Here are some settings you can only specifiy, if you do a full rendering. In case of
77+
incremental rendering, the renderer reads this settings from the file 'map.settings' in
78+
the output directory.**
79+
80+
81+
--texture-size=(a number)
82+
83+
This is the size (in pixels) of the block textures. The default texture
84+
size is 12px (16px is the size of the default minecraft textures). The size (width and
85+
height) of your terrain.png must be a multiple of 16 and width and height must be equal.
86+
87+
The size of a tile is 32*texturesize, so the higher the texture size, the more image data
88+
the renderer has to process. If you want a high detail, use texture size 16, but texture
89+
size 12 looks still good and is faster to render.
90+
91+
--render-unknown-blocks
92+
93+
With this setting the renderer renders unknown blocks as red blocks (for debugging
94+
purposes). Per default the renderer just ignores unknown blocks and doesn't render them.
95+
96+
--render-leaves-transparent
97+
98+
You can specifiy this to use the transparent leaves textures instead of the opaque
99+
textures. This option can make the renderer a bit slower, because the renderer has to scan
100+
the blocks after the leaves to the ground also.
101+
102+
## Version history ##
103+
104+
**v.0.1 (December 2012)**
105+
106+
* first version on github, features:
107+
* rendering minecraft worlds to tiles and an html file to view them like a Google Map
108+
* incremental rendering, multithreading

TODO

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Important things:
2+
- add all blocks
3+
- better documentation
4+
5+
Blocks:
6+
# - a lot of blocks (grass, torches, transparent leaves,...) have some transparency on
7+
# their edges after resizing, could be a performance problem
8+
# - maybe use simple nearest neighbor resizing for transparent blocks
9+
- fix east ascending stairs texture bug
10+
11+
Other things:
12+
- performance and ram improvements are always good
13+
- composite tile rendering also multithreaded
14+
- biome depend grass/leaves/water color?
15+
- maybe more rendermodes?

src/Makefile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CXX=g++
2+
CXXFLAGS=-std=c++0x -Werror
3+
4+
ifeq ($(mode),debug)
5+
CXXFLAGS+= -g
6+
else ifeq ($(mode),profile)
7+
CXXFLAGS+= -O3
8+
else
9+
CXXFLAGS+= -O3
10+
endif
11+
12+
LDFLAGS=-lpng -pthread -lboost_iostreams -lboost_system -lboost_filesystem -lboost_program_options
13+
14+
OBJECTS=util.o $(addprefix mc/, cache.o chunk.o nbt.o pos.o region.o world.o) $(addprefix render/, image.o manager.o render.o textures.o tile.o)
15+
TEST_OBJECTS=$(addprefix test/, test_image.o test_nbt.o test_pos.o test_tile.o)
16+
17+
all: $(OBJECTS) mapcrafter testtextures #test
18+
clean:
19+
rm -rf mapcrafter mapcrafter.o testtextures testtextures.o $(OBJECTS)
20+
21+
mapcrafter: mapcrafter.o $(OBJECTS)
22+
$(CXX) $(CXXFLAGS) -o mapcrafter mapcrafter.o $(OBJECTS) $(LDFLAGS)
23+
testtextures: testtextures.o $(OBJECTS)
24+
$(CXX) $(CXXFLAGS) -o testtextures testtextures.o $(OBJECTS) $(LDFLAGS)
25+
26+
test: test/test_all.cpp $(TEST_OBJECTS) $(OBJECTS)
27+
$(CXX) $(CXXFLAGS) -o test/test_all -I. test/test_all.cpp $(TEST_OBJECTS) $(OBJECTS) $(LDFLAGS) -lboost_unit_test_framework
28+
29+
runtest: test
30+
cd test && ./test_all --log_level=test_suite
31+
32+
%.o: %.cpp
33+
$(CXX) $(CXXFLAGS) -I. -c $< -o $@
34+
35+
mc/cache.o: mc/cache.cpp mc/pos.h mc/chunk.h mc/region.h mc/world.h
36+
mc/chunk.o: mc/chunk.cpp mc/nbt.h mc/pos.h
37+
mc/nbt.o: mc/nbt.cpp
38+
mc/pos.o: mc/pos.cpp
39+
mc/region.o: mc/region.cpp mc/pos.h mc/chunk.h
40+
mc/world.o: mc/world.cpp mc/pos.h mc/chunk.h mc/region.h
41+
42+
render/image.o: render/image.cpp
43+
render/manager.o: mc/cache.h mc/pos.h mc/chunk.h mc/region.h mc/world.h render/render.h
44+
render/render.o: render/render.cpp mc/pos.h mc/cache.h render/textures.h render/tile.h
45+
render/textures.o: render/image.o
46+
render/tile.o: render/tile.cpp mc/pos.h mc/chunk.h mc/cache.h
47+
48+
test/test_image.o: render/image.h
49+
test/test_nbt.o: mc/nbt.h
50+
test/test_pos.o: mc/pos.h
51+
test/test_tile.o: render/tile.h

src/data/endportal.png

335 Bytes
Loading

src/data/find_images.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import os
5+
import zipfile
6+
7+
files = {
8+
"terrain.png" : "terrain.png",
9+
"chest.png" : "item/chest.png",
10+
"enderchest.png" : "item/enderchest.png",
11+
"largechest.png" : "item/largechest.png",
12+
}
13+
14+
if __name__ == "__main__":
15+
if len(sys.argv) < 2:
16+
print "Usage: ./find_images.py [-f] <minecraft.jar>"
17+
sys.exit(1)
18+
19+
force = False
20+
path = sys.argv[1]
21+
if len(sys.argv) >= 3:
22+
force = sys.argv[1] == "-f"
23+
path = sys.argv[2]
24+
25+
jar = zipfile.ZipFile(path)
26+
27+
for filename, path in files.items():
28+
try:
29+
info = jar.getinfo(path)
30+
print filename, "found...",
31+
if os.path.exists(filename) and not force:
32+
print "skipping because it already exists (use -f to force)"
33+
else:
34+
fin = jar.open(info)
35+
fout = open(filename, "w")
36+
fout.write(fin.read())
37+
fin.close()
38+
fout.close()
39+
print "ok"
40+
except KeyError:
41+
print filename, "not found!"
42+
continue

src/data/fire.png

595 Bytes
Loading

src/data/template/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Minecraft Map</title>
5+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
6+
<link rel="stylesheet" type="text/css" href="style.css" />
7+
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
8+
<script type="text/javascript" src="markers.js"></script>
9+
<script type="text/javascript">
10+
var MapConfig = {
11+
textureSize: {textureSize},
12+
tileSize: {tileSize},
13+
14+
minZoom: 0,
15+
defaultZoom: 0,
16+
maxZoom: {maxZoom}
17+
};
18+
</script>
19+
<script type="text/javascript" src="map.js"></script>
20+
</head>
21+
<body onload="init()">
22+
<div id="mcmap"></div>
23+
</body>
24+
</html>

src/data/template/map.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* From Minecraft Overviewer.
3+
*/
4+
// our custom projection maps Latitude to Y, and Longitude to X as normal,
5+
// but it maps the range [0.0, 1.0] to [0, tileSize] in both directions
6+
// so it is easier to position markers, etc. based on their position
7+
// (find their position in the lowest-zoom image, and divide by tileSize)
8+
function MapProjection() {
9+
this.inverseTileSize = 1.0 / MapConfig.tileSize;
10+
}
11+
12+
MapProjection.prototype.fromLatLngToPoint = function(latLng) {
13+
var x = latLng.lng() * MapConfig.tileSize;
14+
var y = latLng.lat() * MapConfig.tileSize;
15+
return new google.maps.Point(x, y);
16+
};
17+
18+
MapProjection.prototype.fromPointToLatLng = function(point) {
19+
var lng = point.x * this.inverseTileSize;
20+
var lat = point.y * this.inverseTileSize;
21+
return new google.maps.LatLng(lat, lng);
22+
};
23+
24+
function convertMCtoLatLng(x, z, y) {
25+
// the size of a 1/4 block image divided by the total size of all render tiles
26+
// on the highest zoom level
27+
var block = (MapConfig.textureSize/2.0) / (MapConfig.tileSize * Math.pow(2, MapConfig.maxZoom));
28+
29+
// at first calculate the row and the column of the block
30+
// column is just x+z
31+
var col = x+z;
32+
// row is z-x, and every y to bottom adds 2 rows
33+
var row = z-x + (256-y)*2;
34+
35+
// midpoint of the map is in lat/lng 0.5|0.5
36+
// we have to move the lng by the size of one tile
37+
// lng is now 2*block size for every column
38+
var lng = 0.5 - (1.0 / Math.pow(2, MapConfig.maxZoom + 1)) + col * 2*block;
39+
// lat is now one block size for every row
40+
var lat = 0.5 + row * block;
41+
42+
return new google.maps.LatLng(lat, lng);
43+
}
44+
45+
46+
var MCMapOptions = {
47+
/**
48+
* From Minecraft Overviewer.
49+
*/
50+
getTileUrl: function(tile, zoom) {
51+
var url = ".";
52+
if(tile.x < 0 || tile.x >= Math.pow(2, zoom) || tile.y < 0 || tile.y >= Math.pow(2, zoom)) {
53+
url += "/blank";
54+
} else if(zoom == 0) {
55+
url += "/base";
56+
} else {
57+
for(var z = zoom - 1; z >= 0; --z) {
58+
var x = Math.floor(tile.x / Math.pow(2, z)) % 2;
59+
var y = Math.floor(tile.y / Math.pow(2, z)) % 2;
60+
url += "/" + (x + 2 * y + 1);
61+
}
62+
}
63+
url = url + ".png";
64+
return(url);
65+
},
66+
tileSize: new google.maps.Size(MapConfig.tileSize, MapConfig.tileSize),
67+
maxZoom: MapConfig.maxZoom,
68+
minZoom: MapConfig.minZoom,
69+
isPng: true
70+
};
71+
72+
function init() {
73+
var MCMapType = new google.maps.ImageMapType(MCMapOptions);
74+
MCMapType.name = "Minecraft Map";
75+
MCMapType.alt = "Minecraft Map";
76+
MCMapType.projection = new MapProjection();
77+
78+
var mapOptions = {
79+
zoom: MapConfig.defaultZoom,
80+
center: new google.maps.LatLng(0.5, 0.5),
81+
82+
navigationControl: true,
83+
scaleControl: false,
84+
mapTypeControl: false,
85+
streetViewControl: false,
86+
};
87+
88+
var map = new google.maps.Map(document.getElementById("mcmap"), mapOptions);
89+
map.mapTypes.set("mcmap", MCMapType);
90+
map.setMapTypeId("mcmap");
91+
}

src/data/template/markers.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var MARKERS = [
2+
{markers}
3+
];

src/data/template/style.css

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
html {
2+
width: 100%;
3+
height: 100%
4+
}
5+
6+
body {
7+
width: 100%;
8+
height: 100%;
9+
margin: 0;
10+
padding: 0;
11+
}
12+
13+
#mcmap {
14+
width: 100%;
15+
height: 100%
16+
}

0 commit comments

Comments
 (0)