Page 1 of 4
[Mod] MAPP - map for Minetest - optimized! [0.2.4]

Posted:
Wed Feb 27, 2013 23:26
by 4aiman
Here how it looks like:

How to use this: craft a map block out of 4 dirts:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Take a map into your hands and just left-click! As easy as that! ;)
Licence: WTFPL
Download: https://github.com/4aiman/mapp/archive/master.zipIncludes 16*16 and 32*32 textures!
Credit goes to:
pandaro, who made
player_radar mod.
I looked into the "player_radar" mod and came up with idea to use smth similar for maps.
So I wrote a simple test-mod and start to actually test it.
RealBadAngel, who made map a tool, not a block that must be punched :)
Calinou for ideas about the playermark.
kaeza and
Splizard for optimizing the code.

Posted:
Wed Feb 27, 2013 23:56
by lkjoel
COOL!!! +1000

Posted:
Thu Feb 28, 2013 01:47
by 0gb.us
Oh? That's awesome!
If this could be incorporated into some sort of in-menu (inventory_plus) map, that would be even better. Once you lay the foundation, the rest would be easy. I'll swap on_punch() for on_receive_fields(), and add it to my world.
I'll have to keep an eye on this and see how it progresses.

Posted:
Thu Feb 28, 2013 02:06
by Josh
Looking good! however i would prefer the map to appear in the players hand and not show up when
you punch a block. But great work 4aiman :)
P.S: What do you mean by: Dont use this in your playing world? Can't we use it in singleplayer?

Posted:
Thu Feb 28, 2013 02:10
by Traxie21
You can't really make the map appear in the player's hand.
And I think he means that it might corrupt your world.

Posted:
Thu Feb 28, 2013 05:52
by 4aiman
I mean that cycles like the one in this prototype is very slow.
But what's more important, they STOP client-server communication ('cause server is too busy to answer it's clients).
I tested that on 5 or 6 worlds and have to delete some of them, 'cause (after 4th-8th punch of a map node) server went "silent" (which is normal by itself - the server was computing a map formspec). Sometimes I just wait a little and server begins to response once again. But sometimes even after restarting minetest maps with map_node refuse to load. I mean, I can load the game, but it looks like the game can't load any blocks than it already loaded. That leaves me in a 30*30*30 world (approx.) w/o any way to dig smth and get node_drops (well, that's natural thing when server's too busy).
The main problem is how to allow server make it's work while still be responsible.
Smth like Application.ProcessMessages would be great. Or creating a different thread would be great.
I'll see what I can do wit what we have atm.
PS: if anyone will use this/have some ideas on this, I encourage all of those people to post here their suggestions/code samples/links to your modifications/links to things inspired by this prototype. One can never know what this thing may lead to ;)

Posted:
Thu Feb 28, 2013 12:20
by jojoa1997
could you have paper do this like looking at a map.
P=paper, C=coal
PPP
PCP
PPP
coal is to implement writing.

Posted:
Fri Mar 01, 2013 20:55
by 4aiman
UPDATE!
+ Different heights distinction
+ Shows map depending on map_block's position
+ Underground map_block will show you map of the cave you're in

Posted:
Fri Mar 01, 2013 22:05
by VanessaE
Have you considered making this an item that you punch with (like using a tool or eating an apple) to display the map? I think that would be more natural than placing the block on the ground and punching it.

Posted:
Fri Mar 01, 2013 22:31
by RealBadAngel

Posted:
Sat Mar 02, 2013 07:03
by cHyper
awesome mod...

