diff --git a/.gitignore b/.gitignore index 62a6260..2dd60fe 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ bounds_y dirs rivers unused/ +data/ diff --git a/README.md b/README.md index c9886a9..8ac7ce9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ The Python part relies on external libraries that you need to install: They are commonly found on `pip` or `conda` Python distributions. # Usage +By default, the mod contains a demo 400x400 map (so you can start the game directly), but it is recommended that you run the pre-processing script to generate a new map before world creation, if you can. + ## Pre-processing Run the script `terrain_rivers.py` via command line. You can optionally append the map size (by default 400). Example for a 1000x1000 map: ``` @@ -25,5 +27,10 @@ Run the script `terrain_rivers.py` via command line. You can optionally append t ``` For a default 400x400 map, it should take between 1 and 2 minutes. It will generate 5 files directly in the mod folder, containing the map data. +If you have `matplotlib` installed, the script `view_map.py` can be used to get a map preview. Example: +``` +./view_map.py data/ +``` + ## Map generation Just create a Minetest world with `singlenode` mapgen, enable this mod and start the world. The data files are immediately copied in the world folder so you can re-generate them afterwards, it won't affect the old worlds. diff --git a/demo_data/dem b/demo_data/dem new file mode 100644 index 0000000..1d342f6 Binary files /dev/null and b/demo_data/dem differ diff --git a/demo_data/dirs b/demo_data/dirs new file mode 100644 index 0000000..50a1003 Binary files /dev/null and b/demo_data/dirs differ diff --git a/demo_data/lakes b/demo_data/lakes new file mode 100644 index 0000000..02abb28 Binary files /dev/null and b/demo_data/lakes differ diff --git a/demo_data/offset_x b/demo_data/offset_x new file mode 100644 index 0000000..972b30d Binary files /dev/null and b/demo_data/offset_x differ diff --git a/demo_data/offset_y b/demo_data/offset_y new file mode 100644 index 0000000..0526d31 Binary files /dev/null and b/demo_data/offset_y differ diff --git a/demo_data/rivers b/demo_data/rivers new file mode 100644 index 0000000..2edbe4b Binary files /dev/null and b/demo_data/rivers differ diff --git a/demo_data/size b/demo_data/size new file mode 100644 index 0000000..c71f36a --- /dev/null +++ b/demo_data/size @@ -0,0 +1,2 @@ +401 +401 \ No newline at end of file diff --git a/load.lua b/load.lua index b502567..9dc08ff 100644 --- a/load.lua +++ b/load.lua @@ -1,4 +1,4 @@ -local worldpath = minetest.get_worldpath() .. "/" +local worldpath = minetest.get_worldpath() .. "/river_data/" local function load_map(filename, bytes, signed, size) local file = io.open(worldpath .. filename, 'r') diff --git a/polygons.lua b/polygons.lua index afa9f3f..eac655c 100644 --- a/polygons.lua +++ b/polygons.lua @@ -1,15 +1,22 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) .. '/' -local worldpath = minetest.get_worldpath() .. '/' +local mod_data_path = modpath .. 'data/' +if not io.open(mod_data_path .. 'size', 'r') then + mod_data_path = modpath .. 'demo_data/' +end + +local world_data_path = minetest.get_worldpath() .. '/river_data/' +minetest.mkdir(world_data_path) + local load_map = dofile(modpath .. 'load.lua') local function copy_if_needed(filename) - local wfilename = worldpath..filename + local wfilename = world_data_path..filename local wfile = io.open(wfilename, 'r') if wfile then wfile:close() return end - local mfilename = modpath..filename + local mfilename = mod_data_path..filename local mfile = io.open(mfilename, 'r') local wfile = io.open(wfilename, 'w') wfile:write(mfile:read("*all")) @@ -18,7 +25,7 @@ local function copy_if_needed(filename) end copy_if_needed('size') -local sfile = io.open(worldpath..'size') +local sfile = io.open(world_data_path..'size') local X = tonumber(sfile:read('*l')) local Z = tonumber(sfile:read('*l')) sfile:close() diff --git a/terrain_rivers.py b/terrain_rivers.py index a526d7b..687622b 100755 --- a/terrain_rivers.py +++ b/terrain_rivers.py @@ -77,6 +77,9 @@ offset_x, offset_y = bounds.twist(bx, by, bounds.get_fixed(model.dirs)) offset_x = np.clip(np.floor(offset_x * 256), -128, 127) offset_y = np.clip(np.floor(offset_y * 256), -128, 127) +if not os.path.isdir('data'): + os.mkdir('data') +os.chdir('data') # Save the files save(model.dem, 'dem', dtype='>i2') save(model.lakes, 'lakes', dtype='>i2') diff --git a/view_map.py b/view_map.py index 27a33d8..821c2b1 100755 --- a/view_map.py +++ b/view_map.py @@ -27,6 +27,11 @@ def view_map(dem, lakes, rivers): plt.show() if __name__ == "__main__": + import sys + import os + if len(sys.argv) > 1: + os.chdir(sys.argv[1]) + def load_map(name, dtype, shape): dtype = np.dtype(dtype) with open(name, 'rb') as f: