LVM and mapgen help request

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

LVM and mapgen help request

by stu » Sun Apr 20, 2014 18:12

I am looking for some help with map generation and the lua voxel manipulator.
Hopefully you can get the idea of what I am trying to do from the code.
Basically replacing each grass node with one of 4 random variants.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_generated(function(minp, maxp, seed)
   local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
   local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
   local data = vm:get_data()
   for i in area:iterp(emin, emax) do
      if data[i] == minetest.get_content_id("default:grass") then
         local n = tostring(math.random(1, 4))
         data[i] = minetest.get_content_id("default:grass_"..n)
      end
   end
   vm:set_data(data)
   vm:set_lighting({day=0, night=0})
   vm:calc_lighting()
   vm:write_to_map(data)
end)


This code does do what I want but is incredibly slow.
Is there a better way to achieve the same effect?

Edit: Note this is not minetest_game, the grass node here is a solid (drawtype normal) node.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: LVM and mapgen help request

by Krock » Sun Apr 20, 2014 18:31

try this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   local area = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
   local data = vm:get_data()
   local c_grass = minetest.get_content_id("default:grass")
   for i in area:iterp(minp, maxp) do
      if data[i] == c_grass then
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: LVM and mapgen help request

by stu » Sun Apr 20, 2014 18:50

Krock wrote:try this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   local area = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
   local data = vm:get_data()
   local c_grass = minetest.get_content_id("default:grass")
   for i in area:iterp(minp, maxp) do
      if data[i] == c_grass then


That is certainly a lot faster, thanks.

Edit: Although this change does make a massive improvement, it is still not quite as fast as I'd like,
maybe I am just expecting too much.

Note that I took the get_content_id calls out of the loop entirely.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 7 guests

cron