Posted:
Sat Mar 02, 2013 07:22
by 4aiman
VanessaE wrote:Have you considered making this an item that you punch with (like using a tool or eating an apple) to display the map? I think that would be more natural than placing the block on the ground and punching it.
This mod is merely a prototype - I just testing things, so that's why I didn't make it "more natutal" :)
RealBadAngel, thanks for tweaking this towards peoples wishes! ;)
Also, two words: naming convention. It's "mapp:map", not "map:map". ;)
I've updated this mod at GitHub, so link from the first post now leads to a tool. Those, who for any reason still want a block, look into init_.lua.
Any ideas for adding player mark? Not only a point, but rather an arrow, which shows what wilder is looking at?
[Rotate modifier can't rotate less than 90 deg...

Posted:
Sat Mar 02, 2013 18:18
by pandaro
Any ideas for adding player mark? Not only a point, but rather an arrow, which shows what wilder is looking at?
player:getyaw()
and +1 good work

Posted:
Sat Mar 02, 2013 18:48
by 4aiman
pandaro wrote:player:getyaw()
I mean, how to rotate texture to show that yaw, not how to get it ;)

Posted:
Sat Mar 02, 2013 19:04
by kaeza
Hmm... this may sound complicated, but how about you draw a bunch of textures for, let's say, angles 0-90 in 10deg increments, and use them as a base, rotating to get the other angles as needed?

Posted:
Sat Mar 02, 2013 20:52
by Calinou

Posted:
Sun Mar 03, 2013 15:42
by 4aiman
Hmm.. 4 textures + rotate... Thanks, kaeza, Calinou, I'll add this ;)
Added!

Posted:
Tue Mar 05, 2013 22:17
by Inocudom
A feature that turns whether liquids show on the map on or off would be a good idea (or the liquids could be transparent with the nodes below showing in them.)

Posted:
Wed Mar 06, 2013 11:50
by 4aiman
Inocudom wrote:A feature that turns whether liquids show on the map on or off would be a good idea (or the liquids could be transparent with the nodes below showing in them.)
I had the same idea ;) Will implement once be at home.
Also, there are some questions:
1. Could anyone teach me how to "cut" a single frame from a sprite-sheet? Things like flowing water and lava can be shown using water/lava~source texture, but what about animated torches & grass and other things?
2. I wanted to hide landscape if player is underground. I made a func is_ug(pos) that checks that.
But the problem is where to stop. Currently I go up if the block at y=player.pos.y in not an "air" block and go down if it is.
But imagine a cave, that splits into to paths each going in the opposite direction to another: one up goes and one goes down. So, my question is about logic:
How can I know when I need to go DOWN instead of going UP, if the block at y=player.pos.y in not an "air"?
Currently I go 10-15 blocks down and if there's still non-air block then I go up. Is there any better way to draw only what player would see, e.g w/o drawing the surface?

Posted:
Thu Mar 07, 2013 22:20
by Splizard
I have made a pull request on github with some misc performance improvements:
- Making minetest.env and minetest.registered_nodes local.
- Using table.concat instead of concatenating in a loop.
- And other small things.
The map is now generated up to 2x as fast as before and the time it takes to generate is now printed in the terminal.
https://github.com/4aiman/mapp/pull/1

Posted:
Fri Mar 08, 2013 07:14
by 4aiman
I'm still far from my place, so anyone will have to wait а little longer before I can do anything...
Although I can't say my version was slow, I'll test your improvements and merge them. But I'm going to delete the part with generation time, 'cause if we talk about performance, then we must clean up all unnecessary code. I believe that was added for me to notice speed up.
Where can I read about lua tricks like using tables instead of strings to get higher performance?

Posted:
Fri Mar 08, 2013 11:11
by kaeza
https://github.com/4aiman/mapp/pull/2A small contribution.
Just tested this mod (been too busy [read as lazy] lately :) ); it's very impressive.
Excellent work.
Edit:
Small suggestion: make the visible range customizable in the script. This can be useful for singleplayer where the mod runs fast (without network overhead).

Posted:
Fri Mar 08, 2013 13:53
by RealBadAngel
well if this mod could make efficent and good rules to display the map, maybe i or some1 else could implement it as a engine hud feature...

Posted:
Fri Mar 08, 2013 15:43
by kaeza
Added experimental threading support to avoid freezing the server.
https://github.com/kaeza/mapp/tree/threadingNeed to do some testing first, then I'll open a pull request.
Can someone help testing this?
EDIT: Works a bit slow on singleplayer; threading support can be disabled by setting ENABLE_THREADS to false.

Posted:
Fri Mar 08, 2013 15:59
by 4aiman
Merged both.
Thanks for help, guys!
PS: I believe the only thing that needs to be in a separate thread is logging. (Don't confuse logging with debug info and writing to StdErr output.)
Very often when I think smth is slow, simple deletion of any output to the terminal make things usable.
I don't say we don't need threading, but single core PCs won't benefit from it much.

Posted:
Fri Mar 08, 2013 16:07
by kaeza
4aiman wrote:Merged both.
Thanks for help, guys!
PS: I believe the only thing that needs to be in a separate thread is logging. (Don't confuse logging with debug info and writing to StdErr output.)
Very often when I think smth is slow, simple deletion of any output to the terminal make things usable.
I don't say we don't need threading, but single core PCs won't benefit from it much.
It's not threading per-se. It's collaborative multithreading.
What this means is that a routine suspends execution ("yields") to the caller routine.
What the patch does is incrementally generate the formspec at each game step. This means the server does not get frozen in the for loop, yielding at every line of the map.
When this happens, the server regains control, and allows other mods (and the game itself) to do their stuff. Then, at the next game step, it resumes the "threads" to generate another map line, and so on until it is complete and the map is shown to the player. It's not perfect, but at least leaves some time for other tasks.
EDIT: This also means no real threads are created. For more info, see this:
http://www.lua.org/manual/5.1/manual.html#2.11

Posted:
Fri Mar 08, 2013 17:17
by 4aiman
I know how threads work ;)
The problem is that some other mod (like floatlands) will do it's stuff w/o letting anyting to interfere, and a player may wait for a very long time before entire map will be drawn... It's not the problem of this mod, though.
Also, shrinking yaw calculation wasn't flawless: Server keeps printing messages like this
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
Creating a dummy image for "d-30.png"
That's because in my version there wasn't negative angles: you've deleted this:
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 yaw<0 then yaw = 360 + yaw end
if yaw>360 then yaw = yaw - 360 end
Edit:
Works too slow with any world-generating mod...
Kaeza, maybe you can add "threading" support to, for example, floatlands mod, so anyone can test that with current mod?

Posted:
Fri Mar 08, 2013 18:52
by 0gb.us
If you can't rotate less than 90 degrees, can you rotate more that 360 to simulate angles less than 90?
I don't know if that will work, it's just something you could try.

Posted:
Fri Mar 08, 2013 19:40
by 4aiman
0gb.us wrote:If you can't rotate less than 90 degrees, can you rotate more that 360 to simulate angles less than 90?
I don't know if that will work, it's just something you could try.
Can't say I got your point.
Lua API provides a way to rotate images by 90, 180 and 360 degrees only.
Besides, why do I need to rotate smth more than 360?
I wanted to have more precise angles and that resulted (after following a piece of advice provided me by Calinou) into having 9 textures (0 to 80 degrees) which are rotated by that implemented values. So now we can show player's direction with a step of 10 degrees - that's pretty "smooth", I think.
The only problem with negative angles was rooted to deletion of the quoted piece of code.

Posted:
Sun Mar 10, 2013 20:58
by Splizard
4aiman wrote:I'm still far from my place, so anyone will have to wait а little longer before I can do anything...
Although I can't say my version was slow, I'll test your improvements and merge them. But I'm going to delete the part with generation time, 'cause if we talk about performance, then we must clean up all unnecessary code. I believe that was added for me to notice speed up.
Where can I read about lua tricks like using tables instead of strings to get higher performance?
Yes it wasn't too slow but extra speed is nice :)
Thanks for merging it, you could just comment out the generation time stuff so you can use it if you need it again.
You can find some Lua optimizing tricks here:
http://www.lua.org/gems/sample.pdfhttp://lua-users.org/wiki/OptimisationTipshttp://stackoverflow.com/questions/154672/what-can-i-do-to-increase-the-performance-of-a-lua-program