Change folder structure: data files are now in a directory.

Also added a demo 400x400 map, that is overriden on pre-processing.
This commit is contained in:
Gael-de-Sailly 2020-04-26 23:29:36 +02:00
parent b429b302e1
commit a9ab0e53d3
13 changed files with 30 additions and 5 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ bounds_y
dirs
rivers
unused/
data/

View File

@ -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.

BIN
demo_data/dem Normal file

Binary file not shown.

BIN
demo_data/dirs Normal file

Binary file not shown.

BIN
demo_data/lakes Normal file

Binary file not shown.

BIN
demo_data/offset_x Normal file

Binary file not shown.

BIN
demo_data/offset_y Normal file

Binary file not shown.

BIN
demo_data/rivers Normal file

Binary file not shown.

2
demo_data/size Normal file
View File

@ -0,0 +1,2 @@
401
401

View File

@ -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')

View File

@ -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()

View File

@ -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')

View File

@ -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: