mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-29 12:20:41 +01:00
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:
parent
b429b302e1
commit
a9ab0e53d3
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ bounds_y
|
||||
dirs
|
||||
rivers
|
||||
unused/
|
||||
data/
|
||||
|
@ -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
BIN
demo_data/dem
Normal file
Binary file not shown.
BIN
demo_data/dirs
Normal file
BIN
demo_data/dirs
Normal file
Binary file not shown.
BIN
demo_data/lakes
Normal file
BIN
demo_data/lakes
Normal file
Binary file not shown.
BIN
demo_data/offset_x
Normal file
BIN
demo_data/offset_x
Normal file
Binary file not shown.
BIN
demo_data/offset_y
Normal file
BIN
demo_data/offset_y
Normal file
Binary file not shown.
BIN
demo_data/rivers
Normal file
BIN
demo_data/rivers
Normal file
Binary file not shown.
2
demo_data/size
Normal file
2
demo_data/size
Normal file
@ -0,0 +1,2 @@
|
||||
401
|
||||
401
|
2
load.lua
2
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')
|
||||
|
15
polygons.lua
15
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()
|
||||
|
@ -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')
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user