Get Nodes around a specified position

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

Get Nodes around a specified position

by sapier » Sat Jan 07, 2012 14:20

When using "get_objects_inside_radius" i recognized there was no function doing this for nodes too.

running a 3d for loop around nodes using getnode is feasable but seems to be way to time consuming, at least if done in lua.

here's a patch adding "get_nodes_inside_radius".


This feature can be used in at least 3 mods i know about:

farming -> detect water nearby
animals -> plasmaballs removing terrain nodes
minereal detector -> no need to parse surrounding in lua

wheat pumpkin etc (probably) -> detect water too

Patch
Last edited by sapier on Sat Jan 07, 2012 14:21, edited 1 time in total.
DON'T mention coding style!
(c) sapier all rights reserved
 

robin
Member
 
Posts: 22
Joined: Mon Jan 02, 2012 15:53

by robin » Sat Jan 07, 2012 15:31

Good idea!

Can you create a small mod to test the function?

I'm also just curious about the following: Is there any way to proof, that the native functions works faster than the lua implementation? I've heard it in some threads, but never saw evidence for it.
 

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

by sfan5 » Sat Jan 07, 2012 21:32

Should be merged! +3
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Sat Jan 07, 2012 23:02

+1000

it depends on the script for the speed.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sat Jan 07, 2012 23:59

This is just pushing all the nodes at once. You would still need to loop through them in LUA. A better way to do this might be to ask the server how many of a certain node or in the radius. Another thing to consider is how you are defining a radius, cube or sphere?
 

sapier
Member
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

by sapier » Sun Jan 08, 2012 04:07

Yes this still forces you to loop through the list but you won't have to go up the way to c++ and back to lua for each node.

I tought about adding a function testing presence of a specific node(s) for farming too. This will most likely add another speed increase.

But it will limit the functions use in following use cases

1) If you're interested in different nodes you'll have to call it for each node
e.g. mineral detector
2) If you're interested in all nodes except of two/three/four you can't really use the function
e.g. plasmaballs in animals which only don't harm cobble and stone by now
3) If you don't know wich nodes do interesst you on calling
e.g. if you decide which nodes you're interested by some node parameters (that may be set by other mods too)

Probably a solution migt be changing to:
get_nodes_inside_radius(pos,radius,nodename)
If nodename is nil -> return all nodes
else -> return only nodes with this name.


It's called get_nodes_inside_RADIUS ... if it's usefull to have other shapes than circle which dont have a radius there at least should be a name change to lets say get_objects_inside_AREA.

I personaly do not support cube shape because of:
1) you would have to add this for objects too to make it symmetrical (everyone looks for it at objects too if present here)
2) Even as minetests basic shape is cube most people do think in distances and cube shape would have realy strange effects if using larger "radius" values
3) If adding cube shape why not add cylinder tourus pyramid and cone too ;-)

This is MY PERSONAL opinion ;-)
Last edited by sapier on Sun Jan 08, 2012 04:08, edited 1 time in total.
DON'T mention coding style!
(c) sapier all rights reserved
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Mon Jan 09, 2012 15:40

I see now the function "current_pos.getDistanceFrom(pos)" so yeah you are searching a sphere shape. It would be nice to have that as a LUA function. I'm sure some other mods could use that function.

Also, an interesting thing about LUA to C++ functions it that the number of arguments and the number of returned items are not fixed.
So you could call:
"nodes = get_nodes_inside_radius(pos, radius)"
and just get all the nodes in a table

or call:
"num_of_nodes = get_nodes_inside_radius(pos, radius, nodename)"
and get a number returned

or call:
"num_of_nodes1, num_of_nodes2 = get_nodes_inside_radius(pos, radius, nodename, nodename)"
and get two numbers returned. You could have as many different nodenames as you want.
Last edited by randomproof on Mon Jan 09, 2012 15:41, edited 1 time in total.
 

jn
Member
 
Posts: 106
Joined: Tue Jan 03, 2012 19:15

by jn » Tue Jan 10, 2012 15:09

A minor nitpick: Indenting the individual "for"s of a XYZ loop doesn't necessarily help readability; see player.cpp:378.
(https://github.com/celeron55/minetest/blob/master/src/player.cpp#L378)
 

User avatar
Neuromancer
Member
 
Posts: 793
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

by Neuromancer » Sat Aug 25, 2012 21:53

Was get_nodes_inside_radius ever added to Minetest? What is the best way to do this short of installing sapier's patch? Do we still have to loop through all the nodes?
 

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

by PilzAdam » Sat Aug 25, 2012 22:01

Neuromancer wrote:Was get_nodes_inside_radius ever added to Minetest? What is the best way to do this short of installing sapier's patch? Do we still have to loop through all the nodes?

https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt#L1024
 

User avatar
Neuromancer
Member
 
Posts: 793
Joined: Tue Jun 12, 2012 22:28
GitHub: Neuromancer56

by Neuromancer » Sun Aug 26, 2012 01:02

Thanks Pilz. I'm using this to find places to create a waterfall sound. To do it in version .13 I just used the brute force lua for loops method.

I'm thinking I'm going to need find_nodes_in_area because if there is just 1 flowing water node it doesn't make sense to have a small waterfall sound. So I will look for at least 10 default:water_flowing nodes in the area. How wide out do you think I can go (min & max pos) without affecting performance? +/- 10 for all positions x,y, & z? 15, 20?
Last edited by Neuromancer on Sun Aug 26, 2012 01:04, edited 1 time in total.
 


Return to Minetest Features

Who is online

Users browsing this forum: Bing [Bot] and 7 guests

cron