test if a chunk is generated?

Post Reply
i1abnrk
Member
Posts: 26
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll
Location: Wisconsin
Contact:

test if a chunk is generated?

by i1abnrk » Post

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.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

You cant test if it has generated, but you can test if its loaded by using minetest.get_node_or_nil().

User avatar
Casimir
Member
Posts: 1207
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

by Casimir » Post

Here "pos" is one position in the area you want to check.

Code: Select all

if minetest.registered_nodes[minetest.get_node(pos).name] then
    -- succes
end

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Casimir wrote:Here "pos" is one position in the area you want to check.

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.

User avatar
Casimir
Member
Posts: 1207
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

by Casimir » Post

Then...

Code: Select all

if minetest.get_node(pos).name ~= "ignore" then
    -- succes
end

i1abnrk
Member
Posts: 26
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll
Location: Wisconsin
Contact:

by i1abnrk » Post

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.
Last edited by i1abnrk on Mon Mar 03, 2014 15:33, edited 1 time in total.

sfan5
Moderator
Posts: 4095
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5
Location: Germany

by sfan5 » Post

get_node returns a table, you can't compare that to a node id
Do it like this:
Casimir wrote:Then...

Code: Select all

if minetest.get_node(pos).name ~= "ignore" then
    -- success
end
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Casimir wrote:Then...

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...
Last edited by PilzAdam on Mon Mar 03, 2014 16:17, edited 1 time in total.

i1abnrk
Member
Posts: 26
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll
Location: Wisconsin
Contact:

by i1abnrk » Post

~='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'.
Last edited by i1abnrk on Mon Mar 03, 2014 16:49, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: dxt_73 and 37 guests