Page 1 of 1

test if a chunk is generated?

PostPosted: Mon Mar 03, 2014 04:30
by i1abnrk
Hi everyone. I'm working on a mapgen mod that adapts genmud (old text-based rpg) code to lua. I'm looking for a way to test if a chunk has generated. Is there a null or something if I try to get a node that hasn't been generated yet? Some of the features I'm adapting (such as connecting roads) will be easier a simple test like this for edge-finding.
Thanks for any ideas.

PostPosted: Mon Mar 03, 2014 11:25
by PilzAdam
You cant test if it has generated, but you can test if its loaded by using minetest.get_node_or_nil().

PostPosted: Mon Mar 03, 2014 12:20
by Casimir
Here "pos" is one position in the area you want to check.
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
if minetest.registered_nodes[minetest.get_node(pos).name] then
    -- succes
end

PostPosted: Mon Mar 03, 2014 13:03
by PilzAdam
Casimir wrote:Here "pos" is one position in the area you want to check.
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
if minetest.registered_nodes[minetest.get_node(pos).name] then
    -- succes
end

This will always jump to "succes"; get_node() returns ignore for unloaded areas, and ignore is in the registered_nodes table.

PostPosted: Mon Mar 03, 2014 14:55
by Casimir
Then...
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
if minetest.get_node(pos).name ~= "ignore" then
    -- succes
end

PostPosted: Mon Mar 03, 2014 15:05
by i1abnrk
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 c_nil = minetest.get_content_id("ignore")
if minetest.get_node(pos)==c_nil then
    --true
end

This looks valid. These are good ideas. get_node_or_nil is undocumented in wiki.
So am I right in assuming only asynchronous sqlite transactions are available to lua? (vm:get_data() and vm:write_to_map()) Using async means the edge-finding technique requires a full rewrite of voxeldata every time a client accesses a chunk. Synchronous writeback from client this way could strain the server so I'd best write genmud on server-side in C++ as a patch I think.
These are assumptions, does it sound right?
Genmud generates the full map and minetest uses event-based chunk generation. Using perlin prediction is possible in lua instead of server code. The logic switches would be more tedious and slow in lua, though.

PostPosted: Mon Mar 03, 2014 15:49
by sfan5
get_node returns a table, you can't compare that to a node id
Do it like this:
Casimir wrote:Then...
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
if minetest.get_node(pos).name ~= "ignore" then
    -- success
end

PostPosted: Mon Mar 03, 2014 16:16
by PilzAdam
Casimir wrote:Then...
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
if minetest.get_node(pos).name ~= "ignore" then
    -- succes
end

Thats like exaclty the same thing as I posted as first answer to this topic...

PostPosted: Mon Mar 03, 2014 16:26
by i1abnrk
~='ignore' works for me. I think testing 'if loaded' the closest solution I'll get with the current lua API. I'll have to pick through github to see if I can expose a sqlite query to lua to test 'if generated'.