potential optimizations; added support for villagers

This commit is contained in:
Sokomine 2017-06-10 23:23:27 +02:00
parent 963377c0a3
commit 1e6ebef346
5 changed files with 35 additions and 11 deletions

View File

@ -55,6 +55,9 @@ dofile(mg_villages.modpath.."/name_gen.lua");
dofile(mg_villages.modpath.."/villages.lua")
-- determine type of work, name, age, bed position etc. for villagers (none included!)
dofile(mg_villages.modpath.."/inhabitants.lua")
-- adds a command that allows to teleport to a known village
dofile(mg_villages.modpath.."/chat_commands.lua")
-- protect villages from griefing

View File

@ -1,6 +1,6 @@
------------------------------------------------------------------------------
-- Interface for other mdos
-- Interface for other mods
-- this function gets executed only once per village - namely when the first
-- part of a village is generated;
@ -18,13 +18,16 @@ end
-- the voxelmanip data (data, param2_data, a) is just for reading, i.e. finding
-- a good spawning position for the trader
mg_villages.part_of_village_spawned = function( village, minp, maxp, data, param2_data, a, cid )
-- mobf needs a way to spawn its traders
if( minetest.get_modpath( 'mobf_trader' )) then
mob_village_traders.part_of_village_spawned( village, minp, maxp, data, param2_data, a, cid );
end
-- assign jobs and names and age and gender etc. to bed positions
mg_villages.inhabitants.part_of_village_spawned( village, minp, maxp, data, param2_data, a, cid );
end
------------------------------------------------------------------------------
local vm_data_buffer;
local param2_data_buffer;
local data_vm;
local data_param2_data;
mg_villages.wseed = 0;
@ -337,6 +340,7 @@ mg_villages.flatten_village_area = function( villages, minp, maxp, vm, data, par
for village_nr, village in ipairs(villages) do
local force_ground = nil;
local force_underground = nil;
local has_artificial_snow = false;
if( village.village_type
and mg_villages.village_type_data[ village.village_type ]
and mg_villages.village_type_data[ village.village_type ].force_ground
@ -355,7 +359,6 @@ mg_villages.flatten_village_area = function( villages, minp, maxp, vm, data, par
and village_area[ x ][ z ][ 2 ]~= 0
and data[a:index(x,village.vh,z)] ~= cid.c_ignore) then
local has_artificial_snow = false;
if( village.artificial_snow and village.artificial_snow==1) then
has_artificial_snow = true;
end
@ -911,6 +914,8 @@ end
mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm, data, param2_data, a, top, seed )
local t1 = minetest.get_us_time();
local data;
local param2data;
local cid = {}
cid.c_air = minetest.get_content_id( 'air' );
@ -1014,8 +1019,8 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
MaxEdge={x=emax.x, y=emax.y, z=emax.z},
}
data = vm:get_data(data);
param2_data = vm:get_param2_data(param2_data);
data = vm:get_data(vm_data_buffer);
param2_data = vm:get_param2_data(param2_data_buffer);
end
t1 = time_elapsed( t1, 'get_vmap_data' );
@ -1109,6 +1114,7 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
-- only update lighting where we actually placed the nodes
vm:calc_lighting( e1, e2 ); --minp, maxp ); --tmin, tmax)
-- vm:calc_lighting( {x=e1.x+1,y=e1.y+1,z=e1.z+1}, {x=e2.x-1,y=e2.y-1,z=e2.z-1});
t1 = time_elapsed( t1, 'vm calc lighting' );
vm:write_to_map(data)
@ -1189,6 +1195,7 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
for _,v in pairs( mg_villages.all_villages ) do
count = count + 1;
end
village.to_add_data.extra_calls = {};
village.extra_calls = {}; -- do not save these values
village.nr = count;
mg_villages.anz_villages = count;

View File

@ -221,6 +221,11 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
+ (village.vh - pos.y ) * (village.vh - pos.y )
+ (village.vz - pos.z ) * (village.vz - pos.z ) ));
if( fields and fields.inhabitants ) then
minetest.chat_send_player( player:get_player_name(), mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr ));
return;
end
-- create the header
local formspec = "size[13,10]"..
"label[3.3,0.0;Plot No.: "..tostring( plot_nr )..", with "..tostring( mg_villages.BUILDINGS[ plot.btype ].scm ).."]"..
@ -233,7 +238,7 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
"field[20,20;0.1,0.1;pos2str;Pos;"..minetest.pos_to_string( pos ).."]";
build_chest.show_size_data( building_name );
if( plot and plot.traders ) then
if( plot and plot.traders ) then -- TODO: deprecated; but may be useful in a new form for mobs that live in the house
if( #plot.traders > 1 ) then
formspec = formspec.."label[0.3,7.0;Some traders live here. One works as a "..tostring(plot.traders[1].typ)..".]";
for i=2,#plot.traders do
@ -271,7 +276,6 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
-- TODO: hire mob
end
local replace_row = -1;
-- the player selected a material which ought to be replaced
if( fields.build_chest_replacements ) then
@ -401,6 +405,7 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
local original_formspec = "size[8,3]"..
"button[7.0,0.0;1.0,0.5;info;Info]"..
"button[6.0,1.0;2.0,0.5;inhabitants;Who lives here]"..
"label[1.0,0.5;Plot No.: "..tostring( plot_nr ).."]"..
"label[2.5,0.5;Building:]"..
"label[3.5,0.5;"..tostring( mg_villages.BUILDINGS[btype].scm ).."]"..

View File

@ -3,6 +3,10 @@
-- it will then calculate the minimum point (xbmin, avsurfy, zbmin) where the house should be spawned
-- and mark a mapchunk-sized 'house area' for terrain blending
-- re-use already created data structures by the perlin noise functions
local noise_object_blending = nil;
local noise_buffer = nil;
mg_villages.village_area_mark_single_house_area = function(village_area, minp, maxp, pos, pr, village_nr, village)
local YFLATMIN = 2 -- Lowest flat area height
@ -30,7 +34,10 @@ mg_villages.village_area_mark_single_house_area = function(village_area, minp, m
-- 2D noise perlinmap
local chulens = {x=sidelen, y=sidelen, z=sidelen}
local minpos = {x=minp.x, y=minp.z}
local nvals_blend = minetest.get_perlin_map(np_blend, chulens):get2dMap_flat(minpos)
noise_object_blending = noise_object_blending or minetest.get_perlin_map(np_blend, chulens);
local nvals_blend = noise_object_blending:get2dMap_flat(minpos, noise_buffer);
-- local nvals_blend = minetest.get_perlin_map(np_blend, chulens):get2dMap_flat(minpos)
-- mark mapchunk-sized house area
local ni = 1

View File

@ -3,6 +3,8 @@
-- how the buildings are rotated, where the roads will be, which replacement materials
-- will be used etc.
local calls;
local function is_village_block(minp)
local x, z = math.floor(minp.x/80), math.floor(minp.z/80)
local vcc = mg_villages.VILLAGE_CHECK_COUNT