test if a chunk is generated?

i1abnrk
Member
 
Posts: 19
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll

test if a chunk is generated?

by i1abnrk » Mon Mar 03, 2014 04:30

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

by PilzAdam » Mon Mar 03, 2014 11:25

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: 1101
Joined: Fri Aug 03, 2012 16:59

by Casimir » Mon Mar 03, 2014 12:20

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
 

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

by PilzAdam » Mon Mar 03, 2014 13:03

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.
 

User avatar
Casimir
Member
 
Posts: 1101
Joined: Fri Aug 03, 2012 16:59

by Casimir » Mon Mar 03, 2014 14:55

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
 

i1abnrk
Member
 
Posts: 19
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll

by i1abnrk » Mon Mar 03, 2014 15:05

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

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Mon Mar 03, 2014 15:49

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
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

by PilzAdam » Mon Mar 03, 2014 16:16

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

i1abnrk
Member
 
Posts: 19
Joined: Sat May 11, 2013 03:20
GitHub: i1abnrk
IRC: i1abnrk
In-game: mervyncoll

by i1abnrk » Mon Mar 03, 2014 16:26

~='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.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 8 guests

cron