Page 1 of 1

Minetest as an experimental tool for neuroscience

PostPosted: Wed May 25, 2016 17:18
by eeMagic
Hi everyone

I want to use Minetest for analyse memory. It looks like a perfect environment and it's quite easy design the maps. But I need some way to export precise information about the behaviour of the Player.

My principal goal is save in a file the player's coordinates with the system timestamp (aprox 60 per second, but I can work with less). Do you know if that is possible?

Could someone give me some tip?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Wed May 25, 2016 17:28
by burli
Well, there is a function called register_globalstep. This function is called every few milliseconds from the engine

You can get the current player and his position, the system time with os.clock() and open a file to store the values

And by the way: welcome and this is an interesting project

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 10:34
by eeMagic
Thanks!

Now I know it's possible I can keep working. I didn't check how to code it, but probably I will need a way to close the file (I can open it in init.lua). Do you remember some function called when the game is close?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 10:43
by burli
I would close the file after writing to prevent file corruption an case of a crash. But if you really keep it open you can use this

http://dev.minetest.net/minetest.register_on_shutdown

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 12:15
by rubenwardy
The server doesn't update fast enough to be able to record at 60fps, by default it updates at 10fps.
To log at 60fps you'll need to set the server fps to 60 (dedicated_time_Step or something in minetest.conf) or edit the client source code. You'll probably end up needing to do the latter as I doubt that the server could work that fast, and that the client would even send their position that fast.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 15:15
by eeMagic
@burli: thanks. You are right, at least I will save in different files each stage.

@rubenwardy: thanks for the info. That isn't so bad, It could work fine with 10fps and a little of interpolation (without the fast privilege the movement is quite slow). In any case, I will check how to reduce the time_step.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 15:42
by burli
I tinker a bit with register_globalstep.

1. dedicated_time_step has no effect (I guess it's the wrong parameter for this)
2. in idle register_globalstep is around 30 calls per second (cps)
3. if I move cps can go up??!!
4. if I have lots of mods installed cps can go below 10 or even to 0 (no calls for one or more seconds)

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu May 26, 2016 22:25
by ptvirgo
Depending on exactly how you want to interpret your data, it might be more efficient to log key-presses and mouse movements. Interesting sounding project, I hope you'll tell us more about it.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Fri May 27, 2016 13:43
by eeMagic
@ptvirgo: That could be useful. But I need the coordinates because the environment should have walls... and they will break the relationship between key-press and position.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Fri May 27, 2016 14:19
by burli
I don't think that you really need 60 positions per second. The human reaction time is around 0.2 seconds. It you record 20 positions per second it's enough I think

Re: Minetest as an experimental tool for neuroscience

PostPosted: Fri May 27, 2016 21:17
by ptvirgo
@eeMagic: Yeah, I wasn't thinking about that; no good being efficient if you cant' actually use the results..!
So are you finding what you need? How's the project coming?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Fri May 27, 2016 23:20
by eeMagic
@ptvirgo: I have a lot to learn (specially about lua), but I think that minetest has all the features I need. The project is going quite slowly, first I have to show that the idea is really possible (and that requires a lot of code and time) .

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sat May 28, 2016 01:12
by sofar
eemagic:

The code below will do what you need, click on the link to see the full source:

https://gist.github.com/sofar/e5da2a6ce ... 9b367bd7ac

Put this in worlds/<worldname>/worldmods/track/init.lua and start your world, and this will output CSV formatted time+position files for each player.

Output files are overwritten if the player reconnects.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sat May 28, 2016 11:37
by eeMagic
@sofar: Thank you very much!! It works perfectly! Now I can start with the crazy stuff.

Sorry for the stupid question but... what is the difference between a worldmod and a mod?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sat May 28, 2016 11:42
by rubenwardy
There are three places a mod can be.

In a subgame like minetest game (games/minetest_game/mods/) - the mod is automatically enabled and specific to that subgame, so any world using that subgame will have that mod.
The main mods dir (mods/)- disabled by default, and world can enable amd use it.
The worldmods mod dir (worlds/worldname/worldmods/) - always enabled, mods are specific to that world.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sat May 28, 2016 13:21
by burli
rubenwardy wrote:The worldmods mod dir (worlds/worldname/worldmods/) - always enabled, mods are specific to that world.

Didn't know that

Re: Minetest as an experimental tool for neuroscience

PostPosted: Tue Jun 21, 2016 11:46
by eeMagic
Hi again,
I keep working in this project. My biggest problem now is how to add/remove a few blocks before load, I'm using
minetest.after() but I don't want to show the previous arrange of blocks.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Tue Jun 28, 2016 17:38
by eeMagic
Is it possible use a fixed camera? or at least change the max distance of set_eye_offset() in third person?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Wed Jun 29, 2016 09:13
by srifqi
eeMagic wrote:Is it possible use a fixed camera? or at least change the max distance of set_eye_offset() in third person?

I'm not sure about fixed camera. Also, if you mean "max distance" is viewing range, you can set it by pressing Numpad - or Numpad + or add this line into minetest.conf:
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
viewing_range = (insert your viewing range here, in block)

Re: Minetest as an experimental tool for neuroscience

PostPosted: Wed Jun 29, 2016 10:15
by eeMagic
I mean the relative position of the camera. In set_eye_offset(offset_first, offset_third), I found that after y=15, offset_third doesn't change any more.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Thu Jun 30, 2016 15:17
by srifqi
eeMagic wrote:I mean the relative position of the camera. In set_eye_offset(offset_first, offset_third), I found that after y=15, offset_third doesn't change any more.

Yes, it does. As stated in docs/lua_api.txt:
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
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
    * in first person view
    * in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sat Jul 16, 2016 15:35
by eeMagic
Is there a way to change that maximum values?

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sun Jul 17, 2016 16:20
by srifqi
eeMagic wrote:Is there a way to change that maximum values?

You can, but you need to change engine codes. It's already hard-coded in the engine code (src/script/lua_api/l_object.cpp) to "Prevent abuse of offset values (keep player always visible)":
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
   // Prevent abuse of offset values (keep player always visible)
   offset_third.X = rangelim(offset_third.X,-10,10);
   offset_third.Z = rangelim(offset_third.Z,-5,5);
   /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
   offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS

Remove those lines above in source code and compile.

Re: Minetest as an experimental tool for neuroscience

PostPosted: Sun Jul 24, 2016 16:15
by eeMagic
thanks :)

I have a big problem now. I have to use an external C library to communicate with hardware. I made a dll wrapper in C for lua and it works (I tested it using luaforwindows) . But minetest crash when I try to use: require(wrappername) in the init.lua of a mod.

I'm using Minetest portable 32 bits, Visual Studio for compiling and I tested the code with luaforwindows.

am I totally confused?
is it there another way to use dlls in minetest